c/7888: wrong code produced by GCC 3.1

tabasso@tabasoft.it tabasso@tabasoft.it
Wed Sep 11 09:01:00 GMT 2002


>Number:         7888
>Category:       c
>Synopsis:       wrong code produced by GCC 3.1
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 11 08:06:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Raul Tabasso
>Release:        gcc 3.1
>Organization:
>Environment:
MacOSX 1.2 with gcc 3.1 compiling with NO -o option
>Description:
The GCC compiler version 3.1 produce wrong code when declaring a register variable of type double. Suppressing the register statement avoids the problem.

The register clause in line: "register double	zero = 0" produce a wrong code when using this register variable in a statement like "*dblP++ = zero;" where "dblP" is a pointer to a double.
The code will clear only the first 4 bytes and NOT 8 as it should be.
>How-To-Repeat:
// Code that cause the bug:
void ClearBlock(void *blockP, int blockSize)
{
register double	zero = 0;
double *dblP = (double*)blockP;
int  step32 = blockSize / (sizeof(double) * 4);
char  *charP(char*)blockP;

if (step32)
{
      blockSize -= step32 * (sizeof(double) * 4);
do {
      *dblP++ = zero;
      *dblP++ = zero;
      *dblP++ = zero;
      *dblP++ = zero;
      } while (--step32);
  charP = (char*)dblP;
 }
if (blockSize)
{
  do {
      *charP++ = 0;
      } while (--blockSize);
}
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list