[clang] Thread Safety Analysis: Support warning on taking address of guarded variables (PR #123063)
Aaron Puchert via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 11 07:59:30 PST 2025
================
@@ -1983,11 +1983,21 @@ class ThreadSafetyReporter : public clang::threadSafety::ThreadSafetyHandler {
void handleNoMutexHeld(const NamedDecl *D, ProtectedOperationKind POK,
AccessKind AK, SourceLocation Loc) override {
- assert((POK == POK_VarAccess || POK == POK_VarDereference) &&
- "Only works for variables");
- unsigned DiagID = POK == POK_VarAccess?
- diag::warn_variable_requires_any_lock:
- diag::warn_var_deref_requires_any_lock;
+ unsigned DiagID = 0;
+ switch (POK) {
+ case POK_VarAccess:
+ DiagID = diag::warn_variable_requires_any_lock;
+ break;
+ case POK_VarDereference:
+ DiagID = diag::warn_var_deref_requires_any_lock;
+ break;
+ case POK_AddressOf:
+ DiagID = diag::warn_addressof_requires_any_lock;
+ break;
+ default:
+ assert(false && "Only works for variables");
+ break;
----------------
aaronpuchert wrote:
Wouldn't `llvm_unreachable` be the standard idiom here?
https://github.com/llvm/llvm-project/pull/123063
More information about the cfe-commits
mailing list