[PATCH] D124038: [clang] Prevent folding of non-const compound expr
serge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 20 05:17:22 PDT 2022
serge-sans-paille added a comment.
Alternatively, the following also works, but it splits the logic into anotherplace, while current patch is at least consistent with existing state
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 498f0d4..233307f 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3352,6 +3352,17 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E,
NoteLValueLocation(Info, Base);
}
+ // In the particular case of CompoundLiteralExpr initialization, check that it is itself
+ // constant.
+ if (Info.InConstantContext)
+ if (const CompoundLiteralExpr *CLE = dyn_cast_or_null<CompoundLiteralExpr>(
+ VD->getAnyInitializer()->IgnoreCasts())) {
+ QualType CLET = CLE->getType().getCanonicalType();
+ if (!CLET.isConstant(Info.Ctx)) {
+ Info.FFDiag(E);
+ }
+ }
+
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124038/new/
https://reviews.llvm.org/D124038
More information about the cfe-commits
mailing list