Issue 90491
Summary `-Wconditional-uninitialized` false positive with vector types
Labels vectorization, clang:diagnostics, false-positive
Assignees
Reporter wheatman
    The following code leads to what I believe is a false positive of `-Wconditional-uninitialized`
compile with `-std=c++20 -Wconditional-uninitialized -DVECTOR`

this is with current trunk (19.0 145176dc0c93566ce4aef721044d49ab8ba50f87)
```cpp
#include <array>

static constexpr int num_blocks = 8;
using data_type = float;

#ifdef VECTOR
typedef float vec_type __attribute__((vector_size(sizeof(data_type) * num_blocks)));
#else
using vec_type = std::array<data_type, num_blocks>;
#endif

  vec_type load_vec(const data_type *f) {
 vec_type data;
    for (int i = 0; i < num_blocks; i++) {
 data[i] = f[i];
    }
    return data;
  }


vec_type foo(const data_type * f) {
    return load_vec(f);
}
```
https://godbolt.org/z/e5farervq

You get the following warning 
```
<source>:17:12: warning: variable 'data' may be uninitialized when used here [-Wconditional-uninitialized]
   17 | return data;
      |            ^~~~
<source>:13:5: note: variable 'data' is declared here
   13 |     vec_type data;
```


Interestingly if you use it in the same function the false positive seems to go away
```cpp

static constexpr int num_blocks = 8;
using data_type = float;

typedef float vec_type __attribute__((vector_size(sizeof(data_type) * num_blocks)));


 data_type sum_vec(const data_type *f) {
    vec_type data;
    for (int i = 0; i < num_blocks; i++) {
      data[i] = f[i];
    }
 data_type total = 0;
    for (int i = 0; i < num_blocks; i++) {
 total += data[i];
    }
    return total;
  }


data_type foo(const data_type * f) {
    return sum_vec(f);
}
```

https://godbolt.org/z/dWb5KWojr


_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to