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

    <tr>
        <th>Summary</th>
        <td>
            Return statement prevents -Wsometimes-uninitialized warning
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:diagnostics
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          sfc-gh-sgiesecke
      </td>
    </tr>
</table>

<pre>
    As expected, clang produces a -Wsometimes-uninitialized warning with the following code:
```
int foo(bool flag, bool otherFlag) {

    int bar;

    if (flag) {
        bar = 1;
    }
    if (otherFlag) {
        // return 1;
    }

    return bar;
}
```
saying
```
<source>:5:9: error: variable 'bar' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
    if (flag) {
 ^~~~
<source>:12:12: note: uninitialized use occurs here
    return bar;
           ^~~
<source>:5:5: note: remove the 'if' if its condition is always true
    if (flag) {
 ^~~~~~~~~~
<source>:3:12: note: initialize the variable 'bar' to silence this warning
    int bar;
           ^
            = 0
```

However, if I uncomment the `return` statement, no warning is produced:
```
int foo(bool flag, bool otherFlag) {

    int bar;

    if (flag) {
        bar = 1;
    }
    if (otherFlag) {
        return 1;
    }

    return bar;
}
```

However, the situation about the potential read of the uninitialized `bar` variable doesn't change. Is this a bug in the `-Wsometimes-uninitialized` implementation or intentional?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcVc2S4yYQfhp06fIUAku2Djp4ZtaVveayZ4RaEgkCF43sTA7z7Cnkv3hsJ7nkstQUYzVN_3z9Na2ITO8Qa1a8suI9U1McfKip04t-WFBvkFD_jlnj2496Q4B_7FBHbJl4A22V62EXfDtpJFCw-EF-xGhGpMXkjDPRKGv-xBYOKjjjejiYOEAcEDpvrT8kkfYtMrlh_J3xDSv56W_-NC5C5z0T68Z7C51VfXI8f_g4YNjOkgrY6vVkYN4BANLdRgUm7086YGLdfb0Kp9WoAEy-Q365mqRs9f7VwuMIzmaY2DKxhYBxCu6ZsavopHcT8UXrFhVSH8b1D4-YfCM_BY1MfmNyUzC5qZjcAIbgQ_qxV8GoxiIwsUq-xAoMwUTYwpeKDehwjyEpmi7pae9aE4136UanLCGw4nXx42hbvD2tPivuoLsHnxXfPj8_H2aRi_MGzsdEli-xToTgtZ4CwYAB_xFUuK7Z5VPcir_7Czj6Pc7MveBhOjCRbmFR9qA-CGKY8L-mfFwPw5B3eV-znmN5UM3ogYxFp5OGoXPnPe-LW0DuZHMr8Mdkm_df_CHxJPWl6eA7TE77cUQXj2iV_FgEVnKgqCKmo6Ts_OVVMHR-Rdqf8SX4H56AO-gT1mTipGYmqsZPR_x3PqJLlIGAqgXfzdLb9mElTz5LfuVT65EcE6sIelCuxxf4Tkc-KWimHow7V_d515cczLizc8GPYfmQapHi8U5ZJrdZW8u2kpXKsM7LVZGXvCzzbKg7XeUtXzWcd0IKXZUC-WqtJcdl0VZFlZlacCF5LvOci6XIX1rka6F4hVXXdHwt2ZLjqIx9sXY_vvjQZ4ZowrrkS15lVjVoaR56QsxzjMlNa1TvPEWjiQmRpmGo0-1FM_XEltwainS1F020WP96LNqF2rALuEcX6d-nYTYFWw8x7iixfh4XvYnD1LxoPzKxTZ5O_xa74H9DHZnYzmkQE9s5k78CAAD__0fAR80">