r302880 - [analyzer] Add modelling of __builtin_assume

Gabor Horvath via cfe-commits cfe-commits at lists.llvm.org
Fri May 12 00:02:55 PDT 2017


Author: xazax
Date: Fri May 12 02:02:54 2017
New Revision: 302880

URL: http://llvm.org/viewvc/llvm-project?rev=302880&view=rev
Log:
[analyzer] Add modelling of __builtin_assume

Differential Revision: https://reviews.llvm.org/D33092

Added:
    cfe/trunk/test/Analysis/builtin-assume.c
Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp?rev=302880&r1=302879&r2=302880&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp Fri May 12 02:02:54 2017
@@ -41,6 +41,22 @@ bool BuiltinFunctionChecker::evalCall(co
   default:
     return false;
 
+  case Builtin::BI__builtin_assume: {
+    assert (CE->arg_begin() != CE->arg_end());
+    SVal ArgSVal = state->getSVal(CE->getArg(0), LCtx);
+    if (ArgSVal.isUndef())
+      return true; // Return true to model purity.
+
+    state = state->assume(ArgSVal.castAs<DefinedOrUnknownSVal>(), true);
+    // FIXME: do we want to warn here? Not right now. The most reports might
+    // come from infeasible paths, thus being false positives.
+    if (!state)
+      return true;
+
+    C.addTransition(state);
+    return true;
+  }
+
   case Builtin::BI__builtin_unpredictable:
   case Builtin::BI__builtin_expect:
   case Builtin::BI__builtin_assume_aligned:

Added: cfe/trunk/test/Analysis/builtin-assume.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/builtin-assume.c?rev=302880&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/builtin-assume.c (added)
+++ cfe/trunk/test/Analysis/builtin-assume.c Fri May 12 02:02:54 2017
@@ -0,0 +1,8 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
+
+void clang_analyzer_eval(int);
+
+void f(int i) {
+  __builtin_assume(i < 10);
+  clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
+}




More information about the cfe-commits mailing list