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]

[tree-ssa] fix pathalogical statement expression crash


Silly users.


r~


	* c-parse.in (primary): Set STMT_LINENO on STMT_EXPR.
        * c-simplify.c (gimplify_stmt_expr): Be prepared for last_stmt
        to be null.
        * gcc.c-torture/compile/20031203-2.c: New.

Index: c-parse.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-parse.in,v
retrieving revision 1.144.2.24
diff -u -p -r1.144.2.24 c-parse.in
--- c-parse.in	1 Dec 2003 19:38:23 -0000	1.144.2.24
+++ c-parse.in	4 Dec 2003 02:16:08 -0000
@@ -678,6 +678,7 @@ primary:
 		  if (!last_expr_type)
 		    last_expr_type = void_type_node;
 		  $$ = build1 (STMT_EXPR, last_expr_type, $1);
+		  STMT_LINENO ($$) = input_line;
 		  TREE_SIDE_EFFECTS ($$) = 1;
 		}
 	| compstmt_primary_start error ')'
Index: c-simplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/c-simplify.c,v
retrieving revision 1.1.4.84
diff -u -p -r1.1.4.84 c-simplify.c
--- c-simplify.c	14 Nov 2003 08:16:54 -0000	1.1.4.84
+++ c-simplify.c	4 Dec 2003 02:16:09 -0000
@@ -964,13 +964,14 @@ gimplify_stmt_expr (tree *expr_p)
 	if (TREE_CODE (substmt) != SCOPE_STMT)
 	  last_stmt = substmt;
 
-      if (TREE_CODE (last_stmt) != EXPR_STMT
+      if (last_stmt == NULL_TREE
+	  || TREE_CODE (last_stmt) != EXPR_STMT
 	  || (TREE_TYPE (last_stmt)
 	      && VOID_TYPE_P (TREE_TYPE (last_stmt))))
 	{
 	  location_t loc;
 	  loc.file = input_filename;
-	  loc.line = STMT_LINENO (last_stmt);
+	  loc.line = STMT_LINENO (last_stmt ? last_stmt : *expr_p);
 	  warning ("%Hstatement-expressions should end with a "
 		   "non-void expression", &loc);
 	  last_expr = NULL_TREE;
@@ -986,7 +987,7 @@ gimplify_stmt_expr (tree *expr_p)
 	}
 
 #if defined ENABLE_CHECKING
-      if (!is_last_stmt_of_scope (last_stmt))
+      if (last_stmt && !is_last_stmt_of_scope (last_stmt))
 	abort ();
 #endif
 
Index: testsuite/gcc.c-torture/compile/20031203-3.c
===================================================================
RCS file: testsuite/gcc.c-torture/compile/20031203-3.c
diff -N testsuite/gcc.c-torture/compile/20031203-3.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.c-torture/compile/20031203-3.c	4 Dec 2003 02:16:10 -0000
@@ -0,0 +1,7 @@
+/* Don't ICE on user silliness.  GCC 3.4 and before accepts this without
+   comment; 3.5 warns.  Perhaps eventually we'll declare this an error.  */
+
+void bar (void)
+{
+        ({});
+}


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