Prevent folding of integer constant expressions in AST

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Prevent folding of integer constant expressions in AST

Fangrui Song via cfe-dev
Hi,

I am using ParseAST to traverse the AST provided by clang, using a ConstDeclVisitor, a ConstStmtVisitor and a TypeVisitor.
My problem now is that for expressions such as

char main_foo[sizeof(int) == sizeof(char) ? 5 : 8];

I cannot access the expression for the array size, from VisitConstantArrayType(). I can only access the folded numerical value, in this case 8.
Is there a way to access the unfolded expression? Or disable folding of integer constant expressions all together?
I am using clang 6.0.

Thank you and best regards,
Benedikt
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Prevent folding of integer constant expressions in AST

Fangrui Song via cfe-dev
Hi,

I wanted to bump this question. Maybe someone has an idea how to solve this.

Thank you and best regards,
Benedikt

________________________________________
From: Benedikt Lukas Huber <[hidden email]>
Sent: Thursday, January 16, 2020 5:21 PM
To: via cfe-dev
Subject: Prevent folding of integer constant expressions in AST

Hi,

I am using ParseAST to traverse the AST provided by clang, using a ConstDeclVisitor, a ConstStmtVisitor and a TypeVisitor.
My problem now is that for expressions such as

char main_foo[sizeof(int) == sizeof(char) ? 5 : 8];

I cannot access the expression for the array size, from VisitConstantArrayType(). I can only access the folded numerical value, in this case 8.
Is there a way to access the unfolded expression? Or disable folding of integer constant expressions all together?
I am using clang 6.0.

Thank you and best regards,
Benedikt
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Prevent folding of integer constant expressions in AST

Fangrui Song via cfe-dev
I have already sent the following on the list, may this helps.
Assume that you have the desired `VarDecl` `D` of `main_foo`:
```
const Expr *SizeExpr = nullptr;
if (const TypeSourceInfo *TSI = D->getTypeSourceInfo())
  if (const auto ATL = TSI->getTypeLoc().getAs<ArrayTypeLoc>())
    SizeExpr = ATL.getSizeExpr();
```

On Mon, Mar 30, 2020 at 1:24 PM Benedikt Lukas Huber via cfe-dev <[hidden email]> wrote:
Hi,

I wanted to bump this question. Maybe someone has an idea how to solve this.

Thank you and best regards,
Benedikt

________________________________________
From: Benedikt Lukas Huber <[hidden email]>
Sent: Thursday, January 16, 2020 5:21 PM
To: via cfe-dev
Subject: Prevent folding of integer constant expressions in AST

Hi,

I am using ParseAST to traverse the AST provided by clang, using a ConstDeclVisitor, a ConstStmtVisitor and a TypeVisitor.
My problem now is that for expressions such as

char main_foo[sizeof(int) == sizeof(char) ? 5 : 8];

I cannot access the expression for the array size, from VisitConstantArrayType(). I can only access the folded numerical value, in this case 8.
Is there a way to access the unfolded expression? Or disable folding of integer constant expressions all together?
I am using clang 6.0.

Thank you and best regards,
Benedikt
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Prevent folding of integer constant expressions in AST

Fangrui Song via cfe-dev
Thank you, that seems to be what I need.

Best regards,
Benedikt

________________________________________
From: Csaba Dabis <[hidden email]>
Sent: Monday, March 30, 2020 1:29 PM
To: Benedikt Lukas Huber
Cc: via cfe-dev
Subject: Re: [cfe-dev] Prevent folding of integer constant expressions in AST

I have already sent the following on the list, may this helps.
Assume that you have the desired `VarDecl` `D` of `main_foo`:
```
const Expr *SizeExpr = nullptr;
if (const TypeSourceInfo *TSI = D->getTypeSourceInfo())
  if (const auto ATL = TSI->getTypeLoc().getAs<ArrayTypeLoc>())
    SizeExpr = ATL.getSizeExpr();
```

On Mon, Mar 30, 2020 at 1:24 PM Benedikt Lukas Huber via cfe-dev <[hidden email]<mailto:[hidden email]>> wrote:
Hi,

I wanted to bump this question. Maybe someone has an idea how to solve this.

Thank you and best regards,
Benedikt

________________________________________
From: Benedikt Lukas Huber <[hidden email]>
Sent: Thursday, January 16, 2020 5:21 PM
To: via cfe-dev
Subject: Prevent folding of integer constant expressions in AST

Hi,

I am using ParseAST to traverse the AST provided by clang, using a ConstDeclVisitor, a ConstStmtVisitor and a TypeVisitor.
My problem now is that for expressions such as

char main_foo[sizeof(int) == sizeof(char) ? 5 : 8];

I cannot access the expression for the array size, from VisitConstantArrayType(). I can only access the folded numerical value, in this case 8.
Is there a way to access the unfolded expression? Or disable folding of integer constant expressions all together?
I am using clang 6.0.

Thank you and best regards,
Benedikt
_______________________________________________
cfe-dev mailing list
[hidden email]<mailto:[hidden email]>
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev