Re: PR60147: fix ICE with DECL_NAMELIST and tree-pretty-printer.c

2014-02-27 Thread Richard Biener
On Thu, Feb 27, 2014 at 11:39 AM, Tobias Burnus
 wrote:
> On Thu, Feb 27, 2014 at 10:43:33AM +0100, Richard Biener wrote:
>
>> > hence, one ends up in the code I quote above. That code calls
>> >   print_declaration()
> ...
>> > Hence, TREE_TYPE() is void_type_node and dereferencing that one leads to 
>> > an ICE.
>
> Sorry, I misremembered. In any case, the following leads to an ICE.
>
> print_declaration has the code:
>   if (TREE_CODE (t) != FUNCTION_DECL)
>   if (DECL_INITIAL (t))
> ...
>   dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
> which handles the "CONSTRUCTOR" - which fails with:
> else if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
> as TREE_TYPE (node) == NULL.
>
>
>> Instead of the goto please duplicate the pp_semicolon and return.
>>
>> Ok with that change.  You probably still want to add the NAMELIST_DECL
>> case to dump_generic_node (to avoid the << Unknown tree: ...).
>
> Fine with me. I assume that that is only relevant for calls to debug_tree()
> in the debugger? Because otherwise, it shouldn't be reachable.

Yes.

> Thanks for the review!
>
> Tobias


Re: PR60147: fix ICE with DECL_NAMELIST and tree-pretty-printer.c

2014-02-27 Thread Tobias Burnus
On Thu, Feb 27, 2014 at 10:43:33AM +0100, Richard Biener wrote:

> > hence, one ends up in the code I quote above. That code calls
> >   print_declaration()
...
> > Hence, TREE_TYPE() is void_type_node and dereferencing that one leads to an 
> > ICE.

Sorry, I misremembered. In any case, the following leads to an ICE.

print_declaration has the code:
  if (TREE_CODE (t) != FUNCTION_DECL)
  if (DECL_INITIAL (t))
...
  dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
which handles the "CONSTRUCTOR" - which fails with:
else if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
as TREE_TYPE (node) == NULL.


> Instead of the goto please duplicate the pp_semicolon and return.
> 
> Ok with that change.  You probably still want to add the NAMELIST_DECL
> case to dump_generic_node (to avoid the << Unknown tree: ...).

Fine with me. I assume that that is only relevant for calls to debug_tree()
in the debugger? Because otherwise, it shouldn't be reachable.

Thanks for the review!

Tobias


Re: PR60147: fix ICE with DECL_NAMELIST and tree-pretty-printer.c

2014-02-27 Thread Richard Biener
On Thu, Feb 27, 2014 at 10:37 AM, Tobias Burnus
 wrote:
> Hi Richard, hi all,
>
> I wrote:
>> @@ -1713,21 +1733,24 @@ dump_generic_node (pretty_printer *buffer, tree 
>> node, int spc, int flags,
>> case BIND_EXPR:
> ...
>> for (op0 = BIND_EXPR_VARS (node); op0; op0 = DECL_CHAIN (op0))
>>   {
>>-print_declaration (buffer, op0, spc+2, flags);
>>+if (TREE_CODE(op0) == NAMELIST_DECL)
> ...
>
> Richard Biener wrote:
>> Works for me, but doesn't the simpler
>
>> --- tree-pretty-print.c (revision 208066)
>> +++ tree-pretty-print.c (working copy)
>> @@ -1390,6 +1390,7 @@
>> case FIELD_DECL:
>> case DEBUG_EXPR_DECL:
>> case NAMESPACE_DECL:
>>+case NAMELIST_DECL:
>>   dump_decl_name (buffer, node, flags);
>>   break;
>>
>> also work?  It's odd that we need to do sth special just for namelist-decls.
>
> It won't do - at least not like that. NAMELIST_DECL are stored in BIND_EXPR,
> hence, one ends up in the code I quote above. That code calls
>   print_declaration()
>
> NAMELIST_DECL are created as
>   decl = make_node (NAMELIST_DECL);
>   TREE_TYPE (decl) = void_type_node;
>   NAMELIST_DECL_ASSOCIATED_DECL (decl) = build_constructor (NULL_TREE, 
> nml_decls);
> Hence, TREE_TYPE() is void_type_node and dereferencing that one leads to an 
> ICE.

Where is it "dereferenced"?  void_type_node is a valid type.

>
> However, the following should work - do you like it more?
>
> Tobias
>
>
> --- a/gcc/tree-pretty-print.c
> +++ b/gcc/tree-pretty-print.c
> @@ -2686,6 +2686,13 @@ print_declaration (pretty_printer *buffer, tree t, int 
> spc, int flags)
>  {
>INDENT (spc);
>
> +  if (TREE_CODE(t) == NAMELIST_DECL)
> +{
> +   pp_string(buffer, "namelist ");
> +   dump_decl_name (buffer, t, flags);
> +   goto done;
> +}
> +
>if (TREE_CODE (t) == TYPE_DECL)
>  pp_string (buffer, "typedef ");
>
> @@ -2767,6 +2774,7 @@ print_declaration (pretty_printer *buffer, tree t, int 
> spc, int flags)
>pp_right_bracket (buffer);
>  }
>
> +done:
>pp_semicolon (buffer);

Instead of the goto please duplicate the pp_semicolon and return.

Ok with that change.  You probably still want to add the NAMELIST_DECL
case to dump_generic_node (to avoid the << Unknown tree: ...).

Thanks,
Richard.

>  }


Re: PR60147: fix ICE with DECL_NAMELIST and tree-pretty-printer.c

2014-02-27 Thread Tobias Burnus
Hi Richard, hi all,

I wrote:
> @@ -1713,21 +1733,24 @@ dump_generic_node (pretty_printer *buffer, tree node, 
> int spc, int flags,
> case BIND_EXPR:
...
> for (op0 = BIND_EXPR_VARS (node); op0; op0 = DECL_CHAIN (op0))
>   {
>-print_declaration (buffer, op0, spc+2, flags);
>+if (TREE_CODE(op0) == NAMELIST_DECL)
...

Richard Biener wrote:
> Works for me, but doesn't the simpler

> --- tree-pretty-print.c (revision 208066)
> +++ tree-pretty-print.c (working copy)
> @@ -1390,6 +1390,7 @@
> case FIELD_DECL:
> case DEBUG_EXPR_DECL:
> case NAMESPACE_DECL:
>+case NAMELIST_DECL:
>   dump_decl_name (buffer, node, flags);
>   break;
>
> also work?  It's odd that we need to do sth special just for namelist-decls.

It won't do - at least not like that. NAMELIST_DECL are stored in BIND_EXPR,
hence, one ends up in the code I quote above. That code calls
  print_declaration()

NAMELIST_DECL are created as
  decl = make_node (NAMELIST_DECL);
  TREE_TYPE (decl) = void_type_node;
  NAMELIST_DECL_ASSOCIATED_DECL (decl) = build_constructor (NULL_TREE, 
nml_decls);
Hence, TREE_TYPE() is void_type_node and dereferencing that one leads to an ICE.


However, the following should work - do you like it more?

Tobias


--- a/gcc/tree-pretty-print.c
+++ b/gcc/tree-pretty-print.c
@@ -2686,6 +2686,13 @@ print_declaration (pretty_printer *buffer, tree t, int 
spc, int flags)
 {
   INDENT (spc);

+  if (TREE_CODE(t) == NAMELIST_DECL)
+{
+   pp_string(buffer, "namelist ");
+   dump_decl_name (buffer, t, flags);
+   goto done;
+}
+
   if (TREE_CODE (t) == TYPE_DECL)
 pp_string (buffer, "typedef ");

@@ -2767,6 +2774,7 @@ print_declaration (pretty_printer *buffer, tree t, int 
spc, int flags)
   pp_right_bracket (buffer);
 }

+done:
   pp_semicolon (buffer);
 }


Re: PR60147: fix ICE with DECL_NAMELIST and tree-pretty-printer.c

2014-02-27 Thread Richard Biener
On Wed, Feb 26, 2014 at 11:19 PM, Tobias Burnus  wrote:
> Dear all,
>
> as suggested by Richard, it now only prints the namelist name and no longer
> the variables of the namelist.
>
> Bootstrapped on x86-64-gnu-linux and currently regtesting.
> OK for the trunk when it succeeds?

Works for me, but doesn't the simpler

Index: tree-pretty-print.c
===
--- tree-pretty-print.c (revision 208066)
+++ tree-pretty-print.c (working copy)
@@ -1390,6 +1390,7 @@
 case FIELD_DECL:
 case DEBUG_EXPR_DECL:
 case NAMESPACE_DECL:
+case NAMELIST_DECL:
   dump_decl_name (buffer, node, flags);
   break;

also work?  It's odd that we need to do sth special just for namelist-decls.

Richard.

> Tobias
>
>
> On February 22, 2014 10:00, Tobias Burnus wrote:
>>
>> Since GCC 4.9, gfortran generates a DECL_NAMELIST (for DWARF's
>> DW_TAG_namelist) - they are stored in the BIND_EXPR. Namelists are a bit
>> boring: They only group variable names and the namelist name is only used in
>> I/O statements (READ, WRITE) to permit a fancy data input [and output] - and
>> for the debugger.
>>
>> Due to DW_TAG_namelist, namelists are now exposed to the middle end - and
>> I forgot to handle them also in the tree pretty printer - hence
>> -fdump-tree-original now ICEs.
>>
>> For the pretty printer one has two options: Ignoring (or "NYI;") the decl
>> or dumping it. The attached patch does the latter.
>>
>> Bootstrapped (C/C++/Fortran) and regtested on x86-64-gnu-linux.
>> OK for the trunk?
>>
>> Tobias


Re: PR60147: fix ICE with DECL_NAMELIST and tree-pretty-printer.c

2014-02-26 Thread Tobias Burnus

Dear all,

as suggested by Richard, it now only prints the namelist name and no 
longer the variables of the namelist.


Bootstrapped on x86-64-gnu-linux and currently regtesting.
OK for the trunk when it succeeds?

Tobias

On February 22, 2014 10:00, Tobias Burnus wrote:
Since GCC 4.9, gfortran generates a DECL_NAMELIST (for DWARF's 
DW_TAG_namelist) - they are stored in the BIND_EXPR. Namelists are a 
bit boring: They only group variable names and the namelist name is 
only used in I/O statements (READ, WRITE) to permit a fancy data input 
[and output] - and for the debugger.


Due to DW_TAG_namelist, namelists are now exposed to the middle end - 
and I forgot to handle them also in the tree pretty printer - hence 
-fdump-tree-original now ICEs.


For the pretty printer one has two options: Ignoring (or "NYI;") the 
decl or dumping it. The attached patch does the latter.


Bootstrapped (C/C++/Fortran) and regtested on x86-64-gnu-linux.
OK for the trunk?

Tobias
2014-02-26  Tobias Burnus  

	PR middle-end/60147
	* tree-pretty-print.c (dump_generic_node): Handle
	NAMELIST_DECL.

diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c
index 0595499..0d46a1c 100644
--- a/gcc/tree-pretty-print.c
+++ b/gcc/tree-pretty-print.c
@@ -1720,7 +1720,16 @@ dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
 
 	  for (op0 = BIND_EXPR_VARS (node); op0; op0 = DECL_CHAIN (op0))
 		{
-		  print_declaration (buffer, op0, spc+2, flags);
+		  if (TREE_CODE(op0) == NAMELIST_DECL)
+		{
+		  INDENT (spc+2);
+		  pp_string (buffer, "namelist /");
+		  dump_decl_name (buffer, op0, flags);
+		  pp_string (buffer, "/");
+		  pp_semicolon (buffer);
+		}
+		  else
+		print_declaration (buffer, op0, spc+2, flags);
 		  pp_newline (buffer);
 		}
 	}


PR60147: fix ICE with DECL_NAMELIST and tree-pretty-printer.c

2014-02-22 Thread Tobias Burnus
Since GCC 4.9, gfortran generates a DECL_NAMELIST (for DWARF's 
DW_TAG_namelist) - they are stored in the BIND_EXPR. Namelists are a bit 
boring: They only group variable names and the namelist name is only 
used in I/O statements (READ, WRITE) to permit a fancy data input [and 
output] - and for the debugger.


Due to DW_TAG_namelist, namelists are now exposed to the middle end - 
and I forgot to handle them also in the tree pretty printer - hence 
-fdump-tree-original now ICEs.


For the pretty printer one has two options: Ignoring (or "NYI;") the 
decl or dumping it. The attached patch does the latter.


Bootstrapped (C/C++/Fortran) and regtested on x86-64-gnu-linux.
OK for the trunk?

Tobias
2014-02-22  Tobias Burnus  

	PR middle-end/60147
	* tree-pretty-print.c (dump_generic_node): Handle
	NAMELIST_DECL.

diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c
index 0595499..80c59a6 100644
--- a/gcc/tree-pretty-print.c
+++ b/gcc/tree-pretty-print.c
@@ -1386,20 +1386,40 @@ dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
   break;
 
 case VAR_DECL:
 case PARM_DECL:
 case FIELD_DECL:
 case DEBUG_EXPR_DECL:
 case NAMESPACE_DECL:
   dump_decl_name (buffer, node, flags);
   break;
 
+case NAMELIST_DECL:
+  {
+	unsigned i;
+	tree value;
+INDENT (spc);
+	pp_string (buffer, "namelist /");
+	dump_decl_name (buffer, node, flags);
+	pp_string (buffer, "/ ");
+	op0 = NAMELIST_DECL_ASSOCIATED_DECL(node);
+	FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (op0), i, value)
+	  {
+	if (i != 0)
+	  pp_string (buffer, ", ");
+	if (value)
+	  dump_decl_name (buffer, value, flags);
+	  }
+	pp_semicolon (buffer);
+	break;
+  }
+
 case RESULT_DECL:
   pp_string (buffer, "");
   break;
 
 case COMPONENT_REF:
   op0 = TREE_OPERAND (node, 0);
   str = ".";
   if (op0
 	  && (TREE_CODE (op0) == INDIRECT_REF
 	  || (TREE_CODE (op0) == MEM_REF
@@ -1713,21 +1733,24 @@ dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
 case BIND_EXPR:
   pp_left_brace (buffer);
   if (!(flags & TDF_SLIM))
 	{
 	  if (BIND_EXPR_VARS (node))
 	{
 	  pp_newline (buffer);
 
 	  for (op0 = BIND_EXPR_VARS (node); op0; op0 = DECL_CHAIN (op0))
 		{
-		  print_declaration (buffer, op0, spc+2, flags);
+		  if (TREE_CODE(op0) == NAMELIST_DECL)
+		dump_generic_node (buffer, op0, spc+2, flags, false);
+		  else
+		print_declaration (buffer, op0, spc+2, flags);
 		  pp_newline (buffer);
 		}
 	}
 
 	  newline_and_indent (buffer, spc+2);
 	  dump_generic_node (buffer, BIND_EXPR_BODY (node), spc+2, flags, true);
 	  newline_and_indent (buffer, spc);
 	  pp_right_brace (buffer);
 	}
   is_expr = false;