From 0a088ead85fae11bb41d8a93ebe213db5554f087 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 28 Apr 2020 18:22:34 -0700 Subject: Improve diagnostics for missing import / #include of module. Fix a few bugs where we would fail to properly determine header to module correspondence when determining whether to suggest a #include or import, and suggest a #include more often in language modes where there is no import syntax. Generally, if the target is in a header with include guards or #pragma once, we should suggest either #including or importing that header, and not importing a module that happens to textually include it. In passing, improve the notes we attach to the corresponding diagnostics: calling an entity that we couldn't see "previous" is confusing. --- clang/lib/Lex/ModuleMap.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'clang/lib/Lex/ModuleMap.cpp') diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index 4f7d5ab..85bf93a 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -662,7 +662,20 @@ ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(const FileEntry *File) { } ArrayRef -ModuleMap::findAllModulesForHeader(const FileEntry *File) const { +ModuleMap::findAllModulesForHeader(const FileEntry *File) { + HeadersMap::iterator Known = findKnownHeader(File); + if (Known != Headers.end()) + return Known->second; + + if (findOrCreateModuleForHeaderInUmbrellaDir(File)) + return Headers.find(File)->second; + + return None; +} + +ArrayRef +ModuleMap::findResolvedModulesForHeader(const FileEntry *File) const { + // FIXME: Is this necessary? resolveHeaderDirectives(File); auto It = Headers.find(File); if (It == Headers.end()) -- cgit v1.1