<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 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"MS Gothic";
panose-1:2 11 6 9 7 2 5 8 2 4;}
@font-face
{font-family:"MS Gothic";
panose-1:2 11 6 9 7 2 5 8 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:"\@MS Gothic";
panose-1:2 11 6 9 7 2 5 8 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.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">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Define a variable that takes the address of the otherwise-unused function.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--paulr<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></a></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 #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> llvm-dev [mailto:llvm-dev-bounces@lists.llvm.org]
<b>On Behalf Of </b>Soham Sinha via llvm-dev<br>
<b>Sent:</b> Tuesday, June 26, 2018 12:20 PM<br>
<b>To:</b> hans@chromium.org<br>
<b>Cc:</b> via llvm-dev<br>
<b>Subject:</b> Re: [llvm-dev] How to force an unused function declaration in clang<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">I realize that gcc also <a href="https://godbolt.org/g/ismnEj" target="_blank">
doesn't provide</a> this feature if the function doesn't have a body. I was wondering if there is any elegant way to achieve this, instead of the "hack" I mentioned earlier.<o:p></o:p></p>
<div>
<p class="MsoNormal"><br clear="all">
<o:p></o:p></p>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">Regards,<o:p></o:p></p>
<div>
<p class="MsoNormal">Soham Sinha<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">PhD Student, Department of Computer Science<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Boston University<o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Tue, Jun 26, 2018 at 10:58 AM Soham Sinha <<a href="mailto:soham1@bu.edu" target="_blank">soham1@bu.edu</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">It does, when the function has a body. When it doesn't, <a href="https://godbolt.org/g/2BCvht" target="_blank">it ignores</a>. The body might be provided later on in the toolchain via linking a library.<o:p></o:p></p>
<div>
<p class="MsoNormal"><br clear="all">
<o:p></o:p></p>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">Regards,<o:p></o:p></p>
<div>
<p class="MsoNormal">Soham Sinha<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">PhD Student, Department of Computer Science<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Boston University<o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Tue, Jun 26, 2018 at 10:25 AM Hans Wennborg <<a href="mailto:hans@chromium.org" target="_blank">hans@chromium.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">
<p class="MsoNormal">It works for me:<br>
<br>
<a href="https://godbolt.org/g/3QzqAH" target="_blank">https://godbolt.org/g/3QzqAH</a><br>
<br>
Can you share an example?<br>
<br>
On Tue, Jun 26, 2018 at 5:21 PM, Soham Sinha via llvm-dev<br>
<<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
> For the same reason GCC allowed the attribute. Even if I want to use/inline<br>
> a function later on in the pipeline.<br>
><br>
> Regards,<br>
> Soham Sinha<br>
> PhD Student, Department of Computer Science<br>
> Boston University<br>
><br>
><br>
> On Tue, Jun 26, 2018 at 8:30 AM <a href="http://mayuyu.io" target="_blank">mayuyu.io</a> <<a href="mailto:admin@mayuyu.io" target="_blank">admin@mayuyu.io</a>> wrote:<br>
>><br>
>> Out of curiosity, how does an unused declaration affect the emitted object<br>
>> file<br>
>><br>
>> Zhang<br>
>><br>
>> > <span style="font-family:"MS Gothic"">在</span> 2018<span style="font-family:"MS Gothic"">年</span>6<span style="font-family:"MS Gothic"">月</span>26<span style="font-family:"MS Gothic"">日,</span>08:48<span style="font-family:"MS Gothic"">,</span>Soham Sinha
via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
>> > <span style="font-family:"MS Gothic"">写道:</span><br>
>> ><br>
>> > clang doesn't seem to respect __attribute__((used)) in C functions. Even<br>
>> > if I declare a function like the following: __attribute__((used)) void<br>
>> > function(), then also it doesn't declare the function in its IR file if I<br>
>> > don't use the function. Is there any other way to force the declaration of<br>
>> > "unused" function declarations with clang.<br>
>> ><br>
>> > I have hacked in clang 6.0.0 in<br>
>> > tools/clang/lib/CodeGen/CodeGenModule.cpp file. I changed in EmitGlobal<br>
>> > function to detect if the function has "used" attribute and then if it has<br>
>> > then use "GetOrCreateLLVMFunction" this to create the function declaration.<br>
>> > However, this hack fails in some other cases. Therefore I am looking for a<br>
>> > proper way to do this.<br>
>> ><br>
>> > Regards,<br>
>> > Soham Sinha<br>
>> > PhD Student, Department of Computer Science<br>
>> > Boston University<br>
>> > _______________________________________________<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" target="_blank">
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
>><br>
>><br>
>><br>
><br>
> _______________________________________________<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" target="_blank">
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
><o:p></o:p></p>
</blockquote>
</div>
</blockquote>
</div>
</div>
</div>
</body>
</html>