[cfe-dev] Reuse of expressions in synthesized functions.
Pavel Labath
labath at google.com
Wed Aug 14 04:52:06 PDT 2013
On 14 August 2013 12:47, Abramo Bagnara <abramo.bagnara at bugseng.com> wrote:
> Il 14/08/2013 12:33, Pavel Labath ha scritto:
> >
> >
> >> Could you please elaborate on that? I'm not sure what you mean by
> > repeated initializers. Do you know of a situation where an AST node can
> > be present in the tree twice?
> >
> $ cat p.c
> void f() {
> int a[10] = {[1 ... 8] = 2};
> }
> $ clang -cc1 -ast-dump p.c
> TranslationUnitDecl 0x54ae6e0 <<invalid sloc>>
> |-TypedefDecl 0x54aebc0 <<invalid sloc>> __int128_t '__int128'
> |-TypedefDecl 0x54aec20 <<invalid sloc>> __uint128_t 'unsigned __int128'
> |-TypedefDecl 0x54aef70 <<invalid sloc>> __builtin_va_list
> '__va_list_tag [1]'
> `-FunctionDecl 0x54af010 <p.c:1:1, line:3:1> f 'void ()'
> `-CompoundStmt 0x54af330 <line:1:10, line:3:1>
> `-DeclStmt 0x54af318 <line:2:3, col:30>
> `-VarDecl 0x54af130 <col:3, col:29> a 'int [10]'
> `-InitListExpr 0x54af280 <col:15, col:29> 'int [10]'
> |-ImplicitValueInitExpr 0x54af308 <<invalid sloc>> 'int'
> |-IntegerLiteral 0x54af1c8 <col:28> 'int' 2
> |-IntegerLiteral 0x54af1c8 <col:28> 'int' 2
> |-IntegerLiteral 0x54af1c8 <col:28> 'int' 2
> |-IntegerLiteral 0x54af1c8 <col:28> 'int' 2
> |-IntegerLiteral 0x54af1c8 <col:28> 'int' 2
> |-IntegerLiteral 0x54af1c8 <col:28> 'int' 2
> |-IntegerLiteral 0x54af1c8 <col:28> 'int' 2
> `-IntegerLiteral 0x54af1c8 <col:28> 'int' 2
>
>
Wow.. I didn't even know such syntax exists. This is a nice example, thanks.
Right now, the static analyzer seems to get this code right (which is quite
surprising, since even the compiler does not support this right now), but
as soon as I replace 2 by something more complicated (a function call), it
stops for some reason, which I didn't investigate yet. But in any case, the
analyzers approach to this is wrong, as it tries to evaluate the expression
multiple times, which, I guess, it shouldn't (gcc doesn't).
Since the compiler doesn't support this yet, I guess this is not such an
important issue yet, but it's definitely a thing to keep an eye on.
Soon or later I personally hope that such node replication will
> disappear, but currently we have it and I don't know if there is the
> intention to get rid of it.
>
>
I think I would also prefer a different AST representation of the above
code, because the current one gives the impression that the RHS expression
is to be evaluated multiple times.
cheers,
pavel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130814/cb03f449/attachment.html>
More information about the cfe-dev
mailing list