From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by sourceware.org (Postfix) with ESMTPS id 41FD7385C403 for ; Wed, 23 Feb 2022 15:50:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 41FD7385C403 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-qv1-xf2d.google.com with SMTP id x3so9096951qvd.8 for ; Wed, 23 Feb 2022 07:50:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=mime-version:from:date:message-id:subject:to; bh=k1EgdH2HsxzCqJuoByQlkeq9hCA/HyMcWQqU/Ezf8xM=; b=CyyrxSLDsh9oc6J3AjPD3ic5VgrQjgNTqfhi5Q2wm1e1vUxRNB8XyKh2b8jMj8xRVt zPTpnWaw6xj4NrNmJZYx9KntK4Dbb4svYSWfM42BGbJXoqBoF8A3++TVR7U00gUw/l38 N4F1iNnGhMUFfekIkOo0hV1+5pWE8VA7M9gAu3nBg1QVfGbJZ8Di8qRH6kuAamKmhdpG wcLDGwxphQ+sNuT1ML09gr6oxCOfUj9Tuq45k6KDg61My9AGs4suSBJZSZ0Izms1T6zR /ajWjSrSmncWo5n34tfkjZQAAdgvviBiZMxayuCsSLJNgw8HEIkzRi+s0OKhKbZ8thH5 +nJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=k1EgdH2HsxzCqJuoByQlkeq9hCA/HyMcWQqU/Ezf8xM=; b=p5kjzFi7OjLKd76siogV36G0p0SDtwzRpXIUAsqnpU4HyMuFzLg+MwgSeaBxZhs3oz 51130ae9HU9rtll0mrsqU3vyJWj+rU21hyFHMX0UryrZzEUMJzT7G5ynrPIimY1CVaeo +Y4q53hLWO1vAcKkw1dJ6UmJ2GdDPpdePTGOAsU7VtWP5WR4E6UOTADJkTqUktsKKsGB l6SwwT/hR0PssxsFPgfuef8BiVu1offQJbLsWvcHK7hgTetiBSQgT//E7p/8WheeoYuA 0cfzVLYP0QKMJu30ZjVDIYn5NbHxpoo6siF8fc6ZPxOha6xB/HztafmvDPSeJUlA4ClL NCNg== X-Gm-Message-State: AOAM531FN1FqD/bpcOpj/hGX4Ie9DnuxFC5IfhVP51wPFICQ1eVxItwL T2Fy5KAMaDDqD7mz8BXHVG4HgmyEnKHIdU//fR1GDuHQDoZCdw== X-Google-Smtp-Source: ABdhPJwIc6AIE48hGtts5BPThNB5d4d7KpyKqHPbBPB6+nv0UADxIXUwmnWBJIY5LhK9mFxemr6XRDWT0m4IuYBKPHQ= X-Received: by 2002:ad4:5ba8:0:b0:42c:1046:419e with SMTP id 8-20020ad45ba8000000b0042c1046419emr23225559qvq.119.1645631439798; Wed, 23 Feb 2022 07:50:39 -0800 (PST) MIME-Version: 1.0 From: Philip Herron Date: Wed, 23 Feb 2022 15:50:28 +0000 Message-ID: Subject: qual_union_type help To: gcc Mailing List , gcc-rust@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-rust@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: gcc-rust mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Feb 2022 15:50:41 -0000 Hi everyone I am seeking some help on using the QUAL_UNION_TYPE it seems ideally placed to be used for enums in Rust. My initial implementation was achieved by simply using a union such as: union my_enum { variant_a { enum discriminant; ...data } ; variant_b { enum discriminant; ...data} ; } Having each variant contain an enum for the discriminant meant that dataless handling variants were quite simple. Upon trying to use the QUAL_UNION_TYPE this all seems reasonably trivial but I can't figure out what to set the DECL_QUALIFIER to be, initially from reading the documentation on https://gcc.gnu.org/onlinedocs/gccint/Types.html it seemed that it wants a slightly different layout by using a placeholder_expr to reference an outer discriminant field such that the layout becomes: struct my_enum { enum discriminant; union variants { variant_a { data }; variant_b { data }; } } So I have been creating my DECL_QUALIFIER as follows: ``` tree field_offset = NULL_TREE; tree place_holder = build0 (PLACEHOLDER_EXPR, sizetype); tree place_holder_expr = build3 (COMPONENT_REF, TREE_TYPE (qual_field), place_holder, qual_field, field_offset); DECL_QUALIFIER (field) = build2 (EQ_EXPR, boolean_type_node, place_holder_expr, discrim); ``` So this seems to generate some interesting code and then finally hit an ICE inside: Breakpoint 5, gimplify_expr (expr_p=0x7ffff6ff1f48, pre_p=0x7fffffffd2d8, post_p=0x7fffffffbb58, gimple_test_f=0x15aa98f , fallback=3) at ../../gccrs/gcc/gimplify.cc:15755 15755 gcc_unreachable (); (gdb) call debug_tree(*expr_p) unit-size align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7ffff700a000 precision:64 min max > > This makes sense this we can't gimplify a placeholder expression. So this seems that when i make a constructor for the QUAL_UNION_TYPE i must iterate the fields and replace the placeholder_expr to have a reference to the discriminant via another COMPONENT_REF. Though does this mean for the constructor i will need to create a temporary to hold onto it to create another component_ref? Or am I doing this completely wrong? I haven't had much success in following the QUAL_UNION_TYPE code in the Ada front-end, but any pointers would be greatly appreciated. Thanks. --Phil