Skip to content

Commit 9545845

Browse files
Rollup merge of #156901 - Zalathar:needs-asm-ret, r=folkertdev
compiletest: Simplify `//@ needs-asm-mnemonic: ret` to just `//@ needs-asm-ret` - Simplification of #155692. --- The `needs-asm-mnemonic` directive was very general, but in practice was only being used for `ret`. There are very few other mnemonics that it could plausibly be useful for (e.g. `nop`), because any instruction that requires arguments is probably going to be non-portable. This PR replaces `needs-asm-mnemonic` with a simpler `needs-asm-ret` directive that uses the same machinery as other simple needs directives. If we happend to need more mnemonics in the future, we can just add more simple directives as appropriate (e.g. `needs-asm-nop`).
2 parents 95a3f83 + 028b8b6 commit 9545845

9 files changed

Lines changed: 27 additions & 77 deletions

File tree

src/doc/rustc-dev-guide/src/tests/compiletest.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,6 @@ See also the [codegen tests](#codegen-tests) for a similar set of tests.
346346
If you need to work with `#![no_std]` cross-compiling tests, consult the
347347
[`minicore` test auxiliary](./minicore.md) chapter.
348348

349-
#### Conditional assembly tests based on instruction support
350-
351-
Tests that depend on specific assembly instructions being available can use the
352-
`//@ needs-asm-mnemonic: <MNEMONIC>` directive.
353-
This will skip the test if the target backend does not support the specified instruction mnemonic.
354-
355-
For example, a test that requires the `RET` instruction:
356-
```rust,ignore
357-
//@ needs-asm-mnemonic: RET
358-
```
359-
360349
[`tests/assembly-llvm`]: https://github.com/rust-lang/rust/tree/HEAD/tests/assembly-llvm
361350

362351

src/doc/rustc-dev-guide/src/tests/directives.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ The following directives will check rustc build settings and target settings:
164164
For tests that cross-compile to explicit targets
165165
via `--target`, use `needs-llvm-components` instead to ensure the appropriate
166166
backend is available.
167-
- `needs-asm-mnemonic: <MNEMONIC>` — ignores if the target backend does not
168-
support the specified assembly mnemonic (e.g., `RET`, `NOP`).
169-
Only supported with the LLVM backend.
167+
- `needs-asm-ret` - ignores if the target does not have a `ret` instruction
168+
in its assembly syntax. Most target architectures have this instruction,
169+
making it handy for portable inline-assembly tests, but some architectures
170+
(e.g. 32-bit ARM) do not have it.
170171
- `needs-profiler-runtime` — ignores the test if the profiler runtime was not
171172
enabled for the target (`build.profiler = true` in `bootstrap.toml`)
172173
- `needs-sanitizer-support` — ignores if the sanitizer support was not enabled

src/tools/compiletest/src/directives/directive_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub(crate) const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
159159
"min-llvm-version",
160160
"min-system-llvm-version",
161161
"minicore-compile-flags",
162-
"needs-asm-mnemonic",
162+
"needs-asm-ret",
163163
"needs-asm-support",
164164
"needs-backends",
165165
"needs-crate-type",

src/tools/compiletest/src/directives/needs.rs

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -101,37 +101,6 @@ pub(super) fn handle_needs(
101101
}
102102
}
103103

104-
if name == "needs-asm-mnemonic" {
105-
let Some(rest) = ln.value_after_colon() else {
106-
return IgnoreDecision::Error {
107-
message: "expected `needs-asm-mnemonic` to have a mnemonic name after colon"
108-
.to_string(),
109-
};
110-
};
111-
112-
if !config.default_codegen_backend.is_llvm() {
113-
return IgnoreDecision::Ignore {
114-
reason: "skipping test as non-LLVM backend does not support mnemonic queries"
115-
.to_string(),
116-
};
117-
}
118-
119-
let mnemonic = rest.trim();
120-
let has_mnemonic = match mnemonic {
121-
"ret" => conditions.has_ret_mnemonic,
122-
"nop" => conditions.has_nop_mnemonic,
123-
_ => has_mnemonic(config, mnemonic),
124-
};
125-
126-
if has_mnemonic {
127-
return IgnoreDecision::Continue;
128-
} else {
129-
return IgnoreDecision::Ignore {
130-
reason: format!("skipping test as target does not have `{mnemonic}` mnemonic"),
131-
};
132-
}
133-
}
134-
135104
// Handled elsewhere.
136105
if name == "needs-llvm-components" || name == "needs-backends" {
137106
return IgnoreDecision::Continue;
@@ -163,11 +132,6 @@ struct Need {
163132
pub(crate) struct PreparedNeedsConditions {
164133
/// The `//@ needs-*` conditions that can be treated as a simple name->boolean mapping.
165134
simple_needs: HashMap<&'static str, Need>,
166-
167-
/// Might add particular other mnemonics heavily needed by tests here.
168-
/// Otherwise call into llvm for every check
169-
has_ret_mnemonic: bool,
170-
has_nop_mnemonic: bool,
171135
}
172136

173137
pub(crate) fn prepare_needs_conditions(config: &Config) -> PreparedNeedsConditions {
@@ -177,6 +141,14 @@ pub(crate) fn prepare_needs_conditions(config: &Config) -> PreparedNeedsConditio
177141
// Note that we intentionally still put the needs- prefix here to make the file show up when
178142
// grepping for a directive name, even though we could technically strip that.
179143
let simple_needs = vec![
144+
// This used to be a more general `//@ needs-asm-mnemonic: ret` directive,
145+
// but was simplified to just `//@ needs-asm-ret` because there are very
146+
// few other mnemonics (`nop`?) that it could ever be useful with.
147+
Need {
148+
name: "needs-asm-ret",
149+
condition: has_mnemonic(config, "ret"),
150+
ignore_reason: "ignored on targets without a `ret` assembly instruction",
151+
},
180152
Need {
181153
name: "needs-asm-support",
182154
condition: config.has_asm_support(),
@@ -398,11 +370,7 @@ pub(crate) fn prepare_needs_conditions(config: &Config) -> PreparedNeedsConditio
398370
})
399371
.collect::<HashMap<_, _>>();
400372

401-
PreparedNeedsConditions {
402-
simple_needs,
403-
has_ret_mnemonic: has_mnemonic(config, "ret"),
404-
has_nop_mnemonic: has_mnemonic(config, "nop"),
405-
}
373+
PreparedNeedsConditions { simple_needs }
406374
}
407375

408376
fn find_dlltool(config: &Config) -> bool {

src/tools/compiletest/src/directives/tests.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,23 +1270,15 @@ fn test_edition_range_edition_to_test() {
12701270
}
12711271

12721272
#[test]
1273-
fn needs_asm_mnemonic() {
1273+
fn needs_asm_ret() {
12741274
let config_x86_64 = cfg().target("x86_64-unknown-linux-gnu").build();
12751275
let config_aarch64 = cfg().target("aarch64-unknown-linux-gnu").build();
1276-
1277-
// invalid mnemonic
1278-
assert!(check_ignore(&config_x86_64, "//@ needs-asm-mnemonic:GRUGGY"));
1279-
assert!(check_ignore(&config_aarch64, "//@ needs-asm-mnemonic:gruggy"));
1280-
1281-
// valid x86 and aarch64
1282-
assert!(!check_ignore(&config_x86_64, "//@ needs-asm-mnemonic:RET"));
1283-
assert!(!check_ignore(&config_aarch64, "//@ needs-asm-mnemonic:ret"));
1284-
1285-
// this is aarch64 specific
1286-
assert!(check_ignore(&config_x86_64, "//@ needs-asm-mnemonic:ldrsbwui"));
1287-
assert!(!check_ignore(&config_aarch64, "//@ needs-asm-mnemonic:LDRSBWui"));
1288-
1289-
// this is x86 specific
1290-
assert!(check_ignore(&config_aarch64, "//@ needs-asm-mnemonic:CMPxCHG16B"));
1291-
assert!(!check_ignore(&config_x86_64, "//@ needs-asm-mnemonic:CMPXchg16B"));
1276+
// 32-bit ARM does not have a "ret" mnemonic.
1277+
let config_arm32 = cfg().target("armv7a-none-eabi").build();
1278+
let config_wasm = cfg().target("wasm32v1-none").build();
1279+
1280+
assert!(!check_ignore(&config_x86_64, "//@ needs-asm-ret"));
1281+
assert!(!check_ignore(&config_aarch64, "//@ needs-asm-ret"));
1282+
assert!(check_ignore(&config_arm32, "//@ needs-asm-ret"));
1283+
assert!(check_ignore(&config_wasm, "//@ needs-asm-ret"));
12921284
}

tests/codegen-llvm/cffi/c-variadic-naked.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ needs-asm-support
2-
//@ needs-asm-mnemonic: ret
2+
//@ needs-asm-ret
33

44
// tests that `va_start` is not injected into naked functions
55

tests/codegen-llvm/naked-fn/aligned.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ compile-flags: -C no-prepopulate-passes -Copt-level=0
22
//@ needs-asm-support
3-
//@ needs-asm-mnemonic: ret
3+
//@ needs-asm-ret
44
//@ ignore-wasm32 aligning functions is not currently supported on wasm (#143368)
55

66
#![crate_type = "lib"]

tests/codegen-llvm/naked-fn/min-function-alignment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ compile-flags: -C no-prepopulate-passes -Copt-level=0 -Zmin-function-alignment=16
22
//@ needs-asm-support
3-
//@ needs-asm-mnemonic: ret
3+
//@ needs-asm-ret
44
//@ ignore-wasm32 aligning functions is not currently supported on wasm (#143368)
55

66
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity

tests/run-make/naked-dead-code-elimination/rmake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ ignore-cross-compile
22
//@ needs-asm-support
3-
//@ needs-asm-mnemonic: RET
3+
//@ needs-asm-ret
44

55
use run_make_support::symbols::object_contains_any_symbol;
66
use run_make_support::{bin_name, rustc};

0 commit comments

Comments
 (0)