<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - unaligned Memory Access Identify"
href="https://bugs.llvm.org/show_bug.cgi?id=45707">45707</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>unaligned Memory Access Identify
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>8.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>2077213809@qq.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>When I write code to access a specified address that is not 4-byte aligned,The
compiler still thinks he's 4-byte aligned.
code:
void test() {
int *p = (int *)0x101;
*p = 2;
}
cmd: clang -O2 --target=arm-none-eabi -mcpu=cortex-r52 -emit-llvm -S test.c
test.ll
llvm IR: -- the store is align 4!
define dso_local void @test() local_unnamed_addr #0 {
store i32 2, i32* inttoptr (i32 257 to i32*), align 4, !tbaa !3
ret void
}
Even if I don't allow unaligned access, the compiler won't split into ldrb.
CMD: llc -mattr=+strict-align test.ll
ASM:
test:
.fnstart
@ %bb.0:
mov r0, #1
mov r1, #2
orr r0, r0, #256
str r1, [r0]
bx lr
GCC can identify the misaligned access.
CMD: arm-none-eabi-gcc -mcpu=cortex-r52 -munaligned-access -O2 -S test.c
test:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
mov r3, #0
mov r2, #2
str r2, [r3, #257] @ unaligned
bx lr
CMD: arm-none-eabi-gcc -mcpu=cortex-r52 -mno-unaligned-access -O2 -S test.c
test:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
mov r3, #0
mov r2, #2
strb r3, [r3, #258]
strb r3, [r3, #259]
strb r3, [r3, #260]
strb r2, [r3, #257]
bx lr</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>