Skip to content

Skip over std namespace in WebKit checkers. #90552

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

Closed
Closed
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 @@ -53,6 +53,12 @@ class UncountedCallArgsChecker
bool shouldVisitTemplateInstantiations() const { return true; }
bool shouldVisitImplicitCode() const { return false; }

bool TraverseNamespaceDecl(NamespaceDecl *Decl) {
if (safeGetName(Decl) == "std")
return true;
return RecursiveASTVisitor<LocalVisitor>::TraverseNamespaceDecl(Decl);
}

bool TraverseClassTemplateDecl(ClassTemplateDecl *Decl) {
if (isRefType(safeGetName(Decl)))
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ class UncountedLocalVarsChecker
bool shouldVisitTemplateInstantiations() const { return true; }
bool shouldVisitImplicitCode() const { return false; }

bool TraverseNamespaceDecl(NamespaceDecl *Decl) {
if (safeGetName(Decl) == "std")
return true;
return RecursiveASTVisitor<LocalVisitor>::TraverseNamespaceDecl(Decl);
}

bool VisitVarDecl(VarDecl *V) {
Checker->visitVarDecl(V);
return true;
Expand Down
27 changes: 27 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/call-args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,30 @@ namespace cxx_member_operator_call {
// expected-warning@-1{{Call argument for parameter 'bad' is uncounted and unsafe}}
}
}

namespace std {

template <typename T>
T* other_function();

template <typename T>
void another_function(T*, T*);

template <typename T>
void some_function(T* a)
{
another_function(other_function<T>(), a);
}

} // std

namespace ignore_std_namespace {

RefCountable *ref_counted();

void foo() {
std::some_function(ref_counted());
// expected-warning@-1{{Call argument for parameter 'a' is uncounted and unsafe}}
}

} // ignore_std_namespace
26 changes: 26 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,29 @@ void bar() {
}

} // namespace ignore_for_if

namespace std {

void memcpy(void*, void*, unsigned long);

template <typename T>
void some_function(T* a, T* b)
{
T* temp = new T;
memcpy(temp, a, sizeof(T));
memcpy(a, b, sizeof(T));
memcpy(b, temp, sizeof(T));
delete temp;
}

} // std

namespace ignore_std_namespace {

RefCountable *ref_counted();

void foo() {
std::some_function(ref_counted(), ref_counted());
}

} // ignore_std_namespace