Fixing ICE on calling externally a function that returns calldata pointers

Co-authored-by: chriseth <chris@ethereum.org>
This commit is contained in:
Djordje Mijovic
2020-06-10 14:41:45 +02:00
co-authored by chriseth
parent d2e9b4e946
commit e73fe17277
4 changed files with 37 additions and 11 deletions
+10 -2
View File
@@ -112,14 +112,22 @@ public:
/// @returns a copy of @a _type having the same location as this (and is not a pointer type)
/// if _type is a reference type and an unmodified copy of _type otherwise.
/// This function is mostly useful to modify inner types appropriately.
static Type const* withLocationIfReference(DataLocation _location, Type const* _type)
static Type const* withLocationIfReference(DataLocation _location, Type const* _type, bool _isPointer = false)
{
if (auto refType = dynamic_cast<ReferenceType const*>(_type))
return withLocation(refType, _location, false);
return withLocation(refType, _location, _isPointer);
return _type;
}
static bool isReferenceWithLocation(Type const* _type, DataLocation _location)
{
if (auto const* refType = dynamic_cast<ReferenceType const*>(_type))
if (refType->location() == _location)
return true;
return false;
}
/// @returns the internally-facing or externally-facing type of a function or the type of a function declaration.
static FunctionType const* function(FunctionDefinition const& _function, FunctionType::Kind _kind = FunctionType::Kind::Declaration);
+14 -6
View File
@@ -3445,13 +3445,21 @@ FunctionTypePointer FunctionType::asExternallyCallableFunction(bool _inLibrary,
TypePointers parameterTypes;
for (auto const& t: m_parameterTypes)
{
auto refType = dynamic_cast<ReferenceType const*>(t);
if (refType && refType->location() == DataLocation::CallData)
parameterTypes.push_back(TypeProvider::withLocation(refType, DataLocation::Memory, true));
if (TypeProvider::isReferenceWithLocation(t, DataLocation::CallData))
parameterTypes.push_back(
TypeProvider::withLocationIfReference(DataLocation::Memory, t, true)
);
else
parameterTypes.push_back(t);
}
TypePointers returnParameterTypes;
for (auto const& returnParamType: m_returnParameterTypes)
if (TypeProvider::isReferenceWithLocation(returnParamType, DataLocation::CallData))
returnParameterTypes.push_back(
TypeProvider::withLocationIfReference(DataLocation::Memory, returnParamType, true)
);
else
returnParameterTypes.push_back(returnParamType);
Kind kind = m_kind;
if (_inLibrary)
@@ -3465,7 +3473,7 @@ FunctionTypePointer FunctionType::asExternallyCallableFunction(bool _inLibrary,
return TypeProvider::function(
parameterTypes,
m_returnParameterTypes,
returnParameterTypes,
m_parameterNames,
m_returnParameterNames,
kind,