[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


================
@@ -457,6 +457,9 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *E) {
     if (!Ctx.getLangOpts().HLSL && E->getType()->isConstantMatrixType())
       return false;
 
+    llvm::SaveAndRestore DirectRead(DirectlyReadCLE,
+                                    getDirectlyReadCompoundLiteral(SubExpr));
+
----------------
tbaederr wrote:

Instead of doing this, why would

```c++
    if (const auto *CLE = getDirectlyReadCompoundLiteral(SubExpr)) {
      return this->visit(CLE->getInitializer());
    }
```
directly after the volatile check below not work?

https://github.com/llvm/llvm-project/pull/241126


More information about the cfe-commits mailing list