Hi all.

I hope this is the right place to ask the question.

I found a test case that makes almost all (GCC-5.1 above) versions
(may) produce the wrong code at -Os.

So, I am confused here whether this test case is well-defined or not.

Here is the program (small.c):
```
#include <stdint.h>
#include <stdio.h>
int16_t a;
uint8_t func_2();
static int32_t func_1() { func_2();}
uint8_t func_2(int p) {
int32_t b[4][9] = {{0}, {0}, {0}, 1L};
for (;; a ++) {
for (;;) {
if (p)
break;
return p;
}
p = b[3][1];
}
return 0;
}
int main() {
func_1();
printf("%d\n", a);
return 0;
}
```
```
$gcc -O1 small.c ; ./a.out
0
$gcc -Os small.c ; ./a.out
1
```

I tested it on today's trunk version of GCC, please also check here for
more results for different versions: https://godbolt.org/z/3nfv9vaY8

My confusion is that whether the called function "func_2()" inside the
"func_1" is defined or not.

Can anyone help me to figure it out?

If it's a well-defined program, I will open a bug report.

Thank you very much and looking forward to hearing from you!


Best regards,
Haoxin

Reply via email to