| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-O2 -fdump-tree-optimized -std=gnu89" } */ |
| 3 |
|
| 4 |
extern void link_error (void); |
| 5 |
|
| 6 |
|
| 7 |
/* check that cprop for variables of different types still works even |
| 8 |
if function calls or assignments to different types of data are |
| 9 |
interposed. */ |
| 10 |
|
| 11 |
int test7 (int *intarr) |
| 12 |
{ |
| 13 |
extern int foo7 (int); |
| 14 |
int u = 7, v1; |
| 15 |
foo7 (u); |
| 16 |
v1 = u; |
| 17 |
if (v1 != 7) |
| 18 |
link_error (); |
| 19 |
return v1; |
| 20 |
} |
| 21 |
|
| 22 |
int test77 (int *arr) |
| 23 |
{ |
| 24 |
int u = 7, v1; |
| 25 |
arr[0] = 4; |
| 26 |
v1 = u; |
| 27 |
if (v1 != 7) |
| 28 |
link_error (); |
| 29 |
return v1 + arr[0]; |
| 30 |
} |
| 31 |
|
| 32 |
int test777 (void) |
| 33 |
{ |
| 34 |
extern int foo(int *); |
| 35 |
int u = 7, v1; |
| 36 |
static int sarr[10]; |
| 37 |
sarr[0] = 4; |
| 38 |
v1 = u; |
| 39 |
if (v1 != 7) |
| 40 |
link_error (); |
| 41 |
foo (sarr); |
| 42 |
return v1 + sarr[0]; |
| 43 |
} |
| 44 |
|
| 45 |
int garr[10]; |
| 46 |
int test7777 (void) |
| 47 |
{ |
| 48 |
int u = 7, v1; |
| 49 |
garr[0] = 4; |
| 50 |
v1 = u; |
| 51 |
if (v1 != 7) |
| 52 |
link_error (); |
| 53 |
return v1 + garr[0]; |
| 54 |
} |
| 55 |
|
| 56 |
int test88 (int *arr) |
| 57 |
{ |
| 58 |
static int l; |
| 59 |
int v1; |
| 60 |
l = 8; |
| 61 |
arr[0] = 4; |
| 62 |
v1 = l; |
| 63 |
if (v1 != 8) |
| 64 |
link_error (); |
| 65 |
l = foo88 (l); |
| 66 |
return v1 + arr[0]; |
| 67 |
} |
| 68 |
|
| 69 |
int test888 (void) |
| 70 |
{ |
| 71 |
static int l; |
| 72 |
extern int foo(int *); |
| 73 |
int v1; |
| 74 |
static int sarr[10]; |
| 75 |
l = 8; |
| 76 |
sarr[0] = 4; |
| 77 |
v1 = l; |
| 78 |
if (v1 != 8) |
| 79 |
link_error (); |
| 80 |
foo (sarr); |
| 81 |
l = foo88(l); |
| 82 |
return v1 + sarr[0]; |
| 83 |
} |
| 84 |
|
| 85 |
int test8888 (void) |
| 86 |
{ |
| 87 |
static int l; |
| 88 |
int v1; |
| 89 |
l = 8; |
| 90 |
garr[0] = 4; |
| 91 |
v1 = l; |
| 92 |
if (v1 != 8) |
| 93 |
link_error (); |
| 94 |
return v1 + garr[0]; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
/* global var */ |
| 100 |
int g9; |
| 101 |
int garr9[10]; |
| 102 |
int test9 (int *intarr) |
| 103 |
{ |
| 104 |
extern int foo9 (int) __attribute__ ((const)); |
| 105 |
int h, v; |
| 106 |
g9 = 9; |
| 107 |
h = foo9 (g9); |
| 108 |
v = g9; |
| 109 |
if (v != 9) |
| 110 |
link_error (); |
| 111 |
return g9; |
| 112 |
} |
| 113 |
|
| 114 |
int test99 (int *intarr) |
| 115 |
{ |
| 116 |
extern int foo99 (int) __attribute__ ((pure)); |
| 117 |
int h, v; |
| 118 |
g9 = 9; |
| 119 |
h = foo99 (g9); |
| 120 |
v = g9; |
| 121 |
if (v != 9) |
| 122 |
link_error (); |
| 123 |
return g9; |
| 124 |
} |
| 125 |
|
| 126 |
/* foo9 is const because of its declaration in test9. */ |
| 127 |
extern int foo9 (int); |
| 128 |
|
| 129 |
int test999 (int *arr) |
| 130 |
{ |
| 131 |
static int l; |
| 132 |
int v1; |
| 133 |
g9 = 9; |
| 134 |
l = 4; |
| 135 |
v1 = g9; |
| 136 |
if (v1 != 9) |
| 137 |
link_error (); |
| 138 |
l = foo9 (l); |
| 139 |
return v1 + l; |
| 140 |
} |
| 141 |
|
| 142 |
/* foo99 is pure because of its declaration in test99. */ |
| 143 |
extern int foo9 (int); |
| 144 |
|
| 145 |
int test9999 (void) |
| 146 |
{ |
| 147 |
int v1; |
| 148 |
static int sarr[10]; |
| 149 |
g9 = 9; |
| 150 |
sarr[0] = 4; |
| 151 |
v1 = g9; |
| 152 |
if (v1 != 9) |
| 153 |
link_error (); |
| 154 |
foo (sarr); |
| 155 |
g9 = foo99 (g9); |
| 156 |
return v1 + sarr[0]; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
int test99999 (void) |
| 161 |
{ |
| 162 |
int v1; |
| 163 |
g9 = 9; |
| 164 |
garr9[0] = 4; |
| 165 |
v1 = g9; |
| 166 |
if (v1 != 9) |
| 167 |
link_error (); |
| 168 |
return v1 + garr9[0]; |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
/* There should be not link_error calls, if there is any the |
| 173 |
optimization has failed */ |
| 174 |
/* { dg-final { scan-tree-dump-times "link_error" 0 "optimized"} } */ |