diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index 0c180918dc26..a1c4498a94dc 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -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. diff --git a/clang/test/Preprocessor/pragma_sysheader.c b/clang/test/Preprocessor/pragma_sysheader.c index cf2843bffdea..763e968f7ab0 100644 --- a/clang/test/Preprocessor/pragma_sysheader.c +++ b/clang/test/Preprocessor/pragma_sysheader.c @@ -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