================
@@ -257,6 +258,42 @@ cir::CIRDialect::verifyOperationAttribute(mlir::Operation 
*op,
   if (isOpenCLVersionAttrName(attrName))
     return verifyOpenCLVersionAttr(op, attr);
 
+  if (attrName == getCXXABIAttrName()) {
+    if (!mlir::isa<mlir::ModuleOp>(op))
+      return op->emitOpError() << "expects '" << getCXXABIAttrName()
+                               << "' attribute to be attached to '"
+                               << mlir::ModuleOp::getOperationName() << "'";
+    auto abi = mlir::dyn_cast<mlir::StringAttr>(attr.getValue());
+    if (!abi)
+      return op->emitOpError()
+             << "expects '" << getCXXABIAttrName() << "' to be a string";
+
+    StringRef abival = abi.getValue();
+    if (!clang::TargetCXXABI::isABI(abival))
+      return op->emitOpError() << "unknown C++ ABI '" << abi.getValue() << "'";
+
+    clang::TargetCXXABI::Kind kind =
+        clang::TargetCXXABI::getKind(abival);
+    if (auto triple = op->getAttrOfType<mlir::StringAttr>(getTripleAttrName()))
+      if (!clang::TargetCXXABI::isSupportedCXXABI(
+              llvm::Triple(triple.getValue()), kind))
+        return op->emitOpError()
+               << "C++ ABI '" << abi.getValue()
+               << "' is not supported on target '" << triple.getValue() << "'";
+
+    switch (kind) {
----------------
bcardosolopes wrote:

The unknown-ABI and triple checks belong in the verifier, but this switch 
doesn't. `cir.cxx_abi = "fuchsia"` on a Fuchsia triple is well-formed IR. It 
just isn't handled by TargetLowering yet, and `createItaniumCXXABI` already 
makes that decision, with `default: llvm_unreachable("Other Itanium ABI?")`. 
Keeping the list here means two copies of the same policy that will drift, and 
the IR stops parsing for a reason unrelated to the IR.

Please drop the switch and turn that `llvm_unreachable` into an NYI emit error 
in the lowering instead. That also covers ABIs that come from the triple 
without the attribute, which this check never sees.

https://github.com/llvm/llvm-project/pull/229494
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to