public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17645] Add a warning for potentially unsafe unsigned operations
[not found] <20040924041536.17645.mathieu@malaterre.com>
@ 2005-07-06 2:32 ` mathieu at malaterre dot com
2005-07-06 2:34 ` [Bug c/17645] " pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: mathieu at malaterre dot com @ 2005-07-06 2:32 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From mathieu at malaterre dot com 2005-07-06 02:32 -------
Using gcc --version:
g++ (GCC) 4.1.0 20050607 (experimental)
I still cannot get anything using the -ftrapv:
Ex is:
#include <iostream>
int main()
{
const unsigned int a = 11;
const unsigned int b = 10;
const double t = 0.5;
const unsigned int c = a + t * (b -a);
std::cout << "c=" << c << std::endl;
const unsigned int d = (1.0 - t) * a + t * b;
std::cout << "d=" << d << std::endl;
return 0;
}
compile line:
$ /usr/lib/gcc-snapshot/bin/g++ -O3 -ftrapv test.c
$ ./a.out
c=2147483658
d=10
It looks like -ftrapv only works on signed overflow.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17645
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/17645] Add a warning for potentially unsafe unsigned operations
[not found] <20040924041536.17645.mathieu@malaterre.com>
2005-07-06 2:32 ` [Bug c++/17645] Add a warning for potentially unsafe unsigned operations mathieu at malaterre dot com
@ 2005-07-06 2:34 ` pinskia at gcc dot gnu dot org
2005-07-06 2:59 ` [Bug c++/17645] " mathieu at malaterre dot com
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-06 2:34 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-07-06 02:33 -------
(In reply to comment #6)
> It looks like -ftrapv only works on signed overflow.
Yes because signed overflow is undefined. unsigned overflow wraps by both the C and C++ standards.
--
What |Removed |Added
----------------------------------------------------------------------------
Component|c++ |c
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17645
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/17645] Add a warning for potentially unsafe unsigned operations
[not found] <20040924041536.17645.mathieu@malaterre.com>
2005-07-06 2:32 ` [Bug c++/17645] Add a warning for potentially unsafe unsigned operations mathieu at malaterre dot com
2005-07-06 2:34 ` [Bug c/17645] " pinskia at gcc dot gnu dot org
@ 2005-07-06 2:59 ` mathieu at malaterre dot com
2005-07-06 3:00 ` [Bug c/17645] " mathieu at malaterre dot com
2005-07-15 20:22 ` falk at debian dot org
4 siblings, 0 replies; 6+ messages in thread
From: mathieu at malaterre dot com @ 2005-07-06 2:59 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From mathieu at malaterre dot com 2005-07-06 02:59 -------
Using gcc --version:
g++ (GCC) 4.1.0 20050607 (experimental)
I can still reproduce the same unsafe operation:
#include <iostream>
int main()
{
unsigned int l = (unsigned int)-1;
const int a = l/2;
const int b = l/2+1;
const double t = 0.5;
const int c = a + t * (b -a);
std::cout << "c=" << c << std::endl;
const int d = (1.0 - t) * a + t * b;
std::cout << "d=" << d << std::endl;
return 0;
}
$ /usr/lib/gcc-snapshot/bin/g++ -O3 -ftrapv test.c
$ ./a.out
c=2147483647
d=0
I cannot seems to find a way to generate traps on overflow.
--
What |Removed |Added
----------------------------------------------------------------------------
Component|c |c++
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17645
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/17645] Add a warning for potentially unsafe unsigned operations
[not found] <20040924041536.17645.mathieu@malaterre.com>
` (2 preceding siblings ...)
2005-07-06 2:59 ` [Bug c++/17645] " mathieu at malaterre dot com
@ 2005-07-06 3:00 ` mathieu at malaterre dot com
2005-07-15 20:22 ` falk at debian dot org
4 siblings, 0 replies; 6+ messages in thread
From: mathieu at malaterre dot com @ 2005-07-06 3:00 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From mathieu at malaterre dot com 2005-07-06 03:00 -------
Using gcc --version:
g++ (GCC) 4.1.0 20050607 (experimental)
I can still reproduce the same unsafe operation:
#include <iostream>
int main()
{
unsigned int l = (unsigned int)-1;
const int a = l/2;
const int b = l/2+1;
const double t = 0.5;
const int c = a + t * (b -a);
std::cout << "c=" << c << std::endl;
const int d = (1.0 - t) * a + t * b;
std::cout << "d=" << d << std::endl;
return 0;
}
$ /usr/lib/gcc-snapshot/bin/g++ -O3 -ftrapv test.c
$ ./a.out
c=2147483647
d=0
I cannot seems to find a way to generate traps on overflow.
--
What |Removed |Added
----------------------------------------------------------------------------
Component|c++ |c
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17645
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/17645] Add a warning for potentially unsafe unsigned operations
[not found] <20040924041536.17645.mathieu@malaterre.com>
` (3 preceding siblings ...)
2005-07-06 3:00 ` [Bug c/17645] " mathieu at malaterre dot com
@ 2005-07-15 20:22 ` falk at debian dot org
4 siblings, 0 replies; 6+ messages in thread
From: falk at debian dot org @ 2005-07-15 20:22 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From falk at debian dot org 2005-07-15 19:53 -------
(In reply to comment #9)
> I cannot seems to find a way to generate traps on overflow.
-ftrapv does not trigger on overflowing calculations that are compile-time
constant. I am unsure whether this is a bug or a feature.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17645
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/17645] Add a warning for potentially unsafe unsigned operations
[not found] <bug-17645-9357@http.gcc.gnu.org/bugzilla/>
@ 2006-08-07 20:25 ` mathieu at malaterre dot com
0 siblings, 0 replies; 6+ messages in thread
From: mathieu at malaterre dot com @ 2006-08-07 20:25 UTC (permalink / raw)
To: gcc-bugs
------- Comment #11 from mathieu at malaterre dot com 2006-08-07 20:25 -------
Tested today (Aug 7, 2006) with:
$ /usr/lib/gcc-snapshot/bin/g++ --version
/tmp
g++ (GCC) 4.2.0 20060721 (experimental)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ /usr/lib/gcc-snapshot/bin/g++ -Wall -ftrapv bla.cxx
$ ./a.out
[1] 24229 abort ./a.out
Marking the bug fixed. Thank you !
--
mathieu at malaterre dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17645
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-08-07 20:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20040924041536.17645.mathieu@malaterre.com>
2005-07-06 2:32 ` [Bug c++/17645] Add a warning for potentially unsafe unsigned operations mathieu at malaterre dot com
2005-07-06 2:34 ` [Bug c/17645] " pinskia at gcc dot gnu dot org
2005-07-06 2:59 ` [Bug c++/17645] " mathieu at malaterre dot com
2005-07-06 3:00 ` [Bug c/17645] " mathieu at malaterre dot com
2005-07-15 20:22 ` falk at debian dot org
[not found] <bug-17645-9357@http.gcc.gnu.org/bugzilla/>
2006-08-07 20:25 ` mathieu at malaterre dot com
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).