mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-23 02:32:42 +00:00
191 lines
12 KiB
Plaintext
191 lines
12 KiB
Plaintext
// 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/local.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/var/local.carbon
|
|
|
|
// --- simple.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
fn Run() -> i32 {
|
|
var x: i32 = 1;
|
|
return x;
|
|
}
|
|
|
|
// --- eval_init_in_place.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
eval fn F() -> (i32, i32, i32) { return (1, 2, 3); }
|
|
|
|
fn G() -> (i32, i32, i32) {
|
|
var a: (i32, i32, i32) = F();
|
|
return a;
|
|
}
|
|
|
|
// CHECK:STDOUT: ; ---
|
|
// CHECK:STDOUT: ; ModuleID = 'simple.carbon'
|
|
// CHECK:STDOUT: source_filename = "simple.carbon"
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define i32 @main() #0 !dbg !25 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %x.var = alloca i32, align 4, !dbg !28
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %x.var), !dbg !28
|
|
// CHECK:STDOUT: store i32 1, ptr %x.var, align 4, !dbg !28
|
|
// CHECK:STDOUT: %.loc6 = load i32, ptr %x.var, align 4, !dbg !30
|
|
// CHECK:STDOUT: call void @"_CSelfDestruct.f58524831c37807e:core.Destroy.Core"(ptr %x.var), !dbg !28
|
|
// CHECK:STDOUT: ret i32 %.loc6, !dbg !31
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define weak_odr void @"_CSelfDestruct.f58524831c37807e:core.Destroy.Core"(ptr %self) #0 !dbg !32 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: ret void, !dbg !34
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
|
|
// CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #1
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: attributes #0 = { nounwind }
|
|
// CHECK:STDOUT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !llvm.dbg.cu = !{!19}
|
|
// CHECK:STDOUT: !llvm.module.flags = !{!2, !3}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5}
|
|
// CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3}
|
|
// CHECK:STDOUT: !18 = !DIFile(filename: "simple.carbon", directory: "")
|
|
// CHECK:STDOUT: !19 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !18, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
|
|
// CHECK:STDOUT: !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
|
|
// CHECK:STDOUT: !21 = !{!20}
|
|
// CHECK:STDOUT: !22 = !DISubroutineType(types: !21)
|
|
// CHECK:STDOUT: !23 = !{null, !20}
|
|
// CHECK:STDOUT: !24 = !DISubroutineType(types: !23)
|
|
// CHECK:STDOUT: !25 = distinct !DISubprogram(name: "Run", linkageName: "main", scope: null, file: !18, line: 4, type: !22, spFlags: DISPFlagDefinition, unit: !19)
|
|
// CHECK:STDOUT: !28 = !DILocation(line: 5, column: 3, scope: !25)
|
|
// CHECK:STDOUT: !30 = !DILocation(line: 6, column: 10, scope: !25)
|
|
// CHECK:STDOUT: !31 = !DILocation(line: 6, column: 3, scope: !25)
|
|
// CHECK:STDOUT: !32 = distinct !DISubprogram(name: "SelfDestruct", linkageName: "_CSelfDestruct.f58524831c37807e:core.Destroy.Core", scope: null, file: !18, line: 5, type: !24, spFlags: DISPFlagDefinition, unit: !19, retainedNodes: !35)
|
|
// CHECK:STDOUT: !33 = !DILocalVariable(arg: 1, scope: !32, type: !20)
|
|
// CHECK:STDOUT: !34 = !DILocation(line: 5, column: 3, scope: !32)
|
|
// CHECK:STDOUT: !35 = !{!33}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; ---
|
|
// CHECK:STDOUT: ; ModuleID = 'eval_init_in_place.carbon'
|
|
// CHECK:STDOUT: source_filename = "eval_init_in_place.carbon"
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: @tuple.479.loc4_50 = internal constant { i32, i32, i32 } { i32 1, i32 2, i32 3 }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define void @_CF.Main(ptr sret({ i32, i32, i32 }) %return) #0 !dbg !43 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %tuple.elem0.tuple.elem = getelementptr inbounds nuw { i32, i32, i32 }, ptr %return, i32 0, i32 0, !dbg !46
|
|
// CHECK:STDOUT: %tuple.elem1.tuple.elem = getelementptr inbounds nuw { i32, i32, i32 }, ptr %return, i32 0, i32 1, !dbg !46
|
|
// CHECK:STDOUT: %tuple.elem2.tuple.elem = getelementptr inbounds nuw { i32, i32, i32 }, ptr %return, i32 0, i32 2, !dbg !46
|
|
// CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %return, ptr align 4 @tuple.479.loc4_50, i64 12, i1 false), !dbg !47
|
|
// CHECK:STDOUT: ret void, !dbg !47
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define void @_CG.Main(ptr sret({ i32, i32, i32 }) %return) #0 !dbg !48 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %a.var = alloca { i32, i32, i32 }, align 4, !dbg !51
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %a.var), !dbg !51
|
|
// CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %a.var, ptr align 4 @tuple.479.loc4_50, i64 12, i1 false), !dbg !51
|
|
// CHECK:STDOUT: %tuple.elem0.loc8_10.1.tuple.elem = getelementptr inbounds nuw { i32, i32, i32 }, ptr %a.var, i32 0, i32 0, !dbg !53
|
|
// CHECK:STDOUT: %.loc8_10.1 = load i32, ptr %tuple.elem0.loc8_10.1.tuple.elem, align 4, !dbg !53
|
|
// CHECK:STDOUT: %tuple.elem0.loc8_10.2.tuple.elem = getelementptr inbounds nuw { i32, i32, i32 }, ptr %return, i32 0, i32 0, !dbg !53
|
|
// CHECK:STDOUT: store i32 %.loc8_10.1, ptr %tuple.elem0.loc8_10.2.tuple.elem, align 4, !dbg !53
|
|
// CHECK:STDOUT: %tuple.elem1.loc8_10.1.tuple.elem = getelementptr inbounds nuw { i32, i32, i32 }, ptr %a.var, i32 0, i32 1, !dbg !53
|
|
// CHECK:STDOUT: %.loc8_10.3 = load i32, ptr %tuple.elem1.loc8_10.1.tuple.elem, align 4, !dbg !53
|
|
// CHECK:STDOUT: %tuple.elem1.loc8_10.2.tuple.elem = getelementptr inbounds nuw { i32, i32, i32 }, ptr %return, i32 0, i32 1, !dbg !53
|
|
// CHECK:STDOUT: store i32 %.loc8_10.3, ptr %tuple.elem1.loc8_10.2.tuple.elem, align 4, !dbg !53
|
|
// CHECK:STDOUT: %tuple.elem2.loc8_10.1.tuple.elem = getelementptr inbounds nuw { i32, i32, i32 }, ptr %a.var, i32 0, i32 2, !dbg !53
|
|
// CHECK:STDOUT: %.loc8_10.5 = load i32, ptr %tuple.elem2.loc8_10.1.tuple.elem, align 4, !dbg !53
|
|
// CHECK:STDOUT: %tuple.elem2.loc8_10.2.tuple.elem = getelementptr inbounds nuw { i32, i32, i32 }, ptr %return, i32 0, i32 2, !dbg !53
|
|
// CHECK:STDOUT: store i32 %.loc8_10.5, ptr %tuple.elem2.loc8_10.2.tuple.elem, align 4, !dbg !53
|
|
// CHECK:STDOUT: call void @"_CSelfDestruct.555b1314256372b8:core.Destroy.Core"(ptr %a.var), !dbg !51
|
|
// CHECK:STDOUT: ret void, !dbg !54
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define weak_odr void @"_CSelfDestruct.f58524831c37807e:core.Destroy.Core"(ptr %self) #0 !dbg !55 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: ret void, !dbg !57
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define weak_odr void @"_CSubobjectDestroy.555b1314256372b8:core.Destroy.Core"(ptr %self) #0 !dbg !59 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %tuple.elem2.tuple.elem = getelementptr inbounds nuw { i32, i32, i32 }, ptr %self, i32 0, i32 2, !dbg !61
|
|
// CHECK:STDOUT: call void @"_CSelfDestruct.f58524831c37807e:core.Destroy.Core"(ptr %tuple.elem2.tuple.elem), !dbg !61
|
|
// CHECK:STDOUT: %tuple.elem1.tuple.elem = getelementptr inbounds nuw { i32, i32, i32 }, ptr %self, i32 0, i32 1, !dbg !61
|
|
// CHECK:STDOUT: call void @"_CSelfDestruct.f58524831c37807e:core.Destroy.Core"(ptr %tuple.elem1.tuple.elem), !dbg !61
|
|
// CHECK:STDOUT: %tuple.elem0.tuple.elem = getelementptr inbounds nuw { i32, i32, i32 }, ptr %self, i32 0, i32 0, !dbg !61
|
|
// CHECK:STDOUT: call void @"_CSelfDestruct.f58524831c37807e:core.Destroy.Core"(ptr %tuple.elem0.tuple.elem), !dbg !61
|
|
// CHECK:STDOUT: ret void, !dbg !61
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define weak_odr void @"_CSelfDestruct.555b1314256372b8:core.Destroy.Core"(ptr %self) #0 !dbg !63 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: call void @"_CSubobjectDestroy.555b1314256372b8:core.Destroy.Core"(ptr %self), !dbg !65
|
|
// CHECK:STDOUT: ret void, !dbg !65
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync 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: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
|
|
// CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #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 nosync nounwind willreturn memory(argmem: readwrite) }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !llvm.dbg.cu = !{!37}
|
|
// CHECK:STDOUT: !llvm.module.flags = !{!2, !3}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5}
|
|
// CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3}
|
|
// CHECK:STDOUT: !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
|
|
// CHECK:STDOUT: !23 = !{null, !20}
|
|
// CHECK:STDOUT: !24 = !DISubroutineType(types: !23)
|
|
// CHECK:STDOUT: !36 = !DIFile(filename: "eval_init_in_place.carbon", directory: "")
|
|
// CHECK:STDOUT: !37 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !36, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
|
|
// CHECK:STDOUT: !38 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
|
|
// CHECK:STDOUT: !39 = !{!38}
|
|
// CHECK:STDOUT: !40 = !DISubroutineType(types: !39)
|
|
// CHECK:STDOUT: !41 = !{null, !38}
|
|
// CHECK:STDOUT: !42 = !DISubroutineType(types: !41)
|
|
// CHECK:STDOUT: !43 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main", scope: null, file: !36, line: 4, type: !40, spFlags: DISPFlagDefinition, unit: !37)
|
|
// CHECK:STDOUT: !46 = !DILocation(line: 4, column: 41, scope: !43)
|
|
// CHECK:STDOUT: !47 = !DILocation(line: 4, column: 34, scope: !43)
|
|
// CHECK:STDOUT: !48 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main", scope: null, file: !36, line: 6, type: !40, spFlags: DISPFlagDefinition, unit: !37)
|
|
// CHECK:STDOUT: !51 = !DILocation(line: 7, column: 3, scope: !48)
|
|
// CHECK:STDOUT: !53 = !DILocation(line: 8, column: 10, scope: !48)
|
|
// CHECK:STDOUT: !54 = !DILocation(line: 8, column: 3, scope: !48)
|
|
// CHECK:STDOUT: !55 = distinct !DISubprogram(name: "SelfDestruct", linkageName: "_CSelfDestruct.f58524831c37807e:core.Destroy.Core", scope: null, file: !36, line: 7, type: !24, spFlags: DISPFlagDefinition, unit: !37, retainedNodes: !58)
|
|
// CHECK:STDOUT: !56 = !DILocalVariable(arg: 1, scope: !55, type: !20)
|
|
// CHECK:STDOUT: !57 = !DILocation(line: 7, column: 3, scope: !55)
|
|
// CHECK:STDOUT: !58 = !{!56}
|
|
// CHECK:STDOUT: !59 = distinct !DISubprogram(name: "SubobjectDestroy", linkageName: "_CSubobjectDestroy.555b1314256372b8:core.Destroy.Core", scope: null, file: !36, line: 7, type: !42, spFlags: DISPFlagDefinition, unit: !37, retainedNodes: !62)
|
|
// CHECK:STDOUT: !60 = !DILocalVariable(arg: 1, scope: !59, type: !38)
|
|
// CHECK:STDOUT: !61 = !DILocation(line: 7, column: 3, scope: !59)
|
|
// CHECK:STDOUT: !62 = !{!60}
|
|
// CHECK:STDOUT: !63 = distinct !DISubprogram(name: "SelfDestruct", linkageName: "_CSelfDestruct.555b1314256372b8:core.Destroy.Core", scope: null, file: !36, line: 7, type: !42, spFlags: DISPFlagDefinition, unit: !37, retainedNodes: !66)
|
|
// CHECK:STDOUT: !64 = !DILocalVariable(arg: 1, scope: !63, type: !38)
|
|
// CHECK:STDOUT: !65 = !DILocation(line: 7, column: 3, scope: !63)
|
|
// CHECK:STDOUT: !66 = !{!64}
|
|
// CHECK:STDOUT:
|