<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54860>54860</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Bad codegen: when optimizing for armeabi-v7a target, clang did not consider `-fno-aligned-allocation` option.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
chirsz-ever
</td>
</tr>
</table>
<pre>
Environment: NDK23
The `clang --version` output of my NDK23:
```
Android (7714059, based on r416183c1) clang version 12.0.8 (https://android.googlesource.com/toolchain/llvm-project c935d99d7cf2016289302412d708641d52d2f7ee)
```
My cflags:
```
-frtti -fexceptions -std=c++17 -fno-aligned-allocation -flto
```
When I compile a Android native shared library for armeabi-v7a, there is a type like this:
```cpp
class Mat4 {
public:
//... only some member functions
Mat4 operator*(const Mat4& other) const {
// ...
}
private:
float data_[4][4];
};
```
And there is the code using `Mat4`, where crashes ramdomly occurs.:
```
// m_VertData.mat1, m_mat1, mat2 and m_mat3 are Mat4
m_VertData.mat1 = m_mat1 * mat2 * m_mat3;
```
After checking the generated assembly code, I found that:
![image](https://user-images.githubusercontent.com/31474766/162877140-37ff052f-063a-4ee0-8665-7c2d2a924c66.png)
This `vst1.64 {d20, d21}, [r0:128]` requires `r0` with 16 bytes alignment, but acctually `r0` is not 16-byte-aligned.
My guess is that clang thinks `m_VertData.mat1` is 16-byte-aligned so generating the neon instructions, but due to the `-fno-aligned-allocation` option `m_VertData.mat1` is not 16-byte-aligned, and then the program crashed.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVVGTozYM_jXkRQMDhkB4yEO2aWduOtenTvu4Y2wB7gKmtsk29-srG7K5y-xum2GCkS3pk_RJbrS8Hn-eLsroacTJRfkJfjv_yvIoPUfpaf3_vUeIylQMfOogji9orNITSUAvbl4c6BbG66aXn75XpUPbEz5PkzRaSYjYoaqyIt3XEf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