blob: 3fee937f1c15dafd96170218a60f3b16cc2ab9d4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// This testcase was miscompiled on s390x, because strength-reduction
// did not see biv in C::foo as used after loop, but it was used
// in a REG_EQUAL note.
// { dg-do run }
// { dg-options "-O2" }
extern "C" void abort (void);
struct C
{
int foo (char ch, int offset = __INT_MAX__) const;
int bar (int offset, char c) const;
const char *a;
};
int C::bar (int offset, char c) const
{
char ch = a[offset];
if (ch < c)
return -1;
if (ch > c)
return 1;
return 0;
}
int C::foo (char ch, int offset) const
{
int len = __builtin_strlen (a);
if (len == 0)
return __INT_MAX__;
if (offset >= len)
offset = len - 1;
while (bar (offset, ch) != 0)
{
if (offset == 0)
return __INT_MAX__;
offset--;
}
return offset;
}
int main (void)
{
C c;
c.a = "/some/dir/file.ext";
if (c.foo ('/') != 9)
abort ();
return 0;
}
|