import.carbon 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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/var/import.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/var/import.carbon
  12. // --- simple.carbon
  13. library "[[@TEST_NAME]]";
  14. var v: i32 = 42;
  15. // --- import_simple.carbon
  16. library "[[@TEST_NAME]]";
  17. import library "simple";
  18. fn Run() -> i32 {
  19. return v;
  20. }
  21. // --- tuple_pattern.carbon
  22. library "[[@TEST_NAME]]";
  23. var (v: i32, w: i32) = (1, 2);
  24. let (x: i32, var y: i32) = (3, 4);
  25. var (_: i32, z: i32) = (5, 6);
  26. // --- import_tuple_pattern.carbon
  27. library "[[@TEST_NAME]]";
  28. import library "tuple_pattern";
  29. fn V() -> i32 { return v; }
  30. fn W() -> i32 { return w; }
  31. // TODO: Also test `x`. Right now, lowering a reference to an imported `let` asserts.
  32. fn Y() -> i32 { return y; }
  33. fn Z() -> i32 { return z; }
  34. // CHECK:STDOUT: ; ModuleID = 'simple.carbon'
  35. // CHECK:STDOUT: source_filename = "simple.carbon"
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: @_Cv.Main = global i32 0
  38. // CHECK:STDOUT: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @_C__global_init.Main, ptr null }]
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: define void @_C__global_init.Main() !dbg !4 {
  41. // CHECK:STDOUT: entry:
  42. // CHECK:STDOUT: store i32 42, ptr @_Cv.Main, align 4, !dbg !7
  43. // CHECK:STDOUT: ret void, !dbg !8
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  47. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  50. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  51. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  52. // CHECK:STDOUT: !3 = !DIFile(filename: "simple.carbon", directory: "")
  53. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "__global_init", linkageName: "_C__global_init.Main", scope: null, file: !3, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  54. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  55. // CHECK:STDOUT: !6 = !{}
  56. // CHECK:STDOUT: !7 = !DILocation(line: 4, column: 1, scope: !4)
  57. // CHECK:STDOUT: !8 = !DILocation(line: 0, scope: !4)
  58. // CHECK:STDOUT: ; ModuleID = 'import_simple.carbon'
  59. // CHECK:STDOUT: source_filename = "import_simple.carbon"
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: @_Cv.Main = external global i32
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: define i32 @main() !dbg !4 {
  64. // CHECK:STDOUT: entry:
  65. // CHECK:STDOUT: %.loc7 = load i32, ptr @_Cv.Main, align 4, !dbg !7
  66. // CHECK:STDOUT: ret i32 %.loc7, !dbg !8
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  70. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  73. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  74. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  75. // CHECK:STDOUT: !3 = !DIFile(filename: "import_simple.carbon", directory: "")
  76. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "Run", linkageName: "main", scope: null, file: !3, line: 6, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  77. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  78. // CHECK:STDOUT: !6 = !{}
  79. // CHECK:STDOUT: !7 = !DILocation(line: 7, column: 10, scope: !4)
  80. // CHECK:STDOUT: !8 = !DILocation(line: 7, column: 3, scope: !4)
  81. // CHECK:STDOUT: ; ModuleID = 'tuple_pattern.carbon'
  82. // CHECK:STDOUT: source_filename = "tuple_pattern.carbon"
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: @_Cv.Main = global { i32, i32 } zeroinitializer
  85. // CHECK:STDOUT: @_Cy.Main = global i32 0
  86. // CHECK:STDOUT: @_Cz.Main = global { i32, i32 } zeroinitializer
  87. // CHECK:STDOUT: @tuple.21c.loc4_1 = internal constant { i32, i32 } { i32 1, i32 2 }
  88. // CHECK:STDOUT: @tuple.092.loc8_1 = internal constant { i32, i32 } { i32 5, i32 6 }
  89. // CHECK:STDOUT: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @_C__global_init.Main, ptr null }]
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: define void @_C__global_init.Main() !dbg !4 {
  92. // CHECK:STDOUT: entry:
  93. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 @_Cv.Main, ptr align 4 @tuple.21c.loc4_1, i64 8, i1 false), !dbg !7
  94. // CHECK:STDOUT: store i32 4, ptr @_Cy.Main, align 4, !dbg !8
  95. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 @_Cz.Main, ptr align 4 @tuple.092.loc8_1, i64 8, i1 false), !dbg !9
  96. // CHECK:STDOUT: ret void, !dbg !10
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
  100. // CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #0
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: ; uselistorder directives
  103. // CHECK:STDOUT: uselistorder ptr @llvm.memcpy.p0.p0.i64, { 1, 0 }
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  108. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  111. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  112. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  113. // CHECK:STDOUT: !3 = !DIFile(filename: "tuple_pattern.carbon", directory: "")
  114. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "__global_init", linkageName: "_C__global_init.Main", scope: null, file: !3, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  115. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  116. // CHECK:STDOUT: !6 = !{}
  117. // CHECK:STDOUT: !7 = !DILocation(line: 4, column: 1, scope: !4)
  118. // CHECK:STDOUT: !8 = !DILocation(line: 6, column: 14, scope: !4)
  119. // CHECK:STDOUT: !9 = !DILocation(line: 8, column: 1, scope: !4)
  120. // CHECK:STDOUT: !10 = !DILocation(line: 0, scope: !4)
  121. // CHECK:STDOUT: ; ModuleID = 'import_tuple_pattern.carbon'
  122. // CHECK:STDOUT: source_filename = "import_tuple_pattern.carbon"
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: @_Cv.Main = external global { i32, i32 }
  125. // CHECK:STDOUT: @_Cy.Main = external global i32
  126. // CHECK:STDOUT: @_Cz.Main = external global { i32, i32 }
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: define i32 @_CV.Main() !dbg !4 {
  129. // CHECK:STDOUT: entry:
  130. // CHECK:STDOUT: %.loc6 = load i32, ptr @_Cv.Main, align 4, !dbg !7
  131. // CHECK:STDOUT: ret i32 %.loc6, !dbg !8
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: define i32 @_CW.Main() !dbg !9 {
  135. // CHECK:STDOUT: entry:
  136. // CHECK:STDOUT: %.loc7 = load i32, ptr getelementptr inbounds nuw ({ i32, i32 }, ptr @_Cv.Main, i32 0, i32 1), align 4, !dbg !10
  137. // CHECK:STDOUT: ret i32 %.loc7, !dbg !11
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: define i32 @_CY.Main() !dbg !12 {
  141. // CHECK:STDOUT: entry:
  142. // CHECK:STDOUT: %.loc9 = load i32, ptr @_Cy.Main, align 4, !dbg !13
  143. // CHECK:STDOUT: ret i32 %.loc9, !dbg !14
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: define i32 @_CZ.Main() !dbg !15 {
  147. // CHECK:STDOUT: entry:
  148. // CHECK:STDOUT: %.loc10 = load i32, ptr getelementptr inbounds nuw ({ i32, i32 }, ptr @_Cz.Main, i32 0, i32 1), align 4, !dbg !16
  149. // CHECK:STDOUT: ret i32 %.loc10, !dbg !17
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: ; uselistorder directives
  153. // CHECK:STDOUT: uselistorder ptr @_Cv.Main, { 1, 0 }
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  156. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  157. // CHECK:STDOUT:
  158. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  159. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  160. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  161. // CHECK:STDOUT: !3 = !DIFile(filename: "import_tuple_pattern.carbon", directory: "")
  162. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "V", linkageName: "_CV.Main", scope: null, file: !3, line: 6, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  163. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  164. // CHECK:STDOUT: !6 = !{}
  165. // CHECK:STDOUT: !7 = !DILocation(line: 6, column: 24, scope: !4)
  166. // CHECK:STDOUT: !8 = !DILocation(line: 6, column: 17, scope: !4)
  167. // CHECK:STDOUT: !9 = distinct !DISubprogram(name: "W", linkageName: "_CW.Main", scope: null, file: !3, line: 7, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  168. // CHECK:STDOUT: !10 = !DILocation(line: 7, column: 24, scope: !9)
  169. // CHECK:STDOUT: !11 = !DILocation(line: 7, column: 17, scope: !9)
  170. // CHECK:STDOUT: !12 = distinct !DISubprogram(name: "Y", linkageName: "_CY.Main", scope: null, file: !3, line: 9, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  171. // CHECK:STDOUT: !13 = !DILocation(line: 9, column: 24, scope: !12)
  172. // CHECK:STDOUT: !14 = !DILocation(line: 9, column: 17, scope: !12)
  173. // CHECK:STDOUT: !15 = distinct !DISubprogram(name: "Z", linkageName: "_CZ.Main", scope: null, file: !3, line: 10, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  174. // CHECK:STDOUT: !16 = !DILocation(line: 10, column: 24, scope: !15)
  175. // CHECK:STDOUT: !17 = !DILocation(line: 10, column: 17, scope: !15)