<div dir="ltr">There isn't any option to do that - because it doesn't model the language accurately (well, ultimately, one of these days, we'll get rid of pointer types (everything will just be "pointer" (sort of like C's 'void*') - not specific to the thing it points to) at which point none of this will ever be represented in the IR) - the C language ignores the array portion (so you can pass this function a pointer to a single int, or 3 ints, not exactly 51 ints) entirely, degrading it to a pointer as far as semantics are concerned.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jun 29, 2019 at 10:48 PM Tingyuan LIANG <<a href="mailto:tliang@connect.ust.hk">tliang@connect.ust.hk</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 style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Dear David,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Thanks for your prompt reply! <br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Sure, I can implement a AST visitor to go through the AST to get the information but I just wonder whether there is any other way to let Clang do so.<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
What I am considering is how to let the generated IR looks like below, which some tools realize:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<div><span>define dso_local i32 @_Z1fPii(</span>[51 x i32]*<span></span><span> %A, i32 %x) local_unnamed_addr #0 !dbg !7
</span><span>{</span></div>
<div><span>entry:</span></div>
...</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
}<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div id="gmail-m_5682031420919250322Signature">
<div id="gmail-m_5682031420919250322divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif">
<span id="gmail-m_5682031420919250322ms-rterangepaste-start"></span>
<div><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">Best regards,</span></font><span style="font-size:12pt">
</span><span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0px"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">------------------------------------------</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0px"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">Tingyuan LIANG</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0px"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">MPhil Student</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0px"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">Department of Electronic and Computer Engineering</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0px"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">The Hong Kong University of Science and Technology</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span><span style="font-size:12pt"></span><span id="gmail-m_5682031420919250322ms-rterangepaste-end"></span></div>
</div>
<div id="gmail-m_5682031420919250322appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_5682031420919250322divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>><br>
<b>Sent:</b> Sunday, June 30, 2019 1:40 PM<br>
<b>To:</b> Tingyuan LIANG<br>
<b>Cc:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> Re: [llvm-dev] Information Loss of Array Type in Function Interface in IR Generated by Clang</font>
<div> </div>
</div>
<div>
<div dir="ltr">LLVM IR doesn't maintain a lot of information present in the source. What were you hoping to do with that information? Perhaps you'd be best off doing something up in clang/using the AST uinstead of LLVM IR?</div>
<br>
<div class="gmail-m_5682031420919250322x_gmail_quote">
<div dir="ltr" class="gmail-m_5682031420919250322x_gmail_attr">On Sat, Jun 29, 2019 at 10:36 PM Tingyuan LIANG 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-m_5682031420919250322x_gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Dear all,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Hi! Recently, I notice a situation where I cannot infer the size of the outermost dimension of array in the function interface.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
To concretely depict the problem, I show the C source code and the generated IR code at the end. The array size of A[] is 51 but this information is lost in the generated IR.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
How can I maintain such information in IR? Should I set some argument for Clang so it can do so?</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
The Clang command I used is : <br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
<div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-weight:normal;font-size:14px;line-height:19px">
<div><span style="color:rgb(206,145,120)"> clang -O1 -emit-llvm -S -g tmp.cc -o tmp.bc</span></div>
</div>
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Thanks in advance for your time and suggestion! ^_^<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
C source code: <br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-weight:normal;font-size:14px;line-height:19px">
<div><span style="color:rgb(86,156,214)">int</span><span> </span><span style="color:rgb(220,220,170)">f</span><span> (
</span><span style="color:rgb(86,156,214)">int</span><span> </span><span style="color:rgb(156,220,254)">A</span><span>[</span><span style="color:rgb(181,206,168)">51</span><span>],
</span><span style="color:rgb(86,156,214)">int</span><span> </span><span style="color:rgb(156,220,254)">x</span><span>)
</span></div>
<div><span>{</span></div>
<div><span> </span><span style="color:rgb(197,134,192)">return</span><span> </span><span style="color:rgb(156,220,254)">A</span><span>[x];</span></div>
<div><span>}</span></div>
</div>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
===========================</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
generated IR:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-weight:normal;font-size:14px;line-height:19px">
<div><span>; Function Attrs: norecurse nounwind readonly uwtable</span></div>
<div><span>define dso_local i32 @_Z1fPii(i32</span><span>*</span><span> nocapture readonly %A, i32 %x) local_unnamed_addr #0 !dbg !7
</span><span>{</span></div>
<div><span>entry:</span></div>
<div><span> call </span><span style="color:rgb(86,156,214)">void</span><span> @llvm.dbg.value(metadata i32</span><span>*</span><span> %A, metadata !13, metadata !DIExpression()), !dbg !15</span></div>
<div><span> call </span><span style="color:rgb(86,156,214)">void</span><span> @llvm.dbg.value(metadata i32 %x, metadata !14, metadata !DIExpression()), !dbg !16</span></div>
<div><span> %idxprom </span><span>=</span><span> sext i32 %x to i64, !dbg !17</span></div>
<div><span> %arrayidx </span><span>=</span><span> getelementptr inbounds i32, i32</span><span>*</span><span> %A, i64 %idxprom, !dbg !17</span></div>
<div><span> %0 </span><span>=</span><span> load i32, i32</span><span>*</span><span> %arrayidx, align
</span><span style="color:rgb(181,206,168)">4</span><span>, !dbg !17, !tbaa !18</span></div>
<div><span> ret i32 %0, !dbg !22</span></div>
<div><span>}</span></div>
</div>
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div id="gmail-m_5682031420919250322x_gmail-m_-4750863312345150083Signature">
<div id="gmail-m_5682031420919250322x_gmail-m_-4750863312345150083divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif">
<span id="gmail-m_5682031420919250322x_gmail-m_-4750863312345150083ms-rterangepaste-start"></span>
<div><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">Best regards,</span></font><span style="font-size:12pt">
</span><span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0px"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">------------------------------------------</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0px"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">Tingyuan LIANG</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0px"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">MPhil Student</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0px"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">Department of Electronic and Computer Engineering</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0px"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">The Hong Kong University of Science and Technology</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span><span style="font-size:12pt"></span><span id="gmail-m_5682031420919250322x_gmail-m_-4750863312345150083ms-rterangepaste-end"></span></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>
</div>
</div>
</blockquote></div>