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

Bug: || breaks the maybe-uninitialized warning. #227

Closed
iphydf opened this issue Jan 19, 2025 · 1 comment
Closed

Bug: || breaks the maybe-uninitialized warning. #227

iphydf opened this issue Jan 19, 2025 · 1 comment

Comments

@iphydf
Copy link

iphydf commented Jan 19, 2025

OK:

#pragma safety enable

bool init(_Out int *a) {
    *a = 3;
    return true;
}

int main() {
    int a;
    if (!init(&a)) return 0;
    return a;
}

Fail:

#pragma safety enable

bool init(_Out int *a) {
    *a = 3;
    return true;
}

int main() {
    int a;
    if (!init(&a) || a == 0) return 0;
    return a;
}

Output:

Cake 0.9.36
cake  -target=ir main.c
c:/main.c:11:12: warning: using a uninitialized object 'a' [-Wanalyzer-maybe-uninitialized]
 11 |    return a;
    |           ~  
c:/main.c:11:12: warning: returning an uninitialized 'a' object [-Wanalyzer-maybe-uninitialized]
 11 |    return a;
    |           ~  

Tested on playground.

@thradams
Copy link
Owner

Thanks for the error reporting! It is a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants