Skip to content

Commit 9fc1242

Browse files
committed
only enable/disable aarch64 flags that are not already globally enabled
1 parent 9e7dae7 commit 9fc1242

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

compiler/rustc_codegen_ssa/src/mir/naked_asm.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ fn enable_disable_target_features<'tcx>(
188188
// https://developer.arm.com/documentation/100067/0611/armclang-Integrated-Assembler/AArch32-Target-selection-directives?lang=en
189189

190190
for feature in features {
191-
writeln!(begin, ".arch_extension {}", feature.name).unwrap();
191+
// only enable/disable a feature if it is not already globally enabled.
192+
// so that we don't infuence subsequent asm blocks
193+
if !tcx.sess.unstable_target_features.contains(&feature.name) {
194+
writeln!(begin, ".arch_extension {}", feature.name).unwrap();
192195

193-
// aarch does not have the push/pop mechanism like riscv below.
194-
//
195-
// > The .arch_extension directive is effective until the end of the assembly block and is not propagated to subsequent code
196-
//
197-
// https://github.com/taiki-e/portable-atomic/blob/75a36c33b38c4c68f4095e95f106cfbedce9a914/src/imp/atomic128/aarch64.rs#L330
196+
writeln!(end, ".arch_extension no{}", feature.name).unwrap();
197+
}
198198
}
199199
}
200200
Architecture::Riscv32 | Architecture::Riscv64 => {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//@ add-core-stubs
2+
//@ assembly-output: emit-asm
3+
//@ compile-flags: --target aarch64-unknown-linux-gnu -Ctarget-feature=+lse
4+
//@ needs-llvm-components: aarch64
5+
6+
#![crate_type = "lib"]
7+
#![feature(no_core, naked_functions)]
8+
#![no_core]
9+
10+
extern crate minicore;
11+
use minicore::*;
12+
13+
// check that a naked function using target features does not disable these features for subsequent
14+
// asm blocks.
15+
16+
// CHECK-LABEL: a:
17+
#[no_mangle]
18+
#[naked]
19+
#[target_feature(enable = "lse")]
20+
unsafe extern "C" fn a() {
21+
naked_asm!("casp x2, x3, x2, x3, [x1]")
22+
}
23+
24+
// CHECK-LABEL: b:
25+
#[no_mangle]
26+
#[naked]
27+
unsafe extern "C" fn b() {
28+
naked_asm!("casp x2, x3, x2, x3, [x1]")
29+
}

0 commit comments

Comments
 (0)