// 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/convert.carbon // AUTOUPDATE // TIP: To test this file alone, run: // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/function/generic/self_canonical.carbon // TIP: To dump output, run: // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/function/generic/self_canonical.carbon // In this test, specific46 becomes canonical for others. Then, specific42 is // found to be equivalent to specific46 and it becomes its canonical. // Then through another equivalence from other specifics that point to // specific46, specific46 is picked as the canonical. This is fine, we keep the // chain of equivalences and eventually this is walked to get to specific42. // The canonical for specific46, should not be updated to self in this case. // Test that chains of equivalances are properly maintained and walked. class class_name1 {} class class_name2 {} class class_name3 {} class class_name4 {} class class_name5 {} class class_name6 {} fn third_function[T: type, U: type, V: type](arg1: T, arg2: U, arg3: V); fn fourth_function[T: type](arg: T); fn first_function[T: type](arg: T); fn second_function[T: type, U: type, V: type](arg1: T, arg2: U, arg3: V); fn third_function[T: type, U: type, V: type](arg1: T, arg2: U, unused arg3: V) { var local1: class_name2*; var local2: class_name2*; third_function(arg1, arg2, local2); fourth_function(local1); } fn unused_1[T: type, U: type, V: type](arg1: T, unused arg2: U, arg3: V) { var local1: class_name6*; third_function(arg1, arg3, local1); } fn fourth_function[T: type](unused arg: T) { var local1: class_name5**; var local2: class_name6*; first_function(local1); first_function(local2); } fn first_function[T: type](arg: T) { var local1: class_name4*; var local2: class_name3*; second_function(local2, local1, arg); } fn unused_2[T: type, U: type](arg1: T, arg2: U) { var local1: class_name6*; second_function(arg1, arg2, local1); } fn second_function[T: type, U: type, V: type](arg1: T, unused arg2: U, arg3: V) { var local1: class_name3*; var local2: class_name4*; var local3: class_name2*; second_function(arg3, local3, local2); third_function(local1, arg3, arg1); } fn Main_method_no_template () { var local1: class_name1*; first_function(local1); } // CHECK:STDOUT: ; --- // CHECK:STDOUT: ; ModuleID = 'self_canonical.carbon' // CHECK:STDOUT: source_filename = "self_canonical.carbon" // CHECK:STDOUT: // CHECK:STDOUT: ; Function Attrs: nounwind // CHECK:STDOUT: define weak_odr void @"_CSelfDestruct.73ffa1ae01557cf1:core.Destroy.Core"(ptr %self) #0 !dbg !21 { // CHECK:STDOUT: entry: // CHECK:STDOUT: ret void, !dbg !23 // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: ; Function Attrs: nounwind // CHECK:STDOUT: define weak_odr void @"_CSelfDestruct.28258e58291017cc:core.Destroy.Core"(ptr %self) #0 !dbg !25 { // CHECK:STDOUT: entry: // CHECK:STDOUT: ret void, !dbg !27 // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: ; Function Attrs: nounwind // CHECK:STDOUT: define weak_odr void @"_CSelfDestruct.a247f3a5f241fa11:core.Destroy.Core"(ptr %self) #0 !dbg !29 { // CHECK:STDOUT: entry: // CHECK:STDOUT: ret void, !dbg !31 // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: ; Function Attrs: nounwind // CHECK:STDOUT: define weak_odr void @"_CSelfDestruct.22bdc7946a052e71:core.Destroy.Core"(ptr %self) #0 !dbg !33 { // CHECK:STDOUT: entry: // CHECK:STDOUT: ret void, !dbg !35 // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: ; Function Attrs: nounwind // CHECK:STDOUT: define weak_odr void @"_CSelfDestruct.680a5c6f7a3d0796:core.Destroy.Core"(ptr %self) #0 !dbg !37 { // CHECK:STDOUT: entry: // CHECK:STDOUT: ret void, !dbg !39 // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: ; Function Attrs: nounwind // CHECK:STDOUT: define void @_CMain_method_no_template.Main() #0 !dbg !41 { // CHECK:STDOUT: entry: // CHECK:STDOUT: %local1.var = alloca ptr, align 8, !dbg !42 // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %local1.var), !dbg !42 // CHECK:STDOUT: store ptr poison, ptr %local1.var, align 8, !dbg !42 // CHECK:STDOUT: %.loc82 = load ptr, ptr %local1.var, align 8, !dbg !44 // CHECK:STDOUT: call void @_Cfirst_function.Main.ee57965601b4d646(ptr %.loc82), !dbg !45 // CHECK:STDOUT: call void @"_CSelfDestruct.a79cf9479d679a84:core.Destroy.Core"(ptr %local1.var), !dbg !42 // CHECK:STDOUT: ret void, !dbg !46 // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: ; Function Attrs: nounwind // CHECK:STDOUT: define weak_odr void @"_CSelfDestruct.a79cf9479d679a84:core.Destroy.Core"(ptr %self) #0 !dbg !47 { // CHECK:STDOUT: entry: // CHECK:STDOUT: ret void, !dbg !49 // 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: ; Function Attrs: nounwind // CHECK:STDOUT: define linkonce_odr void @_Cfourth_function.Main.4da09b2222fc2513(ptr %arg) #0 !dbg !192 { // CHECK:STDOUT: entry: // CHECK:STDOUT: %local1.var = alloca ptr, align 8, !dbg !195 // CHECK:STDOUT: %local2.var = alloca ptr, align 8, !dbg !197 // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %local1.var), !dbg !195 // CHECK:STDOUT: store ptr poison, ptr %local1.var, align 8, !dbg !195 // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %local2.var), !dbg !197 // CHECK:STDOUT: store ptr poison, ptr %local2.var, align 8, !dbg !197 // CHECK:STDOUT: %.loc53 = load ptr, ptr %local1.var, align 8, !dbg !199 // CHECK:STDOUT: call void @_Cfirst_function.Main.ee57965601b4d646(ptr %.loc53), !dbg !200 // CHECK:STDOUT: %.loc54 = load ptr, ptr %local2.var, align 8, !dbg !201 // CHECK:STDOUT: call void @_Cfirst_function.Main.ee57965601b4d646(ptr %.loc54), !dbg !202 // CHECK:STDOUT: call void @"_CSelfDestruct.28258e58291017cc:core.Destroy.Core"(ptr %local2.var), !dbg !197 // CHECK:STDOUT: call void @"_CSelfDestruct.a247f3a5f241fa11:core.Destroy.Core"(ptr %local1.var), !dbg !195 // CHECK:STDOUT: ret void, !dbg !203 // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: ; Function Attrs: nounwind // CHECK:STDOUT: define linkonce_odr void @_Cfirst_function.Main.ee57965601b4d646(ptr %arg) #0 !dbg !243 { // CHECK:STDOUT: entry: // CHECK:STDOUT: %local1.var = alloca ptr, align 8, !dbg !246 // CHECK:STDOUT: %local2.var = alloca ptr, align 8, !dbg !248 // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %local1.var), !dbg !246 // CHECK:STDOUT: store ptr poison, ptr %local1.var, align 8, !dbg !246 // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %local2.var), !dbg !248 // CHECK:STDOUT: store ptr poison, ptr %local2.var, align 8, !dbg !248 // CHECK:STDOUT: %.loc61_19 = load ptr, ptr %local2.var, align 8, !dbg !250 // CHECK:STDOUT: %.loc61_27 = load ptr, ptr %local1.var, align 8, !dbg !251 // CHECK:STDOUT: call void @_Csecond_function.Main.efd9fcdf727c9de5(ptr %.loc61_19, ptr %.loc61_27, ptr %arg), !dbg !253 // CHECK:STDOUT: call void @"_CSelfDestruct.22bdc7946a052e71:core.Destroy.Core"(ptr %local2.var), !dbg !248 // CHECK:STDOUT: call void @"_CSelfDestruct.680a5c6f7a3d0796:core.Destroy.Core"(ptr %local1.var), !dbg !246 // CHECK:STDOUT: ret void, !dbg !254 // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: ; Function Attrs: nounwind // CHECK:STDOUT: define linkonce_odr void @_Csecond_function.Main.efd9fcdf727c9de5(ptr %arg1, ptr %arg2, ptr %arg3) #0 !dbg !269 { // CHECK:STDOUT: entry: // CHECK:STDOUT: %local1.var = alloca ptr, align 8, !dbg !276 // CHECK:STDOUT: %local2.var = alloca ptr, align 8, !dbg !278 // CHECK:STDOUT: %local3.var = alloca ptr, align 8, !dbg !280 // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %local1.var), !dbg !276 // CHECK:STDOUT: store ptr poison, ptr %local1.var, align 8, !dbg !276 // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %local2.var), !dbg !278 // CHECK:STDOUT: store ptr poison, ptr %local2.var, align 8, !dbg !278 // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %local3.var), !dbg !280 // CHECK:STDOUT: store ptr poison, ptr %local3.var, align 8, !dbg !280 // CHECK:STDOUT: %.loc75_25 = load ptr, ptr %local3.var, align 8, !dbg !283 // CHECK:STDOUT: %.loc75_33 = load ptr, ptr %local2.var, align 8, !dbg !284 // CHECK:STDOUT: call void @_Csecond_function.Main.efd9fcdf727c9de5(ptr %arg3, ptr %.loc75_25, ptr %.loc75_33), !dbg !285 // CHECK:STDOUT: %.loc76 = load ptr, ptr %local1.var, align 8, !dbg !286 // CHECK:STDOUT: call void @_Cthird_function.Main.1c39a3b349bf66b6(ptr %.loc76, ptr %arg3, ptr %arg1), !dbg !289 // CHECK:STDOUT: call void @"_CSelfDestruct.73ffa1ae01557cf1:core.Destroy.Core"(ptr %local3.var), !dbg !280 // CHECK:STDOUT: call void @"_CSelfDestruct.680a5c6f7a3d0796:core.Destroy.Core"(ptr %local2.var), !dbg !278 // CHECK:STDOUT: call void @"_CSelfDestruct.22bdc7946a052e71:core.Destroy.Core"(ptr %local1.var), !dbg !276 // CHECK:STDOUT: ret void, !dbg !290 // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: ; Function Attrs: nounwind // CHECK:STDOUT: define linkonce_odr void @_Cthird_function.Main.1c39a3b349bf66b6(ptr %arg1, ptr %arg2, ptr %arg3) #0 !dbg !338 { // CHECK:STDOUT: entry: // CHECK:STDOUT: %local1.var = alloca ptr, align 8, !dbg !345 // CHECK:STDOUT: %local2.var = alloca ptr, align 8, !dbg !347 // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %local1.var), !dbg !345 // CHECK:STDOUT: store ptr poison, ptr %local1.var, align 8, !dbg !345 // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %local2.var), !dbg !347 // CHECK:STDOUT: store ptr poison, ptr %local2.var, align 8, !dbg !347 // CHECK:STDOUT: %.loc39 = load ptr, ptr %local2.var, align 8, !dbg !351 // CHECK:STDOUT: call void @_Cthird_function.Main.1c39a3b349bf66b6(ptr %arg1, ptr %arg2, ptr %.loc39), !dbg !352 // CHECK:STDOUT: %.loc40 = load ptr, ptr %local1.var, align 8, !dbg !353 // CHECK:STDOUT: call void @_Cfourth_function.Main.4da09b2222fc2513(ptr %.loc40), !dbg !354 // CHECK:STDOUT: call void @"_CSelfDestruct.73ffa1ae01557cf1:core.Destroy.Core"(ptr %local2.var), !dbg !347 // CHECK:STDOUT: call void @"_CSelfDestruct.73ffa1ae01557cf1:core.Destroy.Core"(ptr %local1.var), !dbg !345 // CHECK:STDOUT: ret void, !dbg !355 // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: ; uselistorder directives // CHECK:STDOUT: uselistorder ptr @_Cfirst_function.Main.ee57965601b4d646, { 1, 2, 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 = !{!15} // 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: !14 = !DIFile(filename: "self_canonical.carbon", directory: "") // CHECK:STDOUT: !15 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !14, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug) // CHECK:STDOUT: !16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) // CHECK:STDOUT: !17 = !{null, !16} // CHECK:STDOUT: !18 = !DISubroutineType(types: !17) // CHECK:STDOUT: !19 = !{null} // CHECK:STDOUT: !20 = !DISubroutineType(types: !19) // CHECK:STDOUT: !21 = distinct !DISubprogram(name: "SelfDestruct", linkageName: "_CSelfDestruct.73ffa1ae01557cf1:core.Destroy.Core", scope: null, file: !14, line: 37, type: !18, spFlags: DISPFlagDefinition, unit: !15, retainedNodes: !24) // CHECK:STDOUT: !22 = !DILocalVariable(arg: 1, scope: !21, type: !16) // CHECK:STDOUT: !23 = !DILocation(line: 37, column: 3, scope: !21) // CHECK:STDOUT: !24 = !{!22} // CHECK:STDOUT: !25 = distinct !DISubprogram(name: "SelfDestruct", linkageName: "_CSelfDestruct.28258e58291017cc:core.Destroy.Core", scope: null, file: !14, line: 44, type: !18, spFlags: DISPFlagDefinition, unit: !15, retainedNodes: !28) // CHECK:STDOUT: !26 = !DILocalVariable(arg: 1, scope: !25, type: !16) // CHECK:STDOUT: !27 = !DILocation(line: 44, column: 3, scope: !25) // CHECK:STDOUT: !28 = !{!26} // CHECK:STDOUT: !29 = distinct !DISubprogram(name: "SelfDestruct", linkageName: "_CSelfDestruct.a247f3a5f241fa11:core.Destroy.Core", scope: null, file: !14, line: 50, type: !18, spFlags: DISPFlagDefinition, unit: !15, retainedNodes: !32) // CHECK:STDOUT: !30 = !DILocalVariable(arg: 1, scope: !29, type: !16) // CHECK:STDOUT: !31 = !DILocation(line: 50, column: 3, scope: !29) // CHECK:STDOUT: !32 = !{!30} // CHECK:STDOUT: !33 = distinct !DISubprogram(name: "SelfDestruct", linkageName: "_CSelfDestruct.22bdc7946a052e71:core.Destroy.Core", scope: null, file: !14, line: 59, type: !18, spFlags: DISPFlagDefinition, unit: !15, retainedNodes: !36) // CHECK:STDOUT: !34 = !DILocalVariable(arg: 1, scope: !33, type: !16) // CHECK:STDOUT: !35 = !DILocation(line: 59, column: 3, scope: !33) // CHECK:STDOUT: !36 = !{!34} // CHECK:STDOUT: !37 = distinct !DISubprogram(name: "SelfDestruct", linkageName: "_CSelfDestruct.680a5c6f7a3d0796:core.Destroy.Core", scope: null, file: !14, line: 58, type: !18, spFlags: DISPFlagDefinition, unit: !15, retainedNodes: !40) // CHECK:STDOUT: !38 = !DILocalVariable(arg: 1, scope: !37, type: !16) // CHECK:STDOUT: !39 = !DILocation(line: 58, column: 3, scope: !37) // CHECK:STDOUT: !40 = !{!38} // CHECK:STDOUT: !41 = distinct !DISubprogram(name: "Main_method_no_template", linkageName: "_CMain_method_no_template.Main", scope: null, file: !14, line: 79, type: !20, spFlags: DISPFlagDefinition, unit: !15) // CHECK:STDOUT: !42 = !DILocation(line: 80, column: 3, scope: !41) // CHECK:STDOUT: !44 = !DILocation(line: 82, column: 18, scope: !41) // CHECK:STDOUT: !45 = !DILocation(line: 82, column: 3, scope: !41) // CHECK:STDOUT: !46 = !DILocation(line: 79, column: 1, scope: !41) // CHECK:STDOUT: !47 = distinct !DISubprogram(name: "SelfDestruct", linkageName: "_CSelfDestruct.a79cf9479d679a84:core.Destroy.Core", scope: null, file: !14, line: 80, type: !18, spFlags: DISPFlagDefinition, unit: !15, retainedNodes: !50) // CHECK:STDOUT: !48 = !DILocalVariable(arg: 1, scope: !47, type: !16) // CHECK:STDOUT: !49 = !DILocation(line: 80, column: 3, scope: !47) // CHECK:STDOUT: !50 = !{!48} // CHECK:STDOUT: !62 = !{null, !16, !16, !16} // CHECK:STDOUT: !63 = !DISubroutineType(types: !62) // CHECK:STDOUT: !192 = distinct !DISubprogram(name: "fourth_function", linkageName: "_Cfourth_function.Main.4da09b2222fc2513", scope: null, file: !14, line: 49, type: !18, spFlags: DISPFlagDefinition, unit: !15, retainedNodes: !204) // CHECK:STDOUT: !193 = !DILocalVariable(arg: 1, scope: !192, type: !16) // CHECK:STDOUT: !195 = !DILocation(line: 50, column: 3, scope: !192) // CHECK:STDOUT: !197 = !DILocation(line: 51, column: 3, scope: !192) // CHECK:STDOUT: !199 = !DILocation(line: 53, column: 18, scope: !192) // CHECK:STDOUT: !200 = !DILocation(line: 53, column: 3, scope: !192) // CHECK:STDOUT: !201 = !DILocation(line: 54, column: 18, scope: !192) // CHECK:STDOUT: !202 = !DILocation(line: 54, column: 3, scope: !192) // CHECK:STDOUT: !203 = !DILocation(line: 49, column: 1, scope: !192) // CHECK:STDOUT: !204 = !{!193} // CHECK:STDOUT: !243 = distinct !DISubprogram(name: "first_function", linkageName: "_Cfirst_function.Main.ee57965601b4d646", scope: null, file: !14, line: 57, type: !18, spFlags: DISPFlagDefinition, unit: !15, retainedNodes: !255) // CHECK:STDOUT: !244 = !DILocalVariable(arg: 1, scope: !243, type: !16) // CHECK:STDOUT: !246 = !DILocation(line: 58, column: 3, scope: !243) // CHECK:STDOUT: !248 = !DILocation(line: 59, column: 3, scope: !243) // CHECK:STDOUT: !250 = !DILocation(line: 61, column: 19, scope: !243) // CHECK:STDOUT: !251 = !DILocation(line: 61, column: 27, scope: !243) // CHECK:STDOUT: !253 = !DILocation(line: 61, column: 3, scope: !243) // CHECK:STDOUT: !254 = !DILocation(line: 57, column: 1, scope: !243) // CHECK:STDOUT: !255 = !{!244} // CHECK:STDOUT: !269 = distinct !DISubprogram(name: "second_function", linkageName: "_Csecond_function.Main.efd9fcdf727c9de5", scope: null, file: !14, line: 70, type: !63, spFlags: DISPFlagDefinition, unit: !15, retainedNodes: !291) // CHECK:STDOUT: !270 = !DILocalVariable(arg: 1, scope: !269, type: !16) // CHECK:STDOUT: !271 = !DILocalVariable(arg: 2, scope: !269, type: !16) // CHECK:STDOUT: !272 = !DILocalVariable(arg: 3, scope: !269, type: !16) // CHECK:STDOUT: !276 = !DILocation(line: 71, column: 3, scope: !269) // CHECK:STDOUT: !278 = !DILocation(line: 72, column: 3, scope: !269) // CHECK:STDOUT: !280 = !DILocation(line: 73, column: 3, scope: !269) // CHECK:STDOUT: !283 = !DILocation(line: 75, column: 25, scope: !269) // CHECK:STDOUT: !284 = !DILocation(line: 75, column: 33, scope: !269) // CHECK:STDOUT: !285 = !DILocation(line: 75, column: 3, scope: !269) // CHECK:STDOUT: !286 = !DILocation(line: 76, column: 18, scope: !269) // CHECK:STDOUT: !289 = !DILocation(line: 76, column: 3, scope: !269) // CHECK:STDOUT: !290 = !DILocation(line: 70, column: 1, scope: !269) // CHECK:STDOUT: !291 = !{!270, !271, !272} // CHECK:STDOUT: !338 = distinct !DISubprogram(name: "third_function", linkageName: "_Cthird_function.Main.1c39a3b349bf66b6", scope: null, file: !14, line: 35, type: !63, spFlags: DISPFlagDefinition, unit: !15, retainedNodes: !356) // CHECK:STDOUT: !339 = !DILocalVariable(arg: 1, scope: !338, type: !16) // CHECK:STDOUT: !340 = !DILocalVariable(arg: 2, scope: !338, type: !16) // CHECK:STDOUT: !341 = !DILocalVariable(arg: 3, scope: !338, type: !16) // CHECK:STDOUT: !345 = !DILocation(line: 36, column: 3, scope: !338) // CHECK:STDOUT: !347 = !DILocation(line: 37, column: 3, scope: !338) // CHECK:STDOUT: !351 = !DILocation(line: 39, column: 30, scope: !338) // CHECK:STDOUT: !352 = !DILocation(line: 39, column: 3, scope: !338) // CHECK:STDOUT: !353 = !DILocation(line: 40, column: 19, scope: !338) // CHECK:STDOUT: !354 = !DILocation(line: 40, column: 3, scope: !338) // CHECK:STDOUT: !355 = !DILocation(line: 35, column: 1, scope: !338) // CHECK:STDOUT: !356 = !{!339, !340, !341} // CHECK:STDOUT: