aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Frontend/PrintPreprocessedOutput.cpp11
-rw-r--r--test/Preprocessor/line-directive-output.c4
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp
index 30707dc0c0..0dc9281166 100644
--- a/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -95,6 +95,7 @@ private:
bool DisableLineMarkers;
bool DumpDefines;
bool UseLineDirective;
+ bool IsFirstFileEntered;
public:
PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream &os,
bool lineMarkers, bool defines)
@@ -107,6 +108,7 @@ public:
EmittedDirectiveOnThisLine = false;
FileType = SrcMgr::C_User;
Initialized = false;
+ IsFirstFileEntered = false;
// If we're in microsoft mode, use normal #line instead of line markers.
UseLineDirective = PP.getLangOpts().MicrosoftExt;
@@ -273,6 +275,15 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc,
Initialized = true;
}
+ // Do not emit an enter marker for the main file (which we expect is the first
+ // entered file). This matches gcc, and improves compatibility with some tools
+ // which track the # line markers as a way to determine when the preprocessed
+ // output is in the context of the main file.
+ if (Reason == PPCallbacks::EnterFile && !IsFirstFileEntered) {
+ IsFirstFileEntered = true;
+ return;
+ }
+
switch (Reason) {
case PPCallbacks::EnterFile:
WriteLineInfo(CurLine, " 1", 2);
diff --git a/test/Preprocessor/line-directive-output.c b/test/Preprocessor/line-directive-output.c
index 290703a50e..bd3ea949eb 100644
--- a/test/Preprocessor/line-directive-output.c
+++ b/test/Preprocessor/line-directive-output.c
@@ -2,6 +2,10 @@
// PR6101
int a;
// CHECK: # 1 "{{.*}}line-directive-output.c"
+
+// Check that we do not emit an enter marker for the main file.
+// CHECK-NOT: # 1 "{{.*}}line-directive-output.c" 1
+
// CHECK: int a;
// CHECK-NEXT: # 50 "{{.*}}line-directive-output.c"