Skip to content

Commit 3b31c39

Browse files
committed
Address code review comments
1 parent 8d97328 commit 3b31c39

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

clang/lib/CIR/CodeGen/CIRGenCXXABI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ CIRGenCXXABI::AddedStructorArgCounts CIRGenCXXABI::addImplicitConstructorArgs(
3838
}
3939

4040
CatchTypeInfo CIRGenCXXABI::getCatchAllTypeInfo() {
41-
return CatchTypeInfo{nullptr, 0};
41+
return CatchTypeInfo{{}, 0};
4242
}
4343

4444
void CIRGenCXXABI::buildThisParam(CIRGenFunction &cgf,

clang/lib/CIR/CodeGen/CIRGenCleanup.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class EHScope {
8282

8383
Kind getKind() const { return static_cast<Kind>(commonBits.kind); }
8484

85-
bool hasEHBranches() const {
85+
bool mayThrow() const {
8686
// Traditional LLVM codegen also checks for `!block->use_empty()`, but
8787
// in CIRGen the block content is not important, just used as a way to
8888
// signal `hasEHBranches`.
@@ -105,12 +105,11 @@ class EHCatchScope : public EHScope {
105105

106106
public:
107107
struct Handler {
108-
/// A type info value, or null (C++ null, not an LLVM null pointer)
109-
/// for a catch-all.
108+
/// A type info value, or null MLIR attribute for a catch-all
110109
CatchTypeInfo type;
111110

112111
/// The catch handler for this type.
113-
mlir::Block *block;
112+
mlir::Region *region;
114113
};
115114

116115
private:
@@ -130,10 +129,10 @@ class EHCatchScope : public EHScope {
130129

131130
unsigned getNumHandlers() const { return catchBits.numHandlers; }
132131

133-
void setHandler(unsigned i, CatchTypeInfo type, mlir::Block *block) {
132+
void setHandler(unsigned i, CatchTypeInfo type, mlir::Region *region) {
134133
assert(i < getNumHandlers());
135134
getHandlers()[i].type = type;
136-
getHandlers()[i].block = block;
135+
getHandlers()[i].region = region;
137136
}
138137

139138
// Clear all handler blocks.

clang/lib/CIR/CodeGen/CIRGenException.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ CIRGenFunction::emitCXXTryStmtUnderScope(const CXXTryStmt &s) {
111111
}
112112

113113
// Create the scope to represent only the C/C++ `try {}` part. However,
114-
// don't populate right away. Reserve some space to store the exception
115-
// info but don't emit the bulk right away, for now only make sure the
114+
// don't populate right away. Create regions for the catch handlers,
115+
// but don't emit the handler bodies yet. For now, only make sure the
116116
// scope returns the exception information.
117117
auto tryOp = cir::TryOp::create(
118118
builder, tryLoc,
@@ -130,8 +130,10 @@ CIRGenFunction::emitCXXTryStmtUnderScope(const CXXTryStmt &s) {
130130
unsigned numRegionsToCreate =
131131
hasCatchAll ? numHandlers : numHandlers + 1;
132132

133-
for (unsigned i = 0; i != numRegionsToCreate; ++i)
134-
builder.createBlock(result.addRegion());
133+
for (unsigned i = 0; i != numRegionsToCreate; ++i) {
134+
mlir::Region *region = result.addRegion();
135+
builder.createBlock(region);
136+
}
135137
});
136138

137139
// Finally emit the body for try/catch.
@@ -175,10 +177,10 @@ void CIRGenFunction::enterCXXTryStmt(const CXXTryStmt &s, cir::TryOp tryOp,
175177
}
176178

177179
// No exception decl indicates '...', a catch-all.
178-
mlir::Block *handler = &tryOp.getHandlerRegions()[i].getBlocks().front();
180+
mlir::Region *handler = &tryOp.getHandlerRegions()[i];
179181
catchScope->setHandler(i, cgm.getCXXABI().getCatchAllTypeInfo(), handler);
180182

181-
// Under async exceptions, catch(...) need to catch HW exception too
183+
// Under async exceptions, catch(...) needs to catch HW exception too
182184
// Mark scope with SehTryBegin as a SEH __try scope
183185
if (getLangOpts().EHAsynch) {
184186
cgm.errorNYI("enterCXXTryStmt: EHAsynch");
@@ -194,7 +196,7 @@ void CIRGenFunction::exitCXXTryStmt(const CXXTryStmt &s, bool isFnTryBlock) {
194196
cir::TryOp tryOp = curLexScope->getTry();
195197

196198
// If the catch was not required, bail out now.
197-
if (!catchScope.hasEHBranches()) {
199+
if (!catchScope.mayThrow()) {
198200
catchScope.clearHandlerBlocks();
199201
ehStack.popCatch();
200202

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ class CIRGenFunction : public CIRGenTypeCache {
942942

943943
LexicalScope *parentScope = nullptr;
944944

945-
// Holds actual value for ScopeKind::Try
945+
// Holds the actual value for ScopeKind::Try
946946
cir::TryOp tryOp = nullptr;
947947

948948
// Only Regular is used at the moment. Support for other kinds will be

0 commit comments

Comments
 (0)