From 3416c029cf136d81ee1d0b159f99665d6206ccc7 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 4 Feb 2020 20:37:51 +0100 Subject: [PATCH] Relaxed assert in AsmJsonImporter::createAsmNode. --- liblangutil/SourceLocation.h | 5 ++--- libsolidity/ast/AsmJsonImporter.cpp | 5 ++++- test/libevmasm/Assembler.cpp | 4 ++-- test/liblangutil/SourceLocation.cpp | 6 +++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/liblangutil/SourceLocation.h b/liblangutil/SourceLocation.h index 063c3e417..e6f97942e 100644 --- a/liblangutil/SourceLocation.h +++ b/liblangutil/SourceLocation.h @@ -76,8 +76,7 @@ struct SourceLocation source && 0 <= start && start <= end && - // in some cases (json import) source->source() can be empty - (source->source().empty() || end <= int(source->source().length())); + end <= int(source->source().length()); } std::string text() const @@ -125,7 +124,7 @@ inline std::ostream& operator<<(std::ostream& _out, SourceLocation const& _locat if (_location.source) _out << _location.source->name(); - _out << "[" << _location.start << "," << _location.end << ")"; + _out << "[" << _location.start << "," << _location.end << "]"; return _out; } diff --git a/libsolidity/ast/AsmJsonImporter.cpp b/libsolidity/ast/AsmJsonImporter.cpp index fb6acc07b..a47ea27f7 100644 --- a/libsolidity/ast/AsmJsonImporter.cpp +++ b/libsolidity/ast/AsmJsonImporter.cpp @@ -54,7 +54,10 @@ T AsmJsonImporter::createAsmNode(Json::Value const& _node) { T r; r.location = createSourceLocation(_node); - astAssert(r.location.hasText(), "Invalid source location in Asm AST"); + astAssert( + r.location.source && 0 <= r.location.start && r.location.start <= r.location.end, + "Invalid source location in Asm AST" + ); return r; } diff --git a/test/libevmasm/Assembler.cpp b/test/libevmasm/Assembler.cpp index 31b30dd45..eac83e1bb 100644 --- a/test/libevmasm/Assembler.cpp +++ b/test/libevmasm/Assembler.cpp @@ -51,11 +51,11 @@ BOOST_AUTO_TEST_SUITE(Assembler) BOOST_AUTO_TEST_CASE(all_assembly_items) { Assembly _assembly; - auto root_asm = make_shared("", "root.asm"); + auto root_asm = make_shared("lorem ipsum", "root.asm"); _assembly.setSourceLocation({1, 3, root_asm}); Assembly _subAsm; - auto sub_asm = make_shared("", "sub.asm"); + auto sub_asm = make_shared("lorem ipsum", "sub.asm"); _subAsm.setSourceLocation({6, 8, sub_asm}); _subAsm.append(Instruction::INVALID); shared_ptr _subAsmPtr = make_shared(_subAsm); diff --git a/test/liblangutil/SourceLocation.cpp b/test/liblangutil/SourceLocation.cpp index 8fe4740fd..c5b47d0f6 100644 --- a/test/liblangutil/SourceLocation.cpp +++ b/test/liblangutil/SourceLocation.cpp @@ -33,9 +33,9 @@ BOOST_AUTO_TEST_SUITE(SourceLocationTest) BOOST_AUTO_TEST_CASE(test_fail) { - auto const source = std::make_shared("", "source"); - auto const sourceA = std::make_shared("", "sourceA"); - auto const sourceB = std::make_shared("", "sourceB"); + auto const source = std::make_shared("lorem ipsum", "source"); + auto const sourceA = std::make_shared("lorem ipsum", "sourceA"); + auto const sourceB = std::make_shared("lorem ipsum", "sourceB"); BOOST_CHECK(SourceLocation{} == SourceLocation{}); BOOST_CHECK((SourceLocation{0, 3, sourceA} != SourceLocation{0, 3, sourceB}));