Be more robust, we shuold not crash when we cannot find the corresponding token from the
tokenbuffer.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
could you give some more details about the crash, so that we actually now where to fix it? e.g. is it token buffers missing the spelled token at that offset somehow ? or is it AST reporting a weird source locations for user-defined literals and we need to do some sort of post processing (or maybe it should've been filtered all together). as doing it like this will imply us completely eating such diagnostics.
sorry, for not giving more details. See the other comment.
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp | ||
---|---|---|
421 | here is the UserDefinedLiteral AST node: `-UserDefinedLiteral 0x5556682e4500 <line:46:3> 'int' |-ImplicitCastExpr 0x5556682e44e8 <col:4> 'int (*)(unsigned long long)' <FunctionToPointerDecay> | `-DeclRefExpr 0x5556682e44a0 <col:4> 'int (unsigned long long)' lvalue Function 0x5556682e4290 'operator""s' 'int (unsigned long long)' `-IntegerLiteral 0x5556682e4480 <col:3> 'unsigned long long' 1 The source location of the UserDefinedLiteral points to ^1s, while the source location of the inner DeclRefExpr points to 1^s (1 offset shift). In the token buffer, we only have a single spelled token 1s, thus AST.getTokens().spelledTokenAt can not find any token that starts at 1^s source loc. | |
429 | T |
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp | ||
---|---|---|
421 | thanks, that makes sense! then instead of "suppressing" these, can we use spelledTokensTouching().front() (and asserting that it isn't empty?) |
use syntax::spelledTokensTouching.
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp | ||
---|---|---|
421 | Thanks, this is a good idea. But we have to use the back(), for the case ns::^abc (we want to point to abc, not the ::). |
here is the UserDefinedLiteral AST node:
The source location of the UserDefinedLiteral points to ^1s, while the source location of the inner DeclRefExpr points to 1^s (1 offset shift). In the token buffer, we only have a single spelled token 1s, thus AST.getTokens().spelledTokenAt can not find any token that starts at 1^s source loc.