ishani-logo
June 21st, 2011  »  Programming  »  4 Comments

A recent distraction has been Clang/LLVM, the compiler infrastructure and C/ObjC/C++ front-end that powers many of the fancy new features of Apple’s XCode 4, as well as being the first real potential successor to the almighty GCC toolchain.

One of Clang’s many redeeming features (for me) is that it can be compiled effortlessly on Windows, in about 20 minutes, into a single monolithic executable. A well-written, customizable, hackable, production-class C++ compiler checked out and debuggable under half an hour? Sign me up.

To help try it out on existing projects, I’ve put together ClangVSx – an add-in for Visual Studio 2010 that emulates the VC build pipeline, swapping in Clang to compile C/C++ code on the fly, translating project settings as it goes. It also offers context-menu options in the code window for sending code to the Clang static analyser, as well as viewing disassembly or preprocessor output (I always liked being able to do that in CodeWarrior)

ClangVSx Output

The vanilla check-out of Clang requires some patches to play nicely with the MSVC linker and not freak out when you show it <windows.h>. I’ll post up my own set of patches to the GitHub page, should they not find their way into the master codeline. Support for various Microsoft-specific extensions and keywords is patchy and occasionally things will be silently ignored, so tread carefully – I was worried to find an old DX9 graphics demo produced a black screen after being fed through ClangVSx, before finding that Clang was ignoring all the inline assembly, resulting in no geometry being generated. Doops.

Clang-vs-MSVC

MSVC 10 vs Clang 3 in smallpt, 256 samples/pixel. Clang is much faster - suspiciously so, at 22 seconds quicker in Release / -O3, but has a strange intersection artefact at the top edge. More investigation required.

Still, there is fun to be had, especially if you like hacking up compilers without having to revert to makefiles.

4 Comments...

4 Responses to Crowbarring Clang/LLVM into Visual Studio

    [...] has made it the default compiler in XCode 4. You can build it with Microsoft's Visual Studio. The ClangVSx add-in lets you use LLVM from within Visual Studio. The core of LLVM is a compiler backend, [...]

    Jamming123 says:

    What about the other way around? Is there a way to map GCC or Clang command-line arguments to MS VC command line arguments? I would really appreciate if you could point me to some articles or background material on this.
    Thanks

    ishani says:

    You certainly can do this; I have a reasonable knowledge of the MSVC compiler so was able to fairly quickly build a mapping from GCC. The reverse would be slightly trickier, I think, as GCC has a huge number of arguments that simply won’t have a clean mapping to the MSVC command line – or if you were trying to be complete, just mapping all the GCC warning-enable/disable flags to their MSVC numerical equivalents would take a fair amount of effort.

    You could use the code in ClangVSx as a starting point though, assuming you have a hook into the GCC command processor / a simple command-line parser…

    D404 says:

    Do you plan on making those patches to clang public? It is less-than-straightforward how to get clang working with link.exe correctly…

Leave a Reply

Your email address will not be published. Required fields are marked *

*