2
0

basic.ll 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. ; Test basic address sanitizer instrumentation.
  2. ;
  3. ; RUN: opt < %s -asan -asan-module -S | FileCheck %s
  4. 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"
  5. target triple = "x86_64-unknown-linux-gnu"
  6. ; CHECK: @llvm.global_ctors = {{.*}}@asan.module_ctor
  7. define i32 @test_load(i32* %a) sanitize_address {
  8. ; CHECK-LABEL: @test_load
  9. ; CHECK-NOT: load
  10. ; CHECK: %[[LOAD_ADDR:[^ ]*]] = ptrtoint i32* %a to i64
  11. ; CHECK: lshr i64 %[[LOAD_ADDR]], 3
  12. ; CHECK: {{or|add}}
  13. ; CHECK: %[[LOAD_SHADOW_PTR:[^ ]*]] = inttoptr
  14. ; CHECK: %[[LOAD_SHADOW:[^ ]*]] = load i8, i8* %[[LOAD_SHADOW_PTR]]
  15. ; CHECK: icmp ne i8
  16. ; CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}!prof ![[PROF:[0-9]+]]
  17. ;
  18. ; First instrumentation block refines the shadow test.
  19. ; CHECK: and i64 %[[LOAD_ADDR]], 7
  20. ; CHECK: add i64 %{{.*}}, 3
  21. ; CHECK: trunc i64 %{{.*}} to i8
  22. ; CHECK: icmp sge i8 %{{.*}}, %[[LOAD_SHADOW]]
  23. ; CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
  24. ;
  25. ; The crash block reports the error.
  26. ; CHECK: call void @__asan_report_load4(i64 %[[LOAD_ADDR]])
  27. ; CHECK: unreachable
  28. ;
  29. ; The actual load.
  30. ; CHECK: %tmp1 = load i32, i32* %a
  31. ; CHECK: ret i32 %tmp1
  32. entry:
  33. %tmp1 = load i32, i32* %a, align 4
  34. ret i32 %tmp1
  35. }
  36. define void @test_store(i32* %a) sanitize_address {
  37. ; CHECK-LABEL: @test_store
  38. ; CHECK-NOT: store
  39. ; CHECK: %[[STORE_ADDR:[^ ]*]] = ptrtoint i32* %a to i64
  40. ; CHECK: lshr i64 %[[STORE_ADDR]], 3
  41. ; CHECK: {{or|add}}
  42. ; CHECK: %[[STORE_SHADOW_PTR:[^ ]*]] = inttoptr
  43. ; CHECK: %[[STORE_SHADOW:[^ ]*]] = load i8, i8* %[[STORE_SHADOW_PTR]]
  44. ; CHECK: icmp ne i8
  45. ; CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
  46. ;
  47. ; First instrumentation block refines the shadow test.
  48. ; CHECK: and i64 %[[STORE_ADDR]], 7
  49. ; CHECK: add i64 %{{.*}}, 3
  50. ; CHECK: trunc i64 %{{.*}} to i8
  51. ; CHECK: icmp sge i8 %{{.*}}, %[[STORE_SHADOW]]
  52. ; CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
  53. ;
  54. ; The crash block reports the error.
  55. ; CHECK: call void @__asan_report_store4(i64 %[[STORE_ADDR]])
  56. ; CHECK: unreachable
  57. ;
  58. ; The actual load.
  59. ; CHECK: store i32 42, i32* %a
  60. ; CHECK: ret void
  61. ;
  62. entry:
  63. store i32 42, i32* %a, align 4
  64. ret void
  65. }
  66. ; Check that asan leaves just one alloca.
  67. declare void @alloca_test_use([10 x i8]*)
  68. define void @alloca_test() sanitize_address {
  69. entry:
  70. %x = alloca [10 x i8], align 1
  71. %y = alloca [10 x i8], align 1
  72. %z = alloca [10 x i8], align 1
  73. call void @alloca_test_use([10 x i8]* %x)
  74. call void @alloca_test_use([10 x i8]* %y)
  75. call void @alloca_test_use([10 x i8]* %z)
  76. ret void
  77. }
  78. ; CHECK-LABEL: define void @alloca_test()
  79. ; CHECK: = alloca
  80. ; CHECK-NOT: = alloca
  81. ; CHECK: ret void
  82. define void @LongDoubleTest(x86_fp80* nocapture %a) nounwind uwtable sanitize_address {
  83. entry:
  84. store x86_fp80 0xK3FFF8000000000000000, x86_fp80* %a, align 16
  85. ret void
  86. }
  87. ; CHECK-LABEL: LongDoubleTest
  88. ; CHECK: __asan_report_store_n
  89. ; CHECK: __asan_report_store_n
  90. ; CHECK: ret void
  91. define void @i40test(i40* %a, i40* %b) nounwind uwtable sanitize_address {
  92. entry:
  93. %t = load i40, i40* %a
  94. store i40 %t, i40* %b, align 8
  95. ret void
  96. }
  97. ; CHECK-LABEL: i40test
  98. ; CHECK: __asan_report_load_n{{.*}}, i64 5)
  99. ; CHECK: __asan_report_load_n{{.*}}, i64 5)
  100. ; CHECK: __asan_report_store_n{{.*}}, i64 5)
  101. ; CHECK: __asan_report_store_n{{.*}}, i64 5)
  102. ; CHECK: ret void
  103. define void @i64test_align1(i64* %b) nounwind uwtable sanitize_address {
  104. entry:
  105. store i64 0, i64* %b, align 1
  106. ret void
  107. }
  108. ; CHECK-LABEL: i64test_align1
  109. ; CHECK: __asan_report_store_n{{.*}}, i64 8)
  110. ; CHECK: __asan_report_store_n{{.*}}, i64 8)
  111. ; CHECK: ret void
  112. define void @i80test(i80* %a, i80* %b) nounwind uwtable sanitize_address {
  113. entry:
  114. %t = load i80, i80* %a
  115. store i80 %t, i80* %b, align 8
  116. ret void
  117. }
  118. ; CHECK-LABEL: i80test
  119. ; CHECK: __asan_report_load_n{{.*}}, i64 10)
  120. ; CHECK: __asan_report_load_n{{.*}}, i64 10)
  121. ; CHECK: __asan_report_store_n{{.*}}, i64 10)
  122. ; CHECK: __asan_report_store_n{{.*}}, i64 10)
  123. ; CHECK: ret void
  124. ; asan should not instrument functions with available_externally linkage.
  125. define available_externally i32 @f_available_externally(i32* %a) sanitize_address {
  126. entry:
  127. %tmp1 = load i32, i32* %a
  128. ret i32 %tmp1
  129. }
  130. ; CHECK-LABEL: @f_available_externally
  131. ; CHECK-NOT: __asan_report
  132. ; CHECK: ret i32
  133. declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
  134. declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1) nounwind
  135. declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1) nounwind
  136. define void @memintr_test(i8* %a, i8* %b) nounwind uwtable sanitize_address {
  137. entry:
  138. tail call void @llvm.memset.p0i8.i64(i8* %a, i8 0, i64 100, i32 1, i1 false)
  139. tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %a, i8* %b, i64 100, i32 1, i1 false)
  140. tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %b, i64 100, i32 1, i1 false)
  141. ret void
  142. }
  143. ; CHECK-LABEL: memintr_test
  144. ; CHECK: __asan_memset
  145. ; CHECK: __asan_memmove
  146. ; CHECK: __asan_memcpy
  147. ; CHECK: ret void
  148. ; CHECK: define internal void @asan.module_ctor()
  149. ; CHECK: call void @__asan_init_v5()
  150. ; PROF
  151. ; CHECK: ![[PROF]] = !{!"branch_weights", i32 1, i32 100000}