archiel@hercules.UUCP (Archie Lachner) (10/02/84)
Several people have asked for copies of the program that exercises the cc optimizer bug that I reported recently. One suggested that I submit it to this news group. Though a fix for the bug has already been posted, I'm happy to comply. ------- #include <stdio.h> main() { union { int one_word; /* one-word form */ struct { unsigned int type:7; /* type */ unsigned int flag_1:1; /* flag no 1 */ unsigned int flag_2:1; /* flag no 2 */ unsigned int count:7; /* count of whatever */ unsigned int number:16; /* number of "things" */ } split; /* split form */ } field_union; int type; int flag_1; int flag_2; int count; int number; field_union.one_word = 0x300; fprintf(stdout, "foobar: field_union = %d (%x hex)\n", field_union.one_word, field_union.one_word); type = field_union.split.type; fprintf(stdout, "foobar: type = %d\n", type); flag_1 = field_union.split.flag_1; fprintf(stdout, "foobar: flag_1 = %d\n", flag_1); flag_2 = field_union.split.flag_2; fprintf(stdout, "foobar: flag_2 = %d\n", flag_2); count = field_union.split.count; fprintf(stdout, "foobar: count = %d\n", count); /* * when this is compiled with optimization, "number" will be 3 * * it should be 0 * * the error can be traced to line 54 of the assembler output * produced using "cc -O -S" * * the source address in a "movzwl" instruction is incorrect */ number = field_union.split.number; fprintf(stdout, "foobar: number = %d\n", number); exit(0); } -- Archie Lachner Logic Design Systems Division Tektronix, Inc. uucp: {ucbvax,decvax,pur-ee,cbosg,ihnss}!tektronix!teklds!archiel CSnet: archiel@tek ARPAnet: archiel.tek@csnet-relay