c++: Fix further protected_set_expr_location related -fcompare-debug issues [PR94441]
authorJakub Jelinek <jakub@redhat.com>
Sat, 4 Apr 2020 07:16:07 +0000 (09:16 +0200)
committerJakub Jelinek <jakub@redhat.com>
Sat, 4 Apr 2020 07:16:07 +0000 (09:16 +0200)
commitaae5d08a8d4dcee576a85ea76febe56c53675ef2
tree994c134f624ee1e684e02604cb4efa1d7080e7bd
parent78e276490953638f2e0694ea39dfa2818d6d2d7d
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.
gcc/ChangeLog
gcc/cp/ChangeLog
gcc/cp/cp-gimplify.c
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr94441.C [new file with mode: 0644]
gcc/tree-iterator.c
gcc/tree-iterator.h
gcc/tree.c
gcc/tree.h