-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang] fix diagnostic printing of expressions ignoring LangOpts #134693
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
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
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
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.
So is this correct, to cast a pointer to
uint64_t? It looks like we do this and in about half the other place we useintptr_t, which I would be much less suspicious of.CC @AaronBallman @erichkeane
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.
intptr_t/uintptr_tI think avoids any 'round trip' errors by standard, but I thinkuint64_tis going to be the same type ANYWAY so this is probably harmless at least. I think the suggestion to useintptr_t/uintptr_tis a good one that should happen.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.
If we care that uint64_t might not round trip a pointer in theory, even though it should always in practice, then do we care uintptr_t is not guaranteed to be provided in theory, even though it should always be in practice?
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.
THAT we don't care about because : 1- it is a compile-time diagnosed missing 'thing', and 2- We know all our supported host platforms have (and presumably always will have) that type.
So it is a matter of "potentially ill-formed" vs "potential-UB".
Either way, it doesn't MATTER very much, but from a 'most correct' perspective (as frankly,
uint64_tanduintptr_tare probably the same type, and I would bet good money that none of our platforms would ever change that/never giveuintptr_tits own representation to take advantage of this UB), but just changing the cast type here is the right thing to do.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.
It's not just here though, this is the same for all other kinds, and the same for the parameter type, and the same for where we store this.
It wouldn't change much regarding potential UB if we wrote uintptr_t here, but then this would implicitly cast to uint64_t anyway.
Now if we change that to uintptr_t, then that would be bad in 32 bit platforms, as this is used to pack other things besides pointers. So presumably we want to change the parameter and structure types here to something that's at least as big as both types, which would be uintmax perhaps?
Or maybe just assert somewhere that uint64 is at least as big as uintptr?
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.
As far as correctness: we need to smuggle pointers through a
uintptr_t. Beyond that, there is no harm then again casting that immediately to theuint64_t.So the 'fixit' suggestion is:
The underlying type here is fine, and SHOULD stay
uint64_t. But thereinterpret_castof pointer-to-int itself is the problematic part. If you'd like, you can put a static-assert thatsizeof(uintptr_t)is <=sizeof(uint64_t), but I'm not horribly worried about 128 bit pointersThere 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.
But presumably, I'd have to go on and do this for all diagnostics stream operators, not just this one, otherwise it would not be helpful to the next individual, who just
like me, did the same way it was done somewhere else :)
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.
We probably SHOULD, and you can do so without review if you care to. Else, we can just make @shafik do this, since he started 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.
I am not super sympathetic here,
reinterpret_castin a code review should have both the author and the reviewer on high alert and they should carefully examine the code and if we suspect the same pattern is used elsewhere we should confirm it is used consistently. Which in this case it is not.The PR was turned over pretty quickly w/o giving any of the other long list of reviewers a chance to comment.
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.
Yes, I had carefully reviewed it and I think it was fine, given the circumstances.
For reference, here are all the other uses:
So 6 uint64_t vs 3 intptr_t (excluding this patch). Without going on and changing everything else, there is no single answer here which would be satisfy everyone.