[clang] b6d6af9 - Thread Safety Analysis: Add test for alias reassignment through pointer-to-pointer (#179028)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 31 04:36:11 PST 2026
Author: Marco Elver
Date: 2026-01-31T13:36:05+01:00
New Revision: b6d6af98feb6850e6402d4bbee21cab970d74b4f
URL: https://github.com/llvm/llvm-project/commit/b6d6af98feb6850e6402d4bbee21cab970d74b4f
DIFF: https://github.com/llvm/llvm-project/commit/b6d6af98feb6850e6402d4bbee21cab970d74b4f.diff
LOG: Thread Safety Analysis: Add test for alias reassignment through pointer-to-pointer (#179028)
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/
Added:
Modified:
clang/test/SemaCXX/warn-thread-safety-analysis.cpp
Removed:
################################################################################
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 = μ
+ 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;
More information about the cfe-commits
mailing list