[clang] [clang][CodeGen] Emit file-scope compound literals in a constant context (PR #221390)
Akash Manna via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 8 21:12:03 PDT 2026
akash-manna-sky wrote:
> We really shouldn't have an InConstantContext bit in CodeGen at all.
>
> Anything that's actually a constant context should be evaluated by Sema, and the result of that evaluation should be stored in a ConstantExpr. Anything else is asking for trouble: constant evaluation has significantly different rules in constant contexts, and can have weird side-effects like triggering template instantiation.
Makes sense... Sema already wraps each element of a file-scope compound literal in a `ConstantExpr`, it just never filled in the value. I've moved the fix there: the element is evaluated once in Sema and the result stored in that wrapper, so CodeGen emits the stored value and no longer re-evaluates it. I dropped The CodeGen and CIR changes. This also makes the evaluator and CodeGen agree on the literal's contents, which resolves the FIXME in `static-compound-literals-reeval.cpp`.
https://github.com/llvm/llvm-project/pull/221390
More information about the cfe-commits
mailing list