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.


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.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to