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)? Cheers
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
> On 24 Mar 2015, at 14:55, Aaron Ballman <aaron at aaronballman.com> wrote: > > 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! > > ~AaronHi, Thx for your answer... I tried that without any luck: static void handleOBF(Sema &S, Decl *D, const AttributeList &Attr) { D->addAttr(::new (S.Context)NoFLAAttr(Attr.getRange(), S.Context, Attr.getAttributeSpellingListIndex())); // ??????????? llvm::AttrBuilder FuncAttrs; FuncAttrs.addAttribute(); } In CodeGenModule::ConstructAttributeList it uses a AttrBuilder, I tried there to add a random attribute and it works. But I’m not understanding how to do that in SemaDeclAttr.cpp. Cheers
Seemingly Similar Threads
- [LLVMdev] Propagate clang attribute to IR
- [LLVMdev] Using the New Attributes Classes
- [LLVMdev] Embedding cpu and feature strings into IR and enabling switching subtarget on a per function basis
- [RFC] Attribute overhaul 2
- [RFC] Adding a -memeq-lib-function flag to allow the user to specify a memeq function.