[LLVMdev] Propagate clang attribute to IR

Aaron Ballman
2015-03-24T13:55:35Z

On Tue, Mar 24, 2015 at 9:48 AM, Rinaldini Julien
<julien.rinaldini at heig-vd.ch> wrote:
> Hi,
>
> I want to *tag* some functions with some *flags*. I was using
annotate((“myFlag”)) and everything was working fine until I tried on ObjC
method. It seems that clang just ignore it.
>
> So, to be able to *flag* my functions I’m trying to add a *real* attribute
to clang.
>
> I’ve added a new attribute to clang in
tools/clang/include/clang/Basic/Attr.td:
>
> def NoFLA : Attr {
>   let Spellings = [GNU<"nofla">, CXX11<"gnu",
"nofla">];
> }
>
> In tools/clang/lib/Sema/SemaDeclAttr.cpp I added my new attribute to the
switch that handle it and created my own handler function.
> I’m trying to simply pass my attribute to the IR attribute list, but,
sadly, I have absolutely no idea how to do that. I looked at others handler but
none seems to do that. I also tried to use handleSimpleAttribute, but it doesn’t
work either.
>
> Any idea how to do that (or enable annotate on ObjC method)?

handleSimpleAttribute takes the parsed attribute (AttributeList entry)
and turns it into a semantic attribute (Attr subclass). You have to
manually handle the semantic attribute in whatever way makes sense for
your attribute. Check out CodeGenModule::ConstructAttributeList for an
example of how function semantic attributes translate into IR
attributes to be passed along to LLVM.

HTH!

~Aaron