Similarly to LBOUND in https://reviews.llvm.org/D123237, fix UBOUND() folding
for constant arrays (for both w/ and w/o DIM=): convert
GetConstantArrayLboundHelper into common helper class for both lower/upper
bounds.
Details
Diff Detail
Event Timeline
flang/lib/Evaluate/fold-integer.cpp | ||
---|---|---|
77–78 | Don't know which type is preferred in FE - std::enable_if or maybe constexpr |
Hello, just wanted to push a patch based on https://reviews.llvm.org/D123237#3443084 (which is still in review) to mention similar problem. (Can I somehow set base to different review HEAD, not main branch?)
flang/lib/Evaluate/fold-integer.cpp | ||
---|---|---|
34 | I think the template makes this helper class interface a bit too complex for what it does. I am not sure it is worth making this a template parameter (templates are nice, but they have f18 compile time cost and f18 executable size costs, in this case, I do not think the template adds a lot of type safety). What about doing having an interface like: static Expr<T> GetConstantArrayBound::GetLbound(const Expr<SomeType>&, std::optional<int> dim); with the implementation looking something like: template <typename T> Expr<T> PackageConstantBounds( const ConstantSubscripts &&bounds, bool asScalar = false) { // .... like PackageConstant, but returns Expr<T> } class GetConstantArrayBound { public: static Expr<T> GetConstantArrayBound::GetLbound(const Expr<SomeType>& array, std::optional<ConstantSubscript> dim) { return PackageConstantBounds<T>(GetConstantArrayBound(dim, /*getLbound=*/true)::Get(array), dim.has_value()); } //... same for GetUbound private: // Private ctor ... ConstantSubscripts Get(const Constant<T> &x) { if (getLbound) { // Return the lower bound if (dim_) { return {x.lbounds().at(*dim_)}; } else { return x.lbounds(); } } else { return x.ComputeUbounds(dim_); } } // Deal with the const Parentheses<T> &x. (return ones for lbouds, and the left operand shape for ubound). const std::optional<ConstantSubscript> dim_; const bool getLBound_; } } |
flang/lib/Evaluate/fold-integer.cpp | ||
---|---|---|
34 | Thanks a lot for detailed feedback, suggested change looks much better, updated. |
flang/lib/Evaluate/fold-integer.cpp | ||
---|---|---|
77–81 | Proper UBOUD((x)) is done in https://reviews.llvm.org/D123944 fyi (Did not want to mix changes and simplify review a bit) |
Other than my inlined comment about UBOUND of (cst), this looks good.
flang/lib/Evaluate/fold-integer.cpp | ||
---|---|---|
77 | The UBOUND case if missing for the Parentheses<T> case (need to return the shape). You can probably use GetConstantExtents if you make the FoldingContext& available here, or you can set a flag that parentheses were met and return x.shape() in Get(const Constant<T> &x) in that case. |
flang/lib/Evaluate/fold-integer.cpp | ||
---|---|---|
77 | It's very next PR in sequence (Revision Contents -> Stack) - https://reviews.llvm.org/D123944, could combine into 1 patch if that's better. |
Windows buildbot failed https://lab.llvm.org/buildbot/#/builders/172/builds/11593 after this patch in flang\test\Semantics\select-rank.f90:
******************** TEST 'Flang :: Semantics/select-rank.f90' FAILED ******************** Script: -- : 'RUN: at line 1'; "C:\Python310\python.exe" C:\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\llvm-project\flang\test\Semantics/test_errors.py C:\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\llvm-project\flang\test\Semantics\select-rank.f90 c:\users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\build\bin\flang-new.exe -fc1 -- Exit Code: 1 Command Output (stdout): -- $ ":" "RUN: at line 1" $ "C:\Python310\python.exe" "C:\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\llvm-project\flang\test\Semantics/test_errors.py" "C:\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\llvm-project\flang\test\Semantics\select-rank.f90" "c:\users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\build\bin\flang-new.exe" "-fc1" # command output: PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: c:\\users\\buildbot-worker\\minipc-ryzen-win\\flang-x86_64-windows\\build\\bin\\flang-new.exe -fc1 -fsyntax-only C:\\Users\\buildbot-worker\\minipc-ryzen-win\\flang-x86_64-windows\\llvm-project\\flang\\test\\Semantics\\select-rank.f90 #0 0x00007ff786545e9d (c:\users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\build\bin\flang-new.exe+0xfc5e9d) #1 0x00007ff786561245 (c:\users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\build\bin\flang-new.exe+0xfe1245) #2 0x0000000000000068 #3 0x0000000000000007 error: command failed with exit status: 1 -- ********************
but for now I don't understand the root cause yet (no lbound/ubound in testcase)
(CC @jeanPerier / @klausler )
I do not understand the failure either. It seems the windows bot is green again: https://lab.llvm.org/buildbot/#/builders/172/builds/11594, so this may have been a glitch...
I think the template makes this helper class interface a bit too complex for what it does. I am not sure it is worth making this a template parameter (templates are nice, but they have f18 compile time cost and f18 executable size costs, in this case, I do not think the template adds a lot of type safety).
What about doing having an interface like:
static Expr<T> GetConstantArrayBound::GetLbound(const Expr<SomeType>&, std::optional<int> dim);
and
static Expr<T> GetConstantArrayBound::GetUbound(const Expr<SomeType>&, std::optional<int> dim);
with the implementation looking something like: