This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[RFA] make missing header a fatal error with -MMD
- From: Chris Demetriou <cgd at google dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 11 Sep 2009 10:01:07 -0700
- Subject: [RFA] make missing header a fatal error with -MMD
This fixes a the long-open bug http://gcc.gnu.org/PR28435, in which
-MMD allows compilation to succeed even though a header was missing.
(.o file produced, and everything. yuck.)
bootstrapped on x86_64-linux (Ubuntu Hardy) system @ rev 151627.
Tested:
Dropped the new tests into an existing source tree at the same rev.
bootstrapped, tested with make -j3 check -k
RUNTESTFLAGS="--target_board 'unix{-m32,-m64}'" from top-level.
Applied patch to a new tree, bootstrapped, ran the tests.
In the unmodified source tree, the new test
gcc.dg/cpp/missing-sysheader-MMD.c fails. (The other new tests pass,
as expected).
In the modified source tree, all of the new tests pass. All of the
other test results were identical.
chris
----
[libcpp/ChangeLog]
2009-09-10 Chris Demetriou <cgd@google.com>
PR preprocessor/28435:
* include/cpplib.h (struct cpp_options): Add new member
deps.need_preprocessor_output.
* files.c (open_file_failed): If preprocessor output is needed
always report an error.
[gcc/ChangeLog]
2009-09-10 Chris Demetriou <cgd@google.com>
PR preprocessor/28435:
* c-opts.c (c_common_handle_option): For -MD and -MMD, indicate
to cpplib that the preprocessor output is needed.
[gcc/testsuite/ChangeLog]
2009-09-10 Chris Demetriou <cgd@google.com>
PR preprocessor/28435:
* gcc.dg/cpp/missing-header-MD.c: New test.
* gcc.dg/cpp/missing-header-MMD.c: New test.
* gcc.dg/cpp/missing-sysheader-MD.c: New test.
* gcc.dg/cpp/missing-sysheader-MMD.c: New test.
[libcpp/ChangeLog]
2009-09-10 Chris Demetriou <cgd@google.com>
PR preprocessor/28435:
* include/cpplib.h (struct cpp_options): Add new member
deps.need_preprocessor_output.
* files.c (open_file_failed): If preprocessor output is needed
always report an error.
[gcc/ChangeLog]
2009-09-10 Chris Demetriou <cgd@google.com>
PR preprocessor/28435:
* c-opts.c (c_common_handle_option): For -MD and -MMD, indicate
to cpplib that the preprocessor output is needed.
[gcc/testsuite/ChangeLog]
2009-09-10 Chris Demetriou <cgd@google.com>
PR preprocessor/28435:
* gcc.dg/cpp/missing-header-MD.c: New test.
* gcc.dg/cpp/missing-header-MMD.c: New test.
* gcc.dg/cpp/missing-sysheader-MD.c: New test.
* gcc.dg/cpp/missing-sysheader-MMD.c: New test.
Index: gcc/testsuite/gcc.dg/cpp/missing-header-MD.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/missing-header-MD.c (revision 0)
+++ gcc/testsuite/gcc.dg/cpp/missing-header-MD.c (revision 0)
@@ -0,0 +1,6 @@
+/* Test that missing user headers are fatal errors with -MD. */
+/* { dg-do compile } */
+/* { dg-options "-MD" } */
+
+#include "nonexistent.h" /* { dg-error "nonexistent.h" } */
+/* { dg-message "terminated" "" { target *-*-* } 0 } */
Index: gcc/testsuite/gcc.dg/cpp/missing-header-MMD.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/missing-header-MMD.c (revision 0)
+++ gcc/testsuite/gcc.dg/cpp/missing-header-MMD.c (revision 0)
@@ -0,0 +1,6 @@
+/* Test that missing user headers are fatal errors with -MMD. */
+/* { dg-do compile } */
+/* { dg-options "-MMD" } */
+
+#include "nonexistent.h" /* { dg-error "nonexistent.h" } */
+/* { dg-message "terminated" "" { target *-*-* } 0 } */
Index: gcc/testsuite/gcc.dg/cpp/missing-sysheader-MD.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/missing-sysheader-MD.c (revision 0)
+++ gcc/testsuite/gcc.dg/cpp/missing-sysheader-MD.c (revision 0)
@@ -0,0 +1,6 @@
+/* Test that missing system headers are fatal errors with -MD. */
+/* { dg-do compile } */
+/* { dg-options "-MD" } */
+
+#include <nonexistent.h> /* { dg-error "nonexistent.h" } */
+/* { dg-message "terminated" "" { target *-*-* } 0 } */
Index: gcc/testsuite/gcc.dg/cpp/missing-sysheader-MMD.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/missing-sysheader-MMD.c (revision 0)
+++ gcc/testsuite/gcc.dg/cpp/missing-sysheader-MMD.c (revision 0)
@@ -0,0 +1,6 @@
+/* Test that missing system headers are fatal errors with -MMD. */
+/* { dg-do compile } */
+/* { dg-options "-MMD" } */
+
+#include <nonexistent.h> /* { dg-error "nonexistent.h" } */
+/* { dg-message "terminated" "" { target *-*-* } 0 } */
Index: gcc/c-opts.c
===================================================================
--- gcc/c-opts.c (revision 151627)
+++ gcc/c-opts.c (working copy)
@@ -343,6 +343,7 @@ c_common_handle_option (size_t scode, const char *
case OPT_MD:
case OPT_MMD:
cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
+ cpp_opts->deps.need_preprocessor_output = true;
deps_file = arg;
break;
Index: libcpp/files.c
===================================================================
--- libcpp/files.c (revision 151627)
+++ libcpp/files.c (working copy)
@@ -935,15 +935,28 @@ open_file_failed (cpp_reader *pfile, _cpp_file *fi
errno = file->err_no;
if (print_dep && CPP_OPTION (pfile, deps.missing_files) && errno == ENOENT)
- deps_add_dep (pfile->deps, file->name);
+ {
+ deps_add_dep (pfile->deps, file->name);
+ /* If the preprocessor output (other than dependency information) is
+ being used, we must also flag an error. */
+ if (CPP_OPTION (pfile, deps.need_preprocessor_output))
+ cpp_errno (pfile, CPP_DL_FATAL, file->path);
+ }
else
{
- /* If we are outputting dependencies but not for this file then
- don't error because we can still produce correct output. */
- if (CPP_OPTION (pfile, deps.style) && ! print_dep)
+ /* If we are not outputting dependencies, or if we are and dependencies
+ were requested for this file, or if preprocessor output is needed
+ in addition to dependency information, this is an error.
+
+ Otherwise (outputting dependencies but not for this file, and not
+ using the preprocessor output), we can still produce correct output
+ so it's only a warning. */
+ if (CPP_OPTION (pfile, deps.style) == DEPS_NONE
+ || print_dep
+ || CPP_OPTION (pfile, deps.need_preprocessor_output))
+ cpp_errno (pfile, CPP_DL_FATAL, file->path);
+ else
cpp_errno (pfile, CPP_DL_WARNING, file->path);
- else
- cpp_errno (pfile, CPP_DL_FATAL, file->path);
}
}
Index: libcpp/include/cpplib.h
===================================================================
--- libcpp/include/cpplib.h (revision 151627)
+++ libcpp/include/cpplib.h (working copy)
@@ -433,6 +433,10 @@ struct cpp_options
/* If true, no dependency is generated on the main file. */
bool ignore_main_file;
+
+ /* If true, intend to use the preprocessor output (e.g., for compilation)
+ in addition to the dependency info. */
+ bool need_preprocessor_output;
} deps;
/* Target-specific features set by the front end or client. */