<div dir="ltr">Summary of discussion happened on IRC with Aaron Ballman :<div><br></div><div>The actual problem is that for function declaration clang does not process any thing else except lowring it to appropriate LLVM IR construct thus regmask attribute is getting dropped also annotate attribute. ( This can be verified from lib/CodeGen/CGDecl.cpp )</div><div><br></div><div>So this needs to be fixed in CGDecl.cpp at least for custom attribute like regmask. </div><div><br></div><div>The fix should be some thing similar to</div><div><div>void CodeGenModule::AddGlobalAnnotations()</div></div><div><br></div><div><div>So while clang codegen to LLVM IR the attribute should be propagated to LLVM IR appropriately.</div></div><div><br></div><div>-Vivek</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 11, 2016 at 8:45 PM, vivek pandya <span dir="ltr"><<a href="mailto:vivekvpandya@gmail.com" target="_blank">vivekvpandya@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Mon, Jul 11, 2016 at 6:03 PM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>On Mon, Jul 11, 2016 at 6:47 AM, vivek pandya via cfe-dev<br>
<<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br>
> Hello Clang Developers,<br>
><br>
> I want to add a new attribute which is required to work with function<br>
> declaration as shown in example given below:<br>
><br>
> extern void foo(int param) __attribute__((regmask("R8,R11")));<br>
><br>
> int foo2(int param) {<br>
> foo(param);<br>
> return param;<br>
> }<br>
><br>
> For this I have done following changes:<br>
><br>
> Attr.td<br>
><br>
> def RegMask : Attr {<br>
>   let Spellings = [GNU<"regmask">];<br>
>   let Args = [StringArgument<"ClobbersList">];<br>
>   let Subjects = SubjectList<[Function]>;<br>
>   let Documentation = [Undocumented];<br>
> }<br>
><br>
> lib/Sema/SemaDeclAttr.cpp<br>
><br>
> static void handleRegMaskAttr(Sema &S, Decl *D, const AttributeList &Attr) {<br>
>   // Make sure that there is a string literal as the annotation's single<br>
>   // argument.<br>
>   StringRef Str;<br>
>   if (!S.checkStringLiteralArgumentAttr(Attr, 0, Str))<br>
>     return;<br>
><br>
>   D->addAttr(::new (S.Context)<br>
>              AnnotateAttr(Attr.getRange(), S.Context, Str,<br>
>                           Attr.getAttributeSpellingListIndex()));<br>
>   llvm::dbgs() << "Reg Mask attribute : " << Str << "\n";<br>
> }<br>
><br>
> above method is very similar to handleAnnotateAttr<br>
><br>
> and use this method inside ProcessDeclAttribute method as follows :<br>
><br>
> // Attribute to help interprocedural register allocation<br>
>   case AttributeList::AT_RegMask:<br>
>     handleRegMaskAttr(S, D, Attr);<br>
>     break;<br>
>   }<br>
><br>
> but this does not work for me, it works on function definitions but not with<br>
> function declaration.<br>
><br>
> Am I missing here any thing?<br>
<br>
</div></div>The attribute should inherit from InheritableAttr instead of just<br>
Attr. That should cause it to be inherited by later redeclarations.<br></blockquote></div></div><div>I think my question is not clear, in the example given above foo and foo2 both are different function and what I want is that foo is extern function for current module and for this declaration I want regmask attribute as a string.</div><div>Why should I need InheritableAttr when foo is not going to be redeclared in the current module? </div><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span><br>
> Note: I want to parse this string at MI level if possible or at IR level to<br>
> create a RegMask out of that.<br>
<br>
</span>How do you intend to report diagnostics to the user if the parsed<br>
string contains something unexpected?<br></blockquote></span><div>If I am not able to use clang's diagnostics then I believe I should take help of some thing like LLVM_ERROR.</div><span class="HOEnZb"><font color="#888888"><div>-Vivek</div></font></span><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
~Aaron<br>
<br>
><br>
> Sincerely,<br>
> Vivek<br>
><br>
> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
><br>
</blockquote></span></div><br></div></div>
</blockquote></div><br></div>