Bug 22231 - -MG ignores missing headers even with -c
Summary: -MG ignores missing headers even with -c
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 4.0.1
: P2 normal
Target Milestone: 4.4.0
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks: 28435
  Show dependency treegraph
 
Reported: 2005-06-29 13:53 UTC by Johannes Stezenbach
Modified: 2008-05-09 22:18 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-01-21 03:09:47


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Johannes Stezenbach 2005-06-29 13:53:57 UTC
I just spent half an hour to debug mysterious build failures
(make complaining about missing dependencies) in some
third party code. (The reason was a missing -Ipath.)

Given what the documentation of -MG
in the preprocessor says I'm not sure this is a real bug,
but as an enhancement request I think gcc shouldn't
pass -MG to the preprocessor if it is used in combination
with -c (or -S etc.), or produce an error (it doesn't
really make sense to use -MG with -c).

This behaviour is the same in gcc --version:
gcc-3.3 (GCC) 3.3.6 (Debian 1:3.3.6-7)
gcc-3.4 (GCC) 3.4.5 20050613 (prerelease) (Debian 3.4.4-1)
gcc-4.0 (GCC) 4.0.1 20050617 (prerelease) (Debian 4.0.0-10)

$ cat >t.c
#include "foo.h"
$ gcc -MD -c t.c
t.c:1:17: foo.h: No such file or directory
$ ls -l t.*
-rw-r--r--  1 js js 17 Jun 29 15:35 t.c
-rw-r--r--  1 js js  0 Jun 29 15:36 t.d
$ gcc -MD -MG -c t.c
$ ls -l t.*
-rw-r--r--  1 js js  17 Jun 29 15:35 t.c
-rw-r--r--  1 js js  15 Jun 29 15:35 t.d
-rw-r--r--  1 js js 637 Jun 29 15:35 t.o
$ cat t.d
t.o: t.c foo.h
$
Comment 1 Tom Tromey 2007-01-08 01:54:32 UTC
Confirmed.
I'm inclined to agree that we should disallow -MG in this situation.
Perhaps this is best done in c-opts.c:sanitize_cpp_opts()
Comment 2 Tom Tromey 2007-01-21 03:09:47 UTC
I am testing a patch for this.
Comment 3 Tom Tromey 2008-05-08 16:40:45 UTC
I finally submitted this patch.
http://gcc.gnu.org/ml/gcc-patches/2008-05/msg00520.html
Comment 4 Tom Tromey 2008-05-09 22:17:57 UTC
Subject: Bug 22231

Author: tromey
Date: Fri May  9 22:17:00 2008
New Revision: 135128

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135128
Log:
gcc
	PR preprocessor/22231:
	* c-opts.c (sanitize_cpp_opts): Disallow -MG if compilation is
	proceeding.
gcc/testsuite
	PR preprocessor/22231:
	* gcc.dg/pr22231.c: New file.

Added:
    trunk/gcc/testsuite/gcc.dg/pr22231.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-opts.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Tom Tromey 2008-05-09 22:18:47 UTC
Fixed on trunk.
It is very unlikely that this will be back-ported, so I'm closing the bug.