From: Dodji Seketeli Date: Tue, 28 Jan 2014 15:03:19 +0000 (+0100) Subject: PR preprocessor/59935 - caret diagnostics crashes on non-file locations X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=367c82866e7c439004f283bb45fdbe09479c0d7f;p=gcc.git PR preprocessor/59935 - caret diagnostics crashes on non-file locations 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. Signed-off-by: Dodji Seketeli From-SVN: r207195 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0dc6d605318..e802cba1619 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2014-01-28 Jakub Jelinek + + PR preprocessor/59935 + * 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. + 2014-01-28 Richard Biener PR tree-optimization/58742 diff --git a/gcc/input.c b/gcc/input.c index 547c177b09f..63cd062ec5b 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/ChangeLog b/gcc/testsuite/ChangeLog index c85c2c23868..30cbfa6ab9a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2014-01-28 Dodji Seketeli + + PR preprocessor/59935 + * c-c++-common/cpp/warning-zero-location.c: New test. + * c-c++-common/cpp/warning-zero-location-2.c: Likewise. + 2014-01-27 Steve Ellcey * gcc.target/mips/pr52125.c: Add -mno-optgp option. 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 00000000000..c0e0bf75fdf --- /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 +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 00000000000..ca2e102bba0 --- /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 }