Skip to content

Commit 21aea26

Browse files
committed
Added tests
1 parent 64e69b8 commit 21aea26

10 files changed

Lines changed: 124 additions & 11 deletions

File tree

compiler/rustc_interface/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ pub struct IgnoringOutDir;
114114
#[diag("can't use option `-o` or `--emit` to write multiple output types to stdout")]
115115
pub struct MultipleOutputTypesToStdout;
116116

117+
#[derive(Diagnostic)]
118+
#[diag("packedstack with backchain needs softfloat")]
119+
#[note(
120+
"enabling both `packedstack` and `backchain` attributes is incompatible with the default s390x target. Switch to s390x-unknown-none-softfloat if you need both attributes!"
121+
)]
122+
pub struct PackedStackBackchainNeedsSoftfloat;
123+
117124
#[derive(Diagnostic)]
118125
#[diag(
119126
"target feature `{$feature}` must be {$enabled} to ensure that the ABI of the current target can be implemented correctly"

compiler/rustc_interface/src/util.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_session::{EarlyDiagCtxt, Session, filesearch};
2525
use rustc_span::edition::Edition;
2626
use rustc_span::source_map::SourceMapInputs;
2727
use rustc_span::{SessionGlobals, Symbol, sym};
28-
use rustc_target::spec::Target;
28+
use rustc_target::spec::{Abi, Arch, Target};
2929
use tracing::info;
3030

3131
use crate::errors;
@@ -96,6 +96,16 @@ pub(crate) fn check_abi_required_features(sess: &Session) {
9696
sess.dcx().emit_warn(errors::AbiRequiredTargetFeature { feature, enabled: "disabled" });
9797
}
9898
}
99+
100+
// we need to have access to the complete constructed `target` and the session options.
101+
// this is the first place in the `run_compiler` flow where all this is available
102+
if sess.target.arch == Arch::S390x
103+
&& sess.opts.unstable_opts.packed_stack
104+
&& sess.unstable_target_features.contains(&Symbol::intern(&"backchain"))
105+
&& sess.target.abi != Abi::SoftFloat
106+
{
107+
sess.dcx().emit_err(errors::PackedStackBackchainNeedsSoftfloat);
108+
}
99109
}
100110

101111
pub static STACK_SIZE: OnceLock<usize> = OnceLock::new();

compiler/rustc_target/src/spec/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,16 +3258,6 @@ impl Target {
32583258
));
32593259
}
32603260
}
3261-
// If both `packed-stack` and `backchain` are set we need to use soft-float ABI.
3262-
if self.arch == Arch::S390x
3263-
&& features_enabled.contains("packed-stack")
3264-
&& features_enabled.contains("backchain")
3265-
&& !matches!(self.abi, Abi::SoftFloat)
3266-
{
3267-
return Err(format!(
3268-
"Enabling both `packed-stack` and `backchain` attributes is incompatible with the default s390x target. Switch to s390x-unknown-none-softfloat if you need both attributes."
3269-
));
3270-
}
32713261
}
32723262

32733263
Ok(())
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//@ add-minicore
2+
//@ revisions: enable-packedstack default-packedstack
3+
//@ assembly-output: emit-asm
4+
//@ compile-flags: -Copt-level=3 --crate-type=lib --target=s390x-unknown-linux-gnu -Cforce-unwind-tables=no
5+
//@ needs-llvm-components: systemz
6+
//@[enable-packedstack] compile-flags: -Zpacked-stack
7+
#![feature(no_core, lang_items)]
8+
#![no_std]
9+
#![no_core]
10+
11+
extern crate minicore;
12+
use minicore::*;
13+
14+
extern "C" {
15+
fn extern_func() -> i32;
16+
}
17+
18+
// CHECK-LABEL: test_packedstack
19+
#[no_mangle]
20+
extern "C" fn test_packedstack() -> i32 {
21+
// test the creation of call stack with and without packed-stack
22+
23+
// without packed-stack we always reserve a least the maximal space of 160 bytes
24+
// default-packedstack: stmg %r14, %r15, 112(%r15)
25+
// default-packedstack-NEXT: aghi %r15, -160
26+
// default-packedstack-NEXT: brasl %r14, extern_func
27+
28+
// with packed-stack only the actually needed registers are reserved on the stack
29+
// enable-packedstack: stmg %r14, %r15, 144(%r15)
30+
// enable-packedstack-NEXT: aghi %r15, -16
31+
// enable-packedstack-NEXT: brasl %r14, extern_func
32+
unsafe {
33+
extern_func();
34+
}
35+
1
36+
// CHECK: br %r{{.*}}
37+
}

tests/codegen-llvm/packedstack.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@ add-minicore
2+
//@ compile-flags: -Copt-level=3 --crate-type=lib --target=s390x-unknown-linux-gnu -Zpacked-stack
3+
//@ needs-llvm-components: systemz
4+
#![crate_type = "lib"]
5+
#![feature(no_core, lang_items)]
6+
#![no_core]
7+
8+
extern crate minicore;
9+
use minicore::*;
10+
11+
#[no_mangle]
12+
13+
pub fn test_packedstack() {
14+
// CHECK: @test_packedstack() unnamed_addr #0
15+
}
16+
// CHECK: attributes #0 = { {{.*}}"packed-stack"{{.*}} }

tests/ui/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,10 @@ Exercises operator overloading via [`std::ops`](https://doc.rust-lang.org/std/op
10701070

10711071
See [`repr(packed)` | Nomicon](https://doc.rust-lang.org/nomicon/other-reprs.html#reprpacked-reprpackedn).
10721072

1073+
## `tests/ui/packedstack/`
1074+
1075+
Tests different combinations that `-Zpacked-stack` will affect.
1076+
10731077
## `tests/ui/panic-handler/`
10741078

10751079
See [panic handler | Nomicon](https://doc.rust-lang.org/nomicon/panic-handler.html).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: unstable feature specified for `-Ctarget-feature`: `backchain`
2+
|
3+
= note: this feature is not stably supported; its behavior can change in the future
4+
5+
error: packedstack with backchain needs softfloat
6+
|
7+
= note: enabling both `packedstack` and `backchain` attributes is incompatible with the default s390x target. Switch to s390x-unknown-none-softfloat if you need both attributes!
8+
9+
error: aborting due to 1 previous error; 1 warning emitted
10+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//@ revisions: wrong_arch only_packedstack need_softfloat with_softfloat
2+
//@ compile-flags: -Zpacked-stack --crate-type=lib
3+
4+
//@ [wrong_arch] compile-flags: --target=x86_64-unknown-linux-gnu
5+
//@ [wrong_arch] needs-llvm-components: x86
6+
7+
//@ [only_packedstack] compile-flags: --target=s390x-unknown-linux-gnu
8+
//@ [only_packedstack] build-pass
9+
//@ [only_packedstack] needs-llvm-components: systemz
10+
11+
//@ [need_softfloat] compile-flags: -Ctarget-feature=+backchain --target=s390x-unknown-linux-gnu
12+
//@ [need_softfloat] check-fail
13+
//@ [need_softfloat] needs-llvm-components: systemz
14+
15+
//@ [with_softfloat] compile-flags: -Ctarget-feature=+backchain
16+
//@ [with_softfloat] compile-flags: --target=s390x-unknown-none-softfloat
17+
//@ [with_softfloat] build-pass
18+
//@ [with_softfloat] needs-llvm-components: systemz
19+
20+
//@ ignore-backends: gcc
21+
22+
#![feature(no_core)]
23+
#![crate_type = "rlib"]
24+
#![no_core]
25+
26+
//[wrong_arch]~? ERROR `-Zpacked-stack` is only supported on s390x
27+
//[need_softfloat]~? WARN unstable feature specified for `-Ctarget-feature`: `backchain`
28+
//[need_softfloat]~? ERROR packedstack with backchain needs softfloat
29+
//[with_softfloat]~? WARN unstable feature specified for `-Ctarget-feature`: `backchain`
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: unstable feature specified for `-Ctarget-feature`: `backchain`
2+
|
3+
= note: this feature is not stably supported; its behavior can change in the future
4+
5+
warning: 1 warning emitted
6+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: `-Zpacked-stack` is only supported on s390x
2+
3+
error: aborting due to 1 previous error
4+

0 commit comments

Comments
 (0)