[clang] [CIR] Implement Statement Expressions (PR #153677)
Bruno Cardoso Lopes via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 15 14:31:10 PDT 2025
================
@@ -23,16 +25,57 @@ using namespace clang;
using namespace clang::CIRGen;
using namespace cir;
-void CIRGenFunction::emitCompoundStmtWithoutScope(const CompoundStmt &s) {
- for (auto *curStmt : s.body()) {
- if (emitStmt(curStmt, /*useCurrentScope=*/false).failed())
- getCIRGenModule().errorNYI(curStmt->getSourceRange(),
- std::string("emitCompoundStmtWithoutScope: ") +
- curStmt->getStmtClassName());
+mlir::LogicalResult CIRGenFunction::emitCompoundStmtWithoutScope(
+ const CompoundStmt &s, Address *lastValue, AggValueSlot slot) {
+ mlir::LogicalResult result = mlir::success();
+ const Stmt *exprResult = s.getStmtExprResult();
+ assert((!lastValue || (lastValue && exprResult)) &&
+ "If lastValue is not null then the CompoundStmt must have a "
+ "StmtExprResult");
+
+ for (const Stmt *curStmt : s.body()) {
+ // We have to special case labels here. They are statements, but when put
+ // at the end of a statement expression, they yield the value of their
+ // subexpression. Handle this by walking through all labels we encounter,
+ // emitting them before we evaluate the subexpr.
+ // Similar issues arise for attributed statements.
+ if (lastValue && exprResult == curStmt) {
----------------
bcardosolopes wrote:
Might be cleaner to factor the content of this `if` out in a helper function.
https://github.com/llvm/llvm-project/pull/153677
More information about the cfe-commits
mailing list