History log of /llvm-project/flang/lib/Evaluate/shape.cpp (Results 1 – 25 of 65)
Revision Date Author Comments
# e252c402 27-Jan-2025 Peter Klausler <pklausler@nvidia.com>

[flang] Fix spurious error due to bad expression shape calculation (#124323)

GetShape() needed to be called with a FoldingContext in order to
properly construct an extent expression for the shape o

[flang] Fix spurious error due to bad expression shape calculation (#124323)

GetShape() needed to be called with a FoldingContext in order to
properly construct an extent expression for the shape of an array
constructor whose elements (nested in an implied DO loop) were not
scalars.

Fixes https://github.com/llvm/llvm-project/issues/124191.

show more ...


# b720b6cb 14-Jan-2025 Peter Klausler <pklausler@nvidia.com>

[flang] Fix crash from fuzzy test. (#122364)

Fixes https://github.com/llvm/llvm-project/issues/122002.


# bf23ae6d 14-Jan-2025 Peter Klausler <pklausler@nvidia.com>

[flang] Fix crash in fuzzed input program (#122193)

Fixes https://github.com/llvm/llvm-project/issues/121971.


# 3a8a52f4 08-Jan-2025 Peter Klausler <pklausler@nvidia.com>

[flang] Make IsCoarray() more accurate (#121415)

A designator without cosubscripts can have subscripts, component
references, substrings, &c. and still have corank. The current
IsCoarray() predica

[flang] Make IsCoarray() more accurate (#121415)

A designator without cosubscripts can have subscripts, component
references, substrings, &c. and still have corank. The current
IsCoarray() predicate only seems to work for whole variable/component
references. This was breaking some cases of THIS_IMAGE().

show more ...


# 94963919 08-Jan-2025 Peter Klausler <pklausler@nvidia.com>

[flang] Fold LCOBOUND & UCOBOUND (#121411)

Implement constant folding for LCOBOUND and UCOBOUND intrinsic
functions. Moves some error detection code from intrinsics.cpp to
fold-integer.cpp so that

[flang] Fold LCOBOUND & UCOBOUND (#121411)

Implement constant folding for LCOBOUND and UCOBOUND intrinsic
functions. Moves some error detection code from intrinsics.cpp to
fold-integer.cpp so that erroneous calls get properly flagged and
converted into known errors.

show more ...


# 73cf0142 24-Jun-2024 jeanPerier <jperier@nvidia.com>

[flang] harden TypeAndShape for assumed-ranks (#96234)

SIZEOF and C_SIZEOF were broken for assumed-ranks because
`TypeAndShape::MeasureSizeInBytes` behaved as a scalar because the
`TypeAndShape::s

[flang] harden TypeAndShape for assumed-ranks (#96234)

SIZEOF and C_SIZEOF were broken for assumed-ranks because
`TypeAndShape::MeasureSizeInBytes` behaved as a scalar because the
`TypeAndShape::shape_` member was the same for scalar and assumed-ranks.

The easy fix would have been to add special handling in
`MeasureSizeInBytes` for assumed-ranks using the TypeAndShape
attributes, but I think this solution would leave `TypeAndShape::shape_`
manipulation fragile to future developers. Hence, I went for the
solution that turn shape_ into a `std::optional<Shape>`.

show more ...


# 8ccb56cf 23-May-2024 Peter Klausler <35819229+klausler@users.noreply.github.com>

[flang] Fix bad shape analysis of assumed-rank dummy (#92936)

Shape analysis for the results of SHAPE, LBOUND, and UBOUND (without
DIM=) needs to account for an assumed-rank dummy argument, and ret

[flang] Fix bad shape analysis of assumed-rank dummy (#92936)

Shape analysis for the results of SHAPE, LBOUND, and UBOUND (without
DIM=) needs to account for an assumed-rank dummy argument, and return a
shape vector with a single unknown element.

show more ...


# 181eab27 29-Jan-2024 jeanPerier <jperier@nvidia.com>

[flang] Set KIND in compiler generated COUNT for SIZE(PACK) (#79801)

Compiler was rewriting SIZE(PACK(x, MASK)) to COUNT(MASK). It was
wrapping the COUNT call without a KIND argument (leading to IN

[flang] Set KIND in compiler generated COUNT for SIZE(PACK) (#79801)

Compiler was rewriting SIZE(PACK(x, MASK)) to COUNT(MASK). It was
wrapping the COUNT call without a KIND argument (leading to INTEGER(4)
result in the characteristics) in an Expr<ExtentType> (implying
INTEGER(8) result), this lead to inconsistencies that later hit verifier
errors in lowering.

Set the KIND argument to the KIND of ExtentType to ensure the built
expression is consistent.

This requires giving access to some safe place where the "kind" name can
be saved and turned into a CharBlock (count has a DIM argument that
require using the KIND keyword here). For the FoldingContext that belong
to SemanticsContext, this is the same string set as the one used by
SemanticsContext for similar purposes.

show more ...


# 7b801233 15-Jan-2024 Peter Klausler <35819229+klausler@users.noreply.github.com>

[flang] More support for assumed-size Cray pointees (#77381)

Recognize Cray pointees as such when they are declared as assumed size
arrays, and don't emit a bogus error message about implied shape

[flang] More support for assumed-size Cray pointees (#77381)

Recognize Cray pointees as such when they are declared as assumed size
arrays, and don't emit a bogus error message about implied shape arrays.

Fixes https://github.com/llvm/llvm-project/issues/77330.

show more ...


# 9bbec0ad 18-Sep-2023 Peter Klausler <35819229+klausler@users.noreply.github.com>

[flang] Fix SIZEOF() expression rewriting (#66241)

The rewriting of the extension intrinsic function SIZEOF was producing
results that would reference symbols that were not available in the
curren

[flang] Fix SIZEOF() expression rewriting (#66241)

The rewriting of the extension intrinsic function SIZEOF was producing
results that would reference symbols that were not available in the
current scope, leading to crashes in lowering. The symbols could be
function result variables, for SIZEOF(func()), or bare derived type
component names, for SIZEOF(array(n)%component). Fixing this without
regressing on a current test case involved careful threading of some
state through the TypeAndShape characterization code and the
shape/bounds analyzer, and some clean-up was done along the way.

show more ...


# 4fed5959 13-Sep-2023 Peter Klausler <35819229+klausler@users.noreply.github.com>

[flang] Correct semantic representation & handling of RANK(*) (#66234)

A RANK(*) case in a SELECT RANK construct selects the case of an
assumed-rank dummy argument whose effective actual argument i

[flang] Correct semantic representation & handling of RANK(*) (#66234)

A RANK(*) case in a SELECT RANK construct selects the case of an
assumed-rank dummy argument whose effective actual argument is an
assumed-size array. In this case, the attributes of the selector are
those of a rank-1 assumed-size array, and the selector cannot be
allocatable or a pointer.

Ensure that the representation of a SELECT RANK construct's per-case
AssocEntityDetails can distinguish RANK(n), RANK(*), and RANK DEFAULT,
and clean up various code sites and tests where the distinctions matter.

show more ...


# 057564fe 10-Sep-2023 Tianlan Zhou <bobby825@126.com>

Fix some typos in comments: evalute -> evaluate (NFC) (#65906)


# 0c0b2ea9 11-Aug-2023 Peter Klausler <pklausler@nvidia.com>

[flang] Check procedure pointer initializations; clean up ELEMENTAL

Implements compatibility checking for initializers in procedure pointer
declarations. This work exposed some inconsistency in how

[flang] Check procedure pointer initializations; clean up ELEMENTAL

Implements compatibility checking for initializers in procedure pointer
declarations. This work exposed some inconsistency in how ELEMENTAL
interfaces were handled and checked, from both unrestricted intrinsic
functions and others, and some refinements needed for function result
compatbility checking; these have also been ironed out. Some new
warnings are now emitted, and this affected a dozen or so tests.

Differential Revision: https://reviews.llvm.org/D159026

show more ...


# 16c4b320 25-Jul-2023 Peter Klausler <pklausler@nvidia.com>

[flang] Correct handling of non-default lower bounds in ASSOCIATE with named constants

Work through several issues with LBOUND() and UBOUND() of ASSOCIATE
construct entities that have been associate

[flang] Correct handling of non-default lower bounds in ASSOCIATE with named constants

Work through several issues with LBOUND() and UBOUND() of ASSOCIATE
construct entities that have been associated with named constants or
subobjects of named constants that are sporting non-default lower bounds.
Sometimes the non-default lower bounds matter, sometimes they don't.
Add a fairly exhaustive test to work through the possibilities.

Differential Revision: https://reviews.llvm.org/D156756

show more ...


# fb7366ca 27-Jul-2023 Slava Zakharin <szakharin@nvidia.com>

[flang] Fixed shape computation for elementals with optional dummys.

It looks like a regression after D151737: shape of the elemental
call became rank-0.

Reviewed By: klausler

Differential Revisio

[flang] Fixed shape computation for elementals with optional dummys.

It looks like a regression after D151737: shape of the elemental
call became rank-0.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D156386

show more ...


# 7db4c583 02-Jun-2023 Peter Klausler <pklausler@nvidia.com>

[flang] Fix crash in shape analysis of PACK()

A CHECK() was firing when a call to the PACK intrinsic does not have a
VECTOR= argument and at least one dimension of the shape of the ARRAY=
argument c

[flang] Fix crash in shape analysis of PACK()

A CHECK() was firing when a call to the PACK intrinsic does not have a
VECTOR= argument and at least one dimension of the shape of the ARRAY=
argument could not be determined. The CHECK was inappropriate, since
this can of course happen, such as when that argument is the result
of the SPREAD() intrinsic with non-constant DIM= or NCOPIES= arguments.
Replace with an if() statement.

Differential Revision: https://reviews.llvm.org/D152212

show more ...


# 71d5a949 25-May-2023 Peter Klausler <pklausler@nvidia.com>

[flang] Don't fold SIZE()/SHAPE() into expression referencing optional dummy arguments

When computing the shape of an expression at compilation time as part of
folding an intrinsic function like SIZ

[flang] Don't fold SIZE()/SHAPE() into expression referencing optional dummy arguments

When computing the shape of an expression at compilation time as part of
folding an intrinsic function like SIZE(), don't create an expression that
increases a dependence on the presence of an optional dummy argument.

Differential Revision: https://reviews.llvm.org/D151737

show more ...


# aca9016b 02-Feb-2023 Peter Klausler <pklausler@nvidia.com>

[flang] Fix crash on SELECT RANK

In some circumstances, such as in compile-time array shape analysis,
clients of the utility function ResolveAssociations() don't really
want it to drill all of the w

[flang] Fix crash on SELECT RANK

In some circumstances, such as in compile-time array shape analysis,
clients of the utility function ResolveAssociations() don't really
want it to drill all of the way down to an assumed-rank dummy argument.
Add a variation, ResolveAssociationsExceptSelectRank(), that
will return a specific rank case's AssocEntity symbol instead.
This fixes a crash in subscript validation checking that stemmed from
deducing an incorrect number of lower and upper bound expressions
from a specific rank case association entity.

Differential Revision: https://reviews.llvm.org/D143778

show more ...


# 635656f4 16-Dec-2022 Peter Klausler <pklausler@nvidia.com>

[flang] Expunge needless semantics::ProcInterface

The ProcInterface structure is used only by ProcEntityDetails; it represents
what a program might have put in parentheses in a procedure-declaration

[flang] Expunge needless semantics::ProcInterface

The ProcInterface structure is used only by ProcEntityDetails; it represents
what a program might have put in parentheses in a procedure-declaration-stmt,
either the name of a procedure interface or a declaration-type-spec.

If a procedure entity has an implicit interface, the function result
type (if any) can be kept in EntityDetails::type_, which already exists
and is currently redundant for ProcEntityDetails symbols.

All that is really needed is a nullable Symbol pointer in ProcEntityDetails
to point to the procedure's explicit interface, when it has one.

Also, catch the case where a procedure has an explicit interface
and a program attempts to also give it a type.

Differential Revision: https://reviews.llvm.org/D140134

show more ...


# 19d11b4d 21-Sep-2022 Peter Klausler <pklausler@nvidia.com>

[flang] Allow "non-expandable" scalars in single-element contexts

When a scalar expression is not expandable -- i.e., it would have to be
evaluated once and saved in a temporary to avoid changing th

[flang] Allow "non-expandable" scalars in single-element contexts

When a scalar expression is not expandable -- i.e., it would have to be
evaluated once and saved in a temporary to avoid changing the semantics
of the program if it were to be evaluated more than once -- it affects
some aspects of folding and expression semantics. In cases where
scalar expansion would not cause multiple evaluations due to the shape
of the result having but a single element, however, these "non-expandable"
scalar expressions can be safely allowed.

Differential Revision: https://reviews.llvm.org/D134476

show more ...


# c4a73957 21-Sep-2022 Jean Perier <jperier@nvidia.com>

[flang] Limit shape inquiries rewrite to associate construct entity

The previous code was rewriting all shape inquires on associate
construct entities to inquires on the associated expression or var

[flang] Limit shape inquiries rewrite to associate construct entity

The previous code was rewriting all shape inquires on associate
construct entities to inquires on the associated expression or variable.

This is is incorrect because at the point of inquiry, some statement
between the association and the inquiry may have modified the expression
operands or variable in a way that changes its shapes or bounds.

For instance, in the example below, expression rewrites was previously
replacing `size(x, 1)` by `size(p, 1)` which is invalid if p is a
pointer.

```
associate(x => p + 1)
call call_that_may_modify_p_shape()
print *, size(x, 1)
end associate
```

This change restricts rewrites of shape inquiries on associate construct entity
to use the associated expression shape and bounds if and only if the
shape/bounds are compile time constant. Otherwise, this may be invalid.

Differential Revision: https://reviews.llvm.org/D133857

show more ...


# be68a6ad 08-Jul-2022 Peter Klausler <pklausler@nvidia.com>

[flang] Error detection/avoidance for TRANSFER with empty MOLD= type

When MOLD= is an array and there is no SIZE= in a call to TRANSFER(),
the size of an element of the MOLD= is used as the denomina

[flang] Error detection/avoidance for TRANSFER with empty MOLD= type

When MOLD= is an array and there is no SIZE= in a call to TRANSFER(),
the size of an element of the MOLD= is used as the denominator in a
division to establish the extent of the vector result. When the
total storage size of the SOURCE= is known to be zero, the result is
empty and no division is needed.

To avoid a division by zero at runtime, we need to check for a zero-sized
MOLD= element type when the storage size of SOURCE= is nonzero and there
is no SIZE=. Further, in the compilation-time rewriting of calls to
SHAPE(TRANSFER(...)) and SIZE(TRANSFER(...)) for constant folding and
simplification purposes, we can't replace the call with an arithmetic
element count expression when the storage size of SOURCE= is not known
to be zero and the element size of MOLD= is not known to be nonzero at
compilation time.

These changes mostly affect tests using a MOLD= argument that is an
assumed-length character.

Differential Revision: https://reviews.llvm.org/D129680

show more ...


# cd03e96f 23-Mar-2022 Peter Klausler <pklausler@nvidia.com>

[flang] Add & use a better visit() (take 2)

Adds flang/include/flang/Common/log2-visit.h, which defines
a Fortran::common::visit() template function that is a drop-in
replacement for std::visit().

[flang] Add & use a better visit() (take 2)

Adds flang/include/flang/Common/log2-visit.h, which defines
a Fortran::common::visit() template function that is a drop-in
replacement for std::visit(). Modifies most use sites in
the front-end and runtime to use common::visit().

The C++ standard mandates that std::visit() have O(1) execution
time, which forces implementations to build dispatch tables.
This new common::visit() is O(log2 N) in the number of alternatives
in a variant<>, but that N tends to be small and so this change
produces a fairly significant improvement in compiler build
memory requirements, a 5-10% improvement in compiler build time,
and a small improvement in compiler execution time.

Building with -DFLANG_USE_STD_VISIT causes common::visit()
to be an alias for std::visit().

Calls to common::visit() with multiple variant arguments
are referred to std::visit(), pending further work.

This change is enabled only for GCC builds with GCC >= 9;
an earlier attempt (D122441) ran into bugs in some versions of
clang and was reverted rather than simply disabled; and it is
not well tested with MSVC. In non-GCC and older GCC builds,
common::visit() is simply an alias for std::visit().

show more ...


# ca2be81e 06-Apr-2022 Peter Klausler <pklausler@nvidia.com>

[flang] Fix Symbol::Rank for ProcEntityDetails

When a procedure pointer or procedure dummy argument has a
defined interface, the rank of the pointer (or dummy) is the
rank of the interface.

Also tw

[flang] Fix Symbol::Rank for ProcEntityDetails

When a procedure pointer or procedure dummy argument has a
defined interface, the rank of the pointer (or dummy) is the
rank of the interface.

Also tweak code discovered in shape analysis when investigating
this problam so that it returns a vector of emptied extents rather
than std::nullopt when the extents are not scope-invariant, so that
the rank can at least be known.

Differential Revision: https://reviews.llvm.org/D123727

show more ...


# d0549597 01-Apr-2022 Peter Klausler <pklausler@nvidia.com>

[flang] Fix shape analysis of RESHAPE result

Shape analysis of RESHAPE(..., SHAPE=s) should of course return
the SHAPE= actual argument when it is constant; but when it is
not, its length is still k

[flang] Fix shape analysis of RESHAPE result

Shape analysis of RESHAPE(..., SHAPE=s) should of course return
the SHAPE= actual argument when it is constant; but when it is
not, its length is still known, and thus so is the rank of the
result of RESHAPE(), and shape analysis should at least return
a shape vector of the right length rather than a result that
makes the result appear to be a scalar, which can lead to some
bogus error messages.

Also, while here: rename a private GetShapeHelper::AsShape()
routine so that it can't be confused with the ones in the API
of shape.h.

Differential Revision: https://reviews.llvm.org/D123712

show more ...


123