-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Sema] add cast from IncompleteArrayType to ConstantArrayType in TryReferenceListInitialization #65918
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
Conversation
…eferenceListInitialization Fixed: #62945 c++20 supports "Permit conversions to arrays of unknown bound". This need additional cast from IncompleteArrayType to ConstantArrayType in TryReferenceListInitialization
@llvm/pr-subscribers-clang ChangesFixed: #62945
|
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.
This needs a release note.
cc @erichkeane
clang/lib/Sema/SemaInit.cpp
Outdated
// unless T is “reference to array of unknown bound of U”, in which case | ||
// the type of the prvalue is the type of x in the declaration U x[] H, | ||
// where H is the initializer list. | ||
Sequence.AddQualificationConversionStep(cv1T1, VK_XValue); |
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.
Is qualification conversion right here? I'm not sure we convert qualifiers here.
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 have changed sequence in the latest commit.
The reason to qualification conversion is that in cpp 20, spec. requires support cast from initializer list
to reference to array of unknown bound
.
for example:
void foo(int a) {
auto f = [](int(&&)[]) {};
f({a});
}
{a}
should be casted from int[1] to int[].
ast will look like:
`-CXXOperatorCallExpr 0x12b904d18 <col:3, col:8> 'void':'void' '()'
|-ImplicitCastExpr 0x12b904c58 <col:4, col:8> 'void (*)(int (&&)[]) const' <FunctionToPointerDecay>
| `-DeclRefExpr 0x12b904bd8 <col:4, col:8> 'void (int (&&)[]) const' lvalue CXXMethod 0x12b904008 'operator()' 'void (int (&&)[]) const'
|-ImplicitCastExpr 0x12b904c70 <col:3> 'const (lambda at ID/test.cpp:2:12)' lvalue <NoOp>
| `-DeclRefExpr 0x12b904b10 <col:3> '(lambda at ID/test.cpp:2:12)':'(lambda at ID/test.cpp:2:12)' lvalue Var 0x12b8ee210 'f' '(lambda at ID/test.cpp:2:12)':'(lambda at ID/test.cpp:2:12)'
`-MaterializeTemporaryExpr 0x12b904d00 <col:5, col:7> 'int[]':'int[]' xvalue
`-ImplicitCastExpr 0x12b904ce8 <col:5, col:7> 'int[]':'int[]' <NoOp>
`-InitListExpr 0x12b904c88 <col:5, col:7> 'int[1]'
`-ImplicitCastExpr 0x12b904cc8 <col:6> 'int' <LValueToRValue>
`-DeclRefExpr 0x12b904b30 <col:6> 'int' lvalue ParmVar 0x12b8edfb8 'a' 'int'
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.
@HerrCai0907 I see what you mean and what the patch accomplishes. But my confusion was, why in order to do that AddQualificationConversionStep
is called? IMO this is just to convert cv-qualifiers. The goal is to convert one array type to another, right?
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, int[1] to int[] in above example. Because spec. require in this case, type should be int[], but clang will treat initialize list as int[1], which causes crash when IR emit.
Co-authored-by: Mariya Podchishchaeva <[email protected]>
I guess this ends up producing a CK_NoOp CastExpr? That's probably okay, but can we amend the documentation for CK_NoOp to give this as an example? |
Done |
LGTM |
Local branch amd-gfx 6b554b9 Merged main:7ebf3e019488 into amd-gfx:481ed31ee2aa Remote branch main d89d3a6 [Sema] add cast from IncompleteArrayType to ConstantArrayType in TryReferenceListInitialization (llvm#65918)
Fixed: #62945
c++20 supports "Permit conversions to arrays of unknown bound". This need additional cast from IncompleteArrayType to ConstantArrayType in TryReferenceListInitialization