| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
- // Exceptions. See /LICENSE for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- //
- // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
- //
- // AUTOUPDATE
- // TIP: To test this file alone, run:
- // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/var/import.carbon
- // TIP: To dump output, run:
- // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/var/import.carbon
- // --- simple.carbon
- library "[[@TEST_NAME]]";
- var v: i32 = 42;
- // --- import_simple.carbon
- library "[[@TEST_NAME]]";
- import library "simple";
- fn Run() -> i32 {
- return v;
- }
- // --- tuple_pattern.carbon
- library "[[@TEST_NAME]]";
- var (v: i32, w: i32) = (1, 2);
- let (x: i32, var y: i32) = (3, 4);
- var (_: i32, z: i32) = (5, 6);
- // --- import_tuple_pattern.carbon
- library "[[@TEST_NAME]]";
- import library "tuple_pattern";
- fn V() -> i32 { return v; }
- fn W() -> i32 { return w; }
- // TODO: Also test `x`. Right now, lowering a reference to an imported `let` asserts.
- fn Y() -> i32 { return y; }
- fn Z() -> i32 { return z; }
- // CHECK:STDOUT: ; ModuleID = 'simple.carbon'
- // CHECK:STDOUT: source_filename = "simple.carbon"
- // CHECK:STDOUT:
- // CHECK:STDOUT: @_Cv.Main = global i32 0
- // CHECK:STDOUT: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @_C__global_init.Main, ptr null }]
- // CHECK:STDOUT:
- // CHECK:STDOUT: ; Function Attrs: nounwind
- // CHECK:STDOUT: define internal void @_C__global_init.Main() #0 !dbg !4 {
- // CHECK:STDOUT: entry:
- // CHECK:STDOUT: store i32 42, ptr @_Cv.Main, align 4, !dbg !7
- // CHECK:STDOUT: ret void, !dbg !8
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: attributes #0 = { nounwind }
- // CHECK:STDOUT:
- // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
- // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
- // CHECK:STDOUT:
- // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
- // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
- // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
- // CHECK:STDOUT: !3 = !DIFile(filename: "simple.carbon", directory: "")
- // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "__global_init", linkageName: "_C__global_init.Main", scope: null, file: !3, type: !5, spFlags: DISPFlagDefinition, unit: !2)
- // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
- // CHECK:STDOUT: !6 = !{null}
- // CHECK:STDOUT: !7 = !DILocation(line: 4, column: 1, scope: !4)
- // CHECK:STDOUT: !8 = !DILocation(line: 0, scope: !4)
- // CHECK:STDOUT: ; ModuleID = 'import_simple.carbon'
- // CHECK:STDOUT: source_filename = "import_simple.carbon"
- // CHECK:STDOUT:
- // CHECK:STDOUT: @_Cv.Main = external global i32
- // CHECK:STDOUT:
- // CHECK:STDOUT: ; Function Attrs: nounwind
- // CHECK:STDOUT: define i32 @main() #0 !dbg !4 {
- // CHECK:STDOUT: entry:
- // CHECK:STDOUT: %.loc7 = load i32, ptr @_Cv.Main, align 4, !dbg !8
- // CHECK:STDOUT: ret i32 %.loc7, !dbg !9
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: attributes #0 = { nounwind }
- // CHECK:STDOUT:
- // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
- // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
- // CHECK:STDOUT:
- // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
- // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
- // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
- // CHECK:STDOUT: !3 = !DIFile(filename: "import_simple.carbon", directory: "")
- // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "Run", linkageName: "main", scope: null, file: !3, line: 6, type: !5, spFlags: DISPFlagDefinition, unit: !2)
- // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
- // CHECK:STDOUT: !6 = !{!7}
- // CHECK:STDOUT: !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
- // CHECK:STDOUT: !8 = !DILocation(line: 7, column: 10, scope: !4)
- // CHECK:STDOUT: !9 = !DILocation(line: 7, column: 3, scope: !4)
- // CHECK:STDOUT: ; ModuleID = 'tuple_pattern.carbon'
- // CHECK:STDOUT: source_filename = "tuple_pattern.carbon"
- // CHECK:STDOUT:
- // CHECK:STDOUT: @_Cv.Main = global { i32, i32 } zeroinitializer
- // CHECK:STDOUT: @_Cy.Main = global i32 0
- // CHECK:STDOUT: @_Cz.Main = global { i32, i32 } zeroinitializer
- // CHECK:STDOUT: @tuple.21c.loc4_1 = internal constant { i32, i32 } { i32 1, i32 2 }
- // CHECK:STDOUT: @tuple.092.loc8_1 = internal constant { i32, i32 } { i32 5, i32 6 }
- // CHECK:STDOUT: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @_C__global_init.Main, ptr null }]
- // CHECK:STDOUT:
- // CHECK:STDOUT: ; Function Attrs: nounwind
- // CHECK:STDOUT: define internal void @_C__global_init.Main() #0 !dbg !4 {
- // CHECK:STDOUT: entry:
- // 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
- // CHECK:STDOUT: store i32 4, ptr @_Cy.Main, align 4, !dbg !8
- // 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
- // CHECK:STDOUT: ret void, !dbg !10
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
- // CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #1
- // CHECK:STDOUT:
- // CHECK:STDOUT: ; uselistorder directives
- // CHECK:STDOUT: uselistorder ptr @llvm.memcpy.p0.p0.i64, { 1, 0 }
- // CHECK:STDOUT:
- // CHECK:STDOUT: attributes #0 = { nounwind }
- // CHECK:STDOUT: attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
- // CHECK:STDOUT:
- // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
- // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
- // CHECK:STDOUT:
- // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
- // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
- // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
- // CHECK:STDOUT: !3 = !DIFile(filename: "tuple_pattern.carbon", directory: "")
- // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "__global_init", linkageName: "_C__global_init.Main", scope: null, file: !3, type: !5, spFlags: DISPFlagDefinition, unit: !2)
- // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
- // CHECK:STDOUT: !6 = !{null}
- // CHECK:STDOUT: !7 = !DILocation(line: 4, column: 1, scope: !4)
- // CHECK:STDOUT: !8 = !DILocation(line: 6, column: 14, scope: !4)
- // CHECK:STDOUT: !9 = !DILocation(line: 8, column: 1, scope: !4)
- // CHECK:STDOUT: !10 = !DILocation(line: 0, scope: !4)
- // CHECK:STDOUT: ; ModuleID = 'import_tuple_pattern.carbon'
- // CHECK:STDOUT: source_filename = "import_tuple_pattern.carbon"
- // CHECK:STDOUT:
- // CHECK:STDOUT: @_Cv.Main = external global { i32, i32 }
- // CHECK:STDOUT: @_Cy.Main = external global i32
- // CHECK:STDOUT: @_Cz.Main = external global { i32, i32 }
- // CHECK:STDOUT:
- // CHECK:STDOUT: ; Function Attrs: nounwind
- // CHECK:STDOUT: define i32 @_CV.Main() #0 !dbg !4 {
- // CHECK:STDOUT: entry:
- // CHECK:STDOUT: %.loc6_24 = load i32, ptr @_Cv.Main, align 4, !dbg !8
- // CHECK:STDOUT: ret i32 %.loc6_24, !dbg !9
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: ; Function Attrs: nounwind
- // CHECK:STDOUT: define i32 @_CW.Main() #0 !dbg !10 {
- // CHECK:STDOUT: entry:
- // CHECK:STDOUT: %.loc7_24 = load i32, ptr getelementptr inbounds nuw ({ i32, i32 }, ptr @_Cv.Main, i32 0, i32 1), align 4, !dbg !11
- // CHECK:STDOUT: ret i32 %.loc7_24, !dbg !12
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: ; Function Attrs: nounwind
- // CHECK:STDOUT: define i32 @_CY.Main() #0 !dbg !13 {
- // CHECK:STDOUT: entry:
- // CHECK:STDOUT: %.loc9_24 = load i32, ptr @_Cy.Main, align 4, !dbg !14
- // CHECK:STDOUT: ret i32 %.loc9_24, !dbg !15
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: ; Function Attrs: nounwind
- // CHECK:STDOUT: define i32 @_CZ.Main() #0 !dbg !16 {
- // CHECK:STDOUT: entry:
- // CHECK:STDOUT: %.loc10_24 = load i32, ptr getelementptr inbounds nuw ({ i32, i32 }, ptr @_Cz.Main, i32 0, i32 1), align 4, !dbg !17
- // CHECK:STDOUT: ret i32 %.loc10_24, !dbg !18
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: ; uselistorder directives
- // CHECK:STDOUT: uselistorder ptr @_Cv.Main, { 1, 0 }
- // CHECK:STDOUT:
- // CHECK:STDOUT: attributes #0 = { nounwind }
- // CHECK:STDOUT:
- // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
- // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
- // CHECK:STDOUT:
- // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
- // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
- // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
- // CHECK:STDOUT: !3 = !DIFile(filename: "import_tuple_pattern.carbon", directory: "")
- // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "V", linkageName: "_CV.Main", scope: null, file: !3, line: 6, type: !5, spFlags: DISPFlagDefinition, unit: !2)
- // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
- // CHECK:STDOUT: !6 = !{!7}
- // CHECK:STDOUT: !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
- // CHECK:STDOUT: !8 = !DILocation(line: 6, column: 24, scope: !4)
- // CHECK:STDOUT: !9 = !DILocation(line: 6, column: 17, scope: !4)
- // CHECK:STDOUT: !10 = distinct !DISubprogram(name: "W", linkageName: "_CW.Main", scope: null, file: !3, line: 7, type: !5, spFlags: DISPFlagDefinition, unit: !2)
- // CHECK:STDOUT: !11 = !DILocation(line: 7, column: 24, scope: !10)
- // CHECK:STDOUT: !12 = !DILocation(line: 7, column: 17, scope: !10)
- // CHECK:STDOUT: !13 = distinct !DISubprogram(name: "Y", linkageName: "_CY.Main", scope: null, file: !3, line: 9, type: !5, spFlags: DISPFlagDefinition, unit: !2)
- // CHECK:STDOUT: !14 = !DILocation(line: 9, column: 24, scope: !13)
- // CHECK:STDOUT: !15 = !DILocation(line: 9, column: 17, scope: !13)
- // CHECK:STDOUT: !16 = distinct !DISubprogram(name: "Z", linkageName: "_CZ.Main", scope: null, file: !3, line: 10, type: !5, spFlags: DISPFlagDefinition, unit: !2)
- // CHECK:STDOUT: !17 = !DILocation(line: 10, column: 24, scope: !16)
- // CHECK:STDOUT: !18 = !DILocation(line: 10, column: 17, scope: !16)
|