Skip to content

Commit 3c6d1a7

Browse files
committed
Add test for repr(transparent) with scalar
1 parent 8ecb276 commit 3c6d1a7

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

compiler/rustc_mir_dataflow/src/value_analysis.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ impl Map {
614614
}
615615
}
616616

617-
/// Register fields of the given (local, projection) place.
617+
/// Potentially register the (local, projection) place and its fields, recursively.
618618
///
619619
/// Invariant: The projection must only contain fields.
620620
fn register_with_filter_rec<'tcx>(
@@ -626,13 +626,16 @@ impl Map {
626626
filter: &mut impl FnMut(Ty<'tcx>) -> bool,
627627
exclude: &FxHashSet<Place<'tcx>>,
628628
) {
629-
if exclude.contains(&Place { local, projection: tcx.intern_place_elems(projection) }) {
629+
let place = Place { local, projection: tcx.intern_place_elems(projection) };
630+
if exclude.contains(&place) {
630631
// This will also exclude all projections of the excluded place.
631632
return;
632633
}
633634

634635
// Note: The framework supports only scalars for now.
635636
if filter(ty) && ty.is_scalar() {
637+
trace!("registering place: {:?}", place);
638+
636639
// We know that the projection only contains trackable elements.
637640
let place = self.make_place(local, projection).unwrap();
638641

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
- // MIR for `main` before DataflowConstProp
2+
+ // MIR for `main` after DataflowConstProp
3+
4+
fn main() -> () {
5+
let mut _0: (); // return place in scope 0 at $DIR/repr_transparent.rs:+0:11: +0:11
6+
let _1: I32; // in scope 0 at $DIR/repr_transparent.rs:+1:9: +1:10
7+
let mut _3: i32; // in scope 0 at $DIR/repr_transparent.rs:+2:17: +2:26
8+
let mut _4: i32; // in scope 0 at $DIR/repr_transparent.rs:+2:17: +2:20
9+
let mut _5: i32; // in scope 0 at $DIR/repr_transparent.rs:+2:23: +2:26
10+
scope 1 {
11+
debug x => _1; // in scope 1 at $DIR/repr_transparent.rs:+1:9: +1:10
12+
let _2: I32; // in scope 1 at $DIR/repr_transparent.rs:+2:9: +2:10
13+
scope 2 {
14+
debug y => _2; // in scope 2 at $DIR/repr_transparent.rs:+2:9: +2:10
15+
}
16+
}
17+
18+
bb0: {
19+
StorageLive(_1); // scope 0 at $DIR/repr_transparent.rs:+1:9: +1:10
20+
Deinit(_1); // scope 0 at $DIR/repr_transparent.rs:+1:13: +1:19
21+
(_1.0: i32) = const 0_i32; // scope 0 at $DIR/repr_transparent.rs:+1:13: +1:19
22+
StorageLive(_2); // scope 1 at $DIR/repr_transparent.rs:+2:9: +2:10
23+
StorageLive(_3); // scope 1 at $DIR/repr_transparent.rs:+2:17: +2:26
24+
StorageLive(_4); // scope 1 at $DIR/repr_transparent.rs:+2:17: +2:20
25+
- _4 = (_1.0: i32); // scope 1 at $DIR/repr_transparent.rs:+2:17: +2:20
26+
+ _4 = const 0_i32; // scope 1 at $DIR/repr_transparent.rs:+2:17: +2:20
27+
StorageLive(_5); // scope 1 at $DIR/repr_transparent.rs:+2:23: +2:26
28+
- _5 = (_1.0: i32); // scope 1 at $DIR/repr_transparent.rs:+2:23: +2:26
29+
- _3 = Add(move _4, move _5); // scope 1 at $DIR/repr_transparent.rs:+2:17: +2:26
30+
+ _5 = const 0_i32; // scope 1 at $DIR/repr_transparent.rs:+2:23: +2:26
31+
+ _3 = const 0_i32; // scope 1 at $DIR/repr_transparent.rs:+2:17: +2:26
32+
StorageDead(_5); // scope 1 at $DIR/repr_transparent.rs:+2:25: +2:26
33+
StorageDead(_4); // scope 1 at $DIR/repr_transparent.rs:+2:25: +2:26
34+
Deinit(_2); // scope 1 at $DIR/repr_transparent.rs:+2:13: +2:27
35+
- (_2.0: i32) = move _3; // scope 1 at $DIR/repr_transparent.rs:+2:13: +2:27
36+
+ (_2.0: i32) = const 0_i32; // scope 1 at $DIR/repr_transparent.rs:+2:13: +2:27
37+
StorageDead(_3); // scope 1 at $DIR/repr_transparent.rs:+2:26: +2:27
38+
_0 = const (); // scope 0 at $DIR/repr_transparent.rs:+0:11: +3:2
39+
StorageDead(_2); // scope 1 at $DIR/repr_transparent.rs:+3:1: +3:2
40+
StorageDead(_1); // scope 0 at $DIR/repr_transparent.rs:+3:1: +3:2
41+
return; // scope 0 at $DIR/repr_transparent.rs:+3:2: +3:2
42+
}
43+
}
44+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// unit-test: DataflowConstProp
2+
3+
// The struct has scalar ABI, but is not a scalar type.
4+
// Make sure that we handle this correctly.
5+
#[repr(transparent)]
6+
struct I32(i32);
7+
8+
// EMIT_MIR repr_transparent.main.DataflowConstProp.diff
9+
fn main() {
10+
let x = I32(0);
11+
let y = I32(x.0 + x.0);
12+
}

0 commit comments

Comments
 (0)