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

2024-04-18 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:6c152c9db3b5b9d43e12846fb7a44977c0b65fc2

commit r14-10012-g6c152c9db3b5b9d43e12846fb7a44977c0b65fc2
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.

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

diff --git a/gcc/internal-fn.cc b/gcc/internal-fn.cc
index 5269f0ac528..c7c5222a169 100644
--- a/gcc/internal-fn.cc
+++ b/gcc/internal-fn.cc
@@ -1631,7 +1631,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 ();
 
@@ -2479,6 +2483,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.  */
@@ -2499,7 +2504,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 (&const_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;
@@ -2629,6 +2638,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.  */
@@ -2707,7 +2717,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
@@ -2748,6 +2762,7 @@ expand_arith_overflow (enum tree_code code, gimple *stmt)
  ops.location = loc;
  rtx tem = expand_expr_real_2 (&ops, NULL_RTX, mode, EXPAND_NORMAL);
  expand_arith_overflow_result_store (lhs, target, mode, tem);
+ flag_trapv = save_flag_trapv;
  return;
}
 
@@ -2771,6 +2786,7 @@ 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 */
@@ -2781,6 +2797,7 @@ expand_arith_overflow (enum tree_code code, gimple *stmt)
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 ();
@@ -2826,6 +2843,7 @@ expand_arith_overflow (enum tree_code code, gimple *stmt)
  else
expand_mul_overflow (loc, lhs, arg0, arg1, unsr_p,
 uns0_p, uns1_p, false, NULL);
+ flag_trapv = save_flag_trapv;
  r

[gcc r14-10013] libgcc: Fix up __divmodbitint4 [PR114755]

2024-04-18 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:82d6d385f9708fb6d5e2a2bacd003155cfc41c08

commit r14-10013-g82d6d385f9708fb6d5e2a2bacd003155cfc41c08
Author: Jakub Jelinek 
Date:   Thu Apr 18 09:49:02 2024 +0200

libgcc: Fix up __divmodbitint4 [PR114755]

The following testcase aborts on aarch64-linux but does not on x86_64-linux.
In both cases there is UB in the __divmodbitint4 implemenetation.
When the divisor is negative with most significant limb (even when partial)
all ones, has at least 2 limbs and the second most significant limb has the
most significant bit clear, when this number is negated, it will have 0
in the most significant limb.
Already in the PR114397 r14-9592 fix I was dealing with such divisors, but
thought the problem is only if because of that un < vn doesn't imply the
quotient is 0 and remainder u.
But as this testcase shows, the problem is with such divisors always.
What happens is that we use __builtin_clz* on the most significant limb,
and assume it will not be 0 because that is UB for the builtins.
Normally the most significant limb of the divisor shouldn't be 0, as
guaranteed by the bitint_reduce_prec e.g. for the positive numbers, unless
the divisor is just 0 (but for vn == 1 we have special cases).

The following patch moves the handling of this corner case a few lines
earlier before the un < vn check, because adjusting the vn later is harder.

2024-04-18  Jakub Jelinek  

PR libgcc/114755
* libgcc2.c (__divmodbitint4): Perform the decrement on negative
v with most significant limb all ones and the second least
significant limb with most significant bit clear always, regardless 
of
un < vn.

* gcc.dg/torture/bitint-69.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/torture/bitint-69.c |  26 
 libgcc/libgcc2.c | 105 +++
 2 files changed, 75 insertions(+), 56 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/bitint-69.c 
b/gcc/testsuite/gcc.dg/torture/bitint-69.c
new file mode 100644
index 000..5f89357678e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-69.c
@@ -0,0 +1,26 @@
+/* PR libgcc/114755 */
+/* { dg-do run { target bitint } } */
+/* { dg-options "-std=c23" } */
+/* { dg-skip-if "" { ! run_expensive_tests }  { "*" } { "-O0" "-O2" } } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
+
+#if __BITINT_MAXWIDTH__ >= 255
+_BitInt(65)
+foo (void)
+{
+  _BitInt(255) a = 0x040404040404040404040404wb;
+  _BitInt(65) b = -0xwb;
+  _BitInt(65) r = a % b;
+  return r;
+}
+#endif
+
+int
+main ()
+{
+#if __BITINT_MAXWIDTH__ >= 255
+  _BitInt(65) x = foo ();
+  if (x != 0x0404040408080808wb)
+__builtin_abort ();
+#endif
+}
diff --git a/libgcc/libgcc2.c b/libgcc/libgcc2.c
index 71c73d6b846..120d071a168 100644
--- a/libgcc/libgcc2.c
+++ b/libgcc/libgcc2.c
@@ -1705,69 +1705,62 @@ __divmodbitint4 (UBILtype *q, SItype qprec,
   USItype rn = ((USItype) rprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
   USItype up = auprec % W_TYPE_SIZE;
   USItype vp = avprec % W_TYPE_SIZE;
-  if (__builtin_expect (un < vn, 0))
+  /* If vprec < 0 and the top limb of v is all ones and the second most
+ significant limb has most significant bit clear, then just decrease
+ vn/avprec/vp, because after negation otherwise v2 would have most
+ significant limb clear.  */
+  if (vprec < 0
+  && ((v[BITINT_END (0, vn - 1)] | (vp ? ((UWtype) -1 << vp) : 0))
+ == (UWtype) -1)
+  && vn > 1
+  && (Wtype) v[BITINT_END (1, vn - 2)] >= 0)
 {
-  /* If abs(v) > abs(u), then q is 0 and r is u.
-Unfortunately un < vn doesn't always mean abs(v) > abs(u).
-If uprec > 0 and vprec < 0 and vn == un + 1, if the
-top limb of v is all ones and the second most significant
-limb has most significant bit clear, then just decrease
-vn/avprec/vp and continue, after negation both numbers
-will have the same number of limbs.  */
-  if (un + 1 == vn
- && uprec >= 0
- && vprec < 0
- && ((v[BITINT_END (0, vn - 1)] | (vp ? ((UWtype) -1 << vp) : 0))
- == (UWtype) -1)
- && (Wtype) v[BITINT_END (1, vn - 2)] >= 0)
-   {
- vp = 0;
- --vn;
+  vp = 0;
+  --vn;
 #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
- ++v;
+  ++v;
 #endif
+}
+  if (__builtin_expect (un < vn, 0))
+{
+  /* q is 0 and r is u.  */
+  if (q)
+   __builtin_memset (q, 0, qn * sizeof (UWtype));
+  if (r == NULL)
+   return;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+  r += rn - 1;
+  u += un - 1;
+#endif
+  if (up)
+   --un;
+  if (rn < un)
+   un = rn;
+  for (rn -= un; un; --un)
+   {
+ *r = *u;
+ r += BITINT_INC;
+ u += BITINT_INC;
}
-  else
+  if 

[gcc r14-10014] AArch64: remove reliance on register allocator for simd/gpreg costing. [PR114741]

2024-04-18 Thread Tamar Christina via Gcc-cvs
https://gcc.gnu.org/g:a2f4be3dae04fa8606d1cc8451f0b9d450f7e6e6

commit r14-10014-ga2f4be3dae04fa8606d1cc8451f0b9d450f7e6e6
Author: Tamar Christina 
Date:   Thu Apr 18 11:47:42 2024 +0100

AArch64: remove reliance on register allocator for simd/gpreg costing. 
[PR114741]

In PR114741 we see that we have a regression in codegen when SVE is enable 
where
the simple testcase:

void foo(unsigned v, unsigned *p)
{
*p = v & 1;
}

generates

foo:
fmovs31, w0
and z31.s, z31.s, #1
str s31, [x1]
ret

instead of:

foo:
and w0, w0, 1
str w0, [x1]
ret

This causes an impact it not just codesize but also performance.  This is 
caused
by the use of the ^ constraint modifier in the pattern 3.

The documentation states that this modifier should only have an effect on 
the
alternative costing in that a particular alternative is to be preferred 
unless
a non-psuedo reload is needed.

The pattern was trying to convey that whenever both r and w are required, 
that
it should prefer r unless a reload is needed.  This is because if a reload 
is
needed then we can construct the constants more flexibly on the SIMD side.

We were using this so simplify the implementation and to get generic cases 
such
as:

double negabs (double x)
{
   unsigned long long y;
   memcpy (&y, &x, sizeof(double));
   y = y | (1UL << 63);
   memcpy (&x, &y, sizeof(double));
   return x;
}

which don't go through an expander.
However the implementation of ^ in the register allocator is not according 
to
the documentation in that it also has an effect during coloring.  During 
initial
register class selection it applies a penalty to a class, similar to how ? 
does.

In this example the penalty makes the use of GP regs expensive enough that 
it no
longer considers them:

r106: preferred FP_REGS, alternative NO_REGS, allocno FP_REGS
;;3--> b  0: i   9 r106=r105&0x1
:cortex_a53_slot_any:GENERAL_REGS+0(-1)FP_REGS+1(1)PR_LO_REGS+0(0)
 PR_HI_REGS+0(0):model 4

which is not the expected behavior.  For GCC 14 this is a conservative fix.

1. we remove the ^ modifier from the logical optabs.

2. In order not to regress copysign we then move the copysign expansion to
   directly use the SIMD variant.  Since copysign only supports floating 
point
   modes this is fine and no longer relies on the register allocator to 
select
   the right alternative.

It once again regresses the general case, but this case wasn't optimized in
earlier GCCs either so it's not a regression in GCC 14.  This change gives
strict better codegen than earlier GCCs and still optimizes the important 
cases.

gcc/ChangeLog:

PR target/114741
* config/aarch64/aarch64.md (3): Remove ^ from alt 2.
(copysign3): Use SIMD version of IOR directly.

gcc/testsuite/ChangeLog:

PR target/114741
* gcc.target/aarch64/fneg-abs_2.c: Update codegen.
* gcc.target/aarch64/fneg-abs_4.c: xfail for now.
* gcc.target/aarch64/pr114741.c: New test.

Diff:
---
 gcc/config/aarch64/aarch64.md | 23 +
 gcc/testsuite/gcc.target/aarch64/fneg-abs_2.c |  5 ++---
 gcc/testsuite/gcc.target/aarch64/fneg-abs_4.c |  4 ++--
 gcc/testsuite/gcc.target/aarch64/pr114741.c   | 29 +++
 4 files changed, 48 insertions(+), 13 deletions(-)

diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index 385a669b9b3..dbde066f747 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -4811,7 +4811,7 @@
   ""
   {@ [ cons: =0 , 1  , 2; attrs: type , arch  ]
  [ r, %r , r; logic_reg   , * ] \t%0, 
%1, %2
- [ rk   , ^r ,  ; logic_imm   , * ] \t%0, 
%1, %2
+ [ rk   , r  ,  ; logic_imm   , * ] \t%0, 
%1, %2
  [ w, 0  ,  ; *   , sve   ] \t%Z0., 
%Z0., #%2
  [ w, w  , w; neon_logic  , simd  ] 
\t%0., %1., %2.
   }
@@ -7192,22 +7192,29 @@
(match_operand:GPF 2 "nonmemory_operand")]
   "TARGET_SIMD"
 {
-  machine_mode int_mode = mode;
-  rtx bitmask = gen_reg_rtx (int_mode);
-  emit_move_insn (bitmask, GEN_INT (HOST_WIDE_INT_M1U
-   << (GET_MODE_BITSIZE (mode) - 1)));
+  rtx signbit_const = GEN_INT (HOST_WIDE_INT_M1U
+  << (GET_MODE_BITSIZE (mode) - 1));
   /* copysign (x, -1) should instead be expanded as orr with the sign
  bit.  */
   rtx op2_elt = unwrap_const_vec_duplicate (operands[2]);
   if (GET_CODE (op2_elt) == CONST_DOUBLE
   && real_isneg (CONST_DOUBLE_REAL_VALUE (op2_e

[gcc r14-10015] [libstdc++] define zoneinfo_dir_override on vxworks

2024-04-18 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:da3504ae4d1e6872585b1107a4932efd3824e943

commit r14-10015-gda3504ae4d1e6872585b1107a4932efd3824e943
Author: Alexandre Oliva 
Date:   Thu Apr 18 08:00:52 2024 -0300

[libstdc++] define zoneinfo_dir_override on vxworks

VxWorks fails to load kernel-mode modules with weak undefined symbols.
In RTP mode modules, that undergo final linking, weak undefined
symbols are not a problem.

This patch adds kernel-mode VxWorks multilibs to the set of targets
that don't support weak undefined symbols without special flags, in
which tzdb's zoneinfo_dir_override is given a weak definition.


for  libstdc++-v3/ChangeLog

* src/c++20/tzdb.cc (__gnu_cxx::zoneinfo_dir_override): Define
on VxWorks non-RTP.

Diff:
---
 libstdc++-v3/src/c++20/tzdb.cc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc
index 890a4c53e2d..639d1c440ba 100644
--- a/libstdc++-v3/src/c++20/tzdb.cc
+++ b/libstdc++-v3/src/c++20/tzdb.cc
@@ -70,8 +70,9 @@ namespace __gnu_cxx
 #else
   [[gnu::weak]] const char* zoneinfo_dir_override();
 
-#if defined(__APPLE__) || defined(__hpux__)
-  // Need a weak definition for Mach-O.
+#if defined(__APPLE__) || defined(__hpux__) \
+  || (defined(__VXWORKS__) && !defined(__RTP__))
+  // Need a weak definition for Mach-O et al.
   [[gnu::weak]] const char* zoneinfo_dir_override()
   {
 #ifdef _GLIBCXX_ZONEINFO_DIR


[gcc r14-10016] [libstdc++] [testsuite] xfail double-prec from_chars for float128_t

2024-04-18 Thread Alexandre Oliva via Libstdc++-cvs
https://gcc.gnu.org/g:5b178179e85ace01a97def40531e915c180aaeca

commit r14-10016-g5b178179e85ace01a97def40531e915c180aaeca
Author: Alexandre Oliva 
Date:   Thu Apr 18 08:00:56 2024 -0300

[libstdc++] [testsuite] xfail double-prec from_chars for float128_t

Tests 20_util/from_chars/4.cc and 20_util/to_chars/long_double.cc were
adjusted about a year ago to skip long double on some targets, because
the fastfloat library was limited to 64-bit doubles.

The same problem comes up in similar float128_t tests on
aarch64-vxworks.  This patch adjusts them similarly.

Unlike the earlier tests, that got similar treatment for
x86_64-vxworks, these haven't failed there.


for  libstdc++-v3/ChangeLog

* testsuite/20_util/from_chars/8.cc: Skip float128_t testing
on aarch64-vxworks.
* testsuite/20_util/to_chars/float128_c++23.cc: Xfail run on
aarch64-vxworks.

Diff:
---
 libstdc++-v3/testsuite/20_util/from_chars/8.cc| 3 ++-
 libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/20_util/from_chars/8.cc 
b/libstdc++-v3/testsuite/20_util/from_chars/8.cc
index ee60d88c332..a6343422c5a 100644
--- a/libstdc++-v3/testsuite/20_util/from_chars/8.cc
+++ b/libstdc++-v3/testsuite/20_util/from_chars/8.cc
@@ -17,6 +17,7 @@
 
 // { dg-do run { target c++23 } }
 // { dg-add-options ieee }
+// { dg-additional-options "-DSKIP_LONG_DOUBLE" { target aarch64-*-vxworks* } }
 
 #include 
 #include 
@@ -343,7 +344,7 @@ test06()
 #if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
   test_max_mantissa();
 #endif
-#if defined(__GLIBCXX_TYPE_INT_N_0) \
+#if defined(__GLIBCXX_TYPE_INT_N_0) && !defined SKIP_LONG_DOUBLE \
 && defined(__STDCPP_FLOAT128_T__) && 
defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128)
   test_max_mantissa();
 #endif
diff --git a/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc 
b/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc
index 547632817b4..ca00761ee7c 100644
--- a/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc
+++ b/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc
@@ -19,6 +19,7 @@
 // { dg-require-effective-target ieee_floats }
 // { dg-require-effective-target size32plus }
 // { dg-add-options ieee }
+// { dg-xfail-run-if "from_chars limited to double-precision" { 
aarch64-*-vxworks* } }
 
 #include 
 #include 


[gcc r14-10017] [libstdc++] [testsuite] disable SRA for compare_exchange_padding

2024-04-18 Thread Alexandre Oliva via Libstdc++-cvs
https://gcc.gnu.org/g:dcf0bd14cda706be8d0c18963812beefca51df39

commit r14-10017-gdcf0bd14cda706be8d0c18963812beefca51df39
Author: Alexandre Oliva 
Date:   Thu Apr 18 08:00:59 2024 -0300

[libstdc++] [testsuite] disable SRA for compare_exchange_padding

On arm-vx7r2, the uses of as.load() as initializer get SRAed, so the
padding bits in the tests are not what we might expect from full-word
struct copies.

I tried adding a function to perform bitwise copying, but even taking
the as.load() argument by const&, we'd still construct a temporary
with SRAed field-wise copying.  Unable to find another way to ensure
we wouldn't get a temporary, I went for disabling SRA.


for  libstdc++-v3/ChangeLog

* testsuite/29_atomics/atomic/compare_exchange_padding.cc:
Disable SRA.

Diff:
---
 libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git 
a/libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc 
b/libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc
index 2f18d426e7f..a6081968ca8 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc
@@ -1,6 +1,7 @@
 // { dg-do run { target c++20 } }
 // { dg-require-atomic-cmpxchg-word "" }
 // { dg-add-options libatomic }
+// { dg-additional-options "-fno-tree-sra" }
 
 #include 
 #include 
@@ -26,10 +27,10 @@ main ()
   s.s = 42;
 
   std::atomic as{ s };
-  auto ts = as.load();
+  auto ts = as.load(); // SRA might prevent copying of padding bits here.
   VERIFY( !compare_struct(s, ts) ); // padding cleared on construction
   as.exchange(s);
-  auto es = as.load();
+  auto es = as.load(); // SRA might prevent copying of padding bits here.
   VERIFY( compare_struct(ts, es) ); // padding cleared on exchange
 
   S n;


[gcc r14-10018] [testsuite] introduce strndup effective target

2024-04-18 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:5dfbc05c4a8da4a177056c57e13e5050c637056e

commit r14-10018-g5dfbc05c4a8da4a177056c57e13e5050c637056e
Author: Alexandre Oliva 
Date:   Thu Apr 18 08:01:04 2024 -0300

[testsuite] introduce strndup effective target

A number of tests that call strndup fail on vxworks, where there's no
strndup.  Some of them already had workarounds to skip the strndup
parts of the tests on platforms that don't offer it.  I've changed
them to rely on a strndup effective target instead, and extended the
logic to other tests that were otherwise skipped entirely.


for  gcc/ChangeLog

* doc/sourcebuild.texi (strndup): Add effective target.

for  gcc/testsuite/ChangeLog

* lib/target-supports.exp (check_effective_target_strndup): New.
* gcc.dg/builtin-dynamic-object-size-0.c: Skip strndup tests
when the function is not available.
* gcc.dg/builtin-dynamic-object-size-1.c: Likewise.
* gcc.dg/builtin-dynamic-object-size-2.c: Likewise.
* gcc.dg/builtin-dynamic-object-size-3.c: Likewise.
* gcc.dg/builtin-dynamic-object-size-4.c: Likewise.
* gcc.dg/builtin-object-size-1.c: Likewise.
* gcc.dg/builtin-object-size-2.c: Likewise.
* gcc.dg/builtin-object-size-3.c: Likewise.
* gcc.dg/builtin-object-size-4.c: Likewise.

Diff:
---
 gcc/doc/sourcebuild.texi |  3 +++
 gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c | 10 +-
 gcc/testsuite/gcc.dg/builtin-dynamic-object-size-1.c |  2 +-
 gcc/testsuite/gcc.dg/builtin-dynamic-object-size-2.c |  2 +-
 gcc/testsuite/gcc.dg/builtin-dynamic-object-size-3.c |  2 +-
 gcc/testsuite/gcc.dg/builtin-dynamic-object-size-4.c |  2 +-
 gcc/testsuite/gcc.dg/builtin-object-size-1.c |  7 ---
 gcc/testsuite/gcc.dg/builtin-object-size-2.c |  7 ---
 gcc/testsuite/gcc.dg/builtin-object-size-3.c |  7 ---
 gcc/testsuite/gcc.dg/builtin-object-size-4.c |  7 ---
 gcc/testsuite/lib/target-supports.exp| 11 +++
 11 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 7c0df90e822..8e4e59ac44c 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2837,6 +2837,9 @@ can be included without error when @option{-mbig-endian} 
is passed.
 @item stpcpy
 Target provides @code{stpcpy} function.
 
+@item strndup
+Target provides @code{strndup} function.
+
 @item sysconf
 Target supports @code{sysconf}.
 
diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c 
b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
index 173e7c755f4..d02e37f79d9 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
@@ -1,7 +1,7 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 /* { dg-require-effective-target size20plus } */
-/* { dg-skip-if "no strndup" { hppa*-*-hpux* } } */
+/* { dg-additional-options "-DSKIP_STRNDUP" { target { ! strndup } } } */
 
 #include "builtin-object-size-common.h"
 
@@ -567,6 +567,7 @@ test_strdup (const char *in)
   return sz;
 }
 
+#ifndef SKIP_STRNDUP
 size_t
 __attribute__ ((noinline))
 test_strndup (const char *in, size_t bound)
@@ -577,6 +578,7 @@ test_strndup (const char *in, size_t bound)
   __builtin_free (res);
   return sz;
 }
+#endif
 
 size_t
 __attribute__ ((noinline))
@@ -589,6 +591,7 @@ test_strdup_min (const char *in)
   return sz;
 }
 
+#ifndef SKIP_STRNDUP
 size_t
 __attribute__ ((noinline))
 test_strndup_min (const char *in, size_t bound)
@@ -599,6 +602,7 @@ test_strndup_min (const char *in, size_t bound)
   __builtin_free (res);
   return sz;
 }
+#endif
 
 /* Other tests.  */
 
@@ -788,12 +792,16 @@ main (int argc, char **argv)
   const char *str = "hello world";
   if (test_strdup (str) != __builtin_strlen (str) + 1)
 FAIL ();
+#ifndef SKIP_STRNDUP
   if (test_strndup (str, 4) != 5)
 FAIL ();
+#endif
   if (test_strdup_min (str) != __builtin_strlen (str) + 1)
 FAIL ();
+#ifndef SKIP_STRNDUP
   if (test_strndup_min (str, 4) != 1)
 FAIL ();
+#endif
 
   DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-1.c 
b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-1.c
index ffa59985024..76b4f704fed 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-1.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-1.c
@@ -1,7 +1,7 @@
 /* { dg-do run } */
 /* { dg-options "-O2 -Wno-stringop-overread" } */
 /* { dg-require-effective-target alloca } */
-/* { dg-skip-if "no strndup" { hppa*-*-hpux* } } */
+/* { dg-additional-options "-DSKIP_STRNDUP" { target { ! strndup } } } */
 
 #define __builtin_object_size __builtin_dynamic_object_size
 #include "builtin-object-size-1.c"
diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-2.c 
b/gcc/testsuite/gcc.dg/builtin-dynamic-obj

[gcc r14-10019] [testsuite] [analyzer] avoid vxworks libc mode_t

2024-04-18 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:76a1bcc05f152da17770e94eaaf7aa491af2ff01

commit r14-10019-g76a1bcc05f152da17770e94eaaf7aa491af2ff01
Author: Alexandre Oliva 
Date:   Thu Apr 18 08:01:07 2024 -0300

[testsuite] [analyzer] avoid vxworks libc mode_t

Define macro that prevents mode_t from being defined by vxworks'
headers as well.


for  gcc/testsuite/ChangeLog

* gcc.dg/analyzer/fd-4.c: Define macro to avoid mode_t on
vxworks.

Diff:
---
 gcc/testsuite/gcc.dg/analyzer/fd-4.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-4.c 
b/gcc/testsuite/gcc.dg/analyzer/fd-4.c
index 880de3d7896..d104bfdad54 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-4.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-4.c
@@ -1,4 +1,5 @@
 /* { dg-additional-options "-D_MODE_T_DECLARED=1" { target newlib } } */
+/* { dg-additional-options "-D_DEFINED_mode_t" { target *-*-vxworks* } } */
 #if defined(_AIX) || defined(__hpux)
 #define _MODE_T
 #endif


[gcc r14-10020] [testsuite] [analyzer] skip access-mode: O_ACCMODE on vxworks

2024-04-18 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:5be4f203c491b654ae2b2d5a01b58613f74aba1d

commit r14-10020-g5be4f203c491b654ae2b2d5a01b58613f74aba1d
Author: Alexandre Oliva 
Date:   Thu Apr 18 08:01:11 2024 -0300

[testsuite] [analyzer] skip access-mode: O_ACCMODE on vxworks

O_ACCMODE is not defined on vxworks, and the test is meaningless and
failing without it, so skip it.


for  gcc/testsuite/ChangeLog

* gcc.dg/analyzer/fd-access-mode-target-headers.c: Skip on
vxworks as well.

Diff:
---
 gcc/testsuite/gcc.dg/analyzer/fd-access-mode-target-headers.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-access-mode-target-headers.c 
b/gcc/testsuite/gcc.dg/analyzer/fd-access-mode-target-headers.c
index b57b9fa2279..9fc32638a3d 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-access-mode-target-headers.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-access-mode-target-headers.c
@@ -1,5 +1,4 @@
-/* { dg-skip-if "" { powerpc*-*-aix* || newlib } } */
-/* { dg-skip-if "" { avr-*-* } } */
+/* { dg-skip-if "" { { powerpc*-*-aix* avr-*-* *-*-vxworks* } || newlib } } */
 
 #include 
 #include 


[gcc r14-10021] [testsuite] [analyzer] require fork where used

2024-04-18 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:8a1170903212ed31fd970d3c1b9fabf50868d01a

commit r14-10021-g8a1170903212ed31fd970d3c1b9fabf50868d01a
Author: Alexandre Oliva 
Date:   Thu Apr 18 08:01:15 2024 -0300

[testsuite] [analyzer] require fork where used

Mark tests that fail due to the lack of fork, as in vxworks kernel
mode, as requiring fork.


for  gcc/testsuite/ChangeLog

* gcc.dg/analyzer/pipe-glibc.c: Require fork.
* gcc.dg/analyzer/pipe-manpages.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c| 5 +++--
 gcc/testsuite/gcc.dg/analyzer/pipe-manpages.c | 2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c 
b/gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c
index 60558a870b9..fe38ddef395 100644
--- a/gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c
+++ b/gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c
@@ -1,6 +1,7 @@
-/* Example of pipe usage from glibc manual.  */
-
 /* { dg-skip-if "" { "avr-*-*" } } */
+/* { dg-require-fork "" } */
+
+/* Example of pipe usage from glibc manual.  */
 
 #include 
 #include 
diff --git a/gcc/testsuite/gcc.dg/analyzer/pipe-manpages.c 
b/gcc/testsuite/gcc.dg/analyzer/pipe-manpages.c
index 6b9ae4d2602..ac5805fdba0 100644
--- a/gcc/testsuite/gcc.dg/analyzer/pipe-manpages.c
+++ b/gcc/testsuite/gcc.dg/analyzer/pipe-manpages.c
@@ -1,3 +1,5 @@
+/* { dg-require-fork "" } */
+
 /* Example of "pipe" from release 5.13 of the Linux man-pages project.
 
 Copyright (C) 2005, 2008, Michael Kerrisk 


[gcc r14-10022] [testsuite] [analyzer] include sys/select.h if available

2024-04-18 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:e965162bb9de6d2cd68cdc0e26dda56abd25fcdf

commit r14-10022-ge965162bb9de6d2cd68cdc0e26dda56abd25fcdf
Author: Alexandre Oliva 
Date:   Thu Apr 18 08:01:21 2024 -0300

[testsuite] [analyzer] include sys/select.h if available

Test that calls select fails on vxworks because select is only
declared in sys/select.h.  Include that header if it's present.


for  gcc/testsuite/ChangeLog

* gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c:
Include sys/select.h if present.

Diff:
---
 gcc/testsuite/gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git 
a/gcc/testsuite/gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c 
b/gcc/testsuite/gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c
index fcbcc740170..f922a52238f 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c
@@ -8,6 +8,9 @@
 #include 
 #include 
 #include 
+#if __has_include()
+#include 
+#endif
 #include 
 #include 
 #include 


[gcc r14-10023] [testsuite] xfail pr103798-2 in C++ on vxworks too [PR113706]

2024-04-18 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:cc02ebfcfd0755b330c50a840ab713fedd6d8887

commit r14-10023-gcc02ebfcfd0755b330c50a840ab713fedd6d8887
Author: Alexandre Oliva 
Date:   Thu Apr 18 08:01:26 2024 -0300

[testsuite] xfail pr103798-2 in C++ on vxworks too [PR113706]

pr103798-2.c fails in C++ on targets that provide a ISO C++-compliant
declaration of memchr, because it mismatches the C-compatible builtin,
as per PR113706.  Expect the C++ test to fail on vxworks as well.


for  gcc/testsuite/ChangeLog

PR testsuite/113706
* c-c++-common/pr103798-2.c: XFAIL in C++ on vxworks too.

Diff:
---
 gcc/testsuite/c-c++-common/pr103798-2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/c-c++-common/pr103798-2.c 
b/gcc/testsuite/c-c++-common/pr103798-2.c
index bc126c205e1..83cdfaa1660 100644
--- a/gcc/testsuite/c-c++-common/pr103798-2.c
+++ b/gcc/testsuite/c-c++-common/pr103798-2.c
@@ -28,4 +28,4 @@ main ()
 }
 
 /* See PR c++/113706 for the xfail.  */
-/* { dg-final { scan-assembler-not "memchr" { xfail { c++ && *-*-solaris2* } } 
} } */
+/* { dg-final { scan-assembler-not "memchr" { xfail { c++ && { *-*-solaris2* 
*-*-vxworks* } } } } } */


[gcc r14-10025] [testsuite] [aarch64] Require fpic effective target.

2024-04-18 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:df92df0c19f7783519a392f7ac7d4e617250c328

commit r14-10025-gdf92df0c19f7783519a392f7ac7d4e617250c328
Author: Alexandre Oliva 
Date:   Thu Apr 18 08:01:32 2024 -0300

[testsuite] [aarch64] Require fpic effective target.

Co-authored-by: Olivier Hainque 

for  gcc/testsuite/ChangeLog

* gcc.target/aarch64/pr94201.c: Add missing
dg-require-effective-target fpic.
* gcc.target/aarch64/pr103085.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.target/aarch64/pr103085.c | 1 +
 gcc/testsuite/gcc.target/aarch64/pr94201.c  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/gcc/testsuite/gcc.target/aarch64/pr103085.c 
b/gcc/testsuite/gcc.target/aarch64/pr103085.c
index dbc9c15b71f..347280ed42b 100644
--- a/gcc/testsuite/gcc.target/aarch64/pr103085.c
+++ b/gcc/testsuite/gcc.target/aarch64/pr103085.c
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
 /* { dg-options "-O2 -fstack-protector-strong -fPIC" } */
+/* { dg-require-effective-target fpic } */
 
 void g(int*);
 void
diff --git a/gcc/testsuite/gcc.target/aarch64/pr94201.c 
b/gcc/testsuite/gcc.target/aarch64/pr94201.c
index 69176169186..3b9b79059e0 100644
--- a/gcc/testsuite/gcc.target/aarch64/pr94201.c
+++ b/gcc/testsuite/gcc.target/aarch64/pr94201.c
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
 /* { dg-options "-mcmodel=tiny -mabi=ilp32 -fPIC" } */
+/* { dg-require-effective-target fpic } */
 
 extern int bar (void *);
 extern long long a;


[gcc r14-10024] [testsuite] [i386] require fpic for pr111497.C

2024-04-18 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:514c6b1cb766dc0a14121016ce84b9f5a1ef4e41

commit r14-10024-g514c6b1cb766dc0a14121016ce84b9f5a1ef4e41
Author: Alexandre Oliva 
Date:   Thu Apr 18 08:01:29 2024 -0300

[testsuite] [i386] require fpic for pr111497.C

Fix another test that uses -fPIC without requiring fpic support.


for  gcc/testsuite/ChangeLog

* g++.target/i386/pr111497.C: Require fpic support.

Diff:
---
 gcc/testsuite/g++.target/i386/pr111497.C | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/g++.target/i386/pr111497.C 
b/gcc/testsuite/g++.target/i386/pr111497.C
index a645bb95907..30e2e0409ad 100644
--- a/gcc/testsuite/g++.target/i386/pr111497.C
+++ b/gcc/testsuite/g++.target/i386/pr111497.C
@@ -1,5 +1,6 @@
 // { dg-do compile { target ia32 } }
 // { dg-options "-march=i686 -mtune=generic -fPIC -O2 -g" }
+// { dg-require-effective-target fpic }
 
 class A;
 struct B { const char *b1; int b2; };


[gcc r14-10026] [c++] [testsuite] adjust contracts9.C for negative addresses

2024-04-18 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:ce2dfc57b4562fef0d279697d96f672bc903e853

commit r14-10026-gce2dfc57b4562fef0d279697d96f672bc903e853
Author: Alexandre Oliva 
Date:   Thu Apr 18 08:01:35 2024 -0300

[c++] [testsuite] adjust contracts9.C for negative addresses

The test expected the address of a literal string, converted to long
long, to yield a positive value.  That expectation doesn't necessarily
hold, and the test fails where it doesn't.

Adjust the test to use a pointer that will compare as expected.

for  gcc/testsuite/ChangeLog

* g++.dg/contracts/contracts9.C: Don't assume string literals
have non-negative addresses.

Diff:
---
 gcc/testsuite/g++.dg/contracts/contracts9.C | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/contracts/contracts9.C 
b/gcc/testsuite/g++.dg/contracts/contracts9.C
index 09a1a6532c5..58b60aca320 100644
--- a/gcc/testsuite/g++.dg/contracts/contracts9.C
+++ b/gcc/testsuite/g++.dg/contracts/contracts9.C
@@ -27,7 +27,7 @@ int main()
 {
   fun1(1, -1);
   fun1(-1, 1.0);
-  fun1(-1, "test");
+  fun1(-1, (const char *)0x1234);
 
   [[ assert: fun1(-1, -5) ]];
   [[ assert: test::fun(10, -6) ]];


[gcc r14-10027] [testsuite] [arm] accept empty init for bfloat16

2024-04-18 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:36d003816352052f610a3f63ab74b6443eb7efb7

commit r14-10027-g36d003816352052f610a3f63ab74b6443eb7efb7
Author: Alexandre Oliva 
Date:   Thu Apr 18 08:01:37 2024 -0300

[testsuite] [arm] accept empty init for bfloat16

Complete r13-2205, adjusting an arm-specific test that expects a
no-longer-issued error at an empty initializer.


for  gcc/testsuite/ChangeLog

* gcc.target/arm/bfloat16_scalar_typecheck.c: Accept C23
empty initializers.

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

diff --git a/gcc/testsuite/gcc.target/arm/bfloat16_scalar_typecheck.c 
b/gcc/testsuite/gcc.target/arm/bfloat16_scalar_typecheck.c
index 8c80c55bc9f..04ede93bda1 100644
--- a/gcc/testsuite/gcc.target/arm/bfloat16_scalar_typecheck.c
+++ b/gcc/testsuite/gcc.target/arm/bfloat16_scalar_typecheck.c
@@ -42,7 +42,7 @@ bfloat16_t footest (bfloat16_t scalar0)
   short initi_1_4 = glob_bfloat; /* { dg-error {invalid conversion from type 
'bfloat16_t'} } */
   double initi_1_5 = glob_bfloat; /* { dg-error {invalid conversion from type 
'bfloat16_t'} } */
 
-  bfloat16_t scalar2_1 = {}; /* { dg-error {empty scalar initializer} } */
+  bfloat16_t scalar2_1 = {};
   bfloat16_t scalar2_2 = { glob_bfloat };
   bfloat16_t scalar2_3 = { 0 }; /* { dg-error {invalid conversion to type 
'bfloat16_t'} } */
   bfloat16_t scalar2_4 = { 0.1 }; /* { dg-error {invalid conversion to type 
'bfloat16_t'} } */
@@ -94,7 +94,7 @@ bfloat16_t footest (bfloat16_t scalar0)
 
   /* Compound literals.  */
 
-  (bfloat16_t) {}; /* { dg-error {empty scalar initializer} } */
+  (bfloat16_t) {};
   (bfloat16_t) { glob_bfloat };
   (bfloat16_t) { 0 }; /* { dg-error {invalid conversion to type 'bfloat16_t'} 
} */
   (bfloat16_t) { 0.1 }; /* { dg-error {invalid conversion to type 
'bfloat16_t'} } */


[gcc r14-10028] [testsuite] [i386] work around fails with --enable-frame-pointer

2024-04-18 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:0ea96af1150c221092a0880af51dbe66b75ecb03

commit r14-10028-g0ea96af1150c221092a0880af51dbe66b75ecb03
Author: Alexandre Oliva 
Date:   Thu Apr 18 08:01:40 2024 -0300

[testsuite] [i386] work around fails with --enable-frame-pointer

A few x86 tests get unexpected insn counts if the toolchain is
configured with --enable-frame-pointer.  Add explicit
-fomit-frame-pointer so that the expected insn sequences are output.


for  gcc/testsuite/ChangeLog

* gcc.target/i386/pr107261.c: Add -fomit-frame-pointer.
* gcc.target/i386/pr69482-1.c: Likewise.
* gcc.target/i386/pr69482-2.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.target/i386/pr107261.c  | 2 +-
 gcc/testsuite/gcc.target/i386/pr69482-1.c | 2 +-
 gcc/testsuite/gcc.target/i386/pr69482-2.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.target/i386/pr107261.c 
b/gcc/testsuite/gcc.target/i386/pr107261.c
index eb1d232fbfc..b422af9cbf9 100644
--- a/gcc/testsuite/gcc.target/i386/pr107261.c
+++ b/gcc/testsuite/gcc.target/i386/pr107261.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -msse2" } */
+/* { dg-options "-O2 -msse2 -fomit-frame-pointer" } */
 
 typedef __bf16 v4bf __attribute__ ((vector_size (8)));
 typedef __bf16 v2bf __attribute__ ((vector_size (4)));
diff --git a/gcc/testsuite/gcc.target/i386/pr69482-1.c 
b/gcc/testsuite/gcc.target/i386/pr69482-1.c
index 99bb6ad5a37..7ef0e71b17c 100644
--- a/gcc/testsuite/gcc.target/i386/pr69482-1.c
+++ b/gcc/testsuite/gcc.target/i386/pr69482-1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O3 -fno-stack-protector" } */
+/* { dg-options "-O3 -fno-stack-protector -fomit-frame-pointer" } */
 
 static inline void memset_s(void* s, int n) {
   volatile unsigned char * p = s;
diff --git a/gcc/testsuite/gcc.target/i386/pr69482-2.c 
b/gcc/testsuite/gcc.target/i386/pr69482-2.c
index 58e89a79333..6aabe4fb393 100644
--- a/gcc/testsuite/gcc.target/i386/pr69482-2.c
+++ b/gcc/testsuite/gcc.target/i386/pr69482-2.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2" } */
+/* { dg-options "-O2 -fomit-frame-pointer" } */
 
 void bar ()
 {


[gcc r14-10029] [testsuite] [i386] add -msse2 to tests that require it

2024-04-18 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:7eecc08ccf75679e6ae688d92e50afae935547ab

commit r14-10029-g7eecc08ccf75679e6ae688d92e50afae935547ab
Author: Alexandre Oliva 
Date:   Thu Apr 18 08:01:43 2024 -0300

[testsuite] [i386] add -msse2 to tests that require it

Without -msse2, an i586-targeting toolchain fails bf16_short_warn.c
because neither type __m128bh nor intrinsic _mm_cvtneps_pbh get
declared.


for  gcc/testsuite/ChangeLog

* gcc.target/i386/bf16_short_warn.c: Add -msse2.

Diff:
---
 gcc/testsuite/gcc.target/i386/bf16_short_warn.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/i386/bf16_short_warn.c 
b/gcc/testsuite/gcc.target/i386/bf16_short_warn.c
index 3e47a815200..2e05624bc26 100644
--- a/gcc/testsuite/gcc.target/i386/bf16_short_warn.c
+++ b/gcc/testsuite/gcc.target/i386/bf16_short_warn.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2" } */
+/* { dg-options "-O2 -msse2" } */
 
 #include
 typedef struct {


[gcc/devel/jlaw/crc] Refactored sym-exec: Added comments, changed members' names ...

2024-04-18 Thread Mariam Arutunian via Gcc-cvs
https://gcc.gnu.org/g:525b7590e3668c7a72b0d77c89bdd1ac5f6ada8a

commit 525b7590e3668c7a72b0d77c89bdd1ac5f6ada8a
Author: Mariam Arutunian 
Date:   Mon Apr 15 15:36:18 2024 +0400

Refactored sym-exec: Added comments, changed members' names ...

Diff:
---
 gcc/sym-exec/condition.cc  |  14 ++--
 gcc/sym-exec/condition.h   |   2 +-
 gcc/sym-exec/expression.cc | 114 +++---
 gcc/sym-exec/expression.h  |  26 +++
 gcc/sym-exec/state.cc  | 172 +++--
 gcc/sym-exec/state.h   |  62 +---
 6 files changed, 265 insertions(+), 125 deletions(-)

diff --git a/gcc/sym-exec/condition.cc b/gcc/sym-exec/condition.cc
index 39d9d9eddf3..5b558d1e315 100644
--- a/gcc/sym-exec/condition.cc
+++ b/gcc/sym-exec/condition.cc
@@ -2,24 +2,24 @@
 
 bit_condition::bit_condition (value_bit *left, value_bit *right, tree_code 
code)
 {
-  this->left = left;
-  this->right = right;
-  this->code = code;
-  type = BIT_CONDITION;
+  this->m_left = left;
+  this->m_right = right;
+  this->m_code = code;
+  m_type = BIT_CONDITION;
 }
 
 
 bit_condition::bit_condition (const bit_condition &expr)
 {
   bit_expression::copy (&expr);
-  code = expr.get_code ();
+  m_code = expr.get_code ();
 }
 
 
 tree_code
 bit_condition::get_code () const
 {
-  return code;
+  return m_code;
 }
 
 
@@ -33,7 +33,7 @@ bit_condition::copy () const
 void
 bit_condition::print_expr_sign ()
 {
-  switch (code)
+  switch (m_code)
 {
   case GT_EXPR:
fprintf (dump_file, " > ");
diff --git a/gcc/sym-exec/condition.h b/gcc/sym-exec/condition.h
index dc3ec382d2f..1882c6cfa91 100644
--- a/gcc/sym-exec/condition.h
+++ b/gcc/sym-exec/condition.h
@@ -13,7 +13,7 @@ enum condition_status {
 
 class bit_condition : public bit_expression {
  private:
-  tree_code code;
+  tree_code m_code;
   void print_expr_sign ();
 
  public:
diff --git a/gcc/sym-exec/expression.cc b/gcc/sym-exec/expression.cc
index 7a830eb437a..0f885550ab8 100644
--- a/gcc/sym-exec/expression.cc
+++ b/gcc/sym-exec/expression.cc
@@ -7,76 +7,76 @@
 value_type
 value_bit::get_type () const
 {
-  return type;
+  return m_type;
 }
 
-
-symbolic_bit::symbolic_bit (size_t i, tree orig) : value_bit (i), origin (orig)
+symbolic_bit::symbolic_bit (size_t i, tree orig)
+: value_bit (i), m_origin (orig)
 {
-  type = SYMBOLIC_BIT;
+  m_type = SYMBOLIC_BIT;
 }
 
 
-bit::bit (unsigned char i) : val (i)
+bit::bit (unsigned char i) : m_val (i)
 {
-  type = BIT;
+  m_type = BIT;
 }
 
 
 value_bit *
 bit_expression::get_left ()
 {
-  return left;
+  return m_left;
 }
 
 
 value_bit *
 bit_expression::get_right ()
 {
-  return right;
+  return m_right;
 }
 
 
 void
 bit_expression::set_left (value_bit *expr)
 {
-  left = expr;
+  m_left = expr;
 }
 
 
 void
 bit_expression::set_right (value_bit *expr)
 {
-  right = expr;
+  m_right = expr;
 }
 
 
 size_t
 value_bit::get_index () const
 {
-  return index;
+  return m_index;
 }
 
 
 unsigned char
 bit::get_val () const
 {
-  return val;
+  return m_val;
 }
 
 
 void
 bit::set_val (unsigned char new_val)
 {
-  val = new_val;
+  m_val = new_val;
 }
 
 
 bit_complement_expression::bit_complement_expression (value_bit *right)
 {
-  this->left = nullptr;
-  this->right = right;
-  type = BIT_COMPLEMENT_EXPRESSION;
+  this->m_left = nullptr;
+  this->m_right = right;
+  m_type = BIT_COMPLEMENT_EXPRESSION;
 }
 
 
@@ -89,10 +89,10 @@ bit_complement_expression::bit_complement_expression (
 
 bit_expression::~bit_expression ()
 {
-  delete left;
-  left = nullptr;
-  delete right;
-  right = nullptr;
+  delete m_left;
+  m_left = nullptr;
+  delete m_right;
+  m_right = nullptr;
 }
 
 
@@ -113,13 +113,13 @@ bit::copy () const
 void
 bit_expression::copy (const bit_expression *expr)
 {
-  if (expr->left)
-left = expr->left->copy ();
+  if (expr->m_left)
+m_left = expr->m_left->copy ();
 
-  if (expr->right)
-right = expr->right->copy ();
+  if (expr->m_right)
+m_right = expr->m_right->copy ();
 
-  type = expr->type;
+  m_type = expr->m_type;
 }
 
 
@@ -181,9 +181,9 @@ bit_complement_expression::copy () const
 
 bit_xor_expression::bit_xor_expression (value_bit *left, value_bit *right)
 {
-  this->left = left;
-  this->right = right;
-  type = BIT_XOR_EXPRESSION;
+  this->m_left = left;
+  this->m_right = right;
+  m_type = BIT_XOR_EXPRESSION;
 }
 
 
@@ -195,9 +195,9 @@ bit_xor_expression::bit_xor_expression (const 
bit_xor_expression &expr)
 
 bit_and_expression::bit_and_expression (value_bit *left, value_bit *right)
 {
-  this->left = left;
-  this->right = right;
-  type = BIT_AND_EXPRESSION;
+  this->m_left = left;
+  this->m_right = right;
+  m_type = BIT_AND_EXPRESSION;
 }
 
 
@@ -209,9 +209,9 @@ bit_and_expression::bit_and_expression (const 
bit_and_expression &expr)
 
 bit_or_expression::bit_or_expression (value_bit *left, value_bit *right)
 {
-  this->left = left;
-  this->right = right;
-  type = BIT_OR_EXPRESSION;
+  this->m_left = left;
+  this->m_right = righ

[gcc r12-10336] libstdc++, Darwin: Limit recursive mutex init to OS versions needing it.

2024-04-18 Thread Iain D Sandoe via Libstdc++-cvs
https://gcc.gnu.org/g:ab4ff3e9fe881ef85a8156f2be528872c6a2fdfc

commit r12-10336-gab4ff3e9fe881ef85a8156f2be528872c6a2fdfc
Author: Iain Sandoe 
Date:   Sat Dec 3 17:09:35 2022 +

libstdc++, Darwin: Limit recursive mutex init to OS versions needing it.

The problem described in pr 51906 was fixed in the next OS release.  Limit 
the
workaround to systems that need it.

Signed-off-by: Iain Sandoe 

libstdc++-v3/ChangeLog:

* config/os/bsd/darwin/os_defines.h
(_GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC): Limit use of this macro
to OS versions that need it.

(cherry picked from commit a044c9d25972b22c6b4c8ec27f2de5fd622573cc)

Diff:
---
 libstdc++-v3/config/os/bsd/darwin/os_defines.h | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/config/os/bsd/darwin/os_defines.h 
b/libstdc++-v3/config/os/bsd/darwin/os_defines.h
index a8b6d4fa324..f56f31ad2f5 100644
--- a/libstdc++-v3/config/os/bsd/darwin/os_defines.h
+++ b/libstdc++-v3/config/os/bsd/darwin/os_defines.h
@@ -39,8 +39,12 @@
 // -flat_namespace to work around the way that it doesn't.
 #define _GLIBCXX_WEAK_DEFINITION __attribute__ ((weak))
 
-// Static initializer macro is buggy in darwin, see libstdc++/51906
+#if defined (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) \
+ && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1080)
+// Static initializer macro is absent for Darwin < 11 and buggy in Darwin 11,
+// see libstdc++/51906.  Fixed in Darwin 12 (OS X 10.8).
 #define _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC
+#endif
 
 // Configure checks for nanosleep fail on Darwin, but nanosleep and
 // sched_yield are always available, so use them.


[gcc r12-10337] Darwin: Move checking of the 'shared' driver spec.

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

commit r12-10337-gffe514c8ebd359e5d3fc22d30ee8f5fee259d15f
Author: Iain Sandoe 
Date:   Sun Jul 9 09:02:39 2023 +0100

Darwin: Move checking of the 'shared' driver spec.

This avoids a bunch of irrelevant diagnostics if the user passes '-shared' 
to
gnatmake.  Currently, we push '-dynamiclib' back onto the command line 
(since
that is the Darwin spelling of 'shared') but this is not handled by gnat1,
leading to a diagnostic for every character after the '-d'.

'-shared' has no effect on gnatmake (it needs to be passed to gnatbind).

This moves the handling of '-shared' to leaf specs so that we do not need to
push 'dynamiclib' onto the command line.

includes changes in 3b18fd28c83ac90bf408389c003ed25d93438210.

gcc/ChangeLog:

* config/darwin.h:
(SUBTARGET_DRIVER_SELF_SPECS): Move handling of 'shared' into the 
same
specs as 'dynamiclib'. (STARTFILE_SPEC): Handle 'shared'.

(cherry picked from commit 2e36eedb244badaaf2a70388071115c851b8db9b)

Signed-off-by: Iain Sandoe 

Diff:
---
 gcc/config/darwin.h | 34 +-
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index ba5fb0a2b48..6b81820072b 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -133,10 +133,9 @@ extern GTY(()) int darwin_ms_struct;
cases where these driver opts are used multiple times, or to control
operations on more than one command (e.g. dynamiclib).  These are handled
specially and we then add %= 10.7 mmacosx-version-min= -no_pie) }"
 
 #define DARWIN_CC1_SPEC
\
-  "%

[gcc r12-10338] configure, Darwin: Adjust handing of stdlib option.

2024-04-18 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:6ac3a4beaeb0981ad956beada305b4ff75f0df8d

commit r12-10338-g6ac3a4beaeb0981ad956beada305b4ff75f0df8d
Author: Iain Sandoe 
Date:   Sat Sep 16 08:40:49 2023 +0100

configure, Darwin: Adjust handing of stdlib option.

The intent of the configuration choices for -stdlib is that default
setting should choose reasonable options for the target.  This should
enable -stdlib= for Darwin targets where libc++ is the default on the
system (so that it is only necessary to provide the headers).

However, it seems that there are some cases where (external) config
scripts are using -stdlib (incorrectly) to determine if the compiler
in use is GCC or clang.

In order to allow for these cases, this patch refines the setting
like so:

--with-gxx-libcxx-include-dir= is used to configure the path containing
libc++ headers; it also controls the enabling of the -stdlib option.

We are adding a special value for path:
if --with-gxx-libcxx-include-dir is 'no' we disable the stdlib option.

Otherwise if the --with-gxx-libcxx-include-dir is set we use the path
provided, and enable the stdlib option.

if --with-gxx-libcxx-include-dir is unset
We decide on the stdlib option based on the OS type and revision being
targeted.  The path is set to a fixed position relative to the compiler
install (similar logic to that used for libstdc++ headers).

Signed-off-by: Iain Sandoe 

gcc/ChangeLog:

* configure: Regenerate.
* configure.ac: Handle explict disable of stdlib option, set
defaults for Darwin.

(cherry picked from commit ce7a757fd9ecb99c4f54cfde5cf5ef9a9e7819fc)

Diff:
---
 gcc/configure| 45 ++---
 gcc/configure.ac | 38 ++
 2 files changed, 64 insertions(+), 19 deletions(-)

diff --git a/gcc/configure b/gcc/configure
index 9d65cfc67b5..04acb3fb3a8 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -3750,31 +3750,54 @@ gcc_gxx_libcxx_include_dir=
 if test "${with_gxx_libcxx_include_dir+set}" = set; then :
   withval=$with_gxx_libcxx_include_dir; case "${withval}" in
 yes)   as_fn_error $? "bad value ${withval} given for libc++ include 
directory" "$LINENO" 5 ;;
-no);;
 *) gcc_gxx_libcxx_include_dir=$with_gxx_libcxx_include_dir ;;
 esac
 fi
 
 
+# --with-gxx-libcxx-include-dir controls the enabling of the -stdlib option.
+# if --with-gxx-libcxx-include-dir is 'no' we disable the stdlib option.
+# if --with-gxx-libcxx-include-dir is unset we enable the stdlib option
+# based on the platform (to be available on platform versions where it is the
+# default for the system tools). We also use a default path within the compiler
+# install tree.
+# Otherwise, we use the path provided and enable the stdlib option.
 # If both --with-sysroot and --with-gxx-libcxx-include-dir are passed, we
 # check to see if the latter starts with the former and, upon success, compute
 # gcc_gxx_libcxx_include_dir as relative to the sysroot.
 gcc_gxx_libcxx_include_dir_add_sysroot=0
-
+gcc_enable_stdlib_opt=0
 if test x${gcc_gxx_libcxx_include_dir} != x; then
+  if test x${gcc_gxx_libcxx_include_dir} = xno; then
+# set defaults for the dir, but the option is disabled anyway.
+gcc_gxx_libcxx_include_dir=
+  else
+gcc_enable_stdlib_opt=1
+  fi
+else
+  case $target in
+*-darwin1[1-9]* | *-darwin2*)
+   # Default this on for Darwin versions which default to libcxx,
+   # and embed the path in the compiler install so that we get a
+   # self-contained toolchain.
+   gcc_enable_stdlib_opt=1
+   ;;
+*) ;;
+  esac
+fi
 
-$as_echo "#define ENABLE_STDLIB_OPTION 1" >>confdefs.h
+cat >>confdefs.h <<_ACEOF
+#define ENABLE_STDLIB_OPTION $gcc_enable_stdlib_opt
+_ACEOF
 
-else
-  $as_echo "#define ENABLE_STDLIB_OPTION 0" >>confdefs.h
 
-fi
-# ??? This logic must match 
libstdc++-v3/acinclude.m4:GLIBCXX_EXPORT_INSTALL_INFO.
+# Sysroot behaviour as for gxx-include-dir
 if test x${gcc_gxx_libcxx_include_dir} = x; then
+  # default path,embedded in the compiler tree.
+  libcxx_incdir='include/c++/v1'
   if test x${enable_version_specific_runtime_libs} = xyes; then
-gcc_gxx_libcxx_include_dir='${libsubdir}/libc++_include/c++/v1'
+gcc_gxx_libcxx_include_dir='${libsubdir}/$libcxx_incdir'
   else
-libcxx_incdir='libc++_include/c++/$(version)/v1'
 if test x$host != x$target; then
libcxx_incdir="$target_alias/$libcxx_incdir"
 fi
@@ -19668,7 +19691,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19671 "configure"
+#line 19694 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19774,7 +19797,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19777 "configure"
+#line 19800 

[gcc r12-10339] build: Allow for Xcode 15 ld -v output

2024-04-18 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:23fa5cdd4cd0feb6580e1451c3ad849b24cfa570

commit r12-10339-g23fa5cdd4cd0feb6580e1451c3ad849b24cfa570
Author: Rainer Orth 
Date:   Thu Aug 17 10:14:49 2023 +0200

build: Allow for Xcode 15 ld -v output

Since Xcode 15 beta 6, ld -v output differs from previous versions:

* macOS 13/Xcode 14:

  @(#)PROGRAM:ld  PROJECT:ld64-857.1

* macOS 14/Xcode 15:

  @(#)PROGRAM:ld  PROJECT:dyld-1015.1

configure cannot handle the new form, so LD64_VERSION isn't set.

This patch fixes this.  The autoconf manual states that sed doesn't
portably support alternation, so I'm using two separate expressions to
extract the version number.

Tested on x86_64-apple-darwin23.0.0.

2023-08-16  Rainer Orth  

gcc:
* configure.ac (gcc_cv_ld64_version): Allow for dyld in ld -v
output.
* configure: Regenerate.

(cherry picked from commit 0beac9209f0ae230b34ad31e76e7b0b633a5fb21)

Diff:
---
 gcc/configure| 3 ++-
 gcc/configure.ac | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/configure b/gcc/configure
index 04acb3fb3a8..d62b03a75c9 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -30852,7 +30852,8 @@ $as_echo "$gcc_cv_ld64_major" >&6; }
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking linker version" >&5
 $as_echo_n "checking linker version... " >&6; }
 if test x"${gcc_cv_ld64_version}" = x; then
-  gcc_cv_ld64_version=`$gcc_cv_ld -v 2>&1 | grep ld64 | sed s/.*ld64-// | 
awk '{print $1}'`
+  gcc_cv_ld64_version=`$gcc_cv_ld -v 2>&1 | $EGREP 'ld64|dyld' \
+  | sed -e 's/.*ld64-//' -e 's/.*dyld-//'| awk '{print $1}'`
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld64_version" >&5
 $as_echo "$gcc_cv_ld64_version" >&6; }
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 0fe8f4ad6fc..e387ffa8ed5 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -6406,7 +6406,8 @@ if test x"$ld64_flag" = x"yes"; then
 # If the version was not specified, try to find it.
 AC_MSG_CHECKING(linker version)
 if test x"${gcc_cv_ld64_version}" = x; then
-  gcc_cv_ld64_version=`$gcc_cv_ld -v 2>&1 | grep ld64 | sed s/.*ld64-// | 
awk '{print $1}'`
+  gcc_cv_ld64_version=`$gcc_cv_ld -v 2>&1 | $EGREP 'ld64|dyld' \
+  | sed -e 's/.*ld64-//' -e 's/.*dyld-//'| awk '{print $1}'`
 fi
 AC_MSG_RESULT($gcc_cv_ld64_version)


[gcc r12-10340] Darwin: Match system sections and relocs for exception tables.

2024-04-18 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:71e3f9f5ec7516fa67d004974445821eea5a3342

commit r12-10340-g71e3f9f5ec7516fa67d004974445821eea5a3342
Author: Iain Sandoe 
Date:   Thu Aug 31 19:20:43 2023 +0100

Darwin: Match system sections and relocs for exception tables.

System tools from Darwin10 onwards have moved the exceptions tables from
the __DATA segment to the __TEXT one.  They also revised the relocations
used for typeinfo.  While Darwin9 was not changed at the time, in fact the
tools there are equally happy with the revised scheme - and therefore at
present there seems no reason to special-case it.

Signed-off-by: Iain Sandoe 

gcc/ChangeLog:

* config/darwin-sections.def (darwin_exception_section): Move to
the __TEXT segment.
* config/darwin.cc (darwin_emit_except_table_label): Align before
the exception table label.
* config/darwin.h (ASM_PREFERRED_EH_DATA_FORMAT): Use indirect PC-
relative 4byte relocs.

(cherry picked from commit 0fe7962afc7c01488432b98b6f442b24946a490d)

Diff:
---
 gcc/config/darwin-sections.def | 2 +-
 gcc/config/darwin.cc   | 1 +
 gcc/config/darwin.h| 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/config/darwin-sections.def b/gcc/config/darwin-sections.def
index 394ea165880..cdd5985cc36 100644
--- a/gcc/config/darwin-sections.def
+++ b/gcc/config/darwin-sections.def
@@ -157,7 +157,7 @@ DEF_SECTION (machopic_picsymbol_stub3_section, 
SECTION_NO_ANCHOR,
 
 /* Exception-related.  */
 DEF_SECTION (darwin_exception_section, SECTION_NO_ANCHOR,
-".section __DATA,__gcc_except_tab", 0)
+".section __TEXT,__gcc_except_tab", 0)
 DEF_SECTION (darwin_eh_frame_section, SECTION_NO_ANCHOR,
 ".section " EH_FRAME_SECTION_NAME ",__eh_frame"
 EH_FRAME_SECTION_ATTR, 0)
diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc
index 919ddb08704..8aa10153cde 100644
--- a/gcc/config/darwin.cc
+++ b/gcc/config/darwin.cc
@@ -2245,6 +2245,7 @@ darwin_emit_except_table_label (FILE *file)
 {
   char section_start_label[30];
 
+  fputs ("\t.p2align\t2\n", file);
   ASM_GENERATE_INTERNAL_LABEL (section_start_label, "GCC_except_table",
   except_table_label_num++);
   ASM_OUTPUT_LABEL (file, section_start_label);
diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index 6b81820072b..7026d200d59 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -1112,7 +1112,7 @@ enum machopic_addr_class {
 
 #undef ASM_PREFERRED_EH_DATA_FORMAT
 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL)  \
-  (((CODE) == 2 && (GLOBAL) == 1) \
+  (((CODE) == 2 && (GLOBAL) == 1) || ((CODE) == 0 && (GLOBAL) == 1) \
? (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4) : \
  ((CODE) == 1 || (GLOBAL) == 0) ? DW_EH_PE_pcrel : DW_EH_PE_absptr)


[gcc r12-10341] Darwin: Place global inits in the correct section.

2024-04-18 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:11d379f5ff8a5d3ce3ec4bc2f66471cab15c9ff7

commit r12-10341-g11d379f5ff8a5d3ce3ec4bc2f66471cab15c9ff7
Author: Iain Sandoe 
Date:   Fri Sep 1 09:04:13 2023 +0100

Darwin: Place global inits in the correct section.

This handles placement of global initializers into __TEXT,__StaticInit as 
used
by other platform toolchains.

Signed-off-by: Iain Sandoe 

gcc/ChangeLog:

* config/darwin-sections.def (static_init_section): Add the
__TEXT,__StaticInit section.
* config/darwin.cc (darwin_function_section): Use the static init
section for global initializers, to match other platform toolchains.

(cherry picked from commit 68dc3e94fd6bd395a8b343533485616dff3fc796)

Diff:
---
 gcc/config/darwin-sections.def | 2 ++
 gcc/config/darwin.cc   | 8 
 2 files changed, 10 insertions(+)

diff --git a/gcc/config/darwin-sections.def b/gcc/config/darwin-sections.def
index cdd5985cc36..af7bb404688 100644
--- a/gcc/config/darwin-sections.def
+++ b/gcc/config/darwin-sections.def
@@ -98,6 +98,8 @@ DEF_SECTION (mod_init_section, 0, ".mod_init_func", 0)
 DEF_SECTION (mod_term_section, 0, ".mod_term_func", 0)
 DEF_SECTION (constructor_section, 0, ".constructor", 0)
 DEF_SECTION (destructor_section, 0, ".destructor", 0)
+DEF_SECTION (static_init_section, SECTION_CODE,
+".section\t__TEXT,__StaticInit,regular,pure_instructions", 0)
 
 /* Objective-C ABI=0 (Original version) sections.  */
 DEF_SECTION (objc_class_section, 0, ".objc_class", 1)
diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc
index 8aa10153cde..68a692dc74e 100644
--- a/gcc/config/darwin.cc
+++ b/gcc/config/darwin.cc
@@ -3879,6 +3879,14 @@ darwin_function_section (tree decl, enum node_frequency 
freq,
   if (decl && DECL_SECTION_NAME (decl) != NULL)
 return get_named_section (decl, NULL, 0);
 
+  /* Intercept functions in global init; these are placed in separate sections.
+ FIXME: there should be some neater way to do this.  */
+  if (DECL_NAME (decl)
+  && (startswith (IDENTIFIER_POINTER (DECL_NAME (decl)), "_GLOBAL__sub_I")
+ || startswith (IDENTIFIER_POINTER (DECL_NAME (decl)),
+"__static_initialization_and_destruction")))
+return  darwin_sections[static_init_section];
+
   /* We always put unlikely executed stuff in the cold section.  */
   if (freq == NODE_FREQUENCY_UNLIKELY_EXECUTED)
 return (use_coal) ? darwin_sections[text_cold_coal_section]


[gcc r12-10342] Darwin: Partial reversion of r14-3648 (Inits Section).

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

commit r12-10342-ga732f63ebc032fbcd7740156d497472d16bdea50
Author: Iain Sandoe 
Date:   Sun Sep 10 14:48:42 2023 +0100

Darwin: Partial reversion of r14-3648 (Inits Section).

Although the Darwin ABI places both hot and cold partitions in the same
section (the linker can partition by name), this does not work with the
current dwarf2out implementation.

Since we do see global initialization code getting hot/cold splits, this
patch places the cold parts into text_cold, and keeps the hot part in
the correct Init section per ABI.

TODO: figure out a way to allow us to match the ABI fully.

gcc/ChangeLog:

* config/darwin.cc (darwin_function_section): Place unlikely
executed global init code into the standard cold section.

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

Diff:
---
 gcc/config/darwin.cc | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc
index 68a692dc74e..8f039de1d8d 100644
--- a/gcc/config/darwin.cc
+++ b/gcc/config/darwin.cc
@@ -3879,19 +3879,22 @@ darwin_function_section (tree decl, enum node_frequency 
freq,
   if (decl && DECL_SECTION_NAME (decl) != NULL)
 return get_named_section (decl, NULL, 0);
 
+  /* We always put unlikely executed stuff in the cold section; we have to put
+ this ahead of the global init section, since partitioning within a section
+ breaks some assumptions made in the DWARF handling.  */
+  if (freq == NODE_FREQUENCY_UNLIKELY_EXECUTED)
+return (use_coal) ? darwin_sections[text_cold_coal_section]
+ : darwin_sections[text_cold_section];
+
   /* Intercept functions in global init; these are placed in separate sections.
- FIXME: there should be some neater way to do this.  */
+ FIXME: there should be some neater way to do this, FIXME we should be able
+ to partition within a section.  */
   if (DECL_NAME (decl)
   && (startswith (IDENTIFIER_POINTER (DECL_NAME (decl)), "_GLOBAL__sub_I")
  || startswith (IDENTIFIER_POINTER (DECL_NAME (decl)),
 "__static_initialization_and_destruction")))
 return  darwin_sections[static_init_section];
 
-  /* We always put unlikely executed stuff in the cold section.  */
-  if (freq == NODE_FREQUENCY_UNLIKELY_EXECUTED)
-return (use_coal) ? darwin_sections[text_cold_coal_section]
- : darwin_sections[text_cold_section];
-
   /* If we have LTO *and* feedback information, then let LTO handle
  the function ordering, it makes a better job (for normal, hot,
  startup and exit - hence the bailout for cold above).  */


[gcc r12-10343] Darwin: Check as for .build_version support and use it if available.

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

commit r12-10343-gda939fb65affbb91424a8b3582dbf643122f37ca
Author: Iain Sandoe 
Date:   Tue Oct 17 11:10:27 2023 +0100

Darwin: Check as for .build_version support and use it if available.

This adds support for the minimum OS version data in assembler files.
At present, we have no mechanism to detect the SDK version in use, and
so that is omitted from build_versions.

We follow the implementation in clang, '.build_version' is only emitted
(where supported) for target macOS versions >= 10.14.  For earlier macOS
we fall back to using a '.macosx_version_min' directive.  This latter is
also emitted when the assembler supports it, but not build_version.

gcc/ChangeLog:

* config.in: Regenerate.
* config/darwin.cc (darwin_file_start): Add assembler directives
for the target OS version, where these are supported by the
assembler.
(darwin_override_options): Check for building >= macOS 10.14.
* configure: Regenerate.
* configure.ac: Check for assembler support of .build_version
directives.

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

Diff:
---
 gcc/config.in|  6 ++
 gcc/config/darwin.cc | 34 --
 gcc/configure| 33 +
 gcc/configure.ac | 10 +-
 4 files changed, 80 insertions(+), 3 deletions(-)

diff --git a/gcc/config.in b/gcc/config.in
index f3bdcb4cdda..52f496ca5de 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -604,6 +604,12 @@
 #endif
 
 
+/* Define if your macOS assembler supports .build_version directives */
+#ifndef USED_FOR_TARGET
+#undef HAVE_AS_MACOS_BUILD_VERSION
+#endif
+
+
 /* Define if the assembler understands -march=rv*_zifencei. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_AS_MARCH_ZIFENCEI
diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc
index 8f039de1d8d..926ba9dca62 100644
--- a/gcc/config/darwin.cc
+++ b/gcc/config/darwin.cc
@@ -3034,7 +3034,35 @@ darwin_asm_output_dwarf_offset (FILE *file, int size, 
const char * lab,
 void
 darwin_file_start (void)
 {
-  /* Nothing to do.  */
+#ifdef HAVE_AS_MMACOSX_VERSION_MIN_OPTION
+  /* This should not happen with a well-formed command line, but the user could
+ invoke cc1* directly without it.  */
+  if (!darwin_macosx_version_min)
+return;
+  /* This assumes that the version passed has been validated in the driver.  */
+  unsigned maj, min, tiny;
+  int count = sscanf (darwin_macosx_version_min, "%u.%u.%u", &maj, &min, 
&tiny);
+  if (count < 0)
+return;
+  if (count < 3)
+tiny = 0;
+  if (count < 2)
+min = 0;
+  const char *directive;
+#ifdef HAVE_AS_MACOS_BUILD_VERSION
+  /* We only handle macos, so far.  */
+  if (generating_for_darwin_version >= 18)
+directive = "build_version macos, ";
+  else
+#endif
+directive = "macosx_version_min ";
+  if (count > 2 && tiny != 0)
+fprintf (asm_out_file, "\t.%s %u, %u, %u\n", directive, maj, min, tiny);
+  else if (count > 1)
+fprintf (asm_out_file, "\t.%s %u, %u\n", directive, maj, min);
+  else
+ fprintf (asm_out_file, "\t.%s %u, 0\n", directive, maj);
+#endif
 }
 
 /* Called for the TARGET_ASM_FILE_END hook.
@@ -3256,7 +3284,9 @@ darwin_override_options (void)
   /* Keep track of which (major) version we're generating code for.  */
   if (darwin_macosx_version_min)
 {
-  if (strverscmp (darwin_macosx_version_min, "10.7") >= 0)
+  if (strverscmp (darwin_macosx_version_min, "10.14") >= 0)
+   generating_for_darwin_version = 18;
+  else if (strverscmp (darwin_macosx_version_min, "10.7") >= 0)
generating_for_darwin_version = 11;
   else if (strverscmp (darwin_macosx_version_min, "10.6") >= 0)
generating_for_darwin_version = 10;
diff --git a/gcc/configure b/gcc/configure
index d62b03a75c9..f697874f2d8 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -26125,6 +26125,39 @@ $as_echo "#define HAVE_AS_MMACOSX_VERSION_MIN_OPTION 
1" >>confdefs.h
 
 fi
 
+if test x$gcc_cv_as_mmacosx_version_min = "xyes"; then
+   { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for 
.build_version" >&5
+$as_echo_n "checking assembler for .build_version... " >&6; }
+if ${gcc_cv_as_darwin_build_version+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  gcc_cv_as_darwin_build_version=no
+  if test x$gcc_cv_as != x; then
+$as_echo ' .build_version macos, 10, 14 sdk_version 10, 14' > conftest.s
+if { ac_try='$gcc_cv_as $gcc_cv_as_flags -mmacosx-version-min=10.14 -o 
conftest.o conftest.s >&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+then
+   gcc_cv_as_darwin_build_version=yes
+else
+

[gcc r14-10030] Fortran: Fix ICE and clear incorrect error messages [PR114739]

2024-04-18 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:e243d0feafa533141ef7e23820d5cc60cf33204a

commit r14-10030-ge243d0feafa533141ef7e23820d5cc60cf33204a
Author: Paul Thomas 
Date:   Thu Apr 18 18:07:25 2024 +0100

Fortran: Fix ICE and clear incorrect error messages [PR114739]

2024-04-18  Paul Thomas  

gcc/fortran
PR fortran/114739
* primary.cc (gfc_match_varspec): Check for default type before
checking for derived types with the right component name.

gcc/testsuite/
PR fortran/114739
* gfortran.dg/pr114739.f90: New test.
* gfortran.dg/derived_comp_array_ref_8.f90: Add 'implicit none'
for consistency with expected error message.
* gfortran.dg/nullify_4.f90: ditto
* gfortran.dg/pointer_init_6.f90: ditto
* gfortran.dg/pr107397.f90: ditto
* gfortran.dg/pr88138.f90: ditto

Diff:
---
 gcc/fortran/primary.cc |  9 +
 gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90 |  1 +
 gcc/testsuite/gfortran.dg/nullify_4.f90|  1 +
 gcc/testsuite/gfortran.dg/pointer_init_6.f90   |  2 +-
 gcc/testsuite/gfortran.dg/pr107397.f90 |  1 +
 gcc/testsuite/gfortran.dg/pr114739.f90 | 11 +++
 gcc/testsuite/gfortran.dg/pr88138.f90  |  1 +
 7 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index 5dd6875a4a6..606e84432be 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -2236,6 +2236,15 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, 
bool sub_flag,
   match mm;
   old_loc = gfc_current_locus;
   mm = gfc_match_name (name);
+
+  /* Check to see if this has a default complex.  */
+  if (sym->ts.type == BT_UNKNOWN && tgt_expr == NULL
+ && gfc_get_default_type (sym->name, sym->ns)->type != BT_UNKNOWN)
+   {
+ gfc_set_default_type (sym, 0, sym->ns);
+ primary->ts = sym->ts;
+   }
+
   /* This is a usable inquiry reference, if the symbol is already known
 to have a type or no derived types with a component of this name
 can be found.  If this was an inquiry reference with the same name
diff --git a/gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90 
b/gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90
index 739f4adfb78..22dfdc668a6 100644
--- a/gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90
+++ b/gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90
@@ -2,6 +2,7 @@
 !
 ! PR fortran/52325
 !
+implicit none
 real :: f
 cc%a = 5 ! { dg-error "Symbol 'cc' at .1. has no IMPLICIT type" }
 f%a = 5  ! { dg-error "Unexpected '%' for nonderived-type variable 'f' at" }
diff --git a/gcc/testsuite/gfortran.dg/nullify_4.f90 
b/gcc/testsuite/gfortran.dg/nullify_4.f90
index 0fd5056ee07..240110fabf8 100644
--- a/gcc/testsuite/gfortran.dg/nullify_4.f90
+++ b/gcc/testsuite/gfortran.dg/nullify_4.f90
@@ -3,6 +3,7 @@
 !
 ! Check error recovery; was crashing before.
 !
+implicit none
 real, pointer :: ptr
 nullify(ptr, mesh%coarser) ! { dg-error "Symbol 'mesh' at .1. has no IMPLICIT 
type" }
 end
diff --git a/gcc/testsuite/gfortran.dg/pointer_init_6.f90 
b/gcc/testsuite/gfortran.dg/pointer_init_6.f90
index 3abad4ae179..477626e66bb 100644
--- a/gcc/testsuite/gfortran.dg/pointer_init_6.f90
+++ b/gcc/testsuite/gfortran.dg/pointer_init_6.f90
@@ -21,7 +21,7 @@ end module m1
 
 
 module m2
-
+ implicit none
  type :: t
procedure(s), pointer, nopass :: ppc
  end type
diff --git a/gcc/testsuite/gfortran.dg/pr107397.f90 
b/gcc/testsuite/gfortran.dg/pr107397.f90
index fd59bf16007..f77b4b00d00 100644
--- a/gcc/testsuite/gfortran.dg/pr107397.f90
+++ b/gcc/testsuite/gfortran.dg/pr107397.f90
@@ -1,6 +1,7 @@
 !{ dg-do compile }
 !
 program p
+  implicit none
   type t
 real :: a = 1.0
   end type
diff --git a/gcc/testsuite/gfortran.dg/pr114739.f90 
b/gcc/testsuite/gfortran.dg/pr114739.f90
new file mode 100644
index 000..eb82cb3f65b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr114739.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! The fix here was triggered by an ICE prior to r14-9489-g3fd46d859cda10
+! Before that gfortran gave an incorrect "no implicit type" error for all
+! three statements.
+program main
+  implicit complex(z)
+  implicit character(c)
+  z2%re = 1.
+  z2%im = 2.
+  print *, z2, c%kind
+end
diff --git a/gcc/testsuite/gfortran.dg/pr88138.f90 
b/gcc/testsuite/gfortran.dg/pr88138.f90
index c4019a6ca2e..f1130cf2bab 100644
--- a/gcc/testsuite/gfortran.dg/pr88138.f90
+++ b/gcc/testsuite/gfortran.dg/pr88138.f90
@@ -1,5 +1,6 @@
 ! { dg-do compile }
 program p
+   implicit none
type t
   character :: c = 'c'
end type


[gcc r14-10031] Add nios2*-*-* to the list of obsolete targets

2024-04-18 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:e498ba92355881a91f271860f9de359d913e5a68

commit r14-10031-ge498ba92355881a91f271860f9de359d913e5a68
Author: Sandra Loosemore 
Date:   Mon Apr 8 14:36:08 2024 +

Add nios2*-*-* to the list of obsolete targets

This patch marks the nios2*-*-* targets obsolete in GCC 14.  Intel has
EOL'ed this architecture and the maintainers no longer have access to
hardware for testing.  While the port is still in reasonably good
shape at this time, no further testing or updates are planned.

gcc/
* config.gcc: Add nios2*-*-* to the list of obsoleted targets.

contrib/
* config-list.mk (LIST): --enable-obsolete for nios2*-*-*.

Diff:
---
 contrib/config-list.mk | 3 ++-
 gcc/config.gcc | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/contrib/config-list.mk b/contrib/config-list.mk
index 16df66f0fc6..f282cd95c8d 100644
--- a/contrib/config-list.mk
+++ b/contrib/config-list.mk
@@ -78,7 +78,8 @@ LIST = \
   moxie-uclinux moxie-rtems \
   msp430-elf msp430-elfbare \
   nds32le-elf nds32be-elf \
-  nios2-elf nios2-linux-gnu nios2-rtems \
+  nios2-elfOPT-enable-obsolete nios2-linux-gnuOPT-enable-obsolete \
+  nios2-rtemsOPT-enable-obsolete \
   nvptx-none \
   or1k-elf or1k-linux-uclibc or1k-linux-musl or1k-rtems \
   pdp11-aout \
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 5df3c52f8e9..029ad1f1f08 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -274,6 +274,7 @@ esac
 case ${target}${target_min} in
 *-*-solaris2.11.[0-3]* \
| ia64*-*-* \
+   | nios2*-*-*\
  )
 if test "x$enable_obsolete" != xyes; then
   echo "*** Configuration ${target}${target_min} is obsolete." >&2


[gcc r14-10033] [vxworks] avoid mangling __STDC_VERSION_LIMITS_H__

2024-04-18 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:694fa3717a908317e895543d949eb7180911615a

commit r14-10033-g694fa3717a908317e895543d949eb7180911615a
Author: Alexandre Oliva 
Date:   Fri Apr 19 02:52:21 2024 -0300

[vxworks] avoid mangling __STDC_VERSION_LIMITS_H__

The mangling of the macro name that guards limits.h from reinclusion
was mangling a c23-required macro as well.  Make the edit pattern
stricter.


for  gcc/ChangeLog

* config/t-vxworks (vxw-glimits.h): Don't mangle c23-required
__STDC_VERSION_LIMITS_H__ define.

Diff:
---
 gcc/config/t-vxworks | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/t-vxworks b/gcc/config/t-vxworks
index b89350c3c70..6063943e346 100644
--- a/gcc/config/t-vxworks
+++ b/gcc/config/t-vxworks
@@ -57,7 +57,7 @@ T_GLIMITS_H = vxw-glimits.h
 
 vxw-glimits.h: $(srcdir)/glimits.h
ID=`echo $(BASEVER_c) | sed -e 's/\./_/g'` && \
-   sed -e "s/_LIMITS_H__/_LIMITS_H__$${ID}_/" < $< > $@T
+   sed -e "s/_LIMITS_H___/_LIMITS_H__$${ID}_/" < $< > $@T
mv $@T $@
 
 # Arrange to "provide" a tailored version of stdint-gcc.h


[gcc r14-10034] libgcc: Another __divmodbitint4 bug fix [PR114762]

2024-04-18 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:36f4c8a9ac8f71fc21fcb169c7913e8fef30d15c

commit r14-10034-g36f4c8a9ac8f71fc21fcb169c7913e8fef30d15c
Author: Jakub Jelinek 
Date:   Fri Apr 19 08:44:54 2024 +0200

libgcc: Another __divmodbitint4 bug fix [PR114762]

The following testcase is miscompiled because the code to decrement
vn on negative value with all ones in most significant limb (even partial)
and 0 in most significant bit of the second most significant limb doesn't
take into account the case where all bits below the most significant limb
are zero.  This has been a problem both in the version before yesterday's
commit where it has been done only if un was one shorter than vn before this
decrement, and is now problem even more often when it is done earlier.
When we decrement vn in such case and negate it, we end up with all 0s in
the v2 value, so have both the problems with UB on __builtin_clz* and the
expectations of the algorithm that the divisor has most significant bit set
after shifting, plus when the decremented vn is 1 it can SIGFPE on division
by zero even when it is not division by zero etc.  Other values shouldn't
get 0 in the new most significant limb after negation, because the
bitint_reduce_prec canonicalization should reduce prec if the second most
significant limb is all ones and if that limb is all zeros, if at least
one limb below it is non-zero, carry in will make it non-zero.

The following patch fixes it by checking if at least one bit below the
most significant limb is non-zero, in that case it decrements, otherwise
it will do nothing (but e.g. for the un < vn case that also means the
divisor is large enough that the result should be q 0 r u).

2024-04-18  Jakub Jelinek  

PR libgcc/114762
* libgcc2.c (__divmodbitint4): Perform the decrement on negative
v with most significant limb all ones and the second least
significant limb with most significant bit clear always, regardless 
of
un < vn.

* gcc.dg/torture/bitint-70.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/torture/bitint-70.c | 22 ++
 libgcc/libgcc2.c | 13 ++---
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/bitint-70.c 
b/gcc/testsuite/gcc.dg/torture/bitint-70.c
new file mode 100644
index 000..2d693bb5849
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-70.c
@@ -0,0 +1,22 @@
+/* PR libgcc/114762 */
+/* { dg-do run { target bitint } } */
+/* { dg-options "-std=c23" } */
+/* { dg-skip-if "" { ! run_expensive_tests }  { "*" } { "-O0" "-O2" } } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
+
+#if __BITINT_MAXWIDTH__ >= 255
+__attribute__((__noipa__)) signed _BitInt(255)
+foo (signed _BitInt(255) a, signed _BitInt(65) b)
+{
+  return a / b;
+}
+#endif
+
+int
+main ()
+{
+#if __BITINT_MAXWIDTH__ >= 255
+  if (foo (1, -0xwb - 1wb))
+__builtin_abort ();
+#endif
+}
diff --git a/libgcc/libgcc2.c b/libgcc/libgcc2.c
index 120d071a168..3fcb85c5b92 100644
--- a/libgcc/libgcc2.c
+++ b/libgcc/libgcc2.c
@@ -1715,11 +1715,18 @@ __divmodbitint4 (UBILtype *q, SItype qprec,
   && vn > 1
   && (Wtype) v[BITINT_END (1, vn - 2)] >= 0)
 {
-  vp = 0;
-  --vn;
+  /* Unless all bits below the most significant limb are zero.  */
+  SItype vn2;
+  for (vn2 = vn - 2; vn2 >= 0; --vn2)
+   if (v[BITINT_END (vn - 1 - vn2, vn2)])
+ {
+   vp = 0;
+   --vn;
 #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
-  ++v;
+   ++v;
 #endif
+   break;
+ }
 }
   if (__builtin_expect (un < vn, 0))
 {


[gcc r14-10035] rtlanal: Fix set_noop_p for volatile loads or stores [PR114768]

2024-04-18 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:9f295847a9c32081bdd0fe908ffba58e830a24fb

commit r14-10035-g9f295847a9c32081bdd0fe908ffba58e830a24fb
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.

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 d38455bc559..4158a531bdd 100644
--- a/gcc/rtlanal.cc
+++ b/gcc/rtlanal.cc
@@ -1637,12 +1637,15 @@ set_noop_p (const_rtx set)
 return true;
 
   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..2075f0d6b82
--- /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" { target { ! { nvptx*-*-* } 
} } } } */
+
+void
+foo (int *p)
+{
+  *p = *(volatile int *) p;
+}