llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.78k stars 11.9k forks source link

[clang][ThreadSafety] Skip past implicit cast in `translateAttrExpr` #92277

Closed antoniofrighetto closed 5 months ago

antoniofrighetto commented 5 months ago

Ignore ImplicitCastExpr when building AttrExp for capability attribute diagnostics.

Fixes: https://github.com/llvm/llvm-project/issues/92118.

llvmbot commented 5 months ago

@llvm/pr-subscribers-clang-analysis

@llvm/pr-subscribers-clang

Author: Antonio Frighetto (antoniofrighetto)

Changes Ignore `ImplicitCastExpr` when building `AttrExp` for capability attribute diagnostics. Fixes: https://github.com/llvm/llvm-project/issues/92118. --- Full diff: https://github.com/llvm/llvm-project/pull/92277.diff 2 Files Affected: - (modified) clang/lib/Analysis/ThreadSafetyCommon.cpp (+1-1) - (modified) clang/test/SemaCXX/warn-thread-safety-analysis.cpp (+1-1) ``````````diff diff --git a/clang/lib/Analysis/ThreadSafetyCommon.cpp b/clang/lib/Analysis/ThreadSafetyCommon.cpp index 33f1f466df244..71de84f698e26 100644 --- a/clang/lib/Analysis/ThreadSafetyCommon.cpp +++ b/clang/lib/Analysis/ThreadSafetyCommon.cpp @@ -197,7 +197,7 @@ CapabilityExpr SExprBuilder::translateAttrExpr(const Expr *AttrExp, else if (const auto *UO = dyn_cast(AttrExp)) { if (UO->getOpcode() == UO_LNot) { Neg = true; - AttrExp = UO->getSubExpr(); + AttrExp = UO->getSubExpr()->IgnoreImplicit(); } } diff --git a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp index dfb966d3b5902..749d9e135d941 100644 --- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp +++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp @@ -5341,7 +5341,7 @@ void dispatch_log(const char *msg) __attribute__((requires_capability(!FlightCon void dispatch_log2(const char *msg) __attribute__((requires_capability(Logger))) {} void flight_control_entry(void) __attribute__((requires_capability(FlightControl))) { - dispatch_log("wrong"); /* expected-warning {{cannot call function 'dispatch_log' while mutex 'FlightControl' is held}} */ + dispatch_log("wrong"); /* expected-warning {{cannot call function 'dispatch_log' while role 'FlightControl' is held}} */ dispatch_log2("also wrong"); /* expected-warning {{calling function 'dispatch_log2' requires holding role 'Logger' exclusively}} */ } ``````````