* [Bug c++/55885] Modulo operator crashes for int and long variables if they have minimal value
2013-01-06 10:50 [Bug c++/55885] New: Modulo operator crashes for int and long variables if they have minimal value klaus.wieder at endolandia dot de
@ 2013-01-06 11:01 ` schwab@linux-m68k.org
2013-01-06 12:14 ` kwieder at polytechnic dot edu.na
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: schwab@linux-m68k.org @ 2013-01-06 11:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55885
Andreas Schwab <schwab@linux-m68k.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> 2013-01-06 11:01:33 UTC ---
INT_MIN % -1 is undefined due to overflow. -fwrapv has no effect on division
operations.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/55885] Modulo operator crashes for int and long variables if they have minimal value
2013-01-06 10:50 [Bug c++/55885] New: Modulo operator crashes for int and long variables if they have minimal value klaus.wieder at endolandia dot de
2013-01-06 11:01 ` [Bug c++/55885] " schwab@linux-m68k.org
@ 2013-01-06 12:14 ` kwieder at polytechnic dot edu.na
2013-01-06 12:26 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: kwieder at polytechnic dot edu.na @ 2013-01-06 12:14 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55885
--- Comment #2 from kwieder at polytechnic dot edu.na 2013-01-06 12:14:16 UTC ---
Thanks for the quick response.
Why is
INT_MIN % -1
ok
and why is
int b = -1;
INT_MIN % b
not ok.
I"m well aware of INT_MIN / -1 is overflowing. If your are using a division
for the % operator, which you probably do, then INT_MIN % -1 should also crash.
Regards,
Klaus
On Jan 6, 2013, at 1:01 PM, schwab@linux-m68k.org wrote:
> if they have minimal value
>
> Date: Sun, 06 Jan 2013 11:01:33 +0000
>
> X-Bugzilla-Reason: Reporter
>
> X-Bugzilla-Type: changed
>
> X-Bugzilla-Watch-Reason: None
>
> X-Bugzilla-Product: gcc
>
> X-Bugzilla-Component: c++
>
> X-Bugzilla-Keywords:
>
> X-Bugzilla-Severity: normal
>
> X-Bugzilla-Who: schwab@linux-m68k.org
>
> X-Bugzilla-Status: RESOLVED
>
> X-Bugzilla-Priority: P3
>
> X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
>
> X-Bugzilla-Target-Milestone: ---
>
> X-Bugzilla-Changed-Fields: Status Resolution
>
> Message-ID: <bug-55885-22726-Gx0wFhkedU@http.gcc.gnu.org/bugzilla/>
>
> In-Reply-To: <bug-55885-22726@http.gcc.gnu.org/bugzilla/>
>
> References: <bug-55885-22726@http.gcc.gnu.org/bugzilla/>
>
> X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
>
> Auto-Submitted: auto-generated
>
> Content-Type: text/plain; charset="UTF-8"
>
> MIME-Version: 1.0
>
>
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55885
>
>
>
> Andreas Schwab <schwab@linux-m68k.org> changed:
>
>
>
> What |Removed |Added
>
> ----------------------------------------------------------------------------
>
> Status|UNCONFIRMED |RESOLVED
>
> Resolution| |INVALID
>
>
>
> --- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> 2013-01-06 11:01:33 UTC ---
>
> INT_MIN % -1 is undefined due to overflow. -fwrapv has no effect on division
>
> operations.
>
>
>
> --
>
> Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
>
> ------- You are receiving this mail because: -------
>
> You reported the bug.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/55885] Modulo operator crashes for int and long variables if they have minimal value
2013-01-06 10:50 [Bug c++/55885] New: Modulo operator crashes for int and long variables if they have minimal value klaus.wieder at endolandia dot de
2013-01-06 11:01 ` [Bug c++/55885] " schwab@linux-m68k.org
2013-01-06 12:14 ` kwieder at polytechnic dot edu.na
@ 2013-01-06 12:26 ` redi at gcc dot gnu.org
2013-01-06 12:45 ` kwieder at polytechnic dot edu.na
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2013-01-06 12:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55885
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-01-06 12:26:13 UTC ---
Are you asking why undefined behaviour doesn't have consistent results?
http://c-faq.com/ansi/experiment.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/55885] Modulo operator crashes for int and long variables if they have minimal value
2013-01-06 10:50 [Bug c++/55885] New: Modulo operator crashes for int and long variables if they have minimal value klaus.wieder at endolandia dot de
` (2 preceding siblings ...)
2013-01-06 12:26 ` redi at gcc dot gnu.org
@ 2013-01-06 12:45 ` kwieder at polytechnic dot edu.na
2013-01-07 15:34 ` joseph at codesourcery dot com
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: kwieder at polytechnic dot edu.na @ 2013-01-06 12:45 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55885
--- Comment #4 from kwieder at polytechnic dot edu.na 2013-01-06 12:44:42 UTC ---
Hi Jonathan,
According to the the standard C++ implementation
(a % -b) <==> (a % b), therefore
(INT_MIN % -1) <==> (INT_MIN %1) == 0
Neither INT_MIN % -1 nor INT_MIN %1 require a division, therefore there should
be no undefined behaviour in the first place.
Regards,
Klaus
On Jan 6, 2013, at 2:26 PM, redi at gcc dot gnu.org wrote:
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-01-06
12:26:13 UTC ---
Are you asking why undefined behaviour doesn't have consistent results?
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/55885] Modulo operator crashes for int and long variables if they have minimal value
2013-01-06 10:50 [Bug c++/55885] New: Modulo operator crashes for int and long variables if they have minimal value klaus.wieder at endolandia dot de
` (3 preceding siblings ...)
2013-01-06 12:45 ` kwieder at polytechnic dot edu.na
@ 2013-01-07 15:34 ` joseph at codesourcery dot com
2021-08-22 21:52 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: joseph at codesourcery dot com @ 2013-01-07 15:34 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55885
--- Comment #5 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2013-01-07 15:34:34 UTC ---
INT_MIN % -1 and INT_MIN / -1 *should* be made defined by -fwrapv; that's
bug 30484.
Without -fwrapv, C11 made explicit the intent that the modulo operation is
undefined in the cases where division is undefined ("If the quotient a/b
is representable, the expression (a/b)*b + a%b shall equal a; otherwise,
the behavior of both a/b and a%b is undefined."); I don't know about C++.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/55885] Modulo operator crashes for int and long variables if they have minimal value
2013-01-06 10:50 [Bug c++/55885] New: Modulo operator crashes for int and long variables if they have minimal value klaus.wieder at endolandia dot de
` (4 preceding siblings ...)
2013-01-07 15:34 ` joseph at codesourcery dot com
@ 2021-08-22 21:52 ` pinskia at gcc dot gnu.org
2021-08-22 21:53 ` pinskia at gcc dot gnu.org
2021-08-22 21:56 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-22 21:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55885
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jens.seifert at de dot ibm.com
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 93013 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/55885] Modulo operator crashes for int and long variables if they have minimal value
2013-01-06 10:50 [Bug c++/55885] New: Modulo operator crashes for int and long variables if they have minimal value klaus.wieder at endolandia dot de
` (5 preceding siblings ...)
2021-08-22 21:52 ` pinskia at gcc dot gnu.org
@ 2021-08-22 21:53 ` pinskia at gcc dot gnu.org
2021-08-22 21:56 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-22 21:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55885
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note PR 30484 is for the -fwrapv issue with %.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/55885] Modulo operator crashes for int and long variables if they have minimal value
2013-01-06 10:50 [Bug c++/55885] New: Modulo operator crashes for int and long variables if they have minimal value klaus.wieder at endolandia dot de
` (6 preceding siblings ...)
2021-08-22 21:53 ` pinskia at gcc dot gnu.org
@ 2021-08-22 21:56 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-22 21:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55885
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |Eric.Deplagne at nerim dot net
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 29511 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 9+ messages in thread