Issue |
145919
|
Summary |
Miscompiling error resulting to go into a forloop whereas the condition is false
|
Labels |
new issue
|
Assignees |
|
Reporter |
alliaces
|
Hi !
I'm encoutering a problem from clang19.1.0 (clang20.1.0 also has it) with this kind of code :
https://godbolt.org/z/WWdqcvj6h
```c++
double recursiveEval(int n, const double a) {
return n <= 0 ? 0 : a + recursiveEval(n - 1, a);
}
double eval(const std::vector<double>& emptyVector) {
std::vector<double> vec;
for (const double& it : emptyVector) {
std::cerr << "BIG ERROR !! I should not be here" << std::endl;
vec.push_back(recursiveEval(it, it));
}
return recursiveEval(vec.size(), vec[0]);
}
int main(int argc, char **argv) {
std::vector<double> coefs;
eval(coefs);
return 0;
}
```
It segfaults but that is not the problem. The problem is we go into the forloop whereas the vector _emptyVector_ is empty.
The problem disappears when (any of these):
- vec or emptyVector are not empty
- `vec[0]` is replaced by a prvalue
- the line `return recursiveEval(vec.size(), vec[0]);` is deleted (replaced by any return).
Thanks for your help
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs