summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2015-07-01 02:29:35 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2015-07-01 02:29:35 +0000
commitdc8f320f3b4a3541df82ea1f1f6fe43bb85963a8 (patch)
tree645bfcbdf1a8b8fa75081302d58f7b6ea43df008
parentcbbee9496cc7535e78f4b864812326495c98d779 (diff)
[modules] Before checking whether the controlling macro of a header is defined,
update the identifier in case we've imported a definition of the macro (and thus the contents of the header) from a module. Also fold ExternalIdentifierLookup into ExternalPreprocessorSource; it no longer makes sense to keep these separate now that the only user of the former also needs the latter. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241137 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/IdentifierTable.h13
-rw-r--r--include/clang/Lex/ExternalPreprocessorSource.h7
-rw-r--r--include/clang/Lex/HeaderSearch.h18
-rw-r--r--include/clang/Serialization/ASTReader.h1
-rw-r--r--lib/Basic/IdentifierTable.cpp2
-rw-r--r--lib/Lex/HeaderSearch.cpp9
-rw-r--r--test/Modules/Inputs/submodule-visibility/a.h2
-rw-r--r--test/Modules/Inputs/submodule-visibility/b.h3
-rw-r--r--test/Modules/Inputs/submodule-visibility/c.h6
-rw-r--r--test/Modules/Inputs/submodule-visibility/module.modulemap1
-rw-r--r--test/Modules/Inputs/submodule-visibility/other.h1
11 files changed, 36 insertions, 27 deletions
diff --git a/include/clang/Basic/IdentifierTable.h b/include/clang/Basic/IdentifierTable.h
index bc586e41f8..33a8b747c6 100644
--- a/include/clang/Basic/IdentifierTable.h
+++ b/include/clang/Basic/IdentifierTable.h
@@ -406,19 +406,6 @@ public:
virtual IdentifierIterator *getIdentifiers();
};
-/// \brief An abstract class used to resolve numerical identifier
-/// references (meaningful only to some external source) into
-/// IdentifierInfo pointers.
-class ExternalIdentifierLookup {
-public:
- virtual ~ExternalIdentifierLookup();
-
- /// \brief Return the identifier associated with the given ID number.
- ///
- /// The ID 0 is associated with the NULL identifier.
- virtual IdentifierInfo *GetIdentifier(unsigned ID) = 0;
-};
-
/// \brief Implements an efficient mapping from strings to IdentifierInfo nodes.
///
/// This has no other purpose, but this is an extremely performance-critical
diff --git a/include/clang/Lex/ExternalPreprocessorSource.h b/include/clang/Lex/ExternalPreprocessorSource.h
index 33e7a2d84b..adf8e713e9 100644
--- a/include/clang/Lex/ExternalPreprocessorSource.h
+++ b/include/clang/Lex/ExternalPreprocessorSource.h
@@ -23,7 +23,7 @@ class Module;
/// information.
///
/// This abstract class allows an external sources (such as the \c ASTReader)
-/// to provide additional macro definitions.
+/// to provide additional preprocessing information.
class ExternalPreprocessorSource {
public:
virtual ~ExternalPreprocessorSource();
@@ -34,6 +34,11 @@ public:
/// \brief Update an out-of-date identifier.
virtual void updateOutOfDateIdentifier(IdentifierInfo &II) = 0;
+ /// \brief Return the identifier associated with the given ID number.
+ ///
+ /// The ID 0 is associated with the NULL identifier.
+ virtual IdentifierInfo *GetIdentifier(unsigned ID) = 0;
+
/// \brief Map a module ID to a module.
virtual Module *getModule(unsigned ModuleID) = 0;
};
diff --git a/include/clang/Lex/HeaderSearch.h b/include/clang/Lex/HeaderSearch.h
index da640e2325..4c13380100 100644
--- a/include/clang/Lex/HeaderSearch.h
+++ b/include/clang/Lex/HeaderSearch.h
@@ -27,7 +27,7 @@
namespace clang {
class DiagnosticsEngine;
-class ExternalIdentifierLookup;
+class ExternalPreprocessorSource;
class FileEntry;
class FileManager;
class HeaderSearchOptions;
@@ -111,8 +111,9 @@ struct HeaderFileInfo {
/// \brief Retrieve the controlling macro for this header file, if
/// any.
- const IdentifierInfo *getControllingMacro(ExternalIdentifierLookup *External);
-
+ const IdentifierInfo *
+ getControllingMacro(ExternalPreprocessorSource *External);
+
/// \brief Determine whether this is a non-default header file info, e.g.,
/// it corresponds to an actual header we've included or tried to include.
bool isNonDefault() const {
@@ -242,8 +243,9 @@ class HeaderSearch {
llvm::StringSet<llvm::BumpPtrAllocator> FrameworkNames;
/// \brief Entity used to resolve the identifier IDs of controlling
- /// macros into IdentifierInfo pointers, as needed.
- ExternalIdentifierLookup *ExternalLookup;
+ /// macros into IdentifierInfo pointers, and keep the identifire up to date,
+ /// as needed.
+ ExternalPreprocessorSource *ExternalLookup;
/// \brief Entity used to look up stored header file information.
ExternalHeaderFileInfoSource *ExternalSource;
@@ -345,11 +347,11 @@ public:
FileInfo.clear();
}
- void SetExternalLookup(ExternalIdentifierLookup *EIL) {
- ExternalLookup = EIL;
+ void SetExternalLookup(ExternalPreprocessorSource *EPS) {
+ ExternalLookup = EPS;
}
- ExternalIdentifierLookup *getExternalLookup() const {
+ ExternalPreprocessorSource *getExternalLookup() const {
return ExternalLookup;
}
diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h
index 670124082c..ef5b107a2f 100644
--- a/include/clang/Serialization/ASTReader.h
+++ b/include/clang/Serialization/ASTReader.h
@@ -304,7 +304,6 @@ class ASTReader
public ExternalHeaderFileInfoSource,
public ExternalSemaSource,
public IdentifierInfoLookup,
- public ExternalIdentifierLookup,
public ExternalSLocEntrySource
{
public:
diff --git a/lib/Basic/IdentifierTable.cpp b/lib/Basic/IdentifierTable.cpp
index 40b28222b8..36fba994f1 100644
--- a/lib/Basic/IdentifierTable.cpp
+++ b/lib/Basic/IdentifierTable.cpp
@@ -71,8 +71,6 @@ IdentifierIterator *IdentifierInfoLookup::getIdentifiers() {
return new EmptyLookupIterator();
}
-ExternalIdentifierLookup::~ExternalIdentifierLookup() {}
-
IdentifierTable::IdentifierTable(const LangOptions &LangOpts,
IdentifierInfoLookup* externalLookup)
: HashTable(8192), // Start with space for 8K identifiers.
diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp
index 67a00586a6..89120ff84d 100644
--- a/lib/Lex/HeaderSearch.cpp
+++ b/lib/Lex/HeaderSearch.cpp
@@ -14,6 +14,7 @@
#include "clang/Lex/HeaderSearch.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/IdentifierTable.h"
+#include "clang/Lex/ExternalPreprocessorSource.h"
#include "clang/Lex/HeaderMap.h"
#include "clang/Lex/HeaderSearchOptions.h"
#include "clang/Lex/LexDiagnostic.h"
@@ -33,9 +34,13 @@
using namespace clang;
const IdentifierInfo *
-HeaderFileInfo::getControllingMacro(ExternalIdentifierLookup *External) {
- if (ControllingMacro)
+HeaderFileInfo::getControllingMacro(ExternalPreprocessorSource *External) {
+ if (ControllingMacro) {
+ if (ControllingMacro->isOutOfDate())
+ External->updateOutOfDateIdentifier(
+ *const_cast<IdentifierInfo *>(ControllingMacro));
return ControllingMacro;
+ }
if (!ControllingMacroID || !External)
return nullptr;
diff --git a/test/Modules/Inputs/submodule-visibility/a.h b/test/Modules/Inputs/submodule-visibility/a.h
index 34ac6b2b2e..e4965d7221 100644
--- a/test/Modules/Inputs/submodule-visibility/a.h
+++ b/test/Modules/Inputs/submodule-visibility/a.h
@@ -5,3 +5,5 @@ int n;
#endif
#define A
+
+#include "c.h"
diff --git a/test/Modules/Inputs/submodule-visibility/b.h b/test/Modules/Inputs/submodule-visibility/b.h
index dae75bf331..67ef6529db 100644
--- a/test/Modules/Inputs/submodule-visibility/b.h
+++ b/test/Modules/Inputs/submodule-visibility/b.h
@@ -1,5 +1,8 @@
int m = n;
+#include "other.h"
+#include "c.h"
+
#if defined(A) && !defined(ALLOW_NAME_LEAKAGE)
#error A is defined
#endif
diff --git a/test/Modules/Inputs/submodule-visibility/c.h b/test/Modules/Inputs/submodule-visibility/c.h
new file mode 100644
index 0000000000..259b8c7c61
--- /dev/null
+++ b/test/Modules/Inputs/submodule-visibility/c.h
@@ -0,0 +1,6 @@
+#ifndef C_H_INCLUDED
+#define C_H_INCLUDED
+
+struct C {};
+
+#endif
diff --git a/test/Modules/Inputs/submodule-visibility/module.modulemap b/test/Modules/Inputs/submodule-visibility/module.modulemap
index 2e13344dc6..d2f0c7783f 100644
--- a/test/Modules/Inputs/submodule-visibility/module.modulemap
+++ b/test/Modules/Inputs/submodule-visibility/module.modulemap
@@ -1,4 +1,5 @@
module x { module a { header "a.h" } module b { header "b.h" } }
+module other { header "other.h" }
module cycles {
module cycle1 { header "cycle1.h" }
diff --git a/test/Modules/Inputs/submodule-visibility/other.h b/test/Modules/Inputs/submodule-visibility/other.h
new file mode 100644
index 0000000000..f40c757ca6
--- /dev/null
+++ b/test/Modules/Inputs/submodule-visibility/other.h
@@ -0,0 +1 @@
+#include "c.h"