clang -E -o support

To be more compatible with gcc, clang should support outputting preprocessed source to a file, instead of relying on shell redirection. The attached patch allows "clang -E a.c -o a.i" to work. In fact, it supports the following:

$ echo "" > a.c
$ clang -E a.c
# 1 "a.c" 1
# 0 "a.c"
# 1 "<predefines>" 1
# 1 "a.c" 2

$ clang -E a.c -o -
# 1 "a.c" 1
# 0 "a.c"
# 1 "<predefines>" 1
# 1 "a.c" 2

$ clang -E a.c -o a.i
$ cat a.i
# 1 "a.c" 1
# 0 "a.c"
# 1 "<predefines>" 1
# 1 "a.c" 2
$ clang -E a.c -o /dev/null
$ clang -E a.c -o /System/unwritable
Assertion failed: (OutputFD >= 0 && "failed to open output file"), function InitOutputBuffer, file PrintPreprocessedOutput.cpp, line 73.
0 clang 0x0022d655 _ZN40_GLOBAL__N_Signals.cpp_00000000_62F12DC115PrintStackTraceEv + 45
1 clang 0x0022d9fb _ZN40_GLOBAL__N_Signals.cpp_00000000_62F12DC113SignalHandlerEi + 323
...

I also compiled PrintPreprocessedOutput.cpp with USE_STDIO set to 1 on Mac OS X, so I believe that codepath should work as well.

clang-E-o.patch (3.53 KB)

Excellent, thanks Shantonu!
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20080121/003943.html

-Chris