Message ID | 20221007150952.102429-1-ppalka@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8DC603858CDB for <patchwork@sourceware.org>; Fri, 7 Oct 2022 15:10:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8DC603858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665155427; bh=J3vkffE+vcc8M2jaYtzZ7qalyxyYixwiAhCxLbUvfH8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Gq2N/Bi+pAPVgpvnPPrB1TIkpvb+a3axApcxd7xnoK2YwQgr4C084kD3e/uuVdFKJ M5htpIyqhkYkwmmbp7aYWV0R3a+yBqsDC2a+ruo4wR/Bpsj2pSRCFP5h+jz+mu8BmD PqzYgkppfyP30NIQ6VRWwysR3Z+edE5EOrXNndvg= 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 3C96E3858CDB for <gcc-patches@gcc.gnu.org>; Fri, 7 Oct 2022 15:09:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3C96E3858CDB 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-531-AzLogzq7PZan5_f_gkbmMg-1; Fri, 07 Oct 2022 11:09:56 -0400 X-MC-Unique: AzLogzq7PZan5_f_gkbmMg-1 Received: by mail-qk1-f200.google.com with SMTP id j13-20020a05620a288d00b006be7b2a758fso3937888qkp.1 for <gcc-patches@gcc.gnu.org>; Fri, 07 Oct 2022 08:09:56 -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=J3vkffE+vcc8M2jaYtzZ7qalyxyYixwiAhCxLbUvfH8=; b=1ngJXhGo0+hYO9qPwLaWMLUCPxkZfu4deGyNfkikZqBp/LZqqUCnVUqIuDNPNYN4Tz /jbioiJGigQv7XpvVPqFu2vDm4fb6pnfrg5fpFbsNgb5Y5OaMIqLYEKtBX47o+m64y/7 xQhbTsGR/F4V1GdhfyFK/CG3CThSzTa7BFJ/i4KbATlh2Yc5rj14UMEWCLsCb0uTo+p8 YfHg1MBy/sDRRwoPbMXFU/nP/9hVFGkXQ2N8yQaG3wqP2L/JsWTpCWsRgrVhh2tWy6IF q5wcZoz7LJiufhSluIruJvOTQBBgdphUEcIj0tlrRFgnsyzqxH47eegHwm6I6S1Ni2S9 e+KA== X-Gm-Message-State: ACrzQf0MUM2hMehKm0QdEklEzL76gNV1LGMf7z/43kCH2qVjEOOzrjbB 1awGQ8pGYJPgn68evClusaqdqcwyTvGrBxJJxB2mT+8l1M7uyLjVsCC6/YXI+AkcEFeB9ryiO3r Pf1FRH69KPZ7BC6O6ZyyV3QQSnKFvBUgIlSS/WhQ2nGrE3rotOHwdxZFOD3lX/K6pzWw= X-Received: by 2002:ae9:f715:0:b0:6e7:73bf:63c9 with SMTP id s21-20020ae9f715000000b006e773bf63c9mr3880448qkg.225.1665155395448; Fri, 07 Oct 2022 08:09:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4GLNTGb/bstbSLX4ipSPVqbAfCe7SFaSoCinckQ6Aujn7pwEMePDdtXyDRf8uVzsQwdy2NmA== X-Received: by 2002:ae9:f715:0:b0:6e7:73bf:63c9 with SMTP id s21-20020ae9f715000000b006e773bf63c9mr3880430qkg.225.1665155395141; Fri, 07 Oct 2022 08:09:55 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id f11-20020a05620a280b00b006ce515196a7sm2295911qkp.8.2022.10.07.08.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Oct 2022 08:09:54 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++ modules: ICE with bitfield member in class template Date: Fri, 7 Oct 2022 11:09:52 -0400 Message-Id: <20221007150952.102429-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.0.rc2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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, RCVD_IN_DNSWL_LOW, 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Patrick Palka via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Patrick Palka <ppalka@redhat.com> Cc: nathan@acm.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
c++ modules: ICE with bitfield member in class template
|
|
Commit Message
Patrick Palka
Oct. 7, 2022, 3:09 p.m. UTC
According to grokbitfield, DECL_BITFIELD_REPRESENTATIVE may "temporarily" contain the width of the bitfield until we layout the class type (after which it'll contain a FIELD_DECL). But for a class template, it'll always be the width since we don't/can't layout dependent types. Tested on x86_64-pc-linux-gnu, does this look OK for trunk? gcc/cp/ChangeLog: * module.cc (trees_out::mark_class_def): Guard against DECL_BITFIELD_REPRESENTATIVE not being a decl. gcc/testsuite/ChangeLog: * g++.dg/modules/bfield-3.H: New test. --- gcc/cp/module.cc | 3 ++- gcc/testsuite/g++.dg/modules/bfield-3.H | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/modules/bfield-3.H
Comments
On 10/7/22 11:09, Patrick Palka wrote: > According to grokbitfield, DECL_BITFIELD_REPRESENTATIVE may "temporarily" > contain the width of the bitfield until we layout the class type (after > which it'll contain a FIELD_DECL). But for a class template, it'll always > be the width since we don't/can't layout dependent types. > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk? ok, but could you add a comment on why it might not be a decl? > > gcc/cp/ChangeLog: > > * module.cc (trees_out::mark_class_def): Guard against > DECL_BITFIELD_REPRESENTATIVE not being a decl. > > gcc/testsuite/ChangeLog: > > * g++.dg/modules/bfield-3.H: New test. > --- > gcc/cp/module.cc | 3 ++- > gcc/testsuite/g++.dg/modules/bfield-3.H | 8 ++++++++ > 2 files changed, 10 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/modules/bfield-3.H > > diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc > index cb1929bc5d5..172a72e92b9 100644 > --- a/gcc/cp/module.cc > +++ b/gcc/cp/module.cc > @@ -11919,7 +11919,8 @@ trees_out::mark_class_def (tree defn) > mark_class_member (member); > if (TREE_CODE (member) == FIELD_DECL) > if (tree repr = DECL_BIT_FIELD_REPRESENTATIVE (member)) > - mark_declaration (repr, false); > + if (DECL_P (repr)) > + mark_declaration (repr, false); > } > > /* Mark the binfo hierarchy. */ > diff --git a/gcc/testsuite/g++.dg/modules/bfield-3.H b/gcc/testsuite/g++.dg/modules/bfield-3.H > new file mode 100644 > index 00000000000..4fd4db7116a > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/bfield-3.H > @@ -0,0 +1,8 @@ > +// { dg-additional-options -fmodule-header } > +// { dg-module-cmi {} } > + > +template<int N> > +struct A { > + int x : 1; > + int y : N; > +};
On Fri, 7 Oct 2022, Nathan Sidwell wrote: > On 10/7/22 11:09, Patrick Palka wrote: > > According to grokbitfield, DECL_BITFIELD_REPRESENTATIVE may "temporarily" > > contain the width of the bitfield until we layout the class type (after > > which it'll contain a FIELD_DECL). But for a class template, it'll always > > be the width since we don't/can't layout dependent types. > > > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk? > > ok, but could you add a comment on why it might not be a decl? Thanks a lot, I added a comment and committed the following: -- >8 -- Subject: [PATCH] c++ modules: ICE with bitfield in class template According to grokbitfield, DECL_BIT_FIELD_REPRESENTATIVE may temporarily contain the width of the bitfield until we layout the class type (after which it'll contain a decl). Thus for a bitfield in a class template it'll always be the width, and this patch makes us avoid ICEing from mark_class_def in this case. gcc/cp/ChangeLog: * module.cc (trees_out::mark_class_def): Guard against DECL_BIT_FIELD_REPRESENTATIVE not being a decl. gcc/testsuite/ChangeLog: * g++.dg/modules/bfield-3.H: New test. --- gcc/cp/module.cc | 6 +++++- gcc/testsuite/g++.dg/modules/bfield-3.H | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/modules/bfield-3.H diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index cb1929bc5d5..a7c199c00a4 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -11919,7 +11919,11 @@ trees_out::mark_class_def (tree defn) mark_class_member (member); if (TREE_CODE (member) == FIELD_DECL) if (tree repr = DECL_BIT_FIELD_REPRESENTATIVE (member)) - mark_declaration (repr, false); + /* If we're marking a class template definition, then + DECL_BIT_FIELD_REPRESENTATIVE will contain the width + instead of a decl (as set by grokbitfield). */ + if (DECL_P (repr)) + mark_declaration (repr, false); } /* Mark the binfo hierarchy. */ diff --git a/gcc/testsuite/g++.dg/modules/bfield-3.H b/gcc/testsuite/g++.dg/modules/bfield-3.H new file mode 100644 index 00000000000..4fd4db7116a --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/bfield-3.H @@ -0,0 +1,8 @@ +// { dg-additional-options -fmodule-header } +// { dg-module-cmi {} } + +template<int N> +struct A { + int x : 1; + int y : N; +};
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index cb1929bc5d5..172a72e92b9 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -11919,7 +11919,8 @@ trees_out::mark_class_def (tree defn) mark_class_member (member); if (TREE_CODE (member) == FIELD_DECL) if (tree repr = DECL_BIT_FIELD_REPRESENTATIVE (member)) - mark_declaration (repr, false); + if (DECL_P (repr)) + mark_declaration (repr, false); } /* Mark the binfo hierarchy. */ diff --git a/gcc/testsuite/g++.dg/modules/bfield-3.H b/gcc/testsuite/g++.dg/modules/bfield-3.H new file mode 100644 index 00000000000..4fd4db7116a --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/bfield-3.H @@ -0,0 +1,8 @@ +// { dg-additional-options -fmodule-header } +// { dg-module-cmi {} } + +template<int N> +struct A { + int x : 1; + int y : N; +};