[flang-commits] [flang] [flang][hlfir] Return function call result as AsExpr. (PR #67769)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Fri Sep 29 02:38:46 PDT 2023


================
@@ -1232,8 +1232,28 @@ genUserCall(Fortran::lower::PreparedActualArguments &loweredActuals,
 
   if (!fir::getBase(result))
     return std::nullopt; // subroutine call.
-  // TODO: "move" non pointer results into hlfir.expr.
-  return extendedValueToHlfirEntity(loc, builder, result, ".tmp.func_result");
+
+  hlfir::Entity resultEntity =
+      extendedValueToHlfirEntity(loc, builder, result, ".tmp.func_result");
+
+  if (!fir::isPointerType(fir::getBase(result).getType())) {
+    // Just load trivial scalars right away.
+    if (resultEntity.isScalar() &&
+        fir::isa_trivial(resultEntity.getFortranElementType()))
+      resultEntity = loadTrivialScalar(loc, builder, resultEntity);
+
+    if (resultEntity.isVariable()) {
+      // Function result must not be freed, since it is allocated on the stack.
----------------
tblah wrote:

What about `hlfir.destroy`? I think in other cases we do create a destroy operation even when the result type does not need deallocation. But I am open to not doing so.

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


More information about the flang-commits mailing list