thinlto-distributed-cfi-devirt.ll 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. ; REQUIRES: x86-registered-target
  2. ; Backend test for distribute ThinLTO with CFI.
  3. ; It additionally enables -fwhole-program-vtables to get more information in
  4. ; TYPE_IDs of GLOBALVAL_SUMMARY_BLOCK.
  5. ; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t.o %s
  6. ; FIXME: Fix machine verifier issues and remove -verify-machineinstrs=0. PR39436.
  7. ; RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
  8. ; RUN: -verify-machineinstrs=0 \
  9. ; RUN: -o %t2.index \
  10. ; RUN: -r=%t.o,test,px \
  11. ; RUN: -r=%t.o,_ZN1A1nEi,p \
  12. ; RUN: -r=%t.o,_ZN1B1fEi,p \
  13. ; RUN: -r=%t.o,_ZN1C1fEi,p \
  14. ; RUN: -r=%t.o,_ZTV1B, \
  15. ; RUN: -r=%t.o,_ZTV1C, \
  16. ; RUN: -r=%t.o,_ZN1A1nEi, \
  17. ; RUN: -r=%t.o,_ZN1B1fEi, \
  18. ; RUN: -r=%t.o,_ZN1C1fEi, \
  19. ; RUN: -r=%t.o,_ZTV1B,px \
  20. ; RUN: -r=%t.o,_ZTV1C,px
  21. ; Ensure that typeids are in the index.
  22. ; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s
  23. ; CHECK-LABEL: <GLOBALVAL_SUMMARY_BLOCK
  24. ; CHECK: <TYPE_ID op0=0 op1=6 op2=4 op3=7 op4=0 op5=0 op6=0 op7=0 op8=0 op9=2 op10=6 op11=0 op12=0 op13=8 op14=1 op15=6 op16=9 op17=0/>
  25. ; CHECK-LABEL: </GLOBALVAL_SUMMARY_BLOCK
  26. ; CHECK-LABEL: <STRTAB_BLOCK
  27. ; CHECK: blob data = '_ZTS1A_ZN1A1nEi'
  28. ; CHECK-LABEL: </STRTAB_BLOCK
  29. ; RUN: llvm-dis %t.o.thinlto.bc -o - | FileCheck %s --check-prefix=CHECK-DIS
  30. ; Round trip it through llvm-as
  31. ; RUN: llvm-dis %t.o.thinlto.bc -o - | llvm-as -o - | llvm-dis -o - | FileCheck %s --check-prefix=CHECK-DIS
  32. ; CHECK-DIS: ^0 = module: (path: "{{.*}}thinlto-distributed-cfi-devirt.ll.tmp.o", hash: ({{.*}}, {{.*}}, {{.*}}, {{.*}}, {{.*}}))
  33. ; CHECK-DIS: ^1 = gv: (guid: 8346051122425466633, summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 1, dsoLocal: 0, canAutoHide: 0), insts: 18, typeIdInfo: (typeTests: (^2), typeCheckedLoadVCalls: (vFuncId: (^2, offset: 8), vFuncId: (^2, offset: 0))))))
  34. ; CHECK-DIS: ^2 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7), wpdResolutions: ((offset: 0, wpdRes: (kind: branchFunnel)), (offset: 8, wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi"))))) ; guid = 7004155349499253778
  35. ; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \
  36. ; RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc -O2 \
  37. ; RUN: -emit-llvm -o - -x ir %t.o | FileCheck %s --check-prefixes=CHECK-IR
  38. ; Check that backend does not fail generating native code.
  39. ; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \
  40. ; RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc -O2 \
  41. ; RUN: -o %t.native.o -x ir %t.o
  42. target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
  43. target triple = "x86_64-grtev4-linux-gnu"
  44. %struct.A = type { i32 (...)** }
  45. %struct.B = type { %struct.A }
  46. %struct.C = type { %struct.A }
  47. @_ZTV1B = constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.B*, i32)* @_ZN1B1fEi to i8*), i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A1nEi to i8*)] }, !type !0, !type !1
  48. @_ZTV1C = constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.C*, i32)* @_ZN1C1fEi to i8*), i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A1nEi to i8*)] }, !type !0, !type !2
  49. ; CHECK-IR-LABEL: define i32 @test
  50. define i32 @test(%struct.A* %obj, i32 %a) {
  51. entry:
  52. %0 = bitcast %struct.A* %obj to i8**
  53. %vtable5 = load i8*, i8** %0
  54. %1 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable5, i32 8, metadata !"_ZTS1A")
  55. %2 = extractvalue { i8*, i1 } %1, 1
  56. br i1 %2, label %cont, label %trap
  57. trap:
  58. tail call void @llvm.trap()
  59. unreachable
  60. cont:
  61. %3 = extractvalue { i8*, i1 } %1, 0
  62. %4 = bitcast i8* %3 to i32 (%struct.A*, i32)*
  63. ; Check that the call was devirtualized.
  64. ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi
  65. %call = tail call i32 %4(%struct.A* nonnull %obj, i32 %a)
  66. %vtable16 = load i8*, i8** %0
  67. %5 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable16, i32 0, metadata !"_ZTS1A")
  68. %6 = extractvalue { i8*, i1 } %5, 1
  69. br i1 %6, label %cont2, label %trap
  70. cont2:
  71. %7 = extractvalue { i8*, i1 } %5, 0
  72. %8 = bitcast i8* %7 to i32 (%struct.A*, i32)*
  73. ; Check that traps are conditional. Invalid TYPE_ID can cause
  74. ; unconditional traps.
  75. ; CHECK-IR: br i1 {{.*}}, label %trap
  76. ; We still have to call it as virtual.
  77. ; CHECK-IR: %call3 = tail call i32 %8
  78. %call3 = tail call i32 %8(%struct.A* nonnull %obj, i32 %call)
  79. ret i32 %call3
  80. }
  81. ; CHECK-IR-LABEL: ret i32
  82. ; CHECK-IR-LABEL: }
  83. declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
  84. declare void @llvm.trap()
  85. declare i32 @_ZN1B1fEi(%struct.B* %this, i32 %a)
  86. declare i32 @_ZN1A1nEi(%struct.A* %this, i32 %a)
  87. declare i32 @_ZN1C1fEi(%struct.C* %this, i32 %a)
  88. !0 = !{i64 16, !"_ZTS1A"}
  89. !1 = !{i64 16, !"_ZTS1B"}
  90. !2 = !{i64 16, !"_ZTS1C"}