[gcc r13-8637] c-family: Allow arguments with NULLPTR_TYPE as sentinels [PR114780]

2024-04-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:e802786436851b1f5efca21a14d4f41c83c83f4f

commit r13-8637-ge802786436851b1f5efca21a14d4f41c83c83f4f
Author: Jakub Jelinek 
Date:   Sat Apr 20 00:12:36 2024 +0200

c-family: Allow arguments with NULLPTR_TYPE as sentinels [PR114780]

While in C++ the ellipsis argument conversions include
"An argument that has type cv std::nullptr_t is converted to type void*"
in C23 a nullptr_t argument is not promoted in any way, but va_arg
description says:
"the type of the next argument is nullptr_t and type is a pointer type that 
has the same
representation and alignment requirements as a pointer to a character type."
So, while in C++ check_function_sentinel will never see NULLPTR_TYPE, for
C23 it can see that and currently we incorrectly warn about those.

The only question is whether we should warn on any argument with
nullptr_t type or just about nullptr (nullptr_t argument with integer_zerop
value).  Through undefined behavior guess one could pass non-NULL pointer
that way, say by union { void *p; nullptr_t q; } u; u.p = 
and pass u.q to ..., but valid code should always pass something that will
read as (char *) 0 when read using va_arg (ap, char *), so I think it is
better not to warn rather than warn in those cases.

Note, clang seems to pass (void *)0 rather than expression of nullptr_t
type to ellipsis in C23 mode as if it did the C++ ellipsis argument
conversions, in that case guess not warning about that would be even safer,
but what GCC does I think follows the spec more closely, even when in a
valid program one shouldn't be able to observe the difference.

2024-04-20  Jakub Jelinek  

PR c/114780
* c-common.cc (check_function_sentinel): Allow as sentinel any
argument of NULLPTR_TYPE.

* gcc.dg/format/sentinel-2.c: New test.

(cherry picked from commit 2afdecccbaf5c5b1c7a235509b37092540906c02)

Diff:
---
 gcc/c-family/c-common.cc |  1 +
 gcc/testsuite/gcc.dg/format/sentinel-2.c | 21 +
 2 files changed, 22 insertions(+)

diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index aae397ed755..d423cbbacae 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -5703,6 +5703,7 @@ check_function_sentinel (const_tree fntype, int nargs, 
tree *argarray)
   sentinel = fold_for_warn (argarray[nargs - 1 - pos]);
   if ((!POINTER_TYPE_P (TREE_TYPE (sentinel))
   || !integer_zerop (sentinel))
+ && TREE_CODE (TREE_TYPE (sentinel)) != NULLPTR_TYPE
  /* Although __null (in C++) is only an integer we allow it
 nevertheless, as we are guaranteed that it's exactly
 as wide as a pointer, and we don't want to force
diff --git a/gcc/testsuite/gcc.dg/format/sentinel-2.c 
b/gcc/testsuite/gcc.dg/format/sentinel-2.c
new file mode 100644
index 000..eeff4b2f4bb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/sentinel-2.c
@@ -0,0 +1,21 @@
+/* PR c/114780 */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -Wformat" } */
+
+#include 
+
+[[gnu::sentinel]] void foo (int, ...);
+[[gnu::sentinel]] void bar (...);
+
+void
+baz (nullptr_t p)
+{
+  foo (1, 2, nullptr);
+  foo (3, 4, 5, p);
+  bar (nullptr);
+  bar (p);
+  foo (6, 7, 0);   // { dg-warning "missing sentinel in function call" }
+  bar (0); // { dg-warning "missing sentinel in function call" }
+  foo (8, 9, NULL);
+  bar (NULL);
+}


[gcc r13-8635] internal-fn: Temporarily disable flag_trapv during .{ADD, SUB, MUL}_OVERFLOW etc. expansion [PR114753]

2024-04-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:10f689596ad1633f4f5de1852c8f82a993fe948e

commit r13-8635-g10f689596ad1633f4f5de1852c8f82a993fe948e
Author: Jakub Jelinek 
Date:   Thu Apr 18 09:45:14 2024 +0200

internal-fn: Temporarily disable flag_trapv during .{ADD,SUB,MUL}_OVERFLOW 
etc. expansion [PR114753]

__builtin_{add,sub,mul}_overflow{,_p} builtins are well defined
for all inputs even for -ftrapv, and the -fsanitize=signed-integer-overflow
ifns shouldn't abort in libgcc but emit the desired ubsan diagnostics
or abort depending on -fsanitize* setting regardless of -ftrapv.
The expansion of these internal functions uses expand_expr* in various
places (e.g. MULT_EXPR at least in 2 spots), so temporarily disabling
flag_trapv in all those spots would be hard.
The following patch disables it around the bodies of 3 functions
which can do the expand_expr calls.
If it was in the C++ FE, I'd use some RAII sentinel, but I don't think
we have one in the middle-end.

2024-04-18  Jakub Jelinek  

PR middle-end/114753
* internal-fn.cc (expand_mul_overflow): Save flag_trapv and
temporarily clear it for the duration of the function, then
restore previous value.
(expand_vector_ubsan_overflow): Likewise.
(expand_arith_overflow): Likewise.

* gcc.dg/pr114753.c: New test.

(cherry picked from commit 6c152c9db3b5b9d43e12846fb7a44977c0b65fc2)

Diff:
---
 gcc/internal-fn.cc  | 19 +++
 gcc/testsuite/gcc.dg/pr114753.c | 14 ++
 2 files changed, 33 insertions(+)

diff --git a/gcc/internal-fn.cc b/gcc/internal-fn.cc
index 6e81dc05e0e..c8943e6cb9e 100644
--- a/gcc/internal-fn.cc
+++ b/gcc/internal-fn.cc
@@ -1482,7 +1482,11 @@ expand_mul_overflow (location_t loc, tree lhs, tree 
arg0, tree arg1,
   rtx target = NULL_RTX;
   signop sign;
   enum insn_code icode;
+  int save_flag_trapv = flag_trapv;
 
+  /* We don't want any __mulv?i3 etc. calls from the expansion of
+ these internal functions, so disable -ftrapv temporarily.  */
+  flag_trapv = 0;
   done_label = gen_label_rtx ();
   do_error = gen_label_rtx ();
 
@@ -2324,6 +2328,7 @@ expand_mul_overflow (location_t loc, tree lhs, tree arg0, 
tree arg1,
   else
expand_arith_overflow_result_store (lhs, target, mode, res);
 }
+  flag_trapv = save_flag_trapv;
 }
 
 /* Expand UBSAN_CHECK_* internal function if it has vector operands.  */
@@ -2344,7 +2349,11 @@ expand_vector_ubsan_overflow (location_t loc, enum 
tree_code code, tree lhs,
   rtx resvr = NULL_RTX;
   unsigned HOST_WIDE_INT const_cnt = 0;
   bool use_loop_p = (!cnt.is_constant (_cnt) || const_cnt > 4);
+  int save_flag_trapv = flag_trapv;
 
+  /* We don't want any __mulv?i3 etc. calls from the expansion of
+ these internal functions, so disable -ftrapv temporarily.  */
+  flag_trapv = 0;
   if (lhs)
 {
   optab op;
@@ -2474,6 +2483,7 @@ expand_vector_ubsan_overflow (location_t loc, enum 
tree_code code, tree lhs,
 }
   else if (resvr)
 emit_move_insn (lhsr, resvr);
+  flag_trapv = save_flag_trapv;
 }
 
 /* Expand UBSAN_CHECK_ADD call STMT.  */
@@ -2552,7 +2562,11 @@ expand_arith_overflow (enum tree_code code, gimple *stmt)
   prec0 = MIN (prec0, pr);
   pr = get_min_precision (arg1, uns1_p ? UNSIGNED : SIGNED);
   prec1 = MIN (prec1, pr);
+  int save_flag_trapv = flag_trapv;
 
+  /* We don't want any __mulv?i3 etc. calls from the expansion of
+ these internal functions, so disable -ftrapv temporarily.  */
+  flag_trapv = 0;
   /* If uns0_p && uns1_p, precop is minimum needed precision
  of unsigned type to hold the exact result, otherwise
  precop is minimum needed precision of signed type to
@@ -2593,6 +2607,7 @@ expand_arith_overflow (enum tree_code code, gimple *stmt)
  ops.location = loc;
  rtx tem = expand_expr_real_2 (, NULL_RTX, mode, EXPAND_NORMAL);
  expand_arith_overflow_result_store (lhs, target, mode, tem);
+ flag_trapv = save_flag_trapv;
  return;
}
 
@@ -2616,16 +2631,19 @@ expand_arith_overflow (enum tree_code code, gimple 
*stmt)
  if (integer_zerop (arg0) && !unsr_p)
{
  expand_neg_overflow (loc, lhs, arg1, false, NULL);
+ flag_trapv = save_flag_trapv;
  return;
}
  /* FALLTHRU */
case PLUS_EXPR:
  expand_addsub_overflow (loc, code, lhs, arg0, arg1, unsr_p,
  unsr_p, unsr_p, false, NULL);
+ flag_trapv = save_flag_trapv;
  return;
case MULT_EXPR:
  expand_mul_overflow (loc, lhs, arg0, arg1, unsr_p,
   unsr_p, unsr_p, false, NULL);
+ flag_trapv = save_flag_trapv;
  return;
default:
  gcc_unreachable ();
@@ -2671,6 +2689,7 @@ expand_arith_overflow 

[gcc r13-8634] asan: Don't instrument .ABNORMAL_DISPATCHER [PR114743]

2024-04-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:cd8e2137462d9ae1723fa193b6062ec65d164457

commit r13-8634-gcd8e2137462d9ae1723fa193b6062ec65d164457
Author: Jakub Jelinek 
Date:   Wed Apr 17 10:24:18 2024 +0200

asan: Don't instrument .ABNORMAL_DISPATCHER [PR114743]

.ABNORMAL_DISPATCHER is currently the only internal function with
ECF_NORETURN, and asan likes to instrument ECF_NORETURN calls by adding
some builtin call before them, which breaks the .ABNORMAL_DISPATCHER
discovery added in gsi_safe_*.

The following patch fixes asan not to instrument .ABNORMAL_DISPATCHER
calls, like it doesn't instrument a couple of specific builtin calls
as well.

2024-04-17  Jakub Jelinek  

PR sanitizer/114743
* asan.cc (maybe_instrument_call): Don't instrument calls to
.ABNORMAL_DISPATCHER.

* gcc.dg/asan/pr112709-2.c (freddy): New function from
gcc.dg/ubsan/pr112709-2.c version of the test.

(cherry picked from commit 299d14a54672a4d12c1abbe4031a732bb56cddaa)

Diff:
---
 gcc/asan.cc|  3 +++
 gcc/testsuite/gcc.dg/asan/pr112709-2.c | 12 
 2 files changed, 15 insertions(+)

diff --git a/gcc/asan.cc b/gcc/asan.cc
index a917aa24ed8..55ce68f9777 100644
--- a/gcc/asan.cc
+++ b/gcc/asan.cc
@@ -3025,6 +3025,9 @@ maybe_instrument_call (gimple_stmt_iterator *iter)
  break;
}
}
+  if (gimple_call_internal_p (stmt, IFN_ABNORMAL_DISPATCHER))
+   /* Don't instrument this.  */
+   return false;
   /* If a function does not return, then we must handle clearing up the
 shadow stack accordingly.  For ASAN we can simply set the entire stack
 to "valid" for accesses by setting the shadow space to 0 and all
diff --git a/gcc/testsuite/gcc.dg/asan/pr112709-2.c 
b/gcc/testsuite/gcc.dg/asan/pr112709-2.c
index e793f53507f..6fa3491c7eb 100644
--- a/gcc/testsuite/gcc.dg/asan/pr112709-2.c
+++ b/gcc/testsuite/gcc.dg/asan/pr112709-2.c
@@ -48,3 +48,15 @@ l3:
   if (x < 4)
 goto *q[x & 3];
 }
+
+void
+freddy (int x, int *y, struct S *p)
+{
+  bar (*p);
+  ++p;
+  if (x == 25)
+x = foo (2);
+  else if (x == 42)
+x = foo (foo (3));
+  *y = bar (*p);
+}


[gcc r13-8631] Limit special asan/ubsan/bitint returns_twice handling to calls in bbs with abnormal pred [PR114687]

2024-04-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:7a1a52934a2ab9ac9205a3a4d5b82a672fefba7e

commit r13-8631-g7a1a52934a2ab9ac9205a3a4d5b82a672fefba7e
Author: Jakub Jelinek 
Date:   Fri Apr 12 10:59:54 2024 +0200

Limit special asan/ubsan/bitint returns_twice handling to calls in bbs with 
abnormal pred [PR114687]

The tree-cfg.cc verifier only diagnoses returns_twice calls preceded
by non-label/debug stmts if it is in a bb with abnormal predecessor.
The following testcase shows that if a user lies in the attributes
(a function which never returns can't be pure, and can't return
twice when it doesn't ever return at all), when we figure it out,
we can remove the abnormal edges to the "returns_twice" call and perhaps
whole .ABNORMAL_DISPATCHER etc.
edge_before_returns_twice_call then ICEs because it can't find such
an edge.

The following patch limits the special handling to calls in bbs where
the verifier requires that.

2024-04-12  Jakub Jelinek  

PR sanitizer/114687
* gimple-iterator.cc (gsi_safe_insert_before): Only use
edge_before_returns_twice_call if bb_has_abnormal_pred.
(gsi_safe_insert_seq_before): Likewise.

* gcc.dg/asan/pr114687.c: New test.

(cherry picked from commit c9e94ae448ba309dba74de3ee1974a3ed9248889)

Diff:
---
 gcc/gimple-iterator.cc   |  6 --
 gcc/testsuite/gcc.dg/asan/pr114687.c | 22 ++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-iterator.cc b/gcc/gimple-iterator.cc
index 07a77ca2a77..ee1081dec1a 100644
--- a/gcc/gimple-iterator.cc
+++ b/gcc/gimple-iterator.cc
@@ -1048,7 +1048,8 @@ gsi_safe_insert_before (gimple_stmt_iterator *iter, 
gimple *g)
   gimple *stmt = gsi_stmt (*iter);
   if (stmt
   && is_gimple_call (stmt)
-  && (gimple_call_flags (stmt) & ECF_RETURNS_TWICE) != 0)
+  && (gimple_call_flags (stmt) & ECF_RETURNS_TWICE) != 0
+  && bb_has_abnormal_pred (gsi_bb (*iter)))
 {
   edge e = edge_before_returns_twice_call (gsi_bb (*iter));
   basic_block new_bb = gsi_insert_on_edge_immediate (e, g);
@@ -1071,7 +1072,8 @@ gsi_safe_insert_seq_before (gimple_stmt_iterator *iter, 
gimple_seq seq)
   gimple *stmt = gsi_stmt (*iter);
   if (stmt
   && is_gimple_call (stmt)
-  && (gimple_call_flags (stmt) & ECF_RETURNS_TWICE) != 0)
+  && (gimple_call_flags (stmt) & ECF_RETURNS_TWICE) != 0
+  && bb_has_abnormal_pred (gsi_bb (*iter)))
 {
   edge e = edge_before_returns_twice_call (gsi_bb (*iter));
   gimple *f = gimple_seq_first_stmt (seq);
diff --git a/gcc/testsuite/gcc.dg/asan/pr114687.c 
b/gcc/testsuite/gcc.dg/asan/pr114687.c
new file mode 100644
index 000..48cc8688176
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/asan/pr114687.c
@@ -0,0 +1,22 @@
+/* PR sanitizer/114687 */
+/* { dg-do compile } */
+
+int a;
+int foo (int);
+
+__attribute__((pure, returns_twice)) int
+bar (void)
+{
+  a = 1;
+  while (a)
+a = 2;
+  return a;
+}
+
+int
+baz (void)
+{
+  int d = bar ();
+  foo (d);
+  return 0;
+}


[gcc r13-8636] rtlanal: Fix set_noop_p for volatile loads or stores [PR114768]

2024-04-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:ab3b83afc149edda11fa3c7cbb3815606731003b

commit r13-8636-gab3b83afc149edda11fa3c7cbb3815606731003b
Author: Jakub Jelinek 
Date:   Fri Apr 19 08:47:53 2024 +0200

rtlanal: Fix set_noop_p for volatile loads or stores [PR114768]

On the following testcase, combine propagates the mem/v load into mem store
with the same address and then removes it, because noop_move_p says it is a
no-op move.  If it was the other way around, i.e. mem/v store and mem load,
or both would be mem/v, it would be kept.
The problem is that rtx_equal_p never checks any kind of flags on the rtxes
(and I think it would be quite dangerous to change it at this point), and
set_noop_p checks side_effects_p on just one of the operands, not both.
In the MEM <- MEM set, it only checks it on the destination, in
store to ZERO_EXTRACT only checks it on the source.

The following patch adds the missing side_effects_p checks.

2024-04-19  Jakub Jelinek  

PR rtl-optimization/114768
* rtlanal.cc (set_noop_p): Don't return true for MEM <- MEM
sets if src has side-effects or for stores into ZERO_EXTRACT
if ZERO_EXTRACT operand has side-effects.

* gcc.dg/pr114768.c: New test.

(cherry picked from commit 9f295847a9c32081bdd0fe908ffba58e830a24fb)

Diff:
---
 gcc/rtlanal.cc  | 11 +++
 gcc/testsuite/gcc.dg/pr114768.c | 10 ++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc
index 6b02428b735..7edb07a9b2c 100644
--- a/gcc/rtlanal.cc
+++ b/gcc/rtlanal.cc
@@ -1639,12 +1639,15 @@ set_noop_p (const_rtx set)
 return 1;
 
   if (MEM_P (dst) && MEM_P (src))
-return rtx_equal_p (dst, src) && !side_effects_p (dst);
+return (rtx_equal_p (dst, src)
+   && !side_effects_p (dst)
+   && !side_effects_p (src));
 
   if (GET_CODE (dst) == ZERO_EXTRACT)
-return rtx_equal_p (XEXP (dst, 0), src)
-  && !BITS_BIG_ENDIAN && XEXP (dst, 2) == const0_rtx
-  && !side_effects_p (src);
+return (rtx_equal_p (XEXP (dst, 0), src)
+   && !BITS_BIG_ENDIAN && XEXP (dst, 2) == const0_rtx
+   && !side_effects_p (src)
+   && !side_effects_p (XEXP (dst, 0)));
 
   if (GET_CODE (dst) == STRICT_LOW_PART)
 dst = XEXP (dst, 0);
diff --git a/gcc/testsuite/gcc.dg/pr114768.c b/gcc/testsuite/gcc.dg/pr114768.c
new file mode 100644
index 000..ffe3b368638
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr114768.c
@@ -0,0 +1,10 @@
+/* PR rtl-optimization/114768 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-rtl-final" } */
+/* { dg-final { scan-rtl-dump "\\\(mem/v:" "final" } } */
+
+void
+foo (int *p)
+{
+  *p = *(volatile int *) p;
+}


[gcc r13-8627] c++: Fix ICE with weird copy assignment operator [PR114572]

2024-04-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:910fa4d9df8f72d16279324cca2bf1f2649aa68b

commit r13-8627-g910fa4d9df8f72d16279324cca2bf1f2649aa68b
Author: Jakub Jelinek 
Date:   Fri Apr 5 09:31:28 2024 +0200

c++: Fix ICE with weird copy assignment operator [PR114572]

While ctors/dtors don't return anything (undeclared void or this pointer
on arm) and copy assignment operators normally return a reference to *this,
it isn't invalid to return uselessly some class object which might need
destructing, but the OpenMP clause handling code wasn't expecting that.

The following patch fixes that.

2024-04-05  Jakub Jelinek  

PR c++/114572
* cp-gimplify.cc (cxx_omp_clause_apply_fn): Call build_cplus_new
on build_call_a result if it has class type.

* testsuite/libgomp.c++/pr114572.C: New test.

(cherry picked from commit 592536eb3c0a97a55b1019ff0216ef77e6ca847e)

Diff:
---
 gcc/cp/cp-gimplify.cc|  4 
 libgomp/testsuite/libgomp.c++/pr114572.C | 24 
 2 files changed, 28 insertions(+)

diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
index 2eea7a6c0cf..3109f38d5cb 100644
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -2116,6 +2116,8 @@ cxx_omp_clause_apply_fn (tree fn, tree arg1, tree arg2)
   TREE_PURPOSE (parm), fn,
   i - is_method, tf_warning_or_error);
   t = build_call_a (fn, i, argarray);
+  if (MAYBE_CLASS_TYPE_P (TREE_TYPE (t)))
+   t = build_cplus_new (TREE_TYPE (t), t, tf_warning_or_error);
   t = fold_convert (void_type_node, t);
   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
   append_to_statement_list (t, );
@@ -2149,6 +2151,8 @@ cxx_omp_clause_apply_fn (tree fn, tree arg1, tree arg2)
   TREE_PURPOSE (parm), fn,
   i - is_method, tf_warning_or_error);
   t = build_call_a (fn, i, argarray);
+  if (MAYBE_CLASS_TYPE_P (TREE_TYPE (t)))
+   t = build_cplus_new (TREE_TYPE (t), t, tf_warning_or_error);
   t = fold_convert (void_type_node, t);
   return fold_build_cleanup_point_expr (TREE_TYPE (t), t);
 }
diff --git a/libgomp/testsuite/libgomp.c++/pr114572.C 
b/libgomp/testsuite/libgomp.c++/pr114572.C
new file mode 100644
index 000..21d5c847f8d
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c++/pr114572.C
@@ -0,0 +1,24 @@
+// PR c++/114572
+// { dg-do run }
+// { dg-options "-fopenmp -O0" }
+
+#include 
+
+struct S
+{
+  S () : s (0) {}
+  ~S () {}
+  S operator= (const S ) { s = x.s; return *this; }
+  int s;
+};
+
+int
+main ()
+{
+  S s;
+  #pragma omp parallel for lastprivate(s)
+  for (int i = 0; i < 10; ++i)
+s.s = i;
+  if (s.s != 9)
+abort ();
+}


[gcc r13-8628] vect: Don't clear base_misaligned in update_epilogue_loop_vinfo [PR114566]

2024-04-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:38af0d59043da4cc07cd62c17da599e43668e3be

commit r13-8628-g38af0d59043da4cc07cd62c17da599e43668e3be
Author: Jakub Jelinek 
Date:   Fri Apr 5 14:56:14 2024 +0200

vect: Don't clear base_misaligned in update_epilogue_loop_vinfo [PR114566]

The following testcase is miscompiled, because in the vectorized
epilogue the vectorizer assumes it can use aligned loads/stores
(if the base decl gets alignment increased), but it actually doesn't
increase that.
This is because r10-4203-g97c1460367 added the hunk following
patch removes.  The explanation feels reasonable, but actually it
is not true as the testcase proves.
The thing is, we vectorize the main loop with 64-byte vectors
and the corresponding data refs have base_alignment 16 (the
a array has DECL_ALIGN 128) and offset_alignment 32.  Now, because
of the offset_alignment 32 rather than 64, we need to use unaligned
loads/stores in the main loop (and ditto in the first load/store
in vectorized epilogue).  But the second load/store in the vectorized
epilogue uses only 32-byte vectors and because it is a multiple
of offset_alignment, it checks if we could increase alignment of the
a VAR_DECL, the function returns true, sets base_misaligned = true
and says the access is then aligned.
But when update_epilogue_loop_vinfo clears base_misaligned with the
assumption that the var had to have the alignment increased already,
the update of DECL_ALIGN doesn't happen anymore.

Now, I'd think this base_alignment = false was needed before
r10-4030-gd2db7f7901 change was committed where it incorrectly
overwrote DECL_ALIGN even if it was already larger, rather than
just always increasing it.  But with that change in, it doesn't
make sense to me anymore.

Note, the testcase is latent on the trunk, but reproduces on the 13
branch.

2024-04-05  Jakub Jelinek  

PR tree-optimization/114566
* tree-vect-loop.cc (update_epilogue_loop_vinfo): Don't clear
base_misaligned.

* gcc.target/i386/avx512f-pr114566.c: New test.

(cherry picked from commit a844095e17c1a5aada1364c6f6eaade87ead463c)

Diff:
---
 gcc/testsuite/gcc.target/i386/avx512f-pr114566.c | 34 
 gcc/tree-vect-loop.cc|  8 +-
 2 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/gcc/testsuite/gcc.target/i386/avx512f-pr114566.c 
b/gcc/testsuite/gcc.target/i386/avx512f-pr114566.c
new file mode 100644
index 000..abfab1bfcd5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx512f-pr114566.c
@@ -0,0 +1,34 @@
+/* PR tree-optimization/114566 */
+/* { dg-do run } */
+/* { dg-options "-O3 -mavx512f" } */
+/* { dg-additional-options "-fstack-protector-strong" { target 
fstack_protector } } */
+/* { dg-require-effective-target avx512f } */
+
+#define AVX512F
+#include "avx512f-helper.h"
+
+__attribute__((noipa)) int
+foo (float x, float y)
+{
+  float a[8][56];
+  __builtin_memset (a, 0, sizeof (a));
+
+  for (int j = 0; j < 8; j++)
+for (int k = 0; k < 56; k++)
+  {
+   float b = k * y;
+   if (b < 0.)
+ b = 0.;
+   if (b > 0.)
+ b = 0.;
+   a[j][k] += b;
+  }
+
+  return __builtin_log (x);
+}
+
+void
+TEST (void)
+{
+  foo (86.25f, 0.625f);
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index b4ce9535646..31ced32126e 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -10607,9 +10607,7 @@ find_in_mapping (tree t, void *context)
corresponding dr_vec_info need to be reconnected to the EPILOGUE's
stmt_vec_infos, their statements need to point to their corresponding copy,
if they are gather loads or scatter stores then their reference needs to be
-   updated to point to its corresponding copy and finally we set
-   'base_misaligned' to false as we have already peeled for alignment in the
-   prologue of the main loop.  */
+   updated to point to its corresponding copy.  */
 
 static void
 update_epilogue_loop_vinfo (class loop *epilogue, tree advance)
@@ -10750,10 +10748,6 @@ update_epilogue_loop_vinfo (class loop *epilogue, tree 
advance)
}
   DR_STMT (dr) = STMT_VINFO_STMT (stmt_vinfo);
   stmt_vinfo->dr_aux.stmt = stmt_vinfo;
-  /* The vector size of the epilogue is smaller than that of the main loop
-so the alignment is either the same or lower. This means the dr will
-thus by definition be aligned.  */
-  STMT_VINFO_DR_INFO (stmt_vinfo)->base_misaligned = false;
 }
 
   epilogue_vinfo->shared->datarefs_copy.release ();


[gcc r13-8626] fold-const: Handle NON_LVALUE_EXPR in native_encode_initializer [PR114537]

2024-04-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:a297f9bbb9611414fe48f6d61a8829bf5808bd2c

commit r13-8626-ga297f9bbb9611414fe48f6d61a8829bf5808bd2c
Author: Jakub Jelinek 
Date:   Thu Apr 4 10:47:52 2024 +0200

fold-const: Handle NON_LVALUE_EXPR in native_encode_initializer [PR114537]

The following testcase is incorrectly rejected.  The problem is that
for bit-fields native_encode_initializer expects the corresponding
CONSTRUCTOR elt value must be INTEGER_CST, but that isn't the case
here, it is wrapped into NON_LVALUE_EXPR by maybe_wrap_with_location.
We could STRIP_ANY_LOCATION_WRAPPER as well, but as all we are looking for
is INTEGER_CST inside, just looking through NON_LVALUE_EXPR seems easier.

2024-04-04  Jakub Jelinek  

PR c++/114537
* fold-const.cc (native_encode_initializer): Look through
NON_LVALUE_EXPR if val is INTEGER_CST.

* g++.dg/cpp2a/bit-cast16.C: New test.

(cherry picked from commit 1baec8deb014b8a7da58879a407a4c00cdeb5a09)

Diff:
---
 gcc/fold-const.cc   |  2 ++
 gcc/testsuite/g++.dg/cpp2a/bit-cast16.C | 16 
 2 files changed, 18 insertions(+)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 31ae6cebbe6..25dd7c1094e 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -8485,6 +8485,8 @@ native_encode_initializer (tree init, unsigned char *ptr, 
int len,
  if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
return 0;
 
+ if (TREE_CODE (val) == NON_LVALUE_EXPR)
+   val = TREE_OPERAND (val, 0);
  if (TREE_CODE (val) != INTEGER_CST)
return 0;
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/bit-cast16.C 
b/gcc/testsuite/g++.dg/cpp2a/bit-cast16.C
new file mode 100644
index 000..d298af67ef2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/bit-cast16.C
@@ -0,0 +1,16 @@
+// PR c++/114537
+// { dg-do compile { target c++20 } }
+
+namespace std {
+template
+constexpr T
+bit_cast (const F& f) noexcept
+{
+  return __builtin_bit_cast (T, f);
+}
+}
+
+struct A { signed char b : 1 = 0; signed char c : 7 = 0; };
+struct D { unsigned char e; };
+constexpr unsigned char f = std::bit_cast (A{}).e;
+static_assert (f == 0);


[gcc r13-8629] c++: Fix up maybe_warn_for_constant_evaluated calls [PR114580]

2024-04-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:ae3b6dea0445f9650cf1a684527efac06497f1b4

commit r13-8629-gae3b6dea0445f9650cf1a684527efac06497f1b4
Author: Jakub Jelinek 
Date:   Tue Apr 9 09:31:42 2024 +0200

c++: Fix up maybe_warn_for_constant_evaluated calls [PR114580]

When looking at maybe_warn_for_constant_evaluated for the trivial
infinite loops patch, I've noticed that it can emit weird diagnostics
for if constexpr in templates, first warn that std::is_constant_evaluted()
always evaluates to false (because the function template is not constexpr)
and then during instantiation warn that std::is_constant_evaluted()
always evaluates to true (because it is used in if constexpr condition).
Now, only the latter is actually true, even when the if constexpr
is in a non-constexpr function, it will still always evaluate to true.

So, the following patch fixes it to call maybe_warn_for_constant_evaluated
always with IF_STMT_CONSTEXPR_P (if_stmt) as the second argument rather than
true if it is if constexpr with non-dependent condition etc.

2024-04-09  Jakub Jelinek  

PR c++/114580
* semantics.cc (finish_if_stmt_cond): Call
maybe_warn_for_constant_evaluated with IF_STMT_CONSTEXPR_P (if_stmt)
as the second argument, rather than true/false depending on if
it is if constexpr with non-dependent constant expression with
bool type.

* g++.dg/cpp2a/is-constant-evaluated15.C: New test.

(cherry picked from commit cfed80b9e4f562c99679739548df9369117dd791)

Diff:
---
 gcc/cp/semantics.cc| 10 +++-
 .../g++.dg/cpp2a/is-constant-evaluated15.C | 28 ++
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index ff5252905fe..a9fabf92a2a 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -1046,6 +1046,7 @@ tree
 finish_if_stmt_cond (tree orig_cond, tree if_stmt)
 {
   tree cond = maybe_convert_cond (orig_cond);
+  maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt));
   if (IF_STMT_CONSTEXPR_P (if_stmt)
   && !type_dependent_expression_p (cond)
   && require_constant_expression (cond)
@@ -1054,16 +1055,11 @@ finish_if_stmt_cond (tree orig_cond, tree if_stmt)
 converted to bool.  */
   && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
 {
-  maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/true);
   cond = instantiate_non_dependent_expr (cond);
   cond = cxx_constant_value (cond);
 }
-  else
-{
-  maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false);
-  if (processing_template_decl)
-   cond = orig_cond;
-}
+  else if (processing_template_decl)
+cond = orig_cond;
   finish_cond (_COND (if_stmt), cond);
   add_stmt (if_stmt);
   THEN_CLAUSE (if_stmt) = push_stmt_list ();
diff --git a/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated15.C 
b/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated15.C
new file mode 100644
index 000..50a3cac6e07
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated15.C
@@ -0,0 +1,28 @@
+// PR c++/114580
+// { dg-do compile { target c++17 } }
+// { dg-options "-Wtautological-compare" }
+
+namespace std {
+  constexpr inline bool
+  is_constant_evaluated () noexcept
+  {
+#if __cpp_if_consteval >= 202106L
+if consteval { return true; } else { return false; }
+#else
+return __builtin_is_constant_evaluated ();
+#endif
+  }
+}
+
+template 
+void foo ()
+{
+  if constexpr ((T) std::is_constant_evaluated ()) // { dg-warning 
"'std::is_constant_evaluated' always evaluates to true in 'if constexpr'" }
+;  // { dg-bogus 
"'std::is_constant_evaluated' always evaluates to false in a non-'constexpr' 
function" }
+}
+
+void
+bar ()
+{
+  foo  ();
+}


[gcc r13-8632] c++: Fix bogus warnings about ignored annotations [PR114691]

2024-04-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:ed7be7ba6f125cfda7ad07263213cbe02b7e7ced

commit r13-8632-ged7be7ba6f125cfda7ad07263213cbe02b7e7ced
Author: Jakub Jelinek 
Date:   Fri Apr 12 20:53:10 2024 +0200

c++: Fix bogus warnings about ignored annotations [PR114691]

The middle-end warns about the ANNOTATE_EXPR added for while/for loops
if they declare a var inside of the loop condition.
This is because the assumption is that ANNOTATE_EXPR argument is used
immediately in a COND_EXPR (later GIMPLE_COND), but simplify_loop_decl_cond
wraps the ANNOTATE_EXPR inside of a TRUTH_NOT_EXPR, so it no longer
holds.

The following patch fixes that by adding the TRUTH_NOT_EXPR inside of the
ANNOTATE_EXPR argument if any.

2024-04-12  Jakub Jelinek  

PR c++/114691
* semantics.cc (simplify_loop_decl_cond): Use cp_build_unary_op with
TRUTH_NOT_EXPR on ANNOTATE_EXPR argument (if any) rather than
ANNOTATE_EXPR itself.

* g++.dg/ext/pr114691.C: New test.

(cherry picked from commit 91146346f57cc54dfeb2669347edd0eb3d13af7f)

Diff:
---
 gcc/cp/semantics.cc |  6 +-
 gcc/testsuite/g++.dg/ext/pr114691.C | 22 ++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index a9fabf92a2a..3bf478fd68c 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -800,7 +800,11 @@ simplify_loop_decl_cond (tree *cond_p, tree body)
   *cond_p = boolean_true_node;
 
   if_stmt = begin_if_stmt ();
-  cond = cp_build_unary_op (TRUTH_NOT_EXPR, cond, false, tf_warning_or_error);
+  cond_p = 
+  while (TREE_CODE (*cond_p) == ANNOTATE_EXPR)
+cond_p = _OPERAND (*cond_p, 0);
+  *cond_p = cp_build_unary_op (TRUTH_NOT_EXPR, *cond_p, false,
+  tf_warning_or_error);
   finish_if_stmt_cond (cond, if_stmt);
   finish_break_stmt ();
   finish_then_clause (if_stmt);
diff --git a/gcc/testsuite/g++.dg/ext/pr114691.C 
b/gcc/testsuite/g++.dg/ext/pr114691.C
new file mode 100644
index 000..bda8ff9b39f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/pr114691.C
@@ -0,0 +1,22 @@
+// PR c++/114691
+// { dg-do compile }
+// { dg-options "-O2 -Wall" }
+
+void qux (int);
+int foo (int);
+
+void
+bar (int x)
+{
+  #pragma GCC ivdep
+  while (int y = foo (x))  // { dg-bogus "ignoring loop annotation" }
+qux (y);
+}
+
+void
+baz (int x)
+{
+  #pragma GCC ivdep
+  for (; int y = foo (x); )// { dg-bogus "ignoring loop annotation" }
+qux (y);
+}


[gcc r13-8633] attribs: Don't crash on NULL TREE_TYPE in diag_attr_exclusions [PR114634]

2024-04-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:2c85e8def0efd4b0d9d312a1f0cbbee332b4e0d1

commit r13-8633-g2c85e8def0efd4b0d9d312a1f0cbbee332b4e0d1
Author: Jakub Jelinek 
Date:   Mon Apr 15 10:25:22 2024 +0200

attribs: Don't crash on NULL TREE_TYPE in diag_attr_exclusions [PR114634]

The enumerator still doesn't have TREE_TYPE set but diag_attr_exclusions
assumes that all decls must have types.
I think it is better in something as unimportant as diag_attr_exclusions
to be more robust, if there is no type, it can just diagnose exclusions
on the DECL_ATTRIBUTES, like for types it only diagnoses it on
TYPE_ATTRIBUTES.

2024-04-15  Jakub Jelinek  

PR c++/114634
* attribs.cc (diag_attr_exclusions): Set attrs[1] to NULL_TREE for
decls with NULL TREE_TYPE.

* g++.dg/ext/attrib68.C: New test.

(cherry picked from commit 7ec54f5fdfec298812a749699874db4d6a7246bb)

Diff:
---
 gcc/attribs.cc  | 7 ++-
 gcc/testsuite/g++.dg/ext/attrib68.C | 8 
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gcc/attribs.cc b/gcc/attribs.cc
index 080b95928eb..24818c76f70 100644
--- a/gcc/attribs.cc
+++ b/gcc/attribs.cc
@@ -480,7 +480,12 @@ diag_attr_exclusions (tree last_decl, tree node, tree 
attrname,
   if (DECL_P (node))
 {
   attrs[0] = DECL_ATTRIBUTES (node);
-  attrs[1] = TYPE_ATTRIBUTES (TREE_TYPE (node));
+  if (TREE_TYPE (node))
+   attrs[1] = TYPE_ATTRIBUTES (TREE_TYPE (node));
+  else
+   /* TREE_TYPE can be NULL e.g. while processing attributes on
+  enumerators.  */
+   attrs[1] = NULL_TREE;
 }
   else
 {
diff --git a/gcc/testsuite/g++.dg/ext/attrib68.C 
b/gcc/testsuite/g++.dg/ext/attrib68.C
new file mode 100644
index 000..be3b1108491
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attrib68.C
@@ -0,0 +1,8 @@
+// PR c++/114634
+// { dg-do compile }
+
+template 
+struct A
+{
+  enum { e __attribute__ ((aligned (16))) };   // { dg-error "alignment may 
not be specified for 'e'" }
+};


[gcc r13-8630] asan, v3: Fix up handling of > 32 byte aligned variables with -fsanitize=address -fstack-protector*

2024-04-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:a16d90ec302e588dab5d7d31ccdd7b3fd5c6214e

commit r13-8630-ga16d90ec302e588dab5d7d31ccdd7b3fd5c6214e
Author: Jakub Jelinek 
Date:   Thu Apr 11 11:12:11 2024 +0200

asan, v3: Fix up handling of > 32 byte aligned variables with 
-fsanitize=address -fstack-protector* [PR110027]

On Tue, Mar 26, 2024 at 02:08:02PM +0800, liuhongt wrote:
> > > So, try to add some other variable with larger size and smaller 
alignment
> > > to the frame (and make sure it isn't optimized away).
> > >
> > > alignb above is the alignment of the first partition's var, if
> > > align_frame_offset really needs to depend on the var alignment, it 
probably
> > > should be the maximum alignment of all the vars with alignment
> > > alignb * BITS_PER_UNIT <=3D MAX_SUPPORTED_STACK_ALIGNMENT
> > >
>
> In asan_emit_stack_protection, when it allocated fake stack, it assume
> bottom of stack is also aligned to alignb. And the place violated this
> is the first var partition. which is 32 bytes offsets,  it should be
> BIGGEST_ALIGNMENT / BITS_PER_UNIT.
> So I think we need to use MAX (BIGGEST_ALIGNMENT /
> BITS_PER_UNIT, ASAN_RED_ZONE_SIZE) for the first var partition.

Your first patch aligned offsets[0] to maximum of alignb and
ASAN_RED_ZONE_SIZE.  But as I wrote in the reply to that mail, alignb there
is the alignment of just a single variable which is the first one to appear
in the sorted list and is placed in the highest spot in the stack frame.
That is not necessarily the largest alignment, the sorting ensures that it
is a variable with the largest size in the frame (and only if several of
them have equal size, largest alignment from the same sized ones).  Your
second patch used maximum of BIGGEST_ALIGNMENT / BITS_PER_UNIT and
ASAN_RED_ZONE_SIZE.  That doesn't change anything at all when using
-mno-avx512f - offsets[0] is still just 32-byte aligned in that case
relative to top of frame, just changes the -mavx512f case to be 64-byte
aligned offsets[0] (aka offsets[0] is then either 0 or -64 instead of either
0 or -32).  That will not help if any variable in the frame needs 128-byte,
256-byte, 512-byte ...  4096-byte alignment.  If you want to fix the bug in
the spot you've touched, you'd need to walk all the
stack_vars[stack_vars_sorted[si2]] for si2 [si + 1, n - 1] and for those
where the loop would do anything (i.e.
stack_vars[i2].representative == i2
&& TREE_CODE (decl2) == SSA_NAME
   ? SA.partition_to_pseudo[var_to_partition (SA.map, decl2)] == NULL_RTX
   : DECL_RTL (decl2) == pc_rtx
and the pred applies (but that means also walking the earlier ones!
because with -fstack-protector* the vars can be processed in several calls) 
and
alignb2 * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT
and compute maximum of those alignments.
That maximum is already computed,
data->asan_alignb = MAX (data->asan_alignb, alignb);
computes that, but you get the final result only after you do all the
expand_stack_vars calls.  You'd need to compute it before.

Though, that change would be still in the wrong place.
The thing is, it would be a waste of the precious stack space when it isn't
needed at all (e.g.  when asan will not at compile time do the use after
return checking, or if it won't do it at runtime, or even if it will do at
runtime it will waste the space on the stack).

The following patch fixes it solely for the __asan_stack_malloc_N
allocations, doesn't enlarge unnecessarily further the actual stack frame.
Because asan is only supported on FRAME_GROWS_DOWNWARD architectures
(mips, rs6000 and xtensa are conditional FRAME_GROWS_DOWNWARD arches, which
for -fsanitize=address or -fstack-protector* use FRAME_GROWS_DOWNWARD 1,
otherwise 0, others supporting asan always just use 1), the assumption for
the dynamic stack realignment is that the top of the stack frame (aka offset
0) is aligned to alignb passed to the function (which is the maximum of 
alignb
of all the vars in the frame).  As checked by the assertion in the patch,
offsets[0] is 0 most of the time and so that assumption is correct, the only
case when it is not 0 is if -fstack-protector* is on together with
-fsanitize=address and cfgexpand.cc (create_stack_guard) created a stack
guard.  That is the only variable which is allocated in the stack frame
right away, for all others with -fsanitize=address defer_stack_allocation
(or -fstack-protector*) returns true and so they aren't allocated
immediately but handled during the frame layout phases.  So, the original
frame_offset of 0 is changed because of the stack guard to
-pointer_size_in_bytes and later at the
  if (data->asan_vec.is_empty ())
{
  align_frame_offset 

[gcc r13-8625] libquadmath: Don't assume the storage for __float128 arguments is aligned [PR114533]

2024-04-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:cc39bd532d4de1ba0b2785246fb6fdd63ec2e92c

commit r13-8625-gcc39bd532d4de1ba0b2785246fb6fdd63ec2e92c
Author: Jakub Jelinek 
Date:   Wed Apr 3 10:02:35 2024 +0200

libquadmath: Don't assume the storage for __float128 arguments is aligned 
[PR114533]

With the 
register_printf_type/register_printf_modifier/register_printf_specifier
APIs the C library is just told the size of the argument and is provided 
with
a callback to fetch the argument from va_list using va_arg into C library 
provided
memory.  The C library isn't told what alignment requirement it has, but we 
were
using direct load of a __float128 value from that memory which assumes
__alignof (__float128) alignment.

The following patch fixes that by using memcpy instead.

I haven't been able to reproduce an actual crash, tried
 #include 
 #include 
 #include 

int main ()
{
  __float128 r;
  int prec = 20;
  int width = 46;
  char buf[128];

  r = 2.0q;
  r = sqrtq (r);
  int n = quadmath_snprintf (buf, sizeof buf, "%+-#*.20Qe", width, r);
  if ((size_t) n < sizeof buf)
printf ("%s\n", buf);
/* Prints: +1.41421356237309504880e+00 */
  quadmath_snprintf (buf, sizeof buf, "%Qa", r);
  if ((size_t) n < sizeof buf)
printf ("%s\n", buf);
/* Prints: 0x1.6a09e667f3bcc908b2fb1366ea96p+0 */
  n = quadmath_snprintf (NULL, 0, "%+-#46.*Qe", prec, r);
  if (n > -1)
{
  char *str = malloc (n + 1);
  if (str)
{
  quadmath_snprintf (str, n + 1, "%+-#46.*Qe", prec, r);
  printf ("%s\n", str);
  /* Prints: +1.41421356237309504880e+00 */
}
  free (str);
}
  printf ("%+-#*.20Qe\n", width, r);
  printf ("%Qa\n", r);
  printf ("%+-#46.*Qe\n", prec, r);
  printf ("%d %Qe %d %Qe %d %Qe\n", 1, r, 2, r, 3, r);
  return 0;
}
In any case, I think memcpy for loading from it is right.

2024-04-03  Simon Chopin  
Jakub Jelinek  

PR libquadmath/114533
* printf/printf_fp.c (__quadmath_printf_fp): Use memcpy to copy
__float128 out of args.
* printf/printf_fphex.c (__quadmath_printf_fphex): Likewise.

Signed-off-by: Simon Chopin 
(cherry picked from commit 8455d6f6cd43b7b143ab9ee19437452fceba9cc9)

Diff:
---
 libquadmath/printf/printf_fp.c| 2 +-
 libquadmath/printf/printf_fphex.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/libquadmath/printf/printf_fp.c b/libquadmath/printf/printf_fp.c
index 8effcee88fa..9968aa5307c 100644
--- a/libquadmath/printf/printf_fp.c
+++ b/libquadmath/printf/printf_fp.c
@@ -363,7 +363,7 @@ __quadmath_printf_fp (struct __quadmath_printf_file *fp,
 
   /* Fetch the argument value. */
 {
-  fpnum = **(const __float128 **) args[0];
+  memcpy (, *(const void *const *) args[0], sizeof (fpnum));
 
   /* Check for special values: not a number or infinity.  */
   if (isnanq (fpnum))
diff --git a/libquadmath/printf/printf_fphex.c 
b/libquadmath/printf/printf_fphex.c
index a40a6b00945..ddb413563c6 100644
--- a/libquadmath/printf/printf_fphex.c
+++ b/libquadmath/printf/printf_fphex.c
@@ -163,7 +163,8 @@ __quadmath_printf_fphex (struct __quadmath_printf_file *fp,
 
   /* Fetch the argument value. */
 {
-  fpnum.value = **(const __float128 **) args[0];
+  memcpy (, *(const void *const *) args[0],
+ sizeof (fpnum.value));
 
   /* Check for special values: not a number or infinity.  */
   if (isnanq (fpnum.value))


[gcc r13-8624] expr: Fix up emit_push_insn [PR114552]

2024-04-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:ba6fd407891fd83648ad803c85b607dc09e23be4

commit r13-8624-gba6fd407891fd83648ad803c85b607dc09e23be4
Author: Jakub Jelinek 
Date:   Wed Apr 3 09:59:45 2024 +0200

expr: Fix up emit_push_insn [PR114552]

r13-990 added optimizations in multiple spots to optimize during
expansion storing of constant initializers into targets.
In the load_register_parameters and expand_expr_real_1 cases,
it checks it has a tree as the source and so knows we are reading
that whole decl's value, so the code is fine as is, but in the
emit_push_insn case it checks for a MEM from which something
is pushed and checks for SYMBOL_REF as the MEM's address, but
still assumes the whole object is copied, which as the following
testcase shows might not always be the case.  In the testcase,
k is 6 bytes, then 2 bytes of padding, then another 4 bytes,
while the emit_push_insn wants to store just the 6 bytes.

The following patch simply verifies it is the whole initializer
that is being stored, I think that is best thing to do so late
in GCC 14 cycle as well for backporting.

For GCC 15, perhaps the code could stop requiring it must be at offset zero,
nor that the size is equal, but could use
get_symbol_constant_value/fold_ctor_reference gimple-fold APIs to actually
extract just part of the initializer if we e.g. push just some subset
(of course, still verify that it is a subset).  For sizes which are power
of two bytes and we have some integer modes, we could use as type for
fold_ctor_reference corresponding integral types, otherwise dunno, punt
or use some structure (e.g. try to find one in the initializer?), whatever.
But even in the other spots it could perhaps handle loading of
COMPONENT_REFs or MEM_REFs from the .rodata vars.

2024-04-03  Jakub Jelinek  

PR middle-end/114552
* expr.cc (emit_push_insn): Only use store_constructor for
immediate_const_ctor_p if int_expr_size matches size.

* gcc.c-torture/execute/pr114552.c: New test.

(cherry picked from commit 03039744f368a24a452e4ea8d946e9c2cedaf1aa)

Diff:
---
 gcc/expr.cc|  9 ++---
 gcc/testsuite/gcc.c-torture/execute/pr114552.c | 24 
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/gcc/expr.cc b/gcc/expr.cc
index f8f5cc5a6ca..5dac06fa94b 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -5084,6 +5084,7 @@ emit_push_insn (rtx x, machine_mode mode, tree type, rtx 
size,
  /* If source is a constant VAR_DECL with a simple constructor,
  store the constructor to the stack instead of moving it.  */
  const_tree decl;
+ HOST_WIDE_INT sz;
  if (partial == 0
  && MEM_P (xinner)
  && SYMBOL_REF_P (XEXP (xinner, 0))
@@ -5091,9 +5092,11 @@ emit_push_insn (rtx x, machine_mode mode, tree type, rtx 
size,
  && VAR_P (decl)
  && TREE_READONLY (decl)
  && !TREE_SIDE_EFFECTS (decl)
- && immediate_const_ctor_p (DECL_INITIAL (decl), 2))
-   store_constructor (DECL_INITIAL (decl), target, 0,
-  int_expr_size (DECL_INITIAL (decl)), false);
+ && immediate_const_ctor_p (DECL_INITIAL (decl), 2)
+ && (sz = int_expr_size (DECL_INITIAL (decl))) > 0
+ && CONST_INT_P (size)
+ && INTVAL (size) == sz)
+   store_constructor (DECL_INITIAL (decl), target, 0, sz, false);
  else
emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr114552.c 
b/gcc/testsuite/gcc.c-torture/execute/pr114552.c
new file mode 100644
index 000..22cb4ee351f
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr114552.c
@@ -0,0 +1,24 @@
+/* PR middle-end/114552 */
+
+struct __attribute__((packed)) S { short b; int c; };
+struct T { struct S b; int e; };
+static const struct T k = { { 1, 0 }, 0 };
+
+__attribute__((noinline)) void
+foo (void)
+{
+  asm volatile ("" : : : "memory");
+}
+
+__attribute__((noinline)) void
+bar (struct S n)
+{
+  foo ();
+}
+
+int
+main ()
+{
+  bar (k.b);
+  return 0;
+}


[gcc r13-8623] Fix up postboot dependencies [PR106472]

2024-04-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:cb277dea557aaa25fdced201f7c45c753c709dfa

commit r13-8623-gcb277dea557aaa25fdced201f7c45c753c709dfa
Author: Jakub Jelinek 
Date:   Tue Apr 2 13:40:27 2024 +0200

Fix up postboot dependencies [PR106472]

On Wed, Mar 13, 2024 at 10:13:37AM +0100, Jakub Jelinek wrote:
> While the first Makefile.tpl hunk looks obviously ok, the others look
> completely wrong to me.
> There is nothing special about libgo vs. libbacktrace/libatomic
> compared to any other target library which is not bootstrapped vs. any
> of its dependencies which are in the bootstrapped set.
> So, Makefile.tpl shouldn't hardcode such dependencies.

Here is my version of the fix.
The dependencies in the toplevel Makefile simply didn't take into account
that some target modules could be in a bootstrapped build built in some
configurations as bootstrap modules (typically as dependencies of other
target bootstrap modules), while in other configurations just as
dependencies of non-bootstrap target modules and so not built during the
bootstrap, but after it.
Makefile.tpl arranges for those postboot target module -> target module
dependencies to be emitted only inside of an @unless gcc-bootstrap block,
while for @if gcc-bootstrap it just emits
configure-target-whatever: stage_last
dependencies which ensure those postbootstrap target modules are only built
after everything that is bootstrapped has been.

Now, the libbacktrace/libatomic target modules have bootstrap=true
target_modules = { module= libbacktrace; bootstrap=true; };
target_modules = { module= libatomic; bootstrap=true; lib_path=.libs; };
because those modules are dependencies of libphobos target module, so
when d is included among bootstrapped languages, those are all bootstrapped
and everything works correctly.
While if d is not included, libphobos target module is disabled,
libbacktrace/libatomic target modules aren't bootstrapped, nothing during
bootstrap needs them, but post bootstrap libgo target module depends on
the libatomic and libbacktrace target modules, libgfortran target module
depends on the libbacktrace target module and libgm2 target module depends
on the libatomic target module, but those dependencies were emitted only
@unless gcc-bootstrap.  There is a similar theoretical problem for zlib
target module if GCJ would be ressurected, libphobos as bootstrap target
module depends on the zlib target module, but if d is not configured,
fastjar also depends on it.

The following patch arranges for the @if gcc-bootstrap case to emit also
target module -> target module dependencies, but conditionally on the
on dependency not being bootstrapped.

In the generated Makefile.in you can see what the Makefile.tpl change
produces and that it just adds extra dependencies which weren't there
before in the @if gcc-bootstrap case.

I've bootstrapped without this patch with
../configure --enable-languages=c,c++,go; make
on x86_64-linux (note, make -j2 or higher usually worked) which failed
as described in the PR, then with this patch with the same command which
built fine and the Makefile difference between the two builds being
diff -up obj40{a,b}/Makefile
--- obj40a/Makefile 2024-03-31 00:35:22.243791499 +0100
+++ obj40b/Makefile 2024-03-31 22:40:38.143299144 +0200
@@ -29376,6 +29376,14 @@ configure-bison: stage_last
 configure-flex: stage_last
 configure-m4: stage_last

+configure-target-fastjar: maybe-configure-target-zlib
+all-target-fastjar: maybe-all-target-zlib
+all-target-libgo: maybe-all-target-libbacktrace
+all-target-libgo: maybe-all-target-libatomic
+all-target-libgm2: maybe-all-target-libatomic
+configure-target-libgfortran: maybe-all-target-libbacktrace
+configure-target-libgo: maybe-all-target-libbacktrace
+

 # Dependencies for target modules on other target modules are
 # described by lang_env_dependencies; the defaults apply to anything

which I believe are exactly the extra dependencies we want.
Plus I've done normal x86_64-linux and i686-linux bootstraps/regtests
which in my case include 
--enable-languages=default,ada,obj-c++,lto,go,d,rust,m2
for x86_64 and the same except ada for i686; those with my usual make -j32.
The Makefile difference in those builds vs. unpatched case
is just an extra empty line.

2024-04-02  Jakub Jelinek  

PR bootstrap/106472
* Makefile.tpl (make-postboot-target-dep): New lambda.
Use it to add --enable-bootstrap dependencies of target modules
on other target modules if the latter aren't bootstrapped.
* Makefile.in: Regenerate.

(cherry picked from commit 9a5e4aade2b847c5262577a1490ce6f3df9a9841)

Diff:
---
 Makefile.in  | 30 

[gcc r14-10057] Revert "RISC-V: Support highpart register overlap for widen vx/vf instructions"

2024-04-20 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:ef2392236ec629351496d7f299d6a0956080e4d9

commit r14-10057-gef2392236ec629351496d7f299d6a0956080e4d9
Author: Pan Li 
Date:   Sun Apr 21 09:37:00 2024 +0800

Revert "RISC-V: Support highpart register overlap for widen vx/vf 
instructions"

This reverts commit a23415d7572774701d7ec04664390260ab9a3f63.

Diff:
---
 gcc/config/riscv/vector.md |  65 ---
 .../gcc.target/riscv/rvv/base/pr112431-22.c| 188 -
 .../gcc.target/riscv/rvv/base/pr112431-23.c| 119 -
 .../gcc.target/riscv/rvv/base/pr112431-24.c|  86 --
 .../gcc.target/riscv/rvv/base/pr112431-25.c| 104 
 .../gcc.target/riscv/rvv/base/pr112431-26.c|  68 
 .../gcc.target/riscv/rvv/base/pr112431-27.c|  51 --
 7 files changed, 31 insertions(+), 650 deletions(-)

diff --git a/gcc/config/riscv/vector.md b/gcc/config/riscv/vector.md
index 2a6ab979588..f620f13682c 100644
--- a/gcc/config/riscv/vector.md
+++ b/gcc/config/riscv/vector.md
@@ -3818,28 +3818,27 @@
(set_attr "mode" "")])
 
 (define_insn 
"@pred_dual_widen__scalar"
-  [(set (match_operand:VWEXTI 0 "register_operand"   "=vr,   
vr,   vr,   vr,  vr,vr, ?, ?")
+  [(set (match_operand:VWEXTI 0 "register_operand"  "=,")
(if_then_else:VWEXTI
  (unspec:
-   [(match_operand: 1 "vector_mask_operand"   
"vmWc1,vmWc1,vmWc1,vmWc1,vmWc1,vmWc1,vmWc1,vmWc1")
-(match_operand 5 "vector_length_operand"  "   rK,   
rK,   rK,   rK,   rK,   rK,   rK,   rK")
-(match_operand 6 "const_int_operand"  "i,
i,i,i,i,i,i,i")
-(match_operand 7 "const_int_operand"  "i,
i,i,i,i,i,i,i")
-(match_operand 8 "const_int_operand"  "i,
i,i,i,i,i,i,i")
+   [(match_operand: 1 "vector_mask_operand"   
"vmWc1,vmWc1")
+(match_operand 5 "vector_length_operand"  "   rK,   
rK")
+(match_operand 6 "const_int_operand"  "i,
i")
+(match_operand 7 "const_int_operand"  "i,
i")
+(match_operand 8 "const_int_operand"  "i,
i")
 (reg:SI VL_REGNUM)
 (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE)
  (any_widen_binop:VWEXTI
(any_extend:VWEXTI
- (match_operand: 3 "register_operand" "  W21,  
W21,  W42,  W42,  W84,  W84,   vr,   vr"))
+ (match_operand: 3 "register_operand" "   vr,   
vr"))
(any_extend:VWEXTI
  (vec_duplicate:
-   (match_operand: 4 "reg_or_0_operand"   "   rJ,   
rJ,   rJ,   rJ,   rJ,   rJ,   rJ,   rJ"
- (match_operand:VWEXTI 2 "vector_merge_operand"   "   vu,
0,   vu,0,   vu,0,   vu,0")))]
+   (match_operand: 4 "reg_or_0_operand"   "   rJ,   
rJ"
+ (match_operand:VWEXTI 2 "vector_merge_operand"   "   vu,
0")))]
   "TARGET_VECTOR"
   "vw.vx\t%0,%3,%z4%p1"
   [(set_attr "type" "vi")
-   (set_attr "mode" "")
-   (set_attr "group_overlap" "W21,W21,W42,W42,W84,W84,none,none")])
+   (set_attr "mode" "")])
 
 (define_insn "@pred_single_widen_sub"
   [(set (match_operand:VWEXTI 0 "register_operand"  "=,")
@@ -3928,28 +3927,27 @@
(set_attr "mode" "")])
 
 (define_insn "@pred_widen_mulsu_scalar"
-  [(set (match_operand:VWEXTI 0 "register_operand"   "=vr,   
vr,   vr,   vr,  vr,vr, ?, ?")
+  [(set (match_operand:VWEXTI 0 "register_operand"  "=,")
(if_then_else:VWEXTI
  (unspec:
-   [(match_operand: 1 "vector_mask_operand"   
"vmWc1,vmWc1,vmWc1,vmWc1,vmWc1,vmWc1,vmWc1,vmWc1")
-(match_operand 5 "vector_length_operand"  "   rK,   
rK,   rK,   rK,   rK,   rK,   rK,   rK")
-(match_operand 6 "const_int_operand"  "i,
i,i,i,i,i,i,i")
-(match_operand 7 "const_int_operand"  "i,
i,i,i,i,i,i,i")
-(match_operand 8 "const_int_operand"  "i,
i,i,i,i,i,i,i")
+   [(match_operand: 1 "vector_mask_operand"   
"vmWc1,vmWc1")
+(match_operand 5 "vector_length_operand"  "   rK,   
rK")
+(match_operand 6 "const_int_operand"  "i,
i")
+(match_operand 7 "const_int_operand"  "i,
i")
+(match_operand 8 "const_int_operand"  "i,
i")
 (reg:SI VL_REGNUM)
 (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE)
  (mult:VWEXTI
(sign_extend:VWEXTI
- (match_operand: 3 

[gcc r14-10056] RISC-V: Add xfail test case for incorrect overlap on v0

2024-04-20 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:d37b34fe82e6e19e80ec9c46400f63fa90ba5255

commit r14-10056-gd37b34fe82e6e19e80ec9c46400f63fa90ba5255
Author: Pan Li 
Date:   Sat Apr 20 22:43:13 2024 +0800

RISC-V: Add xfail test case for incorrect overlap on v0

We reverted below patch for register group overlap, add the related
insn test and mark it as xfail.  And we will remove the xfail
after we support the register overlap in GCC-15.

018ba3ac952 RISC-V: Fix overlap group incorrect overlap on v0

The below test suites are passed.
* The rv64gcv fully regression test.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/pr112431-34.c: New test.

Signed-off-by: Pan Li 

Diff:
---
 .../gcc.target/riscv/rvv/base/pr112431-34.c| 101 +
 1 file changed, 101 insertions(+)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr112431-34.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/pr112431-34.c
new file mode 100644
index 000..286185aa01e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr112431-34.c
@@ -0,0 +1,101 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O3" } */
+
+#include "riscv_vector.h"
+
+size_t __attribute__ ((noinline))
+sumation (size_t sum0, size_t sum1, size_t sum2, size_t sum3, size_t sum4,
+ size_t sum5, size_t sum6, size_t sum7, size_t sum8, size_t sum9,
+ size_t sum10, size_t sum11, size_t sum12, size_t sum13, size_t sum14,
+ size_t sum15)
+{
+  return sum0 + sum1 + sum2 + sum3 + sum4 + sum5 + sum6 + sum7 + sum8 + sum9
++ sum10 + sum11 + sum12 + sum13 + sum14 + sum15;
+}
+
+size_t
+foo (char const *buf, size_t len)
+{
+  size_t sum = 0;
+  size_t vl = __riscv_vsetvlmax_e8m8 ();
+  size_t step = vl * 4;
+  const char *it = buf, *end = buf + len;
+  for (; it + step <= end;)
+{
+  vuint8m1_t v0 = __riscv_vle8_v_u8m1 ((void *) it, vl);
+  it += vl;
+  vuint8m1_t v1 = __riscv_vle8_v_u8m1 ((void *) it, vl);
+  it += vl;
+  vuint8m1_t v2 = __riscv_vle8_v_u8m1 ((void *) it, vl);
+  it += vl;
+  vuint8m1_t v3 = __riscv_vle8_v_u8m1 ((void *) it, vl);
+  it += vl;
+  vuint8m1_t v4 = __riscv_vle8_v_u8m1 ((void *) it, vl);
+  it += vl;
+  vuint8m1_t v5 = __riscv_vle8_v_u8m1 ((void *) it, vl);
+  it += vl;
+  vuint8m1_t v6 = __riscv_vle8_v_u8m1 ((void *) it, vl);
+  it += vl;
+  vuint8m1_t v7 = __riscv_vle8_v_u8m1 ((void *) it, vl);
+  it += vl;
+  vuint8m1_t v8 = __riscv_vle8_v_u8m1 ((void *) it, vl);
+  it += vl;
+  vuint8m1_t v9 = __riscv_vle8_v_u8m1 ((void *) it, vl);
+  it += vl;
+  vuint8m1_t v10 = __riscv_vle8_v_u8m1 ((void *) it, vl);
+  it += vl;
+  vuint8m1_t v11 = __riscv_vle8_v_u8m1 ((void *) it, vl);
+  it += vl;
+  vuint8m1_t v12 = __riscv_vle8_v_u8m1 ((void *) it, vl);
+  it += vl;
+  vuint8m1_t v13 = __riscv_vle8_v_u8m1 ((void *) it, vl);
+  it += vl;
+  vuint8m1_t v14 = __riscv_vle8_v_u8m1 ((void *) it, vl);
+  it += vl;
+  vuint8m1_t v15 = __riscv_vle8_v_u8m1 ((void *) it, vl);
+  it += vl;
+  
+  asm volatile("nop" ::: "memory");
+  vint16m2_t vw0 = __riscv_vluxei8_v_i16m2 ((void *) it, v0, vl);
+  vint16m2_t vw1 = __riscv_vluxei8_v_i16m2 ((void *) it, v1, vl);
+  vint16m2_t vw2 = __riscv_vluxei8_v_i16m2 ((void *) it, v2, vl);
+  vint16m2_t vw3 = __riscv_vluxei8_v_i16m2 ((void *) it, v3, vl);
+  vint16m2_t vw4 = __riscv_vluxei8_v_i16m2 ((void *) it, v4, vl);
+  vint16m2_t vw5 = __riscv_vluxei8_v_i16m2 ((void *) it, v5, vl);
+  vint16m2_t vw6 = __riscv_vluxei8_v_i16m2 ((void *) it, v6, vl);
+  vint16m2_t vw7 = __riscv_vluxei8_v_i16m2 ((void *) it, v7, vl);
+  vint16m2_t vw8 = __riscv_vluxei8_v_i16m2 ((void *) it, v8, vl);
+  vint16m2_t vw9 = __riscv_vluxei8_v_i16m2 ((void *) it, v9, vl);
+  vint16m2_t vw10 = __riscv_vluxei8_v_i16m2 ((void *) it, v10, vl);
+  vint16m2_t vw11 = __riscv_vluxei8_v_i16m2 ((void *) it, v11, vl);
+  vint16m2_t vw12 = __riscv_vluxei8_v_i16m2 ((void *) it, v12, vl);
+  vint16m2_t vw13 = __riscv_vluxei8_v_i16m2 ((void *) it, v13, vl);
+  vint16m2_t vw14 = __riscv_vluxei8_v_i16m2 ((void *) it, v14, vl);
+  vbool8_t mask = *(vbool8_t*)it;
+  vint16m2_t vw15 = __riscv_vluxei8_v_i16m2_m (mask, (void *) it, v15, vl);
+
+  asm volatile("nop" ::: "memory");
+  size_t sum0 = __riscv_vmv_x_s_i16m2_i16 (vw0);
+  size_t sum1 = __riscv_vmv_x_s_i16m2_i16 (vw1);
+  size_t sum2 = __riscv_vmv_x_s_i16m2_i16 (vw2);
+  size_t sum3 = __riscv_vmv_x_s_i16m2_i16 (vw3);
+  size_t sum4 = __riscv_vmv_x_s_i16m2_i16 (vw4);
+  size_t sum5 = __riscv_vmv_x_s_i16m2_i16 (vw5);
+  size_t sum6 = __riscv_vmv_x_s_i16m2_i16 (vw6);
+  size_t sum7 = __riscv_vmv_x_s_i16m2_i16 (vw7);
+  size_t sum8 = __riscv_vmv_x_s_i16m2_i16 (vw8);
+  size_t sum9 = __riscv_vmv_x_s_i16m2_i16 (vw9);
+  size_t sum10 = 

[gcc r12-10366] Testsuite, Darwin: skip PIE test

2024-04-20 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:a6fa5387a3417ee46a97886d1065eb102363

commit r12-10366-ga6fa5387a3417ee46a97886d1065eb102363
Author: Francois-Xavier Coudert 
Date:   Mon Oct 30 12:41:17 2023 +0100

Testsuite, Darwin: skip PIE test

gcc/testsuite/ChangeLog:

* gcc.dg/pie-2.c: Skip test on darwin.

(cherry picked from commit a0c557690c8d5327deda6e21f8d1deca8451a4cb)

Diff:
---
 gcc/testsuite/gcc.dg/pie-2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/gcc.dg/pie-2.c b/gcc/testsuite/gcc.dg/pie-2.c
index 1838745a11a..0a1cc27a503 100644
--- a/gcc/testsuite/gcc.dg/pie-2.c
+++ b/gcc/testsuite/gcc.dg/pie-2.c
@@ -2,6 +2,7 @@
 /* { dg-options "-fPIE" } */
 /* { dg-require-effective-target pie } */
 /* { dg-skip-if "__PIC__ is always 1 for MIPS" { mips*-*-* } } */
+/* { dg-skip-if "__PIE__ is often not defined on darwin" { *-*-darwin* } } */
 
 #if __PIC__ != 2
 # error __PIC__ is not 2!


[gcc r12-10365] testsuite, Darwin: Skip g++.dg/debug/dwarf2/pr85550.C

2024-04-20 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:65f76ed01aca192ccfc13764456892760f9ab1fd

commit r12-10365-g65f76ed01aca192ccfc13764456892760f9ab1fd
Author: Iain Sandoe 
Date:   Sun Oct 1 20:38:44 2023 +0100

testsuite, Darwin: Skip g++.dg/debug/dwarf2/pr85550.C

There are two problems here; first that the emitted asm for
-fdebug-types-section is ELF-specfic leading to assembler errors for
Mach-O.  If we fix this, we get a secondary fail since the debug linker
does not recognise DW_FORM_ref_sig8.  Disable ths test until we get
DWARF-5 support in the external Darwin toolchain components.

gcc/testsuite/ChangeLog:

* g++.dg/debug/dwarf2/pr85550.C: Skip for Darwin.

Signed-off-by: Iain Sandoe 
(cherry picked from commit 76547f4c97b1c0744487d624c5e2e5a15d0370a9)

Diff:
---
 gcc/testsuite/g++.dg/debug/dwarf2/pr85550.C | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/pr85550.C 
b/gcc/testsuite/g++.dg/debug/dwarf2/pr85550.C
index 35b0f56e959..c95f75255d4 100644
--- a/gcc/testsuite/g++.dg/debug/dwarf2/pr85550.C
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/pr85550.C
@@ -2,6 +2,7 @@
 // { dg-do link }
 // { dg-options "-O2 -g -fdebug-types-section" }
 // { dg-skip-if "AIX DWARF5" { powerpc-ibm-aix* } }
+// { dg-skip-if "No debug linker support" { *-*-darwin* } }
 
 struct A {
   int bar () const { return 0; }


[gcc r12-10364] testsuite: adjust for darwin linker warning

2024-04-20 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:69e2b9620d223c98c0457b26d99964434c69ef11

commit r12-10364-g69e2b9620d223c98c0457b26d99964434c69ef11
Author: Francois-Xavier Coudert 
Date:   Fri Sep 8 21:55:56 2023 +0200

testsuite: adjust for darwin linker warning

On recent macOS versions, no_pie is deprecated and the linker complains
about it: "-no_pie is deprecated when targeting new OS versions"

gcc/testsuite/ChangeLog:

* gcc.dg/darwin-segaddr.c: Adjust for darwin linker warning.
* gcc.dg/pie-7.c: Likewise.

(cherry picked from commit d9926c0d974646dc6024d5a881fe1bee2f499139)

Diff:
---
 gcc/testsuite/gcc.dg/darwin-segaddr.c | 1 +
 gcc/testsuite/gcc.dg/pie-7.c  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/darwin-segaddr.c 
b/gcc/testsuite/gcc.dg/darwin-segaddr.c
index 526db77bd9c..77112ddb484 100644
--- a/gcc/testsuite/gcc.dg/darwin-segaddr.c
+++ b/gcc/testsuite/gcc.dg/darwin-segaddr.c
@@ -2,6 +2,7 @@
 /* { dg-do run { target *-*-darwin* } } */
 /* { dg-options "-O0 -segaddr __TEST 0x20 -fno-pie" { target { *-*-darwin* 
&& { ! lp64 } } } } */
 /* { dg-options "-O0 -segaddr __TEST 0x11000 -fno-pie" { target { 
*-*-darwin* && lp64 } } } */
+/* { dg-prune-output "-no_pie is deprecated when targeting new OS versions" } 
*/
 
 extern void abort ();
 
diff --git a/gcc/testsuite/gcc.dg/pie-7.c b/gcc/testsuite/gcc.dg/pie-7.c
index e118a98bafd..3879a6cc120 100644
--- a/gcc/testsuite/gcc.dg/pie-7.c
+++ b/gcc/testsuite/gcc.dg/pie-7.c
@@ -1,5 +1,6 @@
 /* { dg-do run { target pie } } */
 /* { dg-options "-fno-pie -no-pie" } */
+/* { dg-prune-output "-no_pie is deprecated when targeting new OS versions" } 
*/
 
 int main(void)
 {


[gcc r12-10363] Testsuite, darwin: account for macOS 13 and 14

2024-04-20 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:79f5f989986a32b4c68daf53f9bc5741094af97a

commit r12-10363-g79f5f989986a32b4c68daf53f9bc5741094af97a
Author: Francois-Xavier Coudert 
Date:   Mon Aug 21 00:00:44 2023 +0200

Testsuite, darwin: account for macOS 13 and 14

gcc/testsuite/ChangeLog:

* gcc.dg/darwin-minversion-link.c: Account for macOS 13 and 14.

(cherry picked from commit 6d33602650612c89e7e32201266763b167f62a46)

Diff:
---
 gcc/testsuite/gcc.dg/darwin-minversion-link.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/darwin-minversion-link.c 
b/gcc/testsuite/gcc.dg/darwin-minversion-link.c
index b6ede31c985..a835e9d4648 100644
--- a/gcc/testsuite/gcc.dg/darwin-minversion-link.c
+++ b/gcc/testsuite/gcc.dg/darwin-minversion-link.c
@@ -17,6 +17,8 @@
 /* { dg-additional-options "-mmacosx-version-min=010.015.06 -DCHECK=101506" { 
target *-*-darwin19* } } */
 /* { dg-additional-options "-mmacosx-version-min=011.000.00 -DCHECK=11" { 
target *-*-darwin20* } } */
 /* { dg-additional-options "-mmacosx-version-min=012.000.00 -DCHECK=12" { 
target *-*-darwin21* } } */
+/* { dg-additional-options "-mmacosx-version-min=013.000.00 -DCHECK=13" { 
target *-*-darwin22* } } */
+/* { dg-additional-options "-mmacosx-version-min=014.000.00 -DCHECK=14" { 
target *-*-darwin23* } } */
 
 int
 main ()


[gcc r12-10362] Testsuite: mark IPA test as requiring alias support

2024-04-20 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:3d48cd6623d7b70c8d1e2a0365bb016390409013

commit r12-10362-g3d48cd6623d7b70c8d1e2a0365bb016390409013
Author: Francois-Xavier Coudert 
Date:   Sun Aug 20 14:13:22 2023 +0200

Testsuite: mark IPA test as requiring alias support

This was indicated in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85656
but never committed. Without it, the test fails on darwin.

gcc/testsuite/ChangeLog:
* gcc.dg/ipa/ipa-icf-38.c: Require alias support.

(cherry picked from commit 02393e4b5eabe1c64720b022cb6f819e7b4dc08b)

Diff:
---
 gcc/testsuite/gcc.dg/ipa/ipa-icf-38.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-icf-38.c 
b/gcc/testsuite/gcc.dg/ipa/ipa-icf-38.c
index 452e1b88514..57c5262dd4a 100644
--- a/gcc/testsuite/gcc.dg/ipa/ipa-icf-38.c
+++ b/gcc/testsuite/gcc.dg/ipa/ipa-icf-38.c
@@ -1,4 +1,5 @@
 /* { dg-do link } */
+/* { dg-require-alias "" } */
 /* { dg-options "-O2 -fdump-ipa-icf-optimized -flto -fdump-tree-optimized" } */
 /* { dg-require-effective-target lto } */
 /* { dg-additional-sources "ipa-icf-38a.c" }*/


[gcc r12-10361] Testsuite: fix analyzer tests on Darwin

2024-04-20 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:c2cb625eb141cacd0bee6c6ce5888d673ac38ca4

commit r12-10361-gc2cb625eb141cacd0bee6c6ce5888d673ac38ca4
Author: Francois-Xavier Coudert 
Date:   Sat Aug 19 23:22:06 2023 +0200

Testsuite: fix analyzer tests on Darwin

On macOS, system headers redefine by default some macros (memcpy,
memmove, etc) to checked versions, which defeats the analyzer. We
want to turn this off.
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104042

gcc/testsuite/ChangeLog:

PR analyzer/104042
* gcc.dg/analyzer/analyzer.exp: Pass -D_FORTIFY_SOURCE=0 on Darwin.

(cherry picked from commit ce33bbfcbc7dd3afc6c96fb48a19ed00f0c598ce)

Diff:
---
 gcc/testsuite/gcc.dg/analyzer/analyzer.exp | 8 
 1 file changed, 8 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/analyzer/analyzer.exp 
b/gcc/testsuite/gcc.dg/analyzer/analyzer.exp
index 15d979cd8b5..333e8402443 100644
--- a/gcc/testsuite/gcc.dg/analyzer/analyzer.exp
+++ b/gcc/testsuite/gcc.dg/analyzer/analyzer.exp
@@ -32,6 +32,14 @@ if [info exists DEFAULT_CFLAGS] then {
 # If a testcase doesn't have special options, use these.
 set DEFAULT_CFLAGS "-fanalyzer -Wanalyzer-too-complex 
-fanalyzer-call-summaries"
 
+if { [istarget "*-*-darwin*" ] } {
+  # On macOS, system headers redefine by default some macros (memcpy,
+  # memmove, etc) to checked versions, which defeats the analyzer. We
+  # want to turn this off.
+  # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104042
+  set DEFAULT_CFLAGS "$DEFAULT_CFLAGS -D_FORTIFY_SOURCE=0"
+}
+
 # Initialize `dg'.
 dg-init


[gcc r12-10360] testsuite, Darwin: Allow for undefined symbols in shared test.

2024-04-20 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:edc5acccf94e521c126b4d3b3b49287ceb8cd841

commit r12-10360-gedc5acccf94e521c126b4d3b3b49287ceb8cd841
Author: Iain Sandoe 
Date:   Mon Jan 29 10:09:25 2024 +

testsuite, Darwin: Allow for undefined symbols in shared test.

Darwin's linker defaults to error on undefined (which makes it look as
if we do not support shared, leading to tests being marked incorrectly
as unsupported).

This fixes the issue by allowing the symbols used in the target
supports test to be undefined.

includes commit 0ed6e5b4820e01fa86b48a7b1d62f752ec97ea41

gcc/testsuite/ChangeLog:

* lib/target-supports.exp (check_effective_target_shared):
Allow the external symbols referenced in the test to be undefined.

(cherry picked from commit 639bd5e9b759a6d733fadbd5f956889d965e9368)

Co-authored-by: Francois-Xavier Coudert 

Diff:
---
 gcc/testsuite/lib/target-supports.exp | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index e0076ed8f69..64216dfbdb2 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -1258,13 +1258,20 @@ proc check_effective_target_aarch64_tlsle32 { } {
 # emitted, 0 otherwise.
 
 proc check_effective_target_shared { } {
+# Darwin's linker defaults to error on undefined (which makes it look as
+# if we do not support shared) but we can tell it to allow the symbols used
+# here to be undefined.
+set extra_flags ""
+if { [istarget *-*-darwin\[912\]*] } {
+  set extra_flags "-Wl,-U,_foo,-U,_bar,-U,__Z3foov"
+}
 # Note that M68K has a multilib that supports -fpic but not
 # -fPIC, so we need to check both.  We test with a program that
 # requires GOT references.
 return [check_no_compiler_messages shared executable {
extern int foo (void); extern int bar;
int baz (void) { return foo () + bar; }
-} "-shared -fpic"]
+} "-shared -fpic $extra_flags"]
 }
 
 # Return 1 if -pie, -fpie and -fPIE are supported, 0 otherwise.


[gcc r12-10359] testsuite, jit, Darwin: Handle Mach-O in assembler tests.

2024-04-20 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:b358e73b7d642afa7a2b836283910ef7539dafe2

commit r12-10359-gb358e73b7d642afa7a2b836283910ef7539dafe2
Author: Iain Sandoe 
Date:   Sat Jan 13 13:40:51 2024 +

testsuite, jit, Darwin: Handle Mach-O in assembler tests.

Several of the jit tests check for assembler-specific output
which differs on Mach-O from ELF.

This patch uses the facility to make the scans target-dependent
and adds handling for darwin.

gcc/testsuite/ChangeLog:

* jit.dg/test-setting-alignment.c:  Handle Darwin in
jit-verify-assemble output.

Signed-off-by: Iain Sandoe 
(cherry picked from commit 283e3a974bf08e4fb64d51d2062e1f7ed7482ff4)

Diff:
---
 gcc/testsuite/jit.dg/test-setting-alignment.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/jit.dg/test-setting-alignment.c 
b/gcc/testsuite/jit.dg/test-setting-alignment.c
index 8489df9c6b9..14edc723f61 100644
--- a/gcc/testsuite/jit.dg/test-setting-alignment.c
+++ b/gcc/testsuite/jit.dg/test-setting-alignment.c
@@ -62,5 +62,6 @@ create_code (gcc_jit_context *ctxt, void *user_data)
 }
 
 /* { dg-final { jit-verify-output-file-was-created "" } } */
-/* { dg-final { jit-verify-assembler-output ".comm foo,4,8" } } */
+/* { dg-final { jit-verify-assembler-output ".comm foo,4,8" { target { ! 
*-*-darwin* } } } } */
+/* { dg-final { jit-verify-assembler-output ".comm\\s_foo,4,3" { target 
*-*-darwin* } } } */
 /* { dg-final { jit-verify-assembler-output "movl  -16\\\(%rbp\\\), %eax" 
} } */


[gcc r12-10358] testsuite, jit: Allow for target-specific assembler scans.

2024-04-20 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:e73c4d7a236da0a1a9232861fe32bca0e5304870

commit r12-10358-ge73c4d7a236da0a1a9232861fe32bca0e5304870
Author: Iain Sandoe 
Date:   Sat Jan 13 13:30:08 2024 +

testsuite, jit: Allow for target-specific assembler scans.

If we want to support multiple object formats and to allow for
scan-assembler tests, we need to make it possible to adjust the
tests on a per-target basis.

This adds similar mechamisms to jit-verify-assembler-output
to those used for the general scan-assembler dg directives.

As an aside; it would, perhaps, be possible to integrate this more
with scanasm.exp (which would also give access to function body
scanning) but I did not attempt that for this patch.

After this, we can accept things like:
... { jit-verify-assembler-output ".." { target *-*-darwin* } } }

gcc/testsuite/ChangeLog:

* jit.dg/jit.exp: Accept target clauses in jit-verify-assembler
handling.

Signed-off-by: Iain Sandoe 
(cherry picked from commit e0e3ef18a047d54d63be91d82a55448851353260)

Diff:
---
 gcc/testsuite/jit.dg/jit.exp | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/gcc/testsuite/jit.dg/jit.exp b/gcc/testsuite/jit.dg/jit.exp
index 3568dbb9d63..35d38cec5bc 100644
--- a/gcc/testsuite/jit.dg/jit.exp
+++ b/gcc/testsuite/jit.dg/jit.exp
@@ -871,9 +871,23 @@ proc jit-verify-assembler { args } {
 proc jit-verify-assembler-output { args } {
 verbose "jit-verify-assembler: $args"
 
+if { [llength $args] > 3 } {
+   error "jit-verify-assembler-output: too many arguments"
+   return
+}
+
 set dg-output-text [lindex $args 0]
 verbose "dg-output-text: ${dg-output-text}"
 
+if { [llength $args] >= 2 } {
+   switch [dg-process-target [lindex $args 1]] {
+   "S" { }
+   "N" { return }
+   "F" { setup_xfail "*-*-*" }
+   "P" { }
+   }
+}
+
 upvar 2 name name
 verbose "name: $name"


[gcc r12-10357] testsuite, jit: Handle whitespace in test-link-section-assembler.c.

2024-04-20 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:12e4b9ce523bd60acfb3d5567e493822fcdcf698

commit r12-10357-g12e4b9ce523bd60acfb3d5567e493822fcdcf698
Author: Iain Sandoe 
Date:   Sat Jan 13 12:49:28 2024 +

testsuite, jit: Handle whitespace in test-link-section-assembler.c.

Darwin has a different .section directive that has more fields and
uses different whitespace.  Amend the whitespace in the scan-asm to
be more flexible.

gcc/testsuite/ChangeLog:

* jit.dg/test-link-section-assembler.c: Accept any whitespace
between the .section directive and its arguments.

Signed-off-by: Iain Sandoe 
(cherry picked from commit 2b0abfd3f8dbe3e9af79bb6bdc06d727d36f1946)

Diff:
---
 gcc/testsuite/jit.dg/test-link-section-assembler.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/jit.dg/test-link-section-assembler.c 
b/gcc/testsuite/jit.dg/test-link-section-assembler.c
index a90b00e9a82..a78e9fd26ef 100644
--- a/gcc/testsuite/jit.dg/test-link-section-assembler.c
+++ b/gcc/testsuite/jit.dg/test-link-section-assembler.c
@@ -34,4 +34,4 @@ create_code (gcc_jit_context *ctxt, void *user_data)
 }
 
 /* { dg-final { jit-verify-output-file-was-created "" } } */
-/* { dg-final { jit-verify-assembler-output ".section  .my_section" } } */
+/* { dg-final { jit-verify-assembler-output ".section\\s.my_section" } } */


[gcc r12-10356] Objective-C/C++: Ensure sufficient setup for the preprocessor.

2024-04-20 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:633e24e1c7846cdd6796074f42254afdf0f44ef3

commit r12-10356-g633e24e1c7846cdd6796074f42254afdf0f44ef3
Author: Iain Sandoe 
Date:   Tue Jan 9 17:31:41 2024 +

Objective-C/C++: Ensure sufficient setup for the preprocessor.

The tokenizer makes use of functions that determine if identifiers
are interface or class names, and those functions need a hash map
to be set up.

This ensures that these are initialized before pre-process-only
jobs are run.

gcc/objc/ChangeLog:

* objc-act.cc (objc_init): Initialize interface and class
name hash maps before the preprocessor uses them.

Signed-off-by: Iain Sandoe 
(cherry picked from commit 60f58d0630805e8dce79f5489658fd83e42fa8f1)

Diff:
---
 gcc/objc/objc-act.cc | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/objc/objc-act.cc b/gcc/objc/objc-act.cc
index 252274c8f5d..4820c5dbac3 100644
--- a/gcc/objc/objc-act.cc
+++ b/gcc/objc/objc-act.cc
@@ -347,6 +347,11 @@ bool
 objc_init (void)
 {
   bool ok;
+
+  /* Set up stuff used by the preprocessor as well as FE parser.  */
+  interface_hash_init ();
+  hash_init ();
+
 #ifdef OBJCPLUS
   if (cxx_init () == false)
 #else
@@ -376,8 +381,6 @@ objc_init (void)
 
   /* Set up stuff used by FE parser and all runtimes.  */
   errbuf = XNEWVEC (char, 1024 * 10);
-  interface_hash_init ();
-  hash_init ();
   objc_encoding_init ();
   /* ... and then check flags and set-up for the selected runtime ... */
   if (flag_next_runtime && flag_objc_abi >= 2)


[gcc r14-10054] Revert "RISC-V: Fix overlap group incorrect overlap on v0"

2024-04-20 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:3afcb04bd7d444b4c6547ad98668c2a6a7f37a21

commit r14-10054-g3afcb04bd7d444b4c6547ad98668c2a6a7f37a21
Author: Pan Li 
Date:   Sat Apr 20 22:37:56 2024 +0800

Revert "RISC-V: Fix overlap group incorrect overlap on v0"

This reverts commit 018ba3ac952bed4ae01344c060360f13f7cc084a.

Diff:
---
 gcc/config/riscv/vector.md | 268 ++---
 .../gcc.target/riscv/rvv/base/pr112431-34.c| 101 
 2 files changed, 134 insertions(+), 235 deletions(-)

diff --git a/gcc/config/riscv/vector.md b/gcc/config/riscv/vector.md
index 8a727e2ea41..2a6ab979588 100644
--- a/gcc/config/riscv/vector.md
+++ b/gcc/config/riscv/vector.md
@@ -2254,70 +2254,70 @@
 
 ;; DEST eew is greater than SOURCE eew.
 (define_insn "@pred_indexed_load_x2_greater_eew"
-  [(set (match_operand:VEEWEXT2 0 "register_operand"   "=vd, 
vr, vd, vr, vd, vr, vd, vr, vd, vr, vd, vr, ?, ?")
+  [(set (match_operand:VEEWEXT2 0 "register_operand" "=vr, 
  vr,   vr,   vr,   vr,   vr, ?, ?")
(if_then_else:VEEWEXT2
  (unspec:
-   [(match_operand: 1 "vector_mask_operand"   " 
vm,Wc1, vm,Wc1, vm,Wc1, vm,Wc1, vm,Wc1, vm,Wc1,vmWc1,vmWc1")
-(match_operand 5 "vector_length_operand"  " rK, 
rK, rK, rK, rK, rK, rK, rK, rK, rK, rK, rK,   rK,   rK")
-(match_operand 6 "const_int_operand"  "i,  i,  
i,  i,  i,  i,  i,  i,  i,  i,  i,  i,i,i")
-(match_operand 7 "const_int_operand"  "i,  i,  
i,  i,  i,  i,  i,  i,  i,  i,  i,  i,i,i")
-(match_operand 8 "const_int_operand"  "i,  i,  
i,  i,  i,  i,  i,  i,  i,  i,  i,  i,i,i")
+   [(match_operand: 1 "vector_mask_operand"   
"vmWc1,vmWc1,vmWc1,vmWc1,vmWc1,vmWc1,vmWc1,vmWc1")
+(match_operand 5 "vector_length_operand"  "   rK,  
 rK,   rK,   rK,   rK,   rK,   rK,   rK")
+(match_operand 6 "const_int_operand"  "i,  
  i,i,i,i,i,i,i")
+(match_operand 7 "const_int_operand"  "i,  
  i,i,i,i,i,i,i")
+(match_operand 8 "const_int_operand"  "i,  
  i,i,i,i,i,i,i")
 (reg:SI VL_REGNUM)
 (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE)
  (unspec:VEEWEXT2
-   [(match_operand 3 "pmode_reg_or_0_operand" " rJ, 
rJ, rJ, rJ, rJ, rJ, rJ, rJ, rJ, rJ, rJ, rJ,   rJ,   rJ")
+   [(match_operand 3 "pmode_reg_or_0_operand" "   rJ,  
 rJ,   rJ,   rJ,   rJ,   rJ,   rJ,   rJ")
 (mem:BLK (scratch))
-(match_operand: 4 "register_operand" 
"W21,W21,W21,W21,W42,W42,W42,W42,W84,W84,W84,W84,   vr,   vr")] ORDER)
- (match_operand:VEEWEXT2 2 "vector_merge_operand" " vu, 
vu,  0,  0, vu, vu,  0,  0, vu, vu,  0,  0,   vu,0")))]
+(match_operand: 4 "register_operand" "  W21,  
W21,  W42,  W42,  W84,  W84,   vr,   vr")] ORDER)
+ (match_operand:VEEWEXT2 2 "vector_merge_operand" "   vu,  
  0,   vu,0,   vu,0,   vu,0")))]
   "TARGET_VECTOR"
   "vlxei.v\t%0,(%z3),%4%p1"
   [(set_attr "type" "vldx")
(set_attr "mode" "")
-   (set_attr "group_overlap" 
"W21,W21,W21,W21,W42,W42,W42,W42,W84,W84,W84,W84,none,none")])
+   (set_attr "group_overlap" "W21,W21,W42,W42,W84,W84,none,none")])
 
 (define_insn "@pred_indexed_load_x4_greater_eew"
-  [(set (match_operand:VEEWEXT4 0 "register_operand"   "=vd, 
vr, vd, vr, vd, vr, vd, vr, ?, ?")
+  [(set (match_operand:VEEWEXT4 0 "register_operand""=vr,  
  vr,   vr,   vr, ?, ?")
(if_then_else:VEEWEXT4
  (unspec:
-   [(match_operand: 1 "vector_mask_operand"   " 
vm,Wc1, vm,Wc1, vm,Wc1, vm,Wc1,vmWc1,vmWc1")
-(match_operand 5 "vector_length_operand"  " rK, 
rK, rK, rK, rK, rK, rK, rK,   rK,   rK")
-(match_operand 6 "const_int_operand"  "  i,  
i,  i,  i,  i,  i,  i,  i,i,i")
-(match_operand 7 "const_int_operand"  "  i,  
i,  i,  i,  i,  i,  i,  i,i,i")
-(match_operand 8 "const_int_operand"  "  i,  
i,  i,  i,  i,  i,  i,  i,i,i")
+   [(match_operand: 1 "vector_mask_operand"   
"vmWc1,vmWc1,vmWc1,vmWc1,vmWc1,vmWc1")
+(match_operand 5 "vector_length_operand"  "   rK,  
 rK,   rK,   rK,   rK,   rK")
+(match_operand 6 "const_int_operand"  "i,  
  i,i,i,i,i")
+(match_operand 7 "const_int_operand"  "i,  
  i,i,i,i,i")
+(match_operand 8 "const_int_operand"  "i,  
  i,

[gcc r14-10053] PR modula2/112893 full type checking between proctype and procedure not implemented

2024-04-20 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:f9a48fe7032d9894e88d0d121ba6f75b08ea5dcb

commit r14-10053-gf9a48fe7032d9894e88d0d121ba6f75b08ea5dcb
Author: Gaius Mulley 
Date:   Sat Apr 20 14:35:18 2024 +0100

PR modula2/112893 full type checking between proctype and procedure not 
implemented

This patch implements full type checking between proctype and procedures.
The change implements an associated proc type built for each
procedure.  M2Check.mod will request GetProcedureProcType if it encounters
a procedure.  Before this patch a procedure was associated with the type
ADDRESS in the type checking module M2Check.  The
gm2/pim/pass/proccard.mod have been corrected now this assumption has
been removed.

gcc/m2/ChangeLog:

PR modula2/112893
* gm2-compiler/M2Check.mod (GetProcedureProcType): Import.
(getType): Return value using GetProcedureProcType if sym is a
procedure.
* gm2-compiler/M2Range.mod (FoldTypeExpr): Remove quad if
expression is type compatible.
* gm2-compiler/SymbolTable.def (GetProcedureProcType): New
procedure function.
* gm2-compiler/SymbolTable.mod (Procedure): Add ProcedureType.
(MakeProcedure): Initialize ProcedureType.
(PutParam): Call AddProcedureProcTypeParam.
(PutVarParam): Call AddProcedureProcTypeParam.
(AddProcedureProcTypeParam): New procedure.
(GetProcedureProcType): New procedure function.

gcc/testsuite/ChangeLog:

PR modula2/112893
* gm2/pim/pass/another.mod: Correct bug exposed by type checker.
Swap ProcA and ProcB assignments.
* gm2/pim/pass/proccard.mod: Use VAL to convert procedure into a
cardinal.
* gm2/iso/const/fail/castproctype.mod: New test.
* gm2/pim/fail/badproctype.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Check.mod   |  4 +-
 gcc/m2/gm2-compiler/M2Range.mod   |  3 +-
 gcc/m2/gm2-compiler/SymbolTable.def   |  7 +++
 gcc/m2/gm2-compiler/SymbolTable.mod   | 76 ---
 gcc/testsuite/gm2/iso/const/fail/castproctype.mod | 19 ++
 gcc/testsuite/gm2/pim/fail/badproctype.mod| 37 +++
 gcc/testsuite/gm2/pim/pass/another.mod|  8 +--
 gcc/testsuite/gm2/pim/pass/proccard.mod   |  3 +-
 8 files changed, 141 insertions(+), 16 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Check.mod b/gcc/m2/gm2-compiler/M2Check.mod
index 20d463d207b..a4451938b88 100644
--- a/gcc/m2/gm2-compiler/M2Check.mod
+++ b/gcc/m2/gm2-compiler/M2Check.mod
@@ -47,7 +47,7 @@ FROM SymbolTable IMPORT NulSym, IsRecord, IsSet, GetDType, 
GetSType, IsType,
 IsReallyPointer, IsPointer, IsParameter, ModeOfAddr,
 GetMode, GetType, IsUnbounded, IsComposite, 
IsConstructor,
 IsParameter, IsConstString, IsConstLitInternal, 
IsConstLit,
-GetStringLength ;
+GetStringLength, GetProcedureProcType ;
 
 FROM M2GCCDeclare IMPORT GetTypeMin, GetTypeMax ;
 FROM M2System IMPORT Address ;
@@ -1397,7 +1397,7 @@ PROCEDURE getType (sym: CARDINAL) : CARDINAL ;
 BEGIN
IF (sym # NulSym) AND IsProcedure (sym)
THEN
-  RETURN Address
+  RETURN GetProcedureProcType (sym)
ELSIF IsTyped (sym)
THEN
   RETURN GetDType (sym)
diff --git a/gcc/m2/gm2-compiler/M2Range.mod b/gcc/m2/gm2-compiler/M2Range.mod
index 50c2a48fe7f..4b8e5fadfe7 100644
--- a/gcc/m2/gm2-compiler/M2Range.mod
+++ b/gcc/m2/gm2-compiler/M2Range.mod
@@ -1719,7 +1719,8 @@ BEGIN
'expression of type {%1Etad} is 
incompatible with type {%2tad}',
left, right, strict, isin)
   THEN
- SubQuad(q) ;
+ SubQuad(q)
+  ELSE
  setReported (r)
   END
END
diff --git a/gcc/m2/gm2-compiler/SymbolTable.def 
b/gcc/m2/gm2-compiler/SymbolTable.def
index ec48631e43f..d7f0f8d943c 100644
--- a/gcc/m2/gm2-compiler/SymbolTable.def
+++ b/gcc/m2/gm2-compiler/SymbolTable.def
@@ -1394,6 +1394,13 @@ PROCEDURE PutProcedureNoReturn (Sym: CARDINAL; value: 
BOOLEAN) ;
 PROCEDURE IsProcedureNoReturn (Sym: CARDINAL) : BOOLEAN ;
 
 
+(*
+   GetProcedureProcType - returns the proctype matching procedure sym.
+*)
+
+PROCEDURE GetProcedureProcType (sym: CARDINAL) : CARDINAL ;
+
+
 (*
PutModuleStartQuad - Places QuadNumber into the Module symbol, Sym.
 QuadNumber is the start quad of Module,
diff --git a/gcc/m2/gm2-compiler/SymbolTable.mod 
b/gcc/m2/gm2-compiler/SymbolTable.mod
index 13ee1fb6fe3..7543bb52749 100644
--- a/gcc/m2/gm2-compiler/SymbolTable.mod
+++ b/gcc/m2/gm2-compiler/SymbolTable.mod
@@ -407,6 +407,7 @@ TYPE
SavePriority  : BOOLEAN ;(* Does procedure need to save   *)

[gcc r14-10052] RISC-V: Add xfail test case for wv insn highest overlap

2024-04-20 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:1690e47e101c1e273b1ee052de21d5214257c13a

commit r14-10052-g1690e47e101c1e273b1ee052de21d5214257c13a
Author: Pan Li 
Date:   Sat Apr 20 13:05:52 2024 +0800

RISC-V: Add xfail test case for wv insn highest overlap

We reverted below patch for wv insn overlap, add the related wv
insn test and mark it as xfail.  And we will remove the xfail
after we support the register overlap in GCC-15.

7e854b58084 RISC-V: Support highest overlap for wv instructions

The below test suites are passed.
* The rv64gcv fully regression test.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-11.c: Xfail csr 
check.
* gcc.target/riscv/rvv/base/pr112431-39.c: New test.
* gcc.target/riscv/rvv/base/pr112431-40.c: New test.
* gcc.target/riscv/rvv/base/pr112431-41.c: New test.

Signed-off-by: Pan Li 

Diff:
---
 .../vect/costmodel/riscv/rvv/dynamic-lmul8-11.c|   2 +-
 .../gcc.target/riscv/rvv/base/pr112431-39.c| 158 +
 .../gcc.target/riscv/rvv/base/pr112431-40.c|  94 
 .../gcc.target/riscv/rvv/base/pr112431-41.c|  62 
 4 files changed, 315 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-11.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-11.c
index c9e28251225..5a39f04b140 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-11.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-11.c
@@ -40,7 +40,7 @@ void foo2 (int64_t *__restrict a,
 }
 
 /* { dg-final { scan-assembler {e64,m8} } } */
-/* { dg-final { scan-assembler-not {csrr} } } */
+/* { dg-final { scan-assembler-not {csrr} { xfail riscv*-*-* } } } */
 /* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */
 /* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
 /* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr112431-39.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/pr112431-39.c
new file mode 100644
index 000..770b5411666
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr112431-39.c
@@ -0,0 +1,158 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O3" } */
+
+#include "riscv_vector.h"
+
+void
+foo (void *in, void *out, int n)
+{
+  for (int i = 0; i < n; i++)
+{
+  asm volatile("nop" ::: "memory");
+  vint16m2_t v0 = __riscv_vle16_v_i16m2 (in, 4);in+=100;
+  v0 = __riscv_vwsub_wv_i16m2_tu (v0, v0, 
__riscv_vreinterpret_v_i16m1_i8m1 (__riscv_vget_v_i16m2_i16m1 (v0, 1)), 4);
+  asm volatile("nop" ::: "memory");
+  vint16m2_t v1 = __riscv_vle16_v_i16m2 (in, 4);in+=100;
+  v1 = __riscv_vwsub_wv_i16m2_tu (v1, v1, 
__riscv_vreinterpret_v_i16m1_i8m1 (__riscv_vget_v_i16m2_i16m1 (v1, 1)), 4);
+  asm volatile("nop" ::: "memory");
+  vint16m2_t v2 = __riscv_vle16_v_i16m2 (in, 4);in+=100;
+  v2 = __riscv_vwsub_wv_i16m2_tu (v2, v2, 
__riscv_vreinterpret_v_i16m1_i8m1 (__riscv_vget_v_i16m2_i16m1 (v2, 1)), 4);
+  asm volatile("nop" ::: "memory");
+  vint16m2_t v3 = __riscv_vle16_v_i16m2 (in, 4);in+=100;
+  v3 = __riscv_vwsub_wv_i16m2_tu (v3, v3, 
__riscv_vreinterpret_v_i16m1_i8m1 (__riscv_vget_v_i16m2_i16m1 (v3, 1)), 4);
+  asm volatile("nop" ::: "memory");
+  vint16m2_t v4 = __riscv_vle16_v_i16m2 (in, 4);in+=100;
+  v4 = __riscv_vwsub_wv_i16m2_tu (v4, v4, 
__riscv_vreinterpret_v_i16m1_i8m1 (__riscv_vget_v_i16m2_i16m1 (v4, 1)), 4);
+  asm volatile("nop" ::: "memory");
+  vint16m2_t v5 = __riscv_vle16_v_i16m2 (in, 4);in+=100;
+  v5 = __riscv_vwsub_wv_i16m2_tu (v5, v5, 
__riscv_vreinterpret_v_i16m1_i8m1 (__riscv_vget_v_i16m2_i16m1 (v5, 1)), 4);
+  asm volatile("nop" ::: "memory");
+  vint16m2_t v6 = __riscv_vle16_v_i16m2 (in, 4);in+=100;
+  v6 = __riscv_vwsub_wv_i16m2_tu (v6, v6, 
__riscv_vreinterpret_v_i16m1_i8m1 (__riscv_vget_v_i16m2_i16m1 (v6, 1)), 4);
+  asm volatile("nop" ::: "memory");
+  vint16m2_t v7 = __riscv_vle16_v_i16m2 (in, 4);in+=100;
+  v7 = __riscv_vwsub_wv_i16m2_tu (v7, v7, 
__riscv_vreinterpret_v_i16m1_i8m1 (__riscv_vget_v_i16m2_i16m1 (v7, 1)), 4);
+  asm volatile("nop" ::: "memory");
+  vint16m2_t v8 = __riscv_vle16_v_i16m2 (in, 4);in+=100;
+  v8 = __riscv_vwsub_wv_i16m2_tu (v8, v8, 
__riscv_vreinterpret_v_i16m1_i8m1 (__riscv_vget_v_i16m2_i16m1 (v8, 1)), 4);
+  asm volatile("nop" ::: "memory");
+  vint16m2_t v9 = __riscv_vle16_v_i16m2 (in, 4);in+=100;
+  v9 = __riscv_vwsub_wv_i16m2_tu (v9, v9, 
__riscv_vreinterpret_v_i16m1_i8m1 (__riscv_vget_v_i16m2_i16m1 (v9, 1)), 4);
+  asm volatile("nop" ::: "memory");
+  vint16m2_t v10 = __riscv_vle16_v_i16m2 (in, 4);in+=100;
+  v10 = __riscv_vwsub_wv_i16m2_tu (v10, v10, 

[gcc] Created branch 'omachota/heads/rtl-ssa-dce' in namespace 'refs/users'

2024-04-20 Thread Ondrej Machota via Gcc-cvs
The branch 'omachota/heads/rtl-ssa-dce' was created in namespace 'refs/users' 
pointing to:

 f5447eae72f... Revert "RISC-V: Support highest overlap for wv instructions