mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6519 from ethereum/wrong-mem-loc
Fix wrong location for inline asm blocks
This commit is contained in:
commit
edfebcf957
@ -1036,7 +1036,8 @@ ASTPointer<Statement> Parser::parseStatement()
|
|||||||
ASTPointer<InlineAssembly> Parser::parseInlineAssembly(ASTPointer<ASTString> const& _docString)
|
ASTPointer<InlineAssembly> Parser::parseInlineAssembly(ASTPointer<ASTString> const& _docString)
|
||||||
{
|
{
|
||||||
RecursionGuard recursionGuard(*this);
|
RecursionGuard recursionGuard(*this);
|
||||||
ASTNodeFactory nodeFactory(*this);
|
SourceLocation location{position(), -1, source()};
|
||||||
|
|
||||||
expectToken(Token::Assembly);
|
expectToken(Token::Assembly);
|
||||||
if (m_scanner->currentToken() == Token::StringLiteral)
|
if (m_scanner->currentToken() == Token::StringLiteral)
|
||||||
{
|
{
|
||||||
@ -1050,8 +1051,9 @@ ASTPointer<InlineAssembly> Parser::parseInlineAssembly(ASTPointer<ASTString> con
|
|||||||
shared_ptr<yul::Block> block = asmParser.parse(m_scanner, true);
|
shared_ptr<yul::Block> block = asmParser.parse(m_scanner, true);
|
||||||
if (block == nullptr)
|
if (block == nullptr)
|
||||||
BOOST_THROW_EXCEPTION(FatalError());
|
BOOST_THROW_EXCEPTION(FatalError());
|
||||||
nodeFactory.markEndPosition();
|
|
||||||
return nodeFactory.createNode<InlineAssembly>(_docString, block);
|
location.end = block->location.end;
|
||||||
|
return make_shared<InlineAssembly>(location, _docString, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTPointer<IfStatement> Parser::parseIfStatement(ASTPointer<ASTString> const& _docString)
|
ASTPointer<IfStatement> Parser::parseIfStatement(ASTPointer<ASTString> const& _docString)
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include <liblangutil/ErrorReporter.h>
|
#include <liblangutil/ErrorReporter.h>
|
||||||
#include <test/Options.h>
|
#include <test/Options.h>
|
||||||
#include <test/libsolidity/ErrorCheck.h>
|
#include <test/libsolidity/ErrorCheck.h>
|
||||||
|
#include <libsolidity/ast/ASTVisitor.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace langutil;
|
using namespace langutil;
|
||||||
@ -631,6 +632,42 @@ BOOST_AUTO_TEST_CASE(recursion_depth4)
|
|||||||
CHECK_PARSE_ERROR(text, "Maximum recursion depth reached during parsing");
|
CHECK_PARSE_ERROR(text, "Maximum recursion depth reached during parsing");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(inline_asm_end_location)
|
||||||
|
{
|
||||||
|
auto sourceCode = std::string(R"(
|
||||||
|
contract C {
|
||||||
|
function f() public pure returns (uint y) {
|
||||||
|
uint a;
|
||||||
|
assembly { a := 0x12345678 }
|
||||||
|
uint z = a;
|
||||||
|
y = z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)");
|
||||||
|
ErrorList errors;
|
||||||
|
auto contract = parseText(sourceCode, errors);
|
||||||
|
|
||||||
|
class CheckInlineAsmLocation: public ASTConstVisitor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool visited = false;
|
||||||
|
virtual bool visit(InlineAssembly const& _inlineAsm)
|
||||||
|
{
|
||||||
|
auto loc = _inlineAsm.location();
|
||||||
|
auto asmStr = loc.source->source().substr(loc.start, loc.end - loc.start);
|
||||||
|
BOOST_CHECK_EQUAL(asmStr, "assembly { a := 0x12345678 }");
|
||||||
|
visited = true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
CheckInlineAsmLocation visitor;
|
||||||
|
contract->accept(visitor);
|
||||||
|
|
||||||
|
BOOST_CHECK_MESSAGE(visitor.visited, "No inline asm block found?!");
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,4 +8,4 @@ contract C
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// Warning: (76-93): Assertion checker does not support inline assembly.
|
// Warning: (76-90): Assertion checker does not support inline assembly.
|
||||||
|
@ -10,4 +10,4 @@ contract C
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// Warning: (97-130): Assertion checker does not support inline assembly.
|
// Warning: (97-121): Assertion checker does not support inline assembly.
|
||||||
|
@ -6,4 +6,4 @@ contract C {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// TypeError: (92-126): This variable is of storage pointer type and can be accessed without prior assignment.
|
// TypeError: (92-116): This variable is of storage pointer type and can be accessed without prior assignment.
|
||||||
|
Loading…
Reference in New Issue
Block a user