/src/test/codegen/stores.rs

https://gitlab.com/alx741/rust · Rust · 43 lines · 18 code · 5 blank · 20 comment · 0 complexity · d4b2e6d7b82796ac03b9612ac9d88fc5 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. pub struct Bytes {
  14. a: u8,
  15. b: u8,
  16. c: u8,
  17. d: u8,
  18. }
  19. // CHECK-LABEL: small_array_alignment
  20. // The array is stored as i32, but its alignment is lower, go with 1 byte to avoid target
  21. // dependent alignment
  22. #[no_mangle]
  23. #[rustc_no_mir] // FIXME #27840 MIR has different codegen.
  24. pub fn small_array_alignment(x: &mut [i8; 4], y: [i8; 4]) {
  25. // CHECK: [[VAR:%[0-9]+]] = bitcast [4 x i8]* %y to i32*
  26. // CHECK: store i32 %{{.*}}, i32* [[VAR]], align 1
  27. *x = y;
  28. }
  29. // CHECK-LABEL: small_struct_alignment
  30. // The struct is stored as i32, but its alignment is lower, go with 1 byte to avoid target
  31. // dependent alignment
  32. #[no_mangle]
  33. #[rustc_no_mir] // FIXME #27840 MIR has different codegen.
  34. pub fn small_struct_alignment(x: &mut Bytes, y: Bytes) {
  35. // CHECK: [[VAR:%[0-9]+]] = bitcast %Bytes* %y to i32*
  36. // CHECK: store i32 %{{.*}}, i32* [[VAR]], align 1
  37. *x = y;
  38. }