diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp index 696c6c877dd9..a3c6b8da87d1 100644 --- a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp @@ -24,6 +24,7 @@ #include "clang/Frontend/FrontendDiagnostic.h" #include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/Support/LogicalResult.h" using namespace cir; using namespace clang; @@ -1114,7 +1115,7 @@ mlir::LogicalResult CIRGenFunction::buildFunctionBody(const clang::Stmt *Body) { auto result = mlir::LogicalResult::success(); if (const CompoundStmt *S = dyn_cast(Body)) - result = buildCompoundStmtWithoutScope(*S); + buildCompoundStmtWithoutScope(*S); else result = buildStmt(Body, /*useCurrentScope*/ true); diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h b/clang/lib/CIR/CodeGen/CIRGenFunction.h index 9e2d1687366f..2d56b33dc823 100644 --- a/clang/lib/CIR/CodeGen/CIRGenFunction.h +++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h @@ -834,11 +834,13 @@ class CIRGenFunction : public CIRGenTypeCache { bool IsFnTryBlock = false); void exitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); - mlir::LogicalResult buildCompoundStmt(const clang::CompoundStmt &S); - - mlir::LogicalResult - buildCompoundStmtWithoutScope(const clang::CompoundStmt &S); + Address buildCompoundStmt(const clang::CompoundStmt &S, bool getLast = false, + AggValueSlot slot = AggValueSlot::ignored()); + Address + buildCompoundStmtWithoutScope(const clang::CompoundStmt &S, + bool getLast = false, + AggValueSlot slot = AggValueSlot::ignored()); GlobalDecl CurSEHParent; bool currentFunctionUsesSEHTry() const { return !!CurSEHParent; } diff --git a/clang/lib/CIR/CodeGen/CIRGenStmt.cpp b/clang/lib/CIR/CodeGen/CIRGenStmt.cpp index cedcdac48621..f683f7509876 100644 --- a/clang/lib/CIR/CodeGen/CIRGenStmt.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenStmt.cpp @@ -10,30 +10,27 @@ // //===----------------------------------------------------------------------===// +#include "Address.h" #include "CIRGenFunction.h" +#include "mlir/IR/Value.h" using namespace cir; using namespace clang; using namespace mlir::cir; -mlir::LogicalResult -CIRGenFunction::buildCompoundStmtWithoutScope(const CompoundStmt &S) { +Address CIRGenFunction::buildCompoundStmtWithoutScope(const CompoundStmt &S, + bool getLast, + AggValueSlot slot) { for (auto *CurStmt : S.body()) if (buildStmt(CurStmt, /*useCurrentScope=*/false).failed()) - return mlir::failure(); + return Address::invalid(); - return mlir::success(); + return Address::invalid(); } -mlir::LogicalResult CIRGenFunction::buildCompoundStmt(const CompoundStmt &S) { - mlir::LogicalResult res = mlir::success(); - - auto compoundStmtBuilder = [&]() -> mlir::LogicalResult { - if (buildCompoundStmtWithoutScope(S).failed()) - return mlir::failure(); - - return mlir::success(); - }; +Address CIRGenFunction::buildCompoundStmt(const CompoundStmt &S, bool getLast, + AggValueSlot slot) { + Address retAlloca = Address::invalid(); // Add local scope to track new declared variables. SymTableScopeTy varScope(symbolTable); @@ -42,10 +39,10 @@ mlir::LogicalResult CIRGenFunction::buildCompoundStmt(const CompoundStmt &S) { scopeLoc, /*scopeBuilder=*/ [&](mlir::OpBuilder &b, mlir::Location loc) { LexicalScope lexScope{*this, loc, builder.getInsertionBlock()}; - res = compoundStmtBuilder(); + retAlloca = buildCompoundStmtWithoutScope(S); }); - return res; + return retAlloca; } void CIRGenFunction::buildStopPoint(const Stmt *S) { @@ -260,9 +257,9 @@ mlir::LogicalResult CIRGenFunction::buildSimpleStmt(const Stmt *S, case Stmt::DeclStmtClass: return buildDeclStmt(cast(*S)); case Stmt::CompoundStmtClass: - return useCurrentScope - ? buildCompoundStmtWithoutScope(cast(*S)) - : buildCompoundStmt(cast(*S)); + useCurrentScope ? buildCompoundStmtWithoutScope(cast(*S)) + : buildCompoundStmt(cast(*S)); + break; case Stmt::ReturnStmtClass: return buildReturnStmt(cast(*S)); case Stmt::GotoStmtClass: