Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!wuarchive!udel!haven!boingo.med.jhu.edu!aplcen!jhunix!barrett From: barrett@jhunix.HCF.JHU.EDU (Dan Barrett) Newsgroups: comp.sys.amiga.programmer Subject: Manx 5.0d bug (-sr optimization error) Message-ID: <7536@jhunix.HCF.JHU.EDU> Date: 11 Feb 91 04:56:09 GMT Organization: The Johns Hopkins University - HCF Lines: 53 I have found a bug in Manx 5.0d. The optimizer can produce incorrect code with the -sr option ("compiler picks which local variables get assigned to registers"). Enclosed is a minimal code example that illustrates the bug. Please someone verify this for me. I have an Amiga 1000 running 1.3.2. This prints the right answer: Compile: cc bug.c Link: ln bug.o -lc Run: 1> bug Did you know that 3276476 + 8 - 1 == 3276483? This prints the wrong answer: Compile: cc -sr bug.c Link: ln bug.o -lc Run: 1> bug Did you know that 3276480 + 8 - 1 == 3276488? The problem is in the address arithmetic: p = buf + strlen(buf) - 1; The "- 1" is ignored by the compiler. It doesn't matter what the constant is, as long as it is NOT stored in a variable. Code is below my signature. I hope I saved somebody some frustration by hunting this down!! Dan //////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ | Dan Barrett, Department of Computer Science Johns Hopkins University | | INTERNET: barrett@cs.jhu.edu | | | COMPUSERVE: >internet:barrett@cs.jhu.edu | UUCP: barrett@jhunix.UUCP | \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\///////////////////////////////////// #include #include main() { char *p; char buf[BUFSIZ]; strcpy(buf, "Anything"); /* Any string. */ p = buf + strlen(buf) - 1; printf("Did you know that %ld + %d - 1 == %ld?\n", buf, strlen(buf), p); }