[flang-commits] [flang] [flang] Disambiguate descriptor and data addresses in FIR AA. (PR #179774)

via flang-commits flang-commits at lists.llvm.org
Thu Feb 5 08:59:57 PST 2026


================
@@ -227,6 +227,34 @@ bool AliasAnalysis::Source::mayBeActualArgWithPtr(
   return false;
 }
 
+// Return true if the two locations cannot alias based
+// on the access data type, e.g. an address of a descriptor
+// cannot alias with an address of data (unless the data
+// may contain a descriptor).
+static bool noAliasBasedOnType(mlir::Value lhs, mlir::Value rhs) {
+  mlir::Type lhsType = lhs.getType();
+  mlir::Type rhsType = rhs.getType();
+  if (!fir::isa_ref_type(lhsType) || !fir::isa_ref_type(rhsType))
+    return false;
+  mlir::Type lhsElemType = fir::unwrapRefType(lhsType);
+  mlir::Type rhsElemType = fir::unwrapRefType(rhsType);
+  if (mlir::isa<fir::BaseBoxType>(lhsElemType) !=
+      mlir::isa<fir::BaseBoxType>(rhsElemType)) {
+    // One of the types is fir.box and another is not.
+    mlir::Type nonBoxType;
+    if (mlir::isa<fir::BaseBoxType>(lhsElemType))
+      nonBoxType = rhsElemType;
+    else
+      nonBoxType = lhsElemType;
+
+    if (!fir::isRecordWithDescriptorMember(nonBoxType)) {
----------------
jeanPerier wrote:

I think you need to be more conservative for fir.class types, and maybe fir.box<none> (polymorphic) since the static type does not allow knowing if they hold a descriptor member.
 
So rejecting `fir::isPolymorphicType(lhsElemType)`.



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


More information about the flang-commits mailing list