<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60476>60476</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Inconsistent deduplication of string literals
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
slonopotamus
</td>
</tr>
</table>
<pre>
Given the following code
```cpp
#include <stdio.h>
static const char a[] = "bla";
static const char b[] = "bla";
static const char* const c = "bla";
int main() {
puts(a);
puts(b);
puts(c);
}
```
and compiling it with `-O1` and higher, I would expect either **one** or three literals in object file. **One** in case this falls under "String literals, and compound literals with const-qualified types, need not designate distinct objects." from C++ standard, and **three** in case it doesn't. But what in fact clang 12.0 produces is **two** literals:
```asm
main: # @main
push rbx
lea rbx, [rip + .L.str]
mov rdi, rbx
call puts@PLT
lea rdi, [rip + _ZL1b]
call puts@PLT
mov rdi, rbx
call puts@PLT
xor eax, eax
pop rbx
ret
_ZL1b:
.asciz "bla"
.L.str:
.asciz "bla"
```
So, clang thinks it is safe to merge `a` and `b` variables, but doesn't think it is safe to merge `c` to the same address. Is it misbehaving optimization or I am misunderstanding something?
Also, there's currently going on a [discussion on GCC bugtracker](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108626) that tries to decide whether just merging is valid at all or it violates the standard.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU1v2zgT_jX0ZRBBpvyVgw9x8roIUKAv0D3tpaDIkTQtRWrJkd321y9IyYmTrdFdwxBlcp75ePjMWMVIrUPci_VBrJ8WauTOh3203vnBs-rHuKi9-bH_QCd0wB1C4631Z3ItaG9QlE-ifJifm3L66mGYd2RFTtvRIIjqMbIhX3Si-t81KrJi0qC9iwy6UwHUlAyI6gmElLVVQkpRHW7Z1__NXsiHy68bkOlJjqFX5ITcCXkPYjufAgAMI0chd0rI-xfU1X79Zn_e1NebYvv0jrTr0MoZ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