Le 28/02/2022 à 17:00, Jakub Jelinek a écrit :
On Mon, Feb 28, 2022 at 04:54:24PM +0100, Mikael Morin wrote:
Le 28/02/2022 à 15:27, Kwok Cheung Yeung a écrit :
On 28/02/2022 2:07 pm, Jakub Jelinek wrote:
(...)
Don't we usually test instead || (*expr)->rank != 0 when testing for
scalars?

(...)

So (*expr)->rank is 0 here even with an array. I'm not sure why - is
rank updated later, or did we forget to call something on the event
handle expression?

Testing against n->sym->as for an array check has been used elsewhere in
openmp.cc, to prevent reductions against arrays in OpenACC in
resolve_omp_clauses.

I can’t tell what openmp requires; it depends on your needs.

Checking sym->as captures array variables which may include scalar
expressions (arr(10) is a scalar expression even if arr is an array
variable), while checking expr->rank only capture array expression,
including scalar variable with array subcomponent (scal%array_comp(:) is an
array expression, even if scal is a scalar variable).

gfc_resolve_expr, through gfc_expression_rank takes care of properly setting
expr->rank.
If the check is done at resolution stage (somewhere in resolve_omp_clauses I
guess?), the rank should be set.

I hope it helps.

It is true that the spots I saw in fortran/openmp.cc that test rank look
like:
         if (!gfc_resolve_expr (el->expr)
             || el->expr->ts.type != BT_INTEGER || el->expr->rank != 0)
etc., so probably !gfc_resolve_expr call is missing.

As long as the expression is expected to not be a (contained) function call, I think it should work.

In the general case non-syntaxic errors are preferably checked and reported later at resolution stage, where contained functions are known.

Reply via email to