[cfe-dev] EnumConstant in designated initializers are discarded from AST

Jan Smets via cfe-dev cfe-dev at lists.llvm.org
Tue Dec 13 05:42:03 PST 2016


Hi

I have following sample code

typedef enum
{
    A,
    B,
    C,
} eABC;

typedef struct X {
    int member1;
    int member2;
    int member3;
} tX;

tX var [] =
{
    [A] { 0, 0, 0 },
    [B] { 1, 1, 1 },
    [C] { 2, 2, 2 },
};

Here enum member names are used in the initializer expression.
Duming the resulting AST shows that these have been lowered to
constant integers and that the Enum information is lost.

I get :

`-VarDecl 0x7397d28 <line:15:1, line:20:1> line:15:4 var 'tX [3]' cinit
  `-InitListExpr 0x7398198 <line:16:1, line:20:1> 'tX [3]'
    |-InitListExpr 0x73981e0 <line:17:9, col:19> 'tX':'struct X'
    | |-IntegerLiteral 0x7397df0 <col:11> 'int' 0
    | |-IntegerLiteral 0x7397e10 <col:14> 'int' 0
    | `-IntegerLiteral 0x7397e30 <col:17> 'int' 0

But I would expect something as :

InitListExpr 0x6fd6a00 'tX [3]'
|-DesignatedInitExpr 0x6fd6768 'void'
| |-InitListExpr 0x6fd6710 'tX':'struct X'
| | |-IntegerLiteral 0x6fd66b0 'int' 0
| | |-IntegerLiteral 0x6fd66d0 'int' 0
| | `-IntegerLiteral 0x6fd66f0 'int' 0
| `-DeclRefExpr 0x6fd6688 'int' EnumConstant 0x6fd6120 'A' 'int'

This information is lost somewhere down below
InitializationSequence::Perform()  (case SK_ListInitialization)

Is there a way to get back the original initializer expression?

Thanks
Jan

-- 
Smets Jan
jan at smets.cx



More information about the cfe-dev mailing list