[flang-commits] [flang] [flang] fix regression with optional after PR125059 (PR #125215)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Fri Jan 31 07:11:36 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:
nit: I'm nervous about lists like this because it is easy to forget to update them. Maybe check if it is a function argument?
https://github.com/llvm/llvm-project/pull/125215
More information about the flang-commits
mailing list