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] - Blame information for rev 825

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

Line No. Rev Author Line
1 149 jeremybenn
// { dg-do run }
2
// { dg-options "-O2" }
3
// We used to mis-compile this testcase as we did not know that
4
// &a+offsetof(b,a) was the same as &a.b
5
 
6
struct Iterator {
7
    int * ptr;
8
 
9
    Iterator(int * i) : ptr(i) { }
10
    void operator++() { ++ptr; }
11
    int *const & base() const { return ptr; }
12
};
13
 
14
 
15
Iterator find_7(Iterator first, Iterator last)
16
{
17
  int trip_count  = (last.base() - first.base()) >> 1;
18
 
19
  for ( ; trip_count > 0 ; --trip_count) {
20
    if (*first.ptr == 7) return first;
21
    ++first;
22
 
23
    if (*first.ptr == 7) return first;
24
    ++first;
25
  }
26
 
27
  switch(last.base() - first.base()) {
28
    case 1:
29
          if (*first.ptr == 7) return first;
30
          ++first;
31
    case 0:
32
    default:
33
          return last;
34
  }
35
}
36
 
37
int main() {
38
  int as[5] = {4,4,4,4,7};
39
  return (find_7(Iterator(&as[0]), Iterator(&as[5])).ptr == &as[5]);
40
};
41
 

powered by: WebSVN 2.1.0

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