I really don't know if this is a bug or not but it seems to be. The steps to reproduce: mkdir sys cat >sys/t.h <<FOO #include <bogus.h> FOO cat > t.c <<FOO #include <t.h> FOO gcc -isystem sys t.c -MMD And notice that this actually compiles successfully even though bougs.h does not exist. And removing the -MMD option, it actually fails.
I forgot to say every GCC since at least 2.95.3, I tried has the same behavior.
This looks like the same bug as PR 22231.
*** Bug 29331 has been marked as a duplicate of this bug. ***
Confirmed via the dup bug.
The problem is in libcpp/files.c:open_file_failed. It deliberately only gives a warning when producing dependencies (and under some circumstances doesn't even give a warning) for missing files. I think it does that under the assumption that the user gave only -M (with -E implied), so he would be interested in the preprocessor output nevertheless, and that can be produced even with missing deps. The problem is, that giving -MD or -MMD does not imply -E, i.e. the user really wants the deps to just be a side-effect, as documented. Probably libcpp needs another option which can be set from the driver, which would make it produce errors instead of warnings.
I think we should give an error by default, and only *not* give an error if -MG is passed. My reasoning is that -MG exists only to disable this error. I couldn't think of a reason to disable it in other cases. For instance, it seems to me that "gcc -E" should fail if a header is missing. I looked at open_file_failed, but I don't understand the reasoning behind a lot of the logic in there (though see PR 15220). A comment says: /* If we are outputting dependencies but not for this file then don't error because we can still produce correct output. */ ... but this seems to be based on incorrect logic to me. A <> include may define something which affects later inclusions. I wonder if anybody relies on the current, bogus, behavior.
Subject: Bug 28435 Author: cgd Date: Sat Sep 19 06:15:21 2009 New Revision: 151879 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=151879 Log: [libcpp/ChangeLog] 2009-09-18 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-19 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-19 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. Added: trunk/gcc/testsuite/gcc.dg/cpp/missing-header-MD.c trunk/gcc/testsuite/gcc.dg/cpp/missing-header-MMD.c trunk/gcc/testsuite/gcc.dg/cpp/missing-sysheader-MD.c trunk/gcc/testsuite/gcc.dg/cpp/missing-sysheader-MMD.c Modified: trunk/gcc/ChangeLog trunk/gcc/c-opts.c trunk/gcc/testsuite/ChangeLog trunk/libcpp/ChangeLog trunk/libcpp/files.c trunk/libcpp/include/cpplib.h
Fixed in trunk in rev 151879.
On Linux/ia32, Linux/ia64 and Linux/Intel64, I got FAIL: gcc.dg/cpp/missing-header-MD.c (test for errors, line 5) FAIL: gcc.dg/cpp/missing-header-MD.c (test for excess errors) FAIL: gcc.dg/cpp/missing-header-MMD.c (test for errors, line 5) FAIL: gcc.dg/cpp/missing-header-MMD.c (test for excess errors) FAIL: gcc.dg/cpp/missing-sysheader-MD.c (test for errors, line 5) FAIL: gcc.dg/cpp/missing-sysheader-MD.c (test for excess errors) FAIL: gcc.dg/cpp/missing-sysheader-MMD.c (test for errors, line 5) FAIL: gcc.dg/cpp/missing-sysheader-MMD.c (test for excess errors)
All new tests are failing.
Subject: Re: -MMD vs not found system header (included from a system header) Gack, sorry, looks like I screwed this up. When I retested after updating, I only compared test results before/after, and saw what I was expecting, I didn't actually recheck all of the output from the new tests. I'll see about fixing ASAP.
(In reply to comment #11) > Gack, sorry, looks like I screwed this up. > > When I retested after updating, I only compared test results > before/after, and saw what I was expecting, I didn't actually recheck > all of the output from the new tests. Actually, it looking at this error further, I can't see how the new tests ever passed in trunk. (I initially wrote this in 4.4.0, where I definitely verified that all of the tests passed... but the 'fatal error' bit was changed in trunk, and so I had to change the tests. And I know that I diffed the test results in trunk, but I can only conclude that I never actually verified that they all passed in trunk. *sigh*) Anyway, testing the fix now (copying the error-checking style from the current missing-header-1 test).
Subject: Bug 28435 Author: cgd Date: Sun Sep 20 08:08:06 2009 New Revision: 151894 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=151894 Log: [gcc/testsuite/ChangeLog] 2009-09-20 Chris Demetriou <cgd@google.com> PR preprocessor/28435: * gcc.dg/cpp/missing-header-MD.c: Make output checking match gcc.dg/cpp/missing-header-1.c, and add PR number to test comment. * gcc.dg/cpp/missing-header-MMD.c: Likewise. * gcc.dg/cpp/missing-sysheader-MD.c: Likewise. * gcc.dg/cpp/missing-sysheader-MMD.c: Likewise. Modified: trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gcc.dg/cpp/missing-header-MD.c trunk/gcc/testsuite/gcc.dg/cpp/missing-header-MMD.c trunk/gcc/testsuite/gcc.dg/cpp/missing-sysheader-MD.c trunk/gcc/testsuite/gcc.dg/cpp/missing-sysheader-MMD.c
HJ, I believe I've fixed the tests now: PASS: gcc.dg/cpp/missing-header-MD.c (test for warnings, line ) PASS: gcc.dg/cpp/missing-header-MD.c (test for warnings, line ) PASS: gcc.dg/cpp/missing-header-MD.c (test for excess errors) PASS: gcc.dg/cpp/missing-header-MMD.c (test for warnings, line ) PASS: gcc.dg/cpp/missing-header-MMD.c (test for warnings, line ) PASS: gcc.dg/cpp/missing-header-MMD.c (test for excess errors) PASS: gcc.dg/cpp/missing-sysheader-MD.c (test for warnings, line ) PASS: gcc.dg/cpp/missing-sysheader-MD.c (test for warnings, line ) PASS: gcc.dg/cpp/missing-sysheader-MD.c (test for excess errors) PASS: gcc.dg/cpp/missing-sysheader-MMD.c (test for warnings, line ) PASS: gcc.dg/cpp/missing-sysheader-MMD.c (test for warnings, line ) PASS: gcc.dg/cpp/missing-sysheader-MMD.c (test for excess errors) thanks for letting me know.
*** Bug 42921 has been marked as a duplicate of this bug. ***
(In reply to comment #15) > *** Bug 42921 has been marked as a duplicate of this bug. *** > FWIW, I actually think that's a different issue (though certainly related). this bug was all about -MD and -MMD -- and what happens when an object file needs to be output, but cannot be because of a missing include. AFAICT, that bug is all about, what should the handling of -MM be vs. missing system headers. That having been said, I will note that with: gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) you get the results: [cgd@laptop tmp]$ echo "#include <does_not_exist.h>" > foo.c [cgd@laptop tmp]$ gcc -MM -MF foo.d foo.c && echo succeeded || echo failed foo.c:1:28: does_not_exist.h: No such file or directory failed [cgd@laptop tmp]$ echo '#include "does_not_exist.h"' > foo.c [cgd@laptop tmp]$ gcc -MM -MF foo.d foo.c && echo succeeded || echo failed foo.c:1:28: does_not_exist.h: No such file or directory failed So this certainly used to behave as the submitter of 42921 expected at *some* point. As of 4.2.2 (the next version I have handy after 3.4.4) the first case reported "succeeded" (and the second failed). --cgd
GCC 4.5.0 is being released. Deferring to 4.5.1.
GCC 4.5.1 is being released, adjusting target milestone.
GCC 4.5.2 is being released, adjusting target milestone.
Fixed so closing.