Bug 28435 - -MMD vs not found system header (included from a system header)
Summary: -MMD vs not found system header (included from a system header)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL:
Keywords: patch
: 29331 (view as bug list)
Depends on: 22231
Blocks:
  Show dependency treegraph
 
Reported: 2006-07-19 14:00 UTC by Andrew Pinski
Modified: 2012-01-12 20:26 UTC (History)
8 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.2.0, 4.2.1, 4.2.2, 4.3.1, 4.4.0
Last reconfirmed: 2009-09-19 21:47:02


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2006-07-19 14:00:39 UTC
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.
Comment 1 Andrew Pinski 2006-07-19 14:06:07 UTC
I forgot to say every GCC since at least 2.95.3, I tried has the same behavior.
Comment 2 Andrew Pinski 2006-09-03 20:25:46 UTC
This looks like the same bug as PR 22231.
Comment 3 Andrew Pinski 2006-10-03 15:55:57 UTC
*** Bug 29331 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2006-10-03 15:56:21 UTC
Confirmed via the dup bug.
Comment 5 Michael Matz 2006-10-18 14:04:33 UTC
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.
Comment 6 Tom Tromey 2008-05-09 23:02:50 UTC
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.
Comment 7 cgd@gcc.gnu.org 2009-09-19 06:15:43 UTC
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

Comment 8 cgd@gcc.gnu.org 2009-09-19 19:26:29 UTC
Fixed in trunk in rev 151879.
Comment 9 H.J. Lu 2009-09-19 21:47:02 UTC
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)

Comment 10 H.J. Lu 2009-09-19 21:47:32 UTC
All new tests are failing.
Comment 11 Chris Demetriou 2009-09-20 01:34:45 UTC
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.
Comment 12 cgd@gcc.gnu.org 2009-09-20 01:57:08 UTC
(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).
Comment 13 cgd@gcc.gnu.org 2009-09-20 08:08:20 UTC
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

Comment 14 cgd@gcc.gnu.org 2009-09-20 08:10:07 UTC
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.
Comment 15 Andrew Pinski 2010-02-07 20:33:16 UTC
*** Bug 42921 has been marked as a duplicate of this bug. ***
Comment 16 Chris Demetriou 2010-02-07 21:24:57 UTC
(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
Comment 17 Richard Biener 2010-04-06 11:19:10 UTC
GCC 4.5.0 is being released.  Deferring to 4.5.1.
Comment 18 Richard Biener 2010-07-31 09:29:11 UTC
GCC 4.5.1 is being released, adjusting target milestone.
Comment 19 Richard Biener 2010-12-16 13:03:23 UTC
GCC 4.5.2 is being released, adjusting target milestone.
Comment 20 Andrew Pinski 2012-01-12 20:26:59 UTC
Fixed so closing.