From d9efb6ee52e0c1084494935c8c910aff70667064 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 15 Jun 2009 05:02:34 +0000 Subject: Fix #pragma GCC system_header by making it insert a virtual linemarker into the file at the point of the pragma. This allows clang to know that all sourcelocations after the pragma are in a system header. llvm-svn: 73376 --- clang/lib/Lex/Pragma.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'clang/lib/Lex/Pragma.cpp') diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index ce5934134f4..9776c2cfbd9 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -195,8 +195,10 @@ void Preprocessor::HandlePragmaOnce(Token &OnceTok) { void Preprocessor::HandlePragmaMark() { assert(CurPPLexer && "No current lexer?"); - if (CurLexer) CurLexer->ReadToEndOfLine(); - else CurPTHLexer->DiscardToEndOfLine(); + if (CurLexer) + CurLexer->ReadToEndOfLine(); + else + CurPTHLexer->DiscardToEndOfLine(); } @@ -254,6 +256,18 @@ void Preprocessor::HandlePragmaSystemHeader(Token &SysHeaderTok) { // Mark the file as a system header. HeaderInfo.MarkFileSystemHeader(TheLexer->getFileEntry()); + + PresumedLoc PLoc = SourceMgr.getPresumedLoc(SysHeaderTok.getLocation()); + unsigned FilenameLen = strlen(PLoc.getFilename()); + unsigned FilenameID = SourceMgr.getLineTableFilenameID(PLoc.getFilename(), + FilenameLen); + + // 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(), -- cgit v1.2.3