|
| 1 | +// This tests that target-cpu correctly enables additional features for some Arm targets. |
| 2 | +// These targets were originally defined in such a way that features provided by target-cpu would be |
| 3 | +// disabled by the target spec itself. This was fixed in #123159. |
| 4 | + |
| 5 | +// FIXME: This test should move to tests/assembly when building without #![no_core] in |
| 6 | +// that environment is possible, tracked by #130375. |
| 7 | + |
| 8 | +use run_make_support::{llvm_filecheck, llvm_objdump, rustc, static_lib_name}; |
| 9 | + |
| 10 | +struct TestCase { |
| 11 | + target: &'static str, |
| 12 | + cpu: &'static str, |
| 13 | +} |
| 14 | + |
| 15 | +static CASES: &[TestCase] = &[ |
| 16 | + TestCase { target: "thumbv7em-none-eabihf", cpu: "cortex-m7" }, |
| 17 | + TestCase { target: "thumbv8m.main-none-eabihf", cpu: "cortex-m85" }, |
| 18 | +]; |
| 19 | + |
| 20 | +fn main() { |
| 21 | + for case in CASES { |
| 22 | + let lib = static_lib_name(case.cpu); |
| 23 | + let checks = format!("{}.checks", case.cpu); |
| 24 | + |
| 25 | + let rustc_command = || { |
| 26 | + let mut cmd = rustc(); |
| 27 | + cmd.edition("2021") |
| 28 | + .target(case.target) |
| 29 | + .arg("-Copt-level=3") |
| 30 | + .crate_type("rlib") |
| 31 | + .input("lib.rs") |
| 32 | + .output(&lib); |
| 33 | + cmd |
| 34 | + }; |
| 35 | + |
| 36 | + let objdump_command = || { |
| 37 | + let mut cmd = llvm_objdump(); |
| 38 | + cmd.arg("--arch-name=arm") |
| 39 | + .arg(format!("--mcpu={}", case.cpu)) |
| 40 | + .disassemble() |
| 41 | + .input(&lib); |
| 42 | + cmd |
| 43 | + }; |
| 44 | + |
| 45 | + // First, run without target-cpu and confirm that it fails. |
| 46 | + rustc_command().run(); |
| 47 | + let dis = objdump_command().run().stdout_utf8(); |
| 48 | + llvm_filecheck().patterns(&checks).stdin_buf(dis).run_fail(); |
| 49 | + |
| 50 | + // Then, run with target-cpu and confirm that it succeeds. |
| 51 | + rustc_command().arg(format!("-Ctarget-cpu={}", case.cpu)).run(); |
| 52 | + let dis = objdump_command().run().stdout_utf8(); |
| 53 | + llvm_filecheck().patterns(&checks).stdin_buf(dis).run(); |
| 54 | + } |
| 55 | +} |
0 commit comments