From 98a409be9db44905867242eb583eb31367bfcf94 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 15 Dec 2017 22:53:29 +0100 Subject: [PATCH] backport: re PR debug/83084 (-fcompare-debug failure on ppc64le) Backported from mainline 2017-11-22 Jakub Jelinek PR debug/83084 * valtrack.c (propagate_for_debug_subst, propagate_for_debug): Reset debug insns if they would contain UNSPEC_VOLATILE or volatile asm. (dead_debug_insert_temp): Likewise, but also ignore even non-volatile asm. * g++.dg/opt/pr83084.C: New test. From-SVN: r255710 --- gcc/ChangeLog | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/opt/pr83084.C | 16 ++++++++++++++++ gcc/valtrack.c | 13 ++++++++++++- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/opt/pr83084.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 46251a06aa7..049f127608c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,14 @@ 2017-12-15 Jakub Jelinek Backported from mainline + 2017-11-22 Jakub Jelinek + + PR debug/83084 + * valtrack.c (propagate_for_debug_subst, propagate_for_debug): Reset + debug insns if they would contain UNSPEC_VOLATILE or volatile asm. + (dead_debug_insert_temp): Likewise, but also ignore even non-volatile + asm. + 2017-11-21 James Cowgill Jakub Jelinek diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d2671b73a7c..db3040d6e08 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,11 @@ 2017-12-15 Jakub Jelinek Backported from mainline + 2017-11-22 Jakub Jelinek + + PR debug/83084 + * g++.dg/opt/pr83084.C: New test. + 2017-11-21 Jakub Jelinek PR target/82880 diff --git a/gcc/testsuite/g++.dg/opt/pr83084.C b/gcc/testsuite/g++.dg/opt/pr83084.C new file mode 100644 index 00000000000..d21e30878ec --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr83084.C @@ -0,0 +1,16 @@ +// PR debug/83084 +// { dg-do compile } +// { dg-options "-O2 -fcompare-debug -Wno-return-type" } + +enum E { F }; +template struct A { + bool foo (); + int b; +}; +template <> bool A<>::foo () { + int a; + do + if (a) + return false; + while (__atomic_compare_exchange_n (&b, &a, 0, 1, 4, 0)); +} diff --git a/gcc/valtrack.c b/gcc/valtrack.c index 9e28d4b4f57..9dcf135e167 100644 --- a/gcc/valtrack.c +++ b/gcc/valtrack.c @@ -171,10 +171,13 @@ propagate_for_debug_subst (rtx from, const_rtx old_rtx, void *data) if (REG_P (*iter) && ++cnt > 1) { rtx dval = make_debug_expr_from_rtl (old_rtx); + rtx to = pair->to; + if (volatile_insn_p (to)) + to = gen_rtx_UNKNOWN_VAR_LOC (); /* Emit a debug bind insn. */ rtx bind = gen_rtx_VAR_LOCATION (GET_MODE (old_rtx), - DEBUG_EXPR_TREE_DECL (dval), pair->to, + DEBUG_EXPR_TREE_DECL (dval), to, VAR_INIT_STATUS_INITIALIZED); rtx_insn *bind_insn = emit_debug_insn_before (bind, pair->insn); df_insn_rescan (bind_insn); @@ -217,6 +220,8 @@ propagate_for_debug (rtx_insn *insn, rtx_insn *last, rtx dest, rtx src, dest, propagate_for_debug_subst, &p); if (loc == INSN_VAR_LOCATION_LOC (insn)) continue; + if (volatile_insn_p (loc)) + loc = gen_rtx_UNKNOWN_VAR_LOC (); INSN_VAR_LOCATION_LOC (insn) = loc; df_insn_rescan (insn); } @@ -660,6 +665,12 @@ dead_debug_insert_temp (struct dead_debug_local *debug, unsigned int uregno, } return 0; } + /* Asm in DEBUG_INSN is never useful, we can't emit debug info for + that. And for volatile_insn_p, it is actually harmful + - DEBUG_INSNs shouldn't have any side-effects. */ + else if (GET_CODE (src) == ASM_OPERANDS + || volatile_insn_p (src)) + set = NULL_RTX; } /* ??? Should we try to extract it from a PARALLEL? */