Skip to content

mark arm intrinsics as safe #1716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
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
18,651 changes: 7,907 additions & 10,744 deletions crates/core_arch/src/aarch64/neon/generated.rs

Large diffs are not rendered by default.

149 changes: 72 additions & 77 deletions crates/core_arch/src/aarch64/neon/mod.rs

Large diffs are not rendered by default.

17,545 changes: 7,180 additions & 10,365 deletions crates/core_arch/src/arm_shared/neon/generated.rs

Large diffs are not rendered by default.

1,320 changes: 706 additions & 614 deletions crates/core_arch/src/arm_shared/neon/mod.rs

Large diffs are not rendered by default.

1,979 changes: 690 additions & 1,289 deletions crates/stdarch-gen-arm/spec/neon/aarch64.spec.yml

Large diffs are not rendered by default.

1,275 changes: 450 additions & 825 deletions crates/stdarch-gen-arm/spec/neon/arm_shared.spec.yml

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions crates/stdarch-gen-arm/src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ pub struct FnCall(
/// Function turbofish arguments
#[serde(default)]
pub Vec<Expression>,
/// Function requires unsafe wrapper
#[serde(default)]
pub bool,
);

impl FnCall {
pub fn new_expression(fn_ptr: Expression, arguments: Vec<Expression>) -> Expression {
FnCall(Box::new(fn_ptr), arguments, Vec::new()).into()
FnCall(Box::new(fn_ptr), arguments, Vec::new(), false).into()
}

pub fn new_unsafe_expression(fn_ptr: Expression, arguments: Vec<Expression>) -> Expression {
FnCall(Box::new(fn_ptr), arguments, Vec::new(), true).into()
}

pub fn is_llvm_link_call(&self, llvm_link_name: &String) -> bool {
Expand Down Expand Up @@ -84,7 +91,7 @@ impl FnCall {

impl ToTokens for FnCall {
fn to_tokens(&self, tokens: &mut TokenStream) {
let FnCall(fn_ptr, arguments, turbofish) = self;
let FnCall(fn_ptr, arguments, turbofish, _requires_unsafe_wrapper) = self;

fn_ptr.to_tokens(tokens);

Expand Down Expand Up @@ -301,7 +308,7 @@ impl Expression {
}
Self::CastAs(exp, _ty) => exp.requires_unsafe_wrapper(ctx_fn),
// Functions and macros can be unsafe, but can also contain other expressions.
Self::FnCall(FnCall(fn_exp, args, turbo_args)) => {
Self::FnCall(FnCall(fn_exp, args, turbo_args, requires_unsafe_wrapper)) => {
let fn_name = fn_exp.to_string();
fn_exp.requires_unsafe_wrapper(ctx_fn)
|| fn_name.starts_with("_sv")
Expand All @@ -311,6 +318,7 @@ impl Expression {
|| turbo_args
.iter()
.any(|exp| exp.requires_unsafe_wrapper(ctx_fn))
|| *requires_unsafe_wrapper
}
Self::MethodCall(exp, fn_name, args) => match fn_name.as_str() {
// `as_signed` and `as_unsigned` are unsafe because they're trait methods with
Expand Down
19 changes: 14 additions & 5 deletions crates/stdarch-gen-arm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,10 @@ impl LLVMLink {
})
.try_collect()?;

Ok(FnCall::new_expression(link_sig.fn_name().into(), call_args))
Ok(FnCall::new_unsafe_expression(
link_sig.fn_name().into(),
call_args,
))
}

/// Given a FnCall, apply all the predicate and unsigned conversions as required.
Expand Down Expand Up @@ -1251,7 +1254,7 @@ impl Intrinsic {
.iter()
.map(|sd| sd.try_into())
.try_collect()?;
let mut call: Expression = FnCall(Box::new(name), args, statics).into();
let mut call: Expression = FnCall(Box::new(name), args, statics, false).into();
call.build(self, ctx)?;
Ok(vec![call])
}
Expand Down Expand Up @@ -1320,7 +1323,7 @@ impl Intrinsic {
.iter()
.map(|sd| sd.try_into())
.try_collect()?;
let mut call: Expression = FnCall(Box::new(name), args, statics).into();
let mut call: Expression = FnCall(Box::new(name), args, statics, false).into();
call.build(self, ctx)?;
Ok(vec![call])
}
Expand Down Expand Up @@ -1413,7 +1416,7 @@ impl Intrinsic {
.iter()
.map(|sd| sd.try_into())
.try_collect()?;
let mut call: Expression = FnCall(Box::new(name), args, statics).into();
let mut call: Expression = FnCall(Box::new(name), args, statics, false).into();
call.build(self, ctx)?;

variant.compose = vec![call];
Expand Down Expand Up @@ -1665,7 +1668,13 @@ impl Intrinsic {
.return_type
.as_ref()
.and_then(|t| t.wildcard());
let call = FnCall(Box::new(target_signature.fn_name().into()), args, turbofish).into();
let call = FnCall(
Box::new(target_signature.fn_name().into()),
args,
turbofish,
false,
)
.into();

self.compose = vec![convert_if_required(
ret_wildcard,
Expand Down