Skip to content

Conversation

@chriseth
Copy link
Contributor

@chriseth chriseth commented Aug 4, 2021

@chriseth chriseth force-pushed the shadowing_inlineasm branch 2 times, most recently from 85448c8 to a88a11f Compare August 4, 2021 10:27
@mijovic
Copy link
Contributor

mijovic commented Aug 4, 2021

Can you add a test with variable in inline assembly that shadows local variable?

@chriseth
Copy link
Contributor Author

chriseth commented Aug 4, 2021

Can you add a test with variable in inline assembly that shadows local variable?

that already exists: test/libsolidity/syntaxTests/inlineAssembly/shadowing/local_variable.sol

mijovic
mijovic previously approved these changes Aug 4, 2021
Copy link
Contributor

@mijovic mijovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@chriseth
Copy link
Contributor Author

chriseth commented Aug 4, 2021

Would like to get some more thumbsup since this can break existing contracts (see the tests).

Copy link
Contributor

@hrkrshnn hrkrshnn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this is a breaking change. Since it's only present in Yul codegen, we could prolong the fix to breaking.

uint x;
function f() public pure {
assembly {
function g(f) -> x {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this wouldn't trigger the bug from the issue. But it's fine as long as such examples don't reach codegen.

{
SecondarySourceLocation ssl;
for (auto const* decl: declarations)
ssl.append("The shadowed declaration is here:", decl->location());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For

contract C {
	function f() external {
		assembly {
			function g(gasleft) { gasleft := 2 }
		}
	}
}

The decl->location would be empty.

Should we do something about global functions?

@chriseth
Copy link
Contributor Author

chriseth commented Aug 4, 2021

Ok, true, let me try to fix it in yul codegen in a different way.

@chriseth chriseth force-pushed the shadowing_inlineasm branch from a88a11f to 5948fed Compare August 4, 2021 16:19
@chriseth chriseth changed the base branch from develop to breaking August 4, 2021 16:22
@chriseth chriseth changed the title Fix shadowing error for inline assembly. Disallow shadowing for all identifiers in inline assembly Aug 4, 2021
@chriseth chriseth force-pushed the shadowing_inlineasm branch 3 times, most recently from 8a2b7bf to 5072e6c Compare August 17, 2021 09:54
Copy link
Collaborator

@ekpyron ekpyron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a test case for function arguments colliding with local variables (it's implicitly covered, but might be nice to have explicitly), maybe some other cases, too.

But generally, looks good!

@chriseth chriseth force-pushed the shadowing_inlineasm branch from 5072e6c to aeb2438 Compare August 17, 2021 10:13
@chriseth
Copy link
Contributor Author

@chriseth chriseth merged commit d247cd5 into breaking Aug 17, 2021
@chriseth chriseth deleted the shadowing_inlineasm branch August 17, 2021 11:18
Marenz added a commit that referenced this pull request Aug 30, 2022
Manual Resolved Conflicts:
	Changelog.md
	 * Updated changelog
	test/externalTests/ens.sh
	 * Merged fixes for upstream from both develop and breaking
	test/libsolidity/semanticTests/inlineAssembly/external_identifier_access_shadowing.sol
	 * Removed in #11735 (breaking)
	test/libsolidity/semanticTests/inlineAssembly/function_name_clash.sol
	 * Removed in #12209 (breaking)
	test/libsolidity/semanticTests/storage/mappings_array2d_pop_delete.sol
	 * Removed in #11843 (breaking)
	test/libsolidity/semanticTests/storage/mappings_array_pop_delete.sol
	 * Removed in #11843 (breaking)
	test/libsolidity/syntaxTests/inlineAssembly/basefee_berlin_function.sol
	 * Used version of file from #11842 (breaking)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Sol->Yul] Unimplemented feature error ICE in SMTEncoder::visit(): "Non-local variable assigned in inlined assembly"

5 participants