<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/96512>96512</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[ASAN] new-delete-type-mismatch on aligned operator new
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
thiagomacieira
</td>
</tr>
</table>
<pre>
Simple test case:
```c++
#include <new>
int main()
{
delete new (std::align_val_t(64)) char;
}
```
Produces:
```
=================================================================
==31626==ERROR: AddressSanitizer: new-delete-type-mismatch on 0x509000000040 in thread T0:
object passed to delete has wrong type:
alignment of the allocated type: 64 bytes;
alignment of the deallocated type: default-aligned.
#0 0x5575d77192f8 in operator delete(void*) /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/projects/compiler-rt/lib/asan/asan_new_delete.cpp:143:3
#1 0x5575d771aeb4 in main (/tmp/asan+0x10eeb4) (BuildId: 60e9703eb3f6670b2556a286db665665d9671536)
#2 0x7ff8b962a1ef in __libc_start_call_main (/lib64/libc.so.6+0x2a1ef) (BuildId: a2c0942c27fb9483b47886a1b937337a797bbceb)
#3 0x7ff8b962a2b8 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2a2b8) (BuildId: a2c0942c27fb9483b47886a1b937337a797bbceb)
#4 0x5575d763d104 in _start /home/abuild/rpmbuild/BUILD/glibc-2.39/csu/../sysdeps/x86_64/start.S:115
0x509000000040 is located 0 bytes inside of 1-byte region [0x509000000040,0x509000000041)
allocated by thread T0 here:
#0 0x5575d7718e7d in operator new(unsigned long, std::align_val_t) /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/projects/compiler-rt/lib/asan/asan_new_delete.cpp:98:3
#1 0x5575d771ae9d in main (/tmp/asan+0x10ee9d) (BuildId: 60e9703eb3f6670b2556a286db665665d9671536)
#2 0x7ff8b962a1ef in __libc_start_call_main (/lib64/libc.so.6+0x2a1ef) (BuildId: a2c0942c27fb9483b47886a1b937337a797bbceb)
SUMMARY: AddressSanitizer: new-delete-type-mismatch (/tmp/asan+0x10eeb4) (BuildId: 60e9703eb3f6670b2556a286db665665d9671536) in main
==31626==HINT: if you don't care about these errors you may set ASAN_OPTIONS=new_delete_type_mismatch=0
==31626==ABORTING
```
Reproduced with LLVM 18.1.6.
Matching GCC bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115619
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcVl1vqzgT_jXOjRUENhi4yEXSnJy3Uj-O2p5Xeq-QPybgV4CRbdrm_PqVIWnT9nzsSrta7UaIgPHYz3jmeWa4c7ruAVYo26Bsu-Cjb4xd-Ubz2nRcatCWL4RRh9W97oYWsAfnseQOEF2jeIviNWLxfElENuGaRwnVvWxHBRjRix6eEP00f9G9xx3XPSIFIuVxdn40wxhjBS14wD08YUQK51XYiq55q-u-euRt5REpWBqMSYllwy2ip13z7TtQ8-sXa9QowX0EfXyl23_8deYITRhh8-Onu7vbO0TXeK2UBefuea-9_gY2jPXwtJxPe-kPAyw77TruZYNNj-PnLC7j-ZfGWPfYNxa4wg_xyylibMT_QXo8cOdAYW9OwWu4w0_W9DUOC58ZTFHsoPfY7LFvAPO2NZL7YD3PxBizFIuDD-Ha_NBOwUdLBXs-tn45TQYVveYUIjQOLmV5pvI8Kcm-CC6ZASz3xh5hI1I8Gq0QWYfMQmTXmA4Q2XEx6lYhsrNDd3rcfL282iKya9vHbpkUURKxyFmJyG6wJhyKQ2QnTTfoFuzS-jBVi7CY4_3xr-rhqZq3juQwILpOUoromh6BI0KTM9QcRBpQB_bgiT473w0vS27i5yQGEOkMvtgEpJeBPZjFUOYxBUH3jOWxIFnGOCmYEoxljGWqZHmSUfZCyOOZERw_5_t9IUpGeAL7sHtVtVrIynlufSV521ZneFotAjPDv4ycidgEa7L9iIoTGZcpkSTfizItqEjzomA8ESXNKc15XuZCSBDvUdFzVEQUH1B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