From 47580d22b27148144811c505b6450acd9dd8d729 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Tue, 31 Mar 2009 13:43:29 +0100 Subject: [PATCH] re PR preprocessor/15638 (gcc should have option to treat missing headers as fatal) PR preprocessor/15638 gcc: * c-common.c (c_cpp_error): Handle CPP_DL_FATAL. gcc/fortran: * cpp.c (cb_cpp_error): Handle CPP_DL_FATAL. gcc/testsuite: * gcc.dg/cpp/missing-header-1.c: New test. * gcc.dg/cpp/include2.c: Only test #include <>. Expect "compilation terminated" message. * gcc.dg/cpp/include2a.c: New test. Copy of include2.c but only test #include "". * gcc.dg/pch/counter-2.c, gcc.dg/pch/valid-1.c, gcc.dg/pch/valid-2.c, gcc.dg/pch/warn-1.c: Expect "compilation terminated" message. libcpp: * files.c (_cpp_find_file): Call open_file_failed after diagnosing invalid PCH. (open_file_failed): Make error for missing file fatal. * include/cpplib.h (CPP_DL_FATAL): Define. From-SVN: r145341 --- gcc/ChangeLog | 5 +++++ gcc/c-common.c | 3 +++ gcc/fortran/ChangeLog | 5 +++++ gcc/fortran/cpp.c | 3 +++ gcc/testsuite/ChangeLog | 12 ++++++++++++ gcc/testsuite/gcc.dg/cpp/include2.c | 3 +-- gcc/testsuite/gcc.dg/cpp/include2a.c | 16 ++++++++++++++++ gcc/testsuite/gcc.dg/cpp/missing-header-1.c | 9 +++++++++ gcc/testsuite/gcc.dg/pch/counter-2.c | 1 + gcc/testsuite/gcc.dg/pch/valid-1.c | 1 + gcc/testsuite/gcc.dg/pch/valid-2.c | 1 + gcc/testsuite/gcc.dg/pch/warn-1.c | 1 + libcpp/ChangeLog | 8 ++++++++ libcpp/files.c | 6 +++--- libcpp/include/cpplib.h | 2 ++ 15 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/cpp/include2a.c create mode 100644 gcc/testsuite/gcc.dg/cpp/missing-header-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 15a8228c6cf..1b75a51425f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2009-03-31 Joseph Myers + + PR preprocessor/15638 + * c-common.c (c_cpp_error): Handle CPP_DL_FATAL. + 2009-03-31 Richard Guenther PR middle-end/23401 diff --git a/gcc/c-common.c b/gcc/c-common.c index b1ac9bc9816..f0c312244b2 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -8009,6 +8009,9 @@ c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, case CPP_DL_NOTE: dlevel = DK_NOTE; break; + case CPP_DL_FATAL: + dlevel = DK_FATAL; + break; default: gcc_unreachable (); } diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 09c6961c48b..c7ed02d34ec 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2009-03-31 Joseph Myers + + PR preprocessor/15638 + * cpp.c (cb_cpp_error): Handle CPP_DL_FATAL. + 2009-03-30 Steven G. Kargl PR fortran/38389 diff --git a/gcc/fortran/cpp.c b/gcc/fortran/cpp.c index fc78f9826a2..9187bed7efe 100644 --- a/gcc/fortran/cpp.c +++ b/gcc/fortran/cpp.c @@ -997,6 +997,9 @@ cb_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, case CPP_DL_NOTE: dlevel = DK_NOTE; break; + case CPP_DL_FATAL: + dlevel = DK_FATAL; + break; default: gcc_unreachable (); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c21f1074cfb..3593c7d538b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,15 @@ +2009-03-31 Joseph Myers + + PR preprocessor/15638 + * gcc.dg/cpp/missing-header-1.c: New test. + * gcc.dg/cpp/include2.c: Only test #include <>. Expect + "compilation terminated" message. + * gcc.dg/cpp/include2a.c: New test. Copy of include2.c but only + test #include "". + * gcc.dg/pch/counter-2.c, gcc.dg/pch/valid-1.c, + gcc.dg/pch/valid-2.c, gcc.dg/pch/warn-1.c: Expect "compilation + terminated" message. + 2009-03-31 Richard Guenther PR middle-end/23401 diff --git a/gcc/testsuite/gcc.dg/cpp/include2.c b/gcc/testsuite/gcc.dg/cpp/include2.c index cda818ed5af..67f1065ae8c 100644 --- a/gcc/testsuite/gcc.dg/cpp/include2.c +++ b/gcc/testsuite/gcc.dg/cpp/include2.c @@ -8,9 +8,8 @@ /* Source: Neil Booth, 4 Nov 2000. */ #include > /* { dg-error "extra tokens" "" } */ -#include "silly\"" /* { dg-error "extra tokens" "" } */ /* These error is No such file or directory, just once. However, this message is locale-dependent, so don't test for it. */ /* { dg-error "silly" "" { target *-*-* } 10 } */ -/* { dg-error "missing" "" { target *-*-* } 11 } */ +/* { dg-message "terminated" "" { target *-*-* } 0 } */ diff --git a/gcc/testsuite/gcc.dg/cpp/include2a.c b/gcc/testsuite/gcc.dg/cpp/include2a.c new file mode 100644 index 00000000000..974f3f33263 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/include2a.c @@ -0,0 +1,16 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. */ + +/* { dg-do preprocess } */ + +/* Tests that #include does not allow the terminating '>' or '"' to be + escaped, as per the standard. */ + +/* Source: Neil Booth, 4 Nov 2000. */ + +#include "silly\"" /* { dg-error "extra tokens" "" } */ + +/* These error is No such file or directory, just once. However, this + message is locale-dependent, so don't test for it. */ +/* { dg-error "silly" "" { target *-*-* } 10 } */ +/* { dg-error "missing" "" { target *-*-* } 10 } */ +/* { dg-message "terminated" "" { target *-*-* } 0 } */ diff --git a/gcc/testsuite/gcc.dg/cpp/missing-header-1.c b/gcc/testsuite/gcc.dg/cpp/missing-header-1.c new file mode 100644 index 00000000000..5445d4c4fec --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/missing-header-1.c @@ -0,0 +1,9 @@ +/* Test that missing headers are fatal errors. PR 15638. */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +#include "nonexistent.h" /* { dg-error "nonexistent.h" } */ +/* { dg-message "terminated" "" { target *-*-* } 0 } */ + +/* This declaration should not receive any diagnostic. */ +foo bar; diff --git a/gcc/testsuite/gcc.dg/pch/counter-2.c b/gcc/testsuite/gcc.dg/pch/counter-2.c index 22ba245b698..6dd2245d7d8 100644 --- a/gcc/testsuite/gcc.dg/pch/counter-2.c +++ b/gcc/testsuite/gcc.dg/pch/counter-2.c @@ -10,6 +10,7 @@ #include "counter-2.h" /* { dg-warning "not used because `__COUNTER__' is invalid" } */ /* { dg-error "counter-2.h: No such file or directory" "no such file" { target *-*-* } 10 } */ /* { dg-error "one or more PCH files were found, but they were invalid" "invalid files" { target *-*-* } 10 } */ +/* { dg-message "terminated" "" { target *-*-* } 0 } */ int main(void) { diff --git a/gcc/testsuite/gcc.dg/pch/valid-1.c b/gcc/testsuite/gcc.dg/pch/valid-1.c index 1bf7d914467..3ee90916591 100644 --- a/gcc/testsuite/gcc.dg/pch/valid-1.c +++ b/gcc/testsuite/gcc.dg/pch/valid-1.c @@ -3,5 +3,6 @@ #include "valid-1.h"/* { dg-warning "created with -gnone, but used with -g" } */ /* { dg-error "No such file" "no such file" { target *-*-* } 3 } */ /* { dg-error "they were invalid" "invalid files" { target *-*-* } 3 } */ +/* { dg-message "terminated" "" { target *-*-* } 0 } */ int x; diff --git a/gcc/testsuite/gcc.dg/pch/valid-2.c b/gcc/testsuite/gcc.dg/pch/valid-2.c index 4dbc4b2d37d..34269a87960 100644 --- a/gcc/testsuite/gcc.dg/pch/valid-2.c +++ b/gcc/testsuite/gcc.dg/pch/valid-2.c @@ -3,4 +3,5 @@ #include "valid-2.h" /* { dg-warning "settings for -fexceptions do not match" } */ /* { dg-error "No such file" "no such file" { target *-*-* } 3 } */ /* { dg-error "they were invalid" "invalid files" { target *-*-* } 3 } */ +/* { dg-message "terminated" "" { target *-*-* } 0 } */ int x; diff --git a/gcc/testsuite/gcc.dg/pch/warn-1.c b/gcc/testsuite/gcc.dg/pch/warn-1.c index eaa9cafc39a..64944c776d8 100644 --- a/gcc/testsuite/gcc.dg/pch/warn-1.c +++ b/gcc/testsuite/gcc.dg/pch/warn-1.c @@ -5,6 +5,7 @@ #include "warn-1.h"/* { dg-warning "not used because .DEFINED_VALUE. is defined" } */ /* { dg-error "No such file" "no such file" { target *-*-* } 5 } */ /* { dg-error "they were invalid" "invalid files" { target *-*-* } 5 } */ +/* { dg-message "terminated" "" { target *-*-* } 0 } */ int main(void) diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index b2f4232f81d..e16a9e45ca9 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,11 @@ +2009-03-31 Joseph Myers + + PR preprocessor/15638 + * files.c (_cpp_find_file): Call open_file_failed after diagnosing + invalid PCH. + (open_file_failed): Make error for missing file fatal. + * include/cpplib.h (CPP_DL_FATAL): Define. + 2009-03-30 Sergiy Vyshnevetskiy PR preprocessor/31932: diff --git a/libcpp/files.c b/libcpp/files.c index 007fce77d53..f9e68983a4d 100644 --- a/libcpp/files.c +++ b/libcpp/files.c @@ -1,6 +1,6 @@ /* Part of CPP library. File handling. Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998, - 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 + 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. Written by Per Bothner, 1994. Based on CCCP program by Paul Rubin, June 1986 @@ -488,7 +488,6 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool f return file; } - open_file_failed (pfile, file, angle_brackets); if (invalid_pch) { cpp_error (pfile, CPP_DL_ERROR, @@ -497,6 +496,7 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool f cpp_error (pfile, CPP_DL_ERROR, "use -Winvalid-pch for more information"); } + open_file_failed (pfile, file, angle_brackets); break; } @@ -942,7 +942,7 @@ open_file_failed (cpp_reader *pfile, _cpp_file *file, int angle_brackets) if (CPP_OPTION (pfile, deps.style) && ! print_dep) cpp_errno (pfile, CPP_DL_WARNING, file->path); else - cpp_errno (pfile, CPP_DL_ERROR, file->path); + cpp_errno (pfile, CPP_DL_FATAL, file->path); } } diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index ffde40eef1a..adc6cf13ede 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -813,6 +813,8 @@ cpp_num cpp_num_sign_extend (cpp_num, size_t); #define CPP_DL_ICE 0x04 /* An informative note following a warning. */ #define CPP_DL_NOTE 0x05 +/* A fatal error. */ +#define CPP_DL_FATAL 0x06 /* Output a diagnostic of some kind. */ extern bool cpp_error (cpp_reader *, int, const char *msgid, ...) -- 2.30.2