1 ; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
2 ; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-unknown-linux-gnu"
7 %struct.S = type { [100 x i32] }
9 ; Safe access to a byval argument.
10 define i32 @ByValSafe(%struct.S* byval(%struct.S) nocapture readonly align 8 %zzz) norecurse nounwind readonly safestack uwtable {
12 ; CHECK-LABEL: @ByValSafe
13 ; CHECK-NOT: __safestack_unsafe_stack_ptr
15 %arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 3
16 %0 = load i32, i32* %arrayidx, align 4
20 ; Unsafe access to a byval argument.
21 ; Argument is copied to the unsafe stack.
22 define i32 @ByValUnsafe(%struct.S* byval(%struct.S) nocapture readonly align 8 %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable {
24 ; CHECK-LABEL: @ByValUnsafe
25 ; CHECK: %[[A:.*]] = load {{.*}} @__safestack_unsafe_stack_ptr
26 ; CHECK: store {{.*}} @__safestack_unsafe_stack_ptr
27 ; CHECK: %[[B:.*]] = getelementptr i8, i8* %[[A]], i32 -400
28 ; CHECK: %[[C:.*]] = bitcast %struct.S* %zzz to i8*
29 ; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[B]], i8* align 8 %[[C]], i64 400, i1 false)
31 %arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 %idx
32 %0 = load i32, i32* %arrayidx, align 4
36 ; Unsafe access to a byval argument.
37 ; Argument is copied to the unsafe stack.
38 ; Check that dest align of memcpy is set according to datalayout prefered alignment
39 define i32 @ByValUnsafe2(%struct.S* byval(%struct.S) nocapture readonly %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable {
41 ; CHECK-LABEL: @ByValUnsafe
42 ; CHECK: %[[A:.*]] = load {{.*}} @__safestack_unsafe_stack_ptr
43 ; CHECK: store {{.*}} @__safestack_unsafe_stack_ptr
44 ; CHECK: %[[B:.*]] = getelementptr i8, i8* %[[A]], i32 -400
45 ; CHECK: %[[C:.*]] = bitcast %struct.S* %zzz to i8*
46 ; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[B]], i8* %[[C]], i64 400, i1 false)
48 %arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 %idx
49 %0 = load i32, i32* %arrayidx, align 4
53 ; Highly aligned byval argument.
54 define i32 @ByValUnsafeAligned(%struct.S* byval(%struct.S) nocapture readonly align 64 %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable {
56 ; CHECK-LABEL: @ByValUnsafeAligned
57 ; CHECK: %[[A:.*]] = load {{.*}} @__safestack_unsafe_stack_ptr
58 ; CHECK: %[[B:.*]] = ptrtoint i8* %[[A]] to i64
59 ; CHECK: and i64 %[[B]], -64
61 %arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 0
62 %0 = load i32, i32* %arrayidx, align 64
63 %arrayidx2 = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 %idx
64 %1 = load i32, i32* %arrayidx2, align 4
65 %add = add nsw i32 %1, %0