[cfe-commits] r173291 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp test/Analysis/NoReturn.m
Ted Kremenek
kremenek at apple.com
Wed Jan 23 13:00:27 PST 2013
Author: kremenek
Date: Wed Jan 23 15:00:27 2013
New Revision: 173291
URL: http://llvm.org/viewvc/llvm-project?rev=173291&view=rev
Log:
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>.
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp
cfe/trunk/test/Analysis/NoReturn.m
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp?rev=173291&r1=173290&r2=173291&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp Wed Jan 23 15:00:27 2013
@@ -101,6 +101,13 @@
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:]
Modified: cfe/trunk/test/Analysis/NoReturn.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/NoReturn.m?rev=173291&r1=173290&r2=173291&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/NoReturn.m (original)
+++ cfe/trunk/test/Analysis/NoReturn.m Wed Jan 23 15:00:27 2013
@@ -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 @@
return *x; // no-warning
}
+// Test that __attribute__((analyzer_noreturn)) has the intended
+// effect on Objective-C methods.
+
+ at interface Radar11634353
++ (void) doesNotReturn __attribute__((analyzer_noreturn));
+- (void) alsoDoesNotReturn __attribute__((analyzer_noreturn));
+ at 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}}
+}
+
+
More information about the cfe-commits
mailing list