Skip to content

Commit

Permalink
yul identifiers with leading or trailing dot are restricted
Browse files Browse the repository at this point in the history
  • Loading branch information
clonker committed May 28, 2024
1 parent 43deb95 commit d5aadd0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Compiler Features:


Bugfixes:
* Yul: NameSimplifier and VarNameCleaner steps could lead to forbidden identifiers with a leading and/or trailing dot, e.g., `let x._ := f()` would get simplified to `x.`.


### 0.8.26 (2024-05-21)
Expand Down
13 changes: 12 additions & 1 deletion libyul/optimiser/OptimizerUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ using namespace solidity::langutil;
using namespace solidity::util;
using namespace solidity::yul;

namespace
{

bool hasLeadingOrTrailingDot(std::string_view const _s)
{
yulAssert(!_s.empty());
return _s.front() == '.' || _s.back() == '.';
}

}

void yul::removeEmptyBlocks(Block& _block)
{
auto isEmptyBlock = [](Statement const& _st) -> bool {
Expand All @@ -46,7 +57,7 @@ void yul::removeEmptyBlocks(Block& _block)

bool yul::isRestrictedIdentifier(Dialect const& _dialect, YulString const& _identifier)
{
return _identifier.empty() || TokenTraits::isYulKeyword(_identifier.str()) || _dialect.reservedIdentifier(_identifier);
return _identifier.empty() || hasLeadingOrTrailingDot(_identifier.str()) || TokenTraits::isYulKeyword(_identifier.str()) || _dialect.reservedIdentifier(_identifier);
}

std::optional<evmasm::Instruction> yul::toEVMInstruction(Dialect const& _dialect, YulString const& _name)
Expand Down
20 changes: 20 additions & 0 deletions test/libyul/objectCompiler/leading_and_trailing_dots.yul
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
function e(_._) {
e(0)
}
e(2)
}
// ----
// Assembly:
// /* "source":39:40 */
// 0x02
// /* "source":4:34 */
// tag_1:
// /* "source":28:29 */
// 0x00
// /* "source":26:30 */
// tag_1
// jump // in
// Bytecode: 60025b5f600256
// Opcodes: PUSH1 0x2 JUMPDEST PUSH0 PUSH1 0x2 JUMP
// SourceMappings: 39:1:0:-:0;4:30;28:1;26:4;:::i

0 comments on commit d5aadd0

Please sign in to comment.