<div dir="ltr">You are missing a typdef which would provide the definition of va_list. Because va_list is not defined, we parse 'va_list' in the function parameter as a parameter name. Via the C rules, we implicitly give it type int.<br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 22, 2016 at 4:29 PM, Chengnian Sun <span dir="ltr"><<a href="mailto:chengniansun@gmail.com" target="_blank">chengniansun@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thank you for letting me know this API. However, I have another problem: when I have the forward declaration of vprintf (produced by the preprocessor), the clang AST will assign the type int to va_list. Is it a correct way to use prettyprint to dump code from AST?<div><br></div><div><br><div>=======================================</div><div>
<p><span>bash-3.2$ cat t1.c </span></p>
<p><span>int vprintf(const char * restrict, va_list) __attribute__((__format__ (__printf__, 1, 0)));</span></p>
<p><span>bash-3.2$ clang -Xclang -ast-dump -w -fsyntax-only t1.c</span></p>
<p><span><b>TranslationUnitDecl</b></span><span> 0x10382dcc0</span><span> <</span><span><invalid sloc></span><span>> </span><span><invalid sloc></span></p>
<p><span>|-</span><span><b>TypedefDecl</b></span><span> 0x10382e1c0</span><span> <</span><span><invalid sloc></span><span>> </span><span><invalid sloc></span><span> implicit</span><span><b> __int128_t</b></span><span> </span><span>'__int128'</span></p>
<p><span>|-</span><span><b>TypedefDecl</b></span><span> 0x10382e220</span><span> <</span><span><invalid sloc></span><span>> </span><span><invalid sloc></span><span> implicit</span><span><b> __uint128_t</b></span><span> </span><span>'unsigned __int128'</span></p>
<p><span>|-</span><span><b>TypedefDecl</b></span><span> 0x10382e5b0</span><span> <</span><span><invalid sloc></span><span>> </span><span><invalid sloc></span><span> implicit</span><span><b> __builtin_va_list</b></span><span> </span><span>'__va_list_tag [1]'</span></p>
<p><span>|-</span><span><b>FunctionDecl</b></span><span> 0x10382e910</span><span> <</span><span>t1.c:1:5</span><span>> </span><span>col:5</span><span> implicit</span><span><b> vprintf</b></span><span> </span><span>'int (const char *, __va_list_tag *)'</span><span> extern</span></p>
<p><span>| |-</span><span><b>ParmVarDecl</b></span><span> 0x103871400</span><span> <</span><span><invalid sloc></span><span>> </span><span><invalid sloc></span><span> </span><span>'const char *'</span></p>
<p><span>| |-</span><span><b>ParmVarDecl</b></span><span> 0x103871460</span><span> <</span><span><invalid sloc></span><span>> </span><span><invalid sloc></span><span> </span><span>'__va_list_tag *'</span></p>
<p><span>| `-<b>FormatAttr</b></span><span> 0x1038714d0</span><span> <</span><span>col:5</span><span>> Implicit printf 1 0</span></p>
<p><span>`-</span><span><b>FunctionDecl</b></span><span> 0x103871520</span><span> prev 0x10382e910 <</span><span>col:1</span><span>, </span><span>col:90</span><span>> </span><span>col:5</span><span><b> vprintf</b></span><span> </span><span>'int (const char *restrict, int)'</span></p>
<p><span> |-</span><span><b>ParmVarDecl</b></span><span> 0x10382e640</span><span> <</span><span>col:13</span><span>, </span><span>col:24</span><span>> </span><span>col:34</span><span> </span><span>'const char *restrict'</span></p>
<p><span> |-</span><span><b>ParmVarDecl</b></span><span> 0x10382e6b0</span><span> <</span><span>col:36</span><span>> </span><span>col:36</span><span><b> va_list</b></span><span> </span><span>'int'</span></p>
<p><span> `-<b>FormatAttr</b></span><span> 0x1038715e0</span><span> <</span><span>col:60</span><span>, </span><span>col:88</span><span>> printf 1 0</span></p></div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 22, 2016 at 4:01 PM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Mon, Feb 22, 2016 at 3:46 PM, Chengnian Sun via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">I want to randomly remove the variable declaration "a" or "b" from the source file. There are two ways to do this. <div> 1) I can pretty print the VarDecl of "a" and "b". However, these three builtin typedefs mentioned above make the modified source file not compilable, as the _builtin_va_list is not defined. </div></div></blockquote><div><br></div></span><div>Why not skip things marked as implicit (clang::Decl::isImplicit) ?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span><div dir="ltr"><div> 2) I can use rewriter to change the source file. However, as both "a" and "b" are declared in one statement, removing either of them makes the deletion complex. </div><div><br></div><div>I think another way to do this is to separate the statement "int a, b;" into "int a; int b". Any existing functionality in clang to do this?</div><div><br></div><div>Thank you. Any advice is appreciated. </div><div><br></div><div> </div></div><div class="gmail_extra"><div><div><br><div class="gmail_quote">On Mon, Feb 22, 2016 at 3:30 PM, Meador Inge <span dir="ltr"><<a href="mailto:meadori@gmail.com" target="_blank">meadori@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><span><div class="gmail_quote">On Mon, Feb 22, 2016 at 11:15 AM, Chengnian Sun via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:</div></span><div class="gmail_quote"><span><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>Hi, </div><div><br></div><div>I found out that for the following code (only containing two variable declarations), clang will generate three internal typedef declarations. Is there any way to disable the generation of the three typedef?</div></div></blockquote><div><br></div></span><div>Not that I know of. What problem are you trying to solve by disabling them?</div><span><font color="#888888"><div><br></div><div>-- Meador</div></font></span></div>
</div></div>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span>-- <br><div>Best Regards.<br><br>Chengnian SUN.</div>
</span></div>
<br></span>_______________________________________________<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="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Best Regards.<br><br>Chengnian SUN.</div>
</div>
</div></div></blockquote></div><br></div></div>