diff options
| author | Jordan Rose <jordan_rose@apple.com> | 2013-04-17 18:03:48 +0000 |
|---|---|---|
| committer | Jordan Rose <jordan_rose@apple.com> | 2013-04-17 18:03:48 +0000 |
| commit | add14263ea96e96c9cb6c96786ccffb7e242b87f (patch) | |
| tree | f5b0c1803a190cb80b209b793fa1c2effb09fc56 /clang/lib/StaticAnalyzer/Checkers | |
| parent | c7400488b947f9f13de99f00932c6eb0b5d22fa8 (diff) | |
| download | bcm5719-llvm-add14263ea96e96c9cb6c96786ccffb7e242b87f.tar.gz bcm5719-llvm-add14263ea96e96c9cb6c96786ccffb7e242b87f.zip | |
[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.
<rdar://problem/13665798>
llvm-svn: 179699
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers')
| -rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/ReturnUndefChecker.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/ReturnUndefChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ReturnUndefChecker.cpp index 7a5d9936010..ed96c401a7a 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ReturnUndefChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ReturnUndefChecker.cpp @@ -55,8 +55,17 @@ void ReturnUndefChecker::checkPreStmt(const ReturnStmt *RS, // void test() { // return foo(); // } - if (RT.isNull() || !RT->isVoidType()) - emitUndef(C, RetE); + if (!RT.isNull() && RT->isVoidType()) + return; + + // Not all blocks have explicitly-specified return types; if the return type + // is not available, but the return value expression has 'void' type, assume + // Sema already checked it. + if (RT.isNull() && isa<BlockDecl>(SFC->getDecl()) && + RetE->getType()->isVoidType()) + return; + + emitUndef(C, RetE); return; } |

