Skip to content

Commit

Permalink
codegen: use "_N" (like for other locals) instead of "argN", for argu…
Browse files Browse the repository at this point in the history
…ment names.
  • Loading branch information
eddyb committed Sep 13, 2019
1 parent e9214a1 commit bdad2c5
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 55 deletions.
3 changes: 2 additions & 1 deletion src/librustc_codegen_ssa/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,11 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
mir.args_iter().enumerate().map(|(arg_index, local)| {
let arg_decl = &mir.local_decls[local];

// FIXME(eddyb) don't allocate a `String` unless it gets used.
let name = if let Some(name) = arg_decl.name {
name.as_str().to_string()
} else {
format!("arg{}", arg_index)
format!("{:?}", local)
};

if Some(local) == mir.spread_arg {
Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/adjustments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![crate_type = "lib"]

// Hack to get the correct size for the length part in slices
// CHECK: @helper([[USIZE:i[0-9]+]] %arg0)
// CHECK: @helper([[USIZE:i[0-9]+]] %_1)
#[no_mangle]
pub fn helper(_: usize) {
}
Expand Down
12 changes: 6 additions & 6 deletions src/test/codegen/fastcall-inreg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,27 @@
#![crate_type = "lib"]

pub mod tests {
// CHECK: @f1(i32 inreg %arg0, i32 inreg %arg1, i32 %arg2)
// CHECK: @f1(i32 inreg %_1, i32 inreg %_2, i32 %_3)
#[no_mangle]
pub extern "fastcall" fn f1(_: i32, _: i32, _: i32) {}

// CHECK: @f2(i32* inreg %arg0, i32* inreg %arg1, i32* %arg2)
// CHECK: @f2(i32* inreg %_1, i32* inreg %_2, i32* %_3)
#[no_mangle]
pub extern "fastcall" fn f2(_: *const i32, _: *const i32, _: *const i32) {}

// CHECK: @f3(float %arg0, i32 inreg %arg1, i32 inreg %arg2, i32 %arg3)
// CHECK: @f3(float %_1, i32 inreg %_2, i32 inreg %_3, i32 %_4)
#[no_mangle]
pub extern "fastcall" fn f3(_: f32, _: i32, _: i32, _: i32) {}

// CHECK: @f4(i32 inreg %arg0, float %arg1, i32 inreg %arg2, i32 %arg3)
// CHECK: @f4(i32 inreg %_1, float %_2, i32 inreg %_3, i32 %_4)
#[no_mangle]
pub extern "fastcall" fn f4(_: i32, _: f32, _: i32, _: i32) {}

// CHECK: @f5(i64 %arg0, i32 %arg1)
// CHECK: @f5(i64 %_1, i32 %_2)
#[no_mangle]
pub extern "fastcall" fn f5(_: i64, _: i32) {}

// CHECK: @f6(i1 inreg zeroext %arg0, i32 inreg %arg1, i32 %arg2)
// CHECK: @f6(i1 inreg zeroext %_1, i32 inreg %_2, i32 %_3)
#[no_mangle]
pub extern "fastcall" fn f6(_: bool, _: i32, _: i32) {}
}
28 changes: 14 additions & 14 deletions src/test/codegen/function-arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,48 @@ pub fn boolean(x: bool) -> bool {
x
}

// CHECK: @readonly_borrow(i32* noalias readonly align 4 dereferenceable(4) %arg0)
// CHECK: @readonly_borrow(i32* noalias readonly align 4 dereferenceable(4) %_1)
// FIXME #25759 This should also have `nocapture`
#[no_mangle]
pub fn readonly_borrow(_: &i32) {
}

// CHECK: @static_borrow(i32* noalias readonly align 4 dereferenceable(4) %arg0)
// CHECK: @static_borrow(i32* noalias readonly align 4 dereferenceable(4) %_1)
// static borrow may be captured
#[no_mangle]
pub fn static_borrow(_: &'static i32) {
}

// CHECK: @named_borrow(i32* noalias readonly align 4 dereferenceable(4) %arg0)
// CHECK: @named_borrow(i32* noalias readonly align 4 dereferenceable(4) %_1)
// borrow with named lifetime may be captured
#[no_mangle]
pub fn named_borrow<'r>(_: &'r i32) {
}

// CHECK: @unsafe_borrow(i16* align 2 dereferenceable(2) %arg0)
// CHECK: @unsafe_borrow(i16* align 2 dereferenceable(2) %_1)
// unsafe interior means this isn't actually readonly and there may be aliases ...
#[no_mangle]
pub fn unsafe_borrow(_: &UnsafeInner) {
}

// CHECK: @mutable_unsafe_borrow(i16* align 2 dereferenceable(2) %arg0)
// CHECK: @mutable_unsafe_borrow(i16* align 2 dereferenceable(2) %_1)
// ... unless this is a mutable borrow, those never alias
#[no_mangle]
pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
}

// CHECK: @mutable_borrow(i32* align 4 dereferenceable(4) %arg0)
// CHECK: @mutable_borrow(i32* align 4 dereferenceable(4) %_1)
// FIXME #25759 This should also have `nocapture`
#[no_mangle]
pub fn mutable_borrow(_: &mut i32) {
}

// CHECK: @indirect_struct(%S* noalias nocapture dereferenceable(32) %arg0)
// CHECK: @indirect_struct(%S* noalias nocapture dereferenceable(32) %_1)
#[no_mangle]
pub fn indirect_struct(_: S) {
}

// CHECK: @borrowed_struct(%S* noalias readonly align 4 dereferenceable(32) %arg0)
// CHECK: @borrowed_struct(%S* noalias readonly align 4 dereferenceable(32) %_1)
// FIXME #25759 This should also have `nocapture`
#[no_mangle]
pub fn borrowed_struct(_: &S) {
Expand All @@ -80,36 +80,36 @@ pub fn struct_return() -> S {
}

// Hack to get the correct size for the length part in slices
// CHECK: @helper([[USIZE:i[0-9]+]] %arg0)
// CHECK: @helper([[USIZE:i[0-9]+]] %_1)
#[no_mangle]
pub fn helper(_: usize) {
}

// CHECK: @slice([0 x i8]* noalias nonnull readonly align 1 %arg0.0, [[USIZE]] %arg0.1)
// CHECK: @slice([0 x i8]* noalias nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1)
// FIXME #25759 This should also have `nocapture`
#[no_mangle]
pub fn slice(_: &[u8]) {
}

// CHECK: @mutable_slice([0 x i8]* nonnull align 1 %arg0.0, [[USIZE]] %arg0.1)
// CHECK: @mutable_slice([0 x i8]* nonnull align 1 %_1.0, [[USIZE]] %_1.1)
// FIXME #25759 This should also have `nocapture`
#[no_mangle]
pub fn mutable_slice(_: &mut [u8]) {
}

// CHECK: @unsafe_slice([0 x i16]* nonnull align 2 %arg0.0, [[USIZE]] %arg0.1)
// CHECK: @unsafe_slice([0 x i16]* nonnull align 2 %_1.0, [[USIZE]] %_1.1)
// unsafe interior means this isn't actually readonly and there may be aliases ...
#[no_mangle]
pub fn unsafe_slice(_: &[UnsafeInner]) {
}

// CHECK: @str([0 x i8]* noalias nonnull readonly align 1 %arg0.0, [[USIZE]] %arg0.1)
// CHECK: @str([0 x i8]* noalias nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1)
// FIXME #25759 This should also have `nocapture`
#[no_mangle]
pub fn str(_: &[u8]) {
}

// CHECK: @trait_borrow({}* nonnull align 1 %arg0.0, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}) %arg0.1)
// CHECK: @trait_borrow({}* nonnull align 1 %_1.0, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
// FIXME #25759 This should also have `nocapture`
#[no_mangle]
pub fn trait_borrow(_: &Drop) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![crate_type = "lib"]

// Hack to get the correct size for the length part in slices
// CHECK: @helper([[USIZE:i[0-9]+]] %arg0)
// CHECK: @helper([[USIZE:i[0-9]+]] %_1)
#[no_mangle]
pub fn helper(_: usize) {
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/repeat-trusted-len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use std::iter;

// CHECK: @helper([[USIZE:i[0-9]+]] %arg0)
// CHECK: @helper([[USIZE:i[0-9]+]] %_1)
#[no_mangle]
pub fn helper(_: usize) {
}
Expand Down
34 changes: 17 additions & 17 deletions src/test/codegen/repr-transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,36 @@ pub struct Zst2(());
#[repr(transparent)]
pub struct F32(f32);

// CHECK: define float @test_F32(float %arg0)
// CHECK: define float @test_F32(float %_1)
#[no_mangle]
pub extern fn test_F32(_: F32) -> F32 { loop {} }

#[repr(transparent)]
pub struct Ptr(*mut u8);

// CHECK: define i8* @test_Ptr(i8* %arg0)
// CHECK: define i8* @test_Ptr(i8* %_1)
#[no_mangle]
pub extern fn test_Ptr(_: Ptr) -> Ptr { loop {} }

#[repr(transparent)]
pub struct WithZst(u64, Zst1);

// CHECK: define i64 @test_WithZst(i64 %arg0)
// CHECK: define i64 @test_WithZst(i64 %_1)
#[no_mangle]
pub extern fn test_WithZst(_: WithZst) -> WithZst { loop {} }

#[repr(transparent)]
pub struct WithZeroSizedArray(*const f32, [i8; 0]);

// Apparently we use i32* when newtype-unwrapping f32 pointers. Whatever.
// CHECK: define i32* @test_WithZeroSizedArray(i32* %arg0)
// CHECK: define i32* @test_WithZeroSizedArray(i32* %_1)
#[no_mangle]
pub extern fn test_WithZeroSizedArray(_: WithZeroSizedArray) -> WithZeroSizedArray { loop {} }

#[repr(transparent)]
pub struct Generic<T>(T);

// CHECK: define double @test_Generic(double %arg0)
// CHECK: define double @test_Generic(double %_1)
#[no_mangle]
pub extern fn test_Generic(_: Generic<f64>) -> Generic<f64> { loop {} }

Expand All @@ -53,14 +53,14 @@ pub struct GenericPlusZst<T>(T, Zst2);
#[repr(u8)]
pub enum Bool { True, False, FileNotFound }

// CHECK: define{{( zeroext)?}} i8 @test_Gpz(i8{{( zeroext)?}} %arg0)
// CHECK: define{{( zeroext)?}} i8 @test_Gpz(i8{{( zeroext)?}} %_1)
#[no_mangle]
pub extern fn test_Gpz(_: GenericPlusZst<Bool>) -> GenericPlusZst<Bool> { loop {} }

#[repr(transparent)]
pub struct LifetimePhantom<'a, T: 'a>(*const T, PhantomData<&'a T>);

// CHECK: define i16* @test_LifetimePhantom(i16* %arg0)
// CHECK: define i16* @test_LifetimePhantom(i16* %_1)
#[no_mangle]
pub extern fn test_LifetimePhantom(_: LifetimePhantom<i16>) -> LifetimePhantom<i16> { loop {} }

Expand All @@ -70,28 +70,28 @@ pub struct UnitPhantom<T, U> { val: T, unit: PhantomData<U> }

pub struct Px;

// CHECK: define float @test_UnitPhantom(float %arg0)
// CHECK: define float @test_UnitPhantom(float %_1)
#[no_mangle]
pub extern fn test_UnitPhantom(_: UnitPhantom<f32, Px>) -> UnitPhantom<f32, Px> { loop {} }

#[repr(transparent)]
pub struct TwoZsts(Zst1, i8, Zst2);

// CHECK: define{{( signext)?}} i8 @test_TwoZsts(i8{{( signext)?}} %arg0)
// CHECK: define{{( signext)?}} i8 @test_TwoZsts(i8{{( signext)?}} %_1)
#[no_mangle]
pub extern fn test_TwoZsts(_: TwoZsts) -> TwoZsts { loop {} }

#[repr(transparent)]
pub struct Nested1(Zst2, Generic<f64>);

// CHECK: define double @test_Nested1(double %arg0)
// CHECK: define double @test_Nested1(double %_1)
#[no_mangle]
pub extern fn test_Nested1(_: Nested1) -> Nested1 { loop {} }

#[repr(transparent)]
pub struct Nested2(Nested1, Zst1);

// CHECK: define double @test_Nested2(double %arg0)
// CHECK: define double @test_Nested2(double %_1)
#[no_mangle]
pub extern fn test_Nested2(_: Nested2) -> Nested2 { loop {} }

Expand All @@ -101,7 +101,7 @@ struct f32x4(f32, f32, f32, f32);
#[repr(transparent)]
pub struct Vector(f32x4);

// CHECK: define <4 x float> @test_Vector(<4 x float> %arg0)
// CHECK: define <4 x float> @test_Vector(<4 x float> %_1)
#[no_mangle]
pub extern fn test_Vector(_: Vector) -> Vector { loop {} }

Expand All @@ -111,7 +111,7 @@ impl<T: ?Sized> Mirror for T { type It = Self; }
#[repr(transparent)]
pub struct StructWithProjection(<f32 as Mirror>::It);

// CHECK: define float @test_Projection(float %arg0)
// CHECK: define float @test_Projection(float %_1)
#[no_mangle]
pub extern fn test_Projection(_: StructWithProjection) -> StructWithProjection { loop {} }

Expand All @@ -120,7 +120,7 @@ pub enum EnumF32 {
Variant(F32)
}

// CHECK: define float @test_EnumF32(float %arg0)
// CHECK: define float @test_EnumF32(float %_1)
#[no_mangle]
pub extern fn test_EnumF32(_: EnumF32) -> EnumF32 { loop {} }

Expand All @@ -129,7 +129,7 @@ pub enum EnumF32WithZsts {
Variant(Zst1, F32, Zst2)
}

// CHECK: define float @test_EnumF32WithZsts(float %arg0)
// CHECK: define float @test_EnumF32WithZsts(float %_1)
#[no_mangle]
pub extern fn test_EnumF32WithZsts(_: EnumF32WithZsts) -> EnumF32WithZsts { loop {} }

Expand All @@ -138,7 +138,7 @@ pub union UnionF32 {
field: F32,
}

// CHECK: define float @test_UnionF32(float %arg0)
// CHECK: define float @test_UnionF32(float %_1)
#[no_mangle]
pub extern fn test_UnionF32(_: UnionF32) -> UnionF32 { loop {} }

Expand All @@ -149,7 +149,7 @@ pub union UnionF32WithZsts {
zst2: Zst2,
}

// CHECK: define float @test_UnionF32WithZsts(float %arg0)
// CHECK: define float @test_UnionF32WithZsts(float %_1)
#[no_mangle]
pub extern fn test_UnionF32WithZsts(_: UnionF32WithZsts) -> UnionF32WithZsts { loop {} }

Expand Down
12 changes: 6 additions & 6 deletions src/test/codegen/scalar-pair-bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ pub fn pair_i32_bool(pair: (i32, bool)) -> (i32, bool) {
pair
}

// CHECK: define { i8, i8 } @pair_and_or(i1 zeroext %arg0.0, i1 zeroext %arg0.1)
// CHECK: define { i8, i8 } @pair_and_or(i1 zeroext %_1.0, i1 zeroext %_1.1)
#[no_mangle]
pub fn pair_and_or((a, b): (bool, bool)) -> (bool, bool) {
// Make sure it can operate directly on the unpacked args
// CHECK: and i1 %arg0.0, %arg0.1
// CHECK: or i1 %arg0.0, %arg0.1
// CHECK: and i1 %_1.0, %_1.1
// CHECK: or i1 %_1.0, %_1.1
(a && b, a || b)
}

// CHECK: define void @pair_branches(i1 zeroext %arg0.0, i1 zeroext %arg0.1)
// CHECK: define void @pair_branches(i1 zeroext %_1.0, i1 zeroext %_1.1)
#[no_mangle]
pub fn pair_branches((a, b): (bool, bool)) {
// Make sure it can branch directly on the unpacked bool args
// CHECK: br i1 %arg0.0
// CHECK: br i1 %_1.0
if a {
println!("Hello!");
}
// CHECK: br i1 %arg0.1
// CHECK: br i1 %_1.1
if b {
println!("Goodbye!");
}
Expand Down
Loading

0 comments on commit bdad2c5

Please sign in to comment.