[clang] Effect analysis: correctly detect `(f ? a : b)` as nonblocking when a and b are (PR #111224)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 4 18:36:15 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Doug Wyatt (dougsonos)
<details>
<summary>Changes</summary>
Fix: Effect analysis: correctly detect `(f ? a : b)` as nonblocking when a and b are
---
Full diff: https://github.com/llvm/llvm-project/pull/111224.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaFunctionEffects.cpp (+5-6)
- (modified) clang/test/Sema/attr-nonblocking-constraints.cpp (+10)
``````````diff
diff --git a/clang/lib/Sema/SemaFunctionEffects.cpp b/clang/lib/Sema/SemaFunctionEffects.cpp
index 0fb18d207a50ba..0ac5de29f66aa7 100644
--- a/clang/lib/Sema/SemaFunctionEffects.cpp
+++ b/clang/lib/Sema/SemaFunctionEffects.cpp
@@ -1048,15 +1048,14 @@ class Analyzer {
}
void checkIndirectCall(CallExpr *Call, QualType CalleeType) {
- auto *FPT =
- CalleeType->getAs<FunctionProtoType>(); // Null if FunctionType.
FunctionEffectKindSet CalleeEffects;
- if (FPT)
- CalleeEffects.insert(FPT->getFunctionEffects());
+ if (FunctionEffectsRef Effects = FunctionEffectsRef::get(CalleeType);
+ !Effects.empty())
+ CalleeEffects.insert(Effects);
auto Check1Effect = [&](FunctionEffect Effect, bool Inferring) {
- if (FPT == nullptr || Effect.shouldDiagnoseFunctionCall(
- /*direct=*/false, CalleeEffects))
+ if (Effect.shouldDiagnoseFunctionCall(
+ /*direct=*/false, CalleeEffects))
addViolation(Inferring, Effect, ViolationID::CallsExprWithoutEffect,
Call->getBeginLoc());
};
diff --git a/clang/test/Sema/attr-nonblocking-constraints.cpp b/clang/test/Sema/attr-nonblocking-constraints.cpp
index c694860069c960..ff8caf0e573403 100644
--- a/clang/test/Sema/attr-nonblocking-constraints.cpp
+++ b/clang/test/Sema/attr-nonblocking-constraints.cpp
@@ -156,6 +156,16 @@ void nb10(
static_cast<void (*)()>(fp1)(); // expected-warning {{function with 'nonblocking' attribute must not call non-'nonblocking' expression}}
}
+// Expression involving indirection
+int nb10a() [[clang::nonblocking]];
+int nb10b() [[clang::nonblocking]];
+
+int nb10c(bool x) [[clang::nonblocking]]
+{
+ // Warns that the expression is not nonblocking.
+ return (x ? nb10a : nb10b)();
+}
+
// Interactions with nonblocking(false)
void nb11_no_inference_1() [[clang::nonblocking(false)]] // expected-note {{function does not permit inference of 'nonblocking'}}
{
``````````
</details>
https://github.com/llvm/llvm-project/pull/111224
More information about the cfe-commits
mailing list