Skip to content

[alpha.webkit.UncountedCallArgsChecker] Allow a variable declaration in a trivial function. #82291

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 2 commits into from
Feb 28, 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 @@ -310,8 +310,12 @@ class TrivialFunctionAnalysisVisitor
return true;
if (isa<EnumConstantDecl>(decl))
return true;
if (auto *VD = dyn_cast<VarDecl>(decl))
return VD->hasConstantInitialization() && VD->getEvaluatedValue();
if (auto *VD = dyn_cast<VarDecl>(decl)) {
if (VD->hasConstantInitialization() && VD->getEvaluatedValue())
return true;
auto *Init = VD->getInit();
return !Init || Visit(Init);
}
}
return false;
}
Expand Down
17 changes: 17 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ class RefCounted {
bool trivial23() const { return OptionSet<Flags>::fromRaw(v).contains(Flags::Flag1); }
int trivial24() const { ASSERT(v); return v; }
unsigned trivial25() const { return __c11_atomic_load((volatile _Atomic(unsigned) *)&v, __ATOMIC_RELAXED); }
bool trivial26() { bool hasValue = v; return !hasValue; }
bool trivial27(int v) { bool value; value = v ? 1 : 0; return value; }

static RefCounted& singleton() {
static RefCounted s_RefCounted;
Expand Down Expand Up @@ -262,6 +264,15 @@ class RefCounted {
return __c11_atomic_load((volatile _Atomic(unsigned) *)another(), __ATOMIC_RELAXED);
}

void nonTrivial11() {
Number num(0.3);
}

bool nonTrivial12() {
bool val = otherFunction();
return val;
}

unsigned v { 0 };
Number* number { nullptr };
Enum enumValue { Enum::Value1 };
Expand Down Expand Up @@ -309,6 +320,8 @@ class UnrelatedClass {
getFieldTrivial().trivial23(); // no-warning
getFieldTrivial().trivial24(); // no-warning
getFieldTrivial().trivial25(); // no-warning
getFieldTrivial().trivial26(); // no-warning
getFieldTrivial().trivial27(5); // no-warning
RefCounted::singleton().trivial18(); // no-warning
RefCounted::singleton().someFunction(); // no-warning

Expand All @@ -334,6 +347,10 @@ class UnrelatedClass {
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
getFieldTrivial().nonTrivial10();
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
getFieldTrivial().nonTrivial11();
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
getFieldTrivial().nonTrivial12();
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
}
};

Expand Down