2525#include " clang/AST/ASTContext.h"
2626#include " clang/AST/BaseSubobject.h"
2727#include " clang/AST/CharUnits.h"
28+ #include " clang/AST/CurrentSourceLocExprScope.h"
2829#include " clang/AST/Decl.h"
30+ #include " clang/AST/ExprCXX.h"
2931#include " clang/AST/Stmt.h"
3032#include " clang/AST/Type.h"
3133#include " clang/CIR/Dialect/IR/CIRDialect.h"
@@ -599,6 +601,12 @@ class CIRGenFunction : public CIRGenTypeCache {
599601 // / true when both vcall CFI and whole-program-vtables are enabled.
600602 bool shouldEmitVTableTypeCheckedLoad (const CXXRecordDecl *rd);
601603
604+ // / Source location information about the default argument or member
605+ // / initializer expression we're evaluating, if any.
606+ clang::CurrentSourceLocExprScope curSourceLocExprScope;
607+ using SourceLocExprScopeGuard =
608+ clang::CurrentSourceLocExprScope::SourceLocExprScopeGuard;
609+
602610 // / A scope within which we are constructing the fields of an object which
603611 // / might use a CXXDefaultInitExpr. This stashes away a 'this' value to use if
604612 // / we need to evaluate the CXXDefaultInitExpr within the evaluation.
@@ -617,6 +625,29 @@ class CIRGenFunction : public CIRGenTypeCache {
617625 Address oldCXXDefaultInitExprThis;
618626 };
619627
628+ // / The scope of a CXXDefaultInitExpr. Within this scope, the value of 'this'
629+ // / is overridden to be the object under construction.
630+ class CXXDefaultInitExprScope {
631+ public:
632+ CXXDefaultInitExprScope (CIRGenFunction &cgf, const CXXDefaultInitExpr *e)
633+ : cgf{cgf}, oldCXXThisValue(cgf.cxxThisValue),
634+ oldCXXThisAlignment (cgf.cxxThisAlignment),
635+ sourceLocScope (e, cgf.curSourceLocExprScope) {
636+ cgf.cxxThisValue = cgf.cxxDefaultInitExprThis .getPointer ();
637+ cgf.cxxThisAlignment = cgf.cxxDefaultInitExprThis .getAlignment ();
638+ }
639+ ~CXXDefaultInitExprScope () {
640+ cgf.cxxThisValue = oldCXXThisValue;
641+ cgf.cxxThisAlignment = oldCXXThisAlignment;
642+ }
643+
644+ public:
645+ CIRGenFunction &cgf;
646+ mlir::Value oldCXXThisValue;
647+ clang::CharUnits oldCXXThisAlignment;
648+ SourceLocExprScopeGuard sourceLocScope;
649+ };
650+
620651 LValue makeNaturalAlignPointeeAddrLValue (mlir::Value v, clang::QualType t);
621652 LValue makeNaturalAlignAddrLValue (mlir::Value val, QualType ty);
622653
@@ -658,6 +689,8 @@ class CIRGenFunction : public CIRGenTypeCache {
658689 const clang::CXXRecordDecl *rd);
659690 void initializeVTablePointer (mlir::Location loc, const VPtr &vptr);
660691
692+ AggValueSlot::Overlap_t getOverlapForFieldInit (const FieldDecl *fd);
693+
661694 // / Return the address of a local variable.
662695 Address getAddrOfLocalVar (const clang::VarDecl *vd) {
663696 auto it = localDeclMap.find (vd);
0 commit comments