<div dir="ltr">Hi,<div><br></div><div>I think, the syntax is wrong.</div><div>You can try this way..</div><div><br></div><div><br></div><div><div><b>#define NEWATTR __attribute__((annotate("moviAttr")))</b></div><div><br></div><div>int main()</div><div>{</div><div> NEWATTR volatile unsigned int a = 5;</div><div><b> volatile unsigned int *p;</b></div><div> p = &a;</div><div> return (a+*p);</div><div>}</div></div><div><br></div><div><br></div><div><br></div><div>And it generates</div><div><br></div><div><div>; ModuleID = 'test2.cpp'</div><div>target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"</div><div>target triple = "x86_64-pc-linux-gnu"</div><div><br></div><div>@.str = private unnamed_addr constant [9 x i8] c"moviAttr\00", section "llvm.metadata"</div><div>@.str1 = private unnamed_addr constant [10 x i8] c"test2.cpp\00", section "llvm.metadata"</div><div><br></div><div>; Function Attrs: nounwind uwtable</div><div>define i32 @main() #0 {</div><div> %1 = alloca i32, align 4</div><div> %a = alloca i32, align 4</div><div> %p = alloca i32*, align 8</div><div> store i32 0, i32* %1</div><div> %2 = bitcast i32* %a to i8*</div><div><b> call void @llvm.var.annotation(i8* %2, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8]* @.str1, i32 0, i32 0), i32 5)</b></div><div> store volatile i32 5, i32* %a, align 4</div><div> store i32* %a, i32** %p, align 8</div><div> %3 = load volatile i32* %a, align 4</div><div> %4 = load i32** %p, align 8</div><div> %5 = load volatile i32* %4, align 4</div><div> %6 = add i32 %3, %5</div><div> ret i32 %6</div><div>}</div><div><br></div><div>; Function Attrs: nounwind</div><div><b>declare void @llvm.var.annotation(i8*, i8*, i8*, i32) #1</b></div><div><br></div><div>attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }</div><div>attributes #1 = { nounwind }</div><div><br></div><div>!llvm.ident = !{!0}</div><div><br></div><div>!0 = !{!"Ubuntu clang version 3.6.0-2ubuntu1~trusty1 (tags/RELEASE_360/final) (based on LLVM 3.6.0)"}</div></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 25, 2016 at 12:52 PM, Naveed Ul Mustafa via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi All,<br>
<br>
I need your guidance about a custom attribute. I have defined one for variables. It is accepted in the source code (without any warnings from clang), for example in following snippet.<br>
<br>
#define NEWATTR __attribute__((moviAttr(1)))<br>
<br>
int main()<br>
{<br>
NEWATTR volatile unsigned int a = 5;<br>
volatile unsigned int *p;<br>
p = &a;<br>
return (a+*p);<br>
}<br>
<br>
<br>
and actually when I Dump the declaration, after adding the attribute in handleMoviAttr() function in SemaDeclAttr.cpp as shown in following snippet<br>
<br>
D->addAttr(::new (S.Context)moviAttrAttr(Attr.g<wbr>etRange(), S.Context, Val, Attr.getAttributeSpellingListI<wbr>ndex()));<br>
D->dump();<br>
<br>
It is dumped by clang with following output<br>
<br>
VarDecl 0x440c698 <file.c:6:17, line:10:32> col:32 a 'volatile unsigned int'<br>
`-moviAttrAttr 0x440c6d0 <line:6:32, col:42> 1<br>
<br>
HOWEVER, the attribute doesnt appear in IR of the program. IR is shown below.<br>
<br>
*** IR Dump Before Pre-ISel Intrinsic Lowering ***; ModuleID = 'file.bc'<br>
source_filename = "file.c"<br>
target datalayout = "e-m:e-p:32:32-f64:64-i64:64-v<wbr>128:64-v64:64-v32:32-v16:16-n8<wbr>:16:32-S64"<br>
target triple = "shave"<br>
<br>
; Function Attrs: nounwind<br>
define i32 @main() local_unnamed_addr #0 {<br>
%1 = alloca i32, align 4<br>
%2 = bitcast i32* %1 to i8*<br>
call void @llvm.lifetime.start(i64 4, i8* %2)<br>
store volatile i32 5, i32* %1, align 4<br>
%3 = load volatile i32, i32* %1, align 4<br>
%4 = load volatile i32, i32* %1, align 4<br>
%5 = add i32 %4, %3<br>
call void @llvm.lifetime.end(i64 4, i8* %2)<br>
ret i32 %5<br>
}<br>
<br>
; Function Attrs: argmemonly nounwind<br>
declare void @llvm.lifetime.start(i64, i8* nocapture) #1<br>
<br>
; Function Attrs: argmemonly nounwind<br>
declare void @llvm.lifetime.end(i64, i8* nocapture) #1<br>
<br>
attributes #0 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-lea<wbr>f" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="fal<wbr>se" "stack-protector-buffer-size"=<wbr>"8" "target-cpu"="myriad2.2" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
attributes #1 = { argmemonly nounwind "target-cpu"="myriad2.2" }<br>
<br>
Can someone help me please to solve the problem so that custom attribute also appears in the IR.<br>
<br>
Thanks in advance<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Naveed Ul Mustafa<br>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</font></span></blockquote></div><br></div>