[cfe-commits] r131871 - in /cfe/trunk: lib/Lex/Pragma.cpp test/Preprocessor/pragma_sysheader.c

Chris Lattner sabre at nondot.org
Sun May 22 15:10:16 PDT 2011


Author: lattner
Date: Sun May 22 17:10:16 2011
New Revision: 131871

URL: http://llvm.org/viewvc/llvm-project?rev=131871&view=rev
Log:
Invoke the FileChanged callback before pushing the linemarker for a system
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.


Modified:
    cfe/trunk/lib/Lex/Pragma.cpp
    cfe/trunk/test/Preprocessor/pragma_sysheader.c

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=131871&r1=131870&r2=131871&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Sun May 22 17:10:16 2011
@@ -330,16 +330,16 @@
   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.

Modified: cfe/trunk/test/Preprocessor/pragma_sysheader.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pragma_sysheader.c?rev=131871&r1=131870&r2=131871&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/pragma_sysheader.c (original)
+++ cfe/trunk/test/Preprocessor/pragma_sysheader.c Sun May 22 17:10:16 2011
@@ -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





More information about the cfe-commits mailing list