[clang] bc29069 - [analyzer] Enable PlacementNewChecker by default

Gabor Marton via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 21 04:24:11 PST 2020


Author: Gabor Marton
Date: 2020-01-21T13:23:10+01:00
New Revision: bc29069dc401572ba62f7dd692a3474c1ead76c9

URL: https://github.com/llvm/llvm-project/commit/bc29069dc401572ba62f7dd692a3474c1ead76c9
DIFF: https://github.com/llvm/llvm-project/commit/bc29069dc401572ba62f7dd692a3474c1ead76c9.diff

LOG: [analyzer] Enable PlacementNewChecker by default

Added: 
    

Modified: 
    clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
    clang/test/Analysis/placement-new-user-defined.cpp
    clang/test/Analysis/placement-new.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index d235273cda41..fc1529f2ea1c 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -470,6 +470,12 @@ def NewDeleteLeaksChecker : Checker<"NewDeleteLeaks">,
   Dependencies<[NewDeleteChecker]>,
   Documentation<HasDocumentation>;
 
+def PlacementNewChecker : Checker<"PlacementNew">,
+  HelpText<"Check if default placement new is provided with pointers to "
+           "sufficient storage capacity">,
+  Dependencies<[NewDeleteChecker]>,
+  Documentation<HasDocumentation>;
+
 def CXXSelfAssignmentChecker : Checker<"SelfAssignment">,
   HelpText<"Checks C++ copy and move assignment operators for self assignment">,
   Documentation<NotDocumented>,
@@ -615,12 +621,6 @@ def MismatchedIteratorChecker : Checker<"MismatchedIterator">,
   Dependencies<[IteratorModeling]>,
   Documentation<HasAlphaDocumentation>;
 
-def PlacementNewChecker : Checker<"PlacementNew">,
-  HelpText<"Check if default placement new is provided with pointers to "
-           "sufficient storage capacity">,
-  Dependencies<[NewDeleteChecker]>,
-  Documentation<HasDocumentation>;
-
 } // end: "alpha.cplusplus"
 
 

diff  --git a/clang/test/Analysis/placement-new-user-defined.cpp b/clang/test/Analysis/placement-new-user-defined.cpp
index 47f0b459ea00..b3fe47057f8a 100644
--- a/clang/test/Analysis/placement-new-user-defined.cpp
+++ b/clang/test/Analysis/placement-new-user-defined.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_analyze_cc1 -std=c++11 %s \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=cplusplus.NewDelete \
-// RUN:   -analyzer-checker=alpha.cplusplus.PlacementNew \
+// RUN:   -analyzer-checker=cplusplus.PlacementNew \
 // RUN:   -analyzer-output=text -verify \
 // RUN:   -triple x86_64-unknown-linux-gnu
 

diff  --git a/clang/test/Analysis/placement-new.cpp b/clang/test/Analysis/placement-new.cpp
index 0f5248410a41..37102b810d98 100644
--- a/clang/test/Analysis/placement-new.cpp
+++ b/clang/test/Analysis/placement-new.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_analyze_cc1 -std=c++11 %s \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=cplusplus.NewDelete \
-// RUN:   -analyzer-checker=alpha.cplusplus.PlacementNew \
+// RUN:   -analyzer-checker=cplusplus.PlacementNew \
 // RUN:   -analyzer-output=text -verify \
 // RUN:   -triple x86_64-unknown-linux-gnu
 
@@ -93,6 +93,22 @@ void f() {
 }
 } // namespace testPtrToArrayWithOffsetAsPlace
 
+namespace testZeroSize {
+void f() {
+  int buf[3];                      // expected-note {{'buf' initialized here}}
+  long *lp = ::new (buf + 3) long; // expected-warning{{Storage provided to placement new is only 0 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+} // namespace testZeroSize
+
+namespace testNegativeSize {
+void f() {
+  int buf[3];                      // expected-note {{'buf' initialized here}}
+  long *lp = ::new (buf + 4) long; // expected-warning{{Storage provided to placement new is only -4 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+} // namespace testNegativeSize
+
 namespace testHeapAllocatedBuffer {
 void g2() {
   char *buf = new char[2];     // expected-note {{'buf' initialized here}}


        


More information about the cfe-commits mailing list