[PATCH] fortran: Undo new symbols in all namespaces [PR110996]

2023-09-11 Thread Mikael Morin via Gcc-patches
Hello, this fixes a memory management issue in the fortran frontend. I have included the (reduced) testcase from the PR, even if it wasn't failing here on x86_64 with the test harness. Tested on x86_64-pc-linux-gnu and manually checked the testcase with valgrind. OK for master? -- >8 -- Remove

Re: [PATCH] Fortran: runtime bounds-checking in presence of array constructors [PR31059]

2023-09-01 Thread Mikael Morin via Gcc-patches
Le 31/08/2023 à 22:42, Harald Anlauf via Fortran a écrit : Dear all, gfortran's array bounds-checking code does a mostly reasonable job for array sections in expressions and assignments, but forgot the case that (rank-1) expressions can involve array constructors, which have a shape ;-) The

[PATCH] diagnostics: Delete config pointer before overwriting it.

2023-09-01 Thread Mikael Morin via Gcc-patches
Hello, this is a fix for a small memory leak in the fortran frontend. Tested on x86_64-pc-linux-gnu, nothing stands out besides the apparently well-known guality instability. OK for master ? -- >8 -- Delete m_client_data_hooks before it is reassigned in tree_diagnostics_defaults. This fixes a

Re: [PATCH] fortran: Remove redundant tree walk to delete element

2023-09-09 Thread Mikael Morin via Gcc-patches
Le 08/09/2023 à 23:22, Harald Anlauf via Fortran a écrit : Am 08.09.23 um 12:04 schrieb Mikael Morin via Gcc-patches: Hello, this avoids some redundant work in the symbol deletion code, which is used a lot by the parser to cancel statements that fail to match in the end. I haven't tried

[PATCH] fortran: Remove reference count update [PR108957]

2023-09-15 Thread Mikael Morin via Gcc-patches
Hello, Harald reminded me recently that there was a working patch attached to the PR. I added a documentation comment with the hope that it may help avoid making the same mistake in the future. Regression tested on x86_64-pc-linux-gnu. OK for master? -- >8 -- Remove one reference count

[PATCH] fortran: Remove redundant tree walk to delete element

2023-09-08 Thread Mikael Morin via Gcc-patches
Hello, this avoids some redundant work in the symbol deletion code, which is used a lot by the parser to cancel statements that fail to match in the end. I haven't tried to measure the performance effect, if any, on a pathological example; just passed the fortran testsuite on

Re: [PATCH] Fortran: runtime bounds-checking in presence of array constructors [PR31059]

2023-09-08 Thread Mikael Morin via Gcc-patches
Le 01/09/2023 à 22:48, Harald Anlauf a écrit : Hi Mikael, On 9/1/23 10:41, Mikael Morin via Gcc-patches wrote: May I suggest to handle functions the same way? I'll have a look at them, but will need to gather a few suitable testcases first. I have just opened PR111339 (https://gcc.gnu.org

[PATCH] fortran: Restore interface to its previous state on error [PR48776]

2023-08-27 Thread Mikael Morin via Gcc-patches
Hello, this fixes an old error-recovery bug. Tested on x86_64-pc-linux-gnu. OK for master? -- >8 -- Keep memory of the content of the current interface body being parsed and restore it to its previous state if it has been modified at the time a parse attempt fails. This fixes memory errors

[PATCH 2/4] fortran: Update index extraction code. [PR102043]

2022-04-16 Thread Mikael Morin via Gcc-patches
This avoids a regression on hollerith4.f90 and hollerith6.f90 later in the patch series when code generation for array references is changed to use pointer arithmetic. The problem comes from the extraction of the array index from an ARRAY_REF tree, which doesn’t work if the tree is not an

[PATCH 1/4] fortran: Pre-evaluate string pointers. [PR102043]

2022-04-16 Thread Mikael Morin via Gcc-patches
This avoids a regression on deferred_character_23.f90 later in the patch series when array references are rewritten to use pointer arithmetic. The problem is a SAVE_EXPR tree as TYPE_SIZE_UNIT of one array element type, which is used by the pointer arithmetic expressions. As these expressions

[PATCH 0/4] Use pointer arithmetic for array references [PR102043]

2022-04-16 Thread Mikael Morin via Gcc-patches
4-pc-linux-gnu. OK for master? Mikael Morin (4): fortran: Pre-evaluate string pointers. [PR102043] fortran: Update index extraction code. [PR102043] fortran: Generate an array temporary reference [PR102043] fortran: Use pointer arithmetic to index arrays [PR102043] gcc/fortran/tran

[PATCH 3/4] fortran: Generate an array temporary reference [PR102043]

2022-04-16 Thread Mikael Morin via Gcc-patches
This avoids regressing on char_cast_1.f90 and char_cast_2.f90 later in the patch series when the code generation for array references is changed to use pointer arithmetic. The regressing testcases match part of an array reference in the generated tree dump and it’s not clear how the pattern

[PATCH 4/4] fortran: Use pointer arithmetic to index arrays [PR102043]

2022-04-16 Thread Mikael Morin via Gcc-patches
The code generated for array references used to be ARRAY_REF trees as could be expected. However, the middle-end may conclude from those trees that the indexes used are non-negative (more precisely not below the lower bound), which is a wrong assumption in the case of "reversed- order" arrays.

[PATCH 05/10] fortran: Support clobbering of reference variables [PR41453]

2022-09-16 Thread Mikael Morin via Gcc-patches
This adds support for clobbering of variables passed by reference, when the reference is forwarded to a subroutine as actual argument whose associated dummy has the INTENT(OUT) attribute. This was explicitly disabled and enabling it seems to work, as demonstrated by the new testcase. PR

[PATCH 08/10] fortran: Support clobbering of allocatables and pointers [PR41453]

2022-09-16 Thread Mikael Morin via Gcc-patches
This adds support for clobbering of allocatable and pointer scalar variables passed as actual argument to a subroutine when the associated dummy has the INTENT(OUT) attribute. Support was explicitly disabled, but the clobber generation code seems to support it well, as demonstrated by the newly

[PATCH 10/10] fortran: Support clobbering of derived types [PR41453]

2022-09-16 Thread Mikael Morin via Gcc-patches
This is probably the most risky patch in the series. A previous version of this patch allowing all exactly matching derived types showed two regressions. One of them uncovered PR106817 for which I added a fix in this series, and for the other I have excluded types with allocatable components

[PATCH 07/10] fortran: Support clobbering of ASSOCIATE variables [PR87397]

2022-09-16 Thread Mikael Morin via Gcc-patches
This is in spirit a revert of: r9-3051-gc109362313623d83fe0a5194bceaf994cf0c6ce0 That commit added a condition to avoid generating ICE with clobbers of ASSOCIATE variables. The test added at that point continues to pass if we remove that condition now. PR fortran/87397 PR

[PATCH 09/10] fortran: Support clobbering of variable subreferences [PR88364]

2022-09-16 Thread Mikael Morin via Gcc-patches
This adds support for clobbering of partial variable references, when they are passed as actual argument and the associated dummy has the INTENT(OUT) attribute. Support includes array elements, derived type component references, and complex real or imaginary parts. This is done by removing the

[PATCH 04/10] fortran: Support clobbering with implicit interfaces [PR105012]

2022-09-16 Thread Mikael Morin via Gcc-patches
if there is no information from the procedure interface. gcc/testsuite/ChangeLog: * gfortran.dg/intent_optimize_4.f90: New test. Co-Authored-By: Mikael Morin --- gcc/fortran/trans-expr.cc | 19 +++ .../gfortran.dg/intent_optimize_4.f90 | 24

[PATCH 06/10] fortran: Support clobbering of SAVE variables [PR87395]

2022-09-16 Thread Mikael Morin via Gcc-patches
This is in spirit a revert of: r9-3032-gee7fb0588c6361b4d77337ab0f7527be64fcdde2 That commit added a condition to avoid generating ICE with clobbers of variables with the SAVE attribute. The test added at that point continues to pass if we remove that condition now. PR fortran/87395

[PATCH 02/10] fortran: Fix invalid function decl clobber ICE [PR105012]

2022-09-16 Thread Mikael Morin via Gcc-patches
The fortran frontend, as result symbol for a function without declared result symbol, uses the function symbol itself. This caused an invalid clobber of a function decl to be emitted, leading to an ICE, whereas the intended behaviour was to clobber the function result variable. This change fixes

[PATCH 01/10] fortran: Move the clobber generation code

2022-09-16 Thread Mikael Morin via Gcc-patches
This change inlines the clobber generation code from gfc_conv_expr_reference to the single caller from where the add_clobber flag can be true, and removes the add_clobber argument. What motivates this is the standard making the procedure call a cause for a variable to become undefined, which

[PATCH 03/10] fortran: Move clobbers after evaluation of all arguments [PR106817]

2022-09-16 Thread Mikael Morin via Gcc-patches
For actual arguments whose dummy is INTENT(OUT), we used to generate clobbers on them at the same time we generated the argument reference for the function call. This was wrong if for an argument coming later, the value expression was depending on the value of the just- clobbered argument, and we

[PATCH 00/10] fortran: clobber fixes [PR41453]

2022-09-16 Thread Mikael Morin via Gcc-patches
] Mikael Morin (9): fortran: Move the clobber generation code fortran: Fix invalid function decl clobber ICE [PR105012] fortran: Move clobbers after evaluation of all arguments [PR106817] fortran: Support clobbering of reference variables [PR41453] fortran: Support clobbering of SAVE

[PATCH v2 8/9] fortran: Support clobbering of allocatables and pointers [PR41453]

2022-09-18 Thread Mikael Morin via Gcc-patches
This adds support for clobbering of allocatable and pointer scalar variables passed as actual argument to a subroutine when the associated dummy has the INTENT(OUT) attribute. Support was explicitly disabled, but the clobber generation code seems to support it well, as demonstrated by the newly

[PATCH v2 3/9] fortran: Move clobbers after evaluation of all arguments [PR106817]

2022-09-18 Thread Mikael Morin via Gcc-patches
For actual arguments whose dummy is INTENT(OUT), we used to generate clobbers on them at the same time we generated the argument reference for the function call. This was wrong if for an argument coming later, the value expression was depending on the value of the just- clobbered argument, and we

[PATCH v2 4/9] fortran: Support clobbering with implicit interfaces [PR105012]

2022-09-18 Thread Mikael Morin via Gcc-patches
if there is no information from the procedure interface. gcc/testsuite/ChangeLog: * gfortran.dg/intent_optimize_5.f90: New test. Co-Authored-By: Mikael Morin --- gcc/fortran/trans-expr.cc | 19 +++ .../gfortran.dg/intent_optimize_5.f90 | 24

[PATCH v2 5/9] fortran: Support clobbering of reference variables [PR41453]

2022-09-18 Thread Mikael Morin via Gcc-patches
This adds support for clobbering of variables passed by reference, when the reference is forwarded to a subroutine as actual argument whose associated dummy has the INTENT(OUT) attribute. This was explicitly disabled and enabling it seems to work, as demonstrated by the new testcase. PR

[PATCH v2 1/9] fortran: Move the clobber generation code

2022-09-18 Thread Mikael Morin via Gcc-patches
This change inlines the clobber generation code from gfc_conv_expr_reference to the single caller from where the add_clobber flag can be true, and removes the add_clobber argument. What motivates this is the standard making the procedure call a cause for a variable to become undefined, which

[PATCH v2 0/9] fortran: clobber fixes [PR41453]

2022-09-18 Thread Mikael Morin via Gcc-patches
[PR105012] Mikael Morin (8): fortran: Move the clobber generation code fortran: Fix invalid function decl clobber ICE [PR105012] fortran: Move clobbers after evaluation of all arguments [PR106817] fortran: Support clobbering of reference variables [PR41453] fortran: Support clobbering of SAVE

[PATCH v2 7/9] fortran: Support clobbering of ASSOCIATE variables [PR87397]

2022-09-18 Thread Mikael Morin via Gcc-patches
This is in spirit a revert of: r9-3051-gc109362313623d83fe0a5194bceaf994cf0c6ce0 That commit added a condition to avoid generating ICE with clobbers of ASSOCIATE variables. The test added at that point continues to pass if we remove that condition now. PR fortran/87397 PR

[PATCH v2 9/9] fortran: Support clobbering of derived types [PR41453]

2022-09-18 Thread Mikael Morin via Gcc-patches
This is probably the most risky patch in the series. A previous version of this patch allowing all exactly matching derived types showed two regressions. One of them uncovered PR106817 for which I added a fix in this series, and for the other I have excluded types with allocatable components

[PATCH v2 2/9] fortran: Fix invalid function decl clobber ICE [PR105012]

2022-09-18 Thread Mikael Morin via Gcc-patches
The fortran frontend, as result symbol for a function without declared result symbol, uses the function symbol itself. This caused an invalid clobber of a function decl to be emitted, leading to an ICE, whereas the intended behaviour was to clobber the function result variable. This change fixes

[PATCH v2 6/9] fortran: Support clobbering of SAVE variables [PR87395]

2022-09-18 Thread Mikael Morin via Gcc-patches
This is in spirit a revert of: r9-3032-gee7fb0588c6361b4d77337ab0f7527be64fcdde2 That commit added a condition to avoid generating ICE with clobbers of variables with the SAVE attribute. The test added at that point continues to pass if we remove that condition now. PR fortran/87395

[PATCH 08/14] fortran: Push final procedure expr gen close to its one usage.

2023-07-13 Thread Mikael Morin via Gcc-patches
Final procedure pointer expression is generated in gfc_build_final_call and only used in get_final_proc_ref. Move the generation there. gcc/fortran/ChangeLog: * trans.cc (gfc_add_finalizer_call): Remove local variable final_expr. Pass down expr to get_final_proc_ref and move

[PATCH 06/14] fortran: Reuse final procedure pointer expression

2023-07-13 Thread Mikael Morin via Gcc-patches
Reuse twice the same final procedure pointer expression instead of translating it twice. Final procedure pointer expressions were translated twice, once for the final procedure call, and once for the check for non-nullness (if applicable). gcc/fortran/ChangeLog: * trans.cc

[PATCH 00/14] fortran: Use precalculated class container for deallocation [PR110618]

2023-07-13 Thread Mikael Morin via Gcc-patches
and partially tested with RUNTESTFLAGS="dg.exp=*final*". The complete set has been fully tested on x86_64-pc-linux-gnu. OK for master? [1] https://gcc.gnu.org/pipermail/fortran/2023-July/059582.html [2] https://gcc.gnu.org/pipermail/fortran/2023-July/059583.html Mikael Morin (14): fortra

[PATCH 12/14] fortran: Factor scalar descriptor generation

2023-07-13 Thread Mikael Morin via Gcc-patches
The same scalar descriptor generation code is present twice, in the case of derived type entities, and in the case of polymorphic non-coarray entities. Factor it in preparation for a future third case that will also need the same code for scalar descriptor generation. gcc/fortran/ChangeLog:

[PATCH 05/14] fortran: Add missing cleanup blocks

2023-07-13 Thread Mikael Morin via Gcc-patches
Move cleanup code for the data descriptor after the finalization code as it makes more sense to have it after. Other cleanup blocks should be empty (element size and final pointer are just data references), but add them by the way, just in case. gcc/fortran/ChangeLog: * trans.cc

[PATCH 10/14] fortran: Remove redundant argument in get_var_descr

2023-07-13 Thread Mikael Morin via Gcc-patches
get_var_descr get passed as argument both expr and expr->ts. Remove the type argument which can be retrieved from the other argument. gcc/fortran/ChangeLog: * trans.cc (get_var_descr): Remove argument ts. Use var->ts instead. (gfc_add_finalizer_call): Update caller. ---

[PATCH 13/14] fortran: Use pre-evaluated class container if available [PR110618]

2023-07-13 Thread Mikael Morin via Gcc-patches
Add the possibility to provide a pre-evaluated class container argument to gfc_add_finalizer to avoid repeatedly evaluating data reference expressions in the generated code. PR fortran/110618 gcc/fortran/ChangeLog: * trans.h (gfc_add_finalizer_call): Add class container

[PATCH 01/14] fortran: Outline final procedure pointer evaluation

2023-07-13 Thread Mikael Morin via Gcc-patches
gcc/fortran/ChangeLog: * trans.cc (get_final_proc_ref): New function. (gfc_build_final_call): Outline the pointer evaluation code to get_final_proc_ref. --- gcc/fortran/trans.cc | 27 +-- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git

[PATCH 07/14] fortran: Push element size expression generation close to its usage

2023-07-13 Thread Mikael Morin via Gcc-patches
gfc_add_finalizer_call creates one expression which is only used by the get_final_proc_ref function. Move the expression generation there. gcc/fortran/ChangeLog: * trans.cc (gfc_add_finalizer_call): Remove local variable elem_size. Pass expression to get_elem_size and move the

[PATCH 09/14] fortran: Inline variable definition

2023-07-13 Thread Mikael Morin via Gcc-patches
The variable has_finalizer is only used in one place, inline its definition there. gcc/fortran/ChangeLog: * trans.cc (gfc_add_finalizer_call): Inline definition of variable has_finalizer. Merge nested conditions. --- gcc/fortran/trans.cc | 16 +++- 1 file changed, 7

[PATCH 03/14] fortran: Outline data reference descriptor evaluation

2023-07-13 Thread Mikael Morin via Gcc-patches
gcc/fortran/ChangeLog: * trans.cc (get_var_descr): New function. (gfc_build_final_call): Outline the data reference descriptor evaluation code to get_var_descr. --- gcc/fortran/trans.cc | 149 --- 1 file changed, 83 insertions(+),

[PATCH 02/14] fortran: Outline element size evaluation

2023-07-13 Thread Mikael Morin via Gcc-patches
gcc/fortran/ChangeLog: * trans.cc (get_elem_size): New function. (gfc_build_final_call): Outline the element size evaluation to get_elem_size. --- gcc/fortran/trans.cc | 44 ++-- 1 file changed, 30 insertions(+), 14 deletions(-)

[PATCH 04/14] fortran: Inline gfc_build_final_call

2023-07-13 Thread Mikael Morin via Gcc-patches
Function gfc_build_final_call has been simplified, inline it. gcc/fortran/ChangeLog: * trans.cc (gfc_build_final_call): Inline... (gfc_add_finalizer_call): ... to its one caller. --- gcc/fortran/trans.cc | 66 +--- 1 file changed, 25

[PATCH 11/14] fortran: Outline virtual table pointer evaluation

2023-07-13 Thread Mikael Morin via Gcc-patches
gcc/fortran/ChangeLog: * trans.cc (get_vptr): New function. (gfc_add_finalizer_call): Move virtual table pointer evaluation to get_vptr. --- gcc/fortran/trans.cc | 33 ++--- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git

[PATCH 14/14] fortran: Pass pre-calculated class container argument [pr110618]

2023-07-13 Thread Mikael Morin via Gcc-patches
Pass already evaluated class container argument from gfc_conv_procedure_call down to gfc_add_finalizer_call through gfc_deallocate_scalar_with_status and gfc_deallocate_with_status, to avoid repeatedly evaluating the same data reference expressions in the generated code. PR fortran/110618

[PATCH 2/3] fortran: Factor data references for scalar class argument wrapping [PR92178]

2023-07-11 Thread Mikael Morin via Gcc-patches
In the case of a scalar actual arg passed to a polymorphic assumed-rank dummy with INTENT(OUT) attribute, avoid repeatedly evaluating the actual argument reference by saving a pointer to it. This is non-optimal, but may also be invalid, because the data reference may depend on its own content.

[PATCH 3/3] fortran: Reorder array argument evaluation parts [PR92178]

2023-07-11 Thread Mikael Morin via Gcc-patches
In the case of an array actual arg passed to a polymorphic array dummy with INTENT(OUT) attribute, reorder the argument evaluation code to the following: - first evaluate arguments' values, and data references, - deallocate data references associated with an allocatable, intent(out) dummy, -

[PATCH] fortran: Release symbols in reversed order [PR106050]

2023-07-11 Thread Mikael Morin via Gcc-patches
Hello, I saw the light regarding this PR after Paul posted a comment yesterday. Regression test in progress on x86_64-pc-linux-gnu. I plan to push in the next hours. Mikael -- >8 -- Release symbols in reversed order wrt the order they were allocated. This fixes an error recovery ICE in the

[PATCH 1/3] fortran: defer class wrapper initialization after deallocation [PR92178]

2023-07-11 Thread Mikael Morin via Gcc-patches
If an actual argument is associated with an INTENT(OUT) dummy, and code to deallocate it is generated, generate the class wrapper initialization after the actual argument deallocation. This is achieved by passing a cleaned up expression to gfc_conv_class_to_class, so that the class wrapper

[PATCH 0/3] Fix argument evaluation order [PR92178]

2023-07-11 Thread Mikael Morin via Gcc-patches
-gnu. OK for master? [1] https://gcc.gnu.org/pipermail/fortran/2023-July/059562.html [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110618 Mikael Morin (3): fortran: defer class wrapper initialization after deallocation [PR92178] fortran: Factor data references for scalar class argument

[PATCH] dg-cmp-results: Escape slash from variant argument

2023-08-11 Thread Mikael Morin via Gcc-patches
Hello, I ran into a bug recently, running dg-cmp-results.sh with variant unix/-m32. This fixes it. OK for master? -- >8 -- Escape slash characters in $header variable (coming from the variant argument). This avoids runs with say "unix/-m32" as variant resulting in sed errors "unknown

[PATCH 0/3] fortran: fix length one character dummy args [PR110419]

2023-08-09 Thread Mikael Morin via Gcc-patches
, and powerpc64-unknown-linux-gnu (both -m32 and -m64). OK for master? [1] https://gcc.gnu.org/onlinedocs/gfortran/Argument-passing-conventions.html Mikael Morin (3): fortran: New predicate gfc_length_one_character_type_p fortran: Fix length one character dummy arg type [PR110419] testsuite: Use

[PATCH 3/3] testsuite: Use distinct explicit error codes in value_9.f90

2023-08-09 Thread Mikael Morin via Gcc-patches
Use distinct error codes, so that we can spot directly from the testsuite log which case is failing. gcc/testsuite/ChangeLog: * gfortran.dg/value_9.f90 (val, val4, sub, sub4): Take the error codes from the arguments. (p): Update calls: pass explicit distinct error codes.

[PATCH 2/3] fortran: Fix length one character dummy arg type [PR110419]

2023-08-09 Thread Mikael Morin via Gcc-patches
Revision r14-2171-g8736d6b14a4dfdfb58c80ccd398981b0fb5d00aa changed the argument passing convention for length 1 value dummy arguments to pass just the single character by value. However, the procedure declarations weren't updated to reflect the change in the argument types. This change does the

[PATCH 1/3] fortran: New predicate gfc_length_one_character_type_p

2023-08-09 Thread Mikael Morin via Gcc-patches
Introduce a new predicate to simplify conditionals checking for a character type whose length is the constant one. gcc/fortran/ChangeLog: * gfortran.h (gfc_length_one_character_type_p): New inline function. * check.cc (is_c_interoperable): Use

<    5   6   7   8   9   10