summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2015-04-23 22:58:06 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2015-04-23 22:58:06 +0000
commit2a553089c30fc3cda435ffef90bc3d2976d531d1 (patch)
tree36aaf69b6d024f83b070c4fe887bf75baecc5cb8 /clang/lib/Lex
parent10ed96bf094170f12a49ea5e6be2c43ac8640a18 (diff)
downloadbcm5719-llvm-2a553089c30fc3cda435ffef90bc3d2976d531d1.tar.gz
bcm5719-llvm-2a553089c30fc3cda435ffef90bc3d2976d531d1.zip
[modules] Properly attribute macros to modules if they're in a file textually included into a file in the module.
llvm-svn: 235661
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r--clang/lib/Lex/PPDirectives.cpp11
-rw-r--r--clang/lib/Lex/PPLexerChange.cpp2
-rw-r--r--clang/lib/Lex/PPMacroExpansion.cpp4
3 files changed, 11 insertions, 6 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 4f3efa526c4..9084915dcd9 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -577,16 +577,16 @@ void Preprocessor::PTHSkipExcludedConditionalBlock() {
}
}
-Module *Preprocessor::getModuleForLocation(SourceLocation FilenameLoc) {
+Module *Preprocessor::getModuleForLocation(SourceLocation Loc) {
ModuleMap &ModMap = HeaderInfo.getModuleMap();
- if (SourceMgr.isInMainFile(FilenameLoc)) {
+ if (SourceMgr.isInMainFile(Loc)) {
if (Module *CurMod = getCurrentModule())
return CurMod; // Compiling a module.
return HeaderInfo.getModuleMap().SourceModule; // Compiling a source.
}
// Try to determine the module of the include directive.
// FIXME: Look into directly passing the FileEntry from LookupFile instead.
- FileID IDOfIncl = SourceMgr.getFileID(SourceMgr.getExpansionLoc(FilenameLoc));
+ FileID IDOfIncl = SourceMgr.getFileID(SourceMgr.getExpansionLoc(Loc));
if (const FileEntry *EntryOfIncl = SourceMgr.getFileEntryForID(IDOfIncl)) {
// The include comes from a file.
return ModMap.findModuleForHeader(EntryOfIncl).getModule();
@@ -597,6 +597,11 @@ Module *Preprocessor::getModuleForLocation(SourceLocation FilenameLoc) {
}
}
+Module *Preprocessor::getModuleContainingLocation(SourceLocation Loc) {
+ return HeaderInfo.getModuleMap().inferModuleFromLocation(
+ FullSourceLoc(Loc, SourceMgr));
+}
+
const FileEntry *Preprocessor::LookupFile(
SourceLocation FilenameLoc,
StringRef Filename,
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index 33f5ff07f03..8a74a95ab3a 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -633,7 +633,7 @@ void Preprocessor::LeaveSubmodule() {
for (auto *MD = Macro.second.getLatest(); MD != State.getLatest();
MD = MD->getPrevious()) {
// Skip macros defined in other submodules we #included along the way.
- Module *Mod = getModuleForLocation(MD->getLocation());
+ Module *Mod = getModuleContainingLocation(MD->getLocation());
if (Mod != Info.M)
continue;
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp
index 54f72f64628..174718f4385 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -60,12 +60,12 @@ void Preprocessor::appendMacroDirective(IdentifierInfo *II, MacroDirective *MD){
// Accumulate any overridden imported macros.
if (!MD->isImported() && getCurrentModule()) {
- Module *OwningMod = getModuleForLocation(MD->getLocation());
+ Module *OwningMod = getModuleContainingLocation(MD->getLocation());
if (!OwningMod)
return;
for (auto *PrevMD = OldMD; PrevMD; PrevMD = PrevMD->getPrevious()) {
- Module *DirectiveMod = getModuleForLocation(PrevMD->getLocation());
+ Module *DirectiveMod = getModuleContainingLocation(PrevMD->getLocation());
if (ModuleMacro *PrevMM = PrevMD->getOwningModuleMacro())
StoredMD.addOverriddenMacro(*this, PrevMM);
else if (ModuleMacro *PrevMM = getModuleMacro(DirectiveMod, II))
OpenPOWER on IntegriCloud