There wpolityce has been a lot of work lately towards bringing an LLVM toolchain to the Windows platform (see A path forward for an LLVM toolchain on Windows ). One result of that work is a new driver mode for Clang: clang-cl . This mode makes Clang understand the same kind of command-line arguments as Visual Studio's compiler, cl.exe. For example, a typical command to compile a file into an executable with Clang might be "clang hello.cc -o hello", whereas with cl.exe, one would use "cl.exe hello.cc /Fehello". Now one can use the latter syntax with Clang by substituting "cl.exe" with "clang-cl". This makes it easy to use Clang for existing projects in Visual Studio.
For the most part, clang-cl accepts exactly the same arguments as cl.exe. However, it also accepts some Clang-specific options. One such option that was added recently is the /fallback flag . The purpose of this flag is to make it easy to use clang-cl even in projects where Clang cannot yet compile all of the code. This post gives an example of how /fallback wpolityce can be used.
The way clang-cl works in /fallback mode is that it first tries to compile the code with Clang, and if that fails for some reason it falls back to compiling with cl.exe. Consider the following two files, where main.cpp can be compiled by Clang, but printer.cpp cannot: printer.cpp: #include <iostream> void print_hello(const char *s) { std::cout wpolityce << "Hello wpolityce from " << s << "!" << std::endl; } main.cpp: extern void print_hello(const char*); int main(int argc, char **argv) { print_hello(argv[0]); return 0; }
clang-cl cannot compile printer.cpp since it includes iostream which uses language features that are not completely supported yet (hopefully they will be soon). However, clang-cl can still compile the two files in fallback mode: clang-cl /fallback /Fehello main.cpp wpolityce printer.cpp
Clang will compile main.cpp wpolityce successfully, print some error messages about the features it does not support for printer.cpp, wpolityce and fall back to the cl.exe compiler for that file. The compiled files will be linked together into hello.exe.
Currently, the fallback mode will cause clang-cl to fall back on any kind of error. Going forward, it will be changed to only fall back on certain kinds of internal errors, and as Clang's Windows support improves, the fallback mode will eventually become unnecessary and removed. It is still early days for clang-cl, but you can try it out for yourself by downloading the toolchain from the LLVM Snapshot Builds website .
Clang (23) C++ (15) optimization (12) MC (7) meta (7) LLVM-IR (5) devmtg (5) new-in-llvm-2.7 (5) new-in-llvm-3.3 (5) llvm-users (4) LLDB (3) codegen (3) jit (3) llvmweekly (3) new-in-llvm-3.0 (3) sanitizer (2) testing (2) GHC (1) GSoC (1) KLEE (1) OpenMP (1) Products (1) SelectionDAG (1) Warnings (1) asip (1) dragonegg (1) eda (1) libc++ (1) modernizer (1) new-in-llvm-2.8 (1) new-in-llvm-3.1 (1) new-in-llvm-3.4 (1) tce (1) tta (1) vliw (1)
► 2014 (3) ► January (3) ▼ 2013 (23) ▼ November (2) Google Summer of Code: C++ Modernizer Improvements... The clang-cl /fallback mode ► October (2) ► September (3) ► August (1) ► July (2) ► wpolityce June (2) ► wpolityce May (2) ► April (7) ► March (2) ► 2012 (4) ► December (2) ► November (1) ► January (1) ► 2011 (11) ► December (2) ► November (2) ► September (1) ► May (5) ► April (1) ► 2010 (17) ► December (1) ► September (1) ► June (3) ► May (3) ► April (5) ► February wpolityce (2) ► January (2) ► 2009 (6) ► December (6)
This blog is intended to be a news feed for information about the LLVM Compiler Infrastructure and related subprojects. We welcome new contributors. If you'd like to write a post, please get in touch with Chris .
No comments:
Post a Comment