Hi! 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. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2020-03-26 Jakub Jelinek <ja...@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. --- gcc/tree.c.jj 2020-03-23 19:46:45.552448327 +0100 +++ gcc/tree.c 2020-03-25 17:22:12.438904778 +0100 @@ -5146,6 +5146,33 @@ protected_set_expr_location (tree 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. */ --- gcc/testsuite/g++.dg/debug/pr94323.C.jj 2020-03-25 17:17:49.857819078 +0100 +++ gcc/testsuite/g++.dg/debug/pr94323.C 2020-03-25 17:17:17.533300951 +0100 @@ -0,0 +1,13 @@ +// PR debug/94323 +// { dg-do compile } +// { dg-options "-O2 -fcompare-debug" } + +volatile int a; + +void +foo () +{ + ({ + a; + }); +} Jakub