Ping^3 [PATCH] get source line for diagnostic from preprocessed file / PR preprocessor/79106

2025-01-03 Thread Bader, Lucas
Hello and Happy New Year,

as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79106 is still open, I wanted 
to again bump this patch I provided a while back.
It was earmarked for gcc-11 in 
https://gcc.gnu.org/pipermail/gcc-patches/2020-January/539201.html but did not 
make it into the release.

Original submission: 
https://gcc.gnu.org/legacy-ml/gcc-patches/2019-12/msg01113.html

Please let me know if something is missing.

Best
Lucas

-Original Message-
From: Bader, Lucas 
Sent: Montag, 16. Dezember 2019 12:19
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] get source line for diagnostic from preprocessed file / PR 
preprocessor/79106

Hello,

within a compile cluster, only the preprocessed output of GCC is transferred to 
remote nodes for compilation. 
When GCC produces advanced diagnostics (with -fdiagnostics-show-caret), e.g. 
prints out the affected source
line and fixit hints, it attempts to read the source file again, even when 
compiling a preprocessed file (-fpreprocessed). 
This leads to wrong diagnostics when building with a compile cluster, or, more 
generally, when changing or deleting the original source file.

This patch attempts to alter the behavior by implementing a 
location_get_source_line_preprocessed 
function that can be used in diagnostic-show-locus.c in case a preprocessed 
file is compiled.
There was some previous discussion on this behavior on PR preprocessor/79106.

This is my first patch to GCC, so in case something is wrong with the format, 
please let me know.

Best regards
Lucas



[patch, Fortran, doc] Mention generating C prototypes from Fortran

2025-01-03 Thread Thomas Koenig

Hello world,

I noticed that there is no mention of automatically generating
C prototypes and declarations in the relevant section of
the docs, "Interoperability with C". This patch remedies that.

OK for trunk?

Best regards

Thomas

gcc/fortran/ChangeLog:

* gfortran.texi: New subsection "Generating C prototypes from
Fortran".



Re: [PATCH] Ada: Fix build for dummy s-taprop

2025-01-03 Thread Marc Poulhiès
Thanks,

The change is fine. FTR, the original change you're referring to is
r11-902-gb68c1670b7d40b.

Do you have write access to git?

Marc

Estevan Castilho  writes:

> From: "Estevan Castilho (Tevo)" 
>
> ---
>  gcc/ada/libgnarl/s-taprop__dummy.adb | 11 ++-
>  1 file changed, 2 insertions(+), 9 deletions(-)
>
> diff --git a/gcc/ada/libgnarl/s-taprop__dummy.adb 
> b/gcc/ada/libgnarl/s-taprop__dummy.adb
> index 68ec8b448ba..2127fb1f1b1 100644
> --- a/gcc/ada/libgnarl/s-taprop__dummy.adb
> +++ b/gcc/ada/libgnarl/s-taprop__dummy.adb
> @@ -37,7 +37,6 @@
>  package body System.Task_Primitives.Operations is
>
> use System.OS_Locks;
> -   use System.Parameters;
> use System.Tasking;
>
> pragma Warnings (Off);
> @@ -483,10 +482,7 @@ package body System.Task_Primitives.Operations is
>null;
> end Unlock;
>
> -   procedure Unlock
> - (L   : not null access RTS_Lock;
> -  Global_Lock : Boolean := False)
> -   is
> +   procedure Unlock (L : not null access RTS_Lock) is
> begin
>null;
> end Unlock;
> @@ -525,10 +521,7 @@ package body System.Task_Primitives.Operations is
>Ceiling_Violation := False;
> end Write_Lock;
>
> -   procedure Write_Lock
> - (L   : not null access RTS_Lock;
> -  Global_Lock : Boolean := False)
> -   is
> +   procedure Write_Lock (L : not null access RTS_Lock) is
> begin
>null;
> end Write_Lock;


Re: [RFC/RFA] [PR tree-optimization/92539] Improve code and avoid Warray-bounds false positive

2025-01-03 Thread Richard Biener



> Am 03.01.2025 um 16:22 schrieb Jeff Law :
> 
> So this is an implementation of an idea I had a few years back and 
> prototyped last spring to fix pr92539.
> 
> pr92539 is a false positive Warray-bounds warning triggered by loop 
> unrolling.  The warning is in code that will never execute, but none of the 
> optimizers clean things up well enough or early enough in the pipeline to 
> avoid the warning.
> 
> To optimize away the code we can take advantage of the fact that we're 
> comparing a value to a bogus pointer.  So for example an EQ comparison 
> against &"aa" + 3 is always false and a NE comparison against that would 
> always be true.

Forming the pointer invokes UB, the comparison is neither false nor true.  I’d 
say this is a classical case for path isolation on the pointer forming, not 
only discarding either the true or false path of the compare.

The path isolation pass is probably too late in this case?

> I've implemented this in vr-values.  It's not my preferred location, but we 
> need to handle this scenario before the array-bounds warnings which are 
> currently placed immediately after vrp1.  So vr-values it was...
> 
> This could perhaps also be done in match.pd; there's a reasonable chance it's 
> implementable there and would trigger early enough in the pipeline to avoid 
> the false positive.  I can certainly explore that if folks think that's a 
> better solution to this long standing issue.
> 
> Bootstrapped and regression tested on x86_64 and run through the crosses in 
> my tester.
> 
> Anyway, thoughts?
> 
> Jeff
> 
> 


Re: [PATCH] rtlanal: Treat writes to sp as also writing to memory [PR117938]

2025-01-03 Thread Richard Biener



> Am 03.01.2025 um 10:04 schrieb Richard Sandiford :
> 
> This PR was about a case in which late-combine moved a stack
> deallocation across an earlier stack access.  This was possible
> because the deallocation was missing the RTL-SSA equivalent of
> a vop, which in turn was because rtl_properties didn't treat
> the deallocation as writing to memory.  I think the bug was
> ultimately there.
> 
> Tested on x86_64-linux-gnu (which the PR was reported against)
> and aarch64-linux-gnu.  OK to install?

Ok

> I don't think any earlier users of RTL-SSA are likely to be
> affected by this, so I'm not sure it's worth a backport.

Your call.

Richard 


> Richard
> 
> 
> gcc/
>PR rtl-optimization/117938
>* rtlanal.cc (rtx_properties::try_to_add_dest): Treat writes
>to the stack pointer as also writing to memory.
> 
> gcc/testsuite/
>PR rtl-optimization/117938
>* gcc.dg/torture/pr117938.c: New test.
> ---
> gcc/rtlanal.cc  | 14 +++---
> gcc/testsuite/gcc.dg/torture/pr117938.c | 36 +
> 2 files changed, 47 insertions(+), 3 deletions(-)
> create mode 100644 gcc/testsuite/gcc.dg/torture/pr117938.c
> 
> diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc
> index e7efb48c398..8caffafdaa4 100644
> --- a/gcc/rtlanal.cc
> +++ b/gcc/rtlanal.cc
> @@ -2163,10 +2163,18 @@ rtx_properties::try_to_add_dest (const_rtx x, 
> unsigned int flags)
> 
>   if (LIKELY (REG_P (x)))
> {
> -  /* We want to keep sp alive everywhere -  by making all
> - writes to sp also use sp. */
>   if (REGNO (x) == STACK_POINTER_REGNUM)
> -flags |= rtx_obj_flags::IS_READ;
> +{
> +  /* Stack accesses are dependent on previous allocations and
> + anti-dependent on later deallocations, so both types of
> + stack operation are akin to a memory write.  */
> +  if (ref_iter != ref_end)
> +*ref_iter++ = rtx_obj_reference (MEM_REGNO, flags, BLKmode);
> +
> +  /* We want to keep sp alive everywhere - by making all
> + writes to sp also use sp.  */
> +  flags |= rtx_obj_flags::IS_READ;
> +}
>   try_to_add_reg (x, flags);
>   return;
> }
> diff --git a/gcc/testsuite/gcc.dg/torture/pr117938.c 
> b/gcc/testsuite/gcc.dg/torture/pr117938.c
> new file mode 100644
> index 000..5a3b6d2156c
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/torture/pr117938.c
> @@ -0,0 +1,36 @@
> +/* { dg-do run { target { int32 && int128 } } } */
> +/* { dg-additional-options "-Wno-psabi --param=max-cse-insns=1" } */
> +
> +typedef unsigned V __attribute__((__vector_size__(64)));
> +typedef unsigned __int128 W __attribute__((__vector_size__(64)));
> +unsigned a;
> +W b;
> +V c;
> +W d;
> +
> +__attribute__((__noinline__))
> +W
> +bar (unsigned u, V z, W w)
> +{
> +  u *= z[5];
> +  return u + w;
> +}
> +
> +W
> +foo (V v)
> +{
> +  unsigned g = a ? 1 : -1;
> +  v ^= 0 <= v;
> +  v <<= ((V){ bar (0, c, b)[0] } & 1);
> +  v >>= ((V){ g, bar (1, c, b)[0] } & 1);
> +  return a + b + (W) v + d;
> +}
> +
> +int
> +main ()
> +{
> +  V x = (V) foo ((V) { });
> +  for (unsigned i = 0; i < sizeof(x)/sizeof(x[0]); i++)
> +if (x[i] != (i ? 0x : 0x7fff))
> +  __builtin_abort();
> +}
> --
> 2.25.1
> 


Re: [PATCH] forwprop: Use tree_fits_shwi_p in check_ctz_array

2025-01-03 Thread Richard Biener



> Am 03.01.2025 um 09:44 schrieb Jakub Jelinek :
> 
> Hi!
> 
> When touching the function yesterday, I was surprised to see just
> TREE_CODE (something) != INTEGER_CST checks followed by tree_to_shwi.
> That would ICE if the INTEGER_CST doesn't fit.
> 
> I have actually not been able to reproduce an ICE for the elt case
> as the caller gives up if the precision of the array type is larger than 32
> bits (but I think it is still cleaner to use it), the idx case can actually
> ICE e.g. on
> static const unsigned long long magic = 0x03f08c5392f756cdULL;
> static const char table[] = {
> 0,  [0x8000ULL] = 1, 12,  2, 13, 22, 17,  3, 14, 33, 23, 36, 
> 18, 58, 28,  4,
>62, 15, 34, 26, 24, 48, 50, 37, 19, 55, 59, 52, 29, 44, 39,  5,
>63, 11, 21, 16, 32, 35, 57, 27, 61, 25, 47, 49, 54, 51, 43, 38,
>10, 20, 31, 56, 60, 46, 53, 42, 9, 30, 45, 41,  8, 40,  7,  6,
> };
> 
> int ctz (unsigned long x)
> {
>  unsigned long lsb = x & -x;
>  return table[(lsb * magic) >> 58];
> }
> ~/src/gcc/obj20/gcc/cc1 -quiet /tmp/1.c -O2 -mbmi
> /tmp/1.c:2:19: warning: size of ‘table’ 9223372036854775871 bytes exceeds 
> maximum object size 9223372036854775807 [-Wlarger-than=]
>2 | static const char table[] = {
>  |   ^
> during GIMPLE pass: forwprop
> /tmp/1.c: In function ‘ctz’:
> /tmp/1.c:13:1: internal compiler error: in tree_to_shwi, at tree.cc:6518
>   13 | }
>  | ^
> 0x2efa51f internal_error(char const*, ...)
>../../gcc/diagnostic-global-context.cc:517
> 0xf3c617 fancy_abort(char const*, int, char const*)
>../../gcc/diagnostic.cc:1722
> 0x949a36 tree_to_shwi(tree_node const*)
>../../gcc/tree.cc:6518
> 0x949a36 tree_to_shwi(tree_node const*)
>../../gcc/tree.cc:6516
> 0x18472d5 check_ctz_array
>../../gcc/tree-ssa-forwprop.cc:2286
> but given the 9223372036854775871 bytes long array
> I'm not sure it is appropriate for the testsuite.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok


> 2025-01-03  Jakub Jelinek  
> 
>* tree-ssa-forwprop.cc (check_ctz_array): Use tree_fits_shwi_p instead
>of just TREE_CODE tests for INTEGER_CST.
> 
> --- gcc/tree-ssa-forwprop.cc.jj2025-01-02 12:29:23.906259521 +0100
> +++ gcc/tree-ssa-forwprop.cc2025-01-02 13:54:25.077630882 +0100
> @@ -2278,9 +2278,9 @@ check_ctz_array (tree ctor, unsigned HOS
> 
>   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, idx, elt)
> {
> -  if (TREE_CODE (idx) != INTEGER_CST)
> +  if (!tree_fits_shwi_p (idx))
>return false;
> -  if (TREE_CODE (elt) != INTEGER_CST && TREE_CODE (elt) != RAW_DATA_CST)
> +  if (!tree_fits_shwi_p (elt) && TREE_CODE (elt) != RAW_DATA_CST)
>return false;
> 
>   unsigned HOST_WIDE_INT index = tree_to_shwi (idx);
> 
>Jakub
> 


Re: [PATCH] varasm: Fix up array_size_for_constructor RAW_DATA_CST handling once again [PR118275]

2025-01-03 Thread Richard Biener



> Am 03.01.2025 um 09:49 schrieb Jakub Jelinek :
> 
> Hi!
> 
> As the following testcases show (the latter only if I revert the
> temporary reversion of the C++ large array speedup), the FEs aren't
> really consistent in the type of array CONSTRUCTOR_ELTS indexes,
> it can be bitsizetype, but can be sizetype as well.
> Given that everything else is able to cope with it just fine,
> I'm using build_int_cst which also doesn't care what type it is,
> instead of bitsize_int, which I've used in PR117190 fix (previously
> it was size_int).
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok

> 2025-01-03  Jakub Jelinek  
> 
>PR c++/118275
>* varasm.cc (array_size_for_constructor): Use build_int_cst
>with TREE_TYPE (index) as first argument, instead of bitsize_int.
> 
>* g++.dg/cpp/embed-18.C: New test.
>* g++.dg/ext/flexary41.C: New test.
> 
> --- gcc/varasm.cc.jj2025-01-02 11:23:27.0 +0100
> +++ gcc/varasm.cc2025-01-02 15:01:05.488162995 +0100
> @@ -5648,7 +5648,8 @@ array_size_for_constructor (tree val)
>index = TREE_OPERAND (index, 1);
>   if (value && TREE_CODE (value) == RAW_DATA_CST)
>index = size_binop (PLUS_EXPR, index,
> -bitsize_int (RAW_DATA_LENGTH (value) - 1));
> +build_int_cst (TREE_TYPE (index),
> +   RAW_DATA_LENGTH (value) - 1));
>   if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
>max_index = index;
> }
> --- gcc/testsuite/g++.dg/cpp/embed-18.C.jj2025-01-02 14:48:07.819954910 
> +0100
> +++ gcc/testsuite/g++.dg/cpp/embed-18.C2025-01-02 14:48:47.943398108 +0100
> @@ -0,0 +1,15 @@
> +// PR c++/118275
> +// { dg-do compile }
> +// { dg-options "" }
> +
> +struct A { int a; char b[]; };
> +void bar (A *);
> +
> +void
> +foo ()
> +{
> +  static struct A a = { .a = 1, .b = {
> +#embed __FILE__
> + } };
> +  bar (&a);
> +}
> --- gcc/testsuite/g++.dg/ext/flexary41.C.jj2025-01-02 14:49:42.029647539 
> +0100
> +++ gcc/testsuite/g++.dg/ext/flexary41.C2025-01-02 14:49:35.472738531 
> +0100
> @@ -0,0 +1,24 @@
> +// PR c++/118275
> +// { dg-do compile }
> +// { dg-options "" }
> +
> +struct A { int a; char b[]; };
> +void bar (A *);
> +
> +void
> +foo ()
> +{
> +  static struct A a = { .a = 1, .b = {
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
> + } };
> +  bar (&a);
> +}
> 
>Jakub
> 


Re: [PATCH] testsuite: torture: add LLVM testcase for DSE vs. -ftrivial-auto-var-init=

2025-01-03 Thread Sam James
Mike Stump  writes:

> On Jan 2, 2025, at 4:00 PM, Sam James  wrote:
>> 
>> This testcase came up in a recent LLVM bug report [0] for DSE vs
>> -ftrivial-auto-var-init=. Add it to our testsuite given that area
>> could do with better coverage.
>> 
>> [0] https://github.com/llvm/llvm-project/issues/119646
>> 
>> gcc/testsuite/ChangeLog:
>> 
>>  * gcc.dg/torture/dse-trivial-auto-var-init.c: New test.
>> 
>> Co-authored-by: Andrew Pinski 
>> ---
>> OK?
>
> Ok.  If a bug currently in gcc, would be nice to submit a bug report, get a 
> number and attach it into the test case. If a bug in the past, would be nice 
> to attach that number to it.

Thanks, pushed. PR108657 is the closest I see but not quite the same.

All branches with -ftrivial-auto-var-init pass this testcase.

>
>> .../gcc.dg/torture/dse-trivial-auto-var-init.c  | 17 +
>> 1 file changed, 17 insertions(+)
>> create mode 100644 gcc/testsuite/gcc.dg/torture/dse-trivial-auto-var-init.c
>> 
>> diff --git a/gcc/testsuite/gcc.dg/torture/dse-trivial-auto-var-init.c 
>> b/gcc/testsuite/gcc.dg/torture/dse-trivial-auto-var-init.c
>> new file mode 100644
>> index ..5a3d4c4e3ecb
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.dg/torture/dse-trivial-auto-var-init.c
>> @@ -0,0 +1,17 @@
>> +/* Testcase for LLVM bug: 
>> https://github.com/llvm/llvm-project/issues/119646 */
>> +/* { dg-do run } */
>> +/* { dg-additional-options "-ftrivial-auto-var-init=zero" } */
>> +
>> +int b = 208;
>> +[[gnu::noinline]]
>> +void f(int *e, int a) {
>> +  *e = !!b;
>> +  if (a)
>> +__builtin_trap();
>> +}
>> +int main(void) {
>> +  b = 0;
>> +  f(&b, 0);
>> +  if (b != 0)
>> +__builtin_trap();
>> +}
>> 
>> base-commit: 99d5ef700619c28904846399a6f6692af4c56b1b
>> -- 
>> 2.47.1
>> 


RE: [RFC] PR81358: Enable automatic linking of libatomic

2025-01-03 Thread Joseph Myers
On Fri, 20 Dec 2024, Prathamesh Kulkarni wrote:

> Hi,
> The previous patch (now reverted) had two different issues both stemming from 
> the rule added in libatomic/Makefile.am:
> (1) As mentioned above, it broke multilib builds because it incorrectly 
> copies libatomic.a in $(gcc_objdir). The attached patch fixes it by
> instead copying libatomic.a  over to $(gcc_objdir)$(MULTISUBDIR)/, and can 
> confirm that 64-bit libatomic.a is copied to $build/gcc/ and 32-bit
> libatomic.a is copied to $build/gcc/32/.
> 
> (2) libatomic_convenience.la was not getting generated for some reason, which 
> resulted in build failure while building libdruntime.
> The patch adds libatomic_convenience.la as a dependency, and I can see it now 
> getting generated, which seems to fix the build issue with libdruntime.
> 
> Patch passes bootstrap+test with multilib enabled for --enable-languages=all 
> on x86_64-linux-gnu, and for --enable-languages=c,c++,fortran on 
> aarch64-linux-gnu.
> Does this version look OK ?

This is OK.

To answer Jakub's question about passing -fno-link-libatomic when building 
target libraries, I think it's reasonable for target libraries to use 
atomic interfaces that may, on some targets, need libatomic.

(I'm not asserting that this patch by itself will make target libraries 
using atomic interfaces work in cases that are currently broken.  
Empirically, some such cases are broken already in ways that this patch 
wouldn't fix.  Bug 118280 reports libstdc++ for microblaze using 
__atomic_test_and_set, which is not defined in libatomic - libatomic for 
microblaze-linux-gnu has an undefined reference to that symbol itself, 
only defining __atomic_test_and_set_{1,2,4,8,16}.  And I'm not sure 
there's currently a bug open for it, but for m68k-linux-gnu built for 
ColdFire, libstdc++ has undefined references to hidden __sync_* symbols 
defined in libgcc.a, which also prevents linking with libstdc++, but I 
expect the fix for that would be to use t-slibgcc-libgcc in 
libgcc/config.host for those targets, nothing to do with libatomic since 
the symbols aren't in libatomic.  In both cases, we could also take the 
breakage as evidence that those targets are no longer being used outside 
of bots building many different targets and so might be ripe for 
obsolescence.)

-- 
Joseph S. Myers
josmy...@redhat.com



[PATCH] forwprop: Use tree_fits_shwi_p in check_ctz_array

2025-01-03 Thread Jakub Jelinek
Hi!

When touching the function yesterday, I was surprised to see just
TREE_CODE (something) != INTEGER_CST checks followed by tree_to_shwi.
That would ICE if the INTEGER_CST doesn't fit.

I have actually not been able to reproduce an ICE for the elt case
as the caller gives up if the precision of the array type is larger than 32
bits (but I think it is still cleaner to use it), the idx case can actually
ICE e.g. on
static const unsigned long long magic = 0x03f08c5392f756cdULL;
static const char table[] = {
 0,  [0x8000ULL] = 1, 12,  2, 13, 22, 17,  3, 14, 33, 23, 36, 
18, 58, 28,  4,
62, 15, 34, 26, 24, 48, 50, 37, 19, 55, 59, 52, 29, 44, 39,  5,
63, 11, 21, 16, 32, 35, 57, 27, 61, 25, 47, 49, 54, 51, 43, 38,
10, 20, 31, 56, 60, 46, 53, 42, 9, 30, 45, 41,  8, 40,  7,  6,
};

int ctz (unsigned long x)
{
  unsigned long lsb = x & -x;
  return table[(lsb * magic) >> 58];
}
~/src/gcc/obj20/gcc/cc1 -quiet /tmp/1.c -O2 -mbmi
/tmp/1.c:2:19: warning: size of ‘table’ 9223372036854775871 bytes exceeds 
maximum object size 9223372036854775807 [-Wlarger-than=]
2 | static const char table[] = {
  |   ^
during GIMPLE pass: forwprop
/tmp/1.c: In function ‘ctz’:
/tmp/1.c:13:1: internal compiler error: in tree_to_shwi, at tree.cc:6518
   13 | }
  | ^
0x2efa51f internal_error(char const*, ...)
../../gcc/diagnostic-global-context.cc:517
0xf3c617 fancy_abort(char const*, int, char const*)
../../gcc/diagnostic.cc:1722
0x949a36 tree_to_shwi(tree_node const*)
../../gcc/tree.cc:6518
0x949a36 tree_to_shwi(tree_node const*)
../../gcc/tree.cc:6516
0x18472d5 check_ctz_array
../../gcc/tree-ssa-forwprop.cc:2286
but given the 9223372036854775871 bytes long array
I'm not sure it is appropriate for the testsuite.

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

2025-01-03  Jakub Jelinek  

* tree-ssa-forwprop.cc (check_ctz_array): Use tree_fits_shwi_p instead
of just TREE_CODE tests for INTEGER_CST.

--- gcc/tree-ssa-forwprop.cc.jj 2025-01-02 12:29:23.906259521 +0100
+++ gcc/tree-ssa-forwprop.cc2025-01-02 13:54:25.077630882 +0100
@@ -2278,9 +2278,9 @@ check_ctz_array (tree ctor, unsigned HOS
 
   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, idx, elt)
 {
-  if (TREE_CODE (idx) != INTEGER_CST)
+  if (!tree_fits_shwi_p (idx))
return false;
-  if (TREE_CODE (elt) != INTEGER_CST && TREE_CODE (elt) != RAW_DATA_CST)
+  if (!tree_fits_shwi_p (elt) && TREE_CODE (elt) != RAW_DATA_CST)
return false;
 
   unsigned HOST_WIDE_INT index = tree_to_shwi (idx);

Jakub



[PATCH v3] Add new warning Wmissing-designated-initializers [PR39589]

2025-01-03 Thread Peter Frost
v3 Patch:
* adds documentation
* fixes formatting
* minor code cleanup

Currently the behaviour of Wmissing-field-initializers is inconsistent
between C and C++. The C warning assumes that missing designated
initializers are deliberate, and does not warn. The C++ warning does warn
for missing designated initializers.

This patch changes the behaviour of Wmissing-field-initializers to
universally not warn about missing designated initializers, and adds a new
warning for specifically for missing designated initializers.

NOTE TO MAINTAINERS: This is my first gcc contribution, so I don't have
git write access.

Successfully tested on x86_64-pc-linux-gnu.

PR c/39589

gcc/c-family/ChangeLog:

* c.opt (Wmissing-designated-initializers): New option.
* c.opt.urls: (Wmissing-designated-initializers): New option.

gcc/c/ChangeLog:

* c-typeck.cc (pop_init_level): Generate warning for missing designated
initializers rather than always ignore.

gcc/ChangeLog:

* common.opt.urls: (Wmissing-designated-initializers): New option.
* doc/invoke.texi: (Wmissing-designated-initializers): New option.

gcc/cp/ChangeLog:

* typeck2.cc (process_init_constructor_record): Add check if missing
initializer is designated, warn as appropriate.

gcc/testsuite/ChangeLog:

* g++.dg/diagnostic/base.C: Change flags.
* gcc.dg/20011021-1.c: Fix test, missing designated initializers can
generate a warning now.
* gcc.dg/missing-field-init-1.c: Change flags.
* gcc.dg/pr60784.c: Change flags.
* g++.dg/warn/missing-designated-initializers-1.C: New test.
* g++.dg/warn/missing-designated-initializers-2.C: New test.
* gcc.dg/missing-designated-initializers-1.c: New test.
* gcc.dg/missing-designated-initializers-2.c: New test.

---
 gcc/c-family/c.opt|   4 +
 gcc/c-family/c.opt.urls   |   3 +
 gcc/c/c-typeck.cc |  52 -
 gcc/common.opt.urls   |   2 +-
 gcc/cp/typeck2.cc | 100 +-
 gcc/doc/invoke.texi   |  40 ++-
 gcc/testsuite/g++.dg/diagnostic/base.C|   4 +-
 .../warn/missing-designated-initializers-1.C  |  12 +++
 .../warn/missing-designated-initializers-2.C  |  12 +++
 gcc/testsuite/gcc.dg/20011021-1.c |  17 ++-
 .../missing-designated-initializers-1.c   |  14 +++
 .../missing-designated-initializers-2.c   |  14 +++
 gcc/testsuite/gcc.dg/missing-field-init-1.c   |   2 +-
 gcc/testsuite/gcc.dg/pr60784.c|   2 +-
 14 files changed, 184 insertions(+), 94 deletions(-)
 create mode 100644 
gcc/testsuite/g++.dg/warn/missing-designated-initializers-1.C
 create mode 100644 
gcc/testsuite/g++.dg/warn/missing-designated-initializers-2.C
 create mode 100644 gcc/testsuite/gcc.dg/missing-designated-initializers-1.c
 create mode 100644 gcc/testsuite/gcc.dg/missing-designated-initializers-2.c

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 15698dc65bb..746adc8aaad 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1030,6 +1030,10 @@ Wmissing-field-initializers
 C ObjC C++ ObjC++ Var(warn_missing_field_initializers) Warning 
EnabledBy(Wextra)
 Warn about missing fields in struct initializers.
 
+Wmissing-designated-initializers
+C ObjC C++ ObjC++ Var(warn_missing_designated_initializers) Warning 
EnabledBy(Wextra)
+Warn about missing designated initializers in struct initializers.
+
 Wmissing-format-attribute
 C ObjC C++ ObjC++ Warning Alias(Wsuggest-attribute=format)
 ;
diff --git a/gcc/c-family/c.opt.urls b/gcc/c-family/c.opt.urls
index fd7ffd38d53..88772cd113f 100644
--- a/gcc/c-family/c.opt.urls
+++ b/gcc/c-family/c.opt.urls
@@ -553,6 +553,9 @@ 
UrlSuffix(gcc/Warning-Options.html#index-Wmissing-declarations)
 Wmissing-field-initializers
 UrlSuffix(gcc/Warning-Options.html#index-Wmissing-field-initializers)
 
+Wmissing-designated-initializers
+UrlSuffix(gcc/Warning-Options.html#index-Wmissing-designated-initializers)
+
 Wmissing-format-attribute
 UrlSuffix(gcc/Warning-Options.html#index-Wmissing-format-attribute)
 
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index dbb688cabaa..37cc95f4a37 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -10150,31 +10150,33 @@ pop_init_level (location_t loc, int implicit,
 }
 
   /* Warn when some struct elements are implicitly initialized to zero.  */
-  if (warn_missing_field_initializers
-  && constructor_type
-  && TREE_CODE (constructor_type) == RECORD_TYPE
-  && constructor_unfilled_fields)
-{
-   /* Do not warn for flexible array members or zero-length arrays.  */
-   while (constructor_unfilled_fields
-  && (!DECL_SIZE (constructor_unfilled_fields)
-  || integer_zerop (DECL_SIZE (constructor_unfilled_fields
- constructor_unfilled_fields = DEC

[PATCH] tree-ssa-dce: Punt on allocations with too large constant sizes [PR118224]

2025-01-03 Thread Jakub Jelinek
Hi!

As suggested by Richi in the PR, the following patch will fail to DCE
allocation calls if they have constant size which is too large (over
PTRDIFF_MAX), or for the case of calloc, if either of the arguments
is too large (in that case in theory the call could succeed if the other
argument is variable zero but who cares) or if both are constant and
their product overflows or is above PTRDIFF_MAX.

This will make some pedantic conformance tests happy, though if one
hides the size one will still need to use -fno-malloc-dce or obfuscate even
the malloc etc. uses.  If the size is constant and too large, it isn't worth
trying to optimize it.

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

2025-01-03  Jakub Jelinek  

PR tree-optimization/118224
* tree-ssa-dce.cc (is_removable_allocation_p): Don't return true
for allocations with constant size argument larger than PTRDIFF_MAX
or for calloc with one of the arguments constant larger than
PTRDIFF_MAX or their product known constant above PTRDIFF_MAX.
Fix comment typos, furhter -> further and then -> than.
* lto-section-in.cc (lto_free_function_in_decl_state_for_node):
Fix comment typo, furhter -> further.

* gcc.dg/pr118224.c: New test.
* c-c++-common/ubsan/vla-1.c (bar): Use noipa attribute instead
of noinline, noclone.

--- gcc/tree-ssa-dce.cc.jj  2025-01-02 11:23:26.890372040 +0100
+++ gcc/tree-ssa-dce.cc 2025-01-03 20:01:33.074172650 +0100
@@ -243,38 +243,101 @@ mark_operand_necessary (tree op)
 
 /* Return true if STMT is a call to allocation function that can be
optimized out if the memory block is never used for anything else
-   then NULL pointer check or free.
-   If NON_NULL_CHECK is false, we can furhter assume that return value
-   is never checked to be non-NULL. */
+   than NULL pointer check or free.
+   If NON_NULL_CHECK is false, we can further assume that return value
+   is never checked to be non-NULL.
+   Don't return true if it is called with constant size (or sizes for calloc)
+   and the size is excessively large (larger than PTRDIFF_MAX, for calloc
+   either argument larger than PTRDIFF_MAX or both constant and their product
+   larger than PTRDIFF_MAX).  */
 
 static bool
 is_removable_allocation_p (gcall *stmt, bool non_null_check)
 {
-  tree callee = gimple_call_fndecl (stmt);
+  int arg = -1;
+  tree callee = gimple_call_fndecl (stmt), a1, a2;
   if (callee != NULL_TREE
   && fndecl_built_in_p (callee, BUILT_IN_NORMAL))
 switch (DECL_FUNCTION_CODE (callee))
   {
   case BUILT_IN_MALLOC:
+   arg = 1;
+   goto do_malloc;
   case BUILT_IN_ALIGNED_ALLOC:
+   arg = 2;
+   goto do_malloc;
   case BUILT_IN_CALLOC:
+   arg = 3;
+   goto do_malloc;
   CASE_BUILT_IN_ALLOCA:
+   arg = 1;
+   goto do_malloc;
   case BUILT_IN_STRDUP:
   case BUILT_IN_STRNDUP:
-   return non_null_check ? flag_malloc_dce > 1 : flag_malloc_dce;
+   arg = 0;
+   /* FALLTHRU */
+  do_malloc:
+   if (non_null_check)
+ {
+   if (flag_malloc_dce <= 1)
+ return false;
+ }
+   else if (!flag_malloc_dce)
+ return false;
+   break;
 
   case BUILT_IN_GOMP_ALLOC:
-   return true;
+   arg = 2;
+   break;
 
   default:;
   }
 
-  if (callee != NULL_TREE
+  if (arg == -1
+  && callee != NULL_TREE
   && flag_allocation_dce
   && gimple_call_from_new_or_delete (stmt)
   && DECL_IS_REPLACEABLE_OPERATOR_NEW_P (callee))
-return true;
-  return false;
+arg = 1;
+
+  switch (arg)
+{
+case -1:
+  return false;
+case 0:
+  return true;
+case 1:
+case 2:
+  if (gimple_call_num_args (stmt) < (unsigned) arg)
+   return false;
+  a1 = gimple_call_arg (stmt, arg - 1);
+  if (tree_fits_uhwi_p (a1)
+ && (tree_to_uhwi (a1)
+ > tree_to_uhwi (TYPE_MAX_VALUE (ptrdiff_type_node
+   return false;
+  return true;
+case 3:
+  if (gimple_call_num_args (stmt) < 2)
+   return false;
+  a1 = gimple_call_arg (stmt, 0);
+  a2 = gimple_call_arg (stmt, 1);
+  if (tree_fits_uhwi_p (a1)
+ && (tree_to_uhwi (a1)
+ > tree_to_uhwi (TYPE_MAX_VALUE (ptrdiff_type_node
+   return false;
+  if (tree_fits_uhwi_p (a2)
+ && (tree_to_uhwi (a2)
+ > tree_to_uhwi (TYPE_MAX_VALUE (ptrdiff_type_node
+   return false;
+  if (TREE_CODE (a1) == INTEGER_CST
+ && TREE_CODE (a2) == INTEGER_CST
+ && (wi::to_widest (a1) + wi::to_widest (a2)
+ > tree_to_uhwi (TYPE_MAX_VALUE (ptrdiff_type_node
+   return false;
+  return true;
+default:
+  gcc_unreachable ();
+}
 }
 
 /* Return true if STMT is a conditional
--- gcc/lto-section-in.cc.jj2025-01-02 11:23:17.118508459 +0100
+++ gcc/lto-section-in.cc   2025-01-03 13:49:39.

[PATCH] c++: Honor complain in cp_build_function_call_vec for check_function_arguments warnings [PR117825]

2025-01-03 Thread Jakub Jelinek
Hi!

The following testcase ICEs due to re-entering diagnostics.
When diagnosing -Wformat-security warning, we try to print instantiation
context, which calls tsubst with tf_none, but that in the end calls
cp_build_function_call_vec which calls check_function_arguments which
diagnoses another warning (again -Wformat-security).

The other check_function_arguments caller, build_over_call, doesn't call
that function if !(complain & tf_warning), so I think the best fix is
to do it the same in cp_build_function_call_vec as well.

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

2025-01-03  Jakub Jelinek  

PR c++/117825
* typeck.cc (cp_build_function_call_vec): Don't call
check_function_arguments if complain doesn't have tf_warning bit set.

* g++.dg/warn/pr117825.C: New test.

--- gcc/cp/typeck.cc.jj 2025-01-02 11:47:10.437498434 +0100
+++ gcc/cp/typeck.cc2025-01-03 18:30:06.530525112 +0100
@@ -4513,9 +4513,11 @@ cp_build_function_call_vec (tree functio
 
   /* Check for errors in format strings and inappropriately
  null parameters.  */
-  bool warned_p = check_function_arguments (input_location, fndecl, fntype,
-   nargs, argarray, NULL,
-   cp_comp_parm_types);
+  bool warned_p
+= ((complain & tf_warning)
+   && check_function_arguments (input_location, fndecl, fntype,
+   nargs, argarray, NULL,
+   cp_comp_parm_types));
 
   ret = build_cxx_call (function, nargs, argarray, complain, orig_fndecl);
 
--- gcc/testsuite/g++.dg/warn/pr117825.C.jj 2025-01-03 18:43:07.110516278 
+0100
+++ gcc/testsuite/g++.dg/warn/pr117825.C2025-01-03 18:42:29.384048457 
+0100
@@ -0,0 +1,18 @@
+// PR c++/117825
+// { dg-do compile { target c++17 } }
+// { dg-options "-Wformat -Wformat-security" }
+
+__attribute__((format (printf, 1, 2)))
+int fails (const char *, ...) { return 0; }
+
+template 
+auto wrap (Args... args) -> decltype (func (args...))
+{
+  return func (args...);   // { dg-warning "format not a string literal 
and no format arguments" }
+}
+
+int
+main ()
+{
+  wrap ("Test!");
+}

Jakub



[PATCH] c++: Reinstate check for uninitialized bases with c++ <= 17 [PR118239]

2025-01-03 Thread Simon Martin
We currently accept this code with c++ <= 17 even though it's invalid
since the base is not initialized (we properly reject it with c++ >= 20)

=== cut here ===
struct NoMut1 { int a, b; };
struct NoMut3 : NoMut1 {
  constexpr NoMut3(int a, int b) {}
};
void mutable_subobjects() {
  constexpr NoMut3 nm3(1, 2);
}
=== cut here ===

This is a fallout of r0-118700-gc2b3ec18a494e3, that ignores all fields
with DECL_ARTIFICIAL in cx_check_missing_mem_inits, including those that
represent base classes, and need to be checked.

This patch makes sure that we only skip fields that have DECL_ARTIFICIAL
if they don't have DECL_FIELD_IS_BASE.

Successfully tested on x86_64-pc-linux-gnu.

PR c++/118239

gcc/cp/ChangeLog:

* constexpr.cc (cx_check_missing_mem_inits): Don't skip fields
with DECL_FIELD_IS_BASE.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-base8.C: New test.

---
 gcc/cp/constexpr.cc  |  8 +++
 gcc/testsuite/g++.dg/cpp0x/constexpr-base8.C | 24 
 2 files changed, 28 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-base8.C

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index c8be5a525ee..e1138d3 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -839,9 +839,8 @@ cx_check_missing_mem_inits (tree ctype, tree body, bool 
complain)
   if (i < nelts)
{
  index = CONSTRUCTOR_ELT (body, i)->index;
- /* Skip base and vtable inits.  */
- if (TREE_CODE (index) != FIELD_DECL
- || DECL_ARTIFICIAL (index))
+ /* Skip vtable inits.  */
+ if (TREE_CODE (index) != FIELD_DECL)
continue;
}
 
@@ -852,7 +851,8 @@ cx_check_missing_mem_inits (tree ctype, tree body, bool 
complain)
continue;
  if (DECL_UNNAMED_BIT_FIELD (field))
continue;
- if (DECL_ARTIFICIAL (field))
+ /* Artificial fields can be ignored unless they're bases.  */
+ if (DECL_ARTIFICIAL (field) && !DECL_FIELD_IS_BASE (field))
continue;
  if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
{
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-base8.C 
b/gcc/testsuite/g++.dg/cpp0x/constexpr-base8.C
new file mode 100644
index 000..ecc28693315
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-base8.C
@@ -0,0 +1,24 @@
+// PR c++/118239
+// { dg-do "compile" { target c++11 } }
+
+struct NoMut1 {
+  int a, b;
+};
+
+// Reported case.
+struct NoMut2 : NoMut1 {
+  constexpr NoMut2(int a, int b) /*: NoMut1()*/
+  {} // { dg-error "must be initialized" "" { target c++17_down } }
+};
+
+// Variant with explicit initialization of some member.
+struct NoMut3 : NoMut1 {
+  constexpr NoMut3(int a, int b) : c(0) /*, NoMut1()*/
+  {} // { dg-error "must be initialized" "" { target c++17_down } }
+  int c;
+};
+
+void mutable_subobjects() {
+  constexpr NoMut2 nm2(1, 2); // { dg-error "constant expression" }
+  constexpr NoMut3 nm3(1, 2); // { dg-error "constant expression" }
+}
-- 
2.44.0



Re: [PATCH] testsuite: libitm: Adjust how libitm.c++ passes link flags

2025-01-03 Thread Lewis Hyatt
On Fri, Jan 03, 2025 at 05:48:12PM +, Matthew Malcomson wrote:
> On 1/3/25 17:14, Joseph Myers wrote:
> > Does this patch cover everything dealt with by
> > 
> > ([PATCH] testsuite: libitm: Remove build directory path from test names),
> > or would some separate fix for that issue still be needed in the presence
> > of this patch?

> Ah -- I didn't notice that patch.
> 
> It looks like both do essentially the same thing.
> 
> That one identifies the use of the c++ test runner by checking for the
> presence of the `lang_test_file` variable, and in that case
> `libitm_target_compile` adds the options, while in my patch the c++ test
> runner adds options to `ALWAYS_CFLAGS` which `libitm_target_compile` uses
> directly.

Agreed, they both have the same effect. Mine just added -B symmetrically in
the same way that -L is already added. I guess that also underscores the
question of whether -B is even needed? I am not aware of any reason why it
should be needed when -L is already specified with the same directory, but
would be curious to know what I may be missing.

In any case, seems we may as well go with Matthew's latest version if it is
acked, since it keeps the changes isolated just to c++.exp and doesn't need
to touch libitm.exp?

-Lewis


Re: [PATCH] Fortran: Cray pointer comparison wrongly optimized away [PR106692]

2025-01-03 Thread Harald Anlauf

Hi Jerry!

Am 03.01.25 um 05:21 schrieb Jerry D:

On 1/2/25 12:04 PM, Harald Anlauf wrote:

Dear all,

this patch addresses overeager optimization of Cray pointers when
used in comparisons.  Cray pointers are non-standard, and odd in a
sense that they were introduced before modern Fortran pointers.
Comparisons with e.g. a "NULL" pointer are actually comparisons
with integer zero etc., which means that while they are references
they can actually be "NULL" to mimic a disassociated pointer.
The only solution I could find was treating them locally as volatile
when used in a comparison.  If someone has a better solution, please
share!

As this is a local solution, and a real-world legacy code using Cray
pointers would likely never use such a test in a vectorizable loop,
I expect negligible (performance and code-size) impact.

Regtested on x86_64-pc-linux-gnu.  OK for mainline?

This PR is marked as a regression (since gcc-7), is this OK for
a (limited?) backport?

Thanks,
Harald



The hack is fairly isolated and simple. The problem is a quirk from the 
past. The only way to expose an issue is to get it into the real world 
and see if anyone notices a problem.


I do not have access to any code using Cray pointers beyond what is in
the testsuite.  They might get used in some SPEC benchmark, we'll see.


OK for trunk and maybe 14.  If you think farther back, up to you.


Pushed to mainline as r15-6545 so far.

Thanks for the feedback!

Harald


Jerry






[COMMITTED] MMIX: Replace format for private symbol output by output-time adjustment

2025-01-03 Thread Hans-Peter Nilsson
All this started with belated MMIX regression patrol in observance of
the holidays, looking at gcc.dg/Wstringop-overflow-27.c as a
regression for target mmix.  That's because of a single message not
matched, where there is "note: destination object 'vla::22'" instead
of the expected "note: destination object 'vla'" due to
r11-5523-geafe8ee7af13c3 in which the message format and the match
changed.

That ::22 is because some identifiers that are SSA_NAME-versions and
other clones are "privatized" by ASM_FORMAT_PRIVATE_NAME and its
companion macro by default, ASM_PN_FORMAT; see the patch.  I found
that these "private names" were "unprivatized" for the purpose of
warnings and error messages *in code that only handles the default
format*, "%s.%lu".

I went ahead and wrote and tested a patch-set to hookize that
unprivatizing code, but found that it would only affect errors and
warnings; dumps still had the "target format".  While having bad
thoughts about being hit by yet another structural testism because of
the choice of outputting yet another target-specific format instead of
a canonical "versioned" format, I realized it *already was handling a
canonical format*: only the default "%s.%lu" is properly handled.

To wit, targets are better off with the default "%s.%lu" and adjusting
it (if needed, including not allowing "." or "$"), *at time of
assembly code output*.  IOW, outputs, both references and definitions,
pass a single label-output target code point: ASM_OUTPUT_LABELREF,
which is that time of output.  Some older testsuite adjustments need
to be unadjusted, but is another rabbit-hole, so I've kept that change
separate.  Other tests checking dumps, now started to pass for the
first time, some 20+.

* config/mmix/mmix.cc (mmix_asm_output_labelref): Replace '.'
with '::'.
* config/mmix/mmix.h (ASM_PN_FORMAT): Define to actual default.
---
 gcc/config/mmix/mmix.cc | 29 +
 gcc/config/mmix/mmix.h  | 10 +-
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/gcc/config/mmix/mmix.cc b/gcc/config/mmix/mmix.cc
index 39725c96991b..77e51118f149 100644
--- a/gcc/config/mmix/mmix.cc
+++ b/gcc/config/mmix/mmix.cc
@@ -1586,6 +1586,35 @@ mmix_asm_output_labelref (FILE *stream, const char *name)
 if (*name == '@')
   is_extern = 0;
 
+  size_t ndots = 0;
+  for (const char *s = name; *s != 0; s++)
+if (*s == '.')
+  ndots++;
+
+  /* Replace all '.' with '::'.  We don't want a '.' as part of an identifier
+ as that'd be incompatible with mmixal.  We also don't want to do things
+ like overriding the default "%s.%lu" by '#define ASM_PN_FORMAT "%s::%lu"'
+ as that format will show up in warnings and error messages.  The default
+ won't show up in warnings and errors, as there are mechanisms in place to
+ strip that (but that only handles the default format).  FIXME: Make sure
+ no ":" is seen in the object file; we don't really want that mmixal
+ feature visible there.  */
+  if (ndots > 0)
+{
+  char *colonized_name = XALLOCAVEC (char, strlen (name) + 1 + ndots);
+
+  char *cs = colonized_name;
+  const char *s = name;
+  for (; *s != 0; s++)
+   {
+ if (*s == '.')
+   *cs++ = ':';
+ *cs++ = *s;
+   }
+  *cs = 0;
+  name = colonized_name;
+}
+
   asm_fprintf (stream, "%s%U%s",
   is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
   name);
diff --git a/gcc/config/mmix/mmix.h b/gcc/config/mmix/mmix.h
index e20bca1d363e..3a4bd85dcff8 100644
--- a/gcc/config/mmix/mmix.h
+++ b/gcc/config/mmix/mmix.h
@@ -656,11 +656,11 @@ typedef struct { int regs; int lib; } CUMULATIVE_ARGS;
 #define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \
  sprintf (LABEL, "*%s:%ld", PREFIX, (long)(NUM))
 
-/* Insert "::"; these are rarer than internal labels.  FIXME: Make sure no
-   ":" is seen in the object file; we don't really want that mmixal
-   feature visible there.  We don't want the default, which uses a dot;
-   that'd be incompatible with mmixal.  */
-#define ASM_PN_FORMAT "%s::%lu"
+/* Override the default, which looks at NO_DOT_IN_LABEL and NO_DOLLAR_IN_LABEL.
+   We want the real default "%s.%lu" in dumps and compiler messages, but the
+   actual assembly code format is adjusted to the effect of "%s::%lu".  See
+   mmix_asm_output_labelref.  */
+#define ASM_PN_FORMAT "%s.%lu"
 
 #define ASM_OUTPUT_DEF(STREAM, NAME, VALUE) \
  mmix_asm_output_def (STREAM, NAME, VALUE)
-- 
2.39.2



[COMMITTED] testsuite: Replace MMIX-specific adjustments with TARGET_CALLEE_COPIES-adjustments

2025-01-03 Thread Hans-Peter Nilsson
Also tested that the pattern also matches a TARGET_CALLEE_COPIES-false target.

-- >8 --
With the dump now emitting "privatized symbols" in the default
"%s.%lu" format also for MMIX, there's still a difference for MMIX.
This time it's because numbers have changed (copies introduced before
this point) because it has TARGET_CALLEE_COPIES yielding true.
Redundant copies may have been elided at this point, but the change
in name remains.

Since that's true for other targets too, an obvious change is to
generalize the tested patterns to include TARGET_CALLEE_COPIES-true
targets, as a brief inspection of the history of these tests shows
that the point of these tests lie not in whether copies have been done
but in the part of the pattern that match a constant.

Also fixed up a "." where there should have been a "\\.".

* gcc.dg/tree-ssa/vector-4.c: Replace MMIX adjustments with
TARGET_CALLEE_COPIES-agnostic adjustments.
* gcc.dg/tree-ssa/forwprop-36.c: Ditto.  Correct pattern to match a
literal ".".
---
 gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c | 3 +--
 gcc/testsuite/gcc.dg/tree-ssa/vector-4.c| 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c 
b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c
index f3871bf45e86..d00b957a7d67 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c
@@ -21,5 +21,4 @@ main ()
   return 0;
 }
 
-/* { dg-final { scan-tree-dump "if \\(b.0_\[0-9\]+ != 0\\)" "cddce1" { target 
{ ! mmix-knuth-mmixware } } } } */
-/* { dg-final { scan-tree-dump "if \\(b::1_\[0-9\]+ != 0\\)" "cddce1" { target 
{ mmix-knuth-mmixware } } } } */
+/* { dg-final { scan-tree-dump "if \\(b\\.\[01\]_\[0-9\]+ != 0\\)" "cddce1" } 
} */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vector-4.c 
b/gcc/testsuite/gcc.dg/tree-ssa/vector-4.c
index 982a2a47d6a0..03d70fde55a8 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/vector-4.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vector-4.c
@@ -10,6 +10,5 @@ v4si vs (v4si a, v4si b)
 }
 
 /* The compound literal should be placed directly in the vec_perm.  */
-/* { dg-final { scan-tree-dump-times "VEC_PERM_EXPR ;" 1 
"gimple" { target { ! mmix-knuth-mmixware } } } } */
-/* { dg-final { scan-tree-dump-times "VEC_PERM_EXPR ;" 1 "gimple" { target mmix-knuth-mmixware } } } */
+/* { dg-final { scan-tree-dump-times "VEC_PERM_EXPR ;" 1 "gimple" } } */
 
-- 
2.39.2



[PATCH] c++: Implement mangling of RAW_DATA_CST [PR118278]

2025-01-03 Thread Jakub Jelinek
Hi!

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

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

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

2025-01-03  Jakub Jelinek  

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

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

--- gcc/cp/mangle.cc.jj 2025-01-02 11:47:10.534497080 +0100
+++ gcc/cp/mangle.cc2025-01-02 16:48:06.688649097 +0100
@@ -3748,8 +3748,41 @@ write_expression (tree expr)
unsigned reps = 1;
if (ce->index && TREE_CODE (ce->index) == RANGE_EXPR)
  reps = range_expr_nelts (ce->index);
-   for (unsigned j = 0; j < reps; ++j)
- write_expression (ce->value);
+   if (TREE_CODE (ce->value) == RAW_DATA_CST)
+ {
+   gcc_assert (reps == 1);
+   unsigned int len = RAW_DATA_LENGTH (ce->value);
+   /* If this is the last non-zero element, skip
+  zeros at the end.  */
+   if (i == last_nonzero)
+ while (len)
+   {
+ if (RAW_DATA_POINTER (ce->value)[len - 1])
+   break;
+ --len;
+   }
+   tree valtype = TREE_TYPE (ce->value);
+   for (unsigned int i = 0; i < len; ++i)
+ {
+   write_char ('L');
+   write_type (valtype);
+   unsigned HOST_WIDE_INT v;
+   if (!TYPE_UNSIGNED (valtype)
+   && TYPE_PRECISION (valtype) == BITS_PER_UNIT
+   && RAW_DATA_SCHAR_ELT (ce->value, i) < 0)
+ {
+   write_char ('n');
+   v = -RAW_DATA_SCHAR_ELT (ce->value, i);
+ }
+   else
+ v = RAW_DATA_UCHAR_ELT (ce->value, i);
+   write_unsigned_number (v);
+   write_char ('E');
+ }
+ }
+   else
+ for (unsigned j = 0; j < reps; ++j)
+   write_expression (ce->value);
  }
}
  else
--- gcc/testsuite/g++.dg/abi/mangle80.C.jj  2025-01-02 17:09:58.539575044 
+0100
+++ gcc/testsuite/g++.dg/abi/mangle80.C 2025-01-02 17:22:45.457988243 +0100
@@ -0,0 +1,67 @@
+// PR c++/118278
+// Verify that class literals are mangled the same way regardless
+// of the underlying type.
+// { dg-do compile { target c++20 } }
+// { dg-additional-options -fabi-compat-version=0 }
+
+struct I { int a[5], b[5], c[144]; };
+template  struct X { };
+
+typedef X Ti;
+void f (Ti) { }
+// { dg-final { scan-assembler 
"_Z1f1XIXtl1ItlA5_iLi1ELi2EEtlS1_EtlA144_i(?:Li101ELi102ELi103ELi104ELi105ELi106ELi255ELi254ELi253ELi252ELi251ELi0ELi1ELi2ELi3ELi4E){8}Li101ELi102E"
 } }
+
+struct C { unsigned char a[5], b[5], c[144]; };
+template  struct Y { };
+
+typedef Y Tca;
+void g (Tca) { }
+// { dg-final { scan-assembler 
"_Z1g1YIXtl1CtlA5_hLh1ELh2EEtlS1_EtlA144_h(?:Lh101ELh102ELh103ELh104ELh105ELh106ELh255ELh254ELh253ELh252ELh251ELh0ELh1ELh2ELh3ELh4E){8}Lh101ELh102E"
 } }
+
+typedef Y Tcs;
+void h (Tcs) { }
+// { dg-final { scan-assembler 
"_Z1h1YIXtl1CtlA5_hLh1ELh2EEtlS1_EtlA144_h(?:Lh101ELh102ELh103ELh104ELh105ELh106ELh255ELh254ELh253ELh252ELh251ELh0ELh1ELh2ELh3ELh4E){8}Lh101ELh102E"
 } }
+
+struct S { signed char a[5], b[5], c[144]; };
+template  struct Z { };
+
+typedef Z Tsc;
+
+void i (Tsc) { }
+// { dg-final { scan-assembler 
"_Z1i1ZIXtl1StlA5_aLa1ELa2EEtlS1_EtlA144_a(?:La101ELa102ELa103ELa104ELa105ELa106ELa95ELa94ELa93ELa92ELa91ELa0ELa1ELa2ELa3ELa4E){8}La101ELa102E"
 } }
--- gcc/testsuite/g++.dg/cpp/embed-19.C.jj  2025-01-02 17:02:08.181060996 
+0100
+++ gcc/testsuite/g++.dg/cpp/embed-19.C 2025-01-02 17:06:23.430544485 +0100
@@ -0,0 +1,18 @@
+// PR c++/118278
+// { dg-do compile { target c++20 } }
+// { dg-options "-fabi-compat-version=0" }
+
+struct C { unsigned char a[5], b[5], c[128]; };
+template  struct Y { };
+
+typedef Y Tca;
+void g (Tca) { }
+// { dg-final { scan-assembler 
"_Z1g1YIXtl1CtlA5_hLh1ELh2EEtlS1_EtlA128_h(?:Lh\[0-9]*E){128}" } }
+
+typedef Y Tcs;
+voi

[PATCH] i386: Change mnemonics from TCVTROWPS2PBF16[H, L] to TCVTROWPS2BF16[H, L]

2025-01-03 Thread Haochen Jiang
Hi all,

The mnemonics for TCVTROWPS2PBF16[H,L] has been changed to
TCVTROWPS2BF16[H,L] in ISE056. There will be also some more BF16
mnemonics change upcoming, which will fix the regression in PR118270.

Bootstraped and tested on x86_64-pc-linux-gnu. Ok for trunk?

Ref: https://cdrdv2.intel.com/v1/dl/getContent/671368

Thx,
Haochen

---

In ISE056, the mnemonics for TCVTROWPS2PBF16[H,L] has been changed to
TCVTROWPS2BF16[H,L].

gcc/ChangeLog:

* config/i386/amxavx512intrin.h
(_tile_cvtrowps2pbf16h_internal): Rename to...
(_tile_cvtrowps2bf16h_internal): ...this.
(_tile_cvtrowps2pbf16hi_internal): Rename to...
(_tile_cvtrowps2bf16hi_internal): ...this.
(_tile_cvtrowps2pbf16l_internal): Rename to...
(_tile_cvtrowps2bf16l_internal): ...this.
(_tile_cvtrowps2pbf16li_internal): Rename to...
(_tile_cvtrowps2bf16li_internal): ...this.
(_tile_cvtrowps2pbf16h): Rename to...
(_tile_cvtrowps2bf16h): ...this.
(_tile_cvtrowps2pbf16hi): Rename to...
(_tile_cvtrowps2bf16hi): ...this.
(_tile_cvtrowps2pbf16l): Rename to...
(_tile_cvtrowps2bf16l): ...this.
(_tile_cvtrowps2pbf16li): Rename to...
(_tile_cvtrowps2bf16li): ...this.

gcc/testsuite/ChangeLog:

* gcc.target/i386/amxavx512-asmatt-1.c: Adjust intrin call.
* gcc.target/i386/amxavx512-asmintel-1.c: Ditto.
* gcc.target/i386/amxavx512-cvtrowps2pbf16-2.c: Rename to...
* gcc.target/i386/amxavx512-cvtrowps2bf16-2.c: ...this. Rename
test functions.
---
 gcc/config/i386/amxavx512intrin.h | 32 +--
 .../gcc.target/i386/amxavx512-asmatt-1.c  | 12 +++
 .../gcc.target/i386/amxavx512-asmintel-1.c| 12 +++
 ...2pbf16-2.c => amxavx512-cvtrowps2bf16-2.c} | 30 -
 4 files changed, 43 insertions(+), 43 deletions(-)
 rename gcc/testsuite/gcc.target/i386/{amxavx512-cvtrowps2pbf16-2.c => 
amxavx512-cvtrowps2bf16-2.c} (67%)

diff --git a/gcc/config/i386/amxavx512intrin.h 
b/gcc/config/i386/amxavx512intrin.h
index 59d142948fb..ab5362571d1 100644
--- a/gcc/config/i386/amxavx512intrin.h
+++ b/gcc/config/i386/amxavx512intrin.h
@@ -53,38 +53,38 @@
   dst; \
 })
 
-#define _tile_cvtrowps2pbf16h_internal(src,A)  \
+#define _tile_cvtrowps2bf16h_internal(src,A)   \
 ({ \
   __m512bh dst;
\
   __asm__ volatile \
-  ("{tcvtrowps2pbf16h\t%1, %%tmm"#src", %0|tcvtrowps2pbf16h\t%0, %%tmm"#src", 
%1}" \
+  ("{tcvtrowps2bf16h\t%1, %%tmm"#src", %0|tcvtrowps2bf16h\t%0, %%tmm"#src", 
%1}"   \
: "=v" (dst) : "r" ((unsigned) (A)));   \
   dst; \
 })
 
-#define _tile_cvtrowps2pbf16hi_internal(src,imm)   \
+#define _tile_cvtrowps2bf16hi_internal(src,imm)\
 ({ \
   __m512bh dst;
\
   __asm__ volatile \
-  ("{tcvtrowps2pbf16h\t$"#imm", %%tmm"#src", %0|tcvtrowps2pbf16h\t%0, 
%%tmm"#src", "#imm"}"\
+  ("{tcvtrowps2bf16h\t$"#imm", %%tmm"#src", %0|tcvtrowps2bf16h\t%0, 
%%tmm"#src", "#imm"}"  \
: "=v" (dst) :);\
   dst; \
 })
 
-#define _tile_cvtrowps2pbf16l_internal(src,A)  \
+#define _tile_cvtrowps2bf16l_internal(src,A)   \
 ({ \
   __m512bh dst;
\
   __asm__ volatile \
-  ("{tcvtrowps2pbf16l\t%1, %%tmm"#src", %0|tcvtrowps2pbf16l\t%0, %%tmm"#src", 
%1}" \
+  ("{tcvtrowps2bf16l\t%1, %%tmm"#src", %0|tcvtrowps2bf16l\t%0, %%tmm"#src", 
%1}"   \
: "=v" (dst) : "r" ((unsigned) (A)));   \
   dst; \
 })
 
-#define _tile_cvtrowps2pbf16li_internal(src,imm)   \
+#define _tile_cvtrowps2bf16li_internal(src,imm)\
 ({ \
   __m512bh dst;
\
   __asm__ volatile \
-  ("{tcvtrowps2pbf16l\t$"#imm", %%tmm"#src", %0|tcvtrowps2pbf16l\t%0, 
%%tmm"#src", "#imm"}"\
+  ("{tcvtrowps2bf16l\t$"#imm", %%tmm"#src", %0|tcvt

[PATCH] varasm: Fix up array_size_for_constructor RAW_DATA_CST handling once again [PR118275]

2025-01-03 Thread Jakub Jelinek
Hi!

As the following testcases show (the latter only if I revert the
temporary reversion of the C++ large array speedup), the FEs aren't
really consistent in the type of array CONSTRUCTOR_ELTS indexes,
it can be bitsizetype, but can be sizetype as well.
Given that everything else is able to cope with it just fine,
I'm using build_int_cst which also doesn't care what type it is,
instead of bitsize_int, which I've used in PR117190 fix (previously
it was size_int).

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

2025-01-03  Jakub Jelinek  

PR c++/118275
* varasm.cc (array_size_for_constructor): Use build_int_cst
with TREE_TYPE (index) as first argument, instead of bitsize_int.

* g++.dg/cpp/embed-18.C: New test.
* g++.dg/ext/flexary41.C: New test.

--- gcc/varasm.cc.jj2025-01-02 11:23:27.0 +0100
+++ gcc/varasm.cc   2025-01-02 15:01:05.488162995 +0100
@@ -5648,7 +5648,8 @@ array_size_for_constructor (tree val)
index = TREE_OPERAND (index, 1);
   if (value && TREE_CODE (value) == RAW_DATA_CST)
index = size_binop (PLUS_EXPR, index,
-   bitsize_int (RAW_DATA_LENGTH (value) - 1));
+   build_int_cst (TREE_TYPE (index),
+  RAW_DATA_LENGTH (value) - 1));
   if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
max_index = index;
 }
--- gcc/testsuite/g++.dg/cpp/embed-18.C.jj  2025-01-02 14:48:07.819954910 
+0100
+++ gcc/testsuite/g++.dg/cpp/embed-18.C 2025-01-02 14:48:47.943398108 +0100
@@ -0,0 +1,15 @@
+// PR c++/118275
+// { dg-do compile }
+// { dg-options "" }
+
+struct A { int a; char b[]; };
+void bar (A *);
+
+void
+foo ()
+{
+  static struct A a = { .a = 1, .b = {
+#embed __FILE__
+} };
+  bar (&a);
+}
--- gcc/testsuite/g++.dg/ext/flexary41.C.jj 2025-01-02 14:49:42.029647539 
+0100
+++ gcc/testsuite/g++.dg/ext/flexary41.C2025-01-02 14:49:35.472738531 
+0100
@@ -0,0 +1,24 @@
+// PR c++/118275
+// { dg-do compile }
+// { dg-options "" }
+
+struct A { int a; char b[]; };
+void bar (A *);
+
+void
+foo ()
+{
+  static struct A a = { .a = 1, .b = {
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+} };
+  bar (&a);
+}

Jakub



[PATCH] rtlanal: Treat writes to sp as also writing to memory [PR117938]

2025-01-03 Thread Richard Sandiford
This PR was about a case in which late-combine moved a stack
deallocation across an earlier stack access.  This was possible
because the deallocation was missing the RTL-SSA equivalent of
a vop, which in turn was because rtl_properties didn't treat
the deallocation as writing to memory.  I think the bug was
ultimately there.

Tested on x86_64-linux-gnu (which the PR was reported against)
and aarch64-linux-gnu.  OK to install?

I don't think any earlier users of RTL-SSA are likely to be
affected by this, so I'm not sure it's worth a backport.

Richard


gcc/
PR rtl-optimization/117938
* rtlanal.cc (rtx_properties::try_to_add_dest): Treat writes
to the stack pointer as also writing to memory.

gcc/testsuite/
PR rtl-optimization/117938
* gcc.dg/torture/pr117938.c: New test.
---
 gcc/rtlanal.cc  | 14 +++---
 gcc/testsuite/gcc.dg/torture/pr117938.c | 36 +
 2 files changed, 47 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr117938.c

diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc
index e7efb48c398..8caffafdaa4 100644
--- a/gcc/rtlanal.cc
+++ b/gcc/rtlanal.cc
@@ -2163,10 +2163,18 @@ rtx_properties::try_to_add_dest (const_rtx x, unsigned 
int flags)
 
   if (LIKELY (REG_P (x)))
 {
-  /* We want to keep sp alive everywhere -  by making all
-writes to sp also use sp. */
   if (REGNO (x) == STACK_POINTER_REGNUM)
-   flags |= rtx_obj_flags::IS_READ;
+   {
+ /* Stack accesses are dependent on previous allocations and
+anti-dependent on later deallocations, so both types of
+stack operation are akin to a memory write.  */
+ if (ref_iter != ref_end)
+   *ref_iter++ = rtx_obj_reference (MEM_REGNO, flags, BLKmode);
+
+ /* We want to keep sp alive everywhere - by making all
+writes to sp also use sp.  */
+ flags |= rtx_obj_flags::IS_READ;
+   }
   try_to_add_reg (x, flags);
   return;
 }
diff --git a/gcc/testsuite/gcc.dg/torture/pr117938.c 
b/gcc/testsuite/gcc.dg/torture/pr117938.c
new file mode 100644
index 000..5a3b6d2156c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr117938.c
@@ -0,0 +1,36 @@
+/* { dg-do run { target { int32 && int128 } } } */
+/* { dg-additional-options "-Wno-psabi --param=max-cse-insns=1" } */
+
+typedef unsigned V __attribute__((__vector_size__(64)));
+typedef unsigned __int128 W __attribute__((__vector_size__(64)));
+unsigned a;
+W b;
+V c;
+W d;
+
+__attribute__((__noinline__))
+W
+bar (unsigned u, V z, W w)
+{
+  u *= z[5];
+  return u + w;
+}
+
+W
+foo (V v)
+{
+  unsigned g = a ? 1 : -1;
+  v ^= 0 <= v;
+  v <<= ((V){ bar (0, c, b)[0] } & 1);
+  v >>= ((V){ g, bar (1, c, b)[0] } & 1);
+  return a + b + (W) v + d;
+}
+
+int
+main ()
+{
+  V x = (V) foo ((V) { });
+  for (unsigned i = 0; i < sizeof(x)/sizeof(x[0]); i++)
+if (x[i] != (i ? 0x : 0x7fff))
+  __builtin_abort();
+}
-- 
2.25.1



Re: [PATCH] testsuite: torture: add LLVM testcase for DSE vs. -ftrivial-auto-var-init=

2025-01-03 Thread Mike Stump
On Jan 2, 2025, at 4:00 PM, Sam James  wrote:
> 
> This testcase came up in a recent LLVM bug report [0] for DSE vs
> -ftrivial-auto-var-init=. Add it to our testsuite given that area
> could do with better coverage.
> 
> [0] https://github.com/llvm/llvm-project/issues/119646
> 
> gcc/testsuite/ChangeLog:
> 
>   * gcc.dg/torture/dse-trivial-auto-var-init.c: New test.
> 
> Co-authored-by: Andrew Pinski 
> ---
> OK?

Ok.  If a bug currently in gcc, would be nice to submit a bug report, get a 
number and attach it into the test case. If a bug in the past, would be nice to 
attach that number to it.

> .../gcc.dg/torture/dse-trivial-auto-var-init.c  | 17 +
> 1 file changed, 17 insertions(+)
> create mode 100644 gcc/testsuite/gcc.dg/torture/dse-trivial-auto-var-init.c
> 
> diff --git a/gcc/testsuite/gcc.dg/torture/dse-trivial-auto-var-init.c 
> b/gcc/testsuite/gcc.dg/torture/dse-trivial-auto-var-init.c
> new file mode 100644
> index ..5a3d4c4e3ecb
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/torture/dse-trivial-auto-var-init.c
> @@ -0,0 +1,17 @@
> +/* Testcase for LLVM bug: https://github.com/llvm/llvm-project/issues/119646 
> */
> +/* { dg-do run } */
> +/* { dg-additional-options "-ftrivial-auto-var-init=zero" } */
> +
> +int b = 208;
> +[[gnu::noinline]]
> +void f(int *e, int a) {
> +  *e = !!b;
> +  if (a)
> +__builtin_trap();
> +}
> +int main(void) {
> +  b = 0;
> +  f(&b, 0);
> +  if (b != 0)
> +__builtin_trap();
> +}
> 
> base-commit: 99d5ef700619c28904846399a6f6692af4c56b1b
> -- 
> 2.47.1
> 



[COMMITTED] bpf: install a wrapping stdint.h for bpf-none-unknown targets

2025-01-03 Thread Jose E. Marchesi
This patch makes GCC to wrap the host's stdint.h header when operating
in the default hosted/non-freestanding mode.  It is thus up to the
user to provide a suitable standard header unless -ffreestanding gets
explicitly passed in the compilation line.

A few tests that use stdint.h are adapted to explicitly pass
-ffreestanding.

Tested in a x86_64-linux-gnu host with target bpf-unknown-none.

gcc/ChangeLog:

* config.gcc: install a wrapping stdint.h in bpf targets.

gcc/testsuite/ChangeLog:

* gcc.target/bpf/diag-funargs-2.c: Use -ffreestanding.
* gcc.target/bpf/helper-skb-ancestor-cgroup-id.c: Likewise.
* gcc.target/bpf/helper-bind.c: Likewise.
* gcc.target/bpf/diag-funargs-3.c: Likewise.
---
 gcc/config.gcc   | 2 +-
 gcc/testsuite/gcc.target/bpf/diag-funargs-2.c| 2 +-
 gcc/testsuite/gcc.target/bpf/diag-funargs-3.c| 2 +-
 gcc/testsuite/gcc.target/bpf/helper-bind.c   | 2 +-
 gcc/testsuite/gcc.target/bpf/helper-skb-ancestor-cgroup-id.c | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index c0147355087..55e37146ee0 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1690,7 +1690,7 @@ bpf-*-*)
 tm_file="elfos.h ${tm_file}"
 tmake_file="${tmake_file} bpf/t-bpf"
 use_collect2=no
-use_gcc_stdint=provide
+use_gcc_stdint=wrap
 extra_objs="btfext-out.o core-builtins.o"
 target_gtfiles="$target_gtfiles \$(srcdir)/config/bpf/btfext-out.cc 
\$(srcdir)/config/bpf/core-builtins.cc"
 ;;
diff --git a/gcc/testsuite/gcc.target/bpf/diag-funargs-2.c 
b/gcc/testsuite/gcc.target/bpf/diag-funargs-2.c
index 116f1bc849d..c4c89b6dad3 100644
--- a/gcc/testsuite/gcc.target/bpf/diag-funargs-2.c
+++ b/gcc/testsuite/gcc.target/bpf/diag-funargs-2.c
@@ -1,7 +1,7 @@
 /* Verify proper errors are generated for functions taking too many
arguments, with aggregates and 128-bit arguments.  */
 /* { dg-do compile } */
-/* { dg-options "-O0" } */
+/* { dg-options "-O0 -ffreestanding" } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/bpf/diag-funargs-3.c 
b/gcc/testsuite/gcc.target/bpf/diag-funargs-3.c
index 598a9dbeb4b..9106d4f6edd 100644
--- a/gcc/testsuite/gcc.target/bpf/diag-funargs-3.c
+++ b/gcc/testsuite/gcc.target/bpf/diag-funargs-3.c
@@ -1,7 +1,7 @@
 /* Verify proper errors are generated for functions taking too many
arguments, with aggregates and 128-bit arguments.  */
 /* { dg-do compile } */
-/* { dg-options "-O0" } */
+/* { dg-options "-O0 -ffreestanding" } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/bpf/helper-bind.c 
b/gcc/testsuite/gcc.target/bpf/helper-bind.c
index 53514ba3233..3b20edc2b6a 100644
--- a/gcc/testsuite/gcc.target/bpf/helper-bind.c
+++ b/gcc/testsuite/gcc.target/bpf/helper-bind.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-std=gnu99" } */
+/* { dg-options "-std=gnu99 -ffreestanding" } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/bpf/helper-skb-ancestor-cgroup-id.c 
b/gcc/testsuite/gcc.target/bpf/helper-skb-ancestor-cgroup-id.c
index 075dbe6f852..a6505d45840 100644
--- a/gcc/testsuite/gcc.target/bpf/helper-skb-ancestor-cgroup-id.c
+++ b/gcc/testsuite/gcc.target/bpf/helper-skb-ancestor-cgroup-id.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-std=gnu99 -O2" } */
+/* { dg-options "-std=gnu99 -O2 -ffreestanding" } */
 
 #include 
 
-- 
2.30.2



Re: [PATCH] testsuite: libitm: Adjust how libitm.c++ passes link flags

2025-01-03 Thread Matthew Malcomson

Hi Richard,

I had a little bit more of a think about this patch, and have changed my
mind on how problematic it is to use ALWAYS_CFLAGS w.r.t. naming.  It is
already used by the C++ tests.  If we're happy to use that name then we
don't need to introduce a new save/restore.

Another reason I think this is better is that I noticed that elsewhere
in the testsuite TEST_ALWAYS_FLAGS seems to be specifically for holding
*flags* instead of DejaGNU options, which means that in order to stick
with existing usage we couldn't specify this -B argument is only needed
while linking.

Attaching a patch with this approach -- which is much simpler than the
previous patch.

How does that look to you?

On 1/2/25 15:58, Richard Sandiford wrote:

External email: Use caution opening links or attachments


Matthew Malcomson  writes:

On 1/2/25 12:08, Richard Sandiford wrote:

+# This set in order to give libitm.c++/c++.exp a nicely named flag to set
+# when adding C++ options.
+set TEST_ALWAYS_FLAGS ""


This looked odd at first glance.  By unconditionally writing "" to the
variable, it seems to subvert the save and restore done in c++.exp.



Yeah -- I see your point, that's not good.


How about instead copying the behaviour of asan_init and asan_finish,
so that libitm_init and libitm_finish do the save and restore?  Or perhaps
a slight variation: after saving, libitm_init can set TEST_ALWAYS_FLAGS
to "" if TEST_ALWAYS_FLAGS was previously unset.

c++.exp would then not need to save and restore the flags itself, and
could still assume that TEST_ALWAYS_FLAGS is always set.



Have made the suggested change -- mentioning the extra little bit of
complexity that this introduced ...

Since libitm is a "tool" in the DejaGNU sense (while asan is not),
libitm_finish gets called twice for each libitm_init call.

The `runtest` procedure in DejaGNU's `runtest.exp` calls `${tool}_init`,
executes the c.exp or c++.exp test runner and then calls
`${tool}_finish`, while in each of the test runners we also call
`dg-finish` (as required by the dg.exp API) which calls `${tool}_finish`
directly.

This means using `libitm_finish` needs an extra bit in global state to
check whether we have already reset things.
- Has been set in libitm_init and was unset at start
=> saved_TEST_ALWAYS_FLAGS is unset.
- Has been set in libitm_init and was set at start
=> saved_TEST_ALWAYS_FLAGS is set.
- Has already been reset => some other flag.


Ick.  Hadn't realised that dg-finish called *_finish while dg-init didn't
call *_init.

I suppose a way of handling this without the second variable would be to
make libitm_finish check whether TEST_ALWAYS_FLAGS is set.  If it isn't,
then it must be the second call to libitm_finish.

OK that way if you agree, or OK as-is if you think it's better.

Richard


Have attached the adjusted patch to this email.

 From fbce3b25e8ccad80697f1596f566b268fff71221 Mon Sep 17 00:00:00 2001
From: Matthew Malcomson 
Date: Wed, 11 Dec 2024 11:03:55 +
Subject: [PATCH] testsuite: libitm: Adjust how libitm.c++ passes link flags

For the `gcc` and `g++` tools we often pass -B/path/to/object/dir in via
`TEST_ALWAYS_FLAGS` (see e.g. asan.exp where this is set).
In libitm.c++/c++.exp we pass that -B flag via the `tool_flags` argument
to `dg-runtest`.

Passing as the `tool_flags` argument means that these flags get added to
the name of the test.  This means that if one were to compare the
testsuite results between runs made in different build directories
libitm.c++ gives a reasonable amount of NA->PASS and PASS->NA
differences even though the same tests passed each time.

This patch follows the example set in other parts of the testsuite like
asan_init and passes the -B arguments to the compiler via a global
variable called `TEST_ALWAYS_FLAGS`.  For this DejaGNU "tool" we had to
newly initialise that variable in libitm_init and add a check against
that variable in libitm_target_compile.  I thought about adding the
relevant flags we need for C++ into `ALWAYS_CFLAGS` but decided against
it since the name didn't match what we would be using it for.

We save the global `TEST_ALWAYS_FLAGS` in `libitm_init` and ensure
it's initialised.  We then reset this in `libitm_finish`.  Since
`libitm_finish` gets called twice (once from `dg-finish` and once from
the `runtest` procedure) we have to manage state to tell whether
TEST_ALWAYS_FLAGS has already been reset.

Testing done to bootstrap & regtest on AArch64.  Manually observed that
the testsuite diff between two different build directories no longer
exists.

N.b. since I pass the new flags in the `ldflags` option of the DejaGNU
options while the previous code always passed this -B flag, the compile
test throwdown.C no longer gets compiled with this -B flag.  I believe
that is not a problem.

libitm/ChangeLog:

   * testsuite/libitm.c++/c++.exp: Use TEST_ALWAYS_FLAGS instead of
   passing arguments to dg-runtest.
   * testsuite/lib/libitm.exp (libitm_init): Initialise
  

Re: [patch, Fortran, doc] Mention generating C prototypes from Fortran

2025-01-03 Thread Sam James
Thomas Koenig  writes:

> Hello world,
>
> I noticed that there is no mention of automatically generating
> C prototypes and declarations in the relevant section of
> the docs, "Interoperability with C". This patch remedies that.
>
> OK for trunk?
>
> Best regards
>
>   Thomas
>
> gcc/fortran/ChangeLog:
>
>   * gfortran.texi: New subsection "Generating C prototypes from
>   Fortran".
>
> [2. text/x-patch; p-unsigned.diff]...

This patch appears empty.


Re: [PATCH 1/2] testsuite: add testcase for fixed PR117546

2025-01-03 Thread Sam James
Sam James  writes:

> PR117546 was fixed by Eric's r14-10693-gadab597af288d6 change, but
> the testcase here is sufficiently different to be worth including
> in torture/.
>
> gcc/testsuite/ChangeLog:
>   PR ipa/117546
>   * gcc.dg/torture/pr117546.c: New test.
> ---

Sorry, forgot to ask: OK? (for both)

>  gcc/testsuite/gcc.dg/torture/pr117546.c | 84 +
>  1 file changed, 84 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/torture/pr117546.c
>
> diff --git a/gcc/testsuite/gcc.dg/torture/pr117546.c 
> b/gcc/testsuite/gcc.dg/torture/pr117546.c
> new file mode 100644
> index ..21e2aef18b9a
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/torture/pr117546.c
> @@ -0,0 +1,84 @@
> +/* { dg-do run } */
> +
> +typedef struct {
> +  int a;
> +  int b;
> +} c;
> +
> +typedef struct {
> +  int a;
> +  int b;
> +  int d;
> +} e;
> +
> +typedef struct {
> +  int f;
> +  int g;
> +} h;
> +
> +typedef struct {
> +  h i[1];
> +  e coords[100];
> +} j;
> +
> +struct k {
> +  j glyf;
> +} l;
> +
> +int m, n;
> +double o;
> +e *q;
> +e r;
> +
> +int s(c *v) {
> +  if (v[0].a == m)
> +__builtin_abort();
> +  int t = v[0].a + v[2].b * (v[2].b - v[0].b),
> +  u = (2. + v[4].b - v[2].b) * (v[4].b - v[2].b);
> +  if (t <= 3 * u) {
> +v[0] = v[4];
> +return 1;
> +  }
> +  return 0;
> +}
> +
> +void w(struct k *v) {
> +  c p[5];
> +  e *a = &v->glyf.coords[0];
> +  if (a->d)
> +p[0].a = p[0].b = a->b;
> +  q = &r;
> +  o = p[0].b;
> +  while (v->glyf.i[0].g--) {
> +q = q == &r ? a : q + 1;
> +if (q->d)
> +  switch (n) {
> +  case 2:
> +p[4].a = q->a;
> +p[4].b = q->b;
> +n = s(p);
> +  }
> +else
> +  switch (n) {
> +  case 0:
> +n = 1;
> +break;
> +  case 1:
> +p[2].b = q->b;
> +n = 2;
> +break;
> +  case 2:
> +if (s(p))
> +  n = 1;
> +  }
> +  }
> +}
> +
> +int main() {
> +  l.glyf.i[0] = (h){0, 26};
> +  l.glyf.coords[0] = (e){4, 2, 3};
> +  l.glyf.coords[3] = (e){2, 126, 3};
> +  l.glyf.coords[4] = (e){2, 206};
> +  l.glyf.coords[6] = (e){0, 308, 5};
> +  w(&l);
> +}
>
> base-commit: 26ca00eeedb01f9d5102586b76ae2a6e787111af


Re: [PATCH]AArch64: Implement four and eight chunk VLA concats [PR118272]

2025-01-03 Thread Richard Sandiford
Tamar Christina  writes:
>> -Original Message-
>> From: Richard Sandiford 
>> Sent: Friday, January 3, 2025 10:59 AM
>> To: Tamar Christina 
>> Cc: gcc-patches@gcc.gnu.org; nd ; Richard Earnshaw
>> ; ktkac...@gcc.gnu.org
>> Subject: Re: [PATCH]AArch64: Implement four and eight chunk VLA concats
>> [PR118272]
>> 
>> Tamar Christina  writes:
>> >> >
>> >> > How about instead doing something like:
>> >> >
>> >> >   worklist.reserve (nelts);
>> >> >   for (int i = 0; i < nelts; ++i)
>> >> > worklist.quick_push (force_reg (elem_mode, XVECEXP (vals, 0, i)));
>> >> >
>> >> >   while (nelts > 2)
>> >> > {
>> >> >   for (int i = 0; i < nelts; i += 2)
>> >> > {
>> >> >   ...read worklist[i] and worklist[i + 1]...
>> >> >   ...write back to worklist[i / 2]...
>> >> > }
>> >> >   nelts /= 2;
>> >> > }
>> >> >
>> >> >   emit_insn (gen_aarch64_pack_partial (mode, target, worklist[0],
>> >> >worklist[1]));
>> >> >
>> >>
>> >> I think this is better since we above the memmove.. Apologies for the bug 
>> >> ☹
>> >>
>> >> I'll respin.
>> >
>> > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
>> >
>> > Ok for master?
>> >
>> > Thanks,
>> > Tamar
>> >
>> > gcc/ChangeLog:
>> >
>> > PR target/96342
>> > PR target/118272
>> > * config/aarch64/aarch64-sve.md (vec_init,
>> > vec_initvnx16qivnx2qi): New.
>> > * config/aarch64/aarch64.cc 
>> > (aarch64_sve_expand_vector_init_subvector):
>> > Rewrite to support any arbitrary combinations.
>> > * config/aarch64/iterators.md (SVE_NO2E): Update to use SVE_NO4E
>> > (SVE_NO2E, Vquad): New.
>> >
>> > gcc/testsuite/ChangeLog:
>> >
>> > PR target/96342
>> > PR target/118272
>> > * gcc.target/aarch64/vect-simd-clone-3.c: New test.
>> >
>> > -- inline copy of patch --
>> >
>> > diff --git a/gcc/config/aarch64/aarch64-sve.md 
>> > b/gcc/config/aarch64/aarch64-
>> sve.md
>> > index
>> 6659bb4fcab34699f22ff883825de1cd67108203..35f55bfacfc3238a8a7aa69015
>> f36ba32981af59 100644
>> > --- a/gcc/config/aarch64/aarch64-sve.md
>> > +++ b/gcc/config/aarch64/aarch64-sve.md
>> > @@ -2839,6 +2839,7 @@ (define_expand "vec_init"
>> >}
>> >  )
>> >
>> > +;; Vector constructor combining two half vectors { a, b }
>> >  (define_expand "vec_init"
>> >[(match_operand:SVE_NO2E 0 "register_operand")
>> > (match_operand 1 "")]
>> > @@ -2849,6 +2850,28 @@ (define_expand "vec_init"
>> >}
>> >  )
>> >
>> > +;; Vector constructor combining four quad vectors { a, b, c, d }
>> > +(define_expand "vec_init"
>> > +  [(match_operand:SVE_NO4E 0 "register_operand")
>> > +   (match_operand 1 "")]
>> > +  "TARGET_SVE"
>> > +  {
>> > +aarch64_sve_expand_vector_init_subvector (operands[0], operands[1]);
>> > +DONE;
>> > +  }
>> > +)
>> > +
>> > +;; Vector constructor combining eight vectors { a, b, c, d, ... }
>> > +(define_expand "vec_initvnx16qivnx2qi"
>> > +  [(match_operand:VNx16QI 0 "register_operand")
>> > +   (match_operand 1 "")]
>> > +  "TARGET_SVE"
>> > +  {
>> > +aarch64_sve_expand_vector_init_subvector (operands[0], operands[1]);
>> > +DONE;
>> > +  }
>> > +)
>> > +
>> >  ;; Shift an SVE vector left and insert a scalar into element 0.
>> >  (define_insn "vec_shl_insert_"
>> >[(set (match_operand:SVE_FULL 0 "register_operand")
>> > diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
>> > index
>> cb9b155826d12b622ae0df1736e4b042d01cf56a..c7c165ddb3a825a4e5ce4fc1
>> 18d39047ce9bf7e8 100644
>> > --- a/gcc/config/aarch64/aarch64.cc
>> > +++ b/gcc/config/aarch64/aarch64.cc
>> > @@ -24898,18 +24898,42 @@ aarch64_sve_expand_vector_init_subvector (rtx
>> target, rtx vals)
>> >machine_mode mode = GET_MODE (target);
>> >int nelts = XVECLEN (vals, 0);
>> >
>> > -  gcc_assert (nelts == 2);
>> > +  gcc_assert (nelts % 2 == 0);
>> >
>> > -  rtx arg0 = XVECEXP (vals, 0, 0);
>> > -  rtx arg1 = XVECEXP (vals, 0, 1);
>> > -
>> > -  /* If we have two elements and are concatting vector.  */
>> > -  machine_mode elem_mode = GET_MODE (arg0);
>> > +  /* We have to be concatting vector.  */
>> > +  machine_mode elem_mode = GET_MODE (XVECEXP (vals, 0, 0));
>> >gcc_assert (VECTOR_MODE_P (elem_mode));
>> >
>> > -  arg0 = force_reg (elem_mode, arg0);
>> > -  arg1 = force_reg (elem_mode, arg1);
>> > -  emit_insn (gen_aarch64_pack_partial (mode, target, arg0, arg1));
>> > +  auto_vec worklist;
>> > +  machine_mode wider_mode = elem_mode;
>> > +
>> > +  for (int i = 0; i < nelts; i++)
>> > +worklist.safe_push (force_reg (elem_mode, XVECEXP (vals, 0, i)));
>> > +
>> > +  /* Keep widening pairwise to have maximum throughput.  */
>> > +  while (nelts >= 2)
>> > +{
>> > +  wider_mode
>> > + = related_vector_mode (wider_mode, GET_MODE_INNER (wider_mode),
>> > +GET_MODE_NUNITS (wider_mode) * 2).require 
>> > ();
>> 
>> Formatting nit, sor

Re: [PATCH] testsuite: libitm: Adjust how libitm.c++ passes link flags

2025-01-03 Thread Joseph Myers
Does this patch cover everything dealt with by 
 
([PATCH] testsuite: libitm: Remove build directory path from test names), 
or would some separate fix for that issue still be needed in the presence 
of this patch?

-- 
Joseph S. Myers
josmy...@redhat.com



[PATCH] c++/modules: Fix linkage checks for exported using-decls

2025-01-03 Thread xxx
From: yxj-github-437 <2457369...@qq.com>

This patch attempts to fix an error when build module std. The reason for the
error is __builrin_va_list (aka struct __va_list) is an internal linkage. so
attempt to handle this builtin type by identifying whether DECL_SOURCE_LOCATION 
(entity)
is BUILTINS_LOCATION.

/x/gcc-15.0.0/usr/bin/aarch64-linux-android-g++ -fmodules -std=c++23 -fPIC -O2
-fsearch-include-path bits/std.cc -c
/x/gcc-15.0.0/usr/lib/gcc/aarch64-linux-android/15.0.0/include/c++/bits/std.cc:3642:14:
error: exporting ‘typedef __gnuc_va_list va_list’ that does not have external 
linkage
 3642 |   using std::va_list;
  |  ^~~
: note: ‘struct __va_list’ declared here with internal linkage

gcc:
* cp/name-lookup.cc (check_can_export_using_decl): add identifying 
whether
DECL_SOURCE_LOCATION (entity) is BUILTINS_LOCATION.
---
 gcc/cp/name-lookup.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 0e185d3ef42..73f3034adb4 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -5225,7 +5225,7 @@ check_can_export_using_decl (tree binding)
   if (TREE_CODE (entity) == TYPE_DECL)
 {
   entity = TYPE_MAIN_DECL (TREE_TYPE (entity));
-  if (!entity)
+  if (!entity || DECL_SOURCE_LOCATION (entity) == BUILTINS_LOCATION)
return true;
 }
 
-- 
2.43.0



Re: [RFC/RFA] [PR tree-optimization/92539] Improve code and avoid Warray-bounds false positive

2025-01-03 Thread Qing Zhao


> On Jan 3, 2025, at 11:41, Richard Biener  wrote:
> 
> 
> 
>> Am 03.01.2025 um 16:22 schrieb Jeff Law :
>> 
>> So this is an implementation of an idea I had a few years back and 
>> prototyped last spring to fix pr92539.
>> 
>> pr92539 is a false positive Warray-bounds warning triggered by loop 
>> unrolling.  The warning is in code that will never execute, but none of the 
>> optimizers clean things up well enough or early enough in the pipeline to 
>> avoid the warning.
>> 
>> To optimize away the code we can take advantage of the fact that we're 
>> comparing a value to a bogus pointer.  So for example an EQ comparison 
>> against &"aa" + 3 is always false and a NE comparison against that would 
>> always be true.
> 
> Forming the pointer invokes UB, the comparison is neither false nor true.  
> I’d say this is a classical case for path isolation on the pointer forming, 
> not only discarding either the true or false path of the compare.
> 
> The path isolation pass is probably too late in this case?

Path isolation pass is After bounds pass. 
From my understanding,  path isolation pass only insert TRAP on the problematic 
path.  The false positive warning on that path still there.  Please see:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106762

My work of adding -fdiagnostics-explain-harder also handled path isolation 
pass. 

Should the loop unrolling pass need to be adjusted to avoid forming the invalid 
pointers?

Qing

> 
>> I've implemented this in vr-values.  It's not my preferred location, but we 
>> need to handle this scenario before the array-bounds warnings which are 
>> currently placed immediately after vrp1.  So vr-values it was...
>> 
>> This could perhaps also be done in match.pd; there's a reasonable chance 
>> it's implementable there and would trigger early enough in the pipeline to 
>> avoid the false positive.  I can certainly explore that if folks think 
>> that's a better solution to this long standing issue.
>> 
>> Bootstrapped and regression tested on x86_64 and run through the crosses in 
>> my tester.
>> 
>> Anyway, thoughts?
>> 
>> Jeff
>> 
>> 




Re: [PATCH] testsuite: libitm: Adjust how libitm.c++ passes link flags

2025-01-03 Thread Matthew Malcomson

Ah -- I didn't notice that patch.

It looks like both do essentially the same thing.

That one identifies the use of the c++ test runner by checking for the 
presence of the `lang_test_file` variable, and in that case 
`libitm_target_compile` adds the options, while in my patch the c++ test 
runner adds options to `ALWAYS_CFLAGS` which `libitm_target_compile` 
uses directly.


On 1/3/25 17:14, Joseph Myers wrote:

External email: Use caution opening links or attachments


Does this patch cover everything dealt with by

([PATCH] testsuite: libitm: Remove build directory path from test names),
or would some separate fix for that issue still be needed in the presence
of this patch?

--
Joseph S. Myers
josmy...@redhat.com





[PATCH 1/2] testsuite: add testcase for fixed PR117546

2025-01-03 Thread Sam James
PR117546 was fixed by Eric's r14-10693-gadab597af288d6 change, but
the testcase here is sufficiently different to be worth including
in torture/.

gcc/testsuite/ChangeLog:
PR ipa/117546
* gcc.dg/torture/pr117546.c: New test.
---
 gcc/testsuite/gcc.dg/torture/pr117546.c | 84 +
 1 file changed, 84 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr117546.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr117546.c 
b/gcc/testsuite/gcc.dg/torture/pr117546.c
new file mode 100644
index ..21e2aef18b9a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr117546.c
@@ -0,0 +1,84 @@
+/* { dg-do run } */
+
+typedef struct {
+  int a;
+  int b;
+} c;
+
+typedef struct {
+  int a;
+  int b;
+  int d;
+} e;
+
+typedef struct {
+  int f;
+  int g;
+} h;
+
+typedef struct {
+  h i[1];
+  e coords[100];
+} j;
+
+struct k {
+  j glyf;
+} l;
+
+int m, n;
+double o;
+e *q;
+e r;
+
+int s(c *v) {
+  if (v[0].a == m)
+__builtin_abort();
+  int t = v[0].a + v[2].b * (v[2].b - v[0].b),
+  u = (2. + v[4].b - v[2].b) * (v[4].b - v[2].b);
+  if (t <= 3 * u) {
+v[0] = v[4];
+return 1;
+  }
+  return 0;
+}
+
+void w(struct k *v) {
+  c p[5];
+  e *a = &v->glyf.coords[0];
+  if (a->d)
+p[0].a = p[0].b = a->b;
+  q = &r;
+  o = p[0].b;
+  while (v->glyf.i[0].g--) {
+q = q == &r ? a : q + 1;
+if (q->d)
+  switch (n) {
+  case 2:
+p[4].a = q->a;
+p[4].b = q->b;
+n = s(p);
+  }
+else
+  switch (n) {
+  case 0:
+n = 1;
+break;
+  case 1:
+p[2].b = q->b;
+n = 2;
+break;
+  case 2:
+if (s(p))
+  n = 1;
+  }
+  }
+}
+
+int main() {
+  l.glyf.i[0] = (h){0, 26};
+  l.glyf.coords[0] = (e){4, 2, 3};
+  l.glyf.coords[3] = (e){2, 126, 3};
+  l.glyf.coords[4] = (e){2, 206};
+  l.glyf.coords[6] = (e){0, 308, 5};
+  w(&l);
+}

base-commit: 26ca00eeedb01f9d5102586b76ae2a6e787111af
-- 
2.47.1



[PATCH 2/2] testsuite: add testcase for fixed PR98000

2025-01-03 Thread Sam James
gcc/testsuite/ChangeLog:
PR ipa/98000
* g++.dg/ipa/pr98000.C: New test.
---
 gcc/testsuite/g++.dg/ipa/pr98000.C | 68 ++
 1 file changed, 68 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/ipa/pr98000.C

diff --git a/gcc/testsuite/g++.dg/ipa/pr98000.C 
b/gcc/testsuite/g++.dg/ipa/pr98000.C
new file mode 100644
index ..893812fd0cfd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pr98000.C
@@ -0,0 +1,68 @@
+/* { dg-do compile { target c++17 } } */
+/* { dg-options "-Og -w" } */
+
+struct {
+  template  T *operator()(T);
+} hb_addressof;
+template  static int _hb_cmp_method(Ts...) 
{
+  return 0;
+}
+template 
+inline bool hb_bsearch_impl(K key, V, int compar(void *, void *)) {
+  V p;
+  int __trans_tmp_2 = *hb_addressof(key) = compar(&__trans_tmp_2, p);
+  return false;
+}
+struct hb_array_t {
+  int arrayZ;
+};
+struct hb_sorted_array_t : hb_array_t {
+  void bsearch() {
+hb_bsearch_impl(bsearch_impl_x, &arrayZ, _hb_cmp_method);
+  }
+  int bsearch_impl_x;
+};
+template  struct hb_lazy_loader_t {
+  Returned *operator->();
+};
+namespace OT {
+struct COLR;
+}
+struct hb_ot_face_t {
+  hb_lazy_loader_t COLR;
+};
+struct {
+  hb_ot_face_t table;
+} hb_ot_color_glyph_get_layers_face;
+namespace OT {
+struct IntType {
+  typedef int wide_type;
+  operator wide_type();
+};
+struct UnsizedArrayOf;
+struct OffsetTo {
+  template  friend UnsizedArrayOf operator+(Base, OffsetTo);
+};
+template  using LOffsetTo = OffsetTo;
+template  using LNNOffsetTo = LOffsetTo;
+struct UnsizedArrayOf {
+  void as_array(int);
+};
+struct SortedUnsizedArrayOf {
+  hb_sorted_array_t __trans_tmp_4;
+  void bsearch() { __trans_tmp_4.bsearch(); }
+};
+struct COLR {
+  SortedUnsizedArrayOf __trans_tmp_3;
+  int get_glyph_layers() {
+__trans_tmp_3.bsearch();
+int __trans_tmp_3 = numLayers;
+(this + layersZ).as_array(__trans_tmp_3);
+  }
+  LNNOffsetTo layersZ;
+  IntType numLayers;
+};
+} // namespace OT
+void hb_ot_color_glyph_get_layers() {
+  hb_ot_color_glyph_get_layers_face.table.COLR->get_glyph_layers();
+}
-- 
2.47.1



RE: [PATCH] i386: Change mnemonics from TCVTROWPS2PBF16[H,L] to TCVTROWPS2BF16[H,L]

2025-01-03 Thread Liu, Hongtao


> -Original Message-
> From: Jiang, Haochen 
> Sent: Friday, January 3, 2025 4:55 PM
> To: gcc-patches@gcc.gnu.org
> Cc: Liu, Hongtao ; ubiz...@gmail.com
> Subject: [PATCH] i386: Change mnemonics from TCVTROWPS2PBF16[H,L] to
> TCVTROWPS2BF16[H,L]
> 
> Hi all,
> 
> The mnemonics for TCVTROWPS2PBF16[H,L] has been changed to
> TCVTROWPS2BF16[H,L] in ISE056. There will be also some more BF16
> mnemonics change upcoming, which will fix the regression in PR118270.
Please add PR target/118270 to changelog, otherwise LGTM.
> 
> Bootstraped and tested on x86_64-pc-linux-gnu. Ok for trunk?
> 
> Ref: https://cdrdv2.intel.com/v1/dl/getContent/671368
> 
> Thx,
> Haochen
> 
> ---
> 
> In ISE056, the mnemonics for TCVTROWPS2PBF16[H,L] has been changed to
> TCVTROWPS2BF16[H,L].
> 
> gcc/ChangeLog:
> 
>   * config/i386/amxavx512intrin.h
>   (_tile_cvtrowps2pbf16h_internal): Rename to...
>   (_tile_cvtrowps2bf16h_internal): ...this.
>   (_tile_cvtrowps2pbf16hi_internal): Rename to...
>   (_tile_cvtrowps2bf16hi_internal): ...this.
>   (_tile_cvtrowps2pbf16l_internal): Rename to...
>   (_tile_cvtrowps2bf16l_internal): ...this.
>   (_tile_cvtrowps2pbf16li_internal): Rename to...
>   (_tile_cvtrowps2bf16li_internal): ...this.
>   (_tile_cvtrowps2pbf16h): Rename to...
>   (_tile_cvtrowps2bf16h): ...this.
>   (_tile_cvtrowps2pbf16hi): Rename to...
>   (_tile_cvtrowps2bf16hi): ...this.
>   (_tile_cvtrowps2pbf16l): Rename to...
>   (_tile_cvtrowps2bf16l): ...this.
>   (_tile_cvtrowps2pbf16li): Rename to...
>   (_tile_cvtrowps2bf16li): ...this.
> 
> gcc/testsuite/ChangeLog:
> 
>   * gcc.target/i386/amxavx512-asmatt-1.c: Adjust intrin call.
>   * gcc.target/i386/amxavx512-asmintel-1.c: Ditto.
>   * gcc.target/i386/amxavx512-cvtrowps2pbf16-2.c: Rename to...
>   * gcc.target/i386/amxavx512-cvtrowps2bf16-2.c: ...this. Rename
>   test functions.
> ---
>  gcc/config/i386/amxavx512intrin.h | 32 +--
>  .../gcc.target/i386/amxavx512-asmatt-1.c  | 12 +++
>  .../gcc.target/i386/amxavx512-asmintel-1.c| 12 +++
>  ...2pbf16-2.c => amxavx512-cvtrowps2bf16-2.c} | 30 -
>  4 files changed, 43 insertions(+), 43 deletions(-)  rename
> gcc/testsuite/gcc.target/i386/{amxavx512-cvtrowps2pbf16-2.c =>
> amxavx512-cvtrowps2bf16-2.c} (67%)
> 
> diff --git a/gcc/config/i386/amxavx512intrin.h
> b/gcc/config/i386/amxavx512intrin.h
> index 59d142948fb..ab5362571d1 100644
> --- a/gcc/config/i386/amxavx512intrin.h
> +++ b/gcc/config/i386/amxavx512intrin.h
> @@ -53,38 +53,38 @@
>dst;   
> \
>  })
> 
> -#define _tile_cvtrowps2pbf16h_internal(src,A)
>   \
> +#define _tile_cvtrowps2bf16h_internal(src,A) \
>  ({   \
>__m512bh dst;
>   \
>__asm__ volatile   \
> -
> ("{tcvtrowps2pbf16h\t%1, %%tmm"#src", %0|tcvtrowps2pbf16h\t%0, %%t
> mm"#src", %1}"\
> +
> ("{tcvtrowps2bf16h\t%1, %%tmm"#src", %0|tcvtrowps2bf16h\t%0, %%tm
> m"#src", %1}" \
> : "=v" (dst) : "r" ((unsigned) (A))); \
>dst;   
> \
>  })
> 
> -#define _tile_cvtrowps2pbf16hi_internal(src,imm) \
> +#define _tile_cvtrowps2bf16hi_internal(src,imm)  \
>  ({   \
>__m512bh dst;
>   \
>__asm__ volatile   \
> -
> ("{tcvtrowps2pbf16h\t$"#imm", %%tmm"#src", %0|tcvtrowps2pbf16h\t%0,
>  %%tmm"#src", "#imm"}"\
> +
> ("{tcvtrowps2bf16h\t$"#imm", %%tmm"#src", %0|tcvtrowps2bf16h\t%0, %
> %tmm"#src", "#imm"}"  \
> : "=v" (dst) :);  \
>dst;   
> \
>  })
> 
> -#define _tile_cvtrowps2pbf16l_internal(src,A)
> \
> +#define _tile_cvtrowps2bf16l_internal(src,A) \
>  ({   \
>__m512bh dst;
>   \
>__asm__ volatile   \
> -
> ("{tcvtrowps2pbf16l\t%1, %%tmm"#src", %0|tcvtrowps2pbf16l\t%0, %%tm
> m"#src", %1}" \
> +
> ("{tcvtrowps2bf16l\t%1, %%tmm"#src", %0|tcvtrowps2bf16l\t%0, %%tmm"
> #src", %1}"   \
> : "=v" (dst) : "r" ((unsigned) (A))); \
>dst;   
> \
>  })
> 
> -#define _tile_cvtrowps2pbf16li_internal(src,imm) \
> +#define _tile_cvtrowps2bf16li_internal(src,imm)  \
>  ({   \
>__

Re: [PATCH]AArch64: Implement four and eight chunk VLA concats [PR118272]

2025-01-03 Thread Richard Sandiford
Tamar Christina  writes:
>> >
>> > How about instead doing something like:
>> >
>> >   worklist.reserve (nelts);
>> >   for (int i = 0; i < nelts; ++i)
>> > worklist.quick_push (force_reg (elem_mode, XVECEXP (vals, 0, i)));
>> >
>> >   while (nelts > 2)
>> > {
>> >   for (int i = 0; i < nelts; i += 2)
>> > {
>> >   ...read worklist[i] and worklist[i + 1]...
>> >   ...write back to worklist[i / 2]...
>> > }
>> >   nelts /= 2;
>> > }
>> >
>> >   emit_insn (gen_aarch64_pack_partial (mode, target, worklist[0],
>> >worklist[1]));
>> >
>>
>> I think this is better since we above the memmove.. Apologies for the bug ☹
>>
>> I'll respin.
>
> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
>
> Ok for master?
>
> Thanks,
> Tamar
>
> gcc/ChangeLog:
>
> PR target/96342
> PR target/118272
> * config/aarch64/aarch64-sve.md (vec_init,
> vec_initvnx16qivnx2qi): New.
> * config/aarch64/aarch64.cc 
> (aarch64_sve_expand_vector_init_subvector):
> Rewrite to support any arbitrary combinations.
> * config/aarch64/iterators.md (SVE_NO2E): Update to use SVE_NO4E
> (SVE_NO2E, Vquad): New.
>
> gcc/testsuite/ChangeLog:
>
> PR target/96342
> PR target/118272
> * gcc.target/aarch64/vect-simd-clone-3.c: New test.
>
> -- inline copy of patch --
>
> diff --git a/gcc/config/aarch64/aarch64-sve.md 
> b/gcc/config/aarch64/aarch64-sve.md
> index 
> 6659bb4fcab34699f22ff883825de1cd67108203..35f55bfacfc3238a8a7aa69015f36ba32981af59
>  100644
> --- a/gcc/config/aarch64/aarch64-sve.md
> +++ b/gcc/config/aarch64/aarch64-sve.md
> @@ -2839,6 +2839,7 @@ (define_expand "vec_init"
>}
>  )
>
> +;; Vector constructor combining two half vectors { a, b }
>  (define_expand "vec_init"
>[(match_operand:SVE_NO2E 0 "register_operand")
> (match_operand 1 "")]
> @@ -2849,6 +2850,28 @@ (define_expand "vec_init"
>}
>  )
>
> +;; Vector constructor combining four quad vectors { a, b, c, d }
> +(define_expand "vec_init"
> +  [(match_operand:SVE_NO4E 0 "register_operand")
> +   (match_operand 1 "")]
> +  "TARGET_SVE"
> +  {
> +aarch64_sve_expand_vector_init_subvector (operands[0], operands[1]);
> +DONE;
> +  }
> +)
> +
> +;; Vector constructor combining eight vectors { a, b, c, d, ... }
> +(define_expand "vec_initvnx16qivnx2qi"
> +  [(match_operand:VNx16QI 0 "register_operand")
> +   (match_operand 1 "")]
> +  "TARGET_SVE"
> +  {
> +aarch64_sve_expand_vector_init_subvector (operands[0], operands[1]);
> +DONE;
> +  }
> +)
> +
>  ;; Shift an SVE vector left and insert a scalar into element 0.
>  (define_insn "vec_shl_insert_"
>[(set (match_operand:SVE_FULL 0 "register_operand")
> diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
> index 
> cb9b155826d12b622ae0df1736e4b042d01cf56a..c7c165ddb3a825a4e5ce4fc118d39047ce9bf7e8
>  100644
> --- a/gcc/config/aarch64/aarch64.cc
> +++ b/gcc/config/aarch64/aarch64.cc
> @@ -24898,18 +24898,42 @@ aarch64_sve_expand_vector_init_subvector (rtx 
> target, rtx vals)
>machine_mode mode = GET_MODE (target);
>int nelts = XVECLEN (vals, 0);
>
> -  gcc_assert (nelts == 2);
> +  gcc_assert (nelts % 2 == 0);
>
> -  rtx arg0 = XVECEXP (vals, 0, 0);
> -  rtx arg1 = XVECEXP (vals, 0, 1);
> -
> -  /* If we have two elements and are concatting vector.  */
> -  machine_mode elem_mode = GET_MODE (arg0);
> +  /* We have to be concatting vector.  */
> +  machine_mode elem_mode = GET_MODE (XVECEXP (vals, 0, 0));
>gcc_assert (VECTOR_MODE_P (elem_mode));
>
> -  arg0 = force_reg (elem_mode, arg0);
> -  arg1 = force_reg (elem_mode, arg1);
> -  emit_insn (gen_aarch64_pack_partial (mode, target, arg0, arg1));
> +  auto_vec worklist;
> +  machine_mode wider_mode = elem_mode;
> +
> +  for (int i = 0; i < nelts; i++)
> +worklist.safe_push (force_reg (elem_mode, XVECEXP (vals, 0, i)));
> +
> +  /* Keep widening pairwise to have maximum throughput.  */
> +  while (nelts >= 2)
> +{
> +  wider_mode
> + = related_vector_mode (wider_mode, GET_MODE_INNER (wider_mode),
> +GET_MODE_NUNITS (wider_mode) * 2).require ();

Formatting nit, sorry, but: the last two lines seem to be indented
two columns too far.

> +
> +  for (int i = 0; i < nelts; i += 2)
> +   {
> + rtx arg0 = worklist[i];
> + rtx arg1 = worklist[i+1];
> + gcc_assert (GET_MODE (arg0) == GET_MODE (arg1));
> +
> + rtx tmp = gen_reg_rtx (wider_mode);
> + emit_insn (gen_aarch64_pack_partial (wider_mode, tmp, arg0, arg1));
> + worklist[i / 2] = tmp;
> +   }
> +
> +  nelts /= 2;
> +}
> +
> +  gcc_assert (wider_mode == mode);
> +  emit_move_insn (target, worklist[0]);

The reason I'd suggested using "while (nelts > 2)" and ending with:

  emit_insn (gen_aarch64_pack_partial (mode, target, worklist[0],
  

Re: [PATCH] c++: Implement for namespace statics CWG 2867 - Order of initialization for structured bindings [PR115769]

2025-01-03 Thread Jakub Jelinek
On Thu, Dec 19, 2024 at 11:56:10AM -0500, Jason Merrill wrote:
> Looks right.

So, I've tried to construct a testcase, but turns out modules.cc just
doesn't handle structured bindings at namespace scope at all, so it is
premature to try to get the ordering right in it.

The first patch contains the attempt to turn dr2867-5.C testcase into
a module header testcase with a fix for the first ICE I've run into
(but it ICEs immediately elsewhere, the assumption that all namespace
scope decls have names is all around).

The second patch is much simpler testcase which doesn't care about ordering
of anything and ICEs without/with the other patches the same.

Should be all !DECL_NAME (decl) MK_unique?  Or just
DECL_DECOMPOSITION_P (decl) && !DECL_NAME (decl)?
Structured bindings can't be redeclared, so I guess they are unique.

Jakub
2025-01-03  Jakub Jelinek  

* module.cc (trees_out::get_merge_kind): Don't ICE
if DECL_NAME is NULL.

* g++.dg/modules/dr2867-1_a.H: New test.
* g++.dg/modules/dr2867-1_b.C: New test.

--- gcc/cp/module.cc.jj 2025-01-02 11:47:10.367499411 +0100
+++ gcc/cp/module.cc2025-01-03 12:18:23.403515542 +0100
@@ -10985,7 +10985,8 @@ trees_out::get_merge_kind (tree decl, de
break;
  }
 
-   if (IDENTIFIER_ANON_P (DECL_NAME (decl)))
+   if (DECL_NAME (decl)
+   && IDENTIFIER_ANON_P (DECL_NAME (decl)))
  {
if (RECORD_OR_UNION_TYPE_P (ctx))
  mk = MK_field;
--- gcc/testsuite/g++.dg/modules/dr2867-1_a.H.jj2025-01-03 
12:05:52.601093929 +0100
+++ gcc/testsuite/g++.dg/modules/dr2867-1_a.H   2025-01-03 12:13:23.746737536 
+0100
@@ -0,0 +1,88 @@
+// CWG2867 - Order of initialization for structured bindings.
+// { dg-additional-options -fmodule-header }
+// { dg-module-cmi {} }
+
+#define assert(X) do { if (!(X)) __builtin_abort(); } while (0)
+
+namespace std {
+  template struct tuple_size;
+  template struct tuple_element;
+}
+
+extern int a, c, d, i;
+
+struct A {
+  A () { assert (c == 3); ++c; }
+  ~A () { ++a; }
+  template  int &get () const { assert (c == 5 + I); ++c; return i; }
+};
+
+template <> struct std::tuple_size  { static const int value = 4; };
+template  struct std::tuple_element  { using type = int; };
+template <> struct std::tuple_size  { static const int value = 4; };
+template  struct std::tuple_element  { using type = int; };
+
+struct B {
+  B () { assert (c >= 1 && c <= 2); ++c; }
+  ~B () { assert (c >= 9 && c <= 10); ++c; }
+};
+
+struct C {
+  constexpr C () {}
+  constexpr C (const C &) {}
+  template  int &get () const { assert (d == 1 + I); ++d; return i; }
+};
+
+template <> struct std::tuple_size  { static const int value = 3; };
+template  struct std::tuple_element  { using type = int; };
+template <> struct std::tuple_size  { static const int value = 3; };
+template  struct std::tuple_element  { using type = int; };
+
+inline A
+foo (const B &, const B &)
+{
+  A a;
+  assert (c == 4);
+  ++c;
+  return a;
+}
+
+constexpr C
+foo (const C &, const C &)
+{
+  return C {};
+}
+
+inline int
+bar (int &x, int y)
+{
+  x = y;
+  return y;
+}
+
+inline int
+baz (int &x, int y)
+{
+  assert (x == y);
+  return y;
+}
+
+struct E {
+  ~E () { assert (a == 2); }
+};
+
+namespace {
+E e;
+int c1 = bar (c, 1);
+const auto &[x, y, z, w] = foo (B {}, B {});
+int c2 = baz (c, 11);
+int d1 = bar (d, 1);
+const auto &[s, t, u] = foo (C {}, C {});
+int d2 = baz (d, 4);
+int c3 = bar (c, 1);
+auto [x2, y2, z2, w2] = foo (B {}, B {});
+int c4 = baz (c, 11);
+int d3 = bar (d, 1);
+auto [s2, t2, u2] = foo (C {}, C {});
+int d4 = baz (d, 4);
+}
--- gcc/testsuite/g++.dg/modules/dr2867-1_b.C.jj2025-01-03 
12:13:30.533641916 +0100
+++ gcc/testsuite/g++.dg/modules/dr2867-1_b.C   2025-01-03 12:13:51.037353027 
+0100
@@ -0,0 +1,13 @@
+// CWG2867 - Order of initialization for structured bindings.
+// { dg-do run }
+// { dg-additional-options "-fmodules-ts" }
+
+import "dr2867-1_a.H";
+
+int a, c, d, i;
+
+int
+main ()
+{
+  assert (a == 0);
+}
2025-01-03  Jakub Jelinek  

* g++.dg/modules/decomp-2_a.H: New test.
* g++.dg/modules/decomp-2_b.C: New test.

--- gcc/testsuite/g++.dg/modules/decomp-2_a.H.jj2025-01-03 
12:26:03.425073619 +0100
+++ gcc/testsuite/g++.dg/modules/decomp-2_a.H   2025-01-03 12:22:54.988707272 
+0100
@@ -0,0 +1,11 @@
+// { dg-additional-options -fmodule-header }
+// { dg-module-cmi {} }
+
+struct A {
+  int a, b, c;
+};
+
+namespace {
+A d = { 1, 2, 3 };
+auto [a, b, c] = d;
+}
--- gcc/testsuite/g++.dg/modules/decomp-2_b.C.jj2025-01-03 
12:26:06.737027332 +0100
+++ gcc/testsuite/g++.dg/modules/decomp-2_b.C   2025-01-03 12:25:26.431590654 
+0100
@@ -0,0 +1,11 @@
+// { dg-do run }
+// { dg-additional-options "-fmodules-ts" }
+
+import "decomp-2_a.H";
+
+int
+main ()
+{
+  if (a != 1 || b != 2 || c != 3)
+__builtin_abort ();
+}


Re: [PATCH v5 04/10] OpenMP: Robustify C front end handling of attribute-syntax pragmas

2025-01-03 Thread Sandra Loosemore

On 1/2/25 11:44, Tobias Burnus wrote:

[snip]
Otherwise, LGTM.


I've pushed the attached version of the patch after making the requested 
trivial changes and re-testing this piece of the series in isolation. 
It's independent of parts 1, 2, and 3 which are still pending, but a 
prerequisite for part 5, the C support for metadirective.


-SandraFrom 83e9dbbac718d439724f81c0f3a706d5cea389cf Mon Sep 17 00:00:00 2001
From: Sandra Loosemore 
Date: Fri, 3 Jan 2025 17:35:03 +
Subject: [PATCH] OpenMP: Robustify C front end handling of attribute-syntax
 pragmas

Presently, the code to handle OpenMP attribute-syntax pragmas in the C
front end assumes nothing else is messing with redirecting
parser->tokens, and makes no provision for restoring it from anything
other than parser->tokens_buf when the buffer allocated for the pragma
is exhausted.  Adding support for metadirectives will change that,
since it also needs to buffer tokens for the metadirective
alternatives, and an attribute-syntax directive can appear inside a
metadirective.

This patch adds a more general save/restore mechanism attached to the
parser via a pointer to a new struct omp_attribute_pragma_state.

gcc/c/ChangeLog

	* c-parser.cc (struct c_parser): Change in_omp_attribute_pragma
	field to be of type struct omp_attribute_pragma_state.
	(struct omp_attribute_pragma_state): New.
	(c_parser_skip_until_found): Use the new way to restore state
	on EOF.
	(c_parser_skip_to_pragma_eol): Likewise.
	(c_parser_handle_statement_omp_attributes): Create an
	omp_attribute_pragma_state to hold the restore state.  Do not
	store state in tok.flags.
	(omp_maybe_parse_omp_decl): Likewise.
---
 gcc/c/c-parser.cc | 46 --
 1 file changed, 32 insertions(+), 14 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index f72b0f0e39f..c46aac5f0a2 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -262,15 +262,25 @@ struct GTY(()) c_parser {
   struct omp_for_parse_data * GTY((skip)) omp_for_parse_state;
 
   /* If we're in the context of OpenMP directives written as C23
- attributes turned into pragma, vector of tokens created from that,
- otherwise NULL.  */
-  vec *in_omp_attribute_pragma;
+ attributes turned into pragma, the tokens field is temporarily
+ redirected.  This holds data needed to restore state afterwards.
+ It's NULL otherwise.  */
+  struct omp_attribute_pragma_state *in_omp_attribute_pragma;
 
   /* Set for omp::decl attribute parsing to the decl to which it
  appertains.  */
   tree in_omp_decl_attribute;
 };
 
+/* Holds data needed to restore the token stream to its previous state
+   after parsing an OpenMP attribute-syntax pragma.  */
+struct GTY(()) omp_attribute_pragma_state
+{
+  vec *token_vec;
+  c_token * GTY((skip)) save_tokens;
+  unsigned int save_tokens_avail;
+};
+
 /* Return a pointer to the Nth token in PARSERs tokens_buf.  */
 
 c_token *
@@ -1312,8 +1322,9 @@ c_parser_skip_until_found (c_parser *parser,
 	  c_token *token = c_parser_peek_token (parser);
 	  if (token->type == CPP_EOF)
 	{
-	  parser->tokens = &parser->tokens_buf[0];
-	  parser->tokens_avail = token->flags;
+	  parser->tokens = parser->in_omp_attribute_pragma->save_tokens;
+	  parser->tokens_avail
+		= parser->in_omp_attribute_pragma->save_tokens_avail;
 	  parser->in_omp_attribute_pragma = NULL;
 	}
 	}
@@ -1335,8 +1346,9 @@ c_parser_skip_until_found (c_parser *parser,
 	  c_token *token = c_parser_peek_token (parser);
 	  if (token->type == CPP_EOF)
 		{
-		  parser->tokens = &parser->tokens_buf[0];
-		  parser->tokens_avail = token->flags;
+		  parser->tokens = parser->in_omp_attribute_pragma->save_tokens;
+		  parser->tokens_avail
+		= parser->in_omp_attribute_pragma->save_tokens_avail;
 		  parser->in_omp_attribute_pragma = NULL;
 		}
 	}
@@ -1429,8 +1441,9 @@ c_parser_skip_to_pragma_eol (c_parser *parser, bool error_if_not_eol = true)
   c_token *token = c_parser_peek_token (parser);
   if (token->type == CPP_EOF)
 	{
-	  parser->tokens = &parser->tokens_buf[0];
-	  parser->tokens_avail = token->flags;
+	  parser->tokens = parser->in_omp_attribute_pragma->save_tokens;
+	  parser->tokens_avail
+	= parser->in_omp_attribute_pragma->save_tokens_avail;
 	  parser->in_omp_attribute_pragma = NULL;
 	}
 }
@@ -7184,7 +7197,6 @@ c_parser_handle_statement_omp_attributes (c_parser *parser, tree &attrs,
 return false;
 
   unsigned int tokens_avail = parser->tokens_avail;
-  gcc_assert (parser->tokens == &parser->tokens_buf[0]);
 
   tokens++;
   vec *toks = NULL;
@@ -7216,12 +7228,15 @@ c_parser_handle_statement_omp_attributes (c_parser *parser, tree &attrs,
   tok.type = CPP_EOF;
   tok.keyword = RID_MAX;
   tok.location = toks->last ().location;
-  tok.flags = tokens_avail;
   toks->quick_push (tok);
 
+  gcc_assert (!parser->in_omp_attribute_pragma);
+  parser->in_omp_attribute_pragma = ggc_alloc ();
+  parser->in_omp_att

Re: [PATCH] c++: Implement for namespace statics CWG 2867 - Order of initialization for structured bindings [PR115769]

2025-01-03 Thread Jakub Jelinek
On Fri, Jan 03, 2025 at 12:39:08PM +0100, Jakub Jelinek wrote:
> Should be all !DECL_NAME (decl) MK_unique?  Or just
> DECL_DECOMPOSITION_P (decl) && !DECL_NAME (decl)?
> Structured bindings can't be redeclared, so I guess they are unique.

With
--- gcc/cp/module.cc.jj 2025-01-02 11:47:10.367499411 +0100
+++ gcc/cp/module.cc2025-01-03 13:22:38.529485672 +0100
@@ -10985,6 +10985,12 @@ trees_out::get_merge_kind (tree decl, de
break;
  }
 
+   if (DECL_DECOMPOSITION_P (decl))
+ {
+   mk = MK_unique;
+   break;
+ }
+
if (IDENTIFIER_ANON_P (DECL_NAME (decl)))
  {
if (RECORD_OR_UNION_TYPE_P (ctx))

instead the second testcase doesn't ICE during -fmodule-header saving
anymore, but during import (on the simplified testcase):
0x11ba712 crash_signal
../../gcc/toplev.cc:322
0x891d9b is_bitfield_expr_with_lowered_type(tree_node const*)
../../gcc/cp/typeck.cc:2403
0x8920c0 is_bitfield_expr_with_lowered_type(tree_node const*)
../../gcc/cp/typeck.cc:2443
0x892105 is_bitfield_expr_with_lowered_type(tree_node const*)
../../gcc/cp/typeck.cc:2449
0x89215a unlowered_expr_type(tree_node const*)
../../gcc/cp/typeck.cc:2468
0x4270a2 build_new_op(op_location_t const&, tree_code, int, tree_node*, 
tree_node*, tree_node*, tree_node*, tree_node**, int)
../../gcc/cp/call.cc:7153
0x89a2e1 build_x_binary_op(op_location_t const&, tree_code, tree_node*, 
tree_code, tree_node*, tree_code, tree_node*, tree_node**, int)
../../gcc/cp/typeck.cc:4794
0x6d4f64 cp_parser_binary_expression
../../gcc/cp/parser.cc:10818
0x6d556c cp_parser_assignment_expression
../../gcc/cp/parser.cc:10979
0x6d5aa8 cp_parser_expression
../../gcc/cp/parser.cc:11162
0x6ddfe1 cp_parser_condition
../../gcc/cp/parser.cc:14308

Jakub



[COMMITTED 04/30] ada: Improve expansion of conditional expressions in object declarations

2025-01-03 Thread Marc Poulhiès
From: Eric Botcazou 

This arranges for conditional expressions in objects declarations to have
their expansion delayed when they have a type that cannot be easily copied
or copied at all, including limited and controlled types.

The ultimate goal is to replace the declaration with a renaming declaration
of the dereference of an access value designating an object initialized with
the dependent expression chosen by the condition.

gcc/ada/ChangeLog:

* einfo.ads (Is_Independent): Document usage on Master_Node objects.
* exp_aggr.adb (In_Place_Assign_OK): Remove Parent_Kind variable.
(Convert_To_Assignments): Call Unconditional_Parent and remove the
restriction on the known size for the in-place expansion of the
aggregate in the context of an object declaration.
(Expand_Array_Aggregate): Remove Parent_Kind variable and call
Unconditional_Parent and Delay_Conditional_Expressions_Between
* exp_ch3.adb: Remove clauses for Exp_Dbug.
(Expand_N_Object_Declaration): Factor out the code rewriting the
declaration as a renaming in Rewrite_Object_Declaration_As_Renaming
and call the procedure.
* exp_ch4.adb (Insert_Conditional_Object_Declaration): Declare.
(Expand_N_Case_Expression): Delay expanding the expression if it is
in the context of an optimizable object declaration.  If the parent
node is this object declaration, then replace it with a renaming of
the dereference of an access value designating an object initialized
with the dependent expression chosen by the condition.
(Expand_N_If_Expression): Likewise.
(Insert_Conditional_Object_Declaration): New procedure.
* exp_ch6.adb (Expand_Ctrl_Function_Call): Test the unconditional
parent in the case of an object declaration too.
* exp_ch7.adb (Build_Finalizer.Process_Declarations): Pass Strict to
Processing_Actions from the Is_Independent flag on a Master_Node.
* exp_util.ads (Rewrite_Object_Declaration_As_Renaming): Declare.
* exp_util.adb: Add clauses for Exp_Dbug.
(Rewrite_Object_Declaration_As_Renaming): New procedure extracted
from Expand_N_Object_Declaration.
* sem_ch3.adb (Analyze_Object_Declaration): Also leave the analysis
if the declaration has been replaced with a renaming in the case of
an initialization expression that is a conditional expression.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/einfo.ads|   4 +
 gcc/ada/exp_aggr.adb | 123 +--
 gcc/ada/exp_ch3.adb  |  31 +---
 gcc/ada/exp_ch4.adb  | 368 ---
 gcc/ada/exp_ch6.adb  |  14 +-
 gcc/ada/exp_ch7.adb  |   3 +-
 gcc/ada/exp_util.adb |  41 +
 gcc/ada/exp_util.ads |   3 +
 gcc/ada/sem_ch3.adb  |  15 +-
 9 files changed, 455 insertions(+), 147 deletions(-)

diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index 1a8760c0dbb..025465265f3 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -2804,6 +2804,10 @@ package Einfo is
 --   case of private and incomplete types, this flag is set in both the
 --   partial view and the full view.
 
+--   This flag is also set on the Master_Node objects generated by the
+--   compiler (see Finalization_Master_Node above) to indicate that the
+--   associated finalizable object has relaxed finalization semantics.
+
 --Is_Initial_Condition_Procedure
 --   Defined in functions and procedures. Set for a generated procedure
 --   which verifies the assumption of pragma Initial_Condition at run time.
diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 344e4d10c5f..1f1f58061ce 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -4119,7 +4119,6 @@ package body Exp_Aggr is
 
   --  Local variables
 
-  Parent_Kind : Node_Kind;
   Parent_Node : Node_Id;
 
--  Start of processing for In_Place_Assign_OK
@@ -4132,11 +4131,9 @@ package body Exp_Aggr is
   end if;
 
   Parent_Node := Parent (N);
-  Parent_Kind := Nkind (Parent_Node);
 
-  if Parent_Kind = N_Qualified_Expression then
+  if Nkind (Parent_Node) = N_Qualified_Expression then
  Parent_Node := Parent (Parent_Node);
- Parent_Kind := Nkind (Parent_Node);
   end if;
 
   --  On assignment, sliding can take place, so we cannot do the
@@ -4161,44 +4158,11 @@ package body Exp_Aggr is
procedure Convert_To_Assignments (N : Node_Id; Typ : Entity_Id) is
   Loc : constant Source_Ptr := Sloc (N);
 
-  function Known_Size (Decl : Node_Id; Cond_Init : Boolean) return Boolean;
-  --  Decl is an N_Object_Declaration node. Return true if it declares an
-  --  object with a known size; in this context, that is always the case,
-  --  except for a declaration without explicit constraints of an object,
-  --  either whose nominal subtype is class-wide, or whose initialization
-  

[COMMITTED 10/30] ada: Leave empty parent in an array component of an anonymous access type

2025-01-03 Thread Marc Poulhiès
From: Piotr Trojanek 

An itype created for a record component with an anonymous access type has empty
parent. However, a similar itype created for an array component has its parent
copied from the parent of the array type.

The above discrepancy appears to be not needed for the frontend. Also, it is
confusing for the GNATprove backend, because it looks like the itype entity
of the array component comes from a declaration of the array itself.

gcc/ada/ChangeLog:

* sem_ch3.adb (Array_Type_Declaration): Don't copy parent for an itype
created by an array component declaration.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch3.adb | 6 --
 1 file changed, 6 deletions(-)

diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index eb53d59032c..7bedc043c8d 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -6612,12 +6612,6 @@ package body Sem_Ch3 is
 N   => Access_Definition (Component_Def));
  Set_Is_Local_Anonymous_Access (Element_Type);
 
- --  Propagate the parent. This field is needed if we have to generate
- --  the master_id associated with an anonymous access to task type
- --  component (see Expand_N_Full_Type_Declaration.Build_Master)
-
- Copy_Parent (To => Element_Type, From => T);
-
  --  Ada 2005 (AI-230): In case of components that are anonymous access
  --  types the level of accessibility depends on the enclosing type
  --  declaration
-- 
2.43.0



[COMMITTED 17/30] ada: Simplify uses of the global name buffer

2025-01-03 Thread Marc Poulhiès
From: Piotr Trojanek 

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_dist.adb (Assign_Subprogram_Identifier,
Reserve_NamingContext_Methods): Simplify.
* osint.adb (Append_Suffix_To_File_Name, Find_File, Get_Directory,
Object_File_Name, Strip_Directory): Likewise.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_dist.adb |  8 ++--
 gcc/ada/osint.adb| 22 +-
 2 files changed, 7 insertions(+), 23 deletions(-)

diff --git a/gcc/ada/exp_dist.adb b/gcc/ada/exp_dist.adb
index fcfeba0e1a6..e8f9b68baf3 100644
--- a/gcc/ada/exp_dist.adb
+++ b/gcc/ada/exp_dist.adb
@@ -2089,8 +2089,7 @@ package body Exp_Dist is
   --  disambiguated within their own scope.
 
   if Overload_Order > 1 then
- Name_Buffer (Name_Len + 1 .. Name_Len + 2) := "__";
- Name_Len := Name_Len + 2;
+ Add_Str_To_Name_Buffer ("__");
  Add_Nat_To_Name_Buffer (Overload_Order);
   end if;
 
@@ -11188,11 +11187,8 @@ package body Exp_Dist is
   ---
 
   procedure Reserve_NamingContext_Methods is
- Str_Resolve : constant String := "resolve";
   begin
- Name_Buffer (1 .. Str_Resolve'Length) := Str_Resolve;
- Name_Len := Str_Resolve'Length;
- Overload_Counter_Table.Set (Name_Find, 1);
+ Overload_Counter_Table.Set (Name_Find ("resolve"), 1);
   end Reserve_NamingContext_Methods;
 
   ---
diff --git a/gcc/ada/osint.adb b/gcc/ada/osint.adb
index 645cb630b13..364c069a099 100644
--- a/gcc/ada/osint.adb
+++ b/gcc/ada/osint.adb
@@ -658,8 +658,7 @@ package body Osint is
is
begin
   Get_Name_String (Name);
-  Name_Buffer (Name_Len + 1 .. Name_Len + Suffix'Length) := Suffix;
-  Name_Len := Name_Len + Suffix'Length;
+  Add_Str_To_Name_Buffer (Suffix);
   return Name_Find;
end Append_Suffix_To_File_Name;
 
@@ -1225,12 +1224,8 @@ package body Osint is
   declare
  Full_Path : constant String :=
Normalize_Pathname (Get_Name_String (N));
- Full_Size : constant Natural := Full_Path'Length;
-
   begin
- Name_Buffer (1 .. Full_Size) := Full_Path;
- Name_Len := Full_Size;
- Found:= Name_Find;
+ Found := Name_Find (Full_Path);
   end;
end if;
 
@@ -1446,9 +1441,7 @@ package body Osint is
  end if;
   end loop;
 
-  Name_Len := Hostparm.Normalized_CWD'Length;
-  Name_Buffer (1 .. Name_Len) := Hostparm.Normalized_CWD;
-  return Name_Find;
+  return Name_Find (Hostparm.Normalized_CWD);
end Get_Directory;
 
--
@@ -2182,10 +2175,7 @@ package body Osint is
   Get_Name_String (N);
   Name_Len := Name_Len - ALI_Suffix'Length - 1;
 
-  for J in Target_Object_Suffix'Range loop
- Name_Len := Name_Len + 1;
- Name_Buffer (Name_Len) := Target_Object_Suffix (J);
-  end loop;
+  Add_Str_To_Name_Buffer (Target_Object_Suffix);
 
   return Name_Enter;
end Object_File_Name;
@@ -2935,9 +2925,7 @@ package body Osint is
 
 --  Return part of Name that follows this last directory separator
 
-Name_Buffer (1 .. Name_Len - J) := Name_Buffer (J + 1 .. Name_Len);
-Name_Len := Name_Len - J;
-return Name_Find;
+return Name_Find (Name_Buffer (J + 1 .. Name_Len));
  end if;
   end loop;
 
-- 
2.43.0



[COMMITTED 24/30] ada: Remove guards against empty lists

2025-01-03 Thread Marc Poulhiès
From: Piotr Trojanek 

There is no need to guard against calling First on a No_List, in which case
the call intentionally returns Empty. Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* contracts.adb (Create_Generic_Contract): Remove calls to Present.
* sem_util.adb (Normalize_Actuals): Likewise.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/contracts.adb | 16 
 gcc/ada/sem_util.adb  |  9 ++---
 2 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb
index 7e66a54b675..7eb41f7f107 100644
--- a/gcc/ada/contracts.adb
+++ b/gcc/ada/contracts.adb
@@ -2122,9 +2122,7 @@ package body Contracts is
   if Nkind (Templ) = N_Generic_Package_Declaration then
  Mutate_Ekind (Templ_Id, E_Generic_Package);
 
- if Present (Visible_Declarations (Specification (Templ))) then
-Decl := First (Visible_Declarations (Specification (Templ)));
- end if;
+ Decl := First (Visible_Declarations (Specification (Templ)));
 
   --  A generic package body carries contract-related source pragmas in its
   --  declarations.
@@ -2132,9 +2130,7 @@ package body Contracts is
   elsif Nkind (Templ) = N_Package_Body then
  Mutate_Ekind (Templ_Id, E_Package_Body);
 
- if Present (Declarations (Templ)) then
-Decl := First (Declarations (Templ));
- end if;
+ Decl := First (Declarations (Templ));
 
   --  Generic subprogram declaration
 
@@ -2149,9 +2145,7 @@ package body Contracts is
  --  the Pragmas_After list for contract-related source pragmas.
 
  if Nkind (Context) = N_Compilation_Unit then
-if Present (Aux_Decls_Node (Context))
-  and then Present (Pragmas_After (Aux_Decls_Node (Context)))
-then
+if Present (Aux_Decls_Node (Context)) then
Decl := First (Pragmas_After (Aux_Decls_Node (Context)));
 end if;
 
@@ -2168,9 +2162,7 @@ package body Contracts is
   elsif Nkind (Templ) = N_Subprogram_Body then
  Mutate_Ekind (Templ_Id, E_Subprogram_Body);
 
- if Present (Declarations (Templ)) then
-Decl := First (Declarations (Templ));
- end if;
+ Decl := First (Declarations (Templ));
   end if;
 
   --  Inspect the relevant declarations looking for contract-related source
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 44a87298c6e..6bc50c44291 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -25119,9 +25119,7 @@ package body Sem_Util is
   --  Find if there is a named association, and verify that no positional
   --  associations appear after named ones.
 
-  if Present (Actuals) then
- Actual := First (Actuals);
-  end if;
+  Actual := First (Actuals);
 
   while Present (Actual)
 and then Nkind (Actual) /= N_Parameter_Association
@@ -25169,10 +25167,7 @@ package body Sem_Util is
  Next (Actual);
   end loop;
 
-  if Present (Actuals) then
- Actual := First (Actuals);
-  end if;
-
+  Actual := First (Actuals);
   Formal := First_Formal (S);
   while Present (Formal) loop
 
-- 
2.43.0



[COMMITTED 27/30] ada: Simplify code for obtaining function entity from a function call

2025-01-03 Thread Marc Poulhiès
From: Piotr Trojanek 

Code cleanup; behavior is unaffected.

gcc/ada/ChangeLog:

* sem_ch5.adb (Check_Call): Reuse Get_Called_Entity.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch5.adb | 24 ++--
 1 file changed, 2 insertions(+), 22 deletions(-)

diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index 2a5c8dcdbe5..944259a532a 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -4536,34 +4536,14 @@ package body Sem_Ch5 is
   
 
   function Check_Call (N : Node_Id) return Traverse_Result is
- Nam  : Node_Id;
  Subp : Entity_Id;
- Typ  : Entity_Id;
 
   begin
  if Nkind (N) = N_Function_Call then
-Nam := Name (N);
-
---  Obtain the subprogram being invoked
-
-loop
-   if Nkind (Nam) = N_Explicit_Dereference then
-  Nam := Prefix (Nam);
-
-   elsif Nkind (Nam) = N_Selected_Component then
-  Nam := Selector_Name (Nam);
-
-   else
-  exit;
-   end if;
-end loop;
-
-Subp := Entity (Nam);
+Subp := Get_Called_Entity (N);
 
 if Present (Subp) then
-   Typ := Etype (Subp);
-
-   if Requires_Transient_Scope (Typ) then
+   if Requires_Transient_Scope (Etype (Subp)) then
   return Abandon;
 
elsif Sec_Stack_Needed_For_Return (Subp) then
-- 
2.43.0



[COMMITTED 06/30] ada: Warn on unmodified parameters of expression functions

2025-01-03 Thread Marc Poulhiès
From: Bob Duff 

If an 'out' or 'in out' parameter is not modified in a function body,
we warn. However, the warning was missing when we have an expression
function instead of a proper body. This patch enables the warning
on expression functions.

gcc/ada/ChangeLog:

* sem_ch6.adb (Analyze_Expression_Function): Mark the implicit
spec for an expression function as Comes_From_Source.
(Analyze_Null_Procedure): Minor cleanup.
* sem_warn.adb (Source_E1): New function to compute whether
to give warnings. In particular, return True for [in] out
parameters of expression functions.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch6.adb  | 16 ++--
 gcc/ada/sem_warn.adb | 44 
 2 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index a3b521ddad4..2f09284ebda 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -310,7 +310,7 @@ package body Sem_Ch6 is
   Typ  : Entity_Id := Empty;
 
   Def_Id : Entity_Id := Empty;
-  Prev   : Entity_Id;
+  Prev   : Entity_Id := Current_Entity_In_Scope (Defining_Entity (Spec));
   --  If the expression is a completion, Prev is the entity whose
   --  declaration is completed. Def_Id is needed to analyze the spec.
 
@@ -325,10 +325,15 @@ package body Sem_Ch6 is
   Inline_Processing_Required := True;
 
   --  Create a specification for the generated body. This must be done
-  --  prior to the analysis of the initial declaration.
+  --  prior to the analysis of the initial declaration. We mark the
+  --  generated Defining_Unit_Name as Comes_From_Source to avoid
+  --  suppressing warnings on it. We do not do that in instances,
+  --  because of arcane interactions with ghost generics.
 
   New_Spec := Copy_Subprogram_Spec (Spec);
-  Prev := Current_Entity_In_Scope (Defining_Entity (Spec));
+  if not In_Instance then
+ Set_Comes_From_Source (Defining_Unit_Name (New_Spec));
+  end if;
 
   --  Copy SPARK pragma from expression function
 
@@ -1363,11 +1368,10 @@ package body Sem_Ch6 is
   Form   : Node_Id;
   Null_Body  : Node_Id := Empty;
   Null_Stmt  : Node_Id := Null_Statement (Spec);
-  Prev   : Entity_Id;
+  Prev   : Entity_Id :=
+Current_Entity_In_Scope (Defining_Entity (Spec));
 
begin
-  Prev := Current_Entity_In_Scope (Defining_Entity (Spec));
-
   --  A null procedure is Ghost when it is stand-alone and is subject to
   --  pragma Ghost, or when the corresponding spec is Ghost. Set the mode
   --  now, to ensure that any nodes generated during analysis and expansion
diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 2ffd631d628..2eac80246a6 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -861,6 +861,13 @@ package body Sem_Warn is
   --  Return True if it is OK for an object of type T to be referenced
   --  without having been assigned a value in the source.
 
+  function Source_E1 return Boolean;
+  --  True if E1 is sufficiently "from source" to warrant a warning.
+  --  We are only interested in source entities. We also don't issue
+  --  warnings within instances, since the proper place for such
+  --  warnings is on the template when it is compiled. Expression
+  --  functions are a special case (see body).
+
   function Warnings_Off_E1 return Boolean;
   --  Return True if Warnings_Off is set for E1, or for its Etype (E1T),
   --  or for the base type of E1T.
@@ -1156,6 +1163,34 @@ package body Sem_Warn is
  end if;
   end Type_OK_For_No_Value_Assigned;
 
+  ---
+  -- Source_E1 --
+  ---
+
+  function Source_E1 return Boolean is
+  begin
+ if Instantiation_Location (Sloc (E1)) /= No_Location then
+return False;
+ end if;
+
+ if Comes_From_Source (E1) then
+return True;
+ end if;
+
+ --  In the special case of an expression function, which has been
+ --  turned into an E_Subprogram_Body, we want to warn about unmodified
+ --  [in] out parameters.
+
+ if Ekind (E) = E_Subprogram_Body
+   and then Comes_From_Source (E)
+   and then Ekind (E1) in E_In_Out_Parameter | E_Out_Parameter
+ then
+return True;
+ end if;
+
+ return False;
+  end Source_E1;
+
   -
   -- Warnings_Off_E1 --
   -
@@ -1190,14 +1225,7 @@ package body Sem_Warn is
 
   E1 := First_Entity (E);
   while Present (E1) loop
- --  We are only interested in source entities. We also don't issue
- --  warnings within instances, since the proper place for such
- --  warnings is on the template when it is compiled, and we don't
- 

[COMMITTED 09/30] ada: Incompatible conversion on vxworks in socket.c

2025-01-03 Thread Marc Poulhiès
From: Douglas B Rupp 

In the vxworks section, a conversion between char* and int is
attempted, which results in a warning with gcc. However with clang
with is an error. Note also on 64bit targets, there's a size
mismatch.

gcc/ada/ChangeLog:

* socket.c [__vxworks]: Change vxw_h_addr type to long from
int, and cast the conversion of char* to vxw_h_addr to avoid
warning/error.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/socket.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/socket.c b/gcc/ada/socket.c
index 75b4288a129..297d303cef7 100644
--- a/gcc/ada/socket.c
+++ b/gcc/ada/socket.c
@@ -266,7 +266,7 @@ __gnat_getservbyport (int port, const char *proto,
 #elif defined (__vxworks)
 static char vxw_h_name[MAXHOSTNAMELEN + 1];
 static char *vxw_h_aliases[1] = { NULL };
-static int vxw_h_addr;
+static long vxw_h_addr;
 static char *vxw_h_addr_list[2] = { (char*) &vxw_h_addr, NULL };
 
 int
@@ -307,7 +307,7 @@ __gnat_gethostbyaddr (const char *addr, int len, int type,
 return -1;
   }
 
-  vxw_h_addr   = addr;
+  vxw_h_addr   = (long) addr;
 
   ret->h_name  = &vxw_h_name;
   ret->h_aliases   = &vxw_h_aliases;
-- 
2.43.0



[COMMITTED 08/30] ada: Do not search executables in current dir by default

2025-01-03 Thread Marc Poulhiès
From: Tonu Naks 

gcc/ada/ChangeLog:

* adaint.c: change default behaviour of __gnat_locate_exec_on_path
* adaint.h: change prototype of __gnat_locate_exec_on_path
* libgnat/s-os_lib.adb: pass optional argument in Locate_Exec_On_Path
* libgnat/s-os_lib.ads: change spec of Locate_Exec_On_Path
* libgnat/s-trasym__dwarf.adb: update import of 
__gnat_locate_exec_on_path

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/adaint.c| 31 -
 gcc/ada/adaint.h|  2 +-
 gcc/ada/libgnat/s-os_lib.adb| 11 +++---
 gcc/ada/libgnat/s-os_lib.ads|  9 -
 gcc/ada/libgnat/s-trasym__dwarf.adb |  7 +--
 5 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c
index 9ccac305dde..0b6d4bb6b4e 100644
--- a/gcc/ada/adaint.c
+++ b/gcc/ada/adaint.c
@@ -3079,32 +3079,35 @@ __gnat_locate_exec (char *exec_name, char *path_val)
 /* Locate an executable using the Systems default PATH.  */
 
 char *
-__gnat_locate_exec_on_path (char *exec_name)
+__gnat_locate_exec_on_path (char *exec_name, int current_dir_on_windows)
 {
   char *apath_val;
 
 #if defined (_WIN32)
   TCHAR *wpath_val = _tgetenv (_T("PATH"));
-  TCHAR *wapath_val;
-  /* In Win32 systems we expand the PATH as for XP environment
- variables are not automatically expanded. We also prepend the
- ".;" to the path to match normal NT path search semantics */
-
   #define EXPAND_BUFFER_SIZE 32767
+  apath_val = (char *) alloca (EXPAND_BUFFER_SIZE);
 
-  wapath_val = (TCHAR *) alloca (EXPAND_BUFFER_SIZE);
+  if (current_dir_on_windows) {
+TCHAR *wapath_val;
+/* In Win32 systems we expand the PATH as for XP environment
+  variables are not automatically expanded. We also prepend the
+  ".;" to the path to match normal NT path search semantics */
 
-  wapath_val [0] = '.';
-  wapath_val [1] = ';';
+wapath_val = (TCHAR *) alloca (EXPAND_BUFFER_SIZE);
 
-  DWORD res = ExpandEnvironmentStrings
-(wpath_val, &wapath_val[2], EXPAND_BUFFER_SIZE - 2);
+wapath_val [0] = '.';
+wapath_val [1] = ';';
 
-  if (!res) wapath_val [0] = _T('\0');
+DWORD res = ExpandEnvironmentStrings
+  (wpath_val, &wapath_val[2], EXPAND_BUFFER_SIZE - 2);
 
-  apath_val = (char *) alloca (EXPAND_BUFFER_SIZE);
+if (!res) wapath_val [0] = _T('\0');
 
-  WS2SC (apath_val, wapath_val, EXPAND_BUFFER_SIZE);
+WS2SC (apath_val, wapath_val, EXPAND_BUFFER_SIZE);
+  } else {
+WS2SC (apath_val, wpath_val, EXPAND_BUFFER_SIZE);
+  }
 
 #else
   const char *path_val = getenv ("PATH");
diff --git a/gcc/ada/adaint.h b/gcc/ada/adaint.h
index 0cbfd0e151d..26184640211 100644
--- a/gcc/ada/adaint.h
+++ b/gcc/ada/adaint.h
@@ -240,7 +240,7 @@ extern int__gnat_portable_wait (int *);
 extern int__gnat_portable_no_block_wait(int *);
 extern int__gnat_current_process_id(void);
 extern char  *__gnat_locate_exec   (char *, char *);
-extern char  *__gnat_locate_exec_on_path   (char *);
+extern char  *__gnat_locate_exec_on_path   (char *, int);
 extern char  *__gnat_locate_regular_file   (char *, char *);
 extern void   __gnat_maybe_glob_args   (int *, char ***);
 extern void   __gnat_os_exit  (int);
diff --git a/gcc/ada/libgnat/s-os_lib.adb b/gcc/ada/libgnat/s-os_lib.adb
index dd2156e1dcb..d249663e73a 100644
--- a/gcc/ada/libgnat/s-os_lib.adb
+++ b/gcc/ada/libgnat/s-os_lib.adb
@@ -34,6 +34,7 @@ with Ada.Unchecked_Deallocation;
 with System.Case_Util;
 with System.CRTL;
 with System.Soft_Links;
+with Interfaces.C;
 
 package body System.OS_Lib is
 
@@ -1641,9 +1642,12 @@ package body System.OS_Lib is
-
 
function Locate_Exec_On_Path
- (Exec_Name : String) return String_Access
+ (Exec_Name : String;
+  Current_Dir_On_Win : Boolean := False) return String_Access
is
-  function Locate_Exec_On_Path (C_Exec_Name : Address) return Address;
+  function Locate_Exec_On_Path
+(C_Exec_Name: Address;
+ Current_Dir_On_Win : Interfaces.C.int) return Address;
   pragma Import (C, Locate_Exec_On_Path, "__gnat_locate_exec_on_path");
 
   C_Exec_Name  : String (1 .. Exec_Name'Length + 1);
@@ -1655,7 +1659,8 @@ package body System.OS_Lib is
   C_Exec_Name (1 .. Exec_Name'Length)   := Exec_Name;
   C_Exec_Name (C_Exec_Name'Last):= ASCII.NUL;
 
-  Path_Addr := Locate_Exec_On_Path (C_Exec_Name'Address);
+  Path_Addr := Locate_Exec_On_Path
+(C_Exec_Name'Address, (if Current_Dir_On_Win then 1 else 0));
   Path_Len  := C_String_Length (Path_Addr);
 
   if Path_Len = 0 then
diff --git a/gcc/ada/libgnat/s-os_lib.ads b/gcc/ada/libgnat/s-os_lib.ads
index 54e7205c3e6..37ce8cfd855 100644
--- a/gcc/ada/libgnat/s-os_lib.ads
+++ b/gcc/ada/libgnat/s-os_lib.ads
@@ -494,13 +494,20 @@ package S

[COMMITTED 14/30] ada: Assorted style cleanups

2025-01-03 Thread Marc Poulhiès
From: Piotr Trojanek 

Whitespace and comment cleanups.

gcc/ada/ChangeLog:

* sem_attr.adb (Eval_Attribute): Fix comment for attribute Image.
* tbuild.adb (Make_SC): Remove extra whitespace.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_attr.adb | 2 +-
 gcc/ada/tbuild.adb   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index 6cee808d89a..6eb04b2e258 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -9448,7 +9448,7 @@ package body Sem_Attr is
   ---
 
   --  Image is a scalar attribute, but is never static, because it is
-  --  not a static function (having a non-scalar argument (RM 4.9(22))
+  --  not a static function (having a non-scalar argument (RM 4.9(22)).
   --  However, we can constant-fold the image of an enumeration literal
   --  if names are available and default Image implementation has not
   --  been overridden.
diff --git a/gcc/ada/tbuild.adb b/gcc/ada/tbuild.adb
index 31154266bcb..598030bd5db 100644
--- a/gcc/ada/tbuild.adb
+++ b/gcc/ada/tbuild.adb
@@ -492,7 +492,7 @@ package body Tbuild is
-- Make_SC --
-
 
-   function  Make_SC (Pre, Sel : Node_Id) return Node_Id is
+   function Make_SC (Pre, Sel : Node_Id) return Node_Id is
begin
   return
 Make_Selected_Component (System_Location,
-- 
2.43.0



[COMMITTED 03/30] ada: Preliminary work in analysis and expansion of initialized allocators

2025-01-03 Thread Marc Poulhiès
From: Eric Botcazou 

This makes the expansion of the various cases of initialized allocators more
uniform by factoring out common processing as much as possible.  This also
avoids giving the warning or error for a default-initialized allocator when
it is marked with No_Initialization.  No functional changes.

gcc/ada/ChangeLog:

* checks.adb (Apply_Predicate_Check): Preserve Comes_From_Source.
* exp_ch4.adb (Expand_Allocator_Expression): Factor out common code
for the various cases.  Also delay applying the 2nd predicate check.
In the default case, defer to Make_Build_In_Place_Call_In_Allocator
entirely in the build-in-place case.
* sem_ch4.adb (Analyze_Allocator): Do not give the warning or error
for a default-initialized allocator with No_Initialization.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/checks.adb  |   4 +
 gcc/ada/exp_ch4.adb | 309 ++--
 gcc/ada/sem_ch4.adb |   6 +-
 3 files changed, 160 insertions(+), 159 deletions(-)

diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index c30c99b31aa..467661bf418 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -2893,6 +2893,10 @@ package body Checks is
 
   if Deref then
  Expr := Make_Explicit_Dereference (Loc, Prefix => Expr);
+
+ --  Preserve Comes_From_Source for Predicate_Check_In_Scope
+
+ Preserve_Comes_From_Source (Expr, N);
   end if;
 
   --  Disable checks to prevent an infinite recursion
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 6f54b5c04b4..7fda6221661 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -566,18 +566,25 @@ package body Exp_Ch4 is
   PtrT   : constant Entity_Id  := Etype (N);
   DesigT : constant Entity_Id  := Designated_Type (PtrT);
   Special_Return : constant Boolean:= For_Special_Return_Object (N);
+  Static_Match   : constant Boolean:=
+not Is_Constrained (DesigT)
+  or else Subtypes_Statically_Match (T, DesigT);
 
   procedure Build_Aggregate_In_Place (Temp : Entity_Id; Typ : Entity_Id);
   --  If Exp is an aggregate to build in place, build the declaration of
-  --  Temp with Typ and initializing expression an uninitialized allocator
-  --  for Etype (Exp), then perform an in-place aggregate assignment of Exp
-  --  into the allocated memory.
+  --  object Temp with Typ and initialization expression an uninitialized
+  --  allocator for Etype (Exp), then perform in-place aggregate assignment
+  --  of Exp into the newly allocated memory.
 
   procedure Build_Explicit_Assignment (Temp : Entity_Id; Typ : Entity_Id);
   --  If Exp is a conditional expression whose expansion has been delayed,
-  --  build the declaration of Temp with Typ and initializing expression an
-  --  uninitialized allocator for Etype (Exp), then perform an assignment
-  --  of Exp into the allocated memory.
+  --  build the declaration of object Temp with Typ and initialization
+  --  expression an uninitialized allocator for Etype (Exp), then perform
+  --  assignment of Exp into the newly allocated memory.
+
+  procedure Build_Simple_Allocation (Temp : Entity_Id; Typ : Entity_Id);
+  --  Build the declaration of object Temp with Typ and initialization
+  --  expression the allocator N.
 
   --
   -- Build_Aggregate_In_Place --
@@ -587,6 +594,7 @@ package body Exp_Ch4 is
  Temp_Decl : constant Node_Id :=
Make_Object_Declaration (Loc,
  Defining_Identifier => Temp,
+ Constant_Present=> True,
  Object_Definition   => New_Occurrence_Of (Typ, Loc),
  Expression  =>
Make_Allocator (Loc,
@@ -625,6 +633,7 @@ package body Exp_Ch4 is
  Temp_Decl : constant Node_Id :=
Make_Object_Declaration (Loc,
  Defining_Identifier => Temp,
+ Constant_Present=> True,
  Object_Definition   => New_Occurrence_Of (Typ, Loc),
  Expression  =>
Make_Allocator (Loc,
@@ -653,15 +662,32 @@ package body Exp_Ch4 is
  Insert_Action (N, Assign);
   end Build_Explicit_Assignment;
 
+  -
+  -- Build_Simple_Allocation --
+  -
+
+  procedure Build_Simple_Allocation (Temp : Entity_Id; Typ : Entity_Id) is
+ New_N : constant Node_Id := Relocate_Node (N);
+ Temp_Decl : constant Node_Id :=
+   Make_Object_Declaration (Loc,
+ Defining_Identifier => Temp,
+ Constant_Present=> True,
+ Object_Definition   => New_Occurrence_Of (Typ, Loc),
+ Expression  => New_N);
+
+  begin
+ --  Avoid recursion in the mechanism
+
+ Set_Analyzed (New_N);
+
+ Insert_Action

[COMMITTED 02/30] ada: Remove useless space in ALI P lines

2025-01-03 Thread Marc Poulhiès
From: Ronan Desplanques 

The generated ALI files are syntactically unchanged.

gcc/ada/ChangeLog:

* lib-writ.adb (Write_ALI): Remove useless space.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/lib-writ.adb | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/ada/lib-writ.adb b/gcc/ada/lib-writ.adb
index 4e7ed5a380a..992952eed67 100644
--- a/gcc/ada/lib-writ.adb
+++ b/gcc/ada/lib-writ.adb
@@ -1253,7 +1253,6 @@ package body Lib.Writ is
   if Task_Dispatching_Policy /= ' ' then
  Write_Info_Str  (" T");
  Write_Info_Char (Task_Dispatching_Policy);
- Write_Info_Char (' ');
   end if;
 
   if GNATprove_Mode then
-- 
2.43.0



[COMMITTED 13/30] ada: Handle C++ exception hierarchies

2025-01-03 Thread Marc Poulhiès
From: Alexandre Oliva 

This patch introduces support for defining exceptions in Ada with
C++'s notion of exception type compatibility, such as handling
occurrences of derived types, and obtaining class-wide access to the
thrown/raised objects.  As a bonus, it adds support for C++ dependent
(wrapped) exceptions, and introduces types and interfaces to match
C++'s std::type_info and std::exception.

Support for C++ exceptions with base-type matching, added to raise-gcc
by calling subprograms in Ada units, requires these units and their
dependencies to be linked into programs that link with raise-gcc.

gcc/ada/ChangeLog:

* Makefile.rtl (GNATRTL_NONTASKING_OBJS): Add g-cpp, g-cppstd,
and g-cstyin.
* doc/gnat_rm/interfacing_to_other_languages.rst (Interfacing to C++):
Document class-wide matching and new interfaces.
* exp_prag.adb (Expand_Pragma_Import_Or_Interface): Add class-wide
exception matching support with 'B' as language identifier.
* libgnat/a-exexpr.adb (Setup_Current_Excep): Add Id formal.
(Set_Foreign_Occurrence): Likewise.
(Propagate_GCC_Exception): Adjust.
(Set_Exception_Parameter): Likewise.
(Unhandled_Except_Handler): Likewise.
* libgnat/g-cpp.ads: New.
* libgnat/g-cppexc.adb (Raise_Cpp_Exception): Match 'B' lang id.
(Get_Object_Address): New.
(Get_Object): Rewrite.
(Get_Access_To_Object): New.
(Get_Access_To_Tagged_Object): New.
(Get_Type_Info): New.
(Convert_Caught_Object): New.
* libgnat/g-cppexc.ads (Get_Object_Address): New.
(Get_Object): Note the Cpp Convention requirement.
(Get_Access_To_Object): New.
(Get_Access_To_Tagged_Object): New.
(Get_Type_Info): New.
* libgnat/g-cppstd.adb: New.
* libgnat/g-cppstd.ads: New.
* libgnat/g-csclex.ads: New, unused.
* libgnat/g-cstyin.adb: New.
* libgnat/g-cstyin.ads: New.
* libgnat/g-excact.adb (Exception_Language): New.
(Is_Foreign_Exception): Rewrite.
* libgnat/g-excact.ads (Exception_Languages): New.
(Exception_Language): New.
* libgnat/s-stalib.ads (Lang): Document 'B'.
* raise-gcc.c (__gnat_setup_current_excep): Add Exception_Id formal.
(CXX_DEPENDENT_EXCEPTION_CLASS): New.
(cxx_type_info): New.
(__cxa_exception): Rename exceptionType to encompass PrimaryException.
(_GNAT_Exception): Drop wrapper.
(EID_For): Adjust.
(exception_class_eq): Likewise.
(__gnat_exception_language_is_cplusplus): New.
(__gnat_exception_language_is_ada): New.
(__gnat_convert_caught_object): Declare.
(__gnat_get_cxx_dependent_exception): New.
(__gnat_maybe_get_cxx_dependent_exception): New.
(__gnat_get_cxx_exception_type_info): New.
(__gnat_obtain_caught_object): New.
(is_handled_by): Adjust.   [!CERT] Add eid formal, handle dependent
exceptions and base-type matches.
(get_action_description_for) [!CERT]: Add eid formal.  Adjust.
(personality_body): Adjust.
* gcc-interface/Make-lang.in (GNAT_ADA_OBJS, GNATBIND_OBJS) [!STAGE1]:
Add new g-cpp, g-cppstd, g-cstyin + preexisting g-cppexc
and i-cstrin.
* gnat-style.texi: Regenerate.
* gnat_rm.texi: Regenerate.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/Makefile.rtl  |   3 +
 .../interfacing_to_other_languages.rst| 163 +++-
 gcc/ada/exp_prag.adb  |  57 +++-
 gcc/ada/gcc-interface/Make-lang.in|  10 +
 gcc/ada/gnat-style.texi   |   4 +-
 gcc/ada/gnat_rm.texi  | 164 +++-
 gcc/ada/libgnat/a-exexpr.adb  |  38 ++-
 gcc/ada/libgnat/g-cpp.ads |  36 +++
 gcc/ada/libgnat/g-cppexc.adb  | 213 +--
 gcc/ada/libgnat/g-cppexc.ads  |  48 +++-
 gcc/ada/libgnat/g-cppstd.adb  | 115 
 gcc/ada/libgnat/g-cppstd.ads  |  95 +++
 gcc/ada/libgnat/g-csclex.ads  |  98 +++
 gcc/ada/libgnat/g-cstyin.adb  | 122 +
 gcc/ada/libgnat/g-cstyin.ads  | 141 ++
 gcc/ada/libgnat/g-excact.adb  |  72 -
 gcc/ada/libgnat/g-excact.ads  |   7 +
 gcc/ada/libgnat/s-stalib.ads  |   3 +-
 gcc/ada/raise-gcc.c   | 250 +++---
 19 files changed, 1550 insertions(+), 89 deletions(-)
 create mode 100644 gcc/ada/libgnat/g-cpp.ads
 create mode 100644 gcc/ada/libgnat/g-cppstd.adb
 create mode 100644 gcc/ada/libgnat/g-cppstd.ads
 create mode 100644 gcc/ada/libgnat/g-csclex.ads
 create mode 100644 gcc/ada/libgnat/g-cstyin.adb
 create mode 100644 gcc/ada/libgnat/g-cstyin.ads

diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Mak

[COMMITTED 05/30] ada: Avoid failing reanalysis of aggregate bounds

2025-01-03 Thread Marc Poulhiès
From: Steve Baird 

An expression like Some_Package."+" (Arg1, Arg2) is sometimes transformed
during expansion into an unqualified call of the form "+" (Arg1, Arg2).
This is normally ok, but it means that reanalysis of the expression is likely
to fail and must therefore be avoided. Remove code that was forcing such
reanalysis (the original reason for the now-removed code is unknown).

gcc/ada/ChangeLog:

* exp_aggr.adb (Check_Bounds): Remove calls that were setting the
Analyzed flag to False for two aggregate bound expressions.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_aggr.adb | 2 --
 1 file changed, 2 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 1f1f58061ce..64bb05c9b4c 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -5144,8 +5144,6 @@ package body Exp_Aggr is
 
 Right_Opnd => Cond);
 
-Set_Analyzed (Left_Opnd  (Left_Opnd (Cond)), False);
-Set_Analyzed (Right_Opnd (Left_Opnd (Cond)), False);
 Insert_Action (N,
   Make_Raise_Constraint_Error (Loc,
 Condition => Cond,
-- 
2.43.0



[COMMITTED 12/30] ada: Improve and correct support for inheritance of nonoverriding aspects

2025-01-03 Thread Marc Poulhiès
From: Gary Dismukes 

This set of changes fixes various issues with the handling of inheritance
of nonoverridable aspects (such as for Aggregate, and the indexing and
iterator aspects, among others), plus improves some of the error reporting
related to those. The prior implementation incorrectly handled types
derived from container types with respect to such aspect inheritance,
not properly inheriting the parent type's aspects, leading to rejection
of legal constructs (such as container aggregates for the derived type).
Also, various errors were incorrect (such as stating the wrong aspect)
or unclear.

In the case of types with indexing aspects, the resolution of indexed
names for such types involved locating the eligible indexing functions
anew with the analysis of each indexed name, which was both inefficient
and wrong in some cases. That is addressed by locating the functions once,
when the aspects are resolved, rather doing the location of those in two
places, which is a maintenance hazard and could result in inconsistent
resolution.

Note that this completes work originally undertaken by Ed Schonberg
that was also worked on by Steve Baird.

gcc/ada/ChangeLog:

* diagnostics-constructors.adb 
(Make_Default_Iterator_Not_Primitive_Error):
Revise message to match message change made in sem_ch13.adb.
* freeze.adb (Freeze_Record_Type): Output appropriate aspect name in
error message, using Get_Name_String.
(Freeze_Entity): For derived types, call Analyze_Aspects_At_Freeze_Point
on the parent type, and call Inherit_Nonoverridable_Aspects on the type
(for both parent type and any progenitor types). Add with_clause for
System.Case_Util.
* gen_il-fields.ads: Add Aspect_Subprograms to type Opt_Field_Enum.
* gen_il-gen-gen_nodes.adb: Add field Aspect_Subprograms to
N_Aspect_Specification nodes.
* sem_ch4.adb (Try_Container_Indexing): Remove Find_Indexing_Operations
and the code calling it. Add new function Indexing_Interpretations for
retrieving the eligible indexing functions from the appropriate aspect's
Aspect_Subprograms list and call that instead of Find_Value_Of_Aspect.
* sem_ch7.adb (Analyze_Package_Specification): In loop over entities,
call Analyze_Aspects_At_Freeze_Point for types that have delayed
aspects.
* sem_ch13.ads (Analyze_Aspects_At_Freeze_Point): Add 
Nonoverridable_Only
formal to restrict processing to nonoverridable aspects.
(Check_Function_For_Indexing_Aspect): New exported procedure renamed
from Check_One_Function and moved to library level.
* sem_ch13.adb (Analyze_Aspects_At_Freeze_Point): Test new formal
Nonoverridable_Only formal to skip processing of aspects that are not
nonoverridable when the formal is True. Skip the processing for
Aspect_Full_Access_Only when Nonoverridable_Only is True. Call
Check_Indexing_Functions in the case of indexing aspects (procedure
moved from Analyze_Attribute_Definition_Clause to top level).
(Analyze_Aspect_Specifications): Locate closest ancestor type with an
explicit matching aspect to determine the aspect spec to reference in
the error about a nonoverridable aspect not confirming an inherited
aspect (skipping intermediate derived parents). Ensures that we retain
existing errors flagged on explicit ancestor aspects rather than
implicit inherited ones. Change names of variables Parent_Type and
Inherited_Aspect to Ancestor_Type and Ancestor_Aspect respectively
for clarity.
(Analyze_Attribute_Definition_Clause): Move nested subprograms
Check_Iterator_Functions and Check_Primitive_Function to top level
of package. Move Check_Indexing_Functions (and its nested subprograms)
from here to within Analyze_Aspects_At_Freeze_Point (adding some
formal parameters and adjusting the code appropriately, and no longer
call it from this procedure).
(Is_CW_Or_Access_To_CW): Add test for the parent type having the
indexing aspect for proper setting of Aspect_Specification_Is_Inherited.
Delete "???" comment.
(Look_Through_Anon_Access): Remove unneeded tests of Is_Access_Constant
and Name_Constant_Indexing, which lead to wrong messages in some cases.
(Check_Function_For_Indexing_Aspect): Procedure renamed from
Check_One_Function and moved to library level (was nested within
Check_Indexing_Functions), plus added formals (including Valid, to
check result). Move scope test to beginning, to immediately exclude
subprograms not declared immediately within the same scope as the type.
Improve several error messages. Add error checking for Constant_Indexing
functions. Append the function entity to the Aspect_Subprograms list of
the aspect specification

[COMMITTED 18/30] ada: Reuse existing utility routine to detect attribute Loop_Entry

2025-01-03 Thread Marc Poulhiès
From: Piotr Trojanek 

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* checks.adb (Generate_Index_Checks): Reuse existing utility routine.
* sem_ch4.adb (Analyze_Indexed_Component_Form): Likewise.
* sem_prag.adb (Analyze_Pragma): Likewise.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/checks.adb   | 4 +---
 gcc/ada/sem_ch4.adb  | 4 +---
 gcc/ada/sem_prag.adb | 4 +---
 3 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index 467661bf418..d445ca828ae 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -7306,9 +7306,7 @@ package body Checks is
   --  Delay the generation of the check until 'Loop_Entry has been properly
   --  expanded. This is done in Expand_Loop_Entry_Attributes.
 
-  elsif Nkind (Prefix (N)) = N_Attribute_Reference
-and then Attribute_Name (Prefix (N)) = Name_Loop_Entry
-  then
+  elsif Is_Attribute_Loop_Entry (Prefix (N)) then
  return;
   end if;
 
diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index 6a3b7c6e0a9..18b3a4fc22f 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -3053,9 +3053,7 @@ package body Sem_Ch4 is
   --  the indexed component denotes a loop name, the indexed form is turned
   --  into an attribute reference.
 
-  elsif Nkind (N) = N_Attribute_Reference
-and then Attribute_Name (N) = Name_Loop_Entry
-  then
+  elsif Is_Attribute_Loop_Entry (N) then
  return;
   end if;
 
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index b45be174798..50ba96bbef1 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -13646,9 +13646,7 @@ package body Sem_Prag is
 
function Process (N : Node_Id) return Traverse_Result is
begin
-  if Nkind (N) = N_Attribute_Reference
-and then Attribute_Name (N) = Name_Loop_Entry
-  then
+  if Is_Attribute_Loop_Entry (N) then
  return Abandon;
   else
  return OK;
-- 
2.43.0



[COMMITTED 07/30] ada: Fix double free at run time for class-wide allocation

2025-01-03 Thread Marc Poulhiès
From: Eric Botcazou 

The previous change was too aggressive and overlooked a specific case.

gcc/ada/ChangeLog:

* exp_ch4.adb (Expand_Allocator_Expression): Put back the call to
Remove_Side_Effects in the case of a function call, a class-wide
designated type and a regular storage pool.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch4.adb | 16 
 1 file changed, 16 insertions(+)

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 8db729f0ce9..2fc891a4e39 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -996,6 +996,22 @@ package body Exp_Ch4 is
 (Loc, TagR, Underlying_Type (TagT)));
  end if;
 
+ --  If the designated type is class-wide, then the alignment and the
+ --  controlled nature of the expression are computed dynamically by
+ --  the code generated by Build_Allocate_Deallocate_Proc, which will
+ --  thus need to remove side effects from Exp first. But the below
+ --  test on Exp needs to have its final form to decide whether or not
+ --  to generate an Adjust call, so we preventively remove them here.
+
+ if Nkind (Exp) = N_Function_Call
+   and then Is_Class_Wide_Type (DesigT)
+   and then Present (Storage_Pool (N))
+   and then not Is_RTE (Storage_Pool (N), RE_RS_Pool)
+   and then not Is_RTE (Storage_Pool (N), RE_SS_Pool)
+ then
+Remove_Side_Effects (Exp);
+ end if;
+
  --  Generate an Adjust call if the object will be moved. In Ada 2005,
  --  the object may be inherently limited, in which case there is no
  --  Adjust procedure, and the object is built in place. In Ada 95, the
-- 
2.43.0



[COMMITTED 25/30] ada: Reuse and simplify counting the length of various lists

2025-01-03 Thread Marc Poulhiès
From: Piotr Trojanek 

Use utility routines to compute number of elements in lists of nodes and chains
of formal parameters. Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_aggr.adb (Others_Check): Reuse List_Length; tune whitespace.
* exp_ch3.adb (Constrain_Array): Remove counting of constraints.
* exp_disp.adb (Make_DT): Use Elist utility routines; tune whitespace.
* sem_ch12.adb (Formal_Dimensions): Reuse List_Length.
(Valid_Default_Attribute): Reuse Number_Formals.
* sem_prag.adb (Process_Convention): Likewise.
* sem_util.adb (Normalize_Actuals): Likewise.
(Check_Function_Writable_Actuals): Reuse List_Length.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_aggr.adb | 18 +++---
 gcc/ada/exp_ch3.adb  | 15 ---
 gcc/ada/exp_disp.adb | 18 ++
 gcc/ada/sem_ch12.adb | 22 +-
 gcc/ada/sem_prag.adb | 13 +
 gcc/ada/sem_util.adb | 24 +++-
 6 files changed, 26 insertions(+), 84 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 64bb05c9b4c..dae9d4e5009 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -5352,17 +5352,10 @@ package body Exp_Aggr is
--  Count the number of discrete choices. Start with -1 because
--  the others choice does not count.
 
-   --  Is there some reason we do not use List_Length here ???
-
Nb_Choices := -1;
Assoc := First (Component_Associations (Sub_Aggr));
while Present (Assoc) loop
-  Choice := First (Choice_List (Assoc));
-  while Present (Choice) loop
- Nb_Choices := Nb_Choices + 1;
- Next (Choice);
-  end loop;
-
+  Nb_Choices := Nb_Choices + List_Length (Choice_List (Assoc));
   Next (Assoc);
end loop;
 
@@ -5379,12 +5372,7 @@ package body Exp_Aggr is
  --  choice then compute the number or positional elements.
 
  if Need_To_Check and then Present (Expressions (Sub_Aggr)) then
-Expr := First (Expressions (Sub_Aggr));
-Nb_Elements := Uint_0;
-while Present (Expr) loop
-   Nb_Elements := Nb_Elements + 1;
-   Next (Expr);
-end loop;
+Nb_Elements := UI_From_Int (List_Length (Expressions (Sub_Aggr)));
 
  --  If the aggregate contains discrete choices and an others choice
  --  compute the smallest and largest discrete choice values.
@@ -5395,7 +5383,7 @@ package body Exp_Aggr is
Table : Case_Table_Type (1 .. Nb_Choices);
--  Used to sort all the different choice values
 
-   J: Pos := 1;
+   J : Pos := 1;
 
 begin
Assoc := First (Component_Associations (Sub_Aggr));
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 71bca1cdc88..a68b4f12ca6 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -4300,10 +4300,9 @@ package body Exp_Ch3 is
(SI : Node_Id;
 Check_List : List_Id)
  is
-C : constant Node_Id := Constraint (SI);
-Number_Of_Constraints : Nat := 0;
-Index : Node_Id;
-S, T  : Entity_Id;
+C : constant Node_Id := Constraint (SI);
+Index : Node_Id;
+S, T  : Entity_Id;
 
 procedure Constrain_Index
   (Index  : Node_Id;
@@ -4341,12 +4340,6 @@ package body Exp_Ch3 is
T := Designated_Type (T);
 end if;
 
-S := First (Constraints (C));
-while Present (S) loop
-   Number_Of_Constraints := Number_Of_Constraints + 1;
-   Next (S);
-end loop;
-
 --  In either case, the index constraint must provide a discrete
 --  range for each index of the array type and the type of each
 --  discrete range must be the same as that of the corresponding
@@ -4358,7 +4351,7 @@ package body Exp_Ch3 is
 
 --  Apply constraints to each index type
 
-for J in 1 .. Number_Of_Constraints loop
+while Present (S) loop
Constrain_Index (Index, S, Check_List);
Next (Index);
Next (S);
diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb
index f2501173516..9fcc4694488 100644
--- a/gcc/ada/exp_disp.adb
+++ b/gcc/ada/exp_disp.adb
@@ -4650,7 +4650,6 @@ package body Exp_Disp is
   Name_ITable: Name_Id;
   Nb_Prim: Nat := 0;
   New_Node   : Node_Id;
-  Num_Ifaces : Nat := 0;
   Parent_Typ : Entity_Id;
   Predef_Prims   : Entity_Id;
   Prim   : Entity_Id;
@@ -5

RE: [PATCH]AArch64: Implement four and eight chunk VLA concats [PR118272]

2025-01-03 Thread Tamar Christina
> >
> > How about instead doing something like:
> >
> >   worklist.reserve (nelts);
> >   for (int i = 0; i < nelts; ++i)
> > worklist.quick_push (force_reg (elem_mode, XVECEXP (vals, 0, i)));
> >
> >   while (nelts > 2)
> > {
> >   for (int i = 0; i < nelts; i += 2)
> > {
> >   ...read worklist[i] and worklist[i + 1]...
> >   ...write back to worklist[i / 2]...
> > }
> >   nelts /= 2;
> > }
> >
> >   emit_insn (gen_aarch64_pack_partial (mode, target, worklist[0],
> >worklist[1]));
> >
> 
> I think this is better since we above the memmove.. Apologies for the bug ☹
> 
> I'll respin.

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

Ok for master?

Thanks,
Tamar

gcc/ChangeLog:

PR target/96342
PR target/118272
* config/aarch64/aarch64-sve.md (vec_init,
vec_initvnx16qivnx2qi): New.
* config/aarch64/aarch64.cc (aarch64_sve_expand_vector_init_subvector):
Rewrite to support any arbitrary combinations.
* config/aarch64/iterators.md (SVE_NO2E): Update to use SVE_NO4E
(SVE_NO2E, Vquad): New.

gcc/testsuite/ChangeLog:

PR target/96342
PR target/118272
* gcc.target/aarch64/vect-simd-clone-3.c: New test.

-- inline copy of patch --

diff --git a/gcc/config/aarch64/aarch64-sve.md 
b/gcc/config/aarch64/aarch64-sve.md
index 
6659bb4fcab34699f22ff883825de1cd67108203..35f55bfacfc3238a8a7aa69015f36ba32981af59
 100644
--- a/gcc/config/aarch64/aarch64-sve.md
+++ b/gcc/config/aarch64/aarch64-sve.md
@@ -2839,6 +2839,7 @@ (define_expand "vec_init"
   }
 )
 
+;; Vector constructor combining two half vectors { a, b }
 (define_expand "vec_init"
   [(match_operand:SVE_NO2E 0 "register_operand")
(match_operand 1 "")]
@@ -2849,6 +2850,28 @@ (define_expand "vec_init"
   }
 )
 
+;; Vector constructor combining four quad vectors { a, b, c, d }
+(define_expand "vec_init"
+  [(match_operand:SVE_NO4E 0 "register_operand")
+   (match_operand 1 "")]
+  "TARGET_SVE"
+  {
+aarch64_sve_expand_vector_init_subvector (operands[0], operands[1]);
+DONE;
+  }
+)
+
+;; Vector constructor combining eight vectors { a, b, c, d, ... }
+(define_expand "vec_initvnx16qivnx2qi"
+  [(match_operand:VNx16QI 0 "register_operand")
+   (match_operand 1 "")]
+  "TARGET_SVE"
+  {
+aarch64_sve_expand_vector_init_subvector (operands[0], operands[1]);
+DONE;
+  }
+)
+
 ;; Shift an SVE vector left and insert a scalar into element 0.
 (define_insn "vec_shl_insert_"
   [(set (match_operand:SVE_FULL 0 "register_operand")
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 
cb9b155826d12b622ae0df1736e4b042d01cf56a..c7c165ddb3a825a4e5ce4fc118d39047ce9bf7e8
 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -24898,18 +24898,42 @@ aarch64_sve_expand_vector_init_subvector (rtx target, 
rtx vals)
   machine_mode mode = GET_MODE (target);
   int nelts = XVECLEN (vals, 0);
 
-  gcc_assert (nelts == 2);
+  gcc_assert (nelts % 2 == 0);
 
-  rtx arg0 = XVECEXP (vals, 0, 0);
-  rtx arg1 = XVECEXP (vals, 0, 1);
-
-  /* If we have two elements and are concatting vector.  */
-  machine_mode elem_mode = GET_MODE (arg0);
+  /* We have to be concatting vector.  */
+  machine_mode elem_mode = GET_MODE (XVECEXP (vals, 0, 0));
   gcc_assert (VECTOR_MODE_P (elem_mode));
 
-  arg0 = force_reg (elem_mode, arg0);
-  arg1 = force_reg (elem_mode, arg1);
-  emit_insn (gen_aarch64_pack_partial (mode, target, arg0, arg1));
+  auto_vec worklist;
+  machine_mode wider_mode = elem_mode;
+
+  for (int i = 0; i < nelts; i++)
+worklist.safe_push (force_reg (elem_mode, XVECEXP (vals, 0, i)));
+
+  /* Keep widening pairwise to have maximum throughput.  */
+  while (nelts >= 2)
+{
+  wider_mode
+ = related_vector_mode (wider_mode, GET_MODE_INNER (wider_mode),
+GET_MODE_NUNITS (wider_mode) * 2).require ();
+
+  for (int i = 0; i < nelts; i += 2)
+   {
+ rtx arg0 = worklist[i];
+ rtx arg1 = worklist[i+1];
+ gcc_assert (GET_MODE (arg0) == GET_MODE (arg1));
+
+ rtx tmp = gen_reg_rtx (wider_mode);
+ emit_insn (gen_aarch64_pack_partial (wider_mode, tmp, arg0, arg1));
+ worklist[i / 2] = tmp;
+   }
+
+  nelts /= 2;
+}
+
+  gcc_assert (wider_mode == mode);
+  emit_move_insn (target, worklist[0]);
+
   return;
 }
 
diff --git a/gcc/config/aarch64/iterators.md b/gcc/config/aarch64/iterators.md
index 
07b97547cb292e6d4dc1040173a5d5525fb268d5..60bad5c72bc667be19f8224af87ec5451b4b1a9a
 100644
--- a/gcc/config/aarch64/iterators.md
+++ b/gcc/config/aarch64/iterators.md
@@ -140,9 +140,12 @@ (define_mode_iterator VQ_I [V16QI V8HI V4SI V2DI])
 ;; VQ without 2 element modes.
 (define_mode_iterator VQ_NO2E [V16QI V8HI V4SI V8HF V4SF V8BF])
 
+;; SVE modes without 2 and 4 element modes.
+(define_mode_iterator SVE_NO4E [VNx16QI VNx8QI VNx8HI VNx8H

[RFC/RFA] [PR tree-optimization/92539] Improve code and avoid Warray-bounds false positive

2025-01-03 Thread Jeff Law
So this is an implementation of an idea I had a few years back and 
prototyped last spring to fix pr92539.


pr92539 is a false positive Warray-bounds warning triggered by loop 
unrolling.  The warning is in code that will never execute, but none of 
the optimizers clean things up well enough or early enough in the 
pipeline to avoid the warning.


To optimize away the code we can take advantage of the fact that we're 
comparing a value to a bogus pointer.  So for example an EQ comparison 
against &"aa" + 3 is always false and a NE comparison against that would 
always be true.


I've implemented this in vr-values.  It's not my preferred location, but 
we need to handle this scenario before the array-bounds warnings which 
are currently placed immediately after vrp1.  So vr-values it was...


This could perhaps also be done in match.pd; there's a reasonable chance 
it's implementable there and would trigger early enough in the pipeline 
to avoid the false positive.  I can certainly explore that if folks 
think that's a better solution to this long standing issue.


Bootstrapped and regression tested on x86_64 and run through the crosses 
in my tester.


Anyway, thoughts?

Jeff

PR tree-optimization/92539

gcc/
* vr-values.cc (simplify_using_ranges::fold_cond_with_ops): Optimize
away EQ/NE test against a bogus pointer.


gcc/testsuite/
g++.dg/torture/pr92539.C: New test.



diff --git a/gcc/testsuite/g++.dg/torture/pr92539.C 
b/gcc/testsuite/g++.dg/torture/pr92539.C
new file mode 100644
index 000..36af174620b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr92539.C
@@ -0,0 +1,51 @@
+// { dg-do compile }
+// { dg-additional-options "-Wall" }
+
+static bool
+ischar(int ch)
+{
+return (0 == (ch & ~0xff) || ~0 == (ch | 0xff)) != 0;
+}
+
+static bool eat(char const*& first, char const* last)
+{
+if (first != last && ischar(*first)) {
+++first;
+return true;
+}
+return false;
+}
+
+static bool eat_two(char const*& first, char const* last)
+{
+auto save = first;
+if (eat(first, last) && eat(first, last))
+return true;
+first = save;
+return false;
+}
+
+static bool foo(char const*& first, char const* last)
+{
+auto local_iterator = first;
+int i = 0;
+for (; i < 3; ++i)
+if (!eat_two(local_iterator, last))
+return false;
+first = local_iterator;
+return true;
+}
+
+static bool test(char const* in, bool full_match = true)
+{
+auto last = in;
+while (*last)
+++last;
+return foo(in, last) && (!full_match || (in == last));
+}
+
+int main()
+{
+return test("aa");
+}
+
diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc
index cf273a3fc62..f03c44505d5 100644
--- a/gcc/vr-values.cc
+++ b/gcc/vr-values.cc
@@ -325,6 +325,35 @@ simplify_using_ranges::fold_cond_with_ops (enum tree_code 
code,
   if (res == range_false ())
return boolean_false_node;
 }
+
+  /* If we're comparing pointers and one of the pointers is
+ not a valid pointer (say &MEM  [(void *)"aa" + 4B)
+ return true for EQ and false for NE.  */
+  tree type = TREE_TYPE (op0);
+  if ((code == EQ_EXPR || code == NE_EXPR)
+  && POINTER_TYPE_P (type)
+  && TREE_CODE (op1) == ADDR_EXPR
+  && TREE_CODE (TREE_OPERAND (op1, 0)) == MEM_REF)
+{
+  tree mem_ref = TREE_OPERAND (op1, 0);
+  if (TREE_CODE (TREE_OPERAND (mem_ref, 0)) == ADDR_EXPR)
+   {
+ tree addr_expr = TREE_OPERAND (mem_ref, 0);
+ if (TREE_CODE (TREE_OPERAND (addr_expr, 0)) == STRING_CST)
+   {
+ tree string = TREE_OPERAND (addr_expr, 0);
+
+ if (TREE_CODE (TREE_OPERAND (mem_ref, 1)) == INTEGER_CST)
+   {
+ HOST_WIDE_INT len = TREE_STRING_LENGTH (string);
+ HOST_WIDE_INT offset = tree_to_uhwi (TREE_OPERAND (mem_ref, 
1));
+ if (offset > len)
+   return code == EQ_EXPR ? boolean_false_node : 
boolean_true_node;
+   }
+   }
+   }
+}
+
   return NULL;
 }
 


Re: [PATCH v11] ada: fix timeval timespec on 32 bits archs with 64 bits time_t [PR114065]

2025-01-03 Thread Marc Poulhiès
Hello Nicolas,

>> At first view, it seems possible and desirable to merge _posix and
>> _rtems, but working on this right now would be counter-productive.
>>
>> I suggest to apply patches 1-2 and fix PR114065 first.
>>
>> Then the cosmetic changes in patches 3-6 (and possibly a trivial
>> backport of 8).
>>
>> After that, we will have all the time in the long winter afternoons to
>> discuss file names in patch 7.
>
> Hello Nicolas,
>
> I wanted to test your latest version of the patch, but it does not apply
> cleanly. Any chance you could send an updated version? I've tried to
> apply over some recent revisions and also over some revisions around the
> time you sent your mail, but none worked.

I've discussed with Doug (author of the conflicting change).

Overall, your change is OK, with the following exception: we can't
change the Calendar API, so the revert is not OK. User code using the
new "*_64" function will break. A possible solution would be to
implement the API using your change.

While looking at the changes again, I have one more comment, see below.

> diff --git a/gcc/ada/s-oscons-tmplt.c b/gcc/ada/s-oscons-tmplt.c
> index e5dad44..a64e578 100644
> --- a/gcc/ada/s-oscons-tmplt.c
> +++ b/gcc/ada/s-oscons-tmplt.c
> @@ -1775,6 +1775,22 @@ CNS(MAX_tv_sec, "")
>  CND(SIZEOF_tv_nsec, "tv_nsec");
>  }
>
> +/*
> +
> +   --  Functions with time_t suseconds_t timeval timespec parameters like
> +   --clock_get{res,time} gettimeofday nanosleep
> +   --pthread_cond_{,timed}wait select
> +   --  must be imported from the GNU C library with
> +   --External_Name => (if Glibc_Use_Time_Bits64 then "__foo64" else 
> "foo")
> +   --  The test is safe in files that do not require GNU specifically.
> +
> +*/
> +#if defined(__USE_TIME64_REDIRECTS) || (__TIMESIZE == 32 && 
> __USE_TIME_BITS64)
> +  C("Glibc_Use_Time_Bits64", Boolean, "True", "Y2038 Glibc transition")

Would it make sense to drop the "Glibc" here? Having "Glibc" means that
we end up with glibc specifics in files that are not glibc specific (e.g.
a-exetim__posix.adb or s-osinte__linux.ads). Are these particular macros
glibc specific? We need these to build with other libc (e.g. musl).

> +#else
> +  C("Glibc_Use_Time_Bits64", Boolean, "False", "Y2038 Glibc transition")
> +#endif
> +
>  /*
>
> --  Sizes of various data types

Thanks,
Marc


[COMMITTED 01/30] ada: Fix omissions of ALI P line parameters

2025-01-03 Thread Marc Poulhiès
From: Ronan Desplanques 

Before this patch, the compiler would not report various tasking
settings specified in library units when these library units did not use
tasking, or when they were predefined. While this behavior was
implemented deliberately, that was a long time ago and it proved to be
a pitfall that could cause configuration pragmas to be silently ignored.

This patch makes the compiler report the aforementioned tasking settings
in ALI files unconditionally.

Also, this patch fixes an incorrect statement and a couple of typos in
the spec of Lib.Writ.

gcc/ada/ChangeLog:

* lib-writ.adb (Write_ALI): Remove condition for writing P line
parameters.
* lib-writ.ads: Fix typos. Clarify comment.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/lib-writ.adb | 26 --
 gcc/ada/lib-writ.ads | 15 ---
 2 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/gcc/ada/lib-writ.adb b/gcc/ada/lib-writ.adb
index e6bfbf1bb37..4e7ed5a380a 100644
--- a/gcc/ada/lib-writ.adb
+++ b/gcc/ada/lib-writ.adb
@@ -1240,22 +1240,20 @@ package body Lib.Writ is
  Write_Info_Str (" DB");
   end if;
 
-  if Tasking_Used and then not Is_Predefined_Unit (Main_Unit) then
- if Locking_Policy /= ' ' then
-Write_Info_Str  (" L");
-Write_Info_Char (Locking_Policy);
- end if;
+  if Locking_Policy /= ' ' then
+ Write_Info_Str  (" L");
+ Write_Info_Char (Locking_Policy);
+  end if;
 
- if Queuing_Policy /= ' ' then
-Write_Info_Str  (" Q");
-Write_Info_Char (Queuing_Policy);
- end if;
+  if Queuing_Policy /= ' ' then
+ Write_Info_Str  (" Q");
+ Write_Info_Char (Queuing_Policy);
+  end if;
 
- if Task_Dispatching_Policy /= ' ' then
-Write_Info_Str  (" T");
-Write_Info_Char (Task_Dispatching_Policy);
-Write_Info_Char (' ');
- end if;
+  if Task_Dispatching_Policy /= ' ' then
+ Write_Info_Str  (" T");
+ Write_Info_Char (Task_Dispatching_Policy);
+ Write_Info_Char (' ');
   end if;
 
   if GNATprove_Mode then
diff --git a/gcc/ada/lib-writ.ads b/gcc/ada/lib-writ.ads
index 38206179dfc..fc489e7f3c3 100644
--- a/gcc/ada/lib-writ.ads
+++ b/gcc/ada/lib-writ.ads
@@ -228,9 +228,9 @@ package Lib.Writ is
-- OL   Pragma Default_Scalar_Storage_Order (Low_Order_First) is
--  present in a configuration pragma file that applies.
 
-   -- Qx   A valid Queueing_Policy pragma applies to all the units
-   --  in this file, where x is the first character (upper case)
-   --  of the policy name (e.g. 'P' for Priority_Queueing).
+   -- Qx   A valid Queuing_Policy pragma applies to all the units in
+   --  this file, where x is the first character (upper case) of
+   --  the policy name (e.g. 'P' for Priority_Queuing).
 
-- SL   Indicates that the unit is an Interface to a Standalone
--  Library. Note that this indication is never given by the
@@ -253,10 +253,11 @@ package Lib.Writ is
--  generated exception tables. If ZX is not present, the
--  longjmp/setjmp exception scheme is in use.
 
-   --  Note that language defined units never output policy (Lx, Tx, Qx)
-   --  parameters. Language defined units must correctly handle all
-   --  possible cases. These values are checked for consistency by the
-   --  binder and then copied to the generated binder output file.
+   --  Note that library units from the GNAT runtime library should never
+   --  output policy (Lx, Tx, Qx) parameters. They must correctly handle
+   --  all possible cases to be usable in all contexts. These values are
+   --  checked for consistency by the binder and then copied to the
+   --  generated binder output file.
 
--Note: The P line must be present. Even in Ignore_Errors mode, Scan_ALI
--insists on finding a P line. So if changes are made to the ALI format,
-- 
2.43.0



Re: [PATCH v4 7/7] OpenMP: update documentation for dispatch and adjust_args

2025-01-03 Thread Paul-Antoine Arras

Committing this last patch in the set as obvious (and approved off list).

On 02/10/2024 18:55, Paul-Antoine Arras wrote:

libgomp/ChangeLog:

* libgomp.texi:
---
  libgomp/libgomp.texi | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index c6464ece32e..7026f32f867 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -294,8 +294,8 @@ The OpenMP 4.5 specification is fully supported.
  @item C/C++'s @code{declare variant} directive: elision support of
preprocessed code @tab N @tab
  @item @code{declare variant}: new clauses @code{adjust_args} and
-  @code{append_args} @tab N @tab
-@item @code{dispatch} construct @tab N @tab
+  @code{append_args} @tab P @tab Only @code{adjust_args}
+@item @code{dispatch} construct @tab Y @tab
  @item device-specific ICV settings with environment variables @tab Y @tab
  @item @code{assume} and @code{assumes} directives @tab Y @tab
  @item @code{nothing} directive @tab Y @tab



--
PA


RE: [PATCH]AArch64: Implement four and eight chunk VLA concats [PR118272]

2025-01-03 Thread Tamar Christina
> -Original Message-
> From: Richard Sandiford 
> Sent: Friday, January 3, 2025 10:59 AM
> To: Tamar Christina 
> Cc: gcc-patches@gcc.gnu.org; nd ; Richard Earnshaw
> ; ktkac...@gcc.gnu.org
> Subject: Re: [PATCH]AArch64: Implement four and eight chunk VLA concats
> [PR118272]
> 
> Tamar Christina  writes:
> >> >
> >> > How about instead doing something like:
> >> >
> >> >   worklist.reserve (nelts);
> >> >   for (int i = 0; i < nelts; ++i)
> >> > worklist.quick_push (force_reg (elem_mode, XVECEXP (vals, 0, i)));
> >> >
> >> >   while (nelts > 2)
> >> > {
> >> >   for (int i = 0; i < nelts; i += 2)
> >> > {
> >> >   ...read worklist[i] and worklist[i + 1]...
> >> >   ...write back to worklist[i / 2]...
> >> > }
> >> >   nelts /= 2;
> >> > }
> >> >
> >> >   emit_insn (gen_aarch64_pack_partial (mode, target, worklist[0],
> >> >worklist[1]));
> >> >
> >>
> >> I think this is better since we above the memmove.. Apologies for the bug ☹
> >>
> >> I'll respin.
> >
> > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
> >
> > Ok for master?
> >
> > Thanks,
> > Tamar
> >
> > gcc/ChangeLog:
> >
> > PR target/96342
> > PR target/118272
> > * config/aarch64/aarch64-sve.md (vec_init,
> > vec_initvnx16qivnx2qi): New.
> > * config/aarch64/aarch64.cc 
> > (aarch64_sve_expand_vector_init_subvector):
> > Rewrite to support any arbitrary combinations.
> > * config/aarch64/iterators.md (SVE_NO2E): Update to use SVE_NO4E
> > (SVE_NO2E, Vquad): New.
> >
> > gcc/testsuite/ChangeLog:
> >
> > PR target/96342
> > PR target/118272
> > * gcc.target/aarch64/vect-simd-clone-3.c: New test.
> >
> > -- inline copy of patch --
> >
> > diff --git a/gcc/config/aarch64/aarch64-sve.md b/gcc/config/aarch64/aarch64-
> sve.md
> > index
> 6659bb4fcab34699f22ff883825de1cd67108203..35f55bfacfc3238a8a7aa69015
> f36ba32981af59 100644
> > --- a/gcc/config/aarch64/aarch64-sve.md
> > +++ b/gcc/config/aarch64/aarch64-sve.md
> > @@ -2839,6 +2839,7 @@ (define_expand "vec_init"
> >}
> >  )
> >
> > +;; Vector constructor combining two half vectors { a, b }
> >  (define_expand "vec_init"
> >[(match_operand:SVE_NO2E 0 "register_operand")
> > (match_operand 1 "")]
> > @@ -2849,6 +2850,28 @@ (define_expand "vec_init"
> >}
> >  )
> >
> > +;; Vector constructor combining four quad vectors { a, b, c, d }
> > +(define_expand "vec_init"
> > +  [(match_operand:SVE_NO4E 0 "register_operand")
> > +   (match_operand 1 "")]
> > +  "TARGET_SVE"
> > +  {
> > +aarch64_sve_expand_vector_init_subvector (operands[0], operands[1]);
> > +DONE;
> > +  }
> > +)
> > +
> > +;; Vector constructor combining eight vectors { a, b, c, d, ... }
> > +(define_expand "vec_initvnx16qivnx2qi"
> > +  [(match_operand:VNx16QI 0 "register_operand")
> > +   (match_operand 1 "")]
> > +  "TARGET_SVE"
> > +  {
> > +aarch64_sve_expand_vector_init_subvector (operands[0], operands[1]);
> > +DONE;
> > +  }
> > +)
> > +
> >  ;; Shift an SVE vector left and insert a scalar into element 0.
> >  (define_insn "vec_shl_insert_"
> >[(set (match_operand:SVE_FULL 0 "register_operand")
> > diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
> > index
> cb9b155826d12b622ae0df1736e4b042d01cf56a..c7c165ddb3a825a4e5ce4fc1
> 18d39047ce9bf7e8 100644
> > --- a/gcc/config/aarch64/aarch64.cc
> > +++ b/gcc/config/aarch64/aarch64.cc
> > @@ -24898,18 +24898,42 @@ aarch64_sve_expand_vector_init_subvector (rtx
> target, rtx vals)
> >machine_mode mode = GET_MODE (target);
> >int nelts = XVECLEN (vals, 0);
> >
> > -  gcc_assert (nelts == 2);
> > +  gcc_assert (nelts % 2 == 0);
> >
> > -  rtx arg0 = XVECEXP (vals, 0, 0);
> > -  rtx arg1 = XVECEXP (vals, 0, 1);
> > -
> > -  /* If we have two elements and are concatting vector.  */
> > -  machine_mode elem_mode = GET_MODE (arg0);
> > +  /* We have to be concatting vector.  */
> > +  machine_mode elem_mode = GET_MODE (XVECEXP (vals, 0, 0));
> >gcc_assert (VECTOR_MODE_P (elem_mode));
> >
> > -  arg0 = force_reg (elem_mode, arg0);
> > -  arg1 = force_reg (elem_mode, arg1);
> > -  emit_insn (gen_aarch64_pack_partial (mode, target, arg0, arg1));
> > +  auto_vec worklist;
> > +  machine_mode wider_mode = elem_mode;
> > +
> > +  for (int i = 0; i < nelts; i++)
> > +worklist.safe_push (force_reg (elem_mode, XVECEXP (vals, 0, i)));
> > +
> > +  /* Keep widening pairwise to have maximum throughput.  */
> > +  while (nelts >= 2)
> > +{
> > +  wider_mode
> > + = related_vector_mode (wider_mode, GET_MODE_INNER (wider_mode),
> > +GET_MODE_NUNITS (wider_mode) * 2).require 
> > ();
> 
> Formatting nit, sorry, but: the last two lines seem to be indented
> two columns too far.
> 
> > +
> > +  for (int i = 0; i < nelts; i += 2)
> > +   {
> > + rtx arg0 = worklist[i];
> > +  

Re: [PATCH] c++/modules: Fallback to ftruncate if posix_fallocate fails [PR115008]

2025-01-03 Thread Nathaniel Shead
On Wed, Jan 01, 2025 at 06:11:07PM -0500, Jason Merrill wrote:
> On 12/29/24 4:39 AM, Gerald Pfeifer wrote:
> > On Sat, 28 Dec 2024, Jason Merrill wrote:
> > > On 12/22/24 5:38 AM, Nathaniel Shead wrote:
> > > > Bootstrapped and regtested on x86_64-pc-linux-gnu, and also on
> > > > x86_64-unknown-freebsd13.3 by Gerald ([1], see also the discussion on
> > > > the PR); OK for trunk?
> > > OK.
> > 
> > Can this also go on the GCC 14 branch where this is happening as well?
> 
> Sure.
> 

Thanks, pushed as r14-11125-g1c3dee768a9f7aa384150e4e4a584d6aa1db5e97.

> > (x86_64-unknown-freebsd13.3 testresults there are > 1MB there, too, due to
> > this.)
> > 
> > Thanks,
> > Gerald
> > 
> 


[COMMITTED 15/30] ada: Simplify traversal procedures into traversal functions

2025-01-03 Thread Marc Poulhiès
From: Piotr Trojanek 

Instead of using the generic routine Traverse_Proc to set a global flag when a
particular node is found, we can use its underlying routine Traverse_Func and
check if traversal has been abandoned. We already used this pattern in a number
of places; this patch merely applies it the remaining uses of Traverse_Proc.

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_ch3.adb (Search_Access_Discriminant, Search_Current_Instance,
Search_Internal_Call): Use traversal function instead of traversal
procedure and remove associated global variables.
* exp_util.adb (Search_Calls): Likewise.
* sem_prag.adb (Contains_Loop_Entry): Likewise.
* sem_util.adb (Mentions_Post_State): Likewise.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch3.adb  | 67 ++--
 gcc/ada/exp_util.adb | 11 ++--
 gcc/ada/sem_prag.adb |  8 ++
 gcc/ada/sem_util.adb | 15 +++---
 4 files changed, 35 insertions(+), 66 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index afcb0a9d328..71bca1cdc88 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -10406,63 +10406,57 @@ package body Exp_Ch3 is
 (Decl : Node_Id;
  Rec_Type : Entity_Id) return Boolean
   is
- References_Current_Instance : Boolean := False;
- Has_Access_Discriminant : Boolean := False;
- Has_Internal_Call   : Boolean := False;
-
- function Find_Access_Discriminant
+ function Is_Access_Discriminant
(N : Node_Id) return Traverse_Result;
  --  Look for a name denoting an access discriminant
 
- function Find_Current_Instance
+ function Is_Current_Instance
(N : Node_Id) return Traverse_Result;
  --  Look for a reference to the current instance of the type
 
- function Find_Internal_Call
+ function Is_Internal_Call
(N : Node_Id) return Traverse_Result;
  --  Look for an internal protected function call
 
- --
- -- Find_Access_Discriminant --
- --
+ 
+ -- Is_Access_Discriminant --
+ 
 
- function Find_Access_Discriminant
+ function Is_Access_Discriminant
(N : Node_Id) return Traverse_Result is
  begin
 if Is_Entity_Name (N)
   and then Denotes_Discriminant (N)
   and then Is_Access_Type (Etype (N))
 then
-   Has_Access_Discriminant := True;
return Abandon;
 else
return OK;
 end if;
- end Find_Access_Discriminant;
+ end Is_Access_Discriminant;
 
- ---
- -- Find_Current_Instance --
- ---
+ -
+ -- Is_Current_Instance --
+ -
 
- function Find_Current_Instance
+ function Is_Current_Instance
(N : Node_Id) return Traverse_Result is
  begin
 if Is_Entity_Name (N)
   and then Present (Entity (N))
   and then Is_Current_Instance (N)
 then
-   References_Current_Instance := True;
return Abandon;
 else
return OK;
 end if;
- end Find_Current_Instance;
+ end Is_Current_Instance;
 
- 
- -- Find_Internal_Call --
- 
+ --
+ -- Is_Internal_Call --
+ --
 
- function Find_Internal_Call (N : Node_Id) return Traverse_Result is
+ function Is_Internal_Call (N : Node_Id) return Traverse_Result is
 
 function Call_Scope (N : Node_Id) return Entity_Id;
 --  Return the scope enclosing a given call node N
@@ -10486,21 +10480,20 @@ package body Exp_Ch3 is
   and then Call_Scope (N)
  = Corresponding_Concurrent_Type (Rec_Type)
 then
-   Has_Internal_Call := True;
return Abandon;
 else
return OK;
 end if;
- end Find_Internal_Call;
+ end Is_Internal_Call;
 
- procedure Search_Access_Discriminant is new
-   Traverse_Proc (Find_Access_Discriminant);
+ function Search_Access_Discriminant is new
+   Traverse_Func (Is_Access_Discriminant);
 
- procedure Search_Current_Instance is new
-   Traverse_Proc (Find_Current_Instance);
+ function Search_Current_Instance is new
+   Traverse_Func (Is_Current_Instance);
 
- procedure Search_Internal_Call is new
-   Traverse_Proc (Find_I

[COMMITTED 21/30] ada: Add parentheses in expressions involving combinations of and & or

2025-01-03 Thread Marc Poulhiès
From: Tucker Taft 

In the Expression_Image function, we were not inserting
parentheses properly when there was a sequence of
and and or operators, even though Ada requires such
parentheses to show the correct order of association.

gcc/ada/ChangeLog:

* pprint.adb (Expression_Image): In local function Expr_Name
add a No_Parens flag and define a subtype Not_Associative
to represent the short-circuit operations and And/Or/Xor.
Insert parentheses to separate the subexpressions when
different "Not_Associative" operations occur in a
sequence.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/pprint.adb | 53 --
 1 file changed, 46 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/pprint.adb b/gcc/ada/pprint.adb
index b5935fcb0b4..5958a6b47b2 100644
--- a/gcc/ada/pprint.adb
+++ b/gcc/ada/pprint.adb
@@ -57,12 +57,16 @@ package body Pprint is
   function Expr_Name
 (Expr: Node_Id;
  Take_Prefix : Boolean := True;
- Expand_Type : Boolean := True) return String;
+ Expand_Type : Boolean := True;
+ No_Parens   : Boolean := False) return String;
   --  Return string corresponding to Expr. If no string can be extracted,
   --  return "...". If Take_Prefix is True, go back to prefix when needed,
   --  otherwise only consider the right-hand side of an expression. If
   --  Expand_Type is True and Expr is a type, try to expand Expr (an
   --  internally generated type) into a user understandable name.
+  --  If No_Parens is True, then suppress creating parentheses
+  --  around expression.  If False, check to see whether expression
+  --  should be parenthesized.
 
   function Count_Parentheses (S : String; C : Character) return Natural
 with Pre => C in '(' | ')';
@@ -70,6 +74,8 @@ package body Pprint is
   --  to string S for getting a correctly parenthesized result. For C = '('
   --  this means prepending the character, for C = ')' this means appending
   --  the character.
+  --  In other words, count the number of missing instances of C,
+  --  but never return less than zero.
 
   function Fix_Parentheses (S : String) return String;
   --  Counts the number of required opening and closing parentheses in S to
@@ -101,6 +107,7 @@ package body Pprint is
  Elmt : Node_Id;
 
  Printed_Elmts : Natural := 0;
+ List_Len : constant Natural := Natural (List_Length (List));
 
   begin
  --  Give up if the printed list is too deep
@@ -146,7 +153,8 @@ package body Pprint is
 --  Print expression itself as "12345"
 
 else
-   Append (Buf, Expr_Name (Elmt));
+   Append (Buf, Expr_Name (Elmt, No_Parens => List_Len = 1));
+  --  Suppress parens if is the only parameter.
 end if;
 
 Next (Elmt);
@@ -178,9 +186,32 @@ package body Pprint is
   function Expr_Name
 (Expr: Node_Id;
  Take_Prefix : Boolean := True;
- Expand_Type : Boolean := True) return String
+ Expand_Type : Boolean := True;
+ No_Parens   : Boolean := False) return String
   is
+ --  Define subtype matching logical operations
+ --  and [then], or [else], and xor.
+ subtype Not_Associative is N_Subexpr
+   with Static_Predicate =>
+ Not_Associative in
+   N_Short_Circuit | N_Op_And | N_Op_Or | N_Op_Xor;
   begin
+ if not No_Parens
+  and then
+(Paren_Count (Expr) > 0
+  or else
+ (Nkind (Expr) in Not_Associative
+   and then
+  Nkind (Parent (Expr)) in Not_Associative
+   and then
+  Nkind (Parent (Expr)) /= Nkind (Expr)))
+ then
+--  Parentheses are needed
+return '(' &
+  Expr_Name (Expr, Take_Prefix, Expand_Type, No_Parens => True) &
+  ')';
+ end if;
+
  Num_Elements := Num_Elements + 1;
 
  if Num_Elements > Max_Expr_Elements then
@@ -589,7 +620,9 @@ package body Pprint is
return "abs " & Expr_Name (Right_Opnd (Expr));
 
 when N_Op_Not =>
-   return "not (" & Expr_Name (Right_Opnd (Expr)) & ")";
+   return "not (" &
+  Expr_Name (Right_Opnd (Expr), No_Parens => True) &
+  ")";
 
 when N_Type_Conversion =>
 
@@ -608,7 +641,9 @@ package body Pprint is
Is_Modular_Integer_Type (Etype (Expression (Expr)))
then
   return Expr_Name (Subtype_Mark (Expr)) &
-"(" & Expr_Name (Expression (Expr)) & ")";
+"(" &
+Expr_Name (Expression (Expr), No_Parens => True) &
+")";
else

[COMMITTED 29/30] ada: Rely on default parameter when making non-constant nodes

2025-01-03 Thread Marc Poulhiès
From: Piotr Trojanek 

When calling Make_Access_To_Object_Definition and Make_Object_Declaration we
can rely on the default value of parameter Constant_Present being False. This
makes code cleaner and consistent with relying on the default value of other
parameters of this routine, like Null_Exclusion_Present.

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_ch3.adb, exp_disp.adb: Remove explicit actual parameter
Constant_Present equal False; tune comments.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch3.adb  | 1 -
 gcc/ada/exp_disp.adb | 8 ++--
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index b69da39da36..ad292ee404e 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -2962,7 +2962,6 @@ package body Exp_Ch3 is
   Make_Access_To_Object_Definition (Loc,
 All_Present=> True,
 Null_Exclusion_Present => False,
-Constant_Present   => False,
 Subtype_Indication =>
   New_Occurrence_Of (Rec_Type, Loc);
 
diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb
index 9fcc4694488..906ddc4175c 100644
--- a/gcc/ada/exp_disp.adb
+++ b/gcc/ada/exp_disp.adb
@@ -1527,7 +1527,6 @@ package body Exp_Disp is
   Make_Access_To_Object_Definition (Loc,
 All_Present=> True,
 Null_Exclusion_Present => False,
-Constant_Present   => False,
 Subtype_Indication =>
   New_Occurrence_Of (Desig_Typ, Loc)));
 
@@ -1974,7 +1973,6 @@ package body Exp_Disp is
   Make_Access_To_Object_Definition (Loc,
 All_Present=> True,
 Null_Exclusion_Present => False,
-Constant_Present   => False,
 Subtype_Indication =>
   New_Occurrence_Of (Ftyp, Loc)));
 
@@ -4922,7 +4920,7 @@ package body Exp_Disp is
   if not Building_Static_DT (Typ) then
 
  --  Generate:
- --DT : No_Dispatch_Table_Wrapper;
+ --DT : aliased No_Dispatch_Table_Wrapper;
  --DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
 
  if not Has_DT (Typ) then
@@ -4930,7 +4928,6 @@ package body Exp_Disp is
   Make_Object_Declaration (Loc,
 Defining_Identifier => DT,
 Aliased_Present => True,
-Constant_Present=> False,
 Object_Definition   =>
   New_Occurrence_Of
 (RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
@@ -4973,7 +4970,7 @@ package body Exp_Disp is
 end if;
 
  --  Generate:
- --DT : Dispatch_Table_Wrapper (Nb_Prim);
+ --DT : aliased Dispatch_Table_Wrapper (Nb_Prim);
  --DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
 
  else
@@ -4992,7 +4989,6 @@ package body Exp_Disp is
   Make_Object_Declaration (Loc,
 Defining_Identifier => DT,
 Aliased_Present => True,
-Constant_Present=> False,
 Object_Definition   =>
   Make_Subtype_Indication (Loc,
 Subtype_Mark =>
-- 
2.43.0



[COMMITTED 22/30] ada: Fix comments and change subtype name in response to review

2025-01-03 Thread Marc Poulhiès
From: Tucker Taft 

gcc/ada/ChangeLog:

* pprint.adb (Expression_Image): Adjust and improve comments
to match style recommendations, and change name of subtype
from Not_Associative to Non_Associative, in response to
code review.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/pprint.adb | 27 +--
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/gcc/ada/pprint.adb b/gcc/ada/pprint.adb
index 5958a6b47b2..8061d3daa86 100644
--- a/gcc/ada/pprint.adb
+++ b/gcc/ada/pprint.adb
@@ -64,9 +64,9 @@ package body Pprint is
   --  otherwise only consider the right-hand side of an expression. If
   --  Expand_Type is True and Expr is a type, try to expand Expr (an
   --  internally generated type) into a user understandable name.
-  --  If No_Parens is True, then suppress creating parentheses
-  --  around expression.  If False, check to see whether expression
-  --  should be parenthesized.
+  --  If No_Parens is True, then suppress creating parentheses around
+  --  expression. If False, check to see whether expression should be
+  --  parenthesized.
 
   function Count_Parentheses (S : String; C : Character) return Natural
 with Pre => C in '(' | ')';
@@ -153,8 +153,8 @@ package body Pprint is
 --  Print expression itself as "12345"
 
 else
+   --  Suppress parens if is the only parameter
Append (Buf, Expr_Name (Elmt, No_Parens => List_Len = 1));
-  --  Suppress parens if is the only parameter.
 end if;
 
 Next (Elmt);
@@ -189,24 +189,31 @@ package body Pprint is
  Expand_Type : Boolean := True;
  No_Parens   : Boolean := False) return String
   is
- --  Define subtype matching logical operations
+ --  Define a subtype matching logical operations
  --  and [then], or [else], and xor.
- subtype Not_Associative is N_Subexpr
+ --  In Ada, these operations are non associative -- they
+ --  all have the same precedence, so parentheses
+ --  are needed to indicate the association of
+ --  operands in a sequence of distinct operations.
+ subtype Non_Associative is N_Subexpr
with Static_Predicate =>
- Not_Associative in
+ Non_Associative in
N_Short_Circuit | N_Op_And | N_Op_Or | N_Op_Xor;
   begin
  if not No_Parens
   and then
 (Paren_Count (Expr) > 0
   or else
- (Nkind (Expr) in Not_Associative
+ (Nkind (Expr) in Non_Associative
and then
-  Nkind (Parent (Expr)) in Not_Associative
+  Nkind (Parent (Expr)) in Non_Associative
and then
   Nkind (Parent (Expr)) /= Nkind (Expr)))
  then
---  Parentheses are needed
+--  Parentheses are needed, either because
+--  Paren_Count is greater than zero, or because
+--  this operation and its parent are non associative,
+--  and are not the same operation.
 return '(' &
   Expr_Name (Expr, Take_Prefix, Expand_Type, No_Parens => True) &
   ')';
-- 
2.43.0



[COMMITTED 11/30] ada: Fix small thinko in previous change

2025-01-03 Thread Marc Poulhiès
From: Eric Botcazou 

Even if the declaration of the conditional object is turned into a renaming
during expansion, the conditional object must be finalized when the original
object would have been.

gcc/ada/ChangeLog:

* exp_ch4.adb (Insert_Conditional_Object_Declaration): Create the
Master_Node even if the declaration is turned into a renaming.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch4.adb | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 2fc891a4e39..f44f21d654b 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -13240,9 +13240,7 @@ package body Exp_Ch4 is
   --  cannot invoke Process_Transients_In_Expression on it since it is not
   --  a transient object (it has the lifetime of the original object).
 
-  if Nkind (Obj_Decl) = N_Object_Declaration
-and then Needs_Finalization (Base_Type (Etype (Obj_Id)))
-  then
+  if Needs_Finalization (Base_Type (Etype (Obj_Id))) then
  Master_Node_Id := Make_Temporary (Loc, 'N');
  Master_Node_Decl :=
Make_Master_Node_Declaration (Loc, Master_Node_Id, Obj_Id);
-- 
2.43.0



[COMMITTED 16/30] ada: Simplify check for No_Coextensions restriction

2025-01-03 Thread Marc Poulhiès
From: Piotr Trojanek 

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* sem_res.adb (Resolve_Alocator): Move unrelated code out of a declare
block.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_res.adb | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index 27309b2e019..889cbd307b4 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -5821,13 +5821,13 @@ package body Sem_Res is
   and then Nkind (Associated_Node_For_Itype (Typ)) =
  N_Discriminant_Specification
 then
+   Check_Restriction (No_Coextensions, N);
+
declare
   Discr : constant Entity_Id :=
 Defining_Identifier (Associated_Node_For_Itype (Typ));
 
begin
-  Check_Restriction (No_Coextensions, N);
-
   --  Ada 2012 AI05-0052: If the designated type of the
   --  allocator is limited, then the allocator shall not
   --  be used to define the value of an access discriminant
-- 
2.43.0



[COMMITTED 19/30] ada: Refine subtype of a universal arithmetic utility routine

2025-01-03 Thread Marc Poulhiès
From: Piotr Trojanek 

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* uintp.adb (N_Digits): Refine return subtype, since this routine
always returns a positive number of digits.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/uintp.adb | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/uintp.adb b/gcc/ada/uintp.adb
index fc548e02d57..59ed5b04588 100644
--- a/gcc/ada/uintp.adb
+++ b/gcc/ada/uintp.adb
@@ -174,7 +174,7 @@ package body Uintp is
--  K is as small as possible S.T. Right_Hat < Base * Base. It is required
--  that Left >= Right for the algorithm to work.
 
-   function N_Digits (Input : Valid_Uint) return Int;
+   function N_Digits (Input : Valid_Uint) return Pos;
pragma Inline (N_Digits);
--  Returns number of "digits" in a Uint
 
@@ -603,7 +603,7 @@ package body Uintp is
-- N_Digits --
---
 
-   function N_Digits (Input : Valid_Uint) return Int is
+   function N_Digits (Input : Valid_Uint) return Pos is
begin
   if Direct (Input) then
  if Direct_Val (Input) >= Base then
-- 
2.43.0



[COMMITTED 20/30] ada: Fix latent issue exposed by latest change

2025-01-03 Thread Marc Poulhiès
From: Eric Botcazou 

The finalization machinery needs to precisely locate the point where the
initialization of objects is complete in order to generate the attachment
to the finalization master.  For objects initialized with a built-in-place
function call, this is achieved by means of the BIP_Initialization_Call
field present in their entity node, but this field is only set in the case
where the enclosing scope is transient, which is not guaranteed.

gcc/ada/ChangeLog:

* einfo.ads (BIP_Initialization_Call): Adjust description.
* exp_ch4.adb (Expand_N_Case_Expression): Adjust commentary.
(Expand_N_If_Expression): Likewise.
* exp_ch6.adb (Make_Build_In_Place_Call_In_Object_Declaration):
Set BIP_Initialization_Call unconditionally in the definite case.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/einfo.ads   |  7 +++
 gcc/ada/exp_ch4.adb | 21 -
 gcc/ada/exp_ch6.adb | 20 +---
 3 files changed, 20 insertions(+), 28 deletions(-)

diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index 025465265f3..d283358c0c0 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -526,12 +526,11 @@ package Einfo is
 --   references on this list are illegal due to the visible refinement.
 
 --BIP_Initialization_Call
---   Defined in constants and variables whose corresponding declaration
---   is wrapped in a transient block and the inital value is provided by
+--   Defined in constants and variables whose initial value is provided by
 --   a build-in-place function call. Contains the relocated build-in-place
 --   call after the expansion has decoupled the call from the object. This
---   attribute is used by the finalization machinery to insert cleanup code
---   for all additional transient objects found in the transient block.
+--   attribute is used by the finalization machinery to insert the call to
+--   the routine that attaches the object to the finalization master.
 
 --C_Pass_By_Copy [implementation base type only]
 --   Defined in record types. Set if a pragma Convention for the record
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index f44f21d654b..81b2b734bbf 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -5104,7 +5104,8 @@ package body Exp_Ch4 is
   --  If the expression is in the context of a simple return statement,
   --  possibly through intermediate conditional expressions, we delay
   --  expansion until the (immediate) parent is rewritten as a return
-  --  statement (or is already the return statement).
+  --  statement (or is already the return statement). Likewise if it is
+  --  in the context of an object declaration that can be optimized.
 
   if not Expansion_Delayed (N) then
  declare
@@ -5119,9 +5120,9 @@ package body Exp_Ch4 is
   end if;
 
   --  If the expansion of the expression has been delayed, we wait for the
-  --  rewriting of its parent as an assignment or return statement; when
-  --  that's done, we optimize the assignment or the return statement (the
-  --  very purpose of the manipulation).
+  --  rewriting of its parent as an assignment statement, or as as return
+  --  statement or as an object declaration; when that's done, we optimize
+  --  the assignment, return or declaration (the purpose of the delaying).
 
   if Expansion_Delayed (N) then
  if Nkind (Par) = N_Assignment_Statement then
@@ -5721,8 +5722,10 @@ package body Exp_Ch4 is
   --  If the expression is in the context of a simple return statement,
   --  possibly through intermediate conditional expressions, we delay
   --  expansion until the (immediate) parent is rewritten as a return
-  --  statement (or is already the return statement). Note that this
-  --  deals with the case of the elsif part of the if expression.
+  --  statement (or is already the return statement). Likewise if it is
+  --  in the context of an object declaration that can be optimized.
+  --  Note that this deals with the case of the elsif part of the if
+  --  expression, if it exists.
 
   if not Expansion_Delayed (N) then
  declare
@@ -5737,9 +5740,9 @@ package body Exp_Ch4 is
   end if;
 
   --  If the expansion of the expression has been delayed, we wait for the
-  --  rewriting of its parent as an assignment or return statement; when
-  --  that's done, we optimize the assignment or the return statement (the
-  --  very purpose of the manipulation).
+  --  rewriting of its parent as an assignment statement, or as as return
+  --  statement or as an object declaration; when that's done, we optimize
+  --  the assignment, return or declaration (the purpose of the delaying).
 
   if Expansion_Delayed (N) then
  if Nkind (Par) = N_Assignment_Statement then
diff --git a/gcc/ada/exp_ch6.adb b/gcc

[COMMITTED 23/30] ada: Enclosing_Entity of specless subprogram bodies

2025-01-03 Thread Marc Poulhiès
From: Bob Duff 

Correct Enclosing_Entity of specless subprogram bodies;
these are marked as Comes_From_Source = False,
so the simple name was missing.

gcc/ada/ChangeLog:

* sem_util.adb (Append_Entity_Name): Do not skip the
simple name for a compilation unit (which includes
the case of specless subprogram bodies).

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_util.adb | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 4a26d962303..44a87298c6e 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -649,18 +649,21 @@ package body Sem_Util is
   --  recursively print A.B.C, then print D.
begin
   --  If E is not a source entity, then skip the simple name and just
-  --  recursively print its scope. However, subprogram instances have
-  --  Comes_From_Source = False, but we do want to print the simple name
-  --  of the instance.
+  --  recursively print its scope. However, certain entities have
+  --  Comes_From_Source = False, even though we DO want to print the
+  --  simple name; this happens for specless child subprogram bodies
+  --  and for subprogram instances.
 
   if not Comes_From_Source (E) then
- if Is_Generic_Instance (E)
+ if Is_Compilation_Unit (E) then
+null;
+ elsif Is_Generic_Instance (E)
and then Ekind (E) in E_Function | E_Procedure
  then
 null;
  else
 Append_Entity_Name (Buf, Scope (E));
-return;
+return; -- skip the simple name
  end if;
   end if;
 
-- 
2.43.0



[COMMITTED 26/30] ada: Remove extra checks for raising a constraint error

2025-01-03 Thread Marc Poulhiès
From: Piotr Trojanek 

Routine Is_OK_Static_Expression itself calls Raises_Constraint_Error, so there
is no need to call both of these routines in a row. Code cleanup; semantics is
unaffected.

gcc/ada/ChangeLog:

* sem_attr.adb (Check_Array_Type): Remove extra call.
* sem_util.adb (Static_Boolean): Likewise.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_attr.adb |  4 +---
 gcc/ada/sem_util.adb | 12 ++--
 2 files changed, 3 insertions(+), 13 deletions(-)

diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index 6eb04b2e258..7295784704f 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -1994,9 +1994,7 @@ package body Sem_Attr is
 Resolve (E1, Any_Integer);
 Set_Etype (E1, Standard_Integer);
 
-if not Is_OK_Static_Expression (E1)
-  or else Raises_Constraint_Error (E1)
-then
+if not Is_OK_Static_Expression (E1) then
Flag_Non_Static_Expr
  ("expression for dimension must be static!", E1);
Error_Attr;
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index bd798d74885..c1af2281a22 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -28232,11 +28232,7 @@ package body Sem_Util is
   end if;
 
   if Is_OK_Static_Expression (N) then
- if not Raises_Constraint_Error (N) then
-return Expr_Value (N);
- else
-return No_Uint;
- end if;
+ return Expr_Value (N);
 
   elsif Etype (N) = Any_Type then
  return No_Uint;
@@ -28264,11 +28260,7 @@ package body Sem_Util is
   end if;
 
   if Is_OK_Static_Expression (N) then
- if not Raises_Constraint_Error (N) then
-return Expr_Value (N);
- else
-return No_Uint;
- end if;
+ return Expr_Value (N);
 
   elsif Etype (N) = Any_Type then
  return No_Uint;
-- 
2.43.0



[COMMITTED 28/30] ada: Rely on default parameter when making component definition nodes

2025-01-03 Thread Marc Poulhiès
From: Piotr Trojanek 

When calling Make_Component_Definition we can rely on the default value of
parameter Aliased_Present being False. This makes code cleaner and consistent
with relying on the default value of other parameters of this routine, e.g.
Null_Exclusion_Present.

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_ch3.adb, exp_ch9.adb, exp_dist.adb, exp_imgv.adb, exp_util.adb,
sem_dist.adb: Remove explicit actual parameter Aliased_Present equal
False; tune comments and whitespace.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch3.adb  |  3 ---
 gcc/ada/exp_ch9.adb  | 29 ++---
 gcc/ada/exp_dist.adb |  4 
 gcc/ada/exp_imgv.adb |  1 -
 gcc/ada/exp_util.adb |  3 ---
 gcc/ada/sem_dist.adb |  3 +--
 6 files changed, 7 insertions(+), 36 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index a68b4f12ca6..b69da39da36 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -5687,7 +5687,6 @@ package body Exp_Ch3 is
 
  Component_Definition =>
Make_Component_Definition (Loc,
- Aliased_Present => False,
  Subtype_Indication => New_Occurrence_Of (Typ, Loc))),
 
  Expression =>
@@ -9318,7 +9317,6 @@ package body Exp_Ch3 is
   Defining_Identifier => Parent_N,
   Component_Definition =>
 Make_Component_Definition (Loc,
-  Aliased_Present => False,
   Subtype_Indication => New_Occurrence_Of (Par_Subtype, Loc)));
 
   if Null_Present (Rec_Ext_Part) then
@@ -9376,7 +9374,6 @@ package body Exp_Ch3 is
   Defining_Identifier => First_Tag_Component (T),
   Component_Definition =>
 Make_Component_Definition (Sloc_N,
-  Aliased_Present => False,
   Subtype_Indication => New_Occurrence_Of (RTE (RE_Tag), Sloc_N)));
 
   if Null_Present (Comp_List)
diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
index df51856f9c9..2e49a4a68bc 100644
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -1628,8 +1628,6 @@ package body Exp_Ch9 is
   Make_Defining_Identifier (Loc, Chars (Formal)),
 Component_Definition =>
   Make_Component_Definition (Loc,
-Aliased_Present =>
-  False,
 Subtype_Indication =>
   New_Occurrence_Of (Comp_Nam, Loc;
 
@@ -4808,7 +4806,7 @@ package body Exp_Ch9 is
   Identifier => New_Occurrence_Of (Blkent, Loc),
   Declarations => New_List (
 
---  _Chain : Activation_Chain;
+--  _Chain : aliased Activation_Chain;
 
 Make_Object_Declaration (Loc,
   Defining_Identifier => Chain,
@@ -4968,7 +4966,6 @@ package body Exp_Ch9 is
 
 Component_Definition =>
   Make_Component_Definition (Loc,
-Aliased_Present=> False,
 Subtype_Indication =>
   New_Occurrence_Of (Standard_Character, Loc;
 end;
@@ -4984,7 +4981,6 @@ package body Exp_Ch9 is
 
 Component_Definition =>
   Make_Component_Definition (Loc,
-Aliased_Present=> False,
 Subtype_Indication =>
   Make_Subtype_Indication (Loc,
 Subtype_Mark =>
@@ -5764,7 +5760,6 @@ package body Exp_Ch9 is
   Defining_Identifier  => Make_Temporary (Loc, 'P'),
   Component_Definition =>
 Make_Component_Definition (Loc,
-  Aliased_Present=> False,
   Subtype_Indication =>
 New_Occurrence_Of (RTE (RE_Address), Loc))),
 
@@ -5772,7 +5767,6 @@ package body Exp_Ch9 is
   Defining_Identifier  => Make_Temporary (Loc, 'S'),
   Component_Definition =>
 Make_Component_Definition (Loc,
-  Aliased_Present=> False,
   Subtype_Indication => New_Occurrence_Of (D_T2, Loc;
 
   Decl2 :=
@@ -8153,7 +8147,6 @@ package body Exp_Ch9 is
 Defining_Identifier => Component,
 Component_Definition =>
   Make_Component_Definition (Loc,
-Aliased_Present=> False,
 Subtype_Indication => New_Occurrence_Of (Ctype, Loc;
 
 Next_Formal_With_Extras (Formal);
@@ -9078,14 +9071,12 @@ package body Exp_Ch9 is
if Present (Subtype_Indication (Old_Comp)) then
   New_Comp :=
 Make_Component_Definition (Sloc (Oent),
-  Aliased_Present=> False,
   Subtype_Indication =>
 New_Copy_Tree
   (Subtype_Indication (Old_Comp), Discr_Map));
else
   New_Comp :=
   

Re: [PATCH v11] ada: fix timeval timespec on 32 bits archs with 64 bits time_t [PR114065]

2025-01-03 Thread Sam James
Marc Poulhiès  writes:

> Hello Nicolas,
>
>>> At first view, it seems possible and desirable to merge _posix and
>>> _rtems, but working on this right now would be counter-productive.
>>>
>>> I suggest to apply patches 1-2 and fix PR114065 first.
>>>
>>> Then the cosmetic changes in patches 3-6 (and possibly a trivial
>>> backport of 8).
>>>
>>> After that, we will have all the time in the long winter afternoons to
>>> discuss file names in patch 7.
>>
>> Hello Nicolas,
>>
>> I wanted to test your latest version of the patch, but it does not apply
>> cleanly. Any chance you could send an updated version? I've tried to
>> apply over some recent revisions and also over some revisions around the
>> time you sent your mail, but none worked.
>
> I've discussed with Doug (author of the conflicting change).
>
> Overall, your change is OK, with the following exception: we can't
> change the Calendar API, so the revert is not OK. User code using the
> new "*_64" function will break. A possible solution would be to
> implement the API using your change.
>
> While looking at the changes again, I have one more comment, see below.
>
>> diff --git a/gcc/ada/s-oscons-tmplt.c b/gcc/ada/s-oscons-tmplt.c
>> index e5dad44..a64e578 100644
>> --- a/gcc/ada/s-oscons-tmplt.c
>> +++ b/gcc/ada/s-oscons-tmplt.c
>> @@ -1775,6 +1775,22 @@ CNS(MAX_tv_sec, "")
>>  CND(SIZEOF_tv_nsec, "tv_nsec");
>>  }
>>
>> +/*
>> +
>> +   --  Functions with time_t suseconds_t timeval timespec parameters like
>> +   --clock_get{res,time} gettimeofday nanosleep
>> +   --pthread_cond_{,timed}wait select
>> +   --  must be imported from the GNU C library with
>> +   --External_Name => (if Glibc_Use_Time_Bits64 then "__foo64" else 
>> "foo")
>> +   --  The test is safe in files that do not require GNU specifically.
>> +
>> +*/
>> +#if defined(__USE_TIME64_REDIRECTS) || (__TIMESIZE == 32 && 
>> __USE_TIME_BITS64)
>> +  C("Glibc_Use_Time_Bits64", Boolean, "True", "Y2038 Glibc transition")
>
> Would it make sense to drop the "Glibc" here? Having "Glibc" means that
> we end up with glibc specifics in files that are not glibc specific (e.g.
> a-exetim__posix.adb or s-osinte__linux.ads). Are these particular macros
> glibc specific? We need these to build with other libc (e.g. musl).

As an aside: I won't promise to work on this just yet, but there's some fixes 
needed
to get GNAT building on musl. If these are welcomed, I'll move it a bit
higher up on my list.

>
>> +#else
>> +  C("Glibc_Use_Time_Bits64", Boolean, "False", "Y2038 Glibc transition")
>> +#endif
>> +
>>  /*
>>
>> --  Sizes of various data types
>
> Thanks,
> Marc


[COMMITTED 30/30] ada: Rely on default parameter when making non-null nodes

2025-01-03 Thread Marc Poulhiès
From: Piotr Trojanek 

When calling Make_Access_To_Object_Definition and Make_Parameter_Specification
we can rely on the default value of parameter Null_Exclusion_Present being
False. This makes code cleaner and consistent with relying on the default value
of other parameters of this routine.

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_ch3.adb, exp_ch4.adb, exp_disp.adb, inline.adb: Remove explicit
actual parameter Null_Exclusion_Present equal False.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch3.adb  | 5 ++---
 gcc/ada/exp_ch4.adb  | 7 +++
 gcc/ada/exp_disp.adb | 5 ++---
 gcc/ada/inline.adb   | 9 -
 4 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index ad292ee404e..9419d5d2fac 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -2960,9 +2960,8 @@ package body Exp_Ch3 is
 Defining_Identifier => Acc_Type,
 Type_Definition =>
   Make_Access_To_Object_Definition (Loc,
-All_Present=> True,
-Null_Exclusion_Present => False,
-Subtype_Indication =>
+All_Present=> True,
+Subtype_Indication =>
   New_Occurrence_Of (Rec_Type, Loc);
 
 Set_Handled_Statement_Sequence (Body_Node,
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 81b2b734bbf..18656ea24fd 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -909,11 +909,10 @@ package body Exp_Ch4 is
Defining_Identifier => Def_Id,
Type_Definition =>
  Make_Access_To_Object_Definition (Loc,
-   All_Present=> True,
-   Null_Exclusion_Present => False,
-   Constant_Present   =>
+   All_Present=> True,
+   Constant_Present   =>
  Is_Access_Constant (PtrT),
-   Subtype_Indication =>
+   Subtype_Indication =>
  New_Occurrence_Of (Etype (Exp), Loc;
 
--  Inherit the allocation-related attributes from the original
diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb
index 906ddc4175c..f45c32356a9 100644
--- a/gcc/ada/exp_disp.adb
+++ b/gcc/ada/exp_disp.adb
@@ -1525,9 +1525,8 @@ package body Exp_Disp is
 Defining_Identifier => Make_Temporary (Loc, 'T'),
 Type_Definition =>
   Make_Access_To_Object_Definition (Loc,
-All_Present=> True,
-Null_Exclusion_Present => False,
-Subtype_Indication =>
+All_Present=> True,
+Subtype_Indication =>
   New_Occurrence_Of (Desig_Typ, Loc)));
 
 Stats := New_List (
diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb
index a24b0704c91..30d3b1bbf4d 100644
--- a/gcc/ada/inline.adb
+++ b/gcc/ada/inline.adb
@@ -2431,12 +2431,11 @@ package body Inline is
 
  Append_To (Formals,
Make_Parameter_Specification (Loc,
- Defining_Identifier=>
+ Defining_Identifier =>
Make_Defining_Identifier (Loc, Chars (Obj_Id)),
- In_Present => False,
- Out_Present=> not Constant_Present (Obj_Decl),
- Null_Exclusion_Present => False,
- Parameter_Type => Typ_Def));
+ In_Present  => False,
+ Out_Present => not Constant_Present (Obj_Decl),
+ Parameter_Type  => Typ_Def));
   end Build_Return_Object_Formal;
 
   --
-- 
2.43.0



Re: [PATCH v11] ada: fix timeval timespec on 32 bits archs with 64 bits time_t [PR114065]

2025-01-03 Thread Marc Poulhiès


>> Would it make sense to drop the "Glibc" here? Having "Glibc" means that
>> we end up with glibc specifics in files that are not glibc specific (e.g.
>> a-exetim__posix.adb or s-osinte__linux.ads). Are these particular macros
>> glibc specific? We need these to build with other libc (e.g. musl).
>
> As an aside: I won't promise to work on this just yet, but there's some fixes 
> needed
> to get GNAT building on musl. If these are welcomed, I'll move it a bit
> higher up on my list.

Unless the changes are very intrusive, I don't expect any pushback :)

As I just remembered about some Alpine local patch to get gnat to build,
I tried to find it again, and found a change related to 64 bits time:

https://gitlab.kveer.fr/upstream/alpine-aports/-/blob/3.21-stable/main/gcc/0032-libgnat-time_t-is-always-64-bit-on-musl-libc.patch

So it's possible this change makes the musl build a bit easier.

But there are some more:
https://gitlab.kveer.fr/upstream/alpine-aports/-/blob/3.21-stable/main/gcc/0025-ada-libgnarl-compatibility-for-musl.patch

I guess you are referring to similar changes?

Thanks,

Marc


Re: [PATCH v11] ada: fix timeval timespec on 32 bits archs with 64 bits time_t [PR114065]

2025-01-03 Thread Sam James
Marc Poulhiès  writes:

>>> Would it make sense to drop the "Glibc" here? Having "Glibc" means that
>>> we end up with glibc specifics in files that are not glibc specific (e.g.
>>> a-exetim__posix.adb or s-osinte__linux.ads). Are these particular macros
>>> glibc specific? We need these to build with other libc (e.g. musl).
>>
>> As an aside: I won't promise to work on this just yet, but there's some 
>> fixes needed
>> to get GNAT building on musl. If these are welcomed, I'll move it a bit
>> higher up on my list.
>
> Unless the changes are very intrusive, I don't expect any pushback :)
>

Excellent! Should be nothing of that sort.

> As I just remembered about some Alpine local patch to get gnat to build,
> I tried to find it again, and found a change related to 64 bits time:
>
> https://gitlab.kveer.fr/upstream/alpine-aports/-/blob/3.21-stable/main/gcc/0032-libgnat-time_t-is-always-64-bit-on-musl-libc.patch
>
> So it's possible this change makes the musl build a bit easier.
>
> But there are some more:
> https://gitlab.kveer.fr/upstream/alpine-aports/-/blob/3.21-stable/main/gcc/0025-ada-libgnarl-compatibility-for-musl.patch
>
> I guess you are referring to similar changes?
>

Yes, and I think
https://gitlab.alpinelinux.org/alpine/aports/-/blob/master/main/gcc/0026-ada-musl-support-fixes.patch
is the biggest one.

The main challenge with these patches is often they've been carried
around for years and all rationale/commentary is lost, and sadly assume
musl-only, which is why I usually write them from scratch and just
compare my final result with the ones in other musl distros to see if I
missed anything (or not).

cheers,
sam


RE: [PATCH] COBOL 1/8 hdr: header files

2025-01-03 Thread Robert Dubner



> -Original Message-
> From: Joseph Myers 
> Sent: Thursday, January 2, 2025 14:21
> To: Robert Dubner 
> Cc: James K. Lowden ; gcc-patches@gcc.gnu.org
> Subject: RE: [PATCH] COBOL 1/8 hdr: header files
> 
> On Thu, 19 Dec 2024, Robert Dubner wrote:
> 
> > At compile-time (or on the host), we also do numeric calculations.
> > The ISO specification allows for compile-time computations specified
> > in the source code.  In addition, at times I put initial values for
> > the COBOL variables into the run-time structures that are the COBOL
> > variables.  In order to create those CONSTRUCTOR nodes we have to do
> > those calculations at compile time, hence the use of __int128 and
> _Float128 in the host code.
> >
> > In the run-time/host code, I have been using intTI_type_node for
> > __int128, and unsigned_intTI_type_node for __uint128.  For floating
> > point, I've been using float32_type_node, float64_type_node, and
> float128_type_node.
> >
> > If there are recommendations as to what would work better across other
> > architectures, I am all ears.
> 
> As has been noted, wide_int can be used for large integer arithmetic
> within the compiler.  

My needs are modest; we use __int128 in only a few places in the host
code.  If __int128 were supported by 32-bit GCC, we'd wouldn't be having
this conversation.

But since __int128 isn't available, what I need is a drop-in replacement
for __int128.  What I don't see, yet, is how to use wide_int as a such a
replacement.

So, for example, in code that runs on the host I'll convert a string of
numerals to __int128 by doing something like

__int128 value = 0;
while(*p)
{
value = 10*value + *p++ & 0x0F;
}

And when I need to go back to a string, the loop likes like
{
ch = value % 10 + '0';
value /= 10;
}

If I could be pointed to a place to see how that's done, well, it'll save
me a lot of looking through the existing code.

> For floating-point arithmetic, there are the
> interfaces in real.h to handle floating point within GCC's internal
> representation (note that some of the operations might leave a result
with
> extra internal precision; see how fold-const.cc:const_binop calls
> real_arithmetic followed by real_convert to ensure correct rounding to
the
> desired format, for example).

Again, I am not sure we're talking about the same thing.  We have host
code that uses _Float128 values. That's because there are COBOL compiler
directives that need floating point values that can be bigger than IEEE
binary64.  And the COBOL programmer can create source code like

77 float-val USAGE FLOAT-BINARY-128 VALUE 1234.56789 .

and so our compile-time structure for such variables contains a _Float128
value to hold the initial value.  So, again, we'll need a drop-in
replacement for _Float128 that runs on a 32-bit host.

> 
> I don't know if you support decimal floating-point in your front end,
but
> the real.h interfaces deal with that as well (via calling out to
> libdecnumber for arithmetic on DFP values).  Again, DFP support on the
> target (which is supported for a much more limited set of architectures
-
> just aarch64 / powerpc / x86 / x86_64 / s390) does not depend on DFP
> support on the host, since libdecnumber handles all the DFP arithmetic
> required within the compiler.

The latest ISO specification for the COBOL language allows the programmer
to specify DFP in the IEEE754 decimal64 and decimal128 flavors.
Implementing those is not even on our priority list.  (My personal opinion
is that I would be astonished to discover there is a single COBOL program
in the world that utilizes those.)


> 
> --
> Joseph S. Myers
> josmy...@redhat.com



Re: [RFA] [PR rtl-optimization/107455] Eliminate unnecessary constant load

2025-01-03 Thread Richard Sandiford
Jeff Law  writes:
> This resurrects a patch from a bit over 2 years ago that I never wrapped 
> up.  IIRC, I ended up up catching covid, then in the hospital for an 
> unrelated issue and it just got dropped on the floor in the insanity.
>
> The basic idea here is to help postreload-cse eliminate more 
> const/copies by recording a small set of conditional equivalences (as 
> Richi said in 2022, "Ick").
>
> It was originally to help eliminate an unnecessary constant load I saw 
> in coremark, but as seen in BZ107455 the same issues show up in real 
> code as well.
>
> Richard B and Richard S both had good comments last time around and 
> their requests are reflected in this update:
>
>- Use rtx_equal_p rather than pointer equality
>- Restrict to register "destinations"
>- Restrict to integer modes
>- Adjust entry block handling
>
> My own wider scale testing resulted in a few more changes.
>
>- Robustify extracting the (set (pc) ... ), which then required ...
>- Handle if src/dst are clobbered by the conditional branch
>- Fix logic error causing too many equivalences to be recorded

Heh.  I delayed reviewing this for a bit because I have no memory
of seeing it before (sign I'm getting old).  I haven't found my
previous comments, so sorry if this completely contradicts what
I said before...

Overall it looks good to me, but:

> Bootstrapped & regression tested on x86 and clean in my tester. OK for 
> the trunk?
>
> Jeff
>
>   PR rtl-optimization/107455
> gcc/
>   * postreload.cc (reload_cse_regs_1): Take advantage of conditional
>   equivalences.
>
> gcc/testsuite
>   * gcc.target/riscv/pr107455-1.c: New test.
>   * gcc.target/riscv/pr107455-2.c: New test.
>
> diff --git a/gcc/postreload.cc b/gcc/postreload.cc
> index a220001ef16..01f79898a4a 100644
> --- a/gcc/postreload.cc
> +++ b/gcc/postreload.cc
> @@ -33,6 +33,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "emit-rtl.h"
>  #include "recog.h"
>  
> +#include "cfghooks.h"
>  #include "cfgrtl.h"
>  #include "cfgbuild.h"
>  #include "cfgcleanup.h"
> @@ -221,13 +222,116 @@ reload_cse_regs_1 (void)
>init_alias_analysis ();
>  
>FOR_EACH_BB_FN (bb, cfun)
> -FOR_BB_INSNS (bb, insn)
> -  {
> - if (INSN_P (insn))
> -   cfg_changed |= reload_cse_simplify (insn, testreg);
> +{
> +  /* If BB has a small number of predecessors, see if each of the
> +  has the same implicit set.  If so, record that implicit set so
> +  that we can add it to the cselib tables.  */
> +  rtx_insn *implicit_set;
>  
> - cselib_process_insn (insn);
> -  }
> +  implicit_set = NULL;
> +  if (EDGE_COUNT (bb->preds) <= 3)
> + {
> +   edge e;
> +   edge_iterator ei;
> +   rtx src = NULL_RTX;
> +   rtx dest = NULL_RTX;
> +
> +   /* Iterate over each incoming edge and see if they
> +  all have the same implicit set.  */
> +   FOR_EACH_EDGE (e, ei, bb->preds)
> + {
> +   /* If the predecessor does not end in a conditional
> +  jump, then it does not have an implicit set.  */
> +   if (e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun)
> +   || !block_ends_with_condjump_p (e->src))

AFAICT, this is directly equivalent to:

  any_condjump_p (BB_END (e->src))

as checked below, so I think we should just check that (trusting
that BB_END is nonnull if e->src isn't the entry block).  In particular...

> + break;
> +
> +   /* We know the predecessor ends with a conditional
> +  jump.  Now dig into the actal form of the jump
> +  to potentially extract an implicit set.  */
> +   rtx_insn *condjump = BB_END (e->src);
> +   if (!condjump
> +   || ! any_condjump_p (condjump)
> +   || ! onlyjump_p (condjump))
> + break;

...the onlyjump_p doesn't seem necessary given the later reg_set_p.
Instead we can use...

> +
> +   /* This predecessor ends with a possible equivalence
> +  producing conditional branch.  Extract the condition
> +  and try to use it to create an equivalence.  */
> +   rtx pat = single_set (condjump);

...pc_set instead of single_set here.

> +   rtx i_t_e = SET_SRC (pat);
> +   gcc_assert (GET_CODE (i_t_e) == IF_THEN_ELSE);
> +   rtx cond = XEXP (i_t_e, 0);
> +   if ((GET_CODE (cond) == EQ
> +&& GET_CODE (XEXP (i_t_e, 1)) == LABEL_REF
> +&& XEXP (XEXP (i_t_e, 1), 0) == BB_HEAD (bb))
> +   || (GET_CODE (cond) == NE
> +   && XEXP (i_t_e, 2) == pc_rtx
> +   && e->src->next_bb == bb))

How about using:

  if (((e->flags & EDGE_FALLTHRU) != 0)
  == (XEXP (i_t_e, 1) == pc_rtx)
  ? GET_CODE (cond) == EQ
  : GET_CODE (cond) == NE)

(borrowing a construct from cfgcleanup.cc).  That seems more general,
s

Re: [PATCH] COBOL 1/8 hdr: header files

2025-01-03 Thread Jakub Jelinek
On Fri, Jan 03, 2025 at 12:03:06PM -0600, Robert Dubner wrote:
> > As has been noted, wide_int can be used for large integer arithmetic
> > within the compiler.  
> 
> My needs are modest; we use __int128 in only a few places in the host
> code.  If __int128 were supported by 32-bit GCC, we'd wouldn't be having
> this conversation.
> 
> But since __int128 isn't available, what I need is a drop-in replacement
> for __int128.  What I don't see, yet, is how to use wide_int as a such a
> replacement.
> 
> So, for example, in code that runs on the host I'll convert a string of
> numerals to __int128 by doing something like
> 
> __int128 value = 0;
> while(*p)
>   {
>   value = 10*value + *p++ & 0x0F;
>   }
> 
> And when I need to go back to a string, the loop likes like
>   {
>   ch = value % 10 + '0';
>   value /= 10;
>   }
> 
> If I could be pointed to a place to see how that's done, well, it'll save
> me a lot of looking through the existing code.

wide_int is compiler internal type, so it can handle all cases where you
need to evaluate something 128-bit (or any other precision up to right now
65534 bits) at compile time.
If you want to see e.g. parsing of strings into wide_int/widest_int, you
can look at the BITINT code in c-family/c-lex.cc (interpret_integer)
which handles parsing of decimal, octal, binary and hexadecimal large
numbers (e.g. to parse C23
123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb
and similar numbers).
Printing of wide_int into strings can be done in various ways,
e.g. using wide-int-print.cc APIs, or pp_printf with %wd/%wx etc.

But, if you need to do 128-bit or larger precision computations at runtime,
you really need some supported type with ABI support on the targets etc.
(currently e.g. int128_type_node on some targets or BITINT_TYPE with 128-bit
precision on even fewer targets can do), or e.g. lower it in the FE into say
pair of 64-bit integers (long long) which are supported everywhere; but then
you need to take care of lowering all the needed arithmetics in the FE and
decide in the FE also how it is passed, either as two long longs, or struct
containing those, or array containing those, ...

> 
> > For floating-point arithmetic, there are the
> > interfaces in real.h to handle floating point within GCC's internal
> > representation (note that some of the operations might leave a result
> with
> > extra internal precision; see how fold-const.cc:const_binop calls
> > real_arithmetic followed by real_convert to ensure correct rounding to
> the
> > desired format, for example).
> 
> Again, I am not sure we're talking about the same thing.  We have host
> code that uses _Float128 values. That's because there are COBOL compiler
> directives that need floating point values that can be bigger than IEEE
> binary64.  And the COBOL programmer can create source code like
> 
> 77 float-val USAGE FLOAT-BINARY-128 VALUE 1234.56789 .

Again, the question is if it needs to be supported everywhere, or just error
out on targets which don't have _Float128 (note, there are even targets
which don't support _Float32 and _Float64, e.g. pdp11/vax); and if the
support is only needed at compile time or at runtime too.
real.{h,cc} can support IEEE-like precisions and exponents in larger range
than binary128, I think often something like 160 bits precision.
But if one needs runtime support and especially libm functions, one needs
ABI for that and hw and/or library support.
_Float128 support isn't limited to lp64 targets (unlike __int128; which
needs right now lp64 support with the exception of amdgcn I think), but
still not supported on too many of them (and on various including x86
it is a software emulation rather than hw support).

Jakub



Re: [PATCH] tree-ssa-dce: Punt on allocations with too large constant sizes [PR118224]

2025-01-03 Thread Richard Biener



> Am 03.01.2025 um 22:48 schrieb Jakub Jelinek :
> 
> Hi!
> 
> As suggested by Richi in the PR, the following patch will fail to DCE
> allocation calls if they have constant size which is too large (over
> PTRDIFF_MAX), or for the case of calloc, if either of the arguments
> is too large (in that case in theory the call could succeed if the other
> argument is variable zero but who cares) or if both are constant and
> their product overflows or is above PTRDIFF_MAX.
> 
> This will make some pedantic conformance tests happy, though if one
> hides the size one will still need to use -fno-malloc-dce or obfuscate even
> the malloc etc. uses.  If the size is constant and too large, it isn't worth
> trying to optimize it.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok

Thanks,
Richard 

> 2025-01-03  Jakub Jelinek  
> 
>PR tree-optimization/118224
>* tree-ssa-dce.cc (is_removable_allocation_p): Don't return true
>for allocations with constant size argument larger than PTRDIFF_MAX
>or for calloc with one of the arguments constant larger than
>PTRDIFF_MAX or their product known constant above PTRDIFF_MAX.
>Fix comment typos, furhter -> further and then -> than.
>* lto-section-in.cc (lto_free_function_in_decl_state_for_node):
>Fix comment typo, furhter -> further.
> 
>* gcc.dg/pr118224.c: New test.
>* c-c++-common/ubsan/vla-1.c (bar): Use noipa attribute instead
>of noinline, noclone.
> 
> --- gcc/tree-ssa-dce.cc.jj2025-01-02 11:23:26.890372040 +0100
> +++ gcc/tree-ssa-dce.cc2025-01-03 20:01:33.074172650 +0100
> @@ -243,38 +243,101 @@ mark_operand_necessary (tree op)
> 
> /* Return true if STMT is a call to allocation function that can be
>optimized out if the memory block is never used for anything else
> -   then NULL pointer check or free.
> -   If NON_NULL_CHECK is false, we can furhter assume that return value
> -   is never checked to be non-NULL. */
> +   than NULL pointer check or free.
> +   If NON_NULL_CHECK is false, we can further assume that return value
> +   is never checked to be non-NULL.
> +   Don't return true if it is called with constant size (or sizes for calloc)
> +   and the size is excessively large (larger than PTRDIFF_MAX, for calloc
> +   either argument larger than PTRDIFF_MAX or both constant and their product
> +   larger than PTRDIFF_MAX).  */
> 
> static bool
> is_removable_allocation_p (gcall *stmt, bool non_null_check)
> {
> -  tree callee = gimple_call_fndecl (stmt);
> +  int arg = -1;
> +  tree callee = gimple_call_fndecl (stmt), a1, a2;
>   if (callee != NULL_TREE
>   && fndecl_built_in_p (callee, BUILT_IN_NORMAL))
> switch (DECL_FUNCTION_CODE (callee))
>   {
>   case BUILT_IN_MALLOC:
> +arg = 1;
> +goto do_malloc;
>   case BUILT_IN_ALIGNED_ALLOC:
> +arg = 2;
> +goto do_malloc;
>   case BUILT_IN_CALLOC:
> +arg = 3;
> +goto do_malloc;
>   CASE_BUILT_IN_ALLOCA:
> +arg = 1;
> +goto do_malloc;
>   case BUILT_IN_STRDUP:
>   case BUILT_IN_STRNDUP:
> -return non_null_check ? flag_malloc_dce > 1 : flag_malloc_dce;
> +arg = 0;
> +/* FALLTHRU */
> +  do_malloc:
> +if (non_null_check)
> +  {
> +if (flag_malloc_dce <= 1)
> +  return false;
> +  }
> +else if (!flag_malloc_dce)
> +  return false;
> +break;
> 
>   case BUILT_IN_GOMP_ALLOC:
> -return true;
> +arg = 2;
> +break;
> 
>   default:;
>   }
> 
> -  if (callee != NULL_TREE
> +  if (arg == -1
> +  && callee != NULL_TREE
>   && flag_allocation_dce
>   && gimple_call_from_new_or_delete (stmt)
>   && DECL_IS_REPLACEABLE_OPERATOR_NEW_P (callee))
> -return true;
> -  return false;
> +arg = 1;
> +
> +  switch (arg)
> +{
> +case -1:
> +  return false;
> +case 0:
> +  return true;
> +case 1:
> +case 2:
> +  if (gimple_call_num_args (stmt) < (unsigned) arg)
> +return false;
> +  a1 = gimple_call_arg (stmt, arg - 1);
> +  if (tree_fits_uhwi_p (a1)
> +  && (tree_to_uhwi (a1)
> +  > tree_to_uhwi (TYPE_MAX_VALUE (ptrdiff_type_node
> +return false;
> +  return true;
> +case 3:
> +  if (gimple_call_num_args (stmt) < 2)
> +return false;
> +  a1 = gimple_call_arg (stmt, 0);
> +  a2 = gimple_call_arg (stmt, 1);
> +  if (tree_fits_uhwi_p (a1)
> +  && (tree_to_uhwi (a1)
> +  > tree_to_uhwi (TYPE_MAX_VALUE (ptrdiff_type_node
> +return false;
> +  if (tree_fits_uhwi_p (a2)
> +  && (tree_to_uhwi (a2)
> +  > tree_to_uhwi (TYPE_MAX_VALUE (ptrdiff_type_node
> +return false;
> +  if (TREE_CODE (a1) == INTEGER_CST
> +  && TREE_CODE (a2) == INTEGER_CST
> +  && (wi::to_widest (a1) + wi::to_widest (a2)
> +  > tree_to_uhwi (TYPE_MAX_VALUE (ptrdiff_type_node
> +return false;
> +  return true;
> +default:
> +  gcc_unreachable ();
> +}