]> granicus.if.org Git - clang/commitdiff
Honor attribute 'analyzer_noreturn' on Objective-C methods.
authorTed Kremenek <kremenek@apple.com>
Wed, 23 Jan 2013 21:00:27 +0000 (21:00 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 23 Jan 2013 21:00:27 +0000 (21:00 +0000)
This isn't likely a full solution, but it catches the common cases
and can be refined over time.

Fixes <rdar://problem/11634353>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173291 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp
test/Analysis/NoReturn.m

index 37d91138f0652ef749d075504268f8ac0113b76f..351eabf8df31fa174d515c4284c5228fe0af5c14 100644 (file)
@@ -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:]
index 6d547f47f66ce860e3e8849ae070c6eaa2f1672e..8207d3acfd1d8ae524ac671dda67533762227b64 100644 (file)
@@ -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}}
+}
+
+