Skip to content

Commit 9d7d782

Browse files
Rollup merge of #140460 - heiher:issue-140455, r=Urgau
Fix handling of LoongArch target features not supported by LLVM 19 Fixes #140455
2 parents 96faee4 + 482ad5c commit 9d7d782

File tree

6 files changed

+25
-18
lines changed

6 files changed

+25
-18
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+6
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
273273
("aarch64", "fpmr") => None, // only existed in 18
274274
("arm", "fp16") => Some(LLVMFeature::new("fullfp16")),
275275
// Filter out features that are not supported by the current LLVM version
276+
("loongarch64", "div32" | "lam-bh" | "lamcas" | "ld-seq-sa" | "scq")
277+
if get_version().0 < 20 =>
278+
{
279+
None
280+
}
281+
// Filter out features that are not supported by the current LLVM version
276282
("riscv32" | "riscv64", "zacas") if get_version().0 < 20 => None,
277283
// Enable the evex512 target feature if an avx512 target feature is enabled.
278284
("x86", s) if s.starts_with("avx512") => {

compiler/rustc_target/src/target_features.rs

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ impl Stability {
102102
// check whether they're named already elsewhere in rust
103103
// e.g. in stdarch and whether the given name matches LLVM's
104104
// if it doesn't, to_llvm_feature in llvm_util in rustc_codegen_llvm needs to be adapted.
105+
// Additionally, if the feature is not available in older version of LLVM supported by the current
106+
// rust, the same function must be updated to filter out these features to avoid triggering
107+
// warnings.
105108
//
106109
// Also note that all target features listed here must be purely additive: for target_feature 1.1 to
107110
// be sound, we can never allow features like `+soft-float` (on x86) to be controlled on a

tests/ui/abi/compatibility.rs

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
//@ revisions: loongarch64
4141
//@[loongarch64] compile-flags: --target loongarch64-unknown-linux-gnu
4242
//@[loongarch64] needs-llvm-components: loongarch
43-
//@[loongarch64] min-llvm-version: 20
4443
//FIXME: wasm is disabled due to <https://github.com/rust-lang/rust/issues/115666>.
4544
//FIXME @ revisions: wasm
4645
//FIXME @[wasm] compile-flags: --target wasm32-unknown-unknown

tests/ui/asm/loongarch/bad-reg.loongarch64_lp64d.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm
2-
--> $DIR/bad-reg.rs:23:18
2+
--> $DIR/bad-reg.rs:22:18
33
|
44
LL | asm!("", out("$r0") _);
55
| ^^^^^^^^^^^^
66

77
error: invalid register `$tp`: reserved for TLS
8-
--> $DIR/bad-reg.rs:25:18
8+
--> $DIR/bad-reg.rs:24:18
99
|
1010
LL | asm!("", out("$tp") _);
1111
| ^^^^^^^^^^^^
1212

1313
error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm
14-
--> $DIR/bad-reg.rs:27:18
14+
--> $DIR/bad-reg.rs:26:18
1515
|
1616
LL | asm!("", out("$sp") _);
1717
| ^^^^^^^^^^^^
1818

1919
error: invalid register `$r21`: reserved by the ABI
20-
--> $DIR/bad-reg.rs:29:18
20+
--> $DIR/bad-reg.rs:28:18
2121
|
2222
LL | asm!("", out("$r21") _);
2323
| ^^^^^^^^^^^^^
2424

2525
error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm
26-
--> $DIR/bad-reg.rs:31:18
26+
--> $DIR/bad-reg.rs:30:18
2727
|
2828
LL | asm!("", out("$fp") _);
2929
| ^^^^^^^^^^^^
3030

3131
error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm
32-
--> $DIR/bad-reg.rs:33:18
32+
--> $DIR/bad-reg.rs:32:18
3333
|
3434
LL | asm!("", out("$r31") _);
3535
| ^^^^^^^^^^^^^

tests/ui/asm/loongarch/bad-reg.loongarch64_lp64s.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm
2-
--> $DIR/bad-reg.rs:23:18
2+
--> $DIR/bad-reg.rs:22:18
33
|
44
LL | asm!("", out("$r0") _);
55
| ^^^^^^^^^^^^
66

77
error: invalid register `$tp`: reserved for TLS
8-
--> $DIR/bad-reg.rs:25:18
8+
--> $DIR/bad-reg.rs:24:18
99
|
1010
LL | asm!("", out("$tp") _);
1111
| ^^^^^^^^^^^^
1212

1313
error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm
14-
--> $DIR/bad-reg.rs:27:18
14+
--> $DIR/bad-reg.rs:26:18
1515
|
1616
LL | asm!("", out("$sp") _);
1717
| ^^^^^^^^^^^^
1818

1919
error: invalid register `$r21`: reserved by the ABI
20-
--> $DIR/bad-reg.rs:29:18
20+
--> $DIR/bad-reg.rs:28:18
2121
|
2222
LL | asm!("", out("$r21") _);
2323
| ^^^^^^^^^^^^^
2424

2525
error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm
26-
--> $DIR/bad-reg.rs:31:18
26+
--> $DIR/bad-reg.rs:30:18
2727
|
2828
LL | asm!("", out("$fp") _);
2929
| ^^^^^^^^^^^^
3030

3131
error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm
32-
--> $DIR/bad-reg.rs:33:18
32+
--> $DIR/bad-reg.rs:32:18
3333
|
3434
LL | asm!("", out("$r31") _);
3535
| ^^^^^^^^^^^^^
3636

3737
error: register class `freg` requires at least one of the following target features: d, f
38-
--> $DIR/bad-reg.rs:37:26
38+
--> $DIR/bad-reg.rs:36:26
3939
|
4040
LL | asm!("/* {} */", in(freg) f);
4141
| ^^^^^^^^^^
4242

4343
error: register class `freg` requires at least one of the following target features: d, f
44-
--> $DIR/bad-reg.rs:39:26
44+
--> $DIR/bad-reg.rs:38:26
4545
|
4646
LL | asm!("/* {} */", out(freg) _);
4747
| ^^^^^^^^^^^
4848

4949
error: register class `freg` requires at least one of the following target features: d, f
50-
--> $DIR/bad-reg.rs:41:26
50+
--> $DIR/bad-reg.rs:40:26
5151
|
5252
LL | asm!("/* {} */", in(freg) d);
5353
| ^^^^^^^^^^
5454

5555
error: register class `freg` requires at least one of the following target features: d, f
56-
--> $DIR/bad-reg.rs:43:26
56+
--> $DIR/bad-reg.rs:42:26
5757
|
5858
LL | asm!("/* {} */", out(freg) d);
5959
| ^^^^^^^^^^^

tests/ui/asm/loongarch/bad-reg.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//@ add-core-stubs
22
//@ needs-asm-support
33
//@ revisions: loongarch64_lp64d loongarch64_lp64s
4-
//@ min-llvm-version: 20
54
//@[loongarch64_lp64d] compile-flags: --target loongarch64-unknown-linux-gnu
65
//@[loongarch64_lp64d] needs-llvm-components: loongarch
76
//@[loongarch64_lp64s] compile-flags: --target loongarch64-unknown-none-softfloat

0 commit comments

Comments
 (0)