Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
"fp16" => Some(LLVMFeature::new("fullfp16")),
s => Some(LLVMFeature::new(s)),
},

Arch::Bpf => match s {
"allows-misaligned-mem-access" if major < 22 => None,
s => Some(LLVMFeature::new(s)),
},
// Filter out features that are not supported by the current LLVM version
Arch::LoongArch32 | Arch::LoongArch64 => match s {
"32s" if major < 21 => None,
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,10 @@ static WASM_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-end
];

const BPF_FEATURES: &[(&str, Stability, ImpliedFeatures)] =
&[("alu32", Unstable(sym::bpf_target_feature), &[])];
const BPF_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("alu32", Unstable(sym::bpf_target_feature), &[]),
("allows-misaligned-mem-access", Unstable(sym::bpf_target_feature), &[]),
];

static CSKY_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ const TARGET_FEATURE_IMPLICATIONS_RAW: &[(&str, &[&str])] = &[
("relaxed-simd", &["simd128"]),
// BPF
("alu32", &[]),
("allows-misaligned-mem-access", &[]),
// CSKY
("10e60", &["7e10"]),
("2e3", &["e2"]),
Expand Down
27 changes: 27 additions & 0 deletions tests/assembly-llvm/bpf_unaligned.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//@ add-minicore
//@ assembly-output: emit-asm
//@ compile-flags: --target bpfel-unknown-none -C target_feature=+allows-misaligned-mem-access
//@ min-llvm-version: 22
//@ needs-llvm-components: bpf
#![feature(no_core)]
#![crate_type = "rlib"]
#![no_core]

extern crate minicore;
use minicore::*;

// CHECK-LABEL: test_load_i64:
// CHECK: r0 = *(u64 *)(r1 + 0)
#[no_mangle]
pub unsafe fn test_load_i64(p: *const u64) -> u64 {
let mut tmp: u64 = 0;
copy_nonoverlapping(p as *const u8, &mut tmp as *mut u64 as *mut u8, 8);
tmp
}

// CHECK-LABEL: test_store_i64:
// CHECK: *(u64 *)(r1 + 0) = r2
#[no_mangle]
pub unsafe fn test_store_i64(p: *mut u64, v: u64) {
copy_nonoverlapping(&v as *const u64 as *const u8, p as *mut u8, 8);
}
4 changes: 4 additions & 0 deletions tests/auxiliary/minicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ trait Drop {
fn drop(&mut self);
}

#[rustc_nounwind]
#[rustc_intrinsic]
pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);

pub mod mem {
#[rustc_nounwind]
#[rustc_intrinsic]
Expand Down
11 changes: 11 additions & 0 deletions tests/codegen-llvm/bpf-allows-unaligned.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@ only-bpf
#![crate_type = "lib"]
#![feature(bpf_target_feature)]
#![no_std]

#[no_mangle]
#[target_feature(enable = "allows-misaligned-mem-access")]
// CHECK: define noundef zeroext i8 @foo(i8 noundef returned %arg) unnamed_addr #0 {
pub unsafe fn foo(arg: u8) -> u8 {
arg
}
1 change: 1 addition & 0 deletions tests/ui/check-cfg/target_feature.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
`addsubiw`
`adx`
`aes`
`allows-misaligned-mem-access`
`altivec`
`alu32`
`amx-avx512`
Expand Down
Loading