This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug optimization/1823] -ftrapv aborts with pointer difference due to division optimization


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]