llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Marco Elver (melver)

<details>
<summary>Changes</summary>

Alias reassignment through pointer-to-pointer (nor ptr-to-ptr-to-ptr...) does 
not invalidate an alias for now. While this may result in either false 
positives or negatives, there's rarely a good reason not to just do direct 
assignment within the same scope.

For the time being, we retain this as a deliberate "escape hatch": 
specifically, this may be used to help the alias analysis to "see through" 
complex helper macros that e.g. read a value (such as a pointer) via inline 
assembly or other opaque helpers [1].

Add a test to document the current behaviour.

NFC.

[1] https://lore.kernel.org/all/20260130132951.2714396-1-elver@<!-- 
-->google.com/

---
Full diff: https://github.com/llvm/llvm-project/pull/179028.diff


1 Files Affected:

- (modified) clang/test/SemaCXX/warn-thread-safety-analysis.cpp (+21) 


``````````diff
diff --git a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp 
b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
index d9efa745b7d59..466135a1d9cef 100644
--- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -7498,6 +7498,27 @@ void testReassignment() {
   ptr->mu.Unlock();
 }
 
+// Alias reassignment through pointer-to-pointer (nor ptr-to-ptr-to-ptr...) 
does
+// not invalidate aliases for now.
+//
+// While this may result in either false positives or negatives, there's rarely
+// a good reason not to just do direct assignment within the same scope. For 
the
+// time being, we retain this as a deliberate "escape hatch": specifically, 
this
+// may be used to help the alias analysis to "see through" complex helper 
macros
+// that e.g. read a value (such as a pointer) via inline assembly or other
+// opaque helpers.
+void testReassignmentPointerToAlias(Foo *f) {
+  Mutex *mu = &f->mu;
+  // Escape hatch.
+  Mutex **mu_p = &mu;
+  Mutex *actual_mu = [&] { /* ... */ return mu; }();
+  *mu_p = actual_mu;
+
+  mu->Lock();
+  f->data = 42;
+  mu->Unlock();
+}
+
 // Nested field access through pointer
 struct Container {
   Foo foo;

``````````

</details>


https://github.com/llvm/llvm-project/pull/179028
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to