This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug optimization/10392] [3.3/3.4 regression] [SH] optimizer generates faulty array indexing


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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]