Allow conversion between T* and Cpp.void*. (#6575)

Support an implicit conversion from `T*` to `Cpp.void*` and to `const
Cpp.void*`, and an `unsafe as` conversion in the opposite direction.

In order to support C++ calls taking and returning `void*` (which get
mapped to Carbon `Optional(Cpp.void*)`, also support conversions from
`Optional(T)` to `Optional(U)` if there's a conversion from `T` to `U`.

Fix a bug in `OptionalStorage` for `T*` where its `HasValue` was exactly
backwards.
This commit is contained in:
Richard Smith
2026-01-12 16:32:15 +00:00
committed by GitHub
parent d1b13194d5
commit 31919afa24
31 changed files with 986 additions and 381 deletions
+8 -8
View File
@@ -343,14 +343,14 @@ fn ReturnPtrWithThunk() -> Core.Optional(Cpp.C*) {
// CHECK:STDOUT: !35 = distinct !DISubprogram(name: "ReturnPtrWithThunk", linkageName: "_CReturnPtrWithThunk.Main", scope: null, file: !6, line: 38, type: !21, spFlags: DISPFlagDefinition, unit: !5)
// CHECK:STDOUT: !36 = !DILocation(line: 39, column: 10, scope: !35)
// CHECK:STDOUT: !37 = !DILocation(line: 39, column: 3, scope: !35)
// CHECK:STDOUT: !38 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.5b1b7c6bb83e5c41", scope: null, file: !39, line: 82, type: !40, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !42)
// CHECK:STDOUT: !38 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.5b1b7c6bb83e5c41", scope: null, file: !39, line: 93, type: !40, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !42)
// CHECK:STDOUT: !39 = !DIFile(filename: "{{.*}}/prelude/types/optional.carbon", directory: "")
// CHECK:STDOUT: !40 = !DISubroutineType(types: !41)
// CHECK:STDOUT: !41 = !{!10, !10}
// CHECK:STDOUT: !42 = !{!43}
// CHECK:STDOUT: !43 = !DILocalVariable(arg: 1, scope: !38, type: !10)
// CHECK:STDOUT: !44 = !DILocation(line: 83, column: 12, scope: !38)
// CHECK:STDOUT: !45 = !DILocation(line: 83, column: 5, scope: !38)
// CHECK:STDOUT: !44 = !DILocation(line: 94, column: 12, scope: !38)
// CHECK:STDOUT: !45 = !DILocation(line: 94, column: 5, scope: !38)
// CHECK:STDOUT: !46 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.90961d7b1ce4f089:OptionalAs.0e326e799dad0c64.Core.ea71e3f17b6b4efb", scope: null, file: !39, line: 68, type: !40, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !47)
// CHECK:STDOUT: !47 = !{!48}
// CHECK:STDOUT: !48 = !DILocalVariable(arg: 1, scope: !46, type: !10)
@@ -361,10 +361,10 @@ fn ReturnPtrWithThunk() -> Core.Optional(Cpp.C*) {
// CHECK:STDOUT: !53 = !DILocalVariable(arg: 1, scope: !51, type: !10)
// CHECK:STDOUT: !54 = !DILocation(line: 30, column: 12, scope: !51)
// CHECK:STDOUT: !55 = !DILocation(line: 30, column: 5, scope: !51)
// CHECK:STDOUT: !56 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.e8f8f92d3d08d149:OptionalStorage.Core.f53db17714b9f655", scope: null, file: !39, line: 125, type: !40, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !57)
// CHECK:STDOUT: !56 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.e8f8f92d3d08d149:OptionalStorage.Core.f53db17714b9f655", scope: null, file: !39, line: 138, type: !40, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !57)
// CHECK:STDOUT: !57 = !{!58}
// CHECK:STDOUT: !58 = !DILocalVariable(arg: 1, scope: !56, type: !10)
// CHECK:STDOUT: !59 = !DILocation(line: 126, column: 14, scope: !56)
// CHECK:STDOUT: !60 = !DILocation(line: 127, column: 5, scope: !56)
// CHECK:STDOUT: !61 = !DILocation(line: 126, column: 18, scope: !56)
// CHECK:STDOUT: !62 = !DILocation(line: 128, column: 5, scope: !56)
// CHECK:STDOUT: !59 = !DILocation(line: 139, column: 14, scope: !56)
// CHECK:STDOUT: !60 = !DILocation(line: 140, column: 5, scope: !56)
// CHECK:STDOUT: !61 = !DILocation(line: 139, column: 18, scope: !56)
// CHECK:STDOUT: !62 = !DILocation(line: 141, column: 5, scope: !56)