dynamic.carbon 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/primitives.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/interop/cpp/class/import/dynamic.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/class/import/dynamic.carbon
  12. // --- dynamic_base_from_cpp.carbon
  13. library "[[@TEST_NAME]]";
  14. import Cpp;
  15. inline Cpp '''
  16. struct Base {
  17. int i;
  18. virtual void func();
  19. };
  20. ''';
  21. base class Derived {
  22. extend base: Cpp.Base;
  23. virtual fn other_func[self: Self]();
  24. }
  25. fn Use(d: Derived) -> i32 {
  26. d.other_func();
  27. return d.i;
  28. }
  29. // CHECK:STDOUT: ; ModuleID = 'dynamic_base_from_cpp.carbon'
  30. // CHECK:STDOUT: source_filename = "dynamic_base_from_cpp.carbon"
  31. // CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
  32. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: @"_CDerived.Main.$vtable" = unnamed_addr constant [1 x i32] [i32 trunc (i64 sub (i64 ptrtoint (ptr @_Cother_func.Derived.Main to i64), i64 ptrtoint (ptr @"_CDerived.Main.$vtable" to i64)) to i32)]
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: declare void @_Cother_func.Derived.Main(ptr)
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: ; Function Attrs: nounwind
  39. // CHECK:STDOUT: define i32 @_CUse.Main(ptr %d) #0 !dbg !11 {
  40. // CHECK:STDOUT: entry:
  41. // CHECK:STDOUT: %Derived.other_func.call.vtable = load ptr, ptr %d, align 8, !dbg !18
  42. // CHECK:STDOUT: %Derived.other_func.call = call ptr @llvm.load.relative.i32(ptr %Derived.other_func.call.vtable, i32 0), !dbg !18
  43. // CHECK:STDOUT: call void %Derived.other_func.call(ptr %d), !dbg !18
  44. // CHECK:STDOUT: %.loc22_11.1.base = getelementptr inbounds nuw { [16 x i8] }, ptr %d, i32 0, i32 0, !dbg !19
  45. // CHECK:STDOUT: %.loc22_11.3.i = getelementptr inbounds nuw [16 x i8], ptr %.loc22_11.1.base, i32 0, i32 8, !dbg !19
  46. // CHECK:STDOUT: %.loc22_11.4 = load i32, ptr %.loc22_11.3.i, align 4, !dbg !19
  47. // CHECK:STDOUT: ret i32 %.loc22_11.4, !dbg !20
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: read)
  51. // CHECK:STDOUT: declare ptr @llvm.load.relative.i32(ptr, i32) #1
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: attributes #0 = { nounwind }
  54. // CHECK:STDOUT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: read) }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  57. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  58. // CHECK:STDOUT: !llvm.errno.tbaa = !{!7}
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  61. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  62. // CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
  63. // CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
  64. // CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
  65. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  66. // CHECK:STDOUT: !6 = !DIFile(filename: "dynamic_base_from_cpp.carbon", directory: "")
  67. // CHECK:STDOUT: !7 = !{!8, !8, i64 0}
  68. // CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
  69. // CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
  70. // CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
  71. // CHECK:STDOUT: !11 = distinct !DISubprogram(name: "Use", linkageName: "_CUse.Main", scope: null, file: !6, line: 20, type: !12, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !16)
  72. // CHECK:STDOUT: !12 = !DISubroutineType(types: !13)
  73. // CHECK:STDOUT: !13 = !{!14, !15}
  74. // CHECK:STDOUT: !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  75. // CHECK:STDOUT: !15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
  76. // CHECK:STDOUT: !16 = !{!17}
  77. // CHECK:STDOUT: !17 = !DILocalVariable(arg: 1, scope: !11, type: !15)
  78. // CHECK:STDOUT: !18 = !DILocation(line: 21, column: 3, scope: !11)
  79. // CHECK:STDOUT: !19 = !DILocation(line: 22, column: 10, scope: !11)
  80. // CHECK:STDOUT: !20 = !DILocation(line: 22, column: 3, scope: !11)