[flang] Fix bug converting actual argument to Fortran
authorTim Keith <tkeith@nvidia.com>
Fri, 7 Dec 2018 15:41:49 +0000 (07:41 -0800)
committerTim Keith <tkeith@nvidia.com>
Fri, 7 Dec 2018 15:41:49 +0000 (07:41 -0800)
This fixes a problem with converting the ubound call in the example
below back to Fortran (in this case, for writing to the .mod file).
One of the ActualArguments encountered in ProcedureRef::AsFortran is
a `std::nullopt`, so we need to handle that case.

```
module m
  real :: x(10)
  real :: y(ubound(x, dim=1))
end module
```

Original-commit: flang-compiler/f18@c5ace6b8241cd1ef86f0649941bf38386d99bdc4
Reviewed-on: https://github.com/flang-compiler/f18/pull/240

flang/lib/evaluate/call.cc

index 6b90e27..8f159c3 100644 (file)
@@ -49,8 +49,10 @@ std::ostream &ProcedureRef::AsFortran(std::ostream &o) const {
   proc_.AsFortran(o);
   char separator{'('};
   for (const auto &arg : arguments_) {
-    arg->AsFortran(o << separator);
-    separator = ',';
+    if (arg.has_value()) {
+      arg->AsFortran(o << separator);
+      separator = ',';
+    }
   }
   if (separator == '(') {
     o << '(';