X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCsymt.c;h=d422daf5061e3c6af11810f6a3afb57349f7ad17;hb=4f59e9748a5ba3638324cf2ada80152975eca459;hp=e950c5800ae4f118f7519cc6661b917558659176;hpb=630ef323d03f06cad446dde5413c13185b0d7d54;p=fw%2Fsdcc diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index e950c580..d422daf5 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -2044,8 +2044,28 @@ computeType (sym_link * type1, sym_link * type2, return rType; } +int +comparePtrType (sym_link * dest, sym_link * src, bool bMustCast) +{ + int res; + + if (IS_VOID (src->next) && IS_VOID (dest->next)) + return 1; + if ((IS_VOID (src->next) && !IS_VOID (dest->next)) || + (!IS_VOID (src->next) && IS_VOID (dest->next)) ) + return -1; + res = compareType (dest->next, src->next); + if (res == 1) + return bMustCast ? -1 : 1; + else if (res == -2) + return -2; + else + return 0; +} + /*--------------------------------------------------------------------*/ -/* compareType - will do type check return 1 if match, -1 if castable */ +/* compareType - will do type check return 1 if match, 0 if no match, */ +/* -1 if castable, -2 if only signedness differs */ /*--------------------------------------------------------------------*/ int compareType (sym_link * dest, sym_link * src) @@ -2071,15 +2091,7 @@ compareType (sym_link * dest, sym_link * src) return -1; if (IS_FUNC (dest->next) && IS_VOID(src->next)) return -1; - if (IS_VOID (src->next) && IS_VOID (dest->next)) - return 1; - if ((IS_VOID (src->next) && !IS_VOID (dest->next)) || - (!IS_VOID (src->next) && IS_VOID (dest->next)) ) - return -1; - if (compareType (dest->next, src->next) == 1) - return 1; - else - return 0; + return comparePtrType(dest, src, FALSE); } if (DCL_TYPE (src) == DCL_TYPE (dest)) @@ -2088,15 +2100,7 @@ compareType (sym_link * dest, sym_link * src) { //checkFunction(src,dest); } - if (IS_VOID (src->next) && IS_VOID (dest->next)) - return 1; - if ((IS_VOID (src->next) && !IS_VOID (dest->next)) || - (!IS_VOID (src->next) && IS_VOID (dest->next)) ) - return -1; - if (compareType (dest->next, src->next) == 1) - return 1; - else - return 0; + return comparePtrType(dest, src, FALSE); } if (IS_PTR (dest) && IS_GENPTR (src) && IS_VOID(src->next)) { @@ -2107,10 +2111,7 @@ compareType (sym_link * dest, sym_link * src) ((DCL_TYPE(src) == POINTER) && (DCL_TYPE(dest) == IPOINTER)) )) { - if (compareType (dest->next, src->next)) - return -1; - else - return 0; + return comparePtrType(dest, src, TRUE); } if (IS_PTR (dest) && IS_ARRAY (src)) { @@ -2182,7 +2183,7 @@ compareType (sym_link * dest, sym_link * src) return -1; if (SPEC_USIGN (dest) != SPEC_USIGN (src)) - return -1; + return -2; return 1; } @@ -2423,6 +2424,8 @@ aggregateToPointer (value * val) } break; case S_AUTO: + DCL_TYPE (val->type) = PTR_TYPE(SPEC_OCLS(val->etype)); + break; case S_DATA: case S_REGISTER: DCL_TYPE (val->type) = POINTER;