delorie.com/archives/browse.cgi   search  
Mail Archives: pgcc/1999/10/22/17:41:24

Message-Id: <3.0.5.32.19991022211417.00793ac0@voruta.vu.lt>
X-Sender: rp010gf AT voruta DOT vu DOT lt (Unverified)
X-Mailer: QUALCOMM Windows Eudora Light Version 3.0.5 (32)
Date: Fri, 22 Oct 1999 21:14:17 +0200
To: pgcc AT Delorie DOT com
From: Rimantas Plaipa <Rimantas DOT Plaipa AT gf DOT vu DOT lt>
Subject: Optimization bug in certain switch statements
Mime-Version: 1.0
Reply-To: pgcc AT delorie DOT com

Once I'd tried to use pgcc-1.1.3 to compile mailx for Intel Linux-2.2.x
with glibc2 but the final executable segfaulted on the start while one
compiled with egcs-1.1.2 ran correctly. Now I've checked pgcc-2.95.1 but
the bug is still here. I localized the bug and made the striped example
which looks like that:
------------------------
#include <stdlib.h>

int aa=0x81;

int main(){
        short a=aa;
        if(a==1)return printf("");
        switch(a & (~0x0FF0)){ 
                case 0:printf("2\n");break;
                case 1:printf("right\n");break;
                case 2:printf("2\n");break;
                case 3:printf("3\n");break;
                case 4:printf("4\n");break;
                default:printf("wrong\n");
        }
        return 0;
}
--------------------------------

If the example is compiled without optimization the result of execution is
"right", with -O , -O2 - "wrong".

What's especially funny, if the line with the switch statement is replaced
by the seemingly equivalent statement:

      switch(a & 0xF00F){

the code is compiled correctly.

All other lines however strange they look are also required for the bug to
show up.


Rimantas Plaipa,

Department of Biochemistry and Biophysics,
Vilnius University,
Ciurlionio 21/27, Vilnius 2009, Lithuania.

E-mail: rp010gf AT voruta DOT vu DOT lt
Phone: (370-2)-650381 
Fax: (370-2)-235049

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019