-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[CIR] Unblock simple C++ structure support #138368
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 |
|---|---|---|
|
|
@@ -365,10 +365,15 @@ mlir::Attribute ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &d) { | |
| if (!d.hasLocalStorage()) { | ||
| QualType ty = cgm.getASTContext().getBaseElementType(d.getType()); | ||
| if (ty->isRecordType()) | ||
| if (d.getInit() && isa<CXXConstructExpr>(d.getInit())) { | ||
| cgm.errorNYI(d.getInit()->getBeginLoc(), | ||
| "tryEmitPrivateForVarInit CXXConstructExpr"); | ||
| return {}; | ||
| if (const CXXConstructExpr *e = | ||
| dyn_cast_or_null<CXXConstructExpr>(d.getInit())) { | ||
| const CXXConstructorDecl *cd = e->getConstructor(); | ||
|
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 classic code-gen assume that Also, do we/should we model elidable here?
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. Classic codegen does assume that The AST handles any decisions about which constructors are to be called. Currently, the incubator just represents constructors, when needed, as The AST says this: And the incubator generates this CIR: Is your question whether we should do something here to explicitly show that the copy constructor was elided?
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. Ok, glad to know. Sometimes the As far as elidable. There is a
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. I see. If I add
Member
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. We have been careful not to elide things too early since it might hurt static analysis - this is a big pain point and request from the static analysis community (as clang really early get rid of these). The idea is to represent them in a way that during LoweringPrepare we can either elide them out or apply specific lowering heuristics (e.g. when deciding the best way to initialize large set of constant datas).
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. @bcardosolopes Does that mean that we should be emitting an elidable constructor in CIR even if the For the case without |
||
| // FIXME: we should probably model this more closely to C++ than | ||
| // just emitting a global with zero init (mimic what we do for trivial | ||
| // assignments and whatnots). Since this is for globals shouldn't | ||
| // be a problem for the near future. | ||
| if (cd->isTrivial() && cd->isDefaultConstructor()) | ||
| return cir::ZeroAttr::get(cgm.convertType(d.getType())); | ||
|
Contributor
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. OGCG calls
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. Yeah, that seems reasonable.
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. As I tried to implement this suggestion, it quickly came to my attention that
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. Second complication, the clang AST says that
Contributor
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. Thanks for adding the |
||
| } | ||
| } | ||
| inConstantContext = d.hasConstantInitialization(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.