[llvm-bugs] [Bug 46446] New: Attribute plugin example in trunk does not seem to recognize attribute arguments

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 24 13:03:09 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46446

            Bug ID: 46446
           Summary: Attribute plugin example in trunk does not seem to
                    recognize attribute arguments
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jonathan.protzenko at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

I'm re-posting this from the discord #clang channel, since I haven't any
answers there.

I'm playing with the Attribute plugin in clang/examples, and I modified one
thing: replace OptArgs = 1 (one optional argument) in the constructor with
`NumArgs = 1` (exactly one argument required)... I ran `bin/clang++
-fplugin=lib/Attribute.dylib -std=c++17 /tmp/test.hpp` with the following
contents for test.hpp:

```
[[ example("foo") ]]
void f() {
}
```

and I get:

```
jonathan at absinthe:~/Code/llvm-project/build (master) $ bin/clang++
-fplugin=lib/Attribute.dylib -std=c++17 /tmp/test.hpp 
/tmp/test.hpp:1:4: error: 'example' attribute takes one argument
[[ example("foo") ]]
   ^
1 error generated.
```

which confuses me quite a bit since the attribute *does* seem to have an
argument!

---

First possible cause: the comment in Attr.h is wrong and NumArgs has a
different behavior.

```
  /// The number of required arguments of this attribute.
  unsigned NumArgs : 4;
```

Second possible cause: the syntax I'm using for passing an argument to an
attribute is incorrect, but I thought according to
https://en.cppreference.com/w/cpp/language/attributes that I was correct.

Third possible cause: a genuine issue in ParsedAttr.

---

The reason I'm filing a bug is that I tried something different, leaving the
code in Attribute.cpp as-is, and adding `assert(false)` right after the test ` 
   if (Attr.getNumArgs() > 0) {`, in the hope of at least asserting that this
codepath is reached (same test.hpp). But, alas, nothing happened, which leads
me to think that at the very least something is wrong with the example plugin.

Thanks,

Jonathan

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200624/8df7a4b1/attachment.html>


More information about the llvm-bugs mailing list