/src/test/codegen/function-arguments.rs

https://gitlab.com/jianglu/rust · Rust · 163 lines · 88 code · 27 blank · 48 comment · 0 complexity · 87f77d92daf0b3d1f83c3377d10154b9 MD5 · raw file

  1. // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
  2. // file at the top-level directory of this distribution and at
  3. // http://rust-lang.org/COPYRIGHT.
  4. //
  5. // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
  6. // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
  7. // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
  8. // option. This file may not be copied, modified, or distributed
  9. // except according to those terms.
  10. // compile-flags: -C no-prepopulate-passes
  11. // ignore-tidy-linelength
  12. // min-llvm-version 6.0
  13. #![crate_type = "lib"]
  14. #![feature(custom_attribute)]
  15. pub struct S {
  16. _field: [i32; 8],
  17. }
  18. pub struct UnsafeInner {
  19. _field: std::cell::UnsafeCell<i16>,
  20. }
  21. // CHECK: zeroext i1 @boolean(i1 zeroext %x)
  22. #[no_mangle]
  23. pub fn boolean(x: bool) -> bool {
  24. x
  25. }
  26. // CHECK: @readonly_borrow(i32* noalias readonly dereferenceable(4) %arg0)
  27. // FIXME #25759 This should also have `nocapture`
  28. #[no_mangle]
  29. pub fn readonly_borrow(_: &i32) {
  30. }
  31. // CHECK: @static_borrow(i32* noalias readonly dereferenceable(4) %arg0)
  32. // static borrow may be captured
  33. #[no_mangle]
  34. pub fn static_borrow(_: &'static i32) {
  35. }
  36. // CHECK: @named_borrow(i32* noalias readonly dereferenceable(4) %arg0)
  37. // borrow with named lifetime may be captured
  38. #[no_mangle]
  39. pub fn named_borrow<'r>(_: &'r i32) {
  40. }
  41. // CHECK: @unsafe_borrow(i16* dereferenceable(2) %arg0)
  42. // unsafe interior means this isn't actually readonly and there may be aliases ...
  43. #[no_mangle]
  44. pub fn unsafe_borrow(_: &UnsafeInner) {
  45. }
  46. // CHECK: @mutable_unsafe_borrow(i16* noalias dereferenceable(2) %arg0)
  47. // ... unless this is a mutable borrow, those never alias
  48. #[no_mangle]
  49. pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
  50. }
  51. // CHECK: @mutable_borrow(i32* noalias dereferenceable(4) %arg0)
  52. // FIXME #25759 This should also have `nocapture`
  53. #[no_mangle]
  54. pub fn mutable_borrow(_: &mut i32) {
  55. }
  56. // CHECK: @indirect_struct(%S* noalias nocapture dereferenceable(32) %arg0)
  57. #[no_mangle]
  58. pub fn indirect_struct(_: S) {
  59. }
  60. // CHECK: @borrowed_struct(%S* noalias readonly dereferenceable(32) %arg0)
  61. // FIXME #25759 This should also have `nocapture`
  62. #[no_mangle]
  63. pub fn borrowed_struct(_: &S) {
  64. }
  65. // CHECK: noalias align 4 dereferenceable(4) i32* @_box(i32* noalias dereferenceable(4) %x)
  66. #[no_mangle]
  67. pub fn _box(x: Box<i32>) -> Box<i32> {
  68. x
  69. }
  70. // CHECK: @struct_return(%S* noalias nocapture sret dereferenceable(32))
  71. #[no_mangle]
  72. pub fn struct_return() -> S {
  73. S {
  74. _field: [0, 0, 0, 0, 0, 0, 0, 0]
  75. }
  76. }
  77. // Hack to get the correct size for the length part in slices
  78. // CHECK: @helper([[USIZE:i[0-9]+]] %arg0)
  79. #[no_mangle]
  80. pub fn helper(_: usize) {
  81. }
  82. // CHECK: @slice([0 x i8]* noalias nonnull readonly %arg0.0, [[USIZE]] %arg0.1)
  83. // FIXME #25759 This should also have `nocapture`
  84. #[no_mangle]
  85. pub fn slice(_: &[u8]) {
  86. }
  87. // CHECK: @mutable_slice([0 x i8]* noalias nonnull %arg0.0, [[USIZE]] %arg0.1)
  88. // FIXME #25759 This should also have `nocapture`
  89. #[no_mangle]
  90. pub fn mutable_slice(_: &mut [u8]) {
  91. }
  92. // CHECK: @unsafe_slice([0 x i16]* nonnull %arg0.0, [[USIZE]] %arg0.1)
  93. // unsafe interior means this isn't actually readonly and there may be aliases ...
  94. #[no_mangle]
  95. pub fn unsafe_slice(_: &[UnsafeInner]) {
  96. }
  97. // CHECK: @str([0 x i8]* noalias nonnull readonly %arg0.0, [[USIZE]] %arg0.1)
  98. // FIXME #25759 This should also have `nocapture`
  99. #[no_mangle]
  100. pub fn str(_: &[u8]) {
  101. }
  102. // CHECK: @trait_borrow({}* nonnull %arg0.0, {}* noalias nonnull readonly %arg0.1)
  103. // FIXME #25759 This should also have `nocapture`
  104. #[no_mangle]
  105. pub fn trait_borrow(_: &Drop) {
  106. }
  107. // CHECK: @trait_box({}* noalias nonnull, {}* noalias nonnull readonly)
  108. #[no_mangle]
  109. pub fn trait_box(_: Box<Drop>) {
  110. }
  111. // CHECK: { i8*, i8* } @trait_option(i8* noalias %x.0, i8* %x.1)
  112. #[no_mangle]
  113. pub fn trait_option(x: Option<Box<Drop>>) -> Option<Box<Drop>> {
  114. x
  115. }
  116. // CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias nonnull readonly %x.0, [[USIZE]] %x.1)
  117. #[no_mangle]
  118. pub fn return_slice(x: &[u16]) -> &[u16] {
  119. x
  120. }
  121. // CHECK: { i16, i16 } @enum_id_1(i16 %x.0, i16 %x.1)
  122. #[no_mangle]
  123. pub fn enum_id_1(x: Option<Result<u16, u16>>) -> Option<Result<u16, u16>> {
  124. x
  125. }
  126. // CHECK: i16 @enum_id_2(i16)
  127. #[no_mangle]
  128. pub fn enum_id_2(x: Option<u8>) -> Option<u8> {
  129. x
  130. }
  131. // CHECK: noalias i8* @allocator()
  132. #[no_mangle]
  133. #[allocator]
  134. pub fn allocator() -> *const i8 {
  135. std::ptr::null()
  136. }