gcc optimizer problem, 2.8.1 upwards
svd from BG
svd_bg@yahoo.com
Mon Nov 1 00:13:00 GMT 1999
hi gcc-ers.
the snippet below contains (standalone) C-code that is mistakeably
optimized-to-nothing by gcc optimizer any level of optimization). i have
tried it on gcc 272(linux&solaris), gcc 281 (djgpp), egcs2.91 (cygwin20b1
& solaris 2.5).
gcc2.7.2 is ok. anything above seems to be wrong.
all u actualy need is the readkey() func, the rest are just
stubs/test-driver.
just gcc -O tstgcc.c, and run it.
i've a *lot* of experience with compilers in what they generate (sorry,
ix86 platform only - no money for others/notime to look for myself at
job) - ancient msc's, ztc, highc, watcom; now gcc
i won't say it is good or bad, it's much nearer to good, but that's no
reason to disallow other compilers (read the man/info for "-pedantic" -
playing evangelists, trying to convert people or what? it's not so bad,
but its a bit irritating)
also, disallowing ifdefs in macro instantiation is not very good
#define a(x,y) x+y
...
a(1,
#ifdef USE_ME
me
#else
you
#endif
)
anyway, anything is better than nothing
have a good drink
ciao
svd
====================================
----------tstgcc.c
typedef unsigned short WORD;
typedef unsigned char BYTE;
int kbdhit;
int qKBDHIT() { return !!kbdhit; }
int qKBDSFT() { return kbdhit; }
int qKBDGET() { return kbdhit; }
#define KBDHIT qKBDHIT()
#define KBDSFT qKBDSFT()
#define KBDGET qKBDGET()
int ReadKey( WORD * key, WORD * shift )
{
WORD k;
if ( (WORD) KBDHIT ) {
*shift = KBDSFT;
k = KBDGET;
#ifndef FIX
//optimizer screw up -> misses 2nd cmp & k&=...
//DJGPP281; cygwin20 (egcs2.91)
if ((0xE0==(BYTE)k)
&& (k != 0x80E0)) // Grays: do not distinct from whites
k &= ~0xFF;
#else
if ( 0xE0==(BYTE)k)
if(k != 0x80E0) // Grays: do not distinct from whites
k &= ~0xFF;
#endif
*key = k;
return 1;
} else
return 0;
}
#include <stdio.h>
WORD kbds[] = { 0x3920, 0x4de0, 0x4d00, 0x80e0 };
WORD ress[] = { 0x3920, 0x4d00, 0x4d00, 0x80e0 };
int main() { int i;
for (i=0; i<sizeof kbds/sizeof kbds[0]; i++) { int rc=0;
WORD k,s;
printf("-pass %x \n",kbdhit=kbds[i]);
while (!ReadKey( &k, &s )) {
printf("%d\b\b\b\b\b\b\b", rc++);
}
printf("- got %x [%x] - %s\n", k,ress[i],
(ress[i]==k)?"ok":"wrong!");
}
}
=====
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com
More information about the Gcc-bugs
mailing list