Skip to content

Commit 6ba60aa

Browse files
committed
Address review feedback
1 parent aeaef15 commit 6ba60aa

File tree

5 files changed

+50
-35
lines changed

5 files changed

+50
-35
lines changed

clang/lib/CIR/CodeGen/CIRGenCXXABI.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class CIRGenCXXABI {
3737

3838
void setCXXABIThisValue(CIRGenFunction &cgf, mlir::Value thisPtr);
3939

40-
/// Emit a single constructor/destructor with the gien type from a C++
41-
/// constructor Decl.
40+
/// Emit a single constructor/destructor with the gen type from a C++
41+
/// constructor/destructor Decl.
4242
virtual void emitCXXStructor(clang::GlobalDecl gd) = 0;
4343

4444
public:
@@ -59,7 +59,8 @@ class CIRGenCXXABI {
5959
return md->getParent();
6060
}
6161

62-
/// Return whether the given global decl needs a VTT parameter.
62+
/// Return whether the given global decl needs a VTT (virtual table table)
63+
/// parameter.
6364
virtual bool needsVTTParameter(clang::GlobalDecl gd) { return false; }
6465

6566
/// Build a parameter variable suitable for 'this'.
@@ -71,17 +72,6 @@ class CIRGenCXXABI {
7172
/// Emit constructor variants required by this ABI.
7273
virtual void emitCXXConstructors(const clang::CXXConstructorDecl *d) = 0;
7374

74-
/// Insert any ABI-specific implicit parameters into the parameter list for a
75-
/// function. This generally involves extra data for constructors and
76-
/// destructors.
77-
///
78-
/// ABIs may also choose to override the return type, which has been
79-
/// initialized with the type of 'this' if HasThisReturn(CGF.CurGD) is true or
80-
/// the formal return type of the function otherwise.
81-
virtual void addImplicitStructorParams(CIRGenFunction &cgf,
82-
clang::QualType &resTy,
83-
FunctionArgList &params) = 0;
84-
8575
/// Returns true if the given constructor or destructor is one of the kinds
8676
/// that the ABI says returns 'this' (only applies when called non-virtually
8777
/// for destructors).

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ using namespace clang;
2222
using namespace clang::CIRGen;
2323

2424
/// Checks whether the given constructor is a valid subject for the
25-
/// complete-to-base constructor delgation optimization, i.e. emitting the
25+
/// complete-to-base constructor delegation optimization, i.e. emitting the
2626
/// complete constructor as a simple call to the base constructor.
2727
bool CIRGenFunction::isConstructorDelegationValid(
2828
const CXXConstructorDecl *ctor) {
29-
3029
// Currently we disable the optimization for classes with virtual bases
3130
// because (1) the address of parameter variables need to be consistent across
3231
// all initializers but (2) the delegate function call necessarily creates a

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,13 @@ void CIRGenFunction::emitConstructorBody(FunctionArgList &args) {
527527
// complete ctor and then delegate to the base ctor.
528528

529529
assert(!cir::MissingFeatures::emitCtorPrologue());
530+
if (ctor->isDelegatingConstructor()) {
531+
// This will be handled in emitCtorPrologue, but we should emit a diagnostic
532+
// rather than silently fail to delegate.
533+
cgm.errorNYI(ctor->getSourceRange(),
534+
"emitConstructorBody: delegating ctor");
535+
return;
536+
}
530537

531538
// TODO(cir): propagate this result via mlir::logical result. Just unreachable
532539
// now just to have it handled.
@@ -572,7 +579,7 @@ clang::QualType CIRGenFunction::buildFunctionArgList(clang::GlobalDecl gd,
572579
args.push_back(param);
573580

574581
if (md && (isa<CXXConstructorDecl>(md) || isa<CXXDestructorDecl>(md)))
575-
cgm.getCXXABI().addImplicitStructorParams(*this, retTy, args);
582+
assert(!cir::MissingFeatures::cxxabiStructorImplicitParam());
576583

577584
return retTy;
578585
}

clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ class CIRGenItaniumCXXABI : public CIRGenCXXABI {
4242
void emitInstanceFunctionProlog(SourceLocation loc,
4343
CIRGenFunction &cgf) override;
4444

45-
void addImplicitStructorParams(CIRGenFunction &cgf, QualType &retTy,
46-
FunctionArgList &params) override;
47-
4845
void emitCXXConstructors(const clang::CXXConstructorDecl *d) override;
4946
void emitCXXStructor(clang::GlobalDecl gd) override;
5047
};
@@ -82,19 +79,6 @@ void CIRGenItaniumCXXABI::emitInstanceFunctionProlog(SourceLocation loc,
8279
}
8380
}
8481

85-
void CIRGenItaniumCXXABI::addImplicitStructorParams(CIRGenFunction &cgf,
86-
QualType &retTY,
87-
FunctionArgList &params) {
88-
const auto *md = cast<CXXMethodDecl>(cgf.curGD.getDecl());
89-
assert(isa<CXXConstructorDecl>(md) || isa<CXXDestructorDecl>(md));
90-
91-
// Check if we need a VTT parameter as well.
92-
if (needsVTTParameter(cgf.curGD)) {
93-
cgf.cgm.errorNYI(cgf.curFuncDecl->getLocation(),
94-
"addImplicitStructorParams: VTT parameter");
95-
}
96-
}
97-
9882
void CIRGenItaniumCXXABI::emitCXXStructor(GlobalDecl gd) {
9983
auto *md = cast<CXXMethodDecl>(gd.getDecl());
10084
auto *cd = dyn_cast<CXXConstructorDecl>(md);
@@ -128,8 +112,9 @@ void CIRGenItaniumCXXABI::emitCXXConstructors(const CXXConstructorDecl *d) {
128112
}
129113
}
130114

131-
/// Return whether the given global decl needs a VTT parameter, which it does if
132-
/// it's a base constructor or destructor with virtual bases.
115+
/// Return whether the given global decl needs a VTT (virtual table table)
116+
/// parameter, which it does if it's a base constructor or destructor with
117+
/// virtual bases.
133118
bool CIRGenItaniumCXXABI::needsVTTParameter(GlobalDecl gd) {
134119
auto *md = cast<CXXMethodDecl>(gd.getDecl());
135120

clang/test/CIR/CodeGen/ctor.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,37 @@ void baz() {
3333
// CHECK-NEXT: %[[S_ADDR:.*]] = cir.alloca !rec_Struk, !cir.ptr<!rec_Struk>, ["s", init] {alignment = 4 : i64}
3434
// CHECK-NEXT: cir.call @_ZN5StrukC1Ev(%[[S_ADDR]]) : (!cir.ptr<!rec_Struk>) -> ()
3535
// CHECK-NEXT: cir.return
36+
37+
struct VariadicStruk {
38+
int a;
39+
VariadicStruk(int n, ...) { a = n;}
40+
};
41+
42+
void bar() {
43+
VariadicStruk s(1, 2, 3);
44+
}
45+
46+
// When a variadic constructor is present, we call the C2 constructor directly.
47+
48+
// CHECK-NOT: cir.func @_ZN13VariadicStrukC2Eiz
49+
50+
// CHECK: cir.func @_ZN13VariadicStrukC1Eiz(%arg0: !cir.ptr<!rec_VariadicStruk>
51+
// CHECK-SAME: %arg1: !s32i
52+
// CHECK-SAME: ...) {
53+
// CHECK-NEXT: %[[THIS_ADDR:.*]] = cir.alloca {{.*}} ["this", init]
54+
// CHECK-NEXT: %[[N_ADDR:.*]] = cir.alloca {{.*}} ["n", init]
55+
// CHECK-NEXT: cir.store %arg0, %[[THIS_ADDR]]
56+
// CHECK-NEXT: cir.store %arg1, %[[N_ADDR]]
57+
// CHECK-NEXT: %[[THIS:.*]] = cir.load{{.*}} %[[THIS_ADDR]]
58+
// CHECK-NEXT: %[[N:.*]] = cir.load{{.*}} %[[N_ADDR]]
59+
// CHECK-NEXT: %[[A_ADDR:.*]] = cir.get_member %[[THIS]][0] {name = "a"}
60+
// CHECK-NEXT: cir.store{{.*}} %[[N]], %[[A_ADDR]]
61+
// CHECK-NEXT: cir.return
62+
63+
// CHECK: cir.func @_Z3barv
64+
// CHECK-NEXT: %[[S_ADDR:.*]] = cir.alloca !rec_VariadicStruk, !cir.ptr<!rec_VariadicStruk>, ["s", init]
65+
// CHECK-NEXT: %[[ONE:.*]] = cir.const #cir.int<1> : !s32i
66+
// CHECK-NEXT: %[[TWO:.*]] = cir.const #cir.int<2> : !s32i
67+
// CHECK-NEXT: %[[THREE:.*]] = cir.const #cir.int<3> : !s32i
68+
// CHECK-NEXT: cir.call @_ZN13VariadicStrukC1Eiz(%[[S_ADDR]], %[[ONE]], %[[TWO]], %[[THREE]])
69+
// CHECK-NEXT: cir.return

0 commit comments

Comments
 (0)