diff options
| author | Jakub Jelinek <jakub@redhat.com> | 2020-04-04 09:16:07 +0200 |
|---|---|---|
| committer | Jakub Jelinek <jakub@redhat.com> | 2020-04-04 09:16:07 +0200 |
| commit | aae5d08a8d4dcee576a85ea76febe56c53675ef2 (patch) | |
| tree | 994c134f624ee1e684e02604cb4efa1d7080e7bd /gcc/tree.c | |
| parent | 78e276490953638f2e0694ea39dfa2818d6d2d7d (diff) | |
| download | gcc-aae5d08a8d4dcee576a85ea76febe56c53675ef2.zip gcc-aae5d08a8d4dcee576a85ea76febe56c53675ef2.tar.gz gcc-aae5d08a8d4dcee576a85ea76febe56c53675ef2.tar.bz2 | |
c++: Fix further protected_set_expr_location related -fcompare-debug issues [PR94441]
My recent protected_set_expr_location changes work well when
that function is called unconditionally, but as the testcase shows, the C++
FE has a few spots that do:
if (!EXPR_HAS_LOCATION (stmt))
protected_set_expr_location (stmt, locus);
or similar. Now, if we have for -g0 stmt of some expression that can
have location and has != UNKNOWN_LOCATION, while -g instead has
a STATEMENT_LIST containing some DEBUG_BEGIN_STMTs + that expression with
that location, we don't call protected_set_expr_location in the -g0 case,
but do call it in the -g case, because on the STATEMENT_LIST
!EXPR_HAS_LOCATION.
The following patch introduces a helper function which digs up the single
expression of a STATEMENT_LIST and uses that expression in the
EXPR_HAS_LOCATION check (plus changes protected_set_expr_location to
also use that helper).
Or do we want a further wrapper, perhaps C++ FE only, that would do this
protected_set_expr_location_if_unset (stmt, locus)?
2020-04-04 Jakub Jelinek <jakub@redhat.com>
PR debug/94441
* tree-iterator.h (expr_single): Declare.
* tree-iterator.c (expr_single): New function.
* tree.h (protected_set_expr_location_if_unset): Declare.
* tree.c (protected_set_expr_location): Use expr_single.
(protected_set_expr_location_if_unset): New function.
* parser.c (cp_parser_omp_for_loop): Use
protected_set_expr_location_if_unset.
* cp-gimplify.c (genericize_if_stmt, genericize_cp_loop): Likewise.
* g++.dg/opt/pr94441.C: New test.
Diffstat (limited to 'gcc/tree.c')
| -rw-r--r-- | gcc/tree.c | 38 |
1 files changed, 14 insertions, 24 deletions
@@ -5148,33 +5148,23 @@ protected_set_expr_location (tree t, location_t loc) 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); + t = expr_single (t); + if (t && CAN_HAVE_LOCATION_P (t)) + SET_EXPR_LOCATION (t, loc); } } +/* Like PROTECTED_SET_EXPR_LOCATION, but only do that if T has + UNKNOWN_LOCATION. */ + +void +protected_set_expr_location_if_unset (tree t, location_t loc) +{ + t = expr_single (t); + if (t && !EXPR_HAS_LOCATION (t)) + protected_set_expr_location (t, loc); +} + /* Data used when collecting DECLs and TYPEs for language data removal. */ class free_lang_data_d |
