From: "Jørgen Kvalsvik" <j@lambda.is>
To: gcc-patches@gcc.gnu.org
Cc: hjl.tools@gmail.com, rguenther@suse.de, hubicka@ucw.cz,
ro@CeBiTec.Uni-Bielefeld.DE, "Jørgen Kvalsvik" <j@lambda.is>
Subject: [PATCH 2/2] Copy condition->expr map when inlining [PR114599]
Date: Fri, 5 Apr 2024 21:58:31 +0200 [thread overview]
Message-ID: <20240405195831.2728853-3-j@lambda.is> (raw)
In-Reply-To: <20240405195831.2728853-1-j@lambda.is>
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 <gcond*, unsigned> ();
+
+ 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
next prev parent reply other threads:[~2024-04-05 19:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-05 19:58 [PATCH 0/2] Condition coverage fixes Jørgen Kvalsvik
2024-04-05 19:58 ` [PATCH 1/2] Remove unecessary and broken MC/DC compile test Jørgen Kvalsvik
2024-04-15 8:56 ` Rainer Orth
2024-04-05 19:58 ` Jørgen Kvalsvik [this message]
2024-04-06 5:50 ` [PATCH 0/2] Condition coverage fixes Richard Biener
2024-04-06 11:15 ` Jørgen Kvalsvik
2024-04-06 20:41 ` Jørgen Kvalsvik
2024-04-07 6:26 ` Richard Biener
2024-04-07 7:28 ` Jørgen Kvalsvik
2024-04-08 6:31 ` Sam James
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240405195831.2728853-3-j@lambda.is \
--to=j@lambda.is \
--cc=gcc-patches@gcc.gnu.org \
--cc=hjl.tools@gmail.com \
--cc=hubicka@ucw.cz \
--cc=rguenther@suse.de \
--cc=ro@CeBiTec.Uni-Bielefeld.DE \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).