[clang] Add check in SemaChecking for multiple unsequenced volatile accesses (PR #180955)

via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 14 07:36:02 PST 2026


================
@@ -815,3 +815,29 @@ void test_var() {
 }
 
 } // namespace templates
+
+namespace muliple_read_volatile {
+  volatile int v1;
+  
+  void PositiveTest(){
+    int x = 0;
+    int y = 0;
+    x = v1 + v1;        // cxx11-warning {{unsequenced accesses to volatile qualified 'v1'}}
+                        // cxx17-warning at -1 {{unsequenced accesses to volatile qualified 'v1'}}
+    v1 = v1 * v1;       // cxx11-warning {{unsequenced accesses to volatile qualified 'v1'}}
+                        // cxx17-warning at -1 {{unsequenced accesses to volatile qualified 'v1'}}
+    x = v1 + (y++, v1); // cxx11-warning {{unsequenced accesses to volatile qualified 'v1'}}
+                        // cxx17-warning at -1 {{unsequenced accesses to volatile qualified 'v1'}}
+    x = v1 + v1 || y;   // cxx11-warning {{unsequenced accesses to volatile qualified 'v1'}}
+                        // cxx17-warning at -1 {{unsequenced accesses to volatile qualified 'v1'}}
+  }
+  
+  void NegativeTest(){
+    int x = 0;
+    int y = 0;
+    x = v1 + y;   // no-warning
+    v1 = v1 * y;  // no-warning
+    x = (v1, v1); // no-warning
+    x = v1 || v1; // no-warning
+  }
+} // namespace muliple_read_volatile
----------------
Seraphimt wrote:

@Fznamznon Thank you! I messed two branch with different message and that's why SemaCXX/warn-unsequenced.cpp check fails =_=  I fix it.
Rest failed tests related to builtin. As far I understand, builtin use shouldn't trigger warning because is't funcall.
But unseq checker does not take into account now, example: [https://godbolt.org/z/Y7nsGPnPr]
So I suppose in failed builtin tests turn off unsequenced check.

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


More information about the cfe-commits mailing list