Skip to content

[alpha.webkit.UncountedCallArgsChecker] Treat an explicit construction of Ref from a Ref return value safe. #130911

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
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ bool tryToFindPtrOrigin(
if (isCtorOfSafePtr(ConversionFunc))
return callback(E, true);
}
if (isa<CXXFunctionalCastExpr>(E) && isSafePtrType(cast->getType()))
return callback(E, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this case already handled for parameters and locals? Like are there instances of a constructing a Ref from another Ref parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically don't pass arguments as RefPtr / Ref except a few cases where we pass in as RefPtr&& / Ref&&. I guess we can add a test for it though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

}
// FIXME: This can give false "origin" that would lead to false negatives
// in checkers. See https://reviews.llvm.org/D37023 for reference.
Expand Down
7 changes: 7 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/call-args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ namespace call_with_explicit_temporary_obj {
void baz() {
bar<int>();
}

class Foo {
Ref<RefCountable> ensure();
void foo() {
Ref { ensure() }->method();
}
};
}

namespace call_with_explicit_construct {
Expand Down