Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add tests for RISC-V C ABI
  • Loading branch information
msizanoen1 committed Feb 4, 2020
commit 39633874ae7d0150669004a80740ff3b0708d08d
29 changes: 29 additions & 0 deletions src/test/auxiliary/rust_test_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ struct floats {
double c;
};

struct char_char_double {
uint8_t a;
uint8_t b;
double c;
};

struct char_char_float {
uint8_t a;
uint8_t b;
float c;
};

struct quad
rust_dbg_abi_1(struct quad q) {
struct quad qq = { q.c + 1,
Expand All @@ -185,6 +197,23 @@ rust_dbg_abi_2(struct floats f) {
return ff;
}

struct char_char_double
rust_dbg_abi_3(struct char_char_double a) {
struct char_char_double ccd = { a.a + 1,
a.b - 1,
a.c + 1.0 };
return ccd;
}

struct char_char_float
rust_dbg_abi_4(struct char_char_float a) {
struct char_char_float ccd = { a.a + 1,
a.b - 1,
a.c + 1.0 };
return ccd;
}


int
rust_dbg_static_mut = 3;

Expand Down
181 changes: 181 additions & 0 deletions src/test/codegen/riscv-abi/riscv64-lp64-lp64f-lp64d-abi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
// ignore-tidy-linelength
// compile-flags: -C no-prepopulate-passes
// only-riscv64
// only-linux
#![crate_type = "lib"]
#![allow(improper_ctypes)]

// CHECK: define void @f_void()
#[no_mangle]
pub extern "C" fn f_void() {}

// CHECK: define zeroext i1 @f_scalar_0(i1 zeroext %a)
#[no_mangle]
pub extern "C" fn f_scalar_0(a: bool) -> bool {
a
}

// CHECK: define signext i8 @f_scalar_1(i8 signext %x)
#[no_mangle]
pub extern "C" fn f_scalar_1(x: i8) -> i8 {
x
}

// CHECK: define zeroext i8 @f_scalar_2(i8 zeroext %x)
#[no_mangle]
pub extern "C" fn f_scalar_2(x: u8) -> u8 {
x
}

// CHECK: define signext i32 @f_scalar_3(i32 signext %x)
#[no_mangle]
pub extern "C" fn f_scalar_3(x: i32) -> u32 {
x as u32
}

// CHECK: define i64 @f_scalar_4(i64 %x)
#[no_mangle]
pub extern "C" fn f_scalar_4(x: i64) -> i64 {
x
}

// CHECK: define float @f_fp_scalar_1(float)
#[no_mangle]
pub extern "C" fn f_fp_scalar_1(x: f32) -> f32 {
x
}
// CHECK: define double @f_fp_scalar_2(double)
#[no_mangle]
pub extern "C" fn f_fp_scalar_2(x: f64) -> f64 {
x
}

#[repr(C)]
pub struct Empty {}

// CHECK: define void @f_agg_empty_struct()
#[no_mangle]
pub extern "C" fn f_agg_empty_struct(e: Empty) -> Empty {
e
}

#[repr(C)]
pub struct Tiny {
a: u16,
b: u16,
c: u16,
d: u16,
}

// CHECK: define void @f_agg_tiny(i64)
#[no_mangle]
pub extern "C" fn f_agg_tiny(mut e: Tiny) {
e.a += e.b;
e.c += e.d;
}

// CHECK: define i64 @f_agg_tiny_ret()
#[no_mangle]
pub extern "C" fn f_agg_tiny_ret() -> Tiny {
Tiny { a: 1, b: 2, c: 3, d: 4 }
}

#[repr(C)]
pub struct Small {
a: i64,
b: *mut i64,
}

// CHECK: define void @f_agg_small([2 x i64])
#[no_mangle]
pub extern "C" fn f_agg_small(mut x: Small) {
x.a += unsafe { *x.b };
x.b = &mut x.a;
}

// CHECK: define [2 x i64] @f_agg_small_ret()
#[no_mangle]
pub extern "C" fn f_agg_small_ret() -> Small {
Small { a: 1, b: core::ptr::null_mut() }
}

#[repr(C)]
pub struct SmallAligned {
a: i128,
}

// CHECK: define void @f_agg_small_aligned(i128)
#[no_mangle]
pub extern "C" fn f_agg_small_aligned(mut x: SmallAligned) {
x.a += x.a;
}

#[repr(C)]
pub struct Large {
a: i64,
b: i64,
c: i64,
d: i64,
}

// CHECK: define void @f_agg_large(%Large* {{.*}}%x)
#[no_mangle]
pub extern "C" fn f_agg_large(mut x: Large) {
x.a = x.b + x.c + x.d;
}

// CHECK: define void @f_agg_large_ret(%Large* {{.*}}sret{{.*}}, i32 signext %i, i8 signext %j)
#[no_mangle]
pub extern "C" fn f_agg_large_ret(i: i32, j: i8) -> Large {
Large { a: 1, b: 2, c: 3, d: 4 }
}

// CHECK: define void @f_scalar_stack_1(i64, [2 x i64], i128, %Large* {{.*}}%d, i8 zeroext %e, i8 signext %f, i8 %g, i8 %h)
#[no_mangle]
pub extern "C" fn f_scalar_stack_1(
a: Tiny,
b: Small,
c: SmallAligned,
d: Large,
e: u8,
f: i8,
g: u8,
h: i8,
) {
}

// CHECK: define void @f_scalar_stack_2(%Large* {{.*}}sret{{.*}}, i64 %a, i128, i128, i64 %d, i8 zeroext %e, i8 %f, i8 %g)
#[no_mangle]
pub extern "C" fn f_scalar_stack_2(
a: u64,
b: SmallAligned,
c: SmallAligned,
d: u64,
e: u8,
f: i8,
g: u8,
) -> Large {
Large { a: a as i64, b: e as i64, c: f as i64, d: g as i64 }
}

extern "C" {
fn f_va_callee(_: i32, ...) -> i32;
}

#[no_mangle]
pub unsafe extern "C" fn f_va_caller() {
// CHECK: call signext i32 (i32, ...) @f_va_callee(i32 signext 1, i32 signext 2, i64 3, double {{.*}}, double {{.*}}, i64 {{.*}}, [2 x i64] {{.*}}, i128 {{.*}}, %Large* {{.*}})
f_va_callee(
1,
2i32,
3i64,
4.0f64,
5.0f64,
Tiny { a: 1, b: 2, c: 3, d: 4 },
Small { a: 10, b: core::ptr::null_mut() },
SmallAligned { a: 11 },
Large { a: 12, b: 13, c: 14, d: 15 },
);
// CHECK: call signext i32 (i32, ...) @f_va_callee(i32 signext 1, i32 signext 2, i32 signext 3, i32 signext 4, i128 {{.*}}, i32 signext 6, i32 signext 7, i32 8, i32 9)
f_va_callee(1, 2i32, 3i32, 4i32, SmallAligned { a: 5 }, 6i32, 7i32, 8i32, 9i32);
}
Loading