[PATCH] D33092: [analyzer] Add checker to model builtin functions

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 12 00:16:14 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL302880: [analyzer] Add modelling of __builtin_assume (authored by xazax).

Changed prior to commit:
  https://reviews.llvm.org/D33092?vs=98609&id=98731#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33092

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


Index: cfe/trunk/test/Analysis/builtin-assume.c
===================================================================
--- cfe/trunk/test/Analysis/builtin-assume.c
+++ cfe/trunk/test/Analysis/builtin-assume.c
@@ -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}}
+}
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -41,6 +41,22 @@
   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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33092.98731.patch
Type: text/x-patch
Size: 1442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170512/c1fc00d4/attachment.bin>


More information about the cfe-commits mailing list