Skip to content

Commit a550048

Browse files
committed
Fix too strict assert for calldata string -> bytes conversions
1 parent 0b9ab33 commit a550048

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ Compiler Features:
1212

1313
Bugfixes:
1414
* Antlr Grammar: Allow builtin names in ``yulPath`` to support ``.address`` in function pointers.
15+
* Code Generator: Fix ICE when accessing the members of external functions occupying more than two stack slots.
16+
* Code Generator: Fix ICE when doing an explicit conversion from ``string calldata`` to ``bytes``.
1517
* Control Flow Graph: Perform proper virtual lookup for modifiers for uninitialized variable and unreachable code analysis.
1618
* Immutables: Fix wrong error when the constructor of a base contract uses ``return`` and the parent contract contains immutable variables.
1719
* IR Generator: Fix IR syntax error when copying storage arrays of structs containing functions.
1820
* Natspec: Fix ICE when overriding a struct getter with a Natspec-documented return value and the name in the struct is different.
1921
* TypeChecker: Fix ICE when a constant variable declaration forward references a struct.
20-
* Code Generator: Fix ICE when accessing the members of external functions occupying more than two stack slots.
2122

2223

2324
Solc-Js:

libsolidity/codegen/CompilerUtils.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,10 @@ void CompilerUtils::convertType(
11401140

11411141
solAssert(_targetType.category() == Type::Category::Array, "");
11421142
auto const& targetArrayType = dynamic_cast<ArrayType const&>(_targetType);
1143-
solAssert(typeOnStack.arrayType().isImplicitlyConvertibleTo(targetArrayType), "");
1143+
solAssert(
1144+
typeOnStack.arrayType().isImplicitlyConvertibleTo(targetArrayType) ||
1145+
(typeOnStack.arrayType().isByteArray() && targetArrayType.isByteArray())
1146+
);
11441147
solAssert(
11451148
typeOnStack.arrayType().dataStoredIn(DataLocation::CallData) &&
11461149
typeOnStack.arrayType().isDynamicallySized() &&

libsolidity/codegen/YulUtilFunctions.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3222,7 +3222,10 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
32223222
solAssert(_to.category() == Type::Category::Array, "");
32233223
auto const& targetType = dynamic_cast<ArrayType const&>(_to);
32243224

3225-
solAssert(fromType.arrayType().isImplicitlyConvertibleTo(targetType), "");
3225+
solAssert(
3226+
fromType.arrayType().isImplicitlyConvertibleTo(targetType) ||
3227+
(fromType.arrayType().isByteArray() && targetType.isByteArray())
3228+
);
32263229
solAssert(
32273230
fromType.arrayType().dataStoredIn(DataLocation::CallData) &&
32283231
fromType.arrayType().isDynamicallySized() &&
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Triggered ICE before
2+
contract C {
3+
function f(string calldata data) external pure returns(string memory) {
4+
bytes calldata test = bytes(data[:3]);
5+
return string(test);
6+
}
7+
}
8+
// ====
9+
// compileViaYul: also
10+
// ----
11+
// f(string): 0x20, 3, "123" -> 0x20, 3, "123"

0 commit comments

Comments
 (0)