[flang] Add a way to check and dereference a pointer
authorTim Keith <tkeith@nvidia.com>
Mon, 29 Jul 2019 16:12:52 +0000 (09:12 -0700)
committerTim Keith <tkeith@nvidia.com>
Mon, 29 Jul 2019 16:12:52 +0000 (09:12 -0700)
commit423fcec80189f046b7219b8e22a6c198239a8dc4
tree40566f7d2d002132db0b68ec4c490433eb293ae5
parentde551721e59ead8e787e51e4513b1856c68af41f
[flang] Add a way to check and dereference a pointer

It is common to get a pointer, check it is not null, and dereference it.
Sometimes that requires a named temporary just to be able to do the check.

The macro `DEREF(p)` provides this capability: it asserts that `p` is not null
and returns `*p`. This is analagous to `.value()` on an `std::optional`.

We might want to add a way to disable `CHECK` and the check in `DEREF` together.

This change also includes some examples of making use of `DEREF`.

Original-commit: flang-compiler/f18@d7aa90e55ac80c7f2460ab7b0cb6d1ef0c068938
Reviewed-on: https://github.com/flang-compiler/f18/pull/608
flang/lib/common/idioms.h
flang/lib/semantics/assignment.cc
flang/lib/semantics/check-allocate.cc
flang/lib/semantics/expression.cc
flang/lib/semantics/mod-file.cc
flang/lib/semantics/resolve-names.cc
flang/lib/semantics/scope.cc
flang/lib/semantics/scope.h
flang/lib/semantics/unparse-with-symbols.cc