Skip to content

Commit 020184b

Browse files
committed
emitCompoundStmt should return a LogicalResult
1 parent d68b52a commit 020184b

File tree

5 files changed

+24
-37
lines changed

5 files changed

+24
-37
lines changed

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
7373
CIRGenFunction::StmtExprEvaluation eval(cgf);
7474
Address retAlloca =
7575
cgf.createMemTemp(e->getType(), cgf.getLoc(e->getSourceRange()));
76-
cgf.emitCompoundStmt(*e->getSubStmt(), &retAlloca, dest);
76+
(void)cgf.emitCompoundStmt(*e->getSubStmt(), &retAlloca, dest);
7777
}
7878

7979
void VisitDeclRefExpr(DeclRefExpr *e) { emitAggLoadOfLValue(e); }

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
188188
mlir::Value VisitStmtExpr(StmtExpr *e) {
189189
CIRGenFunction::StmtExprEvaluation eval(cgf);
190190
if (e->getType()->isVoidType()) {
191-
cgf.emitCompoundStmt(*e->getSubStmt());
191+
(void)cgf.emitCompoundStmt(*e->getSubStmt());
192192
return {};
193193
}
194194

195195
Address retAlloca =
196196
cgf.createMemTemp(e->getType(), cgf.getLoc(e->getSourceRange()));
197-
cgf.emitCompoundStmt(*e->getSubStmt(), &retAlloca);
197+
(void)cgf.emitCompoundStmt(*e->getSubStmt(), &retAlloca);
198198

199199
return cgf.emitLoadOfScalar(cgf.makeAddrLValue(retAlloca, e->getType()),
200200
e->getExprLoc());

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,10 @@ mlir::LogicalResult CIRGenFunction::emitFunctionBody(const clang::Stmt *body) {
490490
// We start with function level scope for variables.
491491
SymTableScopeTy varScope(symbolTable);
492492

493-
auto result = mlir::LogicalResult::success();
494493
if (const CompoundStmt *block = dyn_cast<CompoundStmt>(body))
495-
emitCompoundStmtWithoutScope(*block);
496-
else
497-
result = emitStmt(body, /*useCurrentScope=*/true);
494+
return emitCompoundStmtWithoutScope(*block);
498495

499-
return result;
496+
return emitStmt(body, /*useCurrentScope=*/true);
500497
}
501498

502499
static void eraseEmptyAndUnusedBlocks(cir::FuncOp func) {

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,11 +1157,11 @@ class CIRGenFunction : public CIRGenTypeCache {
11571157
LValue emitScalarCompoundAssignWithComplex(const CompoundAssignOperator *e,
11581158
mlir::Value &result);
11591159

1160-
Address emitCompoundStmt(const clang::CompoundStmt &s,
1161-
Address *lastValue = nullptr,
1162-
AggValueSlot slot = AggValueSlot::ignored());
1160+
mlir::LogicalResult
1161+
emitCompoundStmt(const clang::CompoundStmt &s, Address *lastValue = nullptr,
1162+
AggValueSlot slot = AggValueSlot::ignored());
11631163

1164-
Address
1164+
mlir::LogicalResult
11651165
emitCompoundStmtWithoutScope(const clang::CompoundStmt &s,
11661166
Address *lastValue = nullptr,
11671167
AggValueSlot slot = AggValueSlot::ignored());

clang/lib/CIR/CodeGen/CIRGenStmt.cpp

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "mlir/IR/Builders.h"
1717
#include "mlir/IR/Location.h"
18+
#include "mlir/Support/LLVM.h"
1819
#include "clang/AST/ExprCXX.h"
1920
#include "clang/AST/Stmt.h"
2021
#include "clang/AST/StmtOpenACC.h"
@@ -24,16 +25,13 @@ using namespace clang;
2425
using namespace clang::CIRGen;
2526
using namespace cir;
2627

27-
Address CIRGenFunction::emitCompoundStmtWithoutScope(const CompoundStmt &s,
28-
Address *lastValue,
29-
AggValueSlot slot) {
28+
mlir::LogicalResult CIRGenFunction::emitCompoundStmtWithoutScope(
29+
const CompoundStmt &s, Address *lastValue, AggValueSlot slot) {
3030
const Stmt *exprResult = s.getStmtExprResult();
3131
assert((!lastValue || (lastValue && exprResult)) &&
3232
"If lastValue is not null then the CompoundStmt must have a "
3333
"StmtExprResult");
3434

35-
Address retAlloca = Address::invalid();
36-
3735
for (Stmt *curStmt : s.body()) {
3836
// We have to special case labels here. They are statements, but when put
3937
// at the end of a statement expression, they yield the value of their
@@ -44,7 +42,7 @@ Address CIRGenFunction::emitCompoundStmtWithoutScope(const CompoundStmt &s,
4442
while (!isa<Expr>(exprResult)) {
4543
if (const auto *ls = dyn_cast<LabelStmt>(exprResult)) {
4644
if (emitLabel(*ls->getDecl()).failed())
47-
return Address::invalid();
45+
return mlir::failure();
4846
exprResult = ls->getSubStmt();
4947
} else if (const auto *as = dyn_cast<AttributedStmt>(exprResult)) {
5048
// FIXME: Update this if we ever have attributes that affect the
@@ -68,18 +66,16 @@ Address CIRGenFunction::emitCompoundStmtWithoutScope(const CompoundStmt &s,
6866
}
6967
} else {
7068
if (emitStmt(curStmt, /*useCurrentScope=*/false).failed())
71-
return Address::invalid();
69+
return mlir::failure();
7270
}
7371
}
7472

75-
return retAlloca;
73+
return mlir::success();
7674
}
7775

78-
Address CIRGenFunction::emitCompoundStmt(const CompoundStmt &s,
79-
Address *lastValue,
80-
AggValueSlot slot) {
81-
Address retAlloca = Address::invalid();
82-
76+
mlir::LogicalResult CIRGenFunction::emitCompoundStmt(const CompoundStmt &s,
77+
Address *lastValue,
78+
AggValueSlot slot) {
8379
// Add local scope to track new declared variables.
8480
SymTableScopeTy varScope(symbolTable);
8581
mlir::Location scopeLoc = getLoc(s.getSourceRange());
@@ -88,14 +84,10 @@ Address CIRGenFunction::emitCompoundStmt(const CompoundStmt &s,
8884
scopeLoc, [&](mlir::OpBuilder &b, mlir::Type &type, mlir::Location loc) {
8985
scopeInsPt = b.saveInsertionPoint();
9086
});
91-
{
92-
mlir::OpBuilder::InsertionGuard guard(builder);
93-
builder.restoreInsertionPoint(scopeInsPt);
94-
LexicalScope lexScope(*this, scopeLoc, builder.getInsertionBlock());
95-
retAlloca = emitCompoundStmtWithoutScope(s, lastValue, slot);
96-
}
97-
98-
return retAlloca;
87+
mlir::OpBuilder::InsertionGuard guard(builder);
88+
builder.restoreInsertionPoint(scopeInsPt);
89+
LexicalScope lexScope(*this, scopeLoc, builder.getInsertionBlock());
90+
return emitCompoundStmtWithoutScope(s, lastValue, slot);
9991
}
10092

10193
void CIRGenFunction::emitStopPoint(const Stmt *s) {
@@ -297,10 +289,8 @@ mlir::LogicalResult CIRGenFunction::emitSimpleStmt(const Stmt *s,
297289
return emitDeclStmt(cast<DeclStmt>(*s));
298290
case Stmt::CompoundStmtClass:
299291
if (useCurrentScope)
300-
emitCompoundStmtWithoutScope(cast<CompoundStmt>(*s));
301-
else
302-
emitCompoundStmt(cast<CompoundStmt>(*s));
303-
break;
292+
return emitCompoundStmtWithoutScope(cast<CompoundStmt>(*s));
293+
return emitCompoundStmt(cast<CompoundStmt>(*s));
304294
case Stmt::ContinueStmtClass:
305295
return emitContinueStmt(cast<ContinueStmt>(*s));
306296

0 commit comments

Comments
 (0)