[clang] [clang][Sema] Propagate `volatile` during derived-to-base conversion (PR #127824)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 20 06:08:40 PST 2025


================
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -ast-dump %s | FileCheck %s
+
+// Ensure volatile is preserved during derived-to-base conversion. 
+namespace PR127683 {
+
+struct Base {
+  int Val;
+};
+
+struct Derived : Base { };
+
+volatile Derived Obj;
+
+// CHECK:      `-FunctionDecl {{.*}} test_volatile_store 'void ()'
+// CHECK-NEXT:   `-CompoundStmt {{.*}}
+// CHECK-NEXT:     `-BinaryOperator {{.*}} 'volatile int' lvalue '='
+// CHECK-NEXT:       |-MemberExpr {{.*}} 'volatile int' lvalue .Val
+// CHECK-NEXT:       | `-ImplicitCastExpr {{.*}} 'volatile PR127683::Base' lvalue <UncheckedDerivedToBase (Base)>
+void test_volatile_store() {
+  Obj.Val = 0;
+}
----------------
AaronBallman wrote:

I'd appreciate a test for volatile read as well as volatile store.

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


More information about the cfe-commits mailing list