setjmp2.ll 1.9 KB

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