OSDN Git Service

2004-05-20 H.J. Lu <hongjiu.lu@intel.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / pr10392-1.c
1 /* PR optimization/10392
2  * Reporter: marcus@mc.pp.se
3  * Summary: [3.3/3.4 regression] [SH] optimizer generates faulty array indexing
4  * Description:
5  * The address calculation of an index operation on an array on the stack 
6  * can _under some conditions_ get messed up completely
7  *
8  * Testcase tweaked by dank@kegel.com
9  * Problem only happens with -O2 -m4, so it should only happen on sh4,
10  * but what the heck, let's test other architectures, too.
11  * Not marked as xfail since it's a regression.
12 */
13 /* { dg-do run } */
14 /* { dg-options "-O2" } */
15 /* { dg-options "-O2 -m4" { target sh4-*-* } } */
16 const char *dont_optimize_function_away;
17
18 const char *use(const char *str)
19 {
20         dont_optimize_function_away = str;
21         if (str[0] != 'v')
22                 abort();
23         if (str[1] < '1' || str[1] > '6')
24                 abort();
25         if (str[2])
26                 abort();
27         return str[2] ? "notused" : "v6";
28 }
29
30 const char *func(char *a, char *b)
31 {
32         char buf[128];
33         unsigned char i;
34         const char *result;
35
36         char *item[] = {
37                 "v1",
38                 "v2",
39         };
40
41         buf[0] = 'v';
42         buf[1] = '3';
43         buf[2] = 0;
44
45         for (i = 0; i < 2; i++) {
46                 /* bug is: following line passes wild pointer to use() on sh4 -O2 */
47                 result = use(item[i]);
48
49                 use(buf);
50                 use(a);
51                 use(b);
52                 result = use(result);
53         }
54         return result;
55 }
56
57 int main()
58 {
59         func("v4", "v5");
60         return 0;
61 }
62