mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #11575 from ethereum/fix-invalid-yul-escapes-from-literals-in-assembly-blocks
Fix invalid Yul escapes generated from literals in assembly blocks
This commit is contained in:
commit
b3ac0976fc
@ -3157,5 +3157,5 @@ bool IRGeneratorForStatements::visit(TryCatchClause const& _clause)
|
||||
string IRGeneratorForStatements::linkerSymbol(ContractDefinition const& _library) const
|
||||
{
|
||||
solAssert(_library.isLibrary(), "");
|
||||
return "linkersymbol(" + util::escapeAndQuoteString(_library.fullyQualifiedName()) + ")";
|
||||
return "linkersymbol(" + util::escapeAndQuoteYulString(_library.fullyQualifiedName()) + ")";
|
||||
}
|
||||
|
@ -192,11 +192,13 @@ string solidity::util::formatAsStringOrNumber(string const& _value)
|
||||
if (c <= 0x1f || c >= 0x7f || c == '"')
|
||||
return "0x" + h256(_value, h256::AlignLeft).hex();
|
||||
|
||||
return escapeAndQuoteString(_value);
|
||||
// The difference in escaping is only in characters below 0x1f and the string does not have them
|
||||
// so this will work for Solidity strings too.
|
||||
return escapeAndQuoteYulString(_value);
|
||||
}
|
||||
|
||||
|
||||
string solidity::util::escapeAndQuoteString(string const& _input)
|
||||
string solidity::util::escapeAndQuoteYulString(string const& _input)
|
||||
{
|
||||
string out;
|
||||
|
||||
@ -205,18 +207,12 @@ string solidity::util::escapeAndQuoteString(string const& _input)
|
||||
out += "\\\\";
|
||||
else if (c == '"')
|
||||
out += "\\\"";
|
||||
else if (c == '\b')
|
||||
out += "\\b";
|
||||
else if (c == '\f')
|
||||
out += "\\f";
|
||||
else if (c == '\n')
|
||||
out += "\\n";
|
||||
else if (c == '\r')
|
||||
out += "\\r";
|
||||
else if (c == '\t')
|
||||
out += "\\t";
|
||||
else if (c == '\v')
|
||||
out += "\\v";
|
||||
else if (!isprint(c, locale::classic()))
|
||||
{
|
||||
ostringstream o;
|
||||
|
@ -554,7 +554,7 @@ std::string formatAsStringOrNumber(std::string const& _value);
|
||||
|
||||
/// @returns a string with the usual backslash-escapes for non-ASCII
|
||||
/// characters and surrounded by '"'-characters.
|
||||
std::string escapeAndQuoteString(std::string const& _input);
|
||||
std::string escapeAndQuoteYulString(std::string const& _input);
|
||||
|
||||
template<typename Container, typename Compare>
|
||||
bool containerEqual(Container const& _lhs, Container const& _rhs, Compare&& _compare)
|
||||
|
@ -57,7 +57,7 @@ string AsmPrinter::operator()(Literal const& _literal) const
|
||||
break;
|
||||
}
|
||||
|
||||
return escapeAndQuoteString(_literal.value.str()) + appendTypeName(_literal.type);
|
||||
return escapeAndQuoteYulString(_literal.value.str()) + appendTypeName(_literal.type);
|
||||
}
|
||||
|
||||
string AsmPrinter::operator()(Identifier const& _identifier) const
|
||||
|
@ -0,0 +1,12 @@
|
||||
contract C {
|
||||
function f() public pure returns (bytes32 result) {
|
||||
assembly {
|
||||
result := hex"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileToEwasm: also
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
let name := hex"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
|
||||
}
|
||||
// ====
|
||||
// dialect: evm
|
||||
// ----
|
Loading…
Reference in New Issue
Block a user