Skip to content

elide safety checks sometimes for integer division by zero and integer division overflow #12281

@andrewrk

Description

@andrewrk

In theory we could sometimes take advantage of SIGFPE for our integer division by zero safety check:

test "integer division by zero" {
    @setRuntimeSafety(false);
    var x: i32 = 10;
    var y: i32 = 0;
    var z = x / y;
    _ = z;
}
$ stage3/bin/zig test test3.zig 
Test [1/1] test.integer division by zero... Arithmetic exception at address 0x20de9a
./test3.zig:5:5: 0x20de9a in test.integer division by zero (test)
    var z = x / y;
    ^

However, we still need safety checks sometimes, in the case of:

  • architectures that do not have such exceptions for integer division
  • LLVM, which declares integer division by zero as undefined behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.frontendTokenization, parsing, AstGen, Sema, and Liveness.optimization

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions