unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: "Andrew W. Nosenko" <andrew.w.nosenko@gmail.com>
To: Andy Wingo <wingo@pobox.com>
Cc: bug-guile <bug-guile@gnu.org>, bug-autoconf@gnu.org
Subject: Re: bug in check for stack growth direction in _AC_LIBOBJ_ALLOCA
Date: Mon, 20 Jun 2011 13:24:31 +0300	[thread overview]
Message-ID: <BANLkTi=i9dbYzjiMZ8N3jxGh_bFeb78Jnw@mail.gmail.com> (raw)
In-Reply-To: <BANLkTikSZYyw24jt3-L_UcG1RoCGw-wWgA@mail.gmail.com>

On Mon, Jun 20, 2011 at 11:25, Andrew W. Nosenko
<andrew.w.nosenko@gmail.com> wrote:
> On Sun, Jun 19, 2011 at 22:03, Andy Wingo <wingo@pobox.com> wrote:
>> Hi,
>>
>> On Sat 18 Jun 2011 22:25, "Andrew W. Nosenko" <andrew.w.nosenko@gmail.com> writes:
>>
>>> On Fri, Jun 17, 2011 at 13:21, Andy Wingo <wingo@pobox.com> wrote:
>>>>  wingo@badger:/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 <andrew.w.nosenko@gmail.com>



  reply	other threads:[~2011-06-20 10:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-17 10:21 bug in check for stack growth direction in _AC_LIBOBJ_ALLOCA Andy Wingo
2011-06-18 20:25 ` Andrew W. Nosenko
2011-06-19 19:03   ` Andy Wingo
2011-06-20  8:25     ` Andrew W. Nosenko
2011-06-20 10:24       ` Andrew W. Nosenko [this message]
2011-06-18 21:42 ` Paul Eggert
2011-06-19 19:01   ` Andy Wingo
2011-06-20  5:35     ` Paul Eggert
2011-06-20  6:35       ` Ralf Wildenhues
2011-06-20  6:50         ` Paul Eggert
2011-06-20  8:18           ` Andrew W. Nosenko
2011-06-20  8:01       ` Andy Wingo
2011-06-20 17:54       ` Eric Blake
2011-06-20 22:19         ` Paul Eggert
2011-06-21 19:43           ` Ralf Wildenhues
2011-06-21 20:08             ` Paul Eggert
2011-06-20 17:56 ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='BANLkTi=i9dbYzjiMZ8N3jxGh_bFeb78Jnw@mail.gmail.com' \
    --to=andrew.w.nosenko@gmail.com \
    --cc=bug-autoconf@gnu.org \
    --cc=bug-guile@gnu.org \
    --cc=wingo@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).