From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx.kolabnow.com (mx.kolabnow.com [212.103.80.155]) by sourceware.org (Postfix) with ESMTPS id 257CD384641E for ; Fri, 5 Apr 2024 19:58:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 257CD384641E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=lambda.is Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=lambda.is ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 257CD384641E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.103.80.155 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712347142; cv=none; b=I3QrXFR996yLSOpO0S4pYRc/lRSCZLQDwHPBg2emF7FTKWaFZ9t+GSNWmEWGBmaRHFaRSFSV7MrDtZtsluSQ5wn/ANTf517kIiPSrX6DkVNt+QlCbdsgWdswuPpFlaaEkDZvEER1m9jtJA8WGgVLirqUoKjFNq7FoIuXB/ulTCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712347142; c=relaxed/simple; bh=YVYT+wlhm/7OWYvuMHuxUMykiLInaTkNBxQ1WW2Bojo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=I6Suk25S6NXu/K1/BfPUUgOUWylC87YVfWpWn+28I1eG9gUUMAfe3fxp3nlxGmV41hjbp0AWZUC8wJS0eAFqRICamr+sEgUvjwDXr1hTlRmccTMgyGVHRuIDTVBxcaPNJURzPCqNAnMDMbDB+kp9b4DV+qbR4l3yBa/N5BSgtaw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id 4CDAB2096DD0; Fri, 5 Apr 2024 21:58:58 +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:mime-version:references:in-reply-to :message-id:date:date:subject:subject:from:from:received :received:received; s=dkim20160331; t=1712347137; x=1714161538; bh=s4zd8Nmwy3nJlZkyUDxdUNq+zvBoBEtHF1k17rhArbk=; b=XiOn/+yGg2pK oA4VqvTP+JnrQsZuoEh6PqyAU6PLfFcq3vzHty1tj8Oq5q41n22i+zZ6guxZbQgq h21n7yPlEl1WpAwpE7PX5sY2y63wxMKTwe5/QQVw1cyCOeE6ZRqU5dFy4TwYHz3o qzR0wiM2TVVOHfLfQ/3f0el6AdiTkjqNRevrT+NSggtEPJCNaD+1tjTYeQuxb+02 Vka54TXlbyBW1FQasAjWRDHp006XIa2kDFJdbAqEtHw4F4hrB4hJjXoQj0/zcbDI ClPgR33NtBK5HswLD11/FeKVTOxkzwj4hFC+4p/gosgUjTYMyZP8CtUCK9mwvBPz QBx9zZnOphPktWD3MVEaOFLGgbFbzThycb0uDZHfMB0PNQa1QzC2HJ8GbobsywPv 9fqXxoVJfu6fro7O/BvZOE6NLyZ4TpvALxyz87gtTFoLSMkmwU43P1S0t0xMMuj+ aE8/OmDDW4jSncSx07sS6zW+ehq+1fN7RqAfO4J0BrlaEBYni9dvSqdM5BP6jmzJ JS6Cpb3uY11EfTImDmUEXQxM3bvMlB9xeHFcHDJWG03OFSPTuu+TBj5HUMC4ns2a syxJ99gmWs0t4/ZGCXaDWOAQHAk/9tGcfbgCWmYFhdJutgJNaVU7IOG11nH+ch4f +s8VzIYLS3mQWHpVg0bSIQhMQ0xf1fE= X-Virus-Scanned: amavis at mykolab.com X-Spam-Score: -0.999 X-Spam-Level: X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,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 vggHu3rxf9VS; Fri, 5 Apr 2024 21:58:57 +0200 (CEST) Received: from int-mx009.mykolab.com (unknown [10.9.13.9]) by mx.kolabnow.com (Postfix) with ESMTPS id 51EFC2096DC2; Fri, 5 Apr 2024 21:58:57 +0200 (CEST) Received: from ext-subm010.mykolab.com (unknown [10.9.6.10]) by int-mx009.mykolab.com (Postfix) with ESMTPS id 0ABFB20E33D5; Fri, 5 Apr 2024 21:58:57 +0200 (CEST) From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= To: gcc-patches@gcc.gnu.org Cc: hjl.tools@gmail.com, rguenther@suse.de, hubicka@ucw.cz, ro@CeBiTec.Uni-Bielefeld.DE, =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= Subject: [PATCH 2/2] Copy condition->expr map when inlining [PR114599] Date: Fri, 5 Apr 2024 21:58:31 +0200 Message-Id: <20240405195831.2728853-3-j@lambda.is> In-Reply-To: <20240405195831.2728853-1-j@lambda.is> References: <20240405195831.2728853-1-j@lambda.is> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: When a function is tree-inlined, copy the condition -> expression mapping from the inlined function into the caller, shifted so uids are not mixed Tree inlining was always problematic under condition coverage - either through a nullptr dereference (like in the test case), or through quietly mixing conditions when the assigned IDs overlapped. PR middle-end/114599 gcc/ChangeLog: * tree-inline.cc (add_local_variables): Copy cond_uids mappings. gcc/testsuite/ChangeLog: * gcc.misc-tests/gcov-pr114599.c: New test. --- gcc/testsuite/gcc.misc-tests/gcov-pr114599.c | 25 ++++++++++++++++++++ gcc/tree-inline.cc | 20 +++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.misc-tests/gcov-pr114599.c diff --git a/gcc/testsuite/gcc.misc-tests/gcov-pr114599.c b/gcc/testsuite/gcc.misc-tests/gcov-pr114599.c new file mode 100644 index 00000000000..e4c78c9c121 --- /dev/null +++ b/gcc/testsuite/gcc.misc-tests/gcov-pr114599.c @@ -0,0 +1,25 @@ +/* PR middle-end/114599 */ +/* { dg-do compile } */ +/* { dg-options "-fcondition-coverage" } */ + +/* Check that a function with a condition inlined into a function without a + conditional works. When inlining happens the condition -> expression + mapping must be carried over. */ + +extern int type; + +void fn (void); + +__attribute__((always_inline)) +inline void +do_all_fn_doall_arg (void) +{ + if (type) + fn (); +} + +void +do_all_fn_LHASH_DOALL_ARG_arg2 (void) +{ + do_all_fn_doall_arg (); +} diff --git a/gcc/tree-inline.cc b/gcc/tree-inline.cc index eebcea8a029..b18917707cc 100644 --- a/gcc/tree-inline.cc +++ b/gcc/tree-inline.cc @@ -4659,7 +4659,8 @@ prepend_lexical_block (tree current_block, tree new_block) BLOCK_SUPERCONTEXT (new_block) = current_block; } -/* Add local variables from CALLEE to CALLER. */ +/* Add local variables from CALLEE to CALLER. If set for condition coverage, + copy basic condition -> expression mapping to CALLER. */ static inline void add_local_variables (struct function *callee, struct function *caller, @@ -4689,6 +4690,23 @@ add_local_variables (struct function *callee, struct function *caller, } add_local_decl (caller, new_var); } + + /* If -fcondition-coverage is used and the caller has conditions, copy the + mapping into the caller but and the end so the caller and callee + expressions aren't mixed. */ + if (callee->cond_uids) + { + if (!caller->cond_uids) + caller->cond_uids = new hash_map (); + + unsigned dst_max_uid = 0; + for (auto itr : *callee->cond_uids) + if (itr.second >= dst_max_uid) + dst_max_uid = itr.second + 1; + + for (auto itr : *callee->cond_uids) + caller->cond_uids->put (itr.first, itr.second + dst_max_uid); + } } /* Add to BINDINGS a debug stmt resetting SRCVAR if inlining might -- 2.30.2