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

    <tr>
        <th>Summary</th>
        <td>
            Frontend doesn't emit IR (or sanitizer checks) for discarded-value expression (even when they contain UB)
        </td>
    </tr>

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

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

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

<pre>
    So it turns out Clang doesn't emit any IR for loads from pointers if the result of the load isn't used for anything.

A simple case is the example below:

```cpp
int main() {
    int *i = nullptr;
    (void)(*i); // This should be reported by UBSan?
}
```
On godbolt:
https://godbolt.org/z/veE1cWbe8

One way how this can occur in the wild is via the "assert with preserving side effects trick" such as:

```cpp
#define safe_assert(s) do { (s); } while(false)
```

The main problem here is that with enabled sanitizer this issue doesn't get caught or reported as there is just no code that can be sanitized. Note that once you change the expression from `*i` to like `*i + 0` then you actually get a correct sanitizer check emitted.

This actually seems to happen in the frontend which doesn't generate any IR (so, this is not DCE or anything like that).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyFVE2P2zgM_TXOhWjg2JOvgw_JpAPsZQtsp9jjQpaYWB1FMiQ52fTX75PsTNNBgTUcOyRN8vGRVOvUrfnqSEeKg7eB3BDp2Qh7IuU42KJaR-IzzMLe6I-_6Og8GSdUoKN3Z-qdtpF9IH2k2DF5DoOJ5EYpfUh6ijIEVtkdkWKn7WlelIei3I3PHQV97g2TFIHhk_35X5F1LRt3Lerdo0OxKsdb9v2oARI6C41sm6LaUrHej3rClWxFtdNU1AeygzF99EX98AGcLk4rOGb3nU7_6j30L7jptQOk0LnBKKBBmb3zEfW0N_q2_ypsUb9MsNaHD_hG8Yulk1OtM_G9ji7GPiQpp5isc-dPkH7gd-HPC_l3y5vHsr9Ypqu4UeeuoAigpLDkpBw8asykXbVJpNNF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