rick@anasaz.UUCP (Rick Coupland) (01/09/90)
Over the past year or so, I have discovered several bugs in release 5
of the Lattice C compiler. Most of these have been discovered very
painfully by tracking down what I originaly thought were bugs in my
own code.
All but one of these problems were reported to Lattice (on the Lattice BBS)
in Feb. or March of 89. I had hoped that all or most of these bugs would
be fixed in 5.04. However, of the bugs I reported during this period,
only one was fixed.
I am posting this in hopes that this information will save others some
time and frustration in tracking down these bugs. I am also hopeful
that these problems will be fixed by Lattice.
The following files are a set of small test programs. Each of these files
demonstrates one bug in Lattice C 5.04 and contains comments explaining the
problem and giving compiler options which were used.
---------------------------------------------------------------------------
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of shell archive."
# Contents: rpcbug6.c rpcbug7.c rpcbug9.c rpcbug10.c rpcbug11.c
# asmbug.a
# Wrapped by rick@rick on Mon Jan 8 13:57:47 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'rpcbug6.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'rpcbug6.c'\"
else
echo shar: Extracting \"'rpcbug6.c'\" \(643 characters\)
sed "s/^X//" >'rpcbug6.c' <<'END_OF_FILE'
X/*
X** When this file is compiled by version 5.02 of the Lattice Amiga C
X** compiler, the generated code is incorrect. A long int is pushed
X** onto the stack for the first argument in the call to tstsub even
X** though the -w (short ints) option is being used. According to
X** "THE C PROGRAMMING LANGUAGE" by Kernighan and Ritchie, Appendix A
X** section 6.4 "Two pointers to objects of the same type may be
X** subtracted; in this case the result is converted to an integer...".
X**
X** The exact command line used for the compile is given below:
X**
X** lc -w -d rpcbug6.c
X*/
Xvoid tst(p1, p2)
Xchar *p1, *p2;
X{
X tstsub(p2 - p1, 0);
X}
END_OF_FILE
if test 643 -ne `wc -c <'rpcbug6.c'`; then
echo shar: \"'rpcbug6.c'\" unpacked with wrong size!
fi
# end of 'rpcbug6.c'
fi
if test -f 'rpcbug7.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'rpcbug7.c'\"
else
echo shar: Extracting \"'rpcbug7.c'\" \(568 characters\)
sed "s/^X//" >'rpcbug7.c' <<'END_OF_FILE'
X/*
X** When this file is compiled by version 5.02 of the Lattice Amiga C
X** compiler, the generated code is incorrect. The wrong value is assigned
X** to the variable p1 prior to entering the for loop. The variable p2
X** is incremented prior to assigning its value to p1.
X**
X** The exact command line used for the compile is given below:
X**
X** lc -d rpcbug7.c
X*/
X
Xchar *tst(ptr, x)
Xchar *ptr;
Xint x;
X{
X char *p1, *p2;
X
X if (p2 = ptr) {
X if (*p2 == '=') {
X p1 = p2;
X *p2++ = 0;
X for (--p1; *p1 == ' '; *p1 = 0)
X ;
X }
X }
X return p2;
X}
END_OF_FILE
if test 568 -ne `wc -c <'rpcbug7.c'`; then
echo shar: \"'rpcbug7.c'\" unpacked with wrong size!
fi
# end of 'rpcbug7.c'
fi
if test -f 'rpcbug9.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'rpcbug9.c'\"
else
echo shar: Extracting \"'rpcbug9.c'\" \(710 characters\)
sed "s/^X//" >'rpcbug9.c' <<'END_OF_FILE'
X/*
X** When this file is compiled by version 5.02 of the Lattice Amiga C
X** compiler, the generated code is incorrect. The wrong value is assigned
X** to the variable memlist. The value of "ptr" is stored into memlist
X** after being modified by statements 24 & 25.
X**
X** The exact command lines used for the compile are given below:
X**
X** lc -d rpcbug9.c
X**
X*/
Xstatic char *memlist;
Xchar *tst(size)
Xint size;
X{
X register char *lptr;
X register int tsize;
X char *ptr;
X
X if ( !(ptr = (char *)gmem(tsize = size+sizeof(char *)+sizeof(int))) )
X ferr("Out of memory", 1);
X lptr = memlist;
X memlist = ptr;
X *((*(int **)&ptr)++) = tsize;
X *((*(char ***)&ptr)++) = lptr;
X return ptr;
X}
END_OF_FILE
if test 710 -ne `wc -c <'rpcbug9.c'`; then
echo shar: \"'rpcbug9.c'\" unpacked with wrong size!
fi
# end of 'rpcbug9.c'
fi
if test -f 'rpcbug10.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'rpcbug10.c'\"
else
echo shar: Extracting \"'rpcbug10.c'\" \(793 characters\)
sed "s/^X//" >'rpcbug10.c' <<'END_OF_FILE'
X/*
X** When this file is compiled by version 5.02 of the Lattice Amiga C
X** compiler, the generated code does not evaluate the expression on line
X** 34 correctly. The subexpression "(pgad - gadlist)" is evaluated first
X** with the result left in d1. This value is then discarded and the
X** remainder of the code assumes the result is in d0 rather than d1.
X** If line 35 is removed, the code is correct.
X**
X** The exact command line used for the compile is given below:
X**
X** lc -w -d rpcbug10.c
X*/
Xtypedef struct {
X int xyz;
X char abc[7];
X} GadDef;
X
Xextern unsigned int numgads;
Xextern GadDef gadlist[100];
X
Xvoid tst(pgad)
XGadDef *pgad;
X{
X int mvlen;
X
X mvlen = (numgads - (pgad - gadlist) - 1) * sizeof(GadDef);
X memcpy((char *)pgad, (char *)(pgad + 1), mvlen);
X}
END_OF_FILE
if test 793 -ne `wc -c <'rpcbug10.c'`; then
echo shar: \"'rpcbug10.c'\" unpacked with wrong size!
fi
# end of 'rpcbug10.c'
fi
if test -f 'rpcbug11.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'rpcbug11.c'\"
else
echo shar: Extracting \"'rpcbug11.c'\" \(395 characters\)
sed "s/^X//" >'rpcbug11.c' <<'END_OF_FILE'
X/*
X** When this file is compiled by version 5.04 of the Lattice Amiga C
X** compiler, a "CXERR 99" error is generated by lc2. The problem is
X** aparently caused by the "if" statement.
X**
X** The exact command lines used for the compile are given below:
X**
X** lc -d rpcbug9.c
X**
X*/
Xtst(a, b)
Xlong a, b;
X{
X long ltmp;
X
X ltmp = a * b;
X if (*((short *)<mp) > 1)
X return 1;
X return 0;
X}
END_OF_FILE
if test 395 -ne `wc -c <'rpcbug11.c'`; then
echo shar: \"'rpcbug11.c'\" unpacked with wrong size!
fi
# end of 'rpcbug11.c'
fi
if test -f 'asmbug.a' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'asmbug.a'\"
else
echo shar: Extracting \"'asmbug.a'\" \(571 characters\)
sed "s/^X//" >'asmbug.a' <<'END_OF_FILE'
X** Lattice Amiga Assembler, version 5.01
X**
X** When a file is assembled which contains an unitialized data section
X** containing initialized data, the assembler does not generate an error
X** message. However, neither blink nor omd will accept the object file
X** produced by the assembler as being valid. Omd gives the message
X** "Invalid Hunk type". It would be nice if asm detected this condition
X** as an error rather than producing an invalid object file.
X**
X** This file demonstrates the problem.
X
X CSECT udata,2,,2,2
X xdef _AA
X_AA ds.l 1
X_BB dc.l 0
X
X end
END_OF_FILE
if test 571 -ne `wc -c <'asmbug.a'`; then
echo shar: \"'asmbug.a'\" unpacked with wrong size!
fi
# end of 'asmbug.a'
fi
echo shar: End of shell archive.
exit 0
--
Rick Coupland ...!{noao!asuvax | mcdphx}!anasaz!rick
(602) 870-3330