[clang] [clang] Don't fold reads of modifiable file-scope compound literals (PR #241126)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 23 01:43:05 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)
----------------
tbaederr wrote:
```suggestion
S.FFDiag(S.Current->getSource(OpPC),
diag::note_invalid_subexpr_in_const_expr, 1)
```
https://github.com/llvm/llvm-project/pull/241126
More information about the cfe-commits
mailing list