https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/182734
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. >From 6e3643198455f403cee1025688d10c020f5d36a6 Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa <[email protected]> Date: Sun, 22 Feb 2026 02:19:25 -0800 Subject: [PATCH] [alpha.webkit.NoDeleteChecker] Fundamental types are trivially destructive 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. --- .../Checkers/WebKit/PtrTypesSemantics.cpp | 4 ++-- .../Checkers/WebKit/nodelete-annotation.cpp | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) 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); +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
