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

    <tr>
        <th>Summary</th>
        <td>
            Improvement: diagnose undefined behavior: object is referred to outside of its lifetime
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    ```
struct X { int a[5]; } f(void);
int f1(void)
{
    int *p = f().a;
    return *p;              // leads to UB
}
```
Invocation:
```
$ clang -std=c11 -Wall -Wextra -pedantic -O3
```
Expected diagnostics:
```
warning: object is referred to outside of its lifetime, the behavior is undefined
```
Actual diagnostics:
```
<nothing>
```
C11, 6.2.4 Storage durations of objects, 8:
> A **non-lvalue expression with structure or union type, where the structure or union
contains a member with array type** (including, recursively, members of all contained
structures and unions) refers to an object with automatic storage duration and **temporary
lifetime**.36) Its lifetime begins when the expression is evaluated and its initial value is the
value of the expression. Its **lifetime ends when the evaluation of the containing full
expression or full declarator ends**. Any attempt to modify an object with temporary
lifetime results in **undefined behavior**.

> 36) The address of such an object is taken implicitly when an array member is accessed.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVUuPozgQ_jVwKQXxTIcDh_RjpD7NYXc0czW4AO8YG9km3fn3U8YknZ7NSLsIJdgu1_eoMrSan5ton253-hylR-vM0jn4AdHDIwjlgEXVYxVVz1HxSHPP0Ef54aQFj_KapsImH9dnNwvrLGUID0CXD4ny4wxREXJQWMKuGXyIQbcYtUZ5sE9XlH-hGyQybsFp-PZ4wXjeHj7LeFUn3TEntIqK492IKC-hk0wNsLOOE6suy2D3nUlJv_juDIPdjJwpJzrYfS3uJnl5n7FzyIELNihtKdb-CfCNGSXUQMug239oGwhLmns0hhKQJr04KziC7kE4C1L06MSEUf4EbkRocWQnoY3ftiiOvVDI7yIdO7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