clang-cl and intrinsics

Hi all,

I'm trying to use clang-cl on Windows to be able to use ASAN. The
build system I'm using is a little wonky, so I worked around it by
putting the Clang build output dir in the executable search path, and
creating a link from cl.exe -> clang-cl.exe there.

So far, so good -- clang-cl is compiling the code when I build from
Visual Studio.

But as soon as it hits an <ostream> include, I get build errors from
Clang's intrinsics headers, e.g.:

1> In file included from C:\project\t.cpp:1:
1> In file included from C:\project\t.h:5:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\ostream:6:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\ios:6:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\xlocnum:10:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\streambuf:6:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\xiosbase:6:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\xlocale:8:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\stdexcept:7:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\xstring:6:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\xmemory0:942:
1> In file included from
D:\dev\private\llvm-trunk\out\reldbg\bin\..\lib\clang\3.8.0\include\intrin.h:34:
1> In file included from
D:\dev\private\llvm-trunk\out\reldbg\bin\..\lib\clang\3.8.0\include\x86intrin.h:29:
1> In file included from
D:\dev\private\llvm-trunk\out\reldbg\bin\..\lib\clang\3.8.0\include\immintrin.h:31:
1>D:\dev\private\llvm-trunk\out\reldbg\bin\..\lib\clang\3.8.0\include\emmintrin.h(1484,3):
error : use of undeclared identifier '__builtin_ia32_pause'
1> __builtin_ia32_pause();
1> ^

1> In file included from C:\project\t.cpp:1:
1> In file included from C:\project\t.h:5:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\ostream:6:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\ios:6:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\xlocnum:10:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\streambuf:6:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\xiosbase:6:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\xlocale:8:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\stdexcept:7:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\xstring:6:
1> In file included from C:\Program Files (x86)\Microsoft Visual
Studio 11.0\VC\include\xmemory0:942:
1> In file included from
D:\dev\private\llvm-trunk\out\reldbg\bin\..\lib\clang\3.8.0\include\intrin.h:34:
1> In file included from
D:\dev\private\llvm-trunk\out\reldbg\bin\..\lib\clang\3.8.0\include\x86intrin.h:29:
1> In file included from
D:\dev\private\llvm-trunk\out\reldbg\bin\..\lib\clang\3.8.0\include\immintrin.h:37:
1>D:\dev\private\llvm-trunk\out\reldbg\bin\..\lib\clang\3.8.0\include\smmintrin.h(146,45):
error : cannot initialize a parameter of type
'__attribute__((__vector_size__(2 * sizeof(long long)))) long long *'
with an rvalue of type 'const __v2di *'
1> return (__m128i) __builtin_ia32_movntdqa ((const __v2di *) __V);
1> ^~~~~~~~~~~~~~~~~~~~

Did I miss anything here? I'm not telling clang-cl anything about
target, I did try passing various /arch: arguments without any
success.

Thanks for any ideas!

- Kim

This looks like skew between the compiler headers and the compiler. Both those builtins were added in the November / October time frame, so an old clang wouldn’t know about them.

Are you sure you made a symlink from cl.exe to clang-cl.exe and not a copy? Check if “D:\dev\private\llvm-trunk\out\reldbg\bin\cl.exe --version” and “D:\dev\private\llvm-trunk\out\reldbg\bin\clang.exe --version” agree.

Thanks, that gives me something to work from.

It turned out I'd made a hard-link, and when I rebuilt Clang it didn't
follow, just as you predicted.

Unfortunately I accidentally clobbered my entire build tree when I
attempted to remove cl.exe, so it'll be a while until I can testify
that this works :slight_smile:

Feeling hopeful,
- Butterfingers

Just to confirm: that was it.

Thanks!

- Kim