https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/182734
>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 1/2] [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); +} >From ba940acfab2cd8bdeca173101a2159c74369d3ff Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa <[email protected]> Date: Sun, 22 Feb 2026 02:46:02 -0800 Subject: [PATCH 2/2] Fix a regression. We need to check for enum in addition to fundamental types. --- clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp | 2 +- clang/test/Analysis/Checkers/WebKit/nodelete-annotation.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 2a9ddeef9a33e..6f2b3d65afe92 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -524,7 +524,7 @@ class TrivialFunctionAnalysisVisitor return true; // Fundamental types (integral, nullptr_t, etc...) don't have destructors. - if (Ty->isFundamentalType()) + if (Ty->isFundamentalType() || Ty->isIntegralOrEnumerationType()) 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 9c334830b8fa5..ff9c8994bb75e 100644 --- a/clang/test/Analysis/Checkers/WebKit/nodelete-annotation.cpp +++ b/clang/test/Analysis/Checkers/WebKit/nodelete-annotation.cpp @@ -212,6 +212,8 @@ struct ObjectWithConstructor { ObjectWithConstructor(void*) { } ObjectWithConstructor(int x[3]) { } ObjectWithConstructor(void* x[2]) { } + enum class E { V1, V2 }; + ObjectWithConstructor(E) { } }; void [[clang::annotate_type("webkit.nodelete")]] makeObjectWithConstructor() { @@ -223,4 +225,5 @@ void [[clang::annotate_type("webkit.nodelete")]] makeObjectWithConstructor() { ObjectWithConstructor obj4(ints); void* ptrs[] = { nullptr, nullptr }; ObjectWithConstructor obj5(ptrs); + ObjectWithConstructor obj6(ObjectWithConstructor::E::V1); } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
