================ @@ -807,6 +808,65 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { VISITCOMP(EQ) VISITCOMP(NE) #undef VISITCOMP + + mlir::Value VisitBinAssign(const BinaryOperator *e) { + const bool ignore = std::exchange(ignoreResultAssign, false); + + mlir::Value rhs; + LValue lhs; + + switch (e->getLHS()->getType().getObjCLifetime()) { + case Qualifiers::OCL_Strong: + case Qualifiers::OCL_Autoreleasing: + case Qualifiers::OCL_ExplicitNone: + case Qualifiers::OCL_Weak: + assert(!cir::MissingFeatures::objCLifetime()); + break; + case Qualifiers::OCL_None: + // __block variables need to have the rhs evaluated first, plus this + // should improve codegen just a little. + rhs = Visit(e->getRHS()); + assert(!cir::MissingFeatures::sanitizers()); + // TODO(cir): This needs to be emitCheckedLValue() once we support + // sanitizers + lhs = cgf.emitLValue(e->getLHS()); + + // Store the value into the LHS. Bit-fields are handled specially because + // the result is altered by the store, i.e., [C99 6.5.16p1] + // 'An assignment expression has the value of the left operand after the + // assignment...'. + if (lhs.isBitField()) { + cgf.emitStoreThroughBitfieldLValue(RValue::get(rhs), lhs, rhs); + } else { + cgf.emitNullabilityCheck(lhs, rhs, e->getExprLoc()); + CIRGenFunction::SourceLocRAIIObject loc{ + cgf, cgf.getLoc(e->getSourceRange())}; + cgf.emitStoreThroughLValue(RValue::get(rhs), lhs); + } + } + + // If the result is clearly ignored, return now. + if (ignore) + return nullptr; + + // The result of an assignment in C is the assigned r-value. + if (!cgf.getLangOpts().CPlusPlus) + return rhs; + + // If the lvalue is non-volatile, return the computed value of the + // assignment. + if (!lhs.isVolatile()) + return rhs; + + // Otherwise, reload the value. + return emitLoadOfLValue(lhs, e->getExprLoc()); + } + + mlir::Value VisitBinComma(const BinaryOperator *e) { + cgf.emitIgnoredExpr(e->getLHS()); + // NOTE: We don't need to EnsureInsertPoint() like LLVM codegen. ---------------- erichkeane wrote:
Why not? https://github.com/llvm/llvm-project/pull/135115 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits