[llvm-bugs] [Bug 45707] New: unaligned Memory Access Identify
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Apr 28 01:30:33 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=45707
Bug ID: 45707
Summary: unaligned Memory Access Identify
Product: clang
Version: 8.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C
Assignee: unassignedclangbugs at nondot.org
Reporter: 2077213809 at qq.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
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
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200428/91220ac2/attachment-0001.html>
More information about the llvm-bugs
mailing list