From 5cf049a9aca9a6693200563f5debc4d15f3ad21f Mon Sep 17 00:00:00 2001 From: MaartenBrock Date: Mon, 25 Feb 2008 22:12:52 +0000 Subject: [PATCH 1/1] * src/mcs51/gen.c (genPagedPointerSet): fixed bug 1670148 * support/regression/ports/mcs51-xstack-auto/spec.mk: added expf.c * support/regression/tests/bug1670148.c: new, added git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5048 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 6 ++ src/mcs51/gen.c | 94 +++++++++++-------- .../ports/mcs51-xstack-auto/spec.mk | 2 +- support/regression/tests/bug1670148.c | 32 +++++++ 4 files changed, 95 insertions(+), 39 deletions(-) create mode 100644 support/regression/tests/bug1670148.c diff --git a/ChangeLog b/ChangeLog index 03ec0a71..ada71110 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-02-25 Maarten Brock + + * src/mcs51/gen.c (genPagedPointerSet): fixed bug 1670148 + * support/regression/ports/mcs51-xstack-auto/spec.mk: added expf.c + * support/regression/tests/bug1670148.c: new, added + 2008-02-25 Jesus Calvino-Fraga * device/include/mcs51/at89c51ed2.h: fixed bug 1901469. diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index a0960b88..8fb85cad 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -10603,39 +10603,36 @@ genNearPointerSet (operand * right, then don't need anything more */ if (!AOP_INPREG (AOP (result))) { - if ( - //AOP_TYPE (result) == AOP_STK - IS_AOP_PREG(result) - ) + if (IS_AOP_PREG (result)) { - // Aha, it is a pointer, just in disguise. - rname = aopGet (result, 0, FALSE, FALSE); - if (*rname != '@') + // Aha, it is a pointer, just in disguise. + rname = aopGet (result, 0, FALSE, FALSE); + if (*rname != '@') { - fprintf(stderr, "probable internal error: unexpected rname @ %s:%d\n", - __FILE__, __LINE__); + fprintf(stderr, "probable internal error: unexpected rname @ %s:%d\n", + __FILE__, __LINE__); } - else + else { - // Expected case. - emitcode ("mov", "a%s,%s", rname + 1, rname); - rname++; // skip the '@'. + // Expected case. + emitcode ("mov", "a%s,%s", rname + 1, rname); + rname++; // skip the '@'. } } - else + else { - /* otherwise get a free pointer register */ - aop = newAsmop (0); - preg = getFreePtr (ic, &aop, FALSE); - emitcode ("mov", "%s,%s", - preg->name, - aopGet (result, 0, FALSE, TRUE)); - rname = preg->name; + /* otherwise get a free pointer register */ + aop = newAsmop (0); + preg = getFreePtr (ic, &aop, FALSE); + emitcode ("mov", "%s,%s", + preg->name, + aopGet (result, 0, FALSE, TRUE)); + rname = preg->name; } } - else + else { - rname = aopGet (result, 0, FALSE, FALSE); + rname = aopGet (result, 0, FALSE, FALSE); } aopOp (right, ic, FALSE); @@ -10723,16 +10720,37 @@ genPagedPointerSet (operand * right, then don't need anything more */ if (!AOP_INPREG (AOP (result))) { - /* otherwise get a free pointer register */ - aop = newAsmop (0); - preg = getFreePtr (ic, &aop, FALSE); - emitcode ("mov", "%s,%s", - preg->name, - aopGet (result, 0, FALSE, TRUE)); - rname = preg->name; + if (IS_AOP_PREG (result)) + { + // Aha, it is a pointer, just in disguise. + rname = aopGet (result, 0, FALSE, FALSE); + if (*rname != '@') + { + fprintf(stderr, "probable internal error: unexpected rname @ %s:%d\n", + __FILE__, __LINE__); + } + else + { + // Expected case. + emitcode ("mov", "a%s,%s", rname + 1, rname); + rname++; // skip the '@'. + } + } + else + { + /* otherwise get a free pointer register */ + aop = newAsmop (0); + preg = getFreePtr (ic, &aop, FALSE); + emitcode ("mov", "%s,%s", + preg->name, + aopGet (result, 0, FALSE, TRUE)); + rname = preg->name; + } } else - rname = aopGet (result, 0, FALSE, FALSE); + { + rname = aopGet (result, 0, FALSE, FALSE); + } aopOp (right, ic, FALSE); @@ -10741,7 +10759,7 @@ genPagedPointerSet (operand * right, genPackBits ((IS_BITFIELD (retype) ? retype : letype), right, rname, PPOINTER); else { - /* we have can just get the values */ + /* we can just get the values */ int size = AOP_SIZE (right); int offset = 0; @@ -10750,10 +10768,8 @@ genPagedPointerSet (operand * right, l = aopGet (right, offset, FALSE, TRUE); MOVA (l); emitcode ("movx", "@%s,a", rname); - if (size || pi) emitcode ("inc", "%s", rname); - offset++; } } @@ -10772,10 +10788,11 @@ genPagedPointerSet (operand * right, if size > 0 && this could be used again we have to point it back to where it belongs */ - if (AOP_SIZE (right) > 1 && + if ((AOP_SIZE (right) > 1 && !OP_SYMBOL (result)->remat && (OP_SYMBOL (result)->liveTo > ic->seq || - ic->depth)) + ic->depth)) && + !pi) { int size = AOP_SIZE (right) - 1; while (size--) @@ -10784,9 +10801,10 @@ genPagedPointerSet (operand * right, } /* done */ - if (pi) pi->generated = 1; - freeAsmop (result, NULL, ic, TRUE); + if (pi) + pi->generated = 1; freeAsmop (right, NULL, ic, TRUE); + freeAsmop (result, NULL, ic, TRUE); } /*-----------------------------------------------------------------*/ diff --git a/support/regression/ports/mcs51-xstack-auto/spec.mk b/support/regression/ports/mcs51-xstack-auto/spec.mk index ca07c46a..e8ecbabb 100644 --- a/support/regression/ports/mcs51-xstack-auto/spec.mk +++ b/support/regression/ports/mcs51-xstack-auto/spec.mk @@ -18,7 +18,7 @@ SOURCES = _atoi.c _atol.c _autobaud.c _bp.c _schar2fs.c \ _fsadd.c _fssub.c _fsdiv.c _fsmul.c \ _fseq.c _fsneq.c _fsgt.c _fslt.c _fscmp.c \ fabsf.c sqrtf.c logf.c log10f.c powf.c tanf.c \ - errno.c frexpf.c ldexpf.c tancotf.c \ + errno.c frexpf.c ldexpf.c expf.c tancotf.c \ _fsget1arg.c _fsget2args.c _fsnormalize.c \ _fsreturnval.c _fsrshift.c _fsswapargs.c \ _gptrget.c _gptrput.c \ diff --git a/support/regression/tests/bug1670148.c b/support/regression/tests/bug1670148.c new file mode 100644 index 00000000..80f1442a --- /dev/null +++ b/support/regression/tests/bug1670148.c @@ -0,0 +1,32 @@ +/* + bug 1670148.c +*/ + +#include + +// no need to call this, it generates compiler error for xstack-auto +// error 9: FATAL Compiler Internal Error +struct str { + long aa; + long bb; +}; + +struct str *v1; + +void foo(void) +{ + struct str v2; + struct str loc; + + v2.aa = 0; + loc.bb = v1->bb; + loc.aa = v1->aa - v2.aa; + + loc.bb += 0; +} + +void +testBug(void) +{ + ASSERT(1); +} -- 2.30.2