bug-autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug in check for stack growth direction in _AC_LIBOBJ_ALLOCA


From: Andrew W. Nosenko
Subject: Re: bug in check for stack growth direction in _AC_LIBOBJ_ALLOCA
Date: Mon, 20 Jun 2011 13:24:31 +0300

On Mon, Jun 20, 2011 at 11:25, Andrew W. Nosenko
<address@hidden> wrote:
> On Sun, Jun 19, 2011 at 22:03, Andy Wingo <address@hidden> wrote:
>> Hi,
>>
>> On Sat 18 Jun 2011 22:25, "Andrew W. Nosenko" <address@hidden> writes:
>>
>>> On Fri, Jun 17, 2011 at 13:21, Andy Wingo <address@hidden> wrote:
>>>> address@hidden:/tmp$ cat foo.c
>>>>  int
>>>>  find_stack_direction ()
>>>>  {
>>>>    static char *addr = 0;
>>>
>>> Try to rewrite this line as
>>>         volatile static char *addr = 0;
>>> It should help.
>>
>> It didn't, unfortunately.
>
> You are right.  I marked the underlying char as volatile instead of
> the pointer itself.
> The proper version seems
>    static char* volatile addr;
> but ATM I have no compiler around for verify that.
>

The
    static char* volatile addr;
doesn't help also.

Gcc continues to think that it has rights to inline the inner
find_stack_direction() and messes the check as consequence.

Solution: make Gcc unable to inline the function call.

One of possible ways to achieve it: call the inner through volatile pointer.

typedef int (*func_t)();
int find_stack_direction ();

volatile func_t f = &find_stack_direction;

int
find_stack_direction ()
{
    static char *addr = 0;
    auto char dummy;
    if (addr == 0)
    {
        addr = &dummy;
        return f();
    }
    else
        return (&dummy > addr) ? 1 : -1;
}

int
main ()
{
    int r = find_stack_direction ();
    return r < 0;
}


It's not the single way, but just first that come to minds.

-- 
Andrew W. Nosenko <address@hidden>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]