Bug 70700 - ICE using -fdump-tree-all-graph option
Summary: ICE using -fdump-tree-all-graph option
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 6.0
: P3 trivial
Target Milestone: 7.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-17 06:25 UTC by Tom de Vries
Modified: 2016-05-02 07:49 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 7.0
Known to fail: 6.0
Last reconfirmed: 2016-04-17 00:00:00


Attachments
parse.i (35.10 KB, text/plain)
2016-04-17 06:27 UTC, Tom de Vries
Details
proposed patch (692 bytes, patch)
2016-05-01 06:15 UTC, Tom de Vries
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2016-04-17 06:25:01 UTC
Reported by t.w. lefering by email:
------------------------------------------------------------
Using GCC snapshot gcc-6-20160410.tar.bz2 and the
-fdump-tree-all-graph option to generate graph data
internal gcc error happens when compiling Linux sparse:

parse.c:1362:22: internal compiler error: in operator[], at vec.h:714

in tree-ssa-structalias.c line 1212 is build_pred_graph()

at line 1229 the get_varinfo() using vec.h routines hits the internal compiler error:

for (j = 1; j < FIRST_REF_NODE; j++)
{
  if (!get_varinfo (j)->is_special_var)
    bitmap_set_bit (graph->direct_nodes, j);
}

Looks like the variable j gets out-of-range then hit this assert in vec.h:714

in vec.h:

template<typename T, typename A>
inline T &
vec<T, A, vl_embed>::operator[] (unsigned ix)
{
  gcc_checking_assert (ix < m_vecpfx.m_num);
  return m_vecdata[ix];
}

And this is in the generated output:

parse.c: In function 'const_qualifier':
parse.c:1362:22: internal compiler error: in operator[], at vec.h:714
 static struct token *const_qualifier(struct token *next, struct decl_state *ctx)
                      ^~~~~~~~~~~~~~~
0xce89e7 vec<variable_info*, va_heap, vl_embed>::operator[](unsigned int)
	../.././gcc/vec.h:714
0xce89e7 vec<variable_info*, va_heap, vl_ptr>::operator[](unsigned int)
	../.././gcc/vec.h:1180
0xce89e7 get_varinfo
	../.././gcc/tree-ssa-structalias.c:333
0xcf7cd7 get_varinfo
	../.././gcc/vec.h:714
0xcf7cd7 build_pred_graph
	../.././gcc/tree-ssa-structalias.c:1231
0xcf7cd7 solve_constraints
	../.././gcc/tree-ssa-structalias.c:6961
0xcf9593 compute_points_to_sets
	../.././gcc/tree-ssa-structalias.c:7062
0xcf9593 compute_may_aliases()
	../.././gcc/tree-ssa-structalias.c:7389
0xa5afdc execute_function_todo
	../.././gcc/passes.c:1930
0xa5baab execute_todo
	../.././gcc/passes.c:2010
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
------------------------------------------------------------
Comment 1 Tom de Vries 2016-04-17 06:27:33 UTC
Created attachment 38294 [details]
parse.i
Comment 2 Tom de Vries 2016-04-17 06:28:47 UTC
Confirmed using:
... 
$ gcc -O3 parse.i -fdump-tree-all-graph
...
Comment 3 Marek Polacek 2016-04-20 14:09:22 UTC
Can't really bisect this one.  This particular ICE started with r215016, but with r215015 I see another ICE:

$ ./cc1.215015 -quiet ~/x.i -fdump-tree-all-graph -O3
parse.c: In function ‘type_is_ok.isra.0’:
parse.c:2837:1: internal compiler error: in get_loop_body, at cfgloop.c:835
0x772ce6 get_loop_body(loop const*)
	../../gcc/cfgloop.c:835
0x1361812 draw_cfg_nodes_for_loop
	../../gcc/graph.c:218
0x1361914 draw_cfg_nodes
	../../gcc/graph.c:242
0x1361a5c print_graph_cfg(char const*, function*)
	../../gcc/graph.c:287
0xaf3f9a execute_function_dump
	../../gcc/passes.c:1557
0xaf3c15 do_per_function
	../../gcc/passes.c:1478
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 4 Marek Polacek 2016-04-20 14:32:17 UTC
struct S
{
  long m;
};

struct S
fn1 (struct S *a)
{
  if (a->m)
    a->m |= 2;
  return *a;
}
Comment 5 Marek Polacek 2016-04-20 14:42:12 UTC
(gdb) p varmap.length()
$5 = 13
(gdb) p n
$6 = 21

so yeah - we're out-of-range.
Comment 6 Marek Polacek 2016-04-20 15:42:12 UTC
Could be just

--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -2241,7 +2241,11 @@ dump_pred_graph (struct scc_info *si, FILE *file)
       if (graph->points_to[i]
      && !bitmap_empty_p (graph->points_to[i]))
    {
-     fprintf (file, "[label=\"%s = {", get_varinfo (i)->name);
+     if (i < FIRST_REF_NODE)
+       fprintf (file, "[label=\"%s = {", get_varinfo (i)->name);
+     else
+       fprintf (file, "[label=\"*%s = {",
+            get_varinfo (i - FIRST_REF_NODE)->name);
      unsigned j;
      bitmap_iterator bi;
      EXECUTE_IF_SET_IN_BITMAP (graph->points_to[i], 0, j, bi)

but someone would need to check whether we still print a correct info with this.
Comment 7 Tom de Vries 2016-05-01 06:01:53 UTC
(In reply to Marek Polacek from comment #6)
> Could be just
> 
> --- a/gcc/tree-ssa-structalias.c
> +++ b/gcc/tree-ssa-structalias.c
> @@ -2241,7 +2241,11 @@ dump_pred_graph (struct scc_info *si, FILE *file)
>        if (graph->points_to[i]
>       && !bitmap_empty_p (graph->points_to[i]))
>     {
> -     fprintf (file, "[label=\"%s = {", get_varinfo (i)->name);
> +     if (i < FIRST_REF_NODE)
> +       fprintf (file, "[label=\"%s = {", get_varinfo (i)->name);
> +     else
> +       fprintf (file, "[label=\"*%s = {",
> +            get_varinfo (i - FIRST_REF_NODE)->name);
>       unsigned j;
>       bitmap_iterator bi;
>       EXECUTE_IF_SET_IN_BITMAP (graph->points_to[i], 0, j, bi)
> 
> but someone would need to check whether we still print a correct info with
> this.

I've build the compiler with the patch, compiled the example from comment 4, extracted the dot files using the script mentioned in PR70221 and generated pdf files from those. They look ok to me.

Also, the patch itself looks good to me.
Comment 8 Tom de Vries 2016-05-01 06:15:18 UTC
Created attachment 38386 [details]
proposed patch

Patch with testcase included. I'll put this through testing.
Comment 9 Richard Biener 2016-05-02 07:03:21 UTC
Yep, the patch looks ok and pre-approved.
Comment 10 Tom de Vries 2016-05-02 07:42:38 UTC
Author: vries
Date: Mon May  2 07:42:06 2016
New Revision: 235700

URL: https://gcc.gnu.org/viewcvs?rev=235700&root=gcc&view=rev
Log:
Fix ICE in dump_pred_graph

2016-05-02  Marek Polacek  <polacek@redhat.com>
	    Tom de Vries  <tom@codesourcery.com>

	PR tree-optimization/70700
	* tree-ssa-structalias.c (dump_pred_graph): Fix getting varinfo for ids
	bigger than FIRST_REF_NODE.

	* gcc.dg/pr70700.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr70700.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-structalias.c
Comment 11 Tom de Vries 2016-05-02 07:49:26 UTC
Patch with testcase committed, marking resolved-fixed.