From patchwork Fri Jan 21 17:06:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1582668 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=pvpHA4iR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JgQnL20QVz9t2p for ; Sat, 22 Jan 2022 04:08:19 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 48A1C3858413 for ; Fri, 21 Jan 2022 17:08:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 48A1C3858413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1642784897; bh=f3vMjdJvm1X5yi4UKaSJ2qEtolP96tG9pczyOiWlvWI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pvpHA4iRIUKpaz4uwHYClpejQLjDRzyCWs+wrXvJMXB0IacNzI4EXg3w2SdUwwgCe of79B++fP2eOl206XHM5wa5qUEOdFxL0x94lqlMXxRpTZwcIhb6ZcFvLrdm4jYPBMT 5jwQ41f/1bJPaoAiu7+LxtQL3+ISPAIs32tQ0y7w= 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 54D103857C7F for ; Fri, 21 Jan 2022 17:06:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 54D103857C7F Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-179-eM0RPZFcPb6spyl0zkBtJQ-1; Fri, 21 Jan 2022 12:06:40 -0500 X-MC-Unique: eM0RPZFcPb6spyl0zkBtJQ-1 Received: by mail-qv1-f69.google.com with SMTP id jn6-20020ad45de6000000b004146a2f1f97so10142785qvb.19 for ; Fri, 21 Jan 2022 09:06:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=f3vMjdJvm1X5yi4UKaSJ2qEtolP96tG9pczyOiWlvWI=; b=6UpWDVSpOUTNoJhenpZ+DkzSmCAjgfm3rDwVRIOGM/mQXo1breBW/sLOKOS/zs/pOK 1QCXHqskmKSwIfTjzLPNsiwwMunCWk5qff092XlqcXrirozRzENgeea/RyfLE/yGfbLA zGiTHkwFDZvv6eWuOBNQtOwMMQbNCrcNxEkuiu5r1LwbssKyvcstjJxQKxzy4Oi747Wb V4JOcAZ9z8x7TH4+NXGSEI8asDE3bIiMJbx4R3fUaYazAP+TUOJ/YavzCeL+3N3wiRQ1 R9beU2NFJVxG9MRV3EsmE8im6mEMuPj3tl5ZgycmCX7XmKN50VdZBpAvEQu+fu2PULko GDlw== X-Gm-Message-State: AOAM530Q79fE3GG0PYwBmX4NNyWQwcvh9ZGQKJ85SevbfYOXweiT6N9q HMgOxzCZFuzo9EoMjxJ6pI5tsMmG9trcxnovXrEmKIvDBGKReWE17aOY18kDVF+5L+qFcid5FgS rBDfcdZX9wZhuW5OKEdatBqGquGoXVfnln1BJ2Btf42i+ZmTLG8wO0b70x6XD17sWGg== X-Received: by 2002:ad4:5f8a:: with SMTP id jp10mr4605387qvb.86.1642784799770; Fri, 21 Jan 2022 09:06:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3+CMt67msJtGsgg/ZTBHaRsX/+8dK3+2LLaVaxDGQ6WN2jjhHsjmj/2WQ6EVG6kNKH2v9rA== X-Received: by 2002:ad4:5f8a:: with SMTP id jp10mr4605314qvb.86.1642784799152; Fri, 21 Jan 2022 09:06:39 -0800 (PST) Received: from barrymore.cygnus.csb (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id s3sm3411961qkp.117.2022.01.21.09.06.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 09:06:38 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: [[no_unique_address]] and virtual base [PR104139] Date: Fri, 21 Jan 2022 12:06:36 -0500 Message-Id: <20220121170636.542755-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 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, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Fixing a thinko in my patch for 103681: when computing the size of a virtual base, it would help to use its binfo instead of the one for the derived class. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/104139 PR c++/103681 gcc/cp/ChangeLog: * class.cc (end_of_class): Use base_binfo. gcc/testsuite/ChangeLog: * g++.dg/abi/no_unique_address2.C: Adjust to detect this on x86-64. --- gcc/cp/class.cc | 4 +-- gcc/testsuite/g++.dg/abi/no_unique_address2.C | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) base-commit: 45cae5b6392496028f35c5948f7fae0af81d135b diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc index e5cc6f10e3b..5db3722ae46 100644 --- a/gcc/cp/class.cc +++ b/gcc/cp/class.cc @@ -6414,8 +6414,8 @@ end_of_class (tree t, eoc_mode mode) { if (mode == eoc_nv_or_dsize) /* For dsize, don't count trailing empty bases. */ - offset = size_binop (PLUS_EXPR, BINFO_OFFSET (binfo), - CLASSTYPE_SIZE_UNIT (BINFO_TYPE (binfo))); + offset = size_binop (PLUS_EXPR, BINFO_OFFSET (base_binfo), + CLASSTYPE_SIZE_UNIT (BINFO_TYPE (base_binfo))); else offset = end_of_base (base_binfo); if (tree_int_cst_lt (result, offset)) diff --git a/gcc/testsuite/g++.dg/abi/no_unique_address2.C b/gcc/testsuite/g++.dg/abi/no_unique_address2.C index bef6d5b43be..3bb3f76ac92 100644 --- a/gcc/testsuite/g++.dg/abi/no_unique_address2.C +++ b/gcc/testsuite/g++.dg/abi/no_unique_address2.C @@ -41,3 +41,30 @@ struct B4 #define SA(X) static_assert ((X), #X) SA (sizeof (B2) == sizeof (B1)); SA (sizeof (B3) == sizeof (B4)); + +namespace N2 +{ + // C as big as _vptr to test PR c++/104139 + struct C + { + long c; + }; + + struct D: virtual C + { + virtual void f(); + }; + + struct B3: D + { + char c2; + }; + + struct B4 + { + D d [[no_unique_address]]; + char c2; + }; + + SA (sizeof (B3) == sizeof (B4)); +}