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

Sequence points for some of RET statements are improperly generated #3622

Open
AnnaShaleva opened this issue Oct 17, 2024 · 0 comments
Open
Labels
bug Something isn't working compiler Go smart contract compiler I4 No visible changes S4 Routine U2 Seriously planned

Comments

@AnnaShaleva
Copy link
Member

Current Behavior

For some RET instructions our compiler generates sequence points with improper boundaries, for example for void functions (if there's no explicit return keyword in the code), also for functions with named parameters where explicit return keyword is missing and may be for more cases that I'm not aware of (it needs to be investigated). The example of such function is given here: #3559 (comment).

Improper boundaries of such sequence points include the whole function body, like it's described here: #3617 (comment)

One case is caused by this code (but there are probably more cases):

c.saveSequencePoint(decl.Body)
emit.Opcodes(c.prog.BinWriter, opcode.RET)

This behaviour is invalid, because:

  1. There are some return statements that have proper boundaries of sequence points. For example, non-void functions where return keyword is explicitly present. It's because return keyword is properly handled by our compiler and sequence point is generated only for the return AST node:

    case *ast.ReturnStmt:

    c.saveSequencePoint(n)

  2. C# compiler properly handles the described case and generates RET sequence points with short-range. Although it has slightly different behaviour in that it bounds RET opcodes to closing brackets of the corresponding functions (}). This behaviour is described here: neotest: exclude RET statements from coverage #3617 (comment)

Expected Behavior

Boundaries of all sequence points corresponding to RET opcodes must not have function-wide bounds.

Possible Solution

Rework the way how sequence points generated for RET opcodes. At least fix these "function-wide" sequence points. May be rework the whole scheme of RET sequence points generation to make the behaviour similar to C# compiler.

Additional context

Related to #3559 and #3617.

@AnnaShaleva AnnaShaleva added bug Something isn't working compiler Go smart contract compiler U2 Seriously planned S4 Routine I4 No visible changes labels Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler Go smart contract compiler I4 No visible changes S4 Routine U2 Seriously planned
Projects
None yet
Development

No branches or pull requests

1 participant