diff options
author | David Majnemer <david.majnemer@gmail.com> | 2015-04-07 06:01:53 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2015-04-07 06:01:53 +0000 |
commit | 06864814e502e631b2c07463f6e5be7e60a2260d (patch) | |
tree | cbf4410442847f1e35e6b626d218c4692b552af3 /clang/lib | |
parent | 1f508014df7da33d684a5c0cb3c059a675a0aacf (diff) | |
download | bcm5719-llvm-06864814e502e631b2c07463f6e5be7e60a2260d.tar.gz bcm5719-llvm-06864814e502e631b2c07463f6e5be7e60a2260d.zip |
[Sema] Don't crash when __attribute__((nonnull)) is applied to blocks
A simple case of asserting isFunctionOrMethod when we should have
asserted isFunctionOrMethodOrBlock.
This fixes PR23117.
llvm-svn: 234297
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 05a81a82931..fa61b974e04 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -51,6 +51,11 @@ namespace AttributeLangSupport { static bool isFunctionOrMethod(const Decl *D) { return (D->getFunctionType() != nullptr) || isa<ObjCMethodDecl>(D); } +/// \brief Return true if the given decl has function type (function or +/// function-typed variable) or an Objective-C method or a block. +static bool isFunctionOrMethodOrBlock(const Decl *D) { + return isFunctionOrMethod(D) || isa<BlockDecl>(D); +} /// Return true if the given decl has a declarator that should have /// been processed by Sema::GetTypeForDeclarator. @@ -257,7 +262,7 @@ static bool checkFunctionOrMethodParameterIndex(Sema &S, const Decl *D, unsigned AttrArgNum, const Expr *IdxExpr, uint64_t &Idx) { - assert(isFunctionOrMethod(D)); + assert(isFunctionOrMethodOrBlock(D)); // In C++ the implicit 'this' function parameter also counts. // Parameters are counted from one. @@ -1601,7 +1606,7 @@ static void handleAnalyzerNoReturnAttr(Sema &S, Decl *D, // The checking path for 'noreturn' and 'analyzer_noreturn' are different // because 'analyzer_noreturn' does not impact the type. - if (!isFunctionOrMethod(D) && !isa<BlockDecl>(D)) { + if (!isFunctionOrMethodOrBlock(D)) { ValueDecl *VD = dyn_cast<ValueDecl>(D); if (!VD || (!VD->getType()->isBlockPointerType() && !VD->getType()->isFunctionPointerType())) { |