From patchwork Sat Aug 3 18:13:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1968749 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=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=CYu8tF1i; 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 4WbrSp6pRPz1ybS for ; Sun, 4 Aug 2024 04:14:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 98C6A3858C60 for ; Sat, 3 Aug 2024 18:14:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id DCE123858D35 for ; Sat, 3 Aug 2024 18:14:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DCE123858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DCE123858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722708848; cv=none; b=f22oaP5LDo7tC6Ty21PnluJnLPVJgrMczZUBEGr3oBq4ZOxLncQIHcoL3F4uZQXrEY7sg5X+Wy/auv/8q4NXbJ2mSJnXilrgZmzrDQkJwY2drrEK5JkHh8XXyXT3g9g8IhsFSjsfntSBSlVsPvVHbsfiKUWdZWf8JdgpVZwbcCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722708848; c=relaxed/simple; bh=eHE9zXQShp+l7oGso9UhH6JV7d+ylrNMSttusHlpvJ0=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=qpopjwHSieoATsH4UqBYoMgdeSAlNXnTVc6UD+MRFowDjC8zji3XzixoH6RaLI6AU0xax5gfvNzigPoPhfJDvA/DeAc5W0DrPvT85FWPW2FZB5LsJh7zOHoE9vg9ypFkSiVOwJPMzPLnWiJAIJf8li8HnL+aWOBQ33kZzFz8xm8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722708846; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=7nX3yKgVaedahmpPm8JbDQ/btjUVn2UtEXt9EgMx4XY=; b=CYu8tF1iuZNGJ6R6JU8nRU2NRe5+fmdevXhp9dAw2fJVNkfkXc3R4jGSXZSrMZ3XukzR1m RhxT9eAznNyrzhwVfWlKA4eoicnQr/X+hX80Wm31t1R4QKMnnY8H7L9Q4HuBg8BRQaiy5l 3tRODTHh8W7PU0b7PqQyLDUD/eX3SGA= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-303-hF81vr45OAuekt6tLx4XZA-1; Sat, 03 Aug 2024 14:14:03 -0400 X-MC-Unique: hF81vr45OAuekt6tLx4XZA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0127C19560AB; Sat, 3 Aug 2024 18:14:02 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.25]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 101D919560AE; Sat, 3 Aug 2024 18:14:00 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 473IDwF2944127 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 3 Aug 2024 20:13:58 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 473IDvu3944126; Sat, 3 Aug 2024 20:13:57 +0200 Date: Sat, 3 Aug 2024 20:13:57 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] gimplify: Small RAW_DATA_CST gimplification fix Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! I've noticed the following testcase on top of the #embed patchset: https://gcc.gnu.org/pipermail/gcc-patches/2024-June/655012.html https://gcc.gnu.org/pipermail/gcc-patches/2024-June/655013.html https://gcc.gnu.org/pipermail/gcc-patches/2024-July/657049.html https://gcc.gnu.org/pipermail/gcc-patches/2024-July/657053.html https://gcc.gnu.org/pipermail/gcc-patches/2024-July/658137.html hangs during gimplification. While it is gimplifying an assignment from a VAR_DECL .LCNNN to MEM_REF, because the VAR_DECL is TREE_READONLY, it will happily pick its initializer and try to gimplify that, which means recursing to the exact same code. The following patch fixes that by just gimplifying the lhs and building assignment, because the code decided that it should use copying from a static var. Bootstrapped/regtested on powerpc64{,le}-linux, ok for trunk? 2024-08-03 Jakub Jelinek * gimplify.cc (gimplify_init_ctor_eval): For larger RAW_DATA_CST, just gimplify cref as lvalue and add gimple assignment of rctor to cref instead of going through gimplification of INIT_EXPR, as the latter can suffer from infinite recursion. * c-c++-common/cpp/embed-24.c: New test. Jakub --- gcc/gimplify.cc.jj 2024-08-02 11:34:03.651027803 +0200 +++ gcc/gimplify.cc 2024-08-03 10:19:47.071916653 +0200 @@ -5400,9 +5400,10 @@ gimplify_init_ctor_eval (tree object, ve cref = build2 (MEM_REF, rtype, addr, build_int_cst (ptr_type_node, 0)); rctor = tree_output_constant_def (rctor); - tree init = build2 (INIT_EXPR, rtype, cref, rctor); - gimplify_and_add (init, pre_p); - ggc_free (init); + if (gimplify_expr (&cref, pre_p, NULL, is_gimple_lvalue, + fb_lvalue) != GS_ERROR) + gimplify_seq_add_stmt (pre_p, + gimple_build_assign (cref, rctor)); } } else --- gcc/testsuite/c-c++-common/cpp/embed-24.c.jj 2024-08-03 10:10:42.145076112 +0200 +++ gcc/testsuite/c-c++-common/cpp/embed-24.c 2024-08-03 19:40:58.693297792 +0200 @@ -0,0 +1,52 @@ +/* { dg-do run } */ +/* { dg-options "-O2" } */ +/* { dg-additional-options "-std=c23" { target c } } */ + +static unsigned char a[] = { +#embed __FILE__ limit (125) +}; + +void +foo (unsigned char *p) +{ + for (int i = 0; i < 128; ++i) + if (p[i] != ((i < 64 || i == 127) ? (unsigned char) -1 : i - 64 + 33)) + __builtin_abort (); + if (__builtin_memcmp (p + 128, a, 125)) + __builtin_abort (); + for (int i = 253; i < 256; ++i) + if (p[i] != (unsigned char) -1) + __builtin_abort (); +} + +#ifdef __cplusplus +#define M1 (unsigned char) -1 +#else +#define M1 -1 +#endif + +int +main () +{ + unsigned char res[256] = { + M1, M1, M1, M1, M1, M1, M1, M1, + M1, M1, M1, M1, M1, M1, M1, M1, + M1, M1, M1, M1, M1, M1, M1, M1, + M1, M1, M1, M1, M1, M1, M1, M1, + M1, M1, M1, M1, M1, M1, M1, M1, + M1, M1, M1, M1, M1, M1, M1, M1, + M1, M1, M1, M1, M1, M1, M1, M1, + M1, M1, M1, M1, M1, M1, M1, M1, + 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 52, 53, 54, 55, 56, + 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, 75, 76, 77, 78, 79, 80, + 81, 82, 83, 84, 85, 86, 87, 88, + 89, 90, 91, 92, 93, 94, 95, M1, + #embed __FILE__ limit (125) suffix (,) + M1, M1, M1 + }; + foo (res); +}