<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/145919>145919</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Miscompiling error resulting to go into a forloop whereas the condition is false
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          alliaces
      </td>
    </tr>
</table>

<pre>
    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
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVE1vpDgQ_TXVl1JaxqRpOHAgH72bw2qlaLRzjIwpwBO3zdqGqOfXr2w6nZ7JalZaCYEKV736eM8lvFeDIaphdwe7h42Yw2hdLbRWQpLftLY71b8rBJ4Ba56A749IRto5kFNmQIGTs62mI_bOHlFqYYas2mZbhsDLZHKWTKG9xVF4VAF4hW8qjBhG5fFVmQ5tj9J2hJA3CKwZQ5g85A3wA_DDYLvW6rC1bgB--A788PVr97dcvhUjsAYKtj4S-F18WNPZudWEjuTsvFrocREaeKlMQAP8HqU1PuDZS8RyYB_jEB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