Skip to content

Commit 446b2c3

Browse files
committed
[cxx-interop] Add source locations to diagnostics for un-importable APIs.
1 parent c6cea1e commit 446b2c3

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2375,7 +2375,7 @@ ClangModuleUnit *ClangImporter::Implementation::getClangModuleForDecl(
23752375

23762376
void ClangImporter::Implementation::addImportDiagnostic(
23772377
ImportDiagnosticTarget target, Diagnostic &&diag,
2378-
const clang::SourceLocation &loc) {
2378+
clang::SourceLocation loc) {
23792379
ImportDiagnostic importDiag = ImportDiagnostic(target, diag, loc);
23802380
if (SwiftContext.LangOpts.DisableExperimentalClangImporterDiagnostics ||
23812381
CollectedDiagnostics.count(importDiag))

lib/ClangImporter/ImportDecl.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,8 @@ namespace {
19881988
Impl.addImportDiagnostic(
19891989
decl,
19901990
Diagnostic(diag::incomplete_record, Impl.SwiftContext.AllocateCopy(
1991-
decl->getNameAsString())));
1991+
decl->getNameAsString())),
1992+
decl->getLocation());
19921993
}
19931994

19941995
// FIXME: Figure out how to deal with incomplete types, since that
@@ -2004,7 +2005,8 @@ namespace {
20042005
Impl.addImportDiagnostic(
20052006
decl, Diagnostic(
20062007
diag::record_is_dependent,
2007-
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())));
2008+
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())),
2009+
decl->getLocation());
20082010
return nullptr;
20092011
}
20102012

@@ -2013,7 +2015,8 @@ namespace {
20132015
Impl.addImportDiagnostic(
20142016
decl, Diagnostic(
20152017
diag::record_over_aligned,
2016-
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())));
2018+
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())),
2019+
decl->getLocation());
20172020
return nullptr;
20182021
}
20192022

@@ -2034,7 +2037,8 @@ namespace {
20342037
Impl.addImportDiagnostic(
20352038
decl, Diagnostic(
20362039
diag::record_non_trivial_copy_destroy,
2037-
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())));
2040+
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())),
2041+
decl->getLocation());
20382042
return nullptr;
20392043
}
20402044

@@ -2057,7 +2061,8 @@ namespace {
20572061
Impl.addImportDiagnostic(
20582062
decl, Diagnostic(
20592063
diag::record_parent_unimportable,
2060-
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())));
2064+
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())),
2065+
decl->getLocation());
20612066
return nullptr;
20622067
}
20632068

@@ -2435,7 +2440,8 @@ namespace {
24352440
Impl.addImportDiagnostic(
24362441
decl,
24372442
Diagnostic(diag::incomplete_record, Impl.SwiftContext.AllocateCopy(
2438-
decl->getNameAsString())));
2443+
decl->getNameAsString())),
2444+
decl->getLocation());
24392445
}
24402446

24412447
decl = decl->getDefinition();
@@ -2496,7 +2502,8 @@ namespace {
24962502
decl,
24972503
Diagnostic(diag::record_not_automatically_importable,
24982504
Impl.SwiftContext.AllocateCopy(decl->getNameAsString()),
2499-
"does not have a copy constructor or destructor"));
2505+
"does not have a copy constructor or destructor"),
2506+
decl->getLocation());
25002507
return nullptr;
25012508
}
25022509

@@ -2775,7 +2782,8 @@ namespace {
27752782
Diagnostic(diag::reference_passed_by_value,
27762783
Impl.SwiftContext.AllocateCopy(
27772784
recordType->getDecl()->getNameAsString()),
2778-
"a parameter"));
2785+
"a parameter"),
2786+
decl->getLocation());
27792787
return true;
27802788
}
27812789
}
@@ -2791,7 +2799,8 @@ namespace {
27912799
decl, Diagnostic(diag::reference_passed_by_value,
27922800
Impl.SwiftContext.AllocateCopy(
27932801
recordType->getDecl()->getNameAsString()),
2794-
"the return"));
2802+
"the return"),
2803+
decl->getLocation());
27952804
return recordHasReferenceSemantics(recordType->getDecl());
27962805
}
27972806

lib/ClangImporter/ImportType.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,35 +393,40 @@ namespace {
393393

394394
ImportResult VisitExtIntType(const clang::ExtIntType *type) {
395395
Impl.addImportDiagnostic(type, Diagnostic(diag::unsupported_builtin_type,
396-
type->getTypeClassName()));
396+
type->getTypeClassName()),
397+
clang::SourceLocation());
397398
// ExtInt is not supported in Swift.
398399
return Type();
399400
}
400401

401402
ImportResult VisitPipeType(const clang::PipeType *type) {
402403
Impl.addImportDiagnostic(type, Diagnostic(diag::unsupported_builtin_type,
403-
type->getTypeClassName()));
404+
type->getTypeClassName()),
405+
clang::SourceLocation());
404406
// OpenCL types are not supported in Swift.
405407
return Type();
406408
}
407409

408410
ImportResult VisitMatrixType(const clang::MatrixType *ty) {
409411
Impl.addImportDiagnostic(ty, Diagnostic(diag::unsupported_builtin_type,
410-
ty->getTypeClassName()));
412+
ty->getTypeClassName()),
413+
clang::SourceLocation());
411414
// Matrix types are not supported in Swift.
412415
return Type();
413416
}
414417

415418
ImportResult VisitComplexType(const clang::ComplexType *type) {
416419
Impl.addImportDiagnostic(type, Diagnostic(diag::unsupported_builtin_type,
417-
type->getTypeClassName()));
420+
type->getTypeClassName()),
421+
clang::SourceLocation());
418422
// FIXME: Implement once Complex is in the library.
419423
return Type();
420424
}
421425

422426
ImportResult VisitAtomicType(const clang::AtomicType *type) {
423427
Impl.addImportDiagnostic(type, Diagnostic(diag::unsupported_builtin_type,
424-
type->getTypeClassName()));
428+
type->getTypeClassName()),
429+
clang::SourceLocation());
425430
// FIXME: handle pointers and fields of atomic type
426431
return Type();
427432
}
@@ -1028,7 +1033,8 @@ namespace {
10281033
++cp) {
10291034
if (!(*cp)->hasDefinition())
10301035
Impl.addImportDiagnostic(
1031-
type, Diagnostic(diag::incomplete_protocol, *cp));
1036+
type, Diagnostic(diag::incomplete_protocol, *cp),
1037+
clang::SourceLocation());
10321038
}
10331039
}
10341040

@@ -1039,7 +1045,8 @@ namespace {
10391045
Impl.importDecl(objcClass, Impl.CurrentVersion));
10401046
if (!imported && !objcClass->hasDefinition())
10411047
Impl.addImportDiagnostic(
1042-
type, Diagnostic(diag::incomplete_interface, objcClass));
1048+
type, Diagnostic(diag::incomplete_interface, objcClass),
1049+
clang::SourceLocation());
10431050

10441051
if (!imported)
10451052
return nullptr;

lib/ClangImporter/ImporterImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
939939

940940
void addImportDiagnostic(
941941
ImportDiagnosticTarget target, Diagnostic &&diag,
942-
const clang::SourceLocation &loc = clang::SourceLocation());
942+
clang::SourceLocation loc);
943943

944944
/// Import the given Clang identifier into Swift.
945945
///
@@ -1724,7 +1724,7 @@ class ImportDiagnosticAdder {
17241724
public:
17251725
ImportDiagnosticAdder(
17261726
ClangImporter::Implementation &impl, ImportDiagnosticTarget target,
1727-
const clang::SourceLocation &loc = clang::SourceLocation())
1727+
clang::SourceLocation loc)
17281728
: impl(impl), target(target), loc(loc) {}
17291729

17301730
void operator () (Diagnostic &&diag) {

0 commit comments

Comments
 (0)