1*9880d681SAndroid Build Coastguard Worker; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s 3*9880d681SAndroid Build Coastguard Worker 4*9880d681SAndroid Build Coastguard Worker%struct.foo = type { [16 x i8] } 5*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard Worker@.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1 7*9880d681SAndroid Build Coastguard Worker 8*9880d681SAndroid Build Coastguard Worker; struct { [16 x i8] } 9*9880d681SAndroid Build Coastguard Worker 10*9880d681SAndroid Build Coastguard Workerdefine void @foo(i8* %a) nounwind uwtable safestack { 11*9880d681SAndroid Build Coastguard Workerentry: 12*9880d681SAndroid Build Coastguard Worker ; CHECK: %[[USP:.*]] = load i8*, i8** @__safestack_unsafe_stack_ptr 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Worker ; CHECK: %[[USST:.*]] = getelementptr i8, i8* %[[USP]], i32 -16 15*9880d681SAndroid Build Coastguard Worker 16*9880d681SAndroid Build Coastguard Worker ; CHECK: store i8* %[[USST]], i8** @__safestack_unsafe_stack_ptr 17*9880d681SAndroid Build Coastguard Worker 18*9880d681SAndroid Build Coastguard Worker %a.addr = alloca i8*, align 8 19*9880d681SAndroid Build Coastguard Worker %buf = alloca %struct.foo, align 1 20*9880d681SAndroid Build Coastguard Worker 21*9880d681SAndroid Build Coastguard Worker ; CHECK: %[[AADDR:.*]] = alloca i8*, align 8 22*9880d681SAndroid Build Coastguard Worker ; CHECK: store i8* {{.*}}, i8** %[[AADDR]], align 8 23*9880d681SAndroid Build Coastguard Worker store i8* %a, i8** %a.addr, align 8 24*9880d681SAndroid Build Coastguard Worker 25*9880d681SAndroid Build Coastguard Worker ; CHECK: %[[BUFPTR:.*]] = getelementptr i8, i8* %[[USP]], i32 -16 26*9880d681SAndroid Build Coastguard Worker ; CHECK: %[[BUFPTR2:.*]] = bitcast i8* %[[BUFPTR]] to %struct.foo* 27*9880d681SAndroid Build Coastguard Worker ; CHECK: %[[GEP:.*]] = getelementptr inbounds %struct.foo, %struct.foo* %[[BUFPTR2]], i32 0, i32 0, i32 0 28*9880d681SAndroid Build Coastguard Worker %gep = getelementptr inbounds %struct.foo, %struct.foo* %buf, i32 0, i32 0, i32 0 29*9880d681SAndroid Build Coastguard Worker 30*9880d681SAndroid Build Coastguard Worker ; CHECK: %[[A:.*]] = load i8*, i8** %[[AADDR]], align 8 31*9880d681SAndroid Build Coastguard Worker %a2 = load i8*, i8** %a.addr, align 8 32*9880d681SAndroid Build Coastguard Worker 33*9880d681SAndroid Build Coastguard Worker ; CHECK: call i8* @strcpy(i8* %[[GEP]], i8* %[[A]]) 34*9880d681SAndroid Build Coastguard Worker %call = call i8* @strcpy(i8* %gep, i8* %a2) 35*9880d681SAndroid Build Coastguard Worker 36*9880d681SAndroid Build Coastguard Worker ; CHECK: store i8* %[[USP]], i8** @__safestack_unsafe_stack_ptr 37*9880d681SAndroid Build Coastguard Worker ret void 38*9880d681SAndroid Build Coastguard Worker} 39*9880d681SAndroid Build Coastguard Worker 40*9880d681SAndroid Build Coastguard Workerdeclare i8* @strcpy(i8*, i8*) 41