template.carbon 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/int.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/template.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/template.carbon
  12. // --- function_template.h
  13. template<typename T> T identity(T x) { return x; }
  14. class Class {};
  15. // --- call.carbon
  16. library "[[@TEST_NAME]]";
  17. import Cpp library "function_template.h";
  18. fn PassI32(a: i32) -> i32 {
  19. return Cpp.identity(a);
  20. }
  21. fn PassClass(a: Cpp.Class) -> Cpp.Class {
  22. return Cpp.identity(a);
  23. }
  24. // CHECK:STDOUT: ; ModuleID = 'call.carbon'
  25. // CHECK:STDOUT: source_filename = "call.carbon"
  26. // 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"
  27. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: %class.Class = type { i8 }
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: $_Z8identityIiET_S0_ = comdat any
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: $_Z8identityI5ClassET_S1_ = comdat any
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: define i32 @_CPassI32.Main(i32 %a) !dbg !7 {
  36. // CHECK:STDOUT: entry:
  37. // CHECK:STDOUT: %identity.call = call i32 @_Z8identityIiET_S0_(i32 %a), !dbg !10
  38. // CHECK:STDOUT: ret i32 %identity.call, !dbg !11
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: define void @_CPassClass.Main(ptr sret({}) %return, ptr %a) !dbg !12 {
  42. // CHECK:STDOUT: entry:
  43. // CHECK:STDOUT: call void @_Z8identityI5ClassET_S1_.carbon_thunk(ptr %a, ptr %return), !dbg !13
  44. // CHECK:STDOUT: ret void, !dbg !14
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: ; Function Attrs: mustprogress noinline nounwind optnone
  48. // CHECK:STDOUT: define linkonce_odr dso_local i32 @_Z8identityIiET_S0_(i32 %x) #0 comdat {
  49. // CHECK:STDOUT: entry:
  50. // CHECK:STDOUT: %x.addr = alloca i32, align 4
  51. // CHECK:STDOUT: store i32 %x, ptr %x.addr, align 4
  52. // CHECK:STDOUT: %0 = load i32, ptr %x.addr, align 4
  53. // CHECK:STDOUT: ret i32 %0
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress
  57. // CHECK:STDOUT: define dso_local void @_Z8identityI5ClassET_S1_.carbon_thunk(ptr %x, ptr %return) #1 {
  58. // CHECK:STDOUT: entry:
  59. // CHECK:STDOUT: %x.addr = alloca ptr, align 8
  60. // CHECK:STDOUT: %return.addr = alloca ptr, align 8
  61. // CHECK:STDOUT: %agg.tmp = alloca %class.Class, align 1
  62. // CHECK:STDOUT: %undef.agg.tmp = alloca %class.Class, align 1
  63. // CHECK:STDOUT: store ptr %x, ptr %x.addr, align 8
  64. // CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8
  65. // CHECK:STDOUT: %0 = load ptr, ptr %return.addr, align 8
  66. // CHECK:STDOUT: %1 = load ptr, ptr %x.addr, align 8
  67. // CHECK:STDOUT: call void @_Z8identityI5ClassET_S1_()
  68. // CHECK:STDOUT: ret void
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: ; Function Attrs: mustprogress noinline nounwind optnone
  72. // CHECK:STDOUT: define linkonce_odr dso_local void @_Z8identityI5ClassET_S1_() #0 comdat {
  73. // CHECK:STDOUT: entry:
  74. // CHECK:STDOUT: %x = alloca %class.Class, align 1
  75. // CHECK:STDOUT: ret void
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: attributes #0 = { mustprogress noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  79. // CHECK:STDOUT: attributes #1 = { alwaysinline mustprogress "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  82. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  85. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  86. // CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4}
  87. // CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 0}
  88. // CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2}
  89. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  90. // CHECK:STDOUT: !6 = !DIFile(filename: "call.carbon", directory: "")
  91. // CHECK:STDOUT: !7 = distinct !DISubprogram(name: "PassI32", linkageName: "_CPassI32.Main", scope: null, file: !6, line: 6, type: !8, spFlags: DISPFlagDefinition, unit: !5)
  92. // CHECK:STDOUT: !8 = !DISubroutineType(types: !9)
  93. // CHECK:STDOUT: !9 = !{}
  94. // CHECK:STDOUT: !10 = !DILocation(line: 7, column: 10, scope: !7)
  95. // CHECK:STDOUT: !11 = !DILocation(line: 7, column: 3, scope: !7)
  96. // CHECK:STDOUT: !12 = distinct !DISubprogram(name: "PassClass", linkageName: "_CPassClass.Main", scope: null, file: !6, line: 10, type: !8, spFlags: DISPFlagDefinition, unit: !5)
  97. // CHECK:STDOUT: !13 = !DILocation(line: 11, column: 10, scope: !12)
  98. // CHECK:STDOUT: !14 = !DILocation(line: 11, column: 3, scope: !12)