diff options
-rw-r--r-- | lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp | 7 | ||||
-rw-r--r-- | test/Analysis/NoReturn.m | 29 |
2 files changed, 34 insertions, 2 deletions
diff --git a/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp b/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp index 37d91138f0..351eabf8df 100644 --- a/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp +++ b/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/test/Analysis/NoReturn.m b/test/Analysis/NoReturn.m index 6d547f47f6..8207d3acfd 100644 --- a/test/Analysis/NoReturn.m +++ b/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}} +} + + |