[PATCH] D39551: [analyzer] Make __builtin_debugtrap() a sink

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 2 07:52:26 PDT 2017


xazax.hun created this revision.
Herald added subscribers: szepet, baloghadamsoftware, whisperity.

For some reason, `__builtin_debugtrap` is not a sink for the analyzer. I also added some test cases to demonstrate that `__builtin_trap` and `__builtin_unreachable` are handled properly. The former is not marked as noreturn while the last two are. See Builtins.def for details. It was made non-noreturn deliberately, see https://reviews.llvm.org/rL166345
I have however no idea why.


https://reviews.llvm.org/D39551

Files:
  lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
  test/Analysis/builtin-functions.cpp


Index: test/Analysis/builtin-functions.cpp
===================================================================
--- test/Analysis/builtin-functions.cpp
+++ test/Analysis/builtin-functions.cpp
@@ -63,4 +63,18 @@
     clang_analyzer_warnIfReached(); // Assumtion contradicts constraints.
                                     // We give up the analysis on this path.
   }
+  switch (i) {
+  case 1:
+    __builtin_unreachable();
+    clang_analyzer_warnIfReached();
+    break;
+  case 2:
+    __builtin_trap();
+    clang_analyzer_warnIfReached();
+    break;
+  case 3:
+    __builtin_debugtrap();
+    clang_analyzer_warnIfReached();
+    break;
+  }
 }
Index: lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -41,6 +41,10 @@
   default:
     return false;
 
+  case Builtin::BI__builtin_debugtrap:
+    C.generateSink(C.getState(), C.getPredecessor());
+    return true;
+
   case Builtin::BI__builtin_assume: {
     assert (CE->arg_begin() != CE->arg_end());
     SVal ArgSVal = state->getSVal(CE->getArg(0), LCtx);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39551.121304.patch
Type: text/x-patch
Size: 1212 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171102/ce854920/attachment.bin>


More information about the cfe-commits mailing list