From patchwork Tue May 11 10:47:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1477059 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 ozlabs.org (Postfix) with ESMTPS id 4FfZQF3JdPz9sWl for ; Tue, 11 May 2021 20:48:04 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D70C23839C4D; Tue, 11 May 2021 10:48:01 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id EBAAE384B071 for ; Tue, 11 May 2021 10:47:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EBAAE384B071 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rguenther@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D37E2AFEB for ; Tue, 11 May 2021 10:47:58 +0000 (UTC) Date: Tue, 11 May 2021 12:47:58 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/100509 - avoid folding constant to aggregate type Message-ID: <50rsn59q-5784-67rn-n783-94998pnrnq94@fhfr.qr> MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" When folding a constant initializer looking through aliases to incompatible types can lead to us trying to fold a constant to an aggregate type which can't work. Simply avoid trying to constant fold non-register typed symbols. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed to trunk sofar. 2021-05-11 Richard Biener PR middle-end/100509 * gimple-fold.c (fold_gimple_assign): Only call get_symbol_constant_value on register type symbols. * gcc.dg/pr100509.c: New testcase. --- gcc/gimple-fold.c | 3 ++- gcc/testsuite/gcc.dg/pr100509.c | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr100509.c diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 768ef89d876..6beb4f3d305 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -547,7 +547,8 @@ fold_gimple_assign (gimple_stmt_iterator *si) CONSTRUCTOR_ELTS (rhs)); } - else if (DECL_P (rhs)) + else if (DECL_P (rhs) + && is_gimple_reg_type (TREE_TYPE (rhs))) return get_symbol_constant_value (rhs); } break; diff --git a/gcc/testsuite/gcc.dg/pr100509.c b/gcc/testsuite/gcc.dg/pr100509.c new file mode 100644 index 00000000000..9405e2a27df --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr100509.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O" } */ + +struct X { + int a; +}; +const int a = 0; +static struct X A __attribute__((alias("a"))); +void foo() { struct X b = A; }