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

https://gitlab.com/alx741/rust · Rust · 146 lines · 76 code · 24 blank · 46 comment · 0 complexity · bc8de59f9c22abb11a764d63c0c7eb3c 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. #![crate_type = "lib"]
  12. #![feature(allocator)]
  13. pub struct S {
  14. _field: [i64; 4],
  15. }
  16. pub struct UnsafeInner {
  17. _field: std::cell::UnsafeCell<i16>,
  18. }
  19. // CHECK: zeroext i1 @boolean(i1 zeroext)
  20. #[no_mangle]
  21. pub fn boolean(x: bool) -> bool {
  22. x
  23. }
  24. // CHECK: @readonly_borrow(i32* noalias readonly dereferenceable(4))
  25. // FIXME #25759 This should also have `nocapture`
  26. #[no_mangle]
  27. pub fn readonly_borrow(_: &i32) {
  28. }
  29. // CHECK: @static_borrow(i32* noalias readonly dereferenceable(4))
  30. // static borrow may be captured
  31. #[no_mangle]
  32. pub fn static_borrow(_: &'static i32) {
  33. }
  34. // CHECK: @named_borrow(i32* noalias readonly dereferenceable(4))
  35. // borrow with named lifetime may be captured
  36. #[no_mangle]
  37. pub fn named_borrow<'r>(_: &'r i32) {
  38. }
  39. // CHECK: @unsafe_borrow(%UnsafeInner* dereferenceable(2))
  40. // unsafe interior means this isn't actually readonly and there may be aliases ...
  41. #[no_mangle]
  42. pub fn unsafe_borrow(_: &UnsafeInner) {
  43. }
  44. // CHECK: @mutable_unsafe_borrow(%UnsafeInner* dereferenceable(2))
  45. // ... unless this is a mutable borrow, those never alias
  46. // ... except that there's this LLVM bug that forces us to not use noalias, see #29485
  47. #[no_mangle]
  48. pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
  49. }
  50. // CHECK: @mutable_borrow(i32* dereferenceable(4))
  51. // FIXME #25759 This should also have `nocapture`
  52. // ... there's this LLVM bug that forces us to not use noalias, see #29485
  53. #[no_mangle]
  54. pub fn mutable_borrow(_: &mut i32) {
  55. }
  56. // CHECK: @indirect_struct(%S* noalias nocapture dereferenceable(32))
  57. #[no_mangle]
  58. pub fn indirect_struct(_: S) {
  59. }
  60. // CHECK: @borrowed_struct(%S* noalias readonly dereferenceable(32))
  61. // FIXME #25759 This should also have `nocapture`
  62. #[no_mangle]
  63. pub fn borrowed_struct(_: &S) {
  64. }
  65. // CHECK: noalias dereferenceable(4) i32* @_box(i32* noalias dereferenceable(4))
  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]
  75. }
  76. }
  77. // Hack to get the correct size for the length part in slices
  78. // CHECK: @helper([[USIZE:i[0-9]+]])
  79. #[no_mangle]
  80. fn helper(_: usize) {
  81. }
  82. // CHECK: @slice(i8* noalias nonnull readonly, [[USIZE]])
  83. // FIXME #25759 This should also have `nocapture`
  84. #[no_mangle]
  85. fn slice(_: &[u8]) {
  86. }
  87. // CHECK: @mutable_slice(i8* nonnull, [[USIZE]])
  88. // FIXME #25759 This should also have `nocapture`
  89. // ... there's this LLVM bug that forces us to not use noalias, see #29485
  90. #[no_mangle]
  91. fn mutable_slice(_: &mut [u8]) {
  92. }
  93. // CHECK: @unsafe_slice(%UnsafeInner* nonnull, [[USIZE]])
  94. // unsafe interior means this isn't actually readonly and there may be aliases ...
  95. #[no_mangle]
  96. pub fn unsafe_slice(_: &[UnsafeInner]) {
  97. }
  98. // CHECK: @str(i8* noalias nonnull readonly, [[USIZE]])
  99. // FIXME #25759 This should also have `nocapture`
  100. #[no_mangle]
  101. fn str(_: &[u8]) {
  102. }
  103. // CHECK: @trait_borrow(i8* nonnull, void (i8*)** nonnull)
  104. // FIXME #25759 This should also have `nocapture`
  105. #[no_mangle]
  106. fn trait_borrow(_: &Drop) {
  107. }
  108. // CHECK: @trait_box(i8* noalias nonnull, void (i8*)** nonnull)
  109. #[no_mangle]
  110. fn trait_box(_: Box<Drop>) {
  111. }
  112. // CHECK: { i16*, [[USIZE]] } @return_slice(i16* noalias nonnull readonly, [[USIZE]])
  113. #[no_mangle]
  114. fn return_slice(x: &[u16]) -> &[u16] {
  115. x
  116. }
  117. // CHECK: noalias i8* @allocator()
  118. #[no_mangle]
  119. #[allocator]
  120. pub fn allocator() -> *const i8 {
  121. std::ptr::null()
  122. }