From patchwork Thu Oct 13 15:39:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 2077 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp344599wrs; Thu, 13 Oct 2022 08:40:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7TYwYUBbdTYNtGE5O4FjJk9D9eY6PYHPUXrf6hTNhFvoHu1W0QBOs5UvnUyvRkS25452GU X-Received: by 2002:a17:906:478d:b0:78d:ec4d:e2e0 with SMTP id cw13-20020a170906478d00b0078dec4de2e0mr298402ejc.34.1665675611132; Thu, 13 Oct 2022 08:40:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665675611; cv=none; d=google.com; s=arc-20160816; b=0MUehcr5nmBkh5AHbHPnoWasv59sOkXjyNP8qC5/diCOCLAnwnXPF25mek7x4VkWKW edMJVxx+3cHnbSl0Mui9PK5cJBTtGyOhawvlws+eLd0SV5edBZNNPhpqdb0P4hazx5Yc dV7vtdcHiCaUv1Lk41VOPE46cfxAK5T+oEtUVhG9D1NL732BjgjUe149cCDzD5syIJAt d7ezXxJ5FlOOIAmsLk9WPqyFoZvr4Ee+tNBfwseNQw5t4kesIYKYsWLIosBg97KmOoVN xwslzdgCaAyDjGW71QUH5iUQYfEbpHei74sWG+nGZVTtuHvmgs1KV0OpgiM1OzWzyAzt oLwA== 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=0ITCmT0lQh9FQsFLEFjv2dTHLJ8oLk66epnpEnVYp9I=; b=QSzs7Brxz9PdZC4JgCwgJgNmSia4RvD3rxfo9iPH3yy2KPlqhlswG1eAepoBF24Nes 0/Kz5a2FNSf9KROet/4u5Kib1RqHNK+jPMy0DhwkKEj4S3ShtKtS8wB731k7ppZisdgc TNOe1IKtoHt1+9AKAmHFIwRjPqPxJcJzzofHTHlH0AwkX5nCXjbHMNv7N6rb5bVMb0QE 5cJF20F4GKqZV14NxPw93nwGyuC3tGcSN5yHLH6n1U8kyv9Q1PX7kfVkh9hLLFAgdpoA XY1cSYhEwS7NxMqTlJP0pEUIWKoauDqoooS4TxfZV9wKyxB80SM9wjWA1nFGUyx6GCzs w7nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KZkW35pe; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id gn41-20020a1709070d2900b0077cfdda438csi98834ejc.35.2022.10.13.08.40.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 08:40:11 -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=KZkW35pe; 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 25C8E3858404 for ; Thu, 13 Oct 2022 15:40:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 25C8E3858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665675610; bh=0ITCmT0lQh9FQsFLEFjv2dTHLJ8oLk66epnpEnVYp9I=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=KZkW35pe30Mk1huji8+0BuMpvf1lPVfCY5zq7dhULSL6HUJCx3jUG8Zw3/Xe/mk/B alGNJuVeRH1WdsquTe+GsF5kYFiqiHgl3bg465WrW0BF4HDlv3F+duSwaAO6Q5qb9j C2OsOoDiqnXWAEjC4HX3XB3ouaFHKOfCofDcXhLk= 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 758D83858C55 for ; Thu, 13 Oct 2022 15:39:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 758D83858C55 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-427-BGzF8KzdMOe-vj48wT7u4Q-1; Thu, 13 Oct 2022 11:39:24 -0400 X-MC-Unique: BGzF8KzdMOe-vj48wT7u4Q-1 Received: by mail-qt1-f197.google.com with SMTP id ff6-20020a05622a4d8600b0039cbf66e8b5so1574081qtb.19 for ; Thu, 13 Oct 2022 08:39:24 -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=0ITCmT0lQh9FQsFLEFjv2dTHLJ8oLk66epnpEnVYp9I=; b=K+VcElqSMHx58aTDbnF6g1D+QJC+3RDIRh4muaQfzYQMQ1Zjxt9R0pqICiTFmTj9FN pjZNPEeKtbo8jX4inbYM6wn1olaTwroToA89HvJ9GOACl1XQUsKPnLxKjJFdEz7ZBGq4 IdJAAReI+Rn50izo933EEz3tsDwTEAkM0nPXQO3PmF7jdN1H0nYiRxCLnVzfZ3oPJqu8 zxjFbHbmUq5EuKJQ4KpWaEcAs+WeNH8kuLdjzl8wqCKW0lGy0zVHGQ6FN9sc0VJP80h0 DJsXgQ7jrL3r2doxlV4EN0hwlSqOdPNLHf/CzjPK+4o8elb9s4EiSZAxZHuguLOSsW7f EX6g== X-Gm-Message-State: ACrzQf0b23wmRVXrO/BG7dyvhgm6MjEdaRKu9EIlOO+X90UOQu7+cR/Q mpXlhhykF5RWFnVBcn6mdXbVT6yhk4sSkawju9g6QVM5gUIEnk6Ie/mj7E8JIfRwdbz8T6HnebP KXdzQ6D6MpDp8cUOm/GYVCCDpSW7EMm97mCM0RDiZMAxNBJabAKjHJC7MNof3wKD6gsI= X-Received: by 2002:a05:6214:c2a:b0:474:2411:b482 with SMTP id a10-20020a0562140c2a00b004742411b482mr208314qvd.128.1665675563482; Thu, 13 Oct 2022 08:39:23 -0700 (PDT) X-Received: by 2002:a05:6214:c2a:b0:474:2411:b482 with SMTP id a10-20020a0562140c2a00b004742411b482mr208297qvd.128.1665675563235; Thu, 13 Oct 2022 08:39:23 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id u2-20020a05620a454200b006af0ce13499sm19667165qkp.115.2022.10.13.08.39.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 08:39:22 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++ modules: verify_type failure with typedef enum [PR106848] Date: Thu, 13 Oct 2022 11:39:21 -0400 Message-Id: <20221013153921.3795800-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.0.68.ge85701b4af MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.0 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, 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?1746587469141247846?= X-GMAIL-MSGID: =?utf-8?q?1746587469141247846?= 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; + } 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;