Skip to content

Conversation

@tbaederr
Copy link
Contributor

@tbaederr tbaederr commented Jan 5, 2026

We were forgetting to pass the volatile-ness along.

We were forgetting to pass the volatile-ness along.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Jan 5, 2026
@llvmbot
Copy link
Member

llvmbot commented Jan 5, 2026

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

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 --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) {}

@tbaederr tbaederr merged commit 787a476 into llvm:main Jan 5, 2026
14 checks passed
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Jan 6, 2026
We were forgetting to pass the volatile-ness along.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants