From dff070fb0f2880806ef1ae5471ace37a97dd9e6a Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 18 Apr 2009 22:29:33 +0000 Subject: [PATCH] Fix PR3917: the location of a #line directive is the location of the first _. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69485 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/PPMacroExpansion.cpp | 4 ++++ test/Preprocessor/line-directive.c | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index 7e695a542b..330e2a17aa 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -485,6 +485,10 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) { // be affected by #line. SourceLocation Loc = Tok.getLocation(); + // Advance to the location of the first _, this might not be the first byte + // of the token if it starts with an escaped newline. + Loc = AdvanceToTokenCharacter(Loc, 0); + // One wrinkle here is that GCC expands __LINE__ to location of the *end* of // a macro instantiation. This doesn't matter for object-like macros, but // can matter for a function-like macro that expands to contain __LINE__. diff --git a/test/Preprocessor/line-directive.c b/test/Preprocessor/line-directive.c index 04c69a6791..a9ed4bcf8c 100644 --- a/test/Preprocessor/line-directive.c +++ b/test/Preprocessor/line-directive.c @@ -79,3 +79,11 @@ typedef int w; // expected-error {{redefinition of typedef 'w' is invalid in C} #line 010 // expected-warning {{#line directive interprets number as decimal, not octal}} extern int array[__LINE__ == 10 ? 1:-1]; +/* PR3917 */ +#line 41 +extern char array2[\ +_\ +_LINE__ == 42 ? 1: -1]; /* line marker is location of first _ */ + + + -- 2.40.0