mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 08:15:31 +00:00
Bug 1536724. Consider a smartptr temporary to be live for MOZ_CAN_RUN_SCRIPT analysis purposes. r=andi
Differential Revision: https://phabricator.services.mozilla.com/D24120 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
14f6385d4b
commit
0d0978f826
@ -65,7 +65,11 @@ void CanRunScriptChecker::registerMatchers(MatchFinder *AstMatcher) {
|
||||
// 2) It's a const member of "this". We know "this" is alive (recursively)
|
||||
// and const members can't change their value hence can't drop their
|
||||
// reference until "this" gets destroyed.
|
||||
auto KnownLiveSmartPtr = anyOf(StackSmartPtr, ConstMemberOfThisSmartPtr);
|
||||
auto KnownLiveSmartPtr = anyOf(
|
||||
StackSmartPtr,
|
||||
ConstMemberOfThisSmartPtr,
|
||||
ignoreTrivials(cxxConstructExpr(hasType(isSmartPtrToRefCounted()))));
|
||||
|
||||
auto MozKnownLiveCall =
|
||||
ignoreTrivials(callExpr(callee(functionDecl(hasName("MOZ_KnownLive")))));
|
||||
|
||||
|
@ -347,6 +347,45 @@ struct DisallowConstNonRefPtrMemberArgs {
|
||||
}
|
||||
};
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT void test_temporary_1() {
|
||||
RefPtr<RefCountedBase>(new RefCountedBase())->method_test();
|
||||
}
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT void test_temporary_2() {
|
||||
test_ref(*RefPtr<RefCountedBase>(new RefCountedBase()));
|
||||
}
|
||||
|
||||
struct WeakSmartPtr {
|
||||
RefCountedBase* member;
|
||||
|
||||
explicit WeakSmartPtr(RefCountedBase* arg) : member(arg) {}
|
||||
|
||||
RefCountedBase* operator->() const {
|
||||
return member;
|
||||
}
|
||||
|
||||
RefCountedBase& operator*() const {
|
||||
return *member;
|
||||
}
|
||||
|
||||
operator RefCountedBase*() const {
|
||||
return member;
|
||||
}
|
||||
};
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT void test_temporary_3() {
|
||||
WeakSmartPtr(new RefCountedBase())->method_test(); // expected-error {{arguments must all be strong refs or parent parameters when calling a function marked as MOZ_CAN_RUN_SCRIPT (including the implicit object argument)}}
|
||||
}
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT void test_temporary_4() {
|
||||
test_ref(*WeakSmartPtr(new RefCountedBase())); // expected-error {{arguments must all be strong refs or parent parameters when calling a function marked as MOZ_CAN_RUN_SCRIPT (including the implicit object argument)}}
|
||||
}
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT void test_temporary_5() {
|
||||
test2(WeakSmartPtr(new RefCountedBase())); // expected-error {{arguments must all be strong refs or parent parameters when calling a function marked as MOZ_CAN_RUN_SCRIPT (including the implicit object argument)}}
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct TArray {
|
||||
TArray() {
|
||||
|
Loading…
Reference in New Issue
Block a user