/src/test/codegen/align-struct.rs

https://gitlab.com/rust-lang/rust · Rust · 71 lines · 41 code · 10 blank · 20 comment · 0 complexity · ad683d2f9962a3a616a49727f0e4c81e MD5 · raw file

  1. // compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0
  2. //
  3. #![crate_type = "lib"]
  4. #[repr(align(64))]
  5. pub struct Align64(i32);
  6. // CHECK: %Align64 = type { i32, [15 x i32] }
  7. pub struct Nested64 {
  8. a: Align64,
  9. b: i32,
  10. c: i32,
  11. d: i8,
  12. }
  13. // CHECK: %Nested64 = type { %Align64, i32, i32, i8, [55 x i8] }
  14. pub enum Enum4 {
  15. A(i32),
  16. B(i32),
  17. }
  18. // No Aggregate type, and hence nothing in LLVM IR.
  19. pub enum Enum64 {
  20. A(Align64),
  21. B(i32),
  22. }
  23. // CHECK: %Enum64 = type { i32, [31 x i32] }
  24. // CHECK: %"Enum64::A" = type { [8 x i64], %Align64 }
  25. // CHECK-LABEL: @align64
  26. #[no_mangle]
  27. pub fn align64(i : i32) -> Align64 {
  28. // CHECK: %a64 = alloca %Align64, align 64
  29. // CHECK: call void @llvm.memcpy.{{.*}}({{i8\*|ptr}} align 64 %{{.*}}, {{i8\*|ptr}} align 64 %{{.*}}, i{{[0-9]+}} 64, i1 false)
  30. let a64 = Align64(i);
  31. a64
  32. }
  33. // For issue 54028: make sure that we are specifying the correct alignment for fields of aligned
  34. // structs
  35. // CHECK-LABEL: @align64_load
  36. #[no_mangle]
  37. pub fn align64_load(a: Align64) -> i32 {
  38. // CHECK: {{%.*}} = load i32, {{i32\*|ptr}} {{%.*}}, align 64
  39. a.0
  40. }
  41. // CHECK-LABEL: @nested64
  42. #[no_mangle]
  43. pub fn nested64(a: Align64, b: i32, c: i32, d: i8) -> Nested64 {
  44. // CHECK: %n64 = alloca %Nested64, align 64
  45. let n64 = Nested64 { a, b, c, d };
  46. n64
  47. }
  48. // CHECK-LABEL: @enum4
  49. #[no_mangle]
  50. pub fn enum4(a: i32) -> Enum4 {
  51. // CHECK: %e4 = alloca { i32, i32 }, align 4
  52. let e4 = Enum4::A(a);
  53. e4
  54. }
  55. // CHECK-LABEL: @enum64
  56. #[no_mangle]
  57. pub fn enum64(a: Align64) -> Enum64 {
  58. // CHECK: %e64 = alloca %Enum64, align 64
  59. let e64 = Enum64::A(a);
  60. e64
  61. }