This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch fix regression preprocessor/17610, v2
- From: neroden at fastmail dot fm (Nathanael Nerode)
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 27 Nov 2004 17:47:52 -0500
- Subject: [patch fix regression preprocessor/17610, v2
Slightly improved from last version.
Fixes the bug. Bootstrapped & regression tested on i686-pc-linux-gnu.
A testcase is included (slightly revised from previous version), which cleanly
passes on the fixed compiler (or on the old 3.3, which worked), and fails on
the broken version.
(It's still imperfect because in the failing case it may time out, which
is wasteful, but whatever.)
OK to commit?
(libcpp)
PR preprocessor/17610
* directives.c (do_include_common): Error out if an empty filename
is given for #include (or #include_next or #import).
(gcc)
PR preprocessor/17610
* testsuite/gcc.dg/cpp/empty-include.c: New testcase.
Index: directives.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/directives.c,v
retrieving revision 1.9
diff -u -p -r1.9 directives.c
--- directives.c 23 Nov 2004 23:25:39 -0000 1.9
+++ directives.c 27 Nov 2004 20:44:22 -0000
@@ -668,6 +668,14 @@ do_include_common (cpp_reader *pfile, en
if (!fname)
return;
+ if (!*fname)
+ {
+ cpp_error (pfile, CPP_DL_ERROR, "empty filename in #%s",
+ pfile->directive->name);
+ free ((void *) fname);
+ return;
+ }
+
/* Prevent #include recursion. */
if (pfile->line_table->depth >= CPP_STACK_MAX)
cpp_error (pfile, CPP_DL_ERROR, "#include nested too deeply");
Index: ../gcc/testsuite/gcc.dg/cpp/empty-include.c
===================================================================
RCS file: ../gcc/testsuite/gcc.dg/cpp/empty-include.c
diff -N ../gcc/testsuite/gcc.dg/cpp/empty-include.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ../gcc/testsuite/gcc.dg/cpp/empty-include.c 27 Nov 2004 21:21:42 -0000
@@ -0,0 +1,13 @@
+/*
+ * Copyright 2004 Free Software Foundation, Inc.
+ * Contributed and written by Nathanael Nerode.
+ *
+ * GCC 3.4 would attempt to open stdin as the included file
+ * (PR 17610), causing a sort of hang.
+ *
+ * We should get an error.
+ */
+
+/* {dg-do preprocess} */
+#include "" /* { dg-error "empty" "error on empty filename in include" } */
+int x; /* Otherwise we have an empty file and get more errors. */
--
This space intentionally left blank.