gcl-devel
[Top][All Lists]
Advanced

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

Re: gcc-12 miscompilation


From: Camm Maguire
Subject: Re: gcc-12 miscompilation
Date: Sat, 07 Jan 2023 13:08:14 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

Greetings, and thanks so much for the article.  All I can say is that
this is backward incompatible behavior for gcc going back decades, but I
can see from the flags you point out that it is deliberate and not a
mistake, hence not likely to be 'fixed'.  We will therefore have to work
with it, and the good news is that some simple constant redefinitions
appear to restore intended behavior in preliminary testing (relying on
c99 specifying that signed + unsigned coerces the signed to unsigned).
I also tried compiling/linking gcl with -fsanitize=unsigned, but the
resulting binary could not be run, triggering the OOM killer.

Take care,

Jerry James <loganjerry@gmail.com> writes:

> On Sat, Dec 24, 2022 at 3:27 PM Camm Maguire <camm@maguirefamily.org> wrote:
>> Greetings, and thank you so much for pinning down the offending
>> optimization flag, reducing the bug report, and forwarding the response!
>>
>> I'm not convinced (yet at least) that this code being classified as
>> 'undefined' means gcc is not in error.  Signed and unsigned integer
>> arithmetic of any precision is defined in C to loop around extremal
>> values, i.e. to act as modular operations.  This code acknowledges this
>> and relies upon it -- runtime 'overflows' are not a mistake.  Perhaps
>> there is some better syntax to make this clear?
>
> My understanding is that *unsigned* integer overflow is well-defined,
> and simply wraps around as you describe.  *Signed* integer overflow,
> on the other hand, is undefined behavior.  This article supports that
> view: https://en.wikipedia.org/wiki/Integer_overflow (see the section
> on "Inconsistent behavior").  This also means that, while
> -fno-tree-vrp may cause the symptoms to disappear, the correct flag to
> use is -fwrapv.  Better would be to make sure that overflow only
> happens for unsigned integer operations.
>
> Regards,

-- 
Camm Maguire                                        camm@maguirefamily.org
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah



reply via email to

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