From: liushuyu Date: Wed, 7 Sep 2022 04:41:17 +0000 (-0600) Subject: gccrs: testsuite: add loop condition execution test X-Git-Tag: basepoints/gcc-14~1649 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d5adf09356641070079eadef09717ece164b6b9;p=thirdparty%2Fgcc.git gccrs: testsuite: add loop condition execution test gcc/testsuite/ChangeLog: * rust/execute/torture/loop-condition-eval.rs: New test. Signed-off-by: Zixing Liu --- 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 000000000000..008965917ab0 --- /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 +}