From add14263ea96e96c9cb6c96786ccffb7e242b87f Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Wed, 17 Apr 2013 18:03:48 +0000 Subject: [analyzer] Don't warn for returning void expressions in void blocks. This was slightly tricky because BlockDecls don't currently store an inferred return type. However, we can rely on the fact that blocks with inferred return types will have return statements that match the inferred type. llvm-svn: 179699 --- clang/lib/StaticAnalyzer/Core/CallEvent.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'clang/lib/StaticAnalyzer/Core/CallEvent.cpp') diff --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp index 45b2e219d9e..dfd20b8b332 100644 --- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp +++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -239,8 +239,20 @@ QualType CallEvent::getDeclaredResultType(const Decl *D) { assert(D); if (const FunctionDecl* FD = dyn_cast(D)) return FD->getResultType(); - else if (const ObjCMethodDecl* MD = dyn_cast(D)) + if (const ObjCMethodDecl* MD = dyn_cast(D)) return MD->getResultType(); + if (const BlockDecl *BD = dyn_cast(D)) { + // Blocks are difficult because the return type may not be stored in the + // BlockDecl itself. The AST should probably be enhanced, but for now we + // just do what we can. + QualType Ty = BD->getSignatureAsWritten()->getType(); + if (const FunctionType *FT = Ty->getAs()) + if (!FT->getResultType()->isDependentType()) + return FT->getResultType(); + + return QualType(); + } + return QualType(); } -- cgit v1.2.3