From patchwork Wed Jul 31 09:05:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1966954 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=zUCOJzdS; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=6rLckQRU; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=zUCOJzdS; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=6rLckQRU; 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 4WYmQm0dqHz1ybV for ; Wed, 31 Jul 2024 19:05:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 358F7385C6C1 for ; Wed, 31 Jul 2024 09:05:34 +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 [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 157F93858C3A for ; Wed, 31 Jul 2024 09:05:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 157F93858C3A 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 157F93858C3A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722416713; cv=none; b=uYodmsAVbHc1w1r7DA0NsaWQbd1scKj0JBaSIZZvV0COwk4xQhotNbUA+mPFXvCTYMaSQPTcMWCTf33nf301iYobODcH9HCTmwGzdjLNnjnyeUIJWuVdv2SsCJ3OLrz4EwFZ1ROUHzaituvyztxMq4QVK77o0CXGBryuSawwpQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722416713; c=relaxed/simple; bh=cEXNF1dmUPtRSNiQ1g+xpszsLdY/GeFC3w9O6pB51j8=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=kpGFPBNQJ9AMzqCG5Mm8pzh7Xho4Tb/GrTFbPEAwTlpmzq5zyNa9o1GBwWed8PGz4MK8nrmDkCjWIhWuiNEFGZluu53BX13LdZnRYJqqMqjjx48YH/l/DHilwWATozssYja6IR1Kdb9ckVFj9qzPe5v/zNC3AeClhvI6BiNDySg= 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 F209521A65 for ; Wed, 31 Jul 2024 09:05:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722416711; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=uCcpxfgLs9N4uBGVzlVrCWRwwi7M8+tI3taz8loU2VQ=; b=zUCOJzdSLvr8I0I0vO0tBQhEeJBZ/JrTMGw8f+Ya5CygC+fA90jnOhBZOgnCrMYrvN9IrG DemicYQne3fboh3G1GroAyvi4R01TjpbZMXPh/FcrUYIR4Apt9T9XPp9ek5bN2RR2c7M3g SD0/QaJx322UwVddFyPBiuh4gJIgmXY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722416711; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=uCcpxfgLs9N4uBGVzlVrCWRwwi7M8+tI3taz8loU2VQ=; b=6rLckQRUCG9KA2FA2wntlJ5wcJMYuiLnoU4vVbI+aN90AKKsAbAmQR7mtP+Qtm5mGfKK9t s+xZZ1bj3b4ZU9CA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722416711; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=uCcpxfgLs9N4uBGVzlVrCWRwwi7M8+tI3taz8loU2VQ=; b=zUCOJzdSLvr8I0I0vO0tBQhEeJBZ/JrTMGw8f+Ya5CygC+fA90jnOhBZOgnCrMYrvN9IrG DemicYQne3fboh3G1GroAyvi4R01TjpbZMXPh/FcrUYIR4Apt9T9XPp9ek5bN2RR2c7M3g SD0/QaJx322UwVddFyPBiuh4gJIgmXY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722416711; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=uCcpxfgLs9N4uBGVzlVrCWRwwi7M8+tI3taz8loU2VQ=; b=6rLckQRUCG9KA2FA2wntlJ5wcJMYuiLnoU4vVbI+aN90AKKsAbAmQR7mtP+Qtm5mGfKK9t s+xZZ1bj3b4ZU9CA== Date: Wed, 31 Jul 2024 11:05:10 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/101478 - ICE with degenerate address during gimplification MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-0.93 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MISSING_MID(2.50)[]; NEURAL_HAM_LONG(-0.33)[-0.328]; 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-Score: -0.93 X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FUZZY_PRICES, GIT_PATCH_0, MISSING_MID, 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: <20240731090534.358F7385C6C1@sourceware.org> When we gimplify &MEM[0B + 4] we are re-folding the address in case types are not canonical which ends up with a constant address that recompute_tree_invariant_for_addr_expr ICEs on. Properly guard that call. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR middle-end/101478 * gimplify.cc (gimplify_addr_expr): Check we still have an ADDR_EXPR before calling recompute_tree_invariant_for_addr_expr. * gcc.dg/pr101478.c: New testcase. --- gcc/gimplify.cc | 3 ++- gcc/testsuite/gcc.dg/pr101478.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr101478.c diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 47c9913b55b..fab5532c54d 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -6984,7 +6984,8 @@ gimplify_addr_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p) *expr_p = build_fold_addr_expr (op0); /* Make sure TREE_CONSTANT and TREE_SIDE_EFFECTS are set properly. */ - recompute_tree_invariant_for_addr_expr (*expr_p); + if (TREE_CODE (*expr_p) == ADDR_EXPR) + recompute_tree_invariant_for_addr_expr (*expr_p); /* If we re-built the ADDR_EXPR add a conversion to the original type if required. */ diff --git a/gcc/testsuite/gcc.dg/pr101478.c b/gcc/testsuite/gcc.dg/pr101478.c new file mode 100644 index 00000000000..527620ea0f1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr101478.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ + +struct obj { + int n; + int l; +}; +int main() +{ + (struct obj *)((char *)(__SIZE_TYPE__)({ 0; }) - (char *)&((struct obj *)0)->l); +}