[flang-commits] [flang] [flang] Disambiguate derived component accesses in AliasAnalysis. (PR #189516)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Thu Apr 2 03:30:28 PDT 2026


================
@@ -949,6 +1083,45 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
             return;
           }
 
+          // Record component access steps for the access path.
+          //
+          // hlfir.designate carries the component name directly as a
+          // StringAttr, e.g. hlfir.designate %x{"fieldName"}.
+          if (auto designateOp = mlir::dyn_cast<hlfir::DesignateOp>(defOp)) {
+            if (auto comp = designateOp.getComponent()) {
+              Source::PathStep step;
+              step.kind = Source::PathStep::Kind::Component;
+              step.component = *comp;
+              pathSteps.push_back(step);
+            }
+          } else if (auto coordOp = mlir::dyn_cast<fir::CoordinateOp>(defOp)) {
+            // fir.coordinate_of encodes field accesses as integer indices
+            // into the record type's field list (the field_indices attr).
+            // To recover the field name, look up the first static field
+            // index in the base operand's RecordType.  Dynamic indices
+            // (kDynamicIndex) correspond to array subscripts, not named
+            // components, so they are skipped.
+            std::optional<llvm::ArrayRef<int32_t>> fieldIndices =
+                coordOp.getFieldIndices();
+            if (fieldIndices && !fieldIndices->empty() &&
+                (*fieldIndices)[0] != fir::CoordinateOp::kDynamicIndex) {
+              mlir::Type baseTy =
+                  fir::getFortranElementType(coordOp.getRef().getType());
+              if (auto recTy = mlir::dyn_cast<fir::RecordType>(baseTy)) {
+                auto typeList = recTy.getTypeList();
+                int32_t fieldIdx = (*fieldIndices)[0];
----------------
tblah wrote:

Can't the `fir.coordinate_of` have multiple field indexes? I think we need a PathStep for each one

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


More information about the flang-commits mailing list