/src/test/codegen/naked-functions.rs

https://gitlab.com/alx741/rust · Rust · 69 lines · 30 code · 8 blank · 31 comment · 0 complexity · 5d0f2d592e42c05ed2a067c5a5d715aa 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. // ignore-tidy-linelength
  11. // compile-flags: -C no-prepopulate-passes
  12. #![crate_type = "lib"]
  13. #![feature(naked_functions)]
  14. // CHECK: Function Attrs: naked uwtable
  15. // CHECK-NEXT: define internal void @naked_empty()
  16. #[no_mangle]
  17. #[naked]
  18. fn naked_empty() {
  19. // CHECK: ret void
  20. }
  21. // CHECK: Function Attrs: naked uwtable
  22. #[no_mangle]
  23. #[naked]
  24. // CHECK-NEXT: define internal void @naked_with_args(i{{[0-9]+}})
  25. fn naked_with_args(a: isize) {
  26. // CHECK: %a = alloca i{{[0-9]+}}
  27. // CHECK: ret void
  28. }
  29. // CHECK: Function Attrs: naked uwtable
  30. // CHECK-NEXT: define internal i{{[0-9]+}} @naked_with_return()
  31. #[no_mangle]
  32. #[naked]
  33. fn naked_with_return() -> isize {
  34. // CHECK: ret i{{[0-9]+}} 0
  35. 0
  36. }
  37. // CHECK: Function Attrs: naked uwtable
  38. // CHECK-NEXT: define internal i{{[0-9]+}} @naked_with_args_and_return(i{{[0-9]+}})
  39. #[no_mangle]
  40. #[naked]
  41. fn naked_with_args_and_return(a: isize) -> isize {
  42. // CHECK: %a = alloca i{{[0-9]+}}
  43. // CHECK: ret i{{[0-9]+}} %{{[0-9]+}}
  44. a
  45. }
  46. // CHECK: Function Attrs: naked uwtable
  47. // CHECK-NEXT: define internal void @naked_recursive()
  48. #[no_mangle]
  49. #[naked]
  50. fn naked_recursive() {
  51. // CHECK: call void @naked_empty()
  52. naked_empty();
  53. // CHECK: %{{[0-9]+}} = call i{{[0-9]+}} @naked_with_return()
  54. naked_with_args(
  55. // CHECK: %{{[0-9]+}} = call i{{[0-9]+}} @naked_with_args_and_return(i{{[0-9]+}} %{{[0-9]+}})
  56. naked_with_args_and_return(
  57. // CHECK: call void @naked_with_args(i{{[0-9]+}} %{{[0-9]+}})
  58. naked_with_return()
  59. )
  60. );
  61. }