This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug optimization/1823] -ftrapv aborts with pointer difference due to division optimization
- From: "falk at debian dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Jul 2003 17:09:29 -0000
- Subject: [Bug optimization/1823] -ftrapv aborts with pointer difference due to division optimization
- References: <20010131120600.1823.meeberdt@unity.ncsu.edu>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=1823
falk at debian dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|CLOSED |REOPENED
Component|libstdc++ |optimization
Resolution|FIXED |
Summary|program compiled with - |-ftrapv aborts with pointer
|ftrapv aborts in |difference due to division
|std::queue<>.size() |optimization
Version|3.0 |3.4
------- Additional Comments From falk at debian dot org 2003-07-06 17:09 -------
Here's a test case (works for me on alpha-linux mainline):
struct s { char c[3]; };
__PTRDIFF_TYPE__ frob (struct s *cur, struct s *last) {
return last - cur;
}
int main (void) {
struct s a[17];
if (frob(a, a + 17) != 17)
abort ();
return 0;
}
The problem is caused by the optimization of the division by three to a
multiplication with 0xaaaaaaaaaaaaaaab; this works since the difference
is known to be a multiple of 3.
However, the multiplication is done with a trapping instruction:
subq/v a1,a0,t2
ldq t3,32256(t0) # 0xaaaaaaaaaaaaaaab
mulq/v t2,t3,v0 # traps
ret