From patchwork Sun Sep 24 13:06:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?J=C3=B8rgen_Kvalsvik?= X-Patchwork-Id: 144074 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp656169vqu; Sun, 24 Sep 2023 06:10:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZdDr8OyYsLeZJj6+9loidDdoqm6ofrx1XHxYYw8DCOEXwM7fwu8XzJx6eUz3tvHp2qr1o X-Received: by 2002:a17:907:2d94:b0:9ae:68bf:bec with SMTP id gt20-20020a1709072d9400b009ae68bf0becmr4670212ejc.75.1695561005244; Sun, 24 Sep 2023 06:10:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695561005; cv=none; d=google.com; s=arc-20160816; b=YnvOKfLRqXvvrfRixT1KQB21hdFo32RILrCBCLtC5BN7lwOV152q4ibKJOipHXfNQW JCQmUgkd2D/h3eKzUA+By1R98Q1dP7LY4T+Aw4eljGCVtWo9s7C3R+NHDFEoFfro7ZgP 2goDvbGHFrX9gaK+5b99LN0CuqOMlPFtWo0xYlu5irj+qQVSbPUu9KROAADOsacYtfqp hHoR+0W0pnoQaCK0xbR3ElKYB6B93TL/F+Yem5m+64w88kmgrFT7OnbtKUuF2j3UrCko SBcwFNrv4BZb21V/LYKniAL71iZdYgBh/XzhGizKIjX7MLdQMeRs65OaIMAEn9GpBOsT okcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=O50yC0CltcxxhaAONr4USWkvQ5lgs1EwuqOwbnz6UIA=; fh=qcCNa5IxmC1cU6N/mXsmIWchX0e96q2rQNudpfCbMtE=; b=KRams5kbrUdrl7P6FujkYBKE5qGDaxjFe5x59UBAyFa6EMjJcb+2KZRqA2kgVPPX6a 61hXjFh03czeyGmA2fvRwNcDiEBx3pBHCETrJoq+z/b8NGH39j8srmulfRx/AsSmvcGO E+vE3yBGIyn2RHYWMMD9AjTsAfg665o1oPFpq6ZqSq/UVOZJcoDIA4+5W9N78yinE9wf 7qF6v66XkiG91EcE9Z8/rem+GFSjFZ66vV1OsCqJ1FHM3+2P/5TwRug0N9Ct5Mbzi3/2 gEKkqjk/cmUi4aEd/i8TlaLtVY1q/wg6Cvik2jb6MQ9B6pMrRClAScFDgg0Z+6L7/Ug8 JrKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kolabnow.com header.s=dkim20160331 header.b=fzZxd+sN; 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" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id br11-20020a170906d14b00b0099bce4aa78dsi6738530ejb.865.2023.09.24.06.10.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:10:05 -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=@kolabnow.com header.s=dkim20160331 header.b=fzZxd+sN; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E4D3B385773F for ; Sun, 24 Sep 2023 13:09:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx.kolabnow.com (mx.kolabnow.com [212.103.80.155]) by sourceware.org (Postfix) with ESMTPS id 4B45C3858C66 for ; Sun, 24 Sep 2023 13:09:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B45C3858C66 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=lambda.is Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=lambda.is Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id 35CFD2096F1A for ; Sun, 24 Sep 2023 15:06:59 +0200 (CEST) Authentication-Results: ext-mx-out011.mykolab.com (amavis); dkim=pass (4096-bit key) reason="pass (just generated, assumed good)" header.d=kolabnow.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolabnow.com; h= content-transfer-encoding:content-type:content-type:mime-version :message-id:date:date:subject:subject:from:from:received :received:received; s=dkim20160331; t=1695560817; x=1697375218; bh=O50yC0CltcxxhaAONr4USWkvQ5lgs1EwuqOwbnz6UIA=; b=fzZxd+sNx4hy 8JMvCkYmUFKc1e+2stGh/VpLAqgNFYvsk7h3HIdSVbdOpcee+rA0YRCDstJ0JrcQ 6iKZvh4cebK9Hf263UjZxrm6Z+Skovp5I0bnIM+4TTc5135rn0E8rozHddjcUDOK 2HvYm8YRnI5jCiK92tYn1waxruSgu/rTNh8oq/t9jxFdDXKcvJu9ItmnntwkAbjB Ee010PjimVDx4HBnj8j1btzYKfK67kiQv7uCplqFVvBt8kglOB3j5QbKegfrWxS/ W/KCU3CFL+VjWrMlWyWWa+aLEcBA8me+2j9ozDwM6YKDfDpMJRLHUrNZUwFXTpXq K6SpuSwYaw9z6A6viUVrUJ1YYikVnQBM/MwKphyAGPwm7BmFh/AsbQUYcUzPhWYb bNsDgv/ldsG1p+Ej1CB/QNB8JMOk7bd5y8mSsVAZoYqXee/i1WKHTvKupPYOgTiK 5IfGR1dJH8wtUlsRXNZ1t/+H+n53M5VQ+yEqiGC3KYMVkEIQFrGA3Z47sV2u119u 5RfjbF2Hf3U22pe2+xvoPcxbxFUQ0fc+fjbPtIWpy0w28t/74LJY10+4aUxhdWs5 YbnjIxz44wCmyng7qJObs4IvbPfAeKgn+xT6YdzgtlrQ9pkFhsp1ZUK93gaKY703 ZGomV/Gfx0VRj+g9/wJwT0Fl8LymaM4= X-Virus-Scanned: amavis at mykolab.com X-Spam-Score: -0.999 X-Spam-Level: X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 Received: from mx.kolabnow.com ([127.0.0.1]) by localhost (ext-mx-out011.mykolab.com [127.0.0.1]) (amavis, port 10024) with ESMTP id ZxYgNQC5WB5M for ; Sun, 24 Sep 2023 15:06:57 +0200 (CEST) Received: from int-mx009.mykolab.com (unknown [10.9.13.9]) by mx.kolabnow.com (Postfix) with ESMTPS id BDDAF2096F07 for ; Sun, 24 Sep 2023 15:06:57 +0200 (CEST) Received: from ext-subm010.mykolab.com (unknown [10.9.6.10]) by int-mx009.mykolab.com (Postfix) with ESMTPS id 54A1C20D1498 for ; Sun, 24 Sep 2023 15:06:57 +0200 (CEST) From: =?utf-8?q?J=C3=B8rgen_Kvalsvik?= To: gcc-patches@gcc.gnu.org Cc: =?utf-8?q?J=C3=B8rgen_Kvalsvik?= Subject: [PATCH] Always generate else-block in gimplify Date: Sun, 24 Sep 2023 22:06:23 +0900 Message-Id: <20230924130623.2112322-1-j@lambda.is> MIME-Version: 1.0 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777924576946513694 X-GMAIL-MSGID: 1777924576946513694 This is a request for feedback and a proof-of-concept, not something I intend to merge as-is. It would be nice if gcc, maybe just under some circumstances, always generated an else-block for coverage purposes. I am working on the MC/DC support by CFG analysis for a while https://gcc.gnu.org/pipermail/gcc-patches/2023-June/621449.html and have ironed out a lot of problems. The last problem I know about, which is impossible to actually fix right now, is the "fusing" of nested ifs. Here is an example: if (a) if (b) if (c) { ... } // 3 conditions, 6 outcomes if (a && b && c) { ... } // 3 conditions, 6 outcomes These form isomorphic CFGs which means there is no way for my algorithm to distinguish them. This is sort-of acceptable since the coverage measurements more accurately measure the semantics (and not the syntax), but this also happens when there is code in-between the nesting: if (a) // measures to 2 conditions, 4 outcomes { a += b * 10; b -= a + 2; if (b) { ... } } You would expect this to be measured as: if (a) // 1 condition, 2 outcomes { a += b * 10; b -= a + 2; if (b) // 1 condition, 2 outcomes { ... } } The source of the problem is the missing (or empty) else block, as the algorithm uses the outcome (then/else) edges to determine the limits of expressions. If, however, the else blocks are generated, the conditions are counted as you would expect. So I have a few questions: 1. Is something like this even acceptable? The semantics of the program should not change, assuming the else-block only exists but is without significant behavior. It will only be generated if there is no explicit else in source. 2. Should this only be generated when necessary (e.g. under condition coverage? No optimization?) 3. I used a simple int-init { int __mcdc_barrier = 0; } but there might be better contents for the block that does not add anything operationally. I am not very familiar with this part of gcc and would like to see someting better. Any suggestions? --- gcc/gimplify.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index ade6e335da7..43af38df742 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -4370,6 +4370,14 @@ gimplify_cond_expr (tree *expr_p, gimple_seq *pre_p, fallback_t fallback) enum tree_code pred_code; gimple_seq seq = NULL; + if (TREE_OPERAND (expr, 2) == NULL_TREE) + { + tree var = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier + ("__mcdc_barrier"), integer_type_node); + tree val = build_int_cst (integer_type_node, 0); + TREE_OPERAND (expr, 2) = build2 (INIT_EXPR, TREE_TYPE (var), var, val); + } + /* If this COND_EXPR has a value, copy the values into a temporary within the arms. */ if (!VOID_TYPE_P (type))