Bug 1536736. Allow constexpr things in the MOZ_CAN_RUN_SCRIPT analysis. r=andi

Since these are compile-time constants, they can't exactly go away on us due to
running script, right?

Differential Revision: https://phabricator.services.mozilla.com/D24195

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-03-20 20:04:11 +00:00
Родитель 9679412967
Коммит 22b27ec802
2 изменённых файлов: 35 добавлений и 1 удалений

Просмотреть файл

@ -110,6 +110,10 @@ void CanRunScriptChecker::registerMatchers(MatchFinder *AstMatcher) {
), ),
// and which is not a parameter of the parent function, // and which is not a parameter of the parent function,
unless(declRefExpr(to(parmVarDecl()))), unless(declRefExpr(to(parmVarDecl()))),
// and which is not a constexpr variable, since that must be
// computable at compile-time and therefore isn't going to be going
// away.
unless(declRefExpr(to(varDecl(isConstexpr())))),
// and which is not a default arg with value nullptr, since those are // and which is not a default arg with value nullptr, since those are
// always safe. // always safe.
unless(cxxDefaultArgExpr(isNullDefaultArg())), unless(cxxDefaultArgExpr(isNullDefaultArg())),
@ -130,7 +134,12 @@ void CanRunScriptChecker::registerMatchers(MatchFinder *AstMatcher) {
// implicitCastExpr), but it's simpler to just use // implicitCastExpr), but it's simpler to just use
// ignoreTrivials to strip off the cast. // ignoreTrivials to strip off the cast.
ignoreTrivials(declRefExpr(to(parmVarDecl()))), ignoreTrivials(declRefExpr(to(parmVarDecl()))),
cxxThisExpr() cxxThisExpr(),
// We also allow dereferencing a constexpr variable here,
// since that will just end up with a reference to the
// compile-time-constant thing. Again, use ignoreTrivials()
// to stip off the LValueToRValue cast.
ignoreTrivials(declRefExpr(to(varDecl(isConstexpr()))))
) )
) )
) )

Просмотреть файл

@ -437,3 +437,28 @@ struct DisallowRefPtrTArrayElement {
test2(mArray[0]); // 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)}} test2(mArray[0]); // 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)}}
} }
}; };
struct AllowConstexprMembers {
static constexpr RefCountedBase* mRefCounted = nullptr;
MOZ_CAN_RUN_SCRIPT void foo() {
mRefCounted->method_test();
}
MOZ_CAN_RUN_SCRIPT void bar() {
test2(mRefCounted);
}
MOZ_CAN_RUN_SCRIPT void baz() {
test_ref(*mRefCounted);
}
};
MOZ_CAN_RUN_SCRIPT void test_constexpr_1() {
AllowConstexprMembers::mRefCounted->method_test();
}
MOZ_CAN_RUN_SCRIPT void test_constexpr_2() {
test2(AllowConstexprMembers::mRefCounted);
}
MOZ_CAN_RUN_SCRIPT void test_constexpr_3() {
test_ref(*AllowConstexprMembers::mRefCounted);
}