mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Fix mangling collision for C++ class template specializations (#7269)
Carbon-side thunks (for example the `Copy`/`Destroy` witness thunks generated for imported C++ types) are mangled by Carbon, and their names incorporate a fingerprint of the involved types. The instruction fingerprinter identifies a class only by its name and parent scope, which is sufficient for Carbon classes but not for imported C++ classes: different specializations of one class template (and other cases such as types in anonymous namespaces) share a Carbon name and parent scope. As a result, the thunks for two distinct specializations could mangle to the same name, producing a single LLVM function with two definitions and failing `verifyModule` during lowering. When fingerprinting a class imported from C++, also include the Clang mangled name of its type. Test: toolchain/lower/testdata/interop/cpp/thunks.carbon gains a split with two specializations of one class template, each requiring a thunk; their thunks now get distinct mangled names instead of colliding. Assisted-by: Claude Code --------- Co-authored-by: Christopher Di Bella <cjdb.ns@gmail.com>
This commit is contained in:
co-authored by
Christopher Di Bella
parent
3ef128ac91
commit
8a59f2a76b
@@ -171,7 +171,7 @@ auto DoThing() -> void {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nounwind
|
||||
// CHECK:STDOUT: define weak_odr void @"_COp.9262bcc12ced4e1e:core.Destroy.Core"(ptr %self) #5 !dbg !33 {
|
||||
// CHECK:STDOUT: define weak_odr void @"_COp.47e6e98bb48502be:core.Destroy.Core"(ptr %self) #5 !dbg !33 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: ret void, !dbg !36
|
||||
// CHECK:STDOUT: }
|
||||
@@ -297,7 +297,7 @@ auto DoThing() -> void {
|
||||
// CHECK:STDOUT: !30 = !{!31}
|
||||
// CHECK:STDOUT: !31 = !DILocalVariable(arg: 1, scope: !29, type: !21)
|
||||
// CHECK:STDOUT: !32 = !DILocation(line: 22, column: 1, scope: !29)
|
||||
// CHECK:STDOUT: !33 = distinct !DISubprogram(name: "Op", linkageName: "_COp.9262bcc12ced4e1e:core.Destroy.Core", scope: null, file: !6, line: 22, type: !19, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !34)
|
||||
// CHECK:STDOUT: !33 = distinct !DISubprogram(name: "Op", linkageName: "_COp.47e6e98bb48502be:core.Destroy.Core", scope: null, file: !6, line: 22, type: !19, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !34)
|
||||
// CHECK:STDOUT: !34 = !{!35}
|
||||
// CHECK:STDOUT: !35 = !DILocalVariable(arg: 1, scope: !33, type: !21)
|
||||
// CHECK:STDOUT: !36 = !DILocation(line: 22, column: 1, scope: !33)
|
||||
|
||||
@@ -209,7 +209,7 @@ void delete_new_Base() {
|
||||
// CHECK:STDOUT: declare void @_ZN1AD1Ev(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8)) unnamed_addr #7
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nounwind
|
||||
// CHECK:STDOUT: define weak_odr void @"_COp.bce205344e07c31d:core.Destroy.Core"(ptr %self) #8 !dbg !29 {
|
||||
// CHECK:STDOUT: define weak_odr void @"_COp.6a9ecc3bdf183bcf:core.Destroy.Core"(ptr %self) #8 !dbg !29 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: ret void, !dbg !32
|
||||
// CHECK:STDOUT: }
|
||||
@@ -380,7 +380,7 @@ void delete_new_Base() {
|
||||
// CHECK:STDOUT: !26 = !{!27}
|
||||
// CHECK:STDOUT: !27 = !DILocalVariable(arg: 1, scope: !22, type: !25)
|
||||
// CHECK:STDOUT: !28 = !DILocation(line: 12, column: 1, scope: !22)
|
||||
// CHECK:STDOUT: !29 = distinct !DISubprogram(name: "Op", linkageName: "_COp.bce205344e07c31d:core.Destroy.Core", scope: null, file: !6, line: 12, type: !23, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !30)
|
||||
// CHECK:STDOUT: !29 = distinct !DISubprogram(name: "Op", linkageName: "_COp.6a9ecc3bdf183bcf:core.Destroy.Core", scope: null, file: !6, line: 12, type: !23, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !30)
|
||||
// CHECK:STDOUT: !30 = !{!31}
|
||||
// CHECK:STDOUT: !31 = !DILocalVariable(arg: 1, scope: !29, type: !25)
|
||||
// CHECK:STDOUT: !32 = !DILocation(line: 12, column: 1, scope: !29)
|
||||
|
||||
Reference in New Issue
Block a user