Error in xmmintrin.h with Clang and LLVM 3.1 built from RELEASE_31 tag.

Hello,

I built Clang and LLVM 3.1 on OS X using the following configure command:

configure --with-gcc-toolchain=/opt/local/ --prefix=/opt/clang-3.1/ --enable-targets=x86_64,x86 --enable-optimized

the reason for the gcc-tolchain location is to use the macports gcc 4.6 libstdc++ in order to support more of C++11. I also made the following changes to InitHeaderSearch::AddDefaultCIncludePaths:

void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
const HeaderSearchOptions &HSOpts) {
llvm::Triple::OSType os = triple.getOS();

if (HSOpts.UseStandardSystemIncludes) {
switch (os) {
case llvm::Triple::FreeBSD:
case llvm::Triple::NetBSD:
break;
default:
// FIXME: temporary hack: hard-coded paths.
//AddPath("/usr/local/include", System, true, false, false);

AddPath("/opt/local/include/gcc46/c++", System, true, false, false);
AddPath("/opt/local/include/gcc46/c++/x86_64-apple-darwin11/.", System, true, false, false);
AddPath("/opt/local/include/gcc46/c++/backward/", System, true, false, false);
AddPath("/opt/local/lib/gcc46/gcc/x86_64-apple-darwin11/4.6.3/include", System, true, false, false);
AddPath("/usr/local/include", System, true, false, false);
AddPath("/opt/local/lib/gcc46/gcc/x86_64-apple-darwin11/4.6.3/include-fixed", System, true, false, false);
AddPath("/usr/include", System, true, false, false);

break;
}
}

Then when building a C source file I get the following error:

In file included from /System/Library/Frameworks/Carbon.framework/Headers/Carbon.h:20:
In file included from /System/Library/Frameworks/CoreServices.framework/Headers/CoreServices.h:21:
In file included from /System/Library/Frameworks/CoreServices.framework/Frameworks/AE.framework/Headers/AE.h:20:
In file included from /System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/CarbonCore.h:129:
In file included from /System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/DriverServices.h:32:
In file included from /System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/MachineExceptions.h:29:
/opt/local/lib/gcc46/gcc/x86_64-apple-darwin11/4.6.3/include/xmmintrin.h:102:10: error: invalid conversion between vector type ‘__m128’ and integer type ‘int’ of different size

Any ideas?

Adding "/opt/local/lib/gcc46/gcc/x86_64-apple-darwin11/4.6.3/include/"
to your include paths is a bad idea.

-Eli

May not be the problem here, but errors similar to that happen in xmmintrin.h when building things with GCC and not specifying -msse2. It's a bit too late for me to go digging into the clang driver, but I know I've seen this before from GCC and LLVM-GCC because they assume you have an original Pentium III unless told otherwise. Various combinations of -mcpu / -march usually do it, too.

-Gordon

May not be the problem here, but errors similar to that happen in xmmintrin.h when building things with GCC and not specifying -msse2.

Not the same problem. I’ll expand on Eli’s comment…

To expand on this a bit:

By adding this header search path, you are telling Clang to look into GCC’s internal headers. These headers are written directly against the implementation details of GCC at the precise version they ship with GCC. Clang won’t be able to parse these because it’s implementation details are significantly different. Because of this Clang ships with its own internal headers, including ‘xmmintrin.h’, which are implemented using Clang’s implementation details.

These headers are in a different fundamental group from the “system” headers, these are “builtin” headers. That is, they are considered to be built into the compiler itself, and not a separable entity. As such, they cannot be shared between GCC and Clang, unlike the system headers of libstdc++ or Linux in general.