From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by sourceware.org (Postfix) with ESMTPS id 55CA4385DC18 for ; Wed, 23 Feb 2022 15:50:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 55CA4385DC18 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-xf2e.google.com with SMTP id a1so9058993qvl.6 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=gnWuq0yfputz8g52rdo7dOFliSGBfQt6LoKVmyl6SBah8bqX/km+oulGfFF2nVQUV3 jVzYUkK+KWqTkaX+PfkTlClp5fSTQ36r0kVKRdlUhJlHINJ7REt+2dc+wgCMIEj35OEi jwfurDuBQ7k6xhWFxHnCMkFN+IFupeMMrm7i/hUfTeSdv7wXPX/AE9uvHfZFRwlSwJgO ukbU43TXSWCOH1Wasx5HtzsbsAN1afaQX/0+dCK0TC5fzP3zdWQg53RilgnE4I/bhft7 tMUc74fgLkTnYos06mtmY+xWq1N0wQjavHp0rbFBXj3JJJsUXykHIsox89Q2950e2QzI sOpw== X-Gm-Message-State: AOAM531wnAi+KMP6pvvTaGJ5Bd9vZaIWj4SOX0NQ5DACYUEkwWTvjEd6 gpgN+2x3dBTN/5K+h/hiRgOQ1dc7hBqG3l/xRaCaTkJQAjFHlw== 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.7 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=unavailable 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@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc 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