Fix wrong location for inline asm blocks

This commit is contained in:
Mathias Baumann
2019-04-15 16:40:07 +02:00
parent bf5792f7ca
commit efc8d79d53
5 changed files with 45 additions and 6 deletions
+37
View File
@@ -27,6 +27,7 @@
#include <liblangutil/ErrorReporter.h>
#include <test/Options.h>
#include <test/libsolidity/ErrorCheck.h>
#include <libsolidity/ast/ASTVisitor.h>
using namespace std;
using namespace langutil;
@@ -631,6 +632,42 @@ BOOST_AUTO_TEST_CASE(recursion_depth4)
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()
}
@@ -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.