r235661 - [modules] Properly attribute macros to modules if they're in a file textually included into a file in the module.
Richard Smith
richard-llvm at metafoo.co.uk
Thu Apr 23 15:58:09 PDT 2015
Author: rsmith
Date: Thu Apr 23 17:58:06 2015
New Revision: 235661
URL: http://llvm.org/viewvc/llvm-project?rev=235661&view=rev
Log:
[modules] Properly attribute macros to modules if they're in a file textually included into a file in the module.
Added:
cfe/trunk/test/Modules/Inputs/macros-indirect.h
Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/PPLexerChange.cpp
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/test/Modules/Inputs/macros.h
cfe/trunk/test/Modules/macros.c
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=235661&r1=235660&r2=235661&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Thu Apr 23 17:58:06 2015
@@ -1669,9 +1669,14 @@ private:
void HandleMicrosoftImportDirective(Token &Tok);
// Module inclusion testing.
- /// \brief Find the module for the source or header file that \p FilenameLoc
- /// points to.
- Module *getModuleForLocation(SourceLocation FilenameLoc);
+ /// \brief Find the module that owns the source or header file that
+ /// \p Loc points to. If the location is in a file that was included
+ /// into a module, or is outside any module, returns nullptr.
+ Module *getModuleForLocation(SourceLocation Loc);
+
+ /// \brief Find the module that contains the specified location, either
+ /// directly or indirectly.
+ Module *getModuleContainingLocation(SourceLocation Loc);
// Macro handling.
void HandleDefineDirective(Token &Tok, bool ImmediatelyAfterTopLevelIfndef);
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=235661&r1=235660&r2=235661&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Thu Apr 23 17:58:06 2015
@@ -577,16 +577,16 @@ void Preprocessor::PTHSkipExcludedCondit
}
}
-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::getModuleForLocati
}
}
+Module *Preprocessor::getModuleContainingLocation(SourceLocation Loc) {
+ return HeaderInfo.getModuleMap().inferModuleFromLocation(
+ FullSourceLoc(Loc, SourceMgr));
+}
+
const FileEntry *Preprocessor::LookupFile(
SourceLocation FilenameLoc,
StringRef Filename,
Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=235661&r1=235660&r2=235661&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Thu Apr 23 17:58:06 2015
@@ -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;
Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=235661&r1=235660&r2=235661&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Thu Apr 23 17:58:06 2015
@@ -60,12 +60,12 @@ void Preprocessor::appendMacroDirective(
// 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))
Added: cfe/trunk/test/Modules/Inputs/macros-indirect.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/macros-indirect.h?rev=235661&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/macros-indirect.h (added)
+++ cfe/trunk/test/Modules/Inputs/macros-indirect.h Thu Apr 23 17:58:06 2015
@@ -0,0 +1 @@
+#define INDIRECTLY_IN_MACROS 1
Modified: cfe/trunk/test/Modules/Inputs/macros.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/macros.h?rev=235661&r1=235660&r2=235661&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/macros.h (original)
+++ cfe/trunk/test/Modules/Inputs/macros.h Thu Apr 23 17:58:06 2015
@@ -17,3 +17,4 @@ int (INTEGER);
extern int __MODULE__;
#endif
+#include "macros-indirect.h"
Modified: cfe/trunk/test/Modules/macros.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macros.c?rev=235661&r1=235660&r2=235661&view=diff
==============================================================================
--- cfe/trunk/test/Modules/macros.c (original)
+++ cfe/trunk/test/Modules/macros.c Thu Apr 23 17:58:06 2015
@@ -28,6 +28,10 @@
# error MODULE macro should not be visible
#endif
+#ifndef INDIRECTLY_IN_MACROS
+# error INDIRECTLY_IN_MACROS should be visible
+#endif
+
// CHECK-PREPROCESSED: double d
double d;
DOUBLE *dp = &d;
More information about the cfe-commits
mailing list