1
Fork 0

Take CodegenFnAttrs into account when validating asm! register operands

Checking of asm! register operands now properly takes function
attributes such as #[target_feature] and #[instruction_set] into
account.
This commit is contained in:
Amanieu d'Antras 2022-02-17 18:16:04 +00:00
parent 1ceb104851
commit fc41d4bf35
9 changed files with 176 additions and 192 deletions

View file

@ -87,6 +87,7 @@ pub fn provide(providers: &mut Providers) {
static_mutability,
generator_kind,
codegen_fn_attrs,
asm_target_features,
collect_mod_item_types,
should_inherit_track_caller,
..*providers
@ -3255,6 +3256,24 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
codegen_fn_attrs
}
/// Computes the set of target features used in a function for the purposes of
/// inline assembly.
fn asm_target_features<'tcx>(tcx: TyCtxt<'tcx>, id: DefId) -> &'tcx FxHashSet<Symbol> {
let mut target_features = tcx.sess.target_features.clone();
let attrs = tcx.codegen_fn_attrs(id);
target_features.extend(&attrs.target_features);
match attrs.instruction_set {
None => {}
Some(InstructionSetAttr::ArmA32) => {
target_features.remove(&sym::thumb_mode);
}
Some(InstructionSetAttr::ArmT32) => {
target_features.insert(sym::thumb_mode);
}
}
tcx.arena.alloc(target_features)
}
/// Checks if the provided DefId is a method in a trait impl for a trait which has track_caller
/// applied to the method prototype.
fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool {