Re: [PATCH] rs6000: Fix cpu selection w/ isel (PR100108)

2022-01-11 Thread Sebastian Huber

Hello Segher,

On 20/04/2021 17:00, Segher Boessenkool wrote:

There are various non-IBM CPUs with isel as well, so it is easiest if we
just don't consider that flag here (it is not needed).

2021-04-20  Segher Boessenkool

PR target/100108
* config/rs6000/rs6000.c (rs6000_machine_from_flags): Do not consider
OPTION_MASK_ISEL.
---
Committed to trunk and 11.  Will do 10 in a week or so.


sorry for the late response, however, I noticed a GCC build issue with 
this patch:


/tmp/sh/b-gcc-powerpc-rtems6/./gcc/xgcc 
-B/tmp/sh/b-gcc-powerpc-rtems6/./gcc/ -nostdinc 
-B/tmp/sh/b-gcc-powerpc-rtems6/powerpc-rtems6/m8540/nof/newlib/ -isystem 
/tmp/sh/b-gcc-powerpc-rtems6/powerpc-rtems6/m8540/nof/newlib/targ-include -isystem 
/home/EB/sebastian_h/src/gcc/newlib/libc/include 
-B/tmp/sh/i-powerpc-rtems6/powerpc-rtems6/bin/ 
-B/tmp/sh/i-powerpc-rtems6/powerpc-rtems6/lib/ -isystem 
/tmp/sh/i-powerpc-rtems6/powerpc-rtems6/include -isystem 
/tmp/sh/i-powerpc-rtems6/powerpc-rtems6/sys-include  -mcpu=8540 
-msoft-float -g -O2 -O2 
-I/home/EB/sebastian_h/src/gcc/libgcc/../newlib/libc/sys/rtems/include 
-g -O2 -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE  -W -Wall -Wno-narrowing 
-Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes 
-Wold-style-definition  -isystem ./include   -g -DIN_LIBGCC2 
-fbuilding-libgcc -fno-stack-protector -Dinhibit_libc  -I. -I. 
-I../../../.././gcc -I/home/EB/sebastian_h/src/gcc/libgcc 
-I/home/EB/sebastian_h/src/gcc/libgcc/. 
-I/home/EB/sebastian_h/src/gcc/libgcc/../gcc 
-I/home/EB/sebastian_h/src/gcc/libgcc/../include  -DHAVE_CC_TLS  -o 
_negvdi2.o -MT _negvdi2.o -MD -MP -MF _negvdi2.dep -DL_negvdi2 -c 
/home/EB/sebastian_h/src/gcc/libgcc/libgcc2.c -fvisibility=hidden 
-DHIDE_EXPORTS

/tmp/ccZJ18fW.s: Assembler messages:
/tmp/ccZJ18fW.s:24: Error: unrecognized opcode: `isel'
make: *** [Makefile:501: _negvdi2.o] Error 1

The assembler is called like this:

/tmp/sh/b-gcc-powerpc-rtems6/./gcc/as -I 
/home/EB/sebastian_h/src/gcc/libgcc/../newlib/libc/sys/rtems/include -I 
. -I . -I ../../../.././gcc -I /home/EB/sebastian_h/src/gcc/libgcc -I 
/home/EB/sebastian_h/src/gcc/libgcc/. -I 
/home/EB/sebastian_h/src/gcc/libgcc/../gcc -I 
/home/EB/sebastian_h/src/gcc/libgcc/../include -a32 -me500 -mbig -o 
_negvdi2.o _negvdi2.s


Using -me500 seems to be all right, however, the file contains a machine 
directive:


.file   "libgcc2.c"
.machine ppc
.section".text"

If I remove the ".machine ppc" by hand, the file can be assembled with 
the above command line.


The affect of the patch is:

diff -u _negvdi2.s.before _negvdi2.s.after
--- _negvdi2.s.before   2022-01-11 09:07:43.313828636 +0100
+++ _negvdi2.s.after2022-01-11 08:54:08.424946502 +0100
@@ -1,5 +1,5 @@
.file   "libgcc2.c"
-   .machine power9
+   .machine ppc
.section".text"
 .Ltext0:
.align 2


--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.hu...@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/


Re: [PATCH 5/6] ira: Consider modelling caller-save allocations as loop spills

2022-01-11 Thread Robin Dapp via Gcc-patches
Hi Richard,

this causes a bootstrap error on s390 (where
IRA_HARD_REGNO_ADD_COST_MULTIPLIER is defined). rclass is used in the
#define-guarded area.  I guess you also wanted to move this to the new
function ira_caller_save_cost?

Regards
 Robin

--

../../gcc/ira-costs.c: In function ‘void ira_tune_allocno_costs()’:
../../gcc/ira-costs.c:2354:45: error: ‘rclass’ was not declared in this
scope; did you mean ‘aclass’?
 2354 |cost += ((ira_memory_move_cost[mode][rclass][0]
  | ^~
  | aclass


Re: [PATCH 5/6] ira: Consider modelling caller-save allocations as loop spills

2022-01-11 Thread Richard Sandiford via Gcc-patches
Robin Dapp  writes:
> Hi Richard,
>
> this causes a bootstrap error on s390 (where
> IRA_HARD_REGNO_ADD_COST_MULTIPLIER is defined). rclass is used in the
> #define-guarded area.

Gah, sorry about that.

> I guess you also wanted to move this to the new function
> ira_caller_save_cost?

No, the IRA_HARD_REGNO_ADD_COST_MULTIPLIER heuristic is a separate thing.
It's just that I had to remove the rclass variable to allow bootstrap on
other targets.

Could you try the attached?

Thanks,
Richard


>From 74cca9d27da840dbb79aa9ed9edc6f529945d477 Mon Sep 17 00:00:00 2001
From: Richard Sandiford 
Date: Tue, 11 Jan 2022 08:44:56 +
Subject: [PATCH] ira: Fix s390 build

My g:01f3e6a40e7202310abbeb41c345d325bd69554f broke the s390
build because the rclass variable was still needed by the
IRA_HARD_REGNO_ADD_COST_MULTIPLIER code.

gcc/
	* ira-costs.c (ira_tune_allocno_costs): Fix missing rclass
	definition in IRA_HARD_REGNO_ADD_COST_MULTIPLIER code.
---
 gcc/ira-costs.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/gcc/ira-costs.c b/gcc/ira-costs.c
index cbb58d32be8..1e4cf5a35e4 100644
--- a/gcc/ira-costs.c
+++ b/gcc/ira-costs.c
@@ -2351,10 +2351,13 @@ ira_tune_allocno_costs (void)
 	  if (ira_need_caller_save_p (a, regno))
 		cost += ira_caller_save_cost (a);
 #ifdef IRA_HARD_REGNO_ADD_COST_MULTIPLIER
-	  cost += ((ira_memory_move_cost[mode][rclass][0]
-			+ ira_memory_move_cost[mode][rclass][1])
-		   * ALLOCNO_FREQ (a)
-		   * IRA_HARD_REGNO_ADD_COST_MULTIPLIER (regno) / 2);
+	  {
+		auto rclass = REGNO_REG_CLASS (regno);
+		cost += ((ira_memory_move_cost[mode][rclass][0]
+			  + ira_memory_move_cost[mode][rclass][1])
+			 * ALLOCNO_FREQ (a)
+			 * IRA_HARD_REGNO_ADD_COST_MULTIPLIER (regno) / 2);
+	  }
 #endif
 	  if (INT_MAX - cost < reg_costs[j])
 		reg_costs[j] = INT_MAX;
-- 
2.25.1



[PATCH v6 0/4] __builtin_dynamic_object_size

2022-01-11 Thread Siddhesh Poyarekar
This patchset enhances the __builtin_dynamic_object_size builtin to
produce dynamic expressions for object sizes to improve coverage of
_FORTIFY_SOURCE.

Testing:


This series has been tested with build and test for i686, bootstrap with
ubsan and bootstrap+test with x86_64.

Additional testing plans (i.e. I've already started to do some of this):

- Build packages to compare values returned by __builtin_object_size
  with the older pass and this new one.  Also compare with
  __builtin_dynamic_object_size.

- Expand the list of packages to get more coverage metrics.

- Explore performance impact on applications on building with
  _FORTIFY_SOURCE=3.

Changes from v5:
- Address review comments
- Add a couple more tests for object sizes of pointers passed as
  parameters.

Siddhesh Poyarekar (4):
  tree-object-size: Support dynamic sizes in conditions
  tree-object-size: Handle function parameters
  tree-object-size: Handle GIMPLE_CALL
  tree-object-size: Dynamic sizes for ADDR_EXPR

 gcc/builtins.c|   6 +-
 .../gcc.dg/builtin-dynamic-object-size-0.c| 514 +
 .../gcc.dg/builtin-dynamic-object-size-10.c   |   2 +
 .../builtin-dynamic-object-size-5-main.c  |  32 +
 .../gcc.dg/builtin-dynamic-object-size-5.c|   7 +-
 gcc/testsuite/gcc.dg/builtin-object-size-1.c  | 154 +++-
 gcc/testsuite/gcc.dg/builtin-object-size-2.c  | 133 
 gcc/testsuite/gcc.dg/builtin-object-size-3.c  | 151 
 gcc/testsuite/gcc.dg/builtin-object-size-4.c  |  93 +++
 gcc/testsuite/gcc.dg/builtin-object-size-5.c  |  22 +-
 gcc/tree-object-size.c| 689 +++---
 11 files changed, 1712 insertions(+), 91 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-dynamic-object-size-5-main.c

-- 
2.33.1



[PATCH v6 2/4] tree-object-size: Handle function parameters

2022-01-11 Thread Siddhesh Poyarekar
Handle hints provided by __attribute__ ((access (...))) to compute
dynamic sizes for objects.

gcc/ChangeLog:

* tree-object-size.c: Include tree-dfa.h.
(parm_object_size): New function.
(collect_object_sizes_for): Call it.

gcc/testsuite/ChangeLog:

* gcc.dg/builtin-dynamic-object-size-0.c (test_parmsz_simple,
test_parmsz_scaled, test_parmsz_unknown): New functions.
(main): Call them.  Add new arguments argc and argv.

Signed-off-by: Siddhesh Poyarekar 
---
 .../gcc.dg/builtin-dynamic-object-size-0.c| 35 +++-
 gcc/tree-object-size.c| 54 ++-
 2 files changed, 87 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c 
b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
index b1013e19fd0..c89e2268943 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
@@ -34,6 +34,30 @@ test_deploop (size_t sz, size_t cond)
   return __builtin_dynamic_object_size (bin, 0);
 }
 
+size_t
+__attribute__ ((access (__read_write__, 1, 2)))
+__attribute__ ((noinline))
+test_parmsz_simple (void *obj, size_t sz)
+{
+  return __builtin_dynamic_object_size (obj, 0);
+}
+
+size_t
+__attribute__ ((access (__read_write__, 1, 2)))
+__attribute__ ((noinline))
+test_parmsz_scaled (int *obj, size_t sz)
+{
+  return __builtin_dynamic_object_size (obj, 0);
+}
+
+size_t
+__attribute__ ((access (__read_write__, 1, 3)))
+__attribute__ ((noinline))
+test_parmsz_unknown (void *obj, void *unknown, size_t sz, int cond)
+{
+  return __builtin_dynamic_object_size (cond ? obj : unknown, 0);
+}
+
 unsigned nfails = 0;
 
 #define FAIL() ({ \
@@ -42,7 +66,7 @@ unsigned nfails = 0;
 })
 
 int
-main ()
+main (int argc, char **argv)
 {
   if (test_builtin_malloc_condphi (1) != 32)
 FAIL ();
@@ -50,6 +74,15 @@ main ()
 FAIL ();
   if (test_deploop (128, 129) != 32)
 FAIL ();
+  if (test_parmsz_simple (argv[0], __builtin_strlen (argv[0]) + 1)
+  != __builtin_strlen (argv[0]) + 1)
+FAIL ();
+  int arr[42];
+  if (test_parmsz_scaled (arr, 42) != sizeof (arr))
+FAIL ();
+  if (test_parmsz_unknown (argv[0], argv[0], __builtin_strlen (argv[0]) + 1, 0)
+  != -1)
+FAIL ();
 
   if (nfails > 0)
 __builtin_abort ();
diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c
index 775792b4419..47e1c27bfd3 100644
--- a/gcc/tree-object-size.c
+++ b/gcc/tree-object-size.c
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-fold.h"
 #include "gimple-iterator.h"
 #include "tree-cfg.h"
+#include "tree-dfa.h"
 #include "stringpool.h"
 #include "attribs.h"
 #include "builtins.h"
@@ -1443,6 +1444,57 @@ cond_expr_object_size (struct object_size_info *osi, 
tree var, gimple *stmt)
   return reexamine;
 }
 
+/* Find size of an object passed as a parameter to the function.  */
+
+static void
+parm_object_size (struct object_size_info *osi, tree var)
+{
+  int object_size_type = osi->object_size_type;
+  tree parm = SSA_NAME_VAR (var);
+
+  if (!(object_size_type & OST_DYNAMIC) || !POINTER_TYPE_P (TREE_TYPE (parm)))
+{
+  expr_object_size (osi, var, parm);
+  return;
+}
+
+  /* Look for access attribute.  */
+  rdwr_map rdwr_idx;
+
+  tree fndecl = cfun->decl;
+  const attr_access *access = get_parm_access (rdwr_idx, parm, fndecl);
+  tree typesize = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (parm)));
+  tree sz = NULL_TREE;
+
+  if (access && access->sizarg != UINT_MAX)
+{
+  tree fnargs = DECL_ARGUMENTS (fndecl);
+  tree arg = NULL_TREE;
+  unsigned argpos = 0;
+
+  /* Walk through the parameters to pick the size parameter and safely
+scale it by the type size.  */
+  for (arg = fnargs; arg; arg = TREE_CHAIN (arg), ++argpos)
+   {
+ if (argpos == access->sizarg && INTEGRAL_TYPE_P (TREE_TYPE (arg)))
+   {
+ sz = get_or_create_ssa_default_def (cfun, arg);
+ if (sz != NULL_TREE)
+   {
+ sz = fold_convert (sizetype, sz);
+ if (typesize)
+   sz = size_binop (MULT_EXPR, sz, typesize);
+   }
+ break;
+   }
+   }
+}
+  if (!sz)
+sz = size_unknown (object_size_type);
+
+  object_sizes_set (osi, SSA_NAME_VERSION (var), sz, sz);
+}
+
 /* Compute an object size expression for VAR, which is the result of a PHI
node.  */
 
@@ -1620,7 +1672,7 @@ collect_object_sizes_for (struct object_size_info *osi, 
tree var)
 case GIMPLE_NOP:
   if (SSA_NAME_VAR (var)
  && TREE_CODE (SSA_NAME_VAR (var)) == PARM_DECL)
-   expr_object_size (osi, var, SSA_NAME_VAR (var));
+   parm_object_size (osi, var);
   else
/* Uninitialized SSA names point nowhere.  */
unknown_object_size (osi, var);
-- 
2.33.1



[PATCH v6 1/4] tree-object-size: Support dynamic sizes in conditions

2022-01-11 Thread Siddhesh Poyarekar
Handle GIMPLE_PHI and conditionals specially for dynamic objects,
returning PHI/conditional expressions instead of just a MIN/MAX
estimate.

This makes the returned object size variable for loops and conditionals,
so tests need to be adjusted to look for precise size in some cases.
builtin-dynamic-object-size-5.c had to be modified to only look for
success in maximum object size case and skip over the minimum object
size tests because the result is no longer a compile time constant.

I also added some simple tests to exercise conditionals with dynamic
object sizes.

gcc/ChangeLog:

* builtins.c (fold_builtin_object_size): Adjust for dynamic size
expressions.
* tree-object-size.c: Include gimplify-me.h.
(struct object_size_info): New member UNKNOWNS.
(size_initval_p, size_usable_p, object_sizes_get_raw): New
functions.
(object_sizes_get): Return suitable gimple variable for
object size.
(bundle_sizes): New function.
(object_sizes_set): Use it and handle dynamic object size
expressions.
(object_sizes_set_temp): New function.
(size_for_offset): Adjust for dynamic size expressions.
(emit_phi_nodes, propagate_unknowns, gimplify_size_expressions):
New functions.
(compute_builtin_object_size): Call gimplify_size_expressions
for OST_DYNAMIC.
(dynamic_object_size): New function.
(cond_expr_object_size): Use it.
(phi_dynamic_object_size): New function.
(collect_object_sizes_for): Call it for OST_DYNAMIC.  Adjust to
accommodate dynamic object sizes.

gcc/testsuite/ChangeLog:

* gcc.dg/builtin-dynamic-object-size-0.c: New tests.
* gcc.dg/builtin-dynamic-object-size-10.c: Add comment.
* gcc.dg/builtin-dynamic-object-size-5-main.c: New file.
* gcc.dg/builtin-dynamic-object-size-5.c: Use it and change test
to dg-do run.
* gcc.dg/builtin-object-size-5.c [!N]: Define N.
(test1, test2, test3, test4) [__builtin_object_size]: Expect
exact result for __builtin_dynamic_object_size.
* gcc.dg/builtin-object-size-1.c [__builtin_object_size]: Expect
exact size expressions for __builtin_dynamic_object_size.
* gcc.dg/builtin-object-size-2.c [__builtin_object_size]:
Likewise.
* gcc.dg/builtin-object-size-3.c [__builtin_object_size]:
Likewise.
* gcc.dg/builtin-object-size-4.c [__builtin_object_size]:
Likewise.
* gcc.dg/builtin-object-size-5.c [__builtin_object_size]:
Likewise.

Signed-off-by: Siddhesh Poyarekar 
---
 gcc/builtins.c|   6 +-
 .../gcc.dg/builtin-dynamic-object-size-0.c|  58 ++
 .../gcc.dg/builtin-dynamic-object-size-10.c   |   2 +
 .../builtin-dynamic-object-size-5-main.c  |  32 ++
 .../gcc.dg/builtin-dynamic-object-size-5.c|   7 +-
 gcc/testsuite/gcc.dg/builtin-object-size-1.c  | 119 +++-
 gcc/testsuite/gcc.dg/builtin-object-size-2.c  |  92 
 gcc/testsuite/gcc.dg/builtin-object-size-3.c  | 121 
 gcc/testsuite/gcc.dg/builtin-object-size-4.c  |  78 +++
 gcc/testsuite/gcc.dg/builtin-object-size-5.c  |  22 +-
 gcc/tree-object-size.c| 521 +-
 11 files changed, 1022 insertions(+), 36 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-dynamic-object-size-5-main.c

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 51d3635bd57..c780340ed32 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -10306,7 +10306,8 @@ fold_builtin_object_size (tree ptr, tree ost, enum 
built_in_function fcode)
   if (TREE_CODE (ptr) == ADDR_EXPR)
 {
   compute_builtin_object_size (ptr, object_size_type, &bytes);
-  if (int_fits_type_p (bytes, size_type_node))
+  if ((object_size_type & OST_DYNAMIC)
+ || int_fits_type_p (bytes, size_type_node))
return fold_convert (size_type_node, bytes);
 }
   else if (TREE_CODE (ptr) == SSA_NAME)
@@ -10315,7 +10316,8 @@ fold_builtin_object_size (tree ptr, tree ost, enum 
built_in_function fcode)
later.  Maybe subsequent passes will help determining
it.  */
   if (compute_builtin_object_size (ptr, object_size_type, &bytes)
- && int_fits_type_p (bytes, size_type_node))
+ && ((object_size_type & OST_DYNAMIC)
+ || int_fits_type_p (bytes, size_type_node)))
return fold_convert (size_type_node, bytes);
 }
 
diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c 
b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
new file mode 100644
index 000..b1013e19fd0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
@@ -0,0 +1,58 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+typedef __SIZE_TYPE__ size_t;
+#define abort __builtin_abort
+
+size_t
+__attribute__ ((noinline))
+test_builtin_malloc_condphi (

[PATCH v6 4/4] tree-object-size: Dynamic sizes for ADDR_EXPR

2022-01-11 Thread Siddhesh Poyarekar
Allow returning dynamic expressions from ADDR_EXPR for
__builtin_dynamic_object_size and also allow offsets to be dynamic.

gcc/ChangeLog:

* tree-object-size.c (size_valid_p): New function.
(size_for_offset): Remove OFFSET constness assertion.
(addr_object_size): Build dynamic expressions for object
sizes and use size_valid_p to decide if it is valid for the
given OBJECT_SIZE_TYPE.
(compute_builtin_object_size): Allow dynamic offsets when
computing size at O0.
(call_object_size): Call size_valid_p.
(plus_stmt_object_size): Allow non-constant offset and use
size_valid_p to decide if it is valid for the given
OBJECT_SIZE_TYPE.

gcc/testsuite/ChangeLog:

* gcc.dg/builtin-dynamic-object-size-0.c: Add new tests.
* gcc.dg/builtin-object-size-1.c (test1)
[__builtin_object_size]: Adjust expected output for dynamic
object sizes.
* gcc.dg/builtin-object-size-2.c (test1)
[__builtin_object_size]: Likewise.
* gcc.dg/builtin-object-size-3.c (test1)
[__builtin_object_size]: Likewise.
* gcc.dg/builtin-object-size-4.c (test1)
[__builtin_object_size]: Likewise.

Signed-off-by: Siddhesh Poyarekar 
---
 .../gcc.dg/builtin-dynamic-object-size-0.c| 156 ++
 gcc/testsuite/gcc.dg/builtin-object-size-1.c  |  30 +++-
 gcc/testsuite/gcc.dg/builtin-object-size-2.c  |  43 -
 gcc/testsuite/gcc.dg/builtin-object-size-3.c  |  25 ++-
 gcc/testsuite/gcc.dg/builtin-object-size-4.c  |  17 +-
 gcc/tree-object-size.c|  94 ++-
 6 files changed, 299 insertions(+), 66 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c 
b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
index 930fd49cd16..dd8dc99a580 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
@@ -250,6 +250,79 @@ test_deploop (size_t sz, size_t cond)
   return __builtin_dynamic_object_size (bin, 0);
 }
 
+/* Address expressions.  */
+
+struct dynarray_struct
+{
+  long a;
+  char c[16];
+  int b;
+};
+
+size_t
+__attribute__ ((noinline))
+test_dynarray_struct (size_t sz, size_t off)
+{
+  struct dynarray_struct bin[sz];
+
+  return __builtin_dynamic_object_size (&bin[off].c, 0);
+}
+
+size_t
+__attribute__ ((noinline))
+test_dynarray_struct_subobj (size_t sz, size_t off)
+{
+  struct dynarray_struct bin[sz];
+
+  return __builtin_dynamic_object_size (&bin[off].c[4], 1);
+}
+
+size_t
+__attribute__ ((noinline))
+test_dynarray_struct_subobj2 (size_t sz, size_t off, size_t *objsz)
+{
+  struct dynarray_struct2
+{
+  long a;
+  int b;
+  char c[sz];
+};
+
+  struct dynarray_struct2 bin;
+
+  *objsz = sizeof (bin);
+
+  return __builtin_dynamic_object_size (&bin.c[off], 1);
+}
+
+size_t
+__attribute__ ((noinline))
+test_substring (size_t sz, size_t off)
+{
+  char str[sz];
+
+  return __builtin_dynamic_object_size (&str[off], 0);
+}
+
+size_t
+__attribute__ ((noinline))
+test_substring_ptrplus (size_t sz, size_t off)
+{
+  int str[sz];
+
+  return __builtin_dynamic_object_size (str + off, 0);
+}
+
+size_t
+__attribute__ ((noinline))
+test_substring_ptrplus2 (size_t sz, size_t off, size_t off2)
+{
+  int str[sz];
+  int *ptr = &str[off];
+
+  return __builtin_dynamic_object_size (ptr + off2, 0);
+}
+
 size_t
 __attribute__ ((access (__read_write__, 1, 2)))
 __attribute__ ((noinline))
@@ -258,6 +331,14 @@ test_parmsz_simple (void *obj, size_t sz)
   return __builtin_dynamic_object_size (obj, 0);
 }
 
+size_t
+__attribute__ ((noinline))
+__attribute__ ((access (__read_write__, 1, 2)))
+test_parmsz (void *obj, size_t sz, size_t off)
+{
+  return __builtin_dynamic_object_size (obj + off, 0);
+}
+
 size_t
 __attribute__ ((access (__read_write__, 1, 2)))
 __attribute__ ((noinline))
@@ -266,6 +347,14 @@ test_parmsz_scaled (int *obj, size_t sz)
   return __builtin_dynamic_object_size (obj, 0);
 }
 
+size_t
+__attribute__ ((noinline))
+__attribute__ ((access (__read_write__, 1, 2)))
+test_parmsz_scaled_off (int *obj, size_t sz, size_t off)
+{
+  return __builtin_dynamic_object_size (obj + off, 0);
+}
+
 size_t
 __attribute__ ((access (__read_write__, 1, 3)))
 __attribute__ ((noinline))
@@ -274,6 +363,23 @@ test_parmsz_unknown (void *obj, void *unknown, size_t sz, 
int cond)
   return __builtin_dynamic_object_size (cond ? obj : unknown, 0);
 }
 
+size_t
+__attribute__ ((noinline))
+__attribute__ ((access (__read_write__, 1, 2)))
+test_loop (int *obj, size_t sz, size_t start, size_t end, int incr)
+{
+  int *ptr = obj + start;
+
+  for (int i = start; i != end; i = i + incr)
+{
+  ptr = ptr + incr;
+  if (__builtin_dynamic_object_size (ptr, 0) == 0)
+   return 0;
+}
+
+  return __builtin_dynamic_object_size (ptr, 0);
+}
+
 unsigned nfails = 0;
 
 #define FAIL() ({ \
@@ -333,6 +439,32 @@ main (int argc, char **argv)
 FAIL ();
   if (test_d

[PATCH v6 3/4] tree-object-size: Handle GIMPLE_CALL

2022-01-11 Thread Siddhesh Poyarekar
Handle non-constant expressions in GIMPLE_CALL arguments.  Also handle
alloca.

gcc/ChangeLog:

* tree-object-size.c (alloc_object_size): Make and return
non-constant size expression.
(call_object_size): Return expression or unknown based on
whether dynamic object size is requested.

gcc/testsuite/ChangeLog:

* gcc.dg/builtin-dynamic-object-size-0.c: Add new tests.
* gcc.dg/builtin-object-size-1.c (test1)
[__builtin_object_size]: Alter expected result for dynamic
object size.
* gcc.dg/builtin-object-size-2.c (test1)
[__builtin_object_size]: Likewise.
* gcc.dg/builtin-object-size-3.c (test1)
[__builtin_object_size]: Likewise.
* gcc.dg/builtin-object-size-4.c (test1)
[__builtin_object_size]: Likewise.

Signed-off-by: Siddhesh Poyarekar 
---
 .../gcc.dg/builtin-dynamic-object-size-0.c| 269 +-
 gcc/testsuite/gcc.dg/builtin-object-size-1.c  |   7 +
 gcc/testsuite/gcc.dg/builtin-object-size-2.c  |  14 +
 gcc/testsuite/gcc.dg/builtin-object-size-3.c  |   7 +
 gcc/testsuite/gcc.dg/builtin-object-size-4.c  |  14 +
 gcc/tree-object-size.c|  22 +-
 6 files changed, 325 insertions(+), 8 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c 
b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
index c89e2268943..930fd49cd16 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
@@ -4,6 +4,73 @@
 typedef __SIZE_TYPE__ size_t;
 #define abort __builtin_abort
 
+void *
+__attribute__ ((alloc_size (1)))
+__attribute__ ((__nothrow__ , __leaf__))
+__attribute__ ((noinline))
+alloc_func (size_t sz)
+{
+  return __builtin_malloc (sz);
+}
+
+void *
+__attribute__ ((alloc_size (1, 2)))
+__attribute__ ((__nothrow__ , __leaf__))
+__attribute__ ((noinline))
+calloc_func (size_t cnt, size_t sz)
+{
+  return __builtin_calloc (cnt, sz);
+}
+
+void *
+__attribute__ ((noinline))
+unknown_allocator (size_t cnt, size_t sz)
+{
+  return __builtin_calloc (cnt, sz);
+}
+
+size_t
+__attribute__ ((noinline))
+test_unknown (size_t cnt, size_t sz)
+{
+  void *ch = unknown_allocator (cnt, sz);
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+  __builtin_free (ch);
+  return ret;
+}
+
+/* Malloc-like allocator.  */
+
+size_t
+__attribute__ ((noinline))
+test_malloc (size_t sz)
+{
+  void *ch = alloc_func (sz);
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+  __builtin_free (ch);
+  return ret;
+}
+
+size_t
+__attribute__ ((noinline))
+test_builtin_malloc (size_t sz)
+{
+  void *ch = __builtin_malloc (sz);
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+  __builtin_free (ch);
+  return ret;
+}
+
+size_t
+__attribute__ ((noinline))
+test_builtin_malloc_cond (int cond)
+{
+  void *ch = __builtin_malloc (cond ? 32 : 64);
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+  __builtin_free (ch);
+  return ret;
+}
+
 size_t
 __attribute__ ((noinline))
 test_builtin_malloc_condphi (int cond)
@@ -21,6 +88,155 @@ test_builtin_malloc_condphi (int cond)
   return ret;
 }
 
+size_t
+__attribute__ ((noinline))
+test_builtin_malloc_condphi2 (int cond, size_t in)
+{
+  void *ch;
+
+  if (cond)
+ch = __builtin_malloc (in);
+  else
+ch = __builtin_malloc (64);
+
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+
+  __builtin_free (ch);
+  return ret;
+}
+
+size_t
+__attribute__ ((noinline))
+test_builtin_malloc_condphi3 (int cond, size_t in, size_t in2)
+{
+  void *ch;
+
+  if (cond)
+ch = __builtin_malloc (in);
+  else
+ch = __builtin_malloc (in2);
+
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+
+  __builtin_free (ch);
+  return ret;
+}
+
+size_t
+__attribute__ ((noinline))
+test_builtin_malloc_condphi4 (size_t sz, int cond)
+{
+  char *a = __builtin_malloc (sz);
+  char b[sz / 2];
+
+  size_t ret = __builtin_dynamic_object_size (cond ? b : (void *) &a, 0);
+  __builtin_free (a);
+  return ret;
+}
+
+size_t
+__attribute__ ((noinline))
+test_builtin_malloc_condphi5 (size_t sz, int cond, char *c)
+{
+  char *a = __builtin_malloc (sz);
+
+  size_t ret = __builtin_dynamic_object_size (cond ? c : (void *) &a, 0);
+  __builtin_free (a);
+  return ret;
+}
+
+/* Calloc-like allocator.  */
+
+size_t
+__attribute__ ((noinline))
+test_calloc (size_t cnt, size_t sz)
+{
+  void *ch = calloc_func (cnt, sz);
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+  __builtin_free (ch);
+  return ret;
+}
+
+size_t
+__attribute__ ((noinline))
+test_builtin_calloc (size_t cnt, size_t sz)
+{
+  void *ch = __builtin_calloc (cnt, sz);
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+  __builtin_free (ch);
+  return ret;
+}
+
+size_t
+__attribute__ ((noinline))
+test_builtin_calloc_cond (int cond1, int cond2)
+{
+  void *ch = __builtin_calloc (cond1 ? 32 : 64, cond2 ? 1024 : 16);
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+  __builtin_free (ch);
+  return re

Re: [PATCH] Check sorting of MAINTAINERS

2022-01-11 Thread Martin Liška

On 1/10/22 17:14, Martin Liška wrote:

Are you fine with the suggested changes?


Hello.

Jakub had comments so I'm sending v2 where I added few parsing
exceptions. Now it reports:

...
  Chandra Chavva
  Dehao Chen
- Fabien Chêne  
  Clément Chigot

  Harshit Chopra
  Tamar Christina   

  Eric Christopher  
+ Fabien Chêne  
  Paul Clarke   
  William Cohen 
  Michael Collison  
  Josh Conner   
  R. Kelley Cook
  Alex Coplan   
  Andrea Corallo
  Christian Cornelssen  
  Ludovic Courtès   
  Lawrence Crowl
  Ian Dall  
  David Daney   
  Robin Dapp
  Simon Dardis  
  Sudakshina Das
  Bud Davis 
  Chris Demetriou   
  Sameera Deshpande 
  Wilco Dijkstra
  Benoit Dupont de Dinechin 

  Jason Eckhardt
  Bernd Edlinger

  Phil Edwards  
  Mark Eggleston

  Steve Ellcey  
  Mohan Embar   
  Revital Eres  
  Marc Espie
  Ansgar Esztermann 

  Doug Evans
  Chris Fairles 
  Alessandro Fanfarillo 
  Changpeng Fang
  David Faust   
  Li Feng   
  Thomas Fitzsimmons
  Alexander Fomin   

  Brian Ford
  John Freeman  
  Nathan Froyd  
  Chao-ying Fu  
  Gary Funck
  Pompapathi V Gadad
  Eric Gallager 
  Gopalasubramanian Ganesh  

  Kaveh Ghazi   
  Doug Gilmore  
  Matthew Gingell   
  Jan-Benedict Glaw 
  Marc Glisse   
  Prachi Godbole

  Torbjorn Granlund 
  James Greenhalgh  
  Doug Gregor   
  Matthew Gretton-Dann  
  Yury Gribov   
  Jon Grimm 
  Laurent Guerby
  Haochen Gui   
  Jiufu Guo 
  Xuepeng Guo   
  Wei Guozhi
+ Naveen H.S
  Mostafa Hagog 
  Andrew Haley  
  Frederik Harwath  
  Stuart Hastings   
  Michael Haubenwallner 

  Pat Haugen
  Michael Hayes 
  Alan Hayward  
  Li Jia He 
  Mark Heffernan
  George Helffrich  
  Daniel Hellstrom  
  Fergus Henderson  
  Stuart Henderson  
  Marius Hillenbrand
  Matthew Hiller
  Kazu Hirata   
  Manfred Hollstein 
  Cong Hou  
  Falk Hueffner 
  Andrew John Hughes
  Dominique d'Humieres  
  Andy Hutchinson   
  Jo

Re: [PATCH] Check sorting of MAINTAINERS

2022-01-11 Thread Jakub Jelinek via Gcc-patches
On Tue, Jan 11, 2022 at 10:27:19AM +0100, Martin Liška wrote:
> On 1/10/22 17:14, Martin Liška wrote:
> > Are you fine with the suggested changes?
> 
> Hello.
> 
> Jakub had comments so I'm sending v2 where I added few parsing
> exceptions. Now it reports:

I'm still surprised by what the sort is doing,
( echo Chene; echo Chêne; echo Chfne ) | LC_ALL=en_US.UTF-8 sort
Chene
Chêne
Chfne
That is on glibc 2.32.  On glibc 2.34.9000 I get a different order though,
Chêne last.
That partly ruins the idea of the checking script when the sorting isn't
the same for many people, either the script will be failing for many people
or various people will be changing the order there and back all the time.

Jakub



Re: [PATCH v6 1/4] tree-object-size: Support dynamic sizes in conditions

2022-01-11 Thread Jakub Jelinek via Gcc-patches
On Tue, Jan 11, 2022 at 02:27:47PM +0530, Siddhesh Poyarekar wrote:
> Handle GIMPLE_PHI and conditionals specially for dynamic objects,
> returning PHI/conditional expressions instead of just a MIN/MAX
> estimate.
> 
> This makes the returned object size variable for loops and conditionals,
> so tests need to be adjusted to look for precise size in some cases.
> builtin-dynamic-object-size-5.c had to be modified to only look for
> success in maximum object size case and skip over the minimum object
> size tests because the result is no longer a compile time constant.
> 
> I also added some simple tests to exercise conditionals with dynamic
> object sizes.

Ok, but IMO please fix PR103961 first before committing this patchset.

> gcc/ChangeLog:
> 
>   * builtins.c (fold_builtin_object_size): Adjust for dynamic size
>   expressions.
>   * tree-object-size.c: Include gimplify-me.h.
>   (struct object_size_info): New member UNKNOWNS.
>   (size_initval_p, size_usable_p, object_sizes_get_raw): New
>   functions.
>   (object_sizes_get): Return suitable gimple variable for
>   object size.
>   (bundle_sizes): New function.
>   (object_sizes_set): Use it and handle dynamic object size
>   expressions.
>   (object_sizes_set_temp): New function.
>   (size_for_offset): Adjust for dynamic size expressions.
>   (emit_phi_nodes, propagate_unknowns, gimplify_size_expressions):
>   New functions.
>   (compute_builtin_object_size): Call gimplify_size_expressions
>   for OST_DYNAMIC.
>   (dynamic_object_size): New function.
>   (cond_expr_object_size): Use it.
>   (phi_dynamic_object_size): New function.
>   (collect_object_sizes_for): Call it for OST_DYNAMIC.  Adjust to
>   accommodate dynamic object sizes.
> 
> gcc/testsuite/ChangeLog:
> 
>   * gcc.dg/builtin-dynamic-object-size-0.c: New tests.
>   * gcc.dg/builtin-dynamic-object-size-10.c: Add comment.
>   * gcc.dg/builtin-dynamic-object-size-5-main.c: New file.
>   * gcc.dg/builtin-dynamic-object-size-5.c: Use it and change test
>   to dg-do run.
>   * gcc.dg/builtin-object-size-5.c [!N]: Define N.
>   (test1, test2, test3, test4) [__builtin_object_size]: Expect
>   exact result for __builtin_dynamic_object_size.
>   * gcc.dg/builtin-object-size-1.c [__builtin_object_size]: Expect
>   exact size expressions for __builtin_dynamic_object_size.
>   * gcc.dg/builtin-object-size-2.c [__builtin_object_size]:
>   Likewise.
>   * gcc.dg/builtin-object-size-3.c [__builtin_object_size]:
>   Likewise.
>   * gcc.dg/builtin-object-size-4.c [__builtin_object_size]:
>   Likewise.
>   * gcc.dg/builtin-object-size-5.c [__builtin_object_size]:
>   Likewise.

Jakub



Re: [PATCH v6 1/4] tree-object-size: Support dynamic sizes in conditions

2022-01-11 Thread Siddhesh Poyarekar

On 11/01/2022 15:13, Jakub Jelinek wrote:

On Tue, Jan 11, 2022 at 02:27:47PM +0530, Siddhesh Poyarekar wrote:

Handle GIMPLE_PHI and conditionals specially for dynamic objects,
returning PHI/conditional expressions instead of just a MIN/MAX
estimate.

This makes the returned object size variable for loops and conditionals,
so tests need to be adjusted to look for precise size in some cases.
builtin-dynamic-object-size-5.c had to be modified to only look for
success in maximum object size case and skip over the minimum object
size tests because the result is no longer a compile time constant.

I also added some simple tests to exercise conditionals with dynamic
object sizes.


Ok, but IMO please fix PR103961 first before committing this patchset.



+1, I'm on it right now.

Thanks,
Siddhesh


Re: [PATCH v6 2/4] tree-object-size: Handle function parameters

2022-01-11 Thread Jakub Jelinek via Gcc-patches
On Tue, Jan 11, 2022 at 02:27:48PM +0530, Siddhesh Poyarekar wrote:
> Handle hints provided by __attribute__ ((access (...))) to compute
> dynamic sizes for objects.
> 
> gcc/ChangeLog:
> 
>   * tree-object-size.c: Include tree-dfa.h.
>   (parm_object_size): New function.
>   (collect_object_sizes_for): Call it.
> 
> gcc/testsuite/ChangeLog:
> 
>   * gcc.dg/builtin-dynamic-object-size-0.c (test_parmsz_simple,
>   test_parmsz_scaled, test_parmsz_unknown): New functions.
>   (main): Call them.  Add new arguments argc and argv.
> 
> Signed-off-by: Siddhesh Poyarekar 
> +  /* Walk through the parameters to pick the size parameter and safely
> +  scale it by the type size.  */
> +  for (arg = fnargs; arg; arg = TREE_CHAIN (arg), ++argpos)
> + {
> +   if (argpos == access->sizarg && INTEGRAL_TYPE_P (TREE_TYPE (arg)))
> + {
> +   sz = get_or_create_ssa_default_def (cfun, arg);
> +   if (sz != NULL_TREE)
> + {
> +   sz = fold_convert (sizetype, sz);
> +   if (typesize)
> + sz = size_binop (MULT_EXPR, sz, typesize);
> + }
> +   break;
> + }
> + }

No need for those {}s around the if as body of for, just use
  for (arg = fnargs; arg; arg = TREE_CHAIN (arg), ++argpos)
if (argpos == access->sizarg && INTEGRAL_TYPE_P (TREE_TYPE (arg)))
  {
...
break;
  }

Ok with that change.

Jakub



Re: [PATCH] Check sorting of MAINTAINERS

2022-01-11 Thread Tobias Burnus

On 10.01.22 17:14, Martin Liška wrote:

Are you fine with the suggested changes?


I don't feel strong and having some automatic sorting is nice. But ut as
a human, I note:


+ Kris Van Hees 
- Dominique d'Humieres 


Sorting 'Van Hees' under 'H' and 'd'Humieres' under 'd' feels
inconsistent - I'd either expected both under 'H' or both under 'd'/'V'.

Currently "d'H" is under "H" and "Van H" under "V", with your patch
"d'H" is under "d" and "Van H" under "H".

But I admit that that's not clear and whether something like
de/von/van/Van is regarded as part of the family name for sorting or not
. (Not to talk about names like "Christophe Cartier Dit Moulin", which I
would sort under 'C(artier)'.)


  Christophe Lyon 
+ Manuel López-Ibáñez 
+ Martin v. Löwis 


Somehow it feels odd to have the accented version after 'z' – it feels
more natural just to ignore the accent and order 'ó' and 'ö' after 'o'
and not after 'z'.

Tobias

-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955


Re: [PATCH v6 4/4] tree-object-size: Dynamic sizes for ADDR_EXPR

2022-01-11 Thread Jakub Jelinek via Gcc-patches
On Tue, Jan 11, 2022 at 02:27:50PM +0530, Siddhesh Poyarekar wrote:
> Allow returning dynamic expressions from ADDR_EXPR for
> __builtin_dynamic_object_size and also allow offsets to be dynamic.
> 
> gcc/ChangeLog:
> 
>   * tree-object-size.c (size_valid_p): New function.
>   (size_for_offset): Remove OFFSET constness assertion.
>   (addr_object_size): Build dynamic expressions for object
>   sizes and use size_valid_p to decide if it is valid for the
>   given OBJECT_SIZE_TYPE.
>   (compute_builtin_object_size): Allow dynamic offsets when
>   computing size at O0.
>   (call_object_size): Call size_valid_p.
>   (plus_stmt_object_size): Allow non-constant offset and use
>   size_valid_p to decide if it is valid for the given
>   OBJECT_SIZE_TYPE.
> 
> gcc/testsuite/ChangeLog:
> 
>   * gcc.dg/builtin-dynamic-object-size-0.c: Add new tests.
>   * gcc.dg/builtin-object-size-1.c (test1)
>   [__builtin_object_size]: Adjust expected output for dynamic
>   object sizes.
>   * gcc.dg/builtin-object-size-2.c (test1)
>   [__builtin_object_size]: Likewise.
>   * gcc.dg/builtin-object-size-3.c (test1)
>   [__builtin_object_size]: Likewise.
>   * gcc.dg/builtin-object-size-4.c (test1)
>   [__builtin_object_size]: Likewise.

> +/* Return true if VAL is represents a valid size for OBJECT_SIZE_TYPE.  */

s/is / as in the other patch.

Otherwise LGTM.

Jakub



Re: [PATCH] Check sorting of MAINTAINERS

2022-01-11 Thread Martin Liška

On 1/11/22 10:45, Tobias Burnus wrote:

On 10.01.22 17:14, Martin Liška wrote:

Are you fine with the suggested changes?


I don't feel strong and having some automatic sorting is nice. But ut as
a human, I note:


+ Kris Van Hees 
- Dominique d'Humieres 


Sorting 'Van Hees' under 'H' and 'd'Humieres' under 'd' feels
inconsistent - I'd either expected both under 'H' or both under 'd'/'V'.


Well, I just respect how the authors feel to be sorted:
Van Hees - under 'V'
d'Humieres - under H



Currently "d'H" is under "H" and "Van H" under "V", with your patch
"d'H" is under "d" and "Van H" under "H".


I fixed that in the updated version, please take a look.



But I admit that that's not clear and whether something like
de/von/van/Van is regarded as part of the family name for sorting or not
. (Not to talk about names like "Christophe Cartier Dit Moulin", which I
would sort under 'C(artier)'.)


That's why I added a few exceptions in order to respect their wish.




  Christophe Lyon 
+ Manuel López-Ibáñez 
+ Martin v. Löwis 


Somehow it feels odd to have the accented version after 'z' – it feels
more natural just to ignore the accent and order 'ó' and 'ö' after 'o'
and not after 'z'.


That's what Jakub is speaking about, I was also surprised about the sorting.

Martin



Tobias

-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955




Re: [PATCH] Check sorting of MAINTAINERS

2022-01-11 Thread Martin Liška

On 1/11/22 10:38, Jakub Jelinek wrote:

That is on glibc 2.32.  On glibc 2.34.9000 I get a different order though,
Chêne last.


Heh, that's definitely surprising. Can you raise an issue against Glibc
so that we can discuss it?

Thanks,
Martin


Re: [PATCH] Check sorting of MAINTAINERS

2022-01-11 Thread Martin Liška

On 1/11/22 10:38, Jakub Jelinek wrote:

On Tue, Jan 11, 2022 at 10:27:19AM +0100, Martin Liška wrote:

On 1/10/22 17:14, Martin Liška wrote:

Are you fine with the suggested changes?


Hello.

Jakub had comments so I'm sending v2 where I added few parsing
exceptions. Now it reports:


I'm still surprised by what the sort is doing,
( echo Chene; echo Chêne; echo Chfne ) | LC_ALL=en_US.UTF-8 sort
Chene
Chêne
Chfne
That is on glibc 2.32.  On glibc 2.34.9000 I get a different order though,
Chêne last.
That partly ruins the idea of the checking script when the sorting isn't
the same for many people, either the script will be failing for many people
or various people will be changing the order there and back all the time.

Jakub



Or we can utilize https://pypi.org/project/Unidecode python package that 
provides:

In [7]: unidecode.unidecode('Jääskeläinen')
Out[7]: 'Jaaskelainen'

and sort it by that.

Martin


[patch] Fix reverse SSO issues in IPA-SRA

2022-01-11 Thread Eric Botcazou via Gcc-patches
Hi,

we recently received the report that the IPA-SRA pass introduced in GCC 10 
does not always play nice with the reverse scalar storage order that can be 
used in structures/records/unions.  Reading the code, the pass apparently 
correctly detects it but fails to propagate the information to the rewriting 
phase in some cases and, in particular, does not stream it for LTO.

The attached patch is a tentative fix for these issues spotted essentially by 
code reading.  It also contains various minor tweaks left and right.

Bootstrapped/regtested on x86-64/Linux, OK for mainline, 11 and 10 branches?


2022-01-11  Eric Botcazou  

* ipa-param-manipulation.c (ipa_dump_adjusted_parameters): Dump
reverse flag as "reverse" for the sake of consistency.
* ipa-sra.c: Fix copyright year.
(ipa_sra_function_summaries::duplicate): Copy the reverse flag.
(dump_isra_access): Remove confusing dump line.
(isra_write_node_summary): Write the reverse flag.
(isra_read_node_info): Read it.
(pull_accesses_from_callee): Copy it.

-- 
Eric Botcazoudiff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c
index 4973bfb67dd..fa6815e0941 100644
--- a/gcc/ipa-param-manipulation.c
+++ b/gcc/ipa-param-manipulation.c
@@ -228,7 +228,7 @@ ipa_dump_adjusted_parameters (FILE *f,
 	  fprintf (f, " prefix: %s",
 		   ipa_param_prefixes[apm->param_prefix_index]);
 	  if (apm->reverse)
-	fprintf (f, ", reverse-sso");
+	fprintf (f, ", reverse");
 	  break;
 	}
   fprintf (f, "\n");
diff --git a/gcc/ipa-sra.c b/gcc/ipa-sra.c
index 45030a17c07..c24812b971d 100644
--- a/gcc/ipa-sra.c
+++ b/gcc/ipa-sra.c
@@ -1,6 +1,5 @@
 /* Interprocedural scalar replacement of aggregates
-   Copyright (C) 2008-2022 Free Software Foundation, Inc.
-
+   Copyright (C) 2019-2022 Free Software Foundation, Inc.
Contributed by Martin Jambor 
 
 This file is part of GCC.
@@ -21,7 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 
 /* IPA-SRA is an interprocedural pass that removes unused function return
values (turning functions returning a value which is never used into void
-   functions), removes unused function parameters.  It can also replace an
+   functions) and removes unused function parameters.  It can also replace an
aggregate parameter by a set of other parameters representing part of the
original, turning those passed by reference into new ones which pass the
value directly.
@@ -57,7 +56,6 @@ along with GCC; see the file COPYING3.  If not see
ipa-param-manipulation.h for more details.  */
 
 
-
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
@@ -93,7 +91,7 @@ static void ipa_sra_summarize_function (cgraph_node *);
 #define ISRA_ARG_SIZE_LIMIT_BITS 16
 #define ISRA_ARG_SIZE_LIMIT (1 << ISRA_ARG_SIZE_LIMIT_BITS)
 /* How many parameters can feed into a call actual argument and still be
-   tracked. */
+   tracked.  */
 #define IPA_SRA_MAX_PARAM_FLOW_LEN 7
 
 /* Structure describing accesses to a specific portion of an aggregate
@@ -122,7 +120,7 @@ struct GTY(()) param_access
  transformed function - initially not set for portions of formal parameters
  that are only used as actual function arguments passed to callees.  */
   unsigned certain : 1;
-  /* Set if the access has a reversed scalar storage order.  */
+  /* Set if the access has reverse scalar storage order.  */
   unsigned reverse : 1;
 };
 
@@ -156,7 +154,7 @@ struct gensum_param_access
  arguments to a function call that can be tracked.  */
   bool nonarg;
 
-  /* Set if the access has a reversed scalar storage order.  */
+  /* Set if the access has reverse scalar storage order.  */
   bool reverse;
 };
 
@@ -219,8 +217,8 @@ struct gensum_param_desc
 };
 
 /* Properly deallocate accesses of DESC.  TODO: Since this data structure is
-   not in GC memory, this is not necessary and we can consider removing the
-   function.  */
+   allocated in GC memory, this is not necessary and we can consider removing
+   the function.  */
 
 static void
 free_param_decl_accesses (isra_param_desc *desc)
@@ -275,9 +273,9 @@ public:
   unsigned m_queued : 1;
 };
 
-/* Clean up and deallocate isra_func_summary points to.  TODO: Since this data
-   structure is not in GC memory, this is not necessary and we can consider
-   removing the destructor.  */
+/* Deallocate the memory pointed to by isra_func_summary.  TODO: Since this
+   data structure is allocated in GC memory, this is not necessary and we can
+   consider removing the destructor.  */
 
 isra_func_summary::~isra_func_summary ()
 {
@@ -287,7 +285,6 @@ isra_func_summary::~isra_func_summary ()
   vec_free (m_parameters);
 }
 
-
 /* Mark the function as not a candidate for any IPA-SRA transformation.  Return
true if it was a candidate until now.  */
 
@@ -297,6 +294,7 @@ isra_func_summary::zap ()
   bool ret = m_candidate;
   m_candidate = false;
 
+  /* TODO: see the destructor above.  */
   unsigned len 

Re: [PATCH, OpenMP, C/C++] Fix PR103705

2022-01-11 Thread Jakub Jelinek via Gcc-patches
On Mon, Jan 10, 2022 at 11:01:46PM +0800, Chung-Lin Tang wrote:
> Forgot to attach the patch, here it is :P
> 
> On 2022/1/10 10:59 PM, Chung-Lin Tang wrote:
> > For cases like:
> >    #pragma omp target update from(s[0].a[0:1])
> > 
> > The handling in [c_]finish_omp_clauses was only peeling off ARRAY_REF once
> > before the loop handling COMPONENT_REF, and snagged when the base of the
> > component_ref is an array access. This adds the handling there for both C
> > and C++ front-ends.
> > 
> > (ICE started to happen after 
> > https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=6c0399378e77d029
> > where map/from/to clause syntax was relaxed to allow more stuff)
> > 
> > Tested without regressions, okay to commit?
> > 
> > Thanks,
> > Chung-Lin
> > 
> >      PR c++/103705
> > 
> > gcc/c/ChangeLog:
> > 
> >      * c-typeck.c (c_finish_omp_clauses): Also continue peeling off of
> >      outer node for ARRAY_REFs.
> > 
> > gcc/cp/ChangeLog:
> > 
> >      * semantics.c (finish_omp_clauses): Also continue peeling off of
> >      outer node for ARRAY_REFs.
> > 
> > gcc/testsuite/ChangeLog:
> > 
> >  * c-c++-common/gomp/pr103705.c: New test.

Ok, thanks.

Jakub



Re: [PATCH] Add VxWorks fixincludes hack, open posix API

2022-01-11 Thread Olivier Hainque via Gcc-patches
Hi Rasmus,

> On 17 Dec 2021, at 13:49, Rasmus Villemoes  wrote:
> 
> In the end, we ended up adding a two-argument overload for C++ only, as
> this is/was only relevant for getting libstdc++ (more specifically, the
> new filesystem abstraction stuff) to build. That is, we added
> 
> +#if __GNUC__ > 6 && defined(__cplusplus)
> +extern "C++" {
> +extern int  open (const char *name, int flags);
> +}
> +#endif
> +
> 
> to fcntl.h, and added a trivial definition of that (which calls the
> tree-argument form with a 0 for mode) to the OS build. I guess it could
> also have been an inline.

I experimented with the inline track (patch attached) and we're
having good results with it. It builds and test results we get
are on par with those we had with the varargs approach.

Works better for you?  Thanks again for raising the point.

Cheers,

Olivier


2021-01-10  Olivier Hainque  
Rasmus Villemoes  

* inclhack.def (vxworks_posix_open): New hack.
* tests/base/fcntl.h: Update.
* fixincl.x: Regenerate.



0003-Add-VxWorks-fixincludes-hack-open-posix-API.patch
Description: Binary data


Re: [PATCH 5/6] ira: Consider modelling caller-save allocations as loop spills

2022-01-11 Thread Robin Dapp via Gcc-patches
Hi Richard,

> Could you try the attached?

build and bootstrap look OK with it.  Testsuite shows lots of fallout
but the proper bisect isn't finished yet.  The commit before your series
is still fine - the problem could also be after it, though.  Will report
back later.

Thanks
 Robin


Re: [PATCH] C, C++, Fortran, OpenMP: Add 'has_device_addr' clause to 'target' construct

2022-01-11 Thread Jakub Jelinek via Gcc-patches
On Wed, Nov 24, 2021 at 06:08:02PM +0100, Marcel Vollweiler wrote:
> + case OMP_CLAUSE_HAS_DEVICE_ADDR:
> +   t = OMP_CLAUSE_DECL (c);
> +   if (TREE_CODE (t) == TREE_LIST)
> + {
> +   if (handle_omp_array_sections (c, ort))
> + remove = true;
> +   else
> + {
> +   t = OMP_CLAUSE_DECL (c);
> +   while (TREE_CODE (t) == ARRAY_REF)
> + t = TREE_OPERAND (t, 0);
> + }
> + }
> +   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
> + bitmap_set_bit (&is_on_device_head, DECL_UID (t));

Why the OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR check?
There is no goto into this block nor fallthru into it, and
handle_omp_array_sections better shouldn't change OMP_CLAUSE_CODE.

> goto check_dup_generic;
>  
> + case OMP_CLAUSE_HAS_DEVICE_ADDR:
> +   t = OMP_CLAUSE_DECL (c);
> +   if (TREE_CODE (t) == TREE_LIST)
> + if (handle_omp_array_sections (c, ort))
> +   remove = true;
> + else
> +   {
> + t = OMP_CLAUSE_DECL (c);
> + while (TREE_CODE (t) == ARRAY_REF)
> +   t = TREE_OPERAND (t, 0);
> +   }
> +   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
> + bitmap_set_bit (&is_on_device_head, DECL_UID (t));

Likewise.

> +   if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
> + cxx_mark_addressable (t);
> +   goto check_dup_generic_t;
> +
>   case OMP_CLAUSE_USE_DEVICE_ADDR:
> field_ok = true;
> t = OMP_CLAUSE_DECL (c);

> --- a/gcc/fortran/gfortran.h
> +++ b/gcc/fortran/gfortran.h
> @@ -1391,7 +1391,8 @@ enum
>OMP_LIST_USE_DEVICE_PTR,
>OMP_LIST_USE_DEVICE_ADDR,
>OMP_LIST_NONTEMPORAL,
> -  OMP_LIST_NUM
> +  OMP_LIST_HAS_DEVICE_ADDR,
> +  OMP_LIST_NUM  /* must be the last  */

Capital M and . at the end.

> @@ -2077,6 +2078,12 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const 
> omp_mask mask,
>   }
> break;
>   case 'h':
> +   if ((mask & OMP_CLAUSE_HAS_DEVICE_ADDR)
> +   && gfc_match_omp_variable_list
> +("has_device_addr (",
> + &c->lists[OMP_LIST_HAS_DEVICE_ADDR], false, NULL, NULL,
> +  true) == MATCH_YES)

Formatting, true should be IMO below &c->lists.

> + continue;
> if ((mask & OMP_CLAUSE_HINT)
> && (m = gfc_match_dupl_check (!c->hint, "hint", true, &c->hint))
>!= MATCH_NO)
> @@ -2850,7 +2857,8 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const 
> omp_mask mask,
> if ((mask & OMP_CLAUSE_USE_DEVICE_ADDR)
> && gfc_match_omp_variable_list
>  ("use_device_addr (",
> - &c->lists[OMP_LIST_USE_DEVICE_ADDR], false) == MATCH_YES)
> + &c->lists[OMP_LIST_USE_DEVICE_ADDR], false, NULL, NULL,
> +  true) == MATCH_YES)

Likewise.

> --- a/gcc/fortran/trans-openmp.c
> +++ b/gcc/fortran/trans-openmp.c
> @@ -1910,7 +1910,17 @@ gfc_trans_omp_variable_list (enum omp_clause_code code,
>   tree t = gfc_trans_omp_variable (namelist->sym, declare_simd);
>   if (t != error_mark_node)
> {
> - tree node = build_omp_clause (input_location, code);
> + tree node;
> + /* For HAS_DEVICE_ADDR of an array descriptor, firstprivatize the
> +descriptor such that the bounds are available; its data component
> +is unmodified; it is handled as device address inside target. */
> + if (code == OMP_CLAUSE_HAS_DEVICE_ADDR
> + && (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (t))
> + || (POINTER_TYPE_P (TREE_TYPE (t))
> + && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (t))
> +   node = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE);

Not sure about the above,

> --- a/gcc/gimplify.c
> +++ b/gcc/gimplify.c
> @@ -10024,6 +10024,15 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq 
> *pre_p,
> flags = GOVD_EXPLICIT;
> goto do_add;
>  
> + case OMP_CLAUSE_HAS_DEVICE_ADDR:
> +   decl = OMP_CLAUSE_DECL (c);
> +   if (TREE_CODE (decl) == ARRAY_REF)
> + {
> +   flags = GOVD_FIRSTPRIVATE | GOVD_EXPLICIT;
> +   while (TREE_CODE (decl) == ARRAY_REF)
> + decl = TREE_OPERAND (decl, 0);
> +   goto do_add_decl;

but this looks weird.
If decl after stripping the ARRAY_REFs is a var with pointer type, sure,
firstprivatizing it is the way to go.
But it can be also a variable with ARRAY_TYPE, can't it?  Something like:
  int a[64];
  #pragma omp target data map(a) use_device_addr(a)
  {
#pragma omp target has_device_addr(a[3:16])
a[3] = 1;
  }
and in this case firstprivatization of a looks wrong.  use_device_addr
should replace (but only at omp-low.c time I think) a used in the block
with 

Re: [PATCH 5/6] ira: Consider modelling caller-save allocations as loop spills

2022-01-11 Thread Martin Liška

On 1/11/22 09:52, Richard Sandiford via Gcc-patches wrote:

Robin Dapp  writes:

Hi Richard,

this causes a bootstrap error on s390 (where
IRA_HARD_REGNO_ADD_COST_MULTIPLIER is defined). rclass is used in the
#define-guarded area.


Gah, sorry about that.


I guess you also wanted to move this to the new function
ira_caller_save_cost?


No, the IRA_HARD_REGNO_ADD_COST_MULTIPLIER heuristic is a separate thing.
It's just that I had to remove the rclass variable to allow bootstrap on
other targets.

Could you try the attached?


Hello.

I noticed the same failure. Please push the patch.

Thanks,
Martin



Thanks,
Richard






Re: [PATCH 5/6] ira: Consider modelling caller-save allocations as loop spills

2022-01-11 Thread Robin Dapp via Gcc-patches
> Could you try the attached?

The series with the patch is OK from a testsuite point of view.  The
other problem appears later.

Regards
 Robin


Re: [PATCH 5/6] ira: Consider modelling caller-save allocations as loop spills

2022-01-11 Thread Richard Sandiford via Gcc-patches
Robin Dapp  writes:
>> Could you try the attached?
>
> The series with the patch is OK from a testsuite point of view.  The
> other problem appears later.

OK, thanks for checking.  I've pushed the patch as obvious.

Richard


[PATCH] Mass rename of C++ .c files to .cc suffix

2022-01-11 Thread Martin Liška

Hello.

I've got a patch series that does the renaming. It contains of 2 automatic
scripts ([1] and [2]) that were run as:

$ gcc-renaming-candidates.py gcc --rename && git commit -a -m 'Rename files.' && 
rename-gcc.py . -vv && git commit -a -m 'Automatic renaming'

The first scripts does the renaming (with a couple of exceptions that are 
really C files) and saves
the renamed files to a file. Then the file is then loaded and replacement of 
all the renamed files does happen
for most of the GCC files ([2]). It basically replaces at \b${old_filename}\b 
with ${old_filename}c
(with some exceptions). That corresponds to patch #1 and #2 and the patches are 
quite huge.

The last piece are manual changes needed for Makefile.in, configure.ac and so 
on.

The git branch can be seen here:
https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;a=log;h=refs/users/marxin/heads/cc-renaming

and pulled with:
$ git fetch refs/users/marxin/heads/cc-renaming
$ git co FETCH_HEAD

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Plus it survives build of all FEs (--enable-languages=all) on x86_64-linux-gnu
and I've built all cross compilers.

Thoughts?
Martin

[1] https://github.com/marxin/script-misc/blob/master/gcc-renaming-candidates.py
[2] https://github.com/marxin/script-misc/blob/master/rename-gcc.pyFrom 65bb0c6b03ed394669471befe54482858d982ee2 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Mon, 10 Jan 2022 11:46:58 +0100
Subject: [PATCH 3/3] Manual changes for .cc renaming.

gcc/ChangeLog:

	* Makefile.in: Rename .c names to .cc.
	* config.gcc: Likewise.
	* configure: Regenerate. Likewise.
	* configure.ac: Likewise.
	* gengtype.cc (set_gc_used): Likewise.
	(source_dot_c_frul): Likewise.
	(source_dot_cc_frul): Likewise.
	(struct file_rule_st): Likewise.
	(close_output_files): Likewise.

gcc/ada/ChangeLog:

	* Makefile.rtl: Rename .c names to .cc.
	* gcc-interface/Make-lang.in: Likewise.
	* gcc-interface/Makefile.in: Likewise.

libgcc/ChangeLog:

	* libgcov-driver.c: Rename .c names to .cc.
---
 gcc/Makefile.in| 46 +++---
 gcc/ada/Makefile.rtl   |  8 +++---
 gcc/ada/gcc-interface/Make-lang.in |  6 ++--
 gcc/ada/gcc-interface/Makefile.in  |  6 
 gcc/config.gcc |  2 +-
 gcc/configure  | 37 ++--
 gcc/configure.ac   |  6 ++--
 gcc/gengtype.cc| 30 ---
 libgcc/libgcov-driver.c|  2 +-
 9 files changed, 81 insertions(+), 62 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index e13bf66b040..31ff95500c9 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1784,7 +1784,7 @@ MOSTLYCLEANFILES = insn-flags.h insn-config.h insn-codes.h \
  gcc-ranlib$(exeext) \
  genversion$(build_exeext) gcov$(exeext) gcov-dump$(exeext) \
  gcov-tool$(exeect) \
- gengtype$(exeext) *.[0-9][0-9].* *.[si] *-checksum.c libbackend.a \
+ gengtype$(exeext) *.[0-9][0-9].* *.[si] *-checksum.cc libbackend.a \
  libcommon-target.a libcommon.a libgcc.mk perf.data
 
 # This symlink makes the full installation name of the driver be available
@@ -2421,10 +2421,10 @@ simple_generated_h	= $(simple_rtl_generated_h) insn-constants.h
 simple_generated_c	= $(simple_rtl_generated_c) insn-enums.cc
 
 $(simple_generated_h:insn-%.h=s-%) \
-$(simple_generated_c:insn-%.c=s-%): s-%: $(MD_DEPS)
+$(simple_generated_c:insn-%.cc=s-%): s-%: $(MD_DEPS)
 
 $(simple_rtl_generated_h:insn-%.h=s-%) \
-$(simple_rtl_generated_c:insn-%.c=s-%): s-%: insn-conditions.md
+$(simple_rtl_generated_c:insn-%.cc=s-%): s-%: insn-conditions.md
 
 $(simple_generated_h): insn-%.h: s-%; @true
 
@@ -2434,11 +2434,11 @@ $(simple_generated_h:insn-%.h=s-%): s-%: build/gen%$(build_exeext)
 	$(SHELL) $(srcdir)/../move-if-change tmp-$*.h insn-$*.h
 	$(STAMP) s-$*
 
-$(simple_generated_c): insn-%.c: s-%; @true
-$(simple_generated_c:insn-%.c=s-%): s-%: build/gen%$(build_exeext)
+$(simple_generated_c): insn-%.cc: s-%; @true
+$(simple_generated_c:insn-%.cc=s-%): s-%: build/gen%$(build_exeext)
 	$(RUN_GEN) build/gen$*$(build_exeext) $(md_file) \
-	  $(filter insn-conditions.md,$^) > tmp-$*.c
-	$(SHELL) $(srcdir)/../move-if-change tmp-$*.c insn-$*.c
+	  $(filter insn-conditions.md,$^) > tmp-$*.cc
+	$(SHELL) $(srcdir)/../move-if-change tmp-$*.cc insn-$*.cc
 	$(STAMP) s-$*
 
 # gencheck doesn't read the machine description, and the file produced
@@ -2449,12 +2449,12 @@ s-check : build/gencheck$(build_exeext)
 	$(SHELL) $(srcdir)/../move-if-change tmp-check.h tree-check.h
 	$(STAMP) s-check
 
-# genattrtab produces three files: tmp-{attrtab.c,dfatab.c,latencytab.c}
+# genattrtab produces three files: tmp-{attrtab.cc,dfatab.cc,latencytab.cc}
 insn-attrtab.cc insn-dfatab.cc insn-latencytab.cc: s-attrtab ; @true
 s-attrtab : $(MD_DEPS) build/genattrtab$(build_exeext) \
   insn-conditions.md
 	$(RUN_GEN) build/genattrtab$(build_exeext) $(md_file) insn-conditions.md \
-		-Atmp-attrtab.c -Dtmp-dfatab.c -Ltmp-laten

[PATCH] tree-optimization/pr103961: Never compute offset for -1 size

2022-01-11 Thread Siddhesh Poyarekar
Never try to compute size for offset when the object size is -1, which
is either unknown maximum or uninitialized minimum irrespective of the
osi->pass number.

gcc/ChangeLog:

PR tree-optimization/pr103961
* tree-object-size.c (plus_stmt_object_size): Always avoid
computing offset for -1 size.

gcc/testsuite/ChangeLog:

PR tree-optimization/pr103961
* gcc.dg/pr103961.c: New test case.

Co-authored-by: Jakub Jelinek 
Signed-off-by: Siddhesh Poyarekar 
---
Tested with i686 build+test, x86_64 bootstrap build+test and ubsan
bootstrap.

 gcc/testsuite/gcc.dg/pr103961.c | 30 ++
 gcc/tree-object-size.c  | 11 ---
 2 files changed, 34 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr103961.c

diff --git a/gcc/testsuite/gcc.dg/pr103961.c b/gcc/testsuite/gcc.dg/pr103961.c
new file mode 100644
index 000..2cd52884e3b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr103961.c
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+extern void abort ();
+
+extern inline __attribute__ ((__gnu_inline__)) int
+sprintf (char *restrict s, const char *restrict fmt, ...)
+{
+  return __builtin___sprintf_chk (s, 1, __builtin_object_size (s, 1),
+ fmt, __builtin_va_arg_pack ());
+}
+
+void
+cap_to_text (int c)
+{
+  char buf[1572];
+  char *p;
+  int n, t;
+  p = 20 + buf;
+  for (t = 8; t--; )
+{
+  for (n = 0; n < c; n++)
+   p += sprintf (p, "a,");
+  p--;
+  if (__builtin_object_size (p, 1) == 0)
+   abort ();
+}
+}
+
+/* { dg-final { scan-assembler-not "abort" } } */
diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c
index fbaf57a20f8..f7cc323591c 100644
--- a/gcc/tree-object-size.c
+++ b/gcc/tree-object-size.c
@@ -990,13 +990,10 @@ plus_stmt_object_size (struct object_size_info *osi, tree 
var, gimple *stmt)
  addr_object_size (osi, op0, object_size_type, &bytes, &wholesize);
}
 
-  /* In the first pass, do not compute size for offset if either the
-maximum size is unknown or the minimum size is not initialized yet;
-the latter indicates a dependency loop and will be resolved in
-subsequent passes.  We attempt to compute offset for 0 minimum size
-too because a negative offset could be within bounds of WHOLESIZE,
-giving a non-zero result for VAR.  */
-  if (osi->pass != 0 || !size_unknown_p (bytes, 0))
+  /* size_for_offset doesn't make sense for -1 size, but it does for size 0
+since the wholesize could be non-zero and a negative offset could give
+a non-zero size.  */
+  if (!size_unknown_p (bytes, 0))
bytes = size_for_offset (bytes, op1, wholesize);
 }
   else
-- 
2.33.1



Re: [PATCH] Check sorting of MAINTAINERS

2022-01-11 Thread Martin Liška

On 1/11/22 11:05, Martin Liška wrote:

On 1/11/22 10:38, Jakub Jelinek wrote:

On Tue, Jan 11, 2022 at 10:27:19AM +0100, Martin Liška wrote:

On 1/10/22 17:14, Martin Liška wrote:

Are you fine with the suggested changes?


Hello.

Jakub had comments so I'm sending v2 where I added few parsing
exceptions. Now it reports:


I'm still surprised by what the sort is doing,
( echo Chene; echo Chêne; echo Chfne ) | LC_ALL=en_US.UTF-8 sort
Chene
Chêne
Chfne
That is on glibc 2.32.  On glibc 2.34.9000 I get a different order though,
Chêne last.
That partly ruins the idea of the checking script when the sorting isn't
the same for many people, either the script will be failing for many people
or various people will be changing the order there and back all the time.

Jakub



Or we can utilize https://pypi.org/project/Unidecode python package that 
provides:

In [7]: unidecode.unidecode('Jääskeläinen')
Out[7]: 'Jaaskelainen'

and sort it by that.

Martin


I'm going to push the change and re-order 2 names and we should be done.

MartinFrom 8ad2115c48a8f30c05000c8c3d908a264a4eb1be Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Tue, 11 Jan 2022 14:10:14 +0100
Subject: [PATCH 2/2] Sort 2 names in ChangeLog.

ChangeLog:

	* MAINTAINERS: Sort 2 names.
---
 MAINTAINERS | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index c5aeb1af174..9b5945c048d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -18,6 +18,9 @@ To report problems in GCC, please visit:
 Note: when adding someone to a more specific section please remove any
 corresponding entry from the Write After Approval list.
 
+Note: please verify that sorting is correct with:
+./contrib/check-MAINTAINERS.py MAINTAINERS
+
 Maintainers
 ===
 
@@ -422,6 +425,7 @@ Haochen Gui	
 Jiufu Guo	
 Xuepeng Guo	
 Wei Guozhi	
+Naveen H.S	
 Mostafa Hagog	
 Andrew Haley	
 Frederik Harwath
@@ -447,7 +451,6 @@ Dominique d'Humieres
 Andy Hutchinson	
 Joel Hutton	
 Lewis Hyatt	
-Naveen H.S	
 Roland Illig	
 Meador Inge	
 Bernardo Innocenti
@@ -484,12 +487,12 @@ Louis Krupp	
 Prathamesh Kulkarni
 Venkataramanan Kumar
 Doug Kwan	
+Aaron W. LaFramboise
 Scott Robert Ladd
 Razya Ladelsky	
 Thierry Lafage	
 Rask Ingemann Lambertsen			
 Jerome Lambourg	
-Aaron W. LaFramboise
 Asher Langton	
 Chris Lattner	
 Terry Laurenzo	
-- 
2.34.1

From f770f4913a8247c284dbeb74ba493496b70fe720 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Mon, 10 Jan 2022 16:49:31 +0100
Subject: [PATCH 1/2] Check sorting of MAINTAINERS.

contrib/ChangeLog:

	* check-MAINTAINERS.py: New file.
---
 contrib/check-MAINTAINERS.py | 113 +++
 1 file changed, 113 insertions(+)
 create mode 100755 contrib/check-MAINTAINERS.py

diff --git a/contrib/check-MAINTAINERS.py b/contrib/check-MAINTAINERS.py
new file mode 100755
index 000..ca7bb291282
--- /dev/null
+++ b/contrib/check-MAINTAINERS.py
@@ -0,0 +1,113 @@
+#!/usr/bin/env python3
+
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING.  If not, write to
+# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# Check that names in the file are sorted
+# alphabetically by surname.
+
+import locale
+import sys
+from difflib import ndiff
+from itertools import dropwhile, takewhile
+
+import unidecode
+
+locale.setlocale(locale.LC_ALL, 'en_US.utf8')
+
+exit_code = 0
+
+if len(sys.argv) != 2:
+print('Usage: ./check-MAINTAINERS.py path-to/MAINTAINERS')
+sys.exit(1)
+
+
+def sort_by_surname(line):
+name = line.split('\t')[0]
+parts = name.split()
+surname = parts[-1]
+
+# Special-case some names
+if name == 'Stefan Schulze Frielinghaus':
+surname = parts[1]
+elif name == 'Kris Van Hees':
+surname = parts[1]
+elif surname == "d'Humieres":
+surname = 'Humieres'
+
+# Remove accents
+return (unidecode.unidecode(surname), line)
+
+
+def has_tab(line):
+return '\t' in line
+
+
+def is_empty(line):
+return line
+
+
+def check_group(name, lines):
+global exit_code
+
+for line in lines:
+if line.startswith(' '):
+print(f'Line should not start with space: "{line}"')
+exit_code = 2
+
+lines = [line + '\n' for line in li

Re: [power-ieee128, committed] Enable conversion selection via environment variable

2022-01-11 Thread Jakub Jelinek via Gcc-patches
On Mon, Jan 10, 2022 at 11:44:13PM +0100, Thomas Koenig wrote:
> Hello world,
> 
> I have just pushed the attched patch to the branch.

Thanks.

Here is a patch to fix up the ppc64be vs. ppc64le byteswapping
of IBM extended real(kind=16) and complex(kind=16).
Similarly to the BT_COMPLEX case it halves size and doubles nelems
for the bswap_array calls.  Of course for r16_ibm and r16_ieee conversions
one needs to make sure it is only done when the on file data is in that
format and not in IEEE quad.

> So... time to merge the branch into trunk before stage 4
> kicks in?

IMHO yes.  We need to git merge master; git rebase of course
before trying to cherry-pick those commits into trunk and pushing there.

2022-01-11  Jakub Jelinek  

* io/transfer.c (unformatted_read, unformatted_write): When
byteswapping IBM extended real(kind=16), handle it as byteswapping
two real(kind=8) values.

--- libgfortran/io/transfer.c.jj2022-01-11 13:31:14.881806323 +0100
+++ libgfortran/io/transfer.c   2022-01-11 13:46:00.584288005 +0100
@@ -1145,11 +1145,28 @@ unformatted_read (st_parameter_dt *dtp,
  size /= 2;
}
 #ifndef HAVE_GFC_REAL_17
+#if defined(HAVE_GFC_REAL_16) && GFC_REAL_16_DIGITS == 106
+  /* IBM extended format is stored as a pair of IEEE754
+double values, with the more significant value first
+in both big and little endian.  */
+  if (kind == 16 && (type == BT_REAL || type == BT_COMPLEX))
+   {
+ nelems *= 2;
+ size /= 2;
+   }
+#endif
   bswap_array (dest, dest, size, nelems);
 #else
   unit_convert bswap = convert & ~(GFC_CONVERT_R16_IEEE | 
GFC_CONVERT_R16_IBM);
   if (bswap == GFC_CONVERT_SWAP)
-   bswap_array (dest, dest, size, nelems);
+   {
+ if ((type == BT_REAL || type == BT_COMPLEX)
+ && ((kind == 16 && (convert & GFC_CONVERT_R16_IEEE) == 0)
+ || (kind == 17 && (convert & GFC_CONVERT_R16_IBM
+   bswap_array (dest, dest, size / 2, nelems * 2);
+ else
+   bswap_array (dest, dest, size, nelems);
+   }
 
   if ((convert & GFC_CONVERT_R16_IEEE)
  && kind == 16
@@ -1274,6 +1291,18 @@ unformatted_write (st_parameter_dt *dtp,
  size /= 2;
}
 
+#if !defined(HAVE_GFC_REAL_17) && defined(HAVE_GFC_REAL_16) \
+&& GFC_REAL_16_DIGITS == 106
+  /* IBM extended format is stored as a pair of IEEE754
+double values, with the more significant value first
+in both big and little endian.  */
+  if (kind == 16 && (type == BT_REAL || type == BT_COMPLEX))
+   {
+ nelems *= 2;
+ size /= 2;
+   }
+#endif
+
   /* By now, all complex variables have been split into their
 constituent reals.  */
 
@@ -1321,7 +1350,12 @@ unformatted_write (st_parameter_dt *dtp,
  if ((dtp->u.p.current_unit->flags.convert
   & ~(GFC_CONVERT_R16_IEEE | GFC_CONVERT_R16_IBM))
  == GFC_CONVERT_SWAP)
-   bswap_array (buffer, buffer, size, nc);
+   bswap_array (buffer, buffer, size / 2, nc * 2);
+   }
+ else if (kind == 16 && (type == BT_REAL || type == BT_COMPLEX))
+   {
+ bswap_array (buffer, p, size / 2, nc * 2);
+ p += size * nc;
}
  else
 #endif


Jakub



Re: [patch] Fix reverse SSO issues in IPA-SRA

2022-01-11 Thread Richard Biener via Gcc-patches
On Tue, Jan 11, 2022 at 11:45 AM Eric Botcazou via Gcc-patches
 wrote:
>
> Hi,
>
> we recently received the report that the IPA-SRA pass introduced in GCC 10
> does not always play nice with the reverse scalar storage order that can be
> used in structures/records/unions.  Reading the code, the pass apparently
> correctly detects it but fails to propagate the information to the rewriting
> phase in some cases and, in particular, does not stream it for LTO.
>
> The attached patch is a tentative fix for these issues spotted essentially by
> code reading.  It also contains various minor tweaks left and right.
>
> Bootstrapped/regtested on x86-64/Linux, OK for mainline, 11 and 10 branches?

LGTM.

Thanks,
Richard.

>
> 2022-01-11  Eric Botcazou  
>
> * ipa-param-manipulation.c (ipa_dump_adjusted_parameters): Dump
> reverse flag as "reverse" for the sake of consistency.
> * ipa-sra.c: Fix copyright year.
> (ipa_sra_function_summaries::duplicate): Copy the reverse flag.
> (dump_isra_access): Remove confusing dump line.
> (isra_write_node_summary): Write the reverse flag.
> (isra_read_node_info): Read it.
> (pull_accesses_from_callee): Copy it.
>
> --
> Eric Botcazou


[committed] libstdc++: Make std::common_iterator completely constexpr-able (LWG 3574)

2022-01-11 Thread Jonathan Wakely via Gcc-patches
Tested x86_64-linux. Pushed to trunk.


This library issue was approved in the October 2021 plenary.

libstdc++-v3/ChangeLog:

* include/bits/stl_iterator.h (common_iterator): Add constexpr
to all member functions (LWG 3574).
* testsuite/24_iterators/common_iterator/1.cc: Evaluate some
tests as constant expressions.
* testsuite/24_iterators/common_iterator/2.cc: Likewise.
---
 libstdc++-v3/include/bits/stl_iterator.h  | 34 ++-
 .../24_iterators/common_iterator/1.cc |  9 -
 .../24_iterators/common_iterator/2.cc | 14 
 3 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_iterator.h 
b/libstdc++-v3/include/bits/stl_iterator.h
index cfeb7981ed8..24a71ea55af 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -77,11 +77,12 @@
 # define __cpp_lib_array_constexpr 201803L
 #endif
 
-#if __cplusplus > 201703L
+#if __cplusplus >= 202002L
 # include 
 # include 
 # include 
 # include 
+# include 
 #endif
 
 namespace std _GLIBCXX_VISIBILITY(default)
@@ -1938,7 +1939,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
 }
 
-common_iterator&
+constexpr common_iterator&
 operator=(const common_iterator& __x)
 noexcept(is_nothrow_copy_assignable_v<_It>
 && is_nothrow_copy_assignable_v<_Sent>
@@ -1953,7 +1954,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
&& convertible_to
&& assignable_from<_It&, const _It2&>
&& assignable_from<_Sent&, const _Sent2&>
-  common_iterator&
+  constexpr common_iterator&
   operator=(const common_iterator<_It2, _Sent2>& __x)
   noexcept(is_nothrow_constructible_v<_It, const _It2&>
   && is_nothrow_constructible_v<_Sent, const _Sent2&>
@@ -1973,7 +1974,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_index = -1;
[[fallthrough]];
  case 0b1001:
-   ::new((void*)std::__addressof(_M_sent)) _Sent(__x._M_sent);
+   std::construct_at(std::__addressof(_M_sent), _Sent(__x._M_sent));
_M_index = 1;
break;
  case 0b0100:
@@ -1981,7 +1982,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_index = -1;
[[fallthrough]];
  case 0b1000:
-   ::new((void*)std::__addressof(_M_it)) _It(__x._M_it);
+   std::construct_at(std::__addressof(_M_it), _It(__x._M_it));
_M_index = 0;
break;
  default:
@@ -1991,6 +1992,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return *this;
   }
 
+constexpr
 ~common_iterator()
 {
   switch (_M_index)
@@ -2005,7 +2007,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 }
 
 [[nodiscard]]
-decltype(auto)
+constexpr decltype(auto)
 operator*()
 {
   __glibcxx_assert(_M_index == 0);
@@ -2013,7 +2015,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 }
 
 [[nodiscard]]
-decltype(auto)
+constexpr decltype(auto)
 operator*() const requires __detail::__dereferenceable
 {
   __glibcxx_assert(_M_index == 0);
@@ -2021,7 +2023,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 }
 
 [[nodiscard]]
-decltype(auto)
+constexpr decltype(auto)
 operator->() const requires __detail::__common_iter_has_arrow<_It>
 {
   __glibcxx_assert(_M_index == 0);
@@ -2036,7 +2038,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __arrow_proxy{*_M_it};
 }
 
-common_iterator&
+constexpr common_iterator&
 operator++()
 {
   __glibcxx_assert(_M_index == 0);
@@ -2044,7 +2046,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   return *this;
 }
 
-decltype(auto)
+constexpr decltype(auto)
 operator++(int)
 {
   __glibcxx_assert(_M_index == 0);
@@ -2066,7 +2068,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 template _Sent2>
   requires sentinel_for<_Sent, _It2>
-  friend bool
+  friend constexpr bool
   operator== [[nodiscard]] (const common_iterator& __x,
const common_iterator<_It2, _Sent2>& __y)
   {
@@ -2088,7 +2090,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 template _Sent2>
   requires sentinel_for<_Sent, _It2> && equality_comparable_with<_It, _It2>
-  friend bool
+  friend constexpr bool
   operator== [[nodiscard]] (const common_iterator& __x,
const common_iterator<_It2, _Sent2>& __y)
   {
@@ -2111,7 +2113,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 template _It2, sized_sentinel_for<_It> _Sent2>
   requires sized_sentinel_for<_Sent, _It2>
-  friend iter_difference_t<_It2>
+  friend constexpr iter_difference_t<_It2>
   operator- [[nodiscard]] (const common_iterator& __x,
   const common_iterator<_It2, _Sent2>& __y)
   {
@@ -2133,7 +2135,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 
 [[nodiscard]]
-friend iter_rvalue_reference_t<_It>
+friend constexpr iter_rvalue_

[committed] libstdc++: Make std::variant work with Clang in C++20 mode [PR103891]

2022-01-11 Thread Jonathan Wakely via Gcc-patches
Tested x86_64-linux. Pushed to trunk.


Clang has some bugs with destructors that use constraints to be
conditionally trivial, so disable the P2231R1 constexpr changes to
std::variant unless the compiler is GCC 12 or later.

If/when P2493R0 gets accepted and implemented by G++ we can remove the
__GNUC__ check and use __cpp_concepts >= 202002 instead.

libstdc++-v3/ChangeLog:

PR libstdc++/103891
* include/bits/c++config (_GLIBCXX_HAVE_COND_TRIVIAL_SPECIAL_MEMBERS):
Define.
* include/std/variant (__cpp_lib_variant): Only define C++20
value when the compiler is known to support conditionally
trivial destructors.
* include/std/version (__cpp_lib_variant): Likewise.
---
 libstdc++-v3/include/bits/c++config | 5 +
 libstdc++-v3/include/std/variant| 7 ---
 libstdc++-v3/include/std/version| 5 +++--
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index c64b61b3c90..b197349f976 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -810,6 +810,11 @@ namespace std
 
 #undef _GLIBCXX_HAS_BUILTIN
 
+#if __cplusplus >= 202002L && __cpp_concepts && __GNUC__ >= 12
+// XXX workaround for missing feature test macro for P0848R3 (see P2493R0).
+# define _GLIBCXX_HAVE_COND_TRIVIAL_SPECIAL_MEMBERS 1
+#endif
+
 // PSTL configuration
 
 #if __cplusplus >= 201703L
diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index d74939eddc3..c41f9f27e00 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -44,9 +44,10 @@
 #include 
 #include 
 #include  // in_place_index_t
-#if __cplusplus == 201703L
+#ifndef _GLIBCXX_HAVE_COND_TRIVIAL_SPECIAL_MEMBERS
 # include 
-#else
+#endif
+#if __cplusplus >= 202002L
 # include 
 #endif
 
@@ -54,7 +55,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
-#if __cplusplus >= 202002L && __cpp_concepts
+#ifdef _GLIBCXX_HAVE_COND_TRIVIAL_SPECIAL_MEMBERS
 // P2231R1 constexpr needs constexpr unions and constrained destructors.
 # define __cpp_lib_variant 202106L
 #else
diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version
index f421056964e..012d78e3b6b 100644
--- a/libstdc++-v3/include/std/version
+++ b/libstdc++-v3/include/std/version
@@ -173,7 +173,8 @@
 # define __cpp_lib_to_chars 201611L
 #endif
 #define __cpp_lib_unordered_map_try_emplace 201411
-#if __cplusplus == 201703L || ! __cpp_concepts // N.B. updated value in C++20
+#ifndef _GLIBCXX_HAVE_COND_TRIVIAL_SPECIAL_MEMBERS
+// N.B. updated value in C++20
 # define __cpp_lib_variant 202102L
 #endif
 #endif
@@ -286,7 +287,7 @@
 # endif
 #define __cpp_lib_to_address 201711L
 #define __cpp_lib_to_array 201907L
-#if __cpp_concepts
+#ifdef _GLIBCXX_HAVE_COND_TRIVIAL_SPECIAL_MEMBERS
 # define __cpp_lib_variant 202106L
 #endif
 #endif
-- 
2.31.1



[PATCH] x86_64: Improvements to arithmetic right shifts of V1TImode values.

2022-01-11 Thread Roger Sayle

This patch to the i386 backend's ix86_expand_v1ti_ashiftrt provides
improved (shorter) implementations of V1TI mode arithmetic right shifts
for constant amounts between 111 and 126 bits.  The significance of
this range is that this functionality is useful for (eventually)
providing sign extension from HImode and QImode to V1TImode.

For example, x>>112 (to sign extend a 16-bit value), was previously
generated as a four operation sequence:

movdqa  %xmm0, %xmm1// word7 6 5 4 3 2 1 0
psrad   $31, %xmm0  // V8HI = [S,S,?,?,?,?,?,?]
psrad   $16, %xmm1  // V8HI = [S,X,?,?,?,?,?,?]
punpckhqdq  %xmm0, %xmm1// V8HI = [S,S,?,?,S,X,?,?]
pshufd  $253, %xmm1, %xmm0  // V8HI = [S,S,S,S,S,S,S,X]

with this patch, we now generates a three operation sequence:

psrad   $16, %xmm0  // V8HI = [S,X,?,?,?,?,?,?]
pshufhw $254, %xmm0, %xmm0  // V8HI = [S,S,S,X,?,?,?,?]
pshufd  $254, %xmm0, %xmm0  // V8HI = [S,S,S,S,S,S,S,X]

The correctness of generated code is confirmed by the existing
run-time test gcc.target/i386/sse2-v1ti-ashiftrt-1.c in the testsuite.
This idiom is safe to use for shifts by 127, but that case gets handled
by a two operation sequence earlier in this function.


This patch has been tested on x86_64-pc-linux-gnu with a make bootstrap
and make -k check with no new failures.  OK for mainline?


2022-01-11  Roger Sayle  

gcc/ChangeLog
* config/i386/i386-expand.c (ix86_expand_v1ti_ashiftrt): Provide
new three operation implementations for shifts by 111..126 bits.


Thanks in advance,
Roger
--

diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index 95bba25..3138b5f 100644
--- a/gcc/config/i386/i386-expand.c
+++ b/gcc/config/i386/i386-expand.c
@@ -6470,12 +6470,12 @@ ix86_expand_v1ti_ashiftrt (rtx operands[])
   if (bits == 96)
 {
   /* Three operations.  */
-  rtx tmp3 = gen_reg_rtx (V2DImode);
   rtx tmp1 = gen_reg_rtx (V4SImode);
   rtx tmp2 = gen_reg_rtx (V4SImode);
   emit_move_insn (tmp1, gen_lowpart (V4SImode, op1));
   emit_insn (gen_ashrv4si3 (tmp2, tmp1, GEN_INT (31)));
 
+  rtx tmp3 = gen_reg_rtx (V2DImode);
   rtx tmp4 = gen_reg_rtx (V2DImode);
   rtx tmp5 = gen_reg_rtx (V2DImode);
   emit_move_insn (tmp3, gen_lowpart (V2DImode, tmp1));
@@ -6493,6 +6493,30 @@ ix86_expand_v1ti_ashiftrt (rtx operands[])
   return;
 }
 
+  if (bits >= 111)
+{
+  /* Three operations.  */
+  rtx tmp1 = gen_reg_rtx (V4SImode);
+  rtx tmp2 = gen_reg_rtx (V4SImode);
+  emit_move_insn (tmp1, gen_lowpart (V4SImode, op1));
+  emit_insn (gen_ashrv4si3 (tmp2, tmp1, GEN_INT (bits - 96)));
+
+  rtx tmp3 = gen_reg_rtx (V8HImode);
+  rtx tmp4 = gen_reg_rtx (V8HImode);
+  emit_move_insn (tmp3, gen_lowpart (V8HImode, tmp2));
+  emit_insn (gen_sse2_pshufhw (tmp4, tmp3, GEN_INT (0xfe)));
+
+  rtx tmp5 = gen_reg_rtx (V4SImode);
+  rtx tmp6 = gen_reg_rtx (V4SImode);
+  emit_move_insn (tmp5, gen_lowpart (V4SImode, tmp4));
+  emit_insn (gen_sse2_pshufd (tmp6, tmp5, GEN_INT (0xfe)));
+
+  rtx tmp7 = gen_reg_rtx (V1TImode);
+  emit_move_insn (tmp7, gen_lowpart (V1TImode, tmp6));
+  emit_move_insn (operands[0], tmp7);
+  return;
+}
+
   if (TARGET_AVX2 || TARGET_SSE4_1)
 {
   /* Three operations.  */


Re: [RFC][PATCH 3/N] lto-plugin: Port to C++

2022-01-11 Thread Martin Liška

On 1/10/22 08:50, Richard Biener wrote:

On Wed, Jan 5, 2022 at 2:28 PM Martin Liška  wrote:


Hello.

I'm working on some changes that will be needed for support of ld.mold.
And I would like to have the plugin in C++. Having that, we can utilize basic
contains like std::vector (instead of xrealloc(foo, len + 1)...).

I split the patch into 2 pieces where the second one is only result
of autoreconf and automake.

Lightly tested with ld.bfd, ld.gold and lto.exp.


With the linker plugin build by GCC using its libstdc++ statically(?)
and for example gold (also a C++ application) built by another
(GCC) system compiler there might be two different versioned
libstdc++ in the process image after dlopening the plugin.  Is the
libstdc++ "copy" in the plugin sufficiently isolated to not cause
problems here?  Do we need to pay extra care as to the subset
of the C++ standard library we can use (I'm thinking of parts
initialized on load time like I/O)?


Hmm, didn't realize that.



That said, I'm not sure this is worth the trouble.


Agree. That said, I would like to approve patches 1/2 that are
a stage1 material and do a refactoring that worth doing.

What do you think?
Cheers,
Martin



Richard.



Thoughts?
Thanks,
Martin




Re: [PATCH] C, C++, Fortran, OpenMP: Add 'has_device_addr' clause to 'target' construct

2022-01-11 Thread Tobias Burnus

Hi Jakub, hi all,

let me quickly comment on 'has_device_addr' with Fortran arrays
and with an array section (i.e. regarding your comment quoted
at the very bottom of this email).

Unfortunately, the OpenMP specification is rather unclear
what has_device_addr means for C/C++ array sections and in general
for Fortran, especially when arrays, allocatables/pointers, and
type parameters like nonconst string lengths are involved. Thus,
I opened a spec issue – after some discussions (lang-spec meeting,
C++/affinity (→ Fortran) meeting), it starts to converge:
https://github.com/OpenMP/spec/issues/3180

If I understood it correctly, for C/C++, using has_device_addr with
an array section implies firstprivate, while it does not without
array section.

For Fortran, the discussion converged to
* array descriptor must be the same at beginning/end of target
  region, i.e:
- if allocated before target region, allocation may not be changed
  inside the target region. If unallocated, it can be allocated but
  must be deallocated before the target region is left.
- if a pointer, pointer association must be the same at the end of
  the target region as when it was entered (unmodified or reset)
* meta data (array bounds, alloc status, len type parameters like
  char length) are accessible on the host - and are then made
  accessible to the device (firstprivate, direct access on shared
  memory or whatever means. Due to the conditions above, it is
  indistinguishable).

However, the discussion has not yet fully settled and spec updates
are still needed.

Side remark: I note that use_device_addr permits array sections,
but GCC does not support them yet. (Useful when doing a partial
map of an array + 'omp data use_device_addr()' on the partially
mapped array.)

I have not checked what Marcel's implementation does and whether
that's compatible with the incomplete OpenMP 5.{1,2} spec and
the on-going discussion of/in OpenMP lang-spec Issue 3180.

On 11.01.22 12:53, Jakub Jelinek via Fortran wrote:


+++ b/gcc/fortran/trans-openmp.c
...
+/* For HAS_DEVICE_ADDR of an array descriptor, firstprivatize the
+   descriptor such that the bounds are available; its data component
+   is unmodified; it is handled as device address inside target. */

...

Not sure about the above,


--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
...

but this looks weird.
If decl after stripping the ARRAY_REFs is a var with pointer type, sure,
firstprivatizing it is the way to go.
But it can be also a variable with ARRAY_TYPE, can't it?  Something like:
   int a[64];
   #pragma omp target data map(a) use_device_addr(a)
   {
 #pragma omp target has_device_addr(a[3:16])
 a[3] = 1;
   }
and in this case firstprivatization of a looks wrong.  use_device_addr
should replace (but only at omp-low.c time I think) a used in the block
with the remapped a (i.e. *device_address_of_a).
Or perhaps it could be a non-static data member with array type
inside of a C++ method.


Tobias

-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955


[committed] libstdc++: Optimize std::ostream inserters for single characters

2022-01-11 Thread Jonathan Wakely via Gcc-patches
Tested x86_64-linux. Pushed to trunk.


On the libsdc++ mailing list Lewis Hyatt pointed out the performance
overhead of using sputn in stream inserters, rather than writing
directly to the streambuf's put area:
https://gcc.gnu.org/pipermail/libstdc++/2021-July/052877.html

As Lewis noted, the standard explicitly requires a call to sputn for
inserting a std::basic_string_view or std::basic_string.  But for
inserting single characters or null-terminated strings it is more vague,
and so we can improve performance by not using the __ostream_insert
function.

This is a minimal change that avoids __ostream_insert for single
characters. We can use the unformatted basic_ostream::put(charT)
function when we don't need the additional effects of a formatted output
function (i.e. padding and resetting the width). The put function will
insert into the buffer if possible, and only make a virtual call (to
overflow) if the buffer is full.

We could also avoid sputn when inserting null-terminated character
strings, but that would require using a new function for inserting
null-terminated strings, so the existing code using sputn is still used
for basic_string and basic_string_view. My preference is to leave that
for now, and try to improve the standard. We could either remove the
requirement to call sputn, or allow sputn to write directly to the
buffer instead of calling xsputn.

libstdc++-v3/ChangeLog:

* include/std/ostream (operator<<(basic_ostream&, charT)):
Use unformatted input if no padding is needed.
(operator<<(basic_ostream&, char)): Likewise.
---
 libstdc++-v3/include/std/ostream | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream
index f8073f2a9b7..291ea40b355 100644
--- a/libstdc++-v3/include/std/ostream
+++ b/libstdc++-v3/include/std/ostream
@@ -505,7 +505,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 inline basic_ostream<_CharT, _Traits>&
 operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
-{ return __ostream_insert(__out, &__c, 1); }
+{
+  if (__out.width() != 0)
+   return __ostream_insert(__out, &__c, 1);
+  __out.put(__c);
+  return __out;
+}
 
   template
 inline basic_ostream<_CharT, _Traits>&
@@ -516,7 +521,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 inline basic_ostream&
 operator<<(basic_ostream& __out, char __c)
-{ return __ostream_insert(__out, &__c, 1); }
+{
+  if (__out.width() != 0)
+   return __ostream_insert(__out, &__c, 1);
+  __out.put(__c);
+  return __out;
+}
 
   // Signed and unsigned
   template
-- 
2.31.1



[committed] libstdc++: Install header for freestanding [PR103726]

2022-01-11 Thread Jonathan Wakely via Gcc-patches
Tested x86_64-linux and by minimally tested on  mips-none-elf.
Pushed to trunk.


The standard says that  should be present for freestanding.
That was intentionally left out of the initial implementation, but can
be done without much trouble. The header should be moved to libsupc++ at
some point in stage 1.

The standard also says that  defines a std::hash
specialization, which was missing from our implementation. That's a
problem for freestanding (see LWG 3653) so only do that for hosted.

We can use concepts to constrain the __coroutine_traits_impl base class
when compiled with concepts enabled. In a pure C++20 implementation we
would not need that base class at all and could just use a constrained
partial specialization of coroutine_traits. But the absence of the
__coroutine_traits_impl base would create an ABI difference
between the non-standard C++14/C++17 support for coroutines and the same
code compiled as C++20. If we drop support for  pre-C++20 we
should revisit this.

libstdc++-v3/ChangeLog:

PR libstdc++/103726
* include/Makefile.am: Install  for freestanding.
* include/Makefile.in: Regenerate.
* include/std/coroutine: Adjust headers and preprocessor
conditions.
(__coroutine_traits_impl): Use concepts when available.
[_GLIBCXX_HOSTED] (hash): Define.
---
 libstdc++-v3/include/Makefile.am   |  4 +--
 libstdc++-v3/include/Makefile.in   |  4 +--
 libstdc++-v3/include/std/coroutine | 55 ++
 3 files changed, 45 insertions(+), 18 deletions(-)

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 7afebb5c5f0..8f93bf2d7b7 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -1425,7 +1425,7 @@ endif
 # This is a subset of the full install-headers rule.  We only need ,
 # , , , , , , ,
 # , , , , , ,
-# , , , , ,
+# , , , , , ,
 # and any files which they include (and which we provide).
 # , , ,  and 
 # are installed by libsupc++, so only the others and the sub-includes
@@ -1440,7 +1440,7 @@ install-freestanding-headers:
  ${glibcxx_srcdir}/$(CPU_DEFINES_SRCDIR)/cpu_defines.h; do \
  $(INSTALL_DATA) $${file} $(DESTDIR)${host_installdir}; done
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${std_builddir}
-   for file in limits type_traits atomic bit concepts version; do \
+   for file in limits type_traits atomic bit concepts coroutine version; 
do \
  $(INSTALL_DATA) ${std_builddir}/$${file} 
$(DESTDIR)${gxx_include_dir}/${std_builddir}; done
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${c_base_builddir}
for file in ciso646 cstddef cfloat climits cstdint cstdlib \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index 0031f54f3fa..4ab942ae666 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -1906,7 +1906,7 @@ ${pch3_output}: ${pch3_source} ${pch2_output}
 # This is a subset of the full install-headers rule.  We only need ,
 # , , , , , , ,
 # , , , , , ,
-# , , , , ,
+# , , , , , ,
 # and any files which they include (and which we provide).
 # , , ,  and 
 # are installed by libsupc++, so only the others and the sub-includes
@@ -1921,7 +1921,7 @@ install-freestanding-headers:
  ${glibcxx_srcdir}/$(CPU_DEFINES_SRCDIR)/cpu_defines.h; do \
  $(INSTALL_DATA) $${file} $(DESTDIR)${host_installdir}; done
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${std_builddir}
-   for file in limits type_traits atomic bit concepts version; do \
+   for file in limits type_traits atomic bit concepts coroutine version; 
do \
  $(INSTALL_DATA) ${std_builddir}/$${file} 
$(DESTDIR)${gxx_include_dir}/${std_builddir}; done
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${c_base_builddir}
for file in ciso646 cstddef cfloat climits cstdint cstdlib \
diff --git a/libstdc++-v3/include/std/coroutine 
b/libstdc++-v3/include/std/coroutine
index ead5dad9bf0..f4189c7e3fc 100644
--- a/libstdc++-v3/include/std/coroutine
+++ b/libstdc++-v3/include/std/coroutine
@@ -34,22 +34,23 @@
 // It is very likely that earlier versions would work, but they are untested.
 #if __cplusplus >= 201402L
 
-#include 
+#include 
+#if __cplusplus > 201703L
+# include 
+#endif
+
+#if !defined __cpp_lib_three_way_comparison && _GLIBCXX_HOSTED
+# include  // for std::less
+#endif
 
 /**
  * @defgroup coroutines Coroutines
  *
  * Components for supporting coroutine implementations.
+ *
+ * @since C++20 (and since C++14 as a libstdc++ extension)
  */
 
-#if __cplusplus > 201703L && __cpp_impl_three_way_comparison >= 201907L
-#  include 
-#  define _COROUTINES_USE_SPACESHIP 1
-#else
-#  include  // for std::less
-#  define _COROUTINES_USE_SPACESHIP 0
-#endif
-
 namespace std _GLIBCXX_VISIBILITY (default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -60,25 +61,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   inline namespace __n4861 {
 
-  // 17.1

[Ada] Use atomic builtins for atomic counters on x86 (32bit)

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Remove the x86-specific (32bit) variant of System.Atomic_Counters,
because the __atomic builtins work fine on all x86 CPUs except for i386,
where they can be provided by libatomic (when compiling with
-march=i386).

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* Makefile.rtl (X86_TARGET_PAIRS): Use __builtin variant of
System.Atomic_Counters.
* libgnat/s-atocou__x86.adb: Remove.diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Makefile.rtl
--- a/gcc/ada/Makefile.rtl
+++ b/gcc/ada/Makefile.rtl
@@ -898,7 +898,7 @@ ATOMICS_BUILTINS_TARGET_PAIRS = \
 
 X86_TARGET_PAIRS = \
   a-nuauco.adshttp://www.gnu.org/licenses/>.  --
---  --
--- GNAT was originally developed  by the GNAT team at  New York University. --
--- Extensive contributions were provided by Ada Core Technologies Inc.  --
---  --
---
-
---  This implementation of the package for x86 processor. GCC can't generate
---  code for atomic builtins for 386 CPU. Only increment/decrement instructions
---  are supported, thus this implementaton uses machine code insertions to
---  access the necessary instructions.
-
-with System.Machine_Code;
-
-package body System.Atomic_Counters is
-
-   --  Add comments showing in normal asm language what we generate???
-
-   ---
-   -- Decrement --
-   ---
-
-   function Decrement (Item : aliased in out Atomic_Unsigned) return Boolean is
-  Aux : Boolean;
-
-   begin
-  System.Machine_Code.Asm
-(Template =>
-   "lock%; decl" & ASCII.HT & "%0" & ASCII.LF & ASCII.HT
- & "sete %1",
- Outputs  =>
-   (Atomic_Unsigned'Asm_Output ("=m", Item),
-Boolean'Asm_Output ("=qm", Aux)),
- Inputs   => Atomic_Unsigned'Asm_Input ("m", Item),
- Volatile => True);
-
-  return Aux;
-   end Decrement;
-
-   procedure Decrement (Item : aliased in out Atomic_Unsigned) is
-   begin
-  if Decrement (Item) then
- null;
-  end if;
-   end Decrement;
-
-   function Decrement (Item : in out Atomic_Counter) return Boolean is
-   begin
-  return Decrement (Item.Value);
-   end Decrement;
-
-   ---
-   -- Increment --
-   ---
-
-   procedure Increment (Item : aliased in out Atomic_Unsigned) is
-   begin
-  System.Machine_Code.Asm
-(Template => "lock%; incl" & ASCII.HT & "%0",
- Outputs  => Atomic_Unsigned'Asm_Output ("=m", Item),
- Inputs   => Atomic_Unsigned'Asm_Input ("m", Item),
- Volatile => True);
-   end Increment;
-
-   procedure Increment (Item : in out Atomic_Counter) is
-   begin
-  Increment (Item.Value);
-   end Increment;
-
-   
-   -- Initialize --
-   
-
-   procedure Initialize (Item : out Atomic_Counter) is
-   begin
-  Item.Value := 1;
-   end Initialize;
-
-   
-   -- Is_One --
-   
-
-   function Is_One (Item : Atomic_Counter) return Boolean is
-   begin
-  return Item.Value = 1;
-   end Is_One;
-
-end System.Atomic_Counters;




[Ada] Document LLVM-specific flags

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Add documentation for new -gnatd_u and old -gnatd_R flags used for GNAT
LLVM and its CCG.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* debug.adb: Add documentation for new -gnatd_u and old -gnatd_R
flags used for GNAT LLVM and its CCG.diff --git a/gcc/ada/debug.adb b/gcc/ada/debug.adb
--- a/gcc/ada/debug.adb
+++ b/gcc/ada/debug.adb
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 1992-2021, Free Software Foundation, Inc. --
+--  Copyright (C) 1992-2022, Free Software Foundation, Inc. --
 --  --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -159,7 +159,7 @@ package body Debug is
--  d_r
--  d_s  Stop elaboration checks on synchronous suspension
--  d_t  In LLVM-based CCG, dump LLVM IR after transformations are done
-   --  d_u
+   --  d_u  In LLVM-based CCG, dump flows
--  d_v  Enable additional checks and debug printouts in Atree
--  d_w
--  d_x  Disable inline expansion of Image attribute for enumeration types
@@ -183,7 +183,7 @@ package body Debug is
--  d_O
--  d_P
--  d_Q
-   --  d_R
+   --  d_R  For LLVM, dump the representation of records
--  d_S
--  d_T  Output trace information on invocation path recording
--  d_U  Disable prepending messages with "error:".
@@ -1001,6 +1001,9 @@ package body Debug is
--   after the pass that does transformations to the IR into a
--   filename ending with .trans.ll.
 
+   --  d_u  In the LLVM-based CCG, dump flows, both when originally created
+   --   and after transformations.
+
--  d_v  Enable additional checks and debug printouts in Atree
 
--  d_x  The compiler does not expand in line the Image attribute for user-
@@ -1024,6 +1027,9 @@ package body Debug is
--   it is checked, and the progress of the recursive trace through
--   elaboration calls at compile time.
 
+   --  d_R  In the LLVM backend, output the internal representation of
+   --   each record
+
--  d_T  The compiler outputs trace information to standard output whenever
--   an invocation path is recorded.
 




[Ada] Escalate pre-continuation messages from warnings to errors

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
When a compile-time constraint error is inserted into the AST, we emit
a main message (e.g. "value not in range of ...") and its continuation
(e.g. "Constraint_Error will be raised at run time"). When the main
message is emitted as a warning and the continuation is escalated into
an error, the main message should be escalated into an error as well.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* errout.adb (Error_Msg_Internal): Propagate warnings-as-error
flag from continuation message to its preceding messages.diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -1240,10 +1240,13 @@ package body Errout is
   or else
 Warning_Treated_As_Error (Get_Warning_Tag (Cur_Msg)));
 
-  --  Propagate Warn_Err to this message and preceding continuations
+  --  Propagate Warn_Err to this message and preceding continuations.
+  --  Likewise, propagate Is_Warning_Msg, because the current continued
+  --  message could have been escalated from warning to error.
 
   for J in reverse 1 .. Errors.Last loop
  Errors.Table (J).Warn_Err := Warn_Err;
+ Errors.Table (J).Warn := Is_Warning_Msg;
  exit when not Errors.Table (J).Msg_Cont;
   end loop;
 




[Ada] Code cleanups

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Use membership tests when possible

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch9.adb, gen_il-types.ads, make.adb, par-ch12.adb,
sem_ch13.adb: Use membership tests.diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -4394,7 +4394,7 @@ package body Exp_Ch9 is
   --  It would be better to encapsulate this as a routine in Exp_Dbug ???
 
   if Append_Char /= ' ' then
- if Append_Char = 'P' or Append_Char = 'N' then
+ if Append_Char in 'P' | 'N' then
 Add_Char_To_Name_Buffer (Append_Char);
 return Name_Find;
  else


diff --git a/gcc/ada/gen_il-types.ads b/gcc/ada/gen_il-types.ads
--- a/gcc/ada/gen_il-types.ads
+++ b/gcc/ada/gen_il-types.ads
@@ -577,8 +577,7 @@ package Gen_IL.Types is
   | N_Defining_Operator_Symbol;
 
subtype Opt_Abstract_Type is Opt_Type_Enum with
- Predicate => Opt_Abstract_Type = No_Type or
-   Opt_Abstract_Type in Abstract_Type;
+ Predicate => Opt_Abstract_Type in No_Type | Abstract_Type;
 
subtype Type_Boundaries is Type_Enum with
  Predicate => Type_Boundaries in


diff --git a/gcc/ada/make.adb b/gcc/ada/make.adb
--- a/gcc/ada/make.adb
+++ b/gcc/ada/make.adb
@@ -3765,7 +3765,7 @@ package body Make is
declare
   Arg : constant String := Argument (J);
begin
-  if Arg = "-cargs" or Arg = "-bargs" or Arg = "-largs" then
+  if Arg in "-cargs" | "-bargs" | "-largs" then
  In_Gnatmake_Switches := False;
 
   elsif Arg = "-margs" then


diff --git a/gcc/ada/par-ch12.adb b/gcc/ada/par-ch12.adb
--- a/gcc/ada/par-ch12.adb
+++ b/gcc/ada/par-ch12.adb
@@ -184,7 +184,7 @@ package body Ch12 is
if Token = Tok_Package then
   Append (P_Formal_Package_Declaration, Decls);
 
-   elsif Token = Tok_Procedure or Token = Tok_Function then
+   elsif Token in Tok_Procedure | Tok_Function then
   Append (P_Formal_Subprogram_Declaration, Decls);
 
else


diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -17125,9 +17125,8 @@ package body Sem_Ch13 is
 
procedure Validate_Literal_Aspect (Typ : Entity_Id; ASN : Node_Id) is
   A_Id: constant Aspect_Id := Get_Aspect_Id (ASN);
-  pragma Assert ((A_Id = Aspect_Integer_Literal) or
- (A_Id = Aspect_Real_Literal) or
- (A_Id = Aspect_String_Literal));
+  pragma Assert (A_Id in Aspect_Integer_Literal |
+ Aspect_Real_Literal | Aspect_String_Literal);
   Func_Name   : constant Node_Id := Expression (ASN);
   Overloaded  : Boolean := Is_Overloaded (Func_Name);
 




[Ada] Remove warnings-as-errors about constraints error in dead code

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
GNAT removes error messages attached to nodes within dead code; in
particular, within instances of generic units with alternative branches
for different generic formal types and parameters. Now this removal also
works for error messages that come from warnings about constraint errors
that have been escalated into hard errors due to -gnatwE switch.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* erroutc.ads, erroutc.adb (Is_Runtime_Raise): Global flag to
connect status of initial messages and their continuation; we
already have several flags like this.
(Error_Msg_Object): Add field Warn_Runtime_Raise to connect
error reporting (when problematic code is found) and removal
(when problematic code is determined to be dead).
* errout.adb (Error_Msg_Internal): Handle new field when
recording a continuation message; propagate status from
continuation to the preceding messages.
(To_Be_Removed): For dead code remove both simple warnings and
warnings about constraint errors that have been escalated to
hard errors.
(Set_Msg_Text): Recognize warnings about constraint errors that
are escalated to hard errors.
* errutil.adb (Error_Msg): Handle added field when recording a
new message.diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -1224,6 +1224,7 @@ package body Errout is
   Check   => Is_Check_Msg,
   Warn_Err=> False, -- reset below
   Warn_Chr=> Warning_Msg_Char,
+  Warn_Runtime_Raise  => Is_Runtime_Raise,
   Style   => Is_Style_Msg,
   Serious => Is_Serious_Error,
   Uncond  => Is_Unconditional_Msg,
@@ -1241,12 +1242,14 @@ package body Errout is
 Warning_Treated_As_Error (Get_Warning_Tag (Cur_Msg)));
 
   --  Propagate Warn_Err to this message and preceding continuations.
-  --  Likewise, propagate Is_Warning_Msg, because the current continued
-  --  message could have been escalated from warning to error.
+  --  Likewise, propagate Is_Warning_Msg and Is_Runtime_Raise, because the
+  --  current continued message could have been escalated from warning to
+  --  error.
 
   for J in reverse 1 .. Errors.Last loop
- Errors.Table (J).Warn_Err := Warn_Err;
- Errors.Table (J).Warn := Is_Warning_Msg;
+ Errors.Table (J).Warn_Err   := Warn_Err;
+ Errors.Table (J).Warn   := Is_Warning_Msg;
+ Errors.Table (J).Warn_Runtime_Raise := Is_Runtime_Raise;
  exit when not Errors.Table (J).Msg_Cont;
   end loop;
 
@@ -3290,13 +3293,17 @@ package body Errout is
--  not remove style messages here. They are warning messages
--  but not ones we want removed in this context.
 
-   and then Errors.Table (E).Warn
+   and then (Errors.Table (E).Warn
+   or else
+ Errors.Table (E).Warn_Runtime_Raise)
 
--  Don't remove unconditional messages
 
and then not Errors.Table (E).Uncond
 then
-   Warnings_Detected := Warnings_Detected - 1;
+   if Errors.Table (E).Warn then
+  Warnings_Detected := Warnings_Detected - 1;
+   end if;
 
if Errors.Table (E).Info then
   Warning_Info_Messages := Warning_Info_Messages - 1;
@@ -4072,7 +4079,8 @@ package body Errout is
if Is_Warning_Msg
  and then Warning_Mode = Treat_Run_Time_Warnings_As_Errors
then
-  Is_Warning_Msg := False;
+  Is_Warning_Msg   := False;
+  Is_Runtime_Raise := True;
end if;
 
if Is_Warning_Msg then


diff --git a/gcc/ada/erroutc.adb b/gcc/ada/erroutc.adb
--- a/gcc/ada/erroutc.adb
+++ b/gcc/ada/erroutc.adb
@@ -902,6 +902,7 @@ package body Erroutc is
  Is_Serious_Error := True;
  Is_Unconditional_Msg := False;
  Is_Warning_Msg   := False;
+ Is_Runtime_Raise := False;
 
  --  Check style message
 


diff --git a/gcc/ada/erroutc.ads b/gcc/ada/erroutc.ads
--- a/gcc/ada/erroutc.ads
+++ b/gcc/ada/erroutc.ads
@@ -71,6 +71,11 @@ package Erroutc is
--  Set True to indicate if current message is warning message (contains ?
--  or contains < and Error_Msg_Warn is True).
 
+   Is_Runtime_Raise : Boolean := False;
+   --  Set to True to indicate that the current message is a warning about a
+   --  constraint error that will be raised at runtime (contains [ and switch
+   --  -gnatwE was given).
+
Is_Info_Msg : Boolean := False;
--  Set True to indicate that the current message starts with the characters
--  "info: " and is to be treate

[Ada] Remove extra space in single object declarations

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Fix whitespace in single object declarations; violations detected with a
simple LKQL checker.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_aggr.adb, exp_attr.adb, exp_ch3.adb, exp_ch7.adb,
exp_dist.adb, exp_util.adb, freeze.adb, frontend.adb,
inline.adb, itypes.adb, lib-load.adb, lib-xref.adb,
libgnat/a-cfhase.adb, libgnat/a-cforse.adb,
libgnat/a-chtgbo.adb, libgnat/a-crdlli.adb,
libgnat/a-except.adb, libgnat/a-strfix.adb,
libgnat/a-textio.adb, libgnat/a-tienau.adb,
libgnat/a-tigeau.adb, libgnat/a-witeio.adb,
libgnat/a-wtenau.adb, libgnat/a-wtgeau.adb,
libgnat/a-ztenau.adb, libgnat/a-ztexio.adb,
libgnat/a-ztgeau.adb, libgnat/g-comlin.adb,
libgnat/g-debpoo.adb, libgnat/g-expect.adb,
libgnat/s-fileio.adb, libgnat/s-memory.adb, libgnat/s-mmap.adb,
libgnat/s-objrea.adb, libgnat/s-pehage.adb,
libgnat/s-regpat.adb, libgnat/s-shasto.adb,
libgnat/s-valued.adb, libgnat/s-valuef.adb, par-ch11.adb,
par-ch4.adb, par-ch6.adb, par-ch9.adb, par_sco.adb,
repinfo-input.adb, sem_cat.adb, sem_ch10.adb, sem_ch12.adb,
sem_ch13.adb, sem_ch4.adb, sem_eval.adb, sem_prag.adb,
sem_res.adb, sem_util.adb, sinput.adb, switch-c.adb: Fix style.diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -9375,7 +9375,7 @@ package body Exp_Aggr is
  ---
 
  function Get_Component_Val (N : Node_Id) return Uint is
-Val  : Uint;
+Val : Uint;
 
  begin
 --  We have to analyze the expression here before doing any further


diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -3784,7 +3784,7 @@ package body Exp_Attr is
   --
 
   when Attribute_From_Any => From_Any : declare
- Decls  : constant List_Id   := New_List;
+ Decls : constant List_Id := New_List;
 
   begin
  Rewrite (N,


diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -4139,7 +4139,7 @@ package body Exp_Ch3 is
Set_Static_Initialization (Proc_Id, Agg);
 
declare
-  Comp  : Node_Id;
+  Comp : Node_Id;
begin
   Comp := First (Component_Associations (Agg));
   while Present (Comp) loop


diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -4702,7 +4702,7 @@ package body Exp_Ch7 is
  (N   : Node_Id;
   Ref : Node_Id) return Node_Id
is
-  Loc  : constant Source_Ptr := Sloc (N);
+  Loc : constant Source_Ptr := Sloc (N);
 
begin
   --  For restricted run-time libraries (Ravenscar), tasks are


diff --git a/gcc/ada/exp_dist.adb b/gcc/ada/exp_dist.adb
--- a/gcc/ada/exp_dist.adb
+++ b/gcc/ada/exp_dist.adb
@@ -2908,7 +2908,7 @@ package body Exp_Dist is
-
 
procedure Expand_Calling_Stubs_Bodies (Unit_Node : Node_Id) is
-  Spec  : constant Node_Id := Specification (Unit_Node);
+  Spec : constant Node_Id := Specification (Unit_Node);
begin
   Add_Calling_Stubs_To_Declarations (Spec);
end Expand_Calling_Stubs_Bodies;


diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -8780,7 +8780,7 @@ package body Exp_Util is
--
 
function Is_Possibly_Unaligned_Object (N : Node_Id) return Boolean is
-  T  : constant Entity_Id := Etype (N);
+  T : constant Entity_Id := Etype (N);
 
begin
   --  If renamed object, apply test to underlying object


diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -2124,7 +2124,7 @@ package body Freeze is

 
procedure Check_Strict_Alignment (E : Entity_Id) is
-  Comp  : Entity_Id;
+  Comp : Entity_Id;
 
begin
   --  Bit-packed array types do not require strict alignment, even if they


diff --git a/gcc/ada/frontend.adb b/gcc/ada/frontend.adb
--- a/gcc/ada/frontend.adb
+++ b/gcc/ada/frontend.adb
@@ -539,7 +539,7 @@ begin
--  Initialize_Scalars, but others should be checked: as well???
 
declare
-  Item  : Node_Id;
+  Item : Node_Id;
 
begin
   Item := First (Context_Items (Cunit (Main_Unit)));


diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb
--- a/gcc/ada/inline.adb
+++ b/gcc/ada/inline.adb
@@ -2377,7 +2377,7 @@ package body Inline is
   
 
   function Copy_Return_Object (Obj_Decl : Node_Id) return Node_Id is
- Obj_Id  : constant Entity_Id := Defining_Entity (Obj_Decl);
+ Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl);
 
   begin
   

[Ada] Proof of System.Vectors.Boolean_Operations

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
This proves in SPARK the unit System.Vectors.Boolean_Operations.  The
specification models explicitly the array of Boolean represented by
Vectors.Vector, so that the result of functions can be specified by
expressing the relationship between input and output models.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-veboop.adb: Add ghost code for proof.
* libgnat/s-veboop.ads: Add specification.diff --git a/gcc/ada/libgnat/s-veboop.adb b/gcc/ada/libgnat/s-veboop.adb
--- a/gcc/ada/libgnat/s-veboop.adb
+++ b/gcc/ada/libgnat/s-veboop.adb
@@ -29,7 +29,17 @@
 --  --
 --
 
-package body System.Vectors.Boolean_Operations is
+--  Ghost code, loop invariants and assertions in this unit are meant for
+--  analysis only, not for run-time checking, as it would be too costly
+--  otherwise. This is enforced by setting the assertion policy to Ignore.
+
+pragma Assertion_Policy (Ghost  => Ignore,
+ Loop_Invariant => Ignore,
+ Assert => Ignore);
+
+package body System.Vectors.Boolean_Operations
+  with SPARK_Mode
+is
 
SU : constant := Storage_Unit;
--  Convenient short hand, used throughout
@@ -76,7 +86,26 @@ package body System.Vectors.Boolean_Operations is
---
 
function "not" (Item : Vectors.Vector) return Vectors.Vector is
+
+  procedure Prove_Not (Result : Vectors.Vector)
+  with
+Ghost,
+Pre  => Valid (Item)
+  and then Result = (Item xor True_Val),
+Post => Valid (Result)
+  and then (for all J in 1 .. Vector_Boolean_Size =>
+  Model (Result) (J) = not Model (Item) (J));
+
+  procedure Prove_Not (Result : Vectors.Vector) is
+  begin
+ for J in 1 .. Vector_Boolean_Size loop
+pragma Assert
+  (Element (Result, J) = 1 - Element (Item, J));
+ end loop;
+  end Prove_Not;
+
begin
+  Prove_Not (Item xor True_Val);
   return Item xor True_Val;
end "not";
 
@@ -90,7 +119,32 @@ package body System.Vectors.Boolean_Operations is
end Nand;
 
function Nand (Left, Right : Vectors.Vector) return Vectors.Vector is
+
+  procedure Prove_And (Result : Vectors.Vector)
+  with
+Ghost,
+Pre  => Valid (Left)
+  and then Valid (Right)
+  and then Result = (Left and Right),
+  Post => Valid (Result)
+and then (for all J in 1 .. Vector_Boolean_Size =>
+Model (Result) (J) =
+  (Model (Left) (J) and Model (Right) (J)));
+
+  procedure Prove_And (Result : Vectors.Vector) is
+  begin
+ for J in 1 .. Vector_Boolean_Size loop
+pragma Assert
+  (Element (Result, J) =
+ (if Element (Left, J) = 1
+and Element (Right, J) = 1
+  then 1
+  else 0));
+ end loop;
+  end Prove_And;
+
begin
+  Prove_And (Left and Right);
   return not (Left and Right);
end Nand;
 
@@ -104,7 +158,32 @@ package body System.Vectors.Boolean_Operations is
end Nor;
 
function Nor (Left, Right : Vectors.Vector) return Vectors.Vector is
+
+  procedure Prove_Or (Result : Vectors.Vector)
+  with
+Ghost,
+Pre  => Valid (Left)
+  and then Valid (Right)
+  and then Result = (Left or Right),
+  Post => Valid (Result)
+and then (for all J in 1 .. Vector_Boolean_Size =>
+Model (Result) (J) =
+  (Model (Left) (J) or Model (Right) (J)));
+
+  procedure Prove_Or (Result : Vectors.Vector) is
+  begin
+ for J in 1 .. Vector_Boolean_Size loop
+pragma Assert
+  (Element (Result, J) =
+ (if Element (Left, J) = 1
+or Element (Right, J) = 1
+  then 1
+  else 0));
+ end loop;
+  end Prove_Or;
+
begin
+  Prove_Or (Left or Right);
   return not (Left or Right);
end Nor;
 
@@ -118,7 +197,32 @@ package body System.Vectors.Boolean_Operations is
end Nxor;
 
function Nxor (Left, Right : Vectors.Vector) return Vectors.Vector is
+
+  procedure Prove_Xor (Result : Vectors.Vector)
+  with
+Ghost,
+Pre  => Valid (Left)
+  and then Valid (Right)
+  and then Result = (Left xor Right),
+  Post => Valid (Result)
+and then (for all J in 1 .. Vector_Boolean_Size =>
+Model (Result) (J) =
+  (Model (Left) (J) xor Model (Right) (J)));
+
+  procedure Prove_Xor (Result : Vectors.Vector) is
+  begin
+ for J in 1 .. Vector_Boolean_Size loop
+pragma Assert
+  (Element (Resul

[Ada] Conformance error on protected subp with anonymous-access-to-tagged formal

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
The compiler incorrectly rejected a protected subprogram with a formal
of an anonymous access type that designates a tagged type when the
protected type extends an interface and the formal's designated type (a
different type) is declared immediately within the same scope as the
protected type; an error is issued about the declaration and body not
conforming. This occurs in conjunction with the (nonprotected) wrapper
subprogram created for the protected subprogram, which is declared in
the scope enclosing the protected type. It appears to the compiler that
the type of the access formal of the wrapper subprogram doesn't conform
with the declaration, due to null exclusions being different. The flag
Can_Never_Be_Null gets set on one formal parameter and not the other,
because Check_Controlling_Type sees that the formal's designated type is
declared in the same scope as the wrapper subprogram, and as a result
decides that the access formal is a controlling formal when it really
isn't (so sets Can_Never_Be_Null since controlling access-to-tagged
formals are defined to exclude null).

This problem is fixed by adding a special check in
Check_Controlling_Type to prevent treating formals of
anonymous-access-to-tagged types as controlling when the subprogram has
an associated protected subprogram and the tagged type is not the record
type associated with the protected subprogram's enclosing protected
type.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_disp.adb (Check_Controlling_Type): Add test for the case
where Subp is a subprogram associated with a protected
subprogram and return Empty, unless Tagged_Type is the
corresponding record type of the protected type.diff --git a/gcc/ada/sem_disp.adb b/gcc/ada/sem_disp.adb
--- a/gcc/ada/sem_disp.adb
+++ b/gcc/ada/sem_disp.adb
@@ -478,6 +478,29 @@ package body Sem_Disp is
   if No (Tagged_Type) or else Is_Class_Wide_Type (Tagged_Type) then
  return Empty;
 
+  --  In the special case of a protected subprogram of a tagged protected
+  --  type that has a formal of a tagged type (or access formal whose type
+  --  designates a tagged type), such a formal is not controlling unless
+  --  it's of the protected type's corresponding record type. The latter
+  --  can occur for the special wrapper subprograms created for protected
+  --  subprograms. Such subprograms may occur in the same scope where some
+  --  formal's tagged type is declared, and we don't want formals of that
+  --  tagged type being marked as controlling, for one thing because they
+  --  aren't controlling from the language point of view, but also because
+  --  this can cause errors for access formals when conformance is checked
+  --  between the spec and body of the protected subprogram (null-exclusion
+  --  status of the formals may be set differently, which is the case that
+  --  led to adding this check).
+
+  elsif Is_Subprogram (Subp)
+and then Present (Protected_Subprogram (Subp))
+and then Ekind (Scope (Protected_Subprogram (Subp))) = E_Protected_Type
+and then
+  Base_Type (Tagged_Type)
+/= Corresponding_Record_Type (Scope (Protected_Subprogram (Subp)))
+  then
+ return Empty;
+
   --  The dispatching type and the primitive operation must be defined in
   --  the same scope, except in the case of internal operations and formal
   --  abstract subprograms.




[Ada] Tune inconsistent message about fixed-lower-bound and -gnatX

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Use a dedicated routine to complain about the missing -gnatX switch.

Previously the message was:

  error: fixed-lower-bound array is an extension feature; use -gnatX

and after this change it is:

  error: fixed-lower-bound array is a GNAT specific extension
  error: unit must be compiled with -gnatX switch

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* par-ch3.adb (P_Array_Type_Definition): Use
Error_Msg_GNAT_Extension.diff --git a/gcc/ada/par-ch3.adb b/gcc/ada/par-ch3.adb
--- a/gcc/ada/par-ch3.adb
+++ b/gcc/ada/par-ch3.adb
@@ -2788,12 +2788,7 @@ package body Ch3 is
 else
P_Index_Subtype_Def_With_Fixed_Lower_Bound (Subtype_Mark_Node);
 
-   if not Extensions_Allowed then
-  Error_Msg_N
-("fixed-lower-bound array is an extension feature; "
-   & "use -gnatX",
- Token_Node);
-   end if;
+   Error_Msg_GNAT_Extension ("fixed-lower-bound array");
 end if;
 
 exit when Token = Tok_Right_Paren or else Token = Tok_Of;
@@ -2862,12 +2857,7 @@ package body Ch3 is
  P_Index_Subtype_Def_With_Fixed_Lower_Bound
(Subtype_Mark_Node);
 
- if not Extensions_Allowed then
-Error_Msg_N
-  ("fixed-lower-bound array is an extension feature; "
- & "use -gnatX",
-   Token_Node);
- end if;
+ Error_Msg_GNAT_Extension ("fixed-lower-bound array");
   end if;
 
   exit when Token = Tok_Right_Paren or else Token = Tok_Of;
@@ -3369,12 +3359,7 @@ package body Ch3 is
 --  later during analysis), and scan to the next token.
 
 if Token = Tok_Box then
-   if not Extensions_Allowed then
-  Error_Msg_N
-("fixed-lower-bound array is an extension feature; "
-   & "use -gnatX",
- Expr_Node);
-   end if;
+   Error_Msg_GNAT_Extension ("fixed-lower-bound array");
 
Expr_Node := Empty;
Scan;




[Ada] Remove redundant initialization of Test_And_Set_Flag object

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
When expanding exception declarations we explicitly initialized the
System.Atomic_Operations.Test_And_Set.Test_And_Set_Flag object with 0.
This was redundant, because the Test_And_Set_Flag type has aspect
Default_Value => 0. It is better to not duplicate this constant in the
GNAT code, in case that the default value is changed at some point.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch11.adb (Expand_N_Exception_Declaration): Remove explicit
initialization of the exceptF object.diff --git a/gcc/ada/exp_ch11.adb b/gcc/ada/exp_ch11.adb
--- a/gcc/ada/exp_ch11.adb
+++ b/gcc/ada/exp_ch11.adb
@@ -1089,7 +1089,7 @@ package body Exp_Ch11 is
--  (protecting test only needed if not at library level)
 
-- exceptF : aliased System.Atomic_Operations.Test_And_Set.
-   -- .Test_And_Set_Flag := 0; --  static data
+   -- .Test_And_Set_Flag; --  static data
-- if not Atomic_Test_And_Set (exceptF) then
--Register_Exception (except'Unrestricted_Access);
-- end if;
@@ -1321,9 +1321,7 @@ package body Exp_Ch11 is
   Defining_Identifier => Flag_Id,
   Aliased_Present => True,
   Object_Definition   =>
-New_Occurrence_Of (RTE (RE_Test_And_Set_Flag), Loc),
-  Expression  =>
-Make_Integer_Literal (Loc, 0));
+New_Occurrence_Of (RTE (RE_Test_And_Set_Flag), Loc));
else
   Flag_Decl :=
 Make_Object_Declaration (Loc,




[Ada] Adapt ghost code to maintain proof

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Add two assertions that are now required for the proof of System.Exp_Mod
to go through.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-expmod.adb (Exp_Modular): Add assertions.diff --git a/gcc/ada/libgnat/s-expmod.adb b/gcc/ada/libgnat/s-expmod.adb
--- a/gcc/ada/libgnat/s-expmod.adb
+++ b/gcc/ada/libgnat/s-expmod.adb
@@ -278,6 +278,7 @@ is
  (Big (Result) * Big (Factor) ** (Exp - 1),
   Big (Left) ** Right));
Lemma_Exp_Expand (Big (Factor), Exp - 1);
+   pragma Assert (Exp / 2 = (Exp - 1) / 2);
 end if;
 
 Lemma_Exp_Expand (Big (Factor), Exp);
@@ -286,6 +287,8 @@ is
 exit when Exp = 0;
 
 Rest := Big (Factor) ** Exp;
+pragma Assert (Equal_Modulo
+  (Big (Result) * (Rest * Rest), Big (Left) ** Right));
 Lemma_Exp_Mod (Big (Factor) * Big (Factor), Exp, Big (Modulus));
 pragma Assert
   ((Big (Factor) * Big (Factor)) ** Exp = Rest * Rest);




[Ada] Proof of unit System.Case_Util

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
This unit is needed to prove System.Val_Bool, as it is used in
System.Val_Util called from System.Val_Bool. Add contracts that reflect
the implementation, as we don't want these units to depend on units
under Ada.Characters.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-casuti.adb: Add ghost code.
* libgnat/s-casuti.ads: Add contracts.diff --git a/gcc/ada/libgnat/s-casuti.adb b/gcc/ada/libgnat/s-casuti.adb
--- a/gcc/ada/libgnat/s-casuti.adb
+++ b/gcc/ada/libgnat/s-casuti.adb
@@ -29,8 +29,17 @@
 --  --
 --
 
-package body System.Case_Util is
+--  Ghost code, loop invariants and assertions in this unit are meant for
+--  analysis only, not for run-time checking, as it would be too costly
+--  otherwise. This is enforced by setting the assertion policy to Ignore.
 
+pragma Assertion_Policy (Ghost  => Ignore,
+ Loop_Invariant => Ignore,
+ Assert => Ignore);
+
+package body System.Case_Util
+  with SPARK_Mode
+is
--
-- To_Lower --
--
@@ -53,6 +62,9 @@ package body System.Case_Util is
begin
   for J in A'Range loop
  A (J) := To_Lower (A (J));
+
+ pragma Loop_Invariant
+   (for all K in A'First .. J => A (K) = To_Lower (A'Loop_Entry (K)));
   end loop;
end To_Lower;
 
@@ -78,6 +90,15 @@ package body System.Case_Util is
 A (J) := To_Lower (A (J));
  end if;
 
+ pragma Loop_Invariant
+   (for all K in A'First .. J =>
+  (if K = A'First
+ or else A'Loop_Entry (K - 1) = '_'
+   then
+ A (K) = To_Upper (A'Loop_Entry (K))
+   else
+ A (K) = To_Lower (A'Loop_Entry (K;
+
  Ucase := A (J) = '_';
   end loop;
end To_Mixed;
@@ -111,6 +132,9 @@ package body System.Case_Util is
begin
   for J in A'Range loop
  A (J) := To_Upper (A (J));
+
+ pragma Loop_Invariant
+   (for all K in A'First .. J => A (K) = To_Upper (A'Loop_Entry (K)));
   end loop;
end To_Upper;
 


diff --git a/gcc/ada/libgnat/s-casuti.ads b/gcc/ada/libgnat/s-casuti.ads
--- a/gcc/ada/libgnat/s-casuti.ads
+++ b/gcc/ada/libgnat/s-casuti.ads
@@ -34,29 +34,98 @@
 --  This package provides simple casing functions that do not require the
 --  overhead of the full casing tables found in Ada.Characters.Handling.
 
-package System.Case_Util is
-   pragma Pure;
+--  Preconditions in this unit are meant for analysis only, not for run-time
+--  checking, so that the expected exceptions are raised. This is enforced by
+--  setting the corresponding assertion policy to Ignore. Postconditions and
+--  contract cases should not be executed at runtime as well, in order not to
+--  slow down the execution of these functions.
 
+pragma Assertion_Policy (Pre=> Ignore,
+ Post   => Ignore,
+ Contract_Cases => Ignore,
+ Ghost  => Ignore);
+
+package System.Case_Util
+  with Pure, SPARK_Mode
+is
--  Note: all the following functions handle the full Latin-1 set
 
-   function To_Upper (A : Character) return Character;
+   function To_Upper (A : Character) return Character
+   with
+ Post => (declare
+A_Val : constant Natural := Character'Pos (A);
+  begin
+(if A in 'a' .. 'z'
+   or else A_Val in 16#E0# .. 16#F6#
+   or else A_Val in 16#F8# .. 16#FE#
+ then
+   To_Upper'Result = Character'Val (A_Val - 16#20#)
+ else
+   To_Upper'Result = A));
--  Converts A to upper case if it is a lower case letter, otherwise
--  returns the input argument unchanged.
 
-   procedure To_Upper (A : in out String);
-   function To_Upper (A : String) return String;
+   procedure To_Upper (A : in out String)
+   with
+ Post => (for all J in A'Range => A (J) = To_Upper (A'Old (J)));
+
+   function To_Upper (A : String) return String
+   with
+ Post => To_Upper'Result'First = A'First
+   and then To_Upper'Result'Last = A'Last
+   and then (for all J in A'Range =>
+   To_Upper'Result (J) = To_Upper (A (J)));
--  Folds all characters of string A to upper case
 
-   function To_Lower (A : Character) return Character;
+   function To_Lower (A : Character) return Character
+   with
+ Post => (declare
+A_Val : constant Natural := Character'Pos (A);
+  begin
+(if A in 'A' .. 'Z'
+   or else A_Val in 16#C0# .. 16#D6#
+   or else A_Val in 16#D8# .. 16#DE#
+ then
+   To_Lower'Result = Character'Val (A_Val + 16#20#)
+  

[Ada] Fix check for implicit allocation of dynamic objects

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
We check for dynamic objects by recursively examining record components.
We should thus first check if the component is a record type before
checking if it is a `Discriminated_Size` which will be false for all non
array-type components.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch3.adb (Check_Dynamic_Object): Swap check order.diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -3831,6 +3831,9 @@ package body Sem_Ch3 is
then
   null;
 
+   elsif Is_Record_Type (Etype (Comp)) then
+  Check_Dynamic_Object (Etype (Comp));
+
elsif not Discriminated_Size (Comp)
  and then Comes_From_Source (Comp)
then
@@ -3838,8 +3841,6 @@ package body Sem_Ch3 is
 ("component& of non-static size will violate restriction "
  & "No_Implicit_Heap_Allocation?", N, Comp);
 
-   elsif Is_Record_Type (Etype (Comp)) then
-  Check_Dynamic_Object (Etype (Comp));
end if;
 
Next_Component (Comp);




[Ada] Reuse Make_Temporary where possible

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Simplify:

  Make_Defining_Identifier (Loc, Chars => New_Internal_Name (C));

into:

  Make_Temporary (Loc, C);

Code cleanup related to creation of itypes for allocators in GNATprove
mode; semantics is unaffected.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch7.adb (Set_Block_Elab_Proc, Unnest_Block, Unnest_Loop,
Unnest_Statement_List): Simplify with Make_Temporary.
* exp_put_image.adb (Build_Image_Call): Likewise.
* inline.adb (Generate_Subprogram_Body): Likewise.
* sem_ch13.adb (Build_Predicate_Functions): Likewise.
* sem_util.adb (New_Copy_Separate_List): Likewise.diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -4737,8 +4737,7 @@ package body Exp_Ch7 is
   procedure Set_Block_Elab_Proc is
   begin
  if No (Block_Elab_Proc) then
-Block_Elab_Proc :=
-  Make_Defining_Identifier (Loc, Chars => New_Internal_Name ('I'));
+Block_Elab_Proc := Make_Temporary (Loc, 'I');
  end if;
   end Set_Block_Elab_Proc;
 
@@ -9964,9 +9963,7 @@ package body Exp_Ch7 is
   Local_Scop := Entity (Identifier (Decl));
   Ent := First_Entity (Local_Scop);
 
-  Local_Proc :=
-Make_Defining_Identifier (Loc,
-  Chars => New_Internal_Name ('P'));
+  Local_Proc := Make_Temporary (Loc, 'P');
 
   Local_Body :=
 Make_Subprogram_Body (Loc,
@@ -10114,9 +10111,7 @@ package body Exp_Ch7 is
   Local_Scop := Entity (Identifier (Loop_Stmt));
   Ent := First_Entity (Local_Scop);
 
-  Local_Proc :=
-Make_Defining_Identifier (Loc,
-  Chars => New_Internal_Name ('P'));
+  Local_Proc := Make_Temporary (Loc, 'P');
 
   Local_Body :=
 Make_Subprogram_Body (Loc,
@@ -10170,9 +10165,7 @@ package body Exp_Ch7 is
   New_Stmts  : constant List_Id := Empty_List;
 
begin
-  Local_Proc :=
-Make_Defining_Identifier (Loc,
-  Chars => New_Internal_Name ('P'));
+  Local_Proc := Make_Temporary (Loc, 'P');
 
   Local_Body :=
 Make_Subprogram_Body (Loc,


diff --git a/gcc/ada/exp_put_image.adb b/gcc/ada/exp_put_image.adb
--- a/gcc/ada/exp_put_image.adb
+++ b/gcc/ada/exp_put_image.adb
@@ -1072,7 +1072,7 @@ package body Exp_Put_Image is
   Loc : constant Source_Ptr := Sloc (N);
   U_Type : constant Entity_Id := Underlying_Type (Entity (Prefix (N)));
   Sink_Entity : constant Entity_Id :=
-Make_Defining_Identifier (Loc, Chars => New_Internal_Name ('S'));
+Make_Temporary (Loc, 'S');
   Sink_Decl : constant Node_Id :=
 Make_Object_Declaration (Loc,
   Defining_Identifier => Sink_Entity,
@@ -1090,7 +1090,7 @@ package body Exp_Put_Image is
 New_Occurrence_Of (Sink_Entity, Loc),
 Image_Prefix));
   Result_Entity : constant Entity_Id :=
-Make_Defining_Identifier (Loc, Chars => New_Internal_Name ('R'));
+Make_Temporary (Loc, 'R');
   Result_Decl : constant Node_Id :=
 Make_Object_Declaration (Loc,
   Defining_Identifier => Result_Entity,


diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb
--- a/gcc/ada/inline.adb
+++ b/gcc/ada/inline.adb
@@ -2189,7 +2189,7 @@ package body Inline is
 --  conflicts when the non-inlined body N is analyzed.
 
 Set_Defining_Unit_Name (Specification (Body_To_Inline),
-   Make_Defining_Identifier (Sloc (N), New_Internal_Name ('P')));
+   Make_Temporary (Sloc (N), 'P'));
 Set_Corresponding_Spec (Body_To_Inline, Empty);
  end Generate_Subprogram_Body;
 


diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -10666,8 +10666,7 @@ package body Sem_Ch13 is
--  what happens if a return appears within a return.
 
BTemp :=
- Make_Defining_Identifier (Loc,
-   Chars => New_Internal_Name ('B'));
+ Make_Temporary (Loc, 'B');
 
FBody :=
  Make_Subprogram_Body (Loc,


diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -23435,8 +23435,7 @@ package body Sem_Util is
 Elmt := First_Elmt (Decls);
 while Present (Elmt) loop
Decl  := Node (Elmt);
-   New_E := Make_Defining_Identifier (Sloc (Decl),
-  New_Internal_Name ('P'));
+   New_E := Make_Temporary (Sloc (Decl), 'P');
 
if Nkind (Decl) = N_Expression_Function then
   Decl := Specification (Decl);




[Ada] Fix incomplete debug info for derived packed array type

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
The front-end was copying the Packed_Array_Impl_Type of the parent onto
the derived type, which fools the logic of the debug back-end.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch3.adb (Analyze_Subtype_Declaration): In the case of an array
copy Packed_Array_Impl_Type manually here.
(Copy_Array_Subtype_Attributes): Do not copy it here.diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -5512,6 +5512,7 @@ package body Sem_Ch3 is
 when Array_Kind =>
Mutate_Ekind  (Id, E_Array_Subtype);
Copy_Array_Subtype_Attributes (Id, T);
+   Set_Packed_Array_Impl_Type(Id, Packed_Array_Impl_Type (T));
 
 when Decimal_Fixed_Point_Kind =>
Mutate_Ekind (Id, E_Decimal_Fixed_Point_Subtype);
@@ -14972,6 +14973,9 @@ package body Sem_Ch3 is
-- Copy_Array_Subtype_Attributes --
---
 
+   --  Note that we used to copy Packed_Array_Impl_Type too here, but we now
+   --  let it be recreated during freezing for the sake of better debug info.
+
procedure Copy_Array_Subtype_Attributes (T1, T2 : Entity_Id) is
begin
   Set_Size_Info (T1, T2);
@@ -14989,7 +14993,6 @@ package body Sem_Ch3 is
   Set_Convention  (T1, Convention  (T2));
   Set_Is_Limited_Composite(T1, Is_Limited_Composite(T2));
   Set_Is_Private_Composite(T1, Is_Private_Composite(T2));
-  Set_Packed_Array_Impl_Type  (T1, Packed_Array_Impl_Type  (T2));
end Copy_Array_Subtype_Attributes;
 
---




[Ada] Remove unnecessary block in code for expansion of allocators

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Cleanup related to handling of allocators in GNATprove; semantics is
unaffected.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch4.adb (Size_In_Storage_Elements): Remove unnecessary
DECLARE block; refill code and comments.diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -4345,116 +4345,110 @@ package body Exp_Ch4 is
   --
 
   function Size_In_Storage_Elements (E : Entity_Id) return Node_Id is
+ Idx : Node_Id := First_Index (E);
+ Len : Node_Id;
+ Res : Node_Id := Empty;
+
   begin
  --  Logically this just returns E'Max_Size_In_Storage_Elements.
- --  However, the reason for the existence of this function is
- --  to construct a test for sizes too large, which means near the
- --  32-bit limit on a 32-bit machine, and precisely the trouble
- --  is that we get overflows when sizes are greater than 2**31.
+ --  However, the reason for the existence of this function is to
+ --  construct a test for sizes too large, which means near the 32-bit
+ --  limit on a 32-bit machine, and precisely the trouble is that we
+ --  get overflows when sizes are greater than 2**31.
 
  --  So what we end up doing for array types is to use the expression:
 
  --number-of-elements * component_type'Max_Size_In_Storage_Elements
 
  --  which avoids this problem. All this is a bit bogus, but it does
- --  mean we catch common cases of trying to allocate arrays that
- --  are too large, and which in the absence of a check results in
+ --  mean we catch common cases of trying to allocate arrays that are
+ --  too large, and which in the absence of a check results in
  --  undetected chaos ???
 
- declare
-Idx : Node_Id := First_Index (E);
-Len : Node_Id;
-Res : Node_Id := Empty;
+ for J in 1 .. Number_Dimensions (E) loop
 
- begin
-for J in 1 .. Number_Dimensions (E) loop
+if not Is_Modular_Integer_Type (Etype (Idx)) then
+   Len :=
+ Make_Attribute_Reference (Loc,
+   Prefix => New_Occurrence_Of (E, Loc),
+   Attribute_Name => Name_Length,
+   Expressions=> New_List (Make_Integer_Literal (Loc, J)));
 
-   if not Is_Modular_Integer_Type (Etype (Idx)) then
-  Len :=
-Make_Attribute_Reference (Loc,
-  Prefix => New_Occurrence_Of (E, Loc),
-  Attribute_Name => Name_Length,
-  Expressions=> New_List
-  (Make_Integer_Literal (Loc, J)));
+--  For indexes that are modular types we cannot generate code to
+--  compute 'Length since for large arrays 'Last -'First + 1 causes
+--  overflow; therefore we compute 'Last - 'First (which is not the
+--  exact number of components but it is valid for the purpose of
+--  this runtime check on 32-bit targets).
 
-   --  For indexes that are modular types we cannot generate code
-   --  to compute 'Length since for large arrays 'Last -'First + 1
-   --  causes overflow; therefore we compute 'Last - 'First (which
-   --  is not the exact number of components but it is valid for
-   --  the purpose of this runtime check on 32-bit targets).
+else
+   declare
+  Len_Minus_1_Expr : Node_Id;
+  Test_Gt  : Node_Id;
 
-   else
-  declare
- Len_Minus_1_Expr : Node_Id;
- Test_Gt  : Node_Id;
+   begin
+  Test_Gt :=
+Make_Op_Gt (Loc,
+  Make_Attribute_Reference (Loc,
+Prefix => New_Occurrence_Of (E, Loc),
+Attribute_Name => Name_Last,
+Expressions=>
+  New_List (Make_Integer_Literal (Loc, J))),
+  Make_Attribute_Reference (Loc,
+Prefix => New_Occurrence_Of (E, Loc),
+Attribute_Name => Name_First,
+Expressions=>
+  New_List (Make_Integer_Literal (Loc, J;
 
-  begin
- Test_Gt :=
-   Make_Op_Gt (Loc,
- Make_Attribute_Reference (Loc,
-   Prefix => New_Occurrence_Of (E, Loc),
-   Attribute_Name => Name_Last,
-   Expressions=>
- New_List (Make_Intege

[Ada] PR ada/79724

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Fix handling of e.g. gcc-11 in Osint.Program_Name.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

PR ada/79724
* osint.adb (Program_Name): Fix handling of suffixes.diff --git a/gcc/ada/osint.adb b/gcc/ada/osint.adb
--- a/gcc/ada/osint.adb
+++ b/gcc/ada/osint.adb
@@ -2279,8 +2279,6 @@ package body Osint is
 
   Find_Program_Name;
 
-  Start_Of_Suffix := Name_Len + 1;
-
   --  Find the target prefix if any, for the cross compilation case.
   --  For instance in "powerpc-elf-gcc" the target prefix is
   --  "powerpc-elf-"
@@ -2304,9 +2302,7 @@ package body Osint is
  end if;
   end loop;
 
-  if End_Of_Prefix > 1 then
- Start_Of_Suffix := End_Of_Prefix + Prog'Length + 1;
-  end if;
+  Start_Of_Suffix := End_Of_Prefix + Prog'Length + 1;
 
   --  Create the new program name
 




[Ada] Recover proof of Ada.Strings.Fixed with assertions

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Changes in GNATprove make it necessary to add assertions here.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/a-strfix.adb (Insert, Overwrite): Add assertions.diff --git a/gcc/ada/libgnat/a-strfix.adb b/gcc/ada/libgnat/a-strfix.adb
--- a/gcc/ada/libgnat/a-strfix.adb
+++ b/gcc/ada/libgnat/a-strfix.adb
@@ -384,6 +384,10 @@ package body Ada.Strings.Fixed with SPARK_Mode is
Source (Source'First .. Before - 1);
  Result (Front + 1 .. Front + New_Item'Length) :=
New_Item;
+
+ pragma Assert
+   (Result (1 .. Before - Source'First)
+= Source (Source'First .. Before - 1));
  pragma Assert
(Result
   (Before - Source'First + 1
@@ -558,15 +562,21 @@ package body Ada.Strings.Fixed with SPARK_Mode is
 if Position <= Source'Last - New_Item'Length then
Result (Front + New_Item'Length + 1 .. Result'Last) :=
  Source (Position + New_Item'Length .. Source'Last);
+
+   pragma Assert
+ (Result
+(Position - Source'First + New_Item'Length + 1
+ .. Result'Last)
+  = Source (Position + New_Item'Length .. Source'Last));
 end if;
 
 pragma Assert
   (if Position <= Source'Last - New_Item'Length
then
   Result
- (Position - Source'First + New_Item'Length + 1
-  .. Result'Last)
-   = Source (Position + New_Item'Length .. Source'Last));
+(Position - Source'First + New_Item'Length + 1
+ .. Result'Last)
+  = Source (Position + New_Item'Length .. Source'Last));
  end return;
   end;
end Overwrite;




[Ada] Deconstruct a VMS utility routine which is only used by GNATprove

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Routine Compile_Time_Known_Value_Or_Aggr was needed for VMS
compatibility, which was deconstructed in 2014. This routine was dead
since then, until it got accidentally reused by GNATprove to pretty
print counterexamples.

Cleanup related to handling of compile-time-known null values in
GNATprove.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_eval.ads (Compile_Time_Known_Value_Or_Aggr): Remove spec.
* sem_eval.adb (Compile_Time_Known_Value_Or_Aggr): Remove body.diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
--- a/gcc/ada/sem_eval.adb
+++ b/gcc/ada/sem_eval.adb
@@ -1916,90 +1916,6 @@ package body Sem_Eval is
  return False;
end Compile_Time_Known_Value;
 
-   --
-   -- Compile_Time_Known_Value_Or_Aggr --
-   --
-
-   function Compile_Time_Known_Value_Or_Aggr (Op : Node_Id) return Boolean is
-   begin
-  --  If we have an entity name, then see if it is the name of a constant
-  --  and if so, test the corresponding constant value, or the name of
-  --  an enumeration literal, which is always a constant.
-
-  if Is_Entity_Name (Op) then
- declare
-E : constant Entity_Id := Entity (Op);
-V : Node_Id;
-
- begin
-if Ekind (E) = E_Enumeration_Literal then
-   return True;
-
-elsif Ekind (E) /= E_Constant then
-   return False;
-
-else
-   V := Constant_Value (E);
-   return Present (V)
- and then Compile_Time_Known_Value_Or_Aggr (V);
-end if;
- end;
-
-  --  We have a value, see if it is compile-time-known
-
-  else
- if Compile_Time_Known_Value (Op) then
-return True;
-
- elsif Nkind (Op) = N_Aggregate then
-
-if Present (Expressions (Op)) then
-   declare
-  Expr : Node_Id;
-   begin
-  Expr := First (Expressions (Op));
-  while Present (Expr) loop
- if not Compile_Time_Known_Value_Or_Aggr (Expr) then
-return False;
- else
-Next (Expr);
- end if;
-  end loop;
-   end;
-end if;
-
-if Present (Component_Associations (Op)) then
-   declare
-  Cass : Node_Id;
-
-   begin
-  Cass := First (Component_Associations (Op));
-  while Present (Cass) loop
- if not
-   Compile_Time_Known_Value_Or_Aggr (Expression (Cass))
- then
-return False;
- end if;
-
- Next (Cass);
-  end loop;
-   end;
-end if;
-
-return True;
-
- elsif Nkind (Op) = N_Qualified_Expression then
-return Compile_Time_Known_Value_Or_Aggr (Expression (Op));
-
- --  All other types of values are not known at compile time
-
- else
-return False;
- end if;
-
-  end if;
-   end Compile_Time_Known_Value_Or_Aggr;
-
---
-- CRT_Safe_Compile_Time_Known_Value --
---


diff --git a/gcc/ada/sem_eval.ads b/gcc/ada/sem_eval.ads
--- a/gcc/ada/sem_eval.ads
+++ b/gcc/ada/sem_eval.ads
@@ -236,15 +236,6 @@ package Sem_Eval is
 
--  WARNING: There is a matching C declaration of this subprogram in fe.h
 
-   function Compile_Time_Known_Value_Or_Aggr (Op : Node_Id) return Boolean;
-   --  Similar to Compile_Time_Known_Value, but also returns True if the value
-   --  is a compile-time-known aggregate, i.e. an aggregate all of whose
-   --  constituent expressions are either compile-time-known values (based on
-   --  calling Compile_Time_Known_Value) or compile-time-known aggregates.
-   --  Note that the aggregate could still involve run-time checks that might
-   --  fail (such as for subtype checks in component associations), but the
-   --  evaluation of the expressions themselves will not raise an exception.
-
function CRT_Safe_Compile_Time_Known_Value (Op : Node_Id) return Boolean;
--  In the case of configurable run-times, there may be an issue calling
--  Compile_Time_Known_Value with non-static expressions where the legality




[Ada] Adapt proof of System.Arith_Double

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Following changes in GNATprove, ghost code needs some adjustments for
proof to go through.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-aridou.adb (Double_Divide): Adjust proof of lemma
Prove_Signs, call lemma for commutation of Big and
multiplication.
(Multiply_With_Ovflo_Check): Adjust postcondition of
Prove_Pos_Int.
(Scaled_Divide): Explicit commutation in the proof of lemma
Prove_Multiplication, add new lemma Prove_Shift_Progress for
congruence property that is not proved in a larger context, add
assertions at the end of the loop to state loop invariant
properties.diff --git a/gcc/ada/libgnat/s-aridou.adb b/gcc/ada/libgnat/s-aridou.adb
--- a/gcc/ada/libgnat/s-aridou.adb
+++ b/gcc/ada/libgnat/s-aridou.adb
@@ -868,11 +868,14 @@ is
  if (X >= 0) = Den_Pos then
 pragma Assert (Quot >= 0);
 pragma Assert (Big_Q >= 0);
+pragma Assert (Q >= 0);
 pragma Assert (Big (Q) = Big_Q);
  else
 pragma Assert ((X >= 0) /= (Big (Y) * Big (Z) >= 0));
 pragma Assert (Quot <= 0);
 pragma Assert (Big_Q <= 0);
+pragma Assert (if X >= 0 then R >= 0);
+pragma Assert (if X < 0 then R <= 0);
 pragma Assert (Big (R) = Big_R);
  end if;
   end Prove_Signs;
@@ -893,6 +896,7 @@ is
   else
  Big_Q := Quot;
   end if;
+  Lemma_Abs_Mult_Commutation (Big (Y), Big (Z));
   Lemma_Mult_Decomposition (Mult, Yu, Zu, Yhi, Ylo, Zhi, Zlo);
 
   --  Compute Y * Z. Note that if the result overflows Double_Uns, then
@@ -1417,7 +1421,8 @@ is
 Pre  => In_Double_Int_Range (Big (X) * Big (Y))
   and then Mult = Big (T2)
   and then ((X >= 0 and then Y >= 0) or else (X < 0 and then Y < 0)),
-Post => To_Pos_Int (T2) = X * Y;
+Post => In_Double_Int_Range (Big (T2))
+  and then To_Pos_Int (T2) = X * Y;
 
   procedure Prove_Result_Too_Large
   with
@@ -1925,6 +1930,10 @@ is
  Lemma_Hi_Lo (T1, Hi (T1), S3);
  Lemma_Hi_Lo (T2, Hi (T2), Lo (T2));
  Lemma_Hi_Lo (T3, Hi (T3), S2);
+ Lemma_Mult_Commutation (Double_Uns (Q), Double_Uns (Lo (Zu)), T1);
+ Lemma_Mult_Commutation (Double_Uns (Q), Double_Uns (Hi (Zu)), T2);
+ pragma Assert (Big (Double_Uns (Q)) * Big (Zu) =
+  Big_2xxSingle * Big (T2) + Big (T1));
  pragma Assert (Big (Double_Uns (Q)) * Big (Zu) =
Big_2xxSingle * Big_2xxSingle * Big (Double_Uns (Hi (T2)))
  + Big_2xxSingle * Big_2xxSingle * Big (Double_Uns (Hi (T3)))
@@ -2321,6 +2330,21 @@ is
  Post => Shift / 2 = 2 ** (Log_Single_Size - (Inter + 1))
and then (Shift = 2 or (Shift / 2) mod 2 = 0);
 
+   procedure Prove_Shift_Progress
+   with
+ Ghost,
+ Pre  => Shift <= Single_Size / 2
+   and then Shift_Prev = 2 * Shift
+   and then Mask_Prev =
+ Shift_Left (Single_Uns'Last, Single_Size - Shift_Prev)
+   and then Mask =
+ Shift_Left (Single_Uns'Last,
+ Single_Size - Shift_Prev + Shift),
+ Post => Mask_Prev =
+ Shift_Left (Single_Uns'Last, Single_Size - 2 * Shift)
+   and then Mask =
+ Shift_Left (Single_Uns'Last, Single_Size - Shift);
+
procedure Prove_Shifting
with
  Ghost,
@@ -2333,17 +2357,13 @@ is
and then (Hi (Zu_Prev) and Mask_Prev and not Mask) /= 0,
  Post => (Hi (Zu) and Mask) /= 0;
 
-   -
-   -- Prove_Power --
-   -
+   -
+   -- Local lemma null bodies --
+   -
 
procedure Prove_Power is null;
-
-   
-   -- Prove_Shifting --
-   
-
procedure Prove_Shifting is null;
+   procedure Prove_Shift_Progress is null;
 
 begin
Prove_Power;
@@ -2357,6 +2377,7 @@ is
 
Lemma_Double_Shift
  (Single_Uns'Last, Single_Size - Shift_Prev, Shift);
+   Prove_Shift_Progress;
 
if (Hi (Zu) and Mask) = 0 then
   Zu := Shift_Left (Zu, Shift);
@@ -2378,9 +2399,13 @@ is
 
   Scale := Scale + Shift;
 
+  pragma Assert (Zu = Shift_Left (abs Z, Scale));
   pragma Assert
 (Big (Zu) = Big (Double_Uns'(abs Z)) * Big_2xx (Scale));
end if;
+
+   pragma Assert
+ (Big (Zu) = Big (Double_Uns'(abs Z)

[Ada] Remove unreferenced name constants

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
In the Snames unit we had many unreferenced constants. Most of them are
leftovers from features that have been deconstructed years ago, e.g. VAX
support.

Code cleanup; semantics is unaffected.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* snames.ads-tmpl: Remove unreferenced names.diff --git a/gcc/ada/snames.ads-tmpl b/gcc/ada/snames.ads-tmpl
--- a/gcc/ada/snames.ads-tmpl
+++ b/gcc/ada/snames.ads-tmpl
@@ -181,12 +181,9 @@ package Snames is
Name_uController: constant Name_Id := N + $;
Name_uCPU   : constant Name_Id := N + $;
Name_uDispatching_Domain: constant Name_Id := N + $;
-   Name_uEntry_Bodies  : constant Name_Id := N + $;
-   Name_uExpunge   : constant Name_Id := N + $;
Name_uFinalizer : constant Name_Id := N + $;
Name_uFinalizer_Old : constant Name_Id := N + $;
Name_uFinalization_Controller   : constant Name_Id := N + $;
-   Name_uIdepth: constant Name_Id := N + $;
Name_uInit  : constant Name_Id := N + $;
Name_uInit_Level: constant Name_Id := N + $;
Name_uInvariant : constant Name_Id := N + $;
@@ -197,22 +194,18 @@ package Snames is
Name_uPostcond_Enabled  : constant Name_Id := N + $;
Name_uPre   : constant Name_Id := N + $;
Name_uPriority  : constant Name_Id := N + $;
-   Name_uProcess_ATSD  : constant Name_Id := N + $;
Name_uRelative_Deadline : constant Name_Id := N + $;
Name_uResult: constant Name_Id := N + $;
Name_uResult_Object_For_Postcond: constant Name_Id := N + $;
Name_uReturn_Success_For_Postcond   : constant Name_Id := N + $;
Name_uSecondary_Stack   : constant Name_Id := N + $;
Name_uSecondary_Stack_Size  : constant Name_Id := N + $;
-   Name_uService   : constant Name_Id := N + $;
Name_uSize  : constant Name_Id := N + $;
Name_uStack : constant Name_Id := N + $;
-   Name_uTags  : constant Name_Id := N + $;
Name_uTask  : constant Name_Id := N + $;
Name_uTask_Id   : constant Name_Id := N + $;
Name_uTask_Info : constant Name_Id := N + $;
Name_uTask_Name : constant Name_Id := N + $;
-   Name_uTrace_Sp  : constant Name_Id := N + $;
Name_uType_Invariant: constant Name_Id := N + $;
Name_uVariants  : constant Name_Id := N + $;
 
@@ -339,17 +332,14 @@ package Snames is
Name_Origin : constant Name_Id := N + $;
Name_Params : constant Name_Id := N + $;
Name_Partition  : constant Name_Id := N + $;
-   Name_Partition_Interface: constant Name_Id := N + $;
Name_Ras: constant Name_Id := N + $;
Name_uCall  : constant Name_Id := N + $;
Name_RCI_Name   : constant Name_Id := N + $;
Name_Receiver   : constant Name_Id := N + $;
-   Name_Rpc: constant Name_Id := N + $;
Name_Subp_Id: constant Name_Id := N + $;
Name_Operation  : constant Name_Id := N + $;
Name_Argument   : constant Name_Id := N + $;
Name_Arg_Modes  : constant Name_Id := N + $;
-   Name_Handler: constant Name_Id := N + $;
Name_Target : constant Name_Id := N + $;
Name_Req: constant Name_Id := N + $;
Name_Obj_TypeCode   : constant Name_Id := N + $;
@@ -795,14 +785,12 @@ package Snames is
Name_By_Entry   : constant Name_Id := N + $;
Name_By_Protected_Procedure : constant Name_Id := N + $;
Name_Casing : constant Name_Id := N + $;
-   Name_Check_All  : constant Name_Id := N + $;
Name_Code   : constant Name_Id := N + $;
Name_Component  : constant Name_Id := N + $;
Name_Component_Size_4   : constant Name_Id := N + $;
Name_Copy   : constant Name_Id := N + $;
Name_Copy_From  : constant Name_Id := N + $;
Name_Copy_To: constant Name_Id := N + $;
-   Name_D_Float: constant Name_Id := N + $;
Name_Decreases  : constant Name_Id := N + $;
Name_Disable: constant Name_Id := N + $;
Name_Dot_Replacement: constant Name_Id 

[Ada] Balance parentheses in comments about allocators

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Cleanup related to handling of allocators and compile-time-known null
expressions in GNATprove.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch4.adb (Analyze_Allocator): Fix comment.
* sem_eval.ads (Compile-Time Known Values): Likewise.diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -515,7 +515,7 @@ package body Sem_Ch4 is
 --  parameters. Note that this is now a static error even if the
 --  subprogram is not the main program (this is a change, in an
 --  earlier version only the main program was affected, and the
---  check had to be done in the binder.
+--  check had to be done in the binder).
 
 if Nkind (P) = N_Subprogram_Body
   and then Nkind (Parent (P)) = N_Compilation_Unit
@@ -563,7 +563,7 @@ package body Sem_Ch4 is
  Find_Type (Subtype_Mark (E));
 
  --  Analyze the qualified expression, and apply the name resolution
- --  rule given in  4.7(3).
+ --  rule given in 4.7(3).
 
  Analyze (E);
  Type_Id := Etype (E);


diff --git a/gcc/ada/sem_eval.ads b/gcc/ada/sem_eval.ads
--- a/gcc/ada/sem_eval.ads
+++ b/gcc/ada/sem_eval.ads
@@ -113,7 +113,7 @@ package Sem_Eval is
--  The expression 'C' is not static in the technical RM sense, but for many
--  simple record types, the size is in fact known at compile time. When we
--  are trying to perform compile time constant folding (for instance for
-   --  expressions like C + 1, Is_Static_Expression or Is_OK_Static_Expression
+   --  expressions like C + 1), Is_Static_Expression or Is_OK_Static_Expression
--  are not the right functions to test if folding is possible. Instead, we
--  use Compile_Time_Known_Value. All static expressions that do not raise
--  constraint error (i.e. those for which Is_OK_Static_Expression is true)




[Ada] Reduce scope of declare block in analysis of allocators

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Cleanup related to handling of allocators in GNATprove; semantics is
unaffected.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch4.adb (Analyze_Allocator): Move DECLARE block inside IF
statement; refill code and comments.diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -588,59 +588,58 @@ package body Sem_Ch4 is
   --  Case where allocator has a subtype indication
 
   else
- declare
-Def_Id   : Entity_Id;
-Base_Typ : Entity_Id;
-
- begin
---  If the allocator includes a N_Subtype_Indication then a
---  constraint is present, otherwise the node is a subtype mark.
---  Introduce an explicit subtype declaration into the tree
---  defining some anonymous subtype and rewrite the allocator to
---  use this subtype rather than the subtype indication.
-
---  It is important to introduce the explicit subtype declaration
---  so that the bounds of the subtype indication are attached to
---  the tree in case the allocator is inside a generic unit.
-
---  Finally, if there is no subtype indication and the type is
---  a tagged unconstrained type with discriminants, the designated
---  object is constrained by their default values, and it is
---  simplest to introduce an explicit constraint now. In some cases
---  this is done during expansion, but freeze actions are certain
---  to be emitted in the proper order if constraint is explicit.
-
-if Is_Entity_Name (E) and then Expander_Active then
-   Find_Type (E);
-   Type_Id := Entity (E);
-
-   if Is_Tagged_Type (Type_Id)
- and then Has_Defaulted_Discriminants (Type_Id)
- and then not Is_Constrained (Type_Id)
-   then
-  declare
- Constr : constant List_Id:= New_List;
- Loc: constant Source_Ptr := Sloc (E);
- Discr  : Entity_Id := First_Discriminant (Type_Id);
+ --  If the allocator includes a N_Subtype_Indication then a
+ --  constraint is present, otherwise the node is a subtype mark.
+ --  Introduce an explicit subtype declaration into the tree
+ --  defining some anonymous subtype and rewrite the allocator to
+ --  use this subtype rather than the subtype indication.
+
+ --  It is important to introduce the explicit subtype declaration
+ --  so that the bounds of the subtype indication are attached to
+ --  the tree in case the allocator is inside a generic unit.
+
+ --  Finally, if there is no subtype indication and the type is
+ --  a tagged unconstrained type with discriminants, the designated
+ --  object is constrained by their default values, and it is
+ --  simplest to introduce an explicit constraint now. In some cases
+ --  this is done during expansion, but freeze actions are certain
+ --  to be emitted in the proper order if constraint is explicit.
+
+ if Is_Entity_Name (E) and then Expander_Active then
+Find_Type (E);
+Type_Id := Entity (E);
+
+if Is_Tagged_Type (Type_Id)
+  and then Has_Defaulted_Discriminants (Type_Id)
+  and then not Is_Constrained (Type_Id)
+then
+   declare
+  Constr : constant List_Id:= New_List;
+  Loc: constant Source_Ptr := Sloc (E);
+  Discr  : Entity_Id := First_Discriminant (Type_Id);
 
-  begin
- while Present (Discr) loop
-Append (Discriminant_Default_Value (Discr), Constr);
-Next_Discriminant (Discr);
- end loop;
+   begin
+  while Present (Discr) loop
+ Append (Discriminant_Default_Value (Discr), Constr);
+ Next_Discriminant (Discr);
+  end loop;
 
- Rewrite (E,
-   Make_Subtype_Indication (Loc,
- Subtype_Mark => New_Occurrence_Of (Type_Id, Loc),
- Constraint   =>
-   Make_Index_Or_Discriminant_Constraint (Loc,
- Constraints => Constr)));
-  end;
-   end if;
+  Rewrite (E,
+Make_Subtype_Indication (Loc,
+  Subtype_Mark => New_Occurrence_Of (Type_Id, Loc),
+  Constraint   =>
+Make_Index_Or_Discriminant_Constraint (Loc,
+  Constraints => Constr)));
+   end;
 end if;
+ end if;
 
- 

[Ada] Remove name constant used by GNATprove but not by GNAT

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Revert recent removal of Name_Rpc, which is needed by GNATprove to
detect calls to potentially blocking subprograms.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* snames.ads-tmpl: Restore Name_Rpc.diff --git a/gcc/ada/snames.ads-tmpl b/gcc/ada/snames.ads-tmpl
--- a/gcc/ada/snames.ads-tmpl
+++ b/gcc/ada/snames.ads-tmpl
@@ -336,6 +336,7 @@ package Snames is
Name_uCall  : constant Name_Id := N + $;
Name_RCI_Name   : constant Name_Id := N + $;
Name_Receiver   : constant Name_Id := N + $;
+   Name_Rpc: constant Name_Id := N + $;
Name_Subp_Id: constant Name_Id := N + $;
Name_Operation  : constant Name_Id := N + $;
Name_Argument   : constant Name_Id := N + $;




[Ada] Avoid redundant checks for empty lists

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Simplify "No (L) or else Is_Empty_List (L)" into "Is_Empty_List (L)",
since Is_Empty_List can be called on No_List and returns True.

Code cleanup; semantics is unaffected.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch4.adb (Expand_N_Expression_With_Actions): Avoid
redundant check.
* exp_ch5.adb (Expand_N_If_Statement): Likewise.
* exp_ch7.adb (Process_Declarations): Likewise.
* sem_elab.adb (Freeze_Node_Location): Likewise.
* exp_util.adb (Insert_Actions): Likewise.
(Is_OK_PF_Pragma): Likewise.
(Requires_Cleanup_Actions): Remove early exit; ordinary
processing path will similarly do nothing.diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -5697,7 +5697,7 @@ package body Exp_Ch4 is
   --  Do not evaluate the expression when there are no actions because the
   --  expression_with_actions node will be replaced by the expression.
 
-  elsif No (Acts) or else Is_Empty_List (Acts) then
+  elsif Is_Empty_List (Acts) then
  null;
 
   --  Force the evaluation of the expression by capturing its value in a


diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb
--- a/gcc/ada/exp_ch5.adb
+++ b/gcc/ada/exp_ch5.adb
@@ -4475,9 +4475,7 @@ package body Exp_Ch5 is
 --  entire if statement by the sequence of else statements.
 
 if No (Elsif_Parts (N)) then
-   if No (Else_Statements (N))
- or else Is_Empty_List (Else_Statements (N))
-   then
+   if Is_Empty_List (Else_Statements (N)) then
   Rewrite (N,
 Make_Null_Statement (Sloc (N)));
else


diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -2249,7 +2249,7 @@ package body Exp_Ch7 is
   --  Start of processing for Process_Declarations
 
   begin
- if No (Decls) or else Is_Empty_List (Decls) then
+ if Is_Empty_List (Decls) then
 return;
  end if;
 


diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -7172,7 +7172,7 @@ package body Exp_Util is
   Wrapped_Node : Node_Id := Empty;
 
begin
-  if No (Ins_Actions) or else Is_Empty_List (Ins_Actions) then
+  if Is_Empty_List (Ins_Actions) then
  return;
   end if;
 
@@ -9963,7 +9963,7 @@ package body Exp_Util is
 --  Nothing to do when the pragma lacks arguments, in which case it
 --  is illegal.
 
-elsif No (Args) or else Is_Empty_List (Args) then
+elsif Is_Empty_List (Args) then
return False;
 end if;
 
@@ -12674,10 +12674,6 @@ package body Exp_Util is
   Typ : Entity_Id;
 
begin
-  if No (L) or else Is_Empty_List (L) then
- return False;
-  end if;
-
   Decl := First (L);
   while Present (Decl) loop
 


diff --git a/gcc/ada/sem_elab.adb b/gcc/ada/sem_elab.adb
--- a/gcc/ada/sem_elab.adb
+++ b/gcc/ada/sem_elab.adb
@@ -15382,7 +15382,7 @@ package body Sem_Elab is
 
elsif Present (Vis_Decls)
  and then List_Containing (FNode) = Vis_Decls
- and then (No (Prv_Decls) or else Is_Empty_List (Prv_Decls))
+ and then Is_Empty_List (Prv_Decls)
then
   null;
 




[Ada] Remove unreferenced CCG-specific routine Insert_Declaration

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Routine Insert_Declaration was originally added for the Ada-to-C
translator, because in C we can't have declarations within an
expressions. However, it is no longer used, because now we insert
declarations into N_Expression_With_Actions.

Code cleanup related to inserting itypes in spec expressions for
GNATprove.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_util.ads (Insert_Declaration): Remove spec.
* exp_util.adb (Insert_Declaration): Remove body.diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -7916,43 +7916,6 @@ package body Exp_Util is
   end if;
end Insert_Actions_After;
 
-   
-   -- Insert_Declaration --
-   
-
-   procedure Insert_Declaration (N : Node_Id; Decl : Node_Id) is
-  P : Node_Id;
-
-   begin
-  pragma Assert (Nkind (N) in N_Subexpr);
-
-  --  Climb until we find a procedure or a package
-
-  P := N;
-  loop
- pragma Assert (Present (Parent (P)));
- P := Parent (P);
-
- if Is_List_Member (P) then
-exit when Nkind (Parent (P)) in
-N_Package_Specification | N_Subprogram_Body;
-
---  Special handling for handled sequence of statements, we must
---  insert in the statements not the exception handlers!
-
-if Nkind (Parent (P)) = N_Handled_Sequence_Of_Statements then
-   P := First (Statements (Parent (P)));
-   exit;
-end if;
- end if;
-  end loop;
-
-  --  Now do the insertion
-
-  Insert_Before (P, Decl);
-  Analyze (Decl);
-   end Insert_Declaration;
-
-
-- Insert_Library_Level_Action --
-


diff --git a/gcc/ada/exp_util.ads b/gcc/ada/exp_util.ads
--- a/gcc/ada/exp_util.ads
+++ b/gcc/ada/exp_util.ads
@@ -164,18 +164,6 @@ package Exp_Util is
--  generalize to expressions if there is a need but this is tricky to
--  implement because of short-circuits (among other things).
 
-   procedure Insert_Declaration (N : Node_Id; Decl : Node_Id);
-   --  N must be a subexpression (Nkind in N_Subexpr). This is similar to
-   --  Insert_Action (N, Decl), but inserts Decl outside the expression in
-   --  which N appears. This is called Insert_Declaration because the intended
-   --  use is for declarations that have no associated code. We can't go
-   --  moving other kinds of things out of the current expression, since they
-   --  could be executed conditionally (e.g. right operand of short circuit,
-   --  or THEN/ELSE of if expression). This is currently used only in
-   --  Modify_Tree_For_C mode, where it is needed because in C we have no
-   --  way of having declarations within an expression (a really annoying
-   --  limitation).
-
procedure Insert_Library_Level_Action (N : Node_Id);
--  This procedure inserts and analyzes the node N as an action at the
--  library level for the current unit (i.e. it is attached to the




[Ada] Task arrays trigger spurious unreferenced warnings

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Incremental patch to handle multi-dimensional arrays of tasks and
records with task components.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_warn.adb (Check_References): Add call to Has_Task instead
of checking component type.diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -1701,13 +1701,10 @@ package body Sem_Warn is
   and then Ekind (E1) /= E_Constant
   and then Ekind (E1) /= E_Component)
 
- --  Check that E1T is not a task or an array of them
+ --  Check that E1T is not a task or a composite type
+ --  with a task component.
 
- or else not
-   (Is_Task_Type (E1T)
- or else (Ekind (E1T) in Array_Kind
-   and then Is_Task_Type
-  (Component_Type (E1T)
+ or else not Has_Task (E1T))
 
   --  For subunits, only place warnings on the main unit itself,
   --  since parent units are not completely compiled.




[Ada] Accept square brackets for expression functions

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
Ada RM 6.8 allows an expression function to return an aggregate directly
at the top level (enclosed with either parentheses or square brackets).

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* par-ch6.adb (Scan_Body_Or_Expression_Function): Accept left
bracket as token to open an expression function.diff --git a/gcc/ada/par-ch6.adb b/gcc/ada/par-ch6.adb
--- a/gcc/ada/par-ch6.adb
+++ b/gcc/ada/par-ch6.adb
@@ -841,7 +841,14 @@ package body Ch6 is
 begin
--  Expression_Function case
 
-   if Token = Tok_Left_Paren
+   --  If likely an aggregate, check we are in Ada 2022 mode
+
+   if Token = Tok_Left_Bracket then
+  Error_Msg_Ada_2022_Feature
+("!aggregates as expression function", Token_Ptr);
+   end if;
+
+   if Token in Tok_Left_Paren | Tok_Left_Bracket
  or else Likely_Expression_Function
then
   --  Check expression function allowed here




[Ada] Include generic instance names in non-visible entity errors

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
This patch adds the printing of generic instance names when encountering
non-visible entities instead of just the line number of the package
instantiation.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch8.adb (Nvis_Messages): Add generic instance name to
error message.diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -5689,8 +5689,27 @@ package body Sem_Ch8 is
  null;
 
   else
- Error_Msg_N -- CODEFIX
-   ("non-visible declaration#!", N);
+ --  When the entity comes from a generic instance the
+ --  normal error message machinery will give the line
+ --  number of the generic package and the location of
+ --  the generic instance, but not the name of the
+ --  the instance.
+
+ --  So, in order to give more descriptive error messages
+ --  in this case, we include the name of the generic
+ --  package.
+
+ if Is_Generic_Instance (Scope (Ent)) then
+Error_Msg_Name_1 := Chars (Scope (Ent));
+Error_Msg_N -- CODEFIX
+  ("non-visible declaration from %#!", N);
+
+ --  Otherwise print the message normally
+
+ else
+Error_Msg_N -- CODEFIX
+  ("non-visible declaration#!", N);
+ end if;
 
  if Ekind (Scope (Ent)) /= E_Generic_Package then
 Found := True;




[Ada] Relax assertion on designated types for equality operators

2022-01-11 Thread Pierre-Marie de Rodat via Gcc-patches
This will avoid doing artificial conversions during semantic analysis.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* gcc-interface/utils2.c (build_binary_op) : Relax a
little the assertion on designated types of pointer types.diff --git a/gcc/ada/gcc-interface/utils2.c b/gcc/ada/gcc-interface/utils2.c
--- a/gcc/ada/gcc-interface/utils2.c
+++ b/gcc/ada/gcc-interface/utils2.c
@@ -6,7 +6,7 @@
  *  *
  *  C Implementation File   *
  *  *
- *  Copyright (C) 1992-2021, Free Software Foundation, Inc. *
+ *  Copyright (C) 1992-2022, Free Software Foundation, Inc. *
  *  *
  * GNAT is free software;  you can  redistribute it  and/or modify it under *
  * terms of the  GNU General Public License as published  by the Free Soft- *
@@ -1118,7 +1118,7 @@ build_binary_op (enum tree_code op_code, tree result_type,
 	  return result;
 	}
 
-  /* Otherwise, the base types must be the same, unless they are both fat
+  /* Otherwise, the base types must be the same, unless they are both (fat)
 	 pointer types or record types.  In the latter case, use the best type
 	 and convert both operands to that type.  */
   if (left_base_type != right_base_type)
@@ -1131,6 +1131,18 @@ build_binary_op (enum tree_code op_code, tree result_type,
 	  best_type = left_base_type;
 	}
 
+	  else if (POINTER_TYPE_P (left_base_type)
+		   && POINTER_TYPE_P (right_base_type))
+	{
+	  /* Anonymous access types in Ada 2005 can point to different
+		 members of a tagged type hierarchy.  */
+	  gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (left_base_type))
+			  == TYPE_MAIN_VARIANT (TREE_TYPE (right_base_type))
+			  || (TYPE_ALIGN_OK (TREE_TYPE (left_base_type))
+			  && TYPE_ALIGN_OK (TREE_TYPE (right_base_type;
+	  best_type = left_base_type;
+	}
+
 	  else if (TREE_CODE (left_base_type) == RECORD_TYPE
 		   && TREE_CODE (right_base_type) == RECORD_TYPE)
 	{
@@ -1153,13 +1165,6 @@ build_binary_op (enum tree_code op_code, tree result_type,
 		gcc_unreachable ();
 	}
 
-	  else if (POINTER_TYPE_P (left_base_type)
-		   && POINTER_TYPE_P (right_base_type))
-	{
-	  gcc_assert (TREE_TYPE (left_base_type)
-			  == TREE_TYPE (right_base_type));
-	  best_type = left_base_type;
-	}
 	  else
 	gcc_unreachable ();
 




Re: [PATCH] tree-optimization/pr103961: Never compute offset for -1 size

2022-01-11 Thread Jakub Jelinek via Gcc-patches
On Tue, Jan 11, 2022 at 06:40:44PM +0530, Siddhesh Poyarekar wrote:
> Never try to compute size for offset when the object size is -1, which
> is either unknown maximum or uninitialized minimum irrespective of the
> osi->pass number.
> 
> gcc/ChangeLog:
> 
>   PR tree-optimization/pr103961
>   * tree-object-size.c (plus_stmt_object_size): Always avoid
>   computing offset for -1 size.
> 
> gcc/testsuite/ChangeLog:
> 
>   PR tree-optimization/pr103961
>   * gcc.dg/pr103961.c: New test case.

Ok.  Martin's executable testcase would work too but only if
it would be limited to targets with glibc with __sprintf_chk in or
it would need to be linked against -lssp, so I think it is fine as is.

> +void
> +cap_to_text (int c)
> +{
> +  char buf[1572];
> +  char *p;
> +  int n, t;
> +  p = 20 + buf;
> +  for (t = 8; t--; )
> +{
> +  for (n = 0; n < c; n++)
> + p += sprintf (p, "a,");
> +  p--;
> +  if (__builtin_object_size (p, 1) == 0)
> + abort ();
> +}

Just curious, does your PR77608 patch change this such that __bos (p, 1)
is not ~(size_t)0 but 1572?
We don't know if c isn't 0, so can't count on p += sprintf (p, "a,");
actually incrementing the pointer (and unless we try to understand more
what exactly it is doing we'd need to also assume it could e.g. return -1,
and we aren't too smart about loops anyway, but if the PR77608 patch assumes
that variable bounds aren't out of bounds, then a pointer that started
as 20 + buf can be minimum buf + 0 and maximum buf + 1572.
Note, as __bos is trying to prevent exploiting UB, perhaps assuming the
pointer arithmetics or array refs aren't out of bounds isn't perfect, but
then I'd say a __bos (p, 1) == 1572 means bigger security than __bos (p, 1)
== -1 where we punt and don't check anything.

Jakub



Re: [PATCH] [12/11/10] Fix invalid format warnings on Windows

2022-01-11 Thread Martin Liška

Hello.

I do support the patch, but I would ...

On 1/7/22 19:33, Tomas Kalibera wrote:

+  if (is_attribute_p ("format", get_attribute_name (aa)) &&
+  fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
+{
+  switch (DECL_FUNCTION_CODE (fndecl))
+{
+case BUILT_IN_FSCANF:
+case BUILT_IN_PRINTF:
+case BUILT_IN_SCANF:
+case BUILT_IN_SNPRINTF:
+case BUILT_IN_SSCANF:
+case BUILT_IN_VFSCANF:
+case BUILT_IN_VPRINTF:
+case BUILT_IN_VSCANF:
+case BUILT_IN_VSNPRINTF:
+case BUILT_IN_VSSCANF:
+case BUILT_IN_DCGETTEXT:
+case BUILT_IN_DGETTEXT:
+case BUILT_IN_GETTEXT:
+case BUILT_IN_STRFMON:
+case BUILT_IN_STRFTIME:
+case BUILT_IN_SNPRINTF_CHK:
+case BUILT_IN_VSNPRINTF_CHK:
+case BUILT_IN_PRINTF_CHK:
+case BUILT_IN_VPRINTF_CHK:
+  skipped_default_format = 1;
+  break;
+default:
+  break;
+}
+}


... skip this as the listed functions are only these that have defined 
ATTR_FORMAT_*:

$ grep ATTR_FORMAT gcc/builtins.def
DEF_LIB_BUILTIN(BUILT_IN_FSCANF, "fscanf", 
BT_FN_INT_FILEPTR_CONST_STRING_VAR, ATTR_FORMAT_SCANF_2_3)
DEF_LIB_BUILTIN(BUILT_IN_PRINTF, "printf", BT_FN_INT_CONST_STRING_VAR, 
ATTR_FORMAT_PRINTF_1_2)
DEF_LIB_BUILTIN(BUILT_IN_SCANF, "scanf", BT_FN_INT_CONST_STRING_VAR, 
ATTR_FORMAT_SCANF_1_2)
DEF_C99_BUILTIN(BUILT_IN_SNPRINTF, "snprintf", 
BT_FN_INT_STRING_SIZE_CONST_STRING_VAR, ATTR_FORMAT_PRINTF_NOTHROW_3_4)
DEF_LIB_BUILTIN(BUILT_IN_SSCANF, "sscanf", 
BT_FN_INT_CONST_STRING_CONST_STRING_VAR, ATTR_FORMAT_SCANF_NOTHROW_2_3)
DEF_C99_BUILTIN(BUILT_IN_VFSCANF, "vfscanf", 
BT_FN_INT_FILEPTR_CONST_STRING_VALIST_ARG, ATTR_FORMAT_SCANF_2_0)
DEF_LIB_BUILTIN(BUILT_IN_VPRINTF, "vprintf", 
BT_FN_INT_CONST_STRING_VALIST_ARG, ATTR_FORMAT_PRINTF_1_0)
DEF_C99_BUILTIN(BUILT_IN_VSCANF, "vscanf", 
BT_FN_INT_CONST_STRING_VALIST_ARG, ATTR_FORMAT_SCANF_1_0)
DEF_C99_BUILTIN(BUILT_IN_VSNPRINTF, "vsnprintf", 
BT_FN_INT_STRING_SIZE_CONST_STRING_VALIST_ARG, ATTR_FORMAT_PRINTF_NOTHROW_3_0)
DEF_C99_BUILTIN(BUILT_IN_VSSCANF, "vsscanf", 
BT_FN_INT_CONST_STRING_CONST_STRING_VALIST_ARG, ATTR_FORMAT_SCANF_NOTHROW_2_0)
DEF_EXT_LIB_BUILTIN(BUILT_IN_DCGETTEXT, "dcgettext", 
BT_FN_STRING_CONST_STRING_CONST_STRING_INT, ATTR_FORMAT_ARG_2)
DEF_EXT_LIB_BUILTIN(BUILT_IN_DGETTEXT, "dgettext", 
BT_FN_STRING_CONST_STRING_CONST_STRING, ATTR_FORMAT_ARG_2)
DEF_EXT_LIB_BUILTIN(BUILT_IN_GETTEXT, "gettext", BT_FN_STRING_CONST_STRING, 
ATTR_FORMAT_ARG_1)
DEF_EXT_LIB_BUILTIN(BUILT_IN_STRFMON, "strfmon", 
BT_FN_SSIZE_STRING_SIZE_CONST_STRING_VAR, ATTR_FORMAT_STRFMON_NOTHROW_3_4)
DEF_LIB_BUILTIN(BUILT_IN_STRFTIME, "strftime", 
BT_FN_SIZE_STRING_SIZE_CONST_STRING_CONST_TM_PTR, ATTR_FORMAT_STRFTIME_NOTHROW_3_0)
DEF_EXT_LIB_BUILTIN(BUILT_IN_SNPRINTF_CHK, "__snprintf_chk", 
BT_FN_INT_STRING_SIZE_INT_SIZE_CONST_STRING_VAR, ATTR_FORMAT_PRINTF_NOTHROW_5_6)
DEF_EXT_LIB_BUILTIN(BUILT_IN_VSNPRINTF_CHK, "__vsnprintf_chk", 
BT_FN_INT_STRING_SIZE_INT_SIZE_CONST_STRING_VALIST_ARG, ATTR_FORMAT_PRINTF_NOTHROW_5_0)
DEF_EXT_LIB_BUILTIN(BUILT_IN_PRINTF_CHK, "__printf_chk", 
BT_FN_INT_INT_CONST_STRING_VAR, ATTR_FORMAT_PRINTF_2_3)
DEF_EXT_LIB_BUILTIN(BUILT_IN_VPRINTF_CHK, "__vprintf_chk", 
BT_FN_INT_INT_CONST_STRING_VALIST_ARG, ATTR_FORMAT_PRINTF_2_0)

Martin


Re: [Patch][V2]Enable -Wuninitialized + -ftrivial-auto-var-init for address taken variables

2022-01-11 Thread Richard Biener via Gcc-patches
On Wed, Jan 5, 2022 at 5:59 PM Qing Zhao  wrote:
>
> Hi, Richard,
>
> Thanks a lot for the review and questions.
> See my reply embedded below:
>
>
> > On Jan 5, 2022, at 4:33 AM, Richard Biener  
> > wrote:
> >
> > On Thu, Dec 16, 2021 at 5:00 PM Qing Zhao  wrote:
> >>
> >> Hi,
> >>
> >> This is the 2nd version of the patch.
> >> The original patch is at:
> >>
> >> https://gcc.gnu.org/pipermail/gcc-patches/2021-December/586341.html
> >>
> >> In addition to resolve the two issues mentioned in the original patch,
> >> This patch also can be used as a very good workaround for the issue in 
> >> PR103720
> >> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103720
> >>
> >> And as I checked, the patch can fix all the bogus uninitialized warnings 
> >> when
> >> building kernel with -O2 + -ftrivial-auto-var-init=zero + -Wuninitialized.
> >>
> >> So, this is a very important patch that need to be included into gcc12.
> >>
> >> Compared to the 1st patch, the major changes are to resolve Martin’s 
> >> comments on
> >> tree-ssa-uninit.c
> >>
> >> 1.  Add some meaningful temporaries to break the long expression to make it
> >> Readable. And also add comments to explain the purpose of the 
> >> statement;
> >>
> >> 2.  Resolve the memory leakage of the dynamically created string.
> >>
> >> The patch has been bootstrapped and regressing tested on both x86 and 
> >> aarch64, no issues.
> >> Okay for commit?
> >
> >  tree decl_name
> > += build_string_literal (IDENTIFIER_LENGTH (DECL_NAME (decl)) + 1,
> > +   IDENTIFIER_POINTER (DECL_NAME (decl)));
> >
> > you need to deal with DECL_NAME being NULL.
>
> Okay.
> Usually under what situation, the decl_name will be NULL?

I don't know but it definitely happens.

> >  It's also a bit awkward
> > to build another
> > copy of all decl names :/
>
> Yes, this is awkward. But it might be unavoidable for address taken variables 
> since the original variable might be completely deleted by optimizations.
> See the details at:
> https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577431.html
>
> We had a previous discussion on this issue, and the idea of adding this 3rd 
> argument with the name of the variable was proposed by you at that time. -:)

I know ... I didn't have a better idea.

> And I think that’s a good solution to this problem.
>
> > The changes in the uninit warning are also
> > quite ugly, refactoring
> > things to always pass down a name / location pair might improve that
> > (but I'd like to
> > understand the case to fix first).
>
> I will try this idea to see whether it will work.
>
> >
> > + /* The LHS of the call is a temporary variable, we use it as a
> > +placeholder to record the information on whether the warning
> > +has been issued or not.  */
> > + repl_var = gimple_call_lhs (def_stmt);
> >
> > this seems to be a change that can be done independently?
>
> The major purpose of this “repl_var” is used to record the info whether the 
> warning has been issued for the variable or not, then avoid emitting it again 
> later.
> Since the original variable has been completely deleted by optimization, we 
> have to use this “repl_var” for a placeholder to record such info.

But the ... = .DEFERRED_INIT stmt itself could be used to record this
since its location is
already used to indicate the original location, like with
suppress_warning/warning_suppressed_p?

> >
> > + /* Ignore the call to .DEFERRED_INIT that define the original
> > +var itself.  */
> > + if (is_gimple_assign (context))
> > +   {
> > + if (TREE_CODE (gimple_assign_lhs (context)) == VAR_DECL)
> > +   lhs_var = gimple_assign_lhs (context);
> > + else if (TREE_CODE (gimple_assign_lhs (context)) == SSA_NAME)
> > +   lhs_var = SSA_NAME_VAR (gimple_assign_lhs (context));
> > +   }
> > + if (lhs_var
> > + && (lhs_var_name = DECL_NAME (lhs_var))
> > + && (lhs_var_name_str = IDENTIFIER_POINTER (lhs_var_name))
> > + && (strcmp (lhs_var_name_str, var_name_str) == 0))
> > +   return;
> >
> > likewise but I don't really understand what you are doing here.
>
> The above is to exclude the following case:
>
>temp = .DEFERRED_INIT (4, 2, “alt_reloc");
>alt_reloc = temp;
>
> i.e, a call to .DEFERRED_INIT that define the original variable itself.

How can this happen?  It looks like a bug to me.  Do you have a testcase?

>
> >  I'm
> > also not sure
> > I understand the case we try to fix with passing the name - is that
> > for VLA decls
> > that get replaced by allocation?
>
> This whole patch is mainly to resolve the issue that has been discussed last 
> Aug as:
>
> https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577431.html
>
> We have agreed at that time to resolve this issue later.

Yes, I know.  But the patch seems to do multiple things and there's no
new testcase
and the

Re: [Patch][V3][Patch 1/2]Change the 3rd parameter of function .DEFERRED_INIT from IS_VLA to decl name

2022-01-11 Thread Richard Biener via Gcc-patches
On Tue, Jan 11, 2022 at 12:58 AM Qing Zhao  wrote:
>
> Hi, Richard,
>
> I splited the previous patch for “Enable -Wuninitialized + 
> -ftrivial-auto-var-init for address taken variables” into two separate 
> patches.
> This is the first one
>
> This first  patch  is to fix (or work around ) PR103720, therefore it’s an 
> important change, and need to be go into GCC12.
> At the same time, this patch is the preparation for the second patch that 
> will actually enable -Wuninitialized + -ftrivial-auto-var-init for address 
> taken variables.
>
> The reason I separate the previous patch into two is: most of the previous 
> concern was on the second part of the patch (the change in 
> tree-ssa-uninit.c), I don’t
> want those concern prevent this first patch from being approved into GCC12.
>
>
> In this part, I addressed your comments in  gimplify.c :
>
> =
>  tree decl_name
> += build_string_literal (IDENTIFIER_LENGTH (DECL_NAME (decl)) + 1,
> +   IDENTIFIER_POINTER (DECL_NAME (decl)));
>
> you need to deal with DECL_NAME being NULL.
> =
>
> Please also see the detailed description below for the problem and solution 
> of this patch.
>
> This first patch has been bootstrapped and regressing tested on both X86 and 
> aarch64.
>
> Okay for GCC12?

+
+  char *decl_name_anonymous = xasprintf ("D.%u", DECL_UID (decl));
+  const char *decl_name_str = DECL_NAME (decl)
+ ? IDENTIFIER_POINTER (DECL_NAME (decl))
+ : decl_name_anonymous;
+  tree decl_name
+= build_string_literal (strlen (decl_name_str) + 1,
+   decl_name_str);

please avoid the xasprintf in the case DECL_NAME is not NULL, I'd be happy
with sth like

   tree decl_name;
   if (DECL_NAME (decl))
  decl_name = build_string_literal (...);
   else
  {
 char *decl_name_anon = xasprintf (...);
 decl_name = build_string_literal (...);
 free (decl_name_anon);
  }

otherwise the patch is OK to commit (just do the above change and
re-test / push).

Thanks,
Richard.

> Thanks.
>
> Qing.
>
>
> =
>
>  Change the 3rd parameter of function .DEFERRED_INIT from
>  IS_VLA to decl name.
>
> Currently, the 3rd parameter of function .DEFERRED_INIT is IS_VLA, which is
> not needed at all;
>
> In this patch, we change the 3rd parameter from IS_VLA to the name of the var
> decl for the following purposes:
>
> 1. Fix (or work around) PR103720:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103720
>
> As confirmed in PR103720, with the current definition of .DEFERRED_INIT,
>
> Dom transformed:
>   c$a$0_6 = .DEFERRED_INIT (8, 2, 0);
>   _1 = .DEFERRED_INIT (8, 2, 0);
>
> into:
>   c$a$0_6 = .DEFERRED_INIT (8, 2, 0);
>   _1 = c$a$0_6;
>
> which is incorrectly done due to Dom treating the two calls to const function
> .DEFERRED_INIT as the same call since all actual parameters are the same.
>
> The same issue has been exposed in PR102608 due to a different optimization 
> VN,
> the fix for PR102608 is to specially handle call to .DEFERRED_INIT in VN to
> exclude it from CSE.
>
> To fix PR103720, we could do the same as the fix to PR102608 to specially
> handle call to .DEFERRED_INIT in Dom to exclude it from being optimized.
>
> However, in addition to Dom and VN, there should be other optimizations that
> have the same issue as PR103720 or PR102608 (As I built Linux kernel with
> -ftrivial-auto-var-init=zero -Werror, I noticed a bunch of bugos warnings).
>
> Other than identifying all the optimizations and specially handling call to
> .DEFERRED_INIT in all these optimizations, changing the 3rd parameter of the
> function .DEFERRED_INIT from IS_VLA to the name string of the var decl might
> be a better workaround (or a fix). After this change, since the 3rd actual
> parameter is the name string of the variable, different calls for different
> variables will have different name strings as the 3rd actual, As a result, the
> optimization that previously treated the different calls to .DEFERRED_INIT as
> the same will be prevented.
>
> 2. Prepare for enabling -Wuninitialized + -ftrivail-auto-var-init for address
> taken variables.
>
> As discussion in the following thread:
>
> https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577431.html
>
> With the current implemenation of -ftrivial-auto-var-init and uninitialized
> warning analysis, the uninitialized warning for an address taken auto variable
> might be missed since the variable is completely eliminated by optimization 
> and
> replaced with a temporary variable in all the uses.
>
> In order to improve such situation, changing the 3rd parameter of the function
> .DEFERRED_INIT to the name string of the variable will provide necessary
> information to uninitialized warning analysis to make the missing warning
> possible.
>
> gcc/ChangeLog:
>
> 2022-01-10  qing zhao  
>
> * gimplify.c (gimple_add_init_for_auto_var): Delete the 3rd argument.

Re: [PATCH] C, C++, Fortran, OpenMP: Add 'has_device_addr' clause to 'target' construct

2022-01-11 Thread Jakub Jelinek via Gcc-patches
On Tue, Jan 11, 2022 at 02:27:57PM +0100, Tobias Burnus wrote:
> Hi Jakub, hi all,
> 
> let me quickly comment on 'has_device_addr' with Fortran arrays
> and with an array section (i.e. regarding your comment quoted
> at the very bottom of this email).
> 
> Unfortunately, the OpenMP specification is rather unclear
> what has_device_addr means for C/C++ array sections and in general
> for Fortran, especially when arrays, allocatables/pointers, and
> type parameters like nonconst string lengths are involved. Thus,
> I opened a spec issue – after some discussions (lang-spec meeting,
> C++/affinity (→ Fortran) meeting), it starts to converge:
> https://github.com/OpenMP/spec/issues/3180
> 
> If I understood it correctly, for C/C++, using has_device_addr with
> an array section implies firstprivate, while it does not without
> array section.

That seems just wrong for arrays, that will just crash, see below.

Cases like:
  struct S { whatever; } s;
  #pragma omp target data map (s) use_device_addr (s)
  {
// At this point it is invalid to use s.field etc. because
// &s is a device address
#pragma omp target has_device_addr (s)
{
  access (&s);
}
  }
and s/struct S { whatever; } s/int s[16];/
are similar, in all the cases use_device_addr will replace
s in the body with *device_addr_of_s and has_device_addr
needs to firstprivatize the artificial address of s and ensure
that even in the target body s is *some_addr_of_s.
And IMHO array sections should be treated the same, just the
target data could map only parts of the array and not the whole
array, but still device_addr_of_s will be something pointing to the
start of the array, perhaps before the actual object allocated on the
device.
So, I think the gimplifier should strip the ARRAY_REFs and if that yields
something with ARRAY_TYPE, should just treat that var as what appeared
in the has_device_addr clause.  Only if it the array section has
a base pointer that base pointer needs to be copied to the device as is
and so the artificial firstprivate on that pointer that copies the pointer
to the device code.

> Side remark: I note that use_device_addr permits array sections,
> but GCC does not support them yet. (Useful when doing a partial
> map of an array + 'omp data use_device_addr()' on the partially
> mapped array.)

Yes, we should implement that.  But even without that supported, one can
have:
  int a[32];
  #pragma omp target data map (a) use_device_addr (a)
  {
// So, &a[0] is now a device pointer, whole a is mapped
#pragma omp target has_device_addr (a[3:17])
{
  ++a[3];
}
  }
When whole a[0:32] is mapped, obviously a[3:17] is mapped too
and for has_device-addr it IMHO should act like has_device_addr (a)
under the hood, except the user doesn't guarantee that the whole
array is mapped, just that a has a device address.

Now, if we treat the has_device_addr (a[3:17]) in the above testcase
as firstprivate (a), that will mean we try to copy the whole array from
host to the device.  But &a[0] etc. aren't host addresses, they are device
addresses, so unless the host can access the device addresses, that will
segfault.

Jakub



Re: [PATCH] tree-optimization/pr103961: Never compute offset for -1 size

2022-01-11 Thread Siddhesh Poyarekar

On 11/01/2022 19:04, Jakub Jelinek wrote:

On Tue, Jan 11, 2022 at 06:40:44PM +0530, Siddhesh Poyarekar wrote:

Never try to compute size for offset when the object size is -1, which
is either unknown maximum or uninitialized minimum irrespective of the
osi->pass number.

gcc/ChangeLog:

PR tree-optimization/pr103961
* tree-object-size.c (plus_stmt_object_size): Always avoid
computing offset for -1 size.

gcc/testsuite/ChangeLog:

PR tree-optimization/pr103961
* gcc.dg/pr103961.c: New test case.


Ok.  Martin's executable testcase would work too but only if
it would be limited to targets with glibc with __sprintf_chk in or
it would need to be linked against -lssp, so I think it is fine as is.


Thanks I'll push this then.


+void
+cap_to_text (int c)
+{
+  char buf[1572];
+  char *p;
+  int n, t;
+  p = 20 + buf;
+  for (t = 8; t--; )
+{
+  for (n = 0; n < c; n++)
+   p += sprintf (p, "a,");
+  p--;
+  if (__builtin_object_size (p, 1) == 0)
+   abort ();
+}


Just curious, does your PR77608 patch change this such that __bos (p, 1)
is not ~(size_t)0 but 1572?
We don't know if c isn't 0, so can't count on p += sprintf (p, "a,");
actually incrementing the pointer (and unless we try to understand more
what exactly it is doing we'd need to also assume it could e.g. return -1,
and we aren't too smart about loops anyway, but if the PR77608 patch assumes
that variable bounds aren't out of bounds, then a pointer that started
as 20 + buf can be minimum buf + 0 and maximum buf + 1572.
Note, as __bos is trying to prevent exploiting UB, perhaps assuming the
pointer arithmetics or array refs aren't out of bounds isn't perfect, but
then I'd say a __bos (p, 1) == 1572 means bigger security than __bos (p, 1)
== -1 where we punt and don't check anything.


That's a good catch; the 77608 patch actually breaks this again, but for 
a different reason that the patch itself introduces.  The "safe" 
assumption of wholesize for p_4 is not safe enough because p_17 (which 
is p_4 - 1) is assumed to have an underflow, resulting in a zero size again.


I need to rethink the 77608 fix; it won't always be as simple as 
returning the wholesize.


Thanks,
Siddhesh


Re: [PATCH] PR tree-optimization/103821 - Prevent exponential range calculations.

2022-01-11 Thread Andrew MacLeod via Gcc-patches

On 1/11/22 02:01, Richard Biener wrote:

On Tue, Jan 11, 2022 at 12:28 AM Andrew MacLeod via Gcc-patches
 wrote:

This test case demonstrates an unnoticed exponential situation in range-ops.

We end up unrolling the  loop, and the pattern of code creates a set of
cascading multiplies for which we can precisely evaluate them with
sub-ranges.

For instance, we calculated :

_38 = int [8192, 8192][24576, 24576][40960, 40960][57344, 57344]

so _38 has 4 sub-ranges, and then we calculate:

_39 = _38 * _38;

we do 16 sub-range multiplications and end up with:  int [67108864,
67108864][201326592, 201326592][335544320, 335544320][469762048,
469762048][603979776, 603979776][1006632960, 1006632960][1409286144,
1409286144][1677721600, 1677721600][+INF, +INF]

This feeds other multiplies (_39 * _39)  and progresses rapidly to blow
up the number of sub-ranges in subsequent operations.

Folding of sub-ranges is an O(n*m) process. We perform the operation on
each pair of sub-ranges and union them.   Values like _38 * _38 that
continue feeding each other quickly become exponential.

Then combining that with union (an inherently linear operation over the
number of sub-ranges) at each step of the way adds an additional
quadratic operation on top of the exponential factor.

This patch adjusts the wi_fold routine to recognize when the calculation
is moving in an exponential direction, simply produce a summary result
instead of a precise one.  The attached patch does this if (#LH
sub-ranges * #RH sub-ranges > 12)... then it just performs the operation
with the lower and upper bound instead.We could choose a different
number, but that one seems to keep things under control, and allows us
to process up to a 3x4 operation for precision (there is a testcase in
the testsuite for this combination gcc.dg/tree-ssa/pr61839_2.c).
Longer term, we might want adjust this routine to be slightly smarter
than that, but this is a virtually zero-risk solution this late in the
release cycle.

I'm not sure we can do smarter in a good way other than maybe having
a range helper that reduces a N component range to M components
with maintaining as much precision as possible?  Like for [1, 1] u [3, 3]
u [100, 100] and requesting at most 2 elements merge [1, 1] and [3, 3]
and not [100, 100].  That should eventually be doable in O(n log n).
Yeah, similar to my line of thought.  It may also be worth considering 
something similar after we have calculated a range sometimes.  if the 
resulting range has more than N sub-ranges, look to see if it is 
worthwhile trying to compress it at that point too maybe.  Something for 
the next stage-1 to consider.


Andrew



[committed] analyzer: fix false +ve on bitwise binops (PR analyzer/102692)

2022-01-11 Thread David Malcolm via Gcc-patches
PR analyzer/102692 reports a false positive at -O2 from
-Wanalyzer-null-dereference on:
  if (!p || q || !p->next)

At the gimple level, -O2 has converted the first || into bitwise or
controlling a jump:
  _4 = _2 | _3;
  if (_4 != 0)
and a recursive call has been converted to iteration.  The analyzer hits
the symbolic value complexity limit whilst analyzing the iteration and
hits a case where _2 is (_Bool)1 (i.e. true) and _3 (i.e. q) is
UNKNOWN(_Bool).

There are two issues leading to the false positive; fixing either issue
fixes the false positive; this patch fixes both for good measure:

(a) The analyzer erronously treats bitwise ops on UNKNOWN(_Bool) as UNKNOWN,
even for case like (1 | UNKNOWN) where we know the result, leading to
bogus edges in the exploded graph.  The patch fixes these cases.

(b) The state-handling code creates "UNKNOWN" symbolic values, as a way
to give up when symbolic expressions get too complicated, and in various
other cases.  This makes sense when building the exploded graph, since
we want the analysis to terminate, but doesn't make sense when checking
the feasibility along a specific path, where we want precision.  The patch
prevents all use of "unknown" symbolic values when performing feasibility
checking of a path (before it merely stopped doing complexity-checking),
by creating a unique placeholder_svalue instead.

This fixes the -Wanalyzer-null-dereference false positive.

Unfortunately, with GCC 12 there's also a false positive from
-Wanalyzer-use-of-uninitialized-value on this code, which is a separate
issue that the patch does not fix.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r12-6476-g4f34f8cc1d064bfaaed723312c71e92f495d429b.

gcc/analyzer/ChangeLog:
PR analyzer/102692
* diagnostic-manager.cc
(class auto_disable_complexity_checks): Rename to...
(class auto_checking_feasibility): ...this, updating
the calls accordingly.
(epath_finder::explore_feasible_paths): Update for renaming.
* region-model-manager.cc
(region_model_manager::region_model_manager): Update for change from
m_check_complexity to m_checking_feasibility.
(region_model_manager::reject_if_too_complex): Likewise.
(region_model_manager::get_or_create_unknown_svalue): Handle
m_checking_feasibility.
(region_model_manager::create_unique_svalue): New.
(region_model_manager::maybe_fold_binop): Handle BIT_AND_EXPR and
BIT_IOR_EXPRs on booleans where we know the result.
* region-model.cc (test_binop_svalue_folding): Add test coverage
for the above.
* region-model.h (region_model_manager::create_unique_svalue): New
decl.
(region_model_manager::enable_complexity_check): Replace with...
(region_model_manager::begin_checking_feasibility): ...this.
(region_model_manager::disable_complexity_check): Replace with...
(region_model_manager::end_checking_feasibility): ...this.
(region_model_manager::m_check_complexity): Replace with...
(region_model_manager::m_checking_feasibility): ...this.
(region_model_manager::m_managed_dynamic_svalues): New field.

gcc/testsuite/ChangeLog:
PR analyzer/102692
* gcc.dg/analyzer/pr102692.c: New test.
---
 gcc/analyzer/diagnostic-manager.cc   |  17 ++--
 gcc/analyzer/region-model-manager.cc |  55 +++-
 gcc/analyzer/region-model.cc |  33 +++
 gcc/analyzer/region-model.h  |  16 +++-
 gcc/testsuite/gcc.dg/analyzer/pr102692.c | 110 +++
 5 files changed, 219 insertions(+), 12 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr102692.c

diff --git a/gcc/analyzer/diagnostic-manager.cc 
b/gcc/analyzer/diagnostic-manager.cc
index 766effa75a4..cf480514c0e 100644
--- a/gcc/analyzer/diagnostic-manager.cc
+++ b/gcc/analyzer/diagnostic-manager.cc
@@ -303,18 +303,21 @@ private:
 
Hence this is an RAII class for temporarily disabling complexity-checking
in the region_model_manager, for use within
-   epath_finder::explore_feasible_paths.  */
+   epath_finder::explore_feasible_paths.
 
-class auto_disable_complexity_checks
+   We also disable the creation of unknown_svalue instances during feasibility
+   checking, instead creating unique svalues, to avoid paradoxes in paths.  */
+
+class auto_checking_feasibility
 {
 public:
-  auto_disable_complexity_checks (region_model_manager *mgr) : m_mgr (mgr)
+  auto_checking_feasibility (region_model_manager *mgr) : m_mgr (mgr)
   {
-m_mgr->disable_complexity_check ();
+m_mgr->begin_checking_feasibility ();
   }
-  ~auto_disable_complexity_checks ()
+  ~auto_checking_feasibility ()
   {
-m_mgr->enable_complexity_check ();
+m_mgr->end_checking_feasibility ();
   }
 private:
   region_model_manager *m_mgr;
@@ -406,7 +409,7 @@ epath_finder::explore_feasible_paths (const exploded_node 
*target_enode,
   explo

Re: Ping: [PATCH] rs6000: Add split pattern to replace

2022-01-11 Thread David Edelsohn via Gcc-patches
On Tue, Jan 11, 2022 at 2:27 AM Xionghu Luo  wrote:
>
> On 2022/1/11 06:55, David Edelsohn wrote:
> >>> +(define_insn_and_split "sldoi_to_mov_"
> > It would be more consistent with the naming convention to use
> > "sldoi_to_mov" without the final "_".
>
> OK, thanks.
>
> >
> >>> +  [(set (match_operand:VM 0 "altivec_register_operand")
> >>> + (unspec:VM [(match_operand:VM 1 "easy_vector_constant")
> > Should this be "easy_vector_constant_vsldoi"?
>
>
> This doesn't work. easy_vector_constant_vsldoi return false due to
> vspltis_shifted "return 0" as:
>
> vspltis_shifted (rtx op): /* If all elements are equal, we don't need to 
> do VSLDOI.  */
>
>
> (gdb) p op
> $7 = (rtx_def *) (const_vector:V4SI [
> (const_int 0 [0]) repeated x4
> ])
> (gdb) p easy_vector_constant_vsldoi(op, V4SImode)
> $8 = false
> p easy_vector_constant(op, V4SImode)
> $9 = true

Okay, thanks for checking.

>
> >
> >>> + (match_dup 1)
> >>> + (match_operand:VM 2 "u5bit_cint_operand")]
> > This should be match_operand:QI, right?
>
> Yes.

This patch is okay with the other changes.

Thanks, David


Re: [patch] Fix reverse SSO issues in IPA-SRA

2022-01-11 Thread Martin Jambor
Hi Eric,

On Tue, Jan 11 2022, Eric Botcazou via Gcc-patches wrote:
> Hi,
>
> we recently received the report that the IPA-SRA pass introduced in GCC 10 
> does not always play nice with the reverse scalar storage order that can be 
> used in structures/records/unions.  Reading the code, the pass apparently 
> correctly detects it but fails to propagate the information to the rewriting 
> phase in some cases and, in particular, does not stream it for LTO.
>
> The attached patch is a tentative fix for these issues spotted essentially by 
> code reading.  It also contains various minor tweaks left and right.
>
> Bootstrapped/regtested on x86-64/Linux, OK for mainline, 11 and 10 branches?
>
>
> 2022-01-11  Eric Botcazou  
>
>   * ipa-param-manipulation.c (ipa_dump_adjusted_parameters): Dump
>   reverse flag as "reverse" for the sake of consistency.
>   * ipa-sra.c: Fix copyright year.
>   (ipa_sra_function_summaries::duplicate): Copy the reverse flag.
>   (dump_isra_access): Remove confusing dump line.
>   (isra_write_node_summary): Write the reverse flag.
>   (isra_read_node_info): Read it.
>   (pull_accesses_from_callee): Copy it.

Thanks for the fixes, the forgotten duplication and streaming were quite
embarrassing, but one reason is that there are few reverse SSO testcases
in the suite.  Would it be difficult to add some covering the issues you
fixed?

Apart from that...

> @@ -664,8 +663,6 @@ dump_isra_access (FILE *f, param_access *access)
>print_generic_expr (f, access->alias_ptr_type);
>if (access->certain)
>  fprintf (f, ", certain");
> -  else
> -fprintf (f, ", not-certain");
>if (access->reverse)
>  fprintf (f, ", reverse");
>fprintf (f, "\n");

...is this strictly necessary?  I know it is inconsistent but the
certain flag is fairly special.  More importantly...

> @@ -3349,6 +3346,7 @@ pull_accesses_from_callee (cgraph_node *caller, 
> isra_param_desc *param_desc,
> copy->type = argacc->type;
> copy->alias_ptr_type = argacc->alias_ptr_type;
> copy->certain = true;
> +   copy->reverse = argacc->reverse;
> vec_safe_push (param_desc->accesses, copy);
>   }
>else if (prop_kinds[j] == ACC_PROP_CERTAIN)

...earlier in the function, there is a check doing:

  if (argacc->alias_ptr_type != pacc->alias_ptr_type
  || !types_compatible_p (argacc->type, pacc->type))
return "propagated access types would not match existing ones";

Will the types_compatible_p catch the case when one type is a
reverse-SSO and the other is not?  If not, we probably need to check
that the flags are the same too.

Thanks a gain for looking into this.

Martin



[committed] libstdc++: Make copyable-box completely constexpr (LWG 3572)

2022-01-11 Thread Jonathan Wakely via Gcc-patches
Tested powerpc64le-linux. Pushed to trunk.


This LWG issue was approved at the October 2021 plenary and can be
implemented now that std::optional is fully constexpr.

libstdc++-v3/ChangeLog:

* include/std/ranges (ranges::__detail::__box): Add constexpr to
assignment operators (LWG 3572).
* testsuite/std/ranges/adaptors/filter.cc: Check assignment of a
view that uses copyable-box.
---
 libstdc++-v3/include/std/ranges   |  5 ++--
 .../testsuite/std/ranges/adaptors/filter.cc   | 28 +++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index c90d33c89fb..780a3633417 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -109,7 +109,8 @@ namespace ranges
 
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 3477. Simplify constraints for semiregular-box
-   __box&
+   // 3572. copyable-box should be fully constexpr
+   constexpr __box&
operator=(const __box& __that)
noexcept(is_nothrow_copy_constructible_v<_Tp>)
requires (!copyable<_Tp>)
@@ -124,7 +125,7 @@ namespace ranges
  return *this;
}
 
-   __box&
+   constexpr __box&
operator=(__box&& __that)
noexcept(is_nothrow_move_constructible_v<_Tp>)
requires (!movable<_Tp>)
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/filter.cc 
b/libstdc++-v3/testsuite/std/ranges/adaptors/filter.cc
index b8d081e1d5e..ed5a01ca595 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/filter.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/filter.cc
@@ -140,6 +140,33 @@ test06()
   static_assert(!requires { views::all | filter; });
 }
 
+constexpr bool
+test07()
+{
+  struct Pred
+  {
+constexpr Pred() { }
+constexpr Pred(const Pred&) { }
+constexpr Pred(Pred&&) { }
+// These make it non-copyable, so non-copyable-box will provide
+// assignment.
+Pred& operator=(const Pred&) = delete;
+Pred& operator=(Pred&&) = delete;
+
+bool operator()(int i) const { return i < 10; }
+  };
+
+  int i = 0;
+  ranges::filter_view v(views::single(i), Pred{});
+  // LWG 3572. copyable-box should be fully constexpr
+  v = v;
+  v = std::move(v);
+
+  return true;
+}
+
+static_assert( test07() );
+
 int
 main()
 {
@@ -150,4 +177,5 @@ main()
   test05();
   test05();
   test06();
+  test07();
 }
-- 
2.31.1



[committed] libstdc++: Add missing noexcept to lazy_split_view iterator (LWG 3593)

2022-01-11 Thread Jonathan Wakely via Gcc-patches
Tested powerpc64le-linux. Pushed to trunk.


This was approved at the October 2021 plenary. We already have noexcept
in the other places the issue adds it in the spec.

libstdc++-v3/ChangeLog:

* include/std/ranges (ranges::lazy_split_view::_InnerIter::end()):
Add neoxcept (LWG 3593).
---
 libstdc++-v3/include/std/ranges | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 780a3633417..ac85907f129 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -3066,7 +3066,7 @@ namespace views::__adaptor
{ return _InnerIter<_Const>{_M_i}; }
 
constexpr default_sentinel_t
-   end() const
+   end() const noexcept
{ return default_sentinel; }
  };
 
-- 
2.31.1



Re: [Patch][V3][Patch 1/2]Change the 3rd parameter of function .DEFERRED_INIT from IS_VLA to decl name

2022-01-11 Thread Qing Zhao via Gcc-patches


> On Jan 11, 2022, at 7:53 AM, Richard Biener  
> wrote:
> 
> On Tue, Jan 11, 2022 at 12:58 AM Qing Zhao  wrote:
>> 
>> Hi, Richard,
>> 
>> I splited the previous patch for “Enable -Wuninitialized + 
>> -ftrivial-auto-var-init for address taken variables” into two separate 
>> patches.
>> This is the first one
>> 
>> This first  patch  is to fix (or work around ) PR103720, therefore it’s an 
>> important change, and need to be go into GCC12.
>> At the same time, this patch is the preparation for the second patch that 
>> will actually enable -Wuninitialized + -ftrivial-auto-var-init for address 
>> taken variables.
>> 
>> The reason I separate the previous patch into two is: most of the previous 
>> concern was on the second part of the patch (the change in 
>> tree-ssa-uninit.c), I don’t
>> want those concern prevent this first patch from being approved into GCC12.
>> 
>> 
>> In this part, I addressed your comments in  gimplify.c :
>> 
>> =
>> tree decl_name
>> += build_string_literal (IDENTIFIER_LENGTH (DECL_NAME (decl)) + 1,
>> +   IDENTIFIER_POINTER (DECL_NAME (decl)));
>> 
>> you need to deal with DECL_NAME being NULL.
>> =
>> 
>> Please also see the detailed description below for the problem and solution 
>> of this patch.
>> 
>> This first patch has been bootstrapped and regressing tested on both X86 and 
>> aarch64.
>> 
>> Okay for GCC12?
> 
> +
> +  char *decl_name_anonymous = xasprintf ("D.%u", DECL_UID (decl));
> +  const char *decl_name_str = DECL_NAME (decl)
> + ? IDENTIFIER_POINTER (DECL_NAME (decl))
> + : decl_name_anonymous;
> +  tree decl_name
> += build_string_literal (strlen (decl_name_str) + 1,
> +   decl_name_str);
> 
> please avoid the xasprintf in the case DECL_NAME is not NULL, I'd be happy
> with sth like
> 
>   tree decl_name;
>   if (DECL_NAME (decl))
>  decl_name = build_string_literal (...);
>   else
>  {
> char *decl_name_anon = xasprintf (...);
> decl_name = build_string_literal (...);
> free (decl_name_anon);
>  }
> 
> otherwise the patch is OK to commit (just do the above change and
> re-test / push).

Thanks for the comment, will fix this and commit the patch.

Qing
> 
> Thanks,
> Richard.
> 
>> Thanks.
>> 
>> Qing.
>> 
>> 
>> =
>> 
>> Change the 3rd parameter of function .DEFERRED_INIT from
>> IS_VLA to decl name.
>> 
>> Currently, the 3rd parameter of function .DEFERRED_INIT is IS_VLA, which is
>> not needed at all;
>> 
>> In this patch, we change the 3rd parameter from IS_VLA to the name of the var
>> decl for the following purposes:
>> 
>> 1. Fix (or work around) PR103720:
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103720
>> 
>> As confirmed in PR103720, with the current definition of .DEFERRED_INIT,
>> 
>> Dom transformed:
>>  c$a$0_6 = .DEFERRED_INIT (8, 2, 0);
>>  _1 = .DEFERRED_INIT (8, 2, 0);
>> 
>> into:
>>  c$a$0_6 = .DEFERRED_INIT (8, 2, 0);
>>  _1 = c$a$0_6;
>> 
>> which is incorrectly done due to Dom treating the two calls to const function
>> .DEFERRED_INIT as the same call since all actual parameters are the same.
>> 
>> The same issue has been exposed in PR102608 due to a different optimization 
>> VN,
>> the fix for PR102608 is to specially handle call to .DEFERRED_INIT in VN to
>> exclude it from CSE.
>> 
>> To fix PR103720, we could do the same as the fix to PR102608 to specially
>> handle call to .DEFERRED_INIT in Dom to exclude it from being optimized.
>> 
>> However, in addition to Dom and VN, there should be other optimizations that
>> have the same issue as PR103720 or PR102608 (As I built Linux kernel with
>> -ftrivial-auto-var-init=zero -Werror, I noticed a bunch of bugos warnings).
>> 
>> Other than identifying all the optimizations and specially handling call to
>> .DEFERRED_INIT in all these optimizations, changing the 3rd parameter of the
>> function .DEFERRED_INIT from IS_VLA to the name string of the var decl might
>> be a better workaround (or a fix). After this change, since the 3rd actual
>> parameter is the name string of the variable, different calls for different
>> variables will have different name strings as the 3rd actual, As a result, 
>> the
>> optimization that previously treated the different calls to .DEFERRED_INIT as
>> the same will be prevented.
>> 
>> 2. Prepare for enabling -Wuninitialized + -ftrivail-auto-var-init for address
>> taken variables.
>> 
>> As discussion in the following thread:
>> 
>> https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577431.html
>> 
>> With the current implemenation of -ftrivial-auto-var-init and uninitialized
>> warning analysis, the uninitialized warning for an address taken auto 
>> variable
>> might be missed since the variable is completely eliminated by optimization 
>> and
>> replaced with a temporary variable in all the uses.
>> 
>> In order to improve such situation, changing the 3rd pa

Re: [PATCH] Mass rename of C++ .c files to .cc suffix

2022-01-11 Thread Toon Moene

On 1/11/22 13:56, Martin Liška wrote:


Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Plus it survives build of all FEs (--enable-languages=all) on 
x86_64-linux-gnu

and I've built all cross compilers.


Does this also rename .c files in the fortran and libgfortran directories ?

I would recommend to send this message to the fort...@gcc.gnu.org list 
too, then.


Not everyone reads the gcc and gcc-patches lists ...

Kind regards,

--
Toon Moene - e-mail: t...@moene.org - phone: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands


Re: [PATCH] Mass rename of C++ .c files to .cc suffix

2022-01-11 Thread Martin Liška

On 1/11/22 16:48, Toon Moene wrote:

On 1/11/22 13:56, Martin Liška wrote:


Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Plus it survives build of all FEs (--enable-languages=all) on x86_64-linux-gnu
and I've built all cross compilers.


Does this also rename .c files in the fortran and libgfortran directories ?


Hello.

Yes, it does the first one.



I would recommend to send this message to the fort...@gcc.gnu.org list too, 
then.

Not everyone reads the gcc and gcc-patches lists ...


CCing the list now.

Thanks,
Martin



Kind regards,





Re: [PATCH] Mass rename of C++ .c files to .cc suffix

2022-01-11 Thread Jakub Jelinek via Gcc-patches
On Tue, Jan 11, 2022 at 04:50:02PM +0100, Martin Liška wrote:
> On 1/11/22 16:48, Toon Moene wrote:
> > On 1/11/22 13:56, Martin Liška wrote:
> > 
> > > Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> > > Plus it survives build of all FEs (--enable-languages=all) on 
> > > x86_64-linux-gnu
> > > and I've built all cross compilers.
> > 
> > Does this also rename .c files in the fortran and libgfortran directories ?
> 
> Hello.
> 
> Yes, it does the first one.

And it shouldn't in libgfortran - libgfortran, libgcc, libgomp, libquadmath are 
all
written in C, not C++.
While e.g. libcpp or gcc are in C++.

Jakub



Re: [PATCH] Mass rename of C++ .c files to .cc suffix

2022-01-11 Thread Martin Liška

On 1/11/22 16:56, Jakub Jelinek wrote:

While e.g. libcpp or gcc are in C++.


Which means I should rename .c files under libcpp, right?
Is there any other folder from gcc/ and libcpp/ that would need that as well?

Martin


Re: [PATCH] Mass rename of C++ .c files to .cc suffix

2022-01-11 Thread Jakub Jelinek via Gcc-patches
On Tue, Jan 11, 2022 at 05:03:34PM +0100, Martin Liška wrote:
> On 1/11/22 16:56, Jakub Jelinek wrote:
> > While e.g. libcpp or gcc are in C++.
> 
> Which means I should rename .c files under libcpp, right?
> Is there any other folder from gcc/ and libcpp/ that would need that as well?

>From the directories that use .c files for C++, I think that is all.
c++tools/, libcody/, libitm/, libsanitizer/, libstdc++-v3/ already
use .cc or .cpp.

Jakub



Re: [Patch][V2]Enable -Wuninitialized + -ftrivial-auto-var-init for address taken variables

2022-01-11 Thread Qing Zhao via Gcc-patches
Hi, Richard,

> On Jan 11, 2022, at 7:43 AM, Richard Biener  
> wrote:
> 
 
 
 1.  Add some meaningful temporaries to break the long expression to make it
Readable. And also add comments to explain the purpose of the statement;
 
 2.  Resolve the memory leakage of the dynamically created string.
 
 The patch has been bootstrapped and regressing tested on both x86 and 
 aarch64, no issues.
 Okay for commit?
>>> 
>>> tree decl_name
>>> += build_string_literal (IDENTIFIER_LENGTH (DECL_NAME (decl)) + 1,
>>> +   IDENTIFIER_POINTER (DECL_NAME (decl)));
>>> 
>>> you need to deal with DECL_NAME being NULL.
>> 
>> Okay.
>> Usually under what situation, the decl_name will be NULL?
> 
> I don't know but it definitely happens.
> 
>>> It's also a bit awkward
>>> to build another
>>> copy of all decl names :/
>> 
>> Yes, this is awkward. But it might be unavoidable for address taken 
>> variables since the original variable might be completely deleted by 
>> optimizations.
>> See the details at:
>> https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577431.html
>> 
>> We had a previous discussion on this issue, and the idea of adding this 3rd 
>> argument with the name of the variable was proposed by you at that time. -:)
> 
> I know ... I didn't have a better idea.

I think that adding the name string of the auto variable as one parameter to 
the function .DEFERRED_INIT might be the only solution to this issue? (In the 
very beginning of the implementation, we added the VAR itself as one parameter 
to the function .DEFERRED_INIT, but that design didn’t work out)
> 
>> 
>> 
>>> 
>>> + /* The LHS of the call is a temporary variable, we use it as a
>>> +placeholder to record the information on whether the warning
>>> +has been issued or not.  */
>>> + repl_var = gimple_call_lhs (def_stmt);
>>> 
>>> this seems to be a change that can be done independently?
>> 
>> The major purpose of this “repl_var” is used to record the info whether the 
>> warning has been issued for the variable or not, then avoid emitting it 
>> again later.
>> Since the original variable has been completely deleted by optimization, we 
>> have to use this “repl_var” for a placeholder to record such info.
> 
> But the ... = .DEFERRED_INIT stmt itself could be used to record this
> since its location is
> already used to indicate the original location, like with
> suppress_warning/warning_suppressed_p?

Ah, I will check on this. Thanks a lot.
> 
>>> 
>>> + /* Ignore the call to .DEFERRED_INIT that define the original
>>> +var itself.  */
>>> + if (is_gimple_assign (context))
>>> +   {
>>> + if (TREE_CODE (gimple_assign_lhs (context)) == VAR_DECL)
>>> +   lhs_var = gimple_assign_lhs (context);
>>> + else if (TREE_CODE (gimple_assign_lhs (context)) == SSA_NAME)
>>> +   lhs_var = SSA_NAME_VAR (gimple_assign_lhs (context));
>>> +   }
>>> + if (lhs_var
>>> + && (lhs_var_name = DECL_NAME (lhs_var))
>>> + && (lhs_var_name_str = IDENTIFIER_POINTER (lhs_var_name))
>>> + && (strcmp (lhs_var_name_str, var_name_str) == 0))
>>> +   return;
>>> 
>>> likewise but I don't really understand what you are doing here.
>> 
>> The above is to exclude the following case:
>> 
>>   temp = .DEFERRED_INIT (4, 2, “alt_reloc");
>>   alt_reloc = temp;
>> 
>> i.e, a call to .DEFERRED_INIT that define the original variable itself.
> 
> How can this happen?  It looks like a bug to me.  Do you have a testcase?
With -ftrivial-auto-var-init, During gimplification phase, almost all address 
taken variables that do not have an explicit initializer will have the above IR 
pattern.

For example, gcc.dg/auto-init-uninit-16.c:

[opc@qinzhao-ol8u3-x86 gcc]$ cat 
/home/opc/Work/GCC/latest-gcc/gcc/testsuite/gcc.dg/auto-init-uninit-16.c  
/* { dg-do compile } */
/* { dg-options "-O2 -Wuninitialized -ftrivial-auto-var-init=zero" } */

int foo, bar;

static
void decode_reloc(int reloc, int *is_alt)
{
  if (reloc >= 20)
  *is_alt = 1;
  else if (reloc >= 10)
  *is_alt = 0;
}

void testfunc()
{
  int alt_reloc;

  decode_reloc(foo, &alt_reloc);

  if (alt_reloc) /* { dg-warning "may be used uninitialized" "" }  */
bar = 42;
}

With  -ftrivial-auto-var-init=zero, the IR after gimplification is:

  _1 = .DEFERRED_INIT (4, 2, &"alt_reloc"[0]);
  alt_reloc = _1;

And the IR after SSA is similar as the above:

  _1 = .DEFERRED_INIT (4, 2, &"alt_reloc"[0]);
  alt_reloc = _1;

During the early uninitialized analysis phase, the above IR will feed to the 
analyzer, we should exclude such 
IR from issuing fake warnings.

> 
>> 
>>> I'm
>>> also not sure
>>> I understand the case we try to fix with passing the name - is that
>>> for VLA decls
>>> that get replaced by allocation?
>> 
>> This whole patch is mainly to resolve the i

Re: [PATCH] c-family: Fix up -W*conversion on bitwise &/|/^ [PR101537]

2022-01-11 Thread Jason Merrill via Gcc-patches

On 1/4/22 04:32, Jakub Jelinek wrote:

Hi!

The following testcases emit a bogus -Wconversion warning.  This is because
conversion_warning function doesn't handle BIT_*_EXPR (only unsafe_conversion_p
that is called during the default: case, and that one doesn't handle
SAVE_EXPRs added because the unsigned char & or | operands promoted to int
have side-effects and =| or =& is used.

The patch handles BIT_IOR_EXPR/BIT_XOR_EXPR like the last 2 operands of
COND_EXPR by recursing on the two operands, if either of them doesn't fit
into the narrower type, complain.  BIT_AND_EXPR too, but first it needs to
handle some special cases that unsafe_conversion_p does, namely when one
of the two operands is a constant.

This fixes completely the pr101537.c test and for C also pr103881.c
and doesn't regress anything in the testsuite, for C++ pr103881.c still
emits the bogus warnings.
This is because while the C FE emits in that case a SAVE_EXPR that
conversion_warning can handle already, C++ FE emits
TARGET_EXPR , something | D.whatever


in stabilize_expr, yes.


etc. and conversion_warning handles COMPOUND_EXPR by "recursing" on the
rhs.  To handle that case, we'd need for TARGET_EXPR on the lhs remember
in some hash map the mapping from D.whatever to the TARGET_EXPR and when
we see D.whatever, use corresponding TARGET_EXPR initializer instead.


Agreed.


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


OK.


2022-01-04  Jakub Jelinek  

PR c/101537
PR c/103881
gcc/c-family/
* c-warn.c (conversion_warning): Handle BIT_AND_EXPR, BIT_IOR_EXPR
and BIT_XOR_EXPR.
gcc/testsuite/
* c-c++-common/pr101537.c: New test.
* c-c++-common/pr103881.c: New test.

--- gcc/c-family/c-warn.c.jj2022-01-03 10:40:49.745044771 +0100
+++ gcc/c-family/c-warn.c   2022-01-03 12:42:55.174012944 +0100
@@ -1304,6 +1304,34 @@ conversion_warning (location_t loc, tree
|| conversion_warning (loc, type, op2, result));
}
  
+case BIT_AND_EXPR:

+  if (TREE_CODE (expr_type) == INTEGER_TYPE
+ && TREE_CODE (type) == INTEGER_TYPE)
+   for (int i = 0; i < 2; ++i)
+ {
+   tree op = TREE_OPERAND (expr, i);
+   if (TREE_CODE (op) != INTEGER_CST)
+ continue;
+
+   /* If one of the operands is a non-negative constant
+  that fits in the target type, then the type of the
+  other operand does not matter.  */
+   if (int_fits_type_p (op, c_common_signed_type (type))
+   && int_fits_type_p (op, c_common_unsigned_type (type)))
+ return false;
+
+   /* If constant is unsigned and fits in the target
+  type, then the result will also fit.  */
+   if (TYPE_UNSIGNED (TREE_TYPE (op)) && int_fits_type_p (op, type))
+ return false;
+ }
+  /* FALLTHRU */
+case BIT_IOR_EXPR:
+case BIT_XOR_EXPR:
+  return (conversion_warning (loc, type, TREE_OPERAND (expr, 0), result)
+ || conversion_warning (loc, type, TREE_OPERAND (expr, 1),
+result));
+
  default_:
  default:
conversion_kind = unsafe_conversion_p (type, expr, result, true);
--- gcc/testsuite/c-c++-common/pr101537.c.jj2022-01-03 12:08:33.781823852 
+0100
+++ gcc/testsuite/c-c++-common/pr101537.c   2022-01-03 12:08:33.781823852 
+0100
@@ -0,0 +1,26 @@
+/* PR c/101537 */
+/* { dg-do compile } */
+/* { dg-options "-Wconversion" } */
+
+int
+foo ()
+{
+  int aaa = 1;
+  unsigned char bbb = 0;
+  bbb |= aaa ? 1 : 0;
+  return bbb;
+}
+
+int
+bar (unsigned char x, int f)
+{
+  x |= f ? 1 : 0;
+  return x;
+}
+
+int
+baz (unsigned char x, int f)
+{
+  x = x | f ? 1 : 0;
+  return x;
+}
--- gcc/testsuite/c-c++-common/pr103881.c.jj2022-01-03 12:08:33.781823852 
+0100
+++ gcc/testsuite/c-c++-common/pr103881.c   2022-01-03 12:08:33.781823852 
+0100
@@ -0,0 +1,20 @@
+/* PR c/103881 */
+/* { dg-do compile } */
+/* { dg-options "-Wconversion" } */
+
+unsigned char bar (void);
+
+void
+foo (void)
+{
+  unsigned char t = 0;
+  t |= bar ();
+  t |= bar () & bar ();/* { dg-bogus "conversion from 'int' to 'unsigned char' may change 
value" "" { xfail c++ } } */
+  t &= bar () & bar ();/* { dg-bogus "conversion from 'int' to 'unsigned char' may 
change value" "" { xfail c++ } } */
+  t = bar () & bar ();
+
+  unsigned char a = bar ();
+  t |= a & a;
+  t |= bar () & a; /* { dg-bogus "conversion from 'int' to 'unsigned char' may change 
value" "" { xfail c++ } } */
+  t |= a & bar (); /* { dg-bogus "conversion from 'int' to 'unsigned char' may change 
value" "" { xfail c++ } } */
+}

Jakub





Re: [PATCH] c++: Silence -Wuseless-cast warnings during move [PR103480]

2022-01-11 Thread Jason Merrill via Gcc-patches

On 12/31/21 04:30, Jakub Jelinek wrote:

Hi!

This is maybe just a shot in the dark, but IMHO we shouldn't be diagnosing
-Wuseless-cast on casts the compiler adds on its own when calling its move
function.  We don't seem to warn when user calls std::move either.
We call move on elinit (*NON_LVALUE_EXPR <(struct C[2] &&) &D.2497->b>)[0]
so it is already an xvalue_p and try to static_cast it to struct C &&.
But we don't warn e.g. on std::move (std::move (whatever)).

Bootstrapped/regtested on x86_64-linux and i686-linux.


Maybe we should

if (xvalue_p (expr))
  return expr;

instead?  OK either way.


2021-12-31  Jakub Jelinek  

PR c++/103480
* tree.c (move): Add warn_useless_cast warning sentinel.

* g++.dg/warn/Wuseless-cast2.C: New test.

--- gcc/cp/tree.c.jj2021-12-30 15:12:42.739157171 +0100
+++ gcc/cp/tree.c   2021-12-30 18:39:08.050679041 +0100
@@ -1288,6 +1288,7 @@ move (tree expr)
tree type = TREE_TYPE (expr);
gcc_assert (!TYPE_REF_P (type));
type = cp_build_reference_type (type, /*rval*/true);
+  warning_sentinel w (warn_useless_cast);
return build_static_cast (input_location, type, expr,
tf_warning_or_error);
  }
--- gcc/testsuite/g++.dg/warn/Wuseless-cast2.C.jj   2021-12-30 
18:46:17.437651681 +0100
+++ gcc/testsuite/g++.dg/warn/Wuseless-cast2.C  2021-12-30 18:45:41.044162541 
+0100
@@ -0,0 +1,24 @@
+// PR c++/103480
+// { dg-do compile { target c++14 } }
+// { dg-options "-Wuseless-cast" }
+
+template 
+struct A { typedef T t[N]; };
+template 
+struct B { typename A::t b; };
+struct C {
+  constexpr C (C &&) {}
+  template 
+  static auto bar ()
+  {
+B r;
+return r;  // { dg-bogus "useless cast to type" }
+  }
+  C () = default;
+};
+
+void
+foo ()
+{
+  C::bar<2> ();
+}

Jakub





Re: [PATCH] c++: Fix ICEs with OBJ_TYPE_REF pretty printing [PR101597]

2022-01-11 Thread Jason Merrill via Gcc-patches

On 12/31/21 04:13, Jakub Jelinek wrote:

Hi!

The following testcase ICEs, because middle-end uses the C++ FE pretty
printing code through langhooks in the diagnostics.
The FE expects OBJ_TYPE_REF_OBJECT's type to be useful (pointer to the
class type it is called on), but in the middle-end conversions between
pointer types are useless, so the actual type can be some random
unrelated pointer type (in the testcase void * pointer).  The pretty
printing code then ICEs on it.

The following patch fixes that by sticking the original
OBJ_TYPE_REF_OBJECT's also as type of OBJ_TYPE_REF_TOKEN operand.
That one must be an INTEGER_CST, all the current uses of
OBJ_TYPE_REF_TOKEN just use tree_to_uhwi or tree_to_shwi on it,
and because it is constant, there is no risk of the middle-end propagating
into it some other pointer type.  So, approach similar to how MEM_REF
treats its second operand or a couple of internal functions (e.g.
IFN_VA_ARG) some of its parameters.

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


This new expectation needs to be documented in tree.def.  OK with that 
change.



2021-12-30  Jakub Jelinek  

PR c++/101597
gcc/cp/
* class.c (build_vfn_ref): Build OBJ_TYPE_REF with INTEGER_CST
OBJ_TYPE_REF_TOKEN with type equal to OBJ_TYPE_REF_OBJECT type.
* error.c (resolve_virtual_fun_from_obj_type_ref): Use type of
OBJ_TYPE_REF_TOKEN rather than type of OBJ_TYPE_REF_OBJECT as
obj_type.
gcc/objc/
* objc-act.c (objc_rewrite_function_call): Build OBJ_TYPE_REF
with INTEGER_CST OBJ_TYPE_REF_TOKEN with type equal to
OBJ_TYPE_REF_OBJECT type.
* objc-next-runtime-abi-01.c (build_objc_method_call): Likewise.
* objc-gnu-runtime-abi-01.c (build_objc_method_call): Likewise.
* objc-next-runtime-abi-02.c (build_v2_objc_method_fixup_call,
build_v2_build_objc_method_call): Likewise.
gcc/testsuite/
* g++.dg/opt/pr101597.C: New test.

--- gcc/cp/class.c.jj   2021-12-30 15:12:42.706157630 +0100
+++ gcc/cp/class.c  2021-12-30 17:16:23.567589120 +0100
@@ -778,7 +778,8 @@ build_vfn_ref (tree instance_ptr, tree i
   cp_build_addr_expr (aref, tf_warning_or_error));
  
/* Remember this as a method reference, for later devirtualization.  */

-  aref = build3 (OBJ_TYPE_REF, TREE_TYPE (aref), aref, instance_ptr, idx);
+  aref = build3 (OBJ_TYPE_REF, TREE_TYPE (aref), aref, instance_ptr,
+fold_convert (TREE_TYPE (instance_ptr), idx));
  
return aref;

  }
--- gcc/cp/error.c.jj   2021-12-30 15:12:42.714157519 +0100
+++ gcc/cp/error.c  2021-12-30 17:16:23.568589106 +0100
@@ -2149,7 +2149,7 @@ dump_expr_init_vec (cxx_pretty_printer *
  static tree
  resolve_virtual_fun_from_obj_type_ref (tree ref)
  {
-  tree obj_type = TREE_TYPE (OBJ_TYPE_REF_OBJECT (ref));
+  tree obj_type = TREE_TYPE (OBJ_TYPE_REF_TOKEN (ref));
HOST_WIDE_INT index = tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref));
tree fun = BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type)));
while (index)
--- gcc/objc/objc-act.c.jj  2021-12-30 15:12:43.159151319 +0100
+++ gcc/objc/objc-act.c 2021-12-30 17:16:23.569589092 +0100
@@ -9644,11 +9644,9 @@ objc_rewrite_function_call (tree functio
&& TREE_CODE (TREE_OPERAND (function, 0)) == ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (TREE_OPERAND (function, 0), 0))
 == FUNCTION_DECL)
-{
-  function = build3 (OBJ_TYPE_REF, TREE_TYPE (function),
-TREE_OPERAND (function, 0),
-first_param, size_zero_node);
-}
+function = build3 (OBJ_TYPE_REF, TREE_TYPE (function),
+  TREE_OPERAND (function, 0), first_param,
+  build_int_cst (TREE_TYPE (first_param), 0));
  
return function;

  }
--- gcc/objc/objc-next-runtime-abi-01.c.jj  2021-12-30 15:12:43.159151319 
+0100
+++ gcc/objc/objc-next-runtime-abi-01.c 2021-12-30 17:16:23.569589092 +0100
@@ -883,7 +883,7 @@ build_objc_method_call (location_t loc,
  
/* Build an obj_type_ref, with the correct cast for the method call.  */

t = build3 (OBJ_TYPE_REF, sender_cast, method,
-   lookup_object, size_zero_node);
+ lookup_object, build_int_cst (TREE_TYPE (lookup_object), 0));
t = build_function_call_vec (loc, vNULL, t, parms, NULL);
vec_free (parms);
return t;
--- gcc/objc/objc-gnu-runtime-abi-01.c.jj   2021-12-30 14:16:42.837908238 
+0100
+++ gcc/objc/objc-gnu-runtime-abi-01.c  2021-12-30 17:16:23.569589092 +0100
@@ -725,7 +725,8 @@ build_objc_method_call (location_t loc,
parms->quick_push (TREE_VALUE (method_params));
  
/* Build an obj_type_ref, with the correct cast for the method call.  */

-  t = build3 (OBJ_TYPE_REF, sender_cast, method, lookup_object, 
size_zero_node);
+  t = build3 (OBJ_TYPE_REF, sender_cast, method, lookup_object,
+ build_int_cst (TREE_TYPE (lookup_object), 0));
t = build_funct

Re: [PATCH] PR 102935, Fix pr101384-1.c code generation test.

2022-01-11 Thread Bill Schmidt via Gcc-patches
Hi Mike,

This looks fine to me.  Maintainers?

Thanks,
Bill

On 1/7/22 6:33 PM, Michael Meissner wrote:
> Fix pr101384-1.c code generation test.
>
> Add support for the compiler using XXSPLTIB reg,255 to load all 1's into a
> register on power9 and above instead of using VSPLTI{B,H,W} reg,-1.
>
> gcc/testsuite/
> 2022-01-07  Michael Meissner  
>
>   PR testsuite/102935
>   * gcc.target/powerpc/pr101384-1.c: Update insn regexp for power9
>   and power10.
> ---
>  gcc/testsuite/gcc.target/powerpc/pr101384-1.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/testsuite/gcc.target/powerpc/pr101384-1.c 
> b/gcc/testsuite/gcc.target/powerpc/pr101384-1.c
> index 627d7d76721..41cf84bf8bc 100644
> --- a/gcc/testsuite/gcc.target/powerpc/pr101384-1.c
> +++ b/gcc/testsuite/gcc.target/powerpc/pr101384-1.c
> @@ -2,7 +2,7 @@
>  /* { dg-do compile { target le } } */
>  /* { dg-options "-O2 -maltivec" } */
>  /* { dg-require-effective-target powerpc_altivec_ok } */
> -/* { dg-final { scan-assembler-times {\mvspltis[whb] [^\n\r]*,-1\M} 9 } } */
> +/* { dg-final { scan-assembler-times {\mvspltis[whb] 
> [^\n\r]*,-1\M|\mxxspltib[^\n\r]*,255\M} 9 } } */
>  /* { dg-final { scan-assembler-times {\mvslw\M} 3 } } */
>  /* { dg-final { scan-assembler-times {\mvslh\M} 3 } } */
>  /* { dg-final { scan-assembler-times {\mvslb\M} 3 } } */


Re: [PATCH] c++: dependent bases and 'this' availability [PR103831]

2022-01-11 Thread Jason Merrill via Gcc-patches

On 12/28/21 10:08, Patrick Palka wrote:

Here during satisfaction of B's associated constraints we're failing to
reject the object-less call to the non-static member function A::size
ultimately because satisfaction is performed in the (access) context of
the class template B, which has a dependent bases, and so the
any_dependent_bases_p check within build_new_method_call causes us to
avoid rejecting the call.

This patch fixes this by refining the any_dependent_bases_p check within
build_new_method_call: dependent bases can't make a difference for
resolving the implicit object parameter if we're in a conext where
'this' is unavailable, so let's check current_class_ptr too.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk and perhaps 11?  The first testcase exhibits a regression
introduced by r12-1937.


OK for both.


PR c++/103831

gcc/cp/ChangeLog:

* call.c (build_new_method_call): Consider dependent bases only
if 'this' is available.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-class3.C: New test.
* g++.dg/template/non-dependent18.C: New test.
---
  gcc/cp/call.c |  2 +-
  gcc/testsuite/g++.dg/cpp2a/concepts-class3.C  | 12 
  .../g++.dg/template/non-dependent18.C | 19 +++
  3 files changed, 32 insertions(+), 1 deletion(-)
  create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-class3.C
  create mode 100644 gcc/testsuite/g++.dg/template/non-dependent18.C

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index bee367f57d7..3da9e7a6284 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -11098,7 +11098,7 @@ build_new_method_call (tree instance, tree fns, vec **args,
 we know we really need it.  */
  cand->first_arg = instance;
}
- else if (any_dependent_bases_p ())
+ else if (current_class_ptr && any_dependent_bases_p ())
/* We can't tell until instantiation time whether we can use
   *this as the implicit object argument.  */;
  else
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-class3.C 
b/gcc/testsuite/g++.dg/cpp2a/concepts-class3.C
new file mode 100644
index 000..68b50b71278
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-class3.C
@@ -0,0 +1,12 @@
+// PR c++/103831
+// { dg-do compile { target c++20 } }
+
+struct A {
+  constexpr int size() { return 42; } // non-static
+};
+
+template
+  requires (T::size() == 42) // { dg-error "without object" }
+struct B : T { };
+
+template struct B; // { dg-error "constraint" }
diff --git a/gcc/testsuite/g++.dg/template/non-dependent18.C 
b/gcc/testsuite/g++.dg/template/non-dependent18.C
new file mode 100644
index 000..7fe623d497f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/non-dependent18.C
@@ -0,0 +1,19 @@
+// PR c++/103831
+// { dg-do compile { target c++11 } }
+
+struct A {
+  constexpr int size() { return 42; } // non-static
+};
+
+template
+struct B : T {
+  static_assert(A::size() == 42); // { dg-error "without object" }
+
+  static int f() {
+static_assert(A::size() == 42, ""); // { dg-error "without object" }
+return A::size(); // { dg-error "without object" }
+  }
+
+  int n = A::size();
+  static const int m = A::size(); // { dg-error "without object" }
+};




[PATCH] ira: Fix old-reload targets [PR103974]

2022-01-11 Thread Richard Sandiford via Gcc-patches
The new IRA heuristics would need more work on old-reload targets,
since flattening needs to be able to undo the cost propagation.
It's doable, but hardly seems worth it.

This patch therefore makes all the new calls to
ira_subloop_allocnos_can_differ_p return false if !ira_use_lra_p.
The color_pass code that predated the new function (and that was
the source of ira_subloop_allocnos_can_differ_p) continues to
behave as before.

It's a hack, but at least it has the advantage that the new parameter
would become obviously unused if reload and (!)ira_use_lra_p were
removed.  The hack should therefore disappear alongside reload.

Tested on aarch64-linux-gnu and cris-elf.  OK to install?

Richard


gcc/
PR rtl-optimization/103974
* ira-int.h (ira_subloop_allocnos_can_differ_p): Take an
extra argument, default true, that says whether old-reload
targets should be excluded.
* ira-color.c (color_pass): Pass false.
---
 gcc/ira-color.c |  3 ++-
 gcc/ira-int.h   | 10 --
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/gcc/ira-color.c b/gcc/ira-color.c
index 36f3f4d70f3..59d978fe9b3 100644
--- a/gcc/ira-color.c
+++ b/gcc/ira-color.c
@@ -3664,7 +3664,8 @@ color_pass (ira_loop_tree_node_t loop_tree_node)
  ira_assert (bitmap_bit_p (subloop_node->all_allocnos,
ALLOCNO_NUM (subloop_allocno)));
  if (ira_single_region_allocno_p (a, subloop_allocno)
- || !ira_subloop_allocnos_can_differ_p (a, hard_regno >= 0))
+ || !ira_subloop_allocnos_can_differ_p (a, hard_regno >= 0,
+false))
{
  gcc_assert (!ALLOCNO_MIGHT_CONFLICT_WITH_PARENT_P
  (subloop_allocno));
diff --git a/gcc/ira-int.h b/gcc/ira-int.h
index e1e68025211..e80fdeb0328 100644
--- a/gcc/ira-int.h
+++ b/gcc/ira-int.h
@@ -1607,10 +1607,16 @@ ira_loop_border_costs::move_between_loops_cost () const
 
 /* Return true if subloops that contain allocnos for A's register can
use a different assignment from A.  ALLOCATED_P is true for the case
-   in which allocation succeeded for A.  */
+   in which allocation succeeded for A.  EXCLUDE_OLD_RELOAD is true if
+   we should always return false for non-LRA targets.  (This is a hack
+   and should be removed along with old reload.)  */
 inline bool
-ira_subloop_allocnos_can_differ_p (ira_allocno_t a, bool allocated_p = true)
+ira_subloop_allocnos_can_differ_p (ira_allocno_t a, bool allocated_p = true,
+  bool exclude_old_reload = true)
 {
+  if (exclude_old_reload && !ira_use_lra_p)
+return false;
+
   auto regno = ALLOCNO_REGNO (a);
 
   if (pic_offset_table_rtx != NULL
-- 
2.25.1


Re: [PATCH] Mass rename of C++ .c files to .cc suffix

2022-01-11 Thread Harald Anlauf via Gcc-patches

Am 11.01.22 um 16:50 schrieb Martin Liška:

On 1/11/22 16:48, Toon Moene wrote:

On 1/11/22 13:56, Martin Liška wrote:


Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Plus it survives build of all FEs (--enable-languages=all) on
x86_64-linux-gnu
and I've built all cross compilers.


Does this also rename .c files in the fortran and libgfortran
directories ?


Hello.

Yes, it does the first one.


Regarding fortran: can we have a vote on this one?

Some developers (including myself) are not really familiar with C++,
and in the past preference has been expressed on the fortran ML in
favor of not using too much C++.

I would also not really be in a position to review real C++ code.

Thanks,
Harald



I would recommend to send this message to the fort...@gcc.gnu.org list
too, then.

Not everyone reads the gcc and gcc-patches lists ...


CCing the list now.

Thanks,
Martin



Kind regards,








Re: [PATCH] PR 102935, Fix pr101384-1.c code generation test.

2022-01-11 Thread David Edelsohn via Gcc-patches
On Tue, Jan 11, 2022 at 12:06 PM Bill Schmidt  wrote:
>
> Hi Mike,
>
> This looks fine to me.  Maintainers?

Okay.

Thanks, David

>
> Thanks,
> Bill
>
> On 1/7/22 6:33 PM, Michael Meissner wrote:
> > Fix pr101384-1.c code generation test.
> >
> > Add support for the compiler using XXSPLTIB reg,255 to load all 1's into a
> > register on power9 and above instead of using VSPLTI{B,H,W} reg,-1.
> >
> > gcc/testsuite/
> > 2022-01-07  Michael Meissner  
> >
> >   PR testsuite/102935
> >   * gcc.target/powerpc/pr101384-1.c: Update insn regexp for power9
> >   and power10.
> > ---
> >  gcc/testsuite/gcc.target/powerpc/pr101384-1.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/gcc/testsuite/gcc.target/powerpc/pr101384-1.c 
> > b/gcc/testsuite/gcc.target/powerpc/pr101384-1.c
> > index 627d7d76721..41cf84bf8bc 100644
> > --- a/gcc/testsuite/gcc.target/powerpc/pr101384-1.c
> > +++ b/gcc/testsuite/gcc.target/powerpc/pr101384-1.c
> > @@ -2,7 +2,7 @@
> >  /* { dg-do compile { target le } } */
> >  /* { dg-options "-O2 -maltivec" } */
> >  /* { dg-require-effective-target powerpc_altivec_ok } */
> > -/* { dg-final { scan-assembler-times {\mvspltis[whb] [^\n\r]*,-1\M} 9 } } 
> > */
> > +/* { dg-final { scan-assembler-times {\mvspltis[whb] 
> > [^\n\r]*,-1\M|\mxxspltib[^\n\r]*,255\M} 9 } } */
> >  /* { dg-final { scan-assembler-times {\mvslw\M} 3 } } */
> >  /* { dg-final { scan-assembler-times {\mvslh\M} 3 } } */
> >  /* { dg-final { scan-assembler-times {\mvslb\M} 3 } } */


Re: [PATCH] Mass rename of C++ .c files to .cc suffix

2022-01-11 Thread Jonathan Wakely via Gcc-patches
On Tue, 11 Jan 2022 at 18:02, Harald Anlauf via Gcc  wrote:
>
> Am 11.01.22 um 16:50 schrieb Martin Liška:
> > On 1/11/22 16:48, Toon Moene wrote:
> >> On 1/11/22 13:56, Martin Liška wrote:
> >>
> >>> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> >>> Plus it survives build of all FEs (--enable-languages=all) on
> >>> x86_64-linux-gnu
> >>> and I've built all cross compilers.
> >>
> >> Does this also rename .c files in the fortran and libgfortran
> >> directories ?
> >
> > Hello.
> >
> > Yes, it does the first one.
>
> Regarding fortran: can we have a vote on this one?
>
> Some developers (including myself) are not really familiar with C++,
> and in the past preference has been expressed on the fortran ML in
> favor of not using too much C++.
>
> I would also not really be in a position to review real C++ code.

The discussion is purely about renaming files that are *already* C++
source files but have the misleading .c file extension.

Nobody is suggesting using C++ where it isn't already being used.


[PATCH] i386: Introduce V2QImode vector cmove for -msse4.1 [PR103861]

2022-01-11 Thread Uros Bizjak via Gcc-patches
This patch also moves V2HI and V4QImode vector conditional moves
to SSE4.1 targets.  Vector cmoves are implemented with SSE logic functions
without -msse4.1, and they are hardly worthwile for narrow vector modes.
More important, we would like to keep vector logic functions for GPR
registers, and the current RTX description of 32-bit vector modes logic
insns does not include the necessary CC reg clobber.  Solve these issues by
restricting vector cmove insns for these modes to -msse4.1, where logic
instructions are avoided, and pblend insn is used instead.

A follow-up patch will add clobbers and necessary splits to 32-bit
vector mode logic insns, and in a future patch, ix86_sse_movcc will be
improved to use expand_simple_{unop,binop} to emit logic insns, allowing
us to re-enable 16-bit and 32-bit narrow vector cmoves for -msse2.

2022-01-11  Uroš Bizjak  

gcc/ChangeLog:

PR target/103861
* config/i386/mmx.md (vcond):
Use VI_16_32 mode iterator.  Enable for TARGET_SSE4_1.
(vcondu): Ditto.
(vcond_mask_): Ditto.
(mmx_pblendvb_v8qi): Rename from mmx_pblendvb64.
(mmx_pblendvb_): Rename from mmx_pblendvb32.
Use VI_16_32 mode iterator.
* config/i386/i386-expand.c (ix86_expand_sse_movcc):
Update for rename.  Handle V2QImode.
(expand_vec_perm_blend): Update for rename.

gcc/testsuite/ChangeLog:

PR target/103861
* g++.target/i386/pr100637-1b.C (dg-options):
Use -msse4 instead of -msse2.
* g++.target/i386/pr100637-1w.C (dg-options): Ditto.
* g++.target/i386/pr103861-1.C: New test.
* gcc.target/i386/pr100637-4b.c (dg-options):
Use -msse4 instead of -msse2.
* gcc.target/i386/pr103861-4.c: New test.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Pushed to master.

Uros.
diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index add748bcf40..8b1266fb9f1 100644
--- a/gcc/config/i386/i386-expand.c
+++ b/gcc/config/i386/i386-expand.c
@@ -3899,7 +3899,7 @@ ix86_expand_sse_movcc (rtx dest, rtx cmp, rtx op_true, 
rtx op_false)
{
  op_true = force_reg (mode, op_true);
 
- gen = gen_mmx_pblendvb64;
+ gen = gen_mmx_pblendvb_v8qi;
  if (mode != V8QImode)
d = gen_reg_rtx (V8QImode);
  op_false = gen_lowpart (V8QImode, op_false);
@@ -3913,7 +3913,7 @@ ix86_expand_sse_movcc (rtx dest, rtx cmp, rtx op_true, 
rtx op_false)
{
  op_true = force_reg (mode, op_true);
 
- gen = gen_mmx_pblendvb32;
+ gen = gen_mmx_pblendvb_v4qi;
  if (mode != V4QImode)
d = gen_reg_rtx (V4QImode);
  op_false = gen_lowpart (V4QImode, op_false);
@@ -3921,6 +3921,14 @@ ix86_expand_sse_movcc (rtx dest, rtx cmp, rtx op_true, 
rtx op_false)
  cmp = gen_lowpart (V4QImode, cmp);
}
   break;
+case E_V2QImode:
+  if (TARGET_SSE4_1)
+   {
+ op_true = force_reg (mode, op_true);
+
+ gen = gen_mmx_pblendvb_v2qi;
+   }
+  break;
 case E_V16QImode:
 case E_V8HImode:
 case E_V8HFmode:
@@ -18462,9 +18470,9 @@ expand_vec_perm_blend (struct expand_vec_perm_d *d)
vperm = force_reg (vmode, vperm);
 
if (GET_MODE_SIZE (vmode) == 4)
- emit_insn (gen_mmx_pblendvb32 (target, op0, op1, vperm));
+ emit_insn (gen_mmx_pblendvb_v4qi (target, op0, op1, vperm));
else if (GET_MODE_SIZE (vmode) == 8)
- emit_insn (gen_mmx_pblendvb64 (target, op0, op1, vperm));
+ emit_insn (gen_mmx_pblendvb_v8qi (target, op0, op1, vperm));
else if (GET_MODE_SIZE (vmode) == 16)
  emit_insn (gen_sse4_1_pblendvb (target, op0, op1, vperm));
else
diff --git a/gcc/config/i386/mmx.md b/gcc/config/i386/mmx.md
index 91d642187be..fa67278e003 100644
--- a/gcc/config/i386/mmx.md
+++ b/gcc/config/i386/mmx.md
@@ -2580,14 +2580,14 @@
 })
 
 (define_expand "vcond"
-  [(set (match_operand:VI_32 0 "register_operand")
-   (if_then_else:VI_32
+  [(set (match_operand:VI_16_32 0 "register_operand")
+   (if_then_else:VI_16_32
  (match_operator 3 ""
-   [(match_operand:VI_32 4 "register_operand")
-(match_operand:VI_32 5 "register_operand")])
- (match_operand:VI_32 1)
- (match_operand:VI_32 2)))]
-  "TARGET_SSE2"
+   [(match_operand:VI_16_32 4 "register_operand")
+(match_operand:VI_16_32 5 "register_operand")])
+ (match_operand:VI_16_32 1)
+ (match_operand:VI_16_32 2)))]
+  "TARGET_SSE4_1"
 {
   bool ok = ix86_expand_int_vcond (operands);
   gcc_assert (ok);
@@ -2612,14 +2612,14 @@
 })
 
 (define_expand "vcondu"
-  [(set (match_operand:VI_32 0 "register_operand")
-   (if_then_else:VI_32
+  [(set (match_operand:VI_16_32 0 "register_operand")
+   (if_then_else:VI_16_32
  (match_operator 3 ""
-   [(match_operand:VI_32 4 "register_operand")
-(match_operand:VI_32 5 "register_operand")])
- (matc

Re: [PATCH] Mass rename of C++ .c files to .cc suffix

2022-01-11 Thread Jakub Jelinek via Gcc-patches
On Tue, Jan 11, 2022 at 06:23:51PM +, Jonathan Wakely via Gcc-patches wrote:
> > Regarding fortran: can we have a vote on this one?
> >
> > Some developers (including myself) are not really familiar with C++,
> > and in the past preference has been expressed on the fortran ML in
> > favor of not using too much C++.
> >
> > I would also not really be in a position to review real C++ code.
> 
> The discussion is purely about renaming files that are *already* C++
> source files but have the misleading .c file extension.
> 
> Nobody is suggesting using C++ where it isn't already being used.

And even gcc/fortran/ is written in C++, the gcc/ headers it uses are C++
only, they use templates etc., so gcc/fortran/ that uses those headers
has to be C++ too.  That doesn't mean you need to use C++ idioms everywhere
in your code, those files can stay to be mostly C-like with C++ headers and
use C++-only constructs only where it brings sufficient advantages.
Many of the gcc/*.c sources that Martin wants to rename are also written
like that.
The renaming will just match the reality, clang++ will stop warning that
support for .c extension for C++ is deprecated when building gcc, sites like
openhub.net (if they twice a year manage to build stats for gcc, dunno what
they are doing wrong or if it is because of the limiting of anonymous git
on sourceware) will not claim most of GCC is written in C etc.

Jakub



[committed] libstdc++: Install header for freestanding [PR103726]

2022-01-11 Thread Jonathan Wakely via Gcc-patches
Tested x86_64-linux and freestanding mips-elf.


This C++20 header is also supposed to be present for freestanding.

libstdc++-v3/ChangeLog:

PR libstdc++/103726
* include/Makefile.am: Install  for
freestanding.
* include/Makefile.in: Regenerate.
* include/std/version (__cpp_lib_source_location): Define for
freestanding.
---
 libstdc++-v3/include/Makefile.am | 5 +++--
 libstdc++-v3/include/Makefile.in | 5 +++--
 libstdc++-v3/include/std/version | 6 +++---
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 8f93bf2d7b7..8b1300e0f29 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -1426,7 +1426,7 @@ endif
 # , , , , , , ,
 # , , , , , ,
 # , , , , , ,
-# and any files which they include (and which we provide).
+#  and any files which they include (and which we provide).
 # , , ,  and 
 # are installed by libsupc++, so only the others and the sub-includes
 # are copied here.
@@ -1440,7 +1440,8 @@ install-freestanding-headers:
  ${glibcxx_srcdir}/$(CPU_DEFINES_SRCDIR)/cpu_defines.h; do \
  $(INSTALL_DATA) $${file} $(DESTDIR)${host_installdir}; done
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${std_builddir}
-   for file in limits type_traits atomic bit concepts coroutine version; 
do \
+   for file in limits type_traits atomic bit concepts coroutine \
+ source_location version; do \
  $(INSTALL_DATA) ${std_builddir}/$${file} 
$(DESTDIR)${gxx_include_dir}/${std_builddir}; done
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${c_base_builddir}
for file in ciso646 cstddef cfloat climits cstdint cstdlib \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index 4ab942ae666..3ff18fec1e8 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -1907,7 +1907,7 @@ ${pch3_output}: ${pch3_source} ${pch2_output}
 # , , , , , , ,
 # , , , , , ,
 # , , , , , ,
-# and any files which they include (and which we provide).
+#  and any files which they include (and which we provide).
 # , , ,  and 
 # are installed by libsupc++, so only the others and the sub-includes
 # are copied here.
@@ -1921,7 +1921,8 @@ install-freestanding-headers:
  ${glibcxx_srcdir}/$(CPU_DEFINES_SRCDIR)/cpu_defines.h; do \
  $(INSTALL_DATA) $${file} $(DESTDIR)${host_installdir}; done
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${std_builddir}
-   for file in limits type_traits atomic bit concepts coroutine version; 
do \
+   for file in limits type_traits atomic bit concepts coroutine \
+ source_location version; do \
  $(INSTALL_DATA) ${std_builddir}/$${file} 
$(DESTDIR)${gxx_include_dir}/${std_builddir}; done
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${c_base_builddir}
for file in ciso646 cstddef cfloat climits cstdint cstdlib \
diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version
index 012d78e3b6b..c5d5efb1314 100644
--- a/libstdc++-v3/include/std/version
+++ b/libstdc++-v3/include/std/version
@@ -201,6 +201,9 @@
 #endif
 #define __cpp_lib_is_nothrow_convertible 201806L
 #define __cpp_lib_remove_cvref 201711L
+#if __has_builtin(__builtin_source_location)
+# define __cpp_lib_source_location 201907L
+#endif
 #if __cpp_impl_three_way_comparison >= 201907L && __cpp_lib_concepts
 # define __cpp_lib_three_way_comparison 201907L
 #endif
@@ -273,9 +276,6 @@
 # define __cpp_lib_semaphore 201907L
 #endif
 #define __cpp_lib_shift 201806L
-#if __has_builtin(__builtin_source_location)
-# define __cpp_lib_source_location 201907L
-#endif
 #if __cpp_lib_concepts
 # define __cpp_lib_span 202002L
 #endif
-- 
2.31.1



Re: [PATCH] ira: Fix old-reload targets [PR103974]

2022-01-11 Thread Vladimir Makarov via Gcc-patches



On 2022-01-11 12:42, Richard Sandiford wrote:

The new IRA heuristics would need more work on old-reload targets,
since flattening needs to be able to undo the cost propagation.
It's doable, but hardly seems worth it.

Agree. It is not worth to spend your time for work for reload.

This patch therefore makes all the new calls to
ira_subloop_allocnos_can_differ_p return false if !ira_use_lra_p.
The color_pass code that predated the new function (and that was
the source of ira_subloop_allocnos_can_differ_p) continues to
behave as before.

It's a hack, but at least it has the advantage that the new parameter
would become obviously unused if reload and (!)ira_use_lra_p were
removed.  The hack should therefore disappear alongside reload.
I have a feeling that it will stay for a long time if not forever. 
Recently I had the same problem.  My performance patch for IRA resulted 
in ice in reload pass on SH4.

Tested on aarch64-linux-gnu and cris-elf.  OK to install?

OK.  Thank you.



gcc/
PR rtl-optimization/103974
* ira-int.h (ira_subloop_allocnos_can_differ_p): Take an
extra argument, default true, that says whether old-reload
targets should be excluded.
* ira-color.c (color_pass): Pass false.




  1   2   >