From d2f74db4d8e0bd03c947cef213110f2340d7503a Mon Sep 17 00:00:00 2001 From: acqn Date: Wed, 2 Nov 2022 22:44:57 +0800 Subject: [PATCH] Fixed compatibility checks on "pointer to pointer" vs "pointer to array" etc. --- src/cc65/typecmp.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/cc65/typecmp.c b/src/cc65/typecmp.c index 6052f4a84..a84fd2e2e 100644 --- a/src/cc65/typecmp.c +++ b/src/cc65/typecmp.c @@ -266,18 +266,6 @@ static void DoCompare (const Type* lhs, const Type* rhs, typecmp_t* Result) LeftType = (GetUnderlyingTypeCode (lhs) & T_MASK_TYPE); RightType = (GetUnderlyingTypeCode (rhs) & T_MASK_TYPE); - /* If one side is a pointer and the other side is an array, both are - ** compatible. - */ - if (LeftType == T_TYPE_PTR && RightType == T_TYPE_ARRAY) { - RightType = T_TYPE_PTR; - SetResult (Result, TC_PTR_DECAY); - } - if (LeftType == T_TYPE_ARRAY && RightType == T_TYPE_PTR) { - LeftType = T_TYPE_PTR; - SetResult (Result, TC_STRICT_COMPATIBLE); - } - /* Bit-fields are considered compatible if they have the same ** signedness, bit-offset and bit-width. */ @@ -287,12 +275,27 @@ static void DoCompare (const Type* lhs, const Type* rhs, typecmp_t* Result) lhs->A.B.Offs != rhs->A.B.Offs || lhs->A.B.Width != rhs->A.B.Width) { SetResult (Result, TC_INCOMPATIBLE); + return; } if (LeftType != RightType) { SetResult (Result, TC_STRICT_COMPATIBLE); } } + /* If one side is a pointer and the other side is an array, both are + ** compatible. + */ + if (Result->Indirections == 0) { + if (LeftType == T_TYPE_PTR && RightType == T_TYPE_ARRAY) { + RightType = T_TYPE_PTR; + SetResult (Result, TC_PTR_DECAY); + } + if (LeftType == T_TYPE_ARRAY && RightType == T_TYPE_PTR) { + LeftType = T_TYPE_PTR; + SetResult (Result, TC_STRICT_COMPATIBLE); + } + } + /* If the underlying types are not identical, the types are incompatible */ if (LeftType != RightType) { SetResult (Result, TC_INCOMPATIBLE);