[clang] [CIR] Upstream ThreeWayCmpOp (PR #169963)
Hendrik Hübner via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 15 09:11:38 PST 2026
================
@@ -298,8 +299,63 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
Visit(e->getRHS());
}
void VisitBinCmp(const BinaryOperator *e) {
- cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitBinCmp");
+ assert(cgf.getContext().hasSameType(e->getLHS()->getType(),
+ e->getRHS()->getType()));
+ const ComparisonCategoryInfo &cmpInfo =
+ cgf.getContext().CompCategories.getInfoForType(e->getType());
+ assert(cmpInfo.Record->isTriviallyCopyable() &&
+ "cannot copy non-trivially copyable aggregate");
+
+ QualType argTy = e->getLHS()->getType();
+
+ if (!argTy->isIntegralOrEnumerationType() && !argTy->isRealFloatingType() &&
+ !argTy->isNullPtrType() && !argTy->isPointerType() &&
+ !argTy->isMemberPointerType() && !argTy->isAnyComplexType())
+ llvm_unreachable("aggregate three-way comparison");
+
+ mlir::Location loc = cgf.getLoc(e->getSourceRange());
+ CIRGenBuilderTy builder = cgf.getBuilder();
+
+ if (e->getType()->isAnyComplexType())
+ llvm_unreachable("NYI");
+
+ mlir::Value lhs = cgf.emitAnyExpr(e->getLHS()).getValue();
+ mlir::Value rhs = cgf.emitAnyExpr(e->getRHS()).getValue();
+
+ mlir::Value resultScalar;
+ if (argTy->isNullPtrType()) {
+ resultScalar =
+ builder.getConstInt(loc, cmpInfo.getEqualOrEquiv()->getIntValue());
----------------
HendrikHuebner wrote:
I'm not sure how to hit this case in the first place. The clang frontend does not seem to allow three way comparisons with a null pointer constant. There is no test case in OGCG for this either.
https://github.com/llvm/llvm-project/pull/169963
More information about the cfe-commits
mailing list