about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-03-04 08:14:31 +0000
committerbors <bors@rust-lang.org>2022-03-04 08:14:31 +0000
commit62ff2bcf9485f52050093d1780f409d50953549b (patch)
treeecdddf9a7d3659d94103c09cef92d27f01603920 /src/test/codegen
parent65f6d33b775eddfc0128c04083bbf3beea360114 (diff)
parenta381aefebb69c7fa518a20f3db6639f29096cc96 (diff)
downloadrust-62ff2bcf9485f52050093d1780f409d50953549b.tar.gz
rust-62ff2bcf9485f52050093d1780f409d50953549b.zip
Auto merge of #94159 - erikdesjardins:align-load, r=nikic
Add !align metadata on loads of &/&mut/Box

Note that this refers to the alignment of what the loaded value points
to, _not_ the alignment of the loaded value itself.

r? `@ghost` (blocked on #94158)
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/loads.rs44
1 files changed, 36 insertions, 8 deletions
diff --git a/src/test/codegen/loads.rs b/src/test/codegen/loads.rs
index 977175a4a62..c7444ce02fa 100644
--- a/src/test/codegen/loads.rs
+++ b/src/test/codegen/loads.rs
@@ -18,21 +18,47 @@ pub enum MyBool {
     False,
 }
 
+#[repr(align(16))]
+pub struct Align16(u128);
+
+// CHECK: @ptr_alignment_helper({}** {{.*}}align [[PTR_ALIGNMENT:[0-9]+]]
+#[no_mangle]
+pub fn ptr_alignment_helper(x: &&()) {}
+
 // CHECK-LABEL: @load_ref
 #[no_mangle]
 pub fn load_ref<'a>(x: &&'a i32) -> &'a i32 {
-// Alignment of a reference itself is target dependent, so just match any alignment:
-// the main thing we care about here is !nonnull and !noundef.
-// CHECK: load i32*, i32** %x, align {{[0-9]+}}, !nonnull !{{[0-9]+}}, !noundef !{{[0-9]+}}
+// CHECK: load i32*, i32** %x, align [[PTR_ALIGNMENT]], !nonnull !{{[0-9]+}}, !align ![[ALIGN_4_META:[0-9]+]], !noundef !{{[0-9]+}}
+    *x
+}
+
+// CHECK-LABEL: @load_ref_higher_alignment
+#[no_mangle]
+pub fn load_ref_higher_alignment<'a>(x: &&'a Align16) -> &'a Align16 {
+// CHECK: load {{%Align16|i128}}*, {{%Align16|i128}}** %x, align [[PTR_ALIGNMENT]], !nonnull !{{[0-9]+}}, !align ![[ALIGN_16_META:[0-9]+]], !noundef !{{[0-9]+}}
+    *x
+}
+
+// CHECK-LABEL: @load_scalar_pair
+#[no_mangle]
+pub fn load_scalar_pair<'a>(x: &(&'a i32, &'a Align16)) -> (&'a i32, &'a Align16) {
+// CHECK: load i32*, i32** %{{.+}}, align [[PTR_ALIGNMENT]], !nonnull !{{[0-9]+}}, !align ![[ALIGN_4_META]], !noundef !{{[0-9]+}}
+// CHECK: load i64*, i64** %{{.+}}, align [[PTR_ALIGNMENT]], !nonnull !{{[0-9]+}}, !align ![[ALIGN_16_META]], !noundef !{{[0-9]+}}
+    *x
+}
+
+// CHECK-LABEL: @load_raw_pointer
+#[no_mangle]
+pub fn load_raw_pointer<'a>(x: &*const i32) -> *const i32 {
+// loaded raw pointer should not have !nonnull, !align, or !noundef metadata
+// CHECK: load i32*, i32** %x, align [[PTR_ALIGNMENT]]{{$}}
     *x
 }
 
 // CHECK-LABEL: @load_box
 #[no_mangle]
 pub fn load_box<'a>(x: Box<Box<i32>>) -> Box<i32> {
-// Alignment of a box itself is target dependent, so just match any alignment:
-// the main thing we care about here is !nonnull and !noundef.
-// CHECK: load i32*, i32** %x, align {{[0-9]+}}, !nonnull !{{[0-9]+}}, !noundef !{{[0-9]+}}
+// CHECK: load i32*, i32** %x, align [[PTR_ALIGNMENT]], !nonnull !{{[0-9]+}}, !align ![[ALIGN_4_META]], !noundef !{{[0-9]+}}
     *x
 }
 
@@ -120,5 +146,7 @@ pub fn small_struct_alignment(x: Bytes) -> Bytes {
     x
 }
 
-// CHECK: ![[BOOL_RANGE]] = !{i8 0, i8 2}
-// CHECK: ![[NONZEROU16_RANGE]] = !{i16 1, i16 0}
+// CHECK-DAG: ![[BOOL_RANGE]] = !{i8 0, i8 2}
+// CHECK-DAG: ![[NONZEROU16_RANGE]] = !{i16 1, i16 0}
+// CHECK-DAG: ![[ALIGN_4_META]] = !{i64 4}
+// CHECK-DAG: ![[ALIGN_16_META]] = !{i64 16}