Skip to content

Commit 805b182

Browse files
author
Doug Wyatt
committed
[Clang] FunctionEffects: Correctly navigate through array types in FunctionEffectsRef::get().
1 parent 3cac26f commit 805b182

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

clang/include/clang/AST/Type.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8836,13 +8836,22 @@ void FixedPointValueToString(SmallVectorImpl<char> &Str, llvm::APSInt Val,
88368836
unsigned Scale);
88378837

88388838
inline FunctionEffectsRef FunctionEffectsRef::get(QualType QT) {
8839+
const Type *TypePtr = QT.getTypePtr();
88398840
while (true) {
8840-
QualType Pointee = QT->getPointeeType();
8841-
if (Pointee.isNull())
8841+
// Note that getPointeeType() seems to successfully navigate some constructs
8842+
// for which isAnyPointerType() returns false (e.g.
8843+
// pointer-to-member-function).
8844+
QualType Pointee = TypePtr->getPointeeType();
8845+
if (Pointee.isNull()) {
8846+
if (TypePtr->isArrayType()) {
8847+
TypePtr = TypePtr->getBaseElementTypeUnsafe();
8848+
continue;
8849+
}
88428850
break;
8843-
QT = Pointee;
8851+
}
8852+
TypePtr = Pointee.getTypePtr();
88448853
}
8845-
if (const auto *FPT = QT->getAs<FunctionProtoType>())
8854+
if (const auto *FPT = TypePtr->getAs<FunctionProtoType>())
88468855
return FPT->getFunctionEffects();
88478856
return {};
88488857
}

clang/test/Sema/attr-nonblocking-constraints.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,16 @@ void PTMFTester::convert() [[clang::nonblocking]]
246246
(this->*mConvertFunc)();
247247
}
248248

249+
// Allow implicit conversion from array to pointer.
250+
void nb14(unsigned idx) [[clang::nonblocking]]
251+
{
252+
using FP = void (*)() [[clang::nonblocking]];
253+
auto nb = +[]() [[clang::nonblocking]] {};
254+
255+
FP array[4] = { nb, nb, nb, nb };
256+
FP f = array[idx]; // This should not generate a warning.
257+
}
258+
249259
// Block variables
250260
void nb17(void (^blk)() [[clang::nonblocking]]) [[clang::nonblocking]] {
251261
blk();

0 commit comments

Comments
 (0)