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

runtime safety for branching on undefined values and other undefined behavior caused by undefined values #63

Open
andrewrk opened this issue Jan 12, 2016 · 3 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Jan 12, 2016

test "runtime safety for branching on undefined value" {
    var x: u8 = undefined;
    const y = if (x) i32(1) else i32(2);
}

expected output: the runtime calls @panic("branch on undefined value")

@andrewrk andrewrk added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Jan 12, 2016
@andrewrk andrewrk added this to the 0.2.0 milestone May 7, 2017
@andrewrk andrewrk modified the milestones: 0.2.0, 0.3.0 Oct 20, 2017
@andrewrk andrewrk modified the milestones: 0.3.0, 0.4.0 Feb 28, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Sep 28, 2018
@andrewrk
Copy link
Member Author

Related: #1966

After solving #1947, this issue will be for implementing runtime safety for undefined behavior caused by any of the reasons listed in #1947.

@andrewrk andrewrk changed the title error for using uninitialized values runtime safety for branching on undefined values and other undefined behavior caused by undefined values Apr 10, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 May 9, 2019
@andrewrk andrewrk added the stage1 The process of building from source via WebAssembly and the C backend. label Nov 27, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Feb 10, 2020
@andrewrk andrewrk added frontend Tokenization, parsing, AstGen, Sema, and Liveness. and removed stage1 The process of building from source via WebAssembly and the C backend. labels Oct 9, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 9, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Jun 4, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 21, 2021
@ifreund
Copy link
Member

ifreund commented Jan 26, 2023

LLVM has a MemorySanitizer that can detect uninitialized reads with supposedly only 2-3x slowdown compared to 20-30x under valgrind. It has quite a few limitations however: https://clang.llvm.org/docs/MemorySanitizer.html

There's a paper on the implementation titled "MemorySanitizer: fast detector of uninitialized memory use in C++" which looks to be valuable reading for anyone looking into this kind of runtime safety check for zig: https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/43308.pdf

@matu3ba
Copy link
Contributor

matu3ba commented Jan 26, 2023

Additional drawback as mentioned in #2301 (comment):

With this approach for checking UUM => 2.5x compiletime cost, 2x memory. However, this approach still includes false negatives (there can be UUM even though the check says there is none).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
Status: To do
Development

No branches or pull requests

3 participants