[clang] [alpha.webkit.UncountedCallArgsChecker] Add the support for trivial CXXInheritedCtorInitExpr. (PR #111198)
Ryosuke Niwa via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 4 11:57:53 PDT 2024
https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/111198
None
>From 6214c124ce0de7ca754ccd43cfda5a572dc76b12 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at webkit.org>
Date: Fri, 4 Oct 2024 11:57:12 -0700
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Add the support for
trivial CXXInheritedCtorInitExpr.
---
.../Checkers/WebKit/PtrTypesSemantics.cpp | 4 ++++
.../Checkers/WebKit/uncounted-obj-arg.cpp | 21 +++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 4d145be808f6d8..317642c5b9ca20 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -508,6 +508,10 @@ class TrivialFunctionAnalysisVisitor
return IsFunctionTrivial(CE->getConstructor());
}
+ bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E) {
+ return IsFunctionTrivial(E->getConstructor());
+ }
+
bool VisitCXXNewExpr(const CXXNewExpr *NE) { return VisitChildren(NE); }
bool VisitImplicitCastExpr(const ImplicitCastExpr *ICE) {
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 97efb354f0371d..75efc397abcc12 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -224,6 +224,20 @@ class ObjectWithMutatingDestructor {
Number n;
};
+class BaseType {
+public:
+ BaseType() : n(0) { }
+ BaseType(int v) : n(v) { }
+ BaseType(const char*);
+private:
+ Number n;
+};
+
+class SomeType : public BaseType {
+public:
+ using BaseType::BaseType;
+};
+
class RefCounted {
public:
void ref() const;
@@ -336,6 +350,8 @@ class RefCounted {
unsigned trivial60() { return ObjectWithNonTrivialDestructor { 5 }.value(); }
unsigned trivial61() { return DerivedNumber('7').value(); }
void trivial62() { WTFReportBacktrace(); }
+ SomeType trivial63() { return SomeType(0); }
+ SomeType trivial64() { return SomeType(); }
static RefCounted& singleton() {
static RefCounted s_RefCounted;
@@ -425,6 +441,7 @@ class RefCounted {
unsigned nonTrivial21() { return Number("123").value(); }
unsigned nonTrivial22() { return ComplexNumber(123, "456").real().value(); }
unsigned nonTrivial23() { return DerivedNumber("123").value(); }
+ SomeType nonTrivial24() { return SomeType("123"); }
static unsigned s_v;
unsigned v { 0 };
@@ -515,6 +532,8 @@ class UnrelatedClass {
getFieldTrivial().trivial60(); // no-warning
getFieldTrivial().trivial61(); // no-warning
getFieldTrivial().trivial62(); // no-warning
+ getFieldTrivial().trivial63(); // no-warning
+ getFieldTrivial().trivial64(); // no-warning
RefCounted::singleton().trivial18(); // no-warning
RefCounted::singleton().someFunction(); // no-warning
@@ -587,6 +606,8 @@ class UnrelatedClass {
// expected-warning at -1{{Call argument for 'this' parameter is uncounted and unsafe}}
getFieldTrivial().nonTrivial23();
// expected-warning at -1{{Call argument for 'this' parameter is uncounted and unsafe}}
+ getFieldTrivial().nonTrivial24();
+ // expected-warning at -1{{Call argument for 'this' parameter is uncounted and unsafe}}
}
};
More information about the cfe-commits
mailing list