[PATCH] D52888: Thread safety analysis: Handle conditional expression in getTrylockCallExpr

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 4 10:10:31 PDT 2018


aaron.ballman added inline comments.


================
Comment at: lib/Analysis/ThreadSafety.cpp:1445
+      if (!TCond && FCond) {
+        Negate = !Negate;
+        return getTrylockCallExpr(COP->getCond(), C, Negate);
----------------
Rather than do an assignment here, why not just pass `!Negate` directly below, since you're returning?


================
Comment at: test/SemaCXX/warn-thread-safety-analysis.cpp:1879-1880
+  void foo13() {
+    if (mu.TryLock() ? 1 : 0)
+      mu.Unlock();
+  }
----------------
Can you add a test that shows we get it right even if the user does something less than practical, like:
```
if (mu.TryLock() ? mu.TryLock() : false); // Warn about double lock
if (mu.TryLock() ? mu.Unlock(), 1 : 0)
  mu.Unlock(); // Warn about unlocking unheld lock
if (mu.TryLock() ? 1 : mu.Unlock(), 0)
  mu.Unlock(); // Warn about unlocking an unheld lock
if (mu.TryLock() ? (true ? mu.TryLock() : false) : false); // Warn about double lock
```


Repository:
  rC Clang

https://reviews.llvm.org/D52888





More information about the cfe-commits mailing list