about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/mir-opt/inline/cycle.f.Inline.diff42
-rw-r--r--src/test/mir-opt/inline/cycle.g.Inline.diff25
-rw-r--r--src/test/mir-opt/inline/cycle.main.Inline.diff25
-rw-r--r--src/test/mir-opt/inline/cycle.rs18
-rw-r--r--src/test/mir-opt/inline/inline-cycle-generic.rs40
-rw-r--r--src/test/mir-opt/inline/inline_cycle_generic.main.Inline.diff29
-rw-r--r--src/test/ui/const_prop/inline_spans_lint_attribute.rs15
7 files changed, 194 insertions, 0 deletions
diff --git a/src/test/mir-opt/inline/cycle.f.Inline.diff b/src/test/mir-opt/inline/cycle.f.Inline.diff
new file mode 100644
index 00000000000..54dd545dfb9
--- /dev/null
+++ b/src/test/mir-opt/inline/cycle.f.Inline.diff
@@ -0,0 +1,42 @@
+- // MIR for `f` before Inline
++ // MIR for `f` after Inline
+  
+  fn f(_1: impl Fn()) -> () {
+      debug g => _1;                       // in scope 0 at $DIR/cycle.rs:5:6: 5:7
+      let mut _0: ();                      // return place in scope 0 at $DIR/cycle.rs:5:20: 5:20
+      let _2: ();                          // in scope 0 at $DIR/cycle.rs:6:5: 6:8
+      let mut _3: &impl Fn();              // in scope 0 at $DIR/cycle.rs:6:5: 6:6
+      let mut _4: ();                      // in scope 0 at $DIR/cycle.rs:6:5: 6:8
+  
+      bb0: {
+          StorageLive(_2);                 // scope 0 at $DIR/cycle.rs:6:5: 6:8
+          StorageLive(_3);                 // scope 0 at $DIR/cycle.rs:6:5: 6:6
+          _3 = &_1;                        // scope 0 at $DIR/cycle.rs:6:5: 6:6
+          StorageLive(_4);                 // scope 0 at $DIR/cycle.rs:6:5: 6:8
+          _2 = <impl Fn() as Fn<()>>::call(move _3, move _4) -> [return: bb1, unwind: bb3]; // scope 0 at $DIR/cycle.rs:6:5: 6:8
+                                           // mir::Constant
+                                           // + span: $DIR/cycle.rs:6:5: 6:6
+                                           // + literal: Const { ty: for<'r> extern "rust-call" fn(&'r impl Fn(), ()) -> <impl Fn() as std::ops::FnOnce<()>>::Output {<impl Fn() as std::ops::Fn<()>>::call}, val: Value(Scalar(<ZST>)) }
+      }
+  
+      bb1: {
+          StorageDead(_4);                 // scope 0 at $DIR/cycle.rs:6:7: 6:8
+          StorageDead(_3);                 // scope 0 at $DIR/cycle.rs:6:7: 6:8
+          StorageDead(_2);                 // scope 0 at $DIR/cycle.rs:6:8: 6:9
+          _0 = const ();                   // scope 0 at $DIR/cycle.rs:5:20: 7:2
+          drop(_1) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/cycle.rs:7:1: 7:2
+      }
+  
+      bb2: {
+          return;                          // scope 0 at $DIR/cycle.rs:7:2: 7:2
+      }
+  
+      bb3 (cleanup): {
+          drop(_1) -> bb4;                 // scope 0 at $DIR/cycle.rs:7:1: 7:2
+      }
+  
+      bb4 (cleanup): {
+          resume;                          // scope 0 at $DIR/cycle.rs:5:1: 7:2
+      }
+  }
+  
diff --git a/src/test/mir-opt/inline/cycle.g.Inline.diff b/src/test/mir-opt/inline/cycle.g.Inline.diff
new file mode 100644
index 00000000000..46f5e5e2065
--- /dev/null
+++ b/src/test/mir-opt/inline/cycle.g.Inline.diff
@@ -0,0 +1,25 @@
+- // MIR for `g` before Inline
++ // MIR for `g` after Inline
+  
+  fn g() -> () {
+      let mut _0: ();                      // return place in scope 0 at $DIR/cycle.rs:11:8: 11:8
+      let _1: ();                          // in scope 0 at $DIR/cycle.rs:12:5: 12:12
+  
+      bb0: {
+          StorageLive(_1);                 // scope 0 at $DIR/cycle.rs:12:5: 12:12
+          _1 = f::<fn() {main}>(main) -> bb1; // scope 0 at $DIR/cycle.rs:12:5: 12:12
+                                           // mir::Constant
+                                           // + span: $DIR/cycle.rs:12:5: 12:6
+                                           // + literal: Const { ty: fn(fn() {main}) {f::<fn() {main}>}, val: Value(Scalar(<ZST>)) }
+                                           // mir::Constant
+                                           // + span: $DIR/cycle.rs:12:7: 12:11
+                                           // + literal: Const { ty: fn() {main}, val: Value(Scalar(<ZST>)) }
+      }
+  
+      bb1: {
+          StorageDead(_1);                 // scope 0 at $DIR/cycle.rs:12:12: 12:13
+          _0 = const ();                   // scope 0 at $DIR/cycle.rs:11:8: 13:2
+          return;                          // scope 0 at $DIR/cycle.rs:13:2: 13:2
+      }
+  }
+  
diff --git a/src/test/mir-opt/inline/cycle.main.Inline.diff b/src/test/mir-opt/inline/cycle.main.Inline.diff
new file mode 100644
index 00000000000..c8d1448d949
--- /dev/null
+++ b/src/test/mir-opt/inline/cycle.main.Inline.diff
@@ -0,0 +1,25 @@
+- // MIR for `main` before Inline
++ // MIR for `main` after Inline
+  
+  fn main() -> () {
+      let mut _0: ();                      // return place in scope 0 at $DIR/cycle.rs:16:11: 16:11
+      let _1: ();                          // in scope 0 at $DIR/cycle.rs:17:5: 17:9
+  
+      bb0: {
+          StorageLive(_1);                 // scope 0 at $DIR/cycle.rs:17:5: 17:9
+          _1 = f::<fn() {g}>(g) -> bb1;    // scope 0 at $DIR/cycle.rs:17:5: 17:9
+                                           // mir::Constant
+                                           // + span: $DIR/cycle.rs:17:5: 17:6
+                                           // + literal: Const { ty: fn(fn() {g}) {f::<fn() {g}>}, val: Value(Scalar(<ZST>)) }
+                                           // mir::Constant
+                                           // + span: $DIR/cycle.rs:17:7: 17:8
+                                           // + literal: Const { ty: fn() {g}, val: Value(Scalar(<ZST>)) }
+      }
+  
+      bb1: {
+          StorageDead(_1);                 // scope 0 at $DIR/cycle.rs:17:9: 17:10
+          _0 = const ();                   // scope 0 at $DIR/cycle.rs:16:11: 18:2
+          return;                          // scope 0 at $DIR/cycle.rs:18:2: 18:2
+      }
+  }
+  
diff --git a/src/test/mir-opt/inline/cycle.rs b/src/test/mir-opt/inline/cycle.rs
new file mode 100644
index 00000000000..9e8950d8a3d
--- /dev/null
+++ b/src/test/mir-opt/inline/cycle.rs
@@ -0,0 +1,18 @@
+// ignore-wasm32-bare compiled with panic=abort by default
+
+// EMIT_MIR cycle.f.Inline.diff
+#[inline(always)]
+fn f(g: impl Fn()) {
+    g();
+}
+
+// EMIT_MIR cycle.g.Inline.diff
+#[inline(always)]
+fn g() {
+    f(main);
+}
+
+// EMIT_MIR cycle.main.Inline.diff
+fn main() {
+    f(g);
+}
diff --git a/src/test/mir-opt/inline/inline-cycle-generic.rs b/src/test/mir-opt/inline/inline-cycle-generic.rs
new file mode 100644
index 00000000000..24b4f37939a
--- /dev/null
+++ b/src/test/mir-opt/inline/inline-cycle-generic.rs
@@ -0,0 +1,40 @@
+// Check that inliner handles various forms of recursion and doesn't fall into
+// an infinite inlining cycle. The particular outcome of inlining is not
+// crucial otherwise.
+//
+// Regression test for issue #78573.
+
+// EMIT_MIR inline_cycle_generic.main.Inline.diff
+fn main() {
+    <C as Call>::call();
+}
+
+pub trait Call {
+    fn call();
+}
+
+pub struct A;
+pub struct B<T>(T);
+pub struct C;
+
+impl Call for A {
+    #[inline]
+    fn call() {
+        <B<C> as Call>::call()
+    }
+}
+
+
+impl<T: Call> Call for B<T> {
+    #[inline]
+    fn call() {
+        <T as Call>::call()
+    }
+}
+
+impl Call for C {
+    #[inline]
+    fn call() {
+        <B<A> as Call>::call()
+    }
+}
diff --git a/src/test/mir-opt/inline/inline_cycle_generic.main.Inline.diff b/src/test/mir-opt/inline/inline_cycle_generic.main.Inline.diff
new file mode 100644
index 00000000000..9709f273779
--- /dev/null
+++ b/src/test/mir-opt/inline/inline_cycle_generic.main.Inline.diff
@@ -0,0 +1,29 @@
+- // MIR for `main` before Inline
++ // MIR for `main` after Inline
+  
+  fn main() -> () {
+      let mut _0: ();                      // return place in scope 0 at $DIR/inline-cycle-generic.rs:8:11: 8:11
+      let _1: ();                          // in scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24
++     scope 1 (inlined <C as Call>::call) { // at $DIR/inline-cycle-generic.rs:9:5: 9:24
++         scope 2 (inlined <B<A> as Call>::call) { // at $DIR/inline-cycle-generic.rs:9:5: 9:24
++         }
++     }
+  
+      bb0: {
+          StorageLive(_1);                 // scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24
+-         _1 = <C as Call>::call() -> bb1; // scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24
++         _1 = <A as Call>::call() -> bb1; // scope 2 at $DIR/inline-cycle-generic.rs:9:5: 9:24
+                                           // mir::Constant
+-                                          // + span: $DIR/inline-cycle-generic.rs:9:5: 9:22
+-                                          // + literal: Const { ty: fn() {<C as Call>::call}, val: Value(Scalar(<ZST>)) }
++                                          // + span: $DIR/inline-cycle-generic.rs:9:5: 9:24
++                                          // + literal: Const { ty: fn() {<A as Call>::call}, val: Value(Scalar(<ZST>)) }
+      }
+  
+      bb1: {
+          StorageDead(_1);                 // scope 0 at $DIR/inline-cycle-generic.rs:9:24: 9:25
+          _0 = const ();                   // scope 0 at $DIR/inline-cycle-generic.rs:8:11: 10:2
+          return;                          // scope 0 at $DIR/inline-cycle-generic.rs:10:2: 10:2
+      }
+  }
+  
diff --git a/src/test/ui/const_prop/inline_spans_lint_attribute.rs b/src/test/ui/const_prop/inline_spans_lint_attribute.rs
new file mode 100644
index 00000000000..656ff02dc67
--- /dev/null
+++ b/src/test/ui/const_prop/inline_spans_lint_attribute.rs
@@ -0,0 +1,15 @@
+// Must be build-pass, because check-pass will not run const prop and thus not emit the lint anyway.
+// build-pass
+// compile-flags: -Zmir-opt-level=2
+
+#![deny(warnings)]
+
+fn main() {
+    #[allow(arithmetic_overflow)]
+    let _ = add(u8::MAX, 1);
+}
+
+#[inline(always)]
+fn add(x: u8, y: u8) -> u8 {
+    x + y
+}