From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id DE9503850234; Mon, 12 Sep 2022 07:20:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE9503850234 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662967253; bh=a+pyDorSrJq+l3LtLBFKsa9LjaA3Ub3BydcVUwjcjuc=; h=From:To:Subject:Date:From; b=MidsoON4WXK0ohhxyt9RRoOhmCjWgsaG//dxJ7PLJn0AOyBSL7sW26zkVlidUyk/y ufKrijeTV0XojQopDN7RpvHTMPMZUEJ3KorE0gTZC8xjQj6IKHu/xXx4nu6v/WrwyH 9hjTLYiHHYxe5MSXaOOV3U/FhKYVl8S68Z7RvXRs= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] add testcase with struct to test component_ref and constructor codes in eval_constant_expression() X-Act-Checkin: gcc X-Git-Author: Faisal Abbas <90.abbasfaisal@gmail.com> X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: a876e9e8f0c48b476116b0f5808ab32dfb520f56 X-Git-Newrev: 908f1e2022cd1b957a33187d921455ff86749065 Message-Id: <20220912072053.DE9503850234@sourceware.org> Date: Mon, 12 Sep 2022 07:20:53 +0000 (GMT) List-Id: https://gcc.gnu.org/g:908f1e2022cd1b957a33187d921455ff86749065 commit 908f1e2022cd1b957a33187d921455ff86749065 Author: Faisal Abbas <90.abbasfaisal@gmail.com> Date: Tue Sep 6 22:24:52 2022 +0100 add testcase with struct to test component_ref and constructor codes in eval_constant_expression() Diff: --- gcc/testsuite/rust/compile/const8.rs | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/gcc/testsuite/rust/compile/const8.rs b/gcc/testsuite/rust/compile/const8.rs new file mode 100644 index 00000000000..94c4268ec8c --- /dev/null +++ b/gcc/testsuite/rust/compile/const8.rs @@ -0,0 +1,40 @@ +// { dg-options "-w -O0 -fdump-tree-gimple" } +struct Foo { + First: i32, + Second: f32 +} + +struct Bar { + First: i32, + Second: f32 +} + +struct Baz { + First: i32, + Second: f32 +} +const A:Foo = Foo { First: 1, Second: 1.0 }; +const B:Bar = Bar { First: 2, Second: 2.0 }; +const C:Baz = Baz { First: 3, Second: 2.0 }; + +const fn test() -> f32 { + if (A.First == 2) { + return A.Second; + } + else if (B.First == 2) { + return B.Second; + } + else if (C.First == 2) { + return C.Second; + } + + return 0.0; +} + +const D:f32 = test(); + +fn main() { + // { dg-final { scan-tree-dump-times {d = 2.0} 1 gimple } } + let d = D; +} +