Issue 136292
Summary analyzer: Thinks result of `__builtin_mul_overflow` can be uninitialized
Labels new issue
Assignees
Reporter Zentrik
    ```c++
#include <stddef.h>

int test(size_t nel, size_t elsz) {
  size_t nbytes;
  int overflow = __builtin_mul_overflow(nel, elsz, &nbytes);
  int overflow2 = __builtin_add_overflow(nel, nbytes, &nbytes);
  return overflow * overflow2;
}
```

```
> clang++ --analyze -Xclang -analyzer-output=text -std=c++20
clang++: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument]
<source>:6:19: warning: 2nd function call argument is an uninitialized value [core.CallAndMessage]
    6 |   int overflow2 = __builtin_add_overflow(nel, nbytes, &nbytes);
      | ^                           ~~~~~~
<source>:4:3: note: 'nbytes' declared without an initial value
    4 |   size_t nbytes;
      | ^~~~~~~~~~~~~
<source>:5:18: note: Assuming overflow
    5 |   int overflow = __builtin_mul_overflow(nel, elsz, &nbytes);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:6:19: note: 2nd function call argument is an uninitialized value
    6 |   int overflow2 = __builtin_add_overflow(nel, nbytes, &nbytes);
      |                   ^ ~~~~~~
1 warning generated.
Compiler returned: 0
```

Godbolt: https://godbolt.org/z/4q4Efcax8
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to