llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)

<details>
<summary>Changes</summary>

This PR fixes the bug in the "trivial function analysis" that 
CanTriviallyDestruct returns false for some fundamental types such as float and 
nullptr_t. Return true for these types instead as they are trivally destructive.

---
Full diff: https://github.com/llvm/llvm-project/pull/182734.diff


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
(+2-2) 
- (modified) clang/test/Analysis/Checkers/WebKit/nodelete-annotation.cpp (+20) 


``````````diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 8cd64c12b7a73..2a9ddeef9a33e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -523,8 +523,8 @@ class TrivialFunctionAnalysisVisitor
     if (Ty->isPointerOrReferenceType())
       return true;
 
-    // Primitive types don't have destructors.
-    if (Ty->isIntegralOrEnumerationType())
+    // Fundamental types (integral, nullptr_t, etc...) don't have destructors.
+    if (Ty->isFundamentalType())
       return true;
 
     if (const auto *R = Ty->getAsCXXRecordDecl()) {
diff --git a/clang/test/Analysis/Checkers/WebKit/nodelete-annotation.cpp 
b/clang/test/Analysis/Checkers/WebKit/nodelete-annotation.cpp
index 98f4017e5e3fd..9c334830b8fa5 100644
--- a/clang/test/Analysis/Checkers/WebKit/nodelete-annotation.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/nodelete-annotation.cpp
@@ -204,3 +204,23 @@ void [[clang::annotate_type("webkit.nodelete")]] 
makeSubData() {
   // expected-warning@-1{{A function 'makeSubData' has 
[[clang::annotate_type("webkit.nodelete")]] but it contains code that could 
destruct an object}}
   SubData::create()->doSomething();
 }
+
+struct ObjectWithConstructor {
+  ObjectWithConstructor(double x) { }
+  ObjectWithConstructor(float x) { }
+  ObjectWithConstructor(decltype(nullptr)) { }
+  ObjectWithConstructor(void*) { }
+  ObjectWithConstructor(int x[3]) { }
+  ObjectWithConstructor(void* x[2]) { }
+};
+
+void [[clang::annotate_type("webkit.nodelete")]] makeObjectWithConstructor() {
+  ObjectWithConstructor obj1(nullptr);
+  ObjectWithConstructor obj2(0.5);
+  double x = 0.7;
+  ObjectWithConstructor obj3(x);
+  int ints[] = { 1, 2, 3 };
+  ObjectWithConstructor obj4(ints);
+  void* ptrs[] = { nullptr, nullptr };
+  ObjectWithConstructor obj5(ptrs);
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/182734
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to