Skip to content

add a @trap builtin #14765

@andrewrk

Description

@andrewrk

This can be very similar to @breakpoint.

zig/lib/std/os.zig

Lines 552 to 558 in 4789cc0

if (builtin.os.tag == .wasi) {
exit(1);
}
if (builtin.os.tag == .cuda) {
// TODO: introduce `@trap` instead of abusing https://github.com/ziglang/zig/issues/2291
@"llvm.trap"();
}

It should be used in the os.abort implementation for WASI because it causes runtimes to generate a nice stacktrace instead of just exiting.

If a trap is not representable in any particular target, then it can be a compile error. Most targets will have a way to lower trap, however.

This is a contributor-friendly issue for anyone wishing to gently touch many different phases of the compiler pipeline.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.frontendTokenization, parsing, AstGen, Sema, and Liveness.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions