From patchwork Tue Oct 18 18:10:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 4275 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp2094503wrs; Tue, 18 Oct 2022 11:11:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5p5OOM6LlnJI392m2oNCzfEWU4QLcuM9zuM4XmLoZohHpLOw0i+T6hHdMbvPABeMSHBVKz X-Received: by 2002:a05:6402:35d1:b0:45d:3661:567e with SMTP id z17-20020a05640235d100b0045d3661567emr3820960edc.343.1666116708314; Tue, 18 Oct 2022 11:11:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666116708; cv=none; d=google.com; s=arc-20160816; b=u7yQVp9DRFB3bzB3smoP4ldNqRkQzIRCC+5oNJ584Rjso4C+wEsXfvjavEzoKdIAT4 GF4Bl3ZugWyvePnleYOgkfgTLFLYyoTG560j+fdbiWiFVTOIrnOzB+MYJig1JAyLtvB4 TQBf7+VUntO7xKl1/1xPjm4ZO4NOmNTBpFQ4BkUvIXH3UOOVxRUBT5sWweGvhPlSnAQ2 JuVQjMLL6JMw97JLJFpy/ESZ9JtwX53TfP+DupLkmWntCc2OsVPr6hJ9L/VTv9yu+99q 9XHW51fbNgvEH4cUxwj/ggeOqTkNSDd87ePvISN+UFfTKMY8Cq0Ov6puDtNVOY6AUDua PmgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=/n/dwZptbctRUO501WpoaidqQEUtsW4dMz6BFTaPPBw=; b=sWG0E7zwNVtEyaqx0W1Vz3GKnhtSWZdi5qFbfTzn0G+TjTo+GllX+xIwsHI+gS7IjG LUk56zKLP9nkp7rsyf8rZ6omsQ4NIdnyd7bL0IQI/xINIXrAOtdWfIS6p+pmS24CH971 KxviSnMZ6eNueVnoAmKq12VHUivAIVsxEor00Phv3xuFj8bdnEACke7B/0ETg1q7QPMX Vp19CKJYX2uxKo7NjtRxqU/VsU4gz+2/+rnyQw//GdtNRD3+U3bYI6syseGMKMbK/KKL 3WE7yBIjcqxGoGHSijCp79Iuy3XTNh2/14XPLu299beYJ3dAz7TbZ4v8SzMcyMIpO1kF dihw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=AkBvIv63; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dp20-20020a170906c15400b0078ded36fa42si12932272ejc.292.2022.10.18.11.11.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 11:11:48 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=AkBvIv63; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 160083858C2F for ; Tue, 18 Oct 2022 18:11:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 160083858C2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666116700; bh=/n/dwZptbctRUO501WpoaidqQEUtsW4dMz6BFTaPPBw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=AkBvIv63OzViZDFG1lC/3dLk4s+s5tfhQHHpkPQ0rW7FOpddC4XJ6EBngnSnNchln IkD0HeMfLSYoLIrv54Qb6fCqt/yztdGRf/1Yrbja5zK1jJg6nqN7HUVEG097k8Sxra c00FB3AMpWFFKY6fjD3GNHT7dJWHxFifiIUoJV54= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 9CE173858D39 for ; Tue, 18 Oct 2022 18:10:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9CE173858D39 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-443-MWzheaATPNeYUznRckW4Gg-1; Tue, 18 Oct 2022 14:10:55 -0400 X-MC-Unique: MWzheaATPNeYUznRckW4Gg-1 Received: by mail-qk1-f200.google.com with SMTP id u9-20020a05620a454900b006eeafac8ea4so12894834qkp.19 for ; Tue, 18 Oct 2022 11:10:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/n/dwZptbctRUO501WpoaidqQEUtsW4dMz6BFTaPPBw=; b=uKgYaVURaCleVJyJXm+a385hcV0Q6PwRX9O5gozW1Pm51JQSVPqdvRyVK8NP66PDhi coX8jqZdCeWtiK8Z5r8D0oct5sgIplP8ChFRNrwChQrMz5w5CkwXVg3fcUCnNJ8Kkn5a e8Dszpp+sOhB6mXyUFAvK145z3H0fnNmNDxLrmDXQVjDK26J5awH51DCdsyq+ZOh4zbF oTWRKt4x2hGLjds+xMfUhA0AZmhEMuFO/pv4aE/rmU+Bp2tE1qzCww37inSbOay0geFv eLV0HVOwCOC6g//kwJO41tycEDoakG13zCPCgDVX+9fF1u2f4PgGPvujJWCgrhp4rRrO TRpQ== X-Gm-Message-State: ACrzQf2y7oRgodxWBtiiJ+pYNBhT4vMvzefOgn24MTm0OtzzbU9iKXKV cQy4QY5RYv2kue+y/DEuLS3scHA89anFy0Ub+hyc91oN5hdFasVK0TituJ72uGNi6UEPumkrZPG n/w+z7jTQvxcz5/zw4wT2DWs6eKTZGqd249CsFqULONtv9AJKOoFjLR7JGokty7rJkc4= X-Received: by 2002:a05:620a:258a:b0:6cf:ca19:1ec2 with SMTP id x10-20020a05620a258a00b006cfca191ec2mr2818127qko.630.1666116654366; Tue, 18 Oct 2022 11:10:54 -0700 (PDT) X-Received: by 2002:a05:620a:258a:b0:6cf:ca19:1ec2 with SMTP id x10-20020a05620a258a00b006cfca191ec2mr2818104qko.630.1666116654068; Tue, 18 Oct 2022 11:10:54 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id g3-20020a05620a40c300b006ee8874f5fasm2989530qko.53.2022.10.18.11.10.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 11:10:53 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/2] c++ modules: streaming enum with no enumerators [PR102600] Date: Tue, 18 Oct 2022 14:10:49 -0400 Message-Id: <20221018181050.1629201-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.0.118.g4732897cf0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: nathan@acm.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747049993185676748?= X-GMAIL-MSGID: =?utf-8?q?1747049993185676748?= 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. 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{}); } From patchwork Tue Oct 18 18:10:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 4276 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp2094530wrs; Tue, 18 Oct 2022 11:11:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4EDVDMYlNy4TluHkkv9h4WmsFQ1FbNwEp+084A3RKLZCKeUuJVg/llxA5DUwSlOgvOsNHj X-Received: by 2002:a17:906:dc8f:b0:78d:f675:226 with SMTP id cs15-20020a170906dc8f00b0078df6750226mr3466660ejc.745.1666116711355; Tue, 18 Oct 2022 11:11:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666116711; cv=none; d=google.com; s=arc-20160816; b=WkeqBF0RL/OqzPnKrjtSA0qlGWG+KIDG34e85QcWtfx4XuRZC0TWaSb3/t737ixUNU T+vNUJW7k/ueKhsdM9OLm7QvNUZ6a5Skkn/yNpsOdhCMjR4gzbSt+x5/VW5Dmy+BFg/i Gxh441IQuSeNh0M1KJGSYwuR8nR/9Q1Rt9lES3iTUcUJC88j4lPh3Ap1DxegDoPTAHwq MgF/HvigOAkXvImlx3cIHYVMw5yBxoOJZ74cEFeQqWVLQj/MI5ezNu6Vze1F6NhRCe2h Aj9xWFUO+moFlcRW9kq4jOp3RameJt/IRXB0uKkVLcssAEx35Hb3SuVpheXZmV7WbgHl nPuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=MJzX7jbNQIV8iBAeWA4V0WilScIyOUJ7sQj6bfzJ7qU=; b=O5ED6zR+gCg4mvp6z7oExF2qjI0bpQV55NElHMXcZLpWwoQK3qNRoxtf4rAbubBd7F hc+vnbbHOxnb8t9ZWev44TRBX0iJsd7XNUMP1fw2OeoPqpwQQI4JfWKkEQZmvMDTw+B+ 1pRPmGHH/x6i4FJ6ldTKO2BMrdsjfAAF96pGrtg6jr7AhdxK690Yt2NXV3VhbyYwR/rg 7/wPAyO5eyotC+jOoO63aj4GjNHZm8RCtlSMRfmn0qoXyFn79WlMPHXgkhSE/RQhtuaa gDC8K3P6oqeANZ+R+SiFjwITjApbiEaoG7dqzoxzpfXgRtSIF0CAGp3c9LAq7LCpH0of anWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="bMI/YS9L"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id cn4-20020a0564020ca400b0045c4b1f4315si11110112edb.485.2022.10.18.11.11.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 11:11:51 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="bMI/YS9L"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 27D813857BAE for ; Tue, 18 Oct 2022 18:11:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27D813857BAE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666116702; bh=MJzX7jbNQIV8iBAeWA4V0WilScIyOUJ7sQj6bfzJ7qU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=bMI/YS9LAWk0gsqJY0Y939/lJM90V+Z+trjc6K5GiU/nuinkQHiFlKSIcKxtXlC2G FtbWlKOKZ7q3Gei0OReSnF3fCLthFSkjb8s1pRYrDrh4jyUeCg5TpiWlKatfAEBw5A CGZRRxTS9ryFBOryjSK+uJzwWklUkA6q7yM5xqw8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B964B3858D32 for ; Tue, 18 Oct 2022 18:10:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B964B3858D32 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-457-lH_S75neOsyDcjg8n9CoUw-1; Tue, 18 Oct 2022 14:10:57 -0400 X-MC-Unique: lH_S75neOsyDcjg8n9CoUw-1 Received: by mail-qv1-f70.google.com with SMTP id lz4-20020a0562145c4400b004b495b96748so8663774qvb.14 for ; Tue, 18 Oct 2022 11:10:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MJzX7jbNQIV8iBAeWA4V0WilScIyOUJ7sQj6bfzJ7qU=; b=RjgFjGqikVdvLQ9aplNlGC59FALrr0uFhN0k+l1PmyIuXFBbjhFs3oxPP7LLkdA9dq 5NXQMQS2JVXQ9QOVWfm7W9VlYGJCWErWm4m00PETqDgqqMkCLJrNMOJJTpwyBJxjdz7W 6WDQZ84IcLVySsuyHVcu2Nkn28EF6VvsFfEoUNezTfYs7EfRniG3/oYysYdfp6UwQwhD 9cvqeaZv76PDB6oa9hU5uFpjJak9OSn+auM1mVjuduTOfuKAAjY/xv4/5U5ufi9OrNuU h1KlCz98wZi/vCbecaHatWjY76pHZwD4cO/6woSOBllRD9lWgF48u+3dWRSZNQ7sQHFt 5Yaw== X-Gm-Message-State: ACrzQf0H1ovWQ8BcPXwP4m0X1hEFL2OjVrbxo2XRo1hA07/EGQjgrQWh TDsdqETIXo34nXHn1M+kxVxrxwEpZomvcsRzSBLYJ+hY3c/jP0vRgcd8wtS2l1QCol6wYzjVGbc eHtTdukQI0K5GkG8bluExhJ72sZEKCpuf8suUAzP7arddhFDSmugc+QH2u5y0nKySeJo= X-Received: by 2002:a05:6214:e85:b0:4b1:7e5a:3604 with SMTP id hf5-20020a0562140e8500b004b17e5a3604mr3178219qvb.114.1666116656185; Tue, 18 Oct 2022 11:10:56 -0700 (PDT) X-Received: by 2002:a05:6214:e85:b0:4b1:7e5a:3604 with SMTP id hf5-20020a0562140e8500b004b17e5a3604mr3178185qvb.114.1666116655763; Tue, 18 Oct 2022 11:10:55 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id g3-20020a05620a40c300b006ee8874f5fasm2989530qko.53.2022.10.18.11.10.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 11:10:55 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] c++ modules: always stream TYPE_MIN/MAX_VALUE for enums [PR106848] Date: Tue, 18 Oct 2022 14:10:50 -0400 Message-Id: <20221018181050.1629201-2-ppalka@redhat.com> X-Mailer: git-send-email 2.38.0.118.g4732897cf0 In-Reply-To: <20221018181050.1629201-1-ppalka@redhat.com> References: <20221018181050.1629201-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: nathan@acm.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747049996275795064?= X-GMAIL-MSGID: =?utf-8?q?1747049996275795064?= We currently stream TYPE_MIN/MAX_VALUE of an enum only if the enum is defined rather than just declared. But that seems inconsistent with what start_enum does, which always sets TYPE_MIN/MAX_VALUE on the ENUMERAL_TYPE (via copy_type_enum) even for an opaque enum that lacks a definition. This patch makes us stream TYPE_MIN/MAX_VALUE as part of the ENUMERAL_TYPE rather than as part of the defining TYPE_DECL so that TYPE_MIN/MAX_VALUE gets set even for opaque enums. Incidentally, this turns out to fix the below testcase in which 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_MIN/MAX_VALUE, which leads to an ICE from verify_type (with -g). (The stale variant got created from set_underlying_type during earlier stream in of the redundant typedef for the enum.) By streaming these fields as part of the ENUMERAL_TYPE, we guarantee they won't be stale. Tested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/106848 gcc/cp/ChangeLog: * module.cc (trees_out::core_vals): Stream TYPE_MAX_VALUE and TYPE_MIN_VALUE of ENUMERAL_TYPE. (trees_in::core_vals): Likewise. (trees_out::write_enum_def): Don't stream them here. (trees_in::read_enum_def): Likewise. gcc/testsuite/ChangeLog: * g++.dg/modules/enum-10_a.H: New test. * g++.dg/modules/enum-10_b.C: New test. --- gcc/cp/module.cc | 29 ++++++++++++------------ gcc/testsuite/g++.dg/modules/enum-10_a.H | 5 ++++ gcc/testsuite/g++.dg/modules/enum-10_b.C | 6 +++++ 3 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/enum-10_a.H create mode 100644 gcc/testsuite/g++.dg/modules/enum-10_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index cc704817718..bb406a5cf01 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -6016,9 +6016,14 @@ trees_out::core_vals (tree t) if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON)) { + if (code == ENUMERAL_TYPE) + { + WT (t->type_non_common.maxval); + WT (t->type_non_common.minval); + } /* Records and unions hold FIELDS, VFIELD & BINFO on these things. */ - if (!RECORD_OR_UNION_CODE_P (code) && code != ENUMERAL_TYPE) + else if (!RECORD_OR_UNION_CODE_P (code)) { // FIXME: These are from tpl_parm_value's 'type' writing. // Perhaps it should just be doing them directly? @@ -6529,9 +6534,14 @@ trees_in::core_vals (tree t) if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON)) { + if (code == ENUMERAL_TYPE) + { + RT (t->type_non_common.maxval); + RT (t->type_non_common.minval); + } /* Records and unions hold FIELDS, VFIELD & BINFO on these things. */ - if (!RECORD_OR_UNION_CODE_P (code) && code != ENUMERAL_TYPE) + else if (!RECORD_OR_UNION_CODE_P (code)) { /* This is not clobbering TYPE_CACHED_VALUES, because this is a type that doesn't have any. */ @@ -12217,8 +12227,6 @@ trees_out::write_enum_def (tree decl) tree type = TREE_TYPE (decl); tree_node (TYPE_VALUES (type)); - tree_node (TYPE_MIN_VALUE (type)); - tree_node (TYPE_MAX_VALUE (type)); } void @@ -12242,8 +12250,6 @@ trees_in::read_enum_def (tree defn, tree maybe_template) { tree type = TREE_TYPE (defn); tree values = tree_node (); - tree min = tree_node (); - tree max = tree_node (); if (get_overrun ()) return false; @@ -12254,8 +12260,6 @@ 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; rest_of_type_compilation (type, DECL_NAMESPACE_SCOPE_P (defn)); } @@ -12269,22 +12273,17 @@ trees_in::read_enum_def (tree defn, tree maybe_template) tree new_decl = TREE_VALUE (values); if (DECL_NAME (known_decl) != DECL_NAME (new_decl)) - goto bad; + break; new_decl = maybe_duplicate (new_decl); if (!cp_tree_equal (DECL_INITIAL (known_decl), DECL_INITIAL (new_decl))) - goto bad; + break; } if (known || values) - goto bad; - - if (!cp_tree_equal (TYPE_MIN_VALUE (type), min) - || !cp_tree_equal (TYPE_MAX_VALUE (type), max)) { - bad:; error_at (DECL_SOURCE_LOCATION (maybe_dup), "definition of %qD does not match", maybe_dup); inform (DECL_SOURCE_LOCATION (defn), diff --git a/gcc/testsuite/g++.dg/modules/enum-10_a.H b/gcc/testsuite/g++.dg/modules/enum-10_a.H new file mode 100644 index 00000000000..fb7d10ad3b6 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/enum-10_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-10_b.C b/gcc/testsuite/g++.dg/modules/enum-10_b.C new file mode 100644 index 00000000000..76dc3152963 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/enum-10_b.C @@ -0,0 +1,6 @@ +// PR c++/106848 +// { dg-additional-options "-fmodules-ts -g" } + +import "enum-10_a.H"; + +memory_order x = memory_order_seq_cst;