[cfe-dev] MSVC compiler intrinsics, need for direction.

Douglas Gregor dgregor at apple.com
Wed Oct 6 08:16:16 PDT 2010


On Oct 6, 2010, at 8:07 AM, Francois Pichet wrote:

> On Wed, Oct 6, 2010 at 10:59 AM, Douglas Gregor <dgregor at apple.com> wrote:
>> 
>> On Oct 6, 2010, at 7:58 AM, Francois Pichet wrote:
>> 
>>> I did some research and it will be easier than I thought.
>>> With the exception of __noop and __assume (possibly more), MSVC
>>> intrinsics require a prototype.
>>> So they will be handled like normal functions by clang.
>> 
>> Where does this prototype come from?
> 
> #include <intrin.h>

Interesting!

It may still be worth adding these as builtins, unconditionally. A while back, we learned this lesson when we were apparently miscompiling C code like this:

	int* get_int() {
		return (int*)malloc(sizeof(int));
	}

when <stdlib.h> had not been included. This is valid C89: we got an implicit declaration of "malloc"  that returned an int. Of course, on platforms with 64-bit pointers and 32-bit ints, this means that we silently lost the upper 32 bits of the malloc'd pointer value! While Clang was technically correct in doing this, GCC does what user's expect because it predeclares all of the builtins. So, we made Clang always declare these builtins, and more of the world's code started to work.

You might consider doing the same for the MSVC builtins. I'll leave that decision to you.

	- Doug



More information about the cfe-dev mailing list