summaryrefslogtreecommitdiff
path: root/test/Other
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2012-09-25 10:00:49 +0000
committerDuncan Sands <baldrick@free.fr>2012-09-25 10:00:49 +0000
commit00edf4c1d8a691543faf5adf7b05558497d38abb (patch)
treea4d3876a1cd9d802ea9e704501aef037a07a17db /test/Other
parentb1cacc74232164a9d80ee65d20e0095b25eb74d8 (diff)
downloadllvm-00edf4c1d8a691543faf5adf7b05558497d38abb.tar.gz
llvm-00edf4c1d8a691543faf5adf7b05558497d38abb.tar.bz2
llvm-00edf4c1d8a691543faf5adf7b05558497d38abb.tar.xz
Change the way the lint sanity checking pass detects misaligned memory accesses.
Previously it was only be able to detect problems if the pointer was a numerical value (eg inttoptr i32 1 to i32*), but not if it was an alloca or globa. The reason was the use of ComputeMaskedBits: imagine you have "alloca i8, align 2", and ask ComputeMaskedBits what it knows about the bits of the alloca pointer. It can tell you that the bottom bit is known zero (due to align 2) but it can't tell you that bit 1 is known one. That's because the address could be an even multiple of 2 rather than an odd multiple, eg it might be a multiple of 4. Thus trying to use KnownOne is ineffective in the case of an alloca as it will never have any bits set. Instead look explicitly for constant offsets from allocas and globals. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164595 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Other')
-rw-r--r--test/Other/lint.ll8
1 files changed, 6 insertions, 2 deletions
diff --git a/test/Other/lint.ll b/test/Other/lint.ll
index c84f56f8f6..f6787e973e 100644
--- a/test/Other/lint.ll
+++ b/test/Other/lint.ll
@@ -11,6 +11,8 @@ declare void @one_arg(i32)
@CG = constant i32 7
define i32 @foo() noreturn {
+ %buf = alloca i8
+ %buf2 = alloca {i8, i8}, align 2
; CHECK: Caller and callee calling convention differ
call void @bar()
; CHECK: Null pointer dereference
@@ -26,8 +28,10 @@ define i32 @foo() noreturn {
; CHECK: Address one pointer dereference
store i32 0, i32* inttoptr (i64 1 to i32*)
; CHECK: Memory reference address is misaligned
- %x = inttoptr i32 1 to i32*
- load i32* %x, align 4
+ store i8 0, i8* %buf, align 2
+; CHECK: Memory reference address is misaligned
+ %gep = getelementptr {i8, i8}* %buf2, i32 0, i32 1
+ store i8 0, i8* %gep, align 2
; CHECK: Division by zero
%sd = sdiv i32 2, 0
; CHECK: Division by zero