@@ -2076,21 +2076,27 @@ class ScalarExprLowering {
2076
2076
2077
2077
if (arg.passBy == PassBy::BaseAddress || arg.passBy == PassBy::BoxChar) {
2078
2078
auto argAddr = [&]() -> ExtValue {
2079
- // Non contiguous variable need to be copied into a contiguous temp,
2080
- // and the temp need to be copied back after the call in case it was
2081
- // modified.
2082
- if (Fortran::evaluate::IsVariable (*expr) && expr->Rank () > 0 &&
2083
- !Fortran::evaluate::IsSimplyContiguous (
2084
- *expr, converter.getFoldingContext ())) {
2079
+ ExtValue baseAddr;
2080
+ if (Fortran::evaluate::IsVariable (*expr) && expr->Rank () > 0 ) {
2085
2081
auto box = genBoxArg (*expr);
2086
- auto temp = genTempFromMold (box, " .copyinout" );
2087
- if (arg.mayBeReadByCall ())
2088
- genArrayCopy (temp, box);
2089
- if (arg.mayBeModifiedByCall ())
2090
- copyOutPairs.emplace_back (box, temp);
2091
- return temp;
2092
- }
2093
- auto baseAddr = genExtAddr (*expr);
2082
+ if (!Fortran::evaluate::IsSimplyContiguous (
2083
+ *expr, converter.getFoldingContext ())) {
2084
+ // Non contiguous variable need to be copied into a contiguous
2085
+ // temp, and the temp need to be copied back after the call in
2086
+ // case it was modified.
2087
+ auto temp = genTempFromMold (box, " .copyinout" );
2088
+ if (arg.mayBeReadByCall ())
2089
+ genArrayCopy (temp, box);
2090
+ if (arg.mayBeModifiedByCall ())
2091
+ copyOutPairs.emplace_back (box, temp);
2092
+ return temp;
2093
+ }
2094
+ // Contiguous: just use the box we created above!
2095
+ // This gets "unboxed" below, if needed.
2096
+ baseAddr = box;
2097
+ } else
2098
+ baseAddr = genExtAddr (*expr);
2099
+
2094
2100
// Scalar and contiguous expressions may be lowered to a fir.box,
2095
2101
// either to account for potential polymorphism, or because lowering
2096
2102
// did not account for some contiguity hints.
0 commit comments