https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/171222
>From 08d8c69bb704f1f13a1837038d14a4253e3d0b74 Mon Sep 17 00:00:00 2001 From: Andy Kaylor <[email protected]> Date: Mon, 8 Dec 2025 14:54:34 -0800 Subject: [PATCH 1/3] [CIR][NFC] Add stubs for missing visitors in ScalarExprEmitter This adds stubs that issue NYI errors for any visitor that is present in the ClangIR incubator but missing in the upstream implementation. This will make it easier to find to correct locations to implement missing functionality. --- clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp | 148 ++++++++++++++++++++- 1 file changed, 147 insertions(+), 1 deletion(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index 9043ecab42f15..26c46cb336449 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -159,6 +159,14 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { mlir::Value VisitCoawaitExpr(CoawaitExpr *s) { return cgf.emitCoawaitExpr(*s).getValue(); } + mlir::Value VisitCoyieldExpr(CoyieldExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "coyield expr"); + return {}; + } + mlir::Value VisitUnaryCoawait(const UnaryOperator *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "unary coawait expr"); + return {}; + } mlir::Value emitLoadOfLValue(LValue lv, SourceLocation loc) { return cgf.emitLoadOfLValue(lv, loc).getValue(); @@ -198,6 +206,11 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { cir::IntAttr::get(type, e->getValue())); } + mlir::Value VisitFixedPointLiteral(const FixedPointLiteral *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "fixed point literal"); + return {}; + } + mlir::Value VisitFloatingLiteral(const FloatingLiteral *e) { mlir::Type type = cgf.convertType(e->getType()); assert(mlir::isa<cir::FPTypeInterface>(type) && @@ -229,6 +242,19 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { mlir::Value VisitOffsetOfExpr(OffsetOfExpr *e); + mlir::Value VisitSizeOfPackExpr(SizeOfPackExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "size of pack expr"); + return {}; + } + mlir::Value VisitPseudoObjectExpr(PseudoObjectExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "pseudo object expr"); + return {}; + } + mlir::Value VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "sycl unique stable name expr"); + return {}; + } + mlir::Value VisitOpaqueValueExpr(OpaqueValueExpr *e) { if (e->isGLValue()) return emitLoadOfLValue(cgf.getOrCreateOpaqueLValueMapping(e), @@ -238,6 +264,36 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { return cgf.getOrCreateOpaqueRValueMapping(e).getValue(); } + mlir::Value VisitObjCSelectorExpr(ObjCSelectorExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "objc selector expr"); + return {}; + } + mlir::Value VisitObjCProtocolExpr(ObjCProtocolExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "objc protocol expr"); + return {}; + } + mlir::Value VisitObjCIVarRefExpr(ObjCIvarRefExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "objc ivar ref expr"); + return {}; + } + mlir::Value VisitObjCMessageExpr(ObjCMessageExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "objc message expr"); + return {}; + } + mlir::Value VisitObjCIsaExpr(ObjCIsaExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "objc isa expr"); + return {}; + } + mlir::Value VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "objc availability check expr"); + return {}; + } + + mlir::Value VisitMatrixSubscriptExpr(MatrixSubscriptExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "matrix subscript expr"); + return {}; + } + mlir::Value VisitCastExpr(CastExpr *e); mlir::Value VisitCallExpr(const CallExpr *e); @@ -319,6 +375,16 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { mlir::Value VisitInitListExpr(InitListExpr *e); + mlir::Value VisitArrayInitIndexExpr(ArrayInitIndexExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "array init index expr"); + return {}; + } + + mlir::Value VisitImplicitValueInitExpr(const ImplicitValueInitExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "implicit value init expr"); + return {}; + } + mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) { return VisitCastExpr(e); } @@ -726,6 +792,15 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { return Visit(e->getSubExpr()); } + // C++ + mlir::Value VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "materialize temporary expr"); + return {}; + } + mlir::Value VisitSourceLocExpr(SourceLocExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "source loc expr"); + return {}; + } mlir::Value VisitCXXDefaultArgExpr(CXXDefaultArgExpr *dae) { CIRGenFunction::CXXDefaultArgExprScope scope(cgf, dae); return Visit(dae->getExpr()); @@ -745,11 +820,39 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { cgf.emitCXXDeleteExpr(e); return {}; } - + mlir::Value VisitTypeTraitExpr(const TypeTraitExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "type trait expr"); + return {}; + } + mlir::Value + VisitConceptSpecializationExpr(const ConceptSpecializationExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "concept specialization expr"); + return {}; + } + mlir::Value VisitRequiresExpr(const RequiresExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "requires expr"); + return {}; + } + mlir::Value VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "array type trait expr"); + return {}; + } + mlir::Value VisitExpressionTraitExpr(const ExpressionTraitExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "expression trait expr"); + return {}; + } + mlir::Value VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "cxx pseudo destructor expr"); + return {}; + } mlir::Value VisitCXXThrowExpr(const CXXThrowExpr *e) { cgf.emitCXXThrowExpr(e); return {}; } + mlir::Value VisitCXXNoexceptExpr(CXXNoexceptExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "cxx noexcept expr"); + return {}; + } /// Emit a conversion from the specified type to the specified destination /// type, both of which are CIR scalar types. @@ -1213,6 +1316,49 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { return maybePromoteBoolResult(resOp.getResult(), resTy); } + mlir::Value VisitBinPtrMemD(const BinaryOperator *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "ptr mem d expr"); + return {}; + } + + mlir::Value VisitBinPtrMemI(const BinaryOperator *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "ptr mem i expr"); + return {}; + } + + // Other Operators. + mlir::Value VisitBlockExpr(const BlockExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "block expr"); + return {}; + } + + mlir::Value VisitChooseExpr(ChooseExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "choose expr"); + return {}; + } + + mlir::Value VisitObjCStringLiteral(const ObjCStringLiteral *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "objc string literal"); + return {}; + } + mlir::Value VisitObjCBoxedExpr(ObjCBoxedExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "objc boxed expr"); + return {}; + } + mlir::Value VisitObjCArrayLiteral(ObjCArrayLiteral *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "objc array literal"); + return {}; + } + mlir::Value VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "objc dictionary literal"); + return {}; + } + + mlir::Value VisitAsTypeExpr(AsTypeExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "as type expr"); + return {}; + } + mlir::Value VisitAtomicExpr(AtomicExpr *e) { return cgf.emitAtomicExpr(e).getValue(); } >From caae6cce473d83037a56a39bafdd7544295429cc Mon Sep 17 00:00:00 2001 From: Andy Kaylor <[email protected]> Date: Mon, 8 Dec 2025 15:33:16 -0800 Subject: [PATCH 2/3] Make diagnostics more specific --- clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp | 80 +++++++++++++--------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index 26c46cb336449..d5e4abade44d0 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -160,11 +160,11 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { return cgf.emitCoawaitExpr(*s).getValue(); } mlir::Value VisitCoyieldExpr(CoyieldExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "coyield expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: coyield"); return {}; } mlir::Value VisitUnaryCoawait(const UnaryOperator *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "unary coawait expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: unary coawait"); return {}; } @@ -207,7 +207,8 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { } mlir::Value VisitFixedPointLiteral(const FixedPointLiteral *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "fixed point literal"); + cgf.cgm.errorNYI(e->getSourceRange(), + "ScalarExprEmitter: fixed point literal"); return {}; } @@ -243,15 +244,16 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { mlir::Value VisitOffsetOfExpr(OffsetOfExpr *e); mlir::Value VisitSizeOfPackExpr(SizeOfPackExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "size of pack expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: size of pack"); return {}; } mlir::Value VisitPseudoObjectExpr(PseudoObjectExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "pseudo object expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: pseudo object"); return {}; } mlir::Value VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "sycl unique stable name expr"); + cgf.cgm.errorNYI(e->getSourceRange(), + "ScalarExprEmitter: sycl unique stable name"); return {}; } @@ -265,32 +267,34 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { } mlir::Value VisitObjCSelectorExpr(ObjCSelectorExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "objc selector expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: objc selector"); return {}; } mlir::Value VisitObjCProtocolExpr(ObjCProtocolExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "objc protocol expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: objc protocol"); return {}; } mlir::Value VisitObjCIVarRefExpr(ObjCIvarRefExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "objc ivar ref expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: objc ivar ref"); return {}; } mlir::Value VisitObjCMessageExpr(ObjCMessageExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "objc message expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: objc message"); return {}; } mlir::Value VisitObjCIsaExpr(ObjCIsaExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "objc isa expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: objc isa"); return {}; } mlir::Value VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "objc availability check expr"); + cgf.cgm.errorNYI(e->getSourceRange(), + "ScalarExprEmitter: objc availability check"); return {}; } mlir::Value VisitMatrixSubscriptExpr(MatrixSubscriptExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "matrix subscript expr"); + cgf.cgm.errorNYI(e->getSourceRange(), + "ScalarExprEmitter: matrix subscript"); return {}; } @@ -376,12 +380,14 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { mlir::Value VisitInitListExpr(InitListExpr *e); mlir::Value VisitArrayInitIndexExpr(ArrayInitIndexExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "array init index expr"); + cgf.cgm.errorNYI(e->getSourceRange(), + "ScalarExprEmitter: array init index"); return {}; } mlir::Value VisitImplicitValueInitExpr(const ImplicitValueInitExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "implicit value init expr"); + cgf.cgm.errorNYI(e->getSourceRange(), + "ScalarExprEmitter: implicit value init"); return {}; } @@ -794,11 +800,12 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { // C++ mlir::Value VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "materialize temporary expr"); + cgf.cgm.errorNYI(e->getSourceRange(), + "ScalarExprEmitter: materialize temporary"); return {}; } mlir::Value VisitSourceLocExpr(SourceLocExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "source loc expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: source loc"); return {}; } mlir::Value VisitCXXDefaultArgExpr(CXXDefaultArgExpr *dae) { @@ -821,28 +828,32 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { return {}; } mlir::Value VisitTypeTraitExpr(const TypeTraitExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "type trait expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: type trait"); return {}; } mlir::Value VisitConceptSpecializationExpr(const ConceptSpecializationExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "concept specialization expr"); + cgf.cgm.errorNYI(e->getSourceRange(), + "ScalarExprEmitter: concept specialization"); return {}; } mlir::Value VisitRequiresExpr(const RequiresExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "requires expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: requires"); return {}; } mlir::Value VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "array type trait expr"); + cgf.cgm.errorNYI(e->getSourceRange(), + "ScalarExprEmitter: array type trait"); return {}; } mlir::Value VisitExpressionTraitExpr(const ExpressionTraitExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "expression trait expr"); + cgf.cgm.errorNYI(e->getSourceRange(), + "ScalarExprEmitter: expression trait"); return {}; } mlir::Value VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "cxx pseudo destructor expr"); + cgf.cgm.errorNYI(e->getSourceRange(), + "ScalarExprEmitter: cxx pseudo destructor"); return {}; } mlir::Value VisitCXXThrowExpr(const CXXThrowExpr *e) { @@ -850,7 +861,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { return {}; } mlir::Value VisitCXXNoexceptExpr(CXXNoexceptExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "cxx noexcept expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: cxx noexcept"); return {}; } @@ -1317,45 +1328,48 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { } mlir::Value VisitBinPtrMemD(const BinaryOperator *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "ptr mem d expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: ptr mem d"); return {}; } mlir::Value VisitBinPtrMemI(const BinaryOperator *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "ptr mem i expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: ptr mem i"); return {}; } // Other Operators. mlir::Value VisitBlockExpr(const BlockExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "block expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: block"); return {}; } mlir::Value VisitChooseExpr(ChooseExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "choose expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: choose"); return {}; } mlir::Value VisitObjCStringLiteral(const ObjCStringLiteral *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "objc string literal"); + cgf.cgm.errorNYI(e->getSourceRange(), + "ScalarExprEmitter: objc string literal"); return {}; } mlir::Value VisitObjCBoxedExpr(ObjCBoxedExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "objc boxed expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: objc boxed"); return {}; } mlir::Value VisitObjCArrayLiteral(ObjCArrayLiteral *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "objc array literal"); + cgf.cgm.errorNYI(e->getSourceRange(), + "ScalarExprEmitter: objc array literal"); return {}; } mlir::Value VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "objc dictionary literal"); + cgf.cgm.errorNYI(e->getSourceRange(), + "ScalarExprEmitter: objc dictionary literal"); return {}; } mlir::Value VisitAsTypeExpr(AsTypeExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "as type expr"); + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: as type"); return {}; } >From 6ff378690f1cda9ba73c0335a699d1a8e55185e2 Mon Sep 17 00:00:00 2001 From: Andy Kaylor <[email protected]> Date: Mon, 8 Dec 2025 15:48:58 -0800 Subject: [PATCH 3/3] Add another missing case from classic codegen --- clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index d5e4abade44d0..b682d31d61b8a 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -256,7 +256,10 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { "ScalarExprEmitter: sycl unique stable name"); return {}; } - + mlir::Value VisitEmbedExpr(EmbedExpr *e) { + cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: embed"); + return {}; + } mlir::Value VisitOpaqueValueExpr(OpaqueValueExpr *e) { if (e->isGLValue()) return emitLoadOfLValue(cgf.getOrCreateOpaqueLValueMapping(e), _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
