Skip to content

Commit dfd9946

Browse files
authored
Complete all pointer types. (#6340)
Completing a pointer type is trivial, but we still need to do it, and fail to do so in a few places, which can lead to crashes during lowering. Switch to completing pointer types when the type is created to avoid the issue.
1 parent 13a1627 commit dfd9946

File tree

6 files changed

+77
-12
lines changed

6 files changed

+77
-12
lines changed

toolchain/check/testdata/basics/raw_sem_ir/cpp_interop.carbon

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ fn G(x: Cpp.X) {
9191
// CHECK:STDOUT: value_repr: {kind: none, type: type(inst60000012)}
9292
// CHECK:STDOUT: 'type(inst6000001D)':
9393
// CHECK:STDOUT: value_repr: {kind: none, type: type(inst60000012)}
94-
// CHECK:STDOUT: 'type(inst(WitnessType))':
95-
// CHECK:STDOUT: value_repr: {kind: copy, type: type(inst(WitnessType))}
9694
// CHECK:STDOUT: 'type(inst6000001F)':
9795
// CHECK:STDOUT: value_repr: {kind: copy, type: type(inst6000001F)}
98-
// CHECK:STDOUT: 'type(inst60000023)':
99-
// CHECK:STDOUT: value_repr: {kind: pointer, type: type(inst60000026)}
96+
// CHECK:STDOUT: 'type(inst(WitnessType))':
97+
// CHECK:STDOUT: value_repr: {kind: copy, type: type(inst(WitnessType))}
10098
// CHECK:STDOUT: 'type(inst60000026)':
10199
// CHECK:STDOUT: value_repr: {kind: copy, type: type(inst60000026)}
100+
// CHECK:STDOUT: 'type(inst60000023)':
101+
// CHECK:STDOUT: value_repr: {kind: pointer, type: type(inst60000026)}
102102
// CHECK:STDOUT: 'type(inst60000014)':
103103
// CHECK:STDOUT: value_repr: {kind: pointer, type: type(inst60000026)}
104104
// CHECK:STDOUT: 'type(inst60000028)':

toolchain/check/testdata/basics/raw_sem_ir/one_file.carbon

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,18 +351,18 @@ fn Foo[T:! type](p: T*) -> (T*, ()) {
351351
// CHECK:STDOUT: value_repr: {kind: copy, type: type(inst(NamespaceType))}
352352
// CHECK:STDOUT: 'type(inst60000024)':
353353
// CHECK:STDOUT: value_repr: {kind: none, type: type(inst60000024)}
354-
// CHECK:STDOUT: 'type(inst60000026)':
355-
// CHECK:STDOUT: value_repr: {kind: pointer, type: type(inst60000028)}
356354
// CHECK:STDOUT: 'type(inst60000028)':
357355
// CHECK:STDOUT: value_repr: {kind: copy, type: type(inst60000028)}
356+
// CHECK:STDOUT: 'type(inst60000026)':
357+
// CHECK:STDOUT: value_repr: {kind: pointer, type: type(inst60000028)}
358358
// CHECK:STDOUT: 'type(inst60000036)':
359359
// CHECK:STDOUT: value_repr: {kind: none, type: type(inst60000024)}
360360
// CHECK:STDOUT: 'type(symbolic_constant3)':
361361
// CHECK:STDOUT: value_repr: {kind: copy, type: type(symbolic_constant3)}
362-
// CHECK:STDOUT: 'type(symbolic_constant7)':
363-
// CHECK:STDOUT: value_repr: {kind: pointer, type: type(symbolic_constantB)}
364362
// CHECK:STDOUT: 'type(symbolic_constantB)':
365363
// CHECK:STDOUT: value_repr: {kind: copy, type: type(symbolic_constantB)}
364+
// CHECK:STDOUT: 'type(symbolic_constant7)':
365+
// CHECK:STDOUT: value_repr: {kind: pointer, type: type(symbolic_constantB)}
366366
// CHECK:STDOUT: 'type(inst(WitnessType))':
367367
// CHECK:STDOUT: value_repr: {kind: copy, type: type(inst(WitnessType))}
368368
// CHECK:STDOUT: 'type(symbolic_constant4)':

toolchain/check/testdata/basics/raw_sem_ir/one_file_with_textual_ir.carbon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ fn Foo(n: ()) -> ((), ()) {
4646
// CHECK:STDOUT: value_repr: {kind: copy, type: type(inst(NamespaceType))}
4747
// CHECK:STDOUT: 'type(inst6000000F)':
4848
// CHECK:STDOUT: value_repr: {kind: none, type: type(inst6000000F)}
49-
// CHECK:STDOUT: 'type(inst60000018)':
50-
// CHECK:STDOUT: value_repr: {kind: pointer, type: type(inst6000001A)}
5149
// CHECK:STDOUT: 'type(inst6000001A)':
5250
// CHECK:STDOUT: value_repr: {kind: copy, type: type(inst6000001A)}
51+
// CHECK:STDOUT: 'type(inst60000018)':
52+
// CHECK:STDOUT: value_repr: {kind: pointer, type: type(inst6000001A)}
5353
// CHECK:STDOUT: 'type(inst60000026)':
5454
// CHECK:STDOUT: value_repr: {kind: none, type: type(inst6000000F)}
5555
// CHECK:STDOUT: insts:

toolchain/check/type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ auto GetFacetType(Context& context, const SemIR::FacetTypeInfo& info)
236236

237237
auto GetPointerType(Context& context, SemIR::TypeInstId pointee_type_id)
238238
-> SemIR::TypeId {
239-
return GetTypeImpl<SemIR::PointerType>(context, pointee_type_id);
239+
return GetCompleteTypeImpl<SemIR::PointerType>(context, pointee_type_id);
240240
}
241241

242242
auto GetPatternType(Context& context, SemIR::TypeId scrutinee_type_id)

toolchain/check/type.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ auto GetNamedConstraintType(Context& context,
100100
auto GetFacetType(Context& context, const SemIR::FacetTypeInfo& info)
101101
-> SemIR::TypeId;
102102

103-
// Returns a pointer type whose pointee type is `pointee_type_id`.
103+
// Returns a pointer type whose pointee type is `pointee_type_id`. The returned
104+
// type will be complete.
104105
auto GetPointerType(Context& context, SemIR::TypeInstId pointee_type_id)
105106
-> SemIR::TypeId;
106107

toolchain/lower/testdata/interop/cpp/return.carbon

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ fn Var() {
9898
var x: Cpp.X = Cpp.Make();
9999
}
100100

101+
// --- indirect_return_with_args.carbon
102+
103+
library "[[@TEST_NAME]]";
104+
105+
import Cpp inline '''
106+
class C {};
107+
class D {};
108+
C f(D);
109+
''';
110+
111+
fn Call(x: Cpp.D) -> Cpp.C {
112+
return Cpp.f(x);
113+
}
114+
101115
// CHECK:STDOUT: ; ModuleID = 'import_ints.carbon'
102116
// CHECK:STDOUT: source_filename = "import_ints.carbon"
103117
// CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
@@ -481,3 +495,53 @@ fn Var() {
481495
// CHECK:STDOUT: !16 = !DILocation(line: 13, column: 3, scope: !15)
482496
// CHECK:STDOUT: !17 = !DILocation(line: 13, column: 18, scope: !15)
483497
// CHECK:STDOUT: !18 = !DILocation(line: 12, column: 1, scope: !15)
498+
// CHECK:STDOUT: ; ModuleID = 'indirect_return_with_args.carbon'
499+
// CHECK:STDOUT: source_filename = "indirect_return_with_args.carbon"
500+
// CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
501+
// CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
502+
// CHECK:STDOUT:
503+
// CHECK:STDOUT: %class.D = type { i8 }
504+
// CHECK:STDOUT:
505+
// CHECK:STDOUT: ; Function Attrs: nounwind
506+
// CHECK:STDOUT: define void @_CCall.Main(ptr sret({}) %return, ptr %x) #0 !dbg !7 {
507+
// CHECK:STDOUT: entry:
508+
// CHECK:STDOUT: call void @_Z1f1D.carbon_thunk(ptr %x, ptr %return), !dbg !10
509+
// CHECK:STDOUT: ret void, !dbg !11
510+
// CHECK:STDOUT: }
511+
// CHECK:STDOUT:
512+
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress
513+
// CHECK:STDOUT: define dso_local void @_Z1f1D.carbon_thunk(ptr %0, ptr %return) #1 {
514+
// CHECK:STDOUT: entry:
515+
// CHECK:STDOUT: %.addr = alloca ptr, align 8
516+
// CHECK:STDOUT: %return.addr = alloca ptr, align 8
517+
// CHECK:STDOUT: %agg.tmp = alloca %class.D, align 1
518+
// CHECK:STDOUT: %undef.agg.tmp = alloca %class.D, align 1
519+
// CHECK:STDOUT: store ptr %0, ptr %.addr, align 8
520+
// CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8
521+
// CHECK:STDOUT: %1 = load ptr, ptr %return.addr, align 8
522+
// CHECK:STDOUT: %2 = load ptr, ptr %.addr, align 8
523+
// CHECK:STDOUT: call void @_Z1f1D()
524+
// CHECK:STDOUT: ret void
525+
// CHECK:STDOUT: }
526+
// CHECK:STDOUT:
527+
// CHECK:STDOUT: declare void @_Z1f1D() #2
528+
// CHECK:STDOUT:
529+
// CHECK:STDOUT: attributes #0 = { nounwind }
530+
// CHECK:STDOUT: attributes #1 = { alwaysinline mustprogress "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
531+
// CHECK:STDOUT: attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
532+
// CHECK:STDOUT:
533+
// CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
534+
// CHECK:STDOUT: !llvm.dbg.cu = !{!5}
535+
// CHECK:STDOUT:
536+
// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
537+
// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
538+
// CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4}
539+
// CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 0}
540+
// CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2}
541+
// CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
542+
// CHECK:STDOUT: !6 = !DIFile(filename: "indirect_return_with_args.carbon", directory: "")
543+
// CHECK:STDOUT: !7 = distinct !DISubprogram(name: "Call", linkageName: "_CCall.Main", scope: null, file: !6, line: 10, type: !8, spFlags: DISPFlagDefinition, unit: !5)
544+
// CHECK:STDOUT: !8 = !DISubroutineType(types: !9)
545+
// CHECK:STDOUT: !9 = !{}
546+
// CHECK:STDOUT: !10 = !DILocation(line: 11, column: 10, scope: !7)
547+
// CHECK:STDOUT: !11 = !DILocation(line: 11, column: 3, scope: !7)

0 commit comments

Comments
 (0)