This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] preprocessor/58580 - preprocessor goes OOM with warning for zero literals
- From: Dodji Seketeli <dodji at redhat dot com>
- To: Markus Trippelsdorf <markus at trippelsdorf dot de>
- Cc: Jakub Jelinek <jakub at redhat dot com>, Bernd Edlinger <bernd dot edlinger at hotmail dot de>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Tom Tromey <tromey at redhat dot com>, Manuel LÃpez-IbÃÃez <lopezibanez at gmail dot com>
- Date: Tue, 28 Jan 2014 14:19:57 +0100
- Subject: Re: [PATCH] preprocessor/58580 - preprocessor goes OOM with warning for zero literals
- Authentication-results: sourceware.org; auth=none
- References: <878uwt63e2 dot fsf at redhat dot com> <20131113081610 dot GH27813 at tucnak dot zalov dot cz> <87zjp7t73c dot fsf at redhat dot com> <DUB129-W872C78585B0C16D48CFFA5E4A40 at phx dot gbl> <87vbxcig8t dot fsf at redhat dot com> <20140124150532 dot GB396 at x4> <87iot9qtff dot fsf at redhat dot com> <20140124154419 dot GQ892 at tucnak dot redhat dot com> <878uu5qs3q dot fsf at redhat dot com> <20140124230239 dot GH396 at x4> <20140124232038 dot GI396 at x4>
Here is the patch I am committing right now.
gcc/ChangeLog
* input.c (location_get_source_line): Bail out on when line number
is zero, and test the return value of
lookup_or_add_file_to_cache_tab.
gcc/testsuite/ChangeLog
* c-c++-common/cpp/warning-zero-location.c: New test.
* c-c++-common/cpp/warning-zero-location-2.c: Likewise.
diff --git a/gcc/input.c b/gcc/input.c
index 547c177..63cd062 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -698,7 +698,13 @@ location_get_source_line (expanded_location xloc,
static char *buffer;
static ssize_t len;
- fcache * c = lookup_or_add_file_to_cache_tab (xloc.file);
+ if (xloc.line == 0)
+ return NULL;
+
+ fcache *c = lookup_or_add_file_to_cache_tab (xloc.file);
+ if (c == NULL)
+ return NULL;
+
bool read = read_line_num (c, xloc.line, &buffer, &len);
if (read && line_len)
diff --git a/gcc/testsuite/c-c++-common/cpp/warning-zero-location-2.c b/gcc/testsuite/c-c++-common/cpp/warning-zero-location-2.c
new file mode 100644
index 0000000..c0e0bf7
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/warning-zero-location-2.c
@@ -0,0 +1,10 @@
+/*
+ { dg-options "-D _GNU_SOURCE -fdiagnostics-show-caret" }
+ { dg-do compile }
+ */
+
+#line 4636 "configure"
+#include <xxxxxxxxxxxx.h>
+int main() { return 0; }
+
+/* { dg-error "No such file or directory" { target *-*-* } 4636 } */
diff --git a/gcc/testsuite/c-c++-common/cpp/warning-zero-location.c b/gcc/testsuite/c-c++-common/cpp/warning-zero-location.c
new file mode 100644
index 0000000..ca2e102
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/warning-zero-location.c
@@ -0,0 +1,8 @@
+/*
+ { dg-options "-D _GNU_SOURCE -fdiagnostics-show-caret" }
+ { dg-do compile }
+ */
+
+#define _GNU_SOURCE /* { dg-warning "redefined" } */
+
+/* { dg-message "" "#define _GNU_SOURCE" {target *-*-* } 0 }
--
Dodji