[clang] [CIR] Record if c++ ABI was overridden via -fc++-abi flag (PR #229494)

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 8 03:55:53 PDT 2026


================
@@ -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) {
----------------
Fznamznon wrote:

I agree that we should not duplicate the logic. @koparasy , do you? Since you requested this in https://github.com/llvm/llvm-project/pull/229494#discussion_r4199624028 .

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


More information about the cfe-commits mailing list