This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[lto] fix tree-nrv.c assertion failure


The patch below fixes an assert we were triggering in tree-nrv.c.  When
we are returning a value in memory, the gimplifier uses the DECL_RESULT
of the current function for single-argument RETURN_EXPRs.  tree-nrv.c
checked for this and failed because the LTO reader was not respecting
this during construction of the function body.

The problem could have been fixed by simply modifying the reader, but I
thought it might be better to modify the writer and the reader for
symmetry's sake and also to make the reader ever so slightly more
efficient.

Committed to the LTO branch.

-Nathan

gcc/
	* lto-function-out.c (output_expr_operand): Change the
	single-argument RETURN_EXPR case to check whether we are writing
	out DECL_RESULT.

gcc/lto/
	* lto-read.c (input_expr_operand): Change the LTO_return_expr1
	case to use DECL_RESULT if necessary.

Index: gcc/lto-function-out.c
===================================================================
--- gcc/lto-function-out.c	(revision 129836)
+++ gcc/lto-function-out.c	(working copy)
@@ -1527,7 +1527,15 @@ output_expr_operand (struct output_block
 	    /* Form return a; */
 	    output_record_start (ob, expr, expr,
 				 LTO_return_expr1);
-	    output_expr_operand (ob, t);
+            /* If the type of the argument is a type that gets returned
+               in memory, then the gimplifier would have changed the
+               argument of the RETURN_EXPR to point at DECL_RESULT of
+               the current function.  Communicate this fact to the
+               reader so we avoid reading in superfluous trees.  */
+            if (t == DECL_RESULT (current_function_decl))
+              output_zero (ob);
+            else
+              output_expr_operand (ob, t);
 	  }
       }
       break;
Index: gcc/lto/lto-read.c
===================================================================
--- gcc/lto/lto-read.c	(revision 129836)
+++ gcc/lto/lto-read.c	(working copy)
@@ -934,9 +934,17 @@ input_expr_operand (struct input_block *
 	  break;
 	  
 	case LTO_return_expr1:
-	  result = build1 (code, type, 
-			   input_expr_operand (ib, data_in, fn, 
-					       input_record_start (ib)));
+          {
+            enum LTO_tags tag = input_record_start (ib);
+            tree op0;
+
+            if (tag)
+              op0 = input_expr_operand (ib, data_in, fn, tag);
+            else
+              op0 = DECL_RESULT (current_function_decl);
+
+            result = build1 (code, type, op0);
+          }
 	  break;
 	  
 	case LTO_return_expr2:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]