From patchwork Tue Feb 18 15:56:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1240151 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519743-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=cVOGeLn3; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48MQSn2R5Gz9sRh for ; Wed, 19 Feb 2020 02:56:23 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=haK/bgu/OMwfYjkNdIPeRyqYwkqQIFd3rKURKTNwbwYX+/jr3/ Uxa3SUdgASizDcTk9ZDqr78roQzvFq5cMtKeoD89dUpQMcFc/N54DLBRH4W2GhqV 3JYa8ZWZrnIASAj9S5NVijhUw1jeRrQ/M1zkniClNiSO+bnQA1OaTjHlc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=yywRoAkktPPvE5c+iQ2az82gz/0=; b=cVOGeLn3W87daC4lV0iW CBmWkwRSMvzRUD8iYa6t13RZipk21mENqdkjW2rsFSvPuxCLLj3An9xJoulZHl0y UQjsunpZ1VjGRtIBNXEqbIcjz9rf8O3IQ2KNmZ32EPKa1DjfvZ4fTe4BPIclC1mw HrxQ4dpV8PvdLmRm+BCRoEE= Received: (qmail 17779 invoked by alias); 18 Feb 2020 15:56:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 17770 invoked by uid 89); 18 Feb 2020 15:56:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=93667 X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Feb 2020 15:56:14 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 59313AE79 for ; Tue, 18 Feb 2020 15:56:09 +0000 (UTC) From: Martin Jambor To: GCC Patches Cc: Richard Biener Subject: [PATCH] sra: Avoid totally scalarizing overallping field_decls (PR93667) User-Agent: Notmuch/0.29.3 (https://notmuchmail.org) Emacs/26.3 (x86_64-suse-linux-gnu) Date: Tue, 18 Feb 2020 16:56:08 +0100 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi, [[no_unique_address]] C++ attribute can cause two fields of a RECORD_TYPE overlap, which currently confuses the totally scalarizing code into creating invalid access tree. For GCC 10, I'd like to simply disable total scalarization of types where this happens. For GCC 11 I'll write down a TODO item to enable total scalarization of cases like this where the problematic fields are basically empty - despite having a non-zero size - i.e. when they are just RECORD_TYPEs without any data fields. Bootstrapped and tested on x86_64, OK for trunk? Thanks, Martin 2020-02-14 Martin Jambor PR tree-optimization/93667 * tree-sra.c (scalarizable_type_p): Return false if record fields do not follow wach other. testsuite/ * g++.dg/tree-ssa/pr93667.C: New test. --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/tree-ssa/pr93667.C | 11 +++++++++++ gcc/tree-sra.c | 14 ++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 gcc/testsuite/g++.dg/tree-ssa/pr93667.C diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr93667.C b/gcc/testsuite/g++.dg/tree-ssa/pr93667.C new file mode 100644 index 00000000000..d875f53d9ec --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/pr93667.C @@ -0,0 +1,11 @@ +// { dg-do compile } +// { dg-options "-O2 -std=c++2a" } */ + +struct a {}; +struct b { [[no_unique_address]] a aq; }; +struct c { + int d; + [[no_unique_address]] b e; +}; +c f() {return {};} +void g() { f(); } diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index 0cfac0a8192..4c7d651e6b9 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -958,6 +958,9 @@ scalarizable_type_p (tree type, bool const_decl) if (type_contains_placeholder_p (type)) return false; + bool have_predecessor_field = false; + HOST_WIDE_INT prev_pos = 0; + switch (TREE_CODE (type)) { case RECORD_TYPE: @@ -966,6 +969,17 @@ scalarizable_type_p (tree type, bool const_decl) { tree ft = TREE_TYPE (fld); + if (zerop (DECL_SIZE (fld))) + continue; + + HOST_WIDE_INT pos = int_bit_position (fld); + if (have_predecessor_field + && pos <= prev_pos) + return false; + + have_predecessor_field = true; + prev_pos = pos; + if (DECL_BIT_FIELD (fld)) return false;