[Bug optimization/14029] [tree-ssa] Miscompilation of unrolled loop

bangerth at dealii dot org gcc-bugzilla@gcc.gnu.org
Thu Feb 5 18:37:00 GMT 2004


------- Additional Comments From bangerth at dealii dot org  2004-02-05 18:36 -------
OK, here's something smaller: 
----------------------------- 
struct Iterator { 
    int * ptr; 
 
    Iterator(int * i) : ptr(i) { } 
    void operator++() { ++ptr; } 
    int *const & base() const { return ptr; } 
}; 
 
 
Iterator find_7(Iterator first, Iterator last) 
{ 
  int trip_count  = (last.base() - first.base()) >> 1; 
 
  for ( ; trip_count > 0 ; --trip_count) { 
    if (*first.ptr == 7) return first; 
    ++first; 
 
    if (*first.ptr == 7) return first; 
    ++first; 
  } 
 
  switch(last.base() - first.base()) { 
    case 1: 
          if (*first.ptr == 7) return first; 
          ++first; 
    case 0: 
    default: 
          return last; 
  } 
} 
 
int main() { 
  int as[5] = {4,4,4,4,7};   
  return (find_7(Iterator(&as[0]), Iterator(&as[5])).ptr == &as[5]); 
}; 
------------------------ 
 
The function find_7 is miscompiled: 
g/x> /home/bangerth/bin/gcc-tree-ssa/bin/c++ x.cc && ./a.out ; echo $? 
0 
g/x> /home/bangerth/bin/gcc-tree-ssa/bin/c++ x.cc -O2 && ./a.out ; echo $? 
1 
 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |wrong-code
      Known to work|                            |3.4.0 3.5.0 3.3.3
   Last reconfirmed|0000-00-00 00:00:00         |2004-02-05 18:37:03
               date|                            |
            Summary|[tree-ssa] wrong-code       |[tree-ssa] Miscompilation of
                   |                            |unrolled loop
   Target Milestone|---                         |tree-ssa


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14029



More information about the Gcc-bugs mailing list