cpp_compat_int.carbon 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/full.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/cpp_compat_int.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/cpp_compat_int.carbon
  12. // --- primitives.carbon
  13. library "[[@TEST_NAME]]";
  14. // TODO: Return `Core.CppCompat.Long32` when it's copyable.
  15. fn DoubleLong32(l32: Core.CppCompat.Long32) -> i32 {
  16. // TODO: Avoid explicit conversion when multiplication on `Long32` is available.
  17. return 2 * (l32 as i32);
  18. }
  19. // TODO: Return `Core.CppCompat.ULong32` when it's copyable.
  20. fn DoubleULong32(ul32: Core.CppCompat.ULong32) -> u32 {
  21. // TODO: Avoid explicit conversion when multiplication on `ULong32` is available.
  22. return 2 * (ul32 as u32);
  23. }
  24. // TODO: Return `Core.CppCompat.LongLong64` when it's copyable.
  25. fn DoubleLongLong64(ll64: Core.CppCompat.LongLong64) -> i64 {
  26. // TODO: Avoid explicit conversion when multiplication on `LongLong64` is available.
  27. return 2 * (ll64 as i64);
  28. }
  29. // TODO: Return `Core.CppCompat.ULongLong64` when it's copyable.
  30. fn DoubleULong64(ul64: Core.CppCompat.ULongLong64) -> u64 {
  31. // TODO: Avoid explicit conversion when multiplication on `ULongLong64` is available.
  32. return 2 * (ul64 as u64);
  33. }
  34. // CHECK:STDOUT: ; ModuleID = 'primitives.carbon'
  35. // CHECK:STDOUT: source_filename = "primitives.carbon"
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: ; Function Attrs: nounwind
  38. // CHECK:STDOUT: define i32 @_CDoubleLong32.Main(i32 %l32) #0 !dbg !4 {
  39. // CHECK:STDOUT: entry:
  40. // CHECK:STDOUT: %T.binding.as_type.as.MulWith.impl.Op.call = mul i32 2, %l32, !dbg !10
  41. // CHECK:STDOUT: ret i32 %T.binding.as_type.as.MulWith.impl.Op.call, !dbg !11
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: ; Function Attrs: nounwind
  45. // CHECK:STDOUT: define i32 @_CDoubleULong32.Main(i32 %ul32) #0 !dbg !12 {
  46. // CHECK:STDOUT: entry:
  47. // CHECK:STDOUT: %T.binding.as_type.as.MulWith.impl.Op.call = mul i32 2, %ul32, !dbg !18
  48. // CHECK:STDOUT: ret i32 %T.binding.as_type.as.MulWith.impl.Op.call, !dbg !19
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: ; Function Attrs: nounwind
  52. // CHECK:STDOUT: define i64 @_CDoubleLongLong64.Main(i64 %ll64) #0 !dbg !20 {
  53. // CHECK:STDOUT: entry:
  54. // CHECK:STDOUT: %T.binding.as_type.as.MulWith.impl.Op.call = mul i64 2, %ll64, !dbg !26
  55. // CHECK:STDOUT: ret i64 %T.binding.as_type.as.MulWith.impl.Op.call, !dbg !27
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: ; Function Attrs: nounwind
  59. // CHECK:STDOUT: define i64 @_CDoubleULong64.Main(i64 %ul64) #0 !dbg !28 {
  60. // CHECK:STDOUT: entry:
  61. // CHECK:STDOUT: %T.binding.as_type.as.MulWith.impl.Op.call = mul i64 2, %ul64, !dbg !34
  62. // CHECK:STDOUT: ret i64 %T.binding.as_type.as.MulWith.impl.Op.call, !dbg !35
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: attributes #0 = { nounwind }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  68. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  71. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  72. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  73. // CHECK:STDOUT: !3 = !DIFile(filename: "primitives.carbon", directory: "")
  74. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "DoubleLong32", linkageName: "_CDoubleLong32.Main", scope: null, file: !3, line: 5, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !8)
  75. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  76. // CHECK:STDOUT: !6 = !{!7, !7}
  77. // CHECK:STDOUT: !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  78. // CHECK:STDOUT: !8 = !{!9}
  79. // CHECK:STDOUT: !9 = !DILocalVariable(arg: 1, scope: !4, type: !7)
  80. // CHECK:STDOUT: !10 = !DILocation(line: 7, column: 10, scope: !4)
  81. // CHECK:STDOUT: !11 = !DILocation(line: 7, column: 3, scope: !4)
  82. // CHECK:STDOUT: !12 = distinct !DISubprogram(name: "DoubleULong32", linkageName: "_CDoubleULong32.Main", scope: null, file: !3, line: 11, type: !13, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !16)
  83. // CHECK:STDOUT: !13 = !DISubroutineType(types: !14)
  84. // CHECK:STDOUT: !14 = !{!15, !15}
  85. // CHECK:STDOUT: !15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_unsigned)
  86. // CHECK:STDOUT: !16 = !{!17}
  87. // CHECK:STDOUT: !17 = !DILocalVariable(arg: 1, scope: !12, type: !15)
  88. // CHECK:STDOUT: !18 = !DILocation(line: 13, column: 10, scope: !12)
  89. // CHECK:STDOUT: !19 = !DILocation(line: 13, column: 3, scope: !12)
  90. // CHECK:STDOUT: !20 = distinct !DISubprogram(name: "DoubleLongLong64", linkageName: "_CDoubleLongLong64.Main", scope: null, file: !3, line: 17, type: !21, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !24)
  91. // CHECK:STDOUT: !21 = !DISubroutineType(types: !22)
  92. // CHECK:STDOUT: !22 = !{!23, !23}
  93. // CHECK:STDOUT: !23 = !DIBasicType(name: "int", size: 64, encoding: DW_ATE_signed)
  94. // CHECK:STDOUT: !24 = !{!25}
  95. // CHECK:STDOUT: !25 = !DILocalVariable(arg: 1, scope: !20, type: !23)
  96. // CHECK:STDOUT: !26 = !DILocation(line: 19, column: 10, scope: !20)
  97. // CHECK:STDOUT: !27 = !DILocation(line: 19, column: 3, scope: !20)
  98. // CHECK:STDOUT: !28 = distinct !DISubprogram(name: "DoubleULong64", linkageName: "_CDoubleULong64.Main", scope: null, file: !3, line: 23, type: !29, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !32)
  99. // CHECK:STDOUT: !29 = !DISubroutineType(types: !30)
  100. // CHECK:STDOUT: !30 = !{!31, !31}
  101. // CHECK:STDOUT: !31 = !DIBasicType(name: "int", size: 64, encoding: DW_ATE_unsigned)
  102. // CHECK:STDOUT: !32 = !{!33}
  103. // CHECK:STDOUT: !33 = !DILocalVariable(arg: 1, scope: !28, type: !31)
  104. // CHECK:STDOUT: !34 = !DILocation(line: 25, column: 10, scope: !28)
  105. // CHECK:STDOUT: !35 = !DILocation(line: 25, column: 3, scope: !28)