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

2024-04-18 Thread Alexandre Oliva
On Apr 16, 2024, Alexandre Oliva  wrote:

>   * testsuite/20_util/to_chars/float128-c++23.cc: Xfail run on
>   aarch64-vxworks.

FTR, here's the fixed ChangeLog entry I'm putting in: (s/-/_/)

* testsuite/20_util/to_chars/float128_c++23.cc: Xfail run on
aarch64-vxworks.

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity
Excluding neuro-others for not behaving ""normal"" is *not* inclusive


Re: [PATCH] [testsuite] introduce strndup effective target

2024-04-18 Thread Alexandre Oliva
On Apr 16, 2024, Alexandre Oliva  wrote:

>   * 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.

These hunks were missing from the patch I posted, sorry.  I goofed when
resolving the conflicts because the tests had been modified after
gcc-13.  I hope the intent was clear from the ChangeLog entry.
Here they are.

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 ffa59985024f5..76b4f704fed9c 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-object-size-2.c
index fff32da7aea14..cb757a8d699cf 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-2.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-2.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-2.c"
diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-3.c 
b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-3.c
index ac223d67b10a4..8a12f023f27bc 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-3.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-3.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-3.c"
diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-4.c 
b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-4.c
index fdf4284ae1158..0efc2d9858422 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-4.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-4.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-4.c"

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity
Excluding neuro-others for not behaving ""normal"" is *not* inclusive


Re: [PATCH] [testsuite] [arm] accept empty init for bfloat16

2024-04-18 Thread Alexandre Oliva
On Apr 16, 2024, Mike Stump  wrote:

> Indeed, I kinda expect coverage already for that feature in
> another test case.

*nod*, jsm added gcc.dg/c11-empty-init-[123].c (and more) in the patch
that implemented this c23 feature.

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity
Excluding neuro-others for not behaving ""normal"" is *not* inclusive


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

2024-04-18 Thread Richard Earnshaw (lists)
On 18/04/2024 11:11, Tamar Christina wrote:
> Hi All,
> 
> 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 (, , sizeof(double));
>y = y | (1UL << 63);
>memcpy (, , 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.
> 
> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
> 
> Ok for master?
> 
> Thanks,
> Tamar
> 
> 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 --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
> index 
> 385a669b9b3c31cc9108a660e881b9091c71fc7c..dbde066f7478bec51a8703b017ea553aa98be309
>  100644
> --- a/gcc/config/aarch64/aarch64.md
> +++ b/gcc/config/aarch64/aarch64.md
> @@ -4811,7 +4811,7 @@ (define_insn "3"
>""
>{@ [ 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 @@ (define_expand "copysign3"
> (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_elt)))
>  {
> -  emit_insn (gen_ior3 (
> - lowpart_subreg (int_mode, operands[0], mode),
> - lowpart_subreg (int_mode, operands[1], mode), bitmask));
> +  rtx v_bitmask
> + = force_reg (V2mode,
> +  gen_const_vec_duplicate (V2mode,
> +   signbit_const));
> +
> +  emit_insn (gen_iorv23 (
> + lowpart_subreg (V2mode, operands[0], mode),
> + lowpart_subreg 

Re: [PATCH] libgcc: Fix up __divmodbitint4 [PR114755]

2024-04-18 Thread Jakub Jelinek
On Thu, Apr 18, 2024 at 11:25:43AM +0200, Christophe Lyon wrote:
> On Thu, 18 Apr 2024 at 09:37, Jakub Jelinek  wrote:
> > 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).
> 
> Just curious: could this have been caught by ubsan? (I don't know if
> it knows about clz)

ubsan does instrument clz, I don't remember right now if even libgcc is
built with -fsanitize=undefined during bootstrap-ubsan, if it is, it
probably should (but we didn't have this test in the testsuite).

Jakub



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

2024-04-18 Thread Tamar Christina
Hi All,

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 (, , sizeof(double));
   y = y | (1UL << 63);
   memcpy (, , 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.

Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.

Ok for master?

Thanks,
Tamar

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 --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index 
385a669b9b3c31cc9108a660e881b9091c71fc7c..dbde066f7478bec51a8703b017ea553aa98be309
 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -4811,7 +4811,7 @@ (define_insn "3"
   ""
   {@ [ 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 @@ (define_expand "copysign3"
(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_elt)))
 {
-  emit_insn (gen_ior3 (
-   lowpart_subreg (int_mode, operands[0], mode),
-   lowpart_subreg (int_mode, operands[1], mode), bitmask));
+  rtx v_bitmask
+   = force_reg (V2mode,
+gen_const_vec_duplicate (V2mode,
+ signbit_const));
+
+  emit_insn (gen_iorv23 (
+   lowpart_subreg (V2mode, operands[0], mode),
+   lowpart_subreg (V2mode, operands[1], mode),
+   v_bitmask));
   DONE;
 }
 
+  machine_mode int_mode = mode;
+  rtx bitmask = gen_reg_rtx (int_mode);
+  emit_move_insn (bitmask, signbit_const);
   operands[2] = force_reg (mode, operands[2]);
   emit_insn (gen_copysign3_insn (operands[0], operands[1], operands[2],
 

[PATCH v2] gcc-14: Add Ada changes

2024-04-18 Thread Marc Poulhiès
Co-authored-by: Fernando Oleo Blanco 
---
Hello Fernando,

Thanks again for your changes. After consulting other colleagues, I'm proposing 
this revised version.
Does that look ok to you?

As it was simpler I've created a new commit with a Co-authored-by line, but can 
easily change that if you prefer.

Marc

 htdocs/gcc-14/changes.html | 69 +-
 1 file changed, 68 insertions(+), 1 deletion(-)

diff --git a/htdocs/gcc-14/changes.html b/htdocs/gcc-14/changes.html
index b4c602a5..ca2ee1eb 100644
--- a/htdocs/gcc-14/changes.html
+++ b/htdocs/gcc-14/changes.html
@@ -204,7 +204,74 @@ a work-in-progress.
 
 New Languages and Language specific improvements
 
-
+Ada
+
+
+  New implementation-defined aspects and pragmas:
+
+  https://gcc.gnu.org/onlinedocs/gnat_rm/Aspect-Local_005fRestrictions.html;>Local_Restrictions,
+  which specifies that a particular subprogram does not violate one or more
+  local restrictions, nor can it call a subprogram that is not subject to
+  the same requirements.
+  https://gcc.gnu.org/onlinedocs/gnat_rm/Pragma-User_005fAspect_005fDefinition.html;>User_Aspect_Definition
+  and https://gcc.gnu.org/onlinedocs/gnat_rm/Aspect-User_005fAspect.html;>User_Aspect,
+  which provide a mechanism for avoiding textual duplication if some set of
+  aspect specifications is needed in multiple places.
+
+  
+  New implementation-defined aspects and pragmas for verification of the
+  SPARK 2014 subset of Ada:
+
+  https://gcc.gnu.org/onlinedocs/gnat_rm/Aspect-Always_005fTerminates.html;>Always_Terminates,
+  which provides a condition for a subprogram to necessarily complete
+  (either return normally or raise an exception).
+  https://gcc.gnu.org/onlinedocs/gnat_rm/Aspect-Ghost_005fPredicate.html;>Ghost_Predicate,
+  which introduces a subtype predicate that can reference Ghost entities.
+  
+  https://gcc.gnu.org/onlinedocs/gnat_rm/Aspect-Exceptional_005fCases.html;>Exceptional_Cases,
+  which lists exceptions that might be propagated by the subprogram with
+  side effects in the context of its precondition and associates them with 
a
+  specific postcondition.
+  
+  https://gcc.gnu.org/onlinedocs/gnat_rm/Aspect-Side_005fEffects.html;>Side_Effects,
+  which indicates that a function should be handled like a procedure with
+  respect to parameter modes, Global contract, exceptional contract and
+  termination: it may have output parameters, write global variables, raise
+  exceptions and not terminate.
+
+  
+  The new attributes and contracts have been applied to the relevant parts
+  of the Ada runtime library, which has been subsequently proven to be correct
+  with SPARK 2014.
+  Initial support for the
+  https://www.cl.cam.ac.uk/research/security/ctsrd/cheri/;>CHERI
+  architecture.
+  Support for the LoongArch architecture.
+  Support for vxWorks 7 Cert RTP has been removed.
+  Additional hardening improvements. For more information reltated to
+hardening options, refer to
+the https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fharden-compares;>GCC
+Instrumentation Options and
+the https://gcc.gnu.org/onlinedocs/gnat_rm/Security-Hardening-Features.html;>GNAT
+Reference Manual, Security and Hardening Features.
+  
+  Improve style checking for redundant parentheses
+  with https://gcc.gnu.org/onlinedocs/gnat_ugn/Style-Checking.html#index--gnatyz-_0028gcc_0029;>-gnatyz
+  New
+  switch https://gcc.gnu.org/onlinedocs/gnat_ugn/Alphabetical-List-of-All-Switches.html#index--gnateH-_0028gcc_0029;>-gnateH
+  to force reverse Bit_Order threshold to 64.
+  Experimental features:
+https://gcc.gnu.org/onlinedocs/gnat_rm/Pragma-Storage_005fModel.html;>Storage
+Model: this feature proposes to redesign the concepts of Storage Pools
+into a more efficient model allowing higher performances and easier
+integration with low footprint embedded run-times.
+https://gcc.gnu.org/onlinedocs/gnat_rm/String-interpolation.html;>String
+Interpolation: allows for easier string formatting.
+  
+  Bug fixes, refactorization and streamlining of the finalization machinery
+  for declared objects.
+  Further clean up and improvements to the GNAT code.
+
 
 
 
-- 
2.43.2



Re: [PATCH] libgcc: Fix up __divmodbitint4 [PR114755]

2024-04-18 Thread Christophe Lyon
On Thu, 18 Apr 2024 at 09:37, Jakub Jelinek  wrote:
>
> Hi!
>
> 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).

Just curious: could this have been caught by ubsan? (I don't know if
it knows about clz)

Thanks,

Christophe

>
> 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.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, plus tested with
> make check-gcc -j32 -k GCC_TEST_RUN_EXPENSIVE=1 
> RUNTESTFLAGS="GCC_TEST_RUN_EXPENSIVE=1 dg.exp='*bitint* pr112673.c 
> builtin-stdc-bit-*.c pr112566-2.c pr112511.c' dg-torture.exp=*bitint* 
> dfp.exp=*bitint*"
> on aarch64-linux, ok for trunk?
>
> 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.
>
> --- libgcc/libgcc2.c.jj 2024-03-21 13:07:43.629886730 +0100
> +++ libgcc/libgcc2.c2024-04-17 19:00:55.453691368 +0200
> @@ -1705,69 +1705,62 @@ __divmodbitint4 (UBILtype *q, SItype qpr
>USItype rn = ((USItype) rprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
>USItype up = auprec % W_TYPE_SIZE;
>USItype vp = avprec % W_TYPE_SIZE;
> +  /* 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)
> +{
> +  vp = 0;
> +  --vn;
> +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
> +  ++v;
> +#endif
> +}
>if (__builtin_expect (un < vn, 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;
> +  /* 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__
> - ++v;
> +  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 (!rn)
> +   return;
> +  if (up)
> {
> - /* q is 0 and r is u.  */
> - if (q)
> -   __builtin_memset (q, 0, qn * sizeof (UWtype));
> - if (r == NULL)
> + if (uprec > 0)
> +   *r = *u & (((UWtype) 1 << up) - 1);
> + else
> +   *r = *u | ((UWtype) -1 << up);
> + r += BITINT_INC;
> + if (!--rn)
> 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 += 

Re: [PATCH, rs6000] Use bcdsub. instead of bcdadd. for bcd invalid number checking

2024-04-18 Thread Segher Boessenkool
On Thu, Apr 18, 2024 at 11:14:42AM +0800, Kewen.Lin wrote:
> on 2024/4/18 10:01, HAO CHEN GUI wrote:
> >   This patch replace bcdadd. with bcdsub. for bcd invalid number checking.
> > bcdadd on two same numbers might cause overflow which also set
> > overflow/invalid bit so that we can't distinguish it's invalid or overflow.
> > The bcdsub doesn't have the problem as subtracting on two same number never
> > causes overflow.
> > 
> >   Bootstrapped and tested on powerpc64-linux BE and LE with no
> > regressions. Is it OK for the trunk?
> 
> Considering that this issue affects some basic functionality of bcd bifs
> and the fix itself is simple and very safe, OK for trunk, thanks for fixing!

Yup.  If a number X is invalid the X-X calculation might set the
overflow flag as well, but we cannot see that difference at all anyway,
it always has set the invalid flag after all.

Thanks!


Segher


[PATCH] libgfortran: Fix up the autoreconf warnings.

2024-04-18 Thread Iain Sandoe
@tschwinge since he did quite a bit of work on getting autoreconf to
work in the GCC-13 cycle.

This does not address the issues with regenerating lib code, but it
does make things somewhat smoother for cases where the updates are
only in Makefile.am, configure.ac or libtool.m4 for example.

It is based on a patch I've been using on the release branches for
Darwin (written because I wasted a day on a warning missed among the
wall of output).

You should now be able to run "autoreconf -fv" in the libgfortran
directory with only informational output (no warnings).

So far only tested very lightly on trunk - but posting early in case
it helps the way forward.

thanks
Iain

--- 8< ---

This means using sub-dirs and amending some of the recipes accordingly.

libgfortran/ChangeLog:

* Makefile.am: Use sub-dirs, amend recipies accordingly.
* Makefile.in: Regenerate.

Signed-off-by: Iain Sandoe 
---
 libgfortran/Makefile.am | 1431 +++---
 libgfortran/Makefile.in | 9848 ++-
 2 files changed, 4126 insertions(+), 7153 deletions(-)

diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am
index 9f8a4f69863..8bef1729219 100644
--- a/libgfortran/Makefile.am
+++ b/libgfortran/Makefile.am
@@ -1,5 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 
+AUTOMAKE_OPTIONS = foreign subdir-objects
 
 ACLOCAL_AMFLAGS = -I .. -I ../config
 
@@ -239,629 +240,629 @@ runtime/stop.c
 endif
 
 i_all_c= \
-$(srcdir)/generated/all_l1.c \
-$(srcdir)/generated/all_l2.c \
-$(srcdir)/generated/all_l4.c \
-$(srcdir)/generated/all_l8.c \
-$(srcdir)/generated/all_l16.c
+generated/all_l1.c \
+generated/all_l2.c \
+generated/all_l4.c \
+generated/all_l8.c \
+generated/all_l16.c
 
 i_any_c= \
-$(srcdir)/generated/any_l1.c \
-$(srcdir)/generated/any_l2.c \
-$(srcdir)/generated/any_l4.c \
-$(srcdir)/generated/any_l8.c \
-$(srcdir)/generated/any_l16.c
+generated/any_l1.c \
+generated/any_l2.c \
+generated/any_l4.c \
+generated/any_l8.c \
+generated/any_l16.c
 
 i_bessel_c= \
-$(srcdir)/generated/bessel_r4.c \
-$(srcdir)/generated/bessel_r8.c \
-$(srcdir)/generated/bessel_r10.c \
-$(srcdir)/generated/bessel_r16.c \
-$(srcdir)/generated/bessel_r17.c
+generated/bessel_r4.c \
+generated/bessel_r8.c \
+generated/bessel_r10.c \
+generated/bessel_r16.c \
+generated/bessel_r17.c
 
 i_count_c= \
-$(srcdir)/generated/count_1_l.c \
-$(srcdir)/generated/count_2_l.c \
-$(srcdir)/generated/count_4_l.c \
-$(srcdir)/generated/count_8_l.c \
-$(srcdir)/generated/count_16_l.c
+generated/count_1_l.c \
+generated/count_2_l.c \
+generated/count_4_l.c \
+generated/count_8_l.c \
+generated/count_16_l.c
 
 i_iall_c= \
-$(srcdir)/generated/iall_i1.c \
-$(srcdir)/generated/iall_i2.c \
-$(srcdir)/generated/iall_i4.c \
-$(srcdir)/generated/iall_i8.c \
-$(srcdir)/generated/iall_i16.c
+generated/iall_i1.c \
+generated/iall_i2.c \
+generated/iall_i4.c \
+generated/iall_i8.c \
+generated/iall_i16.c
 
 i_iany_c= \
-$(srcdir)/generated/iany_i1.c \
-$(srcdir)/generated/iany_i2.c \
-$(srcdir)/generated/iany_i4.c \
-$(srcdir)/generated/iany_i8.c \
-$(srcdir)/generated/iany_i16.c
+generated/iany_i1.c \
+generated/iany_i2.c \
+generated/iany_i4.c \
+generated/iany_i8.c \
+generated/iany_i16.c
 
 i_iparity_c= \
-$(srcdir)/generated/iparity_i1.c \
-$(srcdir)/generated/iparity_i2.c \
-$(srcdir)/generated/iparity_i4.c \
-$(srcdir)/generated/iparity_i8.c \
-$(srcdir)/generated/iparity_i16.c
+generated/iparity_i1.c \
+generated/iparity_i2.c \
+generated/iparity_i4.c \
+generated/iparity_i8.c \
+generated/iparity_i16.c
 
 i_findloc0_c= \
-$(srcdir)/generated/findloc0_i1.c \
-$(srcdir)/generated/findloc0_i2.c \
-$(srcdir)/generated/findloc0_i4.c \
-$(srcdir)/generated/findloc0_i8.c \
-$(srcdir)/generated/findloc0_i16.c \
-$(srcdir)/generated/findloc0_r4.c \
-$(srcdir)/generated/findloc0_r8.c \
-$(srcdir)/generated/findloc0_r10.c \
-$(srcdir)/generated/findloc0_r16.c \
-$(srcdir)/generated/findloc0_r17.c \
-$(srcdir)/generated/findloc0_c4.c \
-$(srcdir)/generated/findloc0_c8.c \
-$(srcdir)/generated/findloc0_c10.c \
-$(srcdir)/generated/findloc0_c16.c \
-$(srcdir)/generated/findloc0_c17.c
+generated/findloc0_i1.c \
+generated/findloc0_i2.c \
+generated/findloc0_i4.c \
+generated/findloc0_i8.c \
+generated/findloc0_i16.c \
+generated/findloc0_r4.c \
+generated/findloc0_r8.c \
+generated/findloc0_r10.c \
+generated/findloc0_r16.c \
+generated/findloc0_r17.c \
+generated/findloc0_c4.c \
+generated/findloc0_c8.c \
+generated/findloc0_c10.c \
+generated/findloc0_c16.c \
+generated/findloc0_c17.c
 
 i_findloc0s_c= \
-$(srcdir)/generated/findloc0_s1.c \
-$(srcdir)/generated/findloc0_s4.c
+generated/findloc0_s1.c \
+generated/findloc0_s4.c
 
 i_findloc1_c= \
-$(srcdir)/generated/findloc1_i1.c \
-$(srcdir)/generated/findloc1_i2.c \
-$(srcdir)/generated/findloc1_i4.c \
-$(srcdir)/generated/findloc1_i8.c \
-$(srcdir)/generated/findloc1_i16.c \
-$(srcdir)/generated/findloc1_r4.c \
-$(srcdir)/generated/findloc1_r8.c \

Re: [PATCH] [vxworks] avoid mangling __STDC_VERSION_LIMITS_H__

2024-04-18 Thread Olivier Hainque



> On 16 Apr 2024, at 05:27, Alexandre Oliva  wrote:
> 
> 
> 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.
> 
> Regstrapped on x86_64-linux-gnu.  Also tested with gcc-13 on arm-,
> aarch64-, x86- and x86_64-vxworks7r2.  Ok to install?

Ok, thanks Alex.

Olivier

> for  gcc/ChangeLog
> 
>   * config/t-vxworks (vxw-glimits.h): Don't mangle c23-required
>   __STDC_VERSION_LIMITS_H__ define.
> ---
> 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 b89350c3c70f4..6063943e346e6 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
> 
> -- 
> Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
>   Free Software Activist   GNU Toolchain Engineer
> More tolerance and less prejudice are key for inclusion and diversity
> Excluding neuro-others for not behaving ""normal"" is *not* inclusive



Re: [PATCH] libstdc++: Support link chains in std::chrono::tzdb::locate_zone [PR114770]

2024-04-18 Thread Jonathan Wakely
On Thu, 18 Apr 2024 at 17:33, Jonathan Wakely wrote:
>
> This would fix the but,

*fix the bug

> how do people feel about it this close to the
> gcc-14 release?
>
> Tested x86_64-linux.



Re: [PATCH] [testsuite] introduce strndup effective target

2024-04-18 Thread Mike Stump
On Apr 18, 2024, at 4:32 AM, Alexandre Oliva  wrote:
> 
> On Apr 16, 2024, Alexandre Oliva  wrote:
> 
>>  * 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.
> 
> These hunks were missing from the patch I posted

No worries, thanks for all the hard work.


Re: [PATCH 0/3] Recover in-tree libiconv build support

2024-04-18 Thread Kévin Le Gouguec
Arsen Arsenović  writes:

> Evening!
>
> This patchset recovers support for building the toolchain tree with
> in-tree libiconv being used for host modules and gettext.  As spotted by
> Kévin Le Gouguec , I accidentally removed this
> functionality earlier.
>
> This patchset includes the patch sent as:
>
> https://inbox.sourceware.gcc-patches/20231221193243.368541-1-ar...@aarsen.me/
>
> ... and so, supersedes that patchset.
>
> For the in-tree case, the old patch functionality was restored and
> rebased on top of current iconv.m4.  Of course, this does not work for
> gettext, an out-of-tree lib depending on the in-tree libiconv, so, for
> that case, we needed to provide the right information to configure, and
> suppress logic in iconv.m4 using cache vars.
>
> Build-tested on arm64-apple-darwin21.6.0, and I intend to do further
> testing tomorrow.
>
> OK for trunk?  It would be good to get these patches into GCC 14.
>
> I apologize for being quite late with delivering these, I have,
> unfortunately, been busied by various external factors.  Hopefully, it
> is not too late yet.

FWIW, I apologize too for not taking a stab at the fix; on our end, we
pondered this briefly and figured we had no compelling reason to
continue relying on in-tree libiconv builds, so we tweaked our packaging
recipes to configure --with-libiconv-prefix and that was that.

Thanks for finding the time to work on this!


Re: [PATCH] [libstdc++] introduce --disable-compat-libstdcxx-abi

2024-04-18 Thread Alexandre Oliva
On Apr 16, 2024, Jonathan Wakely  wrote:

>> +dnl
>> +dnl Enable -Wabi=2 if not overridden by --disable-compat-libstdcxx-abi.
>> +dnl
>> +AC_DEFUN([GLIBCXX_ENABLE_WABI], [
>> +  # Default.
>> +  WARN_FLAGS_WABI=\ -Wabi=2
>> +  AC_MSG_CHECKING([for --disable-compat-libstdcxx-abi])
>> +  AC_ARG_ENABLE([compat-libstdcxx-abi],

> We have the GLIBCXX_ENABLE macro to simplify creating new --enable options.

*nod*.  There was some reason why I didn't use it at first.  Maybe it
can be used with the patch as it ended up.  Will revisit.

>> +AC_HELP_STRING([--disable-compat-libstdcxx-abi],
>> +  [Disable backward-compatibility ABI symbols)]),

> There's a stray ')' here.

Ugh, thanks

>> --- a/libstdc++-v3/doc/html/manual/configure.html
>> +++ b/libstdc++-v3/doc/html/manual/configure.html

> This should be in doc/xml/manual/configure.xml too, which is used to
> generate the HTML using docbook.

Oh, right.  Doh.  So much for grepping for an existing option and
jumping to edit the first match :-)

> The description here in the docs (and the name of the configure
> option) seem much too vague. Libstdc++ has dozens, probably hundreds,
> of "backward-compatibility ABI symbols", and this only affects touches
> a tiny handful of them. Just the aliases created automatically by the
> compiler for mangling changes, right?

Yeah.

I had used --disable-libstdcxx-Wabi at some point, maybe that's better.


FTR, we now have a binutils patch (thanks H.J.Lu) to address the
underlying problem, so we'll probably no longer need the workaround that
led me to propose this change.  I wonder if there's interest in keeping
it.  I'd be equally happy to make the adjustments, or to withdraw it (or
pretty much anything in between ;-).  WDYT?

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity
Excluding neuro-others for not behaving ""normal"" is *not* inclusive


[PATCH] libstdc++: Support link chains in std::chrono::tzdb::locate_zone [PR114770]

2024-04-18 Thread Jonathan Wakely
This would fix the but, how do people feel about it this close to the
gcc-14 release?

Tested x86_64-linux.

-- >8 --

Since 2022 the TZif format defined in the zic(8) man page has said that
links can refer to other links, rather than only referring to a zone.
This isn't supported by the C++20 spec, which assumes that the target()
for a chrono::time_zone_link always names a chrono::time_zone, not
another chrono::time_zone_link.

This hasn't been a problem until now, because there are no entries in
the tzdata file that chain links together. However, Debian Sid has
changed the target of the Asia/Chungking link from the Asia/Shanghai
zone to the Asia/Chongqing link, creating a link chain. The libstdc++
code is unable to handle this, so chrono::locate_zone("Asia/Chungking")
will fail with the tzdata.zi file from Debian Sid.

It seems likely that the C++ spec will need a change to allow link
chains, so that the original structure of the IANA database can be fully
represented by chrono::tzdb. The alternative would be for chrono::tzdb
to flatten all chains when loading the data, so that a link's target is
always a zone, but this means throwing away information present in the
tzdata.zi input file.

In anticipation of a change to the spec, this commit adds support for
chained links to libstdc++. When a name is found to be a link, we try to
find its target in the list of zones as before, but now if the target
isn't the name of a zone we don't fail. Instead we look for another link
with that name, and keep doing that until we reach the end of the chain
of links, and then look up the last target as a zone.

This new logic would get stuck in a loop if the tzdata.zi file is buggy
and defines a link chain that contains a cycle, e.g. two links that
refer to each other. To deal with that unlikely case, we use the
tortoise and hare algorithm to detect cycles in link chains, and throw
an exception if we detect a cycle. Cycles in links should never happen,
and it is expected that link chains will be short (if they occur at all)
and so the code is optimized for short chains without cycles. Longer
chains (four or more links) and cycles will do more work, but won't fail
to resolve a chain or get stuck in a loop.

libstdc++-v3/ChangeLog:

PR libstdc++/114770
* src/c++20/tzdb.cc (do_locate_zone): Support links that have
another link as their target.
* testsuite/std/time/tzdb/links.cc: New test.
---
 libstdc++-v3/src/c++20/tzdb.cc|  57 -
 libstdc++-v3/testsuite/std/time/tzdb/links.cc | 215 ++
 2 files changed, 268 insertions(+), 4 deletions(-)
 create mode 100644 libstdc++-v3/testsuite/std/time/tzdb/links.cc

diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc
index 639d1c440ba..c7c7cc9deee 100644
--- a/libstdc++-v3/src/c++20/tzdb.cc
+++ b/libstdc++-v3/src/c++20/tzdb.cc
@@ -1599,7 +1599,7 @@ namespace std::chrono
 const time_zone*
 do_locate_zone(const vector& zones,
   const vector& links,
-  string_view tz_name) noexcept
+  string_view tz_name)
 {
   // Lambda mangling changed between -fabi-version=2 and -fabi-version=18
   auto search = [](const Vec& v, string_view name) {
@@ -1610,13 +1610,62 @@ namespace std::chrono
return ptr;
   };
 
+  // Search zones first.
   if (auto tz = search(zones, tz_name))
return tz;
 
+  // Search links second.
   if (auto tz_l = search(links, tz_name))
-   return search(zones, tz_l->target());
+   {
+ // Handle the common case of a link that has a zone as the target.
+ if (auto tz = search(zones, tz_l->target())) [[likely]]
+   return tz;
 
-  return nullptr;
+ // Either tz_l->target() doesn't exist, or we have a chain of links.
+ // Use Floyd's cycle-finding algorithm to avoid infinite loops,
+ // at the cost of extra lookups. In the common case we expect a
+ // chain of links to be short so the loop won't run many times.
+ // In particular, the duplicate lookups to move the tortoise
+ // never happen unless the chain has four or more links.
+ // When a chain contains a cycle we do multiple duplicate lookups,
+ // but that case should never happen with correct tzdata.zi,
+ // so there's no need to optimize cycle detection.
+
+ const time_zone_link* tortoise = tz_l;
+ const time_zone_link* hare = search(links, tz_l->target());
+ while (hare)
+   {
+ // Chains should be short, so first check if it ends here:
+ if (auto tz = search(zones, hare->target())) [[likely]]
+   return tz;
+
+ // Otherwise follow the chain:
+ hare = search(links, hare->target());
+ if (!hare)
+   break;
+
+ // Again, first check if the chain ends at a zone here:
+ if (auto tz = 

[PATCH v1 0/6] Add DLL import/export implementation to AArch64

2024-04-18 Thread Evgeny Karpov
Hello,

This is the second patch series, following the first patch series which
introduced the aarch64-w64-mingw32 target.
https://gcc.gnu.org/pipermail/gcc-patches/2024-February/thread.html#646203
https://gcc.gnu.org/pipermail/gcc-patches/2024-March/thread.html#647128
https://gcc.gnu.org/pipermail/gcc-patches/2024-April/thread.html#649261

The patch series aims at the goal:
Extend the aarch64-w64-mingw32 C implementation to
cross-compile OpenSSL, OpenBLAS, FFmpeg, and libjpeg-turbo. All
packages successfully pass tests.

The changes in this patch series are focused on reusing functionality
for DLL import/export from ix86 in aarch64. The ix86 implementation
for expanding a SYMBOL into its corresponding dllimport symbol has
been moved to the mingw folder. Functions related to
dllimport/dllexport functionality have been renamed for reuse in the
AArch64 target.

This patch series is implemented on top of the first patch series which
has not been merged yet. It is currently awaiting the opening of GCC Stage1.
https://gcc.gnu.org/pipermail/gcc-patches/2024-April/thread.html#649261

Patchwork cannot verify this patch series. However, a link to Linaro CI will
be provided once the testing is complete.
A minimal regression test for building main targets can be found here:
https://github.com/Windows-on-ARM-Experiments/mingw-woarm64-build/actions/runs/8739609732

Regression test for all languages on x86_86-w64-mingw32 is in progress and 
will be also provided.

Known issues:
In order to compile FFmpeg, the optimization level should be reduced
from -O3 to -O2. The fix for this issue is planned to be delivered
in the third patch series.

Thank you for your review!

Coauthors: Zac Walker ,
Mark Harmstone   and
Ron Riddle 

Refactored, prepared, and validated by
Radek Barton  and
Evgeny Karpov 

Regards,
Evgeny


Evgeny Karpov (6):
  Move mingw_* declarations to the mingw folder
  Extract ix86 dllimport implementation to mingw
  Rename functions for reuse in AArch64
  aarch64: Add selectany attribute handling
  Adjust DLL import/export implementation for AArch64
  aarch64: Add DLL import/export to AArch64 target

 gcc/config.gcc  |   8 +-
 gcc/config/aarch64/aarch64-protos.h |   7 +-
 gcc/config/aarch64/aarch64.cc   |  42 -
 gcc/config/aarch64/cygming.h|  26 +++-
 gcc/config/i386/cygming.h   |   8 +-
 gcc/config/i386/i386-expand.cc  |   2 +-
 gcc/config/i386/i386-expand.h   |   2 +-
 gcc/config/i386/i386-protos.h   |  13 +-
 gcc/config/i386/i386.cc | 211 +++--
 gcc/config/mingw/mingw32.h  |   2 +-
 gcc/config/mingw/t-cygming  |   6 +
 gcc/config/mingw/winnt-dll.cc   | 233 
 gcc/config/mingw/winnt-dll.h|  26 
 gcc/config/mingw/winnt.cc   |   8 +-
 gcc/config/mingw/winnt.h|  34 
 15 files changed, 402 insertions(+), 226 deletions(-)
 create mode 100644 gcc/config/mingw/winnt-dll.cc
 create mode 100644 gcc/config/mingw/winnt-dll.h
 create mode 100644 gcc/config/mingw/winnt.h

-- 
2.25.1



[PATCH v1 4/6] aarch64: Add selectany attribute handling

2024-04-18 Thread Evgeny Karpov
This patch extends the aarch64 attributes list with the selectany
attribute for the aarch64-w64-mingw32 target and reuses the mingw
implementation to handle it.

* config/aarch64/aarch64.cc:
Extend the aarch64 attributes list.
* config/aarch64/cygming.h (SUBTARGET_ATTRIBUTE_TABLE):
Define the selectany attribute.
---
 gcc/config/aarch64/aarch64.cc | 5 -
 gcc/config/aarch64/cygming.h  | 3 +++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index c763a8a6298..19205927430 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -855,7 +855,10 @@ static const attribute_spec aarch64_gnu_attributes[] =
  NULL },
   { "Advanced SIMD type", 1, 1, false, true,  false, true,  NULL, NULL },
   { "SVE type",  3, 3, false, true,  false, true,  NULL, NULL 
},
-  { "SVE sizeless type",  0, 0, false, true,  false, true,  NULL, NULL }
+  { "SVE sizeless type",  0, 0, false, true,  false, true,  NULL, NULL },
+#ifdef SUBTARGET_ATTRIBUTE_TABLE
+  SUBTARGET_ATTRIBUTE_TABLE
+#endif
 };
 
 static const scoped_attribute_specs aarch64_gnu_attribute_table =
diff --git a/gcc/config/aarch64/cygming.h b/gcc/config/aarch64/cygming.h
index 0d048879311..76623153080 100644
--- a/gcc/config/aarch64/cygming.h
+++ b/gcc/config/aarch64/cygming.h
@@ -154,6 +154,9 @@ still needed for compilation.  */
 flag_stack_check = STATIC_BUILTIN_STACK_CHECK; \
   } while (0)
 
+#define SUBTARGET_ATTRIBUTE_TABLE \
+  { "selectany", 0, 0, true, false, false, false, \
+mingw_handle_selectany_attribute, NULL }
 
 #define SUPPORTS_ONE_ONLY 1
 
-- 
2.25.1



[gcc-13 PATCH 1/2] libstdc++: Fix libstdc++exp.a so it really does contain Filesystem TS symbols

2024-04-18 Thread Jonathan Wakely
In r14-3812-gb96b554592c5cb I claimed that libstdc++exp.a now contains
all the symbols from libstdc++fs.a as well as libstdc++_libbacktrace.a,
but that wasn't true. Only the symbols from the latter were added to
libstdc++exp.a, the Filesystem TS ones weren't. This seems to be because
libtool won't combine static libs that are going to be installed
separately. Because libstdc++fs.a is still installed, libtool decides it
shouldn't be included in libstdc++exp.a.

The solution is similar to what we already do for libsupc++.a: build two
static libs, libstdc++fs.a and libstdc++fsconvenience.a, where the
former is installed and the latter isn't. If we then tell libtool to
include the latter in libstdc++exp.a it will do as it's told.

libstdc++-v3/ChangeLog:

* src/experimental/Makefile.am: Use libstdc++fsconvenience.a
instead of libstdc++fs.a.
* src/experimental/Makefile.in: Regenerate.
* src/filesystem/Makefile.am: Build libstdc++fsconvenience.a as
well.
* src/filesystem/Makefile.in: Regenerate.

(cherry picked from commit abf40d2953639534af3428424f467adf3cb52177)
---
 libstdc++-v3/src/experimental/Makefile.am |  2 +-
 libstdc++-v3/src/experimental/Makefile.in |  4 +--
 libstdc++-v3/src/filesystem/Makefile.am   |  4 +++
 libstdc++-v3/src/filesystem/Makefile.in   | 37 +++
 4 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/libstdc++-v3/src/experimental/Makefile.am 
b/libstdc++-v3/src/experimental/Makefile.am
index 1c7cea7e846..c5a38d882c2 100644
--- a/libstdc++-v3/src/experimental/Makefile.am
+++ b/libstdc++-v3/src/experimental/Makefile.am
@@ -25,7 +25,7 @@ include $(top_srcdir)/fragment.am
 toolexeclib_LTLIBRARIES = libstdc++exp.la
 
 if ENABLE_FILESYSTEM_TS
-filesystem_lib = $(top_builddir)/src/filesystem/libstdc++fs.la
+filesystem_lib = $(top_builddir)/src/filesystem/libstdc++fsconvenience.la
 else
 filesystem_lib =
 endif
diff --git a/libstdc++-v3/src/experimental/Makefile.in 
b/libstdc++-v3/src/experimental/Makefile.in
index 6f6b742c1cf..c16083a7fc8 100644
--- a/libstdc++-v3/src/experimental/Makefile.in
+++ b/libstdc++-v3/src/experimental/Makefile.in
@@ -148,7 +148,7 @@ am__uninstall_files_from_dir = { \
   }
 am__installdirs = "$(DESTDIR)$(toolexeclibdir)"
 LTLIBRARIES = $(toolexeclib_LTLIBRARIES)
-@ENABLE_FILESYSTEM_TS_TRUE@am__DEPENDENCIES_1 = 
$(top_builddir)/src/filesystem/libstdc++fs.la
+@ENABLE_FILESYSTEM_TS_TRUE@am__DEPENDENCIES_1 = 
$(top_builddir)/src/filesystem/libstdc++fsconvenience.la
 @ENABLE_BACKTRACE_TRUE@am__DEPENDENCIES_2 = 
$(top_builddir)/src/libbacktrace/libstdc++_libbacktrace.la
 am__objects_1 = contract.lo
 am_libstdc__exp_la_OBJECTS = $(am__objects_1)
@@ -450,7 +450,7 @@ WARN_CXXFLAGS = \
 AM_CPPFLAGS = $(GLIBCXX_INCLUDES) $(CPPFLAGS)
 toolexeclib_LTLIBRARIES = libstdc++exp.la
 @ENABLE_FILESYSTEM_TS_FALSE@filesystem_lib = 
-@ENABLE_FILESYSTEM_TS_TRUE@filesystem_lib = 
$(top_builddir)/src/filesystem/libstdc++fs.la
+@ENABLE_FILESYSTEM_TS_TRUE@filesystem_lib = 
$(top_builddir)/src/filesystem/libstdc++fsconvenience.la
 @ENABLE_BACKTRACE_FALSE@backtrace_lib = 
 @ENABLE_BACKTRACE_TRUE@backtrace_lib = 
$(top_builddir)/src/libbacktrace/libstdc++_libbacktrace.la
 headers = 
diff --git a/libstdc++-v3/src/filesystem/Makefile.am 
b/libstdc++-v3/src/filesystem/Makefile.am
index d2e1fde3f13..55f309b5c15 100644
--- a/libstdc++-v3/src/filesystem/Makefile.am
+++ b/libstdc++-v3/src/filesystem/Makefile.am
@@ -22,7 +22,10 @@
 
 include $(top_srcdir)/fragment.am
 
+# Separate libstdc++fs.a to be installed.
 toolexeclib_LTLIBRARIES = libstdc++fs.la
+# Duplicate lib that is to be part of libstdc++exp.a
+noinst_LTLIBRARIES = libstdc++fsconvenience.la
 
 headers =
 
@@ -44,6 +47,7 @@ sources = \
 # vpath % $(top_srcdir)/src/filesystem
 
 libstdc__fs_la_SOURCES = $(sources)
+libstdc__fsconvenience_la_SOURCES = $(sources)
 
 # AM_CXXFLAGS needs to be in each subdirectory so that it can be
 # modified in a per-library or per-sub-library way.  Need to manually
diff --git a/libstdc++-v3/src/filesystem/Makefile.in 
b/libstdc++-v3/src/filesystem/Makefile.in
index 852390ec1a9..76ba905087b 100644
--- a/libstdc++-v3/src/filesystem/Makefile.in
+++ b/libstdc++-v3/src/filesystem/Makefile.in
@@ -147,7 +147,7 @@ am__uninstall_files_from_dir = { \
  $(am__cd) "$$dir" && rm -f $$files; }; \
   }
 am__installdirs = "$(DESTDIR)$(toolexeclibdir)"
-LTLIBRARIES = $(toolexeclib_LTLIBRARIES)
+LTLIBRARIES = $(noinst_LTLIBRARIES) $(toolexeclib_LTLIBRARIES)
 libstdc__fs_la_LIBADD =
 @ENABLE_DUAL_ABI_TRUE@am__objects_1 = cow-dir.lo cow-ops.lo \
 @ENABLE_DUAL_ABI_TRUE@ cow-path.lo
@@ -158,6 +158,10 @@ AM_V_lt = $(am__v_lt_@AM_V@)
 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
 am__v_lt_0 = --silent
 am__v_lt_1 = 
+libstdc__fsconvenience_la_LIBADD =
+am_libstdc__fsconvenience_la_OBJECTS = $(am__objects_2)
+libstdc__fsconvenience_la_OBJECTS =  \
+   $(am_libstdc__fsconvenience_la_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
 

[gcc-13 PATCH 2/2] libstdc++: Add libstdc++_libbacktrace.a to libstdc++exp

2024-04-18 Thread Jonathan Wakely
This completes the fixes to put all experimental symbols into
libstdc++exp.a.

On trunk the libstdc++_libbacktrace.a was removed completely and its
contents aded to libstdc++exp.a instead. We don't want to do that on the
gcc-13 branch because it will break makefiles using it. We can add the
contents to libstdc++exp.a and then install a symlink so that
-lstdc++_libbacktrace still works, but links to libstdc++exp.a instead.

libstdc++-v3/ChangeLog:

* src/experimental/Makefile.am (install-exec-local): New target.
* src/experimental/Makefile.in: Regenerate.
* src/libbacktrace/Makefile.am: Build libstdc++_libbacktrace as
noinst_LTLIBRARIES so it's only a convenience library.
* src/libbacktrace/Makefile.in: Regenerate.
---
 libstdc++-v3/src/experimental/Makefile.am |  5 ++
 libstdc++-v3/src/experimental/Makefile.in | 23 +++---
 libstdc++-v3/src/libbacktrace/Makefile.am |  2 +-
 libstdc++-v3/src/libbacktrace/Makefile.in | 86 ---
 4 files changed, 35 insertions(+), 81 deletions(-)

diff --git a/libstdc++-v3/src/experimental/Makefile.am 
b/libstdc++-v3/src/experimental/Makefile.am
index c5a38d882c2..6cdcdf3525d 100644
--- a/libstdc++-v3/src/experimental/Makefile.am
+++ b/libstdc++-v3/src/experimental/Makefile.am
@@ -66,6 +66,11 @@ AM_CXXFLAGS = \
 AM_MAKEFLAGS = \
"gxx_include_dir=$(gxx_include_dir)"
 
+install-exec-local:
+   -cd '$(DESTDIR)$(toolexeclibdir)' && \
+   $(LN_S) libstdc++exp.la libstdc++_libbacktrace.la && \
+   $(LN_S) libstdc++exp.a libstdc++_libbacktrace.a
+
 # Libtool notes
 
 # 1) In general, libtool expects an argument such as `--tag=CXX' when
diff --git a/libstdc++-v3/src/experimental/Makefile.in 
b/libstdc++-v3/src/experimental/Makefile.in
index c16083a7fc8..87e52c1c83f 100644
--- a/libstdc++-v3/src/experimental/Makefile.in
+++ b/libstdc++-v3/src/experimental/Makefile.in
@@ -740,7 +740,7 @@ install-dvi: install-dvi-am
 
 install-dvi-am:
 
-install-exec-am: install-toolexeclibLTLIBRARIES
+install-exec-am: install-exec-local install-toolexeclibLTLIBRARIES
 
 install-html: install-html-am
 
@@ -789,18 +789,23 @@ uninstall-am: uninstall-toolexeclibLTLIBRARIES
distclean-libtool distclean-tags dvi dvi-am html html-am info \
info-am install install-am install-data install-data-am \
install-dvi install-dvi-am install-exec install-exec-am \
-   install-html install-html-am install-info install-info-am \
-   install-man install-pdf install-pdf-am install-ps \
-   install-ps-am install-strip install-toolexeclibLTLIBRARIES \
-   installcheck installcheck-am installdirs maintainer-clean \
-   maintainer-clean-generic mostlyclean mostlyclean-compile \
-   mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
-   tags tags-am uninstall uninstall-am \
-   uninstall-toolexeclibLTLIBRARIES
+   install-exec-local install-html install-html-am install-info \
+   install-info-am install-man install-pdf install-pdf-am \
+   install-ps install-ps-am install-strip \
+   install-toolexeclibLTLIBRARIES installcheck installcheck-am \
+   installdirs maintainer-clean maintainer-clean-generic \
+   mostlyclean mostlyclean-compile mostlyclean-generic \
+   mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
+   uninstall-am uninstall-toolexeclibLTLIBRARIES
 
 .PRECIOUS: Makefile
 
 
+install-exec-local:
+   -cd '$(DESTDIR)$(toolexeclibdir)' && \
+   $(LN_S) libstdc++exp.la libstdc++_libbacktrace.la && \
+   $(LN_S) libstdc++exp.a libstdc++_libbacktrace.a
+
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
diff --git a/libstdc++-v3/src/libbacktrace/Makefile.am 
b/libstdc++-v3/src/libbacktrace/Makefile.am
index 3992f3ab9c5..4a08f11da1e 100644
--- a/libstdc++-v3/src/libbacktrace/Makefile.am
+++ b/libstdc++-v3/src/libbacktrace/Makefile.am
@@ -31,7 +31,7 @@
 
 include $(top_srcdir)/fragment.am
 
-toolexeclib_LTLIBRARIES = libstdc++_libbacktrace.la
+noinst_LTLIBRARIES = libstdc++_libbacktrace.la
 
 ACLOCAL_AMFLAGS = -I ../.. -I ../../config
 
diff --git a/libstdc++-v3/src/libbacktrace/Makefile.in 
b/libstdc++-v3/src/libbacktrace/Makefile.in
index f5f19149ae6..6b898f65b06 100644
--- a/libstdc++-v3/src/libbacktrace/Makefile.in
+++ b/libstdc++-v3/src/libbacktrace/Makefile.in
@@ -150,35 +150,7 @@ DIST_COMMON = $(srcdir)/Makefile.am
 CONFIG_HEADER = $(top_builddir)/config.h
 CONFIG_CLEAN_FILES = backtrace-supported.h
 CONFIG_CLEAN_VPATH_FILES =
-am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
-am__vpath_adj = case $$p in \
-$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
-*) f=$$p;; \
-  esac;
-am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
-am__install_max = 40
-am__nobase_strip_setup = \
-  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/&/g'`
-am__nobase_strip = \
-  for p in $$list; 

[committed] Add nios2*-*-* to the list of obsolete targets

2024-04-18 Thread Sandra Loosemore

I've committed the attach patch, per

https://gcc.gnu.org/pipermail/gcc/2024-April/243749.html

-SandraFrom 71ba5a721749174815dec712d113f3afb251deda Mon Sep 17 00:00:00 2001
From: Sandra Loosemore 
Date: Mon, 8 Apr 2024 14:36:08 +
Subject: [committed] 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*-*-*.
---
 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
-- 
2.25.1



Re: [PATCH v3] bpf: remove huge memory waste with string allocation.

2024-04-18 Thread David Faust
Hi Cupertino,

On 4/18/24 13:58, Cupertino Miranda wrote:
> Hi David, everyone,
> 
> Following Davids last review I decided to properly detect error cases,
> as suggested.
> The error however should be reported earlier in compilation in
> pack_enum_valud function, where all the errors are reported.
> 
> Thanks for the quick and detailed reviews.
> 
> Regards,
> Cupertino

Thanks for taking the time on this.
This version is nice, just one little comment:

> 
> The BPF backend was allocating an unnecessarily large string when
> constructing CO-RE relocations for enum types.
> This patch further verifies if an enumerator is valid for CO-RE
> representability and returns an error in those cases.

The second sentence is a little awkward and seems to imply the error is
returned when the enumerator is valid :)
Perhaps "...verifies that an enumerator is valid for CO-RE, and returns
an error if it is not" or similar would be more clear?

Otherwise, OK.
Thanks!

> 
> gcc/ChangeLog:
>   * config/bpf/core-builtins.cc (get_index_for_enum_value): Create
>   function.
>   (pack_enum_value): Check for enumerator and error out.
>   (process_enum_value): Correct string allocation.
> ---
>  gcc/config/bpf/core-builtins.cc | 57 ++---
>  1 file changed, 38 insertions(+), 19 deletions(-)
> 
> diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc
> index e03e986e2c1..829acea98f7 100644
> --- a/gcc/config/bpf/core-builtins.cc
> +++ b/gcc/config/bpf/core-builtins.cc
> @@ -795,6 +795,23 @@ process_field_expr (struct cr_builtins *data)
>  static GTY(()) hash_map *bpf_enum_mappings;
>  tree enum_value_type = NULL_TREE;
>  
> +static int
> +get_index_for_enum_value (tree type, tree expr)
> +{
> +  gcc_assert (TREE_CODE (expr) == CONST_DECL
> +   && TREE_CODE (type) == ENUMERAL_TYPE);
> +
> +  unsigned int index = 0;
> +  for (tree l = TYPE_VALUES (type); l; l = TREE_CHAIN (l))
> +{
> +  gcc_assert (index < (1 << 16));
> +  if (TREE_VALUE (l) == expr)
> + return index;
> +  index++;
> +}
> +  return -1;
> +}
> +
>  /* Pack helper for the __builtin_preserve_enum_value.  */
>  
>  static struct cr_local
> @@ -846,6 +863,16 @@ pack_enum_value_fail:
>   ret.reloc_data.default_value = integer_one_node;
>  }
>  
> +  if (ret.fail == false )
> +{
> +  int index = get_index_for_enum_value (type, tmp);
> +  if (index == -1 || index >= (1 << 16))
> + {
> +   bpf_error ("enum value in CO-RE builtin cannot be represented");
> +   ret.fail = true;
> + }
> +}
> +
>ret.reloc_data.type = type;
>ret.reloc_data.kind = kind;
>return ret;
> @@ -864,25 +891,17 @@ process_enum_value (struct cr_builtins *data)
>  
>struct cr_final ret = { NULL, type, data->kind };
>  
> -  if (TREE_CODE (expr) == CONST_DECL
> - && TREE_CODE (type) == ENUMERAL_TYPE)
> -{
> -  unsigned int index = 0;
> -  for (tree l = TYPE_VALUES (type); l; l = TREE_CHAIN (l))
> - {
> -   if (TREE_VALUE (l) == expr)
> - {
> -   char *tmp = (char *) ggc_alloc_atomic ((index / 10) + 1);
> -   sprintf (tmp, "%d", index);
> -   ret.str = (const char *) tmp;
> -
> -   break;
> - }
> -   index++;
> - }
> -}
> -  else
> -gcc_unreachable ();
> +  gcc_assert (TREE_CODE (expr) == CONST_DECL
> +   && TREE_CODE (type) == ENUMERAL_TYPE);
> +
> +  int index = get_index_for_enum_value (type, expr);
> +  gcc_assert (index != -1 && index < (1 << 16));
> +
> +  /* Index can only be a value up to 2^16.  Should always fit
> + in 6 chars.  */
> +  char tmp[6];
> +  sprintf (tmp, "%u", index);
> +  ret.str = CONST_CAST (char *, ggc_strdup(tmp));
>  
>return ret;
>  }


[PATCH v1 1/6] Move mingw_* declarations to the mingw folder

2024-04-18 Thread Evgeny Karpov
This patch refactors recent changes to move mingw-related
functionality to the mingw folder. More renamings to the mingw_
prefix will be done in follow-up commits.

This is the first commit in the second patch series to add DLL
import/export implementation to AArch64.

Coauthors: Zac Walker ,
Mark Harmstone   and
Ron Riddle 

Refactored, prepared, and validated by
Radek Barton  and
Evgeny Karpov 

gcc/ChangeLog:

* config/aarch64/aarch64-protos.h
(mingw_pe_maybe_record_exported_symbol): Move mingw_*
declarations to mingw.
(mingw_pe_section_type_flags): Likewise.
(mingw_pe_unique_section): Likewise.
(mingw_pe_encode_section_info): Likewise.
* config/aarch64/cygming.h
(mingw_pe_asm_named_section): Likewise.
(mingw_pe_declare_function_type): Likewise.
* config/i386/i386-protos.h
(mingw_pe_unique_section): Likewise.
(mingw_pe_declare_function_type): Likewise.
(mingw_pe_maybe_record_exported_symbol): Likewise.
(mingw_pe_encode_section_info): Likewise.
(mingw_pe_section_type_flags): Likewise.
(mingw_pe_asm_named_section): Likewise.
* config/mingw/winnt.h: New file.
---
 gcc/config/aarch64/aarch64-protos.h |  6 +-
 gcc/config/aarch64/cygming.h|  4 
 gcc/config/i386/i386-protos.h   |  8 ++--
 gcc/config/mingw/winnt.h| 29 +
 4 files changed, 32 insertions(+), 15 deletions(-)
 create mode 100644 gcc/config/mingw/winnt.h

diff --git a/gcc/config/aarch64/aarch64-protos.h 
b/gcc/config/aarch64/aarch64-protos.h
index 1d3f94c813e..95972556c56 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -24,6 +24,7 @@
 
 #include "input.h"
 #include "config/arm/aarch-common.h"
+#include "config/mingw/winnt.h"
 
 /* SYMBOL_SMALL_ABSOLUTE: Generate symbol accesses through
high and lo relocs that calculate the base address using a PC
@@ -1110,11 +,6 @@ extern void aarch64_output_patchable_area (unsigned int, 
bool);
 
 extern void aarch64_adjust_reg_alloc_order ();
 
-extern void mingw_pe_maybe_record_exported_symbol (tree, const char *, int);
-extern unsigned int mingw_pe_section_type_flags (tree, const char *, int);
-extern void mingw_pe_unique_section (tree, int);
-extern void mingw_pe_encode_section_info (tree, rtx, int);
-
 bool aarch64_optimize_mode_switching (aarch64_mode_entity);
 void aarch64_restore_za (rtx);
 
diff --git a/gcc/config/aarch64/cygming.h b/gcc/config/aarch64/cygming.h
index 2e7b01feb76..0d048879311 100644
--- a/gcc/config/aarch64/cygming.h
+++ b/gcc/config/aarch64/cygming.h
@@ -51,10 +51,6 @@ still needed for compilation.  */
 #include 
 #endif
 
-extern void mingw_pe_asm_named_section (const char *, unsigned int, tree);
-extern void mingw_pe_declare_function_type (FILE *file, const char *name,
-   int pub);
-
 #define TARGET_ASM_NAMED_SECTION  mingw_pe_asm_named_section
 
 /* Select attributes for named sections.  */
diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
index dbc861fb1ea..96368521380 100644
--- a/gcc/config/i386/i386-protos.h
+++ b/gcc/config/i386/i386-protos.h
@@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public 
License
 along with GCC; see the file COPYING3.  If not see
 .  */
 
+#include "config/mingw/winnt.h"
+
 /* In i386-common.cc.  */
 extern bool ix86_handle_option (struct gcc_options *opts,
struct gcc_options *opts_set ATTRIBUTE_UNUSED,
@@ -295,16 +297,10 @@ extern void ix86_target_macros (void);
 extern void ix86_register_pragmas (void);
 
 /* In winnt.cc  */
-extern void mingw_pe_unique_section (tree, int);
-extern void mingw_pe_declare_function_type (FILE *, const char *, int);
 extern void i386_pe_record_external_function (tree, const char *);
-extern void mingw_pe_maybe_record_exported_symbol (tree, const char *, int);
-extern void mingw_pe_encode_section_info (tree, rtx, int);
 extern bool i386_pe_binds_local_p (const_tree);
 extern const char *i386_pe_strip_name_encoding_full (const char *);
 extern bool i386_pe_valid_dllimport_attribute_p (const_tree);
-extern unsigned int mingw_pe_section_type_flags (tree, const char *, int);
-extern void mingw_pe_asm_named_section (const char *, unsigned int, tree);
 extern void i386_pe_asm_output_aligned_decl_common (FILE *, tree,
const char *,
HOST_WIDE_INT,
diff --git a/gcc/config/mingw/winnt.h b/gcc/config/mingw/winnt.h
new file mode 100644
index 000..da8445904ce
--- /dev/null
+++ b/gcc/config/mingw/winnt.h
@@ -0,0 +1,29 @@
+/* Subroutines for targets on Windows.
+Copyright (C) 2024 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software 

[committed, wwwdocs] gcc-14/changes.html: nios2 target is obsolete

2024-04-18 Thread Sandra Loosemore

I've committed the attached patch, per

https://gcc.gnu.org/pipermail/gcc/2024-April/243749.html

-SandraFrom a6afbd07ee3d669dc6ac396d68a99926a30818f9 Mon Sep 17 00:00:00 2001
From: Sandra Loosemore 
Date: Mon, 15 Apr 2024 17:17:35 +
Subject: [committed, wwwdocs] gcc-14/changes.html: nios2 target is obsolete

---
 htdocs/gcc-14/changes.html | 4 
 1 file changed, 4 insertions(+)

diff --git a/htdocs/gcc-14/changes.html b/htdocs/gcc-14/changes.html
index c98ebe5a..9509487c 100644
--- a/htdocs/gcc-14/changes.html
+++ b/htdocs/gcc-14/changes.html
@@ -49,6 +49,10 @@ a work-in-progress.
   unmaintained for quite a while has been declared obsolete in GCC 14.
   The next release of GCC will have their sources permanently removed.
   
+  Support for the nios2*-*- target ports has also been
+  declared obsolete in GCC 14, and the sources will also be removed
+  in the next release of GCC.
+  
   https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html;>-fanalyzer
 is still only suitable for analyzing C code.
 In particular, using it on C++ is unlikely to give meaningful output.
-- 
2.25.1



[PATCH v3] bpf: remove huge memory waste with string allocation.

2024-04-18 Thread Cupertino Miranda
Hi David, everyone,

Following Davids last review I decided to properly detect error cases,
as suggested.
The error however should be reported earlier in compilation in
pack_enum_valud function, where all the errors are reported.

Thanks for the quick and detailed reviews.

Regards,
Cupertino

The BPF backend was allocating an unnecessarily large string when
constructing CO-RE relocations for enum types.
This patch further verifies if an enumerator is valid for CO-RE
representability and returns an error in those cases.

gcc/ChangeLog:
* config/bpf/core-builtins.cc (get_index_for_enum_value): Create
function.
(pack_enum_value): Check for enumerator and error out.
(process_enum_value): Correct string allocation.
---
 gcc/config/bpf/core-builtins.cc | 57 ++---
 1 file changed, 38 insertions(+), 19 deletions(-)

diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc
index e03e986e2c1..829acea98f7 100644
--- a/gcc/config/bpf/core-builtins.cc
+++ b/gcc/config/bpf/core-builtins.cc
@@ -795,6 +795,23 @@ process_field_expr (struct cr_builtins *data)
 static GTY(()) hash_map *bpf_enum_mappings;
 tree enum_value_type = NULL_TREE;
 
+static int
+get_index_for_enum_value (tree type, tree expr)
+{
+  gcc_assert (TREE_CODE (expr) == CONST_DECL
+ && TREE_CODE (type) == ENUMERAL_TYPE);
+
+  unsigned int index = 0;
+  for (tree l = TYPE_VALUES (type); l; l = TREE_CHAIN (l))
+{
+  gcc_assert (index < (1 << 16));
+  if (TREE_VALUE (l) == expr)
+   return index;
+  index++;
+}
+  return -1;
+}
+
 /* Pack helper for the __builtin_preserve_enum_value.  */
 
 static struct cr_local
@@ -846,6 +863,16 @@ pack_enum_value_fail:
ret.reloc_data.default_value = integer_one_node;
 }
 
+  if (ret.fail == false )
+{
+  int index = get_index_for_enum_value (type, tmp);
+  if (index == -1 || index >= (1 << 16))
+   {
+ bpf_error ("enum value in CO-RE builtin cannot be represented");
+ ret.fail = true;
+   }
+}
+
   ret.reloc_data.type = type;
   ret.reloc_data.kind = kind;
   return ret;
@@ -864,25 +891,17 @@ process_enum_value (struct cr_builtins *data)
 
   struct cr_final ret = { NULL, type, data->kind };
 
-  if (TREE_CODE (expr) == CONST_DECL
- && TREE_CODE (type) == ENUMERAL_TYPE)
-{
-  unsigned int index = 0;
-  for (tree l = TYPE_VALUES (type); l; l = TREE_CHAIN (l))
-   {
- if (TREE_VALUE (l) == expr)
-   {
- char *tmp = (char *) ggc_alloc_atomic ((index / 10) + 1);
- sprintf (tmp, "%d", index);
- ret.str = (const char *) tmp;
-
- break;
-   }
- index++;
-   }
-}
-  else
-gcc_unreachable ();
+  gcc_assert (TREE_CODE (expr) == CONST_DECL
+ && TREE_CODE (type) == ENUMERAL_TYPE);
+
+  int index = get_index_for_enum_value (type, expr);
+  gcc_assert (index != -1 && index < (1 << 16));
+
+  /* Index can only be a value up to 2^16.  Should always fit
+ in 6 chars.  */
+  char tmp[6];
+  sprintf (tmp, "%u", index);
+  ret.str = CONST_CAST (char *, ggc_strdup(tmp));
 
   return ret;
 }
-- 
2.30.2



[PATCH v1 6/6] aarch64: Add DLL import/export to AArch64 target

2024-04-18 Thread Evgeny Karpov
This patch reuses the MinGW implementation to enable DLL import/export
functionality for the aarch64-w64-mingw32 target. It also modifies
environment configurations for MinGW.

gcc/ChangeLog:

* config.gcc: Add winnt-dll.o, which contains the DLL
import/export implementation.
* config/aarch64/aarch64-protos.h (legitimize_pe_coff_symbol):
Declare a MinGW function for expanding a symbol for COFF.
* config/aarch64/aarch64.cc (aarch64_legitimize_pe_coff_symbol):
Add a conditional function that reuses the MinGW implementation
for COFF and does nothing otherwise.
(aarch64_load_symref_appropriately): Add dllimport
implementation.
(aarch64_expand_call): Likewise.
(aarch64_legitimize_address): Likewise.
* config/aarch64/cygming.h (SYMBOL_FLAG_DLLIMPORT): Modify MinGW
environment to support DLL import/export.
(SYMBOL_FLAG_DLLEXPORT): Likewise.
(SYMBOL_REF_DLLIMPORT_P): Likewise.
(SYMBOL_FLAG_STUBVAR): Likewise.
(SYMBOL_REF_STUBVAR_P): Likewise.
(mingw_pe_valid_dllimport_attribute_p): Likewise.
(mingw_pe_file_end): Likewise.
(mingw_pe_record_stub): Likewise.
(TARGET_VALID_DLLIMPORT_ATTRIBUTE_P): Likewise.
(TARGET_ASM_FILE_END): Likewise.
(SUB_TARGET_RECORD_STUB): Likewise.
---
 gcc/config.gcc  |  2 +-
 gcc/config/aarch64/aarch64-protos.h |  1 +
 gcc/config/aarch64/aarch64.cc   | 37 +
 gcc/config/aarch64/cygming.h| 19 +--
 4 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index be2b20a155c..dce3a422daf 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1280,7 +1280,7 @@ aarch64-*-mingw*)
tmake_file="${tmake_file} aarch64/t-aarch64"
target_gtfiles="$target_gtfiles \$(srcdir)/config/mingw/winnt.cc"
extra_options="${extra_options} mingw/cygming.opt mingw/mingw.opt"
-   extra_objs="${extra_objs} winnt.o"
+   extra_objs="${extra_objs} winnt.o winnt-dll.o"
c_target_objs="${c_target_objs} msformat-c.o"
d_target_objs="${d_target_objs} winnt-d.o"
tmake_file="${tmake_file} mingw/t-cygming"
diff --git a/gcc/config/aarch64/aarch64-protos.h 
b/gcc/config/aarch64/aarch64-protos.h
index 95972556c56..996acb60d61 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -25,6 +25,7 @@
 #include "input.h"
 #include "config/arm/aarch-common.h"
 #include "config/mingw/winnt.h"
+#include "config/mingw/winnt-dll.h"
 
 /* SYMBOL_SMALL_ABSOLUTE: Generate symbol accesses through
high and lo relocs that calculate the base address using a PC
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 19205927430..7e28b5f0c08 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -856,6 +856,10 @@ static const attribute_spec aarch64_gnu_attributes[] =
   { "Advanced SIMD type", 1, 1, false, true,  false, true,  NULL, NULL },
   { "SVE type",  3, 3, false, true,  false, true,  NULL, NULL 
},
   { "SVE sizeless type",  0, 0, false, true,  false, true,  NULL, NULL },
+#if TARGET_DLLIMPORT_DECL_ATTRIBUTES
+  { "dllimport", 0, 0, false, false, false, false, handle_dll_attribute, NULL 
},
+  { "dllexport", 0, 0, false, false, false, false, handle_dll_attribute, NULL 
},
+#endif
 #ifdef SUBTARGET_ATTRIBUTE_TABLE
   SUBTARGET_ATTRIBUTE_TABLE
 #endif
@@ -2815,6 +2819,15 @@ tls_symbolic_operand_type (rtx addr)
   return tls_kind;
 }
 
+rtx aarch64_legitimize_pe_coff_symbol (rtx addr, bool inreg)
+{
+#if TARGET_PECOFF
+  return legitimize_pe_coff_symbol (addr, inreg);
+#else
+  return NULL_RTX;
+#endif
+}
+
 /* We'll allow lo_sum's in addresses in our legitimate addresses
so that combine would take care of combining addresses where
necessary, but for generation purposes, we'll generate the address
@@ -2861,6 +2874,17 @@ static void
 aarch64_load_symref_appropriately (rtx dest, rtx imm,
   enum aarch64_symbol_type type)
 {
+  /* If legitimize returns a value
+ copy it directly to the destination and return.  */
+
+  rtx tmp = aarch64_legitimize_pe_coff_symbol (imm, true);
+
+  if (tmp)
+{
+   emit_insn (gen_rtx_SET (dest, tmp));
+   return;
+}
+
   switch (type)
 {
 case SYMBOL_SMALL_ABSOLUTE:
@@ -11231,6 +11255,12 @@ aarch64_expand_call (rtx result, rtx mem, rtx cookie, 
bool sibcall)
 
   gcc_assert (MEM_P (mem));
   callee = XEXP (mem, 0);
+
+  tmp = aarch64_legitimize_pe_coff_symbol (callee, false);
+
+  if (tmp)
+callee = tmp;
+
   mode = GET_MODE (callee);
   gcc_assert (mode == Pmode);
 
@@ -12707,6 +12737,13 @@ aarch64_anchor_offset (HOST_WIDE_INT offset, 
HOST_WIDE_INT size,
 static rtx
 aarch64_legitimize_address (rtx x, rtx /* orig_x  */, machine_mode mode)
 {
+  if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
+{
+  rtx 

[PATCH v1 5/6] Adjust DLL import/export implementation for AArch64

2024-04-18 Thread Evgeny Karpov
The DLL import/export mingw implementation, originally from ix86, requires
minor adjustments to be compatible with AArch64.

gcc/ChangeLog:

* config/mingw/mingw32.h (defined): Use the correct DllMainCRTStartup
entry function.
* config/mingw/winnt-dll.cc (defined): Exclude ix86-related code.
---
 gcc/config/mingw/mingw32.h| 2 +-
 gcc/config/mingw/winnt-dll.cc | 4 
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/config/mingw/mingw32.h b/gcc/config/mingw/mingw32.h
index 08f1b5f0696..efe777051b4 100644
--- a/gcc/config/mingw/mingw32.h
+++ b/gcc/config/mingw/mingw32.h
@@ -79,7 +79,7 @@ along with GCC; see the file COPYING3.  If not see
 #endif
 
 #undef SUB_LINK_ENTRY
-#if TARGET_64BIT_DEFAULT
+#if TARGET_64BIT_DEFAULT || defined (TARGET_AARCH64_MS_ABI)
 #define SUB_LINK_ENTRY SUB_LINK_ENTRY64
 #else
 #define SUB_LINK_ENTRY SUB_LINK_ENTRY32
diff --git a/gcc/config/mingw/winnt-dll.cc b/gcc/config/mingw/winnt-dll.cc
index 349ade6f5c0..294361fab4c 100644
--- a/gcc/config/mingw/winnt-dll.cc
+++ b/gcc/config/mingw/winnt-dll.cc
@@ -206,9 +206,13 @@ legitimize_pe_coff_symbol (rtx addr, bool inreg)
}
 }
 
+#if !defined (TARGET_AARCH64_MS_ABI)
+
   if (ix86_cmodel != CM_LARGE_PIC && ix86_cmodel != CM_MEDIUM_PIC)
 return NULL_RTX;
 
+#endif
+
   if (GET_CODE (addr) == SYMBOL_REF
   && !is_imported_p (addr)
   && SYMBOL_REF_EXTERNAL_P (addr)
-- 
2.25.1



[PATCH v1 3/6] Rename functions for reuse in AArch64

2024-04-18 Thread Evgeny Karpov
This patch renames functions related to dllimport/dllexport
and selectany functionality. These functions will be reused
in the aarch64-w64-mingw32 target.

gcc/ChangeLog:

* config/i386/cygming.h (mingw_pe_record_stub):
Rename functions in mingw folder which will be reused for
aarch64.
(TARGET_ASM_FILE_END): Update to new target-independent name.
(SUBTARGET_ATTRIBUTE_TABLE): Likewise.
(TARGET_VALID_DLLIMPORT_ATTRIBUTE_P): Likewise.
(SUB_TARGET_RECORD_STUB): Likewise.
* config/i386/i386-protos.h (ix86_handle_selectany_attribute): Likewise.
(mingw_handle_selectany_attribute): Likewise.
(i386_pe_valid_dllimport_attribute_p): Likewise.
(mingw_pe_valid_dllimport_attribute_p): Likewise.
(i386_pe_file_end): Likewise.
(mingw_pe_file_end): Likewise.
(i386_pe_record_stub): Likewise.
(mingw_pe_record_stub): Likewise.
* config/mingw/winnt.cc (ix86_handle_selectany_attribute): Likewise.
(mingw_handle_selectany_attribute): Likewise.
(i386_pe_valid_dllimport_attribute_p): Likewise.
(mingw_pe_valid_dllimport_attribute_p): Likewise.
(i386_pe_record_stub): Likewise.
(mingw_pe_record_stub): Likewise.
(i386_pe_file_end): Likewise.
(mingw_pe_file_end): Likewise.
* config/mingw/winnt.h (mingw_handle_selectany_attribute):
Declate functionality that will be reused by multiple targets.
(mingw_pe_file_end): Likewise.
(mingw_pe_record_stub): Likewise.
(mingw_pe_valid_dllimport_attribute_p): Likewise.
---
 gcc/config/i386/cygming.h | 6 +++---
 gcc/config/i386/i386-protos.h | 3 ---
 gcc/config/mingw/winnt.cc | 6 +++---
 gcc/config/mingw/winnt.h  | 6 +-
 4 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/gcc/config/i386/cygming.h b/gcc/config/i386/cygming.h
index 4110ceab824..061136efa0a 100644
--- a/gcc/config/i386/cygming.h
+++ b/gcc/config/i386/cygming.h
@@ -342,7 +342,7 @@ do {\
 
 /* Output function declarations at the end of the file.  */
 #undef TARGET_ASM_FILE_END
-#define TARGET_ASM_FILE_END i386_pe_file_end
+#define TARGET_ASM_FILE_END mingw_pe_file_end
 
 /* Kludge because of missing PE-COFF support for early LTO debug.  */
 #undef  TARGET_ASM_LTO_START
@@ -443,7 +443,7 @@ do {\
 
 #define SUBTARGET_ATTRIBUTE_TABLE \
   { "selectany", 0, 0, true, false, false, false, \
-ix86_handle_selectany_attribute, NULL }
+mingw_handle_selectany_attribute, NULL }
   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
affects_type_identity, handler, exclude } */
 
@@ -451,7 +451,7 @@ do {\
 #undef NO_PROFILE_COUNTERS
 #define NO_PROFILE_COUNTERS 1
 
-#define TARGET_VALID_DLLIMPORT_ATTRIBUTE_P i386_pe_valid_dllimport_attribute_p
+#define TARGET_VALID_DLLIMPORT_ATTRIBUTE_P mingw_pe_valid_dllimport_attribute_p
 #define TARGET_CXX_ADJUST_CLASS_AT_DEFINITION 
i386_pe_adjust_class_at_definition
 #define SUBTARGET_MANGLE_DECL_ASSEMBLER_NAME i386_pe_mangle_decl_assembler_name
 
diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
index dbced12f8d4..4dc90179b9b 100644
--- a/gcc/config/i386/i386-protos.h
+++ b/gcc/config/i386/i386-protos.h
@@ -261,7 +261,6 @@ extern unsigned int ix86_local_alignment (tree, 
machine_mode,
 extern unsigned int ix86_minimum_alignment (tree, machine_mode,
unsigned int);
 extern tree ix86_handle_shared_attribute (tree *, tree, tree, int, bool *);
-extern tree ix86_handle_selectany_attribute (tree *, tree, tree, int, bool *);
 extern int x86_field_alignment (tree, int);
 extern tree ix86_valid_target_attribute_tree (tree, tree,
  struct gcc_options *,
@@ -301,12 +300,10 @@ extern void ix86_register_pragmas (void);
 extern void i386_pe_record_external_function (tree, const char *);
 extern bool i386_pe_binds_local_p (const_tree);
 extern const char *i386_pe_strip_name_encoding_full (const char *);
-extern bool i386_pe_valid_dllimport_attribute_p (const_tree);
 extern void i386_pe_asm_output_aligned_decl_common (FILE *, tree,
const char *,
HOST_WIDE_INT,
HOST_WIDE_INT);
-extern void i386_pe_file_end (void);
 extern void i386_pe_asm_lto_start (void);
 extern void i386_pe_asm_lto_end (void);
 extern void i386_pe_start_function (FILE *, const char *, tree);
diff --git a/gcc/config/mingw/winnt.cc b/gcc/config/mingw/winnt.cc
index 9901576ade0..a0b5950be2e 100644
--- a/gcc/config/mingw/winnt.cc
+++ b/gcc/config/mingw/winnt.cc
@@ -71,7 +71,7 @@ ix86_handle_shared_attribute (tree *node, tree name, tree, 
int,
 /* Handle a "selectany" attribute;

Re: [PATCH] libstdc++: Fix std::ranges::iota is not included in numeric [PR108760]

2024-04-18 Thread Patrick Palka
On Wed, 17 Apr 2024, Michael Levine (BLOOMBERG/ 919 3RD A) wrote:

> This patch fixes GCC Bug 108760: 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108760
> Before this patch, using std::ranges::iota required including  
> when it should have been sufficient to only include .
> 
> When the patch is applied, the following code will compile: 
> https://godbolt.org/z/33EPeqd1b
> 
> I added a test case for this change as well.
> 
> I built my local version of gcc using the following configuration: $ 
> ../gcc/configure --disable-bootstrap --prefix="$(pwd)/_pfx/" 
> --enable-languages=c,c++,lto
> 
> and I tested my changes by running: $ make check-c++ -jN -k

Nice, thanks for the patch!

> 
> I ran this on the following OS:
> 
> Virtualization: wsl
> Operating System: Ubuntu 20.04.6 LTS
> Kernel: Linux 5.15.146.1-microsoft-standard-WSL2
> Architecture: x86-64

> From bd04070c281572ed7a3b48e3d33543e25b8c8afe Mon Sep 17 00:00:00 2001
> From: Michael Levine 
> Date: Fri, 23 Feb 2024 14:13:13 -0500
> Subject: [PATCH 1/2] Fix the bug
> 
> Signed-off-by: Michael Levine 
> ---
>  libstdc++-v3/include/bits/ranges_algo.h | 52 --
>  libstdc++-v3/include/bits/stl_numeric.h | 57 -
>  2 files changed, 56 insertions(+), 53 deletions(-)
> 
> diff --git a/libstdc++-v3/include/bits/ranges_algo.h 
> b/libstdc++-v3/include/bits/ranges_algo.h
> index 62faff173bd..d258be0b93f 100644
> --- a/libstdc++-v3/include/bits/ranges_algo.h
> +++ b/libstdc++-v3/include/bits/ranges_algo.h
> @@ -3521,58 +3521,6 @@ namespace ranges
>  
>  #endif // __glibcxx_ranges_contains
>  
> -#if __glibcxx_ranges_iota >= 202202L // C++ >= 23
> -
> -  template
> -struct out_value_result
> -{
> -  [[no_unique_address]] _Out out;
> -  [[no_unique_address]] _Tp value;
> -
> -  template
> - requires convertible_to
> -   && convertible_to
> - constexpr
> - operator out_value_result<_Out2, _Tp2>() const &
> - { return {out, value}; }
> -
> -  template
> - requires convertible_to<_Out, _Out2>
> -   && convertible_to<_Tp, _Tp2>
> - constexpr
> - operator out_value_result<_Out2, _Tp2>() &&
> - { return {std::move(out), std::move(value)}; }
> -};
> -
> -  template
> -using iota_result = out_value_result<_Out, _Tp>;
> -
> -  struct __iota_fn
> -  {
> -template _Sent, 
> weakly_incrementable _Tp>
> -  requires indirectly_writable<_Out, const _Tp&>
> -  constexpr iota_result<_Out, _Tp>
> -  operator()(_Out __first, _Sent __last, _Tp __value) const
> -  {
> - while (__first != __last)
> -   {
> - *__first = static_cast(__value);
> - ++__first;
> - ++__value;
> -   }
> - return {std::move(__first), std::move(__value)};
> -  }
> -
> -template _Range>
> -  constexpr iota_result, _Tp>
> -  operator()(_Range&& __r, _Tp __value) const
> -  { return (*this)(ranges::begin(__r), ranges::end(__r), 
> std::move(__value)); }
> -  };
> -
> -  inline constexpr __iota_fn iota{};
> -
> -#endif // __glibcxx_ranges_iota
> -
>  #if __glibcxx_ranges_find_last >= 202207L // C++ >= 23
>  
>struct __find_last_fn
> diff --git a/libstdc++-v3/include/bits/stl_numeric.h 
> b/libstdc++-v3/include/bits/stl_numeric.h
> index fe911154ab7..1b06c26dc02 100644
> --- a/libstdc++-v3/include/bits/stl_numeric.h
> +++ b/libstdc++-v3/include/bits/stl_numeric.h
> @@ -59,7 +59,7 @@
>  #include 
>  #include 
>  #include  // For _GLIBCXX_MOVE
> -
> +#include  // For _Range as used by std::ranges::iota
>  
>  namespace std _GLIBCXX_VISIBILITY(default)
>  {
> @@ -102,6 +102,61 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>  }
>  #endif
>  
> +namespace ranges
> +{
> +#if __glibcxx_ranges_iota >= 202202L // C++ >= 23
> +
> +  template
> +struct out_value_result
> +{
> +  [[no_unique_address]] _Out out;
> +  [[no_unique_address]] _Tp value;
> +
> +  template
> + requires convertible_to
> +   && convertible_to
> + constexpr
> + operator out_value_result<_Out2, _Tp2>() const &
> + { return {out, value}; }
> +
> +  template
> + requires convertible_to<_Out, _Out2>
> +   && convertible_to<_Tp, _Tp2>
> + constexpr
> + operator out_value_result<_Out2, _Tp2>() &&
> + { return {std::move(out), std::move(value)}; }
> +};

IIUC out_value_result should continue to be available from , so we
probably don't want to move it to  (or one of its internal headers).
Better would be to move it to  I think.

> +
> +  template
> +using iota_result = out_value_result<_Out, _Tp>;
> +
> +  struct __iota_fn
> +  {
> +template _Sent, 
> weakly_incrementable _Tp>
> +  requires indirectly_writable<_Out, const _Tp&>
> +  constexpr iota_result<_Out, _Tp>
> +  operator()(_Out __first, _Sent __last, _Tp __value) const
> +  {
> + while (__first != __last)
> +   {
> + *__first = static_cast(__value);
> + ++__first;
> + ++__value;
> +  

[gcc-13 PATCH 0/2] Replace libstdc++_libbacktrace.a with libstdc++exp.a

2024-04-18 Thread Jonathan Wakely
The first patch is a backport from trunk to fix the fact that I messed
up the change to add all symbols from libstdc++fs.a into libstdc++exp.a,
which was backported as r13-8207-g17acf9fbeb10d7. The change builds
libstdc++fs.a twice, once to install it and once as a convenience
library to be included into libstdc++exp.a. That change already works
fine on trunk, so should be fine on gcc-13 too.

The second patch is not a backport but is needed for the branch to
ensure that libstdc++exp.a also provides the symbols for
libstdc++_libbacktrace.a but without removing libstdc++_libbacktrace.a
itself. On trunk I removed it and put all its symbols in libstdc++exp.a,
but on the branch we don't want to stop installing that static lib
halfway through the gcc-13 release series, as it will break makefiles
that are using -lstdc++_libbacktrace to get those symbols.

Because libstdc++-v3/src/libbacktrace/Makefile.am is more complicated
than libstdc++-v3/src/filesystem/Makefile.am and because I don't know
what all the _LIBADD etc. variables do, I'm not sure exactly how to do
the "build it twice, once for installation and once as a convenience
library" thing. So instead what this patch does is change it to a
convenience library (as is done on trunk) but then also create a symlink
with the old installed name, pointing to libstdc++exp.a, so that
using -lstdc++_libbacktrace still works. The symlink is created using
$(LN_S) so for targets that don't support symlinks it's just a copy.

One gotcha is that if you do 'make install' over a pre-existing gcc-13
installation, the new symlinks for libstdc++_libbacktrace.{a,la} won't
be created, because there are already real files with those names. That
won't affect users installing gcc-13.3.0 afresh, it would only affect
people who've been building 13.2.1 from git or from snapshots. Apart
from some errors printed to stderr (and ignored by make) it won't really
matter, because the existing regular files provide the same symbols
anyway.

Does this look reasonable, and done correctly?

Or should I bite the bullet and figure out how to properly adjust
src/libbacktrace/Makefile.am to create an installable library and a
convenience library in parallel? Would I need to copy every
libstdc___libbacktrace_la_FOO variable to create a corresponding
libstdc___libbacktraceconvenience_la_FOO variable?

One advantage of the symlink approach is that we don't increase the
installed footprint of gcc-13 by duplicating all the backtrace symbols
in two static archives. We could even consider making libstdc++fs.a a
symlink to libstdc++exp.a as well, on trunk and gcc-13, to stop
duplicating those symbols.

-- >8 --

Jonathan Wakely (2):
  libstdc++: Fix libstdc++exp.a so it really does contain Filesystem TS
symbols
  libstdc++: Add libstdc++_libbacktrace.a to libstdc++exp

 libstdc++-v3/src/experimental/Makefile.am |  7 +-
 libstdc++-v3/src/experimental/Makefile.in | 27 ---
 libstdc++-v3/src/filesystem/Makefile.am   |  4 ++
 libstdc++-v3/src/filesystem/Makefile.in   | 37 --
 libstdc++-v3/src/libbacktrace/Makefile.am |  2 +-
 libstdc++-v3/src/libbacktrace/Makefile.in | 86 ---
 6 files changed, 73 insertions(+), 90 deletions(-)

-- 
2.44.0



Re: [gcc-13 PATCH 2/2] libstdc++: Add libstdc++_libbacktrace.a to libstdc++exp

2024-04-18 Thread Jonathan Wakely
On Thu, 18 Apr 2024 at 20:51, Jonathan Wakely wrote:
>
> This completes the fixes to put all experimental symbols into
> libstdc++exp.a.
>
> On trunk the libstdc++_libbacktrace.a was removed completely and its
> contents aded to libstdc++exp.a instead. We don't want to do that on the
> gcc-13 branch because it will break makefiles using it. We can add the
> contents to libstdc++exp.a and then install a symlink so that
> -lstdc++_libbacktrace still works, but links to libstdc++exp.a instead.

It looks like simply duplicating all the libstdc___libbacktrace_FOO
variables in libbacktrace/Makefile.am does work (see attached patch),
so that we get an installed libstdc++_libbacktrace.a and a
not-installed libstdc++_libbacktraceconvenience.a which gets included
into the installed libstdc++exp.a

So if that's preferable to making the installed
libstdc++_libbacktrace.a a symlink, we can do that.

I still kinda like the symlink approach, because it reduces the size
on disk, and the same approach could be used to get rid of
libstdc++fs.a without breaking makefiles using -lstdc++fs
diff --git a/libstdc++-v3/src/experimental/Makefile.am b/libstdc++-v3/src/experimental/Makefile.am
index 6cdcdf3525d..db6f3321f90 100644
--- a/libstdc++-v3/src/experimental/Makefile.am
+++ b/libstdc++-v3/src/experimental/Makefile.am
@@ -31,7 +31,7 @@ filesystem_lib =
 endif
 
 if ENABLE_BACKTRACE
-backtrace_lib = $(top_builddir)/src/libbacktrace/libstdc++_libbacktrace.la
+backtrace_lib = $(top_builddir)/src/libbacktrace/libstdc++_libbacktraceconvenience.la
 else
 backtrace_lib =
 endif
diff --git a/libstdc++-v3/src/experimental/Makefile.in b/libstdc++-v3/src/experimental/Makefile.in
index 87e52c1c83f..709cc227a1f 100644
--- a/libstdc++-v3/src/experimental/Makefile.in
+++ b/libstdc++-v3/src/experimental/Makefile.in
@@ -149,7 +149,7 @@ am__uninstall_files_from_dir = { \
 am__installdirs = "$(DESTDIR)$(toolexeclibdir)"
 LTLIBRARIES = $(toolexeclib_LTLIBRARIES)
 @ENABLE_FILESYSTEM_TS_TRUE@am__DEPENDENCIES_1 = $(top_builddir)/src/filesystem/libstdc++fsconvenience.la
-@ENABLE_BACKTRACE_TRUE@am__DEPENDENCIES_2 = $(top_builddir)/src/libbacktrace/libstdc++_libbacktrace.la
+@ENABLE_BACKTRACE_TRUE@am__DEPENDENCIES_2 = $(top_builddir)/src/libbacktrace/libstdc++_libbacktraceconvenience.la
 am__objects_1 = contract.lo
 am_libstdc__exp_la_OBJECTS = $(am__objects_1)
 libstdc__exp_la_OBJECTS = $(am_libstdc__exp_la_OBJECTS)
@@ -452,7 +452,7 @@ toolexeclib_LTLIBRARIES = libstdc++exp.la
 @ENABLE_FILESYSTEM_TS_FALSE@filesystem_lib = 
 @ENABLE_FILESYSTEM_TS_TRUE@filesystem_lib = $(top_builddir)/src/filesystem/libstdc++fsconvenience.la
 @ENABLE_BACKTRACE_FALSE@backtrace_lib = 
-@ENABLE_BACKTRACE_TRUE@backtrace_lib = $(top_builddir)/src/libbacktrace/libstdc++_libbacktrace.la
+@ENABLE_BACKTRACE_TRUE@backtrace_lib = $(top_builddir)/src/libbacktrace/libstdc++_libbacktraceconvenience.la
 headers = 
 sources = \
 	contract.cc
diff --git a/libstdc++-v3/src/libbacktrace/Makefile.am b/libstdc++-v3/src/libbacktrace/Makefile.am
index 4a08f11da1e..d45d60c8f69 100644
--- a/libstdc++-v3/src/libbacktrace/Makefile.am
+++ b/libstdc++-v3/src/libbacktrace/Makefile.am
@@ -31,18 +31,21 @@
 
 include $(top_srcdir)/fragment.am
 
-noinst_LTLIBRARIES = libstdc++_libbacktrace.la
+toolexeclib_LTLIBRARIES = libstdc++_libbacktrace.la
+noinst_LTLIBRARIES = libstdc++_libbacktraceconvenience.la
 
 ACLOCAL_AMFLAGS = -I ../.. -I ../../config
 
 # This will be used instead of the common AM_CPPFLAGS from fragment.am
-libstdc___libbacktrace_la_CPPFLAGS = \
+bt_cppflags = \
 	-I $(top_srcdir)/../include -I $(top_srcdir)/../libgcc \
 	-I ../../../libgcc -I .. -I $(top_srcdir) \
 	-I $(top_srcdir)/../libbacktrace \
 	-I $(top_srcdir)/../libiberty \
 	-include $(top_srcdir)/src/libbacktrace/backtrace-rename.h \
 	$(BACKTRACE_CPPFLAGS)
+libstdc___libbacktrace_la_CPPFLAGS = $(bt_cppflags)
+libstdc___libbacktraceconvenience_la_CPPFLAGS = $(bt_cppflags)
 
 WARN_FLAGS = -W -Wall -Wwrite-strings -Wmissing-format-attribute \
 	 -Wcast-qual
@@ -61,8 +64,9 @@ obj_prefix = std_stacktrace
 
 # Each FILE.c in SOURCES will be compiled to SHORTNAME-FILE.o
 libstdc___libbacktrace_la_SHORTNAME = $(obj_prefix)
+libstdc___libbacktraceconvenience_la_SHORTNAME = $(obj_prefix)
 
-libstdc___libbacktrace_la_SOURCES = \
+sources = \
 	atomic.c \
 	backtrace.c \
 	dwarf.c \
@@ -72,6 +76,8 @@ libstdc___libbacktrace_la_SOURCES = \
 	simple.c \
 	state.c \
 	cp-demangle.c
+libstdc___libbacktrace_la_SOURCES = $(sources)
+libstdc___libbacktraceconvenience_la_SOURCES = $(sources)
 
 FORMAT_FILES = \
 	elf.c \
@@ -86,19 +92,25 @@ ALLOC_FILES = \
 	alloc.c \
 	mmap.c
 
-EXTRA_libstdc___libbacktrace_la_SOURCES = \
+extra_sources = \
 	$(FORMAT_FILES) \
 	$(VIEW_FILES) \
 	$(ALLOC_FILES)
 
+EXTRA_libstdc___libbacktrace_la_SOURCES = $(extra_sources)
+EXTRA_libstdc___libbacktraceconvenience_la_SOURCES = $(extra_sources)
+
 # These three files are chosen by configure and added to the link.
 # We need the SHORTNAME- prefix so that they 

[PATCH v1 2/6] Extract ix86 dllimport implementation to mingw

2024-04-18 Thread Evgeny Karpov
This patch extracts the ix86 implementation for expanding a SYMBOL
into its corresponding dllimport, far-address, or refptr symbol.
It will be reused in the aarch64-w64-mingw32 target.
The implementation is copied as is from i386/i386.cc with
minor changes to follow to the code style.

Also this patch replaces the original DLL import/export
implementation in ix86 with mingw.

gcc/ChangeLog:

* config.gcc: Add winnt-dll.o, which contains the DLL
import/export implementation.
* config/i386/cygming.h (SUB_TARGET_RECORD_STUB): Remove the
old implementation. Rename the required function to MinGW.
Rename it to a conditional function that will reuse the
MinGW implementation for COFF and nothing otherwise.
* config/i386/i386-expand.cc (ix86_expand_move): Likewise.
* config/i386/i386-expand.h (is_imported_p): Likewise.
(mingw_GOT_alias_set): Likewise.
(ix86_legitimize_pe_coff_symbol): Likewise.
* config/i386/i386-protos.h: Likewise.
* config/i386/i386.cc (is_imported_p): Likewise.
(ix86_legitimize_pe_coff_symbol): Likewise.
(ix86_GOT_alias_set): Likewise.
(legitimize_pic_address): Likewise.
(struct dllimport_hasher):
(GTY): Likewise.
(get_dllimport_decl): Likewise.
(legitimize_pe_coff_extern_decl): Likewise.
(legitimize_dllimport_symbol): Likewise.
(legitimize_pe_coff_symbol): Likewise.
(ix86_legitimize_address): Likewise.
* config/mingw/winnt.h (mingw_pe_record_stub): Likewise.
* config/mingw/winnt.cc (i386_pe_record_stub): Likewise.
(mingw_pe_record_stub): Likewise.
* config/mingw/t-cygming: Add the winnt-dll.o compilation.
* config/mingw/winnt-dll.cc: New file.
---
 gcc/config.gcc |   6 +-
 gcc/config/i386/cygming.h  |   2 +-
 gcc/config/i386/i386-expand.cc |   2 +-
 gcc/config/i386/i386-expand.h  |   2 +-
 gcc/config/i386/i386-protos.h  |   2 +-
 gcc/config/i386/i386.cc| 211 --
 gcc/config/mingw/t-cygming |   6 +
 gcc/config/mingw/winnt-dll.cc  | 229 +
 gcc/config/mingw/winnt-dll.h   |  26 
 gcc/config/mingw/winnt.cc  |   2 +-
 gcc/config/mingw/winnt.h   |   1 +
 11 files changed, 292 insertions(+), 197 deletions(-)
 create mode 100644 gcc/config/mingw/winnt-dll.cc
 create mode 100644 gcc/config/mingw/winnt-dll.h

diff --git a/gcc/config.gcc b/gcc/config.gcc
index ef7f854735a..be2b20a155c 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2181,7 +2181,7 @@ i[34567]86-*-cygwin*)
tmake_file="${tmake_file} mingw/t-cygming t-slibgcc"
target_gtfiles="$target_gtfiles \$(srcdir)/config/mingw/winnt.cc"
extra_options="${extra_options} mingw/cygming.opt i386/cygwin.opt"
-   extra_objs="${extra_objs} winnt.o winnt-stubs.o"
+   extra_objs="${extra_objs} winnt.o winnt-stubs.o winnt-dll.o"
c_target_objs="${c_target_objs} msformat-c.o"
cxx_target_objs="${cxx_target_objs} winnt-cxx.o msformat-c.o"
d_target_objs="${d_target_objs} cygwin-d.o"
@@ -2199,7 +2199,7 @@ x86_64-*-cygwin*)
tmake_file="${tmake_file} mingw/t-cygming t-slibgcc"
target_gtfiles="$target_gtfiles \$(srcdir)/config/mingw/winnt.cc"
extra_options="${extra_options} mingw/cygming.opt i386/cygwin.opt"
-   extra_objs="${extra_objs} winnt.o winnt-stubs.o"
+   extra_objs="${extra_objs} winnt.o winnt-stubs.o winnt-dll.o"
c_target_objs="${c_target_objs} msformat-c.o"
cxx_target_objs="${cxx_target_objs} winnt-cxx.o msformat-c.o"
d_target_objs="${d_target_objs} cygwin-d.o"
@@ -2283,7 +2283,7 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
*)
;;
esac
-   extra_objs="${extra_objs} winnt.o winnt-stubs.o"
+   extra_objs="${extra_objs} winnt.o winnt-stubs.o winnt-dll.o"
c_target_objs="${c_target_objs} msformat-c.o"
cxx_target_objs="${cxx_target_objs} winnt-cxx.o msformat-c.o"
gas=yes
diff --git a/gcc/config/i386/cygming.h b/gcc/config/i386/cygming.h
index beedf7c398a..4110ceab824 100644
--- a/gcc/config/i386/cygming.h
+++ b/gcc/config/i386/cygming.h
@@ -459,7 +459,7 @@ do {\
 #define TARGET_ASM_ASSEMBLE_VISIBILITY i386_pe_assemble_visibility
 
 #undef SUB_TARGET_RECORD_STUB
-#define SUB_TARGET_RECORD_STUB i386_pe_record_stub
+#define SUB_TARGET_RECORD_STUB mingw_pe_record_stub
 
 /* Static stack checking is supported by means of probes.  */
 #define STACK_CHECK_STATIC_BUILTIN 1
diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index 8bb8f21e686..77bf4433aa8 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -412,7 +412,7 @@ ix86_expand_move (machine_mode mode, rtx operands[])
}
   else
{
- tmp = legitimize_pe_coff_symbol (op1, addend != 

Re: [PATCH v2 2/2] c++/modules: Fix instantiation of imported temploid friends [PR114275]

2024-04-18 Thread Nathaniel Shead
On Wed, Apr 17, 2024 at 02:02:21PM -0400, Patrick Palka wrote:
> On Mon, 15 Apr 2024, Nathaniel Shead wrote:
> 
> > I'm not a huge fan of always streaming 'imported_temploid_friends' for
> > all decls, but I don't think it adds much performance cost over adding a
> > new flag to categorise decls that might be marked as such.
> 
> IIUC this value is going to be almost always null which is encoded as a
> single 0 byte, which should be fast to stream.  But I wonder how much
> larger  gets?  Can we get away with streaming this value
> only for TEMPLATE_DECLs?

Yes, it should either just be a 0 byte or an additional backref
somewhere, which will likely also be small. On my system it increases
the size by 0.26%, from 31186800 bytes to 31268672.

But I've just found that this patch has a bug anyway, in that it doesn't
correctly dedup if the friend types are instantiated in two separate
modules that are then both imported.  I'll see what I need to do to fix
this which may influence what we need to stream here.

> > 
> > Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?
> > 
> > -- >8 --
> > 
> > This patch fixes a number of issues with the handling of temploid friend
> > declarations.
> > 
> > The primary issue is that instantiations of friend declarations should
> > attach the declaration to the same module as the befriending class, by
> > [module.unit] p7.1 and [temp.friend] p2; this could be a different
> > module from the current TU, and so needs special handling.
> 
> Nice, your approach seems consistent with Nathan's comments in the past
> about this issue:
> 
> https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603288.html
> https://gcc.gnu.org/pipermail/gcc-patches/2023-February/611215.htmlw
> 
> > 
> > The other main issue here is that we can't assume that just because name
> > lookup didn't find a definition for a hidden template class, it doesn't
> > mean that it doesn't exist: it could be a non-exported entity that we've
> > nevertheless streamed in from an imported module.  We need to ensure
> > that when instantiating friend classes that we return the same TYPE_DECL
> > that we got from our imports, otherwise we will get later issues with
> > 'duplicate_decls' (rightfully) complaining that they're different.
> > 
> > This doesn't appear necessary for functions due to the existing name
> > lookup handling already finding these hidden declarations.
> 
> It does seem like a weird inconsistency that tsubst_friend_class needs
> this workaround but not tsubst_friend_function.
> 
> I wonder if we can relax duplicate_decls to treat an instantiated
> template friend class as a redeclaration instead of complaining,
> mirroring its behavior for functions, which in turn would let us get rid
> of the name lookup in tsubst_friend_class and eliminate the need for
> lookup_imported_hidden_friend?  This may be too speculative/risky of
> a refactoring at this stage though, and your approach has the nice
> advantage of changing only modules code paths.

Hm, that's a good idea.  I've played around a little bit with trying
this but I've gotten a little stuck, might try again later.  It also
feels a little silly to do a full instantiation of a (potentially) large
type only to immediately throw it away when we could just look for it
beforehand, but this does feel like a neater solution anyway.

> In any case I hope we can fix this issue for GCC 14!  LGTM overall.
> 
> > 
> > PR c++/105320
> > PR c++/114275
> > 
> > gcc/cp/ChangeLog:
> > 
> > * cp-tree.h (propagate_defining_module): Declare.
> > (lookup_imported_hidden_friend): Declare.
> > * decl.cc (duplicate_decls): Also check if hidden declarations
> > can be redeclared in this module.
> > * module.cc (imported_temploid_friends): New map.
> > (init_modules): Initialize it.
> > (trees_out::decl_value): Write it.
> > (trees_in::decl_value): Read it.
> > (get_originating_module_decl): Follow the owning decl for an
> > imported temploid friend.
> > (propagate_defining_module): New function.
> > * name-lookup.cc (lookup_imported_hidden_friend): New function.
> > * pt.cc (tsubst_friend_function): Propagate defining module for
> > new friend functions.
> > (tsubst_friend_class): Lookup imported hidden friends. Check
> > for valid redeclaration. Propagate defining module for new
> > friend classes.
> > 
> > gcc/testsuite/ChangeLog:
> > 
> > * g++.dg/modules/tpl-friend-10_a.C: New test.
> > * g++.dg/modules/tpl-friend-10_b.C: New test.
> > * g++.dg/modules/tpl-friend-10_c.C: New test.
> > * g++.dg/modules/tpl-friend-11_a.C: New test.
> > * g++.dg/modules/tpl-friend-11_b.C: New test.
> > * g++.dg/modules/tpl-friend-12_a.C: New test.
> > * g++.dg/modules/tpl-friend-12_b.C: New test.
> > * g++.dg/modules/tpl-friend-12_c.C: New test.
> > * g++.dg/modules/tpl-friend-12_d.C: New test.
> > * g++.dg/modules/tpl-friend-12_e.C: New test.
> > * 

Re: [PATCH v2 1/2] Driver: Add new -truncate option

2024-04-18 Thread Peter0x44




18 Apr 2024 7:26:27 am Richard Biener :

On Thu, Apr 18, 2024 at 6:12 AM Peter Damianov  
wrote:


This commit adds a new option to the driver that truncates one file 
after

linking.

Tested likeso:

$ gcc hello.c -c
$ du -h hello.o
4.0K  hello.o
$ gcc hello.o -truncate hello
$ ./a.out
Hello world
$ du -h hello.o
$ 0   hello.o


I suppose it should have been

$ gcc hello.o -truncate hello.o

in the example.


Correct.
Sorry about that.




$ gcc hello.o -truncate
gcc: error: missing filename after '-truncate'

The motivation for adding this is PR110710. It is used by lto-wrapper 
to

truncate files in a shell-independent manner.


This looks good to me.

Thanks,
Richard.


Signed-off-by: Peter Damianov 
---
v2: moved truncation to driver::final_actions
v2: moved handling of OPT_truncate to be in alphabetic order

gcc/common.opt |  6 ++
gcc/gcc.cc | 13 +
2 files changed, 19 insertions(+)

diff --git a/gcc/common.opt b/gcc/common.opt
index ad348844775..40cab3cb36a 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -422,6 +422,12 @@ Display target specific command line options 
(including assembler and linker opt

-time
Driver Alias(time)

+;; Truncate the file specified after linking.
+;; This option is used by lto-wrapper to reduce the peak disk-usage 
when

+;; linking with many .LTRANS units.
+truncate
+Driver Separate Undocumented MissingArgError(missing filename after 
%qs)

+
-verbose
Driver Alias(v)

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 728332b8153..b4169bbd3be 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -2138,6 +2138,10 @@ static int have_E = 0;
/* Pointer to output file name passed in with -o. */
static const char *output_file = 0;

+/* Pointer to input file name passed in with -truncate.
+   This file should be truncated after linking. */
+static const char *totruncate_file = 0;
+
/* This is the list of suffixes and codes (%g/%u/%U/%j) and the 
associated
    temp file.  If the HOST_BIT_BUCKET is used for %j, no entry is 
made for

    it here.  */
@@ -4538,6 +4542,10 @@ driver_handle_option (struct gcc_options *opts,
   do_save = false;
   break;

+    case OPT_truncate:
+  totruncate_file = arg;
+  break;
+
 case OPT:
   /* "-###"
 This is similar to -v except that there is no execution
@@ -9286,6 +9294,11 @@ driver::final_actions () const
 delete_failure_queue ();
   delete_temp_files ();

+  if (totruncate_file != NULL && !seen_error ())
+    /* Truncate file specified by -truncate.
+   Used by lto-wrapper to reduce temporary disk-space usage. */
+    truncate(totruncate_file, 0);
+
   if (print_help_list)
 {
   printf (("\nFor bug reporting instructions, please see:\n"));
--
2.39.2



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

2024-04-18 Thread Jakub Jelinek
Hi!

__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.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

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.

--- gcc/internal-fn.cc.jj   2024-03-23 08:22:50.490607002 +0100
+++ gcc/internal-fn.cc  2024-04-17 13:44:21.673594413 +0200
@@ -1631,7 +1631,11 @@ expand_mul_overflow (location_t loc, tre
   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, tre
   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
   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;
@@ -2629,6 +2638,7 @@ expand_vector_ubsan_overflow (location_t
 }
   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 co
   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 co
  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;
}
 
@@ -2771,6 +2786,7 @@ expand_arith_overflow (enum tree_code co
  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 co
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 co
  else
expand_mul_overflow (loc, lhs, arg0, arg1, unsr_p,
 uns0_p, uns1_p, false, NULL);
+ flag_trapv = save_flag_trapv;
  return;
}
 
--- gcc/testsuite/gcc.dg/pr114753.c.jj  2024-04-17 13:55:16.246482369 +0200
+++ gcc/testsuite/gcc.dg/pr114753.c 2024-04-17 13:54:14.035352376 +0200
@@ -0,0 +1,14 @@
+/* PR middle-end/114753 */
+/* { dg-do run } */
+/* { dg-options "-O2 -ftrapv" } */
+
+int
+main ()
+{
+  volatile long long i = __LONG_LONG_MAX__;
+  volatile long long j = 2;
+  long long k;
+  if (!__builtin_mul_overflow (i, j, ) || k != -2LL)
+__builtin_abort ();
+  return 0;
+}

Jakub



[PATCH] libgcc: Fix up __divmodbitint4 [PR114755]

2024-04-18 Thread Jakub Jelinek
Hi!

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.

Bootstrapped/regtested on x86_64-linux and i686-linux, plus tested with
make check-gcc -j32 -k GCC_TEST_RUN_EXPENSIVE=1 
RUNTESTFLAGS="GCC_TEST_RUN_EXPENSIVE=1 dg.exp='*bitint* pr112673.c 
builtin-stdc-bit-*.c pr112566-2.c pr112511.c' dg-torture.exp=*bitint* 
dfp.exp=*bitint*"
on aarch64-linux, ok for trunk?

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.

--- libgcc/libgcc2.c.jj 2024-03-21 13:07:43.629886730 +0100
+++ libgcc/libgcc2.c2024-04-17 19:00:55.453691368 +0200
@@ -1705,69 +1705,62 @@ __divmodbitint4 (UBILtype *q, SItype qpr
   USItype rn = ((USItype) rprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
   USItype up = auprec % W_TYPE_SIZE;
   USItype vp = avprec % W_TYPE_SIZE;
+  /* 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)
+{
+  vp = 0;
+  --vn;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+  ++v;
+#endif
+}
   if (__builtin_expect (un < vn, 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;
+  /* 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__
- ++v;
+  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 (!rn)
+   return;
+  if (up)
{
- /* q is 0 and r is u.  */
- if (q)
-   __builtin_memset (q, 0, qn * sizeof (UWtype));
- if (r == NULL)
+ if (uprec > 0)
+   *r = *u & (((UWtype) 1 << up) - 1);
+ else
+   *r = *u | ((UWtype) -1 << up);
+ r += BITINT_INC;
+ if (!--rn)
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;
-   }
- if (!rn)
-   return;
- if (up)
-   {
- if (uprec > 0)
-   *r = *u & (((UWtype) 1 << up) - 1);
- else
-   *r = *u | ((UWtype) -1 << up);
- r += BITINT_INC;
- if (!--rn)
-   return;
-   }
- UWtype c = uprec < 0 ? (UWtype) -1 : (UWtype) 0;
- for (; rn; 

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

2024-04-18 Thread Richard Biener
On Thu, 18 Apr 2024, Jakub Jelinek wrote:

> Hi!
> 
> __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.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Thanks,
Richard.

> 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.
> 
> --- gcc/internal-fn.cc.jj 2024-03-23 08:22:50.490607002 +0100
> +++ gcc/internal-fn.cc2024-04-17 13:44:21.673594413 +0200
> @@ -1631,7 +1631,11 @@ expand_mul_overflow (location_t loc, tre
>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, tre
>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
>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;
> @@ -2629,6 +2638,7 @@ expand_vector_ubsan_overflow (location_t
>  }
>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 co
>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 co
> 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;
>   }
>  
> @@ -2771,6 +2786,7 @@ expand_arith_overflow (enum tree_code co
> 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 co
>   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 co
> else
>   expand_mul_overflow (loc, lhs, arg0, arg1, unsr_p,
>uns0_p, uns1_p, false, NULL);
> +   flag_trapv = save_flag_trapv;
> return;
>   }
>  
> --- gcc/testsuite/gcc.dg/pr114753.c.jj2024-04-17 13:55:16.246482369 
> +0200
> +++ gcc/testsuite/gcc.dg/pr114753.c   2024-04-17 13:54:14.035352376 +0200
> @@ -0,0 +1,14 @@
> +/* PR middle-end/114753 */
> +/* { dg-do run } */
> +/* { dg-options "-O2 -ftrapv" } */
> +
> +int
> +main ()
> +{
> +  volatile long long i = __LONG_LONG_MAX__;
> +  volatile long long j = 2;
> +  long long k;
> +  if (!__builtin_mul_overflow (i, j, ) || k != -2LL)
> +

Re: [PATCH] libgcc: Fix up __divmodbitint4 [PR114755]

2024-04-18 Thread Richard Biener
On Thu, 18 Apr 2024, Jakub Jelinek wrote:

> Hi!
> 
> 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.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, plus tested with
> make check-gcc -j32 -k GCC_TEST_RUN_EXPENSIVE=1 
> RUNTESTFLAGS="GCC_TEST_RUN_EXPENSIVE=1 dg.exp='*bitint* pr112673.c 
> builtin-stdc-bit-*.c pr112566-2.c pr112511.c' dg-torture.exp=*bitint* 
> dfp.exp=*bitint*"
> on aarch64-linux, ok for trunk?

OK.

Thanks,
Richard.

> 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.
> 
> --- libgcc/libgcc2.c.jj   2024-03-21 13:07:43.629886730 +0100
> +++ libgcc/libgcc2.c  2024-04-17 19:00:55.453691368 +0200
> @@ -1705,69 +1705,62 @@ __divmodbitint4 (UBILtype *q, SItype qpr
>USItype rn = ((USItype) rprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
>USItype up = auprec % W_TYPE_SIZE;
>USItype vp = avprec % W_TYPE_SIZE;
> +  /* 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)
> +{
> +  vp = 0;
> +  --vn;
> +#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
> +  ++v;
> +#endif
> +}
>if (__builtin_expect (un < vn, 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;
> +  /* 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__
> -   ++v;
> +  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 (!rn)
> + return;
> +  if (up)
>   {
> -   /* q is 0 and r is u.  */
> -   if (q)
> - __builtin_memset (q, 0, qn * sizeof (UWtype));
> -   if (r == NULL)
> +   if (uprec > 0)
> + *r = *u & (((UWtype) 1 << up) - 1);
> +   else
> + *r = *u | ((UWtype) -1 << up);
> +   r += BITINT_INC;
> +   if (!--rn)
>   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;
> - }
> -   if (!rn)
> - return;
> -   if (up)
> - {
> -   if (uprec > 0)
> - *r = *u & (((UWtype) 1 << up) - 1);
> -   else
> -  

Re: [PATCH v2 1/2] Driver: Add new -truncate option

2024-04-18 Thread Richard Biener
On Thu, Apr 18, 2024 at 6:12 AM Peter Damianov  wrote:
>
> This commit adds a new option to the driver that truncates one file after
> linking.
>
> Tested likeso:
>
> $ gcc hello.c -c
> $ du -h hello.o
> 4.0K  hello.o
> $ gcc hello.o -truncate hello
> $ ./a.out
> Hello world
> $ du -h hello.o
> $ 0   hello.o

I suppose it should have been

$ gcc hello.o -truncate hello.o

in the example.

> $ gcc hello.o -truncate
> gcc: error: missing filename after '-truncate'
>
> The motivation for adding this is PR110710. It is used by lto-wrapper to
> truncate files in a shell-independent manner.

This looks good to me.

Thanks,
Richard.

> Signed-off-by: Peter Damianov 
> ---
> v2: moved truncation to driver::final_actions
> v2: moved handling of OPT_truncate to be in alphabetic order
>
>  gcc/common.opt |  6 ++
>  gcc/gcc.cc | 13 +
>  2 files changed, 19 insertions(+)
>
> diff --git a/gcc/common.opt b/gcc/common.opt
> index ad348844775..40cab3cb36a 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -422,6 +422,12 @@ Display target specific command line options (including 
> assembler and linker opt
>  -time
>  Driver Alias(time)
>
> +;; Truncate the file specified after linking.
> +;; This option is used by lto-wrapper to reduce the peak disk-usage when
> +;; linking with many .LTRANS units.
> +truncate
> +Driver Separate Undocumented MissingArgError(missing filename after %qs)
> +
>  -verbose
>  Driver Alias(v)
>
> diff --git a/gcc/gcc.cc b/gcc/gcc.cc
> index 728332b8153..b4169bbd3be 100644
> --- a/gcc/gcc.cc
> +++ b/gcc/gcc.cc
> @@ -2138,6 +2138,10 @@ static int have_E = 0;
>  /* Pointer to output file name passed in with -o. */
>  static const char *output_file = 0;
>
> +/* Pointer to input file name passed in with -truncate.
> +   This file should be truncated after linking. */
> +static const char *totruncate_file = 0;
> +
>  /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated
> temp file.  If the HOST_BIT_BUCKET is used for %j, no entry is made for
> it here.  */
> @@ -4538,6 +4542,10 @@ driver_handle_option (struct gcc_options *opts,
>do_save = false;
>break;
>
> +case OPT_truncate:
> +  totruncate_file = arg;
> +  break;
> +
>  case OPT:
>/* "-###"
>  This is similar to -v except that there is no execution
> @@ -9286,6 +9294,11 @@ driver::final_actions () const
>  delete_failure_queue ();
>delete_temp_files ();
>
> +  if (totruncate_file != NULL && !seen_error ())
> +/* Truncate file specified by -truncate.
> +   Used by lto-wrapper to reduce temporary disk-space usage. */
> +truncate(totruncate_file, 0);
> +
>if (print_help_list)
>  {
>printf (("\nFor bug reporting instructions, please see:\n"));
> --
> 2.39.2
>


Re: [PATCH v2 2/2] lto-wrapper: Truncate files using -truncate driver option [PR110710]

2024-04-18 Thread Richard Biener
On Thu, Apr 18, 2024 at 6:12 AM Peter Damianov  wrote:
>
> This commit changes the Makefiles generated by lto-wrapper to no longer use
> the "mv" and "touch" shell commands. These don't exist on Windows, so when the
> Makefile attempts to call them, it results in errors like:
> The system cannot find the file specified.
>
> This problem only manifested when calling gcc from cmd.exe, and having no
> sh.exe present on the PATH. The Windows port of GNU Make searches the PATH for
> an sh.exe, and uses it if present.
>
> I have tested this in environments with and without sh.exe on the PATH and
> confirmed it works as expected.

OK.

Thanks,
Richard.

> Signed-off-by: Peter Damianov 
> ---
>  gcc/lto-wrapper.cc | 6 ++
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/lto-wrapper.cc b/gcc/lto-wrapper.cc
> index 02579951569..a36a59e6fb8 100644
> --- a/gcc/lto-wrapper.cc
> +++ b/gcc/lto-wrapper.cc
> @@ -2023,14 +2023,12 @@ cont:
>   fprintf (mstream, "%s:\n\t@%s ", output_name, new_argv[0]);
>   for (j = 1; new_argv[j] != NULL; ++j)
> fprintf (mstream, " '%s'", new_argv[j]);
> - fprintf (mstream, "\n");
>   /* If we are not preserving the ltrans input files then
>  truncate them as soon as we have processed it.  This
>  reduces temporary disk-space usage.  */
>   if (! save_temps)
> -   fprintf (mstream, "\t@-touch -r \"%s\" \"%s.tem\" > /dev/null 
> "
> -"2>&1 && mv \"%s.tem\" \"%s\"\n",
> -input_name, input_name, input_name, input_name);
> +   fprintf (mstream, " '-truncate' '%s'", input_name);
> + fprintf (mstream, "\n");
> }
>   else
> {
> --
> 2.39.2
>