<div dir="ltr"><div dir="ltr">On Mon, 23 Mar 2020 at 19:45, Yuseok Jeon via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><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)">
<div>Dear all,</div>
<div><br>
</div>
<div></div>
<span>I checked that clang deletes (checked IR code) structure's constructor when a structure is declared with a structure pointer (e.g., structure "Item" in the below example code).</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span><br>
</span><span>On the other hand, clang did not delete constructor when structure declared with variable (not a pointer) as structure "Item2" in the
<span style="font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255);display:inline">
below</span> example code.</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
<div></div>
<div><u>[Example Code]</u></div>
<div>
<div style="margin:0px">
<table width="" style="border-collapse:collapse">
<tbody>
<tr style="background-color:rgb(255,255,255)">
<td style="width:519px;border-width:1px;border-style:solid;border-color:rgb(171,171,171)">
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
class DataSet<br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
{<br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
public:<br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
struct Item<br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
{<br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
int info;<br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
Item() {};</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
}* theitem;<br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
<br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
struct Item2<br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
{<br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
int info; <span style="margin:0px"> </span><br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
Item2() {};<br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
} theitem2; <br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
<br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
int themax;<br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
};<br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
<span style="margin:0px"> </span><br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
int main() {<br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
DataSet T;<br>
</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
return 0;</div>
<div style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">
}</div>
</td>
</tr>
</tbody>
</table>
<br>
</div>
<div style="margin:0px"></div>
</div>
<span>I can understand this clang's behavior (for optimization).<br>
</span>
<div>However, for research purposes, I need to keep constructor although structure declared with a structure pointer.<br>
</div>
<div><br>
</div>
<span>If you don't mind, could you please advise how I find this optimization function (remove constructor) in clang (I plan to update this code)?</span></div></div></blockquote><div><br></div><div>Your description doesn't match what's happening. The constructor isn't being deleted / removed from the IR. Instead, what's happening is that it's never emitted in the first place.</div><div><br></div><div>The process Clang follows is:</div><div><br></div><div>1) Parse and semantically analyze the source file, forming an AST.</div><div>2) Emit all the strong external symbols defined in the AST, and recursively emit any discardable symbols referenced by those strong external symbols.</div><div><br></div><div>Step 1 will build AST for both the Item and Item2 constructors. In step 2, the only strong external symbol to emit as IR is main. main references the DataSet default constructor, so we emit that. The DataSet default constructor references the Item2 constructor, so we emit that. LLVM IR for he Item constructor is never emitted because it's not used by this translation unit.</div><div><br></div><div>Depending on what you want to do for your research purposes, you could either look at the AST rather than the IR, or use the -femit-all-decls flag to ask Clang to emit declarations even if they're unused.</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)">
<div></div>
<div>
<ul>
<li>I tried to forcibly insert constructor using "DeclareImplicitDefaultConstructor or DefineImplicitDefaultConstructor" and check other possible functions such as "ShouldDeleteSpecialMember" (in SemaDeclCXX.cpp). </li><li>However, I could not find an answer yet.</li></ul>
<div>Thank you very much.<br>
</div>
<div><br>
</div>
<div>Best regards,</div>
<div>Y. Jeon.</div>
</div>
</div>
</div>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>