Skip to content

Commit 2fdcdd9

Browse files
authored
Rollup merge of rust-lang#121753 - mu001999:core/add_cfg, r=cuviper
Add proper cfg to keep only one AlignmentEnum definition for different target_pointer_widths Detected by rust-lang#121752 Only one AlignmentEnum would be used with a specified target_pointer_width
2 parents 419f7ae + 88b9e7a commit 2fdcdd9

5 files changed

+17
-21
lines changed

library/core/src/ptr/alignment.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,9 @@ impl Default for Alignment {
234234
}
235235

236236
#[cfg(target_pointer_width = "16")]
237-
type AlignmentEnum = AlignmentEnum16;
238-
#[cfg(target_pointer_width = "32")]
239-
type AlignmentEnum = AlignmentEnum32;
240-
#[cfg(target_pointer_width = "64")]
241-
type AlignmentEnum = AlignmentEnum64;
242-
243237
#[derive(Copy, Clone, PartialEq, Eq)]
244238
#[repr(u16)]
245-
enum AlignmentEnum16 {
239+
enum AlignmentEnum {
246240
_Align1Shl0 = 1 << 0,
247241
_Align1Shl1 = 1 << 1,
248242
_Align1Shl2 = 1 << 2,
@@ -261,9 +255,10 @@ enum AlignmentEnum16 {
261255
_Align1Shl15 = 1 << 15,
262256
}
263257

258+
#[cfg(target_pointer_width = "32")]
264259
#[derive(Copy, Clone, PartialEq, Eq)]
265260
#[repr(u32)]
266-
enum AlignmentEnum32 {
261+
enum AlignmentEnum {
267262
_Align1Shl0 = 1 << 0,
268263
_Align1Shl1 = 1 << 1,
269264
_Align1Shl2 = 1 << 2,
@@ -298,9 +293,10 @@ enum AlignmentEnum32 {
298293
_Align1Shl31 = 1 << 31,
299294
}
300295

296+
#[cfg(target_pointer_width = "64")]
301297
#[derive(Copy, Clone, PartialEq, Eq)]
302298
#[repr(u64)]
303-
enum AlignmentEnum64 {
299+
enum AlignmentEnum {
304300
_Align1Shl0 = 1 << 0,
305301
_Align1Shl1 = 1 << 1,
306302
_Align1Shl2 = 1 << 2,

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
bb2: {
7171
- _1 = move ((_2 as Some).0: std::alloc::Layout);
72-
+ _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum32) }};
72+
+ _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }};
7373
StorageDead(_10);
7474
StorageDead(_2);
7575
StorageLive(_3);
@@ -83,8 +83,8 @@
8383
StorageLive(_8);
8484
- _8 = _1;
8585
- _6 = std::alloc::Global::alloc_impl(move _7, move _8, const false) -> [return: bb3, unwind unreachable];
86-
+ _8 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum32) }};
87-
+ _6 = std::alloc::Global::alloc_impl(const {ALLOC1<imm>: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum32) }}, const false) -> [return: bb3, unwind unreachable];
86+
+ _8 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }};
87+
+ _6 = std::alloc::Global::alloc_impl(const {ALLOC1<imm>: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb3, unwind unreachable];
8888
}
8989

9090
bb3: {

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
bb3: {
7575
- _1 = move ((_2 as Some).0: std::alloc::Layout);
76-
+ _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum32) }};
76+
+ _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }};
7777
StorageDead(_10);
7878
StorageDead(_2);
7979
StorageLive(_3);
@@ -87,8 +87,8 @@
8787
StorageLive(_8);
8888
- _8 = _1;
8989
- _6 = std::alloc::Global::alloc_impl(move _7, move _8, const false) -> [return: bb4, unwind continue];
90-
+ _8 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum32) }};
91-
+ _6 = std::alloc::Global::alloc_impl(const {ALLOC1<imm>: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum32) }}, const false) -> [return: bb4, unwind continue];
90+
+ _8 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }};
91+
+ _6 = std::alloc::Global::alloc_impl(const {ALLOC1<imm>: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb4, unwind continue];
9292
}
9393

9494
bb4: {

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
bb2: {
7171
- _1 = move ((_2 as Some).0: std::alloc::Layout);
72-
+ _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum64) }};
72+
+ _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }};
7373
StorageDead(_10);
7474
StorageDead(_2);
7575
StorageLive(_3);
@@ -83,8 +83,8 @@
8383
StorageLive(_8);
8484
- _8 = _1;
8585
- _6 = std::alloc::Global::alloc_impl(move _7, move _8, const false) -> [return: bb3, unwind unreachable];
86-
+ _8 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum64) }};
87-
+ _6 = std::alloc::Global::alloc_impl(const {ALLOC1<imm>: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum64) }}, const false) -> [return: bb3, unwind unreachable];
86+
+ _8 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }};
87+
+ _6 = std::alloc::Global::alloc_impl(const {ALLOC1<imm>: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb3, unwind unreachable];
8888
}
8989

9090
bb3: {

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
bb3: {
7575
- _1 = move ((_2 as Some).0: std::alloc::Layout);
76-
+ _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum64) }};
76+
+ _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }};
7777
StorageDead(_10);
7878
StorageDead(_2);
7979
StorageLive(_3);
@@ -87,8 +87,8 @@
8787
StorageLive(_8);
8888
- _8 = _1;
8989
- _6 = std::alloc::Global::alloc_impl(move _7, move _8, const false) -> [return: bb4, unwind continue];
90-
+ _8 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum64) }};
91-
+ _6 = std::alloc::Global::alloc_impl(const {ALLOC1<imm>: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum64) }}, const false) -> [return: bb4, unwind continue];
90+
+ _8 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }};
91+
+ _6 = std::alloc::Global::alloc_impl(const {ALLOC1<imm>: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb4, unwind continue];
9292
}
9393

9494
bb4: {

0 commit comments

Comments
 (0)