diff --git a/llvm/lib/TableGen/Main.cpp b/llvm/lib/TableGen/Main.cpp --- a/llvm/lib/TableGen/Main.cpp +++ b/llvm/lib/TableGen/Main.cpp @@ -73,7 +73,7 @@ EC.message() + "\n"); DepOut.os() << OutputFilename << ":"; for (const auto &Dep : Parser.getDependencies()) { - DepOut.os() << ' ' << Dep.first; + DepOut.os() << ' ' << Dep; } DepOut.os() << "\n"; DepOut.keep(); diff --git a/llvm/lib/TableGen/TGLexer.h b/llvm/lib/TableGen/TGLexer.h --- a/llvm/lib/TableGen/TGLexer.h +++ b/llvm/lib/TableGen/TGLexer.h @@ -19,8 +19,8 @@ #include "llvm/Support/DataTypes.h" #include "llvm/Support/SMLoc.h" #include -#include #include +#include #include namespace llvm { @@ -87,10 +87,11 @@ unsigned CurBuffer = 0; public: - typedef std::map DependenciesMapTy; + typedef std::set DependenciesSetTy; + private: /// Dependencies - This is the list of all included files. - DependenciesMapTy Dependencies; + DependenciesSetTy Dependencies; public: TGLexer(SourceMgr &SrcMgr, ArrayRef Macros); @@ -99,7 +100,7 @@ return CurCode = LexToken(CurPtr == CurBuf.begin()); } - const DependenciesMapTy &getDependencies() const { + const DependenciesSetTy &getDependencies() const { return Dependencies; } diff --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp --- a/llvm/lib/TableGen/TGLexer.cpp +++ b/llvm/lib/TableGen/TGLexer.cpp @@ -379,15 +379,7 @@ return true; } - DependenciesMapTy::const_iterator Found = Dependencies.find(IncludedFile); - if (Found != Dependencies.end()) { - PrintError(getLoc(), - "File '" + IncludedFile + "' has already been included."); - SrcMgr.PrintMessage(Found->second, SourceMgr::DK_Note, - "previously included here"); - return true; - } - Dependencies.insert(std::make_pair(IncludedFile, getLoc())); + Dependencies.insert(IncludedFile); // Save the line number and lex buffer of the includer. CurBuf = SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer(); CurPtr = CurBuf.begin(); diff --git a/llvm/lib/TableGen/TGParser.h b/llvm/lib/TableGen/TGParser.h --- a/llvm/lib/TableGen/TGParser.h +++ b/llvm/lib/TableGen/TGParser.h @@ -129,7 +129,7 @@ bool TokError(const Twine &Msg) const { return Error(Lex.getLoc(), Msg); } - const TGLexer::DependenciesMapTy &getDependencies() const { + const TGLexer::DependenciesSetTy &getDependencies() const { return Lex.getDependencies(); } diff --git a/llvm/test/TableGen/duplicate-include.inc b/llvm/test/TableGen/duplicate-include.inc new file mode 100644 --- /dev/null +++ b/llvm/test/TableGen/duplicate-include.inc @@ -0,0 +1,7 @@ +#ifndef DUPLICATE_INCLUDE +#define DUPLICATE_INCLUDE + +// This is used by the duplicate-include.td test +def InInclude; + +#endif diff --git a/llvm/test/TableGen/duplicate-include.td b/llvm/test/TableGen/duplicate-include.td new file mode 100644 --- /dev/null +++ b/llvm/test/TableGen/duplicate-include.td @@ -0,0 +1,7 @@ +// RUN: llvm-tblgen -I %p %s | FileCheck %s + +// CHECK: def InInclude + +include "duplicate-include.inc" +include "duplicate-include.inc" +