This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Array initialization via CXXConstructExpr
ClosedPublic

Authored by tbaeder on Oct 28 2022, 12:26 AM.

Diff Detail

Event Timeline

tbaeder created this revision.Oct 28 2022, 12:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 28 2022, 12:26 AM
tbaeder requested review of this revision.Oct 28 2022, 12:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 28 2022, 12:26 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tbaeder updated this revision to Diff 471534.Oct 28 2022, 6:47 AM
tbaeder updated this revision to Diff 471813.Oct 29 2022, 11:14 PM
aaron.ballman added inline comments.Nov 22 2022, 9:53 AM
clang/lib/AST/Interp/ByteCodeExprGen.cpp
950–951

This should go through ASTContext::getConstantArrayType(). It may also be worth a comment mentioning that VLAs can't have initializers and an unbounded array has known bounds if it has an initializer, as I suspect that's the reason you're not handling either of those here?

clang/test/AST/Interp/arrays.cpp
188–200

I'd like to see a test for when the class ends with a flexible array member (ctor shouldn't be called for that case because we don't know how many trailing objects there will be). That could show up as an unbounded member.

Also, a test case where the ctor will execute UB, to demonstrate we properly diagnose arrays of default-constructed objects.

tbaeder updated this revision to Diff 477418.Nov 23 2022, 1:47 AM
tbaeder added inline comments.
clang/lib/AST/Interp/ByteCodeExprGen.cpp
950–951

I'm not handling them because they are untested everywhere. :/

clang/test/AST/Interp/arrays.cpp
188–200

I added a test for a UB constructor, but a flexible array member shows up as a non-ConstantArrayType member, so the code runs into one or the other assertion.

This revision is now accepted and ready to land.Nov 29 2022, 10:30 AM
This revision was automatically updated to reflect the committed changes.