gcc -O2 produces faulty code : gcc 3.0.3 and gcc 3.0.4

Russell Ruby russ@MATH.ORST.EDU
Sun Mar 10 22:35:00 GMT 2002


Systems:

  Sparc Solaris 8 with gcc 3.0.3 and gcc 3.0.4
and
  IBM AIX with unknown version of gcc

Problem description:

xlhtml is a package (see last paragraph) which renders microsoft
97/2000 excel documents into html.

When compiled with optimization "-O2", xlhtml renders integers
entered as "general" cell values in excel97/2000 spread sheets as
garbage floating point numbers, e.g. "6.95357380974837e-310".

However, if all the source files in the xlhtml-0.4.9.0 distribution
except xlhtml.c are still compiled with "-O2", but xlhtml.c is
compiled with either no optimization or "-O", then integer cell entries
are correctly written as integers in the html output.

For example, here is a snippet of html output when xlhtml.c
is compiled with "-O2".

<TR VALIGN="bottom">
<TD>Waymire</TD>
<TD>6.95357380974822e-310</TD>
<TD>A-J</TD>
<TD>KIDDER 364</TD>
<TD>Rabimov</TD>
<TD>6.95357380974832e-310</TD>
<TD>6.95357380974837e-310</TD>
<TD> </TD>
<TD> </TD>
<TD> </TD>
</TR>

Here is the same output section when xlhtml.c is compiled as "-O",

<TR VALIGN="bottom">
<TD>Waymire</TD>
<TD>20</TD>
<TD>A-J</TD>
<TD>KIDDER 364</TD>
<TD>Rabimov</TD>
<TD>61</TD>
<TD>119</TD>
<TD> </TD>
<TD> </TD>
<TD> </TD>
</TR>

My apologies for not supplying a succinct C source code
example demonstrating the problem.  From experimenting by
changing individual bytes in the six byte chunks in excel
documents corresponding to "general" integer value cells,
what happens would be consistent with pointer arithmetic/dereferencing
getting out of whack under "-O2", but that is just a lame guess.
Again, the problem is in the file xlhtml.c, and not in the "cole" library
which is used to parse and read the "file system" embodied in the
actual excel "xls" file.

The package xlhtml-0.4.9.0 is normally available from www.xlhtml.org,
but since it is temporarily offline because of hardware problems,
I have placed the source package on our anonymous ftp site as:
  ftp://ftp.math.orst.edu/pub/xlhtml-0.4.9.0.tar.gz

thanks,

Russell Ruby   russ@math.orst.edu



More information about the Gcc-bugs mailing list