lifetime.ll 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ; Test hanlding of llvm.lifetime intrinsics.
  2. ; RUN: opt < %s -asan -asan-module -asan-check-lifetime -asan-use-after-return=0 -S | FileCheck %s
  3. target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
  4. target triple = "x86_64-unknown-linux-gnu"
  5. declare void @llvm.lifetime.start(i64, i8* nocapture) nounwind
  6. declare void @llvm.lifetime.end(i64, i8* nocapture) nounwind
  7. define void @lifetime_no_size() sanitize_address {
  8. entry:
  9. %i = alloca i32, align 4
  10. %i.ptr = bitcast i32* %i to i8*
  11. call void @llvm.lifetime.start(i64 -1, i8* %i.ptr)
  12. store volatile i8 0, i8* %i.ptr
  13. call void @llvm.lifetime.end(i64 -1, i8* %i.ptr)
  14. ; Check that lifetime with no size are ignored.
  15. ; CHECK-LABEL: define void @lifetime_no_size()
  16. ; CHECK-NOT: @__asan_poison_stack_memory
  17. ; CHECK-NOT: @__asan_unpoison_stack_memory
  18. ; CHECK: ret void
  19. ret void
  20. }
  21. ; Generic case of lifetime analysis.
  22. define void @lifetime() sanitize_address {
  23. ; CHECK-LABEL: define void @lifetime()
  24. ; Regular variable lifetime intrinsics.
  25. %i = alloca i32, align 4
  26. %i.ptr = bitcast i32* %i to i8*
  27. call void @llvm.lifetime.start(i64 3, i8* %i.ptr)
  28. store volatile i8 0, i8* %i.ptr
  29. ; Memory is unpoisoned at llvm.lifetime.start
  30. ; CHECK: %[[VAR:[^ ]*]] = ptrtoint i32* %{{[^ ]+}} to i64
  31. ; CHECK-NEXT: call void @__asan_unpoison_stack_memory(i64 %[[VAR]], i64 3)
  32. call void @llvm.lifetime.end(i64 4, i8* %i.ptr)
  33. call void @llvm.lifetime.end(i64 2, i8* %i.ptr)
  34. ; Memory is poisoned at every call to llvm.lifetime.end
  35. ; CHECK: call void @__asan_poison_stack_memory(i64 %{{[^ ]+}}, i64 4)
  36. ; CHECK: call void @__asan_poison_stack_memory(i64 %{{[^ ]+}}, i64 2)
  37. ; Lifetime intrinsics for array.
  38. %arr = alloca [10 x i32], align 16
  39. %arr.ptr = bitcast [10 x i32]* %arr to i8*
  40. call void @llvm.lifetime.start(i64 40, i8* %arr.ptr)
  41. store volatile i8 0, i8* %arr.ptr
  42. ; CHECK: call void @__asan_unpoison_stack_memory(i64 %{{[^ ]+}}, i64 40)
  43. call void @llvm.lifetime.end(i64 40, i8* %arr.ptr)
  44. ; CHECK: call void @__asan_poison_stack_memory(i64 %{{[^ ]+}}, i64 40)
  45. ; One more lifetime start/end for the same variable %i.
  46. call void @llvm.lifetime.start(i64 4, i8* %i.ptr)
  47. store volatile i8 0, i8* %i.ptr
  48. ; CHECK: call void @__asan_unpoison_stack_memory(i64 %{{[^ ]+}}, i64 4)
  49. call void @llvm.lifetime.end(i64 4, i8* %i.ptr)
  50. ; CHECK: call void @__asan_poison_stack_memory(i64 %{{[^ ]+}}, i64 4)
  51. ; Memory is unpoisoned at function exit (only once).
  52. ; CHECK: call void @__asan_unpoison_stack_memory(i64 %{{[^ ]+}}, i64 {{.*}})
  53. ; CHECK-NOT: @__asan_unpoison_stack_memory
  54. ; CHECK: ret void
  55. ret void
  56. }
  57. ; Check that arguments of lifetime may come from phi nodes.
  58. define void @phi_args(i1 %x) sanitize_address {
  59. ; CHECK-LABEL: define void @phi_args(i1 %x)
  60. entry:
  61. %i = alloca i64, align 4
  62. %i.ptr = bitcast i64* %i to i8*
  63. call void @llvm.lifetime.start(i64 8, i8* %i.ptr)
  64. store volatile i8 0, i8* %i.ptr
  65. ; CHECK: __asan_unpoison_stack_memory
  66. br i1 %x, label %bb0, label %bb1
  67. bb0:
  68. %i.ptr2 = bitcast i64* %i to i8*
  69. br label %bb1
  70. bb1:
  71. %i.phi = phi i8* [ %i.ptr, %entry ], [ %i.ptr2, %bb0 ]
  72. call void @llvm.lifetime.end(i64 8, i8* %i.phi)
  73. ; CHECK: __asan_poison_stack_memory
  74. ; CHECK: ret void
  75. ret void
  76. }