-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Fix crash with invalid VLA in a type trait #138543
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4700,6 +4700,10 @@ ExprResult Sema::CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, | |
| TInfo->getType()->isVariablyModifiedType()) | ||
| TInfo = TransformToPotentiallyEvaluated(TInfo); | ||
|
|
||
| // It's possible that the transformation above failed. | ||
| if (!TInfo) | ||
| return ExprError(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... i guess we do the same problem above, but it is a shame we don't do a better job trying to just create one of these with a RecoveryExpr in the expr. |
||
|
|
||
| // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t. | ||
| return new (Context) UnaryExprOrTypeTraitExpr( | ||
| ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,3 +41,17 @@ void func(int expr) { | |
| int array[sizeof(Ty) ? sizeof(Ty{}) : sizeof(int)]; | ||
| int old_style_assert[expr ? Ty::one : Ty::Neg_one]; // We don't diagnose as a VLA until instantiation | ||
| } | ||
|
|
||
| namespace GH138444 { | ||
| struct S { // expected-note {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const S &' for 1st argument}} \ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would have liked to see a test for the union case as well since it also triggered the crash. I don't see a way to trigger it w/ the enum case yet. |
||
| expected-note {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'S &&' for 1st argument}} | ||
| S(const char *); // expected-note {{candidate constructor not viable: no known conversion from 'int' to 'const char *' for 1st argument}} | ||
| int size() const; | ||
| }; | ||
|
|
||
| void test() { | ||
| S vec1 = 2; // expected-error {{no viable conversion from 'int' to 'S'}} | ||
| // Previously, this call to sizeof would cause a crash. | ||
| sizeof(int[vec1.size()]); | ||
| } | ||
| } | ||
AaronBallman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.