Skip to content

[Clang] FunctionEffects: Correctly navigate through array types in FunctionEffectsRef::get(). #121525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -8836,13 +8836,16 @@ void FixedPointValueToString(SmallVectorImpl<char> &Str, llvm::APSInt Val,
unsigned Scale);

inline FunctionEffectsRef FunctionEffectsRef::get(QualType QT) {
const Type *TypePtr = QT.getTypePtr();
while (true) {
QualType Pointee = QT->getPointeeType();
if (Pointee.isNull())
if (QualType Pointee = TypePtr->getPointeeType(); !Pointee.isNull())
TypePtr = Pointee.getTypePtr();
else if (TypePtr->isArrayType())
TypePtr = TypePtr->getBaseElementTypeUnsafe();
else
break;
QT = Pointee;
}
if (const auto *FPT = QT->getAs<FunctionProtoType>())
if (const auto *FPT = TypePtr->getAs<FunctionProtoType>())
return FPT->getFunctionEffects();
return {};
}
Expand Down
19 changes: 18 additions & 1 deletion clang/test/Sema/attr-nonblocking-constraints.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -fsyntax-only -fblocks -fcxx-exceptions -std=c++20 -verify -Wfunction-effects %s
// RUN: %clang_cc1 -fsyntax-only -fblocks -fcxx-exceptions -std=c++20 -verify -Wfunction-effects -Wno-vla-extension %s
// These are in a separate file because errors (e.g. incompatible attributes) currently prevent
// the FXAnalysis pass from running at all.

Expand Down Expand Up @@ -246,6 +246,23 @@ void PTMFTester::convert() [[clang::nonblocking]]
(this->*mConvertFunc)();
}

// Allow implicit conversion from array to pointer.
void nb14(unsigned idx) [[clang::nonblocking]]
{
using FP = void (*)() [[clang::nonblocking]];
using FPArray = FP[2];
auto nb = +[]() [[clang::nonblocking]] {};

FPArray src{ nb, nullptr };
FP f = src[idx]; // This should not generate a warning.

FP twoDim[2][2] = {};
FP g = twoDim[1][1];

FP vla[idx];
FP h = vla[0];
}

// Block variables
void nb17(void (^blk)() [[clang::nonblocking]]) [[clang::nonblocking]] {
blk();
Expand Down
Loading