Issue 52786
Summary [-Wuninitialized, -Wsometimes-uninitialized] false positive on nested calls that will never return
Labels new issue
Assignees
Reporter stargateaudio
    Test case:
```
#include <stdio.h>
#include <stdlib.h>

void custom_abort(){
    printf("Called custom_abort");
    exit(1);
}

int main(int argc, char**argv){
    int some_value;
    custom_abort();
    // This code is unreachable
    printf("some_value: %i\n", some_value);
    return 0;
}

```

Output:
```
$ clang -Wall test.c 
test.c:12:32: warning: variable 'some_value' is uninitialized when used here [-Wuninitialized]
    printf("some_value: %i\n", some_value);
                               ^~~~~~~~~~
test.c:10:19: note: initialize the variable 'some_value' to silence this warning
    int some_value;
                  ^
                   = 0
1 warning generated.

```

Of course, that test case is greatly oversimplified, the more important use-case is when we conditionally abort the program instead of initializing (-Wsometimes-uninitialized).  Note that the warning is not generated if `abort` or `exit` is called directly in the `main` function instead of `custom_abort();`.  If the nested call to `abort()`, `exit()`, etc... is conditional, additional analysis may be required to determine if the arguments being passed to the function will result in the call returning or not.

```
$ clang -v
clang version 13.0.0 (Fedora 13.0.0-3.fc35)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/11
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/11
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to