Improve ValueType::matchParameter for pointers with different types

This commit is contained in:
Daniel Marjamäki 2019-07-31 12:12:17 +02:00
parent 35a3a34632
commit 039d49bcb1
2 changed files with 11 additions and 10 deletions

View File

@ -5834,8 +5834,10 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
if (call->pointer > 0 && func->type != ValueType::Type::VOID && ((call->constness | func->constness) != func->constness))
return ValueType::MatchResult::UNKNOWN;
if (call->type != func->type) {
if (func->type == ValueType::Type::VOID)
if (call->type == ValueType::Type::VOID || func->type == ValueType::Type::VOID)
return ValueType::MatchResult::FALLBACK1;
if (call->pointer > 0 && func->pointer > 0)
return ValueType::MatchResult::UNKNOWN;
if (call->isIntegral() && func->isIntegral())
return call->type < func->type ?
ValueType::MatchResult::FALLBACK1 :

View File

@ -5533,18 +5533,17 @@ private:
}
void valueTypeMatchParameter() {
ValueType vt_int;
vt_int.type = ValueType::Type::INT;
vt_int.sign = ValueType::Sign::SIGNED;
ValueType vt_const_int;
vt_const_int.type = ValueType::Type::INT;
vt_const_int.sign = ValueType::Sign::SIGNED;
vt_const_int.constness = 1;
ValueType vt_int(ValueType::Sign::SIGNED, ValueType::Type::INT, 0);
ValueType vt_const_int(ValueType::Sign::SIGNED, ValueType::Type::INT, 0, 1);
ASSERT_EQUALS((int)ValueType::MatchResult::SAME, (int)ValueType::matchParameter(&vt_int, &vt_int));
ASSERT_EQUALS((int)ValueType::MatchResult::SAME, (int)ValueType::matchParameter(&vt_const_int, &vt_int));
ASSERT_EQUALS((int)ValueType::MatchResult::SAME, (int)ValueType::matchParameter(&vt_int, &vt_const_int));
ValueType vt_char_pointer(ValueType::Sign::SIGNED, ValueType::Type::CHAR, 1);
ValueType vt_void_pointer(ValueType::Sign::SIGNED, ValueType::Type::VOID, 1); // compatible
ValueType vt_int_pointer(ValueType::Sign::SIGNED, ValueType::Type::INT, 1); // not compatible
ASSERT_EQUALS((int)ValueType::MatchResult::FALLBACK1, (int)ValueType::matchParameter(&vt_char_pointer, &vt_void_pointer));
ASSERT_EQUALS((int)ValueType::MatchResult::UNKNOWN, (int)ValueType::matchParameter(&vt_char_pointer, &vt_int_pointer));
}
#define FUNC(x) const Function *x = findFunctionByName(#x, &db->scopeList.front()); \