SSE intrinsics not being emitted by clang

Hello,

I’m trying to use SSE intrinsic functions like _mm_store_ps from the header xmmintrin.h. I believe that the compiler is meant to provide the definitions for these functions, is that right? For some reason clang doesn’t seem to be doing that so I’m getting undefined symbol errors while linking. This problem occurs when I invoke clang programatically, but not when I compile using the clang frontend executable, despite using the same arguments with both the executable and CompilerInvocation::CreateFromArgs. I’m trying to work out what could be causing this.

So for instance, this works fine:

F:\Clanggit\build\32\Release\bin>clang -cc1 -triple i686-pc-windows-msvc -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -mrelocation-model static -mdisable-fp-elim -std=c++11 -masm-verbose -mconstructor-aliases -target-cpu pentium4 -D_MT --depe
ndent-lib=libcmt --dependent-lib=oldnames -fdiagnostics-format msvc -D _HAS_EXCEPTIONS=1 -internal-isystem “F:\Clanggit\build\32\Debug\lib\clang\3.7.0\include” -internal-isystem “E:/Microsoft Visual Studio 12.0/VC/include” -internal-isystem “C:/Program Fil
es (x86)/Windows Kits/8.1/Include” -internal-isystem “F:/git/scripta/trunk/include” -internal-isystem “F:\Libraries\eigen\Eigen” -fno-dwarf-directory-asm -ferror-limit 19 -fmessage-length 80 -mstackrealign -target-feature +sse4.2 -fms-extensions -fms-co
mpatibility -fms-compatibility-version=18.00 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -fdelayed-template-parsing -O3 -o outsource.obj -x c++ source.cpp -v
clang -cc1 version 3.7.0 based upon LLVM 3.7.0svn default target i686-pc-windows-msvc
#include “…” search starts here:
#include <…> search starts here:
F:\Clanggit\build\32\Debug\lib\clang\3.7.0\include
E:/Microsoft Visual Studio 12.0/VC/include
C:/Program Files (x86)/Windows Kits/8.1/Include
F:/git/scripta/trunk/include
F:\Libraries\eigen\Eigen
End of search list.

Resulting obj relocs from the above compilation using the clang frontend executable:

File: outsource.obj
Format: COFF-i386
Arch: i386
AddressSize: 32bit
Relocations [
Section (1) .text {
0x7 IMAGE_REL_I386_DIR32 .rdata
0xC IMAGE_REL_I386_REL32 _puts
0x11 IMAGE_REL_I386_REL32 _getchar
}

Resulting obj relocs from the obj created by the compiler instance invocation in my program (using the same arguments):

File: temp
Format: COFF-i386
Arch: i386
AddressSize: 32bit
Relocations [
Section (1) .text {
0x26 IMAGE_REL_I386_DIR32 ??_C@_1LA@EKEBDMEJ@?$AA?4?$AA?1?$AAS?$AAc?$AAr?$AAi?$AAp?$AAt?$AAa?$AA?1?$AAs?$AAc?$AAr?$AAi?$AAp?$AAt?$AAs?$AA?1?$AA?4?$AA?4?$AA?1?$AA?4?$AA?4?$AA?1?$AA?4?$AA?4?$AA?1?$AA?4?$AA?4?$AA?1?$AA?4?$AA?4@
0x2D IMAGE_REL_I386_DIR32 ??C@1BIM@JPMPBING@?$AA?$CI?$AAr?$AAe?$AAi?$AAn?$AAt?$AAe?$AAr?$AAp?$AAr?$AAe?$AAt?$AA?$AAc?$AAa?$AAs?$AAt?$AA?$DM?$AAs?$AAi?$AAz?$AAe?$AA?$AAt?$AA?$DO?$AA?$CI?$AAa?$AAr?$AAr?$AAa?$AAy?$AA?$CJ@
0x32 IMAGE_REL_I386_REL32 __wassert
0x60 IMAGE_REL_I386_DIR32 .rdata
0x65 IMAGE_REL_I386_REL32 _puts
0x81 IMAGE_REL_I386_REL32 __mm_load_ps
0x94 IMAGE_REL_I386_REL32 __mm_load_ps
0xB4 IMAGE_REL_I386_REL32 __mm_store_ps
0xD4 IMAGE_REL_I386_REL32 __mm_store_ps
0xDB IMAGE_REL_I386_DIR32 .rdata
0xE0 IMAGE_REL_I386_REL32 _puts
0xE5 IMAGE_REL_I386_REL32 _getchar
0x10C IMAGE_REL_I386_DIR32 .rdata
0x111 IMAGE_REL_I386_REL32 _puts
}

I suspect this is because your tool is picking up MSVC’s version of xmmintrin.h instead of Clang’s. Make sure that HeaderSearchOptions::ResourceDir is set to something good. The resource directory set by the driver is $(dirname path/to/clang)/…/lib/clang/3.N.0.

It’s been a long standing issue to make it easier for standalone tools to find these headers, although I can’t find the bugzilla issue for it.
http://lists.llvm.org/pipermail/cfe-dev/2014-November/040033.html