[comp.sys.amiga.tech] Lattice C V5.02 bugs

gay@elde.epfl.ch (David Gay) (05/14/89)

The optimiser generates incorrect code in the following two programs:

"bug.c"
/* When compiled with lc -O, the expression
     arrow1->b = y + 2 * a
   is evaluated incorrectly.
   The short's & long's must be left as is. */
struct s1
{
    short a, b, c, d;
};

int dummy;

void r1(long x, long y)
{
    long i;
    long a;
    struct s1 *arrow1;
    long knobsize;

    if ((r2(x + 5, knobsize)) &&
        i/*Any expression */)
    {
        arrow1->a = x + 5;
        /* Must be 2 * a */
        arrow1->b = y + 2 * a;

        if (i/*Any expression*/)
        {
            for (i = 0; i < 10; i++)
            {
                /* Must be (i + 2) */
                dummy = y + (i + 2) * a;
            }
        }
    }
}

Second program:

"bug2.c"
struct s1 {
    short m1;
};

void f1(side, h)
long side, h;
{
    struct s1 *v1;
    int bx;

    f2(side ? 4 : 0);
    v1->m1 = h;
    bx = side ? 0 : 4;

    f3(bx - 1, h - 1 /*generates h*/) && f3(bx - 1, h - 1);
}


The comparisons below between a signed and unsigned char are done with a signed
comparison between the two bytes (causing problems with tf_HiChar = 255).
Shouldn't the chars be extended to a short(at least) first ? (I'm not quite
sure what the Ansi sign preserving rules say ...)

#include <exec/types.h>
#include <graphics/text.h>

void test(struct TextFont *font, char *text)
{
    if (font->tf_CharKern && text[0] >= font->tf_LoChar && text[0] <= font->tf_H
iChar)
    {
    }
}

The type checking code considers a pointer to an undefined struct to be of
the same type as a pointer to any struct (defined or not). The following
program shows this:

struct a
{
    int b;
} *c;

struct ok
{
    char noproblem;
} *g;

struct d *e;

void t2(struct f *a, struct a *b)
{
    a = b; /* No warning */
}

void t3()
{
    t2(c, e); /* No warnings */
    t2(c, g); /* Warning only for g */
}



I've also had problems with CodeProbe:
a) Stopping with CXERR: 202
b) It seems to forget the types/existence of structures sometimes, and thinks
  that variables of these types are char's ...

a) can usually be cured by relinking with a different startup module (if I'm
using c.o, with catch.o, and if using catch.o, with c.o). Setting the stack
to 100000 doesn't help.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
David Gay                                  6 x 9 = 42

GAY@ELDE.EPFL.CH, or GAY%ELDE.EPFL.CH@CLSEPF51.bitnet

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~