[flang-commits] [flang] [flang] emit declare for function result before call (PR #177615)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Fri Jan 23 09:47:03 PST 2026


================
@@ -61,9 +61,9 @@ end module maxtype_mod
 !CHECK:    %[[OMP_IN_DECL:.*]]:2 = hlfir.declare %[[OMP_IN]] {uniq_name = "omp_in"} : (!fir.ref<[[MAXTYPE]]>) -> (!fir.ref<[[MAXTYPE]]>, !fir.ref<[[MAXTYPE]]>)
 !CHECK:    fir.store %[[LHS_ARG]] to %[[OMP_OUT]] : !fir.ref<[[MAXTYPE]]>
 !CHECK:    %[[OMP_OUT_DECL:.*]]:2 = hlfir.declare %[[OMP_OUT]] {uniq_name = "omp_out"} : (!fir.ref<[[MAXTYPE]]>) -> (!fir.ref<[[MAXTYPE]]>, !fir.ref<[[MAXTYPE]]>)
+!CHECK:    %[[TMPRESULT:.*]]:2 = hlfir.declare %[[RESULT]] {uniq_name = ".tmp.func_result"} : (!fir.ref<[[MAXTYPE]]>) -> (!fir.ref<[[MAXTYPE]]>, !fir.ref<[[MAXTYPE]]>)
----------------
vzakhari wrote:

It would be great to use `TMPRESULT` below in `fir.save_result` instead of `RESULT`.  The TBAA tags assignment looks for the instantiation point, i.e. `fir.declare`, and when coming from `RESULT` reference in `fir.save_result` it won't be able to find one - instead, it will stop at `fir.alloca`.  So any store into `RESULT` generated as a result of inlining and handling `fir.save_result` will probably go into its own function root with `null` scope. I think this should be safe, but may be suboptimal.

I guess this change will require a bit more restructuring of the code, so I agree with the current approach.

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


More information about the flang-commits mailing list