-
Notifications
You must be signed in to change notification settings - Fork 14k
[clangd] Do not collect macros when clang-tidy checks call into the preprocessor #106329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first approach I tried was to remove
CollectMainFileMacros
from the preprocessor callbacks at this point, however the currentPreprocessor
API does not make that easy to do (adding a new callback creates aPPChainedCallbacks
, and there are further internal calls made toaddPPCallbacks()
that chain other ones on top of ours). So, I opted to "neutralize" our callback rather than try to remove it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks it's unfortunate but i guess makes sense.
in theory, we can have similar issues with all the others PPCallbcks that we installed. Moreover if others were to use clang-tidy as a library, they'll run into similar pitfalls. As the flow is:
So there might be some value in injecting an extra callback between
Build AST
andPass AST to consumer
. We could properly reset our PPCallbacks to recognize leaving main file for such situations. It's unfortunate that bothFileChanged
andLexedFileChanged
are designed to operate with a contract that hints "new file/location" will be valid. It makes such a semantic possibly breaking. Leaving that idea here in case you want to follow up on that (I'd be happy to review), but I can see that it's much more involved, possibly without anything breaking (and if it does we can always ask people to turn that check off until we fix the issue).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure I understand correctly, the idea is:
PPCallbacks
, e.g.BuildASTDone()
or suchCollectMainFileMacros::BuildASTDone()
to do whatdoneParse()
in the current patch does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd first see if we can extend existing
(Lexed)FileChanged
callbacks to fit this use case without breaking any users.but if that doesn't work, yes, a new callback would be needed.