[clang] Thread Safety Analysis: Add more complex cleanup attribute test (PR #179049)

via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 31 07:57:38 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Marco Elver (melver)

<details>
<summary>Changes</summary>

Test that cleanup attribute is handled correctly in the presence of a unary operator before scope end.

NFC.

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


1 Files Affected:

- (modified) clang/test/Sema/warn-thread-safety-analysis.c (+6) 


``````````diff
diff --git a/clang/test/Sema/warn-thread-safety-analysis.c b/clang/test/Sema/warn-thread-safety-analysis.c
index 53594609e902d..69ec109e1523c 100644
--- a/clang/test/Sema/warn-thread-safety-analysis.c
+++ b/clang/test/Sema/warn-thread-safety-analysis.c
@@ -192,6 +192,12 @@ int main(void) {
     struct Mutex* const __attribute__((unused, cleanup(unlock_scope))) scope = &mu1;
     mutex_exclusive_lock(&mu1);  // With basic alias analysis lock through mu1 also works.
   }
+  {
+    int i = 0;
+    mutex_exclusive_lock(&mu1);
+    struct Mutex* const __attribute__((unused, cleanup(unlock_scope))) scope = &mu1;
+    i++;
+  }
   // Cleanup through cast alias pointer in a for-loop; a variant of this pattern
   // appears in the Linux kernel for generic scoped guard macros.
   for (int i = (mutex_exclusive_lock(foo_.mu_), 0),

``````````

</details>


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


More information about the cfe-commits mailing list