-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFC] Minor fix to tryEmitAbstract type in EmitCXXNewAllocSize #123433
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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.
Do you have a lit test that shows where this would be wrong? Typically in cases like this we count on the AST to have given us the correct type.
Also, it isn't clear to my WHY we expect it to be size-type?
Also,
size_t
isn't guaranteed to be the same size as the pointer, so this could actually be a breaking change on those platforms. By standard, we don't actually have a type that makes that guarantee, thoughintptr_t
anduintptr_t
might be the closest.Still don't really see a situation where this is troublesome though.
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 I understand what tryEmitAbstract is doing correctly, the type here is the type to which we intend the constant to be converted when translating an expression of the form 'new T[C]'. In this case C is a literal, but we need to assign a type to it. The tryEmitAbstract code is creating a constant unsigned integer and truncating or extending it to the width of the type passed in as the second argument.
I think this rule from 5.3.4 of the C++11 standard applies:
If there is a target that clang supports for which the size of size_t is not equal to the size of ptr, that would show a change in behavior with this change. Is there such a target?
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 THINK there are some 32 bit targets with 32 bit pointers and 64 bit size_t, but I'm not positive.
That said, see here:
https://godbolt.org/z/8s1dj4cac
The AST already does the cast to the correct platform-specific size. More particularly:
See the cast to
unsigned long
, orsize_t
, which I've now confirmed is correct, as it is defined to besize_t
in the standard foroperator new[]
. THUS, the overload resolution will always get this type 'correct'. If you've found an exception to that, it should probably be fixed in the AST.I would expect the
e->getType()
to be more correct here, because it is the result of the AST being formed correctly (which, if operatornew[]
is ever extended either by standard or extension to allow user overrides of non-size_t
array sizes here,size_t
would be incorrect).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.
In the code before my change, the
e
ine->getType()
is the new expression, not the constant. I'll see if I can usee->getArraySize()->getType()
instead.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.
OH! I missed that! yes, that seems incorrect. It should be likely the type of the size expression, not the new expression.