[cfe-dev] How to disable the generation of TypedefDecl for __builtin_va_list

David Majnemer via cfe-dev cfe-dev at lists.llvm.org
Mon Feb 22 16:37:20 PST 2016


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.

On Mon, Feb 22, 2016 at 4:29 PM, Chengnian Sun <chengniansun at gmail.com>
wrote:

> 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?
>
>
> =======================================
>
> bash-3.2$ cat t1.c
>
> int vprintf(const char * restrict, va_list) __attribute__((__format__
> (__printf__, 1, 0)));
>
> bash-3.2$ clang -Xclang -ast-dump -w -fsyntax-only t1.c
>
> *TranslationUnitDecl* 0x10382dcc0 <<invalid sloc>> <invalid sloc>
>
> |-*TypedefDecl* 0x10382e1c0 <<invalid sloc>> <invalid sloc> implicit*
> __int128_t* '__int128'
>
> |-*TypedefDecl* 0x10382e220 <<invalid sloc>> <invalid sloc> implicit*
> __uint128_t* 'unsigned __int128'
>
> |-*TypedefDecl* 0x10382e5b0 <<invalid sloc>> <invalid sloc> implicit*
> __builtin_va_list* '__va_list_tag [1]'
>
> |-*FunctionDecl* 0x10382e910 <t1.c:1:5> col:5 implicit* vprintf* 'int
> (const char *, __va_list_tag *)' extern
>
> | |-*ParmVarDecl* 0x103871400 <<invalid sloc>> <invalid sloc> 'const char
> *'
>
> | |-*ParmVarDecl* 0x103871460 <<invalid sloc>> <invalid sloc> '__va_list_tag
> *'
>
> | `-*FormatAttr* 0x1038714d0 <col:5> Implicit printf 1 0
>
> `-*FunctionDecl* 0x103871520 prev 0x10382e910 <col:1, col:90> col:5*
> vprintf* 'int (const char *restrict, int)'
>
>   |-*ParmVarDecl* 0x10382e640 <col:13, col:24> col:34 'const char
> *restrict'
>
>   |-*ParmVarDecl* 0x10382e6b0 <col:36> col:36* va_list* 'int'
>
>   `-*FormatAttr* 0x1038715e0 <col:60, col:88> printf 1 0
>
> On Mon, Feb 22, 2016 at 4:01 PM, David Majnemer <david.majnemer at gmail.com>
> wrote:
>
>>
>>
>> On Mon, Feb 22, 2016 at 3:46 PM, Chengnian Sun via cfe-dev <
>> cfe-dev at lists.llvm.org> wrote:
>>
>>> I want to randomly remove the variable declaration "a" or "b" from the
>>> source file. There are two ways to do this.
>>>     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.
>>>
>>
>> Why not skip things marked as implicit (clang::Decl::isImplicit) ?
>>
>>
>>>     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.
>>>
>>> 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?
>>>
>>> Thank you. Any advice is appreciated.
>>>
>>>
>>>
>>> On Mon, Feb 22, 2016 at 3:30 PM, Meador Inge <meadori at gmail.com> wrote:
>>>
>>>> On Mon, Feb 22, 2016 at 11:15 AM, Chengnian Sun via cfe-dev <
>>>> cfe-dev at lists.llvm.org> wrote:
>>>>
>>>> Hi,
>>>>>
>>>>> 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?
>>>>>
>>>>
>>>> Not that I know of.  What problem are you trying to solve by disabling
>>>> them?
>>>>
>>>> -- Meador
>>>>
>>>
>>>
>>>
>>> --
>>> Best Regards.
>>>
>>> Chengnian SUN.
>>>
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>>
>>>
>>
>
>
> --
> Best Regards.
>
> Chengnian SUN.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160222/c09f3fea/attachment.html>


More information about the cfe-dev mailing list