]> granicus.if.org Git - clang/commitdiff
Invoke the FileChanged callback before pushing the linemarker for a system
authorChris Lattner <sabre@nondot.org>
Sun, 22 May 2011 22:10:16 +0000 (22:10 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 22 May 2011 22:10:16 +0000 (22:10 +0000)
header.  Getting it in the wrong order generated incorrect line markers in -E
mode.  In the testcase from PR9861 we used to generate:

# 1 "test.c" 2
# 1 "./foobar.h" 1
# 0 "./foobar.h"
# 0 "./foobar.h" 3
# 2 "test.c" 2

now we properly produce:

# 1 "test.c" 2
# 1 "./foobar.h" 1
# 1 "./foobar.h" 3
# 2 "test.c" 2

This fixes PR9861.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131871 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/Pragma.cpp
test/Preprocessor/pragma_sysheader.c

index 0c180918dc26df75e15520b7071809fa6db56764..a1c4498a94dc1c36022da596071376bc7b030d12 100644 (file)
@@ -330,16 +330,16 @@ void Preprocessor::HandlePragmaSystemHeader(Token &SysHeaderTok) {
   unsigned FilenameID = SourceMgr.getLineTableFilenameID(PLoc.getFilename(),
                                                          FilenameLen);
 
+  // Notify the client, if desired, that we are in a new source file.
+  if (Callbacks)
+    Callbacks->FileChanged(SysHeaderTok.getLocation(),
+                           PPCallbacks::SystemHeaderPragma, SrcMgr::C_System);
+
   // Emit a line marker.  This will change any source locations from this point
   // forward to realize they are in a system header.
   // Create a line note with this information.
   SourceMgr.AddLineNote(SysHeaderTok.getLocation(), PLoc.getLine(), FilenameID,
                         false, false, true, false);
-
-  // Notify the client, if desired, that we are in a new source file.
-  if (Callbacks)
-    Callbacks->FileChanged(SysHeaderTok.getLocation(),
-                           PPCallbacks::SystemHeaderPragma, SrcMgr::C_System);
 }
 
 /// HandlePragmaDependency - Handle #pragma GCC dependency "foo" blah.
index cf2843bffdea7316693ce6f46c91d71a66c2acce..763e968f7ab0d7b7b302d71cc060b8012df705ed 100644 (file)
@@ -1,3 +1,12 @@
 // RUN: %clang -verify -pedantic %s -fsyntax-only
+// RUN: %clang -E %s | FileCheck %s
 // rdar://6899937
 #include "pragma_sysheader.h"
+
+
+// PR9861: Verify that line markers are not messed up in -E mode.
+// CHECK: # 1 "{{.*}}pragma_sysheader.h" 1
+// CHECK-NEXT: # 1 "{{.*}}pragma_sysheader.h" 3
+// CHECK-NEXT: typedef int x;
+// CHECK-NEXT: typedef int x;
+// CHECK-NEXT: # 5 "{{.*}}pragma_sysheader.c" 2