From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id DC7DA3858C83 for ; Wed, 19 Oct 2022 13:55:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DC7DA3858C83 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666187722; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ToLBQpxhvK/kfCTZVQpenFvAK0OhgZPb5cWyIizRDyM=; b=hjVNVF58MI/OHZTazBqQR/VNvRsWh/YxnkmIr16fhpGekd4SM9y66x6GekpubO3NwC9dq0 zZ1RDKQgm5Ps9tCaCw0lF32ZJHd/IVMaZ+gt1fHp1QfMyWZrUoKKaixbGcBVxOV7N6I1Nj gc6sgDLctnYI2lGLFr7Os80eSr9/c38= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-96-8f_RTMhMNdSMUn0kOl_OzQ-1; Wed, 19 Oct 2022 09:55:21 -0400 X-MC-Unique: 8f_RTMhMNdSMUn0kOl_OzQ-1 Received: by mail-qk1-f199.google.com with SMTP id de21-20020a05620a371500b006eed31abb72so2875413qkb.6 for ; Wed, 19 Oct 2022 06:55:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ToLBQpxhvK/kfCTZVQpenFvAK0OhgZPb5cWyIizRDyM=; b=k8TghFUjN+FR7tFNWX0UpB7BRVAn85Msw+yil7rUsuvw5Kca9qv+EYs0ph3JUPgWZD l+gePFg+rPVHu0fNmqSTLvpQmerhAZCD7divPtm3GpkdOrFK2LMuaE+TTHJFJd57eM5i mZCY1fDVQh1bGK4ijXOyl2bP53ErlbKiKPkiibkBQKx5p214nlLOe4HvhBa+Kd3xe4FN z20qt6HN/0rWHYw9QXu7I5rW/Oaj7jEbJFqtfCuWLGIdfREvVHHmYmo9K9zom0n4jO04 bB4M//EEo91X0h9BheH+99uJzDNeCdhu53B7gZLR2OJZZezmzO2mZ2Yj+8Ti1pvgd+lU nINg== X-Gm-Message-State: ACrzQf2pXQI1VB/Xj/gr3EzWXUoUO137WjLOjk7HXg6i9f788aepovl6 Ca75Pq0o/chcFo//fFM4t5JpAK1GwGVNVqzT6UbNsjkOtD+yeqh3+7Bk9nTy2Y/4eOFGGXwGXOP /AM20WQoPrEAMI8z/YQ== X-Received: by 2002:a05:6214:caf:b0:4b1:7904:5425 with SMTP id s15-20020a0562140caf00b004b179045425mr6779092qvs.32.1666187718990; Wed, 19 Oct 2022 06:55:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Cn/tiHGJbDa93+UHX1JAWKg4XCtPM+4vTgQJZJ8iZBTM9W6e36uk28t6EMiXGIwQF5fa1nw== X-Received: by 2002:a05:6214:caf:b0:4b1:7904:5425 with SMTP id s15-20020a0562140caf00b004b179045425mr6779078qvs.32.1666187718730; Wed, 19 Oct 2022 06:55:18 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id t12-20020ac8530c000000b0039a55f78792sm3988849qtn.89.2022.10.19.06.55.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 06:55:18 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Wed, 19 Oct 2022 09:55:17 -0400 (EDT) To: Richard Biener cc: Patrick Palka , gcc-patches@gcc.gnu.org, nathan@acm.org Subject: Re: [PATCH] c++ modules: verify_type failure with typedef enum [PR106848] In-Reply-To: Message-ID: <5601279b-939f-4492-c14b-c495d7a2a3b2@idea> References: <20221013153921.3795800-1-ppalka@redhat.com> <5cf07598-68ce-efda-05c3-625a1466195f@idea> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 Wed, 19 Oct 2022, Richard Biener wrote: > On Tue, Oct 18, 2022 at 8:26 PM Patrick Palka wrote: > > > > On Fri, 14 Oct 2022, Richard Biener wrote: > > > > > 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. > > > > *nod* reading in the enum before reading in the typedef seems like > > the most direct solution, though not sure how to accomplish that :/ > > For LTO streaming we DFS walk tree edges from all entries into the tree > graph we want to stream, collecting and streaming SCCs. Not sure if > doing similar for module streaming would help this case though. FWIW I managed to obtain a more interesting reduction for this ICE, one that doesn't use a typedef bound to the same name as the enum: $ cat 106848_a.H template struct pair { using type = void(*)(const _T1&); }; struct _ScannerBase { enum _TokenT { _S_token_anychar }; pair<_TokenT> _M_token_tbl; }; $ cat 106848_b.C import "106848_a.H"; using type = _ScannerBase; $ g++ -fmodules-ts -g 106848_a.H 106848_b.C 106848_b.C:3:14: error: type variant differs by TYPE_MAX_VALUE Like in the less interesting testcase, the problem is ultimately that we create a variant of the enum (as part of reading in pair<_TokenT>::type) before reading the enum's definition, thus the variant inherits stale TYPE_MIN/MAX_VALUE. Perhaps pair<_TokenT>::type should indirectly depend on the definition of _TokenT -- but IIUC we generally don't require a type to be defined in order to refer to it, so enforcing such a dependency would be a pessimization I think. So ISTM this isn't a dependency issue (pair<_TokenT>::type already implicitly depends on the ENUMERAL_TYPE, just not also the enum's defining TYPE_DECL), and the true issue is that we're streaming TYPE_MIN/MAX_VALUE only as part of an enum's definition, which the linked patch fixes. > > > A somewhat orthogonal issue (that incidentally fixes this testcase) is > > that we stream TYPE_MIN/MAX_VALUE only for enums with a definition, but > > the frontend sets these fields even for opaque enums. If we make sure > > to stream these fields for all ENUMERAL_TYPEs, then we won't have to > > worry about these fields being stale for variants that may have been > > created before reading in the enum definition (their TYPE_VALUES field > > will still be stale I guess, but verify_type doesn't worry about that > > it seems, so we avoid the ICE). > > > > patch to that effect is at > > https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603831.html > > > > > > > > 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 > > > > > > > > > > > > > >