How to write are Spelling syntax for attributes with arguments?

I’d like to add customs attributes (AS_GNU for the moment) via a clang-plugin using ParsedAttrInfo.

My attributes have arguments.

void f() __attribute__((MyAttr(A)));
void f2() __attribute__((MyAttr(A, B, C)));

How do I have to write the Spelling (and maybe other members of the ParsedAttrInfo-class) to have clang match my attributes?

		    {ParsedAttr::AS_GNU, "MyAttr"}, // works
		    {ParsedAttr::AS_GNU, "MyAttrT(...)"}, // does not work
		    {ParsedAttr::AS_GNU, "MyAttrY()"}, // does not work
		    {ParsedAttr::AS_GNU, "MyAttrZ(1,2,3)"}, // does not work either

I’m unable to find any examples using ParsedAttrInfo, other than the comment in ParsedAttr.h .

Well, easier than I thought. I just set OptArgs to 4 and then it accepts optional arguments to MyAttr.

1 Like

I can confirm that’s the proper way to do that. NumArgs are for the required number of attributes, and OptArgs is for the optional arguments. FWIW, we have a small amount of documentation available here: Clang Plugins — Clang 17.0.0git documentation

1 Like

Thanks. Yes, I saw that documentation, of course. But then examples of __attribute__(())-usages and my brain were mixing up things and didn’t look at the numArgs etc. description - hence my original question. Thanks for confirming.

1 Like