From 30305ebbd91ec8246064fed0a23b4ea8128d89ff Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 14 Jan 2021 10:51:33 +0100 Subject: [PATCH] Fix accessing constants at file level from inline assembly. --- libsolidity/codegen/ir/IRGeneratorForStatements.cpp | 12 ++++-------- .../constants/asm_constant_file_level.sol | 2 ++ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index 300a6ed85..17ba03e22 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -111,19 +111,15 @@ private: solUnimplementedAssert(varDecl, ""); string const& suffix = reference.suffix; - if (suffix.empty() && !varDecl->isStateVariable()) + string value; + if (suffix.empty() && varDecl->isLocalVariable()) { auto const& var = m_context.localVariable(*varDecl); solAssert(var.type().sizeOnStack() == 1, ""); - return yul::Identifier{ - _identifier.location, - yul::YulString{var.commaSeparatedList()} - }; + value = var.commaSeparatedList(); } - - string value; - if (varDecl->isConstant()) + else if (varDecl->isConstant()) { VariableDeclaration const* variable = rootConstVariableDeclaration(*varDecl); solAssert(variable, ""); diff --git a/test/libsolidity/semanticTests/constants/asm_constant_file_level.sol b/test/libsolidity/semanticTests/constants/asm_constant_file_level.sol index 4f9076463..3f28c075d 100644 --- a/test/libsolidity/semanticTests/constants/asm_constant_file_level.sol +++ b/test/libsolidity/semanticTests/constants/asm_constant_file_level.sol @@ -5,5 +5,7 @@ contract C { assembly { z := e } } } +// ==== +// compileViaYul: also // ---- // f() -> 0x1212121212121212121212121000002134593163