Skip to content

Commit bc2244f

Browse files
Rollup merge of #129940 - liushuyu:s390x-target-features, r=RalfJung
s390x: Fix a regression related to backchain feature In #127506, we introduced a new IBM Z-specific target feature, `backchain`. This particular `target-feature` was available as a function-level attribute in LLVM 17 and below, so some hacks were used to avoid blowing up LLVM when querying the supported LLVM features. This led to an unfortunate regression where `cfg!(target-feature = "backchain")` will always return true. This pull request aims to fix this issue, and a test has been introduced to ensure it will never happen again. Fixes #129927. r? `@RalfJung`
2 parents d6a4298 + 6e4c5c1 commit bc2244f

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
353353
None
354354
}
355355
})
356-
.filter(|feature| {
357-
RUSTC_SPECIAL_FEATURES.contains(feature) || features.contains(&Symbol::intern(feature))
358-
})
356+
.filter(|feature| features.contains(&Symbol::intern(feature)))
359357
.map(|feature| Symbol::intern(feature))
360358
.collect()
361359
}
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//@ revisions: enable-backchain disable-backchain
2+
//@ assembly-output: emit-asm
3+
//@ compile-flags: -O --crate-type=lib --target=s390x-unknown-linux-gnu
4+
//@ needs-llvm-components: systemz
5+
//@[enable-backchain] compile-flags: -Ctarget-feature=+backchain
6+
//@[disable-backchain] compile-flags: -Ctarget-feature=-backchain
7+
#![feature(no_core, lang_items)]
8+
#![no_std]
9+
#![no_core]
10+
11+
#[lang = "sized"]
12+
trait Sized {}
13+
14+
extern "C" {
15+
fn extern_func();
16+
}
17+
18+
// CHECK-LABEL: test_backchain
19+
#[no_mangle]
20+
extern "C" fn test_backchain() -> i32 {
21+
// Here we try to match if backchain register is saved to the parameter area (stored in r15/sp)
22+
// And also if a new parameter area (160 bytes) is allocated for the upcoming function call
23+
// enable-backchain: lgr [[REG1:.*]], %r15
24+
// enable-backchain-NEXT: aghi %r15, -160
25+
// enable-backchain: stg [[REG1]], 0(%r15)
26+
// disable-backchain: aghi %r15, -160
27+
// disable-backchain-NOT: stg %r{{.*}}, 0(%r15)
28+
unsafe {
29+
extern_func();
30+
}
31+
// enable-backchain-NEXT: brasl %r{{.*}}, extern_func@PLT
32+
// disable-backchain: brasl %r{{.*}}, extern_func@PLT
33+
34+
// Make sure that the expected return value is written into %r2 (return register):
35+
// enable-backchain-NEXT: lghi %r2, 1
36+
// disable-backchain: lghi %r2, 0
37+
#[cfg(target_feature = "backchain")]
38+
{
39+
1
40+
}
41+
#[cfg(not(target_feature = "backchain"))]
42+
{
43+
0
44+
}
45+
// CHECK: br %r{{.*}}
46+
}

0 commit comments

Comments
 (0)