[PATCH-2, rs6000] Put constant into pseudo at expand when it needs two insns [PR86106]

2023-03-15 Thread HAO CHEN GUI via Gcc-patches
Hi,
  The background and motivation of the patch are listed in the note of
PATCH-1.

  This patch changes the expander of ior/xor and force constant to a pseudo
when it needs 2 insn. Also a combine and split pattern for ior/xor is defined.
rtx_cost of ior insn is adjusted as now it may have 2 insns for certain
constants. We need to check the cost of each operand.

  Bootstrapped and tested on powerpc64-linux BE and LE with no regressions.

Thanks
Gui Haochen

ChangeLog
2023-03-14  Haochen Gui 

gcc/
* gcc/config/rs6000/rs6000.cc (rs6000_rtx_costs): Check the cost of
each operand for IOR as it may have 2 insn for certain constants.
* config/rs6000/rs6000.md (3): Put the second operand into
register when it's a constant and need 2 ior/xor insns.
(split for ior/xor): Remove.
(*_2insn): New insn_and split pattern for 2-insn ior/xor.

gcc/testsuite/
* gcc.target/powerpc/pr86106.c: New.


patch.diff
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index b3a609f3aa3..f53daff547f 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -22081,10 +22081,6 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int 
outer_code,
   return false;

 case IOR:
-  /* FIXME */
-  *total = COSTS_N_INSNS (1);
-  return true;
-
 case CLZ:
 case XOR:
 case ZERO_EXTRACT:
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index dba41e3df90..0541f48c42a 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -3892,7 +3892,8 @@ (define_expand "3"
   DONE;
 }

-  if (non_logical_cint_operand (operands[2], mode))
+  if (non_logical_cint_operand (operands[2], mode)
+  && !can_create_pseudo_p ())
 {
   rtx tmp = ((!can_create_pseudo_p ()
  || rtx_equal_p (operands[0], operands[1]))
@@ -3907,15 +3908,17 @@ (define_expand "3"
   DONE;
 }

-  if (!reg_or_logical_cint_operand (operands[2], mode))
+  if (!logical_operand (operands[2], mode))
 operands[2] = force_reg (mode, operands[2]);
 })

-(define_split
-  [(set (match_operand:GPR 0 "gpc_reg_operand")
-   (iorxor:GPR (match_operand:GPR 1 "gpc_reg_operand")
-   (match_operand:GPR 2 "non_logical_cint_operand")))]
+(define_insn_and_split "*_2insn"
+  [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
+   (iorxor:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
+   (match_operand:GPR 2 "non_logical_cint_operand" "n")))]
   ""
+  "#"
+  "&& (!reload_completed || rtx_equal_p (operands[0], operands[1]))"
   [(set (match_dup 3)
(iorxor:GPR (match_dup 1)
(match_dup 4)))
@@ -3933,7 +3936,8 @@ (define_split

   operands[4] = GEN_INT (hi);
   operands[5] = GEN_INT (lo);
-})
+}
+  [(set_attr "length" "8")])

 (define_insn "*bool3_imm"
   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
diff --git a/gcc/testsuite/gcc.target/powerpc/pr86106.c 
b/gcc/testsuite/gcc.target/powerpc/pr86106.c
new file mode 100644
index 000..71501476800
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr86106.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mno-prefixed" } */
+
+unsigned int
+foo (unsigned int val)
+{
+  unsigned int mask = 0x7f7f7f7f;
+
+  return ~(((val & mask) + mask) | val | mask);
+}
+
+/* { dg-final { scan-assembler-not {\maddis\M} } } */
+/* { dg-final { scan-assembler-not {\maddi\M} } } */
+/* { dg-final { scan-assembler-not {\moris\M} } } */


[PATCH-1, rs6000] Put constant into pseudo at expand when it needs two insns [PR86106]

2023-03-15 Thread HAO CHEN GUI via Gcc-patches
Hi,
  Currently, rs6000 directly expands to 2 insns if an integer constant is the
second operand and it needs two insns. For example, addi/addis and ori/oris.
It may not benefit when the constant is used for more than 2 times in an
extended basic block, just like the case in PR shows.

  One possible solution is to force the constant in pseudo at expand and let
propagation pass and combine pass decide if the pseudo should be replaced
with the constant or not by comparing the rtx/insn cost.

  It generates a constant move if the constant is forced to a pseudo. There
is one constant move if it's used only once. The combine pass can combine
the constant move and add/ior/xor insn and eliminate the move as the insn
cost reduces. There are multiple moves if the constant is used for several
times. In an extended basic block, these constant moves are merged to one by
propagation pass. The combine pass can't replace the pseudo with the constant
as it is no cost saving.

  In an extreme case, the constant is used twice in an extended basic block.
The cost(latency) is unchanged between putting constant in pseudo and
generating 2 insns. The dependence of instructions reduces but one more
register is used. In other case, it should be always optimal to put constant
in a pseudo.

  This patch changes the expander of integer add and force constant to a
pseudo when it needs 2 insn. Also a combine and split pattern is defined.

  Bootstrapped and tested on powerpc64-linux BE and LE with no regressions.

Thanks
Gui Haochen

ChangeLog
2023-03-14  Haochen Gui 

gcc/
* config/rs6000/predicates.md (add_2insn_cint_operand): New predicate
which returns true when op is a 32-bit but not a 16-bit signed
integer constant.
* config/rs6000/rs6000.md (add3): Put the second operand into
register when it's a constant and need 2 add insns.
(*add_2insn): New insn_and_split for 2-insn add.


patch.diff
diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index a1764018545..09e59a48cd3 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -282,6 +282,13 @@ (define_predicate "s32bit_cint_operand"
   (and (match_code "const_int")
(match_test "(0x8000 + UINTVAL (op)) >> 32 == 0")))

+;; Return 1 if op is a 32-bit but not 16-bit constant signed integer
+(define_predicate "add_2insn_cint_operand"
+  (and (match_code "const_int")
+   (and (match_operand 0 "s32bit_cint_operand")
+   (and (not (match_operand 0 "short_cint_operand"))
+(not (match_operand 0 "upper16_cint_operand"))
+
 ;; Return 1 if op is a constant 32-bit unsigned
 (define_predicate "c32bit_cint_operand"
   (and (match_code "const_int")
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 6011f5bf76a..dba41e3df90 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -1796,12 +1796,44 @@ (define_expand "add3"
   /* The ordering here is important for the prolog expander.
 When space is allocated from the stack, adding 'low' first may
 produce a temporary deallocation (which would be bad).  */
-  emit_insn (gen_add3 (tmp, operands[1], GEN_INT (rest)));
-  emit_insn (gen_add3 (operands[0], tmp, GEN_INT (low)));
-  DONE;
+  if (!can_create_pseudo_p ())
+   {
+ emit_insn (gen_add3 (tmp, operands[1], GEN_INT (rest)));
+ emit_insn (gen_add3 (operands[0], tmp, GEN_INT (low)));
+ DONE;
+   }
+
+  operands[2] = force_reg (mode, operands[2]);
 }
 })

+/* The ordering here is important for the prolog expander.
+   When space is allocated from the stack, adding 'low' first may
+   produce a temporary deallocation (which would be bad).  */
+
+(define_insn_and_split "*add_2insn"
+  [(set (match_operand:GPR 0 "gpc_reg_operand" "=b")
+   (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%b")
+ (match_operand:GPR 2 "add_2insn_cint_operand" "n")))]
+  "!TARGET_PREFIXED"
+  "#"
+  "&& 1"
+  [(set (match_dup 0)
+   (plus:GPR (match_dup 1)
+ (match_dup 3)))
+   (set (match_dup 0)
+   (plus:GPR (match_dup 0)
+ (match_dup 4)))]
+{
+  HOST_WIDE_INT val = INTVAL (operands[2]);
+  HOST_WIDE_INT low = sext_hwi (val, 16);
+  HOST_WIDE_INT rest = trunc_int_for_mode (val - low, mode);
+
+  operands[3] = GEN_INT (rest);
+  operands[4] = GEN_INT (low);
+}
+  [(set_attr "length" "8")])
+
 (define_insn "*add3"
   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,r,r")
(plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,b,b")


[PATCH] rs6000: suboptimal code for returning bool value on target ppc

2023-03-15 Thread Ajit Agarwal via Gcc-patches
Hello All:


This patch eliminates unnecessary zero extension instruction from power 
generated assembly.
Bootstrapped and regtested on powerpc64-linux-gnu.

Thanks & Regards
Ajit

rs6000: suboptimal code for returning bool value on target ppc.

New pass to eliminate unnecessary zero extension. This pass
is registered after cse rtl pass.

2023-03-16  Ajit Kumar Agarwal  

gcc/ChangeLog:

* config/rs6000/rs6000-passes.def: Registered zero elimination
pass.
* config/rs6000/rs6000-zext-elim.cc: Add new pass.
* config.gcc: Add new executable.
* config/rs6000/rs6000-protos.h: Add new prototype for zero
elimination pass.
* config/rs6000/rs6000.cc: Add new prototype for zero
elimination pass.
* config/rs6000/t-rs6000: Add new rule.
* expr.cc: Modified gcc assert.
* explow.cc: Modified gcc assert.
* optabs.cc: Modified gcc assert.
---
 gcc/config.gcc|   4 +-
 gcc/config/rs6000/rs6000-passes.def   |   2 +
 gcc/config/rs6000/rs6000-protos.h |   1 +
 gcc/config/rs6000/rs6000-zext-elim.cc | 361 ++
 gcc/config/rs6000/rs6000.cc   |   2 +
 gcc/config/rs6000/t-rs6000|   5 +
 gcc/explow.cc |   3 +-
 gcc/expr.cc   |   4 +-
 gcc/optabs.cc |   3 +-
 9 files changed, 379 insertions(+), 6 deletions(-)
 create mode 100644 gcc/config/rs6000/rs6000-zext-elim.cc

diff --git a/gcc/config.gcc b/gcc/config.gcc
index da3a6d3ba1f..e8ac9d882f0 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -503,7 +503,7 @@ or1k*-*-*)
;;
 powerpc*-*-*)
cpu_type=rs6000
-   extra_objs="rs6000-string.o rs6000-p8swap.o rs6000-logue.o"
+   extra_objs="rs6000-string.o rs6000-p8swap.o rs6000-zext-elim.o 
rs6000-logue.o"
extra_objs="${extra_objs} rs6000-call.o rs6000-pcrel-opt.o"
extra_objs="${extra_objs} rs6000-builtins.o rs6000-builtin.o"
extra_headers="ppc-asm.h altivec.h htmintrin.h htmxlintrin.h"
@@ -538,7 +538,7 @@ riscv*)
;;
 rs6000*-*-*)
extra_options="${extra_options} g.opt fused-madd.opt 
rs6000/rs6000-tables.opt"
-   extra_objs="rs6000-string.o rs6000-p8swap.o rs6000-logue.o"
+   extra_objs="rs6000-string.o rs6000-p8swap.o rs6000-zext-elim.o 
rs6000-logue.o"
extra_objs="${extra_objs} rs6000-call.o rs6000-pcrel-opt.o"
target_gtfiles="$target_gtfiles 
\$(srcdir)/config/rs6000/rs6000-logue.cc 
\$(srcdir)/config/rs6000/rs6000-call.cc"
target_gtfiles="$target_gtfiles 
\$(srcdir)/config/rs6000/rs6000-pcrel-opt.cc"
diff --git a/gcc/config/rs6000/rs6000-passes.def 
b/gcc/config/rs6000/rs6000-passes.def
index ca899d5f7af..d7500feddf1 100644
--- a/gcc/config/rs6000/rs6000-passes.def
+++ b/gcc/config/rs6000/rs6000-passes.def
@@ -28,6 +28,8 @@ along with GCC; see the file COPYING3.  If not see
  The power8 does not have instructions that automaticaly do the byte swaps
  for loads and stores.  */
   INSERT_PASS_BEFORE (pass_cse, 1, pass_analyze_swaps);
+  INSERT_PASS_AFTER (pass_cse, 1, pass_analyze_zext);
+
 
   /* Pass to do the PCREL_OPT optimization that combines the load of an
  external symbol's address along with a single load or store using that
diff --git a/gcc/config/rs6000/rs6000-protos.h 
b/gcc/config/rs6000/rs6000-protos.h
index 1a4fc1df668..f6cf2d673d4 100644
--- a/gcc/config/rs6000/rs6000-protos.h
+++ b/gcc/config/rs6000/rs6000-protos.h
@@ -340,6 +340,7 @@ namespace gcc { class context; }
 class rtl_opt_pass;
 
 extern rtl_opt_pass *make_pass_analyze_swaps (gcc::context *);
+extern rtl_opt_pass *make_pass_analyze_zext (gcc::context *);
 extern rtl_opt_pass *make_pass_pcrel_opt (gcc::context *);
 extern bool rs6000_sum_of_two_registers_p (const_rtx expr);
 extern bool rs6000_quadword_masked_address_p (const_rtx exp);
diff --git a/gcc/config/rs6000/rs6000-zext-elim.cc 
b/gcc/config/rs6000/rs6000-zext-elim.cc
new file mode 100644
index 000..777c7a5a387
--- /dev/null
+++ b/gcc/config/rs6000/rs6000-zext-elim.cc
@@ -0,0 +1,361 @@
+/* Subroutine to eliminate redundant zero extend for power architecture.
+   Copyright (C) 1991-2023 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 COPYING3.  If not see
+   .  */
+
+/* This pass remove unnecessary zero 

Re: [wwwdocs] document modula-2 in gcc-13/changes.html (and index.html)

2023-03-15 Thread Gaius Mulley via Gcc-patches
Gerald Pfeifer  writes:

> The patch is now in, alas all the GNU M2 manual links now point to 
> non-existant locations.
>
> Does maintainer-scripts/update_web_docs_git require an update to cover 
> Modula-2 and actually build the manual we are now linking to (or rather
> trying to)?
>
> Gerald

Apologies I was going to ask about these links.  I've updated the m2
subtree with target documentation independent sections.  Attached is a
proposed patch for maintainer-scripts/update_web_docs_git feel free to
apply or adapt in any way.

regards,
Gaius


--->o--->o--->o--->o--->o--->o--->o--->o--->o--->o--->o--->o--->o--->o

Add modula-2 documentation to be built

Update the online documentation build script to include modula-2.

maintainer-scripts/ChangeLog:

* update_web_docs_git (MANUALS): Add gm2.
Add include path for m2 target independent sections.


diff --git a/maintainer-scripts/update_web_docs_git 
b/maintainer-scripts/update_web_docs_git
index 1c6a993cafd..c678fc29155 100755
--- a/maintainer-scripts/update_web_docs_git
+++ b/maintainer-scripts/update_web_docs_git
@@ -24,6 +24,7 @@ MANUALS="cpp
   gdc
   gfortran
   gfc-internals
+  gm2
   gnat_ugn
   gnat-style
   gnat_rm
@@ -169,6 +170,9 @@ for file in $MANUALS; do
 includes="-I ${includedir} -I `dirname ${filename}`"
 if [ "$file" = "gnat_ugn" ]; then
   includes="$includes -I gcc/gcc/ada -I gcc/gcc/ada/doc/gnat_ugn"
+elif [ "$file" = "gm2" ]; then
+  includes="$includes -I gcc/gcc/m2/target-independent"
+  includes="$includes -I gcc/gcc/m2/target-independent/m2"
 fi
 makeinfo --html --css-ref $CSS $includes -o ${file} ${filename}
 tar cf ${file}-html.tar ${file}/*.html


[PATCH RFC] c++: co_await and move-only type [PR105406]

2023-03-15 Thread Jason Merrill via Gcc-patches
Tested x86_64-pc-linux-gnu.  As with the array issue, I know you have WIP to
deal with larger issues, but this seems like a reasonable local fix.  Does it
make sense to you?

-- 8< --

Here we were building a temporary MoveOnlyAwaitable to hold the result of
evaluating 'o', but since 'o' is an lvalue we should build a reference
instead.

PR c++/105406

gcc/cp/ChangeLog:

* coroutines.cc (build_co_await): Handle lvalue 'o'.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/co-await-moveonly1.C: New test.
---
 gcc/cp/coroutines.cc  |  9 ++-
 .../g++.dg/coroutines/co-await-moveonly1.C| 63 +++
 2 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/coroutines/co-await-moveonly1.C

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index 7f8cbc3d95e..a2189e43db8 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -1024,9 +1024,13 @@ build_co_await (location_t loc, tree a, 
suspend_point_kind suspend_kind)
 }
   else
 {
-  e_proxy = get_awaitable_var (suspend_kind, o_type);
+  tree p_type = o_type;
+  if (glvalue_p (o))
+   p_type = cp_build_reference_type (p_type, !lvalue_p (o));
+  e_proxy = get_awaitable_var (suspend_kind, p_type);
   o = cp_build_modify_expr (loc, e_proxy, INIT_EXPR, o,
tf_warning_or_error);
+  e_proxy = convert_from_reference (e_proxy);
 }
 
   /* I suppose we could check that this is contextually convertible to bool.  
*/
@@ -1120,6 +1124,9 @@ build_co_await (location_t loc, tree a, 
suspend_point_kind suspend_kind)
 }
   TREE_VEC_ELT (awaiter_calls, 2) = awrs_call; /* await_resume().  */
 
+  if (REFERENCE_REF_P (e_proxy))
+e_proxy = TREE_OPERAND (e_proxy, 0);
+
   tree await_expr = build5_loc (loc, CO_AWAIT_EXPR,
TREE_TYPE (TREE_TYPE (awrs_func)),
a, e_proxy, o, awaiter_calls,
diff --git a/gcc/testsuite/g++.dg/coroutines/co-await-moveonly1.C 
b/gcc/testsuite/g++.dg/coroutines/co-await-moveonly1.C
new file mode 100644
index 000..e2831c104bf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/coroutines/co-await-moveonly1.C
@@ -0,0 +1,63 @@
+// PR c++/105406
+// { dg-do compile { target c++20 } }
+
+#include 
+#include 
+
+// A move-only awaitable
+class MoveOnlyAwaitable {
+public:
+MoveOnlyAwaitable() = default;
+MoveOnlyAwaitable(MoveOnlyAwaitable &&) = default;
+MoveOnlyAwaitable =(MoveOnlyAwaitable &&) = default;
+
+MoveOnlyAwaitable(const MoveOnlyAwaitable &) = delete;
+MoveOnlyAwaitable =(const MoveOnlyAwaitable &) = delete;
+
+bool await_ready() const noexcept { return false; }
+void await_suspend(std::coroutine_handle<>) noexcept {}
+void await_resume() {}
+};
+
+struct task {
+struct promise_type {
+auto initial_suspend() const { return std::suspend_never{}; }
+auto final_suspend() const noexcept { return std::suspend_never(); }
+auto get_return_object() { return task{}; }
+void return_void() {}
+void unhandled_exception() {}
+
+template
+T &_transform(T &) {
+return static_cast(t);
+}
+
+
+};
+
+bool await_ready() const { return false; }
+void await_suspend(std::coroutine_handle<> awaiter) {}
+void await_resume() {}
+};
+
+task myCoroutine() {
+// GCC: OK
+// clang: OK
+{
+co_await MoveOnlyAwaitable();
+}
+// GCC: OK
+// clang: OK
+{
+auto moveonly = MoveOnlyAwaitable();
+co_await std::move(moveonly);
+}
+
+// GCC <= 11.2: OK
+// GCC 11.3:ERROR:  error: use of deleted function 
'MoveOnlyAwaitable::MoveOnlyAwaitable(const MoveOnlyAwaitable&)
+// clang: OK
+{
+auto moveonly = MoveOnlyAwaitable();
+co_await moveonly;
+}
+}

base-commit: ea4dd8f512979db247c54d6b41377bb73699bcd7
-- 
2.31.1



[PATCH] [testsuite] fix array element count

2023-03-15 Thread Alexandre Oliva via Gcc-patches


This test is similar to pr103116-1.c, but instead of writing to
4*COUNT elements of x, it writes to 8*COUNT elements, but the
definition of x seems to have been adjusted along with the loop.  Fix
the array size so that it doesn't scribble over unrelated
statically-allocated objects.

Regstrapped on ppc64-linux-gnu.  Also tested with gcc-11 on vxworks7r2
(x86- and x86_64-), where the scribbling caused visible runtime effects.
Ok to install?  I'm tempted to put this in as obvious.


for  gcc/testsuite/ChangeLog

* gcc.dg/vect/pr103116-2.c (x): Fix array size.
---
 gcc/testsuite/gcc.dg/vect/pr103116-2.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr103116-2.c 
b/gcc/testsuite/gcc.dg/vect/pr103116-2.c
index 2f4ed0f404c76..aa9797a94074c 100644
--- a/gcc/testsuite/gcc.dg/vect/pr103116-2.c
+++ b/gcc/testsuite/gcc.dg/vect/pr103116-2.c
@@ -31,7 +31,7 @@ loop (TYPE *restrict x, TYPE *restrict y)
 }
 }
 
-TYPE x[COUNT * 4];
+TYPE x[COUNT * 8];
 
 int
 main (void)

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


[PATCH] [testsuite] test for weak_undefined support and add options

2023-03-15 Thread Alexandre Oliva via Gcc-patches


A number of tests that depend on weak undefined symbols fail to
require that support, and arrange to skip some targets and add special
options to others on a test-by-test basis.  Fix this by stating the
requirement explicitly, and adding a proc to return any required
options.

Others rely on weak undefined symbols only to test for the
availability of posix_memalign.  Drop that in favor of dg effective
target support for posix_memalign.

Regstrapped on ppc64-linux-gnu.  Also tested (with gcc-12) on multiple
*-vxworks7r2 targets (arm, aarch64, ppc64, x86, x86_64).  Ok to install?


for  gcc/testsuite/ChangeLog

* lib/target-supports.exp (add_options_for_weak_undefined):
New.
(check_effective_target_weak_undefined): Use it.
(check_effective_target_posix_memalign): New.
* gcc.dg/torture/pr53922.c: Drop skips and custom options in
favor of effective target requirement and added options for
weak_undefined symbols.
* gcc.dg/torture/pr90020.c: Likewise.
* gcc.dg/addr_equal-1.c: Likewise.
* gcc.target/aarch64/aapcs64/aapcs64.exp: Likewise, for
abitest.S-using tests.
* gcc.dg/torture/pr60092.c: Likewise, but in favor of
posix_memalign tests.
* gcc.dg/vect/vect-tail-nomask-1.c: Likewise.
---
 gcc/testsuite/gcc.dg/addr_equal-1.c|5 ++--
 gcc/testsuite/gcc.dg/torture/pr53922.c |   10 ++--
 gcc/testsuite/gcc.dg/torture/pr60092.c |   12 ++---
 gcc/testsuite/gcc.dg/torture/pr90020.c |7 ++---
 gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c |   11 ++--
 .../gcc.target/aarch64/aapcs64/aapcs64.exp |   17 -
 gcc/testsuite/lib/target-supports.exp  |   26 ++--
 7 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/addr_equal-1.c 
b/gcc/testsuite/gcc.dg/addr_equal-1.c
index 35fa0102e3063..db65dea4a8d2a 100644
--- a/gcc/testsuite/gcc.dg/addr_equal-1.c
+++ b/gcc/testsuite/gcc.dg/addr_equal-1.c
@@ -1,9 +1,8 @@
-/* { dg-do run { target { nonpic || pie_enabled } } } */
-/* { dg-require-weak "" } */
+/* { dg-do run { target { { nonpic || pie_enabled } && weak_undefined } } } */
 /* { dg-require-alias "" } */
 /* { dg-options "-O2 -fdelete-null-pointer-checks" } */
-/* { dg-skip-if "" { powerpc-ibm-aix* } } */
 /* { dg-skip-if "function pointers can be NULL" { keeps_null_pointer_checks } 
} */
+/* { dg-add-options weak_undefined } */
 void abort (void);
 extern int undef_var0, undef_var1;
 extern __attribute__ ((weak)) int weak_undef_var0;
diff --git a/gcc/testsuite/gcc.dg/torture/pr53922.c 
b/gcc/testsuite/gcc.dg/torture/pr53922.c
index b3f2c1a58f830..07359d6764964 100644
--- a/gcc/testsuite/gcc.dg/torture/pr53922.c
+++ b/gcc/testsuite/gcc.dg/torture/pr53922.c
@@ -1,11 +1,5 @@
-/* { dg-do run } */
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined" { *-*-mingw* } } */
-/* { dg-skip-if "No undefined weak" { *-*-aix* } } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } 
*/
+/* { dg-do run { target { weak_undefined } } } */
+/* { dg-add-options weak_undefined } */
 
 int x(int a)
 {
diff --git a/gcc/testsuite/gcc.dg/torture/pr60092.c 
b/gcc/testsuite/gcc.dg/torture/pr60092.c
index 74e7c174a8323..102ba6e0d9f87 100644
--- a/gcc/testsuite/gcc.dg/torture/pr60092.c
+++ b/gcc/testsuite/gcc.dg/torture/pr60092.c
@@ -1,12 +1,7 @@
-/* { dg-do run } */
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target 
*-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } 
*/
+/* { dg-do run { target { posix_memalign } } } */
 
 typedef __SIZE_TYPE__ size_t;
-extern int posix_memalign(void **memptr, size_t alignment, size_t size) 
__attribute__((weak));
+extern int posix_memalign(void **memptr, size_t alignment, size_t size);
 extern void abort(void);
 int
 main (void)
@@ -14,9 +9,6 @@ main (void)
   void *p;
   int ret;
 
-  if (!posix_memalign)
-return 0;
-
   p = (void *)
   ret = posix_memalign (, sizeof (void *), -1);
   if (p != (void *))
diff --git a/gcc/testsuite/gcc.dg/torture/pr90020.c 
b/gcc/testsuite/gcc.dg/torture/pr90020.c
index 657c4ccfe45c4..40035aa758e6e 100644
--- a/gcc/testsuite/gcc.dg/torture/pr90020.c
+++ b/gcc/testsuite/gcc.dg/torture/pr90020.c
@@ -1,8 +1,5 @@
-/* { dg-do run } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* || powerpc-ibm-aix* } } */
-/* { dg-require-weak "" } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target 
*-*-darwin* } } */
-/* { dg-additional-options 

[pushed] maintainer-scripts: Abstract BUGURL in update_web_docs_git

2023-03-15 Thread Gerald Pfeifer
The URL where to report bugs is hard coded in two places; abstract that
into one variable, defined up front.

maintainer-scripts/ChangeLog:

* update_web_docs_git (BUGURL): Introduce and use throughout.
---
 maintainer-scripts/update_web_docs_git | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/maintainer-scripts/update_web_docs_git 
b/maintainer-scripts/update_web_docs_git
index dee9b1d3b5e..1c6a993cafd 100755
--- a/maintainer-scripts/update_web_docs_git
+++ b/maintainer-scripts/update_web_docs_git
@@ -33,6 +33,7 @@ MANUALS="cpp
   libiberty
   porting"
 
+BUGURL="http://gcc.gnu.org/bugs/;
 CSS=/gcc.css
 
 WWWBASE=${WWWBASE:-"/www/gcc/htdocs"}
@@ -154,11 +155,11 @@ includedir=gcc/gcc/doc/include
fi
echo "@set srcdir $WORKDIR/gcc/gcc"
echo "@set VERSION_PACKAGE (GCC)"
-   echo "@set BUGURL @uref{http://gcc.gnu.org/bugs/};
+   echo "@set BUGURL @uref{$BUGURL}"
 ) > $includedir/gcc-vers.texi
 
 # Generate libquadmath-vers.texi.
-echo "@set BUGURL @uref{http://gcc.gnu.org/bugs/}; \
+echo "@set BUGURL @uref{$BUGURL}" \
   > $includedir/libquadmath-vers.texi
 
 # Now convert the relevant files from texi to HTML, PDF and PostScript.
-- 
2.39.2


Re: [PATCH] c++: noexcept and copy elision [PR109030]

2023-03-15 Thread Patrick Palka via Gcc-patches
On Thu, 9 Mar 2023, Jason Merrill wrote:

> On 3/9/23 14:32, Patrick Palka wrote:
> > On Mon, 6 Mar 2023, Marek Polacek via Gcc-patches wrote:
> > 
> > > When processing a noexcept, constructors aren't elided: build_over_call
> > > has
> > >/* It's unsafe to elide the constructor when handling
> > >   a noexcept-expression, it may evaluate to the wrong
> > >   value (c++/53025).  */
> > >&& (force_elide || cp_noexcept_operand == 0))
> > > so the assert I added recently needs to be relaxed a little bit.
> > > 
> > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> > > 
> > >   PR c++/109030
> > > 
> > > gcc/cp/ChangeLog:
> > > 
> > >   * constexpr.cc (cxx_eval_call_expression): Relax assert.
> > > 
> > > gcc/testsuite/ChangeLog:
> > > 
> > >   * g++.dg/cpp0x/noexcept77.C: New test.
> > > ---
> > >   gcc/cp/constexpr.cc | 6 +-
> > >   gcc/testsuite/g++.dg/cpp0x/noexcept77.C | 9 +
> > >   2 files changed, 14 insertions(+), 1 deletion(-)
> > >   create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept77.C
> > > 
> > > diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
> > > index 364695b762c..5384d0e8e46 100644
> > > --- a/gcc/cp/constexpr.cc
> > > +++ b/gcc/cp/constexpr.cc
> > > @@ -2869,7 +2869,11 @@ cxx_eval_call_expression (const constexpr_ctx *ctx,
> > > tree t,
> > >   /* We used to shortcut trivial constructor/op= here, but nowadays
> > >we can only get a trivial function here with
> > > -fno-elide-constructors.  */
> > > -  gcc_checking_assert (!trivial_fn_p (fun) || !flag_elide_constructors);
> > > +  gcc_checking_assert (!trivial_fn_p (fun)
> > > +|| !flag_elide_constructors
> > > +/* We don't elide constructors when processing
> > > +   a noexcept-expression.  */
> > > +|| cp_noexcept_operand);
> > 
> > It seems weird that we're performing constant evaluation within an
> > unevaluated operand.  Would it make sense to also fix this a second way
> > by avoiding constant evaluation from maybe_constant_init when
> > cp_unevaluated_operand && !manifestly_const_eval, like in
> > maybe_constant_value?
> 
> Sounds good.

Hmm, while working on this I noticed we currently don't reject a version of
g++.dg/cpp2a/constexpr-inst1.C that list initializes an aggregate instead of
int (ever since r12-4425-g1595fe44e11a96):

  struct A { int m; };
  template constexpr int f() { return T::value; }
  template void h(decltype(A{B ? f() : 0})); // was 
int{...}
  template void h(...);
  void x() {
h(0); // OK?
  }

ISTM we should instantiate f here for the same reason we do in the
original version of the testcase, and for that to happen we need to
pass manifestly_const_eval=true in massage_init_elt.  Does that seem
reasonable?



Re: [wwwdocs] document modula-2 in gcc-13/changes.html (and index.html)

2023-03-15 Thread Gerald Pfeifer
The patch is now in, alas all the GNU M2 manual links now point to 
non-existant locations.

Does maintainer-scripts/update_web_docs_git require an update to cover 
Modula-2 and actually build the manual we are now linking to (or rather
trying to)?

Gerald


[pushed] c++: co_await and initializer_list [PR103871]

2023-03-15 Thread Jason Merrill via Gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

When flatten_await_stmt processes the backing array for an initializer_list,
we call cp_build_modify_expr to initialize the promoted variable from the
TARGET_EXPR; that needs to be accepted.

PR c++/103871
PR c++/98056

gcc/cp/ChangeLog:

* typeck.cc (cp_build_modify_expr): Allow array initialization of
DECL_ARTIFICIAL variable.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/co-await-initlist1.C: New test.
---
 gcc/cp/typeck.cc  |  2 ++
 .../g++.dg/coroutines/co-await-initlist1.C| 21 +++
 2 files changed, 23 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/coroutines/co-await-initlist1.C

diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index d5a3e501d8e..afb956087ce 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -9630,6 +9630,8 @@ cp_build_modify_expr (location_t loc, tree lhs, enum 
tree_code modifycode,
}
 
   /* Allow array assignment in compiler-generated code.  */
+  else if (DECL_P (lhs) && DECL_ARTIFICIAL (lhs))
+   /* OK, used by coroutines (co-await-initlist1.C).  */;
   else if (!current_function_decl
   || !DECL_DEFAULTED_FN (current_function_decl))
{
diff --git a/gcc/testsuite/g++.dg/coroutines/co-await-initlist1.C 
b/gcc/testsuite/g++.dg/coroutines/co-await-initlist1.C
new file mode 100644
index 000..b8e8923a9c8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/coroutines/co-await-initlist1.C
@@ -0,0 +1,21 @@
+// PR c++/103871
+// { dg-do compile { target c++20 } }
+
+#include 
+#include 
+
+struct my_coro {
+  struct promise_type {
+my_coro get_return_object();
+std::suspend_never initial_suspend();
+std::suspend_never final_suspend() noexcept;
+void unhandled_exception();
+  };
+};
+
+std::suspend_never inner(std::initializer_list);
+
+my_coro doesnt_work()
+{
+  co_await inner({ 1,2,3 });
+}

base-commit: 57052c6ed59c1a2ee4a67982f960e08593956955
-- 
2.31.1



[pushed] diagnostics: attempt to capture crash info in SARIF output [PR109097]

2023-03-15 Thread David Malcolm via Gcc-patches
As noted in PR analyzer/109097, if an internal compiler error occurs
when -fdiagnostics-format=sarif-file is specified, we currently fail
to write out a .sarif file, and the output to stderr doesn't contain
"internal compiler error" or "Internal compiler error"; just the
backtrace if we're lucky, and the "Please submit a full bug report"
messages.

This is a nuisance e.g. for my integration testing of -fanalyzer, where
I'm gathering the results of builds via the .sarif output: if it crashes
on a particular source file, then no output is generated, and it's
effectively silent about the crash.

This patch fixes things by adding a callback to diagnostic_context so
that the SARIF output code can make one final attempt to write its
output if an ICE occurs.  It also special-cases the output, so that an
ICE is treated as an "error"-level "notification" relating to the
operation of the tool (SARIF v2.1.0 section 3.58), rather than a
"result" about the code being analyzed by the tool.

The patch adds test coverage for this via a plugin that can inject:
* calls to internal_compiler_error, and
* writes through a NULL pointer
and verifying that a  .sarif file is written out capturing the crash
(and also that an ICE occurs via dg-ice, which seems to treat the ICE as
an XFAIL, which is reasonable).

I've added support for this to my integration-testing scripts: testing
shows that with this patch we capture analyzer crashes in .sarif files
(specifically, the analyzer crash on qemu: PR analyzer/109094), and I've
updated my scripts to work with and report such output.

I manually verified that the resulting .sarif files validate against the
schema.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r13-6701-g79aaba0a71f34a.

gcc/ChangeLog:
PR analyzer/109097
* diagnostic-format-sarif.cc (class sarif_invocation): New.
(class sarif_ice_notification): New.
(sarif_builder::m_invocation_obj): New field.
(sarif_invocation::add_notification_for_ice): New.
(sarif_invocation::prepare_to_flush): New.
(sarif_ice_notification::sarif_ice_notification): New.
(sarif_builder::sarif_builder): Add m_invocation_obj.
(sarif_builder::end_diagnostic): Special-case DK_ICE and
DK_ICE_NOBT.
(sarif_builder::flush_to_file): Call prepare_to_flush on
m_invocation_obj.  Pass the latter to make_top_level_object.
(sarif_builder::make_result_object): Move creation of "locations"
array to...
(sarif_builder::make_locations_arr): ...this new function.
(sarif_builder::make_top_level_object): Add "invocation_obj" param
and pass it to make_run_object.
(sarif_builder::make_run_object): Add "invocation_obj" param and
use it.
(sarif_ice_handler): New callback.
(diagnostic_output_format_init_sarif): Wire up sarif_ice_handler.
* diagnostic.cc (diagnostic_initialize): Initialize new field
"ice_handler_cb".
(diagnostic_action_after_output): If it is set, make one attempt
to call ice_handler_cb.
* diagnostic.h (diagnostic_context::ice_handler_cb): New field.

gcc/testsuite/ChangeLog:
PR analyzer/109097
* c-c++-common/diagnostic-format-sarif-file-1.c: Verify that we
have an invocation object marked as succeeding, with no
notifications.
* gcc.dg/plugin/crash-test-ice-sarif.c: New test.
* gcc.dg/plugin/crash-test-ice-stderr.c: New test.
* gcc.dg/plugin/crash-test-write-though-null-sarif.c: New test.
* gcc.dg/plugin/crash-test-write-though-null-stderr.c: New test.
* gcc.dg/plugin/crash_test_plugin.c: New plugin.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add the new plugin
and test cases.

Signed-off-by: David Malcolm 
---
 gcc/diagnostic-format-sarif.cc| 173 --
 gcc/diagnostic.cc |  13 ++
 gcc/diagnostic.h  |   3 +
 .../diagnostic-format-sarif-file-1.c  |   5 +
 .../gcc.dg/plugin/crash-test-ice-sarif.c  |  62 +++
 .../gcc.dg/plugin/crash-test-ice-stderr.c |   9 +
 .../crash-test-write-though-null-sarif.c  |  62 +++
 .../crash-test-write-though-null-stderr.c |   9 +
 .../gcc.dg/plugin/crash_test_plugin.c | 135 ++
 gcc/testsuite/gcc.dg/plugin/plugin.exp|   5 +
 10 files changed, 458 insertions(+), 18 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/plugin/crash-test-ice-sarif.c
 create mode 100644 gcc/testsuite/gcc.dg/plugin/crash-test-ice-stderr.c
 create mode 100644 
gcc/testsuite/gcc.dg/plugin/crash-test-write-though-null-sarif.c
 create mode 100644 
gcc/testsuite/gcc.dg/plugin/crash-test-write-though-null-stderr.c
 create mode 100644 gcc/testsuite/gcc.dg/plugin/crash_test_plugin.c

diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index f8fdd586ff0..2c48cbd46e2 

Re: [PATCH v2] PR target/89828 Inernal compiler error on -fno-omit-frame-pointer

2023-03-15 Thread Jeff Law via Gcc-patches




On 3/15/23 01:51, Yoshinori Sato wrote:

What about this?
It no longer occurs for me.

gcc/config/rx/
* rx.cc (add_pop_cfi_notes): Release the frame pointer if it is used.
(rx_expand_prologue): Redesigned stack pointer and frame pointer update 
process.
That fixes the problems building newlib.  It also fixes roughly 300 
failures in the testsuite (primarily fixing ICEs in 
dwarf2out_frame_debug_adjust_cfa).


So the next step is to sit down with the code  and review it :-)

jeff


Re: Now gcc-13: [Fwd: [PATCH] gcc-12: Re-enable split-stack support for GNU/Hurd.]

2023-03-15 Thread Ian Lance Taylor via Gcc-patches
On Wed, Mar 15, 2023 at 9:14 AM Svante Signell  wrote:
>
> Package: gcc-snapshot
> Version: 1:20230315-1
> Severity: important
> Tags: patch
> User: debian-h...@lists.debian.org
> Usertags: hurd
> Affects: gcc-snapshot
> X-Debbugs-CC: debian-h...@lists.debian.org
>
> Hello, seems like the patch gcc_config_gnu.h.diff, in debian gcc-12 named:
> pr104290-followup.diff was lost (again).
>
> How can this patch ever become upstreamed??
>
> It seems like sending to gcc-patches is not enough. Create a regression bug?
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104290 is already reported as a
> regression, it has to be updated to cover upstream releases of gcc-13 now.
>
> For gcc-12 Debian has been carrying it as:
> pr104290-followup.diff
>
> Submitting this problem as new bug to Debian/gcc-13/gcc-snapshot!
>
> Thanks!
>
>
>
> -- Forwarded message --
> From: Svante Signell 
> To: gcc-patches 
> Cc: Ian Lance Taylor , Matthias Klose 
> Bcc:
> Date: Wed, 23 Feb 2022 11:13:50 +0100
> Subject: [PATCH] gcc-12: Re-enable split-stack support for GNU/Hurd.
> Hello,
>
> In line of porting the latest build of libgo/go with gcc-12 to GNU/Hurd, 
> support
> of split-stack was found to be removed.
>
> After patching the files in libgo the build of gotools fails:
> go1: error: '-fsplit-stack' currently only supported on GNU/Linux
> go1: error: '-fsplit-stack' is not supported by this compiler configuration
>
> The attached patch defines OPTION_GLIBC_P(opts) and OPTION_GLIBC that was lost
> in config/gnu.h, needed to enable split-stack support for GNU/Hurd.
>
> This problem happened with the latest commit as discussed in the mail thread
> starting with 
> https://gcc.gnu.org/pipermail/gcc-patches/2022-January/588973.html
> .
>
> The file first doing this check is: (first error: ..)
> src/gcc/common/config/i386/i386-common.cc
> in function:
> static bool ix86_supports_split_stack (bool report,
> struct gcc_options *opts ATTRIBUTE_UNUSED)
>
> and secondly in:src/gcc/opts.cc: (second error: ...)
> in function:
> void
> finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
> location_t loc)
>
> The checking logic is in function ix86_supports_split_stack():
> #if defined(TARGET_THREAD_SPLIT_STACK_OFFSET) && defined(OPTION_GLIBC_P)
>   if (!OPTION_GLIBC_P (opts))
> #endif
> {
>   if (report)
> error ("%<-fsplit-stack%> currently only supported on GNU/Linux");
>   return false;
> }
>
>   bool ret = true;
>
> In case of GNU/Hurd TARGET_THREAD_SPLIT_STACK_OFFSET is defined as well as
> OPTION_GLIBC_P but OPTION_GLIBC_P(opts) is needed to. The attached patch to
> src/gcc/config/gnu.h creates that definition. For GNU/Hurd, gnu.h is included 
> in
> the configure stage:
> Configuring stage 1 in ./gcc
> ...
> Using the following target machine macro files:
> ...
> ../../src/gcc/config/gnu.h
>
> For a longer history about this bug see:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104290
>
> Additionally, I would propose the text in 
> gcc/common/config/i386/i386-common.cc
> to change from:
> error ("%<-fsplit-stack%> currently only supported on GNU/Linux");
> to:
> error ("%<-fsplit-stack%> currently only supported on GLIBC-based systems");


If GNU/Hurd requires glibc, then I think it would be simpler to define
OPTION_GLIBC and OPTION_GLIBC_P as true.

Adding Thomas Schwinge as the GNU/Hurd maintainer.

Ian


[PATCH] c++, libstdc++: new compiler built in is_scalar, use built-in is_scalar in libstdc++ std::is_scalar

2023-03-15 Thread Berke Yavas via Gcc-patches
Have implemented a new compiler built-in for the scalar types(is_scalar). 
Changed the libstdc++
std::is_scalar implementation to use this new compiler built_in when available.

tested on x86_64-redhat-linux. Compared test results and configured with 
--enable-bootstrap

gcc/cp/ChangeLog:

* constraint.cc (diagnose_trait_expr): Add note for CPTK_IS_SCALAR
failing.
* cp-trait.def (IS_SCALAR): Define IS_SCALAR trait.
* cxx-pretty-print.cc (pp_cxx_userdef_literal): Add __is_scalar to
comment.
* parser.cc (cp_parser_fold_expression): Likewise.
* semantics.cc (trait_expr_value): Implement built-in CPTK_IS_SCALAR.
(finish_trait_expr): Add CPTK_IS_SCALAR.

libstdc++-v3/ChangeLog:

* include/bits/cpp_type_traits.h (__is_scalar): Rename to
__is_arith_or_ptr.
* include/bits/stl_algobase.h (__fill_a1, __fill_n_a1): Adjust.
* include/bits/valarray_array.h: Likewise..
* include/std/type_traits (is_scalar): Use built-in __is_scalar if
available.

gcc/testsuite/ChangeLog:

* g++.dg/ext/has-builtin-1.C: Check __is_scalar.
* g++.dg/tm/pr46567.C: Rename __is_scalar to __is_arith_or_ptr to
avoid collision with built-in.
* g++.dg/torture/pr57107.C: Likewise.
* g++.dg/ext/is_scalar.C: New test.

Signed-off-by: Berke Yavas 
---
 gcc/cp/constraint.cc|  3 +++
 gcc/cp/cp-trait.def |  1 +
 gcc/cp/cxx-pretty-print.cc  |  3 ++-
 gcc/cp/parser.cc|  1 +
 gcc/cp/semantics.cc |  4 
 gcc/testsuite/g++.dg/ext/has-builtin-1.C|  4 
 gcc/testsuite/g++.dg/ext/is_scalar.C| 21 +
 gcc/testsuite/g++.dg/tm/pr46567.C   | 10 +-
 gcc/testsuite/g++.dg/torture/pr57107.C  |  4 ++--
 libstdc++-v3/include/bits/cpp_type_traits.h |  4 ++--
 libstdc++-v3/include/bits/stl_algobase.h|  8 
 libstdc++-v3/include/bits/valarray_array.h  |  2 +-
 libstdc++-v3/include/std/type_traits|  7 +++
 13 files changed, 57 insertions(+), 15 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/is_scalar.C

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 9374327008b..f799ba2efd5 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3747,6 +3747,9 @@ diagnose_trait_expr (tree expr, tree args)
 case CPTK_IS_UNION:
   inform (loc, "  %qT is not a union", t1);
   break;
+case CPTK_IS_SCALAR:
+  inform(loc, "  %qT is not a scalar type", t1);
+  break;
 case CPTK_IS_AGGREGATE:
   inform (loc, "  %qT is not an aggregate", t1);
   break;
diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
index 823899a26c5..8dace289e88 100644
--- a/gcc/cp/cp-trait.def
+++ b/gcc/cp/cp-trait.def
@@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, 
"__is_trivially_assignable", 2)
 DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1)
 DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
 DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
+DEFTRAIT_EXPR (IS_SCALAR, "__is_scalar", 1)
 DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, 
"__reference_constructs_from_temporary", 2)
 DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, 
"__reference_converts_from_temporary", 2)
 
diff --git a/gcc/cp/cxx-pretty-print.cc b/gcc/cp/cxx-pretty-print.cc
index bea52a608f1..a79359430a5 100644
--- a/gcc/cp/cxx-pretty-print.cc
+++ b/gcc/cp/cxx-pretty-print.cc
@@ -437,7 +437,8 @@ pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
  __is_polymorphic ( type-id )
  __is_std_layout ( type-id )
  __is_trivial ( type-id )
- __is_union ( type-id )  */
+ __is_union ( type-id )
+ __is_scalar ( type-id )  */
 
 void
 cxx_pretty_printer::primary_expression (tree t)
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index b00a6cd5b8b..8465d4fbcdb 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -5577,6 +5577,7 @@ cp_parser_fold_expression (cp_parser *parser, tree expr1)
  __is_std_layout ( type-id )
  __is_trivial ( type-id )
  __is_union ( type-id )
+ __is_scalar ( type-id )
 
Objective-C++ Extension:
 
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index db982d594e6..81b13d1ae5c 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12025,6 +12025,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree 
type2)
 case CPTK_IS_UNION:
   return type_code1 == UNION_TYPE;
 
+case CPTK_IS_SCALAR:
+  return SCALAR_TYPE_P (type1);
+
 case CPTK_IS_ASSIGNABLE:
   return is_xible (MODIFY_EXPR, type1, type2);
 
@@ -12190,6 +12193,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, 
tree type1, tree type2)
 case CPTK_IS_CLASS:
 case CPTK_IS_ENUM:
 case CPTK_IS_UNION:
+case CPTK_IS_SCALAR:
 case CPTK_IS_SAME:
   break;
 
diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C 

[PATCH] compiler built in is_scalar, use built-in is_scalar in libstdc++ std::is_scalar

2023-03-15 Thread Berke Yavas via Gcc-patches
From: Berke 

Signed-off-by: Berke Yavas 
---
 gcc/cp/constraint.cc|  3 +++
 gcc/cp/cp-trait.def |  1 +
 gcc/cp/cxx-pretty-print.cc  |  3 ++-
 gcc/cp/parser.cc|  1 +
 gcc/cp/semantics.cc |  4 
 gcc/testsuite/g++.dg/ext/has-builtin-1.C|  4 
 gcc/testsuite/g++.dg/ext/is_scalar.C| 21 +
 gcc/testsuite/g++.dg/tm/pr46567.C   | 10 +-
 gcc/testsuite/g++.dg/torture/pr57107.C  |  4 ++--
 libstdc++-v3/include/bits/cpp_type_traits.h |  8 
 libstdc++-v3/include/bits/stl_algobase.h|  8 
 libstdc++-v3/include/bits/valarray_array.h  |  2 +-
 libstdc++-v3/include/std/type_traits|  7 +++
 13 files changed, 59 insertions(+), 17 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/is_scalar.C

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 9374327008b..f799ba2efd5 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3747,6 +3747,9 @@ diagnose_trait_expr (tree expr, tree args)
 case CPTK_IS_UNION:
   inform (loc, "  %qT is not a union", t1);
   break;
+case CPTK_IS_SCALAR:
+  inform(loc, "  %qT is not a scalar type", t1);
+  break;
 case CPTK_IS_AGGREGATE:
   inform (loc, "  %qT is not an aggregate", t1);
   break;
diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
index 823899a26c5..8dace289e88 100644
--- a/gcc/cp/cp-trait.def
+++ b/gcc/cp/cp-trait.def
@@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, 
"__is_trivially_assignable", 2)
 DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1)
 DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
 DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
+DEFTRAIT_EXPR (IS_SCALAR, "__is_scalar", 1)
 DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, 
"__reference_constructs_from_temporary", 2)
 DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, 
"__reference_converts_from_temporary", 2)
 
diff --git a/gcc/cp/cxx-pretty-print.cc b/gcc/cp/cxx-pretty-print.cc
index bea52a608f1..a79359430a5 100644
--- a/gcc/cp/cxx-pretty-print.cc
+++ b/gcc/cp/cxx-pretty-print.cc
@@ -437,7 +437,8 @@ pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
  __is_polymorphic ( type-id )
  __is_std_layout ( type-id )
  __is_trivial ( type-id )
- __is_union ( type-id )  */
+ __is_union ( type-id )
+ __is_scalar ( type-id )  */
 
 void
 cxx_pretty_printer::primary_expression (tree t)
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index b00a6cd5b8b..8465d4fbcdb 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -5577,6 +5577,7 @@ cp_parser_fold_expression (cp_parser *parser, tree expr1)
  __is_std_layout ( type-id )
  __is_trivial ( type-id )
  __is_union ( type-id )
+ __is_scalar ( type-id )
 
Objective-C++ Extension:
 
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index db982d594e6..81b13d1ae5c 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12025,6 +12025,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree 
type2)
 case CPTK_IS_UNION:
   return type_code1 == UNION_TYPE;
 
+case CPTK_IS_SCALAR:
+  return SCALAR_TYPE_P (type1);
+
 case CPTK_IS_ASSIGNABLE:
   return is_xible (MODIFY_EXPR, type1, type2);
 
@@ -12190,6 +12193,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, 
tree type1, tree type2)
 case CPTK_IS_CLASS:
 case CPTK_IS_ENUM:
 case CPTK_IS_UNION:
+case CPTK_IS_SCALAR:
 case CPTK_IS_SAME:
   break;
 
diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C 
b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
index f343e153e56..4bf06a7a438 100644
--- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
+++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
@@ -146,3 +146,7 @@
 #if !__has_builtin (__remove_cvref)
 # error "__has_builtin (__remove_cvref) failed"
 #endif
+#if !__has_builtin (__is_scalar)
+# error "__has_builtin (__is_scalar) failed"
+#endif
+
diff --git a/gcc/testsuite/g++.dg/ext/is_scalar.C 
b/gcc/testsuite/g++.dg/ext/is_scalar.C
new file mode 100644
index 000..1d58f6ec475
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_scalar.C
@@ -0,0 +1,21 @@
+// { dg-do compile { target c++11 } }
+
+#define SA(X) static_assert((X),#X)
+
+struct S { int m; };
+
+enum class E {
+  e
+};
+
+int main() {
+  char* pNull= nullptr;
+
+  SA(__is_scalar(decltype(pNull)));
+  SA(__is_scalar(int));
+  SA(__is_scalar(double));
+  SA(__is_scalar(E));
+  SA(__is_scalar(char const *));
+  SA(!__is_scalar(struct S));
+  return 0;
+}
\ No newline at end of file
diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C 
b/gcc/testsuite/g++.dg/tm/pr46567.C
index 6d791484448..760c7fd6cab 100644
--- a/gcc/testsuite/g++.dg/tm/pr46567.C
+++ b/gcc/testsuite/g++.dg/tm/pr46567.C
@@ -225,7 +225,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
 : public __traitor<__is_void<_Tp>, __is_arithmetic<_Tp> >
 

[PATCH] i386: Fix blend vector permutation for 8-byte modes

2023-03-15 Thread Uros Bizjak via Gcc-patches
8-byte modes should be processed only for TARGET_MMX_WITH_SSE. Handle
V2SFmode and fix V2HImode handling. The resulting BLEND instructions
are always faster than MOVSS/MOVSD, so prioritize them w.r.t MOVSS/MOVSD
for TARGET_SSE4_1.

gcc/ChangeLog:

* config/i386/i386-expand.cc (expand_vec_perm_blend):
Handle 8-byte modes only with TARGET_MMX_WITH_SSE. Handle V2SFmode
and fix V2HImode handling.
(expand_vec_perm_1): Try to emit BLEND instruction
before MOVSS/MOVSD.
* config/i386/mmx.md (*mmx_blendps): New insn pattern.

gcc/testsuite/ChangeLog:

* gcc.target/i386/merge-1.c (dg-options): Use -mno-sse4.
* gcc.target/i386/sse2-mmx-21.c (dg-options): Ditto.
* gcc.target/i386/sse-movss-4.c (dg-options):
Use -mno-sse4.  Simplify scan-assembler-not strings.
* gcc.target/i386/sse2-movsd-3.c (dg-options): Ditto.
* gcc.target/i386/sse2-mmx-movss-1.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.cc b/gcc/config/i386/i386-expand.cc
index e89abf2e817..1545d4365b7 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -19007,9 +19007,10 @@ expand_vec_perm_blend (struct expand_vec_perm_d *d)
 ;
   else if (TARGET_AVX && (vmode == V4DFmode || vmode == V8SFmode))
 ;
-  else if (TARGET_SSE4_1 && (GET_MODE_SIZE (vmode) == 16
-|| GET_MODE_SIZE (vmode) == 8
-|| GET_MODE_SIZE (vmode) == 4))
+  else if (TARGET_SSE4_1
+  && (GET_MODE_SIZE (vmode) == 16
+  || (TARGET_MMX_WITH_SSE && GET_MODE_SIZE (vmode) == 8)
+  || GET_MODE_SIZE (vmode) == 4))
 ;
   else
 return false;
@@ -19042,6 +19043,8 @@ expand_vec_perm_blend (struct expand_vec_perm_d *d)
 case E_V8SFmode:
 case E_V2DFmode:
 case E_V4SFmode:
+case E_V2SFmode:
+case E_V2HImode:
 case E_V4HImode:
 case E_V8HImode:
 case E_V8SImode:
@@ -19897,11 +19900,15 @@ expand_vec_perm_1 (struct expand_vec_perm_d *d)
}
 }
 
+  /* Try the SSE4.1 blend variable merge instructions.  */
+  if (expand_vec_perm_blend (d))
+return true;
+
   /* Try movss/movsd instructions.  */
   if (expand_vec_perm_movs (d))
 return true;
 
-  /* Finally, try the fully general two operand permute.  */
+  /* Try the fully general two operand permute.  */
   if (expand_vselect_vconcat (d->target, d->op0, d->op1, d->perm, nelt,
  d->testing_p))
 return true;
@@ -19924,10 +19931,6 @@ expand_vec_perm_1 (struct expand_vec_perm_d *d)
return true;
 }
 
-  /* Try the SSE4.1 blend variable merge instructions.  */
-  if (expand_vec_perm_blend (d))
-return true;
-
   /* Try one of the AVX vpermil variable permutations.  */
   if (expand_vec_perm_vpermil (d))
 return true;
diff --git a/gcc/config/i386/mmx.md b/gcc/config/i386/mmx.md
index f9c66115f81..18dae03ad0a 100644
--- a/gcc/config/i386/mmx.md
+++ b/gcc/config/i386/mmx.md
@@ -1154,6 +1154,25 @@ (define_expand "vcondv2sf"
   DONE;
 })
 
+(define_insn "*mmx_blendps"
+  [(set (match_operand:V2SF 0 "register_operand" "=Yr,*x,x")
+   (vec_merge:V2SF
+ (match_operand:V2SF 2 "register_operand" "Yr,*x,x")
+ (match_operand:V2SF 1 "register_operand" "0,0,x")
+ (match_operand:SI 3 "const_0_to_3_operand")))]
+  "TARGET_SSE4_1 && TARGET_MMX_WITH_SSE"
+  "@
+   blendps\t{%3, %2, %0|%0, %2, %3}
+   blendps\t{%3, %2, %0|%0, %2, %3}
+   vblendps\t{%3, %2, %1, %0|%0, %1, %2, %3}"
+  [(set_attr "isa" "noavx,noavx,avx")
+   (set_attr "type" "ssemov")
+   (set_attr "length_immediate" "1")
+   (set_attr "prefix_data16" "1,1,*")
+   (set_attr "prefix_extra" "1")
+   (set_attr "prefix" "orig,orig,vex")
+   (set_attr "mode" "V4SF")])
+
 (define_insn "mmx_blendvps"
   [(set (match_operand:V2SF 0 "register_operand" "=Yr,*x,x")
(unspec:V2SF
diff --git a/gcc/testsuite/gcc.target/i386/merge-1.c 
b/gcc/testsuite/gcc.target/i386/merge-1.c
index d5256851096..b018eb19205 100644
--- a/gcc/testsuite/gcc.target/i386/merge-1.c
+++ b/gcc/testsuite/gcc.target/i386/merge-1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O1 -msse2" } */
+/* { dg-options "-O1 -msse2 -mno-sse4" } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/i386/sse-movss-4.c 
b/gcc/testsuite/gcc.target/i386/sse-movss-4.c
index ec3019c8e54..d8a8a03b147 100644
--- a/gcc/testsuite/gcc.target/i386/sse-movss-4.c
+++ b/gcc/testsuite/gcc.target/i386/sse-movss-4.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -msse" } */
+/* { dg-options "-O2 -msse -mno-sse4" } */
 
 typedef unsigned int v4si __attribute__((vector_size(16)));
 typedef float v4sf __attribute__((vector_size(16)));
@@ -7,7 +7,7 @@ typedef float v4sf __attribute__((vector_size(16)));
 v4si foo(v4si x,v4si y) { return (v4si){y[0],x[1],x[2],x[3]}; }
 v4sf bar(v4sf x,v4sf y) { return (v4sf){y[0],x[1],x[2],x[3]}; }
 
-/* { dg-final { 

Re: [PATCH] Fortran: rank checking with explicit-/assumed-size arrays and CLASS [PR58331]

2023-03-15 Thread Harald Anlauf via Gcc-patches

Hi Tobias,

Am 15.03.23 um 10:10 schrieb Tobias Burnus:

Hi Harald,

On 14.03.23 20:38, Harald Anlauf wrote:

The testcase covers only non-coarray cases, as playing with
coarray variants hit pre-exisiting issues in gfortran that
are very likely unrelated to the interface checks.

I concur (but would not rule out additional interface issues).


More testing seems to mostly uncover issues later on in trans*.cc,
e.g. when passing type to class.  I'll open a PR on this as a followup.


I consider this rather as post 13-release stuff.

In any case, the coarray issue can be fixed separately. And I think
post-GCC-13 makes sense.


Good.


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

Thanks – LGTM!

+  formal_as = formal->ts.type == BT_CLASS ? CLASS_DATA (formal)->as
+   : formal->as;
+


(Jakub remarks for such code that some editor (emacs?), he does not use,
mis--auto-indent such a code - and proposes to add a parentheses
around the right-hand side of the assignment.)


Ah, adding parentheses helps!  I've reformatted this block accordingly.
Pushed as:

https://gcc.gnu.org/g:901edd99b44976b3c2b13a7d525d9e315540186a


* * *

I also wonder whether we need some run-time testcase. The interface
check now works and I also tend to write dg-do-compile testcases, but
given what can go wrong with all the array descriptor, class etc
handling, we may want to ensure it works at run time. – Thoughts?


If you comment out the lines with dg-error, the code compiles
and seems to run fine here.  I've even found cases where passing
array sections works correctly here and with current Intel it
does not ;-)

I'd prefer to postpone more elaborate run-time tests until we have
more non-ICEing related code.

Thanks,
Harald


(That's independent of the patch it and could be done as follow up, if
it deemed reasonable. The included testcase is surely compile-only as it
has dg-error checks.)

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





[PATCH v2 2/2] libstdc++: use copy_file_range, improve sendfile in filesystem::copy_file

2023-03-15 Thread Jannik Glückert via Gcc-patches

From c028a0072c7573cfac90289b3606ba19cb8272a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jannik=20Gl=C3=BCckert?= 
Date: Wed, 8 Mar 2023 19:37:43 +0100
Subject: [PATCH 2/2] libstdc++: use copy_file_range
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

copy_file_range is a recent-ish syscall for copying files. It is similar
to sendfile but allows filesystem-specific optimizations. Common are:
Reflinks: BTRFS, XFS, ZFS (does not implement the syscall yet)
Server-side copy: NFS, SMB, Ceph

If copy_file_range is not available for the given files, fall back to
sendfile / userspace copy.

libstdc++-v3/ChangeLog:

* acinclude.m4 (_GLIBCXX_USE_COPY_FILE_RANGE): define
* config.h.in: Regenerate.
* configure: Regenerate.
* src/filesystem/ops-common.h: use copy_file_range in
  std::filesystem::copy_file

Signed-off-by: Jannik Glückert 
---
 libstdc++-v3/acinclude.m4| 20 
 libstdc++-v3/config.h.in |  3 ++
 libstdc++-v3/configure   | 62 
 libstdc++-v3/src/filesystem/ops-common.h | 50 +++
 4 files changed, 135 insertions(+)

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 85a09a5a869..4cf02dc6e4e 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -4581,6 +4581,7 @@ dnl  _GLIBCXX_USE_UTIMENSAT
 dnl  _GLIBCXX_USE_ST_MTIM
 dnl  _GLIBCXX_USE_FCHMOD
 dnl  _GLIBCXX_USE_FCHMODAT
+dnl  _GLIBCXX_USE_COPY_FILE_RANGE
 dnl  _GLIBCXX_USE_SENDFILE
 dnl  HAVE_LINK
 dnl  HAVE_LSEEK
@@ -4779,6 +4780,25 @@ dnl
   if test $glibcxx_cv_truncate = yes; then
 AC_DEFINE(HAVE_TRUNCATE, 1, [Define if truncate is available in .])
   fi
+dnl
+  AC_CACHE_CHECK([for copy_file_range that can copy files],
+glibcxx_cv_copy_file_range, [dnl
+case "${target_os}" in
+  linux*)
+	GCC_TRY_COMPILE_OR_LINK(
+	  [#include ],
+	  [copy_file_range(1, nullptr, 2, nullptr, 1, 0);],
+	  [glibcxx_cv_copy_file_range=yes],
+	  [glibcxx_cv_copy_file_range=no])
+	;;
+  *)
+	glibcxx_cv_copy_file_range=no
+	;;
+esac
+  ])
+  if test $glibcxx_cv_copy_file_range = yes; then
+AC_DEFINE(_GLIBCXX_USE_COPY_FILE_RANGE, 1, [Define if copy_file_range is available in .])
+  fi
 dnl
   AC_CACHE_CHECK([for sendfile that can copy files],
 glibcxx_cv_sendfile, [dnl
diff --git a/libstdc++-v3/src/filesystem/ops-common.h b/libstdc++-v3/src/filesystem/ops-common.h
index 9e1b1d41dc5..202728baef2 100644
--- a/libstdc++-v3/src/filesystem/ops-common.h
+++ b/libstdc++-v3/src/filesystem/ops-common.h
@@ -49,6 +49,9 @@
 #ifdef NEED_DO_COPY_FILE
 # include 
 # include 
+# ifdef _GLIBCXX_USE_COPY_FILE_RANGE
+#  include  // copy_file_range
+# endif
 # ifdef _GLIBCXX_USE_SENDFILE
 #  include  // sendfile
 #  include  // lseek
@@ -359,6 +362,31 @@ _GLIBCXX_BEGIN_NAMESPACE_FILESYSTEM
   }
 
 #ifdef NEED_DO_COPY_FILE
+#ifdef _GLIBCXX_USE_COPY_FILE_RANGE
+  bool
+  copy_file_copy_file_range(int fd_in, int fd_out, size_t length) noexcept
+  {
+// a zero-length file is either empty, or not copyable by this syscall
+// return early to avoid the syscall cost
+if (length == 0)
+  {
+errno = EINVAL;
+return false;
+  }
+size_t bytes_left = length;
+off64_t off_in = 0, off_out = 0;
+ssize_t bytes_copied;
+do {
+  bytes_copied = ::copy_file_range(fd_in, _in, fd_out, _out, bytes_left, 0);
+  bytes_left -= bytes_copied;
+} while (bytes_left > 0 && bytes_copied > 0);
+if (bytes_copied < 0)
+  {
+return false;
+  }
+return true;
+  }
+#endif
 #if defined _GLIBCXX_USE_SENDFILE && ! defined _GLIBCXX_FILESYSTEM_IS_WINDOWS
   bool
   copy_file_sendfile(int fd_in, int fd_out, size_t length) noexcept
@@ -527,6 +555,28 @@ _GLIBCXX_BEGIN_NAMESPACE_FILESYSTEM
 
 bool has_copied = false;
 
+#ifdef _GLIBCXX_USE_COPY_FILE_RANGE
+if (!has_copied)
+  has_copied = copy_file_copy_file_range(in.fd, out.fd, from_st->st_size);
+if (!has_copied)
+  {
+// EINVAL: src and dst are the same file (this is not cheaply detectable from userspace)
+// EINVAL: copy_file_range is unsupported for this file type by the underlying filesystem
+// ENOTSUP: undocumented, can arise with old kernels and NFS
+// EOPNOTSUPP: filesystem does not implement copy_file_range
+// ETXTBSY: src or dst is an active swapfile (nonsensical, but allowed with normal copying)
+// EXDEV: src and dst are on different filesystems that do not support cross-fs copy_file_range
+// ENOENT: undocumented, can arise with CIFS
+// ENOSYS: unsupported by kernel or blocked by seccomp
+if (errno != EINVAL && errno != ENOTSUP && errno != EOPNOTSUPP
+&& errno != ETXTBSY && errno != EXDEV && errno != ENOENT && errno != ENOSYS)
+  {
+ec.assign(errno, std::generic_category());
+return false;
+  }
+  }
+#endif

[PATCH v2 1/2] libstdc++: use copy_file_range, improve sendfile in filesystem::copy_file

2023-03-15 Thread Jannik Glückert via Gcc-patches
This iteration improves error handling for copy_file_range,
particularly around undocumented error codes in earlier kernel
versions.
Additionally this fixes the userspace copy fallback to handle
zero-length files such as in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108178.

Lastly, the case "src gets resized during the copy loop" is now
considered and will return true once the loop hits EOF (this is the
only situation, aside from a zero-length src, where sendfile and
copy_file_range return 0).

Best
Jannik
From b55eb8dccaa44f07d8acbe6294326a46c920b04f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jannik=20Gl=C3=BCckert?= 
Date: Mon, 6 Mar 2023 20:52:08 +0100
Subject: [PATCH 1/2] libstdc++: also use sendfile for big files
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

we were previously only using sendfile for files smaller than 2GB, as
sendfile needs to be called repeatedly for files bigger than that.

some quick numbers, copying a 16GB file, average of 10 repetitions:
old:
real: 13.4s
user: 0.14s
sys : 7.43s
new:
real: 8.90s
user: 0.00s
sys : 3.68s

Additionally, this fixes
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108178

libstdc++-v3/ChangeLog:

* acinclude.m4 (_GLIBCXX_HAVE_LSEEK): define
* config.h.in: Regenerate.
* configure: Regenerate.
* src/filesystem/ops-common.h: enable sendfile for files
  >2GB in std::filesystem::copy_file, skip zero-length files

Signed-off-by: Jannik Glückert 
---
 libstdc++-v3/acinclude.m4|  51 +
 libstdc++-v3/config.h.in |   3 +
 libstdc++-v3/configure   | 127 ---
 libstdc++-v3/src/filesystem/ops-common.h |  86 ---
 4 files changed, 175 insertions(+), 92 deletions(-)

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 5136c0571e8..85a09a5a869 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -4583,6 +4583,7 @@ dnl  _GLIBCXX_USE_FCHMOD
 dnl  _GLIBCXX_USE_FCHMODAT
 dnl  _GLIBCXX_USE_SENDFILE
 dnl  HAVE_LINK
+dnl  HAVE_LSEEK
 dnl  HAVE_READLINK
 dnl  HAVE_SYMLINK
 dnl
@@ -4718,25 +4719,6 @@ dnl
   if test $glibcxx_cv_fchmodat = yes; then
 AC_DEFINE(_GLIBCXX_USE_FCHMODAT, 1, [Define if fchmodat is available in .])
   fi
-dnl
-  AC_CACHE_CHECK([for sendfile that can copy files],
-glibcxx_cv_sendfile, [dnl
-case "${target_os}" in
-  gnu* | linux* | solaris* | uclinux*)
-	GCC_TRY_COMPILE_OR_LINK(
-	  [#include ],
-	  [sendfile(1, 2, (off_t*)0, sizeof 1);],
-	  [glibcxx_cv_sendfile=yes],
-	  [glibcxx_cv_sendfile=no])
-	;;
-  *)
-	glibcxx_cv_sendfile=no
-	;;
-esac
-  ])
-  if test $glibcxx_cv_sendfile = yes; then
-AC_DEFINE(_GLIBCXX_USE_SENDFILE, 1, [Define if sendfile is available in .])
-  fi
 dnl
   AC_CACHE_CHECK([for link],
 glibcxx_cv_link, [dnl
@@ -4749,6 +4731,18 @@ dnl
   if test $glibcxx_cv_link = yes; then
 AC_DEFINE(HAVE_LINK, 1, [Define if link is available in .])
   fi
+dnl
+  AC_CACHE_CHECK([for lseek],
+glibcxx_cv_lseek, [dnl
+GCC_TRY_COMPILE_OR_LINK(
+  [#include ],
+  [lseek(1, 0, SEEK_SET);],
+  [glibcxx_cv_lseek=yes],
+  [glibcxx_cv_lseek=no])
+  ])
+  if test $glibcxx_cv_lseek = yes; then
+AC_DEFINE(HAVE_LSEEK, 1, [Define if lseek is available in .])
+  fi
 dnl
   AC_CACHE_CHECK([for readlink],
 glibcxx_cv_readlink, [dnl
@@ -4785,6 +4779,25 @@ dnl
   if test $glibcxx_cv_truncate = yes; then
 AC_DEFINE(HAVE_TRUNCATE, 1, [Define if truncate is available in .])
   fi
+dnl
+  AC_CACHE_CHECK([for sendfile that can copy files],
+glibcxx_cv_sendfile, [dnl
+case "${target_os}" in
+  gnu* | linux* | solaris* | uclinux*)
+	GCC_TRY_COMPILE_OR_LINK(
+	  [#include ],
+	  [sendfile(1, 2, (off_t*)0, sizeof 1);],
+	  [glibcxx_cv_sendfile=yes],
+	  [glibcxx_cv_sendfile=no])
+	;;
+  *)
+	glibcxx_cv_sendfile=no
+	;;
+esac
+  ])
+  if test $glibcxx_cv_sendfile = yes && test $glibcxx_cv_lseek = yes; then
+AC_DEFINE(_GLIBCXX_USE_SENDFILE, 1, [Define if sendfile is available in .])
+  fi
 dnl
   AC_CACHE_CHECK([for fdopendir],
 glibcxx_cv_fdopendir, [dnl
diff --git a/libstdc++-v3/src/filesystem/ops-common.h b/libstdc++-v3/src/filesystem/ops-common.h
index abbfca43e5c..9e1b1d41dc5 100644
--- a/libstdc++-v3/src/filesystem/ops-common.h
+++ b/libstdc++-v3/src/filesystem/ops-common.h
@@ -51,6 +51,7 @@
 # include 
 # ifdef _GLIBCXX_USE_SENDFILE
 #  include  // sendfile
+#  include  // lseek
 # endif
 #endif
 
@@ -358,6 +359,32 @@ _GLIBCXX_BEGIN_NAMESPACE_FILESYSTEM
   }
 
 #ifdef NEED_DO_COPY_FILE
+#if defined _GLIBCXX_USE_SENDFILE && ! defined _GLIBCXX_FILESYSTEM_IS_WINDOWS
+  bool
+  copy_file_sendfile(int fd_in, int fd_out, size_t length) noexcept
+  {
+// a zero-length file is either empty, or not copyable by this syscall
+// return early to avoid the syscall cost
+if (length == 0)
+  {
+errno 

Re: [PATCH v2] c++: ICE with constexpr lambda [PR107280]

2023-03-15 Thread Marek Polacek via Gcc-patches
On Wed, Mar 15, 2023 at 12:48:27PM -0400, Jason Merrill wrote:
> On 3/15/23 10:37, Marek Polacek wrote:
> > On Fri, Mar 10, 2023 at 01:47:46PM -0500, Jason Merrill wrote:
> > > On 3/10/23 11:17, Marek Polacek wrote:
> > > > We crash here since r10-3661, the store_init_value hunk in particular.
> > > > Before, we called cp_fully_fold_init, so e.g.
> > > > 
> > > > {.str=VIEW_CONVERT_EXPR("")}
> > > > 
> > > > was folded into
> > > > 
> > > > {.str=""}
> > > > 
> > > > but now we don't fold and keep the VCE around, and it causes trouble in
> > > > cxx_eval_store_expression: in the !refs->is_empty () loop we descend on
> > > > .str's initializer but since it's wrapped in a VCE, we skip the 
> > > > STRING_CST
> > > > check and then crash on the CONSTRUCTOR_NO_CLEARING.
> > > > 
> > > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/12?
> > > > 
> > > > PR c++/107280
> > > > 
> > > > gcc/cp/ChangeLog:
> > > > 
> > > > * constexpr.cc (cxx_eval_store_expression): Strip location 
> > > > wrappers.
> > > > 
> > > > gcc/testsuite/ChangeLog:
> > > > 
> > > > * g++.dg/cpp1z/constexpr-lambda28.C: New test.
> > > > ---
> > > >gcc/cp/constexpr.cc |  3 ++-
> > > >gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C | 15 +++
> > > >2 files changed, 17 insertions(+), 1 deletion(-)
> > > >create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C
> > > > 
> > > > diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
> > > > index 8683c00596a..abf6ee560c5 100644
> > > > --- a/gcc/cp/constexpr.cc
> > > > +++ b/gcc/cp/constexpr.cc
> > > > @@ -6033,7 +6033,8 @@ cxx_eval_store_expression (const constexpr_ctx 
> > > > *ctx, tree t,
> > > >   *valp = build_constructor (type, NULL);
> > > >   CONSTRUCTOR_NO_CLEARING (*valp) = no_zero_init;
> > > > }
> > > > -  else if (TREE_CODE (*valp) == STRING_CST)
> > > > +  else if (STRIP_ANY_LOCATION_WRAPPER (*valp),
> > > > +  TREE_CODE (*valp) == STRING_CST)
> > > 
> > > Seems like this is stripping the location wrapper when we try to modify 
> > > the
> > > string; I think we want to strip it earlier, when we first initialize the
> > > array member.
> > 
> > Hmm, I suppose we don't want to do the stripping too early.  I could
> > have put it in get_nsdmi, for instance, but maybe here is good as well?
> 
> I guess I was thinking more around the time when the value is imported into
> constant evaluation, i.e. this chunk of cxx_eval_constant_expression:
> 
> > if (tree init = DECL_INITIAL (r))
> >   {
> > init = cxx_eval_constant_expression (ctx, init, vc_prvalue,
> >  non_constant_p, 
> > overflow_p);
> > /* Don't share a CONSTRUCTOR that might be changed.  */
> > init = unshare_constructor (init);
> > /* Remember that a constant object's constructor has already
> > run.  */
> > if (CLASS_TYPE_P (TREE_TYPE (r))
> > && CP_TYPE_CONST_P (TREE_TYPE (r)))
> >   TREE_READONLY (init) = true;
> > ctx->global->put_value (r, init);
> >   }

Ah, that wouldn't fix the problem as far as I can tell -- here init is
the whole constructor: {.str=VIEW_CONVERT_EXPR("")} so we'd
not have a way to strip the inner init.
 
> Feel free to pursue that approach or go ahead and push your first patch,
> whichever you prefer.

The original patch it is, then.  Thanks.

Marek



Re: [PATCH v2] c++: ICE with constexpr lambda [PR107280]

2023-03-15 Thread Jason Merrill via Gcc-patches

On 3/15/23 10:37, Marek Polacek wrote:

On Fri, Mar 10, 2023 at 01:47:46PM -0500, Jason Merrill wrote:

On 3/10/23 11:17, Marek Polacek wrote:

We crash here since r10-3661, the store_init_value hunk in particular.
Before, we called cp_fully_fold_init, so e.g.

{.str=VIEW_CONVERT_EXPR("")}

was folded into

{.str=""}

but now we don't fold and keep the VCE around, and it causes trouble in
cxx_eval_store_expression: in the !refs->is_empty () loop we descend on
.str's initializer but since it's wrapped in a VCE, we skip the STRING_CST
check and then crash on the CONSTRUCTOR_NO_CLEARING.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/12?

PR c++/107280

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_store_expression): Strip location wrappers.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/constexpr-lambda28.C: New test.
---
   gcc/cp/constexpr.cc |  3 ++-
   gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C | 15 +++
   2 files changed, 17 insertions(+), 1 deletion(-)
   create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 8683c00596a..abf6ee560c5 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -6033,7 +6033,8 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree 
t,
  *valp = build_constructor (type, NULL);
  CONSTRUCTOR_NO_CLEARING (*valp) = no_zero_init;
}
-  else if (TREE_CODE (*valp) == STRING_CST)
+  else if (STRIP_ANY_LOCATION_WRAPPER (*valp),
+  TREE_CODE (*valp) == STRING_CST)


Seems like this is stripping the location wrapper when we try to modify the
string; I think we want to strip it earlier, when we first initialize the
array member.


Hmm, I suppose we don't want to do the stripping too early.  I could
have put it in get_nsdmi, for instance, but maybe here is good as well?


I guess I was thinking more around the time when the value is imported 
into constant evaluation, i.e. this chunk of cxx_eval_constant_expression:



if (tree init = DECL_INITIAL (r))
  {
init = cxx_eval_constant_expression (ctx, init, vc_prvalue,
 non_constant_p, overflow_p);
/* Don't share a CONSTRUCTOR that might be changed.  */
init = unshare_constructor (init);
/* Remember that a constant object's constructor has already
   run.  */

if (CLASS_TYPE_P (TREE_TYPE (r))
&& CP_TYPE_CONST_P (TREE_TYPE (r)))
  TREE_READONLY (init) = true;
ctx->global->put_value (r, init);
  }


Feel free to pursue that approach or go ahead and push your first patch, 
whichever you prefer.


Jason



Now gcc-13: [Fwd: [PATCH] gcc-12: Re-enable split-stack support for GNU/Hurd.]

2023-03-15 Thread Svante Signell via Gcc-patches
Package: gcc-snapshot
Version: 1:20230315-1
Severity: important
Tags: patch
User: debian-h...@lists.debian.org
Usertags: hurd
Affects: gcc-snapshot
X-Debbugs-CC: debian-h...@lists.debian.org

Hello, seems like the patch gcc_config_gnu.h.diff, in debian gcc-12 named:
pr104290-followup.diff was lost (again).

How can this patch ever become upstreamed??

It seems like sending to gcc-patches is not enough. Create a regression bug?  
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104290 is already reported as a
regression, it has to be updated to cover upstream releases of gcc-13 now.

For gcc-12 Debian has been carrying it as:
pr104290-followup.diff

Submitting this problem as new bug to Debian/gcc-13/gcc-snapshot!

Thanks!
--- Begin Message ---
Hello,

In line of porting the latest build of libgo/go with gcc-12 to GNU/Hurd, support
of split-stack was found to be removed.
 
After patching the files in libgo the build of gotools fails:
go1: error: '-fsplit-stack' currently only supported on GNU/Linux
go1: error: '-fsplit-stack' is not supported by this compiler configuration

The attached patch defines OPTION_GLIBC_P(opts) and OPTION_GLIBC that was lost
in config/gnu.h, needed to enable split-stack support for GNU/Hurd. 

This problem happened with the latest commit as discussed in the mail thread
starting with https://gcc.gnu.org/pipermail/gcc-patches/2022-January/588973.html
.

The file first doing this check is: (first error: ..)
src/gcc/common/config/i386/i386-common.cc
in function:
static bool ix86_supports_split_stack (bool report,
struct gcc_options *opts ATTRIBUTE_UNUSED)

and secondly in:src/gcc/opts.cc: (second error: ...)
in function:
void
finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
location_t loc)

The checking logic is in function ix86_supports_split_stack():
#if defined(TARGET_THREAD_SPLIT_STACK_OFFSET) && defined(OPTION_GLIBC_P)
  if (!OPTION_GLIBC_P (opts))
#endif
{
  if (report)
error ("%<-fsplit-stack%> currently only supported on GNU/Linux");
  return false;
}

  bool ret = true;

In case of GNU/Hurd TARGET_THREAD_SPLIT_STACK_OFFSET is defined as well as
OPTION_GLIBC_P but OPTION_GLIBC_P(opts) is needed to. The attached patch to
src/gcc/config/gnu.h creates that definition. For GNU/Hurd, gnu.h is included in
the configure stage:
Configuring stage 1 in ./gcc
...
Using the following target machine macro files:
...
../../src/gcc/config/gnu.h

For a longer history about this bug see:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104290

Additionally, I would propose the text in gcc/common/config/i386/i386-common.cc
to change from:
error ("%<-fsplit-stack%> currently only supported on GNU/Linux");
to:
error ("%<-fsplit-stack%> currently only supported on GLIBC-based systems");

Thanks!

--- a/src/gcc/config/gnu.h	2022-02-06 11:59:41.0 +0100
+++ b/src/gcc/config/gnu.h	2022-02-06 12:00:19.0 +0100
@@ -19,6 +19,9 @@
 along with GCC.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#define OPTION_GLIBC_P(opts)	(DEFAULT_LIBC == LIBC_GLIBC)
+#define OPTION_GLIBC		OPTION_GLIBC_P (_options)
+
 #undef GNU_USER_TARGET_OS_CPP_BUILTINS
 #define GNU_USER_TARGET_OS_CPP_BUILTINS()		\
 do {	\
--- End Message ---


Re: Ping: [PATCH resend] Make -Wuse-after-free=3 the default one in -Wall

2023-03-15 Thread Alejandro Colomar via Gcc-patches
Hi Richard,

On 3/15/23 15:52, Richard Biener wrote:
> On Wed, Mar 15, 2023 at 3:30 PM Alejandro Colomar via Gcc-patches
>  wrote:
>>
>> Ping
> 
> -Wuse-after-free=3 was explicitly added to cover cases with a high
> false-positive rate.  If you want to
> make that the default then instead merge the equality compare case
> back to the =2 case.
> 
> But as I said elsewhere I think that -Wuse-after-free is very much too
> trigger happy, especially
> with value-uses (not accessing released memory but inspecting the old
> pointer value).  Please consider
> looking at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104075 and
> review the false positives
> reported.
> 
> Also see my very recent patches from today trying to limit
> -Wuse-after-free by not diagnosing
> from late IL.

Hmmm, thanks, didn't know about those.  Please ignore my patch.

Cheers,

Alex


-- 

GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5


OpenPGP_signature
Description: OpenPGP digital signature


Re: Ping: [PATCH resend] Make -Wuse-after-free=3 the default one in -Wall

2023-03-15 Thread Richard Biener via Gcc-patches
On Wed, Mar 15, 2023 at 3:30 PM Alejandro Colomar via Gcc-patches
 wrote:
>
> Ping

-Wuse-after-free=3 was explicitly added to cover cases with a high
false-positive rate.  If you want to
make that the default then instead merge the equality compare case
back to the =2 case.

But as I said elsewhere I think that -Wuse-after-free is very much too
trigger happy, especially
with value-uses (not accessing released memory but inspecting the old
pointer value).  Please consider
looking at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104075 and
review the false positives
reported.

Also see my very recent patches from today trying to limit
-Wuse-after-free by not diagnosing
from late IL.

Richard.

> On 2/18/23 00:05, Alejandro Colomar wrote:
> > Link: 
> > 
> > Link: 
> > 
> > Cc: Andreas Schwab 
> > Cc: David Malcolm 
> > Cc: Florian Weimer 
> > Cc: Iker Pedrosa 
> > Cc: Jens Gustedt 
> > Cc: Jonathan Wakely 
> > Cc: Mark Wielaard 
> > Cc: Martin Uecker 
> > Cc: Michael Kerrisk 
> > Cc: Paul Eggert 
> > Cc: Sam James 
> > Cc: Siddhesh Poyarekar 
> > Cc: Yann Droneaud 
> > Signed-off-by: Alejandro Colomar 
> > ---
> >
> > This is a resend of the same patch previously sent to gcc@.
> >
> >  gcc/c-family/c.opt  | 4 ++--
> >  gcc/doc/invoke.texi | 2 +-
> >  2 files changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
> > index c0fea56a8f5..1a3fc2c5d74 100644
> > --- a/gcc/c-family/c.opt
> > +++ b/gcc/c-family/c.opt
> > @@ -1411,11 +1411,11 @@ C ObjC C++ ObjC++ Joined RejectNegative UInteger 
> > Var(warn_unused_const_variable)
> >  Warn when a const variable is unused.
> >
> >  ; Defining this option here in addition to common.opt is necessary
> > -; in order for the default -Wall setting of -Wuse-after-free=2 to take
> > +; in order for the default -Wall setting of -Wuse-after-free=3 to take
> >  ; effect.
> >
> >  Wuse-after-free=
> > -LangEnabledBy(C ObjC C++ LTO ObjC++, Wall,2,0)
> > +LangEnabledBy(C ObjC C++ LTO ObjC++, Wall,3,0)
> >  ; in common.opt
> >
> >  Wvariadic-macros
> > diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> > index 7b308cd3c31..d910052ce0c 100644
> > --- a/gcc/doc/invoke.texi
> > +++ b/gcc/doc/invoke.texi
> > @@ -4720,7 +4720,7 @@ instead of pointers.  This approach obviates needing 
> > to adjust the stored
> >  pointers after reallocation.
> >  @end table
> >
> > -@option{-Wuse-after-free=2} is included in @option{-Wall}.
> > +@option{-Wuse-after-free=3} is included in @option{-Wall}.
> >
> >  @item -Wuseless-cast @r{(C++ and Objective-C++ only)}
> >  @opindex Wuseless-cast
>
> --
> 
> GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5


Re: [PATCH 2/2] tree-optimization/109123 - run -Wuse-afer-free only early

2023-03-15 Thread Jakub Jelinek via Gcc-patches
On Wed, Mar 15, 2023 at 02:39:43PM +, Richard Biener via Gcc-patches wrote:
> I've tested and most of the -Wuse-after-free testcases work with -Og
> before and after the change (unfortunately adding -Og via RUNTESTFLAGS
> doesn't work since explicit -O2 in the testcases overrides that).
> 
> We also do not have much test coverage here and I'm hesitant to change
> this now.
> 
> That said, with the adjusted first patch and the split out fix for
> g++.dg/warn/Wuse-after-free3.C the following is what I propose now.
> There's extra adjustments in gcc.dg/Wuse-after-free-2.c as we now
> mention the pointer that is used.
> 
> I do think not running these kind of diagnostics very late, at least
> a diagnostic like this that's prone to false positives due to
> code motion.  But I'm also happy to leave the state of affairs as-is
> for GCC 13, but I don't promise to be able to pick up things during
> next stage1 again.
> 
> Re-re-re-bootstrap & regtest running on x86_64-unknown-linux-gnu.
> 
> Unless I get clear opinions I'm going to throw some dice whether
> to apply 1/2 and will "defer" this one.

Let's go with both patches then, if somebody files false negative issues
for this warning later on, we can amend it further later.

Jakub



Re: [PATCH, OpenACC, v3] Non-contiguous array support for OpenACC data clauses

2023-03-15 Thread Thomas Schwinge
Hi Chung-Lin!

On 2019-11-26T22:49:21+0800, Chung-Lin Tang  wrote:
> this is a reorg of the last non-contiguous arrays patch.

(Sorry, this is still not the master branch integration email...)


I noticed the following while working on something else:

> --- libgomp/oacc-parallel.c   (revision 278656)
> +++ libgomp/oacc-parallel.c   (working copy)

> @@ -311,8 +488,10 @@ GOACC_parallel_keyed (int flags_m, void (*fn) (voi
>
>goacc_aq aq = get_goacc_asyncqueue (async);
>
> -  tgt = gomp_map_vars_async (acc_dev, aq, mapnum, hostaddrs, NULL, sizes, 
> kinds,
> -  true, GOMP_MAP_VARS_OPENACC);
> +  tgt = gomp_map_vars_openacc (acc_dev, aq, mapnum, hostaddrs, sizes, kinds,
> +nca_info);
> +  free (nca_info);

Given OpenACC 'async', don't we have to defer 'free' of the
non-contiguous array support data structure here?  But I'm not completely
sure -- can we rule out that any asynchronous copying of any data of
'nca_info' is still going on after returning from 'gomp_map_vars'?

> @@ -488,9 +666,19 @@ GOACC_data_start (int flags_m, size_t mapnum,

> -  tgt = gomp_map_vars (acc_dev, mapnum, hostaddrs, NULL, sizes, kinds, true,
> -GOMP_MAP_VARS_OPENACC);
> +  tgt = gomp_map_vars_openacc (acc_dev, NULL, mapnum, hostaddrs, sizes, 
> kinds,
> +nca_info);
> +  free (nca_info);

Here, it's not relevant, as there is no 'async' support (yet) for 'data'
constructs.

> --- libgomp/target.c  (revision 278656)
> +++ libgomp/target.c  (working copy)

> @@ -1044,6 +1114,98 @@ gomp_map_vars_internal (struct gomp_device_descr *

> +   void *ptrblock = goacc_noncontig_array_create_ptrblock
> + (nca, target_ptrblock);
> +   gomp_copy_host2dev (devicep, aq, target_ptrblock, ptrblock,
> +   nca->ptrblock_size, cbufp);
> +   free (ptrblock);

Here again, however, don't we have to defer the 'free'?

Please verify the attached
"Given OpenACC 'async', defer 'free' of non-contiguous array support data 
structures",
in particular the 'libgomp/oacc-parallel.c:GOACC_parallel_keyed' case.


Grüße
 Thomas


-
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
>From 998f1156a51010490c2e918defb4517706916c92 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Wed, 15 Mar 2023 13:34:02 +0100
Subject: [PATCH] Given OpenACC 'async', defer 'free' of non-contiguous array
 support data structures

Fix-up for og12 commit 15d0f61a7fecdc8fd12857c40879ea3730f6d99f
"Merge non-contiguous array support patches".

	libgomp/
	* oacc-parallel.c (GOACC_parallel_keyed): Given OpenACC 'async',
	defer 'free' of non-contiguous array support data structures.
	* target.c (gomp_map_vars_internal): Likewise.
---
 libgomp/oacc-parallel.c | 5 -
 libgomp/target.c| 6 +-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/libgomp/oacc-parallel.c b/libgomp/oacc-parallel.c
index 9cd99b4a0b4..136702d6e61 100644
--- a/libgomp/oacc-parallel.c
+++ b/libgomp/oacc-parallel.c
@@ -470,7 +470,10 @@ GOACC_parallel_keyed (int flags_m, void (*fn) (void *),
 = goacc_map_vars (acc_dev, aq, mapnum, hostaddrs, NULL, sizes, kinds,
 		  nca_info, true, GOMP_MAP_VARS_TARGET);
 
-  free (nca_info);
+  if (aq == NULL)
+free (nca_info);
+  else
+acc_dev->openacc.async.queue_callback_func (aq, free, nca_info);
 
   if (profiling_p)
 {
diff --git a/libgomp/target.c b/libgomp/target.c
index 96ece0b31fd..aaa597f6610 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -1938,7 +1938,11 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep,
 		(nca, target_ptrblock);
 		  gomp_copy_host2dev (devicep, aq, target_ptrblock, ptrblock,
   nca->ptrblock_size, false, cbufp);
-		  free (ptrblock);
+		  if (aq)
+		/* Free once the transfer has completed.  */
+		devicep->openacc.async.queue_callback_func (aq, free, ptrblock);
+		  else
+		free (ptrblock);
 		}
 	}
 	}
-- 
2.25.1



Re: [V4][PATCH 2/2] Update documentation to clarify a GCC extension

2023-03-15 Thread Qing Zhao via Gcc-patches
Hi, Sandra,

Thanks a lot for your review and comment.

Yes, the issue you raised in below was  a really tough one that I didn’t feel 
very comfortable to handle it well…

This documentation change is mainly to fix: PR77650 
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77650).

The real user case for it was the old glibc headers. (As Joshph mentioned in 
the comment #1:
 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77650#c1)

And from my understanding, the code in glibc has already been fixed. 
https://gcc.gnu.org/pipermail/gcc-patches/2023-February/611220.html

But I am not sure in addition to Glibc, whether there are other use cases out 
there currently.

That’s the reason we cannot simply reject this case as an error at this moment. 
And the new warning -Wgnu-variable-sized-type-not-at-end
Is added to catch such case in user case to encourage user to update them. And 
then later we can completely delete this case from GCC support.

Right now, GCC’s implementation cannot handle such case consistently. So, how 
to document this case is really hard.

> On Mar 14, 2023, at 11:26 PM, Sandra Loosemore  
> wrote:
> 
> On 2/24/23 11:35, Qing Zhao via Gcc-patches wrote:
> 
>> gcc/c-family/ChangeLog:
>>  * c.opt: New option -Wgnu-variable-sized-type-not-at-end.
>> gcc/c/ChangeLog:
>>  * c-decl.cc (finish_struct): Issue warnings for new option.
>> gcc/ChangeLog:
>>  * doc/extend.texi: Document GCC extension on a structure containing
>>  a flexible array member to be a member of another structure.
>> gcc/testsuite/ChangeLog:
>>  * gcc.dg/variable-sized-type-flex-array.c: New test.
> 
> I'm only a documentation (and nios2) maintainer so I cannot approve adding a 
> new option or warning.  I was going to review the documentation parts, at 
> least, but I think this proposal is technically flawed because it is trying 
> to document something that is undefined behavior in ways that it doesn't 
> actually behave on all targets.

So, should we mention it in the documentation at all?
Of mention it but specify the possible undefined behavior, the potential risk 
to use this case, and then warn the user to get rid of this usage with the new 
warning?

> 
>> diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
>> index c1122916255..e278148c332 100644
>> --- a/gcc/doc/extend.texi
>> +++ b/gcc/doc/extend.texi
>> @@ -1748,7 +1748,53 @@ Flexible array members may only appear as the last 
>> member of a
>>  A structure containing a flexible array member, or a union containing
>>  such a structure (possibly recursively), may not be a member of a
>>  structure or an element of an array.  (However, these uses are
>> -permitted by GCC as extensions.)
>> +permitted by GCC as extensions, see details below.)
>> +@end itemize
>> +
>> +GCC extension accepts a structure containing an ISO C99 @dfn{flexible array
>> +member}, or a union containing such a structure (possibly recursively)
>> +to be a member of a structure.
>> +
>> +There are two situations:
>> +
>> +@itemize @bullet
>> +@item
>> +The structure with a C99 flexible array member is the last field of another
>> +structure, for example:
>> +
>> +@smallexample
>> +struct flex  @{ int length; char data[]; @};
>> +union union_flex @{ int others; struct flex f; @};
>> +
>> +struct out_flex_struct @{ int m; struct flex flex_data; @};
>> +struct out_flex_union @{ int n; union union_flex flex_data; @};
>> +@end smallexample
>> +
>> +In the above, both @code{out_flex_struct.flex_data.data[]} and
>> +@code{out_flex_union.flex_data.f.data[]} are considered as flexible arrays 
>> too.
>> +
>> +
>> +@item
>> +The structure with a C99 flexible array member is the middle field of 
>> another
>> +structure, for example:
>> +
>> +@smallexample
>> +struct flex  @{ int length; char data[]; @};
>> +
>> +struct mid_flex @{ int m; struct flex flex_data; int n; @};
>> +@end smallexample
>> +
>> +In the above, @code{mid_flex.flex_data.data[]} is allowed to be extended
>> +flexibly to the padding.  E.g, up to 4 elements.
> 
> I think this paragraph is incorrect; how GCC lays out this structure depends 
> on the target and ABI.  Looking at output from a GCC 12 nios2-elf build I 
> have handy, I see it is in fact laying out mid_flex so that member n is at 
> the same address at offset 8 as flex_data.data[0], which is not useful at all.

I think that this behavior you mentioned is consistent with what’s the 
expected. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77650#c5. 
But not sure whether we should document it or not?

>> +However, relying on space in struct padding is a bad programming practice,
>> +compilers do not handle such extension consistently, Any code relying on
>> +this behavior should be modified to ensure that flexible array members
>> +only end up at the ends of structures.
>> +
>> +Please use warning option  @option{-Wgnu-variable-sized-type-not-at-end} to
>> +identify all such cases in the source code and modify them.  This extension
>> +will be deprecated 

Re: [PATCH 2/2] tree-optimization/109123 - run -Wuse-afer-free only early

2023-03-15 Thread Richard Biener via Gcc-patches
On Wed, 15 Mar 2023, Richard Biener wrote:

> On Wed, 15 Mar 2023, Jakub Jelinek wrote:
> 
> > On Wed, Mar 15, 2023 at 10:49:19AM +, Richard Biener via Gcc-patches 
> > wrote:
> > > The following switches the -Wuse-after-free diagnostics from emitted
> > > during the late access warning passes to the early access warning
> > > passes to make sure we run before passes performing code motion run
> > > which are the source of a lot of false positives on use-after-free
> > > not involving memory operations.
> > > 
> > > The patch also fixes issues in c-c++-common/Wuse-after-free-6.c and
> > > g++.dg/warn/Wuse-after-free3.C.
> > > 
> > > Bootstrapped and tested on x86_64-unknown-linux-gnu (without 1/2
> > > sofar, but its testcase XFAILed).
> > > 
> > > OK?
> > > 
> > > Thanks,
> > > Richard.
> > > 
> > >   PR tree-optimization/109123
> > >   * gimple-ssa-warn-access.cc (pass_waccess::warn_invalid_pointer):
> > >   Do not emit -Wuse-after-free late.
> > >   (pass_waccess::check_call): Always check call pointer uses.
> > > 
> > >   * gcc.dg/Wuse-after-free-pr109123.c: New testcase.
> > >   * c-c++-common/Wuse-after-free-6.c: Un-XFAIL case.
> > >   * g++.dg/warn/Wuse-after-free3.C: Remove expected duplicate
> > >   diagnostic.
> > 
> > I guess this is this is related to the never ending debate of what to
> > do with the middle end late warnings, whether we should kill them
> > altogether, move into analyzer framework and/or run early but perform
> > IPA analysis for them.
> 
> Yes.  And for -Wuse-after-free also whether value-uses are considered
> or not, but changing that has a much bigger testsuite fallout.
> 
> > Doing the diagnostics in the early waccess pass is certainly fine
> > no matter what, it will emit there more accurate diagnostics.
> > A big question is whether to avoid diagnosing it late as well (other option
> > is just make sure we don't diagnose same statements twice, once in early
> > waccess and once in late waccess, which can be solved with warning
> > suppressions (unless it is already properly suppressed)), especially for
> > GCC 13.
> > I see we have two copies of early waccess (so, we need to get the
> > suppression right even if the warning is just moved to early waccess),
> > one is very shortly after building ssa, so before early inlining,
> > then there is another early one for -O+ non-Og shortly after IPA,
> > and the late one is immediately before expansion.
> 
> Yep, I think the suppression should already work.
> 
> > So, the question is if the ccp after IPA is sufficient to uncover
> > the most of the use after free issues we want to diagnose, if yes,
> > then perhaps your patch is ok but we need to decide what to do about
> > -Og, whether we shouldn't add
> >   NEXT_PASS (pass_warn_access, /*early=*/true);
> > into -Og pass queue after 
> >   NEXT_PASS (pass_object_sizes);
> > or so.
> 
> That would be possible for sure.  But then there's not much
> done between the late early and the late pass so the late pass
> could run in both modes (but I don't feel like massaging that too much
> at this point).
> 
> There's also -O0 where the late pass catches all always-inlined
> cases.
> 
> > I think even the pre-IPA optimizations can do some harm for use after free
> > false positives, but hopefully not as much as the post IPA optimizations.
> 
> We do some very limited jump-threading but I don't think there's much
> code-motion going on.

I've tested and most of the -Wuse-after-free testcases work with -Og
before and after the change (unfortunately adding -Og via RUNTESTFLAGS
doesn't work since explicit -O2 in the testcases overrides that).

We also do not have much test coverage here and I'm hesitant to change
this now.

That said, with the adjusted first patch and the split out fix for
g++.dg/warn/Wuse-after-free3.C the following is what I propose now.
There's extra adjustments in gcc.dg/Wuse-after-free-2.c as we now
mention the pointer that is used.

I do think not running these kind of diagnostics very late, at least
a diagnostic like this that's prone to false positives due to
code motion.  But I'm also happy to leave the state of affairs as-is
for GCC 13, but I don't promise to be able to pick up things during
next stage1 again.

Re-re-re-bootstrap & regtest running on x86_64-unknown-linux-gnu.

Unless I get clear opinions I'm going to throw some dice whether
to apply 1/2 and will "defer" this one.

Thanks,
Richard.



>From c1ac6d319c76fea434080c0f5c2b779e5cea0446 Mon Sep 17 00:00:00 2001
From: Richard Biener 
Date: Wed, 15 Mar 2023 09:12:33 +0100
Subject: [PATCH] tree-optimization/109123 - run -Wuse-afer-free only early
To: gcc-patches@gcc.gnu.org

The following switches the -Wuse-after-free diagnostics from emitted
during the late access warning passes to the early access warning
passes to make sure we run before passes performing code motion run
which are the source of a lot of false positives on use-after-free
not involving memory operations.

The patch also 

[PATCH v2] c++: ICE with constexpr lambda [PR107280]

2023-03-15 Thread Marek Polacek via Gcc-patches
On Fri, Mar 10, 2023 at 01:47:46PM -0500, Jason Merrill wrote:
> On 3/10/23 11:17, Marek Polacek wrote:
> > We crash here since r10-3661, the store_init_value hunk in particular.
> > Before, we called cp_fully_fold_init, so e.g.
> > 
> >{.str=VIEW_CONVERT_EXPR("")}
> > 
> > was folded into
> > 
> >{.str=""}
> > 
> > but now we don't fold and keep the VCE around, and it causes trouble in
> > cxx_eval_store_expression: in the !refs->is_empty () loop we descend on
> > .str's initializer but since it's wrapped in a VCE, we skip the STRING_CST
> > check and then crash on the CONSTRUCTOR_NO_CLEARING.
> > 
> > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/12?
> > 
> > PR c++/107280
> > 
> > gcc/cp/ChangeLog:
> > 
> > * constexpr.cc (cxx_eval_store_expression): Strip location wrappers.
> > 
> > gcc/testsuite/ChangeLog:
> > 
> > * g++.dg/cpp1z/constexpr-lambda28.C: New test.
> > ---
> >   gcc/cp/constexpr.cc |  3 ++-
> >   gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C | 15 +++
> >   2 files changed, 17 insertions(+), 1 deletion(-)
> >   create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C
> > 
> > diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
> > index 8683c00596a..abf6ee560c5 100644
> > --- a/gcc/cp/constexpr.cc
> > +++ b/gcc/cp/constexpr.cc
> > @@ -6033,7 +6033,8 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, 
> > tree t,
> >   *valp = build_constructor (type, NULL);
> >   CONSTRUCTOR_NO_CLEARING (*valp) = no_zero_init;
> > }
> > -  else if (TREE_CODE (*valp) == STRING_CST)
> > +  else if (STRIP_ANY_LOCATION_WRAPPER (*valp),
> > +  TREE_CODE (*valp) == STRING_CST)
> 
> Seems like this is stripping the location wrapper when we try to modify the
> string; I think we want to strip it earlier, when we first initialize the
> array member.

Hmm, I suppose we don't want to do the stripping too early.  I could
have put it in get_nsdmi, for instance, but maybe here is good as well?

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

-- >8 --
We crash here since r10-3661, the store_init_value hunk in particular.
Before, we called cp_fully_fold_init, so e.g.

  {.str=VIEW_CONVERT_EXPR("")}

was folded into

  {.str=""}

but now we don't fold and keep the VCE around, and it causes trouble in
cxx_eval_store_expression: in the !refs->is_empty () loop we descend on
.str's initializer but since it's wrapped in a VCE, we skip the STRING_CST
check and then crash on the CONSTRUCTOR_NO_CLEARING.

PR c++/107280

gcc/cp/ChangeLog:

* typeck2.cc (process_init_constructor_record): Strip location wrappers.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/constexpr-lambda28.C: New test.
---
 gcc/cp/typeck2.cc   |  1 +
 gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C | 15 +++
 2 files changed, 16 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C

diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc
index c56b69164e2..d0984910ce4 100644
--- a/gcc/cp/typeck2.cc
+++ b/gcc/cp/typeck2.cc
@@ -1889,6 +1889,7 @@ process_init_constructor_record (tree type, tree init, 
int nested, int flags,
  CONSTRUCTOR_PLACEHOLDER_BOUNDARY (init) = 1;
  CONSTRUCTOR_PLACEHOLDER_BOUNDARY (next) = 0;
}
+  STRIP_ANY_LOCATION_WRAPPER (next);
   CONSTRUCTOR_APPEND_ELT (v, field, next);
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C 
b/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C
new file mode 100644
index 000..aafbfddd8b9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C
@@ -0,0 +1,15 @@
+// PR c++/107280
+// { dg-do compile { target c++17 } }
+
+struct string {
+  char str[8] = "";
+};
+template  constexpr void
+test ()
+{
+  string str{};
+  auto append = [&](const char *s) { *str.str = *s; };
+  append("");
+}
+
+static_assert ((test(), true), "");

base-commit: 40c1352c5a4530350012d6a922435cf491663daa
-- 
2.39.2



Ping: [PATCH resend] Make -Wuse-after-free=3 the default one in -Wall

2023-03-15 Thread Alejandro Colomar via Gcc-patches
Ping

On 2/18/23 00:05, Alejandro Colomar wrote:
> Link: 
> 
> Link: 
> Cc: Andreas Schwab 
> Cc: David Malcolm 
> Cc: Florian Weimer 
> Cc: Iker Pedrosa 
> Cc: Jens Gustedt 
> Cc: Jonathan Wakely 
> Cc: Mark Wielaard 
> Cc: Martin Uecker 
> Cc: Michael Kerrisk 
> Cc: Paul Eggert 
> Cc: Sam James 
> Cc: Siddhesh Poyarekar 
> Cc: Yann Droneaud 
> Signed-off-by: Alejandro Colomar 
> ---
> 
> This is a resend of the same patch previously sent to gcc@.
> 
>  gcc/c-family/c.opt  | 4 ++--
>  gcc/doc/invoke.texi | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
> index c0fea56a8f5..1a3fc2c5d74 100644
> --- a/gcc/c-family/c.opt
> +++ b/gcc/c-family/c.opt
> @@ -1411,11 +1411,11 @@ C ObjC C++ ObjC++ Joined RejectNegative UInteger 
> Var(warn_unused_const_variable)
>  Warn when a const variable is unused.
>  
>  ; Defining this option here in addition to common.opt is necessary
> -; in order for the default -Wall setting of -Wuse-after-free=2 to take
> +; in order for the default -Wall setting of -Wuse-after-free=3 to take
>  ; effect.
>  
>  Wuse-after-free=
> -LangEnabledBy(C ObjC C++ LTO ObjC++, Wall,2,0)
> +LangEnabledBy(C ObjC C++ LTO ObjC++, Wall,3,0)
>  ; in common.opt
>  
>  Wvariadic-macros
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index 7b308cd3c31..d910052ce0c 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -4720,7 +4720,7 @@ instead of pointers.  This approach obviates needing to 
> adjust the stored
>  pointers after reallocation.
>  @end table
>  
> -@option{-Wuse-after-free=2} is included in @option{-Wall}.
> +@option{-Wuse-after-free=3} is included in @option{-Wall}.
>  
>  @item -Wuseless-cast @r{(C++ and Objective-C++ only)}
>  @opindex Wuseless-cast

-- 

GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5


OpenPGP_signature
Description: OpenPGP digital signature


Re: [Patch] OpenMP: Add omp_in_explicit_task to omp_runtime_api_call

2023-03-15 Thread Jakub Jelinek via Gcc-patches
On Wed, Mar 15, 2023 at 03:24:04PM +0100, Tobias Burnus wrote:
> When adding a new OpenMP routine, also omp_runtime_api_call needs
> to be adapted - to get proper error like:
> 
> error: OpenMP runtime API call ‘omp_in_explicit_task’ in a region with 
> ‘order(concurrent)’ clause
> 
> OK for mainline?

Yes, thanks.

> OpenMP: Add omp_in_explicit_task to omp_runtime_api_call
> 
> gcc/
>   * omp-low.cc (omp_runtime_api_call): Add omp_runtime_api_call.
> 
> diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
> index 9757592c635..1818132830f 100644
> --- a/gcc/omp-low.cc
> +++ b/gcc/omp-low.cc
> @@ -4082,6 +4082,7 @@ omp_runtime_api_call (const_tree fndecl)
>"get_thread_num",
>"get_wtick",
>"get_wtime",
> +  "in_explicit_task",
>"in_final",
>"in_parallel",
>"init_lock",


Jakub



[Patch] OpenMP: Add omp_in_explicit_task to omp_runtime_api_call

2023-03-15 Thread Tobias Burnus

When adding a new OpenMP routine, also omp_runtime_api_call needs
to be adapted - to get proper error like:

error: OpenMP runtime API call ‘omp_in_explicit_task’ in a region with 
‘order(concurrent)’ clause

OK for mainline?

Tobias

PS: This routine was added in commit 
r13-3258-g0ec4e93fb9fa5e9d2424683c5fab1310c8ae2f76

PPS: I have not fully checked but I think it should be up to date; at least all
other recent additions include updates to that omp-low.cc function and at some 
point
I had checked it for completeness.
-
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
OpenMP: Add omp_in_explicit_task to omp_runtime_api_call

gcc/
	* omp-low.cc (omp_runtime_api_call): Add omp_runtime_api_call.

diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index 9757592c635..1818132830f 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -4082,6 +4082,7 @@ omp_runtime_api_call (const_tree fndecl)
   "get_thread_num",
   "get_wtick",
   "get_wtime",
+  "in_explicit_task",
   "in_final",
   "in_parallel",
   "init_lock",


[PATCH] Avoid duplicate diagnostic in g++.dg/warn/Wuse-after-free3.C

2023-03-15 Thread Richard Biener via Gcc-patches
We are diagnosing

  operator delete (this_3(D));
  A::f (this_3(D));
  *this_3(D) ={v} CLOBBER;

where the CLOBBER appears at the end of the DTOR for C++11 and later.
The following avoids this by simply never diagnosing clobbers as
use-after-free.

Bootstrap and regtest running on x86_64-unknown-linux-gnu, I'm
going to push this if it succeeds.

Richard.

* gimple-ssa-warn-access.cc (pass_waccess::check_pointer_uses):
Do not diagnose clobbers.

* g++.dg/warn/Wuse-after-free3.C: Remove expected duplicate
diagnostic.
---
 gcc/gimple-ssa-warn-access.cc| 4 
 gcc/testsuite/g++.dg/warn/Wuse-after-free3.C | 3 +--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index ed5499ca7fb..88d44690ade 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -4189,6 +4189,10 @@ pass_waccess::check_pointer_uses (gimple *stmt, tree ptr,
  if (use_stmt == stmt || is_gimple_debug (use_stmt))
continue;
 
+ /* A clobber isn't a use.  */
+ if (gimple_clobber_p (use_stmt))
+   continue;
+
  if (realloc_lhs)
{
  /* Check to see if USE_STMT is a mismatched deallocation
diff --git a/gcc/testsuite/g++.dg/warn/Wuse-after-free3.C 
b/gcc/testsuite/g++.dg/warn/Wuse-after-free3.C
index 1862ac8b09d..e5b157865bf 100644
--- a/gcc/testsuite/g++.dg/warn/Wuse-after-free3.C
+++ b/gcc/testsuite/g++.dg/warn/Wuse-after-free3.C
@@ -1,7 +1,6 @@
 // PR target/104213
 // { dg-do compile }
 // { dg-options "-Wuse-after-free" }
-// FIXME: We should not output the warning twice.
 
 struct A
 {
@@ -13,4 +12,4 @@ A::~A ()
 {
   operator delete (this);
   f (); // { dg-warning "used after" }
-} // { dg-warning "used after" }
+}
-- 
2.35.3


Re: [PATCH] RISC-V: Fix reg order of RVV registers.

2023-03-15 Thread Kito Cheng via Gcc-patches
Hi Jeff:

We promised only to commit intrinsic implication and bug fix this
moment, so yes, those optimization and non-bug fix pattern turning
include this will all defer to gcc-14.

On Wed, Mar 15, 2023 at 2:02 AM Jeff Law via Gcc-patches
 wrote:
>
>
>
> On 3/13/23 02:19, juzhe.zh...@rivai.ai wrote:
> > From: Ju-Zhe Zhong 
> >
> > Co-authored-by: kito-cheng 
> > Co-authored-by: kito-cheng 
> >
> > Consider this case:
> > void f19 (void *base,void *base2,void *out,size_t vl, int n)
> > {
> >  vuint64m8_t bindex = __riscv_vle64_v_u64m8 (base + 100, vl);
> >  for (int i = 0; i < n; i++){
> >vbool8_t m = __riscv_vlm_v_b8 (base + i, vl);
> >vuint64m8_t v = __riscv_vluxei64_v_u64m8_m(m,base,bindex,vl);
> >vuint64m8_t v2 = __riscv_vle64_v_u64m8_tu (v, base2 + i, vl);
> >vint8m1_t v3 = __riscv_vluxei64_v_i8m1_m(m,base,v,vl);
> >vint8m1_t v4 = __riscv_vluxei64_v_i8m1_m(m,base,v2,vl);
> >__riscv_vse8_v_i8m1 (out + 100*i,v3,vl);
> >__riscv_vse8_v_i8m1 (out + 222*i,v4,vl);
> >  }
> > }
> >
> > Due to the current unreasonable reg order, this case produce unnecessary
> > register spillings.
> >
> > Fix the order can help for RA.
> >
> > Signed-off-by: Ju-Zhe Zhong 
> > Co-authored-by: kito-cheng 
> > Co-authored-by: kito-cheng 
> >
> > gcc/ChangeLog:
> >
> >  * config/riscv/riscv.h (enum reg_class): Fix reg order.
> >
> > gcc/testsuite/ChangeLog:
> >
> >  * gcc.target/riscv/rvv/base/spill-1.c: Adapt test.
> >  * gcc.target/riscv/rvv/base/spill-2.c: Ditto.
> >  * gcc.target/riscv/rvv/base/spill-3.c: Ditto.
> >  * gcc.target/riscv/rvv/base/spill-4.c: Ditto.
> >  * gcc.target/riscv/rvv/base/spill-5.c: Ditto.
> >  * gcc.target/riscv/rvv/base/spill-6.c: Ditto.
> >  * gcc.target/riscv/rvv/base/spill-7.c: Ditto.
> Are you OK with deferring this to gcc-14?
>
> jeff


Re: [PATCH 1/2] Avoid random stmt order result in pass_waccess::use_after_inval_p

2023-03-15 Thread Jakub Jelinek via Gcc-patches
On Wed, Mar 15, 2023 at 01:07:56PM +, Richard Biener wrote:
> The following patch was bootstrapped and tested on 
> x86_64-unknown-linux-gnu.  It now doesn't regress anything in the
> testsuite but on its own it has the chance to (by luck maybe
> avoided previosuly due to the PHI compare bug) introduce extra
> false-positives.  Fixing only the comparison causes false negatives
> in the testsuite - as said we rely on processing PHIs before the
> invalidation stmt.
> 
> Together with the second patch I'm confident the overall experience
> will be better than what we have now.
> 
> OK?

LGTM.

Jakub



Re: [PATCH 1/2] Avoid random stmt order result in pass_waccess::use_after_inval_p

2023-03-15 Thread Richard Biener via Gcc-patches
On Wed, 15 Mar 2023, Richard Biener wrote:

> On Wed, 15 Mar 2023, Jakub Jelinek wrote:
> 
> > On Wed, Mar 15, 2023 at 10:48:32AM +, Richard Biener wrote:
> > > use_after_inval_p uses stmt UIDs to speed up repeated dominance
> > > checks within a basic-block but it fails to assign UIDs to PHIs
> > > which means compares with PHIs in the same block get a random
> > > result.
> > > 
> > > The following factors renumber_gimple_stmt_uids to expose a new
> > > renumber_gimple_stmt_uids_in_block we can share.
> > > 
> > > This XFAILs the conditional loop case in gcc.dg/Wuse-after-free-2.c
> > > 
> > > Bootstrap and regtest running on x86_64-unknown-linux-gnu.  This
> > > makes 2/2 a net positive on the testsuite (the early waccess
> > > would not run into this bug)
> > > 
> > > OK if testing succeeds?  (we could also special-case PHIs somehow
> > > and assert we never get to compare two PHIs here)
> > > 
> > >   * tree-dfa.h (renumber_gimple_stmt_uids_in_block): New.
> > >   * tree-dfa.cc (renumber_gimple_stmt_uids_in_block): Split
> > >   out from ...
> > >   (renumber_gimple_stmt_uids): ... here and
> > >   (renumber_gimple_stmt_uids_in_blocks): ... here.
> > >   * gimple-ssa-warn-access.cc (pass_waccess::use_after_inval_p):
> > >   Use renumber_gimple_stmt_uids_in_block to also assign UIDs
> > >   to PHIs.
> > > 
> > >   * gcc.dg/Wuse-after-free-2.c: XFAIL conditional loop case.
> > 
> > LGTM.
> 
> Turns out we rely very much on processing PHIs for following pointers
> (we also happily look at earlier pointer adjustments).  So while the
> comparison done to PHIs in the above function is bogus and we should
> possibly fix it it regresses things unless we process PHIs
> unconditionally.
> 
> I'm going to test an adjusted patch.

The following patch was bootstrapped and tested on 
x86_64-unknown-linux-gnu.  It now doesn't regress anything in the
testsuite but on its own it has the chance to (by luck maybe
avoided previosuly due to the PHI compare bug) introduce extra
false-positives.  Fixing only the comparison causes false negatives
in the testsuite - as said we rely on processing PHIs before the
invalidation stmt.

Together with the second patch I'm confident the overall experience
will be better than what we have now.

OK?

Thanks,
Richard.



>From 4077971e24c6be2ee2b3266701f6ca14a6ce3d4b Mon Sep 17 00:00:00 2001
From: Richard Biener 
Date: Wed, 15 Mar 2023 11:41:20 +0100
Subject: [PATCH] Avoid random stmt order result in
 pass_waccess::use_after_inval_p
To: gcc-patches@gcc.gnu.org

use_after_inval_p uses stmt UIDs to speed up repeated dominance
checks within a basic-block but it fails to assign UIDs to PHIs
which means compares with PHIs in the same block get a random
result.

The following factors renumber_gimple_stmt_uids to expose a new
renumber_gimple_stmt_uids_in_block we can share.

But since we rely on processing even earlier PHIs to follow
pointer adjustments (we look at those even if earlier) the patch
also moves PHI handling out of the use_after_inval_p guard.
This then also fixes PR109141.

PR tree-optimizaton/109141
* tree-dfa.h (renumber_gimple_stmt_uids_in_block): New.
* tree-dfa.cc (renumber_gimple_stmt_uids_in_block): Split
out from ...
(renumber_gimple_stmt_uids): ... here and
(renumber_gimple_stmt_uids_in_blocks): ... here.
* gimple-ssa-warn-access.cc (pass_waccess::use_after_inval_p):
Use renumber_gimple_stmt_uids_in_block to also assign UIDs
to PHIs.
(pass_waccess::check_pointer_uses): Process all PHIs.
---
 gcc/gimple-ssa-warn-access.cc | 37 +++
 gcc/tree-dfa.cc   | 48 +++
 gcc/tree-dfa.h|  1 +
 3 files changed, 37 insertions(+), 49 deletions(-)

diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index 8b1c1cc019e..daaa22882fa 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -3862,13 +3862,7 @@ pass_waccess::use_after_inval_p (gimple *inval_stmt, 
gimple *use_stmt,
to consecutive statements in it.  Use the ids to determine which
precedes which.  This avoids the linear traversal on subsequent
visits to the same block.  */
-for (auto si = gsi_start_bb (inval_bb); !gsi_end_p (si);
-gsi_next_nondebug ())
-  {
-   gimple *stmt = gsi_stmt (si);
-   unsigned uid = inc_gimple_stmt_max_uid (m_func);
-   gimple_set_uid (stmt, uid);
-  }
+renumber_gimple_stmt_uids_in_block (m_func, inval_bb);
 
   return gimple_uid (inval_stmt) < gimple_uid (use_stmt);
 }
@@ -4235,27 +4229,26 @@ pass_waccess::check_pointer_uses (gimple *stmt, tree 
ptr,
  tree_code code = gimple_cond_code (cond);
  equality = code == EQ_EXPR || code == NE_EXPR;
}
+ else if (gimple_code (use_stmt) == GIMPLE_PHI)
+   {
+ /* Only add a PHI result to POINTERS if all its
+

[PATCH 2/2] c++: passing one ttp to another [PR108179]

2023-03-15 Thread Jason Merrill via Gcc-patches
I kept trying to improve our choice of how many levels of outer_args to add,
when really the problem was that outer_args are for PARM and for this
reverse deduction we should be adding the outer arguments for ARG.

I spent quite a while trying to get DECL_CONTEXT set consistently on
template template parameters that have gone through
reduce_template_parm_level before I realized I could just use
current_scope().

PR c++/108179
PR c++/104107
PR c++/95036

gcc/cp/ChangeLog:

* pt.cc (coerce_template_template_parms): Use args from
DECL_CONTEXT (arg_tmpl) instead of outer_args.

gcc/testsuite/ChangeLog:

* g++.dg/template/ttp35.C: New test.
---
 gcc/cp/pt.cc  | 32 ++-
 gcc/testsuite/g++.dg/template/ttp35.C |  7 ++
 2 files changed, 24 insertions(+), 15 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/template/ttp35.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index c9cd9f6097d..1b2a250224e 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -8084,22 +8084,24 @@ coerce_template_template_parms (tree parm_tmpl,
 
   tree pargs = template_parms_level_to_args (parm_parms);
 
-  /* PARM, and thus the context in which we are passing ARG to it, may be
-at a deeper level than ARG; when trying to coerce to ARG_PARMS, we
-want to provide the right number of levels, so we reduce the number of
-levels in OUTER_ARGS before prepending them.  This is most important
-when ARG is a namespace-scope template, as in alias-decl-ttp2.C.
+  /* PARM and ARG might be at different template depths, and we want to
+pass the right additional levels of args when coercing PARGS to
+ARG_PARMS in case we need to do any substitution into non-type
+template parameter types.
 
-ARG might also be deeper than PARM (ttp23).  In that case, we include
-all of OUTER_ARGS.  The missing levels seem potentially problematic,
-but I can't come up with a testcase that breaks.  */
-  if (int arg_outer_levs = TMPL_PARMS_DEPTH (arg_parms_full) - 1)
-   {
- auto x = make_temp_override (TREE_VEC_LENGTH (outer_args));
- if (TMPL_ARGS_DEPTH (outer_args) > arg_outer_levs)
-   TREE_VEC_LENGTH (outer_args) = arg_outer_levs;
- pargs = add_to_template_args (outer_args, pargs);
-   }
+OUTER_ARGS are not the right outer levels in this case, as they are
+the args we're building up for PARM, and for the coercion we want the
+args for ARG.  If DECL_CONTEXT isn't set for a template template
+parameter, we can assume that it's in the current scope.  In that case
+we might end up adding more levels than needed, but that shouldn't be
+a problem; any args we need to refer to are at the right level.  */
+  tree ctx = DECL_CONTEXT (arg_tmpl);
+  if (!ctx && DECL_TEMPLATE_TEMPLATE_PARM_P (arg_tmpl))
+   ctx = current_scope ();
+  tree scope_args = NULL_TREE;
+  if (tree tinfo = get_template_info (ctx))
+   scope_args = TI_ARGS (tinfo);
+  pargs = add_to_template_args (scope_args, pargs);
 
   pargs = coerce_template_parms (arg_parms, pargs, NULL_TREE, tf_none);
   if (pargs != error_mark_node)
diff --git a/gcc/testsuite/g++.dg/template/ttp35.C 
b/gcc/testsuite/g++.dg/template/ttp35.C
new file mode 100644
index 000..4847ea46ae1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/ttp35.C
@@ -0,0 +1,7 @@
+// PR c++/108179
+
+template  class F>
+struct Foo {};
+
+template  class F>
+void f(Foo) {}
-- 
2.31.1



[pushed 1/2] c++: coerce_template_template_parms interface tweak

2023-03-15 Thread Jason Merrill via Gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

This should have no semantic effect, but is a prerequisite for the PR108179
fix to follow.

PR c++/108179

gcc/cp/ChangeLog:

* pt.cc (coerce_template_template_parms): Take the arg and parm
templates directly.
(coerce_template_template_parm): Adjust.
(template_template_parm_bindings_ok_p): Adjust.
(convert_template_argument): Adjust.
---
 gcc/cp/pt.cc | 42 +++---
 1 file changed, 15 insertions(+), 27 deletions(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index c53d8e279c6..c9cd9f6097d 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -7772,11 +7772,8 @@ coerce_template_template_parm (tree parm,
 template  class> class TT>
 class C;  */
   {
-   tree parmparm = DECL_TEMPLATE_PARMS (parm);
-   tree argparm = DECL_TEMPLATE_PARMS (arg);
-
if (!coerce_template_template_parms
-   (parmparm, argparm, complain, in_decl, outer_args))
+   (parm, arg, complain, in_decl, outer_args))
  return 0;
   }
   /* Fall through.  */
@@ -8024,21 +8021,19 @@ unify_bound_ttp_args (tree tparms, tree targs, tree 
parm, tree& arg,
   return 0;
 }
 
-/* Return 1 if PARM_PARMS and ARG_PARMS matches using rule for
-   template template parameters.  Both PARM_PARMS and ARG_PARMS are
-   vectors of TREE_LIST nodes containing TYPE_DECL, TEMPLATE_DECL
-   or PARM_DECL.
+/* Return 1 if PARM_TMPL and ARG_TMPL match using rule for
+   template template parameters.
 
Consider the example:
  template  class A;
  template class TT> class B;
 
-   For B, PARM_PARMS are the parameters to TT, while ARG_PARMS are
-   the parameters to A, and OUTER_ARGS contains A.  */
+   For B, PARM_TMPL is TT, while ARG_TMPL is A,
+   and OUTER_ARGS contains A.  */
 
 static int
-coerce_template_template_parms (tree parm_parms_full,
-   tree arg_parms_full,
+coerce_template_template_parms (tree parm_tmpl,
+   tree arg_tmpl,
tsubst_flags_t complain,
tree in_decl,
tree outer_args)
@@ -8047,7 +8042,8 @@ coerce_template_template_parms (tree parm_parms_full,
   tree parm, arg;
   int variadic_p = 0;
 
-  tree parm_parms = INNERMOST_TEMPLATE_PARMS (parm_parms_full);
+  tree parm_parms = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (parm_tmpl));
+  tree arg_parms_full = DECL_TEMPLATE_PARMS (arg_tmpl);
   tree arg_parms = INNERMOST_TEMPLATE_PARMS (arg_parms_full);
 
   gcc_assert (TREE_CODE (parm_parms) == TREE_VEC);
@@ -8228,8 +8224,6 @@ template_template_parm_bindings_ok_p (tree tparms, tree 
targs)
 
  for (idx = 0; idx < len; ++idx)
{
- tree targ_parms = NULL_TREE;
-
  if (packed_args)
/* Extract the next argument from the argument
   pack.  */
@@ -8241,18 +8235,16 @@ template_template_parm_bindings_ok_p (tree tparms, tree 
targs)
 
  /* Extract the template parameters from the template
 argument.  */
- if (TREE_CODE (targ) == TEMPLATE_DECL)
-   targ_parms = DECL_TEMPLATE_PARMS (targ);
- else if (TREE_CODE (targ) == TEMPLATE_TEMPLATE_PARM)
-   targ_parms = DECL_TEMPLATE_PARMS (TYPE_NAME (targ));
+ if (TREE_CODE (targ) == TEMPLATE_TEMPLATE_PARM)
+   targ = TYPE_NAME (targ);
 
  /* Verify that we can coerce the template template
 parameters from the template argument to the template
 parameter.  This requires an exact match.  */
- if (targ_parms
+ if (TREE_CODE (targ) == TEMPLATE_DECL
  && !coerce_template_template_parms
-  (DECL_TEMPLATE_PARMS (tparm),
-   targ_parms,
+  (tparm,
+   targ,
tf_none,
tparm,
targs))
@@ -8545,15 +8537,11 @@ convert_template_argument (tree parm,
val = orig_arg;
  else
{
- tree parmparm = DECL_TEMPLATE_PARMS (parm);
- tree argparm;
-
  /* Strip alias templates that are equivalent to another
 template.  */
  arg = get_underlying_template (arg);
- argparm = DECL_TEMPLATE_PARMS (arg);
 
- if (coerce_template_template_parms (parmparm, argparm,
+ if (coerce_template_template_parms (parm, arg,
  complain, in_decl,
  args))
{

base-commit: 9e44a9932c11f028269f3aa7e3031e703d151b0b
-- 
2.31.1



[pushed] c++: injected class name as default ttp arg [PR58538]

2023-03-15 Thread Jason Merrill via Gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

This function needs to handle this case like convert_template_argument.

PR c++/58538

gcc/cp/ChangeLog:

* semantics.cc (check_template_template_default_arg): Check
maybe_get_template_decl_from_type_decl.

gcc/testsuite/ChangeLog:

* g++.dg/template/ttp7.C: Remove expected error.
---
 gcc/cp/semantics.cc  | 9 +++--
 gcc/testsuite/g++.dg/template/ttp7.C | 2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index d67a9b26719..57dd7b66da8 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -3468,8 +3468,13 @@ check_template_template_default_arg (tree argument)
   && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
 {
   if (TREE_CODE (argument) == TYPE_DECL)
-   error ("invalid use of type %qT as a default value for a template "
-  "template-parameter", TREE_TYPE (argument));
+   {
+ if (tree t = maybe_get_template_decl_from_type_decl (argument))
+   if (TREE_CODE (t) == TEMPLATE_DECL)
+ return t;
+ error ("invalid use of type %qT as a default value for a template "
+"template-parameter", TREE_TYPE (argument));
+   }
   else
error ("invalid default argument for a template template parameter");
   return error_mark_node;
diff --git a/gcc/testsuite/g++.dg/template/ttp7.C 
b/gcc/testsuite/g++.dg/template/ttp7.C
index 0bcaa8f7292..672077e7e7d 100644
--- a/gcc/testsuite/g++.dg/template/ttp7.C
+++ b/gcc/testsuite/g++.dg/template/ttp7.C
@@ -11,6 +11,6 @@ template class = A<0> > struct B2 {};  // { 
dg-error "as a default
 
 template 
 struct S {
-  template  class = S>   struct I1 {};  // { dg-error "as 
a default value" }
+  template  class = S>   struct I1 {}; // PR c++/58538
   template  class = ::S> struct I2 {};
 };

base-commit: 9e44a9932c11f028269f3aa7e3031e703d151b0b
prerequisite-patch-id: dc293188137e8f94cea3b5c135e62efad8fec595
prerequisite-patch-id: 30ba81cfc50ea4cae63d361169fda721504d06f5
-- 
2.31.1



[PATCH] riscv: thead: Add sign/zero extension support for th.ext and th.extu

2023-03-15 Thread Christoph Muellner
From: Christoph Müllner 

The current support of the bitfield-extraction instructions
th.ext and th.extu (XTheadBb extension) only covers sign_extract
and zero_extract. This patch add support for sign_extend and
zero_extend to avoid any shifts for sign or zero extensions.

gcc/ChangeLog:

* config/riscv/riscv.md:
* config/riscv/thead.md (*extend2_th_ext):
(*zero_extendsidi2_th_extu):
(*zero_extendhi2_th_extu):

gcc/testsuite/ChangeLog:

* gcc.target/riscv/xtheadbb-ext-1.c: New test.
* gcc.target/riscv/xtheadbb-extu-1.c: New test.

Signed-off-by: Christoph Müllner 
---
 gcc/config/riscv/riscv.md |  6 +-
 gcc/config/riscv/thead.md | 31 +
 .../gcc.target/riscv/xtheadbb-ext-1.c | 67 +++
 .../gcc.target/riscv/xtheadbb-extu-1.c| 67 +++
 4 files changed, 168 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadbb-ext-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadbb-extu-1.c

diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index 863400cd447..b763b84b763 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -1368,7 +1368,7 @@ (define_insn_and_split "*zero_extendsidi2_internal"
   [(set (match_operand:DI 0 "register_operand" "=r,r")
(zero_extend:DI
(match_operand:SI 1 "nonimmediate_operand" " r,m")))]
-  "TARGET_64BIT && !TARGET_ZBA
+  "TARGET_64BIT && !TARGET_ZBA && !TARGET_XTHEADBB
&& !(REG_P (operands[1])
 && REGNO (operands[1]) == VL_REGNUM)"
   "@
@@ -1395,7 +1395,7 @@ (define_insn_and_split "*zero_extendhi2"
   [(set (match_operand:GPR0 "register_operand" "=r,r")
(zero_extend:GPR
(match_operand:HI 1 "nonimmediate_operand" " r,m")))]
-  "!TARGET_ZBB"
+  "!TARGET_ZBB && !TARGET_XTHEADBB"
   "@
#
lhu\t%0,%1"
@@ -1451,7 +1451,7 @@ (define_insn_and_split 
"*extend2"
   [(set (match_operand:SUPERQI   0 "register_operand" "=r,r")
(sign_extend:SUPERQI
(match_operand:SHORT 1 "nonimmediate_operand" " r,m")))]
-  "!TARGET_ZBB"
+  "!TARGET_ZBB && !TARGET_XTHEADBB"
   "@
#
l\t%0,%1"
diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md
index 63c4af6f77d..978402e0b5d 100644
--- a/gcc/config/riscv/thead.md
+++ b/gcc/config/riscv/thead.md
@@ -59,6 +59,17 @@ (define_insn "*th_ext4"
   [(set_attr "type" "bitmanip")
(set_attr "mode" "")])
 
+(define_insn "*extend2_th_ext"
+  [(set (match_operand:SUPERQI 0 "register_operand" "=r,r")
+   (sign_extend:SUPERQI
+   (match_operand:SHORT 1 "nonimmediate_operand" "r,m")))]
+  "TARGET_XTHEADBB"
+  "@
+   th.ext\t%0,%1,15,0
+   l\t%0,%1"
+  [(set_attr "type" "bitmanip,load")
+   (set_attr "mode" "")])
+
 (define_insn "*th_extu4"
   [(set (match_operand:GPR 0 "register_operand" "=r")
(zero_extract:GPR (match_operand:GPR 1 "register_operand" "r")
@@ -72,6 +83,26 @@ (define_insn "*th_extu4"
   [(set_attr "type" "bitmanip")
(set_attr "mode" "")])
 
+(define_insn "*zero_extendsidi2_th_extu"
+  [(set (match_operand:DI 0 "register_operand" "=r,r")
+   (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "r,m")))]
+  "TARGET_64BIT && TARGET_XTHEADBB"
+  "@
+   th.extu\t%0,%1,31,0
+   lwu\t%0,%1"
+  [(set_attr "type" "bitmanip,load")
+   (set_attr "mode" "SI")])
+
+(define_insn "*zero_extendhi2_th_extu"
+  [(set (match_operand:GPR 0 "register_operand" "=r,r")
+   (zero_extend:GPR (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
+  "TARGET_XTHEADBB"
+  "@
+   th.extu\t%0,%1,15,0
+   lhu\t%0,%1"
+  [(set_attr "type" "bitmanip,load")
+   (set_attr "mode" "HI")])
+
 (define_insn "*th_clz2"
   [(set (match_operand:X 0 "register_operand" "=r")
(clz:X (match_operand:X 1 "register_operand" "r")))]
diff --git a/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-1.c 
b/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-1.c
new file mode 100644
index 000..02f6ec1417d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-1.c
@@ -0,0 +1,67 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_xtheadbb" { target { rv64 } } } */
+/* { dg-options "-march=rv32gc_xtheadbb" { target { rv32 } } } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Os" "-Og" } } */
+
+long sext64_32(int s32)
+{
+return s32;
+}
+
+long sext64_16(short s16)
+{
+return s16;
+}
+
+long sext64_8(char s8)
+{
+return s8;
+}
+
+int sext32_64(long s64)
+{
+return s64;
+}
+
+int sext32_16(short s16)
+{
+return s16;
+}
+
+int sext32_8(char s8)
+{
+return s8;
+}
+
+short sext16_64(long s64)
+{
+return s64;
+}
+
+short sext16_32(int s32)
+{
+return s32;
+}
+
+short sext16_8(char s8)
+{
+return s8;
+}
+
+char sext8_64(long s64)
+{
+return s64;
+}
+
+char sext8_32(int s32)
+{
+return s32;
+}
+
+char sext8_16(short s16)
+{
+return s16;
+}
+
+/* { dg-final { scan-assembler-not "slli" } } */
+/* { 

Re: [PATCH 1/2] Avoid random stmt order result in pass_waccess::use_after_inval_p

2023-03-15 Thread Richard Biener via Gcc-patches
On Wed, 15 Mar 2023, Jakub Jelinek wrote:

> On Wed, Mar 15, 2023 at 10:48:32AM +, Richard Biener wrote:
> > use_after_inval_p uses stmt UIDs to speed up repeated dominance
> > checks within a basic-block but it fails to assign UIDs to PHIs
> > which means compares with PHIs in the same block get a random
> > result.
> > 
> > The following factors renumber_gimple_stmt_uids to expose a new
> > renumber_gimple_stmt_uids_in_block we can share.
> > 
> > This XFAILs the conditional loop case in gcc.dg/Wuse-after-free-2.c
> > 
> > Bootstrap and regtest running on x86_64-unknown-linux-gnu.  This
> > makes 2/2 a net positive on the testsuite (the early waccess
> > would not run into this bug)
> > 
> > OK if testing succeeds?  (we could also special-case PHIs somehow
> > and assert we never get to compare two PHIs here)
> > 
> > * tree-dfa.h (renumber_gimple_stmt_uids_in_block): New.
> > * tree-dfa.cc (renumber_gimple_stmt_uids_in_block): Split
> > out from ...
> > (renumber_gimple_stmt_uids): ... here and
> > (renumber_gimple_stmt_uids_in_blocks): ... here.
> > * gimple-ssa-warn-access.cc (pass_waccess::use_after_inval_p):
> > Use renumber_gimple_stmt_uids_in_block to also assign UIDs
> > to PHIs.
> > 
> > * gcc.dg/Wuse-after-free-2.c: XFAIL conditional loop case.
> 
> LGTM.

Turns out we rely very much on processing PHIs for following pointers
(we also happily look at earlier pointer adjustments).  So while the
comparison done to PHIs in the above function is bogus and we should
possibly fix it it regresses things unless we process PHIs
unconditionally.

I'm going to test an adjusted patch.

Richard.


Re: [PATCH 2/2] tree-optimization/109123 - run -Wuse-afer-free only early

2023-03-15 Thread Richard Biener via Gcc-patches
On Wed, 15 Mar 2023, Jakub Jelinek wrote:

> On Wed, Mar 15, 2023 at 10:49:19AM +, Richard Biener via Gcc-patches 
> wrote:
> > The following switches the -Wuse-after-free diagnostics from emitted
> > during the late access warning passes to the early access warning
> > passes to make sure we run before passes performing code motion run
> > which are the source of a lot of false positives on use-after-free
> > not involving memory operations.
> > 
> > The patch also fixes issues in c-c++-common/Wuse-after-free-6.c and
> > g++.dg/warn/Wuse-after-free3.C.
> > 
> > Bootstrapped and tested on x86_64-unknown-linux-gnu (without 1/2
> > sofar, but its testcase XFAILed).
> > 
> > OK?
> > 
> > Thanks,
> > Richard.
> > 
> > PR tree-optimization/109123
> > * gimple-ssa-warn-access.cc (pass_waccess::warn_invalid_pointer):
> > Do not emit -Wuse-after-free late.
> > (pass_waccess::check_call): Always check call pointer uses.
> > 
> > * gcc.dg/Wuse-after-free-pr109123.c: New testcase.
> > * c-c++-common/Wuse-after-free-6.c: Un-XFAIL case.
> > * g++.dg/warn/Wuse-after-free3.C: Remove expected duplicate
> > diagnostic.
> 
> I guess this is this is related to the never ending debate of what to
> do with the middle end late warnings, whether we should kill them
> altogether, move into analyzer framework and/or run early but perform
> IPA analysis for them.

Yes.  And for -Wuse-after-free also whether value-uses are considered
or not, but changing that has a much bigger testsuite fallout.

> Doing the diagnostics in the early waccess pass is certainly fine
> no matter what, it will emit there more accurate diagnostics.
> A big question is whether to avoid diagnosing it late as well (other option
> is just make sure we don't diagnose same statements twice, once in early
> waccess and once in late waccess, which can be solved with warning
> suppressions (unless it is already properly suppressed)), especially for
> GCC 13.
> I see we have two copies of early waccess (so, we need to get the
> suppression right even if the warning is just moved to early waccess),
> one is very shortly after building ssa, so before early inlining,
> then there is another early one for -O+ non-Og shortly after IPA,
> and the late one is immediately before expansion.

Yep, I think the suppression should already work.

> So, the question is if the ccp after IPA is sufficient to uncover
> the most of the use after free issues we want to diagnose, if yes,
> then perhaps your patch is ok but we need to decide what to do about
> -Og, whether we shouldn't add
>   NEXT_PASS (pass_warn_access, /*early=*/true);
> into -Og pass queue after 
>   NEXT_PASS (pass_object_sizes);
> or so.

That would be possible for sure.  But then there's not much
done between the late early and the late pass so the late pass
could run in both modes (but I don't feel like massaging that too much
at this point).

There's also -O0 where the late pass catches all always-inlined
cases.

> I think even the pre-IPA optimizations can do some harm for use after free
> false positives, but hopefully not as much as the post IPA optimizations.

We do some very limited jump-threading but I don't think there's much
code-motion going on.

Richard.


Re: [PATCH 2/2] tree-optimization/109123 - run -Wuse-afer-free only early

2023-03-15 Thread Jakub Jelinek via Gcc-patches
On Wed, Mar 15, 2023 at 10:49:19AM +, Richard Biener via Gcc-patches wrote:
> The following switches the -Wuse-after-free diagnostics from emitted
> during the late access warning passes to the early access warning
> passes to make sure we run before passes performing code motion run
> which are the source of a lot of false positives on use-after-free
> not involving memory operations.
> 
> The patch also fixes issues in c-c++-common/Wuse-after-free-6.c and
> g++.dg/warn/Wuse-after-free3.C.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu (without 1/2
> sofar, but its testcase XFAILed).
> 
> OK?
> 
> Thanks,
> Richard.
> 
>   PR tree-optimization/109123
>   * gimple-ssa-warn-access.cc (pass_waccess::warn_invalid_pointer):
>   Do not emit -Wuse-after-free late.
>   (pass_waccess::check_call): Always check call pointer uses.
> 
>   * gcc.dg/Wuse-after-free-pr109123.c: New testcase.
>   * c-c++-common/Wuse-after-free-6.c: Un-XFAIL case.
>   * g++.dg/warn/Wuse-after-free3.C: Remove expected duplicate
>   diagnostic.

I guess this is this is related to the never ending debate of what to
do with the middle end late warnings, whether we should kill them
altogether, move into analyzer framework and/or run early but perform
IPA analysis for them.

Doing the diagnostics in the early waccess pass is certainly fine
no matter what, it will emit there more accurate diagnostics.
A big question is whether to avoid diagnosing it late as well (other option
is just make sure we don't diagnose same statements twice, once in early
waccess and once in late waccess, which can be solved with warning
suppressions (unless it is already properly suppressed)), especially for
GCC 13.
I see we have two copies of early waccess (so, we need to get the
suppression right even if the warning is just moved to early waccess),
one is very shortly after building ssa, so before early inlining,
then there is another early one for -O+ non-Og shortly after IPA,
and the late one is immediately before expansion.

So, the question is if the ccp after IPA is sufficient to uncover
the most of the use after free issues we want to diagnose, if yes,
then perhaps your patch is ok but we need to decide what to do about
-Og, whether we shouldn't add
  NEXT_PASS (pass_warn_access, /*early=*/true);
into -Og pass queue after 
  NEXT_PASS (pass_object_sizes);
or so.

I think even the pre-IPA optimizations can do some harm for use after free
false positives, but hopefully not as much as the post IPA optimizations.

Jakub



Re: [PATCH 1/2] Avoid random stmt order result in pass_waccess::use_after_inval_p

2023-03-15 Thread Jakub Jelinek via Gcc-patches
On Wed, Mar 15, 2023 at 10:48:32AM +, Richard Biener wrote:
> use_after_inval_p uses stmt UIDs to speed up repeated dominance
> checks within a basic-block but it fails to assign UIDs to PHIs
> which means compares with PHIs in the same block get a random
> result.
> 
> The following factors renumber_gimple_stmt_uids to expose a new
> renumber_gimple_stmt_uids_in_block we can share.
> 
> This XFAILs the conditional loop case in gcc.dg/Wuse-after-free-2.c
> 
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.  This
> makes 2/2 a net positive on the testsuite (the early waccess
> would not run into this bug)
> 
> OK if testing succeeds?  (we could also special-case PHIs somehow
> and assert we never get to compare two PHIs here)
> 
>   * tree-dfa.h (renumber_gimple_stmt_uids_in_block): New.
>   * tree-dfa.cc (renumber_gimple_stmt_uids_in_block): Split
>   out from ...
>   (renumber_gimple_stmt_uids): ... here and
>   (renumber_gimple_stmt_uids_in_blocks): ... here.
>   * gimple-ssa-warn-access.cc (pass_waccess::use_after_inval_p):
>   Use renumber_gimple_stmt_uids_in_block to also assign UIDs
>   to PHIs.
> 
>   * gcc.dg/Wuse-after-free-2.c: XFAIL conditional loop case.

LGTM.

Jakub



[PATCH 2/2] tree-optimization/109123 - run -Wuse-afer-free only early

2023-03-15 Thread Richard Biener via Gcc-patches
The following switches the -Wuse-after-free diagnostics from emitted
during the late access warning passes to the early access warning
passes to make sure we run before passes performing code motion run
which are the source of a lot of false positives on use-after-free
not involving memory operations.

The patch also fixes issues in c-c++-common/Wuse-after-free-6.c and
g++.dg/warn/Wuse-after-free3.C.

Bootstrapped and tested on x86_64-unknown-linux-gnu (without 1/2
sofar, but its testcase XFAILed).

OK?

Thanks,
Richard.

PR tree-optimization/109123
* gimple-ssa-warn-access.cc (pass_waccess::warn_invalid_pointer):
Do not emit -Wuse-after-free late.
(pass_waccess::check_call): Always check call pointer uses.

* gcc.dg/Wuse-after-free-pr109123.c: New testcase.
* c-c++-common/Wuse-after-free-6.c: Un-XFAIL case.
* g++.dg/warn/Wuse-after-free3.C: Remove expected duplicate
diagnostic.
---
 gcc/gimple-ssa-warn-access.cc | 28 ++---
 .../c-c++-common/Wuse-after-free-6.c  |  2 +-
 gcc/testsuite/g++.dg/warn/Wuse-after-free3.C  |  3 +-
 .../gcc.dg/Wuse-after-free-pr109123.c | 41 +++
 4 files changed, 57 insertions(+), 17 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/Wuse-after-free-pr109123.c

diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index a8ad7a6df65..d0809d321ea 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -3907,7 +3907,8 @@ pass_waccess::warn_invalid_pointer (tree ref, gimple 
*use_stmt,
 
   if (is_gimple_call (inval_stmt))
 {
-  if ((equality && warn_use_after_free < 3)
+  if (!m_early_checks_p
+ || (equality && warn_use_after_free < 3)
  || (maybe && warn_use_after_free < 2)
  || warning_suppressed_p (use_stmt, OPT_Wuse_after_free))
return;
@@ -4300,19 +4301,18 @@ pass_waccess::check_call (gcall *stmt)
   if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
 check_builtin (stmt);
 
-  if (!m_early_checks_p)
-if (tree callee = gimple_call_fndecl (stmt))
-  {
-   /* Check for uses of the pointer passed to either a standard
-  or a user-defined deallocation function.  */
-   unsigned argno = fndecl_dealloc_argno (callee);
-   if (argno < (unsigned) call_nargs (stmt))
- {
-   tree arg = call_arg (stmt, argno);
-   if (TREE_CODE (arg) == SSA_NAME)
- check_pointer_uses (stmt, arg);
- }
-  }
+  if (tree callee = gimple_call_fndecl (stmt))
+{
+  /* Check for uses of the pointer passed to either a standard
+or a user-defined deallocation function.  */
+  unsigned argno = fndecl_dealloc_argno (callee);
+  if (argno < (unsigned) call_nargs (stmt))
+   {
+ tree arg = call_arg (stmt, argno);
+ if (TREE_CODE (arg) == SSA_NAME)
+   check_pointer_uses (stmt, arg);
+   }
+}
 
   check_call_access (stmt);
   check_call_dangling (stmt);
diff --git a/gcc/testsuite/c-c++-common/Wuse-after-free-6.c 
b/gcc/testsuite/c-c++-common/Wuse-after-free-6.c
index 581b1a0a024..0c17a2545f4 100644
--- a/gcc/testsuite/c-c++-common/Wuse-after-free-6.c
+++ b/gcc/testsuite/c-c++-common/Wuse-after-free-6.c
@@ -53,7 +53,7 @@ void* warn_cond_return_after_free (void *p, int c)
   free (p);
   // PHI handling not fully implemented.
   if (c)
-return p;   // { dg-warning "pointer 'p' may be used" "pr??" { 
xfail *-*-* } }
+return p;   // { dg-warning "pointer 'p' may be used" }
   return 0;
 }
 
diff --git a/gcc/testsuite/g++.dg/warn/Wuse-after-free3.C 
b/gcc/testsuite/g++.dg/warn/Wuse-after-free3.C
index 1862ac8b09d..e5b157865bf 100644
--- a/gcc/testsuite/g++.dg/warn/Wuse-after-free3.C
+++ b/gcc/testsuite/g++.dg/warn/Wuse-after-free3.C
@@ -1,7 +1,6 @@
 // PR target/104213
 // { dg-do compile }
 // { dg-options "-Wuse-after-free" }
-// FIXME: We should not output the warning twice.
 
 struct A
 {
@@ -13,4 +12,4 @@ A::~A ()
 {
   operator delete (this);
   f (); // { dg-warning "used after" }
-} // { dg-warning "used after" }
+}
diff --git a/gcc/testsuite/gcc.dg/Wuse-after-free-pr109123.c 
b/gcc/testsuite/gcc.dg/Wuse-after-free-pr109123.c
new file mode 100644
index 000..ece066dd28b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wuse-after-free-pr109123.c
@@ -0,0 +1,41 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wall" } */
+
+typedef long unsigned int size_t;
+extern void *realloc (void *__ptr, size_t __size)
+ __attribute__ ((__nothrow__ , __leaf__)) __attribute__ 
((__warn_unused_result__)) __attribute__ ((__alloc_size__ (2)));
+struct vector_objective; 
+typedef struct vector_objective vector_objective;
+struct vector_objective { double *_begin; double *_end; double *_capacity; };
+static inline size_t vector_objective_size(const vector_objective * v) { 
+return v->_end - v->_begin;  /* { dg-bogus "used after" } */
+}
+static inline size_t 

[PATCH 1/2] Avoid random stmt order result in pass_waccess::use_after_inval_p

2023-03-15 Thread Richard Biener via Gcc-patches
use_after_inval_p uses stmt UIDs to speed up repeated dominance
checks within a basic-block but it fails to assign UIDs to PHIs
which means compares with PHIs in the same block get a random
result.

The following factors renumber_gimple_stmt_uids to expose a new
renumber_gimple_stmt_uids_in_block we can share.

This XFAILs the conditional loop case in gcc.dg/Wuse-after-free-2.c

Bootstrap and regtest running on x86_64-unknown-linux-gnu.  This
makes 2/2 a net positive on the testsuite (the early waccess
would not run into this bug)

OK if testing succeeds?  (we could also special-case PHIs somehow
and assert we never get to compare two PHIs here)

* tree-dfa.h (renumber_gimple_stmt_uids_in_block): New.
* tree-dfa.cc (renumber_gimple_stmt_uids_in_block): Split
out from ...
(renumber_gimple_stmt_uids): ... here and
(renumber_gimple_stmt_uids_in_blocks): ... here.
* gimple-ssa-warn-access.cc (pass_waccess::use_after_inval_p):
Use renumber_gimple_stmt_uids_in_block to also assign UIDs
to PHIs.

* gcc.dg/Wuse-after-free-2.c: XFAIL conditional loop case.
---
 gcc/gimple-ssa-warn-access.cc|  8 +---
 gcc/testsuite/gcc.dg/Wuse-after-free-2.c |  4 +-
 gcc/tree-dfa.cc  | 48 +++-
 gcc/tree-dfa.h   |  1 +
 4 files changed, 25 insertions(+), 36 deletions(-)

diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index 8b1c1cc019e..a8ad7a6df65 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -3862,13 +3862,7 @@ pass_waccess::use_after_inval_p (gimple *inval_stmt, 
gimple *use_stmt,
to consecutive statements in it.  Use the ids to determine which
precedes which.  This avoids the linear traversal on subsequent
visits to the same block.  */
-for (auto si = gsi_start_bb (inval_bb); !gsi_end_p (si);
-gsi_next_nondebug ())
-  {
-   gimple *stmt = gsi_stmt (si);
-   unsigned uid = inc_gimple_stmt_max_uid (m_func);
-   gimple_set_uid (stmt, uid);
-  }
+renumber_gimple_stmt_uids_in_block (m_func, inval_bb);
 
   return gimple_uid (inval_stmt) < gimple_uid (use_stmt);
 }
diff --git a/gcc/testsuite/gcc.dg/Wuse-after-free-2.c 
b/gcc/testsuite/gcc.dg/Wuse-after-free-2.c
index ebc051690db..cd5c43c0fa3 100644
--- a/gcc/testsuite/gcc.dg/Wuse-after-free-2.c
+++ b/gcc/testsuite/gcc.dg/Wuse-after-free-2.c
@@ -113,6 +113,6 @@ int warn_cond_loop (char *p)
   while (*q)
 ++q;
 
-  free (p); // { dg-message "call to 'free'" }
-  return *q;// { dg-warning "pointer 'q' used after 'free'" }
+  free (p); // dg-message "call to 'free'"
+  return *q;// { dg-warning "pointer 'q' used after 'free'" "" { xfail 
*-*-* } }
 }
diff --git a/gcc/tree-dfa.cc b/gcc/tree-dfa.cc
index ec8df0d6401..82803a8ccb1 100644
--- a/gcc/tree-dfa.cc
+++ b/gcc/tree-dfa.cc
@@ -59,6 +59,25 @@ static void collect_dfa_stats (struct dfa_stats_d *);
Dataflow analysis (DFA) routines
 ---*/
 
+/* Renumber the gimple stmt uids in one block.  The caller is responsible
+   of calling set_gimple_stmt_max_uid (fun, 0) at some point.  */
+
+void
+renumber_gimple_stmt_uids_in_block (struct function *fun, basic_block bb)
+{
+  gimple_stmt_iterator bsi;
+  for (bsi = gsi_start_phis (bb); !gsi_end_p (bsi); gsi_next ())
+{
+  gimple *stmt = gsi_stmt (bsi);
+  gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fun));
+}
+  for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next ())
+{
+  gimple *stmt = gsi_stmt (bsi);
+  gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fun));
+}
+}
+
 /* Renumber all of the gimple stmt uids.  */
 
 void
@@ -68,19 +87,7 @@ renumber_gimple_stmt_uids (struct function *fun)
 
   set_gimple_stmt_max_uid (fun, 0);
   FOR_ALL_BB_FN (bb, fun)
-{
-  gimple_stmt_iterator bsi;
-  for (bsi = gsi_start_phis (bb); !gsi_end_p (bsi); gsi_next ())
-   {
- gimple *stmt = gsi_stmt (bsi);
- gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fun));
-   }
-  for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next ())
-   {
- gimple *stmt = gsi_stmt (bsi);
- gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fun));
-   }
-}
+renumber_gimple_stmt_uids_in_block (fun, bb);
 }
 
 /* Like renumber_gimple_stmt_uids, but only do work on the basic blocks
@@ -93,20 +100,7 @@ renumber_gimple_stmt_uids_in_blocks (basic_block *blocks, 
int n_blocks)
 
   set_gimple_stmt_max_uid (cfun, 0);
   for (i = 0; i < n_blocks; i++)
-{
-  basic_block bb = blocks[i];
-  gimple_stmt_iterator bsi;
-  for (bsi = gsi_start_phis (bb); !gsi_end_p (bsi); gsi_next ())
-   {
- gimple *stmt = gsi_stmt (bsi);
- gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
-   }
-  for (bsi = 

[PATCH v4] gcov: Fix "do-while" structure in case statement leads to incorrect code coverage [PR93680]

2023-03-15 Thread Xionghu Luo via Gcc-patches



On 2023/3/9 20:02, Richard Biener wrote:

On Wed, 8 Mar 2023, Xionghu Luo wrote:




On 2023/3/7 19:25, Richard Biener wrote:

It would be nice to avoid creating blocks / preserving labels we'll
immediately remove again.  For that we do need some analysis
before creating basic-blocks that determines whether a label is
possibly reached by a non-falltru edge.



 :
p = 0;
switch (s) , case 0: , case 1: >

 :
:   <= prev_stmt
:   <= stmt
p = p + 1;
n = n + -1;
if (n != 0) goto ; else goto ;

Check if  is a case label and  is a goto target then return
true
in stmt_starts_bb_p to start a new basic block?  This would avoid creating
and
removing blocks, but cleanup_dead_labels has all bbs setup while
stmt_starts_bb_p
does't yet to iterate bbs/labels to establish label_for_bb[] map?



Yes.  I think we'd need something more pragmatic before make_blocks (),
like re-computing TREE_USED of the label decls or computing a bitmap
of targeted labels (targeted by goto, switch or any other means).

I'll note that doing a cleanup_dead_labels () like optimization before
we create blocks will help keeping LABEL_DECL_UID and thus
label_to_block_map dense.  But it does look like a bit of
an chicken-and-egg problem and the question is how effective the
dead label removal is in practice.


Tried to add function compute_target_labels(not sure whether the function
name is suitable) in the front of make_blocks_1, now the fortran case doesn't
create/removing blocks now, but I still have several questions:

  1. I used hash_set to save the target labels instead of bitmap, as
labels
are tree type value instead of block index so bitmap is not good for it since
we don't have LABEL_DECL_UID now?


We don't have LABEL_DECL_UID, we have DECL_UID though, but the choice of
hash_set vs. bitmap is somewhat arbitrary here.  The real cost is
the extra walk over all stmts.


  2. Is the compute_target_labels still only for !optimize?  And if we compute
the target labels before create bbs, it is unnessary to guard the first
cleanup_dead_labels under !optimize now, because the switch-case-do-while
case already create new block for CASE_LABEL already.


OK.


  3. I only added GIMPLE_SWITCH/GIMPLE_COND in compute_target_labels
so far, is it needed to also handle GIMPLE_ASM/GIMPLE_TRANSACTION and even
labels_eh?


I'd add GIMPLE_ASM handling, the rest should be OK wrt debugging and
coverage already?


PS1: The v3 patch will cause one test case fail:

Number of regressions in total: 1

FAIL: gcc.c-torture/compile/limits-caselabels.c   -O0  (test for excess
errors)


due to this exausting case has labels from L0 to L11, they won't be
optimized
to a simple if-else expression like before...


Hmm, that's somewhat unexpected.



PS2: The GIMPLE_GOTO piece of code would cause some fortran cases run fail due
to __builtin_unreachable trap generated in .fixup_cfg1, I didn't dig into it
so
just skip these label...


Please investigate, we might be missing a corner case here.



I think the *previous fix* for labels “in the middle of block” is *incorrect*, 
it should
be handled in make_edges_bb when a basic block only has Label in it, just 
create a
fallthrough edge for it to avoid wrong cfg and unreachable trap generated?


@@ -853,6 +922,12 @@ make_edges_bb (basic_block bb, struct omp_region 
**pcur_region, int *pomp_index)
   bool fallthru = false;
   int ret = 0;

+  if (!optimize && !last)
+{
+  make_edge (bb, bb->next_bb, EDGE_FALLTHRU);
+  return 0;
+}
+
   if (!last)
 return ret;


With the fix, the attached version could pass bootstrap and regression test on 
x86_64-linux-gnu.


From ec505cc7952707db805802af83dd82776a1d949f Mon Sep 17 00:00:00 2001
From: Xionghu Luo 
Date: Tue, 28 Feb 2023 17:46:18 +0800
Subject: [PATCH v4]  gcov: Fix "do-while" structure in case statement leads to
 incorrect code coverage [PR93680]

v4: Address comments.
 4.1. Handle GIMPLE_GOTO and GIMPLE_ASM.
 4.2. Fix failure of limit-caselabels.c (labels on same line),
 pointer_array_1.f90 (unused labels) etc.

v3: Add compute_target_labels and call it in the front of make_blocks_1.
v2: Check whether two locus are on same line.

Start a new basic block if two labels have different location when
test-coverage.

Regression tested pass on x86_64-linux-gnu and aarch64-linux-gnu, OK for
master?

gcc/ChangeLog:

PR gcov/93680
* tree-cfg.cc (stmt_starts_bb_p): Check whether the label is in
target_labels.
(compute_target_labels): New function.
(make_blocks_1): Call compute_target_labels.
(same_line_p): Return false if two locus are both
UNKOWN_LOCATION.

gcc/testsuite/ChangeLog:

PR gcov/93680
* g++.dg/gcov/gcov-1.C: Correct counts.
* gcc.misc-tests/gcov-4.c: Likewise.
* gcc.misc-tests/gcov-pr85332.c: Likewise.
* lib/gcov.exp: Also clean gcda if fail.
* gcc.misc-tests/gcov-pr93680.c: New test.

Signed-off-by: Xionghu Luo 
---
 gcc/tree-cfg.cc   

Pushed: [PATCH] builtins: Move the character difference into result instead of reassigning result [PR109086]

2023-03-15 Thread Xi Ruoyao via Gcc-patches
Already approved in bugzilla and bootstrapped on x86_64-linux-gnu.
Pushed.

expand_simple_binop() is allowed to allocate a new pseudo-register and
return it, instead of forcing the result into the provided
pseudo-register.  This can cause a problem when we expand the unrolled
loop for __builtin_strcmp: the compiler always generates code for all n
iterations of the loop, so "result" will be an alias of the
pseudo-register allocated and used in the last iteration; but at runtime
the loop can break early, causing this pseudo-register uninitialized.

Emit a move instruction in the iteration to force the difference into
one register which has been allocated before the loop, to avoid this
issue.

gcc/ChangeLog:

PR other/109086
* builtins.cc (inline_string_cmp): Force the character
difference into "result" pseudo-register, instead of reassign
the pseudo-register.
---
 gcc/builtins.cc | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index 305c65c29be..90246e214d6 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -7142,8 +7142,16 @@ inline_string_cmp (rtx target, tree var_str, const char 
*const_str,
 
   op0 = convert_modes (mode, unit_mode, op0, 1);
   op1 = convert_modes (mode, unit_mode, op1, 1);
-  result = expand_simple_binop (mode, MINUS, op0, op1,
-   result, 1, OPTAB_WIDEN);
+  rtx diff = expand_simple_binop (mode, MINUS, op0, op1,
+ result, 1, OPTAB_WIDEN);
+
+  /* Force the difference into result register.  We cannot reassign
+result here ("result = diff") or we may end up returning
+uninitialized result when expand_simple_binop allocates a new
+pseudo-register for returning.  */
+  if (diff != result)
+   emit_move_insn (result, diff);
+
   if (i < length - 1)
emit_cmp_and_jump_insns (result, CONST0_RTX (mode), NE, NULL_RTX,
 mode, true, ne_label);
-- 
2.40.0



[PATCH] tree-optimization/109139 - fix .DEFERRED_INIT removal

2023-03-15 Thread Richard Biener via Gcc-patches
The following make sure to strip MEMs when looking for unused
decls on the LHS of .DEFERRED_INIT.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

PR tree-optimization/109139
* tree-ssa-live.cc (remove_unused_locals): Look at the
base address for unused decls on the LHS of .DEFERRED_INIT.

* gcc.dg/torture/pr109139.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr109139.c | 12 
 gcc/tree-ssa-live.cc|  3 ++-
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr109139.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr109139.c 
b/gcc/testsuite/gcc.dg/torture/pr109139.c
new file mode 100644
index 000..9fa97ebc665
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr109139.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-ftrivial-auto-var-init=zero" } */
+
+const int COMPARE_CANDIDATE;
+char ipmi_ek_compare_link_record1_0, ipmi_ek_compare_link_record2_0;
+void ipmi_ek_compare_link()
+{
+  for (; ipmi_ek_compare_link_record1_0;)
+for (; ipmi_ek_compare_link_record2_0;) {
+   int link[COMPARE_CANDIDATE];
+}
+}
diff --git a/gcc/tree-ssa-live.cc b/gcc/tree-ssa-live.cc
index 9118e82b4f1..1be92956cc5 100644
--- a/gcc/tree-ssa-live.cc
+++ b/gcc/tree-ssa-live.cc
@@ -897,7 +897,8 @@ remove_unused_locals (void)
else if (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT))
  {
tree lhs = gimple_call_lhs (stmt);
-   if (DECL_P (lhs) && !is_used_p (lhs))
+   tree base = get_base_address (lhs);
+   if (DECL_P (base) && !is_used_p (base))
  {
unlink_stmt_vdef (stmt);
gsi_remove (, true);
-- 
2.35.3


Re: [PATCH] Fortran: rank checking with explicit-/assumed-size arrays and CLASS [PR58331]

2023-03-15 Thread Tobias Burnus

Hi Harald,

On 14.03.23 20:38, Harald Anlauf wrote:

The testcase covers only non-coarray cases, as playing with
coarray variants hit pre-exisiting issues in gfortran that
are very likely unrelated to the interface checks.

I concur (but would not rule out additional interface issues).

I consider this rather as post 13-release stuff.

In any case, the coarray issue can be fixed separately. And I think
post-GCC-13 makes sense.

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

Thanks – LGTM!

+  formal_as = formal->ts.type == BT_CLASS ? CLASS_DATA (formal)->as
+   : formal->as;
+


(Jakub remarks for such code that some editor (emacs?), he does not use,
mis--auto-indent such a code - and proposes to add a parentheses
around the right-hand side of the assignment.)

* * *

I also wonder whether we need some run-time testcase. The interface
check now works and I also tend to write dg-do-compile testcases, but
given what can go wrong with all the array descriptor, class etc
handling, we may want to ensure it works at run time. – Thoughts?

(That's independent of the patch it and could be done as follow up, if
it deemed reasonable. The included testcase is surely compile-only as it
has dg-error checks.)

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: [wwwdocs] gcc-13: riscv: Document the T-Head CPU support

2023-03-15 Thread Philipp Tomsich
Applied to master, thanks!
Philipp.

On Sun, 5 Mar 2023 at 11:18, Kito Cheng  wrote:

> LGTM :)
>
>
> On Fri, Feb 24, 2023 at 7:19 PM Christoph Muellner
>  wrote:
> >
> > From: Christoph Müllner 
> >
> > This patch documents the new T-Head CPU support for RISC-V.
> >
> > Signed-off-by: Christoph Müllner 
> > ---
> >  htdocs/gcc-13/changes.html | 24 +++-
> >  1 file changed, 23 insertions(+), 1 deletion(-)
> >
> > diff --git a/htdocs/gcc-13/changes.html b/htdocs/gcc-13/changes.html
> > index a803f501..ce5ba35c 100644
> > --- a/htdocs/gcc-13/changes.html
> > +++ b/htdocs/gcc-13/changes.html
> > @@ -490,7 +490,29 @@ a work-in-progress.
> >
> >  RISC-V
> >  
> > -New ISA extension support for zawrs.
> > +  New ISA extension support for Zawrs.
> > +  Support for the following vendor extensions has been added:
> > +
> > +  XTheadBa
> > +  XTheadBb
> > +  XTheadBs
> > +  XTheadCmo
> > +  XTheadCondMov
> > +  XTheadFMemIdx
> > +  XTheadFmv
> > +  XTheadInt
> > +  XTheadMac
> > +  XTheadMemIdx
> > +  XTheadMemPair
> > +  XTheadSync
> > +
> > +  
> > +  The following new CPUs are supported through the
> -mcpu
> > +  option (GCC identifiers in parentheses).
> > +
> > +  T-Head's XuanTie C906 (thead-c906).
> > +
> > +  
> >  
> >
> >  
> > --
> > 2.39.2
> >
>


Re: [PATCH v4 0/9] RISC-V: Add XThead* extension support

2023-03-15 Thread Philipp Tomsich
On Sun, 5 Mar 2023 at 11:19, Kito Cheng  wrote:

> LGTM :)
>

Applied to master, thanks!
--Philipp.

On Thu, Mar 2, 2023 at 4:36 PM Christoph Muellner
>  wrote:
> >
> > From: Christoph Müllner 
> >
> > This series introduces support for the T-Head specific RISC-V ISA
> extensions
> > which are available e.g. on the T-Head XuanTie C906.
> >
> > The ISA spec can be found here:
> >   https://github.com/T-head-Semi/thead-extension-spec
> >
> > This series adds support for the following XThead* extensions:
> > * XTheadBa
> > * XTheadBb
> > * XTheadBs
> > * XTheadCmo
> > * XTheadCondMov
> > * XTheadFmv
> > * XTheadInt
> > * XTheadMac
> > * XTheadMemPair
> > * XTheadSync
> >
> > All extensions are properly integrated and the included tests
> > demonstrate the improvements of the generated code.
> >
> > The series also introduces support for "-mcpu=thead-c906", which also
> > enables all available XThead* ISA extensions of the T-Head C906.
> >
> > All patches have been tested and don't introduce regressions for RV32 or
> RV64.
> > The patches have also been tested with SPEC CPU2017 on QEMU and real HW
> > (D1 board).
> >
> > Support patches for these extensions for Binutils, QEMU, and LLVM have
> > already been merged in the corresponding upstream projects.
> >
> > Patches 1-8 from this series (everything except the last one) got an ACK
> > by Kito. However, since there were a few comments after the ACK, I
> > decided to send out a v4, so that reviewers can verify that their
> > comments have been addressed properly.
> >
> > Note, that there was a concern raised by Andrew Pinski (on CC), which
> > might not be resolved with this series (I could not reproduce the issue,
> > but I might have misunderstood something).
> >
> > Changes in v4:
> > - Drop XTheadMemIdx and XTheadFMemIdx (will be a follow-up series)
> > - Replace 'immediate_operand' by 'const_int_operand' in many patterns
> > - Small cleanups in XTheadBb
> > - Factor out C code into thead.cc (XTheadMemPair) to minimize changes in
> >   riscv.cc
> >
> > Changes in v3:
> > - Bugfix in XTheadBa
> > - Rewrite of XTheadMemPair
> > - Inclusion of XTheadMemIdx and XTheadFMemIdx
> >
> > Christoph Müllner (9):
> >   riscv: Add basic XThead* vendor extension support
> >   riscv: riscv-cores.def: Add T-Head XuanTie C906
> >   riscv: thead: Add support for the XTheadBa ISA extension
> >   riscv: thead: Add support for the XTheadBs ISA extension
> >   riscv: thead: Add support for the XTheadBb ISA extension
> >   riscv: thead: Add support for the XTheadCondMov ISA extensions
> >   riscv: thead: Add support for the XTheadMac ISA extension
> >   riscv: thead: Add support for the XTheadFmv ISA extension
> >   riscv: thead: Add support for the XTheadMemPair ISA extension
> >
> >  gcc/common/config/riscv/riscv-common.cc   |  26 ++
> >  gcc/config.gcc|   1 +
> >  gcc/config/riscv/bitmanip.md  |  52 ++-
> >  gcc/config/riscv/constraints.md   |   8 +
> >  gcc/config/riscv/iterators.md |   4 +
> >  gcc/config/riscv/peephole.md  |  56 +++
> >  gcc/config/riscv/riscv-cores.def  |   4 +
> >  gcc/config/riscv/riscv-opts.h |  26 ++
> >  gcc/config/riscv/riscv-protos.h   |  16 +-
> >  gcc/config/riscv/riscv.cc | 226 +++--
> >  gcc/config/riscv/riscv.md |  67 ++-
> >  gcc/config/riscv/riscv.opt|   3 +
> >  gcc/config/riscv/t-riscv  |   4 +
> >  gcc/config/riscv/thead.cc | 427 ++
> >  gcc/config/riscv/thead.md | 346 ++
> >  .../gcc.target/riscv/mcpu-thead-c906.c|  28 ++
> >  .../gcc.target/riscv/xtheadba-addsl.c |  55 +++
> >  gcc/testsuite/gcc.target/riscv/xtheadba.c |  14 +
> >  gcc/testsuite/gcc.target/riscv/xtheadbb-ext.c |  20 +
> >  .../gcc.target/riscv/xtheadbb-extu-2.c|  22 +
> >  .../gcc.target/riscv/xtheadbb-extu.c  |  22 +
> >  gcc/testsuite/gcc.target/riscv/xtheadbb-ff1.c |  18 +
> >  gcc/testsuite/gcc.target/riscv/xtheadbb-rev.c |  45 ++
> >  .../gcc.target/riscv/xtheadbb-srri.c  |  25 +
> >  gcc/testsuite/gcc.target/riscv/xtheadbb.c |  14 +
> >  gcc/testsuite/gcc.target/riscv/xtheadbs-tst.c |  13 +
> >  gcc/testsuite/gcc.target/riscv/xtheadbs.c |  14 +
> >  gcc/testsuite/gcc.target/riscv/xtheadcmo.c|  14 +
> >  .../riscv/xtheadcondmov-mveqz-imm-eqz.c   |  38 ++
> >  .../riscv/xtheadcondmov-mveqz-imm-not.c   |  38 ++
> >  .../riscv/xtheadcondmov-mveqz-reg-eqz.c   |  38 ++
> >  .../riscv/xtheadcondmov-mveqz-reg-not.c   |  38 ++
> >  .../riscv/xtheadcondmov-mvnez-imm-cond.c  |  38 ++
> >  .../riscv/xtheadcondmov-mvnez-imm-nez.c   |  38 ++
> >  .../riscv/xtheadcondmov-mvnez-reg-cond.c  |  38 ++
> >  .../riscv/xtheadcondmov-mvnez-reg-nez.c   |  38 ++
> >  .../gcc.target/riscv/xtheadcondmov.c  |  14 

[PATCH v2] PR target/89828 Inernal compiler error on -fno-omit-frame-pointer

2023-03-15 Thread Yoshinori Sato
What about this?
It no longer occurs for me.

gcc/config/rx/
* rx.cc (add_pop_cfi_notes): Release the frame pointer if it is used.
(rx_expand_prologue): Redesigned stack pointer and frame pointer update 
process.

Signed-off-by: Yoshinori Sato 
---
 gcc/config/rx/rx.cc | 50 +++--
 1 file changed, 17 insertions(+), 33 deletions(-)

diff --git a/gcc/config/rx/rx.cc b/gcc/config/rx/rx.cc
index 412a3a354b0..51ef4a6be34 100644
--- a/gcc/config/rx/rx.cc
+++ b/gcc/config/rx/rx.cc
@@ -1647,16 +1647,20 @@ mark_frame_related (rtx insn)
 static void
 add_pop_cfi_notes (rtx_insn *insn, unsigned int high, unsigned int low)
 {
-  rtx t = plus_constant (Pmode, stack_pointer_rtx,
-(high - low + 1) * UNITS_PER_WORD);
+  rtx src = stack_pointer_rtx;
+  rtx t;
+  for (unsigned int i = low; i <= high; i++)
+{
+  add_reg_note (insn, REG_CFA_RESTORE, gen_rtx_REG (word_mode, i));
+  if (i == FRAME_POINTER_REGNUM && frame_pointer_needed)
+   src = frame_pointer_rtx;
+}
+  t = plus_constant (Pmode, src, (high - low + 1) * UNITS_PER_WORD);
   t = gen_rtx_SET (stack_pointer_rtx, t);
   add_reg_note (insn, REG_CFA_ADJUST_CFA, t);
   RTX_FRAME_RELATED_P (insn) = 1;
-  for (unsigned int i = low; i <= high; i++)
-add_reg_note (insn, REG_CFA_RESTORE, gen_rtx_REG (word_mode, i));
 }
 
-
 static bool
 ok_for_max_constant (HOST_WIDE_INT val)
 {
@@ -1815,37 +1819,17 @@ rx_expand_prologue (void)
}
 }
 
-  /* If needed, set up the frame pointer.  */
-  if (frame_pointer_needed)
-gen_safe_add (frame_pointer_rtx, stack_pointer_rtx,
- GEN_INT (- (HOST_WIDE_INT) frame_size), true);
-
-  /* Allocate space for the outgoing args.
- If the stack frame has not already been set up then handle this as well.  
*/
-  if (stack_size)
+  if (stack_size || frame_size)
 {
-  if (frame_size)
-   {
- if (frame_pointer_needed)
-   gen_safe_add (stack_pointer_rtx, frame_pointer_rtx,
- GEN_INT (- (HOST_WIDE_INT) stack_size), true);
- else
-   gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
- GEN_INT (- (HOST_WIDE_INT) (frame_size + stack_size)),
- true);
-   }
-  else
-   gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
- GEN_INT (- (HOST_WIDE_INT) stack_size), true);
+  gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
+   GEN_INT (- (HOST_WIDE_INT) (stack_size + frame_size)),
+   true);
 }
-  else if (frame_size)
+  if (frame_pointer_needed)
 {
-  if (! frame_pointer_needed)
-   gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
- GEN_INT (- (HOST_WIDE_INT) frame_size), true);
-  else
-   gen_safe_add (stack_pointer_rtx, frame_pointer_rtx, NULL_RTX,
- false /* False because the epilogue will use the FP not 
the SP.  */);
+  gen_safe_add (frame_pointer_rtx, stack_pointer_rtx,
+   GEN_INT ((HOST_WIDE_INT) stack_size),
+   true);
 }
 }
 
-- 
2.30.2



Re: Re: [PATCH] RISC-V: Fine tune gather load RA constraint

2023-03-15 Thread juzhe.zh...@rivai.ai
Hi, Jeff. I really hope the current "refine tune RA constraint" patches can be 
merged into GCC-13.
These patches are just making RA constraint to be consistent with RVV ISA after 
I double checked RVV ISA.
These RA constraints changing is very safe.
This is the last stuff that I want to make it into GCC-13. 

More patches I am gonna to send are going to expected to be merged into GCC-14.

Thanks.


juzhe.zh...@rivai.ai
 
From: Jeff Law
Date: 2023-03-15 02:08
To: juzhe.zhong; gcc-patches
CC: kito.cheng
Subject: Re: [PATCH] RISC-V: Fine tune gather load RA constraint
 
 
On 3/13/23 02:28, juzhe.zh...@rivai.ai wrote:
> From: Ju-Zhe Zhong 
> 
> For DEST EEW < SOURCE EEW, we can partial overlap register
> according to RVV ISA.
> 
> gcc/ChangeLog:
> 
>  * config/riscv/vector.md: Fix RA constraint.
> 
> gcc/testsuite/ChangeLog:
> 
>  * gcc.target/riscv/rvv/base/narrow_constraint-12.c: New test.
Similarly.  I think this can wait for gcc-14.
 
jeff
 


[PATCH] RISC-V: Fix bugs of ternary integer and floating-point ternary intrinsics.

2023-03-15 Thread juzhe . zhong
From: Ju-Zhe Zhong 

Fix bugs of ternary intrinsic pattern:

interger:
vnmsac.vv vd, vs1, vs2, vm# vd[i] = -(vs1[i] * vs2[i]) + vd[i]  (minus op3 
(mult op1 op2))
vnmsac.vx vd, rs1, vs2, vm# vd[i] = -(x[rs1] * vs2[i]) + vd[i]   (minus op3 
(mult op1 op2))

floating-point:
# FP multiply-accumulate, overwrites addend
vfmacc.vv vd, vs1, vs2, vm# vd[i] = +(vs1[i] * vs2[i]) + vd[i] (plus (mult 
(op1 op2)) op3)
vfmacc.vf vd, rs1, vs2, vm# vd[i] = +(f[rs1] * vs2[i]) + vd[i] (plus (mult 
(op1 op2)) op3)


# FP negate-(multiply-accumulate), overwrites subtrahend
vfnmacc.vv vd, vs1, vs2, vm   # vd[i] = -(vs1[i] * vs2[i]) - vd[i] (minus (neg 
(mult (op1 op2))) op3))
vfnmacc.vf vd, rs1, vs2, vm   # vd[i] = -(f[rs1] * vs2[i]) - vd[i] (minus (neg 
(mult (op1 op2)) op3))
# FP multiply-subtract-accumulator, overwrites subtrahend
vfmsac.vv vd, vs1, vs2, vm# vd[i] = +(vs1[i] * vs2[i]) - vd[i] (minus (mult 
(op1 op2)) op3)
vfmsac.vf vd, rs1, vs2, vm# vd[i] = +(f[rs1] * vs2[i]) - vd[i] (minus (mult 
(op1 op2)) op3)

# FP negate-(multiply-subtract-accumulator), overwrites minuend
vfnmsac.vv vd, vs1, vs2, vm   # vd[i] = -(vs1[i] * vs2[i]) + vd[i] (plus 
(neg:(mult (op1 op2))) op3)
vfnmsac.vf vd, rs1, vs2, vm   # vd[i] = -(f[rs1] * vs2[i]) + vd[i] (plus 
(neg:(mult (op1 op2))) op3)

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins-bases.cc: Fix ternary bug.
* config/riscv/vector-iterators.md (nmsac): Ditto.
(nmsub): Ditto.
(msac): Ditto.
(msub): Ditto.
(nmadd): Ditto.
(nmacc): Ditto.
* config/riscv/vector.md (@pred_mul_): Ditto.
(@pred_mul_plus): Ditto.
(*pred_madd): Ditto.
(*pred_macc): Ditto.
(*pred_mul_plus): Ditto.
(@pred_mul_plus_scalar): Ditto.
(*pred_madd_scalar): Ditto.
(*pred_macc_scalar): Ditto.
(*pred_mul_plus_scalar): Ditto.
(*pred_madd_extended_scalar): Ditto.
(*pred_macc_extended_scalar): Ditto.
(*pred_mul_plus_extended_scalar): Ditto.
(@pred_minus_mul): Ditto.
(*pred_): Ditto.
(*pred_nmsub): Ditto.
(*pred_): Ditto.
(*pred_nmsac): Ditto.
(*pred_mul_): Ditto.
(*pred_minus_mul): Ditto.
(@pred_mul__scalar): Ditto.
(@pred_minus_mul_scalar): Ditto.
(*pred__scalar): Ditto.
(*pred_nmsub_scalar): Ditto.
(*pred__scalar): Ditto.
(*pred_nmsac_scalar): Ditto.
(*pred_mul__scalar): Ditto.
(*pred_minus_mul_scalar): Ditto.
(*pred__extended_scalar): Ditto.
(*pred_nmsub_extended_scalar): Ditto.
(*pred__extended_scalar): Ditto.
(*pred_nmsac_extended_scalar): Ditto.
(*pred_mul__extended_scalar): Ditto.
(*pred_minus_mul_extended_scalar): Ditto.
(*pred_): Ditto.
(*pred_): Ditto.
(*pred__scalar): Ditto.
(*pred__scalar): Ditto.
(@pred_neg_mul_): Ditto.
(@pred_mul_neg_): Ditto.
(*pred_): Ditto.
(*pred_): Ditto.
(*pred_): Ditto.
(*pred_): Ditto.
(*pred_neg_mul_): Ditto.
(*pred_mul_neg_): Ditto.
(@pred_neg_mul__scalar): Ditto.
(@pred_mul_neg__scalar): Ditto.
(*pred__scalar): Ditto.
(*pred__scalar): Ditto.
(*pred__scalar): Ditto.
(*pred__scalar): Ditto.
(*pred_neg_mul__scalar): Ditto.
(*pred_mul_neg__scalar): Ditto.
(@pred_widen_neg_mul_): Ditto.
(@pred_widen_mul_neg_): Ditto.
(@pred_widen_neg_mul__scalar): Ditto.
(@pred_widen_mul_neg__scalar): Ditto.

---
 .../riscv/riscv-vector-builtins-bases.cc  |  80 +-
 gcc/config/riscv/vector-iterators.md  |   8 +-
 gcc/config/riscv/vector.md| 745 ++
 3 files changed, 621 insertions(+), 212 deletions(-)

diff --git a/gcc/config/riscv/riscv-vector-builtins-bases.cc 
b/gcc/config/riscv/riscv-vector-builtins-bases.cc
index 3f0f809c714..839eb66efb2 100644
--- a/gcc/config/riscv/riscv-vector-builtins-bases.cc
+++ b/gcc/config/riscv/riscv-vector-builtins-bases.cc
@@ -627,12 +627,11 @@ public:
   rtx expand (function_expander ) const override
   {
 if (e.op_info->op == OP_TYPE_vx)
-  return e.use_ternop_insn (true,
-   code_for_pred_mul_scalar (PLUS,
- e.vector_mode ()));
+  return e.use_ternop_insn (true, code_for_pred_mul_plus_scalar (
+   e.vector_mode ()));
 if (e.op_info->op == OP_TYPE_vv)
   return e.use_ternop_insn (true,
-   code_for_pred_mul (PLUS, e.vector_mode ()));
+   code_for_pred_mul_plus (e.vector_mode ()));
 gcc_unreachable ();
   }
 };
@@ -645,12 +644,11 @@ public:
   rtx expand (function_expander ) const override
   {
 if (e.op_info->op == OP_TYPE_vx)
-  return e.use_ternop_insn (true,
-