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]

[patch] Fix PR 23439/23440


The following patch fixes an ice-on-invalid-code of both the C and C++
frontend for code like this:

  void foo() { for

In this case both frontends call annotate_with_file_line with a NULL
instead of a proper filename. The NULL is passed to strcmp which
segfaults.

The patch fixes this by returning early from annotate_with_file_line,
if no filename is given. A testcase for each frontend is also included.

Bootstrapped and regtested on i686-pc-linux-gnu.
OK for mainline and 4.0 branch?

Regards,
Volker


2005-09-10  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c/23439
	PR c++/23440
	* tree.c (annotate_with_file_line): Return early on empty filename.
	Compare line numbers before filenames.

===================================================================
--- gcc/gcc/tree.c      16 Aug 2005 00:35:50 -0000      1.500
+++ gcc/gcc/tree.c      11 Sep 2005 09:41:01 -0000
@@ -3109,6 +3109,9 @@ expand_location (source_location loc)
 void
 annotate_with_file_line (tree node, const char *file, int line)
 {
+  if (!file)
+    return;
+
   /* Roughly one percent of the calls to this function are to annotate
      a node with the same information already attached to that node!
      Just return instead of wasting memory.  */
===================================================================


2005-09-10  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c/23439
	* gcc.dg/for-1.c: New test.

	PR c++/23440
	* g++.dg/parse/for1.C: New test.

===================================================================
--- gcc/gcc/testsuite/gcc.dg/for-1.c   2003-09-23 19:59:22 +0200
+++ gcc/gcc/testsuite/gcc.dg/for-1.c   2005-09-11 01:19:56 +0200
@@ -0,0 +1,5 @@
+/* PR c/23439 */
+/* Origin: Serge Belyshev <belyshev@depni.sinp.msu.ru> */
+/* { dg-do compile } */
+
+void foo() { for  /* { dg-error "at end of input" } */
===================================================================
--- gcc/gcc/testsuite/g++.dg/parse/for1.C   2003-09-23 19:59:22 +0200
+++ gcc/gcc/testsuite/g++.dg/parse/for1.C   2005-09-11 01:21:43 +0200
@@ -0,0 +1,5 @@
+// PR c++/23440
+// Origin: Volker Reichelt <reichelt@igpm.rwth-aachen.de>
+// { dg-do compile }
+
+void foo() { for (;;)  // { dg-error "at end of input" }
===================================================================



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