X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCsymt.c;h=b9d4175a6e5a35d302441237f08049ec58b94765;hb=2004a3562e7ee5bfc7b62ec0c843cea8d5f01aaf;hp=9257c4d2be55f167ca78dac5080d0d851d28aebb;hpb=a5f1954d67c5525c090e54776f564aec6d37b05a;p=fw%2Fsdcc diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 9257c4d2..b9d4175a 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -1869,7 +1869,7 @@ computeType (sym_link * type1, sym_link * type2, /* if both are bitvars choose the larger one */ else if (IS_BITVAR (etype1) && IS_BITVAR (etype2)) rType = SPEC_BLEN (etype1) >= SPEC_BLEN (etype2) ? - copyLinkChain (type1) : copyLinkChain (type1); + copyLinkChain (type1) : copyLinkChain (type2); /* if only one of them is a bit variable then the other one prevails */ else if (IS_BITVAR (etype1) && !IS_BITVAR (etype2)) @@ -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,7 +2091,7 @@ compareType (sym_link * dest, sym_link * src) return -1; if (IS_FUNC (dest->next) && IS_VOID(src->next)) return -1; - return compareType (dest->next, src->next); + return comparePtrType(dest, src, FALSE); } if (DCL_TYPE (src) == DCL_TYPE (dest)) @@ -2080,7 +2100,7 @@ compareType (sym_link * dest, sym_link * src) { //checkFunction(src,dest); } - return compareType (dest->next, src->next); + return comparePtrType(dest, src, FALSE); } if (IS_PTR (dest) && IS_GENPTR (src) && IS_VOID(src->next)) { @@ -2091,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)) { @@ -2166,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; }