Use of -Xclang and forwarding to GCC

Hello,
I ran into a problem when using the -Xclang switch. According to the documentation it says that it ‘Pass arg to the clang compiler frontend.’. But then, when I use it, the arguments are also passed to the assembler and the linker. Example (the -W switch is a random one, I just picked it because clang -cc1 recognizes it):

clang -ccc-echo -Xclang -W -o ioi ioi.c

“/home/pamaury/avalon/bin/clang” -cc1 -triple x86_64-unknown-linux-gnu -S -disable-free -main-file-name ioi.c -mrelocation-model static -mdisable-fp-elim -mconstructor-aliases -munwind-tables -target-cpu x86-64 -resource-dir /home/pamaury/avalon/lib/clang/2.8 -ferror-limit 19 -fmessage-length 202 -fgnu-runtime -fdiagnostics-show-option -fcolor-diagnostics -W -o /tmp/cc-0rvFL5.s -x c ioi.c
“/usr/bin/gcc” -Xclang -W -c -m64 -o /tmp/cc-GuWlIA.o -x assembler /tmp/cc-0rvFL5.s
gcc: unrecognized option ‘-Xclang’
“/usr/bin/gcc” -Xclang -W -m64 -o ioi /tmp/cc-GuWlIA.o
gcc: unrecognized option ‘-Xclang’

Looking at the code, it seems that this is because the generic gcc code in gcc::Common::ConstructJob forwards an argument if the option hasForwardToGCC() and hasForwardToGCC() itself is defined as:

bool hasForwardToGCC() const { return !DriverOption && !LinkerInput; }

Which seems strange to me because obviously, clang will not use GCC as the compiler itself (that would defeat the point of using clang :)) so when using the -Xclang option which is not a driver option nor a linker input but clearly a compiler related switch, it should not be forwarded to gcc.

Am I missing something there or this really a bug ?

Amaury Pouly

Looks like a bug.

  - Doug

I filed a bug, see bug 7826.

Amaury Pouly

2010/8/4 Douglas Gregor <dgregor@apple.com>