[PATCH] Fix gcc driver %. handling
Jakub Jelinek
jakub@redhat.com
Thu Apr 26 03:27:00 GMT 2001
Hi!
gcc -MD -o a a.c
calls cc1 with
... -M -MF a.d -MQ .a a -D__GNUC__=3 ...
and cc1 is unhappy about it:
cc1: Output filename specified twice
For this particular switch, switches[i].part1 == "o" and
switches[i].args[0] == "a" and switches[i].args[0] == switches[i].part1 + 2,
so the code below sees arg[0xffffffff] == '\0' (it would crash on 64bit
hosts probably) and stores '.' there, so part1 is now "o.a" and
switches[i].args[0] still "a", so %* expands to ".a a".
Also, we should IMHO append .d (well, .SUFFIX generally) even to filenames
without dots, otherwise it ends up with -M -MF a -MQ a -o a
which does not look very good to me, -M -MF a.d -MQ a -o a is what is IMHO
expected. Tested with
for i in a foo/a a.x foo/a.x; do gcc -MD -o $i a.c; done
and seems to work in all cases.
Ok to commit head & branch? Fixes a regression against 2.95.x.
2001-04-26 Jakub Jelinek <jakub@redhat.com>
* gcc.c (give_switch): If argument contains no dots, append
suffix anyway. If it does not contain even a dir separator,
don't store dot before start of string.
--- gcc/gcc.c.jj Fri Apr 20 00:57:40 2001
+++ gcc/gcc.c Thu Apr 26 13:18:02 2001
@@ -5267,7 +5267,7 @@ give_switch (switchnum, omit_first_word,
do_spec_1 (" ", 0, NULL_PTR);
if (suffix_subst)
{
- unsigned length = strlen (arg);
+ int length = strlen (arg);
while (length-- && !IS_DIR_SEPARATOR (arg[length]))
if (arg[length] == '.')
@@ -5276,11 +5276,9 @@ give_switch (switchnum, omit_first_word,
break;
}
do_spec_1 (arg, 1, NULL_PTR);
- if (!arg[length])
- {
- ((char *)arg)[length] = '.';
- do_spec_1 (suffix_subst, 1, NULL_PTR);
- }
+ if (length >= 0 && !arg[length])
+ ((char *)arg)[length] = '.';
+ do_spec_1 (suffix_subst, 1, NULL_PTR);
}
else
do_spec_1 (arg, 1, NULL_PTR);
Jakub
More information about the Gcc-patches
mailing list