From 1cd998179613a2ef2515faa250950dc775fd81fc Mon Sep 17 00:00:00 2001 From: sandeep Date: Mon, 17 Sep 2001 17:29:43 +0000 Subject: [PATCH] 1) SDCCast.c - allow cast of ZERO to generic pointer (Special case for NULL) 2) SDCCcse.c - Do not change CAST of literal to ASSIGNMENT if the literal is of pointer type & cast to generic pointer git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1280 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCast.c | 5 +++-- src/SDCCcse.c | 41 ++++++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/SDCCast.c b/src/SDCCast.c index 7606c13d..1fcc1797 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -2761,7 +2761,7 @@ decorateType (ast * tree) /* make sure the type is complete and sane */ checkTypeSanity(LETYPE(tree), "(cast)"); -#if 0 +#if 1 /* if the right is a literal replace the tree */ if (IS_LITERAL (RETYPE (tree))) { if (!IS_PTR (LTYPE (tree))) { @@ -2773,7 +2773,8 @@ decorateType (ast * tree) tree->right = NULL; TTYPE (tree) = tree->opval.val->type; tree->values.literalFromCast = 1; - } else if (IS_GENPTR(LTYPE(tree)) && !IS_PTR(RTYPE(tree))) { + } else if (IS_GENPTR(LTYPE(tree)) && !IS_PTR(RTYPE(tree)) && + ((int)floatFromVal(valFromType(RETYPE(tree)))) !=0 ) /* special case of NULL */ { sym_link *rest = LTYPE(tree)->next; werror(W_LITERAL_GENERIC); TTYPE(tree) = newLink(); diff --git a/src/SDCCcse.c b/src/SDCCcse.c index 7d1de84b..b0dc633e 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -810,25 +810,28 @@ algebraicOpts (iCode * ic) } break; case CAST: - /* if this is a cast of a literal value */ - if (IS_OP_LITERAL (IC_RIGHT (ic))) - { - ic->op = '='; - IC_RIGHT (ic) = - operandFromValue (valCastLiteral (operandType (IC_LEFT (ic)), - operandLitValue (IC_RIGHT (ic)))); - IC_LEFT (ic) = NULL; - SET_ISADDR (IC_RESULT (ic), 0); - } - /* if casting to the same */ - if (compareType (operandType (IC_RESULT (ic)), - operandType (IC_RIGHT (ic))) == 1) - { - ic->op = '='; - IC_LEFT (ic) = NULL; - SET_ISADDR (IC_RESULT (ic), 0); - } - break; + { + sym_link *otype = operandType(IC_RIGHT(ic)); + sym_link *ctype = operandType(IC_LEFT(ic)); + /* if this is a cast of a literal value */ + if (IS_OP_LITERAL (IC_RIGHT (ic)) && + !(IS_GENPTR(ctype) && (IS_PTR(otype) && !IS_GENPTR(otype)))) { + ic->op = '='; + IC_RIGHT (ic) = + operandFromValue (valCastLiteral (operandType (IC_LEFT (ic)), + operandLitValue (IC_RIGHT (ic)))); + IC_LEFT (ic) = NULL; + SET_ISADDR (IC_RESULT (ic), 0); + } + /* if casting to the same */ + if (compareType (operandType (IC_RESULT (ic)), + operandType (IC_RIGHT (ic))) == 1) { + ic->op = '='; + IC_LEFT (ic) = NULL; + SET_ISADDR (IC_RESULT (ic), 0); + } + } + break; case '!': if (IS_OP_LITERAL (IC_LEFT (ic))) { -- 2.30.2