From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 62AF93AA88A0; Wed, 8 Jun 2022 11:56:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 62AF93AA88A0 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] Merge #834 X-Act-Checkin: gcc X-Git-Author: bors[bot] <26634292+bors[bot]@users.noreply.github.com> X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 3629645386ad503606f29f95c2e16d0600df6e20 X-Git-Newrev: 768f926074a27a7b1a2179613eeeb8291648b8a7 Message-Id: <20220608115639.62AF93AA88A0@sourceware.org> Date: Wed, 8 Jun 2022 11:56:39 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jun 2022 11:56:39 -0000 https://gcc.gnu.org/g:768f926074a27a7b1a2179613eeeb8291648b8a7 commit 768f926074a27a7b1a2179613eeeb8291648b8a7 Merge: 3629645386a e0588300adc Author: bors[bot] <26634292+bors[bot]@users.noreply.github.com> Date: Thu Dec 16 10:23:26 2021 +0000 Merge #834 834: Add enum code generation r=philberty a=philberty This adds a naieve first pass approach to enum type code generation. The original idea was to use GCC's QUAL_UNION_TYPE but I have ran into issues with the DECL_QUALIFIER as my understanding of how this works is incorrect. This takes an enum such as: ```rust enum AnEnum { A, B, C (char), D (x: i64, y: i64), } ``` And turns this into one big union consisting of all fields as RECORD_TYPES. ```c union AnEnum { record A { RUST$ENUM$DISR }; record B { RUST$ENUM$DISR }; record C { RUST$ENUM$DISR, char }; record D { RUST$ENUM$DISR, i64, i64}; } ``` see: https://github.com/bminor/binutils-gdb/blob/527b8861cd472385fa9160a91dd6d65a25c41987/gdb/dwarf2/read.c#L9010-L9241 With the RUST$ENUM$DISR being the first field in all of the records this means the alignment allows for indirect memory access of the struct to use it as a qualifier field to figure out which variant is currently in use. The data-less varients use their generated discriminat value during type-checking the data variants use their HIR ID for their discriminant. This will likely get redone to get improved GDB integration/updated to use the QUAL_UNION_TYPE when we learn how to do this properly. Fixes #79 Co-authored-by: Philip Herron Diff: gcc/rust/backend/rust-compile-expr.cc | 187 +++++++++++++++----------- gcc/rust/backend/rust-compile-expr.h | 86 ++++++++++-- gcc/rust/backend/rust-compile-resolve-path.cc | 49 ++++++- gcc/rust/backend/rust-compile-type.cc | 166 ++++++++++++++++++++--- gcc/rust/backend/rust-compile-type.h | 2 + gcc/rust/backend/rust-compile.cc | 4 +- gcc/rust/rust-backend.h | 4 +- gcc/rust/rust-gcc.cc | 111 +++++++++------ gcc/rust/typecheck/rust-tyty.h | 8 +- gcc/testsuite/rust/compile/torture/enum1.rs | 13 ++ 10 files changed, 475 insertions(+), 155 deletions(-)