aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-03-26 10:35:52 +0100
committerJakub Jelinek <jakub@redhat.com>2020-03-26 10:35:52 +0100
commitda920d0c46c38fe25ee0b597a8698d3a4d098f3c (patch)
treebd1bd9d225cc9a416eb2df6b4c01883d97207e63 /gcc/tree.c
parentd6730f06420106af01e26414f046626b5292565d (diff)
downloadgcc-da920d0c46c38fe25ee0b597a8698d3a4d098f3c.zip
gcc-da920d0c46c38fe25ee0b597a8698d3a4d098f3c.tar.gz
gcc-da920d0c46c38fe25ee0b597a8698d3a4d098f3c.tar.bz2
tree: Fix -fcompare-debug issues due to protected_set_expr_location [PR94323]
The following testcase FAILs since recently when the C++ FE started calling protected_set_expr_location more often. With -g, it is called on a STATEMENT_LIST that contains a DEBUG_BEGIN_STMT and CLEANUP_POINT_EXPR, and as STATEMENT_LISTs have !CAN_HAVE_LOCATION_P, nothing is set. Without -g, it is called instead on the CLEANUP_POINT_EXPR directly and changes its location. The following patch recurses on the single non-DEBUG_BEGIN_STMT statement of a STATEMENT_LIST if any to make the two behave the same. 2020-03-26 Jakub Jelinek <jakub@redhat.com> PR debug/94323 * tree.c (protected_set_expr_location): Recurse on STATEMENT_LIST that contains exactly one non-DEBUG_BEGIN_STMT statement. * g++.dg/debug/pr94323.C: New test.
Diffstat (limited to 'gcc/tree.c')
-rw-r--r--gcc/tree.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/gcc/tree.c b/gcc/tree.c
index f38dfff..63dc673 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -5146,6 +5146,33 @@ protected_set_expr_location (tree t, location_t loc)
{
if (CAN_HAVE_LOCATION_P (t))
SET_EXPR_LOCATION (t, loc);
+ else if (t && TREE_CODE (t) == STATEMENT_LIST)
+ {
+ /* With -gstatement-frontiers we could have a STATEMENT_LIST with
+ DEBUG_BEGIN_STMT(s) and only a single other stmt, which with
+ -g wouldn't be present and we'd have that single other stmt
+ directly instead. */
+ struct tree_statement_list_node *n = STATEMENT_LIST_HEAD (t);
+ if (!n)
+ return;
+ while (TREE_CODE (n->stmt) == DEBUG_BEGIN_STMT)
+ {
+ n = n->next;
+ if (!n)
+ return;
+ }
+ tree t2 = n->stmt;
+ do
+ {
+ n = n->next;
+ if (!n)
+ {
+ protected_set_expr_location (t2, loc);
+ return;
+ }
+ }
+ while (TREE_CODE (n->stmt) == DEBUG_BEGIN_STMT);
+ }
}
/* Data used when collecting DECLs and TYPEs for language data removal. */