[clang] [clang][bytecode] Mark volatile composite locals as such (PR #174407)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 5 06:16:40 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
We were forgetting to pass the volatile-ness along.
---
Full diff: https://github.com/llvm/llvm-project/pull/174407.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+2-1)
- (modified) clang/test/AST/ByteCode/cxx23.cpp (+14)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index f2021ef9456b7..b4449def1c6f0 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4673,7 +4673,8 @@ UnsignedOrNone Compiler<Emitter>::allocateLocal(DeclTy &&Src, QualType Ty,
Descriptor *D = P.createDescriptor(
Src, Ty.getTypePtr(), Descriptor::InlineDescMD, Ty.isConstQualified(),
- IsTemporary, /*IsMutable=*/false, /*IsVolatile=*/false, Init);
+ IsTemporary, /*IsMutable=*/false, /*IsVolatile=*/Ty.isVolatileQualified(),
+ Init);
if (!D)
return std::nullopt;
D->IsConstexprUnknown = IsConstexprUnknown;
diff --git a/clang/test/AST/ByteCode/cxx23.cpp b/clang/test/AST/ByteCode/cxx23.cpp
index 819460628c1b7..2a8b061d7671a 100644
--- a/clang/test/AST/ByteCode/cxx23.cpp
+++ b/clang/test/AST/ByteCode/cxx23.cpp
@@ -450,6 +450,20 @@ namespace VolatileWrites {
// all-note {{in call to}}
}
+namespace VolatileReads {
+ constexpr int test1(bool b) {
+ if (!b)
+ return -1;
+ struct C {
+ int a;
+ };
+ volatile C c{12}; // all-note {{volatile object declared here}}
+ return ((C&)(c)).a; // all-note {{read of volatile object}}
+ }
+ static_assert(test1(true) == 0); // all-error {{not an integral constant expression}} \
+ // all-note {{in call to}}
+}
+
namespace AIEWithIndex0Narrows {
template <class _Tp> struct greater {
constexpr void operator()(_Tp, _Tp) {}
``````````
</details>
https://github.com/llvm/llvm-project/pull/174407
More information about the cfe-commits
mailing list