diff --git a/toolchain/check/class.cpp b/toolchain/check/class.cpp index 17aff5d4720d..6b5756072562 100644 --- a/toolchain/check/class.cpp +++ b/toolchain/check/class.cpp @@ -183,12 +183,24 @@ static auto BuildVtable(Context& context, Parse::ClassDefinitionId node_id, llvm::SmallVector vtable; Set implemented_impls; + bool carbon_native_vtable = true; if (base_vtable_id.has_value()) { - auto base_vtable_inst_block = context.inst_blocks().Get( - context.vtables().Get(base_vtable_id).virtual_functions_id); + const auto& base_vtable = context.vtables().Get(base_vtable_id); + carbon_native_vtable = base_vtable.carbon_native_vtable; + auto base_vtable_inst_block = + context.inst_blocks().Get(base_vtable.virtual_functions_id); // TODO: Avoid quadratic search. Perhaps build a map from `NameId` to the // elements of the top of `vtable_stack`. for (auto base_vtable_entry_id : base_vtable_inst_block) { + if (!base_vtable_entry_id.has_value()) { + // Foreign vtables may have holes in them for information that we don't + // use. Just skip those entries. + CARBON_CHECK( + !context.vtables().Get(base_vtable_id).carbon_native_vtable); + vtable.push_back(SemIR::InstId::None); + continue; + } + auto [derived_vtable_entry_id, derived_vtable_entry_const_id, fn_id, specific_id] = DecomposeVirtualFunction(context.sem_ir(), base_vtable_entry_id, @@ -265,7 +277,8 @@ static auto BuildVtable(Context& context, Parse::ClassDefinitionId node_id, return context.vtables().Add( {{.class_id = class_id, - .virtual_functions_id = context.inst_blocks().Add(vtable)}}); + .virtual_functions_id = context.inst_blocks().Add(vtable), + .carbon_native_vtable = carbon_native_vtable}}); } // Checks that the specified finished class definition is valid and builds and diff --git a/toolchain/check/cpp/import.cpp b/toolchain/check/cpp/import.cpp index 54faacb0c1f8..c844ff5323df 100644 --- a/toolchain/check/cpp/import.cpp +++ b/toolchain/check/cpp/import.cpp @@ -939,25 +939,26 @@ static auto BuildClassDefinition(Context& context, if (class_info.is_dynamic) { llvm::SmallVector vtable; - const auto& vtable_layout = dyn_cast( - context.ast_context().getVTableContext()) - ->getVTableLayout(clang_def); + auto& vtable_context = *cast( + context.ast_context().getVTableContext()); + const auto& vtable_layout = vtable_context.getVTableLayout(clang_def); auto vtable_components = vtable_layout.vtable_components(); vtable.reserve(vtable_components.size()); - auto num_components = 0; for (const auto& vtable_component : vtable_components) { if (vtable_component.getKind() != clang::VTableComponent::CK_FunctionPointer) { continue; } - ++num_components; const auto* method_decl = vtable_component.getFunctionDecl(); - vtable.push_back(ImportCppFunctionDecl( + auto virtual_index = vtable_context.getMethodVTableIndex(method_decl); + if (virtual_index >= vtable.size()) { + vtable.resize(virtual_index + 1, SemIR::InstId::None); + } + vtable[virtual_index] = ImportCppFunctionDecl( context, SemIR::LocId(import_ir_inst_id), const_cast(method_decl), - MakeVirtualFunctionSignature(context, method_decl))); + MakeVirtualFunctionSignature(context, method_decl)); } - vtable.truncate(num_components); auto vtable_id = context.vtables().Add( {{.class_id = class_id, .virtual_functions_id = context.inst_blocks().Add(vtable), diff --git a/toolchain/check/import_ref.cpp b/toolchain/check/import_ref.cpp index d791ba879b5a..1f2b9cd257bd 100644 --- a/toolchain/check/import_ref.cpp +++ b/toolchain/check/import_ref.cpp @@ -2454,6 +2454,9 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, for (auto [import_vtable_entry_inst_id, local_vtable_entry_inst_id] : llvm::zip_equal(virtual_functions, lazy_virtual_functions)) { + if (!local_vtable_entry_inst_id.has_value()) { + continue; + } // Use LoadedImportRef for imported symbolic constant vtable entries so they // can carry attached constants necessary for applying specifics to these // constants when they are used. diff --git a/toolchain/check/testdata/interop/cpp/class/import/class.carbon b/toolchain/check/testdata/interop/cpp/class/import/class.carbon index 556c79f82361..8d7fff4a1b7d 100644 --- a/toolchain/check/testdata/interop/cpp/class/import/class.carbon +++ b/toolchain/check/testdata/interop/cpp/class/import/class.carbon @@ -522,6 +522,8 @@ fn GenericUse(p2: Generic(Cpp.Class1)) { // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: vtable @Bar.vtable { +// CHECK:STDOUT: invalid +// CHECK:STDOUT: invalid // CHECK:STDOUT: imports.%Bar.f.decl // CHECK:STDOUT: } // CHECK:STDOUT: diff --git a/toolchain/lower/testdata/interop/cpp/class/import/dynamic.carbon b/toolchain/lower/testdata/interop/cpp/class/import/dynamic.carbon index 1a87134a6e52..0cb07add47a2 100644 --- a/toolchain/lower/testdata/interop/cpp/class/import/dynamic.carbon +++ b/toolchain/lower/testdata/interop/cpp/class/import/dynamic.carbon @@ -102,7 +102,6 @@ auto DoThing() -> int { // CHECK:STDOUT: // CHECK:STDOUT: $_ZTV11FurtherBase = comdat any // CHECK:STDOUT: -// CHECK:STDOUT: @"_CDerived.Main.$vtable" = unnamed_addr constant [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint (ptr @_ZN11FurtherBase17further_base_funcEv to i64), i64 ptrtoint (ptr @"_CDerived.Main.$vtable" to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (ptr @_ZN4Base4funcEv to i64), i64 ptrtoint (ptr @"_CDerived.Main.$vtable" to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (ptr @_Cother_func.Derived.Main to i64), i64 ptrtoint (ptr @"_CDerived.Main.$vtable" to i64)) to i32)] // CHECK:STDOUT: @_ZTVN6Carbon7DerivedE = linkonce_odr dso_local unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr @_ZTIN6Carbon7DerivedE, ptr @_ZN11FurtherBase17further_base_funcEv, ptr @_ZN4Base4funcEv] }, comdat, align 8 // CHECK:STDOUT: @_ZTIN6Carbon7DerivedE = linkonce_odr dso_local constant { ptr, ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2), ptr @_ZTSN6Carbon7DerivedE, ptr @_ZTI4Base }, comdat, align 8 // CHECK:STDOUT: @_ZTVN10__cxxabiv120__si_class_type_infoE = external global [0 x ptr] @@ -275,8 +274,8 @@ auto DoThing() -> int { // CHECK:STDOUT: uselistorder ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2), { 1, 0 } // CHECK:STDOUT: uselistorder ptr @_ZN6Carbon7DerivedC2Ev, { 1, 0 } // CHECK:STDOUT: uselistorder ptr @_ZN6Carbon7DerivedD2Ev, { 2, 1, 0 } -// CHECK:STDOUT: uselistorder ptr @_ZN11FurtherBase17further_base_funcEv, { 3, 2, 1, 0 } -// CHECK:STDOUT: uselistorder ptr @_ZN4Base4funcEv, { 2, 1, 0 } +// CHECK:STDOUT: uselistorder ptr @_ZN11FurtherBase17further_base_funcEv, { 2, 1, 0 } +// CHECK:STDOUT: uselistorder ptr @_ZN4Base4funcEv, { 1, 0 } // CHECK:STDOUT: // CHECK:STDOUT: attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } // CHECK:STDOUT: attributes #1 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } diff --git a/toolchain/lower/testdata/interop/cpp/class/virtual_fn.carbon b/toolchain/lower/testdata/interop/cpp/class/virtual_fn.carbon index ae31da0c7515..34d400277f03 100644 --- a/toolchain/lower/testdata/interop/cpp/class/virtual_fn.carbon +++ b/toolchain/lower/testdata/interop/cpp/class/virtual_fn.carbon @@ -19,15 +19,18 @@ import Cpp; inline Cpp ''' struct A { virtual ~A() = 0; + virtual void F() const; }; '''; class Final { extend base: Cpp.A; + override fn F[self: Self](); } base class Base { extend base: Cpp.A; + override fn F[self: Self](); } inline Cpp ''' @@ -71,29 +74,19 @@ void delete_new_Base() { // CHECK:STDOUT: // CHECK:STDOUT: $_ZTSN6Carbon5FinalE = comdat any // CHECK:STDOUT: -// CHECK:STDOUT: $_ZTI1A = comdat any -// CHECK:STDOUT: -// CHECK:STDOUT: $_ZTS1A = comdat any -// CHECK:STDOUT: -// CHECK:STDOUT: $_ZTV1A = comdat any -// CHECK:STDOUT: // CHECK:STDOUT: $_ZTVN6Carbon4BaseE = comdat any // CHECK:STDOUT: // CHECK:STDOUT: $_ZTIN6Carbon4BaseE = comdat any // CHECK:STDOUT: // CHECK:STDOUT: $_ZTSN6Carbon4BaseE = comdat any // CHECK:STDOUT: -// CHECK:STDOUT: @"_CFinal.Main.$vtable" = unnamed_addr constant [0 x i32] zeroinitializer -// CHECK:STDOUT: @"_CBase.Main.$vtable" = unnamed_addr constant [0 x i32] zeroinitializer -// CHECK:STDOUT: @_ZTVN6Carbon5FinalE = linkonce_odr dso_local unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr @_ZTIN6Carbon5FinalE, ptr @_ZN6Carbon5FinalD2Ev, ptr @_ZN6Carbon5FinalD0Ev] }, comdat, align 8 +// CHECK:STDOUT: @_ZTVN6Carbon5FinalE = linkonce_odr dso_local unnamed_addr constant { [5 x ptr] } { [5 x ptr] [ptr null, ptr @_ZTIN6Carbon5FinalE, ptr @_ZN6Carbon5FinalD2Ev, ptr @_ZN6Carbon5FinalD0Ev, ptr @_ZNK1A1FEv] }, comdat, align 8 // CHECK:STDOUT: @_ZTIN6Carbon5FinalE = linkonce_odr dso_local constant { ptr, ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2), ptr @_ZTSN6Carbon5FinalE, ptr @_ZTI1A }, comdat, align 8 // CHECK:STDOUT: @_ZTVN10__cxxabiv120__si_class_type_infoE = external global [0 x ptr] // CHECK:STDOUT: @_ZTSN6Carbon5FinalE = linkonce_odr dso_local constant [16 x i8] c"N6Carbon5FinalE\00", comdat, align 1 -// CHECK:STDOUT: @_ZTI1A = linkonce_odr dso_local constant { ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i64 2), ptr @_ZTS1A }, comdat, align 8 -// CHECK:STDOUT: @_ZTVN10__cxxabiv117__class_type_infoE = external global [0 x ptr] -// CHECK:STDOUT: @_ZTS1A = linkonce_odr dso_local constant [3 x i8] c"1A\00", comdat, align 1 -// CHECK:STDOUT: @_ZTV1A = linkonce_odr dso_local unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr @_ZTI1A, ptr @__cxa_pure_virtual, ptr @__cxa_pure_virtual] }, comdat, align 8 -// CHECK:STDOUT: @_ZTVN6Carbon4BaseE = linkonce_odr dso_local unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr @_ZTIN6Carbon4BaseE, ptr @_ZN6Carbon4BaseD2Ev, ptr @_ZN6Carbon4BaseD0Ev] }, comdat, align 8 +// CHECK:STDOUT: @_ZTI1A = external constant ptr +// CHECK:STDOUT: @_ZTV1A = available_externally unnamed_addr constant { [5 x ptr] } { [5 x ptr] [ptr null, ptr @_ZTI1A, ptr @__cxa_pure_virtual, ptr @__cxa_pure_virtual, ptr @_ZNK1A1FEv] }, align 8 +// CHECK:STDOUT: @_ZTVN6Carbon4BaseE = linkonce_odr dso_local unnamed_addr constant { [5 x ptr] } { [5 x ptr] [ptr null, ptr @_ZTIN6Carbon4BaseE, ptr @_ZN6Carbon4BaseD2Ev, ptr @_ZN6Carbon4BaseD0Ev, ptr @_ZNK1A1FEv] }, comdat, align 8 // CHECK:STDOUT: @_ZTIN6Carbon4BaseE = linkonce_odr dso_local constant { ptr, ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2), ptr @_ZTSN6Carbon4BaseE, ptr @_ZTI1A }, comdat, align 8 // CHECK:STDOUT: @_ZTSN6Carbon4BaseE = linkonce_odr dso_local constant [15 x i8] c"N6Carbon4BaseE\00", comdat, align 1 // CHECK:STDOUT: @@ -101,21 +94,21 @@ void delete_new_Base() { // CHECK:STDOUT: define dso_local void @_Z16delete_new_Finalv() #0 { // CHECK:STDOUT: entry: // CHECK:STDOUT: %p = alloca ptr, align 8 -// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %p) #7 -// CHECK:STDOUT: %call = call noalias noundef nonnull ptr @_Znwm(i64 noundef 8) #8 -// CHECK:STDOUT: call void @_ZN6Carbon5FinalC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %call) #7 +// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %p) #8 +// CHECK:STDOUT: %call = call noalias noundef nonnull ptr @_Znwm(i64 noundef 8) #10 +// CHECK:STDOUT: call void @_ZN6Carbon5FinalC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %call) #8 // CHECK:STDOUT: store ptr %call, ptr %p, align 8, !tbaa !11 // CHECK:STDOUT: %0 = load ptr, ptr %p, align 8, !tbaa !11 // CHECK:STDOUT: %isnull = icmp eq ptr %0, null // CHECK:STDOUT: br i1 %isnull, label %delete.end, label %delete.notnull // CHECK:STDOUT: // CHECK:STDOUT: delete.notnull: ; preds = %entry -// CHECK:STDOUT: call void @_ZN6Carbon5FinalD2Ev(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8) %0) #7 -// CHECK:STDOUT: call void @_ZdlPvm(ptr noundef %0, i64 noundef 8) #9 +// CHECK:STDOUT: call void @_ZN6Carbon5FinalD2Ev(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8) %0) #8 +// CHECK:STDOUT: call void @_ZdlPvm(ptr noundef %0, i64 noundef 8) #11 // CHECK:STDOUT: br label %delete.end // CHECK:STDOUT: // CHECK:STDOUT: delete.end: ; preds = %delete.notnull, %entry -// CHECK:STDOUT: call void @llvm.lifetime.end.p0(ptr %p) #7 +// CHECK:STDOUT: call void @llvm.lifetime.end.p0(ptr %p) #8 // CHECK:STDOUT: ret void // CHECK:STDOUT: } // CHECK:STDOUT: @@ -131,8 +124,8 @@ void delete_new_Base() { // CHECK:STDOUT: %this.addr = alloca ptr, align 8 // CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8, !tbaa !11 // CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8 -// CHECK:STDOUT: call void @_ZN1AC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %this1) #7 -// CHECK:STDOUT: store ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTVN6Carbon5FinalE, i32 0, i32 0, i32 2), ptr %this1, align 8, !tbaa !14 +// CHECK:STDOUT: call void @_ZN1AC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %this1) #8 +// CHECK:STDOUT: store ptr getelementptr inbounds inrange(-16, 24) ({ [5 x ptr] }, ptr @_ZTVN6Carbon5FinalE, i32 0, i32 0, i32 2), ptr %this1, align 8, !tbaa !14 // CHECK:STDOUT: ret void // CHECK:STDOUT: } // CHECK:STDOUT: @@ -143,7 +136,7 @@ void delete_new_Base() { // CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8, !tbaa !11 // CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8 // CHECK:STDOUT: call void @"_C__destroy_thunk:thunk.Final.Main"(ptr noundef nonnull align 8 dereferenceable(8) %this1) -// CHECK:STDOUT: call void @_ZN1AD2Ev(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8) %this1) #7 +// CHECK:STDOUT: call void @_ZN1AD2Ev(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8) %this1) #8 // CHECK:STDOUT: ret void // CHECK:STDOUT: } // CHECK:STDOUT: @@ -157,9 +150,9 @@ void delete_new_Base() { // CHECK:STDOUT: define dso_local void @_Z15delete_new_Basev() #0 { // CHECK:STDOUT: entry: // CHECK:STDOUT: %p = alloca ptr, align 8 -// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %p) #7 -// CHECK:STDOUT: %call = call noalias noundef nonnull ptr @_Znwm(i64 noundef 8) #8 -// CHECK:STDOUT: call void @_ZN6Carbon4BaseC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %call) #7 +// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %p) #8 +// CHECK:STDOUT: %call = call noalias noundef nonnull ptr @_Znwm(i64 noundef 8) #10 +// CHECK:STDOUT: call void @_ZN6Carbon4BaseC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %call) #8 // CHECK:STDOUT: store ptr %call, ptr %p, align 8, !tbaa !16 // CHECK:STDOUT: %0 = load ptr, ptr %p, align 8, !tbaa !16 // CHECK:STDOUT: %isnull = icmp eq ptr %0, null @@ -169,11 +162,11 @@ void delete_new_Base() { // CHECK:STDOUT: %vtable = load ptr, ptr %0, align 8, !tbaa !14 // CHECK:STDOUT: %vfn = getelementptr inbounds ptr, ptr %vtable, i64 1 // CHECK:STDOUT: %1 = load ptr, ptr %vfn, align 8 -// CHECK:STDOUT: call void %1(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8) %0) #7 +// CHECK:STDOUT: call void %1(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8) %0) #8 // CHECK:STDOUT: br label %delete.end // CHECK:STDOUT: // CHECK:STDOUT: delete.end: ; preds = %delete.notnull, %entry -// CHECK:STDOUT: call void @llvm.lifetime.end.p0(ptr %p) #7 +// CHECK:STDOUT: call void @llvm.lifetime.end.p0(ptr %p) #8 // CHECK:STDOUT: ret void // CHECK:STDOUT: } // CHECK:STDOUT: @@ -183,53 +176,70 @@ void delete_new_Base() { // CHECK:STDOUT: %this.addr = alloca ptr, align 8 // CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8, !tbaa !16 // CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8 -// CHECK:STDOUT: call void @_ZN1AC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %this1) #7 -// CHECK:STDOUT: store ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTVN6Carbon4BaseE, i32 0, i32 0, i32 2), ptr %this1, align 8, !tbaa !14 +// CHECK:STDOUT: call void @_ZN1AC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %this1) #8 +// CHECK:STDOUT: store ptr getelementptr inbounds inrange(-16, 24) ({ [5 x ptr] }, ptr @_ZTVN6Carbon4BaseE, i32 0, i32 0, i32 2), ptr %this1, align 8, !tbaa !14 // CHECK:STDOUT: ret void // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: ; Function Attrs: alwaysinline nounwind -// CHECK:STDOUT: define void @"_C__destroy_thunk:thunk.Final.Main"(ptr %self) #5 !dbg !18 { +// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress nounwind uwtable +// CHECK:STDOUT: define internal void @_ZNK1A1FEv.carbon_thunk._(ptr noundef nonnull align 8 dereferenceable(8) %this) #5 { // CHECK:STDOUT: entry: -// CHECK:STDOUT: call void @"_COp.4472d163614a5082:core.Destroy.Core"(ptr %self), !dbg !24 -// CHECK:STDOUT: ret void, !dbg !24 +// CHECK:STDOUT: %this.addr = alloca ptr, align 8 +// CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8, !tbaa !18 +// CHECK:STDOUT: %0 = load ptr, ptr %this.addr, align 8, !tbaa !18, !nonnull !20, !align !21 +// CHECK:STDOUT: %vtable = load ptr, ptr %0, align 8, !tbaa !14 +// CHECK:STDOUT: %vfn = getelementptr inbounds ptr, ptr %vtable, i64 2 +// CHECK:STDOUT: %1 = load ptr, ptr %vfn, align 8 +// CHECK:STDOUT: call void %1(ptr noundef nonnull align 8 dereferenceable(8) %0) +// CHECK:STDOUT: ret void // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: ; Function Attrs: nounwind -// CHECK:STDOUT: declare void @_ZN1AD1Ev(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8)) unnamed_addr #6 +// CHECK:STDOUT: declare void @_CF.Final.Main(ptr) // CHECK:STDOUT: -// CHECK:STDOUT: ; Function Attrs: nounwind -// CHECK:STDOUT: define weak_odr void @"_COp.446491dd079aaad2:core.Destroy.Core"(ptr %self) #7 !dbg !25 { +// CHECK:STDOUT: declare void @_CF.Base.Main(ptr) +// CHECK:STDOUT: +// CHECK:STDOUT: ; Function Attrs: alwaysinline nounwind +// CHECK:STDOUT: define void @"_C__destroy_thunk:thunk.Final.Main"(ptr %self) #6 !dbg !22 { // CHECK:STDOUT: entry: +// CHECK:STDOUT: call void @"_COp.4472d163614a5082:core.Destroy.Core"(ptr %self), !dbg !28 // CHECK:STDOUT: ret void, !dbg !28 // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: ; Function Attrs: nounwind -// CHECK:STDOUT: define weak_odr void @"_COp.4472d163614a5082:core.Destroy.Core"(ptr %self) #7 !dbg !29 { +// 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.446491dd079aaad2:core.Destroy.Core"(ptr %self) #8 !dbg !29 { // CHECK:STDOUT: entry: // CHECK:STDOUT: ret void, !dbg !32 // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: ; Function Attrs: alwaysinline nounwind -// CHECK:STDOUT: define void @"_C__destroy_thunk:thunk.Base.Main"(ptr %self) #5 !dbg !33 { +// CHECK:STDOUT: ; Function Attrs: nounwind +// CHECK:STDOUT: define weak_odr void @"_COp.4472d163614a5082:core.Destroy.Core"(ptr %self) #8 !dbg !33 { // CHECK:STDOUT: entry: -// CHECK:STDOUT: call void @"_COp.96a711151205ee34:core.Destroy.Core"(ptr %self), !dbg !36 // CHECK:STDOUT: ret void, !dbg !36 // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: ; Function Attrs: nounwind -// CHECK:STDOUT: define weak_odr void @"_COp.96a711151205ee34:core.Destroy.Core"(ptr %self) #7 !dbg !37 { +// CHECK:STDOUT: ; Function Attrs: alwaysinline nounwind +// CHECK:STDOUT: define void @"_C__destroy_thunk:thunk.Base.Main"(ptr %self) #6 !dbg !37 { // CHECK:STDOUT: entry: +// CHECK:STDOUT: call void @"_COp.96a711151205ee34:core.Destroy.Core"(ptr %self), !dbg !40 // CHECK:STDOUT: ret void, !dbg !40 // CHECK:STDOUT: } // CHECK:STDOUT: +// CHECK:STDOUT: ; Function Attrs: nounwind +// CHECK:STDOUT: define weak_odr void @"_COp.96a711151205ee34:core.Destroy.Core"(ptr %self) #8 !dbg !41 { +// CHECK:STDOUT: entry: +// CHECK:STDOUT: ret void, !dbg !44 +// CHECK:STDOUT: } +// CHECK:STDOUT: // CHECK:STDOUT: ; Function Attrs: inlinehint mustprogress nounwind uwtable // CHECK:STDOUT: define linkonce_odr dso_local void @_ZN1AC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %this) unnamed_addr #3 comdat align 2 { // CHECK:STDOUT: entry: // CHECK:STDOUT: %this.addr = alloca ptr, align 8 -// CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8, !tbaa !41 +// CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8, !tbaa !18 // CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8 -// CHECK:STDOUT: store ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTV1A, i32 0, i32 0, i32 2), ptr %this1, align 8, !tbaa !14 +// CHECK:STDOUT: store ptr getelementptr inbounds inrange(-16, 24) ({ [5 x ptr] }, ptr @_ZTV1A, i32 0, i32 0, i32 2), ptr %this1, align 8, !tbaa !14 // CHECK:STDOUT: ret void // CHECK:STDOUT: } // CHECK:STDOUT: @@ -239,15 +249,17 @@ void delete_new_Base() { // CHECK:STDOUT: %this.addr = alloca ptr, align 8 // CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8, !tbaa !11 // CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8 -// CHECK:STDOUT: call void @_ZN6Carbon5FinalD2Ev(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8) %this1) #7 -// CHECK:STDOUT: call void @_ZdlPvm(ptr noundef %this1, i64 noundef 8) #9 +// CHECK:STDOUT: call void @_ZN6Carbon5FinalD2Ev(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8) %this1) #8 +// CHECK:STDOUT: call void @_ZdlPvm(ptr noundef %this1, i64 noundef 8) #11 // CHECK:STDOUT: ret void // CHECK:STDOUT: } // CHECK:STDOUT: +// CHECK:STDOUT: declare void @_ZNK1A1FEv(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #9 +// CHECK:STDOUT: // CHECK:STDOUT: declare void @__cxa_pure_virtual() unnamed_addr // CHECK:STDOUT: // CHECK:STDOUT: ; Function Attrs: nounwind -// CHECK:STDOUT: declare void @_ZN1AD2Ev(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8)) unnamed_addr #6 +// CHECK:STDOUT: declare void @_ZN1AD2Ev(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8)) unnamed_addr #7 // CHECK:STDOUT: // CHECK:STDOUT: ; Function Attrs: inlinehint mustprogress nounwind uwtable // CHECK:STDOUT: define linkonce_odr dso_local void @_ZN6Carbon4BaseD2Ev(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8) %this) unnamed_addr #3 comdat align 2 { @@ -255,9 +267,9 @@ void delete_new_Base() { // CHECK:STDOUT: %this.addr = alloca ptr, align 8 // CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8, !tbaa !16 // CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8 -// CHECK:STDOUT: store ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTVN6Carbon4BaseE, i32 0, i32 0, i32 2), ptr %this1, align 8, !tbaa !14 +// CHECK:STDOUT: store ptr getelementptr inbounds inrange(-16, 24) ({ [5 x ptr] }, ptr @_ZTVN6Carbon4BaseE, i32 0, i32 0, i32 2), ptr %this1, align 8, !tbaa !14 // CHECK:STDOUT: call void @"_C__destroy_thunk:thunk.Base.Main"(ptr noundef nonnull align 8 dereferenceable(8) %this1) -// CHECK:STDOUT: call void @_ZN1AD2Ev(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8) %this1) #7 +// CHECK:STDOUT: call void @_ZN1AD2Ev(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8) %this1) #8 // CHECK:STDOUT: ret void // CHECK:STDOUT: } // CHECK:STDOUT: @@ -267,14 +279,15 @@ void delete_new_Base() { // CHECK:STDOUT: %this.addr = alloca ptr, align 8 // CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8, !tbaa !16 // CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8 -// CHECK:STDOUT: call void @_ZN6Carbon4BaseD2Ev(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8) %this1) #7 -// CHECK:STDOUT: call void @_ZdlPvm(ptr noundef %this1, i64 noundef 8) #9 +// CHECK:STDOUT: call void @_ZN6Carbon4BaseD2Ev(ptr noundef nonnull align 8 dead_on_return(8) dereferenceable(8) %this1) #8 +// CHECK:STDOUT: call void @_ZdlPvm(ptr noundef %this1, i64 noundef 8) #11 // CHECK:STDOUT: ret void // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: ; uselistorder directives // CHECK:STDOUT: uselistorder ptr @_ZN6Carbon5FinalD2Ev, { 2, 1, 0 } // CHECK:STDOUT: uselistorder ptr @_ZN1AC2Ev, { 1, 0 } +// CHECK:STDOUT: uselistorder ptr @_ZNK1A1FEv, { 2, 1, 0 } // CHECK:STDOUT: uselistorder ptr @__cxa_pure_virtual, { 1, 0 } // CHECK:STDOUT: uselistorder ptr @_ZN6Carbon4BaseD2Ev, { 1, 0 } // CHECK:STDOUT: @@ -283,11 +296,13 @@ void delete_new_Base() { // CHECK:STDOUT: attributes #2 = { nobuiltin allocsize(0) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } // CHECK:STDOUT: attributes #3 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } // CHECK:STDOUT: attributes #4 = { nobuiltin nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } -// CHECK:STDOUT: attributes #5 = { alwaysinline nounwind } -// CHECK:STDOUT: attributes #6 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } -// CHECK:STDOUT: attributes #7 = { nounwind } -// CHECK:STDOUT: attributes #8 = { builtin allocsize(0) } -// CHECK:STDOUT: attributes #9 = { builtin nounwind } +// CHECK:STDOUT: attributes #5 = { alwaysinline mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +// CHECK:STDOUT: attributes #6 = { alwaysinline nounwind } +// CHECK:STDOUT: attributes #7 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +// CHECK:STDOUT: attributes #8 = { nounwind } +// CHECK:STDOUT: attributes #9 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +// CHECK:STDOUT: attributes #10 = { builtin allocsize(0) } +// CHECK:STDOUT: attributes #11 = { builtin nounwind } // CHECK:STDOUT: // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4} // CHECK:STDOUT: !llvm.dbg.cu = !{!5} @@ -311,28 +326,30 @@ void delete_new_Base() { // CHECK:STDOUT: !15 = !{!"vtable pointer", !10, i64 0} // CHECK:STDOUT: !16 = !{!17, !17, i64 0} // CHECK:STDOUT: !17 = !{!"p1 _ZTSN6Carbon4BaseE", !13, i64 0} -// CHECK:STDOUT: !18 = distinct !DISubprogram(name: "__destroy_thunk", linkageName: "_C__destroy_thunk:thunk.Final.Main", scope: null, file: !6, line: 11, type: !19, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !22) -// CHECK:STDOUT: !19 = !DISubroutineType(types: !20) -// CHECK:STDOUT: !20 = !{null, !21} -// CHECK:STDOUT: !21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) -// CHECK:STDOUT: !22 = !{!23} -// CHECK:STDOUT: !23 = !DILocalVariable(arg: 1, scope: !18, type: !21) -// CHECK:STDOUT: !24 = !DILocation(line: 11, column: 1, scope: !18) -// CHECK:STDOUT: !25 = distinct !DISubprogram(name: "Op", linkageName: "_COp.446491dd079aaad2:core.Destroy.Core", scope: null, file: !6, line: 11, type: !19, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !26) +// CHECK:STDOUT: !18 = !{!19, !19, i64 0} +// CHECK:STDOUT: !19 = !{!"p1 _ZTS1A", !13, i64 0} +// CHECK:STDOUT: !20 = !{} +// CHECK:STDOUT: !21 = !{i64 8} +// CHECK:STDOUT: !22 = distinct !DISubprogram(name: "__destroy_thunk", linkageName: "_C__destroy_thunk:thunk.Final.Main", scope: null, file: !6, line: 12, type: !23, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !26) +// CHECK:STDOUT: !23 = !DISubroutineType(types: !24) +// CHECK:STDOUT: !24 = !{null, !25} +// CHECK:STDOUT: !25 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) // CHECK:STDOUT: !26 = !{!27} -// CHECK:STDOUT: !27 = !DILocalVariable(arg: 1, scope: !25, type: !21) -// CHECK:STDOUT: !28 = !DILocation(line: 11, column: 1, scope: !25) -// CHECK:STDOUT: !29 = distinct !DISubprogram(name: "Op", linkageName: "_COp.4472d163614a5082:core.Destroy.Core", scope: null, file: !6, line: 11, type: !19, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !30) +// 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.446491dd079aaad2: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: !21) -// CHECK:STDOUT: !32 = !DILocation(line: 11, column: 1, scope: !29) -// CHECK:STDOUT: !33 = distinct !DISubprogram(name: "__destroy_thunk", linkageName: "_C__destroy_thunk:thunk.Base.Main", scope: null, file: !6, line: 15, type: !19, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !34) +// CHECK:STDOUT: !31 = !DILocalVariable(arg: 1, scope: !29, type: !25) +// CHECK:STDOUT: !32 = !DILocation(line: 12, column: 1, scope: !29) +// CHECK:STDOUT: !33 = distinct !DISubprogram(name: "Op", linkageName: "_COp.4472d163614a5082:core.Destroy.Core", scope: null, file: !6, line: 12, type: !23, 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: 15, column: 1, scope: !33) -// CHECK:STDOUT: !37 = distinct !DISubprogram(name: "Op", linkageName: "_COp.96a711151205ee34:core.Destroy.Core", scope: null, file: !6, line: 15, type: !19, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !38) +// CHECK:STDOUT: !35 = !DILocalVariable(arg: 1, scope: !33, type: !25) +// CHECK:STDOUT: !36 = !DILocation(line: 12, column: 1, scope: !33) +// CHECK:STDOUT: !37 = distinct !DISubprogram(name: "__destroy_thunk", linkageName: "_C__destroy_thunk:thunk.Base.Main", scope: null, file: !6, line: 17, type: !23, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !38) // CHECK:STDOUT: !38 = !{!39} -// CHECK:STDOUT: !39 = !DILocalVariable(arg: 1, scope: !37, type: !21) -// CHECK:STDOUT: !40 = !DILocation(line: 15, column: 1, scope: !37) -// CHECK:STDOUT: !41 = !{!42, !42, i64 0} -// CHECK:STDOUT: !42 = !{!"p1 _ZTS1A", !13, i64 0} +// CHECK:STDOUT: !39 = !DILocalVariable(arg: 1, scope: !37, type: !25) +// CHECK:STDOUT: !40 = !DILocation(line: 17, column: 1, scope: !37) +// CHECK:STDOUT: !41 = distinct !DISubprogram(name: "Op", linkageName: "_COp.96a711151205ee34:core.Destroy.Core", scope: null, file: !6, line: 17, type: !23, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !42) +// CHECK:STDOUT: !42 = !{!43} +// CHECK:STDOUT: !43 = !DILocalVariable(arg: 1, scope: !41, type: !25) +// CHECK:STDOUT: !44 = !DILocation(line: 17, column: 1, scope: !41)