]> granicus.if.org Git - clang/commitdiff
[analyzer] Add support for __builtin_addressof.
authorJordan Rose <jordan_rose@apple.com>
Fri, 12 Jul 2013 00:26:14 +0000 (00:26 +0000)
committerJordan Rose <jordan_rose@apple.com>
Fri, 12 Jul 2013 00:26:14 +0000 (00:26 +0000)
...so we don't regress on std::addressof.

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

lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
test/Analysis/builtin-functions.cpp [new file with mode: 0644]

index a3327d8b3194cf7f7a89b29f693f7de69b6ca90b..5300fae7756dd8e28e2c0303536f8ab0ba309c10 100644 (file)
@@ -43,8 +43,11 @@ bool BuiltinFunctionChecker::evalCall(const CallExpr *CE,
     return false;
 
   switch (id) {
-  case Builtin::BI__builtin_expect: {
+  case Builtin::BI__builtin_expect:
+  case Builtin::BI__builtin_addressof: {
     // For __builtin_expect, just return the value of the subexpression.
+    // __builtin_addressof is going from a reference to a pointer, but those
+    // are represented the same way in the analyzer.
     assert (CE->arg_begin() != CE->arg_end());
     SVal X = state->getSVal(*(CE->arg_begin()), LCtx);
     C.addTransition(state->BindExpr(CE, LCtx, X));
diff --git a/test/Analysis/builtin-functions.cpp b/test/Analysis/builtin-functions.cpp
new file mode 100644 (file)
index 0000000..5c18665
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify
+
+void clang_analyzer_eval(bool);
+
+void test(int x) {
+  clang_analyzer_eval(&x == __builtin_addressof(x)); // expected-warning{{TRUE}}
+}