<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/81446>81446</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang - Confusing crash in compiled program
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
AldrinMathew
</td>
</tr>
</table>
<pre>
This seemingly correct LLVM IR is crashing once it is compiled and run using clang
The command for compilation throughout this example is
`clang -c --target=x86_64-unknown-linux-gnu ./test/file-m2.ll -o ./test/file-m2.o && clang -o ./test/m2 --target=x86_64-unknown-linux-gnu ./test/file-m2.o && ./test/m2`
[file-m2.txt](https://github.com/llvm/llvm-project/files/14235870/file-m2.txt)
The specific suspicious part are lines 158 to 162:
```llvm
%10 = call i32 (ptr, ...) @printf(ptr @"qat'str'101", i64 14, ptr @"qat'str'100")
%11 = load %"qat'type_Matrix:[4,2,qat'i32]", ptr %res, align 4
store %"qat'type_Matrix:[4,2,qat'i32]" zeroinitializer, ptr %res, align 4
store i32 0, ptr %i, align 4
ret %"qat'type_Matrix:[4,2,qat'i32]" %11
```
The strangest part is if that part is changed to the following, it no longer crashes:
```llvm
%10 = load %"qat'type_Matrix:[4,2,qat'i32]", ptr %res, align 4
%11 = call i32 (ptr, ...) @printf(ptr @"qat'str'101", i64 14, ptr @"qat'str'100")
store %"qat'type_Matrix:[4,2,qat'i32]" zeroinitializer, ptr %res, align 4
store i32 0, ptr %i, align 4
ret %"qat'type_Matrix:[4,2,qat'i32]" %10
```
__All I did here is reverse the order of the instructions `%10` and `%11`__
In the original program, the first order of instruction is the correct one. Similar for LLVM IR as well as these are not dependent on each other.
__Similarly, if another instruction is added after `%11` (in the original file), the program no longer crashes__:
```llvm
%10 = call i32 (ptr, ...) @printf(ptr @"qat'str'101", i64 14, ptr @"qat'str'100")
%11 = load %"qat'type_Matrix:[4,2,qat'i32]", ptr %res, align 4
%"AnotherInst" = call i32 (ptr, ...) @printf(ptr @"qat'str'101", i64 14, ptr @"qat'str'100")
store %"qat'type_Matrix:[4,2,qat'i32]" zeroinitializer, ptr %res, align 4
store i32 0, ptr %i, align 4
ret %"qat'type_Matrix:[4,2,qat'i32]" %11
```
I am not sure if this is an issue with clang or llvm.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcVk1v4zgP_jXKhUhgy1_JwYdOiwAFZi7vO9hroNi0zV1F8kr0tJ1fv5DsNmm7HzMFugUWKOrIpvg8pB6RVN5TbxBrUXwSxc1KTTxYV1_p1pH5onjAu9XRtg_114E8eMQTmV4_QGOdw4bh8-dfvsDt_4A8NE75gUwP1jQIxPGdPY2ksQVlWnCTgckHi0Yr04vkRiRX8_-vAwbbUzDrrFv2KSZrgAdnp36wEwMHEnivTqNGIL94KJPoD9YNrNesXI8sspv7bXko8_VkfjP2zqw1mel-3ZsJNkLuGT0Lue9I4_okN1rD2v7ZBwtClkKWsCA8MzrJt-I9uX3mTZTJZU5E8enRnu9ZFDdCbgfm0YvsSsi9kPueeJiOm8aehNxr_e3xsR6d_RWbR0Qv5D7NZVZsq-SCRHAqdy9PwY_YUEcN-MmP1JCdPIzKMSiHoMmgh7TYAltISxmYXDIuk_kvcplfySJNQGQ30CitgTIJQm5HdkJew2azEXIHIk9GR4a7-UtYCyl_Vyxk5YNllSapkDJsoTKHNA-__soyiZa7M3wa4bVVLQhZPNnzw4iHL4od3Ycwik_Ba8CYP1MmY8rlE5YsXEjlNShNvYF8RvBsHb7JMXxHZ8kQk9L0Hd0PAYUEJheW9MrOIb-NTszVi4N8pQ52yvToedYEeaAOeFDndTMEgzYIhAeEzmpt78j08fAYjAVtTY9uLhfof0ZC73WGZ5V8iEj_WxJK_kZCh8OV1nALLbUwYODiweE3dB6jWqxr0YHt4oKMZzc1oQd4CI6i8zKJvWRZp6JMDodLiFuzeKKejNIwOts7dQoxRj2S83zGucAIXDi2obmzWYMb-D-dSCsXe9Jjq1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