Details
Diff Detail
- Repository
- rC Clang
Event Timeline
This looks reasonable to fix the problem at hand, but would it handle nested structures too?
struct s1 { short f1; // "int f1" is fine. }; struct s2 { struct s1 f2; int x; }; struct s3 { struct s2 f3; int x; }; struct s2 x1 = {0}; struct s3 x2 = {0};
produces this AST (clang-check -ast-dump x.c --):
|-VarDecl 0x55e7bbc60390 <line:13:1, col:18> col:11 x1 'struct s2':'struct s2' cinit | `-InitListExpr 0x55e7bbc60498 <col:16, col:18> 'struct s2':'struct s2' | |-InitListExpr 0x55e7bbc604e8 <col:17> 'struct s1':'struct s1' | | `-ImplicitCastExpr 0x55e7bbc60530 <col:17> 'short' <IntegralCast> | | `-IntegerLiteral 0x55e7bbc60430 <col:17> 'int' 0 | `-ImplicitValueInitExpr 0x55e7bbc60548 <<invalid sloc>> 'int' |-VarDecl 0x55e7bbc605b0 <line:14:1, col:18> col:11 x2 'struct s3':'struct s3' cinit | `-InitListExpr 0x55e7bbc60678 <col:16, col:18> 'struct s3':'struct s3' | |-InitListExpr 0x55e7bbc606c8 <col:17> 'struct s2':'struct s2' | | |-InitListExpr 0x55e7bbc60718 <col:17> 'struct s1':'struct s1' | | | `-ImplicitCastExpr 0x55e7bbc60760 <col:17> 'short' <IntegralCast> | | | `-IntegerLiteral 0x55e7bbc60610 <col:17> 'int' 0 | | `-ImplicitValueInitExpr 0x55e7bbc60778 <<invalid sloc>> 'int' | `-ImplicitValueInitExpr 0x55e7bbc60788 <<invalid sloc>> 'int'
Thanks for reviewing! I don't have commit access, so I can't commit this patch myself.
clang/lib/AST/Expr.cpp | ||
---|---|---|
2092–2100 | Use Expr::IgnoreImplicit rather than checking for an ImplicitCastExpr here: const IntegerLiteral *Lit = dyn_cast<IntegerLiteral>(getInit(0)->IgnoreImplicit()); |
Switched to using Expr::IgnoreImplicit() instead of manually checking for an ImplicitCastExpr.
@rsmith The latest patch version has addressed your feedback, can you confirm that this is ready to be merged?
@al3xtjames I was about to commit this but noticed that some others check whether getInit(0) is NULL or not before proceeding. Should that be done here as well? If not, why?
See for example "Harden InitListExpr::isStringLiteralInit() against getInit() returning null." in
https://github.com/llvm/llvm-project/commit/256bd96d1c2464b0f0ecb482ca52075a3158f6a1#diff-dac09655ff6a54658c320a28a6ea297c
and InitListExpr::isTransparent in
https://github.com/llvm/llvm-project/commit/122f88d481971b68d05ba12395c3b73ab4b31ab3#diff-dac09655ff6a54658c320a28a6ea297c
Use Expr::IgnoreImplicit rather than checking for an ImplicitCastExpr here: