Skip to content

Commit 2b956f5

Browse files
authored
Merge pull request #312 from GuillaumeGomez/fn-param-noalias
Add support for `noalias` function parameters
2 parents 4ffa425 + c83e567 commit 2b956f5

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/abi.rs

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_codegen_ssa::traits::{AbiBuilderMethods, BaseTypeMethods};
33
use rustc_data_structures::fx::FxHashSet;
44
use rustc_middle::bug;
55
use rustc_middle::ty::Ty;
6-
use rustc_target::abi::call::{CastTarget, FnAbi, PassMode, Reg, RegKind};
6+
use rustc_target::abi::call::{ArgAttributes, CastTarget, FnAbi, PassMode, Reg, RegKind};
77

88
use crate::builder::Builder;
99
use crate::context::CodegenCx;
@@ -120,30 +120,49 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
120120
}
121121
};
122122

123+
#[cfg(feature = "master")]
124+
let apply_attrs = |ty: Type<'gcc>, attrs: &ArgAttributes| {
125+
if attrs.regular.contains(rustc_target::abi::call::ArgAttribute::NoAlias)
126+
{
127+
ty.make_restrict()
128+
} else {
129+
ty
130+
}
131+
};
132+
#[cfg(not(feature = "master"))]
133+
let apply_attrs = |ty: Type<'gcc>, _attrs: &ArgAttributes| {
134+
ty
135+
};
136+
123137
for arg in self.args.iter() {
124138
let arg_ty = match arg.mode {
125139
PassMode::Ignore => continue,
126-
PassMode::Direct(_) => arg.layout.immediate_gcc_type(cx),
127-
PassMode::Pair(..) => {
128-
argument_tys.push(arg.layout.scalar_pair_element_gcc_type(cx, 0, true));
129-
argument_tys.push(arg.layout.scalar_pair_element_gcc_type(cx, 1, true));
140+
PassMode::Pair(a, b) => {
141+
argument_tys.push(apply_attrs(arg.layout.scalar_pair_element_gcc_type(cx, 0, true), &a));
142+
argument_tys.push(apply_attrs(arg.layout.scalar_pair_element_gcc_type(cx, 1, true), &b));
130143
continue;
131144
}
132-
PassMode::Indirect { extra_attrs: Some(_), .. } => {
133-
unimplemented!();
134-
}
135145
PassMode::Cast(ref cast, pad_i32) => {
136146
// add padding
137147
if pad_i32 {
138148
argument_tys.push(Reg::i32().gcc_type(cx));
139149
}
140-
cast.gcc_type(cx)
150+
let ty = cast.gcc_type(cx);
151+
apply_attrs(ty, &cast.attrs)
141152
}
142-
PassMode::Indirect { extra_attrs: None, on_stack: true, .. } => {
153+
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: true } => {
154+
// This is a "byval" argument, so we don't apply the `restrict` attribute on it.
143155
on_stack_param_indices.insert(argument_tys.len());
144156
arg.memory_ty(cx)
145157
},
146-
PassMode::Indirect { extra_attrs: None, on_stack: false, .. } => cx.type_ptr_to(arg.memory_ty(cx)),
158+
PassMode::Direct(attrs) => apply_attrs(arg.layout.immediate_gcc_type(cx), &attrs),
159+
PassMode::Indirect { attrs, extra_attrs: None, on_stack: false } => {
160+
apply_attrs(cx.type_ptr_to(arg.memory_ty(cx)), &attrs)
161+
}
162+
PassMode::Indirect { attrs, extra_attrs: Some(extra_attrs), on_stack } => {
163+
assert!(!on_stack);
164+
apply_attrs(apply_attrs(cx.type_ptr_to(arg.memory_ty(cx)), &attrs), &extra_attrs)
165+
}
147166
};
148167
argument_tys.push(arg_ty);
149168
}

0 commit comments

Comments
 (0)