[Bug debug/90574] [gdb] gdb wrongly stopped at a breakpoint in an unexecuted line of code

2019-06-11 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90574

Richard Biener  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #8 from Richard Biener  ---
Fixed.

[Bug debug/90574] [gdb] gdb wrongly stopped at a breakpoint in an unexecuted line of code

2019-06-07 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90574

--- Comment #7 from Richard Biener  ---
Author: rguenth
Date: Fri Jun  7 12:14:55 2019
New Revision: 272040

URL: https://gcc.gnu.org/viewcvs?rev=272040&root=gcc&view=rev
Log:
2019-06-07  Richard Biener  

PR debug/90574
* tree-cfg.c (stmt_starts_bb_p): Split blocks at labels
that appear after user labels.

* gcc.misc-tests/gcov-pr90574-1.c: New testcase.
* gcc.misc-tests/gcov-pr90574-2.c: Likewise.

Added:
trunk/gcc/testsuite/gcc.misc-tests/gcov-pr90574-1.c
trunk/gcc/testsuite/gcc.misc-tests/gcov-pr90574-2.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-cfg.c

[Bug debug/90574] [gdb] gdb wrongly stopped at a breakpoint in an unexecuted line of code

2019-06-06 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90574

--- Comment #6 from Martin Liška  ---
*** Bug 89673 has been marked as a duplicate of this bug. ***

[Bug debug/90574] [gdb] gdb wrongly stopped at a breakpoint in an unexecuted line of code

2019-06-06 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90574

--- Comment #5 from Martin Liška  ---
(In reply to Richard Biener from comment #4)
> Note these issues also appear as coverage errors:
> 
> -:0:Source:t.c
> -:0:Graph:t.gcno
> -:0:Data:t.gcda
> -:0:Runs:1
> -:0:Programs:1
> 1:1:int main(int argc, char **argv)
> -:2:{
> -:3:  if (argc == 0)
> -:4:{
> -:5:  int *ptr;
> 1:6:label:
> -:7:{
> -:8:}
> -:9:}
> 1:   10:  if (argc == 1)
> -:   11:{
> 1:   12:  __builtin_printf("hello\n");
> -:   13:}
> 1:   14:  return 0;
> -:   15:}

If you take a look at following list:
https://gcc.gnu.org/bugzilla/buglist.cgi?bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=SUSPENDED&bug_status=WAITING&bug_status=REOPENED&cf_known_to_fail_type=allwords&cf_known_to_work_type=allwords&email1=yangyibiao%40nju.edu.cn&emailreporter1=1&emailtype1=substring&list_id=239143&query_format=advanced

You'll find bazillion of similar test-cases where we optimize CFG before
gimplification happens.

[Bug debug/90574] [gdb] gdb wrongly stopped at a breakpoint in an unexecuted line of code

2019-06-06 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90574

Richard Biener  changed:

   What|Removed |Added

 CC||marxin at gcc dot gnu.org

--- Comment #4 from Richard Biener  ---
Note these issues also appear as coverage errors:

-:0:Source:t.c
-:0:Graph:t.gcno
-:0:Data:t.gcda
-:0:Runs:1
-:0:Programs:1
1:1:int main(int argc, char **argv)
-:2:{
-:3:  if (argc == 0)
-:4:{
-:5:  int *ptr;
1:6:label:
-:7:{
-:8:}
-:9:}
1:   10:  if (argc == 1)
-:   11:{
1:   12:  __builtin_printf("hello\n");
-:   13:}
1:   14:  return 0;
-:   15:}

[Bug debug/90574] [gdb] gdb wrongly stopped at a breakpoint in an unexecuted line of code

2019-06-06 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90574

--- Comment #3 from Richard Biener  ---
Related testcase:

int main(int argc, char **argv)
{
  switch (argc)
{
case 0:
  {
foo:;
  }
case 1:;
}
  return 0;
}

breaking on the foo: line stops.

Fixing this is a two-edged sword - we do try to build an optimized CFG
(esp. for case label merging), creating more blocks defeats this.
It might be possible to move cleanup_dead_labels after make_edges
so that we can split blocks again when we make edges - but for
switch stmts that would be quite expensive as well.

But to fix these issues building more blocks is a requirement.

The following does this:

Index: gcc/tree-cfg.c
===
--- gcc/tree-cfg.c  (revision 271990)
+++ gcc/tree-cfg.c  (working copy)
@@ -2722,10 +2722,10 @@ stmt_starts_bb_p (gimple *stmt, gimple *
  || FORCED_LABEL (gimple_label_label (label_stmt)))
return true;

-  if (prev_stmt && gimple_code (prev_stmt) == GIMPLE_LABEL)
+  if (glabel *plabel = safe_dyn_cast  (prev_stmt))
{
- if (DECL_NONLOCAL (gimple_label_label (
-  as_a  (prev_stmt
+ if (DECL_NONLOCAL (gimple_label_label (plabel))
+ || !DECL_ARTIFICIAL (gimple_label_label (plabel)))
return true;

  cfg_stats.num_merged_labels++;

it will ensure new BBs for consecutive user labels and artificial labels
following a user label assuming that is the target of a goto.

It prevents case merging for the above testcase during CFG build
when not optimizing CFG cleanup merges them though and in the correct
fasion, deleting the user label, when optimizing.

The debug experience is that gdb no longer stops at the line with the
label but setting a breakpoint on its line will stop at some other
line (that's a consumer issue I guess?).

[Bug debug/90574] [gdb] gdb wrongly stopped at a breakpoint in an unexecuted line of code

2019-05-23 Thread yangyibiao at nju dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90574

--- Comment #2 from Yibiao Yang  ---
(In reply to Richard Biener from comment #1)
> We somehow build a broken(?) CFG from the start:
> 
> ;;   basic block 2, loop depth 0
> ;;pred:   ENTRY
>   if (argc == 0)
> ;;succ:   3
> 
> ;;   basic block 3, loop depth 0
> ;;pred:   2
> label:
>   if (argc == 1)
> goto ; [INV]
>   else
> goto ; [INV]
> 
> see how BB2 only has a single outgoing edge.  CFG cleanup fixes this for us.
> 
> .gimple has
> 
>   [t.c:2:1] {
> void label = <<< error >>>;
> 
> [t.c:3:6] if (argc == 0) goto ; else goto ;
> :
> [t.c:4:5] {
>   int * ptr;
> 
>   [t.c:6:1] label:
> }
> :
> [t.c:10:6] if (argc == 1) goto ; else goto ;
> 
> so that looks good, likewise .lower:
> 
>   [t.c:3:6] if (argc == 0) goto ; else goto ;
>   :
>   [t.c:6:1] label:
>   :
>   [t.c:10:6] if (argc == 1) goto ; else goto ;
> 
> iff we'd elide an empty block as having no side-effects we would have
> deleted the label.
> 
> Thus confirmed as CFG build bug.

Thanks for the comfirmation. 
Another bug I reported seems also a valid bug with a different code structure.
I am not quite sure whether it is a valid or not. 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90584

[Bug debug/90574] [gdb] gdb wrongly stopped at a breakpoint in an unexecuted line of code

2019-05-23 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90574

Richard Biener  changed:

   What|Removed |Added

   Keywords||wrong-code, wrong-debug
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2019-05-23
 CC||rguenth at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #1 from Richard Biener  ---
We somehow build a broken(?) CFG from the start:

;;   basic block 2, loop depth 0
;;pred:   ENTRY
  if (argc == 0)
;;succ:   3

;;   basic block 3, loop depth 0
;;pred:   2
label:
  if (argc == 1)
goto ; [INV]
  else
goto ; [INV]

see how BB2 only has a single outgoing edge.  CFG cleanup fixes this for us.

.gimple has

  [t.c:2:1] {
void label = <<< error >>>;

[t.c:3:6] if (argc == 0) goto ; else goto ;
:
[t.c:4:5] {
  int * ptr;

  [t.c:6:1] label:
}
:
[t.c:10:6] if (argc == 1) goto ; else goto ;

so that looks good, likewise .lower:

  [t.c:3:6] if (argc == 0) goto ; else goto ;
  :
  [t.c:6:1] label:
  :
  [t.c:10:6] if (argc == 1) goto ; else goto ;

iff we'd elide an empty block as having no side-effects we would have
deleted the label.

Thus confirmed as CFG build bug.