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