[clang] [clang] Don't fold reads of modifiable file-scope compound literals (PR #241126)
Prajwal KP via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 23 20:30:32 PST 2026
================
@@ -930,6 +930,22 @@ bool CheckLocalLoad(InterpState &S, CodePtr OpPC, const Block *B) {
return true;
}
+/// A compound literal with static storage duration can be modified unless it
+/// is const-qualified, so its value is not known.
+static bool CheckCompoundLiteral(InterpState &S, CodePtr OpPC, const Block *B) {
+ const auto *CLE =
+ dyn_cast_if_present<CompoundLiteralExpr>(B->getDescriptor()->asExpr());
+ if (!CLE || !CLE->hasStaticStorage() ||
+ CLE->getType().isConstant(S.getASTContext()))
+ return true;
+
+ S.FFDiag(S.Current->getLocation(OpPC),
+ diag::note_invalid_subexpr_in_const_expr)
----------------
Prajwal-kp-18 wrote:
Done
https://github.com/llvm/llvm-project/pull/241126
More information about the cfe-commits
mailing list