From patchwork Thu Jul 14 08:19:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 249 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a98:d5ce:0:b0:178:cc93:bf7d with SMTP id g14csp204713eik; Thu, 14 Jul 2022 01:20:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uEFPQixPOI7Rtw3cQB+vcuefUbI+emqRQN2nGZaGa78BEpZUIVxxy8TxGQXYYwRuZif9sU X-Received: by 2002:a17:906:14d:b0:711:ffc4:3932 with SMTP id 13-20020a170906014d00b00711ffc43932mr7640060ejh.321.1657786834724; Thu, 14 Jul 2022 01:20:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657786834; cv=none; d=google.com; s=arc-20160816; b=niZnmiXoxyBIgoH61HouiZoP0C03hwycF83AVFFbYxml3ae1I7qHxr+XTo7ue/XXQr OABAhRQGYrWzjJMIMRTPx4qXxWQeEPVfhHeCyHbOQ7kGKYps+3u4wqKExW94ni1Gviit MgmuNACeXlfe1QE9zX6YhMAN+bef9ekKkNLsGK0wp2sPugngRzHPYXwJ1B3IQnElYq3m FkNh+YMtW5EU3nyDIYUZkg1vzSbLU54U52VEIaq/3vXDo2AnUNDob3Bf1w0nZPjypVkQ V6s0IX9Nj7IbbiJl/kgbV8GC0ksqnPiA/ZMWh1UggtIql7fc5ohJ5SGFSavcWNqvfiwd ex6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=WLp6/7wAASRy3juHQpo9SREC1w3tR33ALkwLEcdzQr0=; b=y5ZlAEB9t8vHlyWPtWEW+p5Hlxgs428AF9+OXOqY6SRMZZZ1zb1aMebOuvpcfQ/4av GZQwpA8a27IvK2ecsEOXLs3u/ujaL1j9mBLN9/M004rvMsVlwKXczlMY60bZX0FdBASv MdZOR665etPxhTgkyTFT0kXLOX4Nn0R9paDWmmXad0X6PT2g7SJcde7GN5EEA9RmRMwk p4+ej7kgtgb3xj3Huxu2tAO1XRjtYF698wWDm2Z93lqMtxcaHiJbmRtIrCOLTrVQ5qxl j6+g0z6W7HPR0xoPM4+y3ISo/urCF+ClKyDF1H36S0nVADs4dx6SmhkKcTIY3jysWtq0 yfqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vDq9LE4c; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v15-20020a17090606cf00b0072af3c1acf5si1111262ejb.657.2022.07.14.01.20.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 01:20:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vDq9LE4c; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 350F73889E0D for ; Thu, 14 Jul 2022 08:20:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 350F73889E0D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1657786808; bh=WLp6/7wAASRy3juHQpo9SREC1w3tR33ALkwLEcdzQr0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=vDq9LE4cPDY1lIBxh2fz5Iq+IfsCgyaweLaSOJZBrD+RxsvcuCmAMuIr6wr7mBBVM fqARThEOIqJBMcsBASsjOe2XR+lzv5xHXYmKy6FqkTLnQD0CVJ24iOAUPZZRAOIYvI 48vtCGgRMD2HnK76mEnclo0pXYKdV/QtzBPKKwao= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 6796D388CE8D for ; Thu, 14 Jul 2022 08:19:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6796D388CE8D Received: by mail-wm1-x331.google.com with SMTP id l68so547545wml.3 for ; Thu, 14 Jul 2022 01:19:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=WLp6/7wAASRy3juHQpo9SREC1w3tR33ALkwLEcdzQr0=; b=ZMsDQiY09W1/+NISpKMJRBq4F23yDi9xTZNBNI4KPCWrOKXKv6kEl9lId/sUb+Fmh+ bPiIVgcbDA7G8zXDR07yzjjEgYUtwRR/LjqHjkKcq8MIwKlZuL15R+jVxy6gtLSZ/ktl tEmGWKildsrElVHOBgooxk/nS4RENHfSa1SfZsfJOjYBpWzu0p7YXWtNsN3hHcILKHcu pzSeVuIfC0OrOuSib5Sma9a1Py9tRFClSKrzxnwbC7DJEnjMU1hvU4KHVJee4N6e3tJh OLJ9RCmk4ZjpXZ1N1cYfdlxyThbQIzE6IWj570QcyKoi3UgEUOiLFBtT7axETE4LDQM7 nrgQ== X-Gm-Message-State: AJIora88LVZ0KjLMRIH8nIxCbb20FpdO8ubPtdBpEhaSVVSx9VckGY6W YKfg/VEqozKbXTKxS6cKiTDtVWb/Tlrncg== X-Received: by 2002:a05:600c:4149:b0:3a0:4728:60e7 with SMTP id h9-20020a05600c414900b003a0472860e7mr7685308wmm.10.1657786761066; Thu, 14 Jul 2022 01:19:21 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id g6-20020a056000118600b0021d7050ace4sm818787wrx.77.2022.07.14.01.19.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 01:19:20 -0700 (PDT) X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ICE on view conversion between struct and integer Date: Thu, 14 Jul 2022 10:19:18 +0200 Message-ID: <3179248.aeNJFYEL58@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_PORT 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Eric Botcazou via Gcc-patches From: Eric Botcazou Reply-To: Eric Botcazou Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1738315487748248951?= X-GMAIL-MSGID: =?utf-8?q?1738315487748248951?= Hi, you can build a view conversion between pretty much anything in Ada including between types with different sizes, although the compiler warns in this case and gigi pads the smaller type to end up with the same size. The attached testcase triggers an ICE at -O or above for one of them: FAIL: gnat.dg/opt98.adb (test for excess errors) Excess errors: during GIMPLE pass: esra +===========================GNAT BUG DETECTED==============================+ | 13.0.0 20220713 (experimental) [master 6f5cf9470aa] (x86_64-suse-linux) GCC error:| | in gimplify_modify_expr, at gimplify.cc:6254 | | Error detected around /home/eric/cvs/gcc/gcc/testsuite/gnat.dg/opt98.adb:10:7| | Compiling /home/eric/cvs/gcc/gcc/testsuite/gnat.dg/opt98.adb | if (gimplify_ctxp->into_ssa && is_gimple_reg (*to_p)) { /* We should have got an SSA name from the start. */ gcc_assert (TREE_CODE (*to_p) == SSA_NAME || ! gimple_in_ssa_p (cfun)); } This happens from prepare_gimple_addressable for the variable to be marked with DECL_NOT_GIMPLE_REG_P when its initialization is gimplified, so it's apparently just a matter of setting the flag earlier. Bootstrapped/regtested on x86-64/Linux, OK for the mainline? 2022-07-14 Eric Botcazou * gimplify.cc (lookup_tmp_var): Add NOT_GIMPLE_REG boolean parameter and set DECL_NOT_GIMPLE_REG_P on the variable according to it. (internal_get_tmp_var): Add NOT_GIMPLE_REG boolean parameter and pass it in the call to lookup_tmp_var. (get_formal_tmp_var): Pass false in the call to lookup_tmp_var. (get_initialized_tmp_var): Likewise. (prepare_gimple_addressable): Call internal_get_tmp_var instead of get_initialized_tmp_var with NOT_GIMPLE_REG set to true. 2022-07-14 Eric Botcazou * gnat.dg/opt98.ads, gnat.dg/opt98.adb: New test. diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 04990ad91a6..2ac7ca0855e 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -573,20 +573,26 @@ create_tmp_from_val (tree val) } /* Create a temporary to hold the value of VAL. If IS_FORMAL, try to reuse - an existing expression temporary. */ + an existing expression temporary. If NOT_GIMPLE_REG, mark it as such. */ static tree -lookup_tmp_var (tree val, bool is_formal) +lookup_tmp_var (tree val, bool is_formal, bool not_gimple_reg) { tree ret; + /* We cannot mark a formal temporary with DECL_NOT_GIMPLE_REG_P. */ + gcc_assert (!is_formal || !not_gimple_reg); + /* If not optimizing, never really reuse a temporary. local-alloc won't allocate any variable that is used in more than one basic block, which means it will go into memory, causing much extra work in reload and final and poorer code generation, outweighing the extra memory allocation here. */ if (!optimize || !is_formal || TREE_SIDE_EFFECTS (val)) - ret = create_tmp_from_val (val); + { + ret = create_tmp_from_val (val); + DECL_NOT_GIMPLE_REG_P (ret) = not_gimple_reg; + } else { elt_t elt, *elt_p; @@ -617,7 +623,7 @@ lookup_tmp_var (tree val, bool is_formal) static tree internal_get_tmp_var (tree val, gimple_seq *pre_p, gimple_seq *post_p, - bool is_formal, bool allow_ssa) + bool is_formal, bool allow_ssa, bool not_gimple_reg) { tree t, mod; @@ -639,7 +645,7 @@ internal_get_tmp_var (tree val, gimple_seq *pre_p, gimple_seq *post_p, } } else - t = lookup_tmp_var (val, is_formal); + t = lookup_tmp_var (val, is_formal, not_gimple_reg); mod = build2 (INIT_EXPR, TREE_TYPE (t), t, unshare_expr (val)); @@ -667,7 +673,7 @@ internal_get_tmp_var (tree val, gimple_seq *pre_p, gimple_seq *post_p, tree get_formal_tmp_var (tree val, gimple_seq *pre_p) { - return internal_get_tmp_var (val, pre_p, NULL, true, true); + return internal_get_tmp_var (val, pre_p, NULL, true, true, false); } /* Return a temporary variable initialized with VAL. PRE_P and POST_P @@ -678,7 +684,7 @@ get_initialized_tmp_var (tree val, gimple_seq *pre_p, gimple_seq *post_p /* = NULL */, bool allow_ssa /* = true */) { - return internal_get_tmp_var (val, pre_p, post_p, false, allow_ssa); + return internal_get_tmp_var (val, pre_p, post_p, false, allow_ssa, false); } /* Declare all the variables in VARS in SCOPE. If DEBUG_INFO is true, @@ -4574,13 +4580,10 @@ prepare_gimple_addressable (tree *expr_p, gimple_seq *seq_p) { while (handled_component_p (*expr_p)) expr_p = &TREE_OPERAND (*expr_p, 0); + + /* Do not allow an SSA name as the temporary. */ if (is_gimple_reg (*expr_p)) - { - /* Do not allow an SSA name as the temporary. */ - tree var = get_initialized_tmp_var (*expr_p, seq_p, NULL, false); - DECL_NOT_GIMPLE_REG_P (var) = 1; - *expr_p = var; - } + *expr_p = internal_get_tmp_var (*expr_p, seq_p, NULL, false, false, true); } /* A subroutine of gimplify_modify_expr. Replace a MODIFY_EXPR with