Skip to content

Commit ba18556

Browse files
committed
Address review feedback
1 parent d90efb8 commit ba18556

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

clang/lib/CIR/CodeGen/Address.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ class Address {
108108
return nullptr;
109109
return getPointer().getDefiningOp();
110110
}
111+
112+
template <typename OpTy> OpTy getDefiningOp() const {
113+
return mlir::dyn_cast_or_null<OpTy>(getDefiningOp());
114+
}
111115
};
112116

113117
} // namespace clang::CIRGen

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,12 +1110,10 @@ static Address createReferenceTemporary(CIRGenFunction &cgf,
11101110
// The temporary memory should be created in the same scope as the extending
11111111
// declaration of the temporary materialization expression.
11121112
cir::AllocaOp extDeclAlloca;
1113-
if (const clang::ValueDecl *extDecl = m->getExtendingDecl()) {
1113+
if (const ValueDecl *extDecl = m->getExtendingDecl()) {
11141114
auto extDeclAddrIter = cgf.localDeclMap.find(extDecl);
1115-
if (extDeclAddrIter != cgf.localDeclMap.end()) {
1116-
extDeclAlloca = mlir::dyn_cast_if_present<cir::AllocaOp>(
1117-
extDeclAddrIter->second.getDefiningOp());
1118-
}
1115+
if (extDeclAddrIter != cgf.localDeclMap.end())
1116+
extDeclAlloca = extDeclAddrIter->second.getDefiningOp<cir::AllocaOp>();
11191117
}
11201118
mlir::OpBuilder::InsertPoint ip;
11211119
if (extDeclAlloca)
@@ -1151,12 +1149,12 @@ static void pushTemporaryCleanup(CIRGenFunction &cgf,
11511149
return;
11521150
}
11531151

1154-
clang::CXXDestructorDecl *referenceTemporaryDtor = nullptr;
1152+
CXXDestructorDecl *referenceTemporaryDtor = nullptr;
11551153
if (const clang::RecordType *rt = e->getType()
11561154
->getBaseElementTypeUnsafe()
11571155
->getAs<clang::RecordType>()) {
11581156
// Get the destructor for the reference temporary.
1159-
auto *classDecl = cast<clang::CXXRecordDecl>(rt->getDecl());
1157+
auto *classDecl = cast<CXXRecordDecl>(rt->getDecl());
11601158
if (!classDecl->hasTrivialDestructor())
11611159
referenceTemporaryDtor = classDecl->getDestructor();
11621160
}
@@ -1221,8 +1219,7 @@ LValue CIRGenFunction::emitMaterializeTemporaryExpr(
12211219
// Create and initialize the reference temporary.
12221220
Address object = createReferenceTemporary(*this, m, e);
12231221

1224-
if (auto var =
1225-
mlir::dyn_cast<cir::GlobalOp>(object.getPointer().getDefiningOp())) {
1222+
if (auto var = object.getPointer().getDefiningOp<cir::GlobalOp>()) {
12261223
// TODO(cir): add something akin to stripPointerCasts() to ptr above
12271224
cgm.errorNYI(e->getSourceRange(), "emitMaterializeTemporaryExpr: GlobalOp");
12281225
return {};

0 commit comments

Comments
 (0)