From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 617793858C56 for ; Fri, 14 Oct 2022 06:05:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 617793858C56 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x62c.google.com with SMTP id 13so8326971ejn.3 for ; Thu, 13 Oct 2022 23:05:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=OpqMUFUpV73O64P+EAs0pi0XIQeu1YAzge3VCW1yPr4=; b=ExUWsujLYsPNVdjUP6jp7Cu/5w01Xr4tZm+ZinbJgw+Eg7nMcoz5v7ZTSwyb7o9uQh BeqMClHJrlGBs1wj+cggI/V+1E3GflDSF7QaGw0Qy2zbkHBgJ91A3f8nIQcwe6QlpZwu IEZewjDlAjWYNYltVKT3SlTGcWYIYsn75Igenq/6kO0FXRntyq4zr07D/ZfpJD16LD6Y 4d30NWIVGblcrL6fcVa0dxxr4XoG9LNlXCSZKM0f1jsHM965zbA0w8kfelOO4gJMoTPA OuBYebUxHYOWOEWHlugLFptDj7HLMG3LnHdBK+jKbGzR2TcVwT6DObkGP9anwTEcxpoS T7EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OpqMUFUpV73O64P+EAs0pi0XIQeu1YAzge3VCW1yPr4=; b=6J/g2TlzKTHG7TX/4EJzrlmbNHOMenPmobxED7o5rKh1eDAiokV7yJcOSto6YZw0hn Dv8y1u805sgIslQQDNZc3iVgamDjHo+1Ux+1zZ14Y6uYhDJibwt5cfbIUyotP1CRk3rR BfaTJi+4dGSDt8pIU/31HowQ4CCyzdgafqR0KAQnFApi4njaFUg51qDsqzJ+FVFlK+Jd OC5TRdIvBKxTRhkg0KbCVjYlzmVOJi9Gs4uiyZvwxvM2ib5cSi0NmJKXkL8dbZcjmE4A AzQCHGFBpSz/fKFtUtMSJVKvaiUuwb0zcA8F8ipCyE0aWWJIx3PNfEw2Xh4yzfpVSv/O dTyg== X-Gm-Message-State: ACrzQf3qKkg2mGOH9D9ewjmbGGTv/6uZ+X7Uzb5ntwyEiPGyjLz/rA8x CfDDVtGxV46HWupLMQ8MKVFs1aoCglQD14ETf7pKVi4of8I= X-Google-Smtp-Source: AMsMyM6mJJZTdB6mVEdQsz1lWerciZR3qCcZPOmmT8cQjZ/DLe7CGLi2+JedgggtI0ovm9DHBqjKmgCTsAWf7eRCnME= X-Received: by 2002:a17:907:7208:b0:78e:176e:e0c6 with SMTP id dr8-20020a170907720800b0078e176ee0c6mr2376948ejc.594.1665727503303; Thu, 13 Oct 2022 23:05:03 -0700 (PDT) MIME-Version: 1.0 References: <20221013153921.3795800-1-ppalka@redhat.com> In-Reply-To: <20221013153921.3795800-1-ppalka@redhat.com> From: Richard Biener Date: Fri, 14 Oct 2022 08:04:51 +0200 Message-ID: Subject: Re: [PATCH] c++ modules: verify_type failure with typedef enum [PR106848] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org, nathan@acm.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, Oct 13, 2022 at 5:40 PM Patrick Palka via Gcc-patches wrote: > > Here during stream in we end up having created a type variant for the enum > before we read the enum's definition, and thus the variant inherited stale > TYPE_VALUES and TYPE_MIN/MAX_VALUES, which leads to an ICE (with -g). The > stale variant got created from set_underlying_type during earlier stream in > of the (redundant) typedef for the enum. > > This patch works around this by setting TYPE_VALUES and TYPE_MIN/MAX_VALUES > for all variants when reading in an enum definition. Does this look like > the right approach? Or perhaps we need to arrange that we read the enum > definition before reading in the typedef decl? Note that seems to be an > issue only when the typedef name and enum names are the same (thus the > typedef is redundant), otherwise we seem to read the enum definition first > as desired. > > PR c++/106848 > > gcc/cp/ChangeLog: > > * module.cc (trees_in::read_enum_def): Set the TYPE_VALUES, > TYPE_MIN_VALUE and TYPE_MAX_VALUE of all type variants. > > gcc/testsuite/ChangeLog: > > * g++.dg/modules/enum-9_a.H: New test. > * g++.dg/modules/enum-9_b.C: New test. > --- > gcc/cp/module.cc | 9 ++++++--- > gcc/testsuite/g++.dg/modules/enum-9_a.H | 5 +++++ > gcc/testsuite/g++.dg/modules/enum-9_b.C | 6 ++++++ > 3 files changed, 17 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/modules/enum-9_a.H > create mode 100644 gcc/testsuite/g++.dg/modules/enum-9_b.C > > diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc > index 7ffeefa7c1f..97fb80bcd44 100644 > --- a/gcc/cp/module.cc > +++ b/gcc/cp/module.cc > @@ -12303,9 +12303,12 @@ trees_in::read_enum_def (tree defn, tree maybe_template) > > if (installing) > { > - TYPE_VALUES (type) = values; > - TYPE_MIN_VALUE (type) = min; > - TYPE_MAX_VALUE (type) = max; > + for (tree t = type; t; t = TYPE_NEXT_VARIANT (t)) > + { > + TYPE_VALUES (t) = values; > + TYPE_MIN_VALUE (t) = min; > + TYPE_MAX_VALUE (t) = max; > + } it's definitely somewhat ugly but at least type_hash_canon doesn't hash these for ENUMERAL_TYPE (but it does compare them! which in principle means it could as well hash them ...) I think that if you read both from the same module that you should arrange to read what you refer to first? But maybe that's not the actual issue here. Richard. > > rest_of_type_compilation (type, DECL_NAMESPACE_SCOPE_P (defn)); > } > diff --git a/gcc/testsuite/g++.dg/modules/enum-9_a.H b/gcc/testsuite/g++.dg/modules/enum-9_a.H > new file mode 100644 > index 00000000000..fb7d10ad3b6 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/enum-9_a.H > @@ -0,0 +1,5 @@ > +// PR c++/106848 > +// { dg-additional-options -fmodule-header } > +// { dg-module-cmi {} } > + > +typedef enum memory_order { memory_order_seq_cst } memory_order; > diff --git a/gcc/testsuite/g++.dg/modules/enum-9_b.C b/gcc/testsuite/g++.dg/modules/enum-9_b.C > new file mode 100644 > index 00000000000..63e81675d0a > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/enum-9_b.C > @@ -0,0 +1,6 @@ > +// PR c++/106848 > +// { dg-additional-options "-fmodules-ts -g" } > + > +import "enum-9_a.H"; > + > +memory_order x = memory_order_seq_cst; > -- > 2.38.0.68.ge85701b4af >