]> granicus.if.org Git - clang/commitdiff
fix a bug Steve noticed, where a #import of the main file itself would fail.
authorChris Lattner <sabre@nondot.org>
Thu, 15 Nov 2007 19:07:47 +0000 (19:07 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 15 Nov 2007 19:07:47 +0000 (19:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44178 91177308-0d34-0410-b5e6-96231b3b80d8

Lex/Preprocessor.cpp
test/Preprocessor/import_self.c [new file with mode: 0644]

index 718b47693ae71cb1161ea485699aa31c36562fa3..0970590afe9d44b65f790277b4edf6890e3dd84f 100644 (file)
@@ -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<char> PrologFile;
   PrologFile.reserve(4080);
   
diff --git a/test/Preprocessor/import_self.c b/test/Preprocessor/import_self.c
new file mode 100644 (file)
index 0000000..e8f6fa7
--- /dev/null
@@ -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 <import_self.c>
+
+BODY_OF_FILE
+