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

https://gitlab.com/rust-lang/rust · Rust · 277 lines · 198 code · 45 blank · 34 comment · 0 complexity · c26b9ed1a89261afdef18f6821766a24 MD5 · raw file

  1. //
  2. // compile-flags: -C no-prepopulate-passes
  3. // only-riscv64
  4. // only-linux
  5. #![crate_type = "lib"]
  6. // CHECK: define void @f_fpr_tracking(float %0, float %1, float %2, float %3, float %4, float %5, float %6, float %7, i8 zeroext %i)
  7. #[no_mangle]
  8. pub extern "C" fn f_fpr_tracking(
  9. a: f32,
  10. b: f32,
  11. c: f32,
  12. d: f32,
  13. e: f32,
  14. f: f32,
  15. g: f32,
  16. h: f32,
  17. i: u8,
  18. ) {
  19. }
  20. #[repr(C)]
  21. pub struct Float {
  22. f: f32,
  23. }
  24. #[repr(C)]
  25. pub struct FloatFloat {
  26. f: f32,
  27. g: f32,
  28. }
  29. // CHECK: define void @f_float_s_arg(float %0)
  30. #[no_mangle]
  31. pub extern "C" fn f_float_s_arg(a: Float) {}
  32. // CHECK: define float @f_ret_float_s()
  33. #[no_mangle]
  34. pub extern "C" fn f_ret_float_s() -> Float {
  35. Float { f: 1. }
  36. }
  37. // CHECK: define void @f_float_float_s_arg({ float, float } %0)
  38. #[no_mangle]
  39. pub extern "C" fn f_float_float_s_arg(a: FloatFloat) {}
  40. // CHECK: define { float, float } @f_ret_float_float_s()
  41. #[no_mangle]
  42. pub extern "C" fn f_ret_float_float_s() -> FloatFloat {
  43. FloatFloat { f: 1., g: 2. }
  44. }
  45. // CHECK: define void @f_float_float_s_arg_insufficient_fprs(float %0, float %1, float %2, float %3, float %4, float %5, float %6, i64 %7)
  46. #[no_mangle]
  47. pub extern "C" fn f_float_float_s_arg_insufficient_fprs(
  48. a: f32,
  49. b: f32,
  50. c: f32,
  51. d: f32,
  52. e: f32,
  53. f: f32,
  54. g: f32,
  55. h: FloatFloat,
  56. ) {
  57. }
  58. #[repr(C)]
  59. pub struct FloatInt8 {
  60. f: f32,
  61. i: i8,
  62. }
  63. #[repr(C)]
  64. pub struct FloatUInt8 {
  65. f: f32,
  66. i: u8,
  67. }
  68. #[repr(C)]
  69. pub struct FloatInt32 {
  70. f: f32,
  71. i: i32,
  72. }
  73. #[repr(C)]
  74. pub struct FloatInt64 {
  75. f: f32,
  76. i: i64,
  77. }
  78. // CHECK: define void @f_float_int8_s_arg({ float, i8 } %0)
  79. #[no_mangle]
  80. pub extern "C" fn f_float_int8_s_arg(a: FloatInt8) {}
  81. // CHECK: define { float, i8 } @f_ret_float_int8_s()
  82. #[no_mangle]
  83. pub extern "C" fn f_ret_float_int8_s() -> FloatInt8 {
  84. FloatInt8 { f: 1., i: 2 }
  85. }
  86. // CHECK: define void @f_float_int32_s_arg({ float, i32 } %0)
  87. #[no_mangle]
  88. pub extern "C" fn f_float_int32_s_arg(a: FloatInt32) {}
  89. // CHECK: define { float, i32 } @f_ret_float_int32_s()
  90. #[no_mangle]
  91. pub extern "C" fn f_ret_float_int32_s() -> FloatInt32 {
  92. FloatInt32 { f: 1., i: 2 }
  93. }
  94. // CHECK: define void @f_float_uint8_s_arg({ float, i8 } %0)
  95. #[no_mangle]
  96. pub extern "C" fn f_float_uint8_s_arg(a: FloatUInt8) {}
  97. // CHECK: define { float, i8 } @f_ret_float_uint8_s()
  98. #[no_mangle]
  99. pub extern "C" fn f_ret_float_uint8_s() -> FloatUInt8 {
  100. FloatUInt8 { f: 1., i: 2 }
  101. }
  102. // CHECK: define void @f_float_int64_s_arg({ float, i64 } %0)
  103. #[no_mangle]
  104. pub extern "C" fn f_float_int64_s_arg(a: FloatInt64) {}
  105. // CHECK: define { float, i64 } @f_ret_float_int64_s()
  106. #[no_mangle]
  107. pub extern "C" fn f_ret_float_int64_s() -> FloatInt64 {
  108. FloatInt64 { f: 1., i: 2 }
  109. }
  110. // CHECK: define void @f_float_int8_s_arg_insufficient_gprs(i32 signext %a, i32 signext %b, i32 signext %c, i32 signext %d, i32 signext %e, i32 signext %f, i32 signext %g, i32 signext %h, i64 %0)
  111. #[no_mangle]
  112. pub extern "C" fn f_float_int8_s_arg_insufficient_gprs(
  113. a: i32,
  114. b: i32,
  115. c: i32,
  116. d: i32,
  117. e: i32,
  118. f: i32,
  119. g: i32,
  120. h: i32,
  121. i: FloatInt8,
  122. ) {
  123. }
  124. // CHECK: define void @f_struct_float_int8_insufficient_fprs(float %0, float %1, float %2, float %3, float %4, float %5, float %6, float %7, i64 %8)
  125. #[no_mangle]
  126. pub extern "C" fn f_struct_float_int8_insufficient_fprs(
  127. a: f32,
  128. b: f32,
  129. c: f32,
  130. d: f32,
  131. e: f32,
  132. f: f32,
  133. g: f32,
  134. h: f32,
  135. i: FloatInt8,
  136. ) {
  137. }
  138. #[repr(C)]
  139. pub struct FloatArr1 {
  140. a: [f32; 1],
  141. }
  142. // CHECK: define void @f_floatarr1_s_arg(float %0)
  143. #[no_mangle]
  144. pub extern "C" fn f_floatarr1_s_arg(a: FloatArr1) {}
  145. // CHECK: define float @f_ret_floatarr1_s()
  146. #[no_mangle]
  147. pub extern "C" fn f_ret_floatarr1_s() -> FloatArr1 {
  148. FloatArr1 { a: [1.] }
  149. }
  150. #[repr(C)]
  151. pub struct FloatArr2 {
  152. a: [f32; 2],
  153. }
  154. // CHECK: define void @f_floatarr2_s_arg({ float, float } %0)
  155. #[no_mangle]
  156. pub extern "C" fn f_floatarr2_s_arg(a: FloatArr2) {}
  157. // CHECK: define { float, float } @f_ret_floatarr2_s()
  158. #[no_mangle]
  159. pub extern "C" fn f_ret_floatarr2_s() -> FloatArr2 {
  160. FloatArr2 { a: [1., 2.] }
  161. }
  162. #[repr(C)]
  163. pub struct Tricky1 {
  164. f: [f32; 1],
  165. }
  166. #[repr(C)]
  167. pub struct FloatArr2Tricky1 {
  168. g: [Tricky1; 2],
  169. }
  170. // CHECK: define void @f_floatarr2_tricky1_s_arg({ float, float } %0)
  171. #[no_mangle]
  172. pub extern "C" fn f_floatarr2_tricky1_s_arg(a: FloatArr2Tricky1) {}
  173. // CHECK: define { float, float } @f_ret_floatarr2_tricky1_s()
  174. #[no_mangle]
  175. pub extern "C" fn f_ret_floatarr2_tricky1_s() -> FloatArr2Tricky1 {
  176. FloatArr2Tricky1 { g: [Tricky1 { f: [1.] }, Tricky1 { f: [2.] }] }
  177. }
  178. #[repr(C)]
  179. pub struct EmptyStruct {}
  180. #[repr(C)]
  181. pub struct FloatArr2Tricky2 {
  182. s: EmptyStruct,
  183. g: [Tricky1; 2],
  184. }
  185. // CHECK: define void @f_floatarr2_tricky2_s_arg({ float, float } %0)
  186. #[no_mangle]
  187. pub extern "C" fn f_floatarr2_tricky2_s_arg(a: FloatArr2Tricky2) {}
  188. // CHECK: define { float, float } @f_ret_floatarr2_tricky2_s()
  189. #[no_mangle]
  190. pub extern "C" fn f_ret_floatarr2_tricky2_s() -> FloatArr2Tricky2 {
  191. FloatArr2Tricky2 { s: EmptyStruct {}, g: [Tricky1 { f: [1.] }, Tricky1 { f: [2.] }] }
  192. }
  193. #[repr(C)]
  194. pub struct IntFloatInt {
  195. a: i32,
  196. b: f32,
  197. c: i32,
  198. }
  199. // CHECK: define void @f_int_float_int_s_arg([2 x i64] %0)
  200. #[no_mangle]
  201. pub extern "C" fn f_int_float_int_s_arg(a: IntFloatInt) {}
  202. // CHECK: define [2 x i64] @f_ret_int_float_int_s()
  203. #[no_mangle]
  204. pub extern "C" fn f_ret_int_float_int_s() -> IntFloatInt {
  205. IntFloatInt { a: 1, b: 2., c: 3 }
  206. }
  207. #[repr(C)]
  208. pub struct CharCharFloat {
  209. a: u8,
  210. b: u8,
  211. c: f32,
  212. }
  213. // CHECK: define void @f_char_char_float_s_arg(i64 %0)
  214. #[no_mangle]
  215. pub extern "C" fn f_char_char_float_s_arg(a: CharCharFloat) {}
  216. // CHECK: define i64 @f_ret_char_char_float_s()
  217. #[no_mangle]
  218. pub extern "C" fn f_ret_char_char_float_s() -> CharCharFloat {
  219. CharCharFloat { a: 1, b: 2, c: 3. }
  220. }
  221. #[repr(C)]
  222. pub union FloatU {
  223. a: f32,
  224. }
  225. // CHECK: define void @f_float_u_arg(i64 %0)
  226. #[no_mangle]
  227. pub extern "C" fn f_float_u_arg(a: FloatU) {}
  228. // CHECK: define i64 @f_ret_float_u()
  229. #[no_mangle]
  230. pub extern "C" fn f_ret_float_u() -> FloatU {
  231. unsafe { FloatU { a: 1. } }
  232. }