]> granicus.if.org Git - clang/commitdiff
[preprocessor] When "merging" macro argument tokens into one SLocEntry chunk,
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 19 Dec 2012 23:55:44 +0000 (23:55 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 19 Dec 2012 23:55:44 +0000 (23:55 +0000)
make sure they came from the same kind of FileIDs.

Thanks to Abramo Bagnara for providing the test case.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170616 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/TokenLexer.cpp
test/Preprocessor/macro_arg_slocentry_merge.c [new file with mode: 0644]
test/Preprocessor/macro_arg_slocentry_merge.h [new file with mode: 0644]

index 8c6f6204eb838e9826a9d3377dd5979259d528ae..5b41fe9b8d3f2a77def2edb5993cb0b4bef95dcd 100644 (file)
@@ -749,14 +749,18 @@ static void updateConsecutiveMacroArgTokens(SourceManager &SM,
 
   Token *NextTok = begin_tokens + 1;
   for (; NextTok < end_tokens; ++NextTok) {
+    SourceLocation NextLoc = NextTok->getLocation();
+    if (CurLoc.isFileID() != NextLoc.isFileID())
+      break; // Token from different kind of FileID.
+
     int RelOffs;
-    if (!SM.isInSameSLocAddrSpace(CurLoc, NextTok->getLocation(), &RelOffs))
+    if (!SM.isInSameSLocAddrSpace(CurLoc, NextLoc, &RelOffs))
       break; // Token from different local/loaded location.
     // Check that token is not before the previous token or more than 50
     // "characters" away.
     if (RelOffs < 0 || RelOffs > 50)
       break;
-    CurLoc = NextTok->getLocation();
+    CurLoc = NextLoc;
   }
 
   // For the consecutive tokens, find the length of the SLocEntry to contain
diff --git a/test/Preprocessor/macro_arg_slocentry_merge.c b/test/Preprocessor/macro_arg_slocentry_merge.c
new file mode 100644 (file)
index 0000000..9ab385f
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck %s
+
+#include "macro_arg_slocentry_merge.h"
+
+// CHECK: macro_arg_slocentry_merge.h:7:19: error: unknown type name 'win'
+// CHECK: macro_arg_slocentry_merge.h:5:16: note: expanded from macro 'WINDOW'
+// CHECK: macro_arg_slocentry_merge.h:6:18: note: expanded from macro 'P_'
diff --git a/test/Preprocessor/macro_arg_slocentry_merge.h b/test/Preprocessor/macro_arg_slocentry_merge.h
new file mode 100644 (file)
index 0000000..62595b7
--- /dev/null
@@ -0,0 +1,7 @@
+
+
+
+
+#define WINDOW win
+#define P_(args) args
+extern void f P_((WINDOW win));