[cfe-dev] help -- how can i know whether a variable has user-defined attributes or not in Clang?

Nikola Smiljanic popizdeh at gmail.com
Tue Oct 7 16:33:43 PDT 2014


Hi Shen, documentation for __has_attribute says: This function-like macro
takes a single identifier argument that is the name of an attribute. It
evaluates to 1 if the attribute is supported by the current compilation
target, or 0 if not.

So this macro is used to query the compiler support for a specific
attribute.

As far as I understand attributes are mostly useful "inside" the compiler
but you'd like to annotate your variable and query this attribute from the
code? As in:

int x __attribute_(foo);
if (__has_attribute(foo, x)) { ... some code }

Is that what you're trying to do?

Aaron should know this, he's the main attributor :P

On Sat, Oct 4, 2014 at 3:12 AM, Shen Liu <liushenster at gmail.com> wrote:

> Dear Clang Developers,
>
> I am Shen, a beginner in Clang and LLVM. I hope to add some attributes to
> some variables, and check which variables include which attributes in my
> program. For example, I can write a statement as:
>
> int x __attribute_(foo); (here "foo" is an attribute defined by myself)
>
> and then how can i check whether x has attribute "foo"?  In Clang manual,
> the macro "__has_attribute" is just used for adding attribute for clang,
> not for a concrete variable. Can you give me some help?
>
>
> This is the first time for me to use this way to ask questions about LLVM,
> if anything wrong please let me know so i can use a better way to get your
> help.
>
> Thank you very much and have a nice day!
>
> Shen
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141008/45d5f8bb/attachment.html>


More information about the cfe-dev mailing list