Details
- Reviewers
ilya-biryukov gribozavr - Commits
- rGd94c7bf06e00: [clang-tidy] Fix a potential infinite loop in readability-isolate-declaration…
rCTE372206: [clang-tidy] Fix a potential infinite loop in readability-isolate-declaration…
rL372206: [clang-tidy] Fix a potential infinite loop in readability-isolate-declaration…
Diff Detail
- Repository
- rL LLVM
Event Timeline
Do we have unit tests for clang-tidy? If yes, could we also add unit-tests for this function?
The modified function only needs a source manager and lang options, these are easy to mock.
clang-tools-extra/clang-tidy/utils/LexerUtils.h | ||
---|---|---|
38 ↗ | (On Diff #220473) | Would findPrevious have the same problem on the first token of the file? |
66 ↗ | (On Diff #220473) | We seem to be missing a corner case here: what if folks are searching for 'tok::eof'? Currently we would return invalid location, but given the function's signature I'd expect it to return location of 'tok::eof' in that case. I bet we don't run into this in practice, though. |
The fix itself LGTM, getting rid of an infinite loop is important.
All my comment can be addressed later...
Do we have unit tests for clang-tidy? If yes, could we also add unit-tests for this function?
The modified function only needs a source manager and lang options, these are easy to mock.
Unfortunately, we don't have any unit tests for all these utility functions. The modified function is only used in the readability-isolate-declaration check.
I agree that we should add one, will file a bug.
clang-tools-extra/clang-tidy/utils/LexerUtils.h | ||
---|---|---|
38 ↗ | (On Diff #220473) | it depends on the caller. Calling this function directly would probably get into infinite loop. As this function is only used in readability-isolate-declaration check, it seems that the check adds some additional guard code before calling this function, it is probably safe, I assume. (I could not figure out a case that causes the problem). |
66 ↗ | (On Diff #220473) | yeah, I thought that we shouldn't run into this corner case, I tweaked the code to fix this case. |
clang-tools-extra/clang-tidy/utils/LexerUtils.h | ||
---|---|---|
38 ↗ | (On Diff #220473) | Fair point, but putting an assertion or fixing the function would be good too. |