<div dir="ltr">Hello all,<div><br></div><div>I'm using libTooling to generate the AST of a given program (that will later be translated to our own internal AST), and I just found this odd CXXConstructorDecl for the following program:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>class X</div></div><div><div>{</div></div><div><div> public:</div></div><div><div> X() {};</div></div><div><div><br></div></div><div><div> char str[20][20][230];</div></div><div><div>};</div></div><div><div><br></div></div><div><div>int main(void)</div></div><div><div>{</div></div><div><div> X x;</div></div><div><div> X x1 = x;</div></div><div><div> return 0;</div></div><div><div>}</div></div></blockquote><div><div><br></div><div>The implicit constructor for X is:</div><div><br></div><div><div>CXXConstructorDecl 0x3959fd0 <line:3:7> col:7 implicit used X 'void (const class X &) throw()' inline</div><div>| |-ParmVarDecl 0x395a110 <col:7> col:7 used 'const class X &'</div><div>| |-CXXCtorInitializer Field 0x3908c48 'str' 'char [20][20][230]'</div><div>| | `-ImplicitCastExpr 0x395a6e8 <col:7> 'char' <LValueToRValue></div><div>| | `-ArraySubscriptExpr 0x395a6c0 <col:7> 'const char' lvalue</div><div>| | |-ImplicitCastExpr 0x395a6a8 <col:7> 'const char *' <ArrayToPointerDecay></div><div>| | | `-ArraySubscriptExpr 0x395a560 <col:7> 'char const[230]' lvalue</div><div>| | | |-ImplicitCastExpr 0x395a548 <col:7> 'char const (*)[230]' <ArrayToPointerDecay></div><div>| | | | `-ArraySubscriptExpr 0x395a400 <col:7> 'char const[20][230]' lvalue</div><div>| | | | |-ImplicitCastExpr 0x395a3e8 <col:7> 'char const (*)[20][230]' <ArrayToPointerDecay></div><div>| | | | | `-MemberExpr 0x395a298 <col:7> 'char const[20][20][230]' lvalue .str 0x3908c48</div><div>| | | | | `-DeclRefExpr 0x395a270 <col:7> 'const class X' lvalue ParmVar 0x395a110 '' 'const class X &'</div><div>| | | | `-ImplicitCastExpr 0x395a368 <col:7> 'unsigned int' <LValueToRValue></div><div>| | | | `-DeclRefExpr 0x395a340 <col:7> 'unsigned int' lvalue Var 0x395a2e0 '__i0' 'unsigned int'</div><div>| | | `-ImplicitCastExpr 0x395a4c0 <col:7> 'unsigned int' <LValueToRValue></div><div>| | | `-DeclRefExpr 0x395a498 <col:7> 'unsigned int' lvalue Var 0x395a438 '__i1' 'unsigned int'</div><div>| | `-ImplicitCastExpr 0x395a620 <col:7> 'unsigned int' <LValueToRValue></div><div>| | `-DeclRefExpr 0x395a5f8 <col:7> 'unsigned int' lvalue Var 0x395a598 '__i2' 'unsigned int'</div><div>| `-CompoundStmt 0x395a748 <col:7></div></div><div><br></div><div>Which should look this (I think): </div><div><br></div><div>X(const X& ref) : str(ref.str[__i0][__i1][__i2]) {}</div><div><br></div><div>Or maybe: </div><div><br></div><div>X(const X& ref) { str(ref.str[__i0][__i1][__i2]); }<br></div><div><br></div><div>(None of the above is compiled)</div><div>(If we call emit-llvm, it's translated into a memcpy)</div><div><br></div><div>Anyway, there are a few things missing on this AST, in my opinion:</div><div><br></div><div>1. No VarDecl for __i0, __i1, __i2.</div><div>2. No loop to iterate and copy the array elements (a call to memcpy would be good as well, but I don't expect that clang will generate that).</div><div><br></div><div>Does anyone knows if I can generate the AST with the varDecls and the loop? I found a method on SemaDeclCXX that seems to build a loop, it's called buildSingleCopyAssignRecursively. It's called by buildSingleCopyAssign, that even tries to build a memcpy.</div><div><br></div><div>Am I out of luck and will have to go through all the implicit generated CXXConstructorDecls and build a loop myself or is there an alternative?</div><div><br></div><div>Thank you,</div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><br></div><div>Mikhail Ramalho.</div></div></div>
</div></div>