This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug optimization/10392] [3.3/3.4 regression] [SH] optimizer generates faulty array indexing
- From: "dkegel at ixiacom dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 12 Sep 2003 23:08:54 -0000
- Subject: [Bug optimization/10392] [3.3/3.4 regression] [SH] optimizer generates faulty array indexing
- References: <20030413145600.10392.marcus@mc.pp.se>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10392
------- Additional Comments From dkegel at ixiacom dot com 2003-09-12 23:08 -------
OK, how 'bout this? This reproduces the crash nicely,
and should be ready to check in as a dg testcase.
/* PR optimization/10392
* [3.3/3.4 regression] [SH] optimizer generates faulty array indexing
* The address calculation of an index operation on an array on the stack
* can _under some conditions_ get messed up completely
*/
/* { dg-do run } */
const char *foo;
const char *use(const char *str)
{
foo = str;
return str[0] ? "apple" : "bannana";
}
const char *func(char *a, char *b)
{
char buf[128];
unsigned char i;
const char *result;
char *item[] = {
"one",
"two",
};
buf[0] = 'b';
buf[1] = 0;
for (i = 0; i < 2; i++) {
/* bug is: following line crashes with SIGSEGV on sh4 -O2 */
result = use(item[i]);
use(buf);
use(a);
use(b);
result = use(result);
}
return result;
}
int main()
{
/* func never returns zero, so this will always exit with status 0,
* but the optimizer doesn't know that
*/
return func("a", "b") != 0;
}