[flang-commits] [flang] [Flang] Propogate fir.declare attributes through cg-rewrite (PR #137207)

via flang-commits flang-commits at lists.llvm.org
Wed Apr 30 01:43:19 PDT 2025


================
@@ -299,11 +299,17 @@ class DeclareOpConversion : public mlir::OpRewritePattern<fir::DeclareOp> {
       else
         return mlir::failure();
     }
-    // FIXME: Add FortranAttrs and CudaAttrs
+
     auto xDeclOp = rewriter.create<fir::cg::XDeclareOp>(
         loc, declareOp.getType(), declareOp.getMemref(), shapeOpers, shiftOpers,
         declareOp.getTypeparams(), declareOp.getDummyScope(),
         declareOp.getUniqName());
+
+    // Propagate all attributes to fircg.ext_declare to avoid losing metadata
+    // including CUDA and OpenACC attributes.
+    for (const mlir::NamedAttribute &attr : declareOp->getAttrs())
+      xDeclOp->setAttr(attr.getName(), attr.getValue());
----------------
jeanPerier wrote:

How is this not overriding the `operandSegmentSizes` attribute of the AttrSizedOperandSegments interface of the newly created xDeclOp with the one from the declareOp?

I would suggest checking if the attributes names are not already used in the xDeclop to avoid any issues.


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


More information about the flang-commits mailing list