[flang-commits] [flang] Use the RHS of a pointer assignment inside of FORALL if it is already of `boxType` instead of `convertToBox` again. (PR #165771)

Daniel Chen via flang-commits flang-commits at lists.llvm.org
Fri Oct 31 07:13:58 PDT 2025


================
@@ -258,13 +258,19 @@ void fir::factory::AnyVariableStack::pushValue(mlir::Location loc,
                                                fir::FirOpBuilder &builder,
                                                mlir::Value variable) {
   hlfir::Entity entity{variable};
-  mlir::Type storageElementType =
-      hlfir::getFortranElementType(retValueBox.getType());
-  auto [box, maybeCleanUp] =
-      hlfir::convertToBox(loc, builder, entity, storageElementType);
-  fir::runtime::genPushDescriptor(loc, builder, opaquePtr, fir::getBase(box));
-  if (maybeCleanUp)
-    (*maybeCleanUp)();
+  if (mlir::isa<fir::BaseBoxType>(entity.getType())) {
----------------
DanielCChen wrote:

Thanks for the quick review and suggestion!

The following is the revised code based on your suggestion that also fixed the issue this PR is intended.
```
void fir::factory::AnyVariableStack::pushValue(mlir::Location loc,
                                               fir::FirOpBuilder &builder,
                                               mlir::Value variable) {
  hlfir::Entity entity{variable};
  mlir::Value box =
      hlfir::genVariableBox(loc, builder, entity, entity.getBoxType());
  fir::runtime::genPushDescriptor(loc, builder, opaquePtr, fir::getBase(box));
}
```

Would this be good?

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


More information about the flang-commits mailing list