Skip to content

Compiler abort in when compiling switch statement #640

Description

@hungryzzz

Hi, I found a case that aborts during compilation on commit 450e163, but compiles successfully on commit 07a16bc. ASC can also compile it successfully, so I think there are bugs in the commit 450e163.

I am not sure whether this was intentionally fixed by 07a16bc, since that commit does not seem to directly target this specific issue. Could you help confirm the root cause? Thanks so much.

Reduced test case

// bad.ts
export function main(): i32 {
  switch (true) {
    default:
      return 1;
      break; // Commenting out this line can make the compilation succeed.
  }
}

Reproduction

Using commit: 450e163

Command: warpo_asc --optimizeLevel 2 --shrinkLevel 2 bad.ts -o bad.wasm

The compiler aborts with:

abort: <<NULL>> in assemblyscript/src/flow.ts:1432:5
Error: Unreachable instruction executed
    at assemblyscript/src/flow/Flow#addLocalsToBlockWithStartEndStmt
    at assemblyscript/src/flow/Flow#addLocalsToBlock
    at assemblyscript/src/compiler/Compiler#compileSwitchStatement
    at assemblyscript/src/compiler/Compiler#compileStatement
    at assemblyscript/src/compiler/Compiler#compileStatements
    at assemblyscript/src/compiler/Compiler#compileFunctionBody
    at assemblyscript/src/compiler/Compiler#compileFunction
    at assemblyscript/src/compiler/Compiler#compileModuleExport
    at assemblyscript/src/compiler/Compiler#compileModuleExport
    at assemblyscript/src/compiler/Compiler#compileModuleExports
    at assemblyscript/src/compiler/Compiler#compile
compilation failed
AS wasm execution failed
ERROR: compilation failed

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions