<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Times;
        panose-1:2 2 6 3 5 4 5 2 3 4;}
@font-face
        {font-family:"Helvetica Neue";
        panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">In order to get the described effect, I think we’d need to put DW_AT_artificial on the subprogram, and then not attach source locations to the generated code.  That would have the effect of not allowing break/step inside, but the subprogram
 name is still available. This is not the same as `nodebug`, where you lose the subprogram name too.<o:p></o:p></p>
<p class="MsoNormal">Shouldn’t be at all hard to get this to work.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Fangqing, would you be able to file an issue for this?<o:p></o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal">--paulr<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org> <b>On Behalf Of
</b>David Blaikie via llvm-dev<br>
<b>Sent:</b> Friday, January 28, 2022 2:37 PM<br>
<b>To:</b> Reid Kleckner <rnk@google.com><br>
<b>Cc:</b> llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [llvm-dev] about __attribute__((artificial)) and inline pass<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Fri, Jan 28, 2022 at 11:26 AM Reid Kleckner <<a href="mailto:rnk@google.com">rnk@google.com</a>> wrote:<o:p></o:p></p>
</div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">I thought `artificial` and `nodebug` were supposed to be synonyms, just different names invented by different communities.
<o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><br>
Doesn't look like it, based on the GCC documentation and behavior - GCC puts the DW_AT_artificial attribute on the entity, but still fully describes it (DWARF remains the same except for that attribute). I think the second option in the GCC docs is for debug
 info formats that don't have an equivalent of DW_AT_artificial, in which case it downgrades to the equivalent of "nodebug".<br>
 <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">The linked patch doesn't implement the LLVM side of things, so I'm not sure when that got added.<o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><br>
The patch added the artificial flag on the metadata which was already implemented/supported in LLVM (used for things like implicit constructors, etc, which don't have user-written code in them) and matches the GCC behavior - no extra work was needed on the
 LLVM side.<br>
 <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Fri, Jan 28, 2022 at 11:03 AM David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal">Hmm, seems I missed this feature (or at least don't remember) when it went in.<br>
<br>
Looks like the GCC spec might be more accurate to the current implementation than what Clang's documentation says:<br>
<br>
"<span style="font-size:13.5pt;font-family:"Times",serif;color:black">artificial</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><a name="m_8334339238115289765_m_4238466721377605"></a><span style="font-size:13.5pt;font-family:"Times",serif;color:black">This attribute is useful for small inline wrappers which if possible should appear during
 debugging as a unit, depending on the debug info format it will either mean marking the function as artificial or using the caller location for all instructions within the inlined body."<o:p></o:p></span></p>
<p class="MsoNormal"><br>
& the "marking the function as artificial" is the thing that this patch implemented in Clang. This did not have the same effect as nodebug, and doesn't "use the caller location for all instructions within the inlined body".<br>
<br>
It's possible we could implement the "artificial" attribute as a an alias for "nodebug" which would also be conforming with GCC's spec, but would be less expressive than the current implementation (though would save debug info size in a way the current Clang
 implementation does not).<br>
<br>
It looks like Clang's implementation is consistent with GCC's implementation for DWARF - "marking the function as artificial", not "using the caller location for instructions within the inlined body", but Clang's documentation is incorrect, since it documents
 the latter and not the former.<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Fri, Jan 28, 2022 at 9:44 AM Fangqing Du via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">Dear all,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">In clang/llvm 7.0, `__attribute__((artificial))` can be identified by clang and attach `DIFlagArtificial` into function metadata in
<a href="https://urldefense.com/v3/__https:/reviews.llvm.org/D43259*change-jbvcnfxttyAz__;Iw!!JmoZiZGBv3RvKRSx!pEsMF8kDNPtKteuvhreMp6mZjOVtB-7XVCgfOi_ELf630AbjxHC2VDLB3BoX9IMFWg$" target="_blank">
this change.</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">And according to the <a href="https://urldefense.com/v3/__https:/clang.llvm.org/docs/AttributeReference.html*artificial__;Iw!!JmoZiZGBv3RvKRSx!pEsMF8kDNPtKteuvhreMp6mZjOVtB-7XVCgfOi_ELf630AbjxHC2VDLB3BrUKhXpvw$" target="_blank">
specification</a> of `artificial`, if I understand correctly, when the function (which is marked with `artificial` attribute) is inlined, the inlined function instructions should be associated with the callsite line number, instead of the line of inlined callee.<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">But from my observation, with and without this attribute, the inline pass behavior is not affected, and inlined instructions debug location still point to the callee instead of callsite.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Here is my experiment: <a href="https://urldefense.com/v3/__https:/godbolt.org/z/oW8Td5d4M__;!!JmoZiZGBv3RvKRSx!pEsMF8kDNPtKteuvhreMp6mZjOVtB-7XVCgfOi_ELf630AbjxHC2VDLB3BqqabukgA$" target="_blank">
godbolt experiment link</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Is my understanding correct?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Fangqing<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Xilinx Inc.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">== ------------ example -------------===<o:p></o:p></p>
</div>
<div>
<p style="margin:0in;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:10.0pt;font-family:"Helvetica Neue",serif;color:black;background:#CCCCCC">  1 int bar(int);</span><span style="font-size:10.0pt;font-family:"Helvetica Neue",serif"><o:p></o:p></span></p>
<p style="margin:0in;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:10.0pt;font-family:"Helvetica Neue",serif;color:black;background:#CCCCCC">  2 </span><span style="font-size:10.0pt;font-family:"Helvetica Neue",serif"><o:p></o:p></span></p>
<p style="margin:0in;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:10.0pt;font-family:"Helvetica Neue",serif;color:black;background:#CCCCCC">  3 inline int __attribute__((artificial)) __attribute__((always_inline)) foo(int x)</span><span style="font-size:10.0pt;font-family:"Helvetica Neue",serif"><o:p></o:p></span></p>
<p style="margin:0in;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:10.0pt;font-family:"Helvetica Neue",serif;color:black;background:#CCCCCC">  4 {</span><span style="font-size:10.0pt;font-family:"Helvetica Neue",serif"><o:p></o:p></span></p>
<p style="margin:0in;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:10.0pt;font-family:"Helvetica Neue",serif;color:black;background:#CCCCCC">  5     return bar(x + 1); </span><span style="font-size:10.0pt;font-family:"Helvetica Neue",serif"><o:p></o:p></span></p>
<p style="margin:0in;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:10.0pt;font-family:"Helvetica Neue",serif;color:black;background:#CCCCCC">  6 }</span><span style="font-size:10.0pt;font-family:"Helvetica Neue",serif"><o:p></o:p></span></p>
<p style="margin:0in;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:10.0pt;font-family:"Helvetica Neue",serif;color:black;background:#CCCCCC">  7 </span><span style="font-size:10.0pt;font-family:"Helvetica Neue",serif"><o:p></o:p></span></p>
<p style="margin:0in;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:10.0pt;font-family:"Helvetica Neue",serif;color:black;background:#CCCCCC">  8 void baz(void)</span><span style="font-size:10.0pt;font-family:"Helvetica Neue",serif"><o:p></o:p></span></p>
<p style="margin:0in;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:10.0pt;font-family:"Helvetica Neue",serif;color:black;background:#CCCCCC">  9 {</span><span style="font-size:10.0pt;font-family:"Helvetica Neue",serif"><o:p></o:p></span></p>
<p style="margin:0in;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:10.0pt;font-family:"Helvetica Neue",serif;color:black;background:#CCCCCC"> 10     auto x = foo(1);</span><span style="font-size:10.0pt;font-family:"Helvetica Neue",serif"><o:p></o:p></span></p>
<p style="margin:0in;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:10.0pt;font-family:"Helvetica Neue",serif;color:black;background:#CCCCCC"> 11     x = foo(2);</span><span style="font-size:10.0pt;font-family:"Helvetica Neue",serif"><o:p></o:p></span></p>
<p style="margin:0in;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:10.0pt;font-family:"Helvetica Neue",serif;color:black;background:#CCCCCC"> 12 }</span><span style="font-size:10.0pt;font-family:"Helvetica Neue",serif"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">When function 'foo' is inlined, the debug location of call instruction 'bar' still points to line #5, instead of line #10 and #11.<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">_______________________________________________<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://urldefense.com/v3/__https:/lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev__;!!JmoZiZGBv3RvKRSx!pEsMF8kDNPtKteuvhreMp6mZjOVtB-7XVCgfOi_ELf630AbjxHC2VDLB3Bp86eErug$" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</blockquote>
</div>
</blockquote>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</body>
</html>