From b283298f03d2b512204d14ca687f9de263eeff0f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 15 Nov 2007 19:07:47 +0000 Subject: [PATCH] fix a bug Steve noticed, where a #import of the main file itself would fail. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44178 91177308-0d34-0410-b5e6-96231b3b80d8 --- Lex/Preprocessor.cpp | 7 ++++++- test/Preprocessor/import_self.c | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/Preprocessor/import_self.c diff --git a/Lex/Preprocessor.cpp b/Lex/Preprocessor.cpp index 718b47693a..0970590afe 100644 --- a/Lex/Preprocessor.cpp +++ b/Lex/Preprocessor.cpp @@ -416,7 +416,12 @@ void Preprocessor::EnterMainSourceFile(unsigned MainFileID) { // Enter the main file source buffer. EnterSourceFile(MainFileID, 0); - + // Tell the header info that the main file was entered. If the file is later + // #imported, it won't be re-entered. + if (const FileEntry *FE = + SourceMgr.getFileEntryForLoc(SourceLocation::getFileLoc(MainFileID, 0))) + HeaderInfo.IncrementIncludeCount(FE); + std::vector PrologFile; PrologFile.reserve(4080); diff --git a/test/Preprocessor/import_self.c b/test/Preprocessor/import_self.c new file mode 100644 index 0000000000..e8f6fa793d --- /dev/null +++ b/test/Preprocessor/import_self.c @@ -0,0 +1,7 @@ +// RUN: clang -E -I. %s | grep BODY_OF_FILE | wc -l | grep 1 + +// This #import should have no effect, as we're importing the current file. +#import + +BODY_OF_FILE + -- 2.50.1