Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 520e218

Browse files
committedMar 17, 2025
rustc_target: Add target feature constraints for LoongArch
Part of #116344
1 parent c3dd4ee commit 520e218

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
 

‎compiler/rustc_target/src/target_features.rs

+22
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,28 @@ impl Target {
923923
_ => unreachable!(),
924924
}
925925
}
926+
"loongarch64" => {
927+
// LoongArch handles ABI in a very sane way, being fully explicit via `llvm_abiname`
928+
// about what the intended ABI is.
929+
match &*self.llvm_abiname {
930+
"ilp32d" | "lp64d" => {
931+
// Requires d (which implies f), incompatible with nothing.
932+
FeatureConstraints { required: &["d"], incompatible: &[] }
933+
}
934+
"ilp32f" | "lp64f" => {
935+
// Requires f, incompatible with nothing.
936+
FeatureConstraints { required: &["f"], incompatible: &[] }
937+
}
938+
"ilp32s" | "lp64s" => {
939+
// The soft-float ABI does not require any features and is also not
940+
// incompatible with any features. Rust targets explicitly specify the
941+
// LLVM ABI names, which allows for enabling hard-float support even on
942+
// soft-float targets, and ensures that the ABI behavior is as expected.
943+
NOTHING
944+
}
945+
_ => unreachable!(),
946+
}
947+
}
926948
_ => NOTHING,
927949
}
928950
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ compile-flags: --target=loongarch64-unknown-linux-gnu --crate-type=lib
2+
//@ needs-llvm-components: loongarch
3+
//@ compile-flags: -Ctarget-feature=-d
4+
//@ min-llvm-version: 20
5+
// For now this is just a warning.
6+
//@ build-pass
7+
//@error-pattern: must be enabled to ensure that the ABI
8+
#![feature(no_core, lang_items)]
9+
#![no_core]
10+
11+
#[lang = "sized"]
12+
pub trait Sized {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
warning: target feature `d` must be enabled to ensure that the ABI of the current target can be implemented correctly
2+
|
3+
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4+
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
5+
6+
warning: unstable feature specified for `-Ctarget-feature`: `d`
7+
|
8+
= note: this feature is not stably supported; its behavior can change in the future
9+
10+
warning: both target-abi and the triple-implied ABI are invalid, ignoring and using feature-implied ABI
11+
warning: 'lp64f' has not been standardized
12+
warning: 2 warnings emitted
13+

0 commit comments

Comments
 (0)
Failed to load comments.