From: Mark H Weaver <mhw@netris.org>
To: Miroslav Lichvar <mlichvar@redhat.com>
Cc: guile-devel@gnu.org
Subject: Re: Undefined behavior in conv-integer.i.c?
Date: Mon, 20 Jun 2016 16:07:00 -0400 [thread overview]
Message-ID: <871t3rtyjf.fsf@netris.org> (raw)
In-Reply-To: <874mcysf1v.fsf@netris.org> (Mark H. Weaver's message of "Wed, 24 Feb 2016 03:11:56 -0500")
Mark H Weaver <mhw@netris.org> writes:
> Miroslav Lichvar <mlichvar@redhat.com> writes:
>
>> I was looking at a problem with guile-1.8.8 when compiled with
>> gcc-6.0. Two of the tests from the test suite were failing with
>> strange "out of range" errors [1]. After some investigation I think
>> the bug is that the code in libguile/conv-integer.i.c relies on
>> overflow of signed integers in the following code (starting on line
>> 77), specifically -TYPE_MIN being less than zero. Adding -fwrapv to
>> CFLAGS worked as a workaround for me.
>>
>> if (mpz_sgn (SCM_I_BIG_MPZ (val)) >= 0)
>> {
>> if (n < 0)
>> goto out_of_range;
>> }
>> else
>> {
>> n = -n;
>> if (n >= 0)
>> goto out_of_range;
>> }
>
> Thanks for bringing this to our attention. I've attached a preliminary
> patch to address these issues on the 'stable-2.0' branch.
>
>> Looking at the current guile code, conv-integer.i.c is identical to
>> what it was in 1.8.8, but interestingly the tests didn't fail for me.
>> Maybe something else is preventing gcc from using the optimization?
>
> The build system of recent Guile 2.0.x automatically adds -fwrapv to
> CFLAGS where supported. However, I hope to remove -fwrapv in the
> future, when we gain confidence that no code in Guile depends on it.
>
>> I'm not sure what would be the best way to fix it. Maybe n should
>> really be unsigned and compared to the maximum values, but what would
>> be the absolute value of TYPE_MIN if it should work also with other
>> integer representations than two's complement?
>
> My approach was to compare (abs_n - 1) to -(TYPE_MIN + 1) in the case
> where n is negative.
I pushed these fixes as commit 4b60562820d001674ec7124c4a10391ecf7e44c3
to the stable-2.0 branch, which will become guile-2.0.12.
Thanks,
Mark
prev parent reply other threads:[~2016-06-20 20:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-17 16:16 Undefined behavior in conv-integer.i.c? Miroslav Lichvar
2016-02-24 8:11 ` Mark H Weaver
2016-06-20 20:07 ` Mark H Weaver [this message]
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=871t3rtyjf.fsf@netris.org \
--to=mhw@netris.org \
--cc=guile-devel@gnu.org \
--cc=mlichvar@redhat.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).