]> granicus.if.org Git - clang/commitdiff
[analyzer] Handle another Android assert function.
authorDevin Coughlin <dcoughlin@apple.com>
Wed, 30 Dec 2015 00:08:59 +0000 (00:08 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Wed, 30 Dec 2015 00:08:59 +0000 (00:08 +0000)
Android's assert can call both the __assert and __assert2 functions under the cover, but
the NoReturnFunctionChecker does not handle the latter. This commit fixes that.

A patch by Yury Gribov!

Differential Revision: http://reviews.llvm.org/D15810

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

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

index 8d0a060fc456f06038e8dfd63482c1417f5de82d..c1deadef42026733a4764d0b89dedcdea43f0641 100644 (file)
@@ -66,6 +66,7 @@ void NoReturnFunctionChecker::checkPostCall(const CallEvent &CE,
             .Case("assfail", true)
             .Case("db_error", true)
             .Case("__assert", true)
+            .Case("__assert2", true)
             // For the purpose of static analysis, we do not care that
             //  this MSVC function will return if the user decides to continue.
             .Case("_wassert", true)
index 9b7011e793186c5eba6749b6ca9bdfe7a22610e7..5ed92dfe5d4e3f2b27e451196cea9e2571265199 100644 (file)
@@ -131,3 +131,15 @@ void test_wassert() {
   int *p = 0;
   *p = 0xDEADBEEF; // no-warning
 }
+#undef assert
+
+// Test that hard-coded Android __assert2 name is recognized as a noreturn
+#define assert(_Expression) ((_Expression) ? (void)0 : __assert2(0, 0, 0, 0));
+extern void __assert2(const char *, int, const char *, const char *);
+extern void _wassert(const char * _Message, const char *_File, unsigned _Line);
+void test___assert2() {
+  assert(0);
+  int *p = 0;
+  *p = 0xDEADBEEF; // no-warning
+}
+#undef assert