Skip to content

[alpha.webkit.UncountedCallArgsChecker] Add the support for trivial CXXInheritedCtorInitExpr. #111198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 21 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -587,6 +606,8 @@ class UnrelatedClass {
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
getFieldTrivial().nonTrivial23();
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
getFieldTrivial().nonTrivial24();
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
}
};

Expand Down
Loading