From patchwork Thu Jul 18 12:53:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1962098 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=UWNGTeyi; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=YhTS8Zgs; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=UWNGTeyi; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=YhTS8Zgs; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WPt5z2xNYz1xrQ for ; Thu, 18 Jul 2024 22:53:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B8D1385F009 for ; Thu, 18 Jul 2024 12:53:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 483343858C53 for ; Thu, 18 Jul 2024 12:53:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 483343858C53 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 483343858C53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721307203; cv=none; b=lOt/ue8yz18shRwBvFj04zBu9c4CxPTUvUMXCNr+x1UwO6whNcEbK3OeTSbe5ubX4Ksi5Y3V7aMtYTcamnp/aN/S83jUYGrbe96owXgZWThVTFwNtBM7W+1Wc9yYZ9RdpU56R1Xhl2qcTNq4L1Lbe5pMkYznqaKD1UvSU7GviNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721307203; c=relaxed/simple; bh=Gk+anMGboRSKwWFLGZMvXOkY3u1OtReZDkjdzWlBhrY=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=lZiJq87K2L4v92lYxP3YMvKBwfLwRmm5DiNYY5UHEmGjX0XnZPZMCzQqnQB26zp0L3qpwZ60KIQOp7oaHPYagpcvTC3y+PDH6VIDjbnB+5gGHeT9s2GdhVRZNaZ5y2kuznakXR4Os9Acs49HOXBRBSptfvh82z11cPax9xmXlKk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from murzim.nue2.suse.org (unknown [10.168.4.243]) (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 smtp-out1.suse.de (Postfix) with ESMTPS id 0729621907 for ; Thu, 18 Jul 2024 12:53:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721307201; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=XrGx4m/dqhugTPSW2CMq/0TMQTqulhsN03sQaOxUb/c=; b=UWNGTeyisz87JZlHZeWi2kd3lSabZ4ddGlwBLpkLx/7v7CT0lULBgfzFXjB7CU7t4X0Luq NXWf3zaXXvEcvPCY1PwAHzRwduUQ2DpB6YUSRkdzSv9FyHMcONNttG/SAaWCka/dtyVGUc qw6nX3elCuLwy94NaqaA4swrFTEyElc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721307201; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=XrGx4m/dqhugTPSW2CMq/0TMQTqulhsN03sQaOxUb/c=; b=YhTS8Zgsq1TbSXD6/NDTbRVZlBcNOOuQjFNgCUWLeCZ7FxljPhLc0AHnNziQDjBiW4/B9m DYTx0j07kR1CC6CQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721307201; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=XrGx4m/dqhugTPSW2CMq/0TMQTqulhsN03sQaOxUb/c=; b=UWNGTeyisz87JZlHZeWi2kd3lSabZ4ddGlwBLpkLx/7v7CT0lULBgfzFXjB7CU7t4X0Luq NXWf3zaXXvEcvPCY1PwAHzRwduUQ2DpB6YUSRkdzSv9FyHMcONNttG/SAaWCka/dtyVGUc qw6nX3elCuLwy94NaqaA4swrFTEyElc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721307201; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=XrGx4m/dqhugTPSW2CMq/0TMQTqulhsN03sQaOxUb/c=; b=YhTS8Zgsq1TbSXD6/NDTbRVZlBcNOOuQjFNgCUWLeCZ7FxljPhLc0AHnNziQDjBiW4/B9m DYTx0j07kR1CC6CQ== Date: Thu, 18 Jul 2024 14:53:20 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/115641 - invalid address construction MIME-Version: 1.0 X-Spam-Score: 4.44 X-Spamd-Result: default: False [4.44 / 50.00]; MISSING_MID(2.50)[]; NEURAL_SPAM_SHORT(2.04)[0.681]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_ZERO(0.00)[0]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MISSING_XM_UA(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_NONE(0.00)[]; MIME_TRACE(0.00)[0:+] X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.30 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 Message-Id: <20240718125340.0B8D1385F009@sourceware.org> fold_truth_andor_1 via make_bit_field_ref builds an address of a CALL_EXPR which isn't valid GENERIC and later causes an ICE. The following simply avoids the folding for f ().a != 1 || f ().b != 2 as it is a premature optimization anyway. The alternative would have been to build a TARGET_EXPR around the call. To get this far f () has to be const as otherwise the two calls are not semantically equivalent for the optimization. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR middle-end/115641 * fold-const.cc (decode_field_reference): If the inner reference isn't something we can take the address of, fail. * gcc.dg/torture/pr115641.c: New testcase. --- gcc/fold-const.cc | 3 +++ gcc/testsuite/gcc.dg/torture/pr115641.c | 29 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr115641.c diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index fbc24a41427..400449c3617 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -5003,6 +5003,9 @@ decode_field_reference (location_t loc, tree *exp_, HOST_WIDE_INT *pbitsize, || *pbitsize < 0 || offset != 0 || TREE_CODE (inner) == PLACEHOLDER_EXPR + /* We eventually want to build a larger reference and need to take + the address of this. */ + || (!REFERENCE_CLASS_P (inner) && !DECL_P (inner)) /* Reject out-of-bound accesses (PR79731). */ || (! AGGREGATE_TYPE_P (TREE_TYPE (inner)) && compare_tree_int (TYPE_SIZE (TREE_TYPE (inner)), diff --git a/gcc/testsuite/gcc.dg/torture/pr115641.c b/gcc/testsuite/gcc.dg/torture/pr115641.c new file mode 100644 index 00000000000..65fb09ca64f --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr115641.c @@ -0,0 +1,29 @@ +/* { dg-do run } */ + +typedef struct { + char hours, day, month; + short year; +} T; + +T g (void) +{ + T now; + now.hours = 1; + now.day = 2; + now.month = 3; + now.year = 4; + return now; +} + +__attribute__((const)) T f (void) +{ + T virk = g (); + return virk; +} + +int main () +{ + if (f ().hours != 1 || f ().day != 2 || f ().month != 3 || f ().year != 4) + __builtin_abort (); + return 0; +}