From patchwork Thu Oct 21 10:57:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1544303 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=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=Kb7YRVds; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=VkMOsAhn; 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 4HZkwB0ppXz9sR4 for ; Thu, 21 Oct 2021 21:57:46 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 025313858434 for ; Thu, 21 Oct 2021 10:57:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id C8E833858D39 for ; Thu, 21 Oct 2021 10:57:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C8E833858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id ED9AF1FDA8 for ; Thu, 21 Oct 2021 10:57:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1634813850; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=I4hFBJj38LpUESZOK9nXVFi26Aq+/oMwl73Qea6w5HQ=; b=Kb7YRVds0pag7Yy8s/kZHcVOfErWSCCaW9R+gHnQz1SPGV7iHCa5o2iBEUoyaRum1+Wwp0 cR4P6/5K8L12W6Qgqb1hKZ/zZpUZt/LQwwAbhzlPYMLdHSciCpttg6pY2SCCk0yXB26sMW poHhw805N5FrzmSvJG/vYXhGc6PMkFo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1634813850; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=I4hFBJj38LpUESZOK9nXVFi26Aq+/oMwl73Qea6w5HQ=; b=VkMOsAhn6Lki//dYupa7mqutKKSnHepXdNgqz+pbUxEIQg81SI9QQNZ+9givq9BOm/Et2V 8GJnW0Ka5srNkNAA== Received: from suse.cz (unknown [10.100.200.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id D03A1A3B84 for ; Thu, 21 Oct 2021 10:57:30 +0000 (UTC) From: Martin Jambor To: GCC Patches Cc: Subject: [PATCH] sra: Fix corner case of total scalarization with virtual inheritance (PR 102505) User-Agent: Notmuch/0.33.2 (https://notmuchmail.org) Emacs/27.2 (x86_64-suse-linux-gnu) Date: Thu, 21 Oct 2021 12:57:27 +0200 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, PR 102505 is a situation where of SRA takes its initial top-level access size from a get_ref_base_and_extent called on a COMPONENT_REF, and thus derived frm the FIELD_DECL, which however does not include a virtual base. Total scalarization then goes on traversing the type, which however has virtual base past the non-virtual bits, tricking SRA to create sub-accesses outside of the supposedly encompassing accesses, which in turn triggers the verifier within the pass. The patch below fixes that by failing total scalarization when this situation is detected. Bootstrapped and tested on x86_64-linux, OK for trunk and (after testing there) on the branches? Thanks, Martin gcc/ChangeLog: 2021-10-20 Martin Jambor PR tree-optimization/102505 * tree-sra.c (totally_scalarize_subtree): Check that the encountered field fits within the acces we would like to put it in. gcc/testsuite/ChangeLog: 2021-10-20 Martin Jambor PR tree-optimization/102505 * g++.dg/torture/pr102505.C: New test. --- gcc/testsuite/g++.dg/torture/pr102505.C | 15 +++++++++++++++ gcc/tree-sra.c | 2 ++ 2 files changed, 17 insertions(+) create mode 100644 gcc/testsuite/g++.dg/torture/pr102505.C diff --git a/gcc/testsuite/g++.dg/torture/pr102505.C b/gcc/testsuite/g++.dg/torture/pr102505.C new file mode 100644 index 00000000000..a846751a0d6 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr102505.C @@ -0,0 +1,15 @@ +struct D { int i; int pad alignas(16); }; +struct B : virtual D +{ + int j =84; + int k =84; +}; + +struct C: B { }; + +int main() +{ + C c; + if (c.j != 84 || c.k != 84) + __builtin_abort(); +} diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index 9b786e29e4e..f561e1a2133 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -3288,6 +3288,8 @@ totally_scalarize_subtree (struct access *root) continue; HOST_WIDE_INT pos = root->offset + int_bit_position (fld); + if (pos + fsize > root->size) + return false; enum total_sra_field_state state = total_should_skip_creating_access (root, &last_seen_sibling,