From patchwork Fri Apr 28 09:48:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 88549 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp811141vqo; Fri, 28 Apr 2023 02:49:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6YmGNFgNo2S65XoojFS7Y/G3ui/sZr2xtTTtMvxSbwv5tZEoTvtPT7jBmoSYCb86DKFbsX X-Received: by 2002:a17:907:7f27:b0:953:57a1:55e1 with SMTP id qf39-20020a1709077f2700b0095357a155e1mr4852492ejc.62.1682675371285; Fri, 28 Apr 2023 02:49:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682675371; cv=none; d=google.com; s=arc-20160816; b=U/QX0lfj67IL0/PCfZdzG26BG4VynaxQgo53//ndGAK8p7Ixr/irXnhRfH3vxuLMy5 6dB0XcCCyMIwZoljza0xkBKE6LCxXRampipLWIzNsyVq60DLQvmNqQS31aPJ9TWDLbgl VcgT6iGHGgVVtYwiGfcSoiMDgX1+t+bLlT3k8Rzfqzzx8nqj0vMx21SvHMNpz3B8Sxwy 7WgXAODgG38Zz9KQvjQGNIMZXDePrdpCcMpa01EXL5+d4VrcrjeVv9PIxxsl6m61Plla cKW1yG8AeTcTHxvyvxvmxyPdqIU6571f2XdxC+XmQinN6L3qte9nZHKjjmQfPkOq/lV4 y53A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=qzxqZ3jSczYf6O71Ed0fvp90wDIzHIAUWvP5fMPMg+I=; b=JQWSLZ5Fb4FmhTCW+lSMkx41w8YadXbQtAiNTtQkZgCZCiIgJg5Q3eN5drxoK2jhra 1FvBUy7MOZ1xrbn9mbKc813K+8HvX7zRGjOZu066B3C4yoOMol60YBUHHSLv5iOHSJNI fRnlHOeNKISmJ0ByJMd2Sft1IC8n85K73BiBMuu0hcHt8rLqhRsD7UgKalBq7u32Nt/l 7boFVHwIZlENmEfPnwHrdofjWncb6OtRqPVPmtmkUXNS7ZV81uDvkXVEoDEay+dneHYu tmGytrviJBsSWjwSrbM9VajKI6fvGmdsPFL2bT2AIzGE7n4hmsB+dp57DpePxVGv+VvW tTFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="S3GGndG/"; 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 u13-20020a1709063b8d00b0094ee0ec0793si15071433ejf.1045.2023.04.28.02.49.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Apr 2023 02:49:31 -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="S3GGndG/"; 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 63E96385771A for ; Fri, 28 Apr 2023 09:49:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 63E96385771A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682675368; bh=qzxqZ3jSczYf6O71Ed0fvp90wDIzHIAUWvP5fMPMg+I=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=S3GGndG//clD3mDkgVpIL63L7+LQJaeTMwrZohjwK0Rr/QEbr+lbNUN4/RgrkJz52 kNDbhhbEQa//LjXf2zCIXoM4aMp+66afReL7YHUd/9M7RFyomMa9Ywh7rH5/XJJrgx hDGynhwFFdpBtxa9nDQVOy9y43vntn4tg8VeNQQc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 3DB233858C31 for ; Fri, 28 Apr 2023 09:48:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3DB233858C31 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 6695D20039 for ; Fri, 28 Apr 2023 09:48:35 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 51FBC2C153 for ; Fri, 28 Apr 2023 09:48:35 +0000 (UTC) Date: Fri, 28 Apr 2023 09:48:35 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/109644 - missing IL checking User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230428094928.63E96385771A@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764413009974639591?= X-GMAIL-MSGID: =?utf-8?q?1764413009974639591?= We fail to verify the constraints under which we allow handled components to wrap registers. The gcc.dg/pr70022.c testcase shows that we happily end up with _2 = VIEW_CONVERT_EXPR(v_1(D)) as produced by SSA rewrite and update_address_taken. But the intent was that we wrap registers with at most a single level of handled components and specifically only allow __real, __imag, BIT_FIELD_REF and VIEW_CONVERT_EXPR on them, but not ARRAY_REF or COMPONENT_REF. The following makes IL verification stricter which catches the problem. Bootstrapped and tested with all languages enabled on x86_64-unknown-linux-gnu with {,-m32}. Pushed. PR tree-optimization/109644 * tree-cfg.cc (verify_types_in_gimple_reference): Check register constraints on the outermost VIEW_CONVERT_EXPR only. Do not allow register or invariant bases on multi-level or possibly variable index handled components. --- gcc/tree-cfg.cc | 75 +++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index 5ef201adb25..4927fc0a8d9 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -3107,10 +3107,12 @@ verify_types_in_gimple_reference (tree expr, bool require_lvalue) if (TREE_CODE (expr) == REALPART_EXPR || TREE_CODE (expr) == IMAGPART_EXPR - || TREE_CODE (expr) == BIT_FIELD_REF) + || TREE_CODE (expr) == BIT_FIELD_REF + || TREE_CODE (expr) == VIEW_CONVERT_EXPR) { tree op = TREE_OPERAND (expr, 0); - if (!is_gimple_reg_type (TREE_TYPE (expr))) + if (TREE_CODE (expr) != VIEW_CONVERT_EXPR + && !is_gimple_reg_type (TREE_TYPE (expr))) { error ("non-scalar %qs", code_name); return true; @@ -3172,11 +3174,39 @@ verify_types_in_gimple_reference (tree expr, bool require_lvalue) debug_generic_stmt (TREE_TYPE (TREE_TYPE (op))); return true; } + + if (TREE_CODE (expr) == VIEW_CONVERT_EXPR) + { + /* For VIEW_CONVERT_EXPRs which are allowed here too, we only check + that their operand is not a register an invariant when + requiring an lvalue (this usually means there is a SRA or IPA-SRA + bug). Otherwise there is nothing to verify, gross mismatches at + most invoke undefined behavior. */ + if (require_lvalue + && (is_gimple_reg (op) || is_gimple_min_invariant (op))) + { + error ("conversion of %qs on the left hand side of %qs", + get_tree_code_name (TREE_CODE (op)), code_name); + debug_generic_stmt (expr); + return true; + } + else if (is_gimple_reg (op) + && TYPE_SIZE (TREE_TYPE (expr)) != TYPE_SIZE (TREE_TYPE (op))) + { + error ("conversion of register to a different size in %qs", + code_name); + debug_generic_stmt (expr); + return true; + } + } + expr = op; } + bool require_non_reg = false; while (handled_component_p (expr)) { + require_non_reg = true; code_name = get_tree_code_name (TREE_CODE (expr)); if (TREE_CODE (expr) == REALPART_EXPR @@ -3242,34 +3272,6 @@ verify_types_in_gimple_reference (tree expr, bool require_lvalue) } } - if (TREE_CODE (expr) == VIEW_CONVERT_EXPR) - { - /* For VIEW_CONVERT_EXPRs which are allowed here too, we only check - that their operand is not an SSA name or an invariant when - requiring an lvalue (this usually means there is a SRA or IPA-SRA - bug). Otherwise there is nothing to verify, gross mismatches at - most invoke undefined behavior. */ - if (require_lvalue - && (TREE_CODE (op) == SSA_NAME - || is_gimple_min_invariant (op))) - { - error ("conversion of %qs on the left hand side of %qs", - get_tree_code_name (TREE_CODE (op)), code_name); - debug_generic_stmt (expr); - return true; - } - else if (TREE_CODE (op) == SSA_NAME - && TYPE_SIZE (TREE_TYPE (expr)) != TYPE_SIZE (TREE_TYPE (op))) - { - error ("conversion of register to a different size in %qs", - code_name); - debug_generic_stmt (expr); - return true; - } - else if (!handled_component_p (op)) - return false; - } - expr = op; } @@ -3332,9 +3334,20 @@ verify_types_in_gimple_reference (tree expr, bool require_lvalue) debug_generic_stmt (expr); return true; } + else if (require_non_reg + && (is_gimple_reg (expr) + || (is_gimple_min_invariant (expr) + /* STRING_CSTs are representatives of the string table + entry which lives in memory. */ + && TREE_CODE (expr) != STRING_CST))) + { + error ("%qs as base where non-register is required", code_name); + debug_generic_stmt (expr); + return true; + } if (!require_lvalue - && (TREE_CODE (expr) == SSA_NAME || is_gimple_min_invariant (expr))) + && (is_gimple_reg (expr) || is_gimple_min_invariant (expr))) return false; if (TREE_CODE (expr) != SSA_NAME && is_gimple_id (expr))