<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJy1WF2T2joS_TXMiwoK23iABx6AmdSmKvdOapPd5G1K2AKUCItI9jDcX7-nJdnYhkm2snenXHgstfpLp1vd2uj8vBjESzyZ4sWOvQhjpS4GydKPDsYPg_EySkbjUcR0wb7IItcnG0WDeM3CMC_ZIF3tdL7RqhxpsxukD4N4ti_Lo3WM3uFpT8dzWn004kXqytYyLTtqa-VGndnW6AObgPnYyw-_TqOlyfayFFlZGdFT8-vsnhh_vZ_Qi5sDgxrQTgluS0gdXXN73G7Bqsfny14UrNwLxvPcCGuZ3jLObMlLmbG8MnjDFVVR8IPImd58AwtmBDQq8L05gzjTh6Ouipwp6Gq4YtKyymK21EwWspRcyb_wSZSFLYc_KgxsJUaOWhZYQqoXugRBPYCV19Tl-SgGMXZj7hQOukAYEcpcGNAUUPagcyzgGyVuOOEf-kTcjTganVeZaPvi894xy4WbFlYUpYUeBxhxgFnilR-OStByoWQmS6cG-EDSgdzqxdyPw-M-SelcbOFRU0HbwXTlxxn-YCvEVWTxIAnjg-kDWymdfb-MuN-wI24K_lp677CN_04eMAZAzPxSgG66YnGaQt5DjxEJZVuQvmiZky_bKjl2w0HyGNRynOM0bniAxm_-FWnbgpue-Axn7UQBhJTYKOfmjIOPYFYAgwirPbbwl_GEgWTnpoCEGZ63P_b4IDmPuSy1QZxINzvbSiUIz-5rCuIp5ra6KD9lXNFoNAkD_7Li46snG3uybzSNN2UQ_Pv8_JzhywoFLNbJZCaKfK1VdaDPGNP4_iAL8Wd12JCjlhGYrZEBJC1pKKPWYJe8LeFTyU3Z4d6duhZkOyuieqQvghKV1ZXJgl8CcgfxymMX_wzidEo_FEyr5gGi8FvDIE6TmiQFEuJVgGRruEbzZXLlwnDlMI33phlNkwf_7qLb67ECwoNWDz0BXic8LaTfNiDgGMsbJF8EE_RbjMMSHwFvrO2ZP_WOVd6nqQdR0YGU9l9r8rT3v7c4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6ZhWO5qVAaTMZUudjLJLeUw4VY-BP7rpSlEosstLVvFJS0ea1wdQehD7y9cQjthdydM2LhLPgPZg8IaQ>54014</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang: compound literals are not modifiable when used through a const pointer
        </td>
    </tr>

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

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

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

<pre>
    **clang version:**
13.0.1 on Windows11, 13.0.1 at [godbolt.org](https://godbolt.org), previous versions possibly from 4.0.0

**Architecture:**
X86, X64, arm (at least).

**Effect:**
When the address of a static duration unnamed object returned by a compound literal is used to initialized a const-qualified pointer (not a pointer to a const-qualified type!) the object is considered non modifiable.

**How to reproduce**
This code represents a minimal example to elicit the problem:
```
typedef struct {
    int counter;
} Block;

static Block * const block = &(Block){ 255 };

int  f(void) {
   block->counter = 252;
   return block->counter;
}
```
The generated code can be seen [here](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,selection:(endColumn:2,endLineNumber:10,positionColumn:1,positionLineNumber:1,selectionStartColumn:2,selectionStartLineNumber:10,startColumn:1,startLineNumber:1),source:'typedef+struct+%7B%0A++++int+counter%3B%0A%7D+Block%3B%0A%0Astatic+Block+*+const+block+%3D+%26(Block)%7B+255+%7D%3B%0A%0Aint++f(void)+%7B%0A+++block-%3Ecounter+%3D+252%3B%0A+++return+block-%3Ecounter%3B%0A%7D'),l:'5',n:'0',o:'C+source+%231',t:'0')),k:52.597130589590535,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:cclang1301,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'0',intel:'0',libraryCode:'1',trim:'1'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,libs:!(),options:'-O0',selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1,tree:'1'),l:'5',n:'0',o:'x86-64+clang+13.0.1+(C,+Editor+%231,+Compiler+%231)',t:'0'),(h:executor,i:(argsPanelShown:'1',compilationPanelShown:'0',compiler:cg112,compilerOutShown:'0',execArgs:'',execStdin:'',fontScale:14,fontUsePx:'0',j:1,lang:___c,libs:!(),options:'',source:1,stdinPanelShown:'1',tree:'1',wrap:'1'),l:'5',n:'0',o:'Executor+x86-64+gcc+11.2+(C,+Editor+%231)',t:'0')),k:47.40286941040947,l:'4',m:100,n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4).

**Expected behaviour:**
The unnamed object pointed by block is modified, the function returns 252.
As the code is standard compliant - see Rationale below - the behaviour is defined and no warning or error are expected.

**Actual behaviour:**
The function returns 255, the unnamed object is in fact modified, but only with -O0.
Optimization levels from -O0 to -O3 including -Og do not change the function result.
The code does not generate any error or warning with:
`-std=c11 -pedantic -Wextra -Wall`

**Rationale**
I'll use SO/IEC 9899:2011 as a reference in the following.
C11 standard states quite clearly that compound literals are (modifiable) lvalues:
 
>     6.5.2.5 Compound literals
>     ...
>     A postfix expression that consists of a parenthesized type name followed by a 
>     brace-enclosed list of initializers  is a compound literal. It provides an unnamed
>     object whose value is given by the initializer list.
>     ...
>     the result is an lvalue.
>     ...
>     EXAMPLE 5 The following three expressions have different meanings:
>     "/tmp/fileXXXXXX"
>     (char []){"/tmp/fileXXXXXX"}
>     (const char []){"/tmp/fileXXXXXX"}

>     The first always has static storage duration and has type array of char, but need
>     not be modifiable; the last two  have automatic storage duration when they occur
>     within the body of a function, and the first of these two is modifiable.

In C lvalues are generally modifiable, unless the fall in the categories specified in ยง4 of _6.3.2.1 Lvalues, arrays, and function designators_:
> ...
> A modifiable lvalue is an lvalue that does not have array type, does not have an
> incomplete type, does not have a const-qualified type, and if it is a structure or
> union, does not have any member (including, recursively, any member or element
> of all contained aggregates or unions) with a const-qualified type.

None of the exceptions apply to the case in question.

In the light of the above, there's no reason for the example code to misbehave.
An unnamed, static duration, modifiable object is created and initialized, its address taken and used to initialize a const pointer.
It should be possible to use the pointer to modify the underlying object.

Moreover, removing the const qualifier from the pointer declaration produces working code, though the pointer const-qualification should not affect in any way the qualification of the pointed-to object.

Other compilers (e.g. gcc) give the expected behaviour (I understand this not a compelling justification - the standard is).

Thanks for your support.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1WFtv27gS_jXOC2FDFzu2H_JgO1mcAt1Ncdpztm8FJdE2W1p0SSmO99fvNyQlS7LTHhR7AsGKyOHc-M1whpkuzg-jZIUnV7zcsRdhrNTlKF350VH0OIpWcTqJJjHTJftTloU-2TgeJRsWhnnFRrP1TheZVtVEm91o9jhKFvuqOlrH6Dc83elkSauPRrxIXdtGpmVHba3M1JltjT6wKZhHXn74dRqtTL6Xlcir2oiBmp8X98T48_2UXtwcGNSAdkpwW0Hq5Jrb03YLVgM-f-5Fyaq9YLwojLCW6S3jzFa8kjkraoM3XFGXJT-IgunsK1gwI6BRie_sDOJcH466LgumoKvhiknLaovZSjNZykpyJf_CJ1GWthp_rzGwlRg5alliCale6goEzQBWXlNX56MYJdiNpVM46AJhRCgLYUBTQtmDLrCAZ0rccMK_9Im4G3E0uqhz0fXFp71jVgg3LawoKws9DjDiALPEKz8claDlQslcVk4N8IGkA7nVi7mPwuM-SelCbOFRU0Pb0Xztxxn-YCvE1WTxKA3jo_kjWyudf7uMuN-wI24K_lp577DMf6ePGAMgFn4pQDdfs2Q2g7zHASMSyrYgfdGyIF92VXLsxqP0KajlOCezpOUBGr_5V6RdC2564hOctRMlEFJho5ybcw4-glkBDCKs9tjCn8YTBtKdmwISFnje_tjjg-Q8FbLSBnEi3exiK5UgPLuvOYjnmNvqsvqYc0Wj8TQM_MeKD6-eLPJkX2kab8og-PfLly85vqxQwGKTTBaiLDZa1Qf6TDCN7_eyFH_U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