From 78cd51b2eebc406a887fb1dfe438b235537c01b9 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Fri, 12 Jul 2013 00:26:14 +0000 Subject: [PATCH] [analyzer] Add support for __builtin_addressof. ...so we don't regress on std::addressof. llvm-svn: 186140 --- clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp | 5 ++++- clang/test/Analysis/builtin-functions.cpp | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 clang/test/Analysis/builtin-functions.cpp diff --git a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp index a3327d8..5300fae 100644 --- a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp @@ -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/clang/test/Analysis/builtin-functions.cpp b/clang/test/Analysis/builtin-functions.cpp new file mode 100644 index 0000000..5c18665 --- /dev/null +++ b/clang/test/Analysis/builtin-functions.cpp @@ -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}} +} -- 2.7.4