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

    <tr>
        <th>Summary</th>
        <td>
            [clang] Miscompilation concerning const pointer to file-scope compound literal
        </td>
    </tr>

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

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

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

<pre>
    ### Minimal reproducible example:
`main.c`
```c
#include <stdio.h>

typedef struct {
        int foo;
}       global_t;

global_t *const global = &(global_t){0};

int main(void) {
        global->foo = 10;
        printf("%d\n", global->foo);
}
```

### Expected behaviour:
The above code should print 10. The value being assigned also appears in the generated assembly, but isn't printed at execution.

### Actual behaviour:
This code compiles successfully without warnings and prints 0.

### Compiled with:
`clang main.c -Wall -Wextra -Werror -pedantic -fsanitize=undefined,address`
- on version `17.0.0.1`, target `x86_64-unknown-linux-gnu` on godbolt ([link](https://godbolt.org/z/1xqhqrqor))
- on version `14.0.0-1ubuntu1.1`, target `x86_64-pc-linux-gnu`
- on version `12.0.1-19ubuntu3`, target `x86_64-pc-linux-gnu`

All three versions are affected.

I also compiled it on gcc in order to compare:
`gcc main.c -Wall -Wextra -Werror -pedantic -fsanitize=undefined,address`
- on version `13.2.0` on godbolt ([link](https://godbolt.org/z/33xWvh4vK))
- on version `11.4.0-1ubuntu1~22.04`

Both versions compile successfully and produce `10`, the expected behaviour.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VU1v4zYQ_TX0ZSCBImVLOviQ2GugKPZWYI8LihxZ7NKkwg_H2UN_e0HJTuJgU6AoCgiSPcN5fDNvOBQh6KNF3JL1I1nvVyLF0fntWY7ix2jdqnfqZUsYXx74qq0-CQMeJ-9Ukro3CHgRp8kg4Q-E7gl9IBt6EtqWkmzoq2V55PU_49pKkxQC4bsQlXblSPiXq3d-x5c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