Bug 1748874 - Part 5: Require CAN_RUN_SCRIPT to be at the first declaration r=andi

Depends on D135404

Differential Revision: https://phabricator.services.mozilla.com/D135405
This commit is contained in:
Kagami Sascha Rosylight 2022-01-11 11:52:27 +00:00
parent 1ae5ee832f
commit 901a35ec10
4 changed files with 23 additions and 2 deletions

View File

@ -244,6 +244,21 @@ void FuncSetCallback::run(const MatchFinder::MatchResult &Result) {
return;
} else {
Func = Result.Nodes.getNodeAs<FunctionDecl>("canRunScriptFunction");
const char *ErrorAttrInDefinition =
"MOZ_CAN_RUN_SCRIPT must be put in front "
"of the declaration, not the definition";
const char *NoteAttrInDefinition = "The first declaration exists here";
if (!Func->isFirstDecl() &&
!hasCustomAttribute<moz_can_run_script_for_definition>(Func)) {
const FunctionDecl *FirstDecl = Func->getFirstDecl();
if (!hasCustomAttribute<moz_can_run_script>(FirstDecl)) {
Checker.diag(Func->getLocation(), ErrorAttrInDefinition,
DiagnosticIDs::Error);
Checker.diag(FirstDecl->getLocation(), NoteAttrInDefinition,
DiagnosticIDs::Note);
}
}
}
CanRunScriptFuncs.insert(Func);

View File

@ -1,5 +1,6 @@
ATTR(moz_allow_temporary)
ATTR(moz_can_run_script)
ATTR(moz_can_run_script_for_definition)
ATTR(moz_can_run_script_boundary)
ATTR(moz_global_class)
ATTR(moz_heap_allocator)

View File

@ -652,3 +652,7 @@ struct DisallowMozKnownLiveMemberNotFromKnownLive {
foo(mMember->mWhatever); // expected-error {{arguments must all be strong refs or caller's parameters when calling a function marked as MOZ_CAN_RUN_SCRIPT (including the implicit object argument). 'mMember->mWhatever' is neither.}}
}
};
void IncorrectlyUnmarkedEarlyDeclaration(); // expected-note {{The first declaration exists here}}
MOZ_CAN_RUN_SCRIPT void IncorrectlyUnmarkedEarlyDeclaration() {}; // expected-error {{MOZ_CAN_RUN_SCRIPT must be put in front of the declaration, not the definition}}

View File

@ -706,8 +706,9 @@
# if defined(MOZ_CLANG_PLUGIN) || defined(XGILL_PLUGIN)
# define MOZ_CAN_RUN_SCRIPT __attribute__((annotate("moz_can_run_script")))
# define MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION \
__attribute__((annotate("moz_can_run_script")))
# define MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION \
__attribute__((annotate("moz_can_run_script"))) \
__attribute__((annotate("moz_can_run_script_for_definition")))
# define MOZ_CAN_RUN_SCRIPT_BOUNDARY \
__attribute__((annotate("moz_can_run_script_boundary")))
# define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override")))