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 A20633858424 for ; Tue, 18 Oct 2022 18:54:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A20633858424 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=1666119279; 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=YUAdu61B4YxhRBuC54e8v7q1IpHYQdcblb71piSS3q0=; b=TCsYJh8N/8r56UfdjjewYcWqtiUToUlWqYO6nN/NdLWAQiuHxHErX5h8lmh88byOGongBW W6R5iNVqGZ01WhPz3UpRQ7NEbOECqDG1jZRb/W9zc/mYcRVygBtS2If3qKW1PqShpnGrSC LQVv9ZE1wqTtmKE/XGSQwEXHRXRqzrE= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-402-bjEys6dyPrCyM8fmfh4g7g-1; Tue, 18 Oct 2022 14:54:38 -0400 X-MC-Unique: bjEys6dyPrCyM8fmfh4g7g-1 Received: by mail-qt1-f200.google.com with SMTP id 22-20020ac85756000000b0039cf0d41e2cso3311230qtx.13 for ; Tue, 18 Oct 2022 11:54:38 -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=YUAdu61B4YxhRBuC54e8v7q1IpHYQdcblb71piSS3q0=; b=l4JdJv396lwYRmY/Zw28JSptQxgtuVKc0USzhRsFVLczxFb7XsS7mM4LfYdic/52hm eyMfjrW0WL22njmugVDV1xwtS00cokg+/gmC6norD+bmDXLatLdxRkAu+UkLTOtgPF7N jSiq65AzIcro6z+8CSHImBEXCMzR5NY0rVjS7DEtf+nDvXp4J+MSGAVrkrYBwd/lHFFI 8HDSq32znw/tAA8/KUIuyyvIhENADHRG5XKiIidnSDcb7xnOUdjsmctiRwfWBYW6yRT6 VRPm/uh+Jeq8eApOCP3XTQ2mPZhlyPnsduLRU6Db8pvrI4yOMXHb7V5HO7KFvJ/BA/Uj OWGA== X-Gm-Message-State: ACrzQf1HtjARQtRlRKLzjG4KANSLgUf8noNJHRFKrHMw8+vO6YYMFCwG xxUBXd+z5Y5No9Q8SHGo+kagHudmcnra/vrdFVQwlIF05Tq0jOGhEoHImyJSuGysMNFFhu1rcJG 9M3l8b227FO6q1w87eQ== X-Received: by 2002:a05:622a:48b:b0:39c:c920:d8fd with SMTP id p11-20020a05622a048b00b0039cc920d8fdmr3358127qtx.330.1666119277563; Tue, 18 Oct 2022 11:54:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM51U5H5nRXs5+R7zDhBzF3BmydSfJue/1eQY/+vRVJ2rcTgwJzV8kcJKWOO0zT+gHkZQo9OGw== X-Received: by 2002:a05:622a:48b:b0:39c:c920:d8fd with SMTP id p11-20020a05622a048b00b0039cc920d8fdmr3358107qtx.330.1666119277296; Tue, 18 Oct 2022 11:54:37 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id m21-20020a05620a24d500b006bb82221013sm3067866qkn.0.2022.10.18.11.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 11:54:36 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Tue, 18 Oct 2022 14:54:35 -0400 (EDT) To: Patrick Palka cc: gcc-patches@gcc.gnu.org, jason@redhat.com, nathan@acm.org Subject: Re: [PATCH 1/2] c++ modules: streaming enum with no enumerators [PR102600] In-Reply-To: <20221018181050.1629201-1-ppalka@redhat.com> Message-ID: <33f0f895-4a0d-fb63-6caa-5d33b286ab3a@idea> References: <20221018181050.1629201-1-ppalka@redhat.com> 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 Tue, 18 Oct 2022, Patrick Palka wrote: > For an enum declaration, has_definition returns true iff its TYPE_VALUES > field is non-empty. But this will wrongly return false for an enum that's > defined to have no enumerators as in the below testcase. > > This patch fixes has_definition for such enums by checking OPAQUE_ENUM_P > instead, which should always give us the right answer here. Whoops, it looks like the other patch[1] alone fixes both this testcase and its own testcase, and thus this change to has_definition isn't necessary if the other patch goes in. The problem in the below testcase is that the enum defines no enumerators, so has_definition returns false, and therefore we never stream the ENUMERAL_TYPE's TYPE_MIN/MAX_VALUE, which leads to a crash in the middle end due to these fields being empty. The other patch arranges that we always stream TYPE_MIN/MAX_VALUE for ENUMERAL_TYPE regardless of whether we think the enum is defined, so this has_definition false negative doesn't matter anymore. So feel free to ignore this patch if you think the second one looks good :) [1]: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603831.html > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk? > > PR c++/102600 > > gcc/cp/ChangeLog: > > * module.cc (has_definition): For an enum declaration, check > OPAQUE_ENUM_P instead of TYPE_VALUES. > > 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 | 3 ++- > gcc/testsuite/g++.dg/modules/enum-9_a.H | 5 +++++ > gcc/testsuite/g++.dg/modules/enum-9_b.C | 8 ++++++++ > 3 files changed, 15 insertions(+), 1 deletion(-) > 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 2c2f9a9a8cb..cc704817718 100644 > --- a/gcc/cp/module.cc > +++ b/gcc/cp/module.cc > @@ -11443,7 +11443,8 @@ has_definition (tree decl) > if (type == TYPE_MAIN_VARIANT (type) > && decl == TYPE_NAME (type) > && (TREE_CODE (type) == ENUMERAL_TYPE > - ? TYPE_VALUES (type) : TYPE_FIELDS (type))) > + ? !OPAQUE_ENUM_P (type) > + : TYPE_FIELDS (type) != NULL_TREE)) > return true; > } > break; > 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..1aecabfd0bd > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/enum-9_a.H > @@ -0,0 +1,5 @@ > +// PR c++/102600 > +// { dg-additional-options -fmodule-header } > +// { dg-module-cmi {} } > + > +enum class byte : unsigned char { }; > 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..aa1fdf21444 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/enum-9_b.C > @@ -0,0 +1,8 @@ > +// PR c++/102600 > +// { dg-additional-options -fmodules-ts } > + > +import "enum-9_a.H"; > + > +void push(byte) {} > +void write(char v) { push(static_cast(v)); } > +int main() { write(char{}); } > -- > 2.38.0.118.g4732897cf0 > >