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

Friedman, Eli via cfe-dev cfe-dev at lists.llvm.org
Tue Dec 13 11:15:06 PST 2016


On 12/13/2016 5:42 AM, Jan Smets via cfe-dev wrote:
> 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?

InitListExpr::getSyntacticForm()

-Eli

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project




More information about the cfe-dev mailing list