[PATCH] D77507: [clangd] Fix HitMapping assertion in Tokens.cpp
Vince Bridgers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 5 13:53:49 PDT 2020
vabridgers updated this revision to Diff 255193.
vabridgers added a comment.
Remove extraneous test case
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77507/new/
https://reviews.llvm.org/D77507
Files:
clang/lib/Tooling/Syntax/Tokens.cpp
clang/unittests/Tooling/Syntax/TokensTest.cpp
Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===================================================================
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -484,6 +484,42 @@
['EMPTY'_9, 'EMPTY_FUNC'_10) => ['<eof>'_0, '<eof>'_0)
['EMPTY_FUNC'_10, '<eof>'_18) => ['<eof>'_0, '<eof>'_0)
)"},
+ // Baseline case, bugz: https://bugs.llvm.org/show_bug.cgi?id=45428
+ {R"cpp(
+ #define NUM 42
+ #define M2(a1,...) {__VA_ARGS__;}
+ #define M1(a2,...) M2(a2,__VA_ARGS__)
+ void foo(void) { M1(0, NUM); }
+ )cpp",
+ R"(expanded tokens:
+ void foo ( void ) { { 42 ; } ; }
+file './input.cpp'
+ spelled tokens:
+ # define NUM 42 # define M2 ( a1 , ... ) { __VA_ARGS__ ; } # define M1 ( a2 , ... ) M2 ( a2 , __VA_ARGS__ ) void foo ( void ) { M1 ( 0 , NUM ) ; }
+ mappings:
+ ['#'_0, 'void'_30) => ['void'_0, 'void'_0)
+ ['M1'_36, ';'_42) => ['{'_6, ';'_10)
+)"},
+ // Reproducer, bugz: https://bugs.llvm.org/show_bug.cgi?id=45428.
+ // Causes mapping miss when invoking tryConsumeSpelledUntil
+ {R"cpp(
+ #define NUM 42
+ #define M2(a1,...) {__VA_ARGS__;}
+ #define M1(a2,...) M2(a2,__VA_ARGS__)
+ #define M0 M1
+ void foo(void) { M0(0, NUM); }
+ )cpp",
+ R"(expanded tokens:
+ void foo ( void ) { { 42 ; } ; }
+file './input.cpp'
+ spelled tokens:
+ # define NUM 42 # define M2 ( a1 , ... ) { __VA_ARGS__ ; } # define M1 ( a2 , ... ) M2 ( a2 , __VA_ARGS__ ) # define M0 M1 void foo ( void ) { M0 ( 0 , NUM ) ; }
+ mappings:
+ ['#'_0, 'void'_34) => ['void'_0, 'void'_0)
+ ['M0'_40, 'NUM'_44) => ['{'_6, ';'_10)
+ ['NUM'_44, ')'_45) => [';'_10, ';'_10)
+ [')'_45, ';'_46) => [';'_10, ';'_10)
+)"},
// File ends with a macro replacement.
{R"cpp(
#define FOO 10+10;
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===================================================================
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -614,10 +614,7 @@
unsigned MappingBegin = SpelledIndex;
++SpelledIndex;
- bool HitMapping =
- tryConsumeSpelledUntil(File, EndOffset + 1, SpelledIndex).hasValue();
- (void)HitMapping;
- assert(!HitMapping && "recursive macro expansion?");
+ (void)tryConsumeSpelledUntil(File, EndOffset + 1, SpelledIndex).hasValue();
TokenBuffer::Mapping M;
M.BeginExpanded = BeginExpanded;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77507.255193.patch
Type: text/x-patch
Size: 2461 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200405/2ccd7092/attachment-0001.bin>
More information about the cfe-commits
mailing list