Improve diagnostics for overload resolution failure. (#6091)

Include notes listing the candidates and explaining why they didn't
work. Rather than duplicating the (substantial) logic for this, use the
Clang machinery to generate these diagnostics.

In order to support this, add a mechanism to map `SemIR::LocId`s to
`clang::SourceLocation`s. This works by creating source buffers in Clang
that refer into the Carbon source file so that `SourceLocation`s can
point into them.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
Richard SmithandJon Ross-Perkins authored and GitHub committed 2025-09-19 20:22:47 +00:00
1 parent ef488f00fa
commit 925250f8f9
21 files changed
+443 -349

No files matched your search

+7
View File
@@ -1667,6 +1667,13 @@ auto ImportCppFunctionDecl(Context& context, SemIR::LocId loc_id,
SemIR::Function& function_info = context.functions().Get(*function_id);
if (IsCppThunkRequired(context, function_info)) {
Diagnostics::AnnotationScope annotate_diagnostics(
&context.emitter(), [&](auto& builder) {
CARBON_DIAGNOSTIC(InCppThunk, Note,
"in thunk for C++ function used here");
builder.Note(loc_id, InCppThunk);
});
clang::FunctionDecl* thunk_clang_decl =
BuildCppThunk(context, function_info);
if (thunk_clang_decl) {