[LLVMdev] MallocInst/CallInst bitcast,

Daniel Waterworth da.waterworth at googlemail.com
Sat Oct 17 00:34:04 PDT 2009


2009/10/16 srs <skaflotten at gmail.com>

> Daniel Waterworth skrev:
>
>> Thanks very much. I only have one more question, (hopefully), which is, is
>> there a better way of finding the direction of stack growth other than:
>>
>> static bool StackCmp(void *ptr) {
>>  volatile int a;
>>  return (void *)&a > ptr;
>> }
>>
>> bool FindStackDirection() {
>>  volatile int a;
>>  return StackCmp((void *)&a);
>> }
>>
>> Preferably one which isn't destroyed by optimization.
>>
>
> I suggest you turn the scalars into arrays and make the ptr argument
> volatile as well.
>
> Other ways: If you are careful with tail recursion eliminiation, you can
> compare local var addresses from different recursive calls. I believe there
> are va_arg based approaches as well.
>
> That said, there is no truly portable way.
>
> /Stein Roger
>

I've changed the ptr argument to volatile and the StackCmp function to
noinline. It's now providing the correct answer in gcc and llvm-gcc with
optimization on -O3. This will suite my puposes, at least for the time
being.

Thanks alot,

Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091017/52ef2df0/attachment.html>


More information about the llvm-dev mailing list