<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64707>64707</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
gcc and llvm operations about operator new inconsistent
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
LukeSTM
</td>
</tr>
</table>
<pre>
clang: https://godbolt.org/z/E9Pj5W7d9
gcc: https://godbolt.org/z/v83bbPE99
```
#include <cstddef>
#include <new>
#include <iostream>
bool success=false;
struct alignas(2*__STDCPP_DEFAULT_NEW_ALIGNMENT__) A {
} a;
/*
Called by non-array new-expressions to allocate storage required for a single
object whose alignment requirement exceeds __STDCPP_DEFAULT_NEW_ALIGNMENT__
https://en.cppreference.com/w/cpp/memory/new/operator_new
*/
void* operator new(std::size_t, std::align_val_t) {
success=true;
return (void *) &a;
}
int test_it (void) {
A *a=new A();
return success;
}
int main()
{
test_it();
if (success == false) {
std::cout << "fail" << std::endl;
return 1;
}
std::cout << "success" <<std::endl;
return 0;
}
```
I see the asm
```
operator new(unsigned long, std::align_val_t): // @operator new(unsigned long, std::align_val_t)
adrp x8, success
adrp x0, a
add x0, x0, :lo12:a
mov w9, #1
strb w9, [x8, :lo12:success]
ret
test_it(): // @test_it()
adrp x8, success
ldrb w0, [x8, :lo12:success]
ret
```
checked the IR and asm, i think this error is cased by EarlyCSEPass. Becase after this pass ,there is no operator new in test_it().
Anyone have idea to fix it?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVl9v4jgQ_zTmZVSU2PzLAw8pkNNKu1V17WkfkWNPgrfG5mwHyn76k0OgkHZ7d4uQk3hmfvPzzHhs7r2qDeKcjO_JeDngTdhYN__avODT87dBaeVxLjQ3NWE5bELYecJyQgtCi9rK0uowtK4mtPhJaLHKHn-Mv09lRpIlSfJaiP9itZ-xsnxcZZ1VN06S7n_6pEwZoR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