OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [g++.dg/] [opt/] [pr14029.C] - Rev 154

Go to most recent revision | Compare with Previous | Blame | View Log

// { dg-do run }
// { dg-options "-O2" }
// We used to mis-compile this testcase as we did not know that
// &a+offsetof(b,a) was the same as &a.b

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]);
};

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.