Author: Doug Wyatt Date: 2024-10-08T10:20:05+02:00 New Revision: 4d218caa7716743061e8d34d61b2181c94b16440
URL: https://github.com/llvm/llvm-project/commit/4d218caa7716743061e8d34d61b2181c94b16440 DIFF: https://github.com/llvm/llvm-project/commit/4d218caa7716743061e8d34d61b2181c94b16440.diff LOG: [Clang] [Sema] Effects: Correctly detect `(x ? a : b)` as nonblocking when a and b are (#111224) Correctly detect `(x ? a : b)` as nonblocking when `a` and `b` are. Use `FunctionEffectsRef::get` to get to the actual effect set instead of trying to retrieve it manually via the `FunctionProtoType` as we may have to look through function pointers etc. in some cases. --------- Co-authored-by: Doug Wyatt <dwy...@apple.com> Added: Modified: clang/lib/Sema/SemaFunctionEffects.cpp clang/test/Sema/attr-nonblocking-constraints.cpp Removed: ################################################################################ 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..f23093d4dc8a96 100644 --- a/clang/test/Sema/attr-nonblocking-constraints.cpp +++ b/clang/test/Sema/attr-nonblocking-constraints.cpp @@ -156,6 +156,17 @@ 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 blocking(); + +int nb10c(bool x) [[clang::nonblocking]] +{ + int y = (x ? nb10a : blocking)(); // expected-warning {{attribute 'nonblocking' should not be added via type conversion}} + return (x ? nb10a : nb10b)(); // No diagnostic. +} + // Interactions with nonblocking(false) void nb11_no_inference_1() [[clang::nonblocking(false)]] // expected-note {{function does not permit inference of 'nonblocking'}} { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits