/src/test/codegen/adjustments.rs

https://gitlab.com/alx741/rust · Rust · 41 lines · 14 code · 5 blank · 22 comment · 0 complexity · 12e72dce73e1a606c7b0148119aa90ec 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(rustc_attrs)]
  13. // Hack to get the correct size for the length part in slices
  14. // CHECK: @helper([[USIZE:i[0-9]+]])
  15. #[no_mangle]
  16. fn helper(_: usize) {
  17. }
  18. // CHECK-LABEL: @no_op_slice_adjustment
  19. #[no_mangle]
  20. #[rustc_no_mir] // FIXME #27840 MIR has different codegen.
  21. pub fn no_op_slice_adjustment(x: &[u8]) -> &[u8] {
  22. // We used to generate an extra alloca and memcpy for the block's trailing expression value, so
  23. // check that we copy directly to the return value slot
  24. // CHECK: [[SRC:%[0-9]+]] = bitcast { i8*, [[USIZE]] }* %x to
  25. // CHECK: [[DST:%[0-9]+]] = bitcast { i8*, [[USIZE]] }* %sret_slot to i8*
  26. // CHECK: call void @llvm.memcpy.{{.*}}(i8* [[DST]], i8* [[SRC]],
  27. { x }
  28. }
  29. // CHECK-LABEL: @no_op_slice_adjustment2
  30. #[no_mangle]
  31. pub fn no_op_slice_adjustment2(x: &[u8]) -> &[u8] {
  32. // We used to generate an extra alloca and memcpy for the function's return value, so check
  33. // that there's no memcpy (the slice is written to sret_slot element-wise)
  34. // CHECK-NOT: call void @llvm.memcpy.
  35. no_op_slice_adjustment(x)
  36. }