<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">I see, thanks!</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">I actually was iterating over the users of the GEP in another place but my mistake was altering the containing function while iterating, which ended the iteration mid way.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">Cheers,</div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse">--<font color="#888888">Nimrod.</font></span></div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Nov 27, 2020 at 4:55 AM Craig Topper <<a href="mailto:craig.topper@gmail.com">craig.topper@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Each call appears to use an identical ConstantExpr getelementptr. Each of those ConstantExprs is represented by the same object in the memory representation of IR even though its printed in 4 separate places. If you walk the users of that object you should find the 4 calls.<div><br clear="all"><div><div dir="ltr">~Craig</div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 26, 2020 at 5:26 PM Nimrod Partush via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">Hi,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-size:small"><span style="font-family:arial,helvetica,sans-serif">I'm writing some code transformations using CLang. When I run my code on </span><font face="arial, helvetica, sans-serif">clang/test/CodeGen/2009-02-13-zerosize-union-field.c :</font></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-size:small"><font face="monospace">typedef unsigned int Foo __attribute__((aligned(32)));<br>typedef union{Foo:0;}a;<br>typedef union{int x; Foo:0;}b;<br>extern int printf(const char*, ...);<br>int main() {<br> // CHECK: getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 0<br> printf("%ld\n", sizeof(a));<br> // CHECK: getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 1<br> printf("%ld\n", __alignof__(a));<br> // CHECK: getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 4<br> printf("%ld\n", sizeof(b));<br> // CHECK: getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 4<br> printf("%ld\n", __alignof__(b));<br>}</font><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">I see that when I iterate the <font face="monospace">users()</font><font face="arial, helvetica, sans-serif"> of the</font><font face="monospace"> "%ld\n"</font><font face="arial, helvetica, sans-serif"> string, </font>only the last user is reported. Here's my code for doing the iteration:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-size:small"><font face="monospace">for (llvm::GlobalVariable &Glob : TheModule.globals()) <br></font></div><div class="gmail_default" style="font-size:small"><font face="monospace"> for (User *U : Glob.users())</font></div><font face="monospace"> outs() << "User " << *U << "\n";</font><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"> </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">The 4 different calls are clearly visible in the .ll file:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-size:small"><font face="monospace"> %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @"??_C@_04PEDNGLFL@?$CFld?6?$AA@", i64 0, i64 0), i64 4)<br> %call1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @"??_C@_04PEDNGLFL@?$CFld?6?$AA@", i64 0, i64 0), i64 1)<br> %call2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @"??_C@_04PEDNGLFL@?$CFld?6?$AA@", i64 0, i64 0), i64 4)<br> %call3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @"??_C@_04PEDNGLFL@?$CFld?6?$AA@", i64 0, i64 0), i64 4)</font><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">Any idea why this is happening?</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">Thanks</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br clear="all"></div><div><div dir="ltr"><div dir="ltr"><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse">--<font color="#888888">Nimrod.</font></span></div></div></div></div></div></div>
_______________________________________________<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>
</blockquote></div>