<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">I now get your intent but can't really help you. You need to ask interpreter folks.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">I'd suggest you send another email, state clearly what you want, and put a summary in the subject line.</p>
<p style="margin-top:0;margin-bottom:0">You can also try the IRC, though during the week you might have more luck.<br>
</p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Alberto Barbaro <barbaro.alberto@gmail.com><br>
<b>Sent:</b> Saturday, January 26, 2019 7:07:26 PM<br>
<b>To:</b> Doerfert, Johannes Rudolf<br>
<b>Cc:</b> llvm-dev<br>
<b>Subject:</b> Re: [llvm-dev] (no subject)</font>
<div> </div>
</div>
<div>
<div dir="auto">
<div>Hi,
<div dir="auto">All good points and jokes in your email :)</div>
<div dir="auto"><br>
</div>
<div dir="auto">My final goal is the get the value of %8 at runtime. So considering the program is called argv I would like to execute something like ./argv 22 and get the value of argv[0]. Is it possible? So far I have the address where the parameter at position
 0 in store but I'd like to read the value and print it.</div>
<div dir="auto"><br>
</div>
<div dir="auto">I hope it is clear now</div>
<div dir="auto"><br>
</div>
<div dir="auto">Thanks again</div>
<br>
<br>
<div class="x_gmail_quote">
<div dir="ltr">On Fri, Jan 25, 2019, 06:23 Doerfert, Johannes Rudolf <<a href="mailto:jdoerfert@anl.gov">jdoerfert@anl.gov</a> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
On 01/20, Alberto Barbaro via llvm-dev wrote:<br>
> Hi all,<br>
> I have the following C code:<br>
> <br>
> #include<stdio.h><br>
> <br>
> int main(int argc, char *argv[]) {<br>
> <br>
>     printf("%s\n", argv[0]);<br>
>     return argc;<br>
> }<br>
> <br>
> that generates the following IR for the main function:<br>
> <br>
> ; Function Attrs: noinline nounwind optnone uwtable<br>
> define i32 @main(i32, i8**) #0 {<br>
>   %3 = alloca i32, align 4<br>
>   %4 = alloca i32, align 4<br>
>   %5 = alloca i8**, align 8<br>
>   store i32 0, i32* %3, align 4<br>
>   store i32 %0, i32* %4, align 4<br>
>   store i8** %1, i8*** %5, align 8<br>
>   %6 = load i8**, i8*** %5, align 8<br>
>   %7 = getelementptr inbounds i8*, i8** %6, i64 0<br>
>   %8 = load i8*, i8** %7, align 8<br>
>   %9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4<br>
> x i8]* @.str, i32 0, i32 0), i8* %8)<br>
>   %10 = load i32, i32* %4, align 4<br>
>   ret i32 %10<br>
> }<br>
<br>
You should really run -mem2reg (without the optnone though). Also<br>
-instcombine is afterwards often helpful to clean up clang generated<br>
code, or maybe just run it with -O1.<br>
<br>
> I think %8 will contain the address of argv[0], so %7 was storing a pointer<br>
> to pointer to argv? I'm not sure of that.<br>
<br>
Let's see: argc is %0 and argv == &argv[0] is %1. The latter is stored<br>
in %5, which is loaded as %6. The GEP (%7) is a no-op, thus %6 == %7.<br>
Finally, %8 is the value argv[0] of type char/i8.<br>
<br>
> Considering that I can access the GenericValue set by<br>
> visitGetElementPtrInst. How can I obtain the value of argv[0] at runtime<br>
> using the Interpreter class?<br>
<br>
Sorry can't help with that. I don't know the Interpreter class and I<br>
guess "GenericValue" and "visitGetElementPtrInst" are somehow related to<br>
it.<br>
<br>
> Thanks<br>
<br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank" rel="noreferrer">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer noreferrer" target="_blank">
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
<br>
-- <br>
<br>
Johannes Doerfert<br>
Researcher<br>
<br>
Argonne National Laboratory<br>
Lemont, IL 60439, USA<br>
<br>
<a href="mailto:jdoerfert@anl.gov" target="_blank" rel="noreferrer">jdoerfert@anl.gov</a><br>
</blockquote>
</div>
</div>
</div>
</div>
</body>
</html>