r179709 - Fix off-by-one error in #pragma clang system_header.

Jordan Rose jordan_rose at apple.com
Wed Apr 17 12:09:19 PDT 2013


Author: jrose
Date: Wed Apr 17 14:09:18 2013
New Revision: 179709

URL: http://llvm.org/viewvc/llvm-project?rev=179709&view=rev
Log:
Fix off-by-one error in #pragma clang system_header.

The system_header pragma (from GCC) is implemented using line notes in the
source manager. However, a line note's line number specifies the number
not for the current line, but for the next line. This was making all
line numbers appear off by one after the pragma.

Reported by Andy Gibbs, uncovered during r179677.

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

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=179709&r1=179708&r2=179709&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Wed Apr 17 14:09:18 2013
@@ -270,11 +270,12 @@ void PrintPPOutputPPCallbacks::FileChang
     if (IncludeLoc.isValid())
       MoveToLine(IncludeLoc);
   } else if (Reason == PPCallbacks::SystemHeaderPragma) {
-    MoveToLine(NewLine);
-
-    // TODO GCC emits the # directive for this directive on the line AFTER the
-    // directive and emits a bunch of spaces that aren't needed.  Emulate this
-    // strange behavior.
+    // GCC emits the # directive for this directive on the line AFTER the
+    // directive and emits a bunch of spaces that aren't needed. This is because
+    // otherwise we will emit a line marker for THIS line, which requires an
+    // extra blank line after the directive to avoid making all following lines
+    // off by one. We can do better by simply incrementing NewLine here.
+    NewLine += 1;
   }
   
   CurLine = NewLine;

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=179709&r1=179708&r2=179709&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Wed Apr 17 14:09:18 2013
@@ -434,8 +434,9 @@ void Preprocessor::HandlePragmaSystemHea
   // 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);
+  SourceMgr.AddLineNote(SysHeaderTok.getLocation(), PLoc.getLine()+1,
+                        FilenameID, /*IsEntry=*/false, /*IsExit=*/false,
+                        /*IsSystem=*/true, /*IsExternC=*/false);
 }
 
 /// 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=179709&r1=179708&r2=179709&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/pragma_sysheader.c (original)
+++ cfe/trunk/test/Preprocessor/pragma_sysheader.c Wed Apr 17 14:09:18 2013
@@ -7,7 +7,7 @@
 
 // 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: # 2 "{{.*}}pragma_sysheader.h" 3
 // CHECK-NEXT: typedef int x;
 // CHECK-NEXT: typedef int x;
 // CHECK-NEXT: # 6 "{{.*}}pragma_sysheader.c" 2





More information about the cfe-commits mailing list