[cfe-dev] Compiling gcc with clang

Eli Friedman eli.friedman at gmail.com
Tue Jan 27 06:04:58 PST 2009


So I figured it might be an interesting experiment to compile gcc with
clang.  Not surprisingly, there were a number of issues, but there's a
positive result at the end.

The first couple of issues I found were missing CodeGen for
designators and incomplete CodeGen for VLAs; these were easy to work
around in the gcc code because there were already alternate codepaths
for compilers without C99 support.  Next couple of issues were a
couple issues with __extension__, which I fixed with r63100 and
r63101.  The next issue was a misdetection of the target, which leads
to a funny compile error; this is probably a bug in ccc (the old
version, not the new fancy version), but forcing the target is easy
enough.  The next issue was an instance of PR3307; I now have a patch
in my tree, which I'll try to finish/commit soon.

The next issue I ran into was a mysterious parse error; this one took
me a while to figure out, but it turned out not to be a clang bug at
all.  Instead, it was an LLVM miscompilation of one of the build
utilities; I filed PR3421 on that, and hacked the relevant generated
file to work around it.

The next issue I ran into is an instance of PR3341; I worked around
that in the gcc code.  The next issue is an issue I found with the way
clang merges function declarations; I filed this as PR3425.

And with all that done, I got a kind-of-working stage 1 gcc; it could
compile simple programs, but the optimizers were completely broken.

For the next step, I tried changing ccc (again, the old version) to
add "-fast" to the llc command line.  This gives significantly better
results: the build process reaches the end of a three-stage optimized
bootstrap with a few bootstrap comparison failures.  Not perfect, but
not bad.

-Eli



More information about the cfe-dev mailing list