about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJannis Christopher Köhl <mail@koehl.dev>2022-11-11 11:24:31 +0100
committerJannis Christopher Köhl <mail@koehl.dev>2022-11-11 11:24:31 +0100
commit3c6d1a723d2d6466d8ee34d4f442a60fdc8cfa1b (patch)
treee1898d300e093552f38f7249866a6668f8d82ee4
parent8ecb276735f61ef3822b5ed6a48d1c8fd591b79b (diff)
downloadrust-3c6d1a723d2d6466d8ee34d4f442a60fdc8cfa1b.tar.gz
rust-3c6d1a723d2d6466d8ee34d4f442a60fdc8cfa1b.zip
Add test for repr(transparent) with scalar
-rw-r--r--compiler/rustc_mir_dataflow/src/value_analysis.rs7
-rw-r--r--src/test/mir-opt/dataflow-const-prop/repr_transparent.main.DataflowConstProp.diff44
-rw-r--r--src/test/mir-opt/dataflow-const-prop/repr_transparent.rs12
3 files changed, 61 insertions, 2 deletions
diff --git a/compiler/rustc_mir_dataflow/src/value_analysis.rs b/compiler/rustc_mir_dataflow/src/value_analysis.rs
index 13072a30282..0f3b952ceec 100644
--- a/compiler/rustc_mir_dataflow/src/value_analysis.rs
+++ b/compiler/rustc_mir_dataflow/src/value_analysis.rs
@@ -614,7 +614,7 @@ impl Map {
         }
     }
 
-    /// Register fields of the given (local, projection) place.
+    /// Potentially register the (local, projection) place and its fields, recursively.
     ///
     /// Invariant: The projection must only contain fields.
     fn register_with_filter_rec<'tcx>(
@@ -626,13 +626,16 @@ impl Map {
         filter: &mut impl FnMut(Ty<'tcx>) -> bool,
         exclude: &FxHashSet<Place<'tcx>>,
     ) {
-        if exclude.contains(&Place { local, projection: tcx.intern_place_elems(projection) }) {
+        let place = Place { local, projection: tcx.intern_place_elems(projection) };
+        if exclude.contains(&place) {
             // This will also exclude all projections of the excluded place.
             return;
         }
 
         // Note: The framework supports only scalars for now.
         if filter(ty) && ty.is_scalar() {
+            trace!("registering place: {:?}", place);
+
             // We know that the projection only contains trackable elements.
             let place = self.make_place(local, projection).unwrap();
 
diff --git a/src/test/mir-opt/dataflow-const-prop/repr_transparent.main.DataflowConstProp.diff b/src/test/mir-opt/dataflow-const-prop/repr_transparent.main.DataflowConstProp.diff
new file mode 100644
index 00000000000..f66b00a9a22
--- /dev/null
+++ b/src/test/mir-opt/dataflow-const-prop/repr_transparent.main.DataflowConstProp.diff
@@ -0,0 +1,44 @@
+- // MIR for `main` before DataflowConstProp
++ // MIR for `main` after DataflowConstProp
+  
+  fn main() -> () {
+      let mut _0: ();                      // return place in scope 0 at $DIR/repr_transparent.rs:+0:11: +0:11
+      let _1: I32;                         // in scope 0 at $DIR/repr_transparent.rs:+1:9: +1:10
+      let mut _3: i32;                     // in scope 0 at $DIR/repr_transparent.rs:+2:17: +2:26
+      let mut _4: i32;                     // in scope 0 at $DIR/repr_transparent.rs:+2:17: +2:20
+      let mut _5: i32;                     // in scope 0 at $DIR/repr_transparent.rs:+2:23: +2:26
+      scope 1 {
+          debug x => _1;                   // in scope 1 at $DIR/repr_transparent.rs:+1:9: +1:10
+          let _2: I32;                     // in scope 1 at $DIR/repr_transparent.rs:+2:9: +2:10
+          scope 2 {
+              debug y => _2;               // in scope 2 at $DIR/repr_transparent.rs:+2:9: +2:10
+          }
+      }
+  
+      bb0: {
+          StorageLive(_1);                 // scope 0 at $DIR/repr_transparent.rs:+1:9: +1:10
+          Deinit(_1);                      // scope 0 at $DIR/repr_transparent.rs:+1:13: +1:19
+          (_1.0: i32) = const 0_i32;       // scope 0 at $DIR/repr_transparent.rs:+1:13: +1:19
+          StorageLive(_2);                 // scope 1 at $DIR/repr_transparent.rs:+2:9: +2:10
+          StorageLive(_3);                 // scope 1 at $DIR/repr_transparent.rs:+2:17: +2:26
+          StorageLive(_4);                 // scope 1 at $DIR/repr_transparent.rs:+2:17: +2:20
+-         _4 = (_1.0: i32);                // scope 1 at $DIR/repr_transparent.rs:+2:17: +2:20
++         _4 = const 0_i32;                // scope 1 at $DIR/repr_transparent.rs:+2:17: +2:20
+          StorageLive(_5);                 // scope 1 at $DIR/repr_transparent.rs:+2:23: +2:26
+-         _5 = (_1.0: i32);                // scope 1 at $DIR/repr_transparent.rs:+2:23: +2:26
+-         _3 = Add(move _4, move _5);      // scope 1 at $DIR/repr_transparent.rs:+2:17: +2:26
++         _5 = const 0_i32;                // scope 1 at $DIR/repr_transparent.rs:+2:23: +2:26
++         _3 = const 0_i32;                // scope 1 at $DIR/repr_transparent.rs:+2:17: +2:26
+          StorageDead(_5);                 // scope 1 at $DIR/repr_transparent.rs:+2:25: +2:26
+          StorageDead(_4);                 // scope 1 at $DIR/repr_transparent.rs:+2:25: +2:26
+          Deinit(_2);                      // scope 1 at $DIR/repr_transparent.rs:+2:13: +2:27
+-         (_2.0: i32) = move _3;           // scope 1 at $DIR/repr_transparent.rs:+2:13: +2:27
++         (_2.0: i32) = const 0_i32;       // scope 1 at $DIR/repr_transparent.rs:+2:13: +2:27
+          StorageDead(_3);                 // scope 1 at $DIR/repr_transparent.rs:+2:26: +2:27
+          _0 = const ();                   // scope 0 at $DIR/repr_transparent.rs:+0:11: +3:2
+          StorageDead(_2);                 // scope 1 at $DIR/repr_transparent.rs:+3:1: +3:2
+          StorageDead(_1);                 // scope 0 at $DIR/repr_transparent.rs:+3:1: +3:2
+          return;                          // scope 0 at $DIR/repr_transparent.rs:+3:2: +3:2
+      }
+  }
+  
diff --git a/src/test/mir-opt/dataflow-const-prop/repr_transparent.rs b/src/test/mir-opt/dataflow-const-prop/repr_transparent.rs
new file mode 100644
index 00000000000..4ce0ca4dff4
--- /dev/null
+++ b/src/test/mir-opt/dataflow-const-prop/repr_transparent.rs
@@ -0,0 +1,12 @@
+// unit-test: DataflowConstProp
+
+// The struct has scalar ABI, but is not a scalar type.
+// Make sure that we handle this correctly.
+#[repr(transparent)]
+struct I32(i32);
+
+// EMIT_MIR repr_transparent.main.DataflowConstProp.diff
+fn main() {
+    let x = I32(0);
+    let y = I32(x.0 + x.0);
+}