Repository: apple/swift
File: lib/ClangImporter/SwiftLookupTable.cpp (C++)

Code before:

void importer::finalizeLookupTable(
    SwiftLookupTable &table, NameImporter &nameImporter,
    ClangSourceBufferImporter &buffersForDiagnostics) {
  // Resolve any unresolved entries.
  SmallVector<SwiftLookupTable::SingleEntry, 4> unresolved;
  if (table.resolveUnresolvedEntries(unresolved)) {
    // Complain about unresolved entries that remain.
    for (auto entry : unresolved) {
      auto *decl = cast<clang::NamedDecl *>(entry);
      auto swiftName = decl->getAttr<clang::SwiftNameAttr>();

      if (swiftName
          // Clang didn't previously attach SwiftNameAttrs to forward
          // declarations, but this changed and we started diagnosing spurious
          // warnings on @class declarations. Suppress them.
          // FIXME: Can we avoid processing these decls in the first place?
          && !importer::isForwardDeclOfType(decl)) {
        clang::SourceLocation diagLoc = swiftName->getLocation();
        if (!diagLoc.isValid())
          diagLoc = decl->getLocation();
        SourceLoc swiftSourceLoc = buffersForDiagnostics.resolveSourceLocation(
            nameImporter.getClangContext().getSourceManager(), diagLoc);

        DiagnosticEngine &swiftDiags = nameImporter.getContext().Diags;
        bool isSystemModule = decl->getOwningModule()->IsSystem;
        if (!isSystemModule)
          swiftDiags.diagnose(swiftSourceLoc, diag::unresolvable_clang_decl,
                              decl->getNameAsString(), swiftName->getName());
        StringRef moduleName =
            nameImporter.getClangContext().getLangOpts().CurrentModule;
        if (!moduleName.empty() && !isSystemModule) {
          swiftDiags.diagnose(swiftSourceLoc,
                              diag::unresolvable_clang_decl_is_a_framework_bug,
                              moduleName);
        }
      }
    }
  }
}

void SwiftLookupTableWriter::populateTableWithDecl(SwiftLookupTable &table,
                                                   NameImporter &nameImporter,
                                                   clang::Decl *decl) {
  // Skip anything from an AST file.
  if (decl->isFromASTFile())
    return;

  // Exclude a predefined declaration that's not a definition if its
  // definition exists in the same module so that the definition will
  // be associated with the base name, noting predefined declarations

Review comment (suggestion):
Should it suffice to add this?
```
if (isSystemModule)
  continue;
```

Code after:

void importer::finalizeLookupTable(
    SwiftLookupTable &table, NameImporter &nameImporter,
    ClangSourceBufferImporter &buffersForDiagnostics) {
  // Resolve any unresolved entries.
  SmallVector<SwiftLookupTable::SingleEntry, 4> unresolved;
  if (table.resolveUnresolvedEntries(unresolved)) {
    // Complain about unresolved entries that remain.
    for (auto entry : unresolved) {
      auto *decl = cast<clang::NamedDecl *>(entry);
      auto swiftName = decl->getAttr<clang::SwiftNameAttr>();

      if (swiftName
          // Clang didn't previously attach SwiftNameAttrs to forward
          // declarations, but this changed and we started diagnosing spurious
          // warnings on @class declarations. Suppress them.
          // FIXME: Can we avoid processing these decls in the first place?
          && !importer::isForwardDeclOfType(decl)) {
        clang::SourceLocation diagLoc = swiftName->getLocation();
        if (!diagLoc.isValid())
          diagLoc = decl->getLocation();
        SourceLoc swiftSourceLoc = buffersForDiagnostics.resolveSourceLocation(
            nameImporter.getClangContext().getSourceManager(), diagLoc);

        DiagnosticEngine &swiftDiags = nameImporter.getContext().Diags;
        if (decl->getOwningModule()->IsSystem)
          continue;
        swiftDiags.diagnose(swiftSourceLoc, diag::unresolvable_clang_decl,
                            decl->getNameAsString(), swiftName->getName());
        StringRef moduleName =
            nameImporter.getClangContext().getLangOpts().CurrentModule;
        if (!moduleName.empty()) {
          swiftDiags.diagnose(swiftSourceLoc,
                              diag::unresolvable_clang_decl_is_a_framework_bug,
                              moduleName);
        }
      }
    }
  }
}

void SwiftLookupTableWriter::populateTableWithDecl(SwiftLookupTable &table,
                                                   NameImporter &nameImporter,
                                                   clang::Decl *decl) {
  // Skip anything from an AST file.
  if (decl->isFromASTFile())
    return;

  // Exclude a predefined declaration that's not a definition if its
  // definition exists in the same module so that the definition will
  // be associated with the base name, noting predefined declarations