diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index 09c98f642852f..4eaf8705fd257 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -8836,13 +8836,16 @@ void FixedPointValueToString(SmallVectorImpl &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()) + if (const auto *FPT = TypePtr->getAs()) return FPT->getFunctionEffects(); return {}; } diff --git a/clang/test/Sema/attr-nonblocking-constraints.cpp b/clang/test/Sema/attr-nonblocking-constraints.cpp index bbc909f627f4c..b26a945843696 100644 --- a/clang/test/Sema/attr-nonblocking-constraints.cpp +++ b/clang/test/Sema/attr-nonblocking-constraints.cpp @@ -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. @@ -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();