findNextTokenSkippingComments is actually a endless loop,
implementing it correctly.
rangeContainsExpansionsOrDirectives were skiping every second
token, if there were no whitespaces bettwen tokens.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I'm surprised we don't have unit tests that catch this?
clang-tools-extra/clang-tidy/utils/LexerUtils.cpp | ||
---|---|---|
84–85 | I'm not sure this logic is correct - if (CurrentToken is there to ensure that CurrentToken is not a nullopt before dereferencing via CurrentToken->is. It should be: if (CurrentToken && !CurrentToken->is(tok::comment)) return CurrentToken; | |
99 | This is a bit unintuitive if we compare it with e.g. STL iterators - end() is always "one-past" the end. What's the convention for SourceRange, does end contain a valid end range, or one-past-the-end? |
We don't have unit tests for most of code... It's usually tested indirectly by checks... But this code is used I think only in 1-2 checks.
It's usually tested indirectly by checks... But this code is used I think only in 1-2 checks.
I see. I'm still trying to understand why we haven't seen this before. If the function is an endless loop, shouldn't the checks that use this function end up in an endless loop too? Would be interesting to try and reproduce an endless loop in the tests of one of the checks that use this. Anyway the patch is fine as is, thanks for fixing!
clang-tools-extra/clang-tidy/utils/LexerUtils.cpp | ||
---|---|---|
84–85 | You are right, nevermind! |
I'm not sure this logic is correct - if (CurrentToken is there to ensure that CurrentToken is not a nullopt before dereferencing via CurrentToken->is. It should be: