From patchwork Fri Jan 14 18:20:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 50048 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 621DF3850429 for ; Fri, 14 Jan 2022 18:24:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 621DF3850429 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1642184675; bh=qEPCxTR4YxG/9HFfiGcGSSuNWUcvU58bWQ9WqXCbGdI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=P8Neo/Fct3SFDQKSZCUle+izbAZ8VkAJT09mQt9XtkA5+U2++ZqI3I4dCBPfTcAr+ hAcx8mY8LmQGXwQ7KLbeoJJ74N8+31WtSndSyms84KXFgSRzdTKZy3FzbcD8iOF1jG TcO+otEWhhiu4LZhqR5cWrX38H6fOgJW8UiiKRKU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id EEAA23836015 for ; Fri, 14 Jan 2022 18:21:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EEAA23836015 Received: from localhost.intra.ispras.ru (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTP id D88C240D403D; Fri, 14 Jan 2022 18:21:24 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH 3/3] tree-cfg: check placement of returns_twice calls Date: Fri, 14 Jan 2022 21:20:47 +0300 Message-Id: <20220114182047.6270-4-amonakov@ispras.ru> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Alexander Monakov via Gcc-patches From: Alexander Monakov Reply-To: Alexander Monakov Cc: Alexander Monakov Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" When a returns_twice call has an associated abnormal edge, the edge corresponds to the "second return" from the call. It wouldn't make sense if any executable statements appeared between the call and the destination of the edge (they wouldn't be re-executed upon the "second return"), so verify that. gcc/ChangeLog: * tree-cfg.c (gimple_verify_flow_info): Check placement of returns_twice calls. --- gcc/tree-cfg.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index a99f1acb4..70bd31d3d 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -5644,6 +5644,7 @@ gimple_verify_flow_info (void) } /* Verify that body of basic block BB is free of control flow. */ + bool seen_nondebug_stmt = false; for (; !gsi_end_p (gsi); gsi_next (&gsi)) { gimple *stmt = gsi_stmt (gsi); @@ -5664,6 +5665,38 @@ gimple_verify_flow_info (void) gimple_label_label (label_stmt), bb->index); err = 1; } + + /* Check that no statements appear between a returns_twice call + and its associated abnormal edge. */ + if (gimple_code (stmt) == GIMPLE_CALL + && gimple_call_flags (stmt) & ECF_RETURNS_TWICE) + { + const char *misplaced = NULL; + /* TM is an exception: it points abnormal edges just after the + call that starts a transaction, i.e. it must end the BB. */ + if (gimple_call_builtin_p (stmt, BUILT_IN_TM_START)) + { + if (single_succ_p (bb) + && bb_has_abnormal_pred (single_succ (bb)) + && !gsi_one_nondebug_before_end_p (gsi)) + misplaced = "not last"; + } + else + { + if (seen_nondebug_stmt + && bb_has_abnormal_pred (bb)) + misplaced = "not first"; + } + if (misplaced) + { + error ("returns_twice call is %s in basic block %d", + misplaced, bb->index); + print_gimple_stmt (stderr, stmt, 0, TDF_SLIM); + err = 1; + } + } + if (!is_gimple_debug (stmt)) + seen_nondebug_stmt = true; } gsi = gsi_last_nondebug_bb (bb);