[alt.msdos.programmer] new MSC 5.1 bug?

ddl@husc6.harvard.edu (Dan Lanciani) (02/09/90)

	The following useless program illustrates what I think is
a bug in the loop optimization code.  It appears that the compiler
becomes confused and believes that p1 and p2 are equal even when
the code within the if statement is not executed.  Compiling with
-Od produces correct results.  In case it isn't obvious, this
loop abstracts a search (with intent to delete) from a linked list.
If this example is perhaps too far reduced in content, the original
bug tripper can be found in the Sun rpc portmapper daemon's
deregistration function.

				Dan Lanciani
				ddl@harvard.*

struct foo {
	int a, b;
	struct foo *next;
} protofoo = { 1, 2 }, *foo = &protofoo;

main()
{
	struct foo *p1, *p2;

	for (p1 = 0, p2 = foo;;) {
		if (p2->a != protofoo.a || p2->b != protofoo.b) {
			p1 = p2;
			p2 = p2->next;
			continue;
		}
		printf("p1 = %x, p2 = %x\n", p1, p2);
	}
}

ddl@husc6.harvard.edu (Dan Lanciani) (02/10/90)

In article <90040.115357CMH117@PSUVM.BITNET>, CMH117@psuvm.psu.edu (Charles Hannum) writes:
| In article <1537@husc6.harvard.edu>, ddl@husc6.harvard.edu (Dan Lanciani) says:
| >
| >                printf("p1 = %x, p2 = %x\n", p1, p2);
| 
| Your problem may be that you are printing out the pointers as short (16-bit)
| integers.  Try:
| 
|     printf("p1 = %p, p2 = %p\n", p1, p2);
| 

	No, this is small model and I don't really want to print
the pointers at all, I (or rather the portmap program) want to use them...
Just take a look at the generated .asm code.  The compiler believes
that both p1 and p2 are in register bx.

				Dan Lanciani
				ddl@harvard.*

CMH117@psuvm.psu.edu (Charles Hannum) (02/10/90)

In article <1537@husc6.harvard.edu>, ddl@husc6.harvard.edu (Dan Lanciani) says:
>
>                printf("p1 = %x, p2 = %x\n", p1, p2);

Your problem may be that you are printing out the pointers as short (16-bit)
integers.  Try:

    printf("p1 = %p, p2 = %p\n", p1, p2);

%p is the Turbo C mnemonic for "pointer".  If MSC doesn't support this, use:

    printf("p1 = %lx, p2 = %lx\n", p1, p2);

Note that I am assuming that you are using a large data model.  If not, I don't
have a clue.


Virtually,
- Charles Martin Hannum II       "Klein bottle for sale ... inquire within."
    (That's Charles to you!)     "To life immortal!"
  cmh117@psuvm.{bitnet,psu.edu}  "No noozzzz izzz netzzzsnoozzzzz..."
  c9h@psuecl.{bitnet,psu.edu}    "Mem'ry, all alone in the moonlight ..."