Just build clang from trunk on OS X 10.9.2 like this:
git clone http://llvm.org/git/llvm.git
cd llvm/tools
git clone http://llvm.org/git/clang.git
cd ../
cd ./projects
git clone http://llvm.org/git/compiler-rt.git
cd ../
git config branch.master.rebase true
./configure --prefix=/opt/llvm/ --enable-clang-static-analyzer --enable-optimized
make && make install
Now running this version:
$ clang -v
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
Building the testcase.cpp
fails unless I manually supply the path to C++ headers (which is normal, right?):
$ /opt/llvm/bin/clang++ testcase.cpp
testcase.cpp:1:10: fatal error: 'string' file not found
#include <string>
^
1 error generated.
This works:
$ /opt/llvm/bin/clang++ testcase.cpp -o testcase -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/
$ ./testcase
hello
But this crashes: SOLVED: the crash was likely resulting from a conflicting libLTO.dylib. It can be worked around by doing:
export DYLD_LIBRARY_PATH=/opt/llvm/lib/
This was the crash that happened before setting DYLD_LIBRARY_PATH
to point at the right libLTO
:
$ /opt/llvm/bin/clang++ testcase.cpp -g -flto -o testcase -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/
clang: error: unable to execute command: Segmentation fault: 11
clang: error: linker command failed due to signal (use -v to see invocation)
And just supplying the -g
flag leads to some odd warnings:
$ /opt/llvm/bin/clang++ testcase.cpp -g -o testcase -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/
warning: invalid DWARF generated by the compiler: DIE 0x00004029 has multiple AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004029 has multiple AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004029 has multiple AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004029 has multiple AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004049 has multiple AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004049 has multiple AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004049 has multiple AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x000040fb has multiple AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x000040fb has multiple AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x000040fb has multiple AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004691 has multiple AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004698 has multiple AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x000046dd has multiple AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x000046e4 has multiple AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004748 has multiple AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.