From patchwork Wed Aug 31 13:19:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 867 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp227504wro; Wed, 31 Aug 2022 06:20:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR4c9WPxGJl9IutdNPE/SfwHWtH4k65aFdW8xFUqyaXeJYws3LmKTDKzZphoZBZRo1wdJ8LC X-Received: by 2002:aa7:d518:0:b0:448:788d:d293 with SMTP id y24-20020aa7d518000000b00448788dd293mr11782155edq.26.1661952036809; Wed, 31 Aug 2022 06:20:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661952036; cv=none; d=google.com; s=arc-20160816; b=I9lK6cvfihH0vmCApVgg5FvY2+EEU3QQzfGkeNsJORbA78LdTX/BfjwjbVzJKiDu6j auWEEHgcTzBYSPQeepwiRKkeDV55gOsqUuxuGpktgklN/KwnekowdZKkbaCKiV8TieKB f3sEkrWrwG3F3vw67koxAuRxVLRr32qecD/09GKzB1zcF0XopKEJoWcvsy4L8czAzUR+ xeFLqiE0aDYf3fjpvrZr6TC9yFWlH18r8L2To+MOcbLIYZn4MFUXETDwvwckaD1pW7Yk GTMEbg/AK9HcouTep0FmmDYA3TOSdcEKab4cwusUOOmVPoZCGdiftSvsKgYzsVdyM1sI a9eQ== 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=TLcem8idYz4rqC3vs81gt3oMNdAQmjQPjNQoUj89r+c=; b=CjnsCiVGN3j0iKlZDvFtsSpg5ppRKzvBqrk51H+Wp9ZR//sSXkpZv2UWCgfp3DibZa +9ZJgX+siiQQXj2HDxFLvLPwLOwxWda01OZ1bSt+DNzHr8i6SA+WE075Tk/8J3kmEtsH 4cLc5dUv98f8xFNw0OZVcwPJldhei5Jao3LkxTTSO1icK6UKUrTcTG6M7TxECnW5tszs H5GT01MzUw/hRUksuzfs9UaIonVfOXhWDIzJ5PBCUss5RBhwNt115BIsyLiQtF9m1q1a QuQg6yeqgGWmZYvJaZQMiseDNqWTn5+tzB65vEUtv6dZMFEUWR7Ay4hEN2gSVzLAAloo ltpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yVdnFdye; 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 v3-20020a056402348300b00447fc23b420si12022383edc.165.2022.08.31.06.20.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 06:20:36 -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=yVdnFdye; 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 9CB9D3838152 for ; Wed, 31 Aug 2022 13:20:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9CB9D3838152 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661952026; bh=TLcem8idYz4rqC3vs81gt3oMNdAQmjQPjNQoUj89r+c=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=yVdnFdyedbPHhBR5lEcSOZGWrgJyDZuhzEp4nOBQ4anI9W2A97MWEA9mrxmxHWxoR f7AAPS0Iz/qFGDPBlq9Y8q3c9jwX161vbBSFg0Nrz/lZZlVUWnbFOYxvVueAdXi+88 H0dK1Sm93V2wQuhR/8u0Q67ojdLNus7Nul9MSCEg= 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.220.28]) by sourceware.org (Postfix) with ESMTPS id A1B8C383E058 for ; Wed, 31 Aug 2022 13:19:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A1B8C383E058 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 738B822197 for ; Wed, 31 Aug 2022 13:19:42 +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 6D7CC2C141 for ; Wed, 31 Aug 2022 13:19:42 +0000 (UTC) Date: Wed, 31 Aug 2022 13:19:42 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/90994 - fix uninit diagnostics with EH 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: <20220831132026.9CB9D3838152@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742683018672997960?= X-GMAIL-MSGID: =?utf-8?q?1742683018672997960?= r12-3640-g94c12ffac234b2 sneaked in a hack to avoid the diagnostic for the testcase in PR90994 which sees non-call EH control flow confusing predicate analysis. The following patch instead adjusts the existing code handling EH to handle non-calls and do what I think was intented. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/90994 * gimple-predicate-analysis.cc (): Ignore exceptional control flow and skip the edge for the purpose of predicate generation also for non-calls. * g++.dg/torture/pr90994.C: New testcase. --- gcc/gimple-predicate-analysis.cc | 13 +++++---- gcc/testsuite/g++.dg/torture/pr90994.C | 40 ++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/torture/pr90994.C diff --git a/gcc/gimple-predicate-analysis.cc b/gcc/gimple-predicate-analysis.cc index 49500b77832..58eade433dc 100644 --- a/gcc/gimple-predicate-analysis.cc +++ b/gcc/gimple-predicate-analysis.cc @@ -41,6 +41,7 @@ #include "calls.h" #include "value-query.h" #include "cfganal.h" +#include "tree-eh.h" #include "gimple-predicate-analysis.h" @@ -1709,9 +1710,6 @@ predicate::init_from_control_deps (const vec *dep_chains, } /* Get the conditional controlling the bb exit edge. */ gimple *cond_stmt = gsi_stmt (gsi); - if (is_gimple_call (cond_stmt) && EDGE_COUNT (e->src->succs) >= 2) - /* Ignore EH edge. Can add assertion on the other edge's flag. */ - continue; /* Skip this edge if it is bypassing an abort - when the condition is not satisfied we are neither reaching the definition nor the use so it isn't meaningful. Note if @@ -1819,10 +1817,15 @@ predicate::init_from_control_deps (const vec *dep_chains, has_valid_pred = true; } } + else if (stmt_can_throw_internal (cfun, cond_stmt) + && !(e->flags & EDGE_EH)) + /* Ignore the exceptional control flow and proceed as if + E were a fallthru without a controlling predicate for + both the USE (valid) and DEF (questionable) case. */ + has_valid_pred = true; else { - /* Disabled. See PR 90994. - has_valid_pred = false; */ + has_valid_pred = false; break; } } diff --git a/gcc/testsuite/g++.dg/torture/pr90994.C b/gcc/testsuite/g++.dg/torture/pr90994.C new file mode 100644 index 00000000000..8feb36f2361 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr90994.C @@ -0,0 +1,40 @@ +// { dg-do compile } +// { dg-additional-options "-fnon-call-exceptions -Wuninitialized" } + +extern void printval(unsigned char v); + +inline int readbyte(unsigned char *__restrict presult, + unsigned char volatile *ptr) +{ + unsigned char v; + try { + v = *ptr; + } catch (...) { + return -1; + } + *presult = v; + return 0; +} + +int incorrectWarning(unsigned char volatile *ptr) +{ + int error; + unsigned char first; + unsigned char second; + + error = readbyte(&first, ptr); + asm("\n\n\n\n\n" : : "X" (error != 0)); + if (error != 0) + goto err; + + error = readbyte(&second, ptr); + if (error != 0) + goto err; + + printval(first); // { dg-bogus "uninitialized" } + printval(second); + return 0; + +err: + return error; +}