[flang-commits] [flang] [flang] fix isSimplyContiguous and isOptional hlfir::Entity methods (PR #125215)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Fri Jan 31 09:40:03 PST 2025


================
@@ -221,6 +221,25 @@ bool hlfir::Entity::mayHaveNonDefaultLowerBounds() const {
   return true;
 }
 
+mlir::Operation *traverseConverts(mlir::Operation *op) {
+  while (auto convert = llvm::dyn_cast_or_null<fir::ConvertOp>(op))
+    op = convert.getValue().getDefiningOp();
+  return op;
+}
+
+bool hlfir::Entity::mayBeOptional() const {
+  if (!isVariable())
+    return false;
+  // TODO: introduce a fir type to better identify optionals.
+  if (mlir::Operation *op = traverseConverts(getDefiningOp())) {
+    if (auto varIface = llvm::dyn_cast<fir::FortranVariableOpInterface>(op))
+      return varIface.isOptional();
+    return !llvm::isa<fir::AllocaOp, fir::AllocMemOp, fir::ReboxOp,
+                      fir::EmboxOp, fir::LoadOp>(op);
----------------
tblah wrote:

Agreed. Thanks for explaining.

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


More information about the flang-commits mailing list