[gcc r15-6908] c++: Fix up maybe_init_list_as_array for RAW_DATA_CST [PR118124]

2025-01-15 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:64828272cde415bf2d7222eec87147ba84980f3d

commit r15-6908-g64828272cde415bf2d7222eec87147ba84980f3d
Author: Jakub Jelinek 
Date:   Wed Jan 15 08:53:13 2025 +0100

c++: Fix up maybe_init_list_as_array for RAW_DATA_CST [PR118124]

The previous patch made me look around some more and I found
maybe_init_list_as_array doesn't handle RAW_DATA_CSTs correctly either,
while the RAW_DATA_CST is properly split during finish_compound_literal,
it was using CONSTRUCTOR_NELTS as the size of the arrays, which is wrong,
RAW_DATA_CST could stand for far more initializers.

2025-01-15  Jakub Jelinek  

PR c++/118124
* cp-tree.h (build_array_of_n_type): Change second argument type
from int to unsigned HOST_WIDE_INT.
* tree.cc (build_array_of_n_type): Likewise.
* call.cc (count_ctor_elements): New function.
(maybe_init_list_as_array): Use it instead of CONSTRUCTOR_NELTS.
(convert_like_internal): Use length from init's type instead of
len when handling the maybe_init_list_as_array case.

* g++.dg/cpp0x/initlist-opt5.C: New test.

Diff:
---
 gcc/cp/call.cc | 23 ---
 gcc/cp/cp-tree.h   |  2 +-
 gcc/cp/tree.cc |  2 +-
 gcc/testsuite/g++.dg/cpp0x/initlist-opt5.C | 23 +++
 4 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 65d613e37b30..63be8b58906b 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -4331,6 +4331,20 @@ has_non_trivial_temporaries (tree expr)
   return false;
 }
 
+/* Return number of initialized elements in CTOR.  */
+
+static unsigned HOST_WIDE_INT
+count_ctor_elements (tree ctor)
+{
+  unsigned HOST_WIDE_INT len = 0;
+  for (constructor_elt &e: CONSTRUCTOR_ELTS (ctor))
+if (TREE_CODE (e.value) == RAW_DATA_CST)
+  len += RAW_DATA_LENGTH (e.value);
+else
+  ++len;
+  return len;
+}
+
 /* We're initializing an array of ELTTYPE from INIT.  If it seems useful,
return INIT as an array (of its own type) so the caller can initialize the
target array in a loop.  */
@@ -4392,7 +4406,8 @@ maybe_init_list_as_array (tree elttype, tree init)
   if (!is_xible (INIT_EXPR, elttype, copy_argtypes))
 return NULL_TREE;
 
-  tree arr = build_array_of_n_type (init_elttype, CONSTRUCTOR_NELTS (init));
+  unsigned HOST_WIDE_INT len = count_ctor_elements (init);
+  tree arr = build_array_of_n_type (init_elttype, len);
   arr = finish_compound_literal (arr, init, tf_none);
   DECL_MERGEABLE (TARGET_EXPR_SLOT (arr)) = true;
   return arr;
@@ -8801,7 +8816,7 @@ convert_like_internal (conversion *convs, tree expr, tree 
fn, int argnum,
   {
/* Conversion to std::initializer_list.  */
tree elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (totype), 0);
-   unsigned len = CONSTRUCTOR_NELTS (expr);
+   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (expr);
tree array;
 
if (tree init = maybe_init_list_as_array (elttype, expr))
@@ -8809,7 +8824,9 @@ convert_like_internal (conversion *convs, tree expr, tree 
fn, int argnum,
elttype
  = cp_build_qualified_type (elttype, (cp_type_quals (elttype)
   | TYPE_QUAL_CONST));
-   array = build_array_of_n_type (elttype, len);
+   tree index_type = TYPE_DOMAIN (TREE_TYPE (init));
+   array = build_cplus_array_type (elttype, index_type);
+   len = TREE_INT_CST_LOW (TYPE_MAX_VALUE (index_type)) + 1;
array = build_vec_init_expr (array, init, complain);
array = get_target_expr (array);
array = cp_build_addr_expr (array, complain);
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index b65a2677b4ec..2d17c4c77b56 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -8179,7 +8179,7 @@ extern tree build_aggr_init_expr  (tree, tree);
 extern tree get_target_expr(tree,
 tsubst_flags_t = 
tf_warning_or_error);
 extern tree build_cplus_array_type (tree, tree, int is_dep = -1);
-extern tree build_array_of_n_type  (tree, int);
+extern tree build_array_of_n_type  (tree, unsigned HOST_WIDE_INT);
 extern bool array_of_runtime_bound_p   (tree);
 extern bool vla_type_p (tree);
 extern tree build_array_copy   (tree);
diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index dd6e872e4e77..988e99d18bbb 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -1207,7 +1207,7 @@ build_cplus_array_type (tree elt_type, tree index_type, 
int dependent)
 /* Return an ARRAY_TYPE with element type ELT and length N.  */
 
 tree
-build_array_of_n_type (tree elt, int n)
+build_array_of_n_type (tree elt, unsigned HOST_WIDE_INT n)
 {
   return build_cplus_

[gcc r15-6913] Annotate dbg_line_numbers table

2025-01-15 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:bea593f115bccffcb2570fc9cd642403193265d9

commit r15-6913-gbea593f115bccffcb2570fc9cd642403193265d9
Author: Richard Biener 
Date:   Wed Jan 15 11:25:25 2025 +0100

Annotate dbg_line_numbers table

The following adds /*  */ to dbg_line_numbers so there's the chance
to more easily lookup the ID of the match.pd line number used for
dumping when you want to debug a speicific replacement.  It also cuts
the lines down to 10 entries.

  static int dbg_line_numbers[1267] = {
/* 0 */ 161, 164, 173, 175, 178, 181, 183, 189, 197, 195,
/* 10 */ 199, 201, 205, 923, 921, 2060, 2071, 2052, 2058, 2063,
...

* genmatch.cc (define_dump_logs): Make reverse lookup in
dbg_line_numbers easier by adding comments with start index
and cutting number of elements per line to 10.

Diff:
---
 gcc/genmatch.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc
index 3ba6139e12da..b9a792e24554 100644
--- a/gcc/genmatch.cc
+++ b/gcc/genmatch.cc
@@ -890,8 +890,8 @@ define_dump_logs (bool gimple, FILE *f)
 
   for (unsigned i = 0; i < dbg_line_numbers.length () - 1; i++)
 {
-  if (i % 20 == 0)
-   fprintf (f, "\n\t");
+  if (i % 10 == 0)
+   fprintf (f, "\n\t/* %d */ ", i);
 
   fprintf (f, "%d, ", dbg_line_numbers[i]);
 }


[gcc r15-6911] OpenMP/C++: Fix 'declare variant' for struct-returning functions [PR118486]

2025-01-15 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:b67a0d6aca0c049e14e44c3f28ce3806680543ef

commit r15-6911-gb67a0d6aca0c049e14e44c3f28ce3806680543ef
Author: Tobias Burnus 
Date:   Wed Jan 15 10:47:29 2025 +0100

OpenMP/C++: Fix 'declare variant' for struct-returning functions [PR118486]

To find the variant declaration, a call is constructed in
omp_declare_variant_finalize_one, which gives here:
  TARGET_EXPR 

Extracting now the function declaration failed and gave the bogus
  error: could not find variant declaration

Solution: Use the 2nd argument of the TARGET_EXPR and continue.

PR c++/118486

gcc/cp/ChangeLog:

* decl.cc (omp_declare_variant_finalize_one): When resolving
the variant to use, handle variant calls with TARGET_EXPR.

gcc/testsuite/ChangeLog:

* g++.dg/gomp/declare-variant-11.C: New test.

Diff:
---
 gcc/cp/decl.cc |  3 ++
 gcc/testsuite/g++.dg/gomp/declare-variant-11.C | 38 ++
 2 files changed, 41 insertions(+)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 90e9a7fc7cb5..0532c68e35dd 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -8552,6 +8552,9 @@ omp_declare_variant_finalize_one (tree decl, tree attr)
   if (variant == error_mark_node && !processing_template_decl)
 return true;
 
+  if (TREE_CODE (variant) == TARGET_EXPR)
+variant = TARGET_EXPR_INITIAL (variant);
+
   variant = cp_get_callee_fndecl_nofold (STRIP_REFERENCE_REF (variant));
   input_location = save_loc;
 
diff --git a/gcc/testsuite/g++.dg/gomp/declare-variant-11.C 
b/gcc/testsuite/g++.dg/gomp/declare-variant-11.C
new file mode 100644
index ..56b2556416c8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/declare-variant-11.C
@@ -0,0 +1,38 @@
+/* { dg-additional-options "-fdump-tree-gimple" }  */
+
+/* PR c++/118486  */
+
+struct NotAnInt {};
+
+// Wrong return type:
+NotAnInt var1();
+#pragma omp declare variant(var1) match(user={condition(true)})
+int base1();
+/* { dg-error "variant 'NotAnInt var1\\(\\)' and base 'int base1\\(\\)' have 
incompatible types" "" { target *-*-* } .-2 } */
+
+
+// Wrong return type:
+NotAnInt var2();
+float var2(float);
+#pragma omp declare variant(var2) match(user={condition(true)})
+int base2();
+/* { dg-error "variant 'NotAnInt var2\\(\\)' and base 'int base2\\(\\)' have 
incompatible types" "" { target *-*-* } .-2 } */
+
+
+// OK:
+NotAnInt var3();
+#pragma omp declare variant(var3) match(user={condition(true)})
+NotAnInt base3();
+
+void f()
+{
+  // int x;
+  NotAnInt y;
+
+  //x = base1 ();
+  //x = base2 ();
+  y = base3 ();
+}
+
+/* { dg-final { scan-tree-dump "var3 \\(\\);" "gimple" } }  */
+/* { dg-final { scan-tree-dump-not "base3" "gimple" } }  */


[gcc r15-6909] c++: Delete defaulted operator <=> if std::strong_ordering::equal doesn't convert to its rettype [PR

2025-01-15 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:18f6bb9899209ccd41c476254d30596606c81dd7

commit r15-6909-g18f6bb9899209ccd41c476254d30596606c81dd7
Author: Jakub Jelinek 
Date:   Wed Jan 15 08:56:40 2025 +0100

c++: Delete defaulted operator <=> if std::strong_ordering::equal doesn't 
convert to its rettype [PR118387]

Note, the PR raises another problem.
If on the same testcase the B b; line is removed, we silently synthetize
operator<=> which will crash at runtime due to returning without a return
statement.  That is because the standard says that in that case
it should return static_cast(std::strong_ordering::equal);
but I can't find anywhere wording which would say that if that isn't
valid, the function is deleted.
https://eel.is/c++draft/class.compare#class.spaceship-2.2
seems to talk just about cases where there are some members and their
comparison is invalid it is deleted, but here there are none and it
follows
https://eel.is/c++draft/class.compare#class.spaceship-3.sentence-2
So, we synthetize with tf_none, see the static_cast is invalid, don't
add error_mark_node statement silently, but as the function isn't deleted,
we just silently emit it.
Should the standard be amended to say that the operator should be deleted
even if it has no elements and the static cast from
https://eel.is/c++draft/class.compare#class.spaceship-3.sentence-2

On Fri, Jan 10, 2025 at 12:04:53PM -0500, Jason Merrill wrote:
> That seems pretty obviously what we want, and is what the other compilers
> implement.

This patch implements it then.

2025-01-15  Jakub Jelinek  

PR c++/118387
* method.cc (build_comparison_op): Set bad if
std::strong_ordering::equal doesn't convert to rettype.

* g++.dg/cpp2a/spaceship-err6.C: Expect another error.
* g++.dg/cpp2a/spaceship-synth17.C: Likewise.
* g++.dg/cpp2a/spaceship-synth-neg6.C: Likewise.
* g++.dg/cpp2a/spaceship-synth-neg7.C: New test.

* testsuite/25_algorithms/default_template_value.cc
(Input::operator<=>): Use auto as return type rather than bool.

Diff:
---
 gcc/cp/method.cc   | 26 +-
 gcc/testsuite/g++.dg/cpp2a/spaceship-err6.C|  2 +-
 gcc/testsuite/g++.dg/cpp2a/spaceship-synth-neg6.C  |  2 +-
 gcc/testsuite/g++.dg/cpp2a/spaceship-synth-neg7.C  | 58 ++
 gcc/testsuite/g++.dg/cpp2a/spaceship-synth17.C |  2 +-
 .../25_algorithms/default_template_value.cc|  2 +-
 6 files changed, 75 insertions(+), 17 deletions(-)

diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
index 304d11d145c5..3914bbb1ef23 100644
--- a/gcc/cp/method.cc
+++ b/gcc/cp/method.cc
@@ -1635,6 +1635,18 @@ build_comparison_op (tree fndecl, bool defining, 
tsubst_flags_t complain)
  rettype = common_comparison_type (comps);
  apply_deduced_return_type (fndecl, rettype);
}
+  tree retvaleq;
+  if (code == EQ_EXPR)
+   retvaleq = boolean_true_node;
+  else
+   {
+ tree seql = lookup_comparison_result (cc_strong_ordering,
+   "equal", complain);
+ retvaleq = build_static_cast (input_location, rettype, seql,
+   complain);
+ if (retvaleq == error_mark_node)
+   bad = true;
+   }
   if (bad)
{
  DECL_DELETED_FN (fndecl) = true;
@@ -1722,19 +1734,7 @@ build_comparison_op (tree fndecl, bool defining, 
tsubst_flags_t complain)
}
}
   if (defining)
-   {
- tree val;
- if (code == EQ_EXPR)
-   val = boolean_true_node;
- else
-   {
- tree seql = lookup_comparison_result (cc_strong_ordering,
-   "equal", complain);
- val = build_static_cast (input_location, rettype, seql,
-  complain);
-   }
- finish_return_stmt (val);
-   }
+   finish_return_stmt (retvaleq);
 }
   else if (code == NE_EXPR)
 {
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-err6.C 
b/gcc/testsuite/g++.dg/cpp2a/spaceship-err6.C
index 57fbdb330884..7e36df3ff9f3 100644
--- a/gcc/testsuite/g++.dg/cpp2a/spaceship-err6.C
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-err6.C
@@ -10,7 +10,7 @@ class MyClass
 public:
   MyClass(int value): mValue(value) {}
 
-  bool operator<=>(const MyClass&) const = default;
+  bool operator<=>(const MyClass&) const = default;// { dg-error "invalid 
'static_cast' from type 'const std::strong_ordering' to type 'bool'" }
 };
 
 int main()
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-synth-neg6.C 
b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth-neg6.C
index d3f95e13f135..f4df61ed5088 100644
--- a/gcc/testsuite/g++.dg/cpp2a/spaceship-synth-neg6.C
+++ b/gcc/testsuite/g++.dg/c

[gcc r15-6912] testsuite: i386: Fix expected vectoriziation in pr105493.c

2025-01-15 Thread Christoph Mテシllner via Gcc-cvs
https://gcc.gnu.org/g:120a37008222bf6fe17658af3d1ba1b384642905

commit r15-6912-g120a37008222bf6fe17658af3d1ba1b384642905
Author: Christoph Müllner 
Date:   Tue Jan 14 13:20:50 2025 +0100

testsuite: i386: Fix expected vectoriziation in pr105493.c

As reported in PR117079, commit ab18785840d7b8 broke the test pr105493.c.
The test code contains two loops, where the first one is exected to be
vectorized.  The commit that broke that vectorization was the first of
several that enabled vectorization of both loops.
Now, that GCC can vectorize the whole function, let's adjust this test
to expect vectorization of both loops by ensuring that we don't write
to the helper-array 'tmp'.

Signed-off-by: Christoph Müllner 

PR target/117079

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr105493.c: Fix expected vectorization

Signed-off-by: Christoph Müllner 

Diff:
---
 gcc/testsuite/gcc.target/i386/pr105493.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.target/i386/pr105493.c 
b/gcc/testsuite/gcc.target/i386/pr105493.c
index c6fd16753cd9..c2b1a8f466ed 100644
--- a/gcc/testsuite/gcc.target/i386/pr105493.c
+++ b/gcc/testsuite/gcc.target/i386/pr105493.c
@@ -45,7 +45,5 @@ foo ( uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
 return (((uint16_t)sum) + ((uint32_t)sum>>16)) >> 1;
 }
 
-
-/* The first loop should be vectorized, which will eliminate redundant stores
-   and loads.  */
-/* { dg-final { scan-tree-dump-times "  MEM  
\\\[\[\^\]\]\*\\\] = " 4 "slp1" } } */
+/* All loops should be vectorized.  */
+/* { dg-final { scan-tree-dump-times "MEM\[^\n\]*tmp\[^\n\]*= " 0 "slp1" } } */


[gcc r15-6914] middle-end: Fix incorrect type replacement in operands_equals [PR118472]

2025-01-15 Thread Tamar Christina via Gcc-cvs
https://gcc.gnu.org/g:25eb892a8c1587ab720e92548874f0d600aa842e

commit r15-6914-g25eb892a8c1587ab720e92548874f0d600aa842e
Author: Tamar Christina 
Date:   Wed Jan 15 13:58:00 2025 +

middle-end: Fix incorrect type replacement in operands_equals [PR118472]

In g:3c32575e5b6370270d38a80a7fa8eaa144e083d0 I made a mistake and 
incorrectly
replaced the type of the arguments of an expression with the type of the
expression.  This is of course wrong.

This reverts that change and I have also double checked the other 
replacements
and they are fine.

gcc/ChangeLog:

PR middle-end/118472
* fold-const.cc (operand_compare::operand_equal_p): Fix incorrect
replacement.

gcc/testsuite/ChangeLog:

PR middle-end/118472
* gcc.dg/pr118472.c: New test.

Diff:
---
 gcc/fold-const.cc   |  3 ++-
 gcc/testsuite/gcc.dg/pr118472.c | 32 
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 501c6d8a54db..f9f7f4d2f917 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -3746,7 +3746,8 @@ operand_compare::operand_equal_p (tree type0, const_tree 
arg0,
 of op1.  Need to check to make sure they are the same.  */
  if (TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
  && TREE_CODE (TREE_OPERAND (arg1, 1)) == INTEGER_CST
- && TYPE_PRECISION (type0) != TYPE_PRECISION (type1))
+ && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 1)))
+   != TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg1, 1
return false;
  /* FALLTHRU */
 
diff --git a/gcc/testsuite/gcc.dg/pr118472.c b/gcc/testsuite/gcc.dg/pr118472.c
new file mode 100644
index ..dd842a6ae0fe
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr118472.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fopenmp-simd" } */
+
+typedef int a;
+typedef struct {
+  a b __attribute__((__vector_size__(8)));
+} c;
+
+typedef a d __attribute__((__vector_size__(8)));
+c e, f, g;
+d h, j;
+void k() {
+  c l;
+  l.b[1] = 0;
+  c m = l;
+  __builtin_memcpy(&h, &m, sizeof(h));
+  j = h;
+  {
+c l;
+l.b[1] = 0;
+m = l;
+__builtin_memcpy(&h, &m, sizeof(h));
+d m = j;
+__builtin_memcpy(&g, &m, sizeof(g));
+e = g;
+m = h;
+__builtin_memcpy(&g, &m, sizeof(g));
+#pragma omp simd
+for (long i = 0; i < f.b[0]; i++)
+  f.b[i] = e.b[i] > g.b[i];
+  }
+}


[gcc r15-6933] Fix setting of call graph node AutoFDO count

2025-01-15 Thread Eugene Rozenfeld via Gcc-cvs
https://gcc.gnu.org/g:e683c6b029f809c7a1981b4341c95d9652c22e18

commit r15-6933-ge683c6b029f809c7a1981b4341c95d9652c22e18
Author: Eugene Rozenfeld 
Date:   Fri Jan 10 19:48:52 2025 -0800

Fix setting of call graph node AutoFDO count

We are initializing both the call graph node count and
the entry block count of the function with the head_count value
from the profile.

Count propagation algorithm may refine the entry block count
and we may end up with a case where the call graph node count
is set to zero but the entry block count is non-zero. That becomes
a problem because we have this code in execute_fixup_cfg:

 profile_count num = node->count;
 profile_count den = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
 bool scale = num.initialized_p () && !(num == den);

Here if num is 0 but den is not 0, scale becomes true and we
lose the counts in

if (scale)
  bb->count = bb->count.apply_scale (num, den);

This is what happened in the issue reported in PR116743
(a 10% regression in MySQL HAMMERDB tests).
3d9e6767939e9658260e2506e81ec32b37cba041 made an improvement in
AutoFDO count propagation, which caused a mismatch between
the call graph node count (zero) and the entry block count (non-zero)
and subsequent loss of counts as described above.

The fix is to update the call graph node count once we've done count 
propagation.

Tested on x86_64-pc-linux-gnu.

gcc/ChangeLog:
PR gcov-profile/116743
* auto-profile.cc (afdo_annotate_cfg): Fix mismatch between the 
call graph node count
and the entry block count.

Diff:
---
 gcc/auto-profile.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/auto-profile.cc b/gcc/auto-profile.cc
index 5d0e8afb9a18..aa4d1634f018 100644
--- a/gcc/auto-profile.cc
+++ b/gcc/auto-profile.cc
@@ -1538,8 +1538,6 @@ afdo_annotate_cfg (const stmt_set &promoted_stmts)
 
   if (s == NULL)
 return;
-  cgraph_node::get (current_function_decl)->count
- = profile_count::from_gcov_type (s->head_count ()).afdo ();
   ENTRY_BLOCK_PTR_FOR_FN (cfun)->count
  = profile_count::from_gcov_type (s->head_count ()).afdo ();
   EXIT_BLOCK_PTR_FOR_FN (cfun)->count = profile_count::zero ().afdo ();
@@ -1578,6 +1576,8 @@ afdo_annotate_cfg (const stmt_set &promoted_stmts)
   /* Calculate, propagate count and probability information on CFG.  */
   afdo_calculate_branch_prob (&annotated_bb);
 }
+  cgraph_node::get(current_function_decl)->count
+  = ENTRY_BLOCK_PTR_FOR_FN(cfun)->count;
   update_max_bb_count ();
   profile_status_for_fn (cfun) = PROFILE_READ;
   if (flag_value_profile_transformations)


[gcc r15-6928] doc: cleanup trailing whitespace

2025-01-15 Thread Sam James via Gcc-cvs
https://gcc.gnu.org/g:c340ff207f0fd297231e9d5c093c06c11b84bede

commit r15-6928-gc340ff207f0fd297231e9d5c093c06c11b84bede
Author: Sam James 
Date:   Wed Jan 15 22:51:31 2025 +

doc: cleanup trailing whitespace

gcc/ChangeLog:

* doc/extend.texi: Cleanup trailing whitespace.

Diff:
---
 gcc/doc/extend.texi | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 84894efc2ea4..52ba78b80361 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -15355,7 +15355,7 @@ a function if it does not.  For example:
 
 You may use this built-in function in either a macro or an inline
 function.  However, if you use it in an inlined function and pass an
-argument of the function as the argument to the built-in, GCC 
+argument of the function as the argument to the built-in, GCC
 never returns 1 when you call the inline function with a string constant
 or compound literal (@pxref{Compound Literals}) and does not return 1
 when you pass a constant numeric value to the inline function unless you
@@ -15520,9 +15520,9 @@ when testing pointer or floating-point values.
 
 For the purposes of branch prediction optimizations, the probability that
 a @code{__builtin_expect} expression is @code{true} is controlled by GCC's
-@code{builtin-expect-probability} parameter, which defaults to 90%.  
+@code{builtin-expect-probability} parameter, which defaults to 90%.
 
-You can also use @code{__builtin_expect_with_probability} to explicitly 
+You can also use @code{__builtin_expect_with_probability} to explicitly
 assign a probability value to individual expressions.  If the built-in
 is used in a loop construct, the provided probability will influence
 the expected number of iterations made by loop optimizations.


[gcc r15-6927] doc: trivial grammar fix

2025-01-15 Thread Sam James via Gcc-cvs
https://gcc.gnu.org/g:d8e52444aa0fae982dba2176bf29a38b66006380

commit r15-6927-gd8e52444aa0fae982dba2176bf29a38b66006380
Author: Sam James 
Date:   Wed Jan 15 22:50:28 2025 +

doc: trivial grammar fix

We say 'a constant .. expression' elsewhere. Fix the grammar.

gcc/ChangeLog:

* doc/extend.texi: Add 'a' for grammar fix.

Diff:
---
 gcc/doc/extend.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 1e1b4cc837da..84894efc2ea4 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -15534,7 +15534,7 @@ the expected number of iterations made by loop 
optimizations.
 This function has the same semantics as @code{__builtin_expect},
 but the caller provides the expected probability that @var{exp} == @var{c}.
 The last argument, @var{probability}, is a floating-point value in the
-range 0.0 to 1.0, inclusive.  The @var{probability} argument must be
+range 0.0 to 1.0, inclusive.  The @var{probability} argument must be a
 constant floating-point expression.
 @enddefbuiltin


[gcc r15-6934] Fix an incorrect file header comment for the core2 scheduling model

2025-01-15 Thread Andi Kleen via Gcc-cvs
https://gcc.gnu.org/g:efd00e3a48b63bc7d3f3f7a2e5a6be520d05036b

commit r15-6934-gefd00e3a48b63bc7d3f3f7a2e5a6be520d05036b
Author: Andi Kleen 
Date:   Wed Jan 15 19:07:44 2025 -0800

Fix an incorrect file header comment for the core2 scheduling model

Committed as obvious.

gcc/ChangeLog:

* config/i386/x86-tune-sched-core.cc: Fix incorrect comment.

Diff:
---
 gcc/config/i386/x86-tune-sched-core.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/i386/x86-tune-sched-core.cc 
b/gcc/config/i386/x86-tune-sched-core.cc
index 4065a38e5d39..5d41afafde72 100644
--- a/gcc/config/i386/x86-tune-sched-core.cc
+++ b/gcc/config/i386/x86-tune-sched-core.cc
@@ -1,4 +1,4 @@
-/* Scheduler hooks for IA-32 which implement bdver1-4 specific logic.
+/* Scheduler hooks for IA-32 which implement Core 2 specific logic.
Copyright (C) 1988-2025 Free Software Foundation, Inc.
 
 This file is part of GCC.


[gcc r15-6930] libstdc++: Fix fancy pointer test for std::set

2025-01-15 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:f079feecab1dda0ea8c7fe632c41dbb3ee1892b8

commit r15-6930-gf079feecab1dda0ea8c7fe632c41dbb3ee1892b8
Author: Jonathan Wakely 
Date:   Wed Jan 15 21:24:15 2025 +

libstdc++: Fix fancy pointer test for std::set

The alloc_ptr.cc test for std::set tries to use C++17 features
unconditionally, and tries to use the C++23 range members which haven't
been implemented for std::set yet.

Some of the range checks are left in place but commented out, so they
can be added after the ranges members are implemented. Others (such as
prepend_range) are not valid for std::set at all.

Also fix uses of internal feature test macros in two other tests, which
should use the standard __cpp_lib_xxx macros.

libstdc++-v3/ChangeLog:

* 
testsuite/23_containers/set/requirements/explicit_instantiation/alloc_ptr.cc:
Guard node extraction checks with feature test macro. Remove
calls to non-existent range members.
* 
testsuite/23_containers/forward_list/requirements/explicit_instantiation/alloc_ptr.cc:
Use standard macro not internal one.
* 
testsuite/23_containers/list/requirements/explicit_instantiation/alloc_ptr.cc:
Likewise.

Diff:
---
 .../requirements/explicit_instantiation/alloc_ptr.cc  |  2 +-
 .../list/requirements/explicit_instantiation/alloc_ptr.cc |  2 +-
 .../set/requirements/explicit_instantiation/alloc_ptr.cc  | 11 +++
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git 
a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/explicit_instantiation/alloc_ptr.cc
 
b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/explicit_instantiation/alloc_ptr.cc
index e3bf8a13095a..08731f1bf38a 100644
--- 
a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/explicit_instantiation/alloc_ptr.cc
+++ 
b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/explicit_instantiation/alloc_ptr.cc
@@ -87,7 +87,7 @@ test_template_members(__gnu_test::input_container& c)
   l.merge(std::move(l), [](int, int) { return false; });
   l.sort([](int, int) { return false; });
 
-#ifdef __glibcxx_ranges_to_container
+#ifdef __cpp_lib_ranges_to_container
   short arr[2];
   __gnu_test::test_input_range r(arr);
   std::forward_list> l2(std::from_range, r);
diff --git 
a/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/alloc_ptr.cc
 
b/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/alloc_ptr.cc
index c52591b3cf8b..36bd89efcdb3 100644
--- 
a/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/alloc_ptr.cc
+++ 
b/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/alloc_ptr.cc
@@ -86,7 +86,7 @@ test_template_members(__gnu_test::input_container& c)
   l.merge(std::move(l), [](int, int) { return false; });
   l.sort([](int, int) { return false; });
 
-#ifdef __glibcxx_ranges_to_container
+#ifdef __cpp_lib_ranges_to_container
   short arr[2];
   __gnu_test::test_input_range r(arr);
   std::list> l2(std::from_range, r);
diff --git 
a/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/alloc_ptr.cc
 
b/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/alloc_ptr.cc
index 60b583a9b2be..4fa84a74882d 100644
--- 
a/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/alloc_ptr.cc
+++ 
b/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/alloc_ptr.cc
@@ -69,18 +69,21 @@ test_template_members(__gnu_test::input_container& c)
   s.emplace_hint(s.begin(), 1);
   s.insert(c.begin(), c.end());
 
+#ifdef __cpp_lib_node_extract
   std::set, Allocator> s1;
   s.merge(s1);
   std::multiset, Allocator> m1;
   s.merge(m1);
+#endif
 
-#ifdef __glibcxx_ranges_to_container
+#if 0
+#ifdef __cpp_lib_ranges_to_container
   short arr[2];
   __gnu_test::test_input_range r(arr);
   std::set, Allocator> s2(std::from_range, r);
-  s2.assign_range(r);
-  s2.prepend_range(r);
-  s2.append_range(r);
+  std::set, Allocator> s3(std::from_range, r,
+  Allocator{});
   s2.insert_range(s2.begin(), r);
 #endif
+#endif
 }


[gcc r15-6931] libstdc++: Fix use of internal feature test macro in test

2025-01-15 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:79d5504002e1cde242e8284ca134b2573d43bd89

commit r15-6931-g79d5504002e1cde242e8284ca134b2573d43bd89
Author: Jonathan Wakely 
Date:   Wed Jan 15 23:37:14 2025 +

libstdc++: Fix use of internal feature test macro in test

This test should use __cpp_lib_ios_noreplace rather than the internal
__glibcxx_ios_noreplace macro.

libstdc++-v3/ChangeLog:

* testsuite/27_io/ios_base/types/openmode/case_label.cc: Use
standard feature test macro not internal one.

Diff:
---
 libstdc++-v3/testsuite/27_io/ios_base/types/openmode/case_label.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/case_label.cc 
b/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/case_label.cc
index 253a0dc75668..e132070bf487 100644
--- a/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/case_label.cc
+++ b/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/case_label.cc
@@ -44,7 +44,7 @@ case_labels(bitmask_type b)
   break;
 case std::ios_base::trunc:
   break;
-#ifdef __glibcxx_ios_noreplace
+#ifdef __cpp_lib_ios_noreplace
 case std::ios_base::noreplace:
   break;
 #endif


[gcc r15-6929] match: Simplify `1 >> x` into `x == 0` [PR102705]

2025-01-15 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:903ab914dd48c3131ded0cf427da50c23168024c

commit r15-6929-g903ab914dd48c3131ded0cf427da50c23168024c
Author: Andrew Pinski 
Date:   Tue Jan 14 19:38:47 2025 -0800

match: Simplify `1 >> x` into `x == 0` [PR102705]

This in this PR we have missed optimization where we miss that,
`1 >> x` and `(1 >> x) ^ 1` can't be equal. There are a few ways of
optimizing this, the easiest and simpliest is to simplify `1 >> x` into
just `x == 0` as those are equivalant (if we ignore out of range values for 
x).
we already have an optimization for `(1 >> X) !=/== 0` so the only 
difference
here is we don't need the `!=/== 0` part to do the transformation.

So this removes the `(1 >> X) !=/== 0` transformation and just adds a 
simplfied
`1 >> x` -> `x == 0` one.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/102705

gcc/ChangeLog:

* match.pd (`(1 >> X) != 0`): Remove pattern.
(`1 >> x`): New pattern.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr105832-2.c: Update testcase.
* gcc.dg/tree-ssa/pr96669-1.c: Likewise.
* gcc.dg/tree-ssa/pr102705-1.c: New test.
* gcc.dg/tree-ssa/pr102705-2.c: New test.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/match.pd   | 16 
 gcc/testsuite/gcc.dg/tree-ssa/pr102705-1.c | 17 +
 gcc/testsuite/gcc.dg/tree-ssa/pr102705-2.c | 17 +
 gcc/testsuite/gcc.dg/tree-ssa/pr105832-2.c |  8 
 gcc/testsuite/gcc.dg/tree-ssa/pr96669-1.c  |  2 +-
 5 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 171930874988..b6cbb851897d 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4998,6 +4998,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 (op @0 { build_int_cst (TREE_TYPE (@1), prec - 1); })))
   (op @0 { build_int_cst (TREE_TYPE (@1), low); })))
 
+/* Fold `1 >> a` into `a == 0` for scalar integral types. */
+(simplify
+ (rshift integer_onep @2)
+ (if (INTEGRAL_TYPE_P (type))
+  (convert (eq:boolean_type_node @2 { build_zero_cst (TREE_TYPE (@2)); }
 
 /* Simplify (CST << x) & 1 to 0 if CST is even or to x == 0 if it is odd.  */
 (simplify
@@ -5009,7 +5014,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* Simplify ((C << x) & D) != 0 where C and D are power of two constants,
either to false if D is smaller (unsigned comparison) than C, or to
x == log2 (D) - log2 (C).  Similarly for right shifts.
-   Note for `(1 >> x)`, the & 1 has been removed so matching that seperately. 
*/
+   Note `(1 >> x)`, the & 1 has been removed so but will have been
+   already folded above.  */
 (for cmp (ne eq)
  icmp (eq ne)
  (simplify
@@ -5026,13 +5032,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
int c2 = wi::clz (wi::to_wide (@2)); }
  (if (c1 > c2)
   { constant_boolean_node (cmp == NE_EXPR ? false : true, type); }
-  (icmp @0 { build_int_cst (TREE_TYPE (@0), c2 - c1); })
- /* `(1 >> X) != 0` -> `X == 0` */
- /* `(1 >> X) == 0` -> `X != 0` */
- (simplify
-  (cmp (rshift integer_onep@1 @0) integer_zerop)
-   (if (INTEGRAL_TYPE_P (TREE_TYPE (@1)))
-(icmp @0 { build_zero_cst (TREE_TYPE (@0)); }
+  (icmp @0 { build_int_cst (TREE_TYPE (@0), c2 - c1); }))
 
 /* (CST1 << A) == CST2 -> A == ctz (CST2) - ctz (CST1)
(CST1 << A) != CST2 -> A != ctz (CST2) - ctz (CST1)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr102705-1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr102705-1.c
new file mode 100644
index ..60b53c034727
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr102705-1.c
@@ -0,0 +1,17 @@
+/* PR tree-optimization/102705 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-original" } */
+/* { dg-final { scan-tree-dump "a == 0" "original" } } */
+/* { dg-final { scan-tree-dump "b == 0" "original" } } */
+
+int
+f1 (int a)
+{
+  return (1 >> a);
+}
+
+int
+f2 (int b)
+{
+  return ((1 >> b) & 1);
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr102705-2.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr102705-2.c
new file mode 100644
index ..a12606c78568
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr102705-2.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* PR tree-optimization/102705 */
+/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */
+
+
+void foo(void);
+static int b;
+static char c;
+static short a(short d, short e) { return e == 0 || d && e == 1 ? 0 : d % e; }
+int main() {
+  b = c = b >= 2 ? 0 : 1 >> b;
+  short f = a(0 >= 0 ^ c, 5);
+  if (f == c)
+foo();
+  a(0, 9);
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr105832-2.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr105832-2.c
index 2d2a33e27557..ebcc76bda681 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr105832-2.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr105832-2.c
@@ -1,10 +1,10 @@
 /* PR tree-optimizat

[gcc r15-6935] lm32: Args with arg.named false still get passed in regs

2025-01-15 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:3184f6a565ed5efab39faf9eee764f393c74442d

commit r15-6935-g3184f6a565ed5efab39faf9eee764f393c74442d
Author: Keith Packard 
Date:   Wed Jan 15 22:02:36 2025 -0700

lm32: Args with arg.named false still get passed in regs

* config/lm32/lm32.cc (lm32_function_arg): Pass unnamed
arguments in registers too, just like named arguments.

Diff:
---
 gcc/config/lm32/lm32.cc | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/config/lm32/lm32.cc b/gcc/config/lm32/lm32.cc
index 4445295fe2b6..d78efc59da5f 100644
--- a/gcc/config/lm32/lm32.cc
+++ b/gcc/config/lm32/lm32.cc
@@ -632,8 +632,7 @@ lm32_function_arg (cumulative_args_t cum_v, const 
function_arg_info &arg)
   if (targetm.calls.must_pass_in_stack (arg))
 return NULL_RTX;
 
-  if (!arg.named
-  || *cum + LM32_NUM_REGS2 (arg.mode, arg.type) > LM32_NUM_ARG_REGS)
+  if (*cum + LM32_NUM_REGS2 (arg.mode, arg.type) > LM32_NUM_ARG_REGS)
 return NULL_RTX;
 
   return gen_rtx_REG (arg.mode, *cum + LM32_FIRST_ARG_REG);


[gcc r15-6936] lm32: Skip last named param when computing save varargs regs

2025-01-15 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:6e593fcda49b1001e87e94ab709607b4fb2c66cf

commit r15-6936-g6e593fcda49b1001e87e94ab709607b4fb2c66cf
Author: Keith Packard 
Date:   Wed Jan 15 22:05:46 2025 -0700

lm32: Skip last named param when computing save varargs regs

The cumulative args value in setup_incoming_varargs points at
the last named parameter. We need to skip over that (if present) to
get to the first anonymous argument as we only want to include
those anonymous args in the saved register block.

gcc/
* config/lm32/lm32.cc (lm32_setup_incoming_varargs): Skip last
named parameter when preparing to flush registers with unnamed
arguments to th stack.

Diff:
---
 gcc/config/lm32/lm32.cc | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/gcc/config/lm32/lm32.cc b/gcc/config/lm32/lm32.cc
index d78efc59da5f..dfec28608a0a 100644
--- a/gcc/config/lm32/lm32.cc
+++ b/gcc/config/lm32/lm32.cc
@@ -679,14 +679,18 @@ lm32_setup_incoming_varargs (cumulative_args_t cum_v,
 const function_arg_info &arg,
 int *pretend_size, int no_rtl)
 {
-  CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
+  CUMULATIVE_ARGS next_cum = *get_cumulative_args (cum_v);
   int first_anon_arg;
   tree fntype;
 
   fntype = TREE_TYPE (current_function_decl);
 
+  if (!TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (current_function_decl))
+  || arg.type != NULL_TREE)
+lm32_function_arg_advance (pack_cumulative_args (&next_cum), arg);
+
   if (stdarg_p (fntype))
-first_anon_arg = *cum + LM32_FIRST_ARG_REG;
+first_anon_arg = next_cum + LM32_FIRST_ARG_REG;
   else
 {
   /* this is the common case, we have been passed details setup
@@ -697,7 +701,7 @@ lm32_setup_incoming_varargs (cumulative_args_t cum_v,
   int size = arg.promoted_size_in_bytes ();
 
   first_anon_arg =
-   *cum + LM32_FIRST_ARG_REG +
+   next_cum + LM32_FIRST_ARG_REG +
((size + UNITS_PER_WORD - 1) / UNITS_PER_WORD);
 }


[gcc r15-6937] lm32: Compute pretend_size in setup_incoming_varargs even if no_rtl

2025-01-15 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:423e9a8ad59e6972cd6f25238cd328080fed11cc

commit r15-6937-g423e9a8ad59e6972cd6f25238cd328080fed11cc
Author: Keith Packard 
Date:   Wed Jan 15 22:08:59 2025 -0700

lm32: Compute pretend_size in setup_incoming_varargs even if no_rtl

gcc/
* config/lm32/lm32.cc (setup_incoming_varargs): Adjust the
conditionals so that pretend_size is always computed, even
if no_rtl is set.

Diff:
---
 gcc/config/lm32/lm32.cc | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/gcc/config/lm32/lm32.cc b/gcc/config/lm32/lm32.cc
index dfec28608a0a..b677953bb4cc 100644
--- a/gcc/config/lm32/lm32.cc
+++ b/gcc/config/lm32/lm32.cc
@@ -705,16 +705,18 @@ lm32_setup_incoming_varargs (cumulative_args_t cum_v,
((size + UNITS_PER_WORD - 1) / UNITS_PER_WORD);
 }
 
-  if ((first_anon_arg < (LM32_FIRST_ARG_REG + LM32_NUM_ARG_REGS)) && !no_rtl)
+  if (FUNCTION_ARG_REGNO_P (first_anon_arg))
 {
-  int first_reg_offset = first_anon_arg;
   int size = LM32_FIRST_ARG_REG + LM32_NUM_ARG_REGS - first_anon_arg;
-  rtx regblock;
 
-  regblock = gen_rtx_MEM (BLKmode,
- plus_constant (Pmode, arg_pointer_rtx,
-FIRST_PARM_OFFSET (0)));
-  move_block_from_reg (first_reg_offset, regblock, size);
+  if (!no_rtl)
+   {
+ rtx regblock
+   = gen_rtx_MEM (BLKmode,
+  plus_constant (Pmode, arg_pointer_rtx,
+ FIRST_PARM_OFFSET (0)));
+ move_block_from_reg (first_anon_arg, regblock, size);
+   }
 
   *pretend_size = size * UNITS_PER_WORD;
 }


[gcc r15-6938] lm32: In va_arg, skip to stack args with too few remaining reg args

2025-01-15 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:cf9de710aaacd8a3c2cddf348c704b19a5404a0f

commit r15-6938-gcf9de710aaacd8a3c2cddf348c704b19a5404a0f
Author: Keith Packard 
Date:   Wed Jan 15 22:11:01 2025 -0700

lm32: In va_arg, skip to stack args with too few remaining reg args

lm32 has 8 register parameter slots, so many vararg functions end up
with several anonymous parameters passed in registers. If we run out
of registers in the middle of a parameter, the entire parameter will
be placed on the stack, skipping any remaining available registers.

The receiving varargs function doesn't know this, and will save all of
the possible parameter register values just below the stack parameters.

When processing a va_arg call with a type size larger than a single
register, we must check to see if it spans the boundary between
register and stack parameters. If so, we need to skip to the stack
parameters.

This is done by making va_list a structure containing the arg pointer
and the address of the start of the stack parameters. Boundary checks
are inserted in va_arg calls to detect this case and the address of
the parameter is set to the stack parameter start when the parameter
crosses over.

gcc/
* config/lm32/lm32.cc: Add several #includes.
(va_list_type): New.
(lm32_build_va_list): New function.
(lm32_builtin_va_start): Likewise.
(lm32_sd_gimplify_va_arg_expr): Likewise.
(lm32_gimplify_va_arg_expr): Likewise.

Diff:
---
 gcc/config/lm32/lm32.cc | 266 
 1 file changed, 266 insertions(+)

diff --git a/gcc/config/lm32/lm32.cc b/gcc/config/lm32/lm32.cc
index b677953bb4cc..15728969fadd 100644
--- a/gcc/config/lm32/lm32.cc
+++ b/gcc/config/lm32/lm32.cc
@@ -44,6 +44,11 @@
 #include "expr.h"
 #include "tm-constrs.h"
 #include "builtins.h"
+#include "langhooks.h"
+#include "stor-layout.h"
+#include "fold-const.h"
+#include "gimple.h"
+#include "gimplify.h"
 
 /* This file should be included last.  */
 #include "target-def.h"
@@ -66,6 +71,10 @@ static bool lm32_in_small_data_p (const_tree);
 static void lm32_setup_incoming_varargs (cumulative_args_t cum,
 const function_arg_info &,
 int *pretend_size, int no_rtl);
+static tree lm32_build_builtin_va_list (void);
+static void lm32_builtin_va_start (tree valist, rtx nextarg);
+static tree lm32_gimplify_va_arg_expr (tree valist, tree type, gimple_seq 
*pre_p,
+  gimple_seq *post_p);
 static bool lm32_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno,
int *total, bool speed);
 static bool lm32_can_eliminate (const int, const int);
@@ -92,6 +101,13 @@ static HOST_WIDE_INT lm32_starting_frame_offset (void);
 #define TARGET_PROMOTE_FUNCTION_MODE 
default_promote_function_mode_always_promote
 #undef TARGET_SETUP_INCOMING_VARARGS
 #define TARGET_SETUP_INCOMING_VARARGS lm32_setup_incoming_varargs
+#undef TARGET_BUILD_BUILTIN_VA_LIST
+#define TARGET_BUILD_BUILTIN_VA_LIST lm32_build_builtin_va_list
+#undef TARGET_EXPAND_BUILTIN_VA_START
+#define TARGET_EXPAND_BUILTIN_VA_START lm32_builtin_va_start
+#undef TARGET_GIMPLIFY_VA_ARG_EXPR
+#define TARGET_GIMPLIFY_VA_ARG_EXPR lm32_gimplify_va_arg_expr
+
 #undef TARGET_FUNCTION_ARG
 #define TARGET_FUNCTION_ARG lm32_function_arg
 #undef TARGET_FUNCTION_ARG_ADVANCE
@@ -721,6 +737,254 @@ lm32_setup_incoming_varargs (cumulative_args_t cum_v,
   *pretend_size = size * UNITS_PER_WORD;
 }
 }
+/* This is the "struct __va_list".  */
+
+static GTY(()) tree va_list_type;
+
+/* Implement TARGET_BUILD_BUILTIN_VA_LIST.  */
+
+static tree
+lm32_build_builtin_va_list (void)
+{
+  /* We keep one pointer and a count
+
+ The pointer is the regular void *
+
+ The count tracks how many registers arguments
+ remain. When that goes to zero, we have to skip
+ over the reserved space that was the top of the
+ stack at function entry
+
+   */
+  tree va_list_name;
+  tree ap_field;
+  tree ap_reg_field;
+
+  va_list_type = lang_hooks.types.make_type (RECORD_TYPE);
+  /* Name it */
+  va_list_name = build_decl (BUILTINS_LOCATION,
+TYPE_DECL,
+get_identifier ("__va_list"),
+va_list_type);
+
+  DECL_ARTIFICIAL (va_list_name) = 1;
+  TYPE_NAME (va_list_type) = va_list_name;
+  TYPE_STUB_DECL (va_list_type) = va_list_name;
+
+  ap_field = build_decl (BUILTINS_LOCATION,
+FIELD_DECL,
+get_identifier("__ap"),
+ptr_type_node);
+  DECL_ARTIFICIAL (ap_field) = 1;
+  DECL_FIELD_CONTEXT (ap_field) = va_list_type;
+  TYPE_FIELDS (va_list_type) = ap_field;
+
+  ap_reg_field = build_decl(BUILTINS_LOCATION,
+   FIELD_DECL,
+

[gcc(refs/users/aoliva/heads/testme)] [testsuite] [arm] adjust wmul expectations [PR113560]

2025-01-15 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:cfff1937f515837408f1b37d1f81f98fcf2573a8

commit cfff1937f515837408f1b37d1f81f98fcf2573a8
Author: Alexandre Oliva 
Date:   Thu Jan 16 02:53:31 2025 -0300

[testsuite] [arm] adjust wmul expectations [PR113560]

Since the machine-independent widening multiply logic was improved
PR113560, ARM's wmul-[567].c fail.  AFAICT the logic takes advantage
of the fact that, after zero-extending a narrow integral type to a
wider type, further zero- or sign-extending is equivalent, which
enables different instructions to be used for equivalent effect.

Adjust the tests to accept all the equivalent instructions that can be
used.


for  gcc/testsuite/ChangeLog

PR target/113560
* gcc.target/arm/wmul-5.c: Accept other mla instructions.
* gcc.target/arm/wmul-6.c: Likewise.
* gcc.target/arm/wmul-7.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.target/arm/wmul-5.c | 4 +++-
 gcc/testsuite/gcc.target/arm/wmul-6.c | 4 +++-
 gcc/testsuite/gcc.target/arm/wmul-7.c | 4 +++-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.target/arm/wmul-5.c 
b/gcc/testsuite/gcc.target/arm/wmul-5.c
index 9f29a81c0b8b..282e007d9be3 100644
--- a/gcc/testsuite/gcc.target/arm/wmul-5.c
+++ b/gcc/testsuite/gcc.target/arm/wmul-5.c
@@ -8,4 +8,6 @@ foo (long long a, char *b, char *c)
   return a + *b * *c;
 }
 
-/* { dg-final { scan-assembler "umlal" } } */
+/* smlalbb after zero-extending the chars to HImode, or either signed- or
+   unsigned-widening multiply after extending them to SImode.  */
+/* { dg-final { scan-assembler {(?:smlalbb|[us]mlal)} } } */
diff --git a/gcc/testsuite/gcc.target/arm/wmul-6.c 
b/gcc/testsuite/gcc.target/arm/wmul-6.c
index babdaab1efd5..05247e00c5eb 100644
--- a/gcc/testsuite/gcc.target/arm/wmul-6.c
+++ b/gcc/testsuite/gcc.target/arm/wmul-6.c
@@ -8,4 +8,6 @@ foo (long long a, unsigned char *b, signed char *c)
   return a + (long long)*b * (long long)*c;
 }
 
-/* { dg-final { scan-assembler "smlalbb" } } */
+/* After zero-extending B and sign-extending C to [HS]imode, either
+   signed-widening multiply will do.  */
+/* { dg-final { scan-assembler {smlal(?:bb)?} } } */
diff --git a/gcc/testsuite/gcc.target/arm/wmul-7.c 
b/gcc/testsuite/gcc.target/arm/wmul-7.c
index 2db4ad4e10d5..26933c42401a 100644
--- a/gcc/testsuite/gcc.target/arm/wmul-7.c
+++ b/gcc/testsuite/gcc.target/arm/wmul-7.c
@@ -8,4 +8,6 @@ foo (unsigned long long a, unsigned char *b, unsigned short *c)
   return a + *b * *c;
 }
 
-/* { dg-final { scan-assembler "umlal" } } */
+/* After zero-extending both to SImode, either signed- or unsigned-widening
+   multiply will do.  */
+/* { dg-final { scan-assembler {[us]mlal} } } */


[gcc(refs/users/aoliva/heads/testme)] [testsuite] rearrange requirements for dfp bitint run tests

2025-01-15 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:c32ef7c4c95c6cc4e95ff57379f08260d3738c84

commit c32ef7c4c95c6cc4e95ff57379f08260d3738c84
Author: Alexandre Oliva 
Date:   Fri Jan 10 07:18:33 2025 -0300

[testsuite] rearrange requirements for dfp bitint run tests

dfp.exp sets the default to compile when dfprt is not available, but
some dfp bitint tests override the default without that requirement,
and try to run even when dfprt is not available.

Instead of overriding the default, rewrite the requirements so that
they apply even when compiling, since the absence of bitint or of
int128 would presumably cause compile failures.


for  gcc/testsuite/ChangeLog

* gcc.dg/dfp/bitint-1.c: Rewrite requirements to retain dfprt.
* gcc.dg/dfp/bitint-2.c: Likewise.
* gcc.dg/dfp/bitint-3.c: Likewise.
* gcc.dg/dfp/bitint-4.c: Likewise.
* gcc.dg/dfp/bitint-5.c: Likewise.
* gcc.dg/dfp/bitint-6.c: Likewise.
* gcc.dg/dfp/bitint-7.c: Likewise.
* gcc.dg/dfp/bitint-8.c: Likewise.
* gcc.dg/dfp/int128-1.c: Likewise.
* gcc.dg/dfp/int128-2.c: Likewise.
* gcc.dg/dfp/int128-3.c: Likewise.
* gcc.dg/dfp/int128-4.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.dg/dfp/bitint-1.c | 2 +-
 gcc/testsuite/gcc.dg/dfp/bitint-2.c | 2 +-
 gcc/testsuite/gcc.dg/dfp/bitint-3.c | 2 +-
 gcc/testsuite/gcc.dg/dfp/bitint-4.c | 2 +-
 gcc/testsuite/gcc.dg/dfp/bitint-5.c | 2 +-
 gcc/testsuite/gcc.dg/dfp/bitint-6.c | 2 +-
 gcc/testsuite/gcc.dg/dfp/bitint-7.c | 2 +-
 gcc/testsuite/gcc.dg/dfp/bitint-8.c | 2 +-
 gcc/testsuite/gcc.dg/dfp/int128-1.c | 3 ++-
 gcc/testsuite/gcc.dg/dfp/int128-2.c | 3 ++-
 gcc/testsuite/gcc.dg/dfp/int128-3.c | 3 ++-
 gcc/testsuite/gcc.dg/dfp/int128-4.c | 3 ++-
 12 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/dfp/bitint-1.c 
b/gcc/testsuite/gcc.dg/dfp/bitint-1.c
index ab826e16ba39..1493bf3c52f0 100644
--- a/gcc/testsuite/gcc.dg/dfp/bitint-1.c
+++ b/gcc/testsuite/gcc.dg/dfp/bitint-1.c
@@ -1,5 +1,5 @@
 /* PR c/102989 */
-/* { dg-do run { target bitint } } */
+/* { dg-require-effective-target bitint } */
 /* { dg-options "-O2 -std=c23 -pedantic-errors" } */
 
 #if __BITINT_MAXWIDTH__ >= 192
diff --git a/gcc/testsuite/gcc.dg/dfp/bitint-2.c 
b/gcc/testsuite/gcc.dg/dfp/bitint-2.c
index 68cce0e66521..1ed5be8929f2 100644
--- a/gcc/testsuite/gcc.dg/dfp/bitint-2.c
+++ b/gcc/testsuite/gcc.dg/dfp/bitint-2.c
@@ -1,5 +1,5 @@
 /* PR c/102989 */
-/* { dg-do run { target bitint } } */
+/* { dg-require-effective-target bitint } */
 /* { dg-options "-O2 -std=c23 -pedantic-errors" } */
 
 #if __BITINT_MAXWIDTH__ >= 192
diff --git a/gcc/testsuite/gcc.dg/dfp/bitint-3.c 
b/gcc/testsuite/gcc.dg/dfp/bitint-3.c
index 911bf8afb308..11997ddbea69 100644
--- a/gcc/testsuite/gcc.dg/dfp/bitint-3.c
+++ b/gcc/testsuite/gcc.dg/dfp/bitint-3.c
@@ -1,5 +1,5 @@
 /* PR c/102989 */
-/* { dg-do run { target bitint } } */
+/* { dg-require-effective-target bitint } */
 /* { dg-options "-O2 -std=c23 -pedantic-errors" } */
 
 #if __BITINT_MAXWIDTH__ >= 192
diff --git a/gcc/testsuite/gcc.dg/dfp/bitint-4.c 
b/gcc/testsuite/gcc.dg/dfp/bitint-4.c
index 0b6011055786..0e600160752b 100644
--- a/gcc/testsuite/gcc.dg/dfp/bitint-4.c
+++ b/gcc/testsuite/gcc.dg/dfp/bitint-4.c
@@ -1,5 +1,5 @@
 /* PR c/102989 */
-/* { dg-do run { target bitint } } */
+/* { dg-require-effective-target bitint } */
 /* { dg-options "-O2 -std=c23 -pedantic-errors" } */
 
 #if __BITINT_MAXWIDTH__ >= 192
diff --git a/gcc/testsuite/gcc.dg/dfp/bitint-5.c 
b/gcc/testsuite/gcc.dg/dfp/bitint-5.c
index 37d373cdf320..b7f7484d225b 100644
--- a/gcc/testsuite/gcc.dg/dfp/bitint-5.c
+++ b/gcc/testsuite/gcc.dg/dfp/bitint-5.c
@@ -1,5 +1,5 @@
 /* PR c/102989 */
-/* { dg-do run { target bitint } } */
+/* { dg-require-effective-target bitint } */
 /* { dg-options "-O2 -std=c23 -pedantic-errors" } */
 
 #if __BITINT_MAXWIDTH__ >= 192
diff --git a/gcc/testsuite/gcc.dg/dfp/bitint-6.c 
b/gcc/testsuite/gcc.dg/dfp/bitint-6.c
index eb137a60e4b7..e9c538015f4a 100644
--- a/gcc/testsuite/gcc.dg/dfp/bitint-6.c
+++ b/gcc/testsuite/gcc.dg/dfp/bitint-6.c
@@ -1,5 +1,5 @@
 /* PR c/102989 */
-/* { dg-do run { target bitint } } */
+/* { dg-require-effective-target bitint } */
 /* { dg-options "-O2 -std=c23 -pedantic-errors" } */
 
 #if __BITINT_MAXWIDTH__ >= 192
diff --git a/gcc/testsuite/gcc.dg/dfp/bitint-7.c 
b/gcc/testsuite/gcc.dg/dfp/bitint-7.c
index 49e8103723cb..530a26c47e51 100644
--- a/gcc/testsuite/gcc.dg/dfp/bitint-7.c
+++ b/gcc/testsuite/gcc.dg/dfp/bitint-7.c
@@ -1,6 +1,6 @@
 /* PR c/102989 */
 /* Test non-canonical BID significands.  */
-/* { dg-do run { target bitint } } */
+/* { dg-require-effective-target bitint } */
 /* { dg-require-effective-target dfp_bid } */
 /* { dg-options "-std=gnu23 -O2" } */
 
diff --git a/gcc/testsuite/gcc.dg/dfp/bitint-8.c 
b/gcc/testsuite/gcc.dg/dfp/bitint-8.c
index 18263e2bd753..2990877a2fbd 100644
--- a

[gcc(refs/users/aoliva/heads/testme)] [testsuite] skip test on non-hosted libstdc++ [PR113994]

2025-01-15 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:3b49119c091cca16c1d9f67aeee82be573425da3

commit 3b49119c091cca16c1d9f67aeee82be573425da3
Author: Alexandre Oliva 
Date:   Thu Jan 16 02:52:38 2025 -0300

[testsuite] skip test on non-hosted libstdc++ [PR113994]

Tests that include  need to be skipped when libstdc++ is built
in freestanding mode.


for  gcc/testsuite/ChangeLog

PR rtl-optimization/113994
* g++.dg/pr113994.C: Require hosted libstdc++.

Diff:
---
 gcc/testsuite/g++.dg/torture/pr113994.C | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/g++.dg/torture/pr113994.C 
b/gcc/testsuite/g++.dg/torture/pr113994.C
index c9c186d45ee7..bd749c4ada8a 100644
--- a/gcc/testsuite/g++.dg/torture/pr113994.C
+++ b/gcc/testsuite/g++.dg/torture/pr113994.C
@@ -1,5 +1,6 @@
 // PR rtl-optimization/113994
 // { dg-do run }
+// { dg-skip-if "requires hosted libstdc++ for string" { ! hostedlib } }
 
 #include 


[gcc/aoliva/heads/testbase] (32 commits) [ifcombine] robustify decode_field_reference

2025-01-15 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testbase' was updated to point to:

 5006b9d810b1... [ifcombine] robustify decode_field_reference

It previously pointed to:

 52e4ede03097... [ifcombine] propagate signbit mask to XOR right-hand operan

Diff:

Summary of changes (added commits):
---

  5006b9d... [ifcombine] robustify decode_field_reference (*)
  e939005... c++: re-enable NSDMI CONSTRUCTOR folding [PR118355] (*)
  d27db30... OpenMP: Remove dead code from declare variant reimplementat (*)
  1294b81... OpenMP: Re-work and extend context selector resolution (*)
  210a090... OpenMP: New tree nodes for metadirective and dynamic select (*)
  22fe3c0... [ifcombine] check and extend constants to compare with bitf (*)
  e5e9e50... RISC-V: Fix vsetvl compatibility predicate [PR118154]. (*)
  14cb061... match: Keep conditional in simplification to constant [PR11 (*)
  87ffd20... c++/modules: Don't emit imported deduction guides [PR117397 (*)
  744a59f... Ada: add missing support for the S/390 and RISC-V architect (*)
  31c3c1a... tree-optimization/118405 - ICE with vector(1) T vs T load (*)
  20b8500... Fortran: Add LOCALITY support for DO_CONCURRENT (*)
  bbc7900... c: improve UX for -Wincompatible-pointer-types (v3) [PR1168 (*)
  f7b7fe1... c++: Add support for vec_dup to constexpr [PR118445] (*)
  c864ffe... RISC-V: Expand shift count in Xmode in interleave pattern. (*)
  f12bb6c... rs6000: Add clobber and guard for vsx_stxvd2x4_le_const [PR (*)
  f71fe87... Daily bump. (*)
  7b81510... RISC-V: Disallow negative step for interleaving [PR117682] (*)
  1f64536... RISC-V: testsuite: Skip test with -flto (*)
  9a4bb95... PR modula2/116557: Remove physical address from COPYING.FDL (*)
  51f76cd... Fix typos in show_attr. (*)
  a9ebf24... RISC-V: Remove zba check in bitwise and ashift reassociatio (*)
  a52812a... libphobos: Bump soname to version 6 [PR117701] (*)
  a1a14ce... Fix build for STORE_FLAG_VALUE<0 targets [PR118418] (*)
  107d5d6... RISC-V: Improve bitwise and ashift reassociation for single (*)
  8d577a0... RISC-V: Fix the result error caused by not updating ratio w (*)
  7102620... RISC-V: fix thinko in riscv_register_move_cost () (*)
  2ea4801... Accept commas between clauses in OpenMP declare variant (*)
  ecf688e... RISC-V: Fix program logic errors caused by data truncation  (*)
  655a8a0... Add missing target directive in OpenMP dispatch Fortran run (*)
  7cd4de6... PR modula2/118453: Subranges types do not use virtual token (*)
  d23d338... [PR rtl-optimization/107455] Eliminate unnecessary constant (*)

(*) This commit already exists in another branch.
Because the reference `refs/users/aoliva/heads/testbase' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc/aoliva/heads/testme] (37 commits) [testsuite] [arm] adjust wmul expectations [PR113560]

2025-01-15 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 cfff1937f515... [testsuite] [arm] adjust wmul expectations [PR113560]

It previously pointed to:

 e5bef1e1c6f3... [ifcombine] robustify decode_field_reference

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  e5bef1e... [ifcombine] robustify decode_field_reference
  f87cc87... [ifcombine] check and extend constants to compare with bitf


Summary of changes (added commits):
---

  cfff193... [testsuite] [arm] adjust wmul expectations [PR113560]
  05289ed... [testsuite] [arm] multilibs.exp: adjust float abi opt match
  447aaef... [testsuite] drop explicit run overrider in more dfp tests
  3b49119... [testsuite] skip test on non-hosted libstdc++ [PR113994]
  c32ef7c... [testsuite] rearrange requirements for dfp bitint run tests
  5006b9d... [ifcombine] robustify decode_field_reference (*)
  e939005... c++: re-enable NSDMI CONSTRUCTOR folding [PR118355] (*)
  d27db30... OpenMP: Remove dead code from declare variant reimplementat (*)
  1294b81... OpenMP: Re-work and extend context selector resolution (*)
  210a090... OpenMP: New tree nodes for metadirective and dynamic select (*)
  22fe3c0... [ifcombine] check and extend constants to compare with bitf (*)
  e5e9e50... RISC-V: Fix vsetvl compatibility predicate [PR118154]. (*)
  14cb061... match: Keep conditional in simplification to constant [PR11 (*)
  87ffd20... c++/modules: Don't emit imported deduction guides [PR117397 (*)
  744a59f... Ada: add missing support for the S/390 and RISC-V architect (*)
  31c3c1a... tree-optimization/118405 - ICE with vector(1) T vs T load (*)
  20b8500... Fortran: Add LOCALITY support for DO_CONCURRENT (*)
  bbc7900... c: improve UX for -Wincompatible-pointer-types (v3) [PR1168 (*)
  f7b7fe1... c++: Add support for vec_dup to constexpr [PR118445] (*)
  c864ffe... RISC-V: Expand shift count in Xmode in interleave pattern. (*)
  f12bb6c... rs6000: Add clobber and guard for vsx_stxvd2x4_le_const [PR (*)
  f71fe87... Daily bump. (*)
  7b81510... RISC-V: Disallow negative step for interleaving [PR117682] (*)
  1f64536... RISC-V: testsuite: Skip test with -flto (*)
  9a4bb95... PR modula2/116557: Remove physical address from COPYING.FDL (*)
  51f76cd... Fix typos in show_attr. (*)
  a9ebf24... RISC-V: Remove zba check in bitwise and ashift reassociatio (*)
  a52812a... libphobos: Bump soname to version 6 [PR117701] (*)
  a1a14ce... Fix build for STORE_FLAG_VALUE<0 targets [PR118418] (*)
  107d5d6... RISC-V: Improve bitwise and ashift reassociation for single (*)
  8d577a0... RISC-V: Fix the result error caused by not updating ratio w (*)
  7102620... RISC-V: fix thinko in riscv_register_move_cost () (*)
  2ea4801... Accept commas between clauses in OpenMP declare variant (*)
  ecf688e... RISC-V: Fix program logic errors caused by data truncation  (*)
  655a8a0... Add missing target directive in OpenMP dispatch Fortran run (*)
  7cd4de6... PR modula2/118453: Subranges types do not use virtual token (*)
  d23d338... [PR rtl-optimization/107455] Eliminate unnecessary constant (*)

(*) This commit already exists in another branch.
Because the reference `refs/users/aoliva/heads/testme' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc(refs/users/aoliva/heads/testme)] [testsuite] drop explicit run overrider in more dfp tests

2025-01-15 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:447aaefe0a307303ee15664f0151541876871344

commit 447aaefe0a307303ee15664f0151541876871344
Author: Alexandre Oliva 
Date:   Thu Jan 16 02:52:56 2025 -0300

[testsuite] drop explicit run overrider in more dfp tests

A few more dfp tests that recently got backported to gcc-14 override
dfp.exp's selection of default action depending on dfprt.  Let the
default stand.


for  gcc/testsuite/ChangeLog

* gcc.dg/dfp/pr102674.c: Use the default dg-do.
* gcc.dg/dfp/pr43374.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.dg/dfp/pr102674.c | 1 -
 gcc/testsuite/gcc.dg/dfp/pr43374.c  | 1 -
 2 files changed, 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/dfp/pr102674.c 
b/gcc/testsuite/gcc.dg/dfp/pr102674.c
index c67ecf5ce71b..8139353d5ca1 100644
--- a/gcc/testsuite/gcc.dg/dfp/pr102674.c
+++ b/gcc/testsuite/gcc.dg/dfp/pr102674.c
@@ -1,5 +1,4 @@
 /* PR middle-end/102674 */
-/* { dg-do run } */
 /* { dg-options "-O2" } */
 
 #define FP_NAN 0
diff --git a/gcc/testsuite/gcc.dg/dfp/pr43374.c 
b/gcc/testsuite/gcc.dg/dfp/pr43374.c
index 83f3dca1c1f2..3ecadd1bac02 100644
--- a/gcc/testsuite/gcc.dg/dfp/pr43374.c
+++ b/gcc/testsuite/gcc.dg/dfp/pr43374.c
@@ -1,5 +1,4 @@
 /* PR middle-end/43374 */
-/* { dg-do run } */
 /* { dg-options "-O2" } */
 
 __attribute__((noipa)) int


[gcc(refs/users/aoliva/heads/testme)] [testsuite] [arm] multilibs.exp: adjust float abi opt matching

2025-01-15 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:05289ed06f798cf1404664fa75056df78ef7e804

commit 05289ed06f798cf1404664fa75056df78ef7e804
Author: Alexandre Oliva 
Date:   Thu Jan 16 02:53:13 2025 -0300

[testsuite] [arm] multilibs.exp: adjust float abi opt matching

The regexp that matches options that mess with multilibs matches
-mfloat=abi=, but that's probably a typo for -mfloat-abi=.  Fix that,
and add -msoft-float and -mhard-float.


for  gcc/testsuite/ChangeLog

* gcc.target/arm/multilib.exp: Skip if -mfloat-abi=* or any of
its aliases are used.

Diff:
---
 gcc/testsuite/gcc.target/arm/multilib.exp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/arm/multilib.exp 
b/gcc/testsuite/gcc.target/arm/multilib.exp
index 9b5e22e86d01..05fb31316628 100644
--- a/gcc/testsuite/gcc.target/arm/multilib.exp
+++ b/gcc/testsuite/gcc.target/arm/multilib.exp
@@ -20,7 +20,7 @@ dg-init
 
 foreach flagsvar {multilib_flags cflags} {
   if { [board_info [target_info name] exists $flagsvar] 
- && [regexp {(-marm|-mthumb|-march=.*|-mcpu=.*|-mfpu=.*|-mfloat=abi=.*)\y} 
[board_info [target_info name] $flagsvar]] } {
+ && [regexp 
{(-marm|-mthumb|-march=.*|-mcpu=.*|-mfpu=.*|-mfloat-abi=.*|-msoft-float|-mhard-float)\y}
 [board_info [target_info name] $flagsvar]] } {

 # Multilib flags override anything we can apply to a test, so
 # skip if any of the above options are set there.


[gcc r15-6939] tree-optimization/115895 - overrun with masked loop

2025-01-15 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:1b5d2ccd060ce983c7459ee165275e0205271396

commit r15-6939-g1b5d2ccd060ce983c7459ee165275e0205271396
Author: Richard Biener 
Date:   Tue Jan 14 15:26:21 2025 +0100

tree-optimization/115895 - overrun with masked loop

The following addresses the fact that with loop masking (or regular
mask loads) we do not implement load shortening but we override
the case where we need that for correctness.  Likewise when we
attempt to use loop masking to handle large trailing gaps we cannot
do so when there's this overrun case.

PR tree-optimization/115895
* tree-vect-stmts.cc (get_group_load_store_type): When we
might overrun because the group size is not a multiple of the
vector size we cannot use loop masking since that does not
implement the required load shortening.

* gcc.target/i386/vect-pr115895.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.target/i386/vect-pr115895.c | 65 +++
 gcc/tree-vect-stmts.cc| 24 +++---
 2 files changed, 84 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.target/i386/vect-pr115895.c 
b/gcc/testsuite/gcc.target/i386/vect-pr115895.c
new file mode 100644
index ..2246c66d37ea
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vect-pr115895.c
@@ -0,0 +1,65 @@
+/* For some targets we end up vectorizing the below loop such that the `sp`
+   single integer is loaded into a 4 integer vector.
+   While the writes are all safe, without 2 scalar loops being peeled into the
+   epilogue we would read past the end of the 31 integer array.  This happens
+   because we load a 4 integer chunk to only use the first integer and
+   increment by 2 integers at a time, hence the last load needs s[30-33] and
+   the penultimate load needs s[28-31].
+   This testcase ensures that we do not crash due to that behaviour.  */
+/* { dg-do run } */
+/* { dg-options "-std=gnu17 -O2 -ftree-vectorize -fno-vect-cost-model --param 
vect-partial-vector-usage=2 -mavx512bw -mprefer-vector-width=512" } */
+/* { dg-require-effective-target mmap } */
+#include 
+#include 
+
+#define MMAP_SIZE 0x2
+#define ADDRESS 0x112200
+
+#define MB_BLOCK_SIZE 16
+#define VERT_PRED_16 0
+#define HOR_PRED_16 1
+#define DC_PRED_16 2
+int *sptr;
+extern void intrapred_luma_16x16();
+unsigned short mprr_2[5][16][16];
+void initialise_s(int *s) { }
+int main_1() {
+void *s_mapping;
+void *end_s;
+s_mapping = mmap ((void *)ADDRESS, MMAP_SIZE, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+if (s_mapping == MAP_FAILED)
+  {
+   perror ("mmap");
+   return 1;
+  }
+end_s = (s_mapping + MMAP_SIZE);
+sptr = (int*)(end_s - sizeof(int[31]));
+intrapred_luma_16x16(sptr);
+return 0;
+}
+
+void intrapred_luma_16x16(int * restrict sp) {
+for (int j=0; j < MB_BLOCK_SIZE; j++)
+  {
+   mprr_2[VERT_PRED_16][j][0]=sp[j*2];
+   mprr_2[VERT_PRED_16][j][1]=sp[j*2];
+   mprr_2[VERT_PRED_16][j][2]=sp[j*2];
+   mprr_2[VERT_PRED_16][j][3]=sp[j*2];
+   mprr_2[VERT_PRED_16][j][4]=sp[j*2];
+   mprr_2[VERT_PRED_16][j][5]=sp[j*2];
+   mprr_2[VERT_PRED_16][j][6]=sp[j*2];
+   mprr_2[VERT_PRED_16][j][7]=sp[j*2];
+   mprr_2[VERT_PRED_16][j][8]=sp[j*2];
+   mprr_2[VERT_PRED_16][j][9]=sp[j*2];
+   mprr_2[VERT_PRED_16][j][10]=sp[j*2];
+   mprr_2[VERT_PRED_16][j][11]=sp[j*2];
+   mprr_2[VERT_PRED_16][j][12]=sp[j*2];
+   mprr_2[VERT_PRED_16][j][13]=sp[j*2];
+   mprr_2[VERT_PRED_16][j][14]=sp[j*2];
+   mprr_2[VERT_PRED_16][j][15]=sp[j*2];
+  }
+}
+
+#define DO_TEST main_1
+#include "avx512-check.h"
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 0c0f999d3e3c..b5dd1a2e40f1 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -2216,13 +2216,14 @@ get_group_load_store_type (vec_info *vinfo, 
stmt_vec_info stmt_info,
 
 If there is a combination of the access not covering the full
 vector and a gap recorded then we may need to peel twice.  */
+ bool large_vector_overrun_p = false;
  if (loop_vinfo
  && (*memory_access_type == VMAT_CONTIGUOUS
  || *memory_access_type == VMAT_CONTIGUOUS_REVERSE)
  && SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()
  && !multiple_p (group_size * LOOP_VINFO_VECT_FACTOR (loop_vinfo),
  nunits))
-   overrun_p = true;
+   large_vector_overrun_p = overrun_p = true;
 
  /* If the gap splits the vector in half and the target
 can do half-vector operations avoid the epilogue peeling
@@ -2273,7 +2274,8 @@ get_group_load_store_type (vec_info *vinfo, stmt_vec_info 
stmt_info,
 access and that is sufficiently small to be covered
 by the single scalar iteration.  */
  unsign

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Utilisation gfc_clear_descriptor dans gfc_conv_derived_to_class

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:db8dddefb7b3659f1307058b98421fc9edf2e6de

commit db8dddefb7b3659f1307058b98421fc9edf2e6de
Author: Mikael Morin 
Date:   Wed Dec 11 16:03:10 2024 +0100

Utilisation gfc_clear_descriptor dans gfc_conv_derived_to_class

essai suppression

Suppression fonction inutilisée

Sauvegarde compilation OK

Correction régression

Sauvegarde correction null_actual_6

Commentage fonction inutilisée

Correction bornes descripteur null

Diff:
---
 gcc/fortran/trans-array.cc | 339 +++--
 gcc/fortran/trans-array.h  |   4 +-
 gcc/fortran/trans-expr.cc  |  87 ++--
 3 files changed, 373 insertions(+), 57 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index d15576adde10..0370d10d9ebd 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -592,10 +592,10 @@ get_size_info (gfc_typespec &ts)
if (POINTER_TYPE_P (type))
  type = TREE_TYPE (type);
gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
-   tree elt_type = TREE_TYPE (type);
+   tree char_type = TREE_TYPE (type);
tree len = ts.u.cl->backend_decl;
return fold_build2_loc (input_location, MULT_EXPR, size_type_node,
-   size_in_bytes (elt_type),
+   size_in_bytes (char_type),
fold_convert (size_type_node, len));
   }
 
@@ -613,8 +613,61 @@ get_size_info (gfc_typespec &ts)
 }
 
 
+class init_info
+{
+public:
+  virtual bool initialize_data () const { return false; }
+  virtual tree get_data_value () const { return NULL_TREE; }
+  virtual gfc_typespec *get_type () const { return nullptr; }
+};
+
+
+class default_init : public init_info
+{
+private:
+  const symbol_attribute &attr; 
+
+public:
+  default_init (const symbol_attribute &arg_attr) : attr(arg_attr) { }
+  virtual bool initialize_data () const { return !attr.pointer; }
+  virtual tree get_data_value () const {
+if (!initialize_data ())
+  return NULL_TREE;
+
+return null_pointer_node;
+  }
+};
+
+class nullification : public init_info
+{
+private:
+  gfc_typespec &ts;
+
+public:
+  nullification(gfc_typespec &arg_ts) : ts(arg_ts) { }
+  virtual bool initialize_data () const { return true; }
+  virtual tree get_data_value () const { return null_pointer_node; }
+  virtual gfc_typespec *get_type () const { return &ts; }
+};
+
+class scalar_value : public init_info
+{
+private:
+  gfc_typespec &ts;
+  tree value;
+
+public:
+  scalar_value(gfc_typespec &arg_ts, tree arg_value)
+: ts(arg_ts), value(arg_value) { }
+  virtual bool initialize_data () const { return true; }
+  virtual tree get_data_value () const { return value; }
+  virtual gfc_typespec *get_type () const { return &ts; }
+};
+
+
 static tree
-build_dtype (gfc_typespec &ts, int rank, const symbol_attribute &)
+build_dtype (gfc_typespec &ts, int rank, const symbol_attribute &,
+const init_info &init)
 {
   vec *v = nullptr;
 
@@ -622,11 +675,17 @@ build_dtype (gfc_typespec &ts, int rank, const 
symbol_attribute &)
 
   tree fields = TYPE_FIELDS (type);
 
-  if (ts.type != BT_CLASS)
+  gfc_typespec *type_info = init.get_type ();
+  if (type_info == nullptr)
+type_info = &ts;
+
+  if (!(type_info->type == BT_CLASS
+   || (type_info->type == BT_CHARACTER
+   && type_info->deferred)))
 {
   tree elem_len_field = gfc_advance_chain (fields, GFC_DTYPE_ELEM_LEN);
   tree elem_len_val = fold_convert (TREE_TYPE (elem_len_field),
-   get_size_info (ts));
+   get_size_info (*type_info));
   CONSTRUCTOR_APPEND_ELT (v, elem_len_field, elem_len_val);
 }
 
@@ -641,11 +700,11 @@ build_dtype (gfc_typespec &ts, int rank, const 
symbol_attribute &)
   CONSTRUCTOR_APPEND_ELT (v, rank_field, rank_val);
 }
 
-  if (ts.type != BT_CLASS)
+  if (type_info->type != BT_CLASS)
 {
   tree type_info_field = gfc_advance_chain (fields, GFC_DTYPE_TYPE);
   tree type_info_val = build_int_cst (TREE_TYPE (type_info_field),
- get_type_info (ts));
+ get_type_info (*type_info));
   CONSTRUCTOR_APPEND_ELT (v, type_info_field, type_info_val);
 }
 
@@ -656,8 +715,8 @@ build_dtype (gfc_typespec &ts, int rank, const 
symbol_attribute &)
 /* Build a null array descriptor constructor.  */
 
 vec *
-get_default_descriptor_init (tree type, gfc_typespec &ts, int rank,
-const symbol_attribute &attr)
+get_descriptor_init (tree type, gfc_typespec &ts, int rank,
+const symbol_attribute &attr, const init_info &init)
 {
   vec *v = nullptr;
 
@@ -666,15 +725,15 @@ get_default_descriptor_init (tree type, gfc_typespec &ts, 
int rank,
   tree fields = TYPE_FIELDS (type);
 
   /* Don't init pointers by default.  */
-  if 

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Introduction gfc_copy_sequence_descriptor

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:6d1a550acfb35381deea5afbd424a7e79852f5b1

commit 6d1a550acfb35381deea5afbd424a7e79852f5b1
Author: Mikael Morin 
Date:   Tue Dec 31 15:27:35 2024 +0100

Introduction gfc_copy_sequence_descriptor

Correction régression sizeof_6

Diff:
---
 gcc/fortran/trans-array.cc | 39 ++-
 gcc/fortran/trans-expr.cc  | 44 
 gcc/fortran/trans.h|  1 +
 3 files changed, 59 insertions(+), 25 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 4c237b561aa6..5d56a12ebf71 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -9901,32 +9901,21 @@ gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr, 
bool g77,
  if (maybe_shift && !keep_descriptor_lower_bound (expr))
conv_shift_descriptor (&block, se->expr, expr->rank);
 
+ bool assumed_rank_fsym;
+ if (fsym
+ && ((fsym->ts.type == BT_CLASS
+  && CLASS_DATA (fsym)->as
+  && CLASS_DATA (fsym)->as->type == AS_ASSUMED_RANK)
+ || (fsym->ts.type != BT_CLASS
+ && fsym->as
+ && fsym->as->type == AS_ASSUMED_RANK)))
+   assumed_rank_fsym = true;
+ else
+   assumed_rank_fsym = false;
+
  tmp = gfc_class_data_get (ctree);
- if (expr->rank > 1 && CLASS_DATA (fsym)->as->rank != expr->rank
- && CLASS_DATA (fsym)->as->type == AS_EXPLICIT && !no_pack)
-   {
- tree arr = gfc_create_var (TREE_TYPE (tmp), "parm");
- gfc_conv_descriptor_data_set (&block, arr,
-   gfc_conv_descriptor_data_get (
- se->expr));
- gfc_conv_descriptor_lbound_set (&block, arr, gfc_index_zero_node,
- gfc_index_zero_node);
- gfc_conv_descriptor_ubound_set (
-   &block, arr, gfc_index_zero_node,
-   gfc_conv_descriptor_size (se->expr, expr->rank));
- gfc_conv_descriptor_stride_set (
-   &block, arr, gfc_index_zero_node,
-   gfc_conv_descriptor_stride_get (se->expr, gfc_index_zero_node));
- gfc_add_modify (&block, gfc_conv_descriptor_dtype (arr),
- gfc_conv_descriptor_dtype (se->expr));
- gfc_add_modify (&block, gfc_conv_descriptor_rank (arr),
- build_int_cst (signed_char_type_node, 1));
- gfc_conv_descriptor_span_set (&block, arr,
-   gfc_conv_descriptor_span_get (arr));
- gfc_conv_descriptor_offset_set (&block, arr, gfc_index_zero_node);
- se->expr = arr;
-   }
- gfc_class_array_data_assign (&block, tmp, se->expr, true);
+ gfc_copy_sequence_descriptor (block, tmp, se->expr,
+   assumed_rank_fsym);
 
  /* Handle optional.  */
  if (fsym && fsym->attr.optional && sym && sym->attr.optional)
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 003754cdad6f..5dff9692f0ba 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -846,6 +846,50 @@ descriptor_rank (tree descriptor)
 }
 
 
+void
+gfc_copy_sequence_descriptor (stmtblock_t &block, tree lhs_desc, tree rhs_desc,
+ bool assumed_rank_lhs)
+{
+  int lhs_rank = descriptor_rank (lhs_desc);
+  int rhs_rank = descriptor_rank (rhs_desc);
+  tree desc;
+
+  if (assumed_rank_lhs || lhs_rank == rhs_rank)
+desc = rhs_desc;
+  else
+{
+  tree arr = gfc_create_var (TREE_TYPE (lhs_desc), "parm");
+  gfc_conv_descriptor_data_set (&block, arr,
+   gfc_conv_descriptor_data_get (rhs_desc));
+  gfc_conv_descriptor_lbound_set (&block, arr, gfc_index_zero_node,
+ gfc_index_zero_node);
+  tree size = gfc_conv_descriptor_size (rhs_desc, rhs_rank);
+  gfc_conv_descriptor_ubound_set (&block, arr, gfc_index_zero_node, size);
+  gfc_conv_descriptor_stride_set (
+   &block, arr, gfc_index_zero_node,
+   gfc_conv_descriptor_stride_get (rhs_desc, gfc_index_zero_node));
+  for (int i = 1; i < lhs_rank; i++)
+   {
+ gfc_conv_descriptor_lbound_set (&block, arr, gfc_rank_cst[i],
+ gfc_index_zero_node);
+ gfc_conv_descriptor_ubound_set (&block, arr, gfc_rank_cst[i],
+ gfc_index_zero_node);
+ gfc_conv_descriptor_stride_set (&block, arr, gfc_rank_cst[i], size);
+   }
+  gfc_add_modify (&block, gfc_conv_descriptor_dtype (arr),
+ gfc_conv_descriptor_dtype (rhs_desc));
+  gfc_add_modify (&block, gfc_conv_descriptor_rank (arr),
+ build_int_cst (signed_cha

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Factorisation gfc_conv_remap_descriptor

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:7ed00263a569c00bf6bf52ea343e677b873e0e2f

commit 7ed00263a569c00bf6bf52ea343e677b873e0e2f
Author: Mikael Morin 
Date:   Sat Jan 4 21:36:13 2025 +0100

Factorisation gfc_conv_remap_descriptor

Correction régression pointer_remapping_5

Diff:
---
 gcc/fortran/trans-array.cc | 119 +++
 gcc/fortran/trans-expr.cc  | 124 +++--
 gcc/fortran/trans.h|   2 +
 3 files changed, 129 insertions(+), 116 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 5d56a12ebf71..898930634ad1 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1332,6 +1332,125 @@ gfc_conv_shift_descriptor (stmtblock_t *block, tree 
desc,
 }
 
 
+void
+gfc_conv_remap_descriptor (stmtblock_t *block, tree dest, tree src,
+  int src_rank, const gfc_array_spec &as)
+{
+  int dest_rank = gfc_descriptor_rank (dest);
+
+  /* Set dtype.  */
+  tree dtype = gfc_conv_descriptor_dtype (dest);
+  tree tmp = gfc_get_dtype (TREE_TYPE (src));
+  gfc_add_modify (block, dtype, tmp);
+
+  /* Copy data pointer.  */
+  tree data = gfc_conv_descriptor_data_get (src);
+  gfc_conv_descriptor_data_set (block, dest, data);
+
+  /* Copy the span.  */
+  tree span;
+  if (VAR_P (src)
+  && GFC_DECL_PTR_ARRAY_P (src))
+span = gfc_conv_descriptor_span_get (src);
+  else
+{
+  tmp = TREE_TYPE (src);
+  tmp = TYPE_SIZE_UNIT (gfc_get_element_type (tmp));
+  span = fold_convert (gfc_array_index_type, tmp);
+}
+  gfc_conv_descriptor_span_set (block, dest, span);
+
+  /* Copy offset but adjust it such that it would correspond
+ to a lbound of zero.  */
+  if (src_rank == -1)
+gfc_conv_descriptor_offset_set (block, dest,
+   gfc_index_zero_node);
+  else
+{
+  tree offs = gfc_conv_descriptor_offset_get (src);
+  for (int dim = 0; dim < src_rank; ++dim)
+   {
+ tree stride = gfc_conv_descriptor_stride_get (src,
+   gfc_rank_cst[dim]);
+ tree lbound = gfc_conv_descriptor_lbound_get (src,
+   gfc_rank_cst[dim]);
+ tmp = fold_build2_loc (input_location, MULT_EXPR,
+gfc_array_index_type, stride,
+lbound);
+ offs = fold_build2_loc (input_location, PLUS_EXPR,
+ gfc_array_index_type, offs, tmp);
+   }
+  gfc_conv_descriptor_offset_set (block, dest, offs);
+}
+  /* Set the bounds as declared for the LHS and calculate strides as
+ well as another offset update accordingly.  */
+  tree stride = gfc_conv_descriptor_stride_get (src,
+  gfc_rank_cst[0]);
+  for (int dim = 0; dim < dest_rank; ++dim)
+{
+  gfc_se lower_se;
+  gfc_se upper_se;
+
+  gcc_assert (as.lower[dim] && as.upper[dim]);
+
+  /* Convert declared bounds.  */
+  gfc_init_se (&lower_se, NULL);
+  gfc_init_se (&upper_se, NULL);
+  gfc_conv_expr (&lower_se, as.lower[dim]);
+  gfc_conv_expr (&upper_se, as.upper[dim]);
+
+  gfc_add_block_to_block (block, &lower_se.pre);
+  gfc_add_block_to_block (block, &upper_se.pre);
+
+  tree lbound = fold_convert (gfc_array_index_type, lower_se.expr);
+  tree ubound = fold_convert (gfc_array_index_type, upper_se.expr);
+
+  lbound = gfc_evaluate_now (lbound, block);
+  ubound = gfc_evaluate_now (ubound, block);
+
+  gfc_add_block_to_block (block, &lower_se.post);
+  gfc_add_block_to_block (block, &upper_se.post);
+
+  /* Set bounds in descriptor.  */
+  gfc_conv_descriptor_lbound_set (block, dest,
+ gfc_rank_cst[dim], lbound);
+  gfc_conv_descriptor_ubound_set (block, dest,
+ gfc_rank_cst[dim], ubound);
+
+  /* Set stride.  */
+  stride = gfc_evaluate_now (stride, block);
+  gfc_conv_descriptor_stride_set (block, dest,
+ gfc_rank_cst[dim], stride);
+
+  /* Update offset.  */
+  tree offs = gfc_conv_descriptor_offset_get (dest);
+  tmp = fold_build2_loc (input_location, MULT_EXPR,
+gfc_array_index_type, lbound, stride);
+  offs = fold_build2_loc (input_location, MINUS_EXPR,
+ gfc_array_index_type, offs, tmp);
+  offs = gfc_evaluate_now (offs, block);
+  gfc_conv_descriptor_offset_set (block, dest, offs);
+
+  /* Update stride.  */
+  tmp = gfc_conv_array_extent_dim (lbound, ubound, NULL);
+  stride = fold_build2_loc (input_location, MULT_EXPR,
+   gfc_array_index_type, stride, tmp);
+}
+}
+
+
+void
+gfc_conv_remap_descriptor (stmtblock_t *block, tree dest, tree src,
+  int src_rank, const gfc_array_ref &ar)
+{
+  g

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Appel méthode shift descriptor dans gfc_trans_pointer_assignment

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:ecdc8da68c9d5419d4c0e6ec9b1b3278076cbdf0

commit ecdc8da68c9d5419d4c0e6ec9b1b3278076cbdf0
Author: Mikael Morin 
Date:   Tue Dec 17 22:37:18 2024 +0100

Appel méthode shift descriptor dans gfc_trans_pointer_assignment

Diff:
---
 gcc/fortran/trans-array.cc | 129 +++--
 gcc/fortran/trans-array.h  |   1 +
 gcc/fortran/trans-expr.cc  |  28 +-
 3 files changed, 129 insertions(+), 29 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 2fdd15962e49..cdbff27d82ca 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1151,13 +1151,136 @@ gfc_conv_shift_descriptor_lbound (stmtblock_t* block, 
tree desc,
 }
 
 
+class lb_info
+{
+public:
+  virtual gfc_expr *lower_bound (int dim) const = 0;
+};
+
+
+class unset_lb : public lb_info
+{
+public:
+  virtual gfc_expr *lower_bound (int) const { return nullptr; }
+};
+
+
+class defined_lb : public lb_info
+{
+  int rank;
+  gfc_expr * const * lower_bounds;
+
+public:
+  defined_lb (int arg_rank, gfc_expr * const 
arg_lower_bounds[GFC_MAX_DIMENSIONS])
+: rank(arg_rank), lower_bounds(arg_lower_bounds) { }
+  virtual gfc_expr *lower_bound (int dim) const { return lower_bounds[dim]; }
+};
+
+
 static void
-conv_shift_descriptor (stmtblock_t* block, tree desc, int rank)
+conv_shift_descriptor (stmtblock_t *block, tree desc, int rank,
+  const lb_info &info)
 {
   /* Apply a shift of the lbound when supplied.  */
   for (int dim = 0; dim < rank; ++dim)
-gfc_conv_shift_descriptor_lbound (block, desc, dim,
- gfc_index_one_node);
+{
+  gfc_expr *lb_expr = info.lower_bound(dim);
+
+  tree lower_bound;
+  if (lb_expr == nullptr)
+   lower_bound = gfc_index_one_node;
+  else
+   {
+ gfc_se lb_se;
+
+ gfc_init_se (&lb_se, nullptr);
+ gfc_conv_expr (&lb_se, lb_expr);
+
+ gfc_add_block_to_block (block, &lb_se.pre);
+ tree lb_var = gfc_create_var (TREE_TYPE (lb_se.expr), "lower_bound");
+ gfc_add_modify (block, lb_var, lb_se.expr);
+ gfc_add_block_to_block (block, &lb_se.post);
+
+ lower_bound = lb_var;
+   }
+
+  gfc_conv_shift_descriptor_lbound (block, desc, dim, lower_bound);
+}
+}
+
+
+static void
+conv_shift_descriptor (stmtblock_t* block, tree desc, int rank)
+{
+  conv_shift_descriptor (block, desc, rank, unset_lb ());
+}
+
+
+static void
+conv_shift_descriptor (stmtblock_t *block, tree desc, int rank,
+  gfc_expr * const lower_bounds[GFC_MAX_DIMENSIONS])
+{
+  conv_shift_descriptor (block, desc, rank, defined_lb (rank, lower_bounds));
+}
+
+
+static void
+conv_shift_descriptor (stmtblock_t *block, tree desc,
+  const gfc_array_spec &as)
+{
+  conv_shift_descriptor (block, desc, as.rank, as.lower);
+}
+
+
+static void
+set_type (array_type &type, array_type value)
+{
+  gcc_assert (type == AS_UNKNOWN || type == value);
+  type = value;
+}
+
+
+static void
+array_ref_to_array_spec (const gfc_array_ref &ref, gfc_array_spec &spec)
+{
+  spec.rank = ref.dimen;
+  spec.corank = ref.codimen;
+
+  spec.type = AS_UNKNOWN;
+  spec.cotype = AS_ASSUMED_SIZE;
+
+  for (int dim = 0; dim < spec.rank + spec.corank; dim++)
+switch (ref.dimen_type[dim])
+  {
+  case DIMEN_ELEMENT:
+   spec.upper[dim] = ref.start[dim];
+   set_type (spec.type, AS_EXPLICIT);
+   break;
+
+  case DIMEN_RANGE:
+   spec.lower[dim] = ref.start[dim];
+   spec.upper[dim] = ref.end[dim];
+   if (spec.upper[dim] == nullptr)
+ set_type (spec.type, AS_DEFERRED);
+   else
+ set_type (spec.type, AS_EXPLICIT);
+   break;
+
+  default:
+   break;
+  }
+}
+
+
+void
+gfc_conv_shift_descriptor (stmtblock_t *block, tree desc,
+  const gfc_array_ref &ar)
+{
+  gfc_array_spec as;
+
+  array_ref_to_array_spec (ar, as);
+
+  conv_shift_descriptor (block, desc, as);
 }
 
 
diff --git a/gcc/fortran/trans-array.h b/gcc/fortran/trans-array.h
index 17e3d08fdba0..3b05a2eb197a 100644
--- a/gcc/fortran/trans-array.h
+++ b/gcc/fortran/trans-array.h
@@ -214,6 +214,7 @@ tree gfc_get_cfi_dim_sm (tree, tree);
 
 /* Shift lower bound of descriptor, updating ubound and offset.  */
 void gfc_conv_shift_descriptor_lbound (stmtblock_t*, tree, int, tree);
+void gfc_conv_shift_descriptor (stmtblock_t*, tree, const gfc_array_ref &);
 
 /* Add pre-loop scalarization code for intrinsic functions which require
special handling.  */
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index e8b229d853e3..1de4a73974d6 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -11180,32 +11180,8 @@ gfc_trans_pointer_assignment (gfc_expr * expr1, 
gfc_expr * expr2)
}
}
  else
-   {
- /* Bounds remapping.  Just shift the lower bounds.  */
-
- 

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Factorisation copie gfc_conv_expr_descriptor

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:82413c99dc41ba8b632e751540ba26d97ea67ceb

commit 82413c99dc41ba8b632e751540ba26d97ea67ceb
Author: Mikael Morin 
Date:   Wed Jan 15 17:51:21 2025 +0100

Factorisation copie gfc_conv_expr_descriptor

Diff:
---
 gcc/fortran/trans-array.cc | 37 ++---
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 7d43a8c000d3..097a9a0d860a 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -8989,6 +8989,26 @@ is_explicit_coarray (gfc_expr *expr)
   return cas && cas->cotype == AS_EXPLICIT;
 }
 
+
+static void
+copy_descriptor (stmtblock_t *block, tree dest, tree src,
+gfc_expr *src_expr, bool subref)
+{
+  /* Copy the descriptor for pointer assignments.  */
+  gfc_add_modify (block, dest, src);
+
+  /* Add any offsets from subreferences.  */
+  gfc_get_dataptr_offset (block, dest, src, NULL_TREE, subref, src_expr);
+
+  /* and set the span field.  */
+  tree tmp;
+  if (src_expr->ts.type == BT_CHARACTER)
+tmp = gfc_conv_descriptor_span_get (src);
+  else
+tmp = gfc_get_array_span (src, src_expr);
+  gfc_conv_descriptor_span_set (block, dest, tmp);
+}
+
 /* Convert an array for passing as an actual argument.  Expressions and
vector subscripts are evaluated and stored in a temporary, which is then
passed.  For whole arrays the descriptor is passed.  For array sections
@@ -9123,21 +9143,8 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
   if (full && !transposed_dims (ss))
{
  if (se->direct_byref && !se->byref_noassign)
-   {
- /* Copy the descriptor for pointer assignments.  */
- gfc_add_modify (&se->pre, se->expr, desc);
-
- /* Add any offsets from subreferences.  */
- gfc_get_dataptr_offset (&se->pre, se->expr, desc, NULL_TREE,
- subref_array_target, expr);
-
- /* and set the span field.  */
- if (ss_info->expr->ts.type == BT_CHARACTER)
-   tmp = gfc_conv_descriptor_span_get (desc);
- else
-   tmp = gfc_get_array_span (desc, expr);
- gfc_conv_descriptor_span_set (&se->pre, se->expr, tmp);
-   }
+   copy_descriptor (&se->pre, se->expr, desc, expr,
+subref_array_target);
  else if (se->want_pointer)
{
  /* We pass full arrays directly.  This means that pointers and


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Extraction fonction fcncall_realloc_result

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:ed6fee22d9c29ebee21ce323726fb14cfb8d6ed1

commit ed6fee22d9c29ebee21ce323726fb14cfb8d6ed1
Author: Mikael Morin 
Date:   Thu Jan 9 21:38:39 2025 +0100

Extraction fonction fcncall_realloc_result

Correction variable inutilisée

Correction régression coarray dummy_3

Correction régression dummy_3

Diff:
---
 gcc/fortran/trans-array.cc | 64 ++
 gcc/fortran/trans-array.h  |  1 +
 gcc/fortran/trans-expr.cc  | 52 +++--
 3 files changed, 80 insertions(+), 37 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 898930634ad1..7d43a8c000d3 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1451,6 +1451,70 @@ gfc_conv_remap_descriptor (stmtblock_t *block, tree 
dest, tree src,
 }
 
 
+class conditional_lb
+{
+  tree cond;
+public:
+  conditional_lb (tree arg_cond)
+: cond (arg_cond) { }
+
+  tree lower_bound (tree src, int n) const {
+tree lbound = gfc_conv_descriptor_lbound_get (src, gfc_rank_cst[n]);
+lbound = fold_build3_loc (input_location, COND_EXPR,
+ gfc_array_index_type, cond,
+ gfc_index_one_node, lbound);
+return lbound;
+  }
+};
+
+
+static void
+gfc_conv_shift_descriptor (stmtblock_t *block, tree dest, tree src,
+  int rank, const conditional_lb &lb)
+{
+  tree tmp = gfc_conv_descriptor_data_get (src);
+  gfc_conv_descriptor_data_set (block, dest, tmp);
+
+  tree offset = gfc_index_zero_node;
+  for (int n = 0 ; n < rank; n++)
+{
+  tree lbound;
+
+  lbound = lb.lower_bound (dest, n);
+  lbound = gfc_evaluate_now (lbound, block);
+
+  tmp = gfc_conv_descriptor_ubound_get (src, gfc_rank_cst[n]);
+  tmp = fold_build2_loc (input_location, PLUS_EXPR,
+gfc_array_index_type, tmp, lbound);
+  gfc_conv_descriptor_lbound_set (block, dest,
+ gfc_rank_cst[n], lbound);
+  gfc_conv_descriptor_ubound_set (block, dest,
+ gfc_rank_cst[n], tmp);
+
+  /* Set stride and accumulate the offset.  */
+  tmp = gfc_conv_descriptor_stride_get (src, gfc_rank_cst[n]);
+  gfc_conv_descriptor_stride_set (block, dest,
+ gfc_rank_cst[n], tmp);
+  tmp = fold_build2_loc (input_location, MULT_EXPR,
+gfc_array_index_type, lbound, tmp);
+  offset = fold_build2_loc (input_location, MINUS_EXPR,
+   gfc_array_index_type, offset, tmp);
+  offset = gfc_evaluate_now (offset, block);
+}
+
+  gfc_conv_descriptor_offset_set (block, dest, offset);
+}
+
+
+void
+gfc_conv_shift_descriptor (stmtblock_t *block, tree dest, tree src,
+  int rank, tree zero_cond)
+{
+  gfc_conv_shift_descriptor (block, dest, src, rank,
+conditional_lb (zero_cond));
+}
+
+
 static bool
 keep_descriptor_lower_bound (gfc_expr *e)
 {
diff --git a/gcc/fortran/trans-array.h b/gcc/fortran/trans-array.h
index 8df55c2c00a5..571322ae11ff 100644
--- a/gcc/fortran/trans-array.h
+++ b/gcc/fortran/trans-array.h
@@ -216,6 +216,7 @@ tree gfc_get_cfi_dim_sm (tree, tree);
 /* Shift lower bound of descriptor, updating ubound and offset.  */
 void gfc_conv_shift_descriptor_lbound (stmtblock_t*, tree, int, tree);
 void gfc_conv_shift_descriptor (stmtblock_t*, tree, const gfc_array_ref &);
+void gfc_conv_shift_descriptor (stmtblock_t*, tree, tree, int, tree);
 
 /* Add pre-loop scalarization code for intrinsic functions which require
special handling.  */
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index c50b1e05cdbd..77e8a55af457 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -832,6 +832,9 @@ gfc_get_vptr_from_expr (tree expr)
 int
 gfc_descriptor_rank (tree descriptor)
 {
+  if (TREE_TYPE (descriptor) != NULL_TREE)
+return GFC_TYPE_ARRAY_RANK (TREE_TYPE (descriptor));
+
   tree dim = gfc_get_descriptor_dimension (descriptor);
   tree dim_type = TREE_TYPE (dim);
   gcc_assert (TREE_CODE (dim_type) == ARRAY_TYPE);
@@ -916,8 +919,17 @@ gfc_class_array_data_assign (stmtblock_t *block, tree 
lhs_desc, tree rhs_desc,
 type = TREE_TYPE (tmp);
   else
 {
-  gcc_assert (TREE_TYPE (tmp) == TREE_TYPE (tmp2));
-  type = TREE_TYPE (tmp);
+  int corank = GFC_TYPE_ARRAY_CORANK (TREE_TYPE (lhs_desc));
+  int corank2 = GFC_TYPE_ARRAY_CORANK (TREE_TYPE (rhs_desc));
+  if (corank > 0 && corank2 == 0)
+   type = TREE_TYPE (tmp2);
+  else if (corank2 > 0 && corank == 0)
+   type = TREE_TYPE (tmp);
+  else
+   {
+ gcc_assert (TREE_TYPE (tmp) == TREE_TYPE (tmp2));
+ type = TREE_TYPE (tmp);
+   }
 }
 
   tmp = build4_loc (input_location, ARRAY_RANGE_REF, type, tmp,
@@ -11595,7 +11607,6 @@ fcncall_realloc_result (g

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Creation méthode initialisation descripteur

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:3c45ca6ee9cb09354b7ede90cf410c13adeec82c

commit 3c45ca6ee9cb09354b7ede90cf410c13adeec82c
Author: Mikael Morin 
Date:   Thu Dec 5 20:30:08 2024 +0100

Creation méthode initialisation descripteur

Utilisation méthode initialisation descripteur gfc_trans_deferred_array

Correction variable inutilisée

Correction segmentation fault

Correction regression allocatable attribute

Ajout conversion elem_len

conversion type longueur chaine

Initialisation descripteur champ par champ

Silence uninitialized warning.

Diff:
---
 gcc/fortran/expr.cc|  25 +++-
 gcc/fortran/gfortran.h |   1 +
 gcc/fortran/primary.cc |  84 +++-
 gcc/fortran/trans-array.cc | 286 +
 gcc/fortran/trans-intrinsic.cc |   2 +-
 5 files changed, 333 insertions(+), 65 deletions(-)

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 7f3f6c52fb54..e4829448f710 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -5411,27 +5411,38 @@ gfc_get_full_arrayspec_from_expr (gfc_expr *expr)
   gfc_ref *ref;
 
   if (expr->rank == 0)
-return NULL;
+return nullptr;
 
   /* Follow any component references.  */
   if (expr->expr_type == EXPR_VARIABLE
   || expr->expr_type == EXPR_CONSTANT)
 {
-  if (expr->symtree)
-   as = expr->symtree->n.sym->as;
+  gfc_symbol *sym = expr->symtree ? expr->symtree->n.sym : nullptr;
+  if (sym
+ && sym->ts.type == BT_CLASS)
+   as = CLASS_DATA (sym)->as;
+  else if (sym)
+   as = sym->as;
   else
-   as = NULL;
+   as = nullptr;
 
   for (ref = expr->ref; ref; ref = ref->next)
{
  switch (ref->type)
{
case REF_COMPONENT:
- as = ref->u.c.component->as;
+ {
+   gfc_component *comp = ref->u.c.component;
+   if (comp->ts.type == BT_CLASS)
+ as = CLASS_DATA (comp)->as;
+   else
+ as = comp->as;
+ }
  continue;
 
case REF_SUBSTRING:
case REF_INQUIRY:
+ as = nullptr;
  continue;
 
case REF_ARRAY:
@@ -5441,7 +5452,7 @@ gfc_get_full_arrayspec_from_expr (gfc_expr *expr)
  case AR_ELEMENT:
  case AR_SECTION:
  case AR_UNKNOWN:
-   as = NULL;
+   as = nullptr;
continue;
 
  case AR_FULL:
@@ -5453,7 +5464,7 @@ gfc_get_full_arrayspec_from_expr (gfc_expr *expr)
}
 }
   else
-as = NULL;
+as = nullptr;
 
   return as;
 }
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 7367db8853c6..b14857132ed7 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -4049,6 +4049,7 @@ const char *gfc_dt_lower_string (const char *);
 const char *gfc_dt_upper_string (const char *);
 
 /* primary.cc */
+symbol_attribute gfc_symbol_attr (gfc_symbol *);
 symbol_attribute gfc_variable_attr (gfc_expr *, gfc_typespec *);
 symbol_attribute gfc_expr_attr (gfc_expr *);
 symbol_attribute gfc_caf_attr (gfc_expr *, bool i = false, bool *r = NULL);
diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index 8a38720422ec..c934841f4795 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -2867,42 +2867,14 @@ check_substring:
 }
 
 
-/* Given an expression that is a variable, figure out what the
-   ultimate variable's type and attribute is, traversing the reference
-   structures if necessary.
-
-   This subroutine is trickier than it looks.  We start at the base
-   symbol and store the attribute.  Component references load a
-   completely new attribute.
-
-   A couple of rules come into play.  Subobjects of targets are always
-   targets themselves.  If we see a component that goes through a
-   pointer, then the expression must also be a target, since the
-   pointer is associated with something (if it isn't core will soon be
-   dumped).  If we see a full part or section of an array, the
-   expression is also an array.
-
-   We can have at most one full array reference.  */
-
 symbol_attribute
-gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts)
+gfc_symbol_attr (gfc_symbol *sym)
 {
-  int dimension, codimension, pointer, allocatable, target, optional;
+  int dimension, codimension, pointer, allocatable, target;
   symbol_attribute attr;
-  gfc_ref *ref;
-  gfc_symbol *sym;
-  gfc_component *comp;
-  bool has_inquiry_part;
-
-  if (expr->expr_type != EXPR_VARIABLE
-  && expr->expr_type != EXPR_FUNCTION
-  && !(expr->expr_type == EXPR_NULL && expr->ts.type != BT_UNKNOWN))
-gfc_internal_error ("gfc_variable_attr(): Expression isn't a variable");
 
-  sym = expr->symtree->n.sym;
   attr = sym->attr;
 
-  optional = attr.optional;
   if (sym->ts.type == BT_CLASS && sym->attr.class_ok && sym->ts.u.derived)
 {
 

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Sauvegarde modifs

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:e3de44455296f04e014dad8c9efaef858384cfac

commit e3de44455296f04e014dad8c9efaef858384cfac
Author: Mikael Morin 
Date:   Sat Dec 7 22:22:10 2024 +0100

Sauvegarde modifs

Annulation suppression else

Correction assertions

Initialisation vptr

Non initialisation elem_len pour les conteneurs de classe

Mise à jour class_allocatable_14

Diff:
---
 gcc/fortran/trans-array.cc  | 52 ++
 gcc/fortran/trans-array.h   |  2 +
 gcc/fortran/trans-decl.cc   | 58 +
 gcc/testsuite/gfortran.dg/class_allocate_14.f90 |  2 +-
 4 files changed, 66 insertions(+), 48 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 268de211cd66..d15576adde10 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -734,6 +734,58 @@ gfc_build_null_descriptor (tree type, gfc_typespec &ts,
 }
 
 
+tree
+gfc_build_default_class_descriptor (tree type, gfc_typespec &ts)
+{
+  vec *v = nullptr;
+
+  tree fields = TYPE_FIELDS (type);
+
+#define CLASS_DATA_FIELD 0
+#define CLASS_VPTR_FIELD 1
+
+  tree data_field = gfc_advance_chain (fields, CLASS_DATA_FIELD);
+  tree data_type = TREE_TYPE (data_field);
+
+  gcc_assert (ts.type == BT_CLASS);
+  tree data_value;
+  if (ts.u.derived->components->attr.dimension
+  || (ts.u.derived->components->attr.codimension
+ && flag_coarray != GFC_FCOARRAY_LIB))
+{
+  gcc_assert (GFC_DESCRIPTOR_TYPE_P (data_type));
+  data_value = gfc_build_null_descriptor (data_type,
+ ts,
+ 
ts.u.derived->components->as->rank,
+ ts.u.derived->components->attr);
+}
+  else
+{
+  gcc_assert (POINTER_TYPE_P (data_type));
+  data_value = fold_convert (data_type, null_pointer_node);
+}
+  CONSTRUCTOR_APPEND_ELT (v, data_field, data_value);
+
+  tree vptr_field = gfc_advance_chain (fields, CLASS_VPTR_FIELD);
+
+  tree vptr_value;
+  if (ts.u.derived->attr.unlimited_polymorphic)
+vptr_value = fold_convert (TREE_TYPE (vptr_field), null_pointer_node);
+  else
+{
+  gfc_symbol *vsym = gfc_find_derived_vtab (ts.u.derived);
+  tree vsym_decl = gfc_get_symbol_decl (vsym);
+  vptr_value = gfc_build_addr_expr (nullptr, vsym_decl);
+}
+  CONSTRUCTOR_APPEND_ELT (v, vptr_field, vptr_value);
+
+#undef CLASS_DATA_FIELD
+#undef CLASS_VPTR_FIELD
+  
+  return build_constructor (type, v);
+}
+
+
 void
 gfc_clear_descriptor (gfc_expr *var_ref, gfc_se &var)
 {
diff --git a/gcc/fortran/trans-array.h b/gcc/fortran/trans-array.h
index 1bb3294b0749..63a77d562a7b 100644
--- a/gcc/fortran/trans-array.h
+++ b/gcc/fortran/trans-array.h
@@ -140,6 +140,8 @@ void gfc_set_delta (gfc_loopinfo *);
 void gfc_conv_resolve_dependencies (gfc_loopinfo *, gfc_ss *, gfc_ss *);
 /* Build a null array descriptor constructor.  */
 tree gfc_build_null_descriptor (tree);
+tree gfc_build_default_class_descriptor (tree, gfc_typespec &);
+void gfc_clear_descriptor (stmtblock_t *block, gfc_symbol *sym, tree 
descriptor);
 
 /* Get a single array element.  */
 void gfc_conv_array_ref (gfc_se *, gfc_array_ref *, gfc_expr *, locus *);
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 4ae22a5584d0..dad15858fa6a 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -4780,16 +4780,14 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, 
gfc_wrapped_block * block)
   else if (proc_sym == proc_sym->result && IS_CLASS_ARRAY (proc_sym))
 {
   /* Nullify explicit return class arrays on entry.  */
-  tree type;
   tmp = get_proc_result (proc_sym);
-   if (tmp && GFC_CLASS_TYPE_P (TREE_TYPE (tmp)))
- {
-   gfc_start_block (&init);
-   tmp = gfc_class_data_get (tmp);
-   type = TREE_TYPE (gfc_conv_descriptor_data_get (tmp));
-   gfc_conv_descriptor_data_set (&init, tmp, build_int_cst (type, 0));
-   gfc_add_init_cleanup (block, gfc_finish_block (&init), NULL_TREE);
- }
+  if (tmp && GFC_CLASS_TYPE_P (TREE_TYPE (tmp)))
+   {
+ gfc_start_block (&init);
+ tmp = gfc_class_data_get (tmp);
+ gfc_clear_descriptor (&init, proc_sym, tmp);
+ gfc_add_init_cleanup (block, gfc_finish_block (&init), NULL_TREE);
+   }
 }
 
 
@@ -4931,48 +4929,13 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, 
gfc_wrapped_block * block)
}
}
 
-  if (sym->attr.pointer && sym->attr.dimension
- && sym->attr.save == SAVE_NONE
- && !sym->attr.use_assoc
- && !sym->attr.host_assoc
- && !sym->attr.dummy
- && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (sym->backend_decl)))
-   {
- gfc_init_block (&tmpblock);
- gfc_conv_descriptor_span_set (&tmpblock, sym->backend_decl,
-   

[gcc] Created branch 'mikael/heads/refactor_descriptor_v01' in namespace 'refs/users'

2025-01-15 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/refactor_descriptor_v01' was created in namespace 
'refs/users' pointing to:

 82413c99dc41... Factorisation copie gfc_conv_expr_descriptor


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Déplacement shift descriptor vers gfc_conv_array_parameter

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:063c0014407236e53fa5c3734cab2f3fec5fa03f

commit 063c0014407236e53fa5c3734cab2f3fec5fa03f
Author: Mikael Morin 
Date:   Tue Dec 17 17:27:24 2024 +0100

Déplacement shift descriptor vers gfc_conv_array_parameter

Suppression variables inutilisées

Diff:
---
 gcc/fortran/trans-array.cc | 49 ++
 gcc/fortran/trans-array.h  |  2 +-
 gcc/fortran/trans-expr.cc  | 20 +--
 3 files changed, 43 insertions(+), 28 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 0370d10d9ebd..2fdd15962e49 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1151,6 +1151,43 @@ gfc_conv_shift_descriptor_lbound (stmtblock_t* block, 
tree desc,
 }
 
 
+static void
+conv_shift_descriptor (stmtblock_t* block, tree desc, int rank)
+{
+  /* Apply a shift of the lbound when supplied.  */
+  for (int dim = 0; dim < rank; ++dim)
+gfc_conv_shift_descriptor_lbound (block, desc, dim,
+ gfc_index_one_node);
+}
+
+
+static bool
+keep_descriptor_lower_bound (gfc_expr *e)
+{
+  gfc_ref *ref;
+
+  /* Detect any array references with vector subscripts.  */
+  for (ref = e->ref; ref; ref = ref->next)
+if (ref->type == REF_ARRAY && ref->u.ar.type != AR_ELEMENT
+   && ref->u.ar.type != AR_FULL)
+  {
+   int dim;
+   for (dim = 0; dim < ref->u.ar.dimen; dim++)
+ if (ref->u.ar.dimen_type[dim] == DIMEN_VECTOR)
+   break;
+   if (dim < ref->u.ar.dimen)
+ break;
+  }
+
+  /* Array references with vector subscripts and non-variable
+ expressions need be converted to a one-based descriptor.  */
+  if (ref || e->expr_type != EXPR_VARIABLE)
+return false;
+
+  return true;
+}
+
+
 /* Obtain offsets for trans-types.cc(gfc_get_array_descr_info).  */
 
 void
@@ -9454,7 +9491,7 @@ is_pointer (gfc_expr *e)
 void
 gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr, bool g77,
  const gfc_symbol *fsym, const char *proc_name,
- tree *size, tree *lbshift, tree *packed)
+ tree *size, bool maybe_shift, tree *packed)
 {
   tree ptr;
   tree desc;
@@ -9690,13 +9727,9 @@ gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr, 
bool g77,
  stmtblock_t block;
 
  gfc_init_block (&block);
- if (lbshift && *lbshift)
-   {
- /* Apply a shift of the lbound when supplied.  */
- for (int dim = 0; dim < expr->rank; ++dim)
-   gfc_conv_shift_descriptor_lbound (&block, se->expr, dim,
- *lbshift);
-   }
+ if (maybe_shift && !keep_descriptor_lower_bound (expr))
+   conv_shift_descriptor (&block, se->expr, expr->rank);
+
  tmp = gfc_class_data_get (ctree);
  if (expr->rank > 1 && CLASS_DATA (fsym)->as->rank != expr->rank
  && CLASS_DATA (fsym)->as->type == AS_EXPLICIT && !no_pack)
diff --git a/gcc/fortran/trans-array.h b/gcc/fortran/trans-array.h
index 78646275b4ec..17e3d08fdba0 100644
--- a/gcc/fortran/trans-array.h
+++ b/gcc/fortran/trans-array.h
@@ -158,7 +158,7 @@ tree gfc_get_array_span (tree, gfc_expr *);
 void gfc_conv_expr_descriptor (gfc_se *, gfc_expr *);
 /* Convert an array for passing as an actual function parameter.  */
 void gfc_conv_array_parameter (gfc_se *, gfc_expr *, bool, const gfc_symbol *,
-  const char *, tree *, tree * = nullptr,
+  const char *, tree *, bool = false,
   tree * = nullptr);
 
 /* These work with both descriptors and descriptorless arrays.  */
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 6978f83cdc8c..e8b229d853e3 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -991,8 +991,6 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_symbol *fsym,
  stmtblock_t block;
  gfc_init_block (&block);
  gfc_ref *ref;
- int dim;
- tree lbshift = NULL_TREE;
 
  /* Array refs with sections indicate, that a for a formal argument
 expecting contiguous repacking needs to be done.  */
@@ -1005,25 +1003,9 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_symbol *fsym,
  && (ref || e->rank != fsym->ts.u.derived->components->as->rank))
fsym->attr.contiguous = 1;
 
- /* Detect any array references with vector subscripts.  */
- for (ref = e->ref; ref; ref = ref->next)
-   if (ref->type == REF_ARRAY && ref->u.ar.type != AR_ELEMENT
-   && ref->u.ar.type != AR_FULL)
- {
-   for (dim = 0; dim < ref->u.ar.dimen; dim++)
- if (ref->u.ar.dimen_type[dim] == DIMEN_VECTOR)
-   break;
-   if (dim < ref->u.ar.dimen)
- break;
- }
-

[gcc] Deleted branch 'mikael/heads/refactor_descriptor_v01' in namespace 'refs/users'

2025-01-15 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/refactor_descriptor_v01' in namespace 'refs/users' was 
deleted.
It previously pointed to:

 723db6802021... Factorisation copie gfc_conv_expr_descriptor

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  723db68... Factorisation copie gfc_conv_expr_descriptor
  612f8e4... Correction régression dummy_3
  25d2fec... Correction régression coarray dummy_3
  9ef2c76... Correction variable inutilisée
  ff34c5d... Extraction fonction fcncall_realloc_result
  4b81583... Correction régression pointer_remapping_5
  f3b7c9f... Factorisation gfc_conv_remap_descriptor
  4cdda4d... Correction régression sizeof_6
  9c5dab0... Introduction gfc_copy_sequence_descriptor
  10d9c97... Correction assertion même type
  9d8043c... Ajout assertion
  dd00747... Correction dump
  5139aa2... Correction régression modifiable_p
  123cd1a... Utilisation de la méthode de nullification pour nullifier 
  31afcbd... Appel méthode shift descriptor dans gfc_trans_pointer_assi
  389c655... Suppression variables inutilisées
  3e496c2... Déplacement shift descriptor vers gfc_conv_array_parameter
  67aad36... Utilisation gfc_clear_descriptor dans gfc_conv_derived_to_c
  e2cdbdc... Sauvegarde modifs
  9f001e5... Silence uninitialized warning.
  06daad8... Creation méthode initialisation descripteur


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Utilisation de la méthode de nullification pour nullifier un pointeur

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:b68e4d2ef22d8fe82d628a320c6577d1d0a946dd

commit b68e4d2ef22d8fe82d628a320c6577d1d0a946dd
Author: Mikael Morin 
Date:   Wed Dec 18 19:04:41 2024 +0100

Utilisation de la méthode de nullification pour nullifier un pointeur

Correction régression modifiable_p

Correction dump

Ajout assertion

Correction assertion même type

Diff:
---
 gcc/fortran/trans-array.cc  | 96 ++---
 gcc/fortran/trans-array.h   |  1 +
 gcc/fortran/trans-expr.cc   | 35 -
 gcc/testsuite/gfortran.dg/class_allocate_14.f90 |  2 +-
 4 files changed, 106 insertions(+), 28 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index cdbff27d82ca..4c237b561aa6 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -545,9 +545,9 @@ gfc_conv_descriptor_ubound_set (stmtblock_t *block, tree 
desc,
 
 
 static int
-get_type_info (const gfc_typespec &ts)
+get_type_info (const bt &type)
 {
-  switch (ts.type)
+  switch (type)
 {
 case BT_INTEGER:
 case BT_LOGICAL:
@@ -558,7 +558,7 @@ get_type_info (const gfc_typespec &ts)
 case BT_CLASS:
 case BT_VOID:
 case BT_UNSIGNED:
-  return ts.type;
+  return type;
 
 case BT_PROCEDURE:
 case BT_ASSUMED:
@@ -613,11 +613,34 @@ get_size_info (gfc_typespec &ts)
 }
 
 
-class init_info
+class modify_info
 {
 public:
+  virtual bool is_initialization () const { return false; }
   virtual bool initialize_data () const { return false; }
   virtual tree get_data_value () const { return NULL_TREE; }
+};
+
+class nullification : public modify_info
+{
+  virtual bool initialize_data () const { return true; }
+  virtual tree get_data_value () const { return null_pointer_node; }
+  /*
+private:
+  gfc_typespec &ts;
+
+public:
+  null_init(gfc_typespec &arg_ts) : ts(arg_ts) { }
+  virtual bool initialize_data () const { return true; }
+  virtual tree get_data_value () const { return null_pointer_node; }
+  virtual gfc_typespec *get_type () const { return &ts; }
+  */
+};
+
+class init_info : public modify_info
+{
+public:
+  virtual bool is_initialization () const { return true; }
   virtual gfc_typespec *get_type () const { return nullptr; }
 };
 
@@ -638,13 +661,13 @@ public:
   }
 };
 
-class nullification : public init_info
+class null_init : public init_info
 {
 private:
   gfc_typespec &ts;
 
 public:
-  nullification(gfc_typespec &arg_ts) : ts(arg_ts) { }
+  null_init(gfc_typespec &arg_ts) : ts(arg_ts) { }
   virtual bool initialize_data () const { return true; }
   virtual tree get_data_value () const { return null_pointer_node; }
   virtual gfc_typespec *get_type () const { return &ts; }
@@ -700,13 +723,12 @@ build_dtype (gfc_typespec &ts, int rank, const 
symbol_attribute &,
   CONSTRUCTOR_APPEND_ELT (v, rank_field, rank_val);
 }
 
-  if (type_info->type != BT_CLASS)
-{
-  tree type_info_field = gfc_advance_chain (fields, GFC_DTYPE_TYPE);
-  tree type_info_val = build_int_cst (TREE_TYPE (type_info_field),
- get_type_info (*type_info));
-  CONSTRUCTOR_APPEND_ELT (v, type_info_field, type_info_val);
-}
+  tree type_info_field = gfc_advance_chain (fields, GFC_DTYPE_TYPE);
+  tree type_info_val = build_int_cst (TREE_TYPE (type_info_field),
+ get_type_info (type_info->type == BT_CLASS
+? BT_DERIVED
+: type_info->type));
+  CONSTRUCTOR_APPEND_ELT (v, type_info_field, type_info_val);
 
   return build_constructor (type, v);
 }
@@ -715,8 +737,8 @@ build_dtype (gfc_typespec &ts, int rank, const 
symbol_attribute &,
 /* Build a null array descriptor constructor.  */
 
 vec *
-get_descriptor_init (tree type, gfc_typespec &ts, int rank,
-const symbol_attribute &attr, const init_info &init)
+get_descriptor_init (tree type, gfc_typespec *ts, int rank,
+const symbol_attribute *attr, const modify_info &init)
 {
   vec *v = nullptr;
 
@@ -732,11 +754,15 @@ get_descriptor_init (tree type, gfc_typespec &ts, int 
rank,
   CONSTRUCTOR_APPEND_ELT (v, data_field, data_value);
 }
 
-  tree dtype_field = gfc_advance_chain (fields, DTYPE_FIELD);
-  tree dtype_value = build_dtype (ts, rank, attr, init);
-  CONSTRUCTOR_APPEND_ELT (v, dtype_field, dtype_value);
+  if (init.is_initialization ())
+{
+  tree dtype_field = gfc_advance_chain (fields, DTYPE_FIELD);
+  tree dtype_value = build_dtype (*ts, rank, *attr,
+ static_cast (init));
+  CONSTRUCTOR_APPEND_ELT (v, dtype_field, dtype_value);
+}
 
-  if (flag_coarray == GFC_FCOARRAY_LIB && attr.codimension)
+  if (flag_coarray == GFC_FCOARRAY_LIB && attr->codimension)
 {
   /* Declare the variable static so its array descriptor stays present

[gcc] Deleted branch 'mikael/heads/refactor_descriptor_v01' in namespace 'refs/users'

2025-01-15 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/refactor_descriptor_v01' in namespace 'refs/users' was 
deleted.
It previously pointed to:

 310e573c848d... Correction régression dummy_3

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  310e573... Correction régression dummy_3
  8eb0b9e... Correction régression coarray dummy_3
  594c3d4... Correction variable inutilisée
  30e7aab... Extraction fonction fcncall_realloc_result
  85a0e47... Correction régression pointer_remapping_5
  9dee118... Factorisation gfc_conv_remap_descriptor
  7981822... Correction régression sizeof_6
  f90f6f2... Introduction gfc_copy_sequence_descriptor
  5035a9a... Correction assertion même type
  750006e... Ajout assertion
  227befd... Correction dump
  ce517b9... Correction régression modifiable_p
  3b4a129... Utilisation de la méthode de nullification pour nullifier 
  fd12053... Appel méthode shift descriptor dans gfc_trans_pointer_assi
  8bcb2d5... Suppression variables inutilisées
  7e3c4fc... Déplacement shift descriptor vers gfc_conv_array_parameter
  4dda0ed... Utilisation gfc_clear_descriptor dans gfc_conv_derived_to_c
  677ce63... Sauvegarde modifs
  7949e90... Silence uninitialized warning.
  5a961da... Creation méthode initialisation descripteur


[gcc] Created branch 'mikael/heads/refactor_descriptor_v01' in namespace 'refs/users'

2025-01-15 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/refactor_descriptor_v01' was created in namespace 
'refs/users' pointing to:

 723db6802021... Factorisation copie gfc_conv_expr_descriptor


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Creation méthode initialisation descripteur

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:06daad8137fcdad738ff6e294a3ca83b21c0db3b

commit 06daad8137fcdad738ff6e294a3ca83b21c0db3b
Author: Mikael Morin 
Date:   Thu Dec 5 20:30:08 2024 +0100

Creation méthode initialisation descripteur

Utilisation méthode initialisation descripteur gfc_trans_deferred_array

Correction variable inutilisée

Correction segmentation fault

Correction regression allocatable attribute

Ajout conversion elem_len

conversion type longueur chaine

Initialisation descripteur champ par champ

Diff:
---
 gcc/fortran/expr.cc|  25 ++--
 gcc/fortran/gfortran.h |   1 +
 gcc/fortran/primary.cc |  84 -
 gcc/fortran/trans-array.cc | 286 -
 4 files changed, 332 insertions(+), 64 deletions(-)

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 7f3f6c52fb54..e4829448f710 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -5411,27 +5411,38 @@ gfc_get_full_arrayspec_from_expr (gfc_expr *expr)
   gfc_ref *ref;
 
   if (expr->rank == 0)
-return NULL;
+return nullptr;
 
   /* Follow any component references.  */
   if (expr->expr_type == EXPR_VARIABLE
   || expr->expr_type == EXPR_CONSTANT)
 {
-  if (expr->symtree)
-   as = expr->symtree->n.sym->as;
+  gfc_symbol *sym = expr->symtree ? expr->symtree->n.sym : nullptr;
+  if (sym
+ && sym->ts.type == BT_CLASS)
+   as = CLASS_DATA (sym)->as;
+  else if (sym)
+   as = sym->as;
   else
-   as = NULL;
+   as = nullptr;
 
   for (ref = expr->ref; ref; ref = ref->next)
{
  switch (ref->type)
{
case REF_COMPONENT:
- as = ref->u.c.component->as;
+ {
+   gfc_component *comp = ref->u.c.component;
+   if (comp->ts.type == BT_CLASS)
+ as = CLASS_DATA (comp)->as;
+   else
+ as = comp->as;
+ }
  continue;
 
case REF_SUBSTRING:
case REF_INQUIRY:
+ as = nullptr;
  continue;
 
case REF_ARRAY:
@@ -5441,7 +5452,7 @@ gfc_get_full_arrayspec_from_expr (gfc_expr *expr)
  case AR_ELEMENT:
  case AR_SECTION:
  case AR_UNKNOWN:
-   as = NULL;
+   as = nullptr;
continue;
 
  case AR_FULL:
@@ -5453,7 +5464,7 @@ gfc_get_full_arrayspec_from_expr (gfc_expr *expr)
}
 }
   else
-as = NULL;
+as = nullptr;
 
   return as;
 }
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 7367db8853c6..b14857132ed7 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -4049,6 +4049,7 @@ const char *gfc_dt_lower_string (const char *);
 const char *gfc_dt_upper_string (const char *);
 
 /* primary.cc */
+symbol_attribute gfc_symbol_attr (gfc_symbol *);
 symbol_attribute gfc_variable_attr (gfc_expr *, gfc_typespec *);
 symbol_attribute gfc_expr_attr (gfc_expr *);
 symbol_attribute gfc_caf_attr (gfc_expr *, bool i = false, bool *r = NULL);
diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index 8a38720422ec..c934841f4795 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -2867,42 +2867,14 @@ check_substring:
 }
 
 
-/* Given an expression that is a variable, figure out what the
-   ultimate variable's type and attribute is, traversing the reference
-   structures if necessary.
-
-   This subroutine is trickier than it looks.  We start at the base
-   symbol and store the attribute.  Component references load a
-   completely new attribute.
-
-   A couple of rules come into play.  Subobjects of targets are always
-   targets themselves.  If we see a component that goes through a
-   pointer, then the expression must also be a target, since the
-   pointer is associated with something (if it isn't core will soon be
-   dumped).  If we see a full part or section of an array, the
-   expression is also an array.
-
-   We can have at most one full array reference.  */
-
 symbol_attribute
-gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts)
+gfc_symbol_attr (gfc_symbol *sym)
 {
-  int dimension, codimension, pointer, allocatable, target, optional;
+  int dimension, codimension, pointer, allocatable, target;
   symbol_attribute attr;
-  gfc_ref *ref;
-  gfc_symbol *sym;
-  gfc_component *comp;
-  bool has_inquiry_part;
-
-  if (expr->expr_type != EXPR_VARIABLE
-  && expr->expr_type != EXPR_FUNCTION
-  && !(expr->expr_type == EXPR_NULL && expr->ts.type != BT_UNKNOWN))
-gfc_internal_error ("gfc_variable_attr(): Expression isn't a variable");
 
-  sym = expr->symtree->n.sym;
   attr = sym->attr;
 
-  optional = attr.optional;
   if (sym->ts.type == BT_CLASS && sym->attr.class_ok && sym->ts.u.derived)
 {
   dimension = CLASS_DATA (sym)->attr.dimension;
@@ -2938,6 +2910,58 @@ gfc_variable_attr

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Sauvegarde modifs

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:e2cdbdc0ed65fafd6abf0ed91ada804e833b7d21

commit e2cdbdc0ed65fafd6abf0ed91ada804e833b7d21
Author: Mikael Morin 
Date:   Sat Dec 7 22:22:10 2024 +0100

Sauvegarde modifs

Annulation suppression else

Correction assertions

Initialisation vptr

Non initialisation elem_len pour les conteneurs de classe

Mise à jour class_allocatable_14

Diff:
---
 gcc/fortran/trans-array.cc  | 52 ++
 gcc/fortran/trans-array.h   |  2 +
 gcc/fortran/trans-decl.cc   | 58 +
 gcc/testsuite/gfortran.dg/class_allocate_14.f90 |  2 +-
 4 files changed, 66 insertions(+), 48 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 268de211cd66..d15576adde10 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -734,6 +734,58 @@ gfc_build_null_descriptor (tree type, gfc_typespec &ts,
 }
 
 
+tree
+gfc_build_default_class_descriptor (tree type, gfc_typespec &ts)
+{
+  vec *v = nullptr;
+
+  tree fields = TYPE_FIELDS (type);
+
+#define CLASS_DATA_FIELD 0
+#define CLASS_VPTR_FIELD 1
+
+  tree data_field = gfc_advance_chain (fields, CLASS_DATA_FIELD);
+  tree data_type = TREE_TYPE (data_field);
+
+  gcc_assert (ts.type == BT_CLASS);
+  tree data_value;
+  if (ts.u.derived->components->attr.dimension
+  || (ts.u.derived->components->attr.codimension
+ && flag_coarray != GFC_FCOARRAY_LIB))
+{
+  gcc_assert (GFC_DESCRIPTOR_TYPE_P (data_type));
+  data_value = gfc_build_null_descriptor (data_type,
+ ts,
+ 
ts.u.derived->components->as->rank,
+ ts.u.derived->components->attr);
+}
+  else
+{
+  gcc_assert (POINTER_TYPE_P (data_type));
+  data_value = fold_convert (data_type, null_pointer_node);
+}
+  CONSTRUCTOR_APPEND_ELT (v, data_field, data_value);
+
+  tree vptr_field = gfc_advance_chain (fields, CLASS_VPTR_FIELD);
+
+  tree vptr_value;
+  if (ts.u.derived->attr.unlimited_polymorphic)
+vptr_value = fold_convert (TREE_TYPE (vptr_field), null_pointer_node);
+  else
+{
+  gfc_symbol *vsym = gfc_find_derived_vtab (ts.u.derived);
+  tree vsym_decl = gfc_get_symbol_decl (vsym);
+  vptr_value = gfc_build_addr_expr (nullptr, vsym_decl);
+}
+  CONSTRUCTOR_APPEND_ELT (v, vptr_field, vptr_value);
+
+#undef CLASS_DATA_FIELD
+#undef CLASS_VPTR_FIELD
+  
+  return build_constructor (type, v);
+}
+
+
 void
 gfc_clear_descriptor (gfc_expr *var_ref, gfc_se &var)
 {
diff --git a/gcc/fortran/trans-array.h b/gcc/fortran/trans-array.h
index 1bb3294b0749..63a77d562a7b 100644
--- a/gcc/fortran/trans-array.h
+++ b/gcc/fortran/trans-array.h
@@ -140,6 +140,8 @@ void gfc_set_delta (gfc_loopinfo *);
 void gfc_conv_resolve_dependencies (gfc_loopinfo *, gfc_ss *, gfc_ss *);
 /* Build a null array descriptor constructor.  */
 tree gfc_build_null_descriptor (tree);
+tree gfc_build_default_class_descriptor (tree, gfc_typespec &);
+void gfc_clear_descriptor (stmtblock_t *block, gfc_symbol *sym, tree 
descriptor);
 
 /* Get a single array element.  */
 void gfc_conv_array_ref (gfc_se *, gfc_array_ref *, gfc_expr *, locus *);
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 4ae22a5584d0..dad15858fa6a 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -4780,16 +4780,14 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, 
gfc_wrapped_block * block)
   else if (proc_sym == proc_sym->result && IS_CLASS_ARRAY (proc_sym))
 {
   /* Nullify explicit return class arrays on entry.  */
-  tree type;
   tmp = get_proc_result (proc_sym);
-   if (tmp && GFC_CLASS_TYPE_P (TREE_TYPE (tmp)))
- {
-   gfc_start_block (&init);
-   tmp = gfc_class_data_get (tmp);
-   type = TREE_TYPE (gfc_conv_descriptor_data_get (tmp));
-   gfc_conv_descriptor_data_set (&init, tmp, build_int_cst (type, 0));
-   gfc_add_init_cleanup (block, gfc_finish_block (&init), NULL_TREE);
- }
+  if (tmp && GFC_CLASS_TYPE_P (TREE_TYPE (tmp)))
+   {
+ gfc_start_block (&init);
+ tmp = gfc_class_data_get (tmp);
+ gfc_clear_descriptor (&init, proc_sym, tmp);
+ gfc_add_init_cleanup (block, gfc_finish_block (&init), NULL_TREE);
+   }
 }
 
 
@@ -4931,48 +4929,13 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, 
gfc_wrapped_block * block)
}
}
 
-  if (sym->attr.pointer && sym->attr.dimension
- && sym->attr.save == SAVE_NONE
- && !sym->attr.use_assoc
- && !sym->attr.host_assoc
- && !sym->attr.dummy
- && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (sym->backend_decl)))
-   {
- gfc_init_block (&tmpblock);
- gfc_conv_descriptor_span_set (&tmpblock, sym->backend_decl,
-   

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Silence uninitialized warning.

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:9f001e5c480c2c3f8ea72ba811c329eeb76da07c

commit 9f001e5c480c2c3f8ea72ba811c329eeb76da07c
Author: Mikael Morin 
Date:   Fri Dec 6 22:27:47 2024 +0100

Silence uninitialized warning.

Diff:
---
 gcc/fortran/trans-intrinsic.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index cc3a2e5fc105..b6900d734afd 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -12163,7 +12163,7 @@ static gfc_ss *
 nest_loop_dimension (gfc_ss *ss, int dim)
 {
   int ss_dim, i;
-  gfc_ss *new_ss, *prev_ss = gfc_ss_terminator;
+  gfc_ss *new_ss = nullptr, *prev_ss = gfc_ss_terminator;
   gfc_loopinfo *new_loop;
 
   gcc_assert (ss != gfc_ss_terminator);


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Appel méthode shift descriptor dans gfc_trans_pointer_assignment

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:31afcbd6c713314d045af8a018c39aa910088810

commit 31afcbd6c713314d045af8a018c39aa910088810
Author: Mikael Morin 
Date:   Tue Dec 17 22:37:18 2024 +0100

Appel méthode shift descriptor dans gfc_trans_pointer_assignment

Diff:
---
 gcc/fortran/trans-array.cc | 129 +++--
 gcc/fortran/trans-array.h  |   1 +
 gcc/fortran/trans-expr.cc  |  28 +-
 3 files changed, 129 insertions(+), 29 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 2fdd15962e49..cdbff27d82ca 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1151,13 +1151,136 @@ gfc_conv_shift_descriptor_lbound (stmtblock_t* block, 
tree desc,
 }
 
 
+class lb_info
+{
+public:
+  virtual gfc_expr *lower_bound (int dim) const = 0;
+};
+
+
+class unset_lb : public lb_info
+{
+public:
+  virtual gfc_expr *lower_bound (int) const { return nullptr; }
+};
+
+
+class defined_lb : public lb_info
+{
+  int rank;
+  gfc_expr * const * lower_bounds;
+
+public:
+  defined_lb (int arg_rank, gfc_expr * const 
arg_lower_bounds[GFC_MAX_DIMENSIONS])
+: rank(arg_rank), lower_bounds(arg_lower_bounds) { }
+  virtual gfc_expr *lower_bound (int dim) const { return lower_bounds[dim]; }
+};
+
+
 static void
-conv_shift_descriptor (stmtblock_t* block, tree desc, int rank)
+conv_shift_descriptor (stmtblock_t *block, tree desc, int rank,
+  const lb_info &info)
 {
   /* Apply a shift of the lbound when supplied.  */
   for (int dim = 0; dim < rank; ++dim)
-gfc_conv_shift_descriptor_lbound (block, desc, dim,
- gfc_index_one_node);
+{
+  gfc_expr *lb_expr = info.lower_bound(dim);
+
+  tree lower_bound;
+  if (lb_expr == nullptr)
+   lower_bound = gfc_index_one_node;
+  else
+   {
+ gfc_se lb_se;
+
+ gfc_init_se (&lb_se, nullptr);
+ gfc_conv_expr (&lb_se, lb_expr);
+
+ gfc_add_block_to_block (block, &lb_se.pre);
+ tree lb_var = gfc_create_var (TREE_TYPE (lb_se.expr), "lower_bound");
+ gfc_add_modify (block, lb_var, lb_se.expr);
+ gfc_add_block_to_block (block, &lb_se.post);
+
+ lower_bound = lb_var;
+   }
+
+  gfc_conv_shift_descriptor_lbound (block, desc, dim, lower_bound);
+}
+}
+
+
+static void
+conv_shift_descriptor (stmtblock_t* block, tree desc, int rank)
+{
+  conv_shift_descriptor (block, desc, rank, unset_lb ());
+}
+
+
+static void
+conv_shift_descriptor (stmtblock_t *block, tree desc, int rank,
+  gfc_expr * const lower_bounds[GFC_MAX_DIMENSIONS])
+{
+  conv_shift_descriptor (block, desc, rank, defined_lb (rank, lower_bounds));
+}
+
+
+static void
+conv_shift_descriptor (stmtblock_t *block, tree desc,
+  const gfc_array_spec &as)
+{
+  conv_shift_descriptor (block, desc, as.rank, as.lower);
+}
+
+
+static void
+set_type (array_type &type, array_type value)
+{
+  gcc_assert (type == AS_UNKNOWN || type == value);
+  type = value;
+}
+
+
+static void
+array_ref_to_array_spec (const gfc_array_ref &ref, gfc_array_spec &spec)
+{
+  spec.rank = ref.dimen;
+  spec.corank = ref.codimen;
+
+  spec.type = AS_UNKNOWN;
+  spec.cotype = AS_ASSUMED_SIZE;
+
+  for (int dim = 0; dim < spec.rank + spec.corank; dim++)
+switch (ref.dimen_type[dim])
+  {
+  case DIMEN_ELEMENT:
+   spec.upper[dim] = ref.start[dim];
+   set_type (spec.type, AS_EXPLICIT);
+   break;
+
+  case DIMEN_RANGE:
+   spec.lower[dim] = ref.start[dim];
+   spec.upper[dim] = ref.end[dim];
+   if (spec.upper[dim] == nullptr)
+ set_type (spec.type, AS_DEFERRED);
+   else
+ set_type (spec.type, AS_EXPLICIT);
+   break;
+
+  default:
+   break;
+  }
+}
+
+
+void
+gfc_conv_shift_descriptor (stmtblock_t *block, tree desc,
+  const gfc_array_ref &ar)
+{
+  gfc_array_spec as;
+
+  array_ref_to_array_spec (ar, as);
+
+  conv_shift_descriptor (block, desc, as);
 }
 
 
diff --git a/gcc/fortran/trans-array.h b/gcc/fortran/trans-array.h
index 17e3d08fdba0..3b05a2eb197a 100644
--- a/gcc/fortran/trans-array.h
+++ b/gcc/fortran/trans-array.h
@@ -214,6 +214,7 @@ tree gfc_get_cfi_dim_sm (tree, tree);
 
 /* Shift lower bound of descriptor, updating ubound and offset.  */
 void gfc_conv_shift_descriptor_lbound (stmtblock_t*, tree, int, tree);
+void gfc_conv_shift_descriptor (stmtblock_t*, tree, const gfc_array_ref &);
 
 /* Add pre-loop scalarization code for intrinsic functions which require
special handling.  */
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index e8b229d853e3..1de4a73974d6 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -11180,32 +11180,8 @@ gfc_trans_pointer_assignment (gfc_expr * expr1, 
gfc_expr * expr2)
}
}
  else
-   {
- /* Bounds remapping.  Just shift the lower bounds.  */
-
- 

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Utilisation de la méthode de nullification pour nullifier un pointeur

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:123cd1a848e6467b53b01a86e3f8b44b70d41e0e

commit 123cd1a848e6467b53b01a86e3f8b44b70d41e0e
Author: Mikael Morin 
Date:   Wed Dec 18 19:04:41 2024 +0100

Utilisation de la méthode de nullification pour nullifier un pointeur

Diff:
---
 gcc/fortran/trans-array.cc | 93 ++
 gcc/fortran/trans-array.h  |  1 +
 gcc/fortran/trans-expr.cc  |  2 +-
 3 files changed, 71 insertions(+), 25 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index cdbff27d82ca..c9417300d597 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -545,9 +545,9 @@ gfc_conv_descriptor_ubound_set (stmtblock_t *block, tree 
desc,
 
 
 static int
-get_type_info (const gfc_typespec &ts)
+get_type_info (const bt &type)
 {
-  switch (ts.type)
+  switch (type)
 {
 case BT_INTEGER:
 case BT_LOGICAL:
@@ -558,7 +558,7 @@ get_type_info (const gfc_typespec &ts)
 case BT_CLASS:
 case BT_VOID:
 case BT_UNSIGNED:
-  return ts.type;
+  return type;
 
 case BT_PROCEDURE:
 case BT_ASSUMED:
@@ -613,11 +613,34 @@ get_size_info (gfc_typespec &ts)
 }
 
 
-class init_info
+class modify_info
 {
 public:
+  virtual bool is_initialization () const { return false; }
   virtual bool initialize_data () const { return false; }
   virtual tree get_data_value () const { return NULL_TREE; }
+};
+
+class nullification : public modify_info
+{
+  virtual bool initialize_data () const { return true; }
+  virtual tree get_data_value () const { return null_pointer_node; }
+  /*
+private:
+  gfc_typespec &ts;
+
+public:
+  null_init(gfc_typespec &arg_ts) : ts(arg_ts) { }
+  virtual bool initialize_data () const { return true; }
+  virtual tree get_data_value () const { return null_pointer_node; }
+  virtual gfc_typespec *get_type () const { return &ts; }
+  */
+};
+
+class init_info : public modify_info
+{
+public:
+  virtual bool is_initialization () const { return true; }
   virtual gfc_typespec *get_type () const { return nullptr; }
 };
 
@@ -638,13 +661,13 @@ public:
   }
 };
 
-class nullification : public init_info
+class null_init : public init_info
 {
 private:
   gfc_typespec &ts;
 
 public:
-  nullification(gfc_typespec &arg_ts) : ts(arg_ts) { }
+  null_init(gfc_typespec &arg_ts) : ts(arg_ts) { }
   virtual bool initialize_data () const { return true; }
   virtual tree get_data_value () const { return null_pointer_node; }
   virtual gfc_typespec *get_type () const { return &ts; }
@@ -700,13 +723,12 @@ build_dtype (gfc_typespec &ts, int rank, const 
symbol_attribute &,
   CONSTRUCTOR_APPEND_ELT (v, rank_field, rank_val);
 }
 
-  if (type_info->type != BT_CLASS)
-{
-  tree type_info_field = gfc_advance_chain (fields, GFC_DTYPE_TYPE);
-  tree type_info_val = build_int_cst (TREE_TYPE (type_info_field),
- get_type_info (*type_info));
-  CONSTRUCTOR_APPEND_ELT (v, type_info_field, type_info_val);
-}
+  tree type_info_field = gfc_advance_chain (fields, GFC_DTYPE_TYPE);
+  tree type_info_val = build_int_cst (TREE_TYPE (type_info_field),
+ get_type_info (type_info->type == BT_CLASS
+? BT_DERIVED
+: type_info->type));
+  CONSTRUCTOR_APPEND_ELT (v, type_info_field, type_info_val);
 
   return build_constructor (type, v);
 }
@@ -715,8 +737,8 @@ build_dtype (gfc_typespec &ts, int rank, const 
symbol_attribute &,
 /* Build a null array descriptor constructor.  */
 
 vec *
-get_descriptor_init (tree type, gfc_typespec &ts, int rank,
-const symbol_attribute &attr, const init_info &init)
+get_descriptor_init (tree type, gfc_typespec *ts, int rank,
+const symbol_attribute *attr, const modify_info &init)
 {
   vec *v = nullptr;
 
@@ -732,11 +754,15 @@ get_descriptor_init (tree type, gfc_typespec &ts, int 
rank,
   CONSTRUCTOR_APPEND_ELT (v, data_field, data_value);
 }
 
-  tree dtype_field = gfc_advance_chain (fields, DTYPE_FIELD);
-  tree dtype_value = build_dtype (ts, rank, attr, init);
-  CONSTRUCTOR_APPEND_ELT (v, dtype_field, dtype_value);
+  if (init.is_initialization ())
+{
+  tree dtype_field = gfc_advance_chain (fields, DTYPE_FIELD);
+  tree dtype_value = build_dtype (*ts, rank, *attr,
+ static_cast (init));
+  CONSTRUCTOR_APPEND_ELT (v, dtype_field, dtype_value);
+}
 
-  if (flag_coarray == GFC_FCOARRAY_LIB && attr.codimension)
+  if (flag_coarray == GFC_FCOARRAY_LIB && attr->codimension)
 {
   /* Declare the variable static so its array descriptor stays present
 after leaving the scope.  It may still be accessed through another
@@ -759,7 +785,7 @@ get_default_array_descriptor_init (tree type, gfc_typespec 
&ts, int rank,
   gcc_assert (GFC_DESCRIPTOR_TYPE_P (type));
   gcc_assert (DATA_FIELD == 0);

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Utilisation gfc_clear_descriptor dans gfc_conv_derived_to_class

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:67aad3645134201ce997b07b98ab9720ea609513

commit 67aad3645134201ce997b07b98ab9720ea609513
Author: Mikael Morin 
Date:   Wed Dec 11 16:03:10 2024 +0100

Utilisation gfc_clear_descriptor dans gfc_conv_derived_to_class

essai suppression

Suppression fonction inutilisée

Sauvegarde compilation OK

Correction régression

Sauvegarde correction null_actual_6

Commentage fonction inutilisée

Correction bornes descripteur null

Diff:
---
 gcc/fortran/trans-array.cc | 339 +++--
 gcc/fortran/trans-array.h  |   4 +-
 gcc/fortran/trans-expr.cc  |  87 ++--
 3 files changed, 373 insertions(+), 57 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index d15576adde10..0370d10d9ebd 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -592,10 +592,10 @@ get_size_info (gfc_typespec &ts)
if (POINTER_TYPE_P (type))
  type = TREE_TYPE (type);
gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
-   tree elt_type = TREE_TYPE (type);
+   tree char_type = TREE_TYPE (type);
tree len = ts.u.cl->backend_decl;
return fold_build2_loc (input_location, MULT_EXPR, size_type_node,
-   size_in_bytes (elt_type),
+   size_in_bytes (char_type),
fold_convert (size_type_node, len));
   }
 
@@ -613,8 +613,61 @@ get_size_info (gfc_typespec &ts)
 }
 
 
+class init_info
+{
+public:
+  virtual bool initialize_data () const { return false; }
+  virtual tree get_data_value () const { return NULL_TREE; }
+  virtual gfc_typespec *get_type () const { return nullptr; }
+};
+
+
+class default_init : public init_info
+{
+private:
+  const symbol_attribute &attr; 
+
+public:
+  default_init (const symbol_attribute &arg_attr) : attr(arg_attr) { }
+  virtual bool initialize_data () const { return !attr.pointer; }
+  virtual tree get_data_value () const {
+if (!initialize_data ())
+  return NULL_TREE;
+
+return null_pointer_node;
+  }
+};
+
+class nullification : public init_info
+{
+private:
+  gfc_typespec &ts;
+
+public:
+  nullification(gfc_typespec &arg_ts) : ts(arg_ts) { }
+  virtual bool initialize_data () const { return true; }
+  virtual tree get_data_value () const { return null_pointer_node; }
+  virtual gfc_typespec *get_type () const { return &ts; }
+};
+
+class scalar_value : public init_info
+{
+private:
+  gfc_typespec &ts;
+  tree value;
+
+public:
+  scalar_value(gfc_typespec &arg_ts, tree arg_value)
+: ts(arg_ts), value(arg_value) { }
+  virtual bool initialize_data () const { return true; }
+  virtual tree get_data_value () const { return value; }
+  virtual gfc_typespec *get_type () const { return &ts; }
+};
+
+
 static tree
-build_dtype (gfc_typespec &ts, int rank, const symbol_attribute &)
+build_dtype (gfc_typespec &ts, int rank, const symbol_attribute &,
+const init_info &init)
 {
   vec *v = nullptr;
 
@@ -622,11 +675,17 @@ build_dtype (gfc_typespec &ts, int rank, const 
symbol_attribute &)
 
   tree fields = TYPE_FIELDS (type);
 
-  if (ts.type != BT_CLASS)
+  gfc_typespec *type_info = init.get_type ();
+  if (type_info == nullptr)
+type_info = &ts;
+
+  if (!(type_info->type == BT_CLASS
+   || (type_info->type == BT_CHARACTER
+   && type_info->deferred)))
 {
   tree elem_len_field = gfc_advance_chain (fields, GFC_DTYPE_ELEM_LEN);
   tree elem_len_val = fold_convert (TREE_TYPE (elem_len_field),
-   get_size_info (ts));
+   get_size_info (*type_info));
   CONSTRUCTOR_APPEND_ELT (v, elem_len_field, elem_len_val);
 }
 
@@ -641,11 +700,11 @@ build_dtype (gfc_typespec &ts, int rank, const 
symbol_attribute &)
   CONSTRUCTOR_APPEND_ELT (v, rank_field, rank_val);
 }
 
-  if (ts.type != BT_CLASS)
+  if (type_info->type != BT_CLASS)
 {
   tree type_info_field = gfc_advance_chain (fields, GFC_DTYPE_TYPE);
   tree type_info_val = build_int_cst (TREE_TYPE (type_info_field),
- get_type_info (ts));
+ get_type_info (*type_info));
   CONSTRUCTOR_APPEND_ELT (v, type_info_field, type_info_val);
 }
 
@@ -656,8 +715,8 @@ build_dtype (gfc_typespec &ts, int rank, const 
symbol_attribute &)
 /* Build a null array descriptor constructor.  */
 
 vec *
-get_default_descriptor_init (tree type, gfc_typespec &ts, int rank,
-const symbol_attribute &attr)
+get_descriptor_init (tree type, gfc_typespec &ts, int rank,
+const symbol_attribute &attr, const init_info &init)
 {
   vec *v = nullptr;
 
@@ -666,15 +725,15 @@ get_default_descriptor_init (tree type, gfc_typespec &ts, 
int rank,
   tree fields = TYPE_FIELDS (type);
 
   /* Don't init pointers by default.  */
-  if 

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Correction régression modifiable_p

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:5139aa2b3be938ec6cc2c3efdedd8906b40c1eec

commit 5139aa2b3be938ec6cc2c3efdedd8906b40c1eec
Author: Mikael Morin 
Date:   Wed Dec 18 21:38:06 2024 +0100

Correction régression modifiable_p

Diff:
---
 gcc/fortran/trans-array.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index c9417300d597..4c237b561aa6 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -934,6 +934,9 @@ modifiable_p (tree data_ref)
 {
   switch (TREE_CODE (data_ref))
 {
+case INDIRECT_REF:
+  return true;
+
 case CONST_DECL:
   return false;


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Déplacement shift descriptor vers gfc_conv_array_parameter

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:3e496c2acd4e55078082f593b2877d69534ac5b4

commit 3e496c2acd4e55078082f593b2877d69534ac5b4
Author: Mikael Morin 
Date:   Tue Dec 17 17:27:24 2024 +0100

Déplacement shift descriptor vers gfc_conv_array_parameter

Diff:
---
 gcc/fortran/trans-array.cc | 49 ++
 gcc/fortran/trans-array.h  |  2 +-
 gcc/fortran/trans-expr.cc  | 18 +
 3 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 0370d10d9ebd..2fdd15962e49 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1151,6 +1151,43 @@ gfc_conv_shift_descriptor_lbound (stmtblock_t* block, 
tree desc,
 }
 
 
+static void
+conv_shift_descriptor (stmtblock_t* block, tree desc, int rank)
+{
+  /* Apply a shift of the lbound when supplied.  */
+  for (int dim = 0; dim < rank; ++dim)
+gfc_conv_shift_descriptor_lbound (block, desc, dim,
+ gfc_index_one_node);
+}
+
+
+static bool
+keep_descriptor_lower_bound (gfc_expr *e)
+{
+  gfc_ref *ref;
+
+  /* Detect any array references with vector subscripts.  */
+  for (ref = e->ref; ref; ref = ref->next)
+if (ref->type == REF_ARRAY && ref->u.ar.type != AR_ELEMENT
+   && ref->u.ar.type != AR_FULL)
+  {
+   int dim;
+   for (dim = 0; dim < ref->u.ar.dimen; dim++)
+ if (ref->u.ar.dimen_type[dim] == DIMEN_VECTOR)
+   break;
+   if (dim < ref->u.ar.dimen)
+ break;
+  }
+
+  /* Array references with vector subscripts and non-variable
+ expressions need be converted to a one-based descriptor.  */
+  if (ref || e->expr_type != EXPR_VARIABLE)
+return false;
+
+  return true;
+}
+
+
 /* Obtain offsets for trans-types.cc(gfc_get_array_descr_info).  */
 
 void
@@ -9454,7 +9491,7 @@ is_pointer (gfc_expr *e)
 void
 gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr, bool g77,
  const gfc_symbol *fsym, const char *proc_name,
- tree *size, tree *lbshift, tree *packed)
+ tree *size, bool maybe_shift, tree *packed)
 {
   tree ptr;
   tree desc;
@@ -9690,13 +9727,9 @@ gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr, 
bool g77,
  stmtblock_t block;
 
  gfc_init_block (&block);
- if (lbshift && *lbshift)
-   {
- /* Apply a shift of the lbound when supplied.  */
- for (int dim = 0; dim < expr->rank; ++dim)
-   gfc_conv_shift_descriptor_lbound (&block, se->expr, dim,
- *lbshift);
-   }
+ if (maybe_shift && !keep_descriptor_lower_bound (expr))
+   conv_shift_descriptor (&block, se->expr, expr->rank);
+
  tmp = gfc_class_data_get (ctree);
  if (expr->rank > 1 && CLASS_DATA (fsym)->as->rank != expr->rank
  && CLASS_DATA (fsym)->as->type == AS_EXPLICIT && !no_pack)
diff --git a/gcc/fortran/trans-array.h b/gcc/fortran/trans-array.h
index 78646275b4ec..17e3d08fdba0 100644
--- a/gcc/fortran/trans-array.h
+++ b/gcc/fortran/trans-array.h
@@ -158,7 +158,7 @@ tree gfc_get_array_span (tree, gfc_expr *);
 void gfc_conv_expr_descriptor (gfc_se *, gfc_expr *);
 /* Convert an array for passing as an actual function parameter.  */
 void gfc_conv_array_parameter (gfc_se *, gfc_expr *, bool, const gfc_symbol *,
-  const char *, tree *, tree * = nullptr,
+  const char *, tree *, bool = false,
   tree * = nullptr);
 
 /* These work with both descriptors and descriptorless arrays.  */
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 6978f83cdc8c..00dd8815800e 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -1005,25 +1005,9 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_symbol *fsym,
  && (ref || e->rank != fsym->ts.u.derived->components->as->rank))
fsym->attr.contiguous = 1;
 
- /* Detect any array references with vector subscripts.  */
- for (ref = e->ref; ref; ref = ref->next)
-   if (ref->type == REF_ARRAY && ref->u.ar.type != AR_ELEMENT
-   && ref->u.ar.type != AR_FULL)
- {
-   for (dim = 0; dim < ref->u.ar.dimen; dim++)
- if (ref->u.ar.dimen_type[dim] == DIMEN_VECTOR)
-   break;
-   if (dim < ref->u.ar.dimen)
- break;
- }
- /* Array references with vector subscripts and non-variable
-expressions need be converted to a one-based descriptor.  */
- if (ref || e->expr_type != EXPR_VARIABLE)
-   lbshift = gfc_index_one_node;
-
  parmse->expr = var;
  gfc_conv_array_parameter (parmse, e, false, fsym, proc_name, nullptr,
-   &lbshift, &packed);
+  

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Suppression variables inutilisées

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:389c655274feaca1196b27c17bd53ddf41fe04b6

commit 389c655274feaca1196b27c17bd53ddf41fe04b6
Author: Mikael Morin 
Date:   Tue Dec 17 18:55:23 2024 +0100

Suppression variables inutilisées

Diff:
---
 gcc/fortran/trans-expr.cc | 2 --
 1 file changed, 2 deletions(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 00dd8815800e..e8b229d853e3 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -991,8 +991,6 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_symbol *fsym,
  stmtblock_t block;
  gfc_init_block (&block);
  gfc_ref *ref;
- int dim;
- tree lbshift = NULL_TREE;
 
  /* Array refs with sections indicate, that a for a formal argument
 expecting contiguous repacking needs to be done.  */


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Correction dump

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:dd00747bc994c3cb7b2e9bee0c0fe10848173946

commit dd00747bc994c3cb7b2e9bee0c0fe10848173946
Author: Mikael Morin 
Date:   Wed Dec 18 21:55:13 2024 +0100

Correction dump

Diff:
---
 gcc/testsuite/gfortran.dg/class_allocate_14.f90 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gfortran.dg/class_allocate_14.f90 
b/gcc/testsuite/gfortran.dg/class_allocate_14.f90
index 01f02ab6e47a..d938d2536980 100644
--- a/gcc/testsuite/gfortran.dg/class_allocate_14.f90
+++ b/gcc/testsuite/gfortran.dg/class_allocate_14.f90
@@ -25,6 +25,6 @@ call sub()
 call sub2()
 end
 
-! { dg-final { scan-tree-dump-times "static struct __class_m_T_1_0a b = 
{._data={.data=0B, .dtype={.version=0, .rank=1}}, ._vptr=&__vtab_m_T};" 1 
"original" } }
+! { dg-final { scan-tree-dump-times "static struct __class_m_T_1_0a b = 
{._data={.data=0B, .dtype={.version=0, .rank=1, .type=5}}, 
._vptr=&__vtab_m_T};" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "static struct __class_m_T_a y = 
{._data=0B, ._vptr=&__vtab_m_T};" 1 "original" } }


[gcc r15-6915] libstdc++: Fix comments in test that reference wrong subclause of C++11

2025-01-15 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:9cc31b4e07aab75fcbc81b3a9bcaaa21d2c3bdb2

commit r15-6915-g9cc31b4e07aab75fcbc81b3a9bcaaa21d2c3bdb2
Author: Jonathan Wakely 
Date:   Wed Dec 18 17:48:59 2024 +

libstdc++: Fix comments in test that reference wrong subclause of C++11

libstdc++-v3/ChangeLog:

* testsuite/28_regex/traits/char/transform_primary.cc: Fix
subclause numbering in references to the standard.

Diff:
---
 libstdc++-v3/testsuite/28_regex/traits/char/transform_primary.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/testsuite/28_regex/traits/char/transform_primary.cc 
b/libstdc++-v3/testsuite/28_regex/traits/char/transform_primary.cc
index 7f7408c46e5f..c6a09faae535 100644
--- a/libstdc++-v3/testsuite/28_regex/traits/char/transform_primary.cc
+++ b/libstdc++-v3/testsuite/28_regex/traits/char/transform_primary.cc
@@ -21,9 +21,9 @@
 // with this library; see the file COPYING3.  If not see
 // .
 
-// 28.3 Requirements [re.req]
-// 28.2 (4) Table 127 - Regular expression traits class requirements
-// 28.7 Class template regex_traits [re.traits]
+// C++11 28.3 Requirements [re.req]
+// C++11 28.3 (4) Table 137 - Regular expression traits class requirements
+// C++11 28.7 Class template regex_traits [re.traits]
 
 #include 
 #include 


[gcc r15-6919] bpf: calls do not promote attr access_index on lhs

2025-01-15 Thread Cupertino Miranda via Gcc-cvs
https://gcc.gnu.org/g:42786ccf1cb4ebe24945b75898d51675d532af6b

commit r15-6919-g42786ccf1cb4ebe24945b75898d51675d532af6b
Author: Cupertino Miranda 
Date:   Wed Jan 15 14:28:59 2025 +

bpf: calls do not promote attr access_index on lhs

When traversing gimple to introduce CO-RE relocation entries to
expressions that are accesses to attributed perserve_access_index types,
the access is likely to be split in multiple gimple statments.
In order to keep doing the proper CO-RE convertion we will need to mark
the LHS tree nodes of gimple expressions as explicit CO-RE accesses,
such that the gimple traverser will further convert the sub-expressions.

This patch makes sure that this LHS marking will not happen in case the
gimple statement is a function call, which case it is no longer
expecting to keep generating CO-RE accesses with the remaining of the
expression.

gcc/ChangeLog:

* config/bpf/core-builtins.cc
(make_gimple_core_safe_access_index): Fix in condition.

gcc/testsuite/ChangeLog:

* gcc.target/bpf/core-attr-calls.c: New test.

Diff:
---
 gcc/config/bpf/core-builtins.cc|  1 +
 gcc/testsuite/gcc.target/bpf/core-attr-calls.c | 49 ++
 2 files changed, 50 insertions(+)

diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc
index 415a222fb63f..d4aca38d9381 100644
--- a/gcc/config/bpf/core-builtins.cc
+++ b/gcc/config/bpf/core-builtins.cc
@@ -1822,6 +1822,7 @@ make_gimple_core_safe_access_index (tree *tp,
 
   tree lhs;
   if (!wi->is_lhs
+ && gimple_code (wi->stmt) != GIMPLE_CALL
  && (lhs = gimple_get_lhs (wi->stmt)) != NULL_TREE)
core_mark_as_access_index (lhs);
 }
diff --git a/gcc/testsuite/gcc.target/bpf/core-attr-calls.c 
b/gcc/testsuite/gcc.target/bpf/core-attr-calls.c
new file mode 100644
index ..87290c5c2116
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/core-attr-calls.c
@@ -0,0 +1,49 @@
+/* Test for BPF CO-RE __attribute__((preserve_access_index)) with accesses on
+   LHS and both LHS and RHS of assignment with calls involved.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -dA -gbtf -mco-re -masm=normal" } */
+
+struct U {
+  int c;
+  struct V {
+int d;
+int e[4];
+int f;
+int *g;
+  } v;
+};
+
+struct T {
+  int a;
+  int b;
+  struct U u;
+  struct U *ptr_u;
+  struct U *array_u;
+} __attribute__((preserve_access_index));
+
+extern struct U *get_other_u(struct U *);
+extern struct V *get_other_v(struct V *);
+
+void
+func (struct T *t, int i)
+{
+  /* Since we are using the builtin all accesses are converted to CO-RE.  */
+  /* 0:30:0   */
+  __builtin_preserve_access_index(({ get_other_u(t->ptr_u)->c = 42; }));
+
+  /* This should not pass-through CO-RE accesses beyond the call since struct U
+ is not explicitly marked with preserve_access_index. */
+  /* 0:3  */
+  get_other_u(t->ptr_u)->c = 43;
+
+  /* 0:2:1  */
+  get_other_v(&t->u.v)->d = 44;
+}
+
+/* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:3\"\\)" 2 } } */
+/* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:0\"\\)" 1 } } */
+/* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:2:1\"\\)" 1 } } */
+/* { dg-final { scan-assembler-times "bpfcr_type \\(struct T\\)" 3 } } */
+/* { dg-final { scan-assembler-times "bpfcr_type \\(struct U\\)" 1 } } */
+


[gcc r15-6918] bpf: make sure CO-RE relocs are typed with struct BTF_KIND_STRUCT

2025-01-15 Thread Cupertino Miranda via Gcc-cvs
https://gcc.gnu.org/g:d30def000abbc8d254a128751ac87a079cd10202

commit r15-6918-gd30def000abbc8d254a128751ac87a079cd10202
Author: Cupertino Miranda 
Date:   Wed Jan 15 14:25:44 2025 +

bpf: make sure CO-RE relocs are typed with struct BTF_KIND_STRUCT

Based on observation within bpf-next selftests and comparisson of GCC
and clang compiled code, the BPF loader expects all CO-RE relocations to
point to BTF non const and non volatile type nodes.

gcc/ChangeLog:

* btfout.cc (get_btf_kind): Remove static from function definition.
* config/bpf/btfext-out.cc (bpf_code_reloc_add): Check if CO-RE type
is not a const or volatile.
* ctfc.h (btf_dtd_kind): Add prototype for function.

gcc/testsuite/ChangeLog:

* gcc.target/bpf/core-attr-const.c: New test.

Diff:
---
 gcc/btfout.cc  |  2 +-
 gcc/config/bpf/btfext-out.cc   |  7 +
 gcc/ctfc.h |  2 ++
 gcc/testsuite/gcc.target/bpf/core-attr-const.c | 40 ++
 4 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/gcc/btfout.cc b/gcc/btfout.cc
index 16d5b7f97cc4..ff7ea42a9614 100644
--- a/gcc/btfout.cc
+++ b/gcc/btfout.cc
@@ -148,7 +148,7 @@ get_btf_kind (uint32_t ctf_kind)
 
 /* Convenience wrapper around get_btf_kind for the common case.  */
 
-static uint32_t
+uint32_t
 btf_dtd_kind (ctf_dtdef_ref dtd)
 {
   if (!dtd)
diff --git a/gcc/config/bpf/btfext-out.cc b/gcc/config/bpf/btfext-out.cc
index ad5ce9655a7c..7cab59bb5400 100644
--- a/gcc/config/bpf/btfext-out.cc
+++ b/gcc/config/bpf/btfext-out.cc
@@ -298,6 +298,13 @@ bpf_core_reloc_add (const tree type, const char * 
section_name,
   ctf_container_ref ctfc = ctf_get_tu_ctfc ();
   ctf_dtdef_ref dtd = ctf_lookup_tree_type (ctfc, type);
 
+  /* Make sure CO-RE type is never the const or volatile version.  */
+  if ((btf_dtd_kind (dtd) == BTF_KIND_CONST
+   || btf_dtd_kind (dtd) == BTF_KIND_VOLATILE)
+  && kind >= BPF_RELO_FIELD_BYTE_OFFSET
+  && kind <= BPF_RELO_FIELD_RSHIFT_U64)
+dtd = dtd->ref_type;
+
   /* Buffer the access string in the auxiliary strtab.  */
   bpfcr->bpfcr_astr_off = 0;
   gcc_assert (accessor != NULL);
diff --git a/gcc/ctfc.h b/gcc/ctfc.h
index 6a9baa56194c..32c73be6a412 100644
--- a/gcc/ctfc.h
+++ b/gcc/ctfc.h
@@ -465,4 +465,6 @@ extern void btf_mark_type_used (tree);
 extern int ctfc_get_dtd_srcloc (ctf_dtdef_ref, ctf_srcloc_ref);
 extern int ctfc_get_dvd_srcloc (ctf_dvdef_ref, ctf_srcloc_ref);
 
+extern uint32_t btf_dtd_kind (ctf_dtdef_ref dtd);
+
 #endif /* GCC_CTFC_H */
diff --git a/gcc/testsuite/gcc.target/bpf/core-attr-const.c 
b/gcc/testsuite/gcc.target/bpf/core-attr-const.c
new file mode 100644
index ..da6113a3faf1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/core-attr-const.c
@@ -0,0 +1,40 @@
+/* Test to make sure CO-RE access relocs point to non const versions of the
+   type.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O0 -dA -gbtf -mco-re -masm=normal" } */
+
+struct S {
+  int a;
+  int b;
+  int c;
+} __attribute__((preserve_access_index));
+
+void
+func (struct S * s)
+{
+  int *x;
+  int *y;
+  int *z;
+  struct S tmp;
+  const struct S *cs = s;
+  volatile struct S *vs = s;
+
+  /* 0:2 */
+  x = &(s->c);
+
+  /* 0:1 */
+  y = (int *) &(cs->b);
+
+  /* 0:1 */
+  z = (int *) &(vs->b);
+
+  *x = 4;
+  *y = 4;
+  *z = 4;
+}
+
+/* Both const and non const struct type should have the same bpfcr_type. */
+/* { dg-final { scan-assembler-times "0x1\t# bpfcr_type \\(struct S\\)" 1 } } 
*/
+/* { dg-final { scan-assembler-times "0x1\t# bpfcr_type \\(const struct S\\)" 
1 } } */
+/* { dg-final { scan-assembler-times "0x1\t# bpfcr_type \\(volatile struct 
S\\)" 1 } } */


[gcc r15-6920] bpf: set index entry for a VAR_DECL in CO-RE relocs

2025-01-15 Thread Cupertino Miranda via Gcc-cvs
https://gcc.gnu.org/g:01c37f9a4f1d272183ea90bab4f5d527089fc3dc

commit r15-6920-g01c37f9a4f1d272183ea90bab4f5d527089fc3dc
Author: Cupertino Miranda 
Date:   Wed Jan 15 14:38:32 2025 +

bpf: set index entry for a VAR_DECL in CO-RE relocs

CO-RE accesses with non pointer struct variables will also generate a
"0" string access within the CO-RE relocation.
The first index within the access string, has sort of a different
meaning then the remaining of the indexes.
For i0:i1:...:in being an access index for "struct A a" declaration, its
semantics are represented by:
  (&a + (sizeof(struct A) * i0) + offsetof(i1:...:in)

gcc/ChangeLog:
* config/bpf/core-builtins.cc (compute_field_expr): Change
VAR_DECL outcome in switch case.

gcc/testsuite/ChangeLog:
* gcc.target/bpf/core-builtin-1.c: Correct test.
* gcc.target/bpf/core-builtin-2.c: Correct test.
* gcc.target/bpf/core-builtin-exprlist-1.c: Correct test.

Diff:
---
 gcc/config/bpf/core-builtins.cc|  5 -
 gcc/testsuite/gcc.target/bpf/core-builtin-1.c  | 16 
 gcc/testsuite/gcc.target/bpf/core-builtin-2.c  |  3 ++-
 gcc/testsuite/gcc.target/bpf/core-builtin-exprlist-1.c | 16 
 4 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc
index d4aca38d9381..152da94a9761 100644
--- a/gcc/config/bpf/core-builtins.cc
+++ b/gcc/config/bpf/core-builtins.cc
@@ -698,10 +698,13 @@ compute_field_expr (tree node, unsigned int *accessors,
  access_node, false, callback);
   return n;
 
+case VAR_DECL:
+  accessors[0] = 0;
+  return 1;
+
 case ADDR_EXPR:
 case CALL_EXPR:
 case SSA_NAME:
-case VAR_DECL:
 case PARM_DECL:
   return 0;
 default:
diff --git a/gcc/testsuite/gcc.target/bpf/core-builtin-1.c 
b/gcc/testsuite/gcc.target/bpf/core-builtin-1.c
index b4f9998afb8f..0706005f0e5e 100644
--- a/gcc/testsuite/gcc.target/bpf/core-builtin-1.c
+++ b/gcc/testsuite/gcc.target/bpf/core-builtin-1.c
@@ -24,16 +24,16 @@ unsigned long ula[8];
 unsigned long
 func (void)
 {
-  /* 1 */
+  /* 0:1 */
   int b = _(my_s.b);
 
-  /* 2 */
+  /* 0:2 */
   char c = _(my_s.c);
 
-  /* 2:3 */
+  /* 0:2:3 */
   unsigned char uc = _(my_u.uc[3]);
 
-  /* 6 */
+  /* 0:6 */
   unsigned long ul = _(ula[6]);
 
   return b + c + uc + ul;
@@ -55,10 +55,10 @@ u_ptr (union U *pu)
   return x;
 }
 
-/* { dg-final { scan-assembler-times "ascii \"1.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
-/* { dg-final { scan-assembler-times "ascii \"2.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
-/* { dg-final { scan-assembler-times "ascii \"2:3.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
-/* { dg-final { scan-assembler-times "ascii \"6.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:1.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:2.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:2:3.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:6.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
 /* { dg-final { scan-assembler-times "ascii \"0:2.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
 /* { dg-final { scan-assembler-times "ascii \"0:2:3.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
 
diff --git a/gcc/testsuite/gcc.target/bpf/core-builtin-2.c 
b/gcc/testsuite/gcc.target/bpf/core-builtin-2.c
index b72e2566b710..04b3f6b2652a 100644
--- a/gcc/testsuite/gcc.target/bpf/core-builtin-2.c
+++ b/gcc/testsuite/gcc.target/bpf/core-builtin-2.c
@@ -16,11 +16,12 @@ struct S foo;
 
 void func (void)
 {
+  /* 0:1:3:2 */
   char *x = __builtin_preserve_access_index (&foo.u[3].c);
 
   *x = 's';
 }
 
 /* { dg-final { scan-assembler-times "\[\t \]0x402\[\t 
\]+\[^\n\]*btt_info" 1 } } */
-/* { dg-final { scan-assembler-times "ascii \"1:3:2.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:1:3:2.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
 /* { dg-final { scan-assembler-times "bpfcr_type" 1 } } */
diff --git a/gcc/testsuite/gcc.target/bpf/core-builtin-exprlist-1.c 
b/gcc/testsuite/gcc.target/bpf/core-builtin-exprlist-1.c
index 8ce4a6e70de7..c53daf81c5fc 100644
--- a/gcc/testsuite/gcc.target/bpf/core-builtin-exprlist-1.c
+++ b/gcc/testsuite/gcc.target/bpf/core-builtin-exprlist-1.c
@@ -31,16 +31,16 @@ func (void)
   int ic;
 
   __builtin_preserve_access_index (({
-/* 1 */
+/* 0:1 */
 b = my_s.b;
 
-/* 2 */
+/* 0:2 */
 ic = my_s.c;
 
-/* 2:3 */
+/* 0:2:3 */
 uc = my_u.uc[3];
 
-/* 6 */
+/* 0:6 */
 ul = ula[6];
   }));
 
@@ -65,10 +65,10 @@ u_ptr (union U *pu)
   return x;
 }
 
-/* { dg-final { scan-assembler-times "ascii \"1.0\"\[\t 
\]+\[^\n\]*btf_aux_string"

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Factorisation gfc_conv_remap_descriptor

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:f3b7c9f486120d6141a5b762137354304cab8255

commit f3b7c9f486120d6141a5b762137354304cab8255
Author: Mikael Morin 
Date:   Sat Jan 4 21:36:13 2025 +0100

Factorisation gfc_conv_remap_descriptor

Diff:
---
 gcc/fortran/trans-array.cc | 119 +++
 gcc/fortran/trans-expr.cc  | 124 +++--
 gcc/fortran/trans.h|   2 +
 3 files changed, 129 insertions(+), 116 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 5d56a12ebf71..898930634ad1 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1332,6 +1332,125 @@ gfc_conv_shift_descriptor (stmtblock_t *block, tree 
desc,
 }
 
 
+void
+gfc_conv_remap_descriptor (stmtblock_t *block, tree dest, tree src,
+  int src_rank, const gfc_array_spec &as)
+{
+  int dest_rank = gfc_descriptor_rank (dest);
+
+  /* Set dtype.  */
+  tree dtype = gfc_conv_descriptor_dtype (dest);
+  tree tmp = gfc_get_dtype (TREE_TYPE (src));
+  gfc_add_modify (block, dtype, tmp);
+
+  /* Copy data pointer.  */
+  tree data = gfc_conv_descriptor_data_get (src);
+  gfc_conv_descriptor_data_set (block, dest, data);
+
+  /* Copy the span.  */
+  tree span;
+  if (VAR_P (src)
+  && GFC_DECL_PTR_ARRAY_P (src))
+span = gfc_conv_descriptor_span_get (src);
+  else
+{
+  tmp = TREE_TYPE (src);
+  tmp = TYPE_SIZE_UNIT (gfc_get_element_type (tmp));
+  span = fold_convert (gfc_array_index_type, tmp);
+}
+  gfc_conv_descriptor_span_set (block, dest, span);
+
+  /* Copy offset but adjust it such that it would correspond
+ to a lbound of zero.  */
+  if (src_rank == -1)
+gfc_conv_descriptor_offset_set (block, dest,
+   gfc_index_zero_node);
+  else
+{
+  tree offs = gfc_conv_descriptor_offset_get (src);
+  for (int dim = 0; dim < src_rank; ++dim)
+   {
+ tree stride = gfc_conv_descriptor_stride_get (src,
+   gfc_rank_cst[dim]);
+ tree lbound = gfc_conv_descriptor_lbound_get (src,
+   gfc_rank_cst[dim]);
+ tmp = fold_build2_loc (input_location, MULT_EXPR,
+gfc_array_index_type, stride,
+lbound);
+ offs = fold_build2_loc (input_location, PLUS_EXPR,
+ gfc_array_index_type, offs, tmp);
+   }
+  gfc_conv_descriptor_offset_set (block, dest, offs);
+}
+  /* Set the bounds as declared for the LHS and calculate strides as
+ well as another offset update accordingly.  */
+  tree stride = gfc_conv_descriptor_stride_get (src,
+  gfc_rank_cst[0]);
+  for (int dim = 0; dim < dest_rank; ++dim)
+{
+  gfc_se lower_se;
+  gfc_se upper_se;
+
+  gcc_assert (as.lower[dim] && as.upper[dim]);
+
+  /* Convert declared bounds.  */
+  gfc_init_se (&lower_se, NULL);
+  gfc_init_se (&upper_se, NULL);
+  gfc_conv_expr (&lower_se, as.lower[dim]);
+  gfc_conv_expr (&upper_se, as.upper[dim]);
+
+  gfc_add_block_to_block (block, &lower_se.pre);
+  gfc_add_block_to_block (block, &upper_se.pre);
+
+  tree lbound = fold_convert (gfc_array_index_type, lower_se.expr);
+  tree ubound = fold_convert (gfc_array_index_type, upper_se.expr);
+
+  lbound = gfc_evaluate_now (lbound, block);
+  ubound = gfc_evaluate_now (ubound, block);
+
+  gfc_add_block_to_block (block, &lower_se.post);
+  gfc_add_block_to_block (block, &upper_se.post);
+
+  /* Set bounds in descriptor.  */
+  gfc_conv_descriptor_lbound_set (block, dest,
+ gfc_rank_cst[dim], lbound);
+  gfc_conv_descriptor_ubound_set (block, dest,
+ gfc_rank_cst[dim], ubound);
+
+  /* Set stride.  */
+  stride = gfc_evaluate_now (stride, block);
+  gfc_conv_descriptor_stride_set (block, dest,
+ gfc_rank_cst[dim], stride);
+
+  /* Update offset.  */
+  tree offs = gfc_conv_descriptor_offset_get (dest);
+  tmp = fold_build2_loc (input_location, MULT_EXPR,
+gfc_array_index_type, lbound, stride);
+  offs = fold_build2_loc (input_location, MINUS_EXPR,
+ gfc_array_index_type, offs, tmp);
+  offs = gfc_evaluate_now (offs, block);
+  gfc_conv_descriptor_offset_set (block, dest, offs);
+
+  /* Update stride.  */
+  tmp = gfc_conv_array_extent_dim (lbound, ubound, NULL);
+  stride = fold_build2_loc (input_location, MULT_EXPR,
+   gfc_array_index_type, stride, tmp);
+}
+}
+
+
+void
+gfc_conv_remap_descriptor (stmtblock_t *block, tree dest, tree src,
+  int src_rank, const gfc_array_ref &ar)
+{
+  gfc_array_spec as;
+
+  array_ref_to_array_spec (ar,

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Correction régression sizeof_6

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:4cdda4d7cceda9a016f5bf36afa36367a36ef608

commit 4cdda4d7cceda9a016f5bf36afa36367a36ef608
Author: Mikael Morin 
Date:   Sat Jan 4 17:43:49 2025 +0100

Correction régression sizeof_6

Diff:
---
 gcc/fortran/trans-array.cc | 15 ++-
 gcc/fortran/trans-expr.cc  |  5 +++--
 gcc/fortran/trans.h|  2 +-
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index d42575c38485..5d56a12ebf71 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -9901,8 +9901,21 @@ gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr, 
bool g77,
  if (maybe_shift && !keep_descriptor_lower_bound (expr))
conv_shift_descriptor (&block, se->expr, expr->rank);
 
+ bool assumed_rank_fsym;
+ if (fsym
+ && ((fsym->ts.type == BT_CLASS
+  && CLASS_DATA (fsym)->as
+  && CLASS_DATA (fsym)->as->type == AS_ASSUMED_RANK)
+ || (fsym->ts.type != BT_CLASS
+ && fsym->as
+ && fsym->as->type == AS_ASSUMED_RANK)))
+   assumed_rank_fsym = true;
+ else
+   assumed_rank_fsym = false;
+
  tmp = gfc_class_data_get (ctree);
- gfc_copy_sequence_descriptor (block, tmp, se->expr);
+ gfc_copy_sequence_descriptor (block, tmp, se->expr,
+   assumed_rank_fsym);
 
  /* Handle optional.  */
  if (fsym && fsym->attr.optional && sym && sym->attr.optional)
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 09a8fc9dd5dd..5dff9692f0ba 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -847,13 +847,14 @@ descriptor_rank (tree descriptor)
 
 
 void
-gfc_copy_sequence_descriptor (stmtblock_t &block, tree lhs_desc, tree rhs_desc)
+gfc_copy_sequence_descriptor (stmtblock_t &block, tree lhs_desc, tree rhs_desc,
+ bool assumed_rank_lhs)
 {
   int lhs_rank = descriptor_rank (lhs_desc);
   int rhs_rank = descriptor_rank (rhs_desc);
   tree desc;
 
-  if (lhs_rank == rhs_rank)
+  if (assumed_rank_lhs || lhs_rank == rhs_rank)
 desc = rhs_desc;
   else
 {
diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h
index 544cf3fb6497..2ad3a98cf4f6 100644
--- a/gcc/fortran/trans.h
+++ b/gcc/fortran/trans.h
@@ -465,7 +465,7 @@ void gfc_finalize_tree_expr (gfc_se *, gfc_symbol *, 
symbol_attribute, int);
 bool gfc_assignment_finalizer_call (gfc_se *, gfc_expr *, bool);
 
 void gfc_class_array_data_assign (stmtblock_t *, tree, tree, bool);
-void gfc_copy_sequence_descriptor (stmtblock_t &, tree, tree);
+void gfc_copy_sequence_descriptor (stmtblock_t &, tree, tree, bool);
 void gfc_conv_derived_to_class (gfc_se *, gfc_expr *, gfc_symbol *fsym, tree,
bool, bool, const char *, tree * = nullptr);
 void gfc_conv_class_to_class (gfc_se *, gfc_expr *, gfc_typespec, bool, bool,


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Introduction gfc_copy_sequence_descriptor

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:9c5dab02da9a84dec409d418b47005f631316e0e

commit 9c5dab02da9a84dec409d418b47005f631316e0e
Author: Mikael Morin 
Date:   Tue Dec 31 15:27:35 2024 +0100

Introduction gfc_copy_sequence_descriptor

Diff:
---
 gcc/fortran/trans-array.cc | 26 +-
 gcc/fortran/trans-expr.cc  | 43 +++
 gcc/fortran/trans.h|  1 +
 3 files changed, 45 insertions(+), 25 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 4c237b561aa6..d42575c38485 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -9902,31 +9902,7 @@ gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr, 
bool g77,
conv_shift_descriptor (&block, se->expr, expr->rank);
 
  tmp = gfc_class_data_get (ctree);
- if (expr->rank > 1 && CLASS_DATA (fsym)->as->rank != expr->rank
- && CLASS_DATA (fsym)->as->type == AS_EXPLICIT && !no_pack)
-   {
- tree arr = gfc_create_var (TREE_TYPE (tmp), "parm");
- gfc_conv_descriptor_data_set (&block, arr,
-   gfc_conv_descriptor_data_get (
- se->expr));
- gfc_conv_descriptor_lbound_set (&block, arr, gfc_index_zero_node,
- gfc_index_zero_node);
- gfc_conv_descriptor_ubound_set (
-   &block, arr, gfc_index_zero_node,
-   gfc_conv_descriptor_size (se->expr, expr->rank));
- gfc_conv_descriptor_stride_set (
-   &block, arr, gfc_index_zero_node,
-   gfc_conv_descriptor_stride_get (se->expr, gfc_index_zero_node));
- gfc_add_modify (&block, gfc_conv_descriptor_dtype (arr),
- gfc_conv_descriptor_dtype (se->expr));
- gfc_add_modify (&block, gfc_conv_descriptor_rank (arr),
- build_int_cst (signed_char_type_node, 1));
- gfc_conv_descriptor_span_set (&block, arr,
-   gfc_conv_descriptor_span_get (arr));
- gfc_conv_descriptor_offset_set (&block, arr, gfc_index_zero_node);
- se->expr = arr;
-   }
- gfc_class_array_data_assign (&block, tmp, se->expr, true);
+ gfc_copy_sequence_descriptor (block, tmp, se->expr);
 
  /* Handle optional.  */
  if (fsym && fsym->attr.optional && sym && sym->attr.optional)
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 003754cdad6f..09a8fc9dd5dd 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -846,6 +846,49 @@ descriptor_rank (tree descriptor)
 }
 
 
+void
+gfc_copy_sequence_descriptor (stmtblock_t &block, tree lhs_desc, tree rhs_desc)
+{
+  int lhs_rank = descriptor_rank (lhs_desc);
+  int rhs_rank = descriptor_rank (rhs_desc);
+  tree desc;
+
+  if (lhs_rank == rhs_rank)
+desc = rhs_desc;
+  else
+{
+  tree arr = gfc_create_var (TREE_TYPE (lhs_desc), "parm");
+  gfc_conv_descriptor_data_set (&block, arr,
+   gfc_conv_descriptor_data_get (rhs_desc));
+  gfc_conv_descriptor_lbound_set (&block, arr, gfc_index_zero_node,
+ gfc_index_zero_node);
+  tree size = gfc_conv_descriptor_size (rhs_desc, rhs_rank);
+  gfc_conv_descriptor_ubound_set (&block, arr, gfc_index_zero_node, size);
+  gfc_conv_descriptor_stride_set (
+   &block, arr, gfc_index_zero_node,
+   gfc_conv_descriptor_stride_get (rhs_desc, gfc_index_zero_node));
+  for (int i = 1; i < lhs_rank; i++)
+   {
+ gfc_conv_descriptor_lbound_set (&block, arr, gfc_rank_cst[i],
+ gfc_index_zero_node);
+ gfc_conv_descriptor_ubound_set (&block, arr, gfc_rank_cst[i],
+ gfc_index_zero_node);
+ gfc_conv_descriptor_stride_set (&block, arr, gfc_rank_cst[i], size);
+   }
+  gfc_add_modify (&block, gfc_conv_descriptor_dtype (arr),
+ gfc_conv_descriptor_dtype (rhs_desc));
+  gfc_add_modify (&block, gfc_conv_descriptor_rank (arr),
+ build_int_cst (signed_char_type_node, lhs_rank));
+  gfc_conv_descriptor_span_set (&block, arr,
+   gfc_conv_descriptor_span_get (arr));
+  gfc_conv_descriptor_offset_set (&block, arr, gfc_index_zero_node);
+  desc = arr;
+}
+
+  gfc_class_array_data_assign (&block, lhs_desc, desc, true);
+}
+
+
 void
 gfc_class_array_data_assign (stmtblock_t *block, tree lhs_desc, tree rhs_desc,
 bool)
diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h
index 449d2b3026c0..544cf3fb6497 100644
--- a/gcc/fortran/trans.h
+++ b/gcc/fortran/trans.h
@@ -465,6 +465,7 @@ void gfc_finalize_tree_expr (gfc_se *, gfc_symbol *, 
symbol_attribute, int);
 bool gfc_assignm

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Correction régression pointer_remapping_5

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:4b81583449e007a38eca422c025eccf8b256d531

commit 4b81583449e007a38eca422c025eccf8b256d531
Author: Mikael Morin 
Date:   Sat Jan 4 22:36:27 2025 +0100

Correction régression pointer_remapping_5

Diff:
---
 gcc/fortran/trans-expr.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 1bb18da10bc8..c50b1e05cdbd 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -11141,7 +11141,7 @@ gfc_trans_pointer_assignment (gfc_expr * expr1, 
gfc_expr * expr2)
  /* Do rank remapping.  We already have the RHS's descriptor
 converted in rse and now have to build the correct LHS
 descriptor for it.  */
- gfc_conv_remap_descriptor (&block, desc, rse.expr, expr1->rank,
+ gfc_conv_remap_descriptor (&block, desc, rse.expr, expr2->rank,
 remap->u.ar);
}
  else


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Factorisation copie gfc_conv_expr_descriptor

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:723db6802021f587cac576aee491a5cf94f995b0

commit 723db6802021f587cac576aee491a5cf94f995b0
Author: Mikael Morin 
Date:   Wed Jan 15 17:51:21 2025 +0100

Factorisation copie gfc_conv_expr_descriptor

Diff:
---
 gcc/fortran/trans-array.cc | 37 ++---
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 7d43a8c000d3..097a9a0d860a 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -8989,6 +8989,26 @@ is_explicit_coarray (gfc_expr *expr)
   return cas && cas->cotype == AS_EXPLICIT;
 }
 
+
+static void
+copy_descriptor (stmtblock_t *block, tree dest, tree src,
+gfc_expr *src_expr, bool subref)
+{
+  /* Copy the descriptor for pointer assignments.  */
+  gfc_add_modify (block, dest, src);
+
+  /* Add any offsets from subreferences.  */
+  gfc_get_dataptr_offset (block, dest, src, NULL_TREE, subref, src_expr);
+
+  /* and set the span field.  */
+  tree tmp;
+  if (src_expr->ts.type == BT_CHARACTER)
+tmp = gfc_conv_descriptor_span_get (src);
+  else
+tmp = gfc_get_array_span (src, src_expr);
+  gfc_conv_descriptor_span_set (block, dest, tmp);
+}
+
 /* Convert an array for passing as an actual argument.  Expressions and
vector subscripts are evaluated and stored in a temporary, which is then
passed.  For whole arrays the descriptor is passed.  For array sections
@@ -9123,21 +9143,8 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
   if (full && !transposed_dims (ss))
{
  if (se->direct_byref && !se->byref_noassign)
-   {
- /* Copy the descriptor for pointer assignments.  */
- gfc_add_modify (&se->pre, se->expr, desc);
-
- /* Add any offsets from subreferences.  */
- gfc_get_dataptr_offset (&se->pre, se->expr, desc, NULL_TREE,
- subref_array_target, expr);
-
- /* and set the span field.  */
- if (ss_info->expr->ts.type == BT_CHARACTER)
-   tmp = gfc_conv_descriptor_span_get (desc);
- else
-   tmp = gfc_get_array_span (desc, expr);
- gfc_conv_descriptor_span_set (&se->pre, se->expr, tmp);
-   }
+   copy_descriptor (&se->pre, se->expr, desc, expr,
+subref_array_target);
  else if (se->want_pointer)
{
  /* We pass full arrays directly.  This means that pointers and


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Correction régression coarray dummy_3

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:25d2fec9625389541648d78c367df2b237ea1d70

commit 25d2fec9625389541648d78c367df2b237ea1d70
Author: Mikael Morin 
Date:   Fri Jan 10 14:09:37 2025 +0100

Correction régression coarray dummy_3

Diff:
---
 gcc/fortran/trans-expr.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 57a976df58ff..14f92e7575dc 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -832,6 +832,9 @@ gfc_get_vptr_from_expr (tree expr)
 int
 gfc_descriptor_rank (tree descriptor)
 {
+  if (TREE_TYPE (descriptor) != NULL_TREE)
+return GFC_TYPE_ARRAY_RANK (TREE_TYPE (descriptor));
+
   tree dim = gfc_get_descriptor_dimension (descriptor);
   tree dim_type = TREE_TYPE (dim);
   gcc_assert (TREE_CODE (dim_type) == ARRAY_TYPE);


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Correction assertion même type

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:10d9c972cef75bf3d58cb5b32c32a5e0aaba6f52

commit 10d9c972cef75bf3d58cb5b32c32a5e0aaba6f52
Author: Mikael Morin 
Date:   Thu Dec 19 15:19:50 2024 +0100

Correction assertion même type

Diff:
---
 gcc/fortran/trans-expr.cc | 34 +++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 2aed5a02e17f..003754cdad6f 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -828,9 +828,27 @@ gfc_get_vptr_from_expr (tree expr)
   return NULL_TREE;
 }
 
+
+static int
+descriptor_rank (tree descriptor)
+{
+  tree dim = gfc_get_descriptor_dimension (descriptor);
+  tree dim_type = TREE_TYPE (dim);
+  gcc_assert (TREE_CODE (dim_type) == ARRAY_TYPE);
+  tree idx_type = TYPE_DOMAIN (dim_type);
+  gcc_assert (TREE_CODE (idx_type) == INTEGER_TYPE);
+  gcc_assert (integer_zerop (TYPE_MIN_VALUE (idx_type)));
+  tree idx_max = TYPE_MAX_VALUE (idx_type);
+  if (idx_max == NULL_TREE)
+return GFC_MAX_DIMENSIONS;
+  wide_int max = wi::to_wide (idx_max);
+  return max.to_shwi () + 1;
+}
+
+
 void
 gfc_class_array_data_assign (stmtblock_t *block, tree lhs_desc, tree rhs_desc,
-bool lhs_type)
+bool)
 {
   tree tmp, tmp2, type;
 
@@ -846,8 +864,18 @@ gfc_class_array_data_assign (stmtblock_t *block, tree 
lhs_desc, tree rhs_desc,
   tmp = gfc_get_descriptor_dimension (lhs_desc);
   tmp2 = gfc_get_descriptor_dimension (rhs_desc);
 
-  gcc_assert (TREE_TYPE (tmp) == TREE_TYPE (tmp2));
-  type = lhs_type ? TREE_TYPE (tmp) : TREE_TYPE (tmp2);
+  int rank = descriptor_rank (lhs_desc);
+  int rank2 = descriptor_rank (rhs_desc);
+  if (rank == GFC_MAX_DIMENSIONS && rank2 != GFC_MAX_DIMENSIONS)
+type = TREE_TYPE (tmp2);
+  else if (rank2 == GFC_MAX_DIMENSIONS && rank != GFC_MAX_DIMENSIONS)
+type = TREE_TYPE (tmp);
+  else
+{
+  gcc_assert (TREE_TYPE (tmp) == TREE_TYPE (tmp2));
+  type = TREE_TYPE (tmp);
+}
+
   tmp = build4_loc (input_location, ARRAY_RANGE_REF, type, tmp,
gfc_index_zero_node, NULL_TREE, NULL_TREE);
   tmp2 = build4_loc (input_location, ARRAY_RANGE_REF, type, tmp2,


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Ajout assertion

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:9d8043c2f26c9fdafd6b779cd6d2c75f949e503c

commit 9d8043c2f26c9fdafd6b779cd6d2c75f949e503c
Author: Mikael Morin 
Date:   Wed Dec 18 21:57:29 2024 +0100

Ajout assertion

Diff:
---
 gcc/fortran/trans-expr.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 6659f917ac01..2aed5a02e17f 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -846,6 +846,7 @@ gfc_class_array_data_assign (stmtblock_t *block, tree 
lhs_desc, tree rhs_desc,
   tmp = gfc_get_descriptor_dimension (lhs_desc);
   tmp2 = gfc_get_descriptor_dimension (rhs_desc);
 
+  gcc_assert (TREE_TYPE (tmp) == TREE_TYPE (tmp2));
   type = lhs_type ? TREE_TYPE (tmp) : TREE_TYPE (tmp2);
   tmp = build4_loc (input_location, ARRAY_RANGE_REF, type, tmp,
gfc_index_zero_node, NULL_TREE, NULL_TREE);


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Extraction fonction fcncall_realloc_result

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:ff34c5d59b058d43f9150afd888e865a2f393fed

commit ff34c5d59b058d43f9150afd888e865a2f393fed
Author: Mikael Morin 
Date:   Thu Jan 9 21:38:39 2025 +0100

Extraction fonction fcncall_realloc_result

Diff:
---
 gcc/fortran/trans-array.cc | 64 ++
 gcc/fortran/trans-array.h  |  1 +
 gcc/fortran/trans-expr.cc  | 35 +
 3 files changed, 66 insertions(+), 34 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 898930634ad1..7d43a8c000d3 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1451,6 +1451,70 @@ gfc_conv_remap_descriptor (stmtblock_t *block, tree 
dest, tree src,
 }
 
 
+class conditional_lb
+{
+  tree cond;
+public:
+  conditional_lb (tree arg_cond)
+: cond (arg_cond) { }
+
+  tree lower_bound (tree src, int n) const {
+tree lbound = gfc_conv_descriptor_lbound_get (src, gfc_rank_cst[n]);
+lbound = fold_build3_loc (input_location, COND_EXPR,
+ gfc_array_index_type, cond,
+ gfc_index_one_node, lbound);
+return lbound;
+  }
+};
+
+
+static void
+gfc_conv_shift_descriptor (stmtblock_t *block, tree dest, tree src,
+  int rank, const conditional_lb &lb)
+{
+  tree tmp = gfc_conv_descriptor_data_get (src);
+  gfc_conv_descriptor_data_set (block, dest, tmp);
+
+  tree offset = gfc_index_zero_node;
+  for (int n = 0 ; n < rank; n++)
+{
+  tree lbound;
+
+  lbound = lb.lower_bound (dest, n);
+  lbound = gfc_evaluate_now (lbound, block);
+
+  tmp = gfc_conv_descriptor_ubound_get (src, gfc_rank_cst[n]);
+  tmp = fold_build2_loc (input_location, PLUS_EXPR,
+gfc_array_index_type, tmp, lbound);
+  gfc_conv_descriptor_lbound_set (block, dest,
+ gfc_rank_cst[n], lbound);
+  gfc_conv_descriptor_ubound_set (block, dest,
+ gfc_rank_cst[n], tmp);
+
+  /* Set stride and accumulate the offset.  */
+  tmp = gfc_conv_descriptor_stride_get (src, gfc_rank_cst[n]);
+  gfc_conv_descriptor_stride_set (block, dest,
+ gfc_rank_cst[n], tmp);
+  tmp = fold_build2_loc (input_location, MULT_EXPR,
+gfc_array_index_type, lbound, tmp);
+  offset = fold_build2_loc (input_location, MINUS_EXPR,
+   gfc_array_index_type, offset, tmp);
+  offset = gfc_evaluate_now (offset, block);
+}
+
+  gfc_conv_descriptor_offset_set (block, dest, offset);
+}
+
+
+void
+gfc_conv_shift_descriptor (stmtblock_t *block, tree dest, tree src,
+  int rank, tree zero_cond)
+{
+  gfc_conv_shift_descriptor (block, dest, src, rank,
+conditional_lb (zero_cond));
+}
+
+
 static bool
 keep_descriptor_lower_bound (gfc_expr *e)
 {
diff --git a/gcc/fortran/trans-array.h b/gcc/fortran/trans-array.h
index 8df55c2c00a5..571322ae11ff 100644
--- a/gcc/fortran/trans-array.h
+++ b/gcc/fortran/trans-array.h
@@ -216,6 +216,7 @@ tree gfc_get_cfi_dim_sm (tree, tree);
 /* Shift lower bound of descriptor, updating ubound and offset.  */
 void gfc_conv_shift_descriptor_lbound (stmtblock_t*, tree, int, tree);
 void gfc_conv_shift_descriptor (stmtblock_t*, tree, const gfc_array_ref &);
+void gfc_conv_shift_descriptor (stmtblock_t*, tree, tree, int, tree);
 
 /* Add pre-loop scalarization code for intrinsic functions which require
special handling.  */
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index c50b1e05cdbd..b65474a0c919 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -11628,9 +11628,6 @@ fcncall_realloc_result (gfc_se *se, int rank, tree 
dtype)
   tmp = gfc_call_free (tmp);
   gfc_add_expr_to_block (&se->post, tmp);
 
-  tmp = gfc_conv_descriptor_data_get (res_desc);
-  gfc_conv_descriptor_data_set (&se->post, desc, tmp);
-
   /* Check that the shapes are the same between lhs and expression.
  The evaluation of the shape is done in 'shape_block' to avoid
  unitialized warnings from the lhs bounds. */
@@ -11674,37 +11671,7 @@ fcncall_realloc_result (gfc_se *se, int rank, tree 
dtype)
   /* Now reset the bounds returned from the function call to bounds based
  on the lhs lbounds, except where the lhs is not allocated or the shapes
  of 'variable and 'expr' are different. Set the offset accordingly.  */
-  offset = gfc_index_zero_node;
-  for (n = 0 ; n < rank; n++)
-{
-  tree lbound;
-
-  lbound = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[n]);
-  lbound = fold_build3_loc (input_location, COND_EXPR,
-   gfc_array_index_type, zero_cond,
-   gfc_index_one_node, lbound);
-  lbound = gfc_evaluate_now (lbound, &se->post);
-
-  tmp = gfc_conv_descriptor_ubound_get (res_desc, gfc_rank_cst[n]);
-   

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Correction variable inutilisée

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:9ef2c769b80a974979bb9f2024a7eb9b1a2a5ffb

commit 9ef2c769b80a974979bb9f2024a7eb9b1a2a5ffb
Author: Mikael Morin 
Date:   Thu Jan 9 22:35:38 2025 +0100

Correction variable inutilisée

Diff:
---
 gcc/fortran/trans-expr.cc | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index b65474a0c919..57a976df58ff 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -11595,7 +11595,6 @@ fcncall_realloc_result (gfc_se *se, int rank, tree 
dtype)
   tree desc;
   tree res_desc;
   tree tmp;
-  tree offset;
   tree zero_cond;
   tree not_same_shape;
   stmtblock_t shape_block;


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Correction régression dummy_3

2025-01-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:612f8e4f7a77e1128924e6fafe0e12a363fc631b

commit 612f8e4f7a77e1128924e6fafe0e12a363fc631b
Author: Mikael Morin 
Date:   Fri Jan 10 19:03:04 2025 +0100

Correction régression dummy_3

Diff:
---
 gcc/fortran/trans-expr.cc | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 14f92e7575dc..77e8a55af457 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -919,8 +919,17 @@ gfc_class_array_data_assign (stmtblock_t *block, tree 
lhs_desc, tree rhs_desc,
 type = TREE_TYPE (tmp);
   else
 {
-  gcc_assert (TREE_TYPE (tmp) == TREE_TYPE (tmp2));
-  type = TREE_TYPE (tmp);
+  int corank = GFC_TYPE_ARRAY_CORANK (TREE_TYPE (lhs_desc));
+  int corank2 = GFC_TYPE_ARRAY_CORANK (TREE_TYPE (rhs_desc));
+  if (corank > 0 && corank2 == 0)
+   type = TREE_TYPE (tmp2);
+  else if (corank2 > 0 && corank == 0)
+   type = TREE_TYPE (tmp);
+  else
+   {
+ gcc_assert (TREE_TYPE (tmp) == TREE_TYPE (tmp2));
+ type = TREE_TYPE (tmp);
+   }
 }
 
   tmp = build4_loc (input_location, ARRAY_RANGE_REF, type, tmp,


[gcc r15-6922] AArch64: Add FULLY_PIPELINED_FMA to tune baseline

2025-01-15 Thread Wilco Dijkstra via Gcc-cvs
https://gcc.gnu.org/g:2713f6bb90765de81954275a30c62432d30e1d68

commit r15-6922-g2713f6bb90765de81954275a30c62432d30e1d68
Author: Wilco Dijkstra 
Date:   Thu Nov 14 14:34:17 2024 +

AArch64: Add FULLY_PIPELINED_FMA to tune baseline

Add FULLY_PIPELINED_FMA to tune baseline - this is a generic feature that is
already enabled for some cores, but benchmarking it shows it is faster on 
all
modern cores (SPECFP improves ~0.17% on Neoverse V1 and 0.04% on Neoverse 
N1).

gcc:
* config/aarch64/aarch64-tuning-flags.def (AARCH64_EXTRA_TUNE_BASE):
Add AARCH64_EXTRA_TUNE_FULLY_PIPELINED_FMA.
* config/aarch64/tuning_models/ampere1b.h: Remove redundant
AARCH64_EXTRA_TUNE_FULLY_PIPELINED_FMA.
* config/aarch64/tuning_models/neoversev2.h: Likewise.

Diff:
---
 gcc/config/aarch64/aarch64-tuning-flags.def   | 3 ++-
 gcc/config/aarch64/tuning_models/ampere1b.h   | 3 +--
 gcc/config/aarch64/tuning_models/neoversev2.h | 3 +--
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-tuning-flags.def 
b/gcc/config/aarch64/aarch64-tuning-flags.def
index 7ebf390ef818..60967aac9037 100644
--- a/gcc/config/aarch64/aarch64-tuning-flags.def
+++ b/gcc/config/aarch64/aarch64-tuning-flags.def
@@ -49,6 +49,7 @@ AARCH64_EXTRA_TUNING_OPTION ("fully_pipelined_fma", 
FULLY_PIPELINED_FMA)
 AARCH64_EXTRA_TUNING_OPTION ("avoid_pred_rmw", AVOID_PRED_RMW)
 
 /* Baseline tuning settings suitable for all modern cores.  */
-#define AARCH64_EXTRA_TUNE_BASE (AARCH64_EXTRA_TUNE_CHEAP_SHIFT_EXTEND)
+#define AARCH64_EXTRA_TUNE_BASE (AARCH64_EXTRA_TUNE_CHEAP_SHIFT_EXTEND \
+| AARCH64_EXTRA_TUNE_FULLY_PIPELINED_FMA)
 
 #undef AARCH64_EXTRA_TUNING_OPTION
diff --git a/gcc/config/aarch64/tuning_models/ampere1b.h 
b/gcc/config/aarch64/tuning_models/ampere1b.h
index c541623993d2..2ad6003d65c1 100644
--- a/gcc/config/aarch64/tuning_models/ampere1b.h
+++ b/gcc/config/aarch64/tuning_models/ampere1b.h
@@ -103,8 +103,7 @@ static const struct tune_params ampere1b_tunings =
   0,   /* max_case_values.  */
   tune_params::AUTOPREFETCHER_STRONG,  /* autoprefetcher_model.  */
   (AARCH64_EXTRA_TUNE_BASE
-   | AARCH64_EXTRA_TUNE_AVOID_CROSS_LOOP_FMA
-   | AARCH64_EXTRA_TUNE_FULLY_PIPELINED_FMA), /* tune_flags.  */
+   | AARCH64_EXTRA_TUNE_AVOID_CROSS_LOOP_FMA), /* tune_flags.  */
   &ere1b_prefetch_tune,
   AARCH64_LDP_STP_POLICY_ALIGNED,   /* ldp_policy_model.  */
   AARCH64_LDP_STP_POLICY_ALIGNED/* stp_policy_model.  */
diff --git a/gcc/config/aarch64/tuning_models/neoversev2.h 
b/gcc/config/aarch64/tuning_models/neoversev2.h
index 4fabe4df2de7..b000fb465709 100644
--- a/gcc/config/aarch64/tuning_models/neoversev2.h
+++ b/gcc/config/aarch64/tuning_models/neoversev2.h
@@ -220,8 +220,7 @@ static const struct tune_params neoversev2_tunings =
   (AARCH64_EXTRA_TUNE_BASE
| AARCH64_EXTRA_TUNE_CSE_SVE_VL_CONSTANTS
| AARCH64_EXTRA_TUNE_MATCHED_VECTOR_THROUGHPUT
-   | AARCH64_EXTRA_TUNE_AVOID_PRED_RMW
-   | AARCH64_EXTRA_TUNE_FULLY_PIPELINED_FMA),  /* tune_flags.  */
+   | AARCH64_EXTRA_TUNE_AVOID_PRED_RMW),   /* tune_flags.  */
   &generic_armv9a_prefetch_tune,
   AARCH64_LDP_STP_POLICY_ALWAYS,   /* ldp_policy_model.  */
   AARCH64_LDP_STP_POLICY_ALWAYS   /* stp_policy_model.  */


[gcc r15-6916] c++: handle decltype in nested-name-spec printing [PR118139]

2025-01-15 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:1bc474f60fde7aba2e00d00f9fa491aff243ecba

commit r15-6916-g1bc474f60fde7aba2e00d00f9fa491aff243ecba
Author: Marek Polacek 
Date:   Thu Dec 19 17:47:03 2024 -0500

c++: handle decltype in nested-name-spec printing [PR118139]

Compiling this test, we emit:

  error: 'static void CW::operator=(int) requires 
requires(typename'decltype_type' not supported by pp_cxx_unqualified_id::type 
x) {x;}' must be a non-static member function

where the DECLTYPE_TYPE isn't printed properly.  This patch fixes that
to print:

error: 'static void CW::operator=(int) requires requires(typename 
decltype(T())::type x) {x;}' must be a non-static member function

PR c++/118139

gcc/cp/ChangeLog:

* cxx-pretty-print.cc (pp_cxx_nested_name_specifier): Handle
a computed-type-specifier.

gcc/testsuite/ChangeLog:

* g++.dg/diagnostic/decltype1.C: New test.

Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/cxx-pretty-print.cc  | 14 +++---
 gcc/testsuite/g++.dg/diagnostic/decltype1.C |  8 
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/cxx-pretty-print.cc b/gcc/cp/cxx-pretty-print.cc
index 07439993e0b0..cf301bd7cb32 100644
--- a/gcc/cp/cxx-pretty-print.cc
+++ b/gcc/cp/cxx-pretty-print.cc
@@ -234,8 +234,12 @@ pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, 
tree scope, tree t)
 }
 
 /* nested-name-specifier:
-  class-or-namespace-name :: nested-name-specifier(opt)
-  class-or-namespace-name :: template nested-name-specifier   */
+  ::
+  type-name ::
+  namespace-name ::
+  computed-type-specifier ::
+  nested-name-specifier identifier ::
+  nested-name-specifier template(opt) simple-template-id ::  */
 
 static void
 pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t)
@@ -252,7 +256,11 @@ pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree 
t)
   tree scope = get_containing_scope (t);
   pp_cxx_nested_name_specifier (pp, scope);
   pp_cxx_template_keyword_if_needed (pp, scope, t);
-  pp_cxx_unqualified_id (pp, t);
+  /* This is a computed-type-specifier.  */
+  if (TREE_CODE (t) == PACK_INDEX_TYPE || TREE_CODE (t) == DECLTYPE_TYPE)
+   pp->type_id (t);
+  else
+   pp_cxx_unqualified_id (pp, t);
   pp_cxx_colon_colon (pp);
 }
 }
diff --git a/gcc/testsuite/g++.dg/diagnostic/decltype1.C 
b/gcc/testsuite/g++.dg/diagnostic/decltype1.C
new file mode 100644
index ..8b57b165603d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/decltype1.C
@@ -0,0 +1,8 @@
+// PR c++/118139
+// { dg-do compile { target c++20 } }
+
+template
+struct CW {
+  using V = typename decltype(T())::type;
+  static void operator=(int) requires requires(V x) { x; } {} // { dg-error 
{requires requires\(typename decltype\(T\(\)\)::type x\)} }
+};


[gcc r15-6917] c++: Implement mangling of RAW_DATA_CST [PR118278]

2025-01-15 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:8d9d583484006a75bc3ed3b3badb585f3a0bb546

commit r15-6917-g8d9d583484006a75bc3ed3b3badb585f3a0bb546
Author: Jakub Jelinek 
Date:   Wed Jan 15 17:04:31 2025 +0100

c++: Implement mangling of RAW_DATA_CST [PR118278]

As the following testcases show (mangle80.C only after reversion of the
temporary reversion of C++ large array speedup commit), RAW_DATA_CST can
be seen during mangling of some templates and we ICE because
the mangler doesn't handle it.

The following patch handles it and mangles it the same as a sequence of
INTEGER_CSTs that were used previously instead.
The only slight complication is that if ce->value is the last nonzero
element, we need to skip the zeros at the end of RAW_DATA_CST.

2025-01-03  Jakub Jelinek  

PR c++/118278
* mangle.cc (write_expression): Handle RAW_DATA_CST.

* g++.dg/abi/mangle80.C: New test.
* g++.dg/cpp/embed-19.C: New test.

Diff:
---
 gcc/cp/mangle.cc| 37 ++--
 gcc/testsuite/g++.dg/abi/mangle80.C | 67 +
 gcc/testsuite/g++.dg/cpp/embed-19.C | 18 ++
 3 files changed, 120 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc
index 170dafd52c17..114e4a0d7c59 100644
--- a/gcc/cp/mangle.cc
+++ b/gcc/cp/mangle.cc
@@ -3748,8 +3748,41 @@ write_expression (tree expr)
unsigned reps = 1;
if (ce->index && TREE_CODE (ce->index) == RANGE_EXPR)
  reps = range_expr_nelts (ce->index);
-   for (unsigned j = 0; j < reps; ++j)
- write_expression (ce->value);
+   if (TREE_CODE (ce->value) == RAW_DATA_CST)
+ {
+   gcc_assert (reps == 1);
+   unsigned int len = RAW_DATA_LENGTH (ce->value);
+   /* If this is the last non-zero element, skip
+  zeros at the end.  */
+   if (i == last_nonzero)
+ while (len)
+   {
+ if (RAW_DATA_POINTER (ce->value)[len - 1])
+   break;
+ --len;
+   }
+   tree valtype = TREE_TYPE (ce->value);
+   for (unsigned int i = 0; i < len; ++i)
+ {
+   write_char ('L');
+   write_type (valtype);
+   unsigned HOST_WIDE_INT v;
+   if (!TYPE_UNSIGNED (valtype)
+   && TYPE_PRECISION (valtype) == BITS_PER_UNIT
+   && RAW_DATA_SCHAR_ELT (ce->value, i) < 0)
+ {
+   write_char ('n');
+   v = -RAW_DATA_SCHAR_ELT (ce->value, i);
+ }
+   else
+ v = RAW_DATA_UCHAR_ELT (ce->value, i);
+   write_unsigned_number (v);
+   write_char ('E');
+ }
+ }
+   else
+ for (unsigned j = 0; j < reps; ++j)
+   write_expression (ce->value);
  }
}
  else
diff --git a/gcc/testsuite/g++.dg/abi/mangle80.C 
b/gcc/testsuite/g++.dg/abi/mangle80.C
new file mode 100644
index ..e4f6934b431e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/mangle80.C
@@ -0,0 +1,67 @@
+// PR c++/118278
+// Verify that class literals are mangled the same way regardless
+// of the underlying type.
+// { dg-do compile { target c++20 } }
+// { dg-additional-options -fabi-compat-version=0 }
+
+struct I { int a[5], b[5], c[144]; };
+template  struct X { };
+
+typedef X Ti;
+void f (Ti) { }
+// { dg-final { scan-assembler 
"_Z1f1XIXtl1ItlA5_iLi1ELi2EEtlS1_EtlA144_i(?:Li101ELi102ELi103ELi104ELi105ELi106ELi255ELi254ELi253ELi252ELi251ELi0ELi1ELi2ELi3ELi4E){8}Li101ELi102E"
 } }
+
+struct C { unsigned char a[5], b[5], c[144]; };
+template  struct Y { };
+
+typedef Y Tca;
+void g (Tca) { }
+// { dg-final { scan-assembler 
"_Z1g1YIXtl1CtlA5_hLh1ELh2EEtlS1_EtlA144_h(?:Lh101ELh102ELh103ELh104ELh105ELh106ELh255ELh254ELh253ELh252ELh251ELh0ELh1ELh2ELh3ELh4E){8}Lh101ELh102E"
 } }
+
+typedef Y Tcs;
+void h (Tcs) { }
+// { dg-final { scan-assembler 
"_Z1h1YIXtl1CtlA5_hLh1ELh2EEtlS1_EtlA144_h(?:Lh101ELh102ELh103ELh104ELh105ELh106ELh255ELh254ELh253ELh252ELh251ELh0ELh1ELh2ELh3ELh4E){8}Lh101ELh102E"
 } }
+
+struct S { signed char a[5], b[5], c[144]; };
+template  struct Z { };
+
+typedef Z Tsc;
+
+void i (Tsc) { }
+// { dg-final { scan-assembler 
"_Z1i1ZIXtl1StlA5_aLa1ELa2EEtlS1_EtlA144_a(?:La101ELa102ELa103ELa104ELa105ELa106ELa95ELa94ELa93ELa92ELa91ELa0ELa1ELa2ELa3ELa

[gcc r15-6907] c++: Fix ICEs with large initializer lists or ones including #embed [PR118124]

2025-01-15 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:f263f2d525eb9a1b60c2a356eb64262819b6bab0

commit r15-6907-gf263f2d525eb9a1b60c2a356eb64262819b6bab0
Author: Jakub Jelinek 
Date:   Wed Jan 15 08:46:48 2025 +0100

c++: Fix ICEs with large initializer lists or ones including #embed 
[PR118124]

The following testcases ICE due to RAW_DATA_CST not being handled where it
should be during ck_list conversions.

The last 2 testcases started ICEing with r15-6339 committed yesterday
(speedup of large initializers), the first two already with r15-5958
(#embed optimization for C++).

For conversion to initializer_list or char/signed char
we can optimize and keep RAW_DATA_CST with adjusted type if we report
narrowing errors if needed, for others this converts each element
separately.

2025-01-15  Jakub Jelinek  

PR c++/118124
* call.cc (convert_like_internal): Handle RAW_DATA_CST in
ck_list handling.  Formatting fixes.

* g++.dg/cpp/embed-15.C: New test.
* g++.dg/cpp/embed-16.C: New test.
* g++.dg/cpp0x/initlist-opt3.C: New test.
* g++.dg/cpp0x/initlist-opt4.C: New test.

Diff:
---
 gcc/cp/call.cc | 95 --
 gcc/testsuite/g++.dg/cpp/embed-15.C| 35 +++
 gcc/testsuite/g++.dg/cpp/embed-16.C| 18 ++
 gcc/testsuite/g++.dg/cpp0x/initlist-opt3.C | 47 +++
 gcc/testsuite/g++.dg/cpp0x/initlist-opt4.C | 20 +++
 5 files changed, 209 insertions(+), 6 deletions(-)

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 602f496e1806..65d613e37b30 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -8806,8 +8806,9 @@ convert_like_internal (conversion *convs, tree expr, tree 
fn, int argnum,
 
if (tree init = maybe_init_list_as_array (elttype, expr))
  {
-   elttype = cp_build_qualified_type
- (elttype, cp_type_quals (elttype) | TYPE_QUAL_CONST);
+   elttype
+ = cp_build_qualified_type (elttype, (cp_type_quals (elttype)
+  | TYPE_QUAL_CONST));
array = build_array_of_n_type (elttype, len);
array = build_vec_init_expr (array, init, complain);
array = get_target_expr (array);
@@ -8815,13 +8816,94 @@ convert_like_internal (conversion *convs, tree expr, 
tree fn, int argnum,
  }
else if (len)
  {
-   tree val; unsigned ix;
-
+   tree val;
+   unsigned ix;
tree new_ctor = build_constructor (init_list_type_node, NULL);
 
/* Convert all the elements.  */
FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expr), ix, val)
  {
+   if (TREE_CODE (val) == RAW_DATA_CST)
+ {
+   tree elt_type;
+   conversion *next;
+   /* For conversion to initializer_list or
+  initializer_list or initializer_list
+  we can optimize and keep RAW_DATA_CST with adjusted
+  type if we report narrowing errors if needed, for
+  others this converts each element separately.  */
+   if (convs->u.list[ix]->kind == ck_std
+   && (elt_type = convs->u.list[ix]->type)
+   && (TREE_CODE (elt_type) == INTEGER_TYPE
+   || is_byte_access_type (elt_type))
+   && TYPE_PRECISION (elt_type) == CHAR_BIT
+   && (next = next_conversion (convs->u.list[ix]))
+   && next->kind == ck_identity)
+ {
+   if (!TYPE_UNSIGNED (elt_type)
+   /* For RAW_DATA_CST, TREE_TYPE (val) can be
+  either integer_type_node (when it has been
+  created by the lexer from CPP_EMBED) or
+  after digestion/conversion some integral
+  type with CHAR_BIT precision.  For int with
+  precision higher than CHAR_BIT or unsigned char
+  diagnose narrowing conversions from
+  that int/unsigned char to signed char if any
+  byte has most significant bit set.  */
+   && (TYPE_UNSIGNED (TREE_TYPE (val))
+   || (TYPE_PRECISION (TREE_TYPE (val))
+   > CHAR_BIT)))
+ for (int i = 0; i < RAW_DATA_LENGTH (val); ++i)
+   {
+ if (RAW_DATA_SCHAR_ELT (val, i) >= 0)
+   continue;
+ else if (complain & tf_error)
+   {
+ location_t loc
+  

[gcc r15-6910] ipa: Initialize/release global obstack in process_new_functions [PR116068]

2025-01-15 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:dd389c2549a4891e044c96b9298efa2a363c744a

commit r15-6910-gdd389c2549a4891e044c96b9298efa2a363c744a
Author: Jakub Jelinek 
Date:   Wed Jan 15 09:43:32 2025 +0100

ipa: Initialize/release global obstack in process_new_functions [PR116068]

Other spots in cgraphunit.cc already call bitmap_obstack_initialize (NULL);
before running a pass list and bitmap_obstack_release (NULL); after that,
while process_new_functions wasn't doing that and with the new r15-130
bitmap_alloc checking that results in ICE.

2025-01-15  Jakub Jelinek  

PR ipa/116068
* cgraphunit.cc (symbol_table::process_new_functions): Call
bitmap_obstack_initialize (NULL); and bitmap_obstack_release (NULL)
around processing the functions.

* gcc.dg/graphite/pr116068.c: New test.

Diff:
---
 gcc/cgraphunit.cc|  2 ++
 gcc/testsuite/gcc.dg/graphite/pr116068.c | 26 ++
 2 files changed, 28 insertions(+)

diff --git a/gcc/cgraphunit.cc b/gcc/cgraphunit.cc
index 284a22bb808f..82f205488e90 100644
--- a/gcc/cgraphunit.cc
+++ b/gcc/cgraphunit.cc
@@ -311,6 +311,7 @@ symbol_table::process_new_functions (void)
 {
   cgraph_node *node = cgraph_new_nodes[i];
   fndecl = node->decl;
+  bitmap_obstack_initialize (NULL);
   switch (state)
{
case CONSTRUCTION:
@@ -367,6 +368,7 @@ symbol_table::process_new_functions (void)
  gcc_unreachable ();
  break;
}
+  bitmap_obstack_release (NULL);
 }
 
   cgraph_new_nodes.release ();
diff --git a/gcc/testsuite/gcc.dg/graphite/pr116068.c 
b/gcc/testsuite/gcc.dg/graphite/pr116068.c
new file mode 100644
index ..99ff4f8f2e3f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/graphite/pr116068.c
@@ -0,0 +1,26 @@
+/* PR ipa/116068 */
+/* { dg-do compile { target { lto && { bitint && int128 } } } } */
+/* { dg-options "-Os -flto -ffat-lto-objects -floop-parallelize-all 
-ftree-parallelize-loops=2 --param=parloops-schedule=dynamic" } */
+
+#if __BITINT_MAXWIDTH__ >= 1024
+typedef _BitInt (1024) A;
+typedef __attribute__((__vector_size__ (16))) char B;
+typedef __attribute__((__vector_size__ (16))) int C;
+B a;
+A b;
+int c;
+unsigned int *p;
+
+void
+foo0 (unsigned _BitInt (512) x)
+{
+  C d = {};
+  _BitInt (1024) e = x | *(A *) __builtin_memset (&b, c, 8);
+  unsigned h = __builtin_stdc_first_leading_zero (*p);
+  C f = *(C *) __builtin_memset (&d, h, 6);
+  B g = (B) f;
+  a = g + (B) (__int128) e;
+}
+#else
+int i;
+#endif


[gcc r15-6921] AArch64: Deprecate -mabi=ilp32

2025-01-15 Thread Wilco Dijkstra via Gcc-cvs
https://gcc.gnu.org/g:625ea3c6ea1811388d030eddff57cd46c209d49a

commit r15-6921-g625ea3c6ea1811388d030eddff57cd46c209d49a
Author: Wilco Dijkstra 
Date:   Thu Jan 9 19:41:14 2025 +

AArch64: Deprecate -mabi=ilp32

ILP32 was originally intended to make porting to AArch64 easier.  Support 
was
never merged in the Linux kernel or GLIBC, so it has been unsupported for 
many
years.  There isn't a benefit in keeping unsupported features forever, so
deprecate it now (and it could be removed in a future release).

gcc:
* config/aarch64/aarch64.cc (aarch64_override_options): Add warning.
* doc/invoke.texi: Document -mabi=ilp32 as deprecated.

gcc/testsuite:
* gcc.target/aarch64/inline-mem-set-pr112804.c: Add -Wno-deprecated.
* gcc.target/aarch64/pr100518.c: Likewise.
* gcc.target/aarch64/pr113114.c: Likewise.
* gcc.target/aarch64/pr80295.c: Likewise.
* gcc.target/aarch64/pr94201.c: Likewise.
* gcc.target/aarch64/pr94577.c: Likewise.
* gcc.target/aarch64/sve/pr108603.c: Likewise.

Diff:
---
 gcc/config/aarch64/aarch64.cc  | 2 ++
 gcc/doc/invoke.texi| 2 ++
 gcc/testsuite/gcc.target/aarch64/inline-mem-set-pr112804.c | 2 +-
 gcc/testsuite/gcc.target/aarch64/pr100518.c| 2 +-
 gcc/testsuite/gcc.target/aarch64/pr113114.c| 2 +-
 gcc/testsuite/gcc.target/aarch64/pr80295.c | 2 +-
 gcc/testsuite/gcc.target/aarch64/pr94201.c | 2 +-
 gcc/testsuite/gcc.target/aarch64/pr94577.c | 2 +-
 gcc/testsuite/gcc.target/aarch64/sve/pr108603.c| 2 +-
 9 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index ad31e9d255c0..1dbbc9c3cf9b 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -19356,6 +19356,8 @@ aarch64_override_options (void)
   if (TARGET_ILP32)
 error ("assembler does not support %<-mabi=ilp32%>");
 #endif
+  if (TARGET_ILP32)
+warning (OPT_Wdeprecated, "%<-mabi=ilp32%> is deprecated");
 
   /* Convert -msve-vector-bits to a VG count.  */
   aarch64_sve_vg = aarch64_convert_sve_vector_bits (aarch64_sve_vector_bits);
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index dd0d2b41a1a9..13afb4a0d0d8 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -21472,6 +21472,8 @@ The default depends on the specific target 
configuration.  Note that
 the LP64 and ILP32 ABIs are not link-compatible; you must compile your
 entire program with the same ABI, and link with a compatible set of libraries.
 
+The @samp{ilp32} model is deprecated.
+
 @opindex mbig-endian
 @item -mbig-endian
 Generate big-endian code.  This is the default when GCC is configured for an
diff --git a/gcc/testsuite/gcc.target/aarch64/inline-mem-set-pr112804.c 
b/gcc/testsuite/gcc.target/aarch64/inline-mem-set-pr112804.c
index fe8414559864..276c10cd0e86 100644
--- a/gcc/testsuite/gcc.target/aarch64/inline-mem-set-pr112804.c
+++ b/gcc/testsuite/gcc.target/aarch64/inline-mem-set-pr112804.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-finline-stringops -mabi=ilp32 -ftrivial-auto-var-init=zero" 
} */
+/* { dg-options "-finline-stringops -mabi=ilp32 -Wno-deprecated 
-ftrivial-auto-var-init=zero" } */
 
 short m(unsigned k) {
   const unsigned short *n[65];
diff --git a/gcc/testsuite/gcc.target/aarch64/pr100518.c 
b/gcc/testsuite/gcc.target/aarch64/pr100518.c
index 5ca599f5d2e0..177991cfb228 100644
--- a/gcc/testsuite/gcc.target/aarch64/pr100518.c
+++ b/gcc/testsuite/gcc.target/aarch64/pr100518.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-mabi=ilp32 -mstrict-align -O2" } */
+/* { dg-options "-mabi=ilp32 -Wno-deprecated -mstrict-align -O2" } */
 
 int unsigned_range_min, unsigned_range_max, a11___trans_tmp_1;
 
diff --git a/gcc/testsuite/gcc.target/aarch64/pr113114.c 
b/gcc/testsuite/gcc.target/aarch64/pr113114.c
index 5b0383c24359..976e2db71bfa 100644
--- a/gcc/testsuite/gcc.target/aarch64/pr113114.c
+++ b/gcc/testsuite/gcc.target/aarch64/pr113114.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-mabi=ilp32 -O -mearly-ldp-fusion -mlate-ldp-fusion" } */
+/* { dg-options "-mabi=ilp32 -Wno-deprecated -O -mearly-ldp-fusion 
-mlate-ldp-fusion" } */
 void foo_n(double *a) {
   int i = 1;
   for (; i < (int)foo_n; i++)
diff --git a/gcc/testsuite/gcc.target/aarch64/pr80295.c 
b/gcc/testsuite/gcc.target/aarch64/pr80295.c
index b3866d8d6a9e..c79427517d0e 100644
--- a/gcc/testsuite/gcc.target/aarch64/pr80295.c
+++ b/gcc/testsuite/gcc.target/aarch64/pr80295.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-mabi=ilp32" } */
+/* { dg-options "-mabi=ilp32 -Wno-deprecated" } */
 
 void f (void *b) 
 { 
diff --git a/gcc/testsuite/gcc.target/aarch64/pr94201.c 
b/gcc/testsuite/gcc.target/aarch64/pr94201.c
index

[gcc r15-6923] AArch64: Update neoverse512tvb tuning

2025-01-15 Thread Wilco Dijkstra via Gcc-cvs
https://gcc.gnu.org/g:4ce502f31f95ec19e7d347d43afcd015895f135d

commit r15-6923-g4ce502f31f95ec19e7d347d43afcd015895f135d
Author: Wilco Dijkstra 
Date:   Fri Jan 10 19:48:02 2025 +

AArch64: Update neoverse512tvb tuning

Fix the neoverse512tvb tuning to be like Neoverse V1/V2 and add the
missing AARCH64_EXTRA_TUNE_BASE and AARCH64_EXTRA_TUNE_AVOID_PRED_RMW.

gcc:
* config/aarch64/tuning_models/neoverse512tvb.h (tune_flags): 
Update.

Diff:
---
 gcc/config/aarch64/tuning_models/neoverse512tvb.h | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/config/aarch64/tuning_models/neoverse512tvb.h 
b/gcc/config/aarch64/tuning_models/neoverse512tvb.h
index 50eb058e23d1..964b4ac284a8 100644
--- a/gcc/config/aarch64/tuning_models/neoverse512tvb.h
+++ b/gcc/config/aarch64/tuning_models/neoverse512tvb.h
@@ -155,8 +155,10 @@ static const struct tune_params neoverse512tvb_tunings =
   2,   /* min_div_recip_mul_df.  */
   0,   /* max_case_values.  */
   tune_params::AUTOPREFETCHER_WEAK,/* autoprefetcher_model.  */
-  (AARCH64_EXTRA_TUNE_CSE_SVE_VL_CONSTANTS
-   | AARCH64_EXTRA_TUNE_MATCHED_VECTOR_THROUGHPUT),/* tune_flags.  */
+  (AARCH64_EXTRA_TUNE_BASE
+   | AARCH64_EXTRA_TUNE_CSE_SVE_VL_CONSTANTS
+   | AARCH64_EXTRA_TUNE_MATCHED_VECTOR_THROUGHPUT
+   | AARCH64_EXTRA_TUNE_AVOID_PRED_RMW),   /* tune_flags.  */
   &generic_armv9a_prefetch_tune,
   AARCH64_LDP_STP_POLICY_ALWAYS,   /* ldp_policy_model.  */
   AARCH64_LDP_STP_POLICY_ALWAYS   /* stp_policy_model.  */


[gcc r15-6924] c++: Handle RAW_DATA_CST in unify [PR118390]

2025-01-15 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:2619413a5e032e2f2c3d4a2202ba8bf324cf08ab

commit r15-6924-g2619413a5e032e2f2c3d4a2202ba8bf324cf08ab
Author: Jakub Jelinek 
Date:   Wed Jan 15 18:27:07 2025 +0100

c++: Handle RAW_DATA_CST in unify [PR118390]

This patch uses the count_ctor_elements function to fix up
unify deduction of array sizes.

2025-01-15  Jakub Jelinek  

PR c++/118390
* cp-tree.h (count_ctor_elements): Declare.
* call.cc (count_ctor_elements): No longer static.
* pt.cc (unify): Use count_ctor_elements instead of
CONSTRUCTOR_NELTS.

* g++.dg/cpp/embed-20.C: New test.
* g++.dg/cpp0x/pr118390.C: New test.

Diff:
---
 gcc/cp/call.cc|  2 +-
 gcc/cp/cp-tree.h  |  1 +
 gcc/cp/pt.cc  |  2 +-
 gcc/testsuite/g++.dg/cpp/embed-20.C   | 14 ++
 gcc/testsuite/g++.dg/cpp0x/pr118390.C | 23 +++
 5 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 63be8b58906b..9e57261cf17d 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -4333,7 +4333,7 @@ has_non_trivial_temporaries (tree expr)
 
 /* Return number of initialized elements in CTOR.  */
 
-static unsigned HOST_WIDE_INT
+unsigned HOST_WIDE_INT
 count_ctor_elements (tree ctor)
 {
   unsigned HOST_WIDE_INT len = 0;
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 2d17c4c77b56..bb10c7ca053d 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -6815,6 +6815,7 @@ extern tree type_decays_to(tree);
 extern tree extract_call_expr  (tree);
 extern tree build_trivial_dtor_call(tree, bool = false);
 extern tristate ref_conv_binds_to_temporary(tree, tree, bool = false);
+extern unsigned HOST_WIDE_INT count_ctor_elements (tree);
 extern tree build_user_type_conversion (tree, tree, int,
 tsubst_flags_t);
 extern tree build_new_function_call(tree, vec **,
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index ff0a3a4f7d81..3b6743f2e3af 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -25072,7 +25072,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, 
int strict,
  && deducible_array_bound (TYPE_DOMAIN (parm)))
{
  /* Also deduce from the length of the initializer list.  */
- tree max = size_int (CONSTRUCTOR_NELTS (arg));
+ tree max = size_int (count_ctor_elements (arg));
  tree idx = compute_array_index_type (NULL_TREE, max, tf_none);
  if (idx == error_mark_node)
return unify_invalid (explain_p);
diff --git a/gcc/testsuite/g++.dg/cpp/embed-20.C 
b/gcc/testsuite/g++.dg/cpp/embed-20.C
new file mode 100644
index ..ad708406f3d7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp/embed-20.C
@@ -0,0 +1,14 @@
+// PR c++/118390
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+template
+constexpr int
+foo (const T (&x)[N])
+{
+  return N;
+}
+
+static_assert (foo ({
+  #embed __FILE__ limit (64)
+}) == 64, "");
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr118390.C 
b/gcc/testsuite/g++.dg/cpp0x/pr118390.C
new file mode 100644
index ..e5017b017d7f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/pr118390.C
@@ -0,0 +1,23 @@
+// PR c++/118390
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+template
+constexpr int
+foo (const T (&x)[N])
+{
+  return N;
+}
+
+static_assert (foo ({
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+}) == 160, "");


[gcc r15-6925] Fortran: reject NULL as source-expr in ALLOCATE with SOURCE= or MOLD= [PR71884]

2025-01-15 Thread Harald Anlauf via Gcc-cvs
https://gcc.gnu.org/g:892304f1fe3e808b9f498353c144f1ae0591

commit r15-6925-g892304f1fe3e808b9f498353c144f1ae0591
Author: Harald Anlauf 
Date:   Wed Jan 15 19:42:52 2025 +0100

Fortran: reject NULL as source-expr in ALLOCATE with SOURCE= or MOLD= 
[PR71884]

PR fortran/71884

gcc/fortran/ChangeLog:

* resolve.cc (resolve_allocate_expr): Reject intrinsic NULL as
source-expr.

gcc/testsuite/ChangeLog:

* gfortran.dg/pr71884.f90: New test.

Diff:
---
 gcc/fortran/resolve.cc| 12 
 gcc/testsuite/gfortran.dg/pr71884.f90 | 16 
 2 files changed, 28 insertions(+)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 3e74a2e50883..124f4ac4edcd 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -9433,6 +9433,18 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code, bool 
*array_alloc_wo_spec)
   /* Some checks for the SOURCE tag.  */
   if (code->expr3)
 {
+  /* Check F03:C632: "The source-expr shall be a scalar or have the same
+rank as allocate-object".  This would require the MOLD argument to
+NULL() as source-expr for subsequent checking.  However, even the
+resulting disassociated pointer or unallocated array has no shape that
+could be used for SOURCE= or MOLD=.  */
+  if (code->expr3->expr_type == EXPR_NULL)
+   {
+ gfc_error ("The intrinsic NULL cannot be used as source-expr at %L",
+&code->expr3->where);
+ goto failure;
+   }
+
   /* Check F03:C631.  */
   if (!gfc_type_compatible (&e->ts, &code->expr3->ts))
{
diff --git a/gcc/testsuite/gfortran.dg/pr71884.f90 
b/gcc/testsuite/gfortran.dg/pr71884.f90
new file mode 100644
index ..015a10290a15
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr71884.f90
@@ -0,0 +1,16 @@
+! { dg-do compile }
+! PR fortran/71884 - reject NULL as source-expr in ALLOCATE with SOURCE= or 
MOLD=
+!
+! Contributed by G.Steinmetz
+
+program p
+  real, allocatable :: a
+  real, pointer :: b
+  class(*), allocatable :: x
+  class(*), pointer :: y
+
+  allocate (x, source=null())  ! { dg-error "NULL cannot be used as 
source-expr" }
+  allocate (y, source=null(b)) ! { dg-error "NULL cannot be used as 
source-expr" }
+  allocate (x, mold=null(b))   ! { dg-error "NULL cannot be used as 
source-expr" }
+  allocate (y, mold=null())! { dg-error "NULL cannot be used as 
source-expr" }
+end


[gcc r15-6926] libstdc++: Fix reversed args in unreachable assumption [PR109849]

2025-01-15 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:6f85a97248fdff15aadc9514c1118eee0293d256

commit r15-6926-g6f85a97248fdff15aadc9514c1118eee0293d256
Author: Jonathan Wakely 
Date:   Wed Jan 15 09:33:55 2025 +

libstdc++: Fix reversed args in unreachable assumption [PR109849]

libstdc++-v3/ChangeLog:

PR libstdc++/109849
* include/bits/vector.tcc (vector::_M_range_insert): Fix
reversed args in length calculation.

Diff:
---
 libstdc++-v3/include/bits/vector.tcc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/vector.tcc 
b/libstdc++-v3/include/bits/vector.tcc
index 44920a0549ab..4f4c366080be 100644
--- a/libstdc++-v3/include/bits/vector.tcc
+++ b/libstdc++-v3/include/bits/vector.tcc
@@ -934,7 +934,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
const size_type __len =
  _M_check_len(__n, "vector::_M_range_insert");
 #if __cplusplus < 201103L
-   if (__len < (__n + (__old_start - __old_finish)))
+   if (__len < (__n + (__old_finish - __old_start)))
  __builtin_unreachable();
 #endif