/src/test/codegen/riscv-abi/riscv64-lp64-lp64f-lp64d-abi.rs

https://gitlab.com/rust-lang/rust · Rust · 189 lines · 141 code · 26 blank · 22 comment · 8 complexity · 09637d005ce22615135d4d9301f26f1b MD5 · raw file

  1. // compile-flags: --target riscv64gc-unknown-linux-gnu -O -C no-prepopulate-passes
  2. // needs-llvm-components: riscv
  3. #![crate_type = "lib"]
  4. #![no_core]
  5. #![feature(no_core, lang_items)]
  6. #![allow(improper_ctypes)]
  7. #[lang = "sized"]
  8. trait Sized {}
  9. #[lang = "copy"]
  10. trait Copy {}
  11. impl Copy for bool {}
  12. impl Copy for i8 {}
  13. impl Copy for u8 {}
  14. impl Copy for i32 {}
  15. impl Copy for i64 {}
  16. impl Copy for u64 {}
  17. impl Copy for f32 {}
  18. impl Copy for f64 {}
  19. // CHECK: define void @f_void()
  20. #[no_mangle]
  21. pub extern "C" fn f_void() {}
  22. // CHECK: define noundef zeroext i1 @f_scalar_0(i1 noundef zeroext %a)
  23. #[no_mangle]
  24. pub extern "C" fn f_scalar_0(a: bool) -> bool {
  25. a
  26. }
  27. // CHECK: define signext i8 @f_scalar_1(i8 signext %x)
  28. #[no_mangle]
  29. pub extern "C" fn f_scalar_1(x: i8) -> i8 {
  30. x
  31. }
  32. // CHECK: define zeroext i8 @f_scalar_2(i8 zeroext %x)
  33. #[no_mangle]
  34. pub extern "C" fn f_scalar_2(x: u8) -> u8 {
  35. x
  36. }
  37. // CHECK: define signext i32 @f_scalar_3(i32 signext %x)
  38. #[no_mangle]
  39. pub extern "C" fn f_scalar_3(x: i32) -> u32 {
  40. x as u32
  41. }
  42. // CHECK: define i64 @f_scalar_4(i64 %x)
  43. #[no_mangle]
  44. pub extern "C" fn f_scalar_4(x: i64) -> i64 {
  45. x
  46. }
  47. // CHECK: define float @f_fp_scalar_1(float %0)
  48. #[no_mangle]
  49. pub extern "C" fn f_fp_scalar_1(x: f32) -> f32 {
  50. x
  51. }
  52. // CHECK: define double @f_fp_scalar_2(double %0)
  53. #[no_mangle]
  54. pub extern "C" fn f_fp_scalar_2(x: f64) -> f64 {
  55. x
  56. }
  57. #[repr(C)]
  58. pub struct Empty {}
  59. // CHECK: define void @f_agg_empty_struct()
  60. #[no_mangle]
  61. pub extern "C" fn f_agg_empty_struct(e: Empty) -> Empty {
  62. e
  63. }
  64. #[repr(C)]
  65. pub struct Tiny {
  66. a: u16,
  67. b: u16,
  68. c: u16,
  69. d: u16,
  70. }
  71. // CHECK: define void @f_agg_tiny(i64 %0)
  72. #[no_mangle]
  73. pub extern "C" fn f_agg_tiny(mut e: Tiny) {
  74. }
  75. // CHECK: define i64 @f_agg_tiny_ret()
  76. #[no_mangle]
  77. pub extern "C" fn f_agg_tiny_ret() -> Tiny {
  78. Tiny { a: 1, b: 2, c: 3, d: 4 }
  79. }
  80. #[repr(C)]
  81. pub struct Small {
  82. a: i64,
  83. b: *mut i64,
  84. }
  85. // CHECK: define void @f_agg_small([2 x i64] %0)
  86. #[no_mangle]
  87. pub extern "C" fn f_agg_small(mut x: Small) {
  88. }
  89. // CHECK: define [2 x i64] @f_agg_small_ret()
  90. #[no_mangle]
  91. pub extern "C" fn f_agg_small_ret() -> Small {
  92. Small { a: 1, b: 0 as *mut _ }
  93. }
  94. #[repr(C)]
  95. pub struct SmallAligned {
  96. a: i128,
  97. }
  98. // CHECK: define void @f_agg_small_aligned(i128 %0)
  99. #[no_mangle]
  100. pub extern "C" fn f_agg_small_aligned(mut x: SmallAligned) {
  101. }
  102. #[repr(C)]
  103. pub struct Large {
  104. a: i64,
  105. b: i64,
  106. c: i64,
  107. d: i64,
  108. }
  109. // CHECK: define void @f_agg_large({{%Large\*|ptr}} {{.*}}%x)
  110. #[no_mangle]
  111. pub extern "C" fn f_agg_large(mut x: Large) {
  112. }
  113. // CHECK: define void @f_agg_large_ret({{%Large\*|ptr}} {{.*}}sret{{.*}}, i32 signext %i, i8 signext %j)
  114. #[no_mangle]
  115. pub extern "C" fn f_agg_large_ret(i: i32, j: i8) -> Large {
  116. Large { a: 1, b: 2, c: 3, d: 4 }
  117. }
  118. // CHECK: define void @f_scalar_stack_1(i64 %0, [2 x i64] %1, i128 %2, {{%Large\*|ptr}} {{.*}}%d, i8 zeroext %e, i8 signext %f, i8 %g, i8 %h)
  119. #[no_mangle]
  120. pub extern "C" fn f_scalar_stack_1(
  121. a: Tiny,
  122. b: Small,
  123. c: SmallAligned,
  124. d: Large,
  125. e: u8,
  126. f: i8,
  127. g: u8,
  128. h: i8,
  129. ) {
  130. }
  131. // CHECK: define void @f_scalar_stack_2({{%Large\*|ptr}} {{.*}}sret{{.*}} %0, i64 %a, i128 %1, i128 %2, i64 %d, i8 zeroext %e, i8 %f, i8 %g)
  132. #[no_mangle]
  133. pub extern "C" fn f_scalar_stack_2(
  134. a: u64,
  135. b: SmallAligned,
  136. c: SmallAligned,
  137. d: u64,
  138. e: u8,
  139. f: i8,
  140. g: u8,
  141. ) -> Large {
  142. Large { a: a as i64, b: e as i64, c: f as i64, d: g as i64 }
  143. }
  144. extern "C" {
  145. fn f_va_callee(_: i32, ...) -> i32;
  146. }
  147. #[no_mangle]
  148. pub unsafe extern "C" fn f_va_caller() {
  149. // CHECK: call signext i32 (i32, ...) @f_va_callee(i32 signext 1, i32 signext 2, i64 3, double {{.*}}, double {{.*}}, i64 {{.*}}, [2 x i64] {{.*}}, i128 {{.*}}, {{%Large\*|ptr}} {{.*}})
  150. f_va_callee(
  151. 1,
  152. 2i32,
  153. 3i64,
  154. 4.0f64,
  155. 5.0f64,
  156. Tiny { a: 1, b: 2, c: 3, d: 4 },
  157. Small { a: 10, b: 0 as *mut _ },
  158. SmallAligned { a: 11 },
  159. Large { a: 12, b: 13, c: 14, d: 15 },
  160. );
  161. // 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)
  162. f_va_callee(1, 2i32, 3i32, 4i32, SmallAligned { a: 5 }, 6i32, 7i32, 8i32, 9i32);
  163. }