diff options
| author | Ted Kremenek <kremenek@apple.com> | 2013-01-23 21:00:27 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2013-01-23 21:00:27 +0000 |
| commit | 54cd3c681104cc47967650387d0081f4ef814499 (patch) | |
| tree | 50ade0d503e89be0d87ceea068cd1dd2e50ac406 | |
| parent | 39e2738c8b846a32677bb23baed6367692cf45ac (diff) | |
| download | bcm5719-llvm-54cd3c681104cc47967650387d0081f4ef814499.tar.gz bcm5719-llvm-54cd3c681104cc47967650387d0081f4ef814499.zip | |
Honor attribute 'analyzer_noreturn' on Objective-C methods.
This isn't likely a full solution, but it catches the common cases
and can be refined over time.
Fixes <rdar://problem/11634353>.
llvm-svn: 173291
| -rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp | 7 | ||||
| -rw-r--r-- | clang/test/Analysis/NoReturn.m | 29 |
2 files changed, 34 insertions, 2 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp index 37d91138f06..351eabf8df3 100644 --- a/clang/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp @@ -101,6 +101,13 @@ static bool END_WITH_NULL isMultiArgSelector(const Selector *Sel, ...) { void NoReturnFunctionChecker::checkPostObjCMessage(const ObjCMethodCall &Msg, CheckerContext &C) const { + // Check if the method is annotated with analyzer_noreturn. + const ObjCMethodDecl *MD = Msg.getDecl()->getCanonicalDecl(); + if (MD->hasAttr<AnalyzerNoReturnAttr>()) { + C.generateSink(); + return; + } + // HACK: This entire check is to handle two messages in the Cocoa frameworks: // -[NSAssertionHandler // handleFailureInMethod:object:file:lineNumber:description:] diff --git a/clang/test/Analysis/NoReturn.m b/clang/test/Analysis/NoReturn.m index 6d547f47f66..8207d3acfd1 100644 --- a/clang/test/Analysis/NoReturn.m +++ b/clang/test/Analysis/NoReturn.m @@ -1,5 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core -analyzer-store=region -analyzer-constraints=range -verify %s -// expected-no-diagnostics +// RUN: %clang --analyze -Xclang -analyzer-checker=alpha.core -Xclang -verify %s #include <stdarg.h> @@ -88,3 +87,29 @@ int testCustomException(int *x) { return *x; // no-warning } +// Test that __attribute__((analyzer_noreturn)) has the intended +// effect on Objective-C methods. + +@interface Radar11634353 ++ (void) doesNotReturn __attribute__((analyzer_noreturn)); +- (void) alsoDoesNotReturn __attribute__((analyzer_noreturn)); +@end + +void test_rdar11634353() { + [Radar11634353 doesNotReturn]; + int *p = 0; + *p = 0xDEADBEEF; // no-warning +} + +void test_rdar11634352_instance(Radar11634353 *o) { + [o alsoDoesNotReturn]; + int *p = 0; + *p = 0xDEADBEEF; // no-warning +} + +void test_rdar11634353_positive() { + int *p = 0; + *p = 0xDEADBEEF; // expected-warning {{null pointer}} +} + + |

