[clang] [CIR] Diagnose missing/bad `cir.triple` and `cir.opt_info` attributes in CIR tests instead of asserts/crashes (PR #230003)

Ian Li via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 15 00:01:30 PDT 2026


================
@@ -5818,6 +5818,16 @@ mlir::LogicalResult CIRToLLVMTokenNoneOpLowering::matchAndRewrite(
 mlir::LogicalResult CIRToLLVMCpuIdOpLowering::matchAndRewrite(
     cir::CpuIdOp op, OpAdaptor adaptor,
     mlir::ConversionPatternRewriter &rewriter) const {
+  mlir::ModuleOp moduleOp = op->getParentOfType<mlir::ModuleOp>();
+  std::optional<llvm::Triple> triple = cir::getTripleFromModule(moduleOp);
+  if (!triple) {
+    moduleOp.emitError() << "cannot lower " << op.getOperationName() << " "
+                         << "without a '"
+                         << cir::CIRDialect::getTripleAttrName() << "' "
+                         << "attribute";
+    return mlir::failure();
+  }
+
----------------
ianayl wrote:

I changed the wording, but I didn't leave a comment since it'd be caught when we drop the std::optional when the triple becomes a mandatory attribute

https://github.com/llvm/llvm-project/pull/230003


More information about the cfe-commits mailing list