aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/PPDirectives.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-04 06:25:26 +0000
committerChris Lattner <sabre@nondot.org>2009-02-04 06:25:26 +0000
commit137b6a6149c53dbbcb8fba98e524d9ad0f3c8736 (patch)
tree32298d874d906033a58582725b995726b8cf442c /lib/Lex/PPDirectives.cpp
parentbd16209c76e122d50b23af7f65067670946953d8 (diff)
Implement handling of file entry/exit notifications from GNU
line markers, including maintenance of the virtual include stack. For something like this: # 42 "bar.c" 1 # 142 "bar2.c" 1 #warning zappa # 92 "bar.c" 2 #warning gonzo # 102 "foo.c" 2 #warning bonkta we now produce these three warnings: #1: In file included from foo.c:3: In file included from bar.c:42: bar2.c:143:2: warning: #warning zappa #warning zappa ^ #2: In file included from foo.c:3: bar.c:92:2: warning: #warning gonzo #warning gonzo ^ #3: foo.c:102:2: warning: #warning bonkta #warning bonkta ^ git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63722 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/PPDirectives.cpp')
-rw-r--r--lib/Lex/PPDirectives.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index 15487925f5..00cb62384e 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -676,6 +676,23 @@ static bool ReadLineMarkerFlags(bool &IsFileEntry, bool &IsFileExit,
} else if (FlagVal == 2) {
IsFileExit = true;
+ SourceManager &SM = PP.getSourceManager();
+ // If we are leaving the current presumed file, check to make sure the
+ // presumed include stack isn't empty!
+ FileID CurFileID =
+ SM.getDecomposedInstantiationLoc(FlagTok.getLocation()).first;
+ PresumedLoc PLoc = SM.getPresumedLoc(FlagTok.getLocation());
+
+ // If there is no include loc (main file) or if the include loc is in a
+ // different physical file, then we aren't in a "1" line marker flag region.
+ SourceLocation IncLoc = PLoc.getIncludeLoc();
+ if (IncLoc.isInvalid() ||
+ SM.getDecomposedInstantiationLoc(IncLoc).first != CurFileID) {
+ PP.Diag(FlagTok, diag::err_pp_linemarker_invalid_pop);
+ PP.DiscardUntilEndOfDirective();
+ return true;
+ }
+
PP.Lex(FlagTok);
if (FlagTok.is(tok::eom)) return false;
if (GetLineValue(FlagTok, FlagVal, diag::err_pp_linemarker_invalid_flag,PP))
@@ -761,7 +778,7 @@ void Preprocessor::HandleDigitDirective(Token &DigitTok) {
IsSystemHeader, IsExternCHeader, *this))
return;
}
-
+
// Create a line note with this information.
SourceMgr.AddLineNote(DigitTok.getLocation(), LineNo, FilenameID,
IsFileEntry, IsFileExit,