]> granicus.if.org Git - clang/commitdiff
[TableGen] Ignore fake args for parsing-related arg counts.
authorGeorge Burgess IV <george.burgess.iv@gmail.com>
Thu, 1 Dec 2016 17:52:39 +0000 (17:52 +0000)
committerGeorge Burgess IV <george.burgess.iv@gmail.com>
Thu, 1 Dec 2016 17:52:39 +0000 (17:52 +0000)
We should complain about the following:

```
void foo() __attribute__((unavailable("a", "b")));
```

Instead, we currently just ignore "b". (...We also end up ignoring "a",
because we assume elsewhere that this attribute can only have 1 or 0
args.)

This happens because `unavailable` has a fake enum arg, and
`AttributeList::{getMinArgs,getMaxArgs}` include fake args in their
counts.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288388 91177308-0d34-0410-b5e6-96231b3b80d8

test/Sema/attr-unavailable-message.c
utils/TableGen/ClangAttrEmitter.cpp

index 400a2c6328838329e5207163935bc3f5f8207a42..415cb2f079a2e4a71d3adb8f590b3cb0a0b2d0ca 100644 (file)
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 // rdar: //6734520
 
+void tooManyArgs() __attribute__((unavailable("a", "b"))); // expected-error {{'unavailable' attribute takes no more than 1 argument}}
+
 int foo(int)  __attribute__((__unavailable__("USE IFOO INSTEAD"))); // expected-note {{'foo' has been explicitly marked unavailable here}}
 double dfoo(double)  __attribute__((__unavailable__("NO LONGER"))); // expected-note 2 {{'dfoo' has been explicitly marked unavailable here}}
 
index 78a2eb118bc1e636e18b79e156b3e03de5b5b2de..8185b6ab1e2a2a9461625d5731478df7459880d4 100644 (file)
@@ -2540,6 +2540,10 @@ static void emitArgInfo(const Record &R, std::stringstream &OS) {
   unsigned ArgCount = 0, OptCount = 0;
   bool HasVariadic = false;
   for (const auto *Arg : Args) {
+    // If the arg is fake, it's the user's job to supply it: general parsing
+    // logic shouldn't need to know anything about it.
+    if (Arg->getValueAsBit("Fake"))
+      continue;
     Arg->getValueAsBit("Optional") ? ++OptCount : ++ArgCount;
     if (!HasVariadic && isArgVariadic(*Arg, R.getName()))
       HasVariadic = true;