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 3 4target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 5target triple = "x86_64-unknown-linux-gnu" 6 7%struct.S = type { [100 x i32] } 8 9; Safe access to a byval argument. 10define i32 @ByValSafe(%struct.S* byval(%struct.S) nocapture readonly align 8 %zzz) norecurse nounwind readonly safestack uwtable { 11entry: 12 ; CHECK-LABEL: @ByValSafe 13 ; CHECK-NOT: __safestack_unsafe_stack_ptr 14 ; CHECK: ret i32 15 %arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 3 16 %0 = load i32, i32* %arrayidx, align 4 17 ret i32 %0 18} 19 20; Unsafe access to a byval argument. 21; Argument is copied to the unsafe stack. 22define i32 @ByValUnsafe(%struct.S* byval(%struct.S) nocapture readonly align 8 %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable { 23entry: 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) 30 ; CHECK: ret i32 31 %arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 %idx 32 %0 = load i32, i32* %arrayidx, align 4 33 ret i32 %0 34} 35 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 39define i32 @ByValUnsafe2(%struct.S* byval(%struct.S) nocapture readonly %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable { 40entry: 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) 47 ; CHECK: ret i32 48 %arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 %idx 49 %0 = load i32, i32* %arrayidx, align 4 50 ret i32 %0 51} 52 53; Highly aligned byval argument. 54define i32 @ByValUnsafeAligned(%struct.S* byval(%struct.S) nocapture readonly align 64 %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable { 55entry: 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 60 ; CHECK: ret i32 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 66 ret i32 %add 67} 68 69