-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang][bytecode] Fix CXXConstructExpr for multidim arrays #164760
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 all commits
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 |
|---|---|---|
|
|
@@ -3274,34 +3274,43 @@ bool Compiler<Emitter>::VisitCXXConstructExpr(const CXXConstructExpr *E) { | |
| } | ||
|
|
||
| if (T->isArrayType()) { | ||
| const ConstantArrayType *CAT = | ||
| Ctx.getASTContext().getAsConstantArrayType(E->getType()); | ||
| if (!CAT) | ||
| return false; | ||
|
|
||
| size_t NumElems = CAT->getZExtSize(); | ||
| const Function *Func = getFunction(E->getConstructor()); | ||
| if (!Func) | ||
| return false; | ||
|
|
||
| // FIXME(perf): We're calling the constructor once per array element here, | ||
| // in the old intepreter we had a special-case for trivial constructors. | ||
| for (size_t I = 0; I != NumElems; ++I) { | ||
| if (!this->emitConstUint64(I, E)) | ||
| return false; | ||
| if (!this->emitArrayElemPtrUint64(E)) | ||
| return false; | ||
| if (!this->emitDupPtr(E)) | ||
| return false; | ||
|
|
||
| // Constructor arguments. | ||
| for (const auto *Arg : E->arguments()) { | ||
| if (!this->visit(Arg)) | ||
| return false; | ||
| std::function<bool(QualType)> initArrayDimension; | ||
| initArrayDimension = [&](QualType T) -> bool { | ||
| if (!T->isArrayType()) { | ||
| // Constructor arguments. | ||
| for (const auto *Arg : E->arguments()) { | ||
| if (!this->visit(Arg)) | ||
|
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. Does this if statement and it's body get tested by the tests? It does not look like it but maybe I misunderstand.
Contributor
Author
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. The |
||
| return false; | ||
| } | ||
|
|
||
| return this->emitCall(Func, 0, E); | ||
| } | ||
|
|
||
| if (!this->emitCall(Func, 0, E)) | ||
| const ConstantArrayType *CAT = | ||
| Ctx.getASTContext().getAsConstantArrayType(T); | ||
| if (!CAT) | ||
| return false; | ||
| } | ||
| return true; | ||
| QualType ElemTy = CAT->getElementType(); | ||
| unsigned NumElems = CAT->getZExtSize(); | ||
| for (size_t I = 0; I != NumElems; ++I) { | ||
| if (!this->emitConstUint64(I, E)) | ||
| return false; | ||
| if (!this->emitArrayElemPtrUint64(E)) | ||
| return false; | ||
| if (!initArrayDimension(ElemTy)) | ||
| return false; | ||
| } | ||
| return this->emitPopPtr(E); | ||
| }; | ||
|
|
||
| return initArrayDimension(E->getType()); | ||
| } | ||
|
|
||
| return false; | ||
|
|
||
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.
Why not just initialize
initArrayDimensiondirectly?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 don't thinkt that works if it calls itself.
Uh oh!
There was an error while loading. Please reload this page.
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 completely missed that aspect but that is what Deducing This is for, you pass in
this auto &self.Edit: never mind, not available in C++17 except as an extension :-(