Bug 22544 - [4.0/4.1 Regression] gcc ignores input file given on the command line
[4.0/4.1 Regression] gcc ignores input file given on the command line
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: driver
4.0.0
: P2 normal
: 4.0.3
Assigned To: Andrew Pinski
:
: 24241 24395 28877 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2005-07-18 11:43 UTC by bruno
Modified: 2006-08-28 22:49 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-07-18 14:41:30


Attachments
The fix which needs to be tested (1.59 KB, patch)
2005-10-16 04:50 UTC, Andrew Pinski
Details | Diff
fix w/ warning about mixed incompatible languages too (1.38 KB, text/plain)
2005-10-16 16:22 UTC, Bernhard Fischer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bruno 2005-07-18 11:43:39 UTC
gcc-3.4 introduced a syntax for compilation with inter-module analysis: 
  $ gcc -c foo1.c foo2.c -o foo.o 
 
gcc-4.0 performs the same with the command-line option -combine: 
  $ gcc -combine -c foo1.c foo2.c -o foo.o 
 
But Makefiles that have already switched to using the gcc-3.4 invocation 
convention are trapped: gcc-4.0, when invoked without -combine, ignores 
all input files except the last one. 
 
  $ cat foo1.c 
  int foo1 (int x) { return 17 * x; } 
  $ cat foo2.c 
  int foo2 (int x) { return 42 * x; } 
  $ gcc -v 
  Using built-in specs. 
  Target: i686-pc-linux-gnu 
  Configured with: ../gcc-4.0.0/configure --prefix=/home/haible/gnu/arch/linuxgcc40 
--enable-shared --enable-threads --enable-__cxa_atexit 
--enable-languages=c,c++,java,objc --enable-nls 
  Thread model: posix 
  gcc version 4.0.0 
  $ gcc -c foo1.c foo2.c -o foo.o && nm foo.o 
  00000000 T foo2 
 
Expected result: An error, as with gcc-3.3: 
 
  $ gcc -c foo1.c foo2.c -o foo.o && nm foo.o 
  gcc: cannot specify -o with -c or -S and multiple compilations
Comment 1 Andrew Pinski 2005-07-18 14:41:30 UTC
Confirmed.
Comment 2 Andrew Pinski 2005-07-18 14:42:53 UTC
Note GCC 3.3 gave an error:
gcc: cannot specify -o with -c or -S and multiple compilations
Comment 3 Andrew Pinski 2005-10-06 16:46:55 UTC
*** Bug 24241 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2005-10-16 00:22:36 UTC
*** Bug 24395 has been marked as a duplicate of this bug. ***
Comment 5 Andrew Pinski 2005-10-16 04:45:47 UTC
I have a fix.
Comment 6 Andrew Pinski 2005-10-16 04:50:40 UTC
Created attachment 10000 [details]
The fix which needs to be tested

Changelog:
* gcc.c (have_c): New static variable.
(have_o): Likewise.
(process_command): Remove declation of have_c.
Set have_o to 1 when handling -o.
(main): Add a fatel error if there are multiple files specified and -o and -c/-S
is passed witout -combine or multiple languages.
Comment 7 Indan 2005-10-16 12:06:34 UTC
Was the non-standard behaviour in 3.4 a bug or a feature? In any case, isn't it reasonable to mention the -combine option in the error message? Something like:

fatal ("cannot specify -o with -c or -S with multiple files. Try -combine");

I don't have the gcc code, but you check for have_c && have_o, but can have_o ever be true for -S?
Comment 8 Andrew Pinski 2005-10-16 14:32:09 UTC
(In reply to comment #7)
> Was the non-standard behaviour in 3.4 a bug or a feature? In any case, isn't it
> reasonable to mention the -combine option in the error message? 

The behavior in 3.4 was a feature, IIRC not well documented one.

> Something like:
> 
> fatal ("cannot specify -o with -c or -S with multiple files. Try -combine");

Well what happens when you do:

gcc -combine t.cc t.c -c -o t.o
We need an error but what should it be.  I think leaving out the -combine will not confuse
people as they should be reading the documention anyways.

> I don't have the gcc code, but you check for have_c && have_o, but can have_o
> ever be true for -S?

have_c is set for both -S and -c.
Comment 9 Bernhard Fischer 2005-10-16 16:19:12 UTC
(In reply to comment #8)
> (In reply to comment #7)
> > Was the non-standard behaviour in 3.4 a bug or a feature? In any case, isn't it
> > reasonable to mention the -combine option in the error message? 
> 
> The behavior in 3.4 was a feature, IIRC not well documented one.
> 
> > Something like:
> > 
> > fatal ("cannot specify -o with -c or -S with multiple files. Try -combine");
> 
> Well what happens when you do:
> 
> gcc -combine t.cc t.c -c -o t.o
> We need an error but what should it be.  I think leaving out the -combine will
> not confuse
> people as they should be reading the documention anyways.

Yes, they should, still i'd prefer that a hint to -combine is emitted (see attached fix22544.diff2.txt)

Also your patch had odd whitespace.

> 
> > I don't have the gcc code, but you check for have_c && have_o, but can have_o
> > ever be true for -S?
> 
> have_c is set for both -S and -c.
> 

Comment 10 Bernhard Fischer 2005-10-16 16:22:22 UTC
Created attachment 10004 [details]
fix w/ warning about mixed incompatible languages too

Changelog:
* gcc.c (have_c): New static variable.
(have_o): Likewise.
(process_command): Remove declation of have_c.
Set have_o to 1 when handling -o.
(main): Add a fatal error if there are multiple files specified and -o and
-c/-S
is passed witout -combine or multiple languages.
Comment 11 Andrew Pinski 2005-10-16 16:23:08 UTC
(In reply to comment #9)
> Also your patch had odd whitespace.

Do you mean tabs or something else?
tabs = 8 spaces in the GNU coding style.
Comment 12 CVS Commits 2005-10-17 04:22:07 UTC
Subject: Bug 22544

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	pinskia@gcc.gnu.org	2005-10-17 04:22:03

Modified files:
	gcc            : ChangeLog gcc.c 

Log message:
	2005-10-16  Andrew Pinski  <pinskia@physics.uc.edu>
	
	PR driver/22544
	* gcc.c (have_c): New static variable.
	(have_o): Likewise.
	(process_command): Remove declation of have_c.
	Set have_o to 1 when handling -o.
	(main): Add a fatel error if there are multiple
	files specified and -o and -c/-S is passed witout
	-combine or multiple languages.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.10168&r2=2.10169
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gcc.c.diff?cvsroot=gcc&r1=1.472&r2=1.473

Comment 13 Andrew Pinski 2005-10-17 04:22:38 UTC
Fixed.
Comment 14 CVS Commits 2005-10-17 04:22:54 UTC
Subject: Bug 22544

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	pinskia@gcc.gnu.org	2005-10-17 04:22:51

Modified files:
	gcc            : ChangeLog gcc.c 

Log message:
	2005-10-16  Andrew Pinski  <pinskia@physics.uc.edu>
	
	PR driver/22544
	* gcc.c (have_c): New static variable.
	(have_o): Likewise.
	(process_command): Remove declation of have_c.
	Set have_o to 1 when handling -o.
	(main): Add a fatel error if there are multiple
	files specified and -o and -c/-S is passed witout
	-combine or multiple languages.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.466&r2=2.7592.2.467
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gcc.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.448.2.5&r2=1.448.2.6

Comment 15 Bernhard Fischer 2005-10-17 07:09:47 UTC
(In reply to comment #11)
> (In reply to comment #9)
> > Also your patch had odd whitespace.
> 
> Do you mean tabs or something else?
> tabs = 8 spaces in the GNU coding style.
> 
I mean something else, specifically:
@@ -6425,7 +6432,7 @@ main (int argc, const char **argv)
   if (combine_flag)
     combine_inputs = true;
   else
-    combine_inputs = false;
+    combine_inputs = false;  <--this (two extra spaces)
 
   for (i = 0; (int) i < n_infiles; i++)
     {
@@ -6456,6 +6463,9 @@ main (int argc, const char **argv)
       infiles[i].compiled = false;
       infiles[i].preprocessed = false;
     }
+    <-- this (another space error)
+  if (!combine_inputs && have_c && have_o && n_infiles > 1)
Comment 16 Andrew Pinski 2006-08-28 22:49:21 UTC
*** Bug 28877 has been marked as a duplicate of this bug. ***