[PATCH] D75021: [clang][analyzer] Enable core.builtin even with -no-default-checks

Zinovy Nis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 23 09:15:28 PST 2020


zinovy.nis created this revision.
zinovy.nis added reviewers: abdulras, xazax.hun.
zinovy.nis added a project: clang.
Herald added subscribers: cfe-commits, Charusso, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware.

It's required to properly handle __attribute__(([analyzer_]noreturn)) in checks.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75021

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Analysis/no-default-checks.cpp


Index: clang/test/Analysis/no-default-checks.cpp
===================================================================
--- /dev/null
+++ clang/test/Analysis/no-default-checks.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang -std=c++14 --analyze --analyzer-no-default-checks -Xclang -analyzer-checker=core.CallAndMessage -Xclang -verify %s -o - 
+
+// expected-no-diagnostics
+
+inline constexpr bool AnalyzerNoReturn() __attribute__((analyzer_noreturn)) {
+  return false;
+}
+ 
+struct A {
+   int size();
+};
+
+int foo(A* pa) {
+  if (!pa)
+    AnalyzerNoReturn();
+  // No warning on "Called C++ object pointer is null" is expected 
+  // as |pa| has already been checked for nullptr by this point.
+  return pa->size();
+}
\ No newline at end of file
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2941,6 +2941,10 @@
     // Default nullability checks.
     CmdArgs.push_back("-analyzer-checker=nullability.NullPassedToNonnull");
     CmdArgs.push_back("-analyzer-checker=nullability.NullReturnedFromNonnull");
+  } else {
+    // These pseudo-checkers handle assert-like functions and generate no
+    // warnings. They are required to prevent massive false-positive findings.
+    CmdArgs.push_back("-analyzer-checker=core.builtin");
   }
 
   // Set the output format. The default is plist, for (lame) historical reasons.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75021.246112.patch
Type: text/x-patch
Size: 1470 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200223/94afb0ff/attachment.bin>


More information about the cfe-commits mailing list