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 4 %struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t } 5 %struct.__sigset_t = type { [16 x i64] } 6 7 @.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1 8 @buf = internal global [1 x %struct.__jmp_buf_tag] zeroinitializer, align 16 9 10 ; setjmp/longjmp test with dynamically sized array. 11 ; Requires protector. 12 ; CHECK: @foo(i32 %[[ARG:.*]]) 13 define i32 @foo(i32 %size) nounwind uwtable safestack { 14 entry: 15 ; CHECK: %[[DYNPTR:.*]] = alloca i8* 16 ; CHECK-NEXT: %[[SP:.*]] = load i8*, i8** @__safestack_unsafe_stack_ptr 17 ; CHECK-NEXT: store i8* %[[SP]], i8** %[[DYNPTR]] 18 19 ; CHECK-NEXT: %[[ZEXT:.*]] = zext i32 %[[ARG]] to i64 20 ; CHECK-NEXT: %[[MUL:.*]] = mul i64 %[[ZEXT]], 4 21 ; CHECK-NEXT: %[[SP2:.*]] = load i8*, i8** @__safestack_unsafe_stack_ptr 22 ; CHECK-NEXT: %[[PTRTOINT:.*]] = ptrtoint i8* %[[SP2]] to i64 23 ; CHECK-NEXT: %[[SUB:.*]] = sub i64 %[[PTRTOINT]], %[[MUL]] 24 ; CHECK-NEXT: %[[AND:.*]] = and i64 %[[SUB]], -16 25 ; CHECK-NEXT: %[[INTTOPTR:.*]] = inttoptr i64 %[[AND]] to i8* 26 ; CHECK-NEXT: store i8* %[[INTTOPTR]], i8** @__safestack_unsafe_stack_ptr 27 ; CHECK-NEXT: store i8* %[[INTTOPTR]], i8** %unsafe_stack_dynamic_ptr 28 ; CHECK-NEXT: %[[ALLOCA:.*]] = bitcast i8* %[[INTTOPTR]] to i32* 29 %a = alloca i32, i32 %size 30 31 ; CHECK: setjmp 32 ; CHECK-NEXT: %[[LOAD:.*]] = load i8*, i8** %[[DYNPTR]] 33 ; CHECK-NEXT: store i8* %[[LOAD]], i8** @__safestack_unsafe_stack_ptr 34 %call = call i32 @_setjmp(%struct.__jmp_buf_tag* getelementptr inbounds ([1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* @buf, i32 0, i32 0)) returns_twice 35 36 ; CHECK: call void @funcall(i32* %[[ALLOCA]]) 37 call void @funcall(i32* %a) 38 ret i32 0 39 } 40 41 declare i32 @_setjmp(%struct.__jmp_buf_tag*) 42 declare void @funcall(i32*) 43