diff --git a/lib/ClangImporter/ClangDiagnosticConsumer.cpp b/lib/ClangImporter/ClangDiagnosticConsumer.cpp index cb3b26ee5da..540dad80223 100644 --- a/lib/ClangImporter/ClangDiagnosticConsumer.cpp +++ b/lib/ClangImporter/ClangDiagnosticConsumer.cpp @@ -23,7 +23,7 @@ using namespace swift; namespace { class ClangDiagRenderer final : public clang::DiagnosticNoteRenderer { - const std::function callback; @@ -47,7 +47,7 @@ namespace { if (StringRef(SM->getBufferName(Loc)) == ClangImporter::Implementation::bridgingHeaderBufferName) return; - callback(Loc, Level, Message); + callback(clang::FullSourceLoc(Loc, *SM), Level, Message); } void emitDiagnosticLoc(clang::SourceLocation Loc, clang::PresumedLoc PLoc, @@ -92,7 +92,7 @@ static SourceLoc findEndOfLine(SourceManager &SM, SourceLoc loc, } SourceLoc ClangDiagnosticConsumer::resolveSourceLocation( - clang::SourceManager &clangSrcMgr, + const clang::SourceManager &clangSrcMgr, clang::SourceLocation clangLoc) { SourceManager &swiftSrcMgr = ImporterImpl.SwiftContext.SourceMgr; SourceLoc loc; @@ -134,13 +134,13 @@ SourceLoc ClangDiagnosticConsumer::resolveSourceLocation( swiftSrcMgr.closeVirtualFile(endOfLine); } - using SourceManagerRef = llvm::IntrusiveRefCntPtr; + using SourceManagerRef = llvm::IntrusiveRefCntPtr; auto iter = std::lower_bound(sourceManagersWithDiagnostics.begin(), sourceManagersWithDiagnostics.end(), &clangSrcMgr, [](const SourceManagerRef &inArray, - clang::SourceManager *toInsert) { - return std::less()(inArray.get(), toInsert); + const clang::SourceManager *toInsert) { + return std::less()(inArray.get(), toInsert); }); if (iter->get() != &clangSrcMgr) sourceManagersWithDiagnostics.insert(iter, &clangSrcMgr); @@ -180,7 +180,7 @@ void ClangDiagnosticConsumer::HandleDiagnostic( DiagnosticConsumer::HandleDiagnostic(clangDiagLevel, clangDiag); // FIXME: Map over source ranges in the diagnostic. - auto emitDiag = [&](clang::SourceLocation clangNoteLoc, + auto emitDiag = [&ctx, this](clang::FullSourceLoc clangNoteLoc, clang::DiagnosticsEngine::Level clangDiagLevel, StringRef message) { decltype(diag::error_from_clang) diagKind; @@ -205,7 +205,7 @@ void ClangDiagnosticConsumer::HandleDiagnostic( SourceLoc noteLoc; if (clangNoteLoc.isValid()) - noteLoc = resolveSourceLocation(clangDiag.getSourceManager(), + noteLoc = resolveSourceLocation(clangNoteLoc.getManager(), clangNoteLoc); ctx.Diags.diagnose(noteLoc, diagKind, message); }; @@ -213,15 +213,15 @@ void ClangDiagnosticConsumer::HandleDiagnostic( llvm::SmallString<128> message; clangDiag.FormatDiagnostic(message); + clang::SourceManager *clangSrcMgr = + clangDiag.hasSourceManager() ? &clangDiag.getSourceManager() : nullptr; if (clangDiag.getLocation().isInvalid()) { // Diagnostic about the compiler arguments. - emitDiag(clangDiag.getLocation(), clangDiagLevel, message); + emitDiag(clang::FullSourceLoc(clangDiag.getLocation(), *clangSrcMgr), + clangDiagLevel, message); } else { ClangDiagRenderer renderer(ImporterImpl.getClangASTContext(), std::cref(emitDiag)); - clang::SourceManager *clangSrcMgr = - clangDiag.hasSourceManager() ? &clangDiag.getSourceManager() : nullptr; - renderer.emitDiagnostic(clangDiag.getLocation(), clangDiagLevel, message, clangDiag.getRanges(), clangDiag.getFixItHints(), clangSrcMgr); diff --git a/lib/ClangImporter/ClangDiagnosticConsumer.h b/lib/ClangImporter/ClangDiagnosticConsumer.h index e6659d6d84c..0937cbcc5cf 100644 --- a/lib/ClangImporter/ClangDiagnosticConsumer.h +++ b/lib/ClangImporter/ClangDiagnosticConsumer.h @@ -62,14 +62,14 @@ private: // // This is not using SmallPtrSet or similar because we need the // IntrusiveRefCntPtr to stay a ref-counting pointer. - SmallVector, 4> + SmallVector, 4> sourceManagersWithDiagnostics; const clang::IdentifierInfo *CurrentImport = nullptr; SourceLoc DiagLoc; const bool DumpToStderr; - SourceLoc resolveSourceLocation(clang::SourceManager &clangSrcMgr, + SourceLoc resolveSourceLocation(const clang::SourceManager &clangSrcMgr, clang::SourceLocation clangLoc); public: diff --git a/test/ClangModules/Inputs/frameworks/Another.framework/Another b/test/ClangModules/Inputs/frameworks/Another.framework/Another new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/ClangModules/Inputs/frameworks/Another.framework/Headers/Another.h b/test/ClangModules/Inputs/frameworks/Another.framework/Headers/Another.h new file mode 100644 index 00000000000..cd5d83f2fc4 --- /dev/null +++ b/test/ClangModules/Inputs/frameworks/Another.framework/Headers/Another.h @@ -0,0 +1,3 @@ +#ifdef FOO +# error Module should have been built without -DFOO +#endif diff --git a/test/ClangModules/Inputs/frameworks/Another.framework/Modules/module.modulemap b/test/ClangModules/Inputs/frameworks/Another.framework/Modules/module.modulemap new file mode 100644 index 00000000000..a16c4deacc3 --- /dev/null +++ b/test/ClangModules/Inputs/frameworks/Another.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module Another { + umbrella header "Another.h" + module * { + export * + } +} diff --git a/test/ClangModules/Inputs/frameworks/Module.framework/Headers/Buried/Treasure.h b/test/ClangModules/Inputs/frameworks/Module.framework/Headers/Buried/Treasure.h new file mode 100644 index 00000000000..6e81adcb2b6 --- /dev/null +++ b/test/ClangModules/Inputs/frameworks/Module.framework/Headers/Buried/Treasure.h @@ -0,0 +1 @@ +unsigned *Buried_Treasure; diff --git a/test/ClangModules/Inputs/frameworks/Module.framework/Headers/Module.h b/test/ClangModules/Inputs/frameworks/Module.framework/Headers/Module.h new file mode 100644 index 00000000000..a2fd4da390d --- /dev/null +++ b/test/ClangModules/Inputs/frameworks/Module.framework/Headers/Module.h @@ -0,0 +1,19 @@ + +#ifndef MODULE_H +#define MODULE_H +const char *getModuleVersion(void); + +@interface Module ++(const char *)version; // retrieve module version ++alloc; +@end + +#define MODULE_H_MACRO 1 +#__private_macro MODULE_H_MACRO + +#include +#include + +__asm("foo"); + +#endif // MODULE_H diff --git a/test/ClangModules/Inputs/frameworks/Module.framework/Headers/NotInModule.h b/test/ClangModules/Inputs/frameworks/Module.framework/Headers/NotInModule.h new file mode 100644 index 00000000000..6b15791eb2c --- /dev/null +++ b/test/ClangModules/Inputs/frameworks/Module.framework/Headers/NotInModule.h @@ -0,0 +1 @@ +int not_in_module; diff --git a/test/ClangModules/Inputs/frameworks/Module.framework/Headers/Sub.h b/test/ClangModules/Inputs/frameworks/Module.framework/Headers/Sub.h new file mode 100644 index 00000000000..dea76e76461 --- /dev/null +++ b/test/ClangModules/Inputs/frameworks/Module.framework/Headers/Sub.h @@ -0,0 +1,3 @@ +#include +int *Module_Sub; + diff --git a/test/ClangModules/Inputs/frameworks/Module.framework/Headers/Sub2.h b/test/ClangModules/Inputs/frameworks/Module.framework/Headers/Sub2.h new file mode 100644 index 00000000000..6152d2ef640 --- /dev/null +++ b/test/ClangModules/Inputs/frameworks/Module.framework/Headers/Sub2.h @@ -0,0 +1,5 @@ +#import + +int *Module_Sub2; + +#warning here is some warning about something diff --git a/test/ClangModules/Inputs/frameworks/Module.framework/Module b/test/ClangModules/Inputs/frameworks/Module.framework/Module new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/ClangModules/Inputs/frameworks/Module.framework/Modules/module.modulemap b/test/ClangModules/Inputs/frameworks/Module.framework/Modules/module.modulemap new file mode 100644 index 00000000000..837fccb9488 --- /dev/null +++ b/test/ClangModules/Inputs/frameworks/Module.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module Module { + umbrella header "Module.h" + module * { + export * + } +} diff --git a/test/ClangModules/diags_from_module.swift b/test/ClangModules/diags_from_module.swift new file mode 100644 index 00000000000..e3af0e926aa --- /dev/null +++ b/test/ClangModules/diags_from_module.swift @@ -0,0 +1,9 @@ +// RUN: rm -rf %t.mcp +// RUN: not %swift -parse %s -F %S/Inputs/frameworks -module-cache-path %t.mcp -Xcc -D -Xcc FOO 2> %t.err.txt +// RUN: FileCheck -input-file=%t.err.txt %s + +import Module + +// CHECK: Another.h:2:4: error: Module should have been built without -DFOO +// CHECK: Sub2.h:1:9: error: could not build module 'Another' +// CHECK: diags_from_module.swift:[[@LINE-4]]:8: error: could not build Objective-C module 'Module'