public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] testsuite: add loop condition execution test
@ 2022-09-12  7:20 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-09-12  7:20 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6839ad40eebf982f149452cc294ab387350abcef

commit 6839ad40eebf982f149452cc294ab387350abcef
Author: liushuyu <liushuyu011@gmail.com>
Date:   Tue Sep 6 22:41:17 2022 -0600

    testsuite: add loop condition execution test

Diff:
---
 .../rust/execute/torture/loop-condition-eval.rs     | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

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
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-12  7:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-12  7:20 [gcc/devel/rust/master] testsuite: add loop condition execution test Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).