[COMMITTED] gccrs: testsuite: add loop condition execution test

Message ID 20230131132607.662907-1-arthur.cohen@embecosm.com
State Repeat Merge
Headers
Series [COMMITTED] gccrs: testsuite: add loop condition execution test |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Arthur Cohen Jan. 31, 2023, 1:26 p.m. UTC
  From: liushuyu <liushuyu011@gmail.com>

gcc/testsuite/ChangeLog:

	* rust/execute/torture/loop-condition-eval.rs: New test.

Signed-off-by: Zixing Liu <liushuyu011@gmail.com>

Tested on x86_64-pc-linux-gnu, committed on master.

---
 .../execute/torture/loop-condition-eval.rs    | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 gcc/testsuite/rust/execute/torture/loop-condition-eval.rs
  

Patch

diff --git a/gcc/testsuite/rust/execute/torture/loop-condition-eval.rs b/gcc/testsuite/rust/execute/torture/loop-condition-eval.rs
new file mode 100644
index 00000000000..008965917ab
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/loop-condition-eval.rs
@@ -0,0 +1,21 @@ 
+// { dg-output "1\n" }
+pub fn test() -> u64 {
+    let mut n = 113383; // #20 in https://oeis.org/A006884
+    while n != 1 {
+        n = if n % 2 == 0 { n / 2 } else { 3 * n + 1 };
+    }
+    n
+}
+
+pub fn test_1() -> u64 {
+    test()
+}
+
+extern "C" {
+    fn printf(fmt: *const i8, ...);
+}
+
+fn main() -> i32 {
+    unsafe { printf("%lu\n" as *const str as *const i8, test_1()) }
+    0
+}