[PATCH] D128009: [flang] Add semantics test for image_status and add a check

Jean Perier via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 30 01:31:23 PDT 2022


jeanPerier added a comment.

> I am not sure how to ask this question, but if I have an instance of Expr<SomeType> and I know that it is an array (through checking the rank of the argument) , is there a way to unpack the Expr<SomeType> so that I have something like an array of Expr<SomeType>, so that I can iterate over the array and do the check for a non-positive value? This is what I was trying to track down and I couldn't find. I would appreciate any advice or pointing towards portions of code that might be helpful for me to look at, thanks!

An Expr<SomeType> that is an array is not represented as an array of Expr<SomeType> in general because it may not be feasible: e.g. `retrun_some_array()` transformational call cannot be split in an array of `Expr<SomeType>` elements, this needs a lower level representation that will evaluate retrun_some_array in some memory storage first, and this happens only in lowering (and would not matter here, since it is very unlikely we ever could execute the call here at compile time to check for negative elements).

However, there are two kinds of array expressions where you have some opportunities to do some checks: array constants, and array constructors, for those expressions, you can visit all (or some for the array constructor that may also contain array element.

  Expr<SomeType>
           |
       wraps (variant, here you know you should have integers only, so you can use if (const auto *intExpr{UnwrapExpr<Expr<SomeInteger>>(expr)}) { /*your code unwrapping the next level*/}
           |
          \/
  Expr<SomeKind<Category>>>
           |
       wraps (variant, here you can have all kinds, so you have to use std::visit([&](const auto kindExpr&) {  /*your code unwrapping the next level*/ }, intExpr->u); 
           |
          \/
  Expr<Type<Category, Kind>>>
           |
        wraps------------------------------------------------------- or -----wraps ------- or some other nodes you probably can ignore here. Use std::visit(common::visitor ..., kindExpr.u)
           |                                                                                                    |
          \/                                                                                                   \/
  Constant<Type<Category, Kind>>>                                                         ArrayConstructor<Type<Category, Kind>>>
           |                                                                                                    |
          \/                                                                                                   \/
     You can use .values()                                                 You can use for(const auto& arrayCtorValues : arrayConstructor) {...} to loop
     to visit the Scalar<Type<Cat, Kind>> elements.                        through the ArrayConstructorValue that may be expressions, or ImpliedDo
     They have a IsNegative() method.                                      You could only visit the expressions, calling your scalar check again.
  `

Now, as you see this requires some visit effort, and you can go very far if you want to check implied-dos to find a negative constant element somwhere... I think you should simply focus on dealing with the Constant<T> case that is much simpler, and skip the ArrayConstructor<> case. The check you are adding is bonus, having it working on scalar and array constants seems enough to me.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128009/new/

https://reviews.llvm.org/D128009



More information about the llvm-commits mailing list