Skip to content

Commit 1ce4d18

Browse files
committed
attempt to not let features escape for s390x
1 parent 7e763e9 commit 1ce4d18

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

compiler/rustc_codegen_ssa/src/mir/naked_asm.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ fn enable_disable_target_features<'tcx>(
223223
// https://sourceware.org/binutils/docs/as/s390-Directives.html
224224

225225
// based on src/llvm-project/llvm/lib/Target/SystemZ/SystemZFeatures.td
226-
let isa_revision_for_feature = |feature: &TargetFeature| match feature.name.as_str() {
226+
let isa_revision_for_feature_name = |feature_name| match feature_name {
227227
"backchain" => None, // does not define any instructions
228228
"deflate-conversion" => Some(13),
229229
"enhanced-sort" => Some(13),
@@ -240,13 +240,29 @@ fn enable_disable_target_features<'tcx>(
240240
_ => None,
241241
};
242242

243-
if let Some(minimum_isa) = features.filter_map(isa_revision_for_feature).max() {
243+
let target_feature_isa = features
244+
.filter_map(|feature| isa_revision_for_feature_name(feature.name.as_str()))
245+
.max();
246+
247+
if let Some(minimum_isa) = target_feature_isa {
244248
writeln!(begin, ".machine arch{minimum_isa}").unwrap();
245249

246-
// NOTE: LLVM does not currently support `.machine push` and `.machine pop`, so we rely on these
247-
// target features only being applied to this ASM block (LLVM clears them for the next)
250+
// NOTE: LLVM does not currently support `.machine push` and `.machine pop`
251+
// this is tracked in https://github.com/llvm/llvm-project/issues/129053.
252+
//
253+
// So instead we have to try revert to the previous state manually.
248254
//
249-
// https://github.com/llvm/llvm-project/issues/129053
255+
// However, this may still be observable if the user explicitly set the machine to
256+
// a higher value using global assembly.
257+
let global_isa = tcx
258+
.sess
259+
.unstable_target_features
260+
.iter()
261+
.filter_map(|feature| isa_revision_for_feature_name(feature.as_str()))
262+
.max()
263+
.unwrap_or(10);
264+
265+
writeln!(end, ".machine arch{global_isa}").unwrap();
250266
}
251267
}
252268
Architecture::PowerPc | Architecture::PowerPc64 => {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//@ add-core-stubs
2+
//@ compile-flags: --target s390x-unknown-linux-gnu
3+
//@ build-fail
4+
//@ needs-llvm-components: systemz
5+
6+
#![crate_type = "lib"]
7+
#![feature(no_core, naked_functions, s390x_target_feature)]
8+
#![no_core]
9+
10+
extern crate minicore;
11+
use minicore::*;
12+
13+
// check that a naked function using target features does not keep these features enabled
14+
// for subsequent asm blocks.
15+
16+
#[no_mangle]
17+
#[naked]
18+
#[target_feature(enable = "vector-packed-decimal")]
19+
unsafe extern "C" fn a() {
20+
naked_asm!("vlrlr %v24, %r3, 0(%r2)")
21+
}
22+
23+
#[no_mangle]
24+
#[naked]
25+
unsafe extern "C" fn b() {
26+
naked_asm!("vlrlr %v24, %r3, 0(%r2)")
27+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: instruction requires: vector-packed-decimal
2+
|
3+
note: instantiated into assembly here
4+
--> <inline asm>:16:1
5+
|
6+
LL | vlrlr %v24, %r3, 0(%r2)
7+
| ^
8+
9+
error: instruction requires: vector-packed-decimal
10+
|
11+
note: instantiated into assembly here
12+
--> <inline asm>:16:1
13+
|
14+
LL | vlrlr %v24, %r3, 0(%r2)
15+
| ^
16+
17+
error: aborting due to 2 previous errors
18+

0 commit comments

Comments
 (0)