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 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 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* %[[B]], i8* %[[C]], i64 400, i32 8, 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; Highly aligned byval argument. 37define i32 @ByValUnsafeAligned(%struct.S* byval nocapture readonly align 64 %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable { 38entry: 39 ; CHECK-LABEL: @ByValUnsafeAligned 40 ; CHECK: %[[A:.*]] = load {{.*}} @__safestack_unsafe_stack_ptr 41 ; CHECK: %[[B:.*]] = ptrtoint i8* %[[A]] to i64 42 ; CHECK: and i64 %[[B]], -64 43 ; CHECK: ret i32 44 %arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 0 45 %0 = load i32, i32* %arrayidx, align 64 46 %arrayidx2 = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 %idx 47 %1 = load i32, i32* %arrayidx2, align 4 48 %add = add nsw i32 %1, %0 49 ret i32 %add 50} 51 52