From: Ted Kremenek Date: Wed, 23 Jan 2013 21:00:27 +0000 (+0000) Subject: Honor attribute 'analyzer_noreturn' on Objective-C methods. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a5b6469a55fb8796353b073f6c12694b0adc77c2;p=clang 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 . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173291 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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()) { + 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 @@ -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}} +} + +