Differences between linux and macosx

Hi,

I'm getting a weird error in Linux (gentoo) that doesn't happen in MacOS X:

filcab@escher ~ $ cat b.c
#include <alloca.h>
int main ()
{
   char *p = (char *) alloca (2 * sizeof (int));
   if (p) return 0;
   return 0;
}

filcab@escher ~ $ gcc b.c
filcab@escher ~ $ ccc b.c
b.c
clang -emit-llvm-bc -o b.o b.c
clang: Instructions.cpp:713: llvm::Value* getAISize(llvm::Value*): Assertion `Amt->getType() == Type::Int32Ty && "Malloc/Allocation array size is not a 32-bit integer!"' failed.
clang[0x969ddf]
clang[0x969f00]
/lib/libc.so.6[0x2acbb7d18320]

...

in macosx, clang just happily compiles:
[filcab@farnsworth ~] $ cat b.c
#include <alloca.h>

int main(int argc, char **argv)
{
   char *p = alloca(2 * sizeof(int));
   if (p) return 0;
   return 0;
}

[filcab@farnsworth ~] $ ccc b.c
b.c
clang -emit-llvm-bc -o b.o b.c
llvm-ld -native -disable-internalize -o a.out b.o
[filcab@farnsworth ~] $

They both define alloca(size) to __builtin_alloca(size) after defining a prototype for the function and then checking for __GNUC__.

   - Filipe Cabecinhas

Is you Linux install x86-64? CodeGen is mostly untested outside of
regular x86. (You can override the target triple on the commandline.)

That said, it should be easy to always truncate the size argument to
the LLVM alloca to 32 bits.

-Eli

Fixed:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20080616/006124.html

Thanks!

-Chris

Thanks

But why didn't it happen in Mac OS X? Are ints 32 bits in macosx and 64 in linux?

   - Filipe Cabecinhas

size_t is 32-bits on a 32-bit platform.

-Chris

So, I suppose only code compiled with 64-bits (through -m64 which seems default on linux but not on macosx) would have that error.
And ccc will just ignore -m64 when I pass it because it doesn't error (on macosx) nor does it produce 64-bit code.

Is there a way to make it produce 64-bit code?

   - Filipe Cabecinhas

Oh right. This was certainly a problem on darwin/x86-64, it's just that darwin defaults to 32-bit. You can use "-arch x86_64" to get x86-64 codegen (though this is not well tested). I agree that -m64 and -m32 should also work, of course.

-Chris