From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id E7CDB3858031; Tue, 31 Jan 2023 13:16:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E7CDB3858031 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675170973; bh=BecZfN7N/RqScms4uGbvpvnAkBt+rf1PqC4iQzViNfE=; h=From:To:Subject:Date:From; b=CNCD25lbwD/f6XuUavQTxS9D7dKnsTlpxFRVpsBLaMl3lwmEXeuBi739r9y9qQ+dS EB/Vh6r3OKgJAckiMY0pM60bz91QgnBrKv/p2DaBJfNWfcDDmuuYSov8SJZ1I54Rpm McCoKXLl/VsELjB017Ze83+Nf55YkTPxD1tL+BVw= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5557] gccrs: add testcase with struct to test component_ref and constructor codes.. X-Act-Checkin: gcc X-Git-Author: Faisal Abbas <90.abbasfaisal@gmail.com> X-Git-Refname: refs/heads/master X-Git-Oldrev: e6a3886a833a0c499ab20a828ffae79076d47a4d X-Git-Newrev: dd9d6656e9a47c0620afc911eb98693fdc2eea94 Message-Id: <20230131131613.E7CDB3858031@sourceware.org> Date: Tue, 31 Jan 2023 13:16:13 +0000 (GMT) List-Id: https://gcc.gnu.org/g:dd9d6656e9a47c0620afc911eb98693fdc2eea94 commit r13-5557-gdd9d6656e9a47c0620afc911eb98693fdc2eea94 Author: Faisal Abbas <90.abbasfaisal@gmail.com> Date: Tue Sep 6 22:24:52 2022 +0100 gccrs: add testcase with struct to test component_ref and constructor codes.. ..in eval_constant_expression() gcc/testsuite/ChangeLog: * rust/compile/const8.rs: New test. Signed-off-by: Faisal Abbas <90.abbasfaisal@gmail.com> 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; +} +