Summary: This change is part of step five in the series of changes to remove alignment argument from memcpy/memmove/memset in favour of alignment attributes. In particular, this changes the creation of memcpys in the SafeStack pass to set the alignment of the destination object to its stack alignment while separately setting the source byval arguments alignment to its alignment. Steps: Step 1) Remove alignment parameter and create alignment parameter attributes for memcpy/memmove/memset. ( rL322965, rC322964, rL322963 ) Step 2) Expand the IRBuilder API to allow creation of memcpy/memmove with differing source and dest alignments. ( rL323597 ) Step 3) Update Clang to use the new IRBuilder API. ( rC323617 ) Step 4) Update Polly to use the new IRBuilder API. ( rL323618 ) Step 5) Update LLVM passes that create memcpy/memmove calls to use the new IRBuilder API, and those that use use MemIntrinsicInst::[get|set]Alignment() to use [get|set]DestAlignment() and [get|set]SourceAlignment() instead. (rL323886, rL323891, rL324148, rL324273, rL324278, rL324384, rL324395, rL324402, rL324626, rL324642, rL324653, rL324654, rL324773, rL324774, rL324781, rL324784 ) Step 6) Remove the single-alignment IRBuilder API for memcpy/memmove, and the MemIntrinsicInst::[get|set]Alignment() methods. Reference http://lists.llvm.org/pipermail/llvm-dev/2015-August/089384.html http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20151109/312083.html Reviewers: eugenis, bollu Reviewed By: eugenis Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D42710 llvm-svn: 324955
69 lines
2.9 KiB
LLVM
69 lines
2.9 KiB
LLVM
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
|
; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
|
|
|
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
|
target triple = "x86_64-unknown-linux-gnu"
|
|
|
|
%struct.S = type { [100 x i32] }
|
|
|
|
; Safe access to a byval argument.
|
|
define i32 @ByValSafe(%struct.S* byval nocapture readonly align 8 %zzz) norecurse nounwind readonly safestack uwtable {
|
|
entry:
|
|
; CHECK-LABEL: @ByValSafe
|
|
; CHECK-NOT: __safestack_unsafe_stack_ptr
|
|
; CHECK: ret i32
|
|
%arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 3
|
|
%0 = load i32, i32* %arrayidx, align 4
|
|
ret i32 %0
|
|
}
|
|
|
|
; Unsafe access to a byval argument.
|
|
; Argument is copied to the unsafe stack.
|
|
define i32 @ByValUnsafe(%struct.S* byval nocapture readonly align 8 %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable {
|
|
entry:
|
|
; CHECK-LABEL: @ByValUnsafe
|
|
; CHECK: %[[A:.*]] = load {{.*}} @__safestack_unsafe_stack_ptr
|
|
; CHECK: store {{.*}} @__safestack_unsafe_stack_ptr
|
|
; CHECK: %[[B:.*]] = getelementptr i8, i8* %[[A]], i32 -400
|
|
; CHECK: %[[C:.*]] = bitcast %struct.S* %zzz to i8*
|
|
; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[B]], i8* align 8 %[[C]], i64 400, i1 false)
|
|
; CHECK: ret i32
|
|
%arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 %idx
|
|
%0 = load i32, i32* %arrayidx, align 4
|
|
ret i32 %0
|
|
}
|
|
|
|
; Unsafe access to a byval argument.
|
|
; Argument is copied to the unsafe stack.
|
|
; Check that dest align of memcpy is set according to datalayout prefered alignment
|
|
define i32 @ByValUnsafe2(%struct.S* byval nocapture readonly %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable {
|
|
entry:
|
|
; CHECK-LABEL: @ByValUnsafe
|
|
; CHECK: %[[A:.*]] = load {{.*}} @__safestack_unsafe_stack_ptr
|
|
; CHECK: store {{.*}} @__safestack_unsafe_stack_ptr
|
|
; CHECK: %[[B:.*]] = getelementptr i8, i8* %[[A]], i32 -400
|
|
; CHECK: %[[C:.*]] = bitcast %struct.S* %zzz to i8*
|
|
; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[B]], i8* %[[C]], i64 400, i1 false)
|
|
; CHECK: ret i32
|
|
%arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 %idx
|
|
%0 = load i32, i32* %arrayidx, align 4
|
|
ret i32 %0
|
|
}
|
|
|
|
; Highly aligned byval argument.
|
|
define i32 @ByValUnsafeAligned(%struct.S* byval nocapture readonly align 64 %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable {
|
|
entry:
|
|
; CHECK-LABEL: @ByValUnsafeAligned
|
|
; CHECK: %[[A:.*]] = load {{.*}} @__safestack_unsafe_stack_ptr
|
|
; CHECK: %[[B:.*]] = ptrtoint i8* %[[A]] to i64
|
|
; CHECK: and i64 %[[B]], -64
|
|
; CHECK: ret i32
|
|
%arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 0
|
|
%0 = load i32, i32* %arrayidx, align 64
|
|
%arrayidx2 = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 %idx
|
|
%1 = load i32, i32* %arrayidx2, align 4
|
|
%add = add nsw i32 %1, %0
|
|
ret i32 %add
|
|
}
|
|
|