[PATCH] D105500: [flang] Prevent rewrite of shape inquiries to non constant explicit expr
Jean Perier via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 6 10:12:19 PDT 2021
jeanPerier created this revision.
jeanPerier added reviewers: klausler, PeteSteinfeld.
jeanPerier added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a reviewer: sscalpone.
jeanPerier requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Shape analysis was building expressions using non constant explicit bounds.
This caused issues because shape analysis is actively used in front-end
expression rewrites, regardless of the context. When rewriting expressions
inside execution parts it is not guaranteed that non constant specification
expressions will evaluate to the same value they would inside the specification
parts.
Example:
fortran
subroutine foo(n)
real :: x(n)
n = n + 100
print *, size(x, 1)
end subroutine
Was unparsed with `f18 -funparse` to the following program that is not
semantically equivalent:
fortran
SUBROUTINE foo (n)
REAL x(n)
n=n+100_4
PRINT *, int(int(n,kind=8)-1_8+1_8,kind=4)
END SUBROUTINE
Currently, this impacted at least all rewrites of LBOUND, UBOUND, SIZE, SHAPE,
and SIZEOF.
This patch prevents usage of non constant explicit bounds in shape analysis
results, except when requested by the shape analysis user (in contexts where it
is known to be safe to use these). Otherwise, evaluate::DescriptorInquiry are
generated. The only place where keeping non constant explicit bounds in shape
analysis appeared to be needed so far was runtime type info generation (for
derived types).
I considered fixing it at the folding level (by discarding non constant results from
shape analysis), but it seemed less solid (more places to secure, hard to enforce all
usages of shape analysis do not end-up used somewhere else now or in the future). Also,
Being able to rewrite `size(x+y)` where y is an array to `size(y)` is safe and still an
improvement, and naively discarding non constant shape analysis results in folding was
preventing that from happening.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D105500
Files:
flang/include/flang/Evaluate/shape.h
flang/lib/Evaluate/shape.cpp
flang/lib/Semantics/runtime-type-info.cpp
flang/test/Semantics/modfile33.f90
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105500.356770.patch
Type: text/x-patch
Size: 10037 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210706/83be1439/attachment.bin>
More information about the llvm-commits
mailing list