Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug
Bug#: 12448
Product:  
Component:  
Status: ASSIGNED
Resolution:
Assigned To: Tom Tromey <tromey@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: David Taylor <taylor@candd.org>
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 12448 depends on: Show dependency tree
Show dependency graph
Bug 12448 blocks:

Additional Comments:




Mark bug as waiting for feedback
Mark bug as suspended




View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: 2007-01-22 03:29 Opened: 2003-09-29 20:56
In gcc/doc/cppopts.texi, in the description of -MT it says:

    Change the target of the rule emitted by dependency generation.  By
    default CPP takes the name of the main input file, including any path,
    deletes any file suffix such as @samp{.c}, and appends the platform's
    usual object suffix.  The result is the target.

    An @option{-MT} option will set the target to be exactly the string you
    specify.  If you want multiple targets, you can specify them as a single
    argument to @option{-MT}, or use multiple @option{-MT} options.

My reading of this is that if you specify -MT <target>, then the
default target will *NOT* be used.

And examining the code, that appears to be the intent -- for each
target specified with -MT / -MQ, deps_add_target is called.  And after
processing such arguments, deps_add_default_target is called (by
cpp_read_main_file) which only adds the default target if there are no
targets already specified.

But, that isn't the full story.  In gcc.c, variable
cpp_unique_options, we find this line:

    %{!E:%{!M:%{!MM:%{MD|MMD:%{o*:-MQ %*}}}}}

which causes the default target to get added unilaterally.

I believe that either this line should disappear totally or it should
be changed to:

    %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}

i.e., have !MT && !MQ added as a condition.

I have lightly tested both solutions; they both appear to work.

------- Comment #1 From Andrew Pinski 2003-10-01 17:39 -------
*** Bug 12478 has been marked as a duplicate of this bug. ***

------- Comment #2 From David Taylor 2003-10-03 14:34 -------
To reproduce the problem, consider the following Makefile:

CC = gcc
CFLAGS = -MD -MT foo.o -MF foo.d
MV = mv

foo.o: bar.c
        ${CC} bar.c -o - > xfoo.o
        ${MV} xfoo.o foo.o

Suppose bar.c includes no files, then the resulting foo.d
file will contain:

    foo.o -: bar.c

But, it should contain:

    foo.o: bar.c

The - should NOT be present.  You could argue about whether - should ever
be a target within the .d file, but regardless -- if the user specified one
or more targets with -MT / -MQ, then the *DEFAULT* target should *NOT* be used.

Eliminating or editing the cpp_unique_options line, as mentioned, fixes
the problem.

Deleting the line (my preferred fix) bootstraps just fine.  There do not
appear to be any tests within the testsuite that test the -MT / -MQ / -MD /
-MMD / -MF / -M<whatever> options.  If someone will give me a pointer on
how to have the testsuite compare two files -- the generated .d file against
the correct .d file, I will gladly write a test case for this bug.

------- Comment #3 From Vasilis Vasaitis 2003-10-05 18:17 -------
  Hello,

  I just came to Bugzilla to report this bug, and bumped into this existing bug
report. Since this is currently set as UNCONFIRMED, I'd simply like to point out
that the bug is very easily reproducible. For example:

$ touch foo.h
$ echo '#include "foo.h"' > foo.c
$ gcc -c -MD foo.c -MT foo.d -o foo.o
$ cat foo.d
foo.d foo.o: foo.c foo.h

  Now, since -MT is advertised to "set the target to be exactly the string you
specify", and indeed does that in all other cases (i.e., except when it's
specified along with both -MD and -o), this is an obviously wrong behaviour.

------- Comment #4 From Andrew Pinski 2003-11-18 07:20 -------
Confirmed but please send the patch to gcc-patches@gcc.gnu.org.

------- Comment #5 From Steven Bosscher 2003-12-23 12:06 -------
The proposed patch would be this:  
 
------------------------------------------------------------------------ 
<date>  David Taylor  <taylor at candd dot org>   
 
	PR driver/12448 
	* gcc.c (cpp_unique_options): Strip  
 
Index: gcc.c 
=================================================================== 
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v 
retrieving revision 1.400 
diff -c -3 -p -r1.400 gcc.c 
*** gcc.c       20 Dec 2003 07:40:21 -0000      1.400 
--- gcc.c       23 Dec 2003 11:57:41 -0000 
*************** static const char *cpp_unique_options = 
*** 745,751 **** 
   %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\ 
   %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\ 
   %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\ 
!  %{!E:%{!M:%{!MM:%{MD|MMD:%{o*:-MQ %*}}}}}\ 
   %{trigraphs} %{remap} %{g3:-dD} %{H} %C %{D*&U*&A*} %{i*} %Z %i\ 
   %{E|M|MM:%W{o*}}"; 
 
--- 745,751 ---- 
   %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\ 
   %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\ 
   %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\ 
!  %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}} \ 
   %{trigraphs} %{remap} %{g3:-dD} %{H} %C %{D*&U*&A*} %{i*} %Z %i\ 
   %{E|M|MM:%W{o*}}"; 
   
------------------------------------------------------------------------   
 
I really can't tell if this is correct or not.  Evil driver commands! 

------- Comment #6 From Paul Pluzhnikov 2005-02-14 23:37 -------
I just bumped into this bug as well.
Still failing in gcc-3.4.3 a year later :-(

The simplest test case:

  mkdir pr12448 && cd pr12448 && touch foo.c &&
  gcc -c -o foo.o -MD -MTfoobar foo.c && cat foo.d

Current output:
foobar foo.o: foo.c

Expected output:
foobar: foo.c

------- Comment #7 From Andrew Pinski 2005-12-11 18:46 -------
*** Bug 25356 has been marked as a duplicate of this bug. ***

------- Comment #8 From Tom Tromey 2007-01-20 06:19 -------
The patch in this PR looks correct to me.

------- Comment #9 From Tom Tromey 2007-01-22 03:29 -------
I tested this and it works.  I'm submitting it.

------- Comment #10 From patchapp@dberlin.org 2007-01-22 03:30 -------
Subject: Bug number PR driver/12448

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is
http://gcc.gnu.org/ml/gcc-patches/2007-01/msg01759.html

------- Comment #11 From Tom Tromey 2007-03-13 23:50 -------
Subject: Bug 12448

Author: tromey
Date: Tue Mar 13 23:50:42 2007
New Revision: 122889

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122889
Log:
2007-03-13  David Taylor  <taylor@candd.org>

        PR driver/12448:
        * gcc.c (cpp_unique_options): If -MT or -MQ is seen, don't pass
        default -MQ.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gcc.c

------- Comment #12 From Andrew Pinski 2007-05-07 23:48 -------
*** Bug 31851 has been marked as a duplicate of this bug. ***

Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug