aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-06-24 17:58:59 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-06-24 17:58:59 +0000
commit7ddf6b2d77ac4cb27f78d817d7884e6ce17afd0c (patch)
treec72d1e087603aabb37018ce688c626a6ae208499
parent544607ea288b0ff24f7be0db11fcc6007d78da17 (diff)
Allow Lexer::getLocForEndOfToken to return the location just passed the macro instantiation
if the location given points at the last token of the macro instantiation. Fixes rdar://9045701. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133804 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Lex/Lexer.cpp12
-rw-r--r--test/Parser/recovery.c5
2 files changed, 15 insertions, 2 deletions
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index 3b1149c08a..608bd9d0c5 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -679,9 +679,17 @@ SourceLocation Lexer::AdvanceToTokenCharacter(SourceLocation TokStart,
SourceLocation Lexer::getLocForEndOfToken(SourceLocation Loc, unsigned Offset,
const SourceManager &SM,
const LangOptions &Features) {
- if (Loc.isInvalid() || !Loc.isFileID())
+ if (Loc.isInvalid())
return SourceLocation();
-
+
+ if (Loc.isMacroID()) {
+ if (Offset > 0 || !SM.isAtEndOfMacroInstantiation(Loc))
+ return SourceLocation(); // Points inside the macro instantiation.
+
+ // Continue and find the location just after the macro instantiation.
+ Loc = SM.getInstantiationRange(Loc).second;
+ }
+
unsigned Len = Lexer::MeasureTokenLength(Loc, SM, Features);
if (Len > Offset)
Len = Len - Offset;
diff --git a/test/Parser/recovery.c b/test/Parser/recovery.c
index 1b33f0225b..831687dcfc 100644
--- a/test/Parser/recovery.c
+++ b/test/Parser/recovery.c
@@ -74,6 +74,11 @@ void foo() {
X = 4 // expected-error{{expected ';' after expression}}
}
+// rdar://9045701
+void test9045701(int x) {
+#define VALUE 0
+ x = VALUE // expected-error{{expected ';' after expression}}
+}
// rdar://7980651
typedef int intptr_t; // expected-note {{'intptr_t' declared here}}