When importing a trivial destructor from C++, produce a no_op builtin. (#6531)

This avoids us trying to produce a reference to the C++ destructor,
which Clang won't emit because it believes it's unnecessary. This
previously led to link errors.

Fixe #6502.
This commit is contained in:
Richard Smith
2025-12-23 05:30:29 +00:00
committed by GitHub
parent 29018f38a6
commit 531d063596
8 changed files with 81 additions and 47 deletions
+13
View File
@@ -1479,6 +1479,19 @@ static auto ImportFunctionDecl(Context& context, SemIR::LocId loc_id,
// instantiation if needed.
context.clang_sema().MarkFunctionReferenced(GetCppLocation(context, loc_id),
clang_decl);
// If the function is trivial, mark it as being a builtin if possible.
if (clang_decl->isTrivial()) {
// Trivial destructors map to a "no_op" builtin.
if (isa<clang::CXXDestructorDecl>(clang_decl)) {
function_info.SetBuiltinFunction(SemIR::BuiltinFunctionKind::NoOp);
}
// TODO: Should we model a trivial default constructor as performing
// value-initialization (zero-initializing all fields) or
// default-initialization (leaving fields uniniitalized)? Either way we
// could model that effect as a builtin.
// TODO: Add a builtin to model trivial copies.
}
}
return function_info.first_owning_decl_id;