Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement undefined variable detection and prettify warning messages #468

Merged
merged 1 commit into from
Aug 19, 2021

Conversation

LucasSte
Copy link
Contributor

@LucasSte LucasSte commented Aug 16, 2021

This PR implements undefined variable detection for variables in function scope, using the current reaching definitions implementation. A few points need further improvement:

  1. Reaching definitions does not work across functions, which prevents us from detecting new definitions on function calls, whose arguments are memory references.
  2. Codegen Instruction Instr::AbiDecode needs refactoring to make reaching definitions work properly with try-catch statements.

In addition, the PR prettifies warnings and errors messages Solang prints to CLI. Here is an example of the new formatting:

examples/test.sol:24:13-18: error: unreachable statement
Line 24:
	a = 5;
	^^^^^

This work is part of the Linux Foundation mentorship for the Hyperledge Solang compiler. For more information, please refer to the project plan.

Copy link
Contributor

@seanyoung seanyoung left a comment

Choose a reason for hiding this comment

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

Looks great so far!

src/codegen/cfg.rs Outdated Show resolved Hide resolved
src/file_cache.rs Show resolved Hide resolved
src/sema/expression.rs Show resolved Hide resolved
@LucasSte LucasSte force-pushed the undefined-variable-detection branch from cd69f74 to cde7a8d Compare August 17, 2021 20:45
@seanyoung seanyoung changed the title Implement undefined varaible detection and prettify warning messages Implement undefined variable detection and prettify warning messages Aug 18, 2021
@LucasSte LucasSte force-pushed the undefined-variable-detection branch from 2054162 to dbf1120 Compare August 18, 2021 14:14
@LucasSte LucasSte marked this pull request as ready for review August 18, 2021 14:14
@seanyoung seanyoung merged commit 3641eb9 into hyperledger:main Aug 19, 2021
seanyoung added a commit to seanyoung/solang that referenced this pull request Aug 27, 2021
Added
- Added a strength reduce pass to eliminate 256/128 bit multiply, division,
  and modulo where possible.
- Visual Studio Code extension can download the Solang binary from github
  releases, so the user is not required to download it themselves
- The Solana target now has support for arrays and mapping in contract
  storage
- The Solana target has support for the keccak256(), ripemd160(), and
  sha256() builtin hash functions.
- The Solana target has support for the builtins this and block.timestamp.
- Implement abi.encodePacked() for the ethereum abi encoder
- The Solana target now compiles all contracts to a single `bundle.so` BPF
  program.
- Any unused variables, events, or contract variables are now detected and
  warnings are given, thanks to [LucasSte](hyperledger#429)
- The `immutable` attribute on contract storage variables is now supported.
- The `override` attribute on public contract storage variables is now supported.
- The `unchecked {}` code block is now parsed and supported. Math overflow still
  is unsupported for types larger than 64 bit.
- `assembly {}` blocks are now parsed and give a friendly error message.
- Any variable use before it is given a value is now detected and results in
  a undefined variable diagnostic, thanks to [LucasSte](hyperledger#468)

Changed
- Solang now uses LLVM 12.0, based on the [Solana LLVM tree](https://github.com/solana-labs/llvm-project/)

Fixed
- Fix a number of issues with parsing the uniswap v2 contracts
- ewasm: staticcall() and delegatecall() cannot take value argument
- Fixed array support in the ethereum abi encoder and decoder
- Fixed issues in arithmetic on non-power-of-2 types (e.g. uint112)

Signed-off-by: Sean Young <[email protected]>
seanyoung added a commit that referenced this pull request Aug 27, 2021
Added
- Added a strength reduce pass to eliminate 256/128 bit multiply, division,
  and modulo where possible.
- Visual Studio Code extension can download the Solang binary from github
  releases, so the user is not required to download it themselves
- The Solana target now has support for arrays and mapping in contract
  storage
- The Solana target has support for the keccak256(), ripemd160(), and
  sha256() builtin hash functions.
- The Solana target has support for the builtins this and block.timestamp.
- Implement abi.encodePacked() for the ethereum abi encoder
- The Solana target now compiles all contracts to a single `bundle.so` BPF
  program.
- Any unused variables, events, or contract variables are now detected and
  warnings are given, thanks to [LucasSte](#429)
- The `immutable` attribute on contract storage variables is now supported.
- The `override` attribute on public contract storage variables is now supported.
- The `unchecked {}` code block is now parsed and supported. Math overflow still
  is unsupported for types larger than 64 bit.
- `assembly {}` blocks are now parsed and give a friendly error message.
- Any variable use before it is given a value is now detected and results in
  a undefined variable diagnostic, thanks to [LucasSte](#468)

Changed
- Solang now uses LLVM 12.0, based on the [Solana LLVM tree](https://github.com/solana-labs/llvm-project/)

Fixed
- Fix a number of issues with parsing the uniswap v2 contracts
- ewasm: staticcall() and delegatecall() cannot take value argument
- Fixed array support in the ethereum abi encoder and decoder
- Fixed issues in arithmetic on non-power-of-2 types (e.g. uint112)

Signed-off-by: Sean Young <[email protected]>
@LucasSte LucasSte deleted the undefined-variable-detection branch September 6, 2021 12:36
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.

2 participants