Article View: gnu.gcc.bug
Article #533Bug in GCC 1.35 WRT to optimizing constant switch statements
From: Michael Meissner
Date: Mon, 14 Aug 1989 22:05
Date: Mon, 14 Aug 1989 22:05
44 lines
1614 bytes
1614 bytes
Ron Guilmette found a bug in the way GCC 1.35 handles optimizing
switch statements whose index is constant and negative. The problem
is in stmt.c when the constant is converted to tree form, it is not
sign extended, so that later on, it won't match the appropriate case
label. Here is a sample program that demonstrates this (you must
optimize it):
int main ()
{
int num;
switch (num = -1) {
case -1:
exit (0);
case 0:
exit (1);
default:
printf ("wrong case selected\n");
exit (2);
}
}
Here is a patch to fix the problem (your line numbers will vary):
*** stmt.c.orig Mon Aug 14 16:22:06 1989
--- stmt.c Mon Aug 14 17:53:51 1989
***************
*** 2509,2515 ****
if we don't already have one. */
if (TREE_CODE (index_expr) != INTEGER_CST)
{
! index_expr = build_int_2 (INTVAL (index), 0);
index_expr = convert (TREE_TYPE (index_expr), index_expr);
}
--- 2509,2516 ----
if we don't already have one. */
if (TREE_CODE (index_expr) != INTEGER_CST)
{
! index_expr = build_int_2 (INTVAL (index),
! INTVAL (index) >= 0 ? 0 : -1);
index_expr = convert (TREE_TYPE (index_expr), index_expr);
}
Technical Details
Message-ID:
<8908142205.AA07807@tiktok.dg.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watmath!iuvax!cica!tut.cis.ohio-state.edu!DG-RTP.DG.COM!meissnerShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!iuvax!cica!tut.cis.ohio-state.edu!DG-RTP.DG.COM!meissner From: meissner@DG-RTP.DG.COM (Michael Meissner) Newsgroups: gnu.gcc.bug Subject: Bug in GCC 1.35 WRT to optimizing constant switch statements Message-ID: <8908142205.AA07807@tiktok.dg.com> Date: 14 Aug 89 22:05:34 GMT Distribution: gnu Organization: GNUs Not Usenet Lines: 44