Re: [PATCH] Don't add crtfastmath.o for -shared.

2023-01-16 Thread Hongtao Liu via Gcc-patches
On Fri, Jan 13, 2023 at 5:56 PM liuhongt  wrote:
>
> Patches [1] and [2] fixed PR55522 for x86-linux but left all other x86
> targets unfixed (x86-cygwin, x86-darwin and x86-mingw32).
> This patch applies a similar change to other specs using crtfastmath.o.
>
> Ok for trunk?
>
The patches in [1],[2] are already approved, and these 2 patches just
apply them to other 3 targets, so I assume it should be ok, and i'm
going to push the patch to trunk.
> [1] https://gcc.gnu.org/pipermail/gcc-patches/2022-December/608528.html
> [2] https://gcc.gnu.org/pipermail/gcc-patches/2022-December/608529.html
>
> gcc/ChangeLog:
>
> PR target/55522
> * config/i386/cygwin.h (ENDFILE_SPEC): Link crtfastmath.o
> whenever -mdaz-ftz is specified. Don't link crtfastmath.o when
> -share or -mno-daz-ftz is specified.
> * config/i386/darwin.h (ENDFILE_SPEC): Ditto.
> * config/i386/mingw32.h (ENDFILE_SPEC): Ditto.
> ---
>  gcc/config/i386/cygwin.h  | 2 +-
>  gcc/config/i386/darwin.h  | 2 +-
>  gcc/config/i386/mingw32.h | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/config/i386/cygwin.h b/gcc/config/i386/cygwin.h
> index 0a604d65b32..d795ee1e3c5 100644
> --- a/gcc/config/i386/cygwin.h
> +++ b/gcc/config/i386/cygwin.h
> @@ -48,7 +48,7 @@ along with GCC; see the file COPYING3.  If not see
>
>  #undef ENDFILE_SPEC
>  #define ENDFILE_SPEC \
> -  "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}\
> +  
> "%{mdaz-ftz:crtfastmath.o%s;Ofast|ffast-math|funsafe-math-optimizations:%{!shared:%{!mno-daz-ftz:crtfastmath.o%s}}}
>  \
> %{!shared:%:if-exists(default-manifest.o%s)}\
> %{fvtable-verify=none:%s; \
>  fvtable-verify=preinit:vtv_end.o%s; \
> diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h
> index 5bcb714..ac198db0d9c 100644
> --- a/gcc/config/i386/darwin.h
> +++ b/gcc/config/i386/darwin.h
> @@ -110,7 +110,7 @@ along with GCC; see the file COPYING3.  If not see
>
>  #undef ENDFILE_SPEC
>  #define ENDFILE_SPEC \
> -  "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
> +  
> "%{mdaz-ftz:crtfastmath.o%s;Ofast|ffast-math|funsafe-math-optimizations:%{!shared:%{!mno-daz-ftz:crtfastmath.o%s}}}
>  \
> %{mpc32:crtprec32.o%s} \
> %{mpc64:crtprec64.o%s} \
> %{mpc80:crtprec80.o%s}" TM_DESTRUCTOR
> diff --git a/gcc/config/i386/mingw32.h b/gcc/config/i386/mingw32.h
> index 19a98c3d995..4e5b486a3da 100644
> --- a/gcc/config/i386/mingw32.h
> +++ b/gcc/config/i386/mingw32.h
> @@ -196,7 +196,7 @@ along with GCC; see the file COPYING3.  If not see
>
>  #undef ENDFILE_SPEC
>  #define ENDFILE_SPEC \
> -  "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
> +  
> "%{mdaz-ftz:crtfastmath.o%s;Ofast|ffast-math|funsafe-math-optimizations:%{!shared:%{!mno-daz-ftz:crtfastmath.o%s}}}
>  \
> %{!shared:%:if-exists(default-manifest.o%s)}\
> %{fvtable-verify=none:%s; \
>  fvtable-verify=preinit:vtv_end.o%s; \
> --
> 2.31.1
>


-- 
BR,
Hongtao


[PATCH] xtensa: Eliminate unnecessary general-purpose reg-reg moves

2023-01-16 Thread Takayuki 'January June' Suwa via Gcc-patches
Register-register move instructions that can be easily seen as
unnecessary by the human eye may remain in the compiled result.
For example:

/* example */
double test(double a, double b) {
  return __builtin_copysign(a, b);
}

test:
add.n   a3, a3, a3
extui   a5, a5, 31, 1
ssai1
;; be in the same BB
src a7, a5, a3  ;; No '0' in the source constraints
;; No CALL insns in this span
;; Both A3 and A7 are irrelevant to
;;   insns in this span
mov.n   a3, a7  ;; An unnecessary reg-reg move
;; A7 is not used after this
ret.n

The last two instructions above, excluding the return instruction,
could be done like this:

src a3, a5, a3

This symptom often occurs when handling DI/DFmode values with SImode
instructions.  This patch solves the above problem using peephole2
pattern.

gcc/ChangeLog:

* config/xtensa/xtensa.md: New peephole2 pattern that eliminates
the occurrence of genral-purpose register used only once and for
transferring intermediate value.
---
 gcc/config/xtensa/xtensa.md | 44 +
 1 file changed, 44 insertions(+)

diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
index 61bbad8e4..1b53c8c9e 100644
--- a/gcc/config/xtensa/xtensa.md
+++ b/gcc/config/xtensa/xtensa.md
@@ -3089,3 +3089,47 @@ FALLTHRU:;
   df_insn_rescan (insnR);
   set_insn_deleted (insnP);
 })
+
+(define_peephole2
+  [(set (match_operand 0 "register_operand")
+   (match_operand 1 "register_operand"))]
+  "GET_MODE_SIZE (GET_MODE (operands[0])) == 4
+   && GET_MODE_SIZE (GET_MODE (operands[1])) == 4
+   && GP_REG_P (REGNO (operands[0])) && GP_REG_P (REGNO (operands[1]))
+   && peep2_reg_dead_p (1, operands[1])"
+  [(const_int 0)]
+{
+  basic_block bb = BLOCK_FOR_INSN (curr_insn);
+  rtx dest = operands[0], src = operands[1], pattern, t_dest;
+  rtx_insn *insn;
+  int i;
+  for (insn = PREV_INSN (curr_insn);
+   insn && BLOCK_FOR_INSN (insn) == bb;
+   insn = PREV_INSN (insn))
+if (CALL_P (insn))
+  break;
+else if (INSN_P (insn))
+  {
+   if (GET_CODE (pattern = PATTERN (insn)) == SET
+   && REG_P (t_dest = SET_DEST (pattern))
+   && GET_MODE_SIZE (GET_MODE (t_dest)) == 4
+   && REGNO (t_dest) == REGNO (src)
+   && ! REG_P (SET_SRC (pattern)))
+   {
+ extract_constrain_insn (insn);
+ for (i = 1; i < recog_data.n_operands; ++i)
+   if (strchr (recog_data.constraints[i], '0'))
+ goto ABORT;
+ SET_REGNO (t_dest, REGNO (dest));
+ goto FALLTHRU;
+   }
+   if (reg_overlap_mentioned_p (dest, pattern)
+   || reg_overlap_mentioned_p (src, pattern)
+   || set_of (dest, insn)
+   || set_of (src, insn))
+ break;
+  }
+ABORT:
+  FAIL;
+FALLTHRU:;
+})
-- 
2.30.2


[PATCH v2] xtensa: Eliminate the use of callee-saved register that saves and restores only once

2023-01-16 Thread Takayuki 'January June' Suwa via Gcc-patches
In the case of the CALL0 ABI, values that must be retained before and
after function calls are placed in the callee-saved registers (A12
through A15) and referenced later.  However, it is often the case that
the save and the reference are each only once and a simple register-
register move (the frame pointer is needed to recover the stack pointer
and must be excluded).

e.g. in the following example, if there are no other occurrences of
register A14:

;; before
; prologue {
  ...
s32i.n  a14, sp, 16
  ...
; } prologue
  ...
mov.n   a14, a6
  ...
call0   foo
  ...
mov.n   a8, a14
  ...
; epilogue {
  ...
l32i.n  a14, sp, 16
  ...
; } epilogue

It can be possible like this:

;; after
; prologue {
  ...
(deleted)
  ...
; } prologue
  ...
s32i.n  a6, sp, 16
  ...
call0   foo
  ...
l32i.n  a8, sp, 16
  ...
; epilogue {
  ...
(deleted)
  ...
; } epilogue

This patch introduces a new peephole2 pattern that implements the above.

gcc/ChangeLog:

* config/xtensa/xtensa.md: New peephole2 pattern that eliminates
the use of callee-saved register that saves and restores only once
for other register, by using its stack slot directly.
---
 gcc/config/xtensa/xtensa.md | 60 +
 1 file changed, 60 insertions(+)

diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
index 98f3c468f8b..fc512346741 100644
--- a/gcc/config/xtensa/xtensa.md
+++ b/gcc/config/xtensa/xtensa.md
@@ -3024,3 +3024,63 @@ FALLTHRU:;
   operands[1] = GEN_INT (imm0);
   operands[2] = GEN_INT (imm1);
 })
+
+(define_peephole2
+  [(set (match_operand:SI 0 "register_operand")
+   (match_operand:SI 1 "reload_operand"))]
+  "!TARGET_WINDOWED_ABI && df
+   && epilogue_contains (insn)
+   && ! call_used_or_fixed_reg_p (REGNO (operands[0]))
+   && (!frame_pointer_needed
+   || REGNO (operands[0]) != HARD_FRAME_POINTER_REGNUM)"
+  [(const_int 0)]
+{
+  rtx reg = operands[0], pattern;
+  rtx_insn *insnP = NULL, *insnS = NULL, *insnR = NULL;
+  df_ref ref;
+  rtx_insn *insn;
+  for (ref = DF_REG_DEF_CHAIN (REGNO (reg));
+   ref; ref = DF_REF_NEXT_REG (ref))
+if (DF_REF_CLASS (ref) != DF_REF_REGULAR)
+  continue;
+else if ((insn = DF_REF_INSN (ref)) == curr_insn)
+  continue;
+else if (GET_CODE (pattern = PATTERN (insn)) == SET
+&& rtx_equal_p (SET_DEST (pattern), reg)
+&& REG_P (SET_SRC (pattern)))
+  {
+   if (insnS)
+ FAIL;
+   insnS = insn;
+   continue;
+  }
+else
+  FAIL;
+  for (ref = DF_REG_USE_CHAIN (REGNO (reg));
+   ref; ref = DF_REF_NEXT_REG (ref))
+if (DF_REF_CLASS (ref) != DF_REF_REGULAR)
+  continue;
+else if (prologue_contains (insn = DF_REF_INSN (ref)))
+  {
+   insnP = insn;
+   continue;
+  }
+else if (GET_CODE (pattern = PATTERN (insn)) == SET
+&& rtx_equal_p (SET_SRC (pattern), reg)
+&& REG_P (SET_DEST (pattern)))
+  {
+   if (insnR)
+ FAIL;
+   insnR = insn;
+   continue;
+  }
+else
+  FAIL;
+  if (!insnP || !insnS || !insnR)
+FAIL;
+  SET_DEST (PATTERN (insnS)) = copy_rtx (operands[1]);
+  df_insn_rescan (insnS);
+  SET_SRC (PATTERN (insnR)) = copy_rtx (operands[1]);
+  df_insn_rescan (insnR);
+  set_insn_deleted (insnP);
+})
-- 
2.30.2


Re: [PATCH] rs6000: Teach rs6000_opaque_type_invalid_use_p about gcall [PR108348]

2023-01-16 Thread Kewen.Lin via Gcc-patches
Hi Segher,

on 2023/1/16 23:24, Segher Boessenkool wrote:
> On Mon, Jan 16, 2023 at 09:05:38PM +0800, Kewen.Lin wrote:
>>> The *_ok things should only be used for features that can be disabled
>>> during configuration, or features that we *want* users to be able to
>>> turn off (like FP, VMX, VSX, or HMT or QP float, that kind of thing).
>>> That gives quite enough permutations to test already, we do not need to
>>> create a whole bunch extra for no reason :-)
>>
>> Thanks for the explanation!!  I meant to use powerpc_p9modulo_ok to
>> exclude those cases where we can't use -mcpu=power9, as you explained we
>> should not worry about it!?
> 
> But that selector says whether modulo insns are enabled.  This is not
> correct to use here.  I know we have abused these things before, but it
> needs to be untangled, not made worse :-)

Makes sense, thanks for further clarifying!

> 
>> Since the test point requires altivec support
>> (which is implied when specifying -mcpu=power9, I didn't explicitly specify
>> it before), I think I could use powerpc_altivec_ok to replace
>> powerpc_p9modulo_ok here, does it sound good to you?
> 
> VMX can be turned off even with -mcpu=power9.  So yes, it does need
> powerpc_altivec_ok.  Does it need VSX even?

I think we don't need to check VSX here.

Checking VMX is for robustness and ensure it's consistent with the comment:

  /* Allow -maltivec -mabi=no-altivec without warning.  Altivec vector
 modes only exist for GCC vector types if -maltivec.  */
  if (TARGET_32BIT && !TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (arg.mode))
{
  if (TARGET_DEBUG_ARG)
fprintf (stderr, "function_arg_pass_by_reference: AltiVec\n");
  return 1;
}

BR,
Kewen


[PATCH] ada: Respect GNATMAKE

2023-01-16 Thread Peter Foley
Use the GNATMAKE variables consistently.
Avoids failures when bootstraping with a custom GNATMAKE value.

gcc/ada/ChangeLog:

* Make-generated.in: Use GNATMAKE.
* gcc-interface/Makefile.in: Ditto.

Signed-off-by: Peter Foley 
---
 gcc/ada/Make-generated.in | 6 +++---
 gcc/ada/gcc-interface/Makefile.in | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/Make-generated.in b/gcc/ada/Make-generated.in
index 948fc508a56..34c86b2cd63 100644
--- a/gcc/ada/Make-generated.in
+++ b/gcc/ada/Make-generated.in
@@ -18,7 +18,7 @@ GEN_IL_FLAGS = -gnata -gnat2012 -gnatw.g -gnatyg -gnatU 
$(GEN_IL_INCLUDES)
 ada/seinfo_tables.ads ada/seinfo_tables.adb ada/sinfo.h ada/einfo.h 
ada/nmake.ads ada/nmake.adb ada/seinfo.ads ada/sinfo-nodes.ads 
ada/sinfo-nodes.adb ada/einfo-entities.ads ada/einfo-entities.adb: 
ada/stamp-gen_il ; @true
 ada/stamp-gen_il: $(fsrcdir)/ada/gen_il*
$(MKDIR) ada/gen_il
-   cd ada/gen_il; gnatmake -q -g $(GEN_IL_FLAGS) gen_il-main
+   cd ada/gen_il; $(GNATMAKE) -q -g $(GEN_IL_FLAGS) gen_il-main
# Ignore errors to work around finalization issues in older compilers
- cd ada/gen_il; ./gen_il-main
$(fsrcdir)/../move-if-change ada/gen_il/seinfo_tables.ads 
ada/seinfo_tables.ads
@@ -39,14 +39,14 @@ ada/stamp-gen_il: $(fsrcdir)/ada/gen_il*
 # would cause bootstrapping with older compilers to fail. You can call it by
 # hand, as a sanity check that these files are legal.
 ada/seinfo_tables.o: ada/seinfo_tables.ads ada/seinfo_tables.adb
-   cd ada ; gnatmake $(GEN_IL_INCLUDES) seinfo_tables.adb -gnatU -gnatX
+   cd ada ; $(GNATMAKE) $(GEN_IL_INCLUDES) seinfo_tables.adb -gnatU -gnatX
 
 ada/snames.h ada/snames.ads ada/snames.adb : ada/stamp-snames ; @true
 ada/stamp-snames : ada/snames.ads-tmpl ada/snames.adb-tmpl ada/snames.h-tmpl 
ada/xsnamest.adb ada/xutil.ads ada/xutil.adb
-$(MKDIR) ada/bldtools/snamest
$(RM) $(addprefix ada/bldtools/snamest/,$(notdir $^))
$(CP) $^ ada/bldtools/snamest
-   cd ada/bldtools/snamest; gnatmake -q xsnamest ; ./xsnamest
+   cd ada/bldtools/snamest; $(GNATMAKE) -q xsnamest ; ./xsnamest
$(fsrcdir)/../move-if-change ada/bldtools/snamest/snames.ns 
ada/snames.ads
$(fsrcdir)/../move-if-change ada/bldtools/snamest/snames.nb 
ada/snames.adb
$(fsrcdir)/../move-if-change ada/bldtools/snamest/snames.nh ada/snames.h
diff --git a/gcc/ada/gcc-interface/Makefile.in 
b/gcc/ada/gcc-interface/Makefile.in
index da6a56fcec8..c8c38acf447 100644
--- a/gcc/ada/gcc-interface/Makefile.in
+++ b/gcc/ada/gcc-interface/Makefile.in
@@ -616,7 +616,7 @@ OSCONS_EXTRACT=$(GCC_FOR_ADA_RTS) $(GNATLIBCFLAGS_FOR_C) -S 
s-oscons-tmplt.i
-$(MKDIR) ./bldtools/oscons
$(RM) $(addprefix ./bldtools/oscons/,$(notdir $^))
$(CP) $^ ./bldtools/oscons
-   (cd ./bldtools/oscons ; gnatmake -q xoscons)
+   (cd ./bldtools/oscons ; $(GNATMAKE) -q xoscons)
 
 $(RTSDIR)/s-oscons.ads: ../stamp-gnatlib1-$(RTSDIR) s-oscons-tmplt.c gsocket.h 
./bldtools/oscons/xoscons
$(RM) $(RTSDIR)/s-oscons-tmplt.i $(RTSDIR)/s-oscons-tmplt.s
-- 
2.39.0



Re: [PATCH v2] configure: Only create serdep.tmp if needed

2023-01-16 Thread Jeff Law via Gcc-patches




On 1/16/23 18:12, Peter Foley wrote:

There's no reason to create this file if none of the serial configure
options are passed.

v2: Use test instead of [ to avoid running afoul of autoconf quoting.

ChangeLog:

* configure: Regenerate.
* configure.ac: Only create serdep.tmp if needed
Note I think this should be deferred to gcc-14 given that gcc-13 is in 
regression bugfixes only stage right now.


jeff


[PATCH v2] configure: Only create serdep.tmp if needed

2023-01-16 Thread Peter Foley
There's no reason to create this file if none of the serial configure
options are passed.

v2: Use test instead of [ to avoid running afoul of autoconf quoting.

ChangeLog:

* configure: Regenerate.
* configure.ac: Only create serdep.tmp if needed

Signed-off-by: Peter Foley 
---
 configure| 2 ++
 configure.ac | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/configure b/configure
index 85883099410..0494e2fa2bf 100755
--- a/configure
+++ b/configure
@@ -9918,7 +9918,9 @@ esac
 # These force 'configure's to be done one at a time, to avoid problems
 # with contention over a shared config.cache.
 rm -f serdep.tmp
+if test "x${enable_serial_build_configure}" = xyes || test 
"x${enable_serial_host_configure}" = xyes || test 
"x${enable_serial_target_configure}" = xyes; then
 echo '# serdep.tmp' > serdep.tmp
+fi
 olditem=
 test "x${enable_serial_build_configure}" = xyes &&
 for item in ${build_configdirs} ; do
diff --git a/configure.ac b/configure.ac
index 2b612dce6e9..f5cce5830bc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3071,7 +3071,9 @@ esac
 # These force 'configure's to be done one at a time, to avoid problems
 # with contention over a shared config.cache.
 rm -f serdep.tmp
+if test "x${enable_serial_build_configure}" = xyes || test 
"x${enable_serial_host_configure}" = xyes || test 
"x${enable_serial_target_configure}" = xyes; then
 echo '# serdep.tmp' > serdep.tmp
+fi
 olditem=
 test "x${enable_serial_build_configure}" = xyes &&
 for item in ${build_configdirs} ; do
-- 
2.39.0



Re: [PATCH v5] LoongArch: Fixed a compilation failure with '%c' in inline assembly [PR107731].

2023-01-16 Thread Lulu Cheng

Ping?

在 2023/1/13 上午11:27, Lulu Cheng 写道:

Co-authored-by: Yang Yujie 

gcc/ChangeLog:

* config/loongarch/loongarch.cc (loongarch_classify_address):
Add precessint for CONST_INT.
(loongarch_print_operand_reloc): Operand modifier 'c' is supported.
(loongarch_print_operand): Increase the processing of '%c'.
* doc/extend.texi: Adds documents for LoongArch operand modifiers.
And port the public operand modifiers information to this document.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/tst-asm-const.c: Moved to...
* gcc.target/loongarch/pr107731.c: ...here.

---
V2 -> v3:
1. Correct a clerical error.
2. Adding document for loongarch operand modifiers.

v3 -> v4:
Copy the description of "%c" "%n" "%a" "%l" from gccint.pdf to gcc.pdf.

v4 -> v5:
Move the operand modifiers description of "%c", "%n", "%a", "%l" to the top of 
the
x86Operandmodifiers section.

---
  gcc/config/loongarch/loongarch.cc |  14 ++
  gcc/doc/extend.texi   | 135 --
  .../loongarch/{tst-asm-const.c => pr107731.c} |   6 +-
  3 files changed, 106 insertions(+), 49 deletions(-)
  rename gcc/testsuite/gcc.target/loongarch/{tst-asm-const.c => pr107731.c} 
(78%)

diff --git a/gcc/config/loongarch/loongarch.cc 
b/gcc/config/loongarch/loongarch.cc
index c6b03fcf2f9..cdf190b985e 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -2075,6 +2075,11 @@ loongarch_classify_address (struct 
loongarch_address_info *info, rtx x,
return (loongarch_valid_base_register_p (info->reg, mode, strict_p)
  && loongarch_valid_lo_sum_p (info->symbol_type, mode,
   info->offset));
+case CONST_INT:
+  /* Small-integer addresses don't occur very often, but they
+are legitimate if $r0 is a valid base register.  */
+  info->type = ADDRESS_CONST_INT;
+  return IMM12_OPERAND (INTVAL (x));
  
  default:

return false;
@@ -4933,6 +4938,7 @@ loongarch_print_operand_reloc (FILE *file, rtx op, bool 
hi64_part,
  
 'A'	Print a _DB suffix if the memory model requires a release.

 'b'Print the address of a memory operand, without offset.
+   'c'  Print an integer.
 'C'Print the integer branch condition for comparison OP.
 'd'Print CONST_INT OP in decimal.
 'F'Print the FPU branch condition for comparison OP.
@@ -4979,6 +4985,14 @@ loongarch_print_operand (FILE *file, rtx op, int letter)
 fputs ("_db", file);
break;
  
+case 'c':

+  if (CONST_INT_P (op))
+   fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (op));
+  else
+   output_operand_lossage ("unsupported operand for code '%c'", letter);
+
+  break;
+
  case 'C':
loongarch_print_int_branch_condition (file, code, letter);
break;
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 1103e9936f7..256811cb8f5 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -10402,8 +10402,10 @@ ensures that modifying @var{a} does not affect the 
address referenced by
  is undefined if @var{a} is modified before using @var{b}.
  
  @code{asm} supports operand modifiers on operands (for example @samp{%k2}

-instead of simply @samp{%2}). Typically these qualifiers are hardware
-dependent. The list of supported modifiers for x86 is found at
+instead of simply @samp{%2}). @ref{GenericOperandmodifiers,
+Generic Operand modifiers} lists the modifiers that are available
+on all targets.  Other modifiers are hardware dependent.
+For example, the list of supported modifiers for x86 is found at
  @ref{x86Operandmodifiers,x86 Operand modifiers}.
  
  If the C code that follows the @code{asm} makes no use of any of the output

@@ -10671,8 +10673,10 @@ optimizers may discard the @code{asm} statement as 
unneeded
  (see @ref{Volatile}).
  
  @code{asm} supports operand modifiers on operands (for example @samp{%k2}

-instead of simply @samp{%2}). Typically these qualifiers are hardware
-dependent. The list of supported modifiers for x86 is found at
+instead of simply @samp{%2}). @ref{GenericOperandmodifiers,
+Generic Operand modifiers} lists the modifiers that are available
+on all targets.  Other modifiers are hardware dependent.
+For example, the list of supported modifiers for x86 is found at
  @ref{x86Operandmodifiers,x86 Operand modifiers}.
  
  In this example using the fictitious @code{combine} instruction, the

@@ -11024,9 +11028,8 @@ lab:
  @}
  @end example
  
-@anchor{x86Operandmodifiers}

-@subsubsection x86 Operand Modifiers
-
+@anchor{GenericOperandmodifiers}
+@subsubsection Generic Operand Modifiers
  References to input, output, and goto operands in the assembler template
  of extended @code{asm} statements can use
  modifiers to affect the way the operands are formatted in
@@ -11045,48 +11048,31 @@ These modifiers generate this assembler code:
  xchg %ah, %al
  

[COMMITTED] Remove reference to Solaris 9 in comment of add_options_for_tls

2023-01-16 Thread Andrew Pinski via Gcc-patches
Since r5-172-gd9f069ab4f6450, the code no longer matches the
comment as the code for Solaris 9 support was removed.
This just updates the comment to reference AIX only as
the code does.

Committed as obvious.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp (add_options_for_tls): Remove
reference to Solaris 9 in comments.
---
 gcc/testsuite/lib/target-supports.exp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index b906d4004be..38b95145117 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -869,8 +869,8 @@ proc check_effective_target_pcc_bitfield_type_matters { } {
 # Add to FLAGS all the target-specific flags needed to use thread-local 
storage.
 
 proc add_options_for_tls { flags } {
-# On Solaris 9, __tls_get_addr/___tls_get_addr only lives in
-# libthread, so always pass -pthread for native TLS. Same for AIX.
+# On AIX, __tls_get_addr/___tls_get_addr only lives in
+# libthread, so always pass -pthread for native TLS.
 # Need to duplicate native TLS check from
 # check_effective_target_tls_native to avoid recursion.
 if { ([istarget powerpc-ibm-aix*]) &&
-- 
2.17.1



Re: [wwwdocs] gcc-12/changes.html: OpenMP - mention masked support

2023-01-16 Thread Gerald Pfeifer
On Fri, 13 Aug 2021, Tobias Burnus wrote:
> Update the OpenMP section again, now that Jakub has added the 'masked'
> construct.
> 
> Comments?

Just a little follow-up change that I pushed; see below.

Ger "blast from the past" ald


commit dcb59089cf4bd7f09f273d7b3f35c568b1d407fb
Author: Gerald Pfeifer 
Date:   Tue Jan 17 00:37:11 2023 +0100

gcc-12: Address grammaro in OpenMP section

diff --git a/htdocs/gcc-12/changes.html b/htdocs/gcc-12/changes.html
index 1cefaf13..06c63c2f 100644
--- a/htdocs/gcc-12/changes.html
+++ b/htdocs/gcc-12/changes.html
@@ -162,7 +162,7 @@ You may also want to check out our
   master directive have been added.
 The following OpenMP 5.1 features have been added: support for
   expressing OpenMP directives as C++ 11 attributes, the 
masked
-  and scope construct, the nothing and
+  and scope constructs, the nothing and
   error directives, and using primary with the
   proc_bind clause and OMP_PROC_BIND environment
   variable, the reproducible and unconstrained


Re: [wwwdocs] gcc-13/changes.html + projects/gomp/: OpenMP update

2023-01-16 Thread Gerald Pfeifer
Hi Tobias,

On Mon, 16 Jan 2023, Tobias Burnus wrote:
>> requires_offload, unified_address
>> -  and unified_shared_memory clauses cause that the
>> -  only available device is the initial device (the host). Fortran now
>> +  and unified_shared_memory clauses imply the initial
>> +  device (= the host) as the only available device. Fortran now
> I really stumble over the "as" – that sounds wrong and I fail to parse this
> part.
> I think it should be "is".

happy to make this change. Or do you have an idea to reframe the 
sentence (or paragraph) altogether?

(I'm not an expert in that area and so find your description quite
helpful. And based on that "as" -> "is" seems to be sufficient?)

What is your recommendation?

> BTW: Before the release, further updates to changes.html are required.

Keep them coming! :-)

Thanks,
Gerald


gcc-snapshot: FTBFS on hurd-i386 (and other archs?)

2023-01-16 Thread Svante Signell via Gcc-patches
Source: gcc-snapshot
Version: 20230108-1
Severity: important
Tags: patch
User: debian-h...@lists.debian.org
Usertags: hurd
X-Debbugs-CC: debian-h...@lists.debian.org

Hi,

gcc-snapshot in sid FTBFS on hurd-i386 due to that some patches are not
applied when building gcc-snapshot. After the statement in rules.patch
ifeq ($(single_package),yes)
  debian_patches =
endif
previously defined patches are cleared, causing the build failure, see
below.

debian/ files causing the problem:

debian/rules.defs:
ifneq (,$(findstring gcc-snapshot, $(PKGSOURCE)))
  single_package = yes
  trunk_build = yes

debian/rules.patch:
ifeq ($(single_package),yes)
  debian_patches =
endif

Thanks!




[PATCH] Fortran: fix ICE in check_charlen_present [PR108420]

2023-01-16 Thread Harald Anlauf via Gcc-patches
Dear all,

it appears that the fix for pr107874 uncovered a latent bug
for the case of arrays of type character and size zero when
passed to the intrinsics MERGE and SPREAD as SOURCE.  In that
case, there is no constructor from which we could obtain
another character length.  A reasonable solution seems to
retain the array's character length.

Since I could not find a simple case where this fails, I've
added an assertion that we actually have a meaningful length.

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

Thanks,
Harald

From a4fbab560a202f4541f8f9a872774b2cbf72b4b0 Mon Sep 17 00:00:00 2001
From: Harald Anlauf 
Date: Mon, 16 Jan 2023 21:41:09 +0100
Subject: [PATCH] Fortran: fix ICE in check_charlen_present [PR108420]

gcc/fortran/ChangeLog:

	PR fortran/108420
	* iresolve.cc (check_charlen_present): Preserve character length if
	there is no array constructor.

gcc/testsuite/ChangeLog:

	PR fortran/108420
	* gfortran.dg/pr108420.f90: New test.
---
 gcc/fortran/iresolve.cc|  9 ++---
 gcc/testsuite/gfortran.dg/pr108420.f90 | 10 ++
 2 files changed, 16 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr108420.f90

diff --git a/gcc/fortran/iresolve.cc b/gcc/fortran/iresolve.cc
index 711e9178ad4..33794f0a858 100644
--- a/gcc/fortran/iresolve.cc
+++ b/gcc/fortran/iresolve.cc
@@ -94,9 +94,12 @@ check_charlen_present (gfc_expr *source)
   else if (source->expr_type == EXPR_ARRAY)
 {
   gfc_constructor *c = gfc_constructor_first (source->value.constructor);
-  source->ts.u.cl->length
-		= gfc_get_int_expr (gfc_charlen_int_kind, NULL,
-c->expr->value.character.length);
+  if (c)
+	source->ts.u.cl->length
+	  = gfc_get_int_expr (gfc_charlen_int_kind, NULL,
+			  c->expr->value.character.length);
+  if (source->ts.u.cl->length == NULL)
+	gfc_internal_error ("check_charlen_present(): length not set");
 }
 }

diff --git a/gcc/testsuite/gfortran.dg/pr108420.f90 b/gcc/testsuite/gfortran.dg/pr108420.f90
new file mode 100644
index 000..985c0b3bf53
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr108420.f90
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! PR fortran/108420
+! Contributed by G.Steinmetz
+
+program p
+  character :: c = 'c'
+  logical   :: m = .true.
+  print *, merge(transfer('a', 'b', 0), c, .true.)
+  print *, merge(transfer('a', 'b', 0), c, m)
+end
--
2.35.3



[PATCH] Fortran: fix ICE in get_expr_storage_size [PR108421]

2023-01-16 Thread Harald Anlauf via Gcc-patches
Dear all,

here's an obvious patch for an ICE-on-invalid where we missed
a check that we actually have an integer length before trying
to extract a usable value.

Regtested on x86_64-pc-linux-gnu.

I intend to commit it to mainline within the next 24h unless
there are comments.

Cheers,
Harald

diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc
index c4f7faaf597..307082b048d 100644
--- a/gcc/fortran/interface.cc
+++ b/gcc/fortran/interface.cc
@@ -2858,6 +2858,7 @@ get_expr_storage_size (gfc_expr *e)
   if (e->ts.type == BT_CHARACTER)
 {
   if (e->ts.u.cl && e->ts.u.cl->length
+	  && e->ts.u.cl->length->ts.type == BT_INTEGER
   && e->ts.u.cl->length->expr_type == EXPR_CONSTANT)
 	strlen = mpz_get_si (e->ts.u.cl->length->value.integer);
   else if (e->expr_type == EXPR_CONSTANT


Re: [wwwdoc][Patch] Mention Loongson 3a1000 3a2000 3a3000 2k1000 support in gcc9

2023-01-16 Thread Gerald Pfeifer
On Thu, 4 Apr 2019, Paul Hua wrote:
> This is a updated version, Ok for commit?

Yikes - yes!  Apologies, I somehow missed that mail back then (in the 
middle of two weeks essentially off the grid).

I pushed your patch with some minor changes; see below.

Gerald


commit bfea0a7904c170d262ca4b18ae02b97d15625424
Author: Gerald Pfeifer 
Date:   Mon Jan 16 21:04:47 2023 +0100

gcc-9: Mention Loongson 3a1000 3a2000 3a3000 2k1000 support

Originally by Paul Hua .

diff --git a/htdocs/gcc-9/changes.html b/htdocs/gcc-9/changes.html
index ffaf4824..7dfae89c 100644
--- a/htdocs/gcc-9/changes.html
+++ b/htdocs/gcc-9/changes.html
@@ -945,8 +945,44 @@ $ g++ typo.cc
   
 
 
-
-
+MIPS
+
+  
+The Loongson loongson-mmi and loongson-ext
+extensions have been split from loongson3a:
+
+   loongson-mmi contains
+   the Loongson MMI (MultiMedia extensions Instructions).
+   loongson-ext contains
+   the Loongson EXT (EXTensions instructions).
+
+  
+  
+The Loongson EXT2 (EXTensions R2 instructions) are now supported.
+
+   loongson-ext2 contains the Loongson EXT2 
instructions.
+
+Command-line options-m[no-]loongson-mmi,
+-m[no-]loongson-ext, and -m[no-]loongson-ext2
+enable or disable those extensions.
+  
+  
+Support has been added for the following processors
+(GCC identifiers in parentheses):
+
+   Loongson 3A1000 (gs464)
+   which enables loongson-mmi, loongson-ext by 
default.
+   Loongson 3A2000/3A3000 (gs464e)
+   which enables loongson-mmi, loongson-ext, 
loongson-ext2 by default.
+   Loongson 2K1000 (gs264e)
+   which enables loongson-ext, loongson-ext2, 
msa by default.
+
+The GCC identifiers can be used as arguments to the -mcpu
+and -mtune options (as in -mcpu=gs464 or
+-mtune=gs464e) or as arguments to the equivalent target
+attributes and pragmas.
+  
+
 
 
 


Re: [PATCH] x86: Disable -mforce-indirect-call for PIC in 32-bit mode

2023-01-16 Thread Uros Bizjak via Gcc-patches
On Mon, Jan 16, 2023 at 7:56 PM H.J. Lu  wrote:
>
> -mforce-indirect-call generates invalid instruction in 32-bit MI thunk
> since there are no available scratch registers in 32-bit PIC mode.
> Disable -mforce-indirect-call for PIC in 32-bit mode when generating
> MI thunk.
>
> gcc/
>
> PR target/105980
> * config/i386/i386.cc (x86_output_mi_thunk): Disable
> -mforce-indirect-call for PIC in 32-bit mode.
>
> gcc/testsuite/
>
> PR target/105980
> * g++.target/i386/pr105980.C: New test.

OK.

Thanks,
Uros.

> ---
>  gcc/config/i386/i386.cc  | 6 ++
>  gcc/testsuite/g++.target/i386/pr105980.C | 8 
>  2 files changed, 14 insertions(+)
>  create mode 100644 gcc/testsuite/g++.target/i386/pr105980.C
>
> diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> index 19fb03cfd44..3cacf738c4a 100644
> --- a/gcc/config/i386/i386.cc
> +++ b/gcc/config/i386/i386.cc
> @@ -21480,6 +21480,7 @@ x86_output_mi_thunk (FILE *file, tree thunk_fndecl, 
> HOST_WIDE_INT delta,
>rtx this_reg, tmp, fnaddr;
>unsigned int tmp_regno;
>rtx_insn *insn;
> +  int saved_flag_force_indirect_call = flag_force_indirect_call;
>
>if (TARGET_64BIT)
>  tmp_regno = R10_REG;
> @@ -21492,6 +21493,9 @@ x86_output_mi_thunk (FILE *file, tree thunk_fndecl, 
> HOST_WIDE_INT delta,
> tmp_regno = DX_REG;
>else
> tmp_regno = CX_REG;
> +
> +  if (flag_pic)
> +  flag_force_indirect_call = 0;
>  }
>
>emit_note (NOTE_INSN_PROLOGUE_END);
> @@ -21659,6 +21663,8 @@ x86_output_mi_thunk (FILE *file, tree thunk_fndecl, 
> HOST_WIDE_INT delta,
>final (insn, file, 1);
>final_end_function ();
>assemble_end_function (thunk_fndecl, fnname);
> +
> +  flag_force_indirect_call = saved_flag_force_indirect_call;
>  }
>
>  static void
> diff --git a/gcc/testsuite/g++.target/i386/pr105980.C 
> b/gcc/testsuite/g++.target/i386/pr105980.C
> new file mode 100644
> index 000..d8dbc332ea2
> --- /dev/null
> +++ b/gcc/testsuite/g++.target/i386/pr105980.C
> @@ -0,0 +1,8 @@
> +// { dg-do assemble { target { fpic } } }
> +// { dg-options "-O0 -fpic -mforce-indirect-call" }
> +
> +struct A {
> +  virtual ~A();
> +};
> +struct B : virtual A {};
> +void bar() { B(); }
> --
> 2.39.0
>


[committed] wwwdocs: readings: Move www.open-std.org links to https

2023-01-16 Thread Gerald Pfeifer
This looks like the largest remaining block of related issues...

Gerald

---
 htdocs/readings.html | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/htdocs/readings.html b/htdocs/readings.html
index 5e3db8c2..295cc51f 100644
--- a/htdocs/readings.html
+++ b/htdocs/readings.html
@@ -329,39 +329,39 @@ names.
 
   
 
-http://www.open-std.org/jtc1/sc22/wg14/;>WG14 (C
+https://www.open-std.org/jtc1/sc22/wg14/;>WG14 (C
 standards committee)
 
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/n897.pdf;>Draft
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/n897.pdf;>Draft
 C99 Rationale
 
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/summary.htm;>C99
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/summary.htm;>C99
 Defect Reports
 
 http://www.lysator.liu.se/c/rat/title.html;>C89
 Rationale (HTML)
 
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/tc1.htm;>C89
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/tc1.htm;>C89
 Technical Corrigendum 1
 
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/tc2.htm;>C89
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/tc2.htm;>C89
 Technical Corrigendum 2
 
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr.htm;>C89
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr.htm;>C89
 Defect Reports
 
   
 
   Sequence point rules in C:
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/n925.htm;>
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/n925.htm;>
 A formal model of sequence points and related issues by
 Clive Feather
 https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-453.pdf;>
 C formalised in HOL, thesis by Michael Norrish
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/n926.htm;>
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/n926.htm;>
 Sequence points analysis by Raymond Mak
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/n927.htm;>
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/n927.htm;>
 Another formalism for sequence points by D. Hugh Redelmeier
   
 
@@ -379,7 +379,7 @@ names.
 C++ information
 
 
-  http://www.open-std.org/jtc1/sc22/wg21/;>ISO Committee homepage
+  https://www.open-std.org/jtc1/sc22/wg21/;>ISO Committee homepage
   (defects list, etc)
 
 
@@ -494,7 +494,7 @@ names.
 
  Ada standards information:
  
-   http://www.open-std.org/jtc1/sc22/wg9/;>WG9 (Ada
+   https://www.open-std.org/jtc1/sc22/wg9/;>WG9 (Ada
standards committee):

  http://www.ada-auth.org/ais.html;>Ada Issues
-- 
2.38.1


[committed] wwwdocs: git: Remove trailing slash from tags

2023-01-16 Thread Gerald Pfeifer
This is nearly the last case in our tree; nearly current HTML 5 across, 
now.

Gerald
---
 htdocs/git.html | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/htdocs/git.html b/htdocs/git.html
index 4a8b1004..fc30c5ab 100644
--- a/htdocs/git.html
+++ b/htdocs/git.html
@@ -3,8 +3,8 @@
 
 
 
-
-
+
+
 GCC: Anonymous read-only Git access
 https://gcc.gnu.org/gcc.css;>
 
-- 
2.38.1


[PATCH] x86: Disable -mforce-indirect-call for PIC in 32-bit mode

2023-01-16 Thread H.J. Lu via Gcc-patches
-mforce-indirect-call generates invalid instruction in 32-bit MI thunk
since there are no available scratch registers in 32-bit PIC mode.
Disable -mforce-indirect-call for PIC in 32-bit mode when generating
MI thunk.

gcc/

PR target/105980
* config/i386/i386.cc (x86_output_mi_thunk): Disable
-mforce-indirect-call for PIC in 32-bit mode.

gcc/testsuite/

PR target/105980
* g++.target/i386/pr105980.C: New test.
---
 gcc/config/i386/i386.cc  | 6 ++
 gcc/testsuite/g++.target/i386/pr105980.C | 8 
 2 files changed, 14 insertions(+)
 create mode 100644 gcc/testsuite/g++.target/i386/pr105980.C

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 19fb03cfd44..3cacf738c4a 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -21480,6 +21480,7 @@ x86_output_mi_thunk (FILE *file, tree thunk_fndecl, 
HOST_WIDE_INT delta,
   rtx this_reg, tmp, fnaddr;
   unsigned int tmp_regno;
   rtx_insn *insn;
+  int saved_flag_force_indirect_call = flag_force_indirect_call;
 
   if (TARGET_64BIT)
 tmp_regno = R10_REG;
@@ -21492,6 +21493,9 @@ x86_output_mi_thunk (FILE *file, tree thunk_fndecl, 
HOST_WIDE_INT delta,
tmp_regno = DX_REG;
   else
tmp_regno = CX_REG;
+
+  if (flag_pic)
+  flag_force_indirect_call = 0;
 }
 
   emit_note (NOTE_INSN_PROLOGUE_END);
@@ -21659,6 +21663,8 @@ x86_output_mi_thunk (FILE *file, tree thunk_fndecl, 
HOST_WIDE_INT delta,
   final (insn, file, 1);
   final_end_function ();
   assemble_end_function (thunk_fndecl, fnname);
+
+  flag_force_indirect_call = saved_flag_force_indirect_call;
 }
 
 static void
diff --git a/gcc/testsuite/g++.target/i386/pr105980.C 
b/gcc/testsuite/g++.target/i386/pr105980.C
new file mode 100644
index 000..d8dbc332ea2
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/pr105980.C
@@ -0,0 +1,8 @@
+// { dg-do assemble { target { fpic } } }
+// { dg-options "-O0 -fpic -mforce-indirect-call" }
+
+struct A {
+  virtual ~A();
+};
+struct B : virtual A {};
+void bar() { B(); }
-- 
2.39.0



Re: [PATCH] Use cxx11 abi in versioned namespace

2023-01-16 Thread Jonathan Wakely via Gcc-patches
On Mon, 16 Jan 2023 at 17:47, François Dumont  wrote:
>
> On 13/01/23 17:33, Jonathan Wakely wrote:
> > On Mon, 5 Dec 2022 at 21:14, François Dumont via Libstdc++
> >   wrote:
> >> I just rebased this patch.
> >>
> >> All good apart from the to_chars/from_chars symbols issue.
> >>
> >> François
> >>
> >>
> >> On 11/10/22 19:28, François Dumont wrote:
> >>> Hi
> >>>
> >>>  Now that pretty printer is fixed (once patch validated) I'd like
> >>> to propose this patch again.
> >>>
> >>>  Note that I'am adding a check on pretty printer with a std::any on
> >>> a std::wstring. I did so because of the FIXME in printers.py which is
> >>> dealing with 'std::string' explicitely. Looks like in my case, where
> >>> there is no 'std::string' but just a 'std::__8::string' we do not need
> >>> the workaround.
> >>>
> >>>  Once again I am attaching also the version namespace bump patch as
> >>> I think that adopting the cxx11 abi in this mode is a good enough
> >>> reason to bump it. If you agress let me know if I should squash the
> >>> commits before pushing.
> > Yes, I think this change would justify bumping the version.
> >
> >>>  libstdc++: [_GLIBCXX_INLINE_VERSION] Use cxx11 abi
> >>>
> >>>  Use cxx11 abi when activating versioned namespace mode.
> >>>
> >>>  libstdcxx-v3/ChangeLog:
> >>>
> >>>  * acinclude.m4 [GLIBCXX_ENABLE_LIBSTDCXX_DUAL_ABI]:
> >>> Default to "new" libstdcxx abi.
> >>>  * config/locale/dragonfly/monetary_members.cc
> >>> [!_GLIBCXX_USE_DUAL_ABI]: Define money_base
> >>>  members.
> >>>  * config/locale/generic/monetary_members.cc
> >>> [!_GLIBCXX_USE_DUAL_ABI]: Likewise.
> >>>  * config/locale/gnu/monetary_members.cc
> >>> [!_GLIBCXX_USE_DUAL_ABI]: Likewise.
> >>>  * config/locale/gnu/numeric_members.cc
> >>>  [!_GLIBCXX_USE_DUAL_ABI](__narrow_multibyte_chars): Define.
> >>>  * configure: Regenerate.
> >>>  * include/bits/c++config
> >>>  [_GLIBCXX_INLINE_VERSION](_GLIBCXX_NAMESPACE_CXX11,
> >>> _GLIBCXX_BEGIN_NAMESPACE_CXX11): Define
> >>>  empty.
> >>> [_GLIBCXX_INLINE_VERSION](_GLIBCXX_END_NAMESPACE_CXX11,
> >>> _GLIBCXX_DEFAULT_ABI_TAG): Likewise.
> >>>  * python/libstdcxx/v6/printers.py
> >>>  (StdStringPrinter::__init__): Set self.new_string to True
> >>> when std::__8::basic_string type is
> >>>  found.
> >>>  * src/Makefile.am
> >>> [ENABLE_SYMVERS_GNU_NAMESPACE](ldbl_alt128_compat_sources): Define empty.
> >>>  * src/Makefile.in: Regenerate.
> >>>  * src/c++11/Makefile.am (cxx11_abi_sources): Rename into...
> >>>  (dual_abi_sources): ...this, new. Also move several
> >>> sources to...
> >>>  (sources): ...this.
> >>>  (extra_string_inst_sources): Move several sources to...
> >>>  (inst_sources): ...this.
> > I don't understand this part. Moving those files to sources and
> > inst_sources will mean they are always compiled, right? But we don't
> > want them compiled for --disable-libstdcxx-dual-abi
> >
> > In those files you've changed the #if conditions so they are empty if
> > the dual ABI is disabled, but why do they need to be compiled at all?
> > This isn't clear from the patch or the description or the changelog.
>
> --disable-libstdcxx-dual-abi means use cow string implementation. With
> this patch I am introducing somehow another disable-dual-abi mode but
> this time to use cxx11 string implementation.

Oh right, I misremembered. I thought you could choose the ABI when
disabling dual-abi.



>
> At Makefile.am level it was difficult to match both cases so I'm doing
> it at compilation time with most of time the condition:
>
> #if ! _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
>
> I'll make it clearer at ChangeLog level.
>
> >>>  * src/c++11/Makefile.in: Regenerate.
> >>>  * src/c++11/cow-fstream-inst.cc [_GLIBCXX_USE_CXX11_ABI]:
> >>> Skip definitions.
> >>>  * src/c++11/cow-locale_init.cc [_GLIBCXX_USE_CXX11_ABI]:
> >>> Skip definitions.
> >>>  * src/c++11/cow-sstream-inst.cc [_GLIBCXX_USE_CXX11_ABI]:
> >>> Skip definitions.
> >>>  * src/c++11/cow-stdexcept.cc
> >>> [_GLIBCXX_USE_CXX11_ABI](error_category::_M_message):
> >>>  Skip definition.
> >>>  [_GLIBCXX_USE_CXX11_ABI]: Skip Transaction Memory TS
> >>> definitions.
> >>>  * src/c++11/cow-string-inst.cc [_GLIBCXX_USE_CXX11_ABI]:
> >>> Skip definitions.
> >>>  * src/c++11/cow-string-io-inst.cc
> >>> [_GLIBCXX_USE_CXX11_ABI]: Skip definitions.
> >>>  * src/c++11/cow-wstring-inst.cc [_GLIBCXX_USE_CXX11_ABI]:
> >>> Skip definitions.
> >>>  * src/c++11/cow-wstring-io-inst.cc
> >>> [_GLIBCXX_USE_CXX11_ABI]: Skip definitions.
> >>>  * src/c++11/cxx11-hash_tr1.cc [!_GLIBCXX_USE_CXX11_ABI]:
> >>> Skip definitions.
> 

Re: [PATCH] Use cxx11 abi in versioned namespace

2023-01-16 Thread François Dumont via Gcc-patches

On 13/01/23 18:15, Jonathan Wakely wrote:

@@ -396,7 +376,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Non-inline namespace for components replaced by alternates in active 
mode.
namespace __cxx1998
{
-# if _GLIBCXX_USE_CXX11_ABI
+# if _GLIBCXX_USE_CXX11_ABI && ! _GLIBCXX_VERSION_NAMESPACE

This should be INLINE not VERSION, right?


Indeed, I haven't tested the _GLIBCXX_DEBUG mode.



Re: [PATCH] Use cxx11 abi in versioned namespace

2023-01-16 Thread François Dumont via Gcc-patches

On 13/01/23 18:06, Jonathan Wakely wrote:

On Fri, 13 Jan 2023 at 16:33, Jonathan Wakely  wrote:

On Mon, 5 Dec 2022 at 21:14, François Dumont via Libstdc++
 wrote:

I just rebased this patch.

All good apart from the to_chars/from_chars symbols issue.

François


On 11/10/22 19:28, François Dumont wrote:

Hi

 Now that pretty printer is fixed (once patch validated) I'd like
to propose this patch again.

 Note that I'am adding a check on pretty printer with a std::any on
a std::wstring. I did so because of the FIXME in printers.py which is
dealing with 'std::string' explicitely. Looks like in my case, where
there is no 'std::string' but just a 'std::__8::string' we do not need
the workaround.

 Once again I am attaching also the version namespace bump patch as
I think that adopting the cxx11 abi in this mode is a good enough
reason to bump it. If you agress let me know if I should squash the
commits before pushing.

Yes, I think this change would justify bumping the version.


 libstdc++: [_GLIBCXX_INLINE_VERSION] Use cxx11 abi

 Use cxx11 abi when activating versioned namespace mode.

 libstdcxx-v3/ChangeLog:

 * acinclude.m4 [GLIBCXX_ENABLE_LIBSTDCXX_DUAL_ABI]:
Default to "new" libstdcxx abi.
 * config/locale/dragonfly/monetary_members.cc
[!_GLIBCXX_USE_DUAL_ABI]: Define money_base
 members.
 * config/locale/generic/monetary_members.cc
[!_GLIBCXX_USE_DUAL_ABI]: Likewise.
 * config/locale/gnu/monetary_members.cc
[!_GLIBCXX_USE_DUAL_ABI]: Likewise.
 * config/locale/gnu/numeric_members.cc
 [!_GLIBCXX_USE_DUAL_ABI](__narrow_multibyte_chars): Define.
 * configure: Regenerate.
 * include/bits/c++config
 [_GLIBCXX_INLINE_VERSION](_GLIBCXX_NAMESPACE_CXX11,
_GLIBCXX_BEGIN_NAMESPACE_CXX11): Define
 empty.
[_GLIBCXX_INLINE_VERSION](_GLIBCXX_END_NAMESPACE_CXX11,
_GLIBCXX_DEFAULT_ABI_TAG): Likewise.
 * python/libstdcxx/v6/printers.py
 (StdStringPrinter::__init__): Set self.new_string to True
when std::__8::basic_string type is
 found.
 * src/Makefile.am
[ENABLE_SYMVERS_GNU_NAMESPACE](ldbl_alt128_compat_sources): Define empty.
 * src/Makefile.in: Regenerate.
 * src/c++11/Makefile.am (cxx11_abi_sources): Rename into...
 (dual_abi_sources): ...this, new. Also move several
sources to...
 (sources): ...this.
 (extra_string_inst_sources): Move several sources to...
 (inst_sources): ...this.

I don't understand this part. Moving those files to sources and
inst_sources will mean they are always compiled, right? But we don't
want them compiled for --disable-libstdcxx-dual-abi

In those files you've changed the #if conditions so they are empty if
the dual ABI is disabled, but why do they need to be compiled at all?
This isn't clear from the patch or the description or the changelog.



 * src/c++11/Makefile.in: Regenerate.
 * src/c++11/cow-fstream-inst.cc [_GLIBCXX_USE_CXX11_ABI]:
Skip definitions.
 * src/c++11/cow-locale_init.cc [_GLIBCXX_USE_CXX11_ABI]:
Skip definitions.
 * src/c++11/cow-sstream-inst.cc [_GLIBCXX_USE_CXX11_ABI]:
Skip definitions.
 * src/c++11/cow-stdexcept.cc
[_GLIBCXX_USE_CXX11_ABI](error_category::_M_message):
 Skip definition.
 [_GLIBCXX_USE_CXX11_ABI]: Skip Transaction Memory TS
definitions.
 * src/c++11/cow-string-inst.cc [_GLIBCXX_USE_CXX11_ABI]:
Skip definitions.
 * src/c++11/cow-string-io-inst.cc
[_GLIBCXX_USE_CXX11_ABI]: Skip definitions.
 * src/c++11/cow-wstring-inst.cc [_GLIBCXX_USE_CXX11_ABI]:
Skip definitions.
 * src/c++11/cow-wstring-io-inst.cc
[_GLIBCXX_USE_CXX11_ABI]: Skip definitions.
 * src/c++11/cxx11-hash_tr1.cc [!_GLIBCXX_USE_CXX11_ABI]:
Skip definitions.
 * src/c++11/cxx11-ios_failure.cc
[!_GLIBCXX_USE_CXX11_ABI]: Skip definitions.
 [!_GLIBCXX_USE_DUAL_ABI] (__ios_failure): Remove.

For this file I think your changes make sense, because the definitions
of the gcc4-compatible and cxx11 ABI are different, we're not just
compiling it twice.



 * src/c++11/cxx11-locale-inst.cc: Cleanup, just include
locale-inst.cc.
 * src/c++11/cxx11-stdexcept.cc [!_GLIBCXX_USE_CXX11_ABI]:
Skip definitions.
 [!_GLIBCXX_USE_DUAL_ABI](__cow_string): Remove.
 * src/c++11/cxx11-wlocale-inst.cc
[!_GLIBCXX_USE_CXX11_ABI]: Skip definitions.
 * src/c++11/fstream-inst.cc [!_GLIBCXX_USE_CXX11_ABI]:
Skip definitions
 * src/c++11/locale-inst-numeric.h
[!_GLIBCXX_USE_DUAL_ABI](std::use_facet>,
std::use_facet>): Instantiate.
[!_GLIBCXX_USE_DUAL_ABI](std::has_facet>,
std::has_facet>): Instantiate.
 [!_GLIBCXX_USE_DUAL_ABI](std::num_get>): Instantiate.
 

Re: [PATCH] Use cxx11 abi in versioned namespace

2023-01-16 Thread François Dumont via Gcc-patches

On 13/01/23 17:33, Jonathan Wakely wrote:

On Mon, 5 Dec 2022 at 21:14, François Dumont via Libstdc++
  wrote:

I just rebased this patch.

All good apart from the to_chars/from_chars symbols issue.

François


On 11/10/22 19:28, François Dumont wrote:

Hi

 Now that pretty printer is fixed (once patch validated) I'd like
to propose this patch again.

 Note that I'am adding a check on pretty printer with a std::any on
a std::wstring. I did so because of the FIXME in printers.py which is
dealing with 'std::string' explicitely. Looks like in my case, where
there is no 'std::string' but just a 'std::__8::string' we do not need
the workaround.

 Once again I am attaching also the version namespace bump patch as
I think that adopting the cxx11 abi in this mode is a good enough
reason to bump it. If you agress let me know if I should squash the
commits before pushing.

Yes, I think this change would justify bumping the version.


 libstdc++: [_GLIBCXX_INLINE_VERSION] Use cxx11 abi

 Use cxx11 abi when activating versioned namespace mode.

 libstdcxx-v3/ChangeLog:

 * acinclude.m4 [GLIBCXX_ENABLE_LIBSTDCXX_DUAL_ABI]:
Default to "new" libstdcxx abi.
 * config/locale/dragonfly/monetary_members.cc
[!_GLIBCXX_USE_DUAL_ABI]: Define money_base
 members.
 * config/locale/generic/monetary_members.cc
[!_GLIBCXX_USE_DUAL_ABI]: Likewise.
 * config/locale/gnu/monetary_members.cc
[!_GLIBCXX_USE_DUAL_ABI]: Likewise.
 * config/locale/gnu/numeric_members.cc
 [!_GLIBCXX_USE_DUAL_ABI](__narrow_multibyte_chars): Define.
 * configure: Regenerate.
 * include/bits/c++config
 [_GLIBCXX_INLINE_VERSION](_GLIBCXX_NAMESPACE_CXX11,
_GLIBCXX_BEGIN_NAMESPACE_CXX11): Define
 empty.
[_GLIBCXX_INLINE_VERSION](_GLIBCXX_END_NAMESPACE_CXX11,
_GLIBCXX_DEFAULT_ABI_TAG): Likewise.
 * python/libstdcxx/v6/printers.py
 (StdStringPrinter::__init__): Set self.new_string to True
when std::__8::basic_string type is
 found.
 * src/Makefile.am
[ENABLE_SYMVERS_GNU_NAMESPACE](ldbl_alt128_compat_sources): Define empty.
 * src/Makefile.in: Regenerate.
 * src/c++11/Makefile.am (cxx11_abi_sources): Rename into...
 (dual_abi_sources): ...this, new. Also move several
sources to...
 (sources): ...this.
 (extra_string_inst_sources): Move several sources to...
 (inst_sources): ...this.

I don't understand this part. Moving those files to sources and
inst_sources will mean they are always compiled, right? But we don't
want them compiled for --disable-libstdcxx-dual-abi

In those files you've changed the #if conditions so they are empty if
the dual ABI is disabled, but why do they need to be compiled at all?
This isn't clear from the patch or the description or the changelog.


--disable-libstdcxx-dual-abi means use cow string implementation. With 
this patch I am introducing somehow another disable-dual-abi mode but 
this time to use cxx11 string implementation.


At Makefile.am level it was difficult to match both cases so I'm doing 
it at compilation time with most of time the condition:


#if ! _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI

I'll make it clearer at ChangeLog level.


 * src/c++11/Makefile.in: Regenerate.
 * src/c++11/cow-fstream-inst.cc [_GLIBCXX_USE_CXX11_ABI]:
Skip definitions.
 * src/c++11/cow-locale_init.cc [_GLIBCXX_USE_CXX11_ABI]:
Skip definitions.
 * src/c++11/cow-sstream-inst.cc [_GLIBCXX_USE_CXX11_ABI]:
Skip definitions.
 * src/c++11/cow-stdexcept.cc
[_GLIBCXX_USE_CXX11_ABI](error_category::_M_message):
 Skip definition.
 [_GLIBCXX_USE_CXX11_ABI]: Skip Transaction Memory TS
definitions.
 * src/c++11/cow-string-inst.cc [_GLIBCXX_USE_CXX11_ABI]:
Skip definitions.
 * src/c++11/cow-string-io-inst.cc
[_GLIBCXX_USE_CXX11_ABI]: Skip definitions.
 * src/c++11/cow-wstring-inst.cc [_GLIBCXX_USE_CXX11_ABI]:
Skip definitions.
 * src/c++11/cow-wstring-io-inst.cc
[_GLIBCXX_USE_CXX11_ABI]: Skip definitions.
 * src/c++11/cxx11-hash_tr1.cc [!_GLIBCXX_USE_CXX11_ABI]:
Skip definitions.
 * src/c++11/cxx11-ios_failure.cc
[!_GLIBCXX_USE_CXX11_ABI]: Skip definitions.
 [!_GLIBCXX_USE_DUAL_ABI] (__ios_failure): Remove.

For this file I think your changes make sense, because the definitions
of the gcc4-compatible and cxx11 ABI are different, we're not just
compiling it twice.



 * src/c++11/cxx11-locale-inst.cc: Cleanup, just include
locale-inst.cc.
 * src/c++11/cxx11-stdexcept.cc [!_GLIBCXX_USE_CXX11_ABI]:
Skip definitions.
 [!_GLIBCXX_USE_DUAL_ABI](__cow_string): Remove.
 * src/c++11/cxx11-wlocale-inst.cc
[!_GLIBCXX_USE_CXX11_ABI]: Skip definitions.
 * 

Fix wrong code issues with ipa-sra

2023-01-16 Thread Jan Hubicka via Gcc-patches
Hi,
this patch fixes wrong code issues in ipa-sra where we are trying to prove that
on every execution of a given function a call to other function will happen.
The code uses post dominators and makes a wrong query (which passes only for
first BB in function). Hoever post-dominators are only valid if fake edges for
every possible reason for fuction execution to terminate are added.

Fixing this using postdominators is somewhat costy since one needs to walk
whole body and add a lot of fake edges. I ended up implementing a special
purpose function for this which is also useful in ipa-modref and other places
that does similar analysis.

Note that ipa-sra still has similar issue in its safety analysis for
which I filled in separate PR.  It needs to stop on infinite loop and
possibly terminating statements.

Bootstrapped/regtested x86_64-linux, comitted.

gcc/ChangeLog:

2023-01-16  Jan Hubicka  

PR ipa/106077
* ipa-modref.cc (modref_access_analysis::analyze): Use
find_always_executed_bbs.
* ipa-sra.cc (process_scan_results): Likewise.
* ipa-utils.cc (stmt_may_terminate_function_p): New function.
(find_always_executed_bbs): New function.
* ipa-utils.h (stmt_may_terminate_function_p): Declare.
(find_always_executed_bbs): Declare.

gcc/testsuite/ChangeLog:

2023-01-16  Jan Hubicka  

* g++.dg/tree-ssa/pr106077.C: New test.

diff --git a/gcc/ipa-modref.cc b/gcc/ipa-modref.cc
index 16e8bfb97a6..e3196df8aa9 100644
--- a/gcc/ipa-modref.cc
+++ b/gcc/ipa-modref.cc
@@ -1875,11 +1875,11 @@ modref_access_analysis::analyze ()
  statement cannot be analyzed (for any reason), the entire function cannot
  be analyzed by modref.  */
   basic_block bb;
+  bitmap always_executed_bbs = find_always_executed_bbs (cfun, true);
   FOR_EACH_BB_FN (bb, cfun)
 {
   gimple_stmt_iterator si;
-  bool always_executed
- = bb == single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun))->dest;
+  bool always_executed = bitmap_bit_p (always_executed_bbs, bb->index);
 
   for (si = gsi_start_nondebug_after_labels_bb (bb);
   !gsi_end_p (si); gsi_next_nondebug ())
@@ -1926,6 +1926,7 @@ modref_access_analysis::analyze ()
  && !finite_function_p ())
m_summary_lto->side_effects = true;
 }
+  BITMAP_FREE (always_executed_bbs);
 }
 
 /* Return true if OP accesses memory pointed to by SSA_NAME.  */
diff --git a/gcc/ipa-sra.cc b/gcc/ipa-sra.cc
index 4d7c25c8784..81b75910db1 100644
--- a/gcc/ipa-sra.cc
+++ b/gcc/ipa-sra.cc
@@ -2529,7 +2529,8 @@ process_scan_results (cgraph_node *node, struct function 
*fun,
  TODO: Measure the overhead and the effect of just being pessimistic.
  Maybe this is only -O3 material?  */
 
-  bool pdoms_calculated = false;
+  hash_map analyzed_stmts;
+  bitmap always_executed_bbs = NULL;
   if (check_pass_throughs)
 for (cgraph_edge *cs = node->callees; cs; cs = cs->next_callee)
   {
@@ -2566,27 +2567,46 @@ process_scan_results (cgraph_node *node, struct 
function *fun,
continue;
  }
 
-   /* Post-dominator check placed last, hoping that it usually won't
-  be needed.  */
-   if (!pdoms_calculated)
+   /* Walk basic block and see if its execution can terminate earlier.
+  Keep the info for later re-use to avoid quadratic behavoiur 
here.  */
+   gimple_stmt_iterator gsi = gsi_for_stmt (call_stmt);
+   bool safe = true;
+   int n = 0;
+   for (gsi_prev (); !gsi_end_p (gsi); gsi_prev ())
  {
-   gcc_checking_assert (cfun);
-   connect_infinite_loops_to_exit ();
-   calculate_dominance_info (CDI_POST_DOMINATORS);
-   pdoms_calculated = true;
+   bool *b = analyzed_stmts.get (gsi_stmt (gsi));
+   if (b)
+ {
+   safe = *b;
+   gsi_next ();
+   break;
+ }
+   n++;
+   if (stmt_may_terminate_function_p (fun, gsi_stmt (gsi), false))
+ {
+   safe = false;
+   break;
+ }
  }
-   if (dominated_by_p (CDI_POST_DOMINATORS,
-   gimple_bb (call_stmt),
-   single_succ (ENTRY_BLOCK_PTR_FOR_FN (fun
+   if (n)
+ {
+   if (gsi_end_p (gsi))
+ gsi = gsi_start_bb (gimple_bb (call_stmt));
+   for (; gsi_stmt (gsi) != call_stmt; gsi_next ())
+ analyzed_stmts.get_or_insert (gsi_stmt (gsi)) = safe;
+ }
+
+   if (safe && !always_executed_bbs)
+ {
+   mark_dfs_back_edges ();
+   always_executed_bbs = find_always_executed_bbs (fun, false);
+ }
+   if (safe && bitmap_bit_p (always_executed_bbs, gimple_bb 
(call_stmt)->index))
  

Re: realpath() patch to fix symlinks resolution for win32

2023-01-16 Thread i.nixman--- via Gcc-patches


updated patch in attachments.
diff --git a/libiberty/lrealpath.c b/libiberty/lrealpath.c
index 3c7053b0b70..8858619e854 100644
--- a/libiberty/lrealpath.c
+++ b/libiberty/lrealpath.c
@@ -68,8 +68,138 @@ extern char *canonicalize_file_name (const char *);
   /* cygwin has realpath, so it won't get here.  */ 
 # if defined (_WIN32)
 #  define WIN32_LEAN_AND_MEAN
-#  include  /* for GetFullPathName */
-# endif
+#  include  /* for GetFullPathName/GetFinalPathNameByHandle/
+  CreateFile/CloseHandle */
+#  define WIN32_REPLACE_SLASHES(_ptr, _len) \
+ for (unsigned i = 0; i != (_len); ++i) \
+   if ((_ptr)[i] == '\\') (_ptr)[i] = '/';
+
+#  define WIN32_UNC_PREFIX "//?/UNC/"
+#  define WIN32_UNC_PREFIX_LEN (sizeof(WIN32_UNC_PREFIX)-1)
+#  define WIN32_IS_UNC_PREFIX(ptr) \
+  (0 == memcmp(ptr, WIN32_UNC_PREFIX, WIN32_UNC_PREFIX_LEN))
+
+#  define WIN32_NON_UNC_PREFIX "//?/"
+#  define WIN32_NON_UNC_PREFIX_LEN (sizeof(WIN32_NON_UNC_PREFIX)-1)
+#  define WIN32_IS_NON_UNC_PREFIX(ptr) \
+  (0 == memcmp(ptr, WIN32_NON_UNC_PREFIX, WIN32_NON_UNC_PREFIX_LEN))
+
+# define WIN32_IS_SPECIAL_NUL_FILE(ptr) \
+  (0 == strcasecmp(ptr, "NUL"))
+
+/* Get full path name without symlinks resolution.
+   It also converts all forward slashes to back slashes.
+*/
+char* get_full_path_name(const char *filename) {
+  DWORD len;
+  char *buf, *ptr, *res;
+
+  /* determining the required buffer size.
+ from the man: `If the lpBuffer buffer is too small to contain
+ the path, the return value is the size, in TCHARs, of the buffer
+ that is required to hold the path _and_the_terminating_null_character_`
+  */
+  len = GetFullPathName(filename, 0, NULL, NULL);
+
+  if ( len == 0 )
+return strdup(filename);
+
+  buf = (char *)malloc(len);
+
+  /* no point to check the result again */
+  len = GetFullPathName(filename, len, buf, NULL);
+  buf[len] = 0;
+
+  /* replace slashes */
+  WIN32_REPLACE_SLASHES(buf, len);
+
+  /* calculate offset based on prefix type */
+  len = WIN32_IS_UNC_PREFIX(buf)
+? (WIN32_UNC_PREFIX_LEN - 2)
+: WIN32_IS_NON_UNC_PREFIX(buf)
+  ? WIN32_NON_UNC_PREFIX_LEN
+  : 0
+  ;
+
+  ptr = buf + len;
+  if ( WIN32_IS_UNC_PREFIX(buf) ) {
+ptr[0] = '/';
+ptr[1] = '/';
+  }
+
+  res = strdup(ptr);
+
+  free(buf);
+
+  return res;
+}
+
+# if _WIN32_WINNT >= 0x0600
+
+/* Get full path name WITH symlinks resolution.
+   It also converts all forward slashes to back slashes.
+*/
+char* get_final_path_name(HANDLE fh) {
+  DWORD len;
+  char *buf, *ptr, *res;
+
+  /* determining the required buffer size.
+ from the  man: `If the function fails because lpszFilePath is too
+ small to hold the string plus the terminating null character,
+ the return value is the required buffer size, in TCHARs. This
+ value _includes_the_size_of_the_terminating_null_character_`.
+ but in my testcase I have path with 26 chars, the function
+ returns 26 also, ie without the trailing zero-char...
+  */
+  len = GetFinalPathNameByHandle(
+ fh
+,NULL
+,0
+,FILE_NAME_NORMALIZED | VOLUME_NAME_DOS
+  );
+
+  if ( len == 0 )
+return NULL;
+
+  len += 1; /* for zero-char */
+  buf = (char *)malloc(len);
+
+  /* no point to check the result again */
+  len = GetFinalPathNameByHandle(
+ fh
+,buf
+,len
+,FILE_NAME_NORMALIZED | VOLUME_NAME_DOS
+  );
+  buf[len] = 0;
+
+  /* replace slashes */
+  WIN32_REPLACE_SLASHES(buf, len);
+
+  /* calculate offset based on prefix type */
+  len = WIN32_IS_UNC_PREFIX(buf)
+? (WIN32_UNC_PREFIX_LEN - 2)
+: WIN32_IS_NON_UNC_PREFIX(buf)
+  ? WIN32_NON_UNC_PREFIX_LEN
+  : 0
+  ;
+
+  ptr = buf + len;
+  if ( WIN32_IS_UNC_PREFIX(buf) ) {
+ptr[0] = '/';
+ptr[1] = '/';
+  }
+
+  res = strdup(ptr);
+
+  free(buf);
+
+  return res;
+}
+
+# endif // _WIN32_WINNT >= 0x0600
+
+# endif // _WIN32
 #endif
 
 char *
@@ -128,30 +258,51 @@ lrealpath (const char *filename)
   }
 #endif
 
-  /* The MS Windows method.  If we don't have realpath, we assume we
- don't have symlinks and just canonicalize to a Windows absolute
- path.  GetFullPath converts ../ and ./ in relative paths to
- absolute paths, filling in current drive if one is not given
- or using the current directory of a specified drive (eg, "E:foo").
- It also converts all forward slashes to back slashes.  */
+  /* The MS Windows method */
 #if defined (_WIN32)
   {
-char buf[MAX_PATH];
-char* basename;
-DWORD len = GetFullPathName (filename, MAX_PATH, buf, );
-if (len == 0 || len > MAX_PATH - 1)
-  return strdup (filename);
-else
-  {
-	/* The file system is case-preserving but case-insensitive,
-	   Canonicalize to lowercase, using the codepage associated
-	   with the process locale.  */
-CharLowerBuff (buf, len);
-return strdup (buf);
+char *res;
+/* For Windows Vista and greater */
+#if _WIN32_WINNT >= 0x0600
+
+/* For some reason the function receives 

[committed] libstdc++: Fix --with-default-libstdcxx-abi=gcc4-compatible build

2023-01-16 Thread Jonathan Wakely via Gcc-patches
Tested x86_64-linux. Pushed to trunk.

-- >8 --

When building src/c++20/tzdb.cc we currently get a build error for
--with-default-libstdcxx-abi=gcc4-compatible because std::chrono::tzdb
and related types are not declared for the gcc4-compatible ABI (unless
--disable-libstdcxx-dual-abi is also used, so that the gcc4-compatible
ABI is the only one built).

Define _GLIBCXX_USE_CXX11_ABI in tzdb.cc so that for a dual-abi build we
always build it for the cxx11 ABI.

libstdc++-v3/ChangeLog:

* src/c++20/tzdb.cc (_GLIBCXX_USE_CXX11_ABI): Define to 1.
---
 libstdc++-v3/src/c++20/tzdb.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc
index 2ce53d38768..20399b91e47 100644
--- a/libstdc++-v3/src/c++20/tzdb.cc
+++ b/libstdc++-v3/src/c++20/tzdb.cc
@@ -25,6 +25,9 @@
 // The -Wabi warnings in this file are all for non-exported symbols.
 #pragma GCC diagnostic ignored "-Wabi"
 
+// In the usual dual-abi build, std::chrono::tzdb is only defined for cxx11.
+#define _GLIBCXX_USE_CXX11_ABI 1
+
 #include 
 #include // ifstream
 #include // istringstream
-- 
2.39.0



Re: [PATCH] rs6000: Teach rs6000_opaque_type_invalid_use_p about gcall [PR108348]

2023-01-16 Thread Segher Boessenkool
On Mon, Jan 16, 2023 at 09:05:38PM +0800, Kewen.Lin wrote:
> > The *_ok things should only be used for features that can be disabled
> > during configuration, or features that we *want* users to be able to
> > turn off (like FP, VMX, VSX, or HMT or QP float, that kind of thing).
> > That gives quite enough permutations to test already, we do not need to
> > create a whole bunch extra for no reason :-)
> 
> Thanks for the explanation!!  I meant to use powerpc_p9modulo_ok to
> exclude those cases where we can't use -mcpu=power9, as you explained we
> should not worry about it!?

But that selector says whether modulo insns are enabled.  This is not
correct to use here.  I know we have abused these things before, but it
needs to be untangled, not made worse :-)

> Since the test point requires altivec support
> (which is implied when specifying -mcpu=power9, I didn't explicitly specify
> it before), I think I could use powerpc_altivec_ok to replace
> powerpc_p9modulo_ok here, does it sound good to you?

VMX can be turned off even with -mcpu=power9.  So yes, it does need
powerpc_altivec_ok.  Does it need VSX even?


Segher


[COMMITTED] ada: Fix typo in comment

2023-01-16 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

gcc/ada/

* exp_ch3.adb (Make_Allocator_For_Return): Fix typo in comment.

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

---
 gcc/ada/exp_ch3.adb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index daa96df4b32..abe71b252e7 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -7196,7 +7196,7 @@ package body Exp_Ch3 is
 --  We always use the type of the expression for the qualified
 --  expression, rather than the return object's type. We cannot
 --  always use the return object's type because the expression
---  might be of a specific type and the result object mignt not.
+--  might be of a specific type and the return object mignt not.
 
 Alloc :=
   Make_Allocator (Loc,
-- 
2.34.1



[COMMITTED] ada: Fix latent bug exposed by recent work on extended return statements

2023-01-16 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

When the type of the return object is a constrained array, there may be an
implicit sliding that needs to be preserved during the expansion.

gcc/ada/

* exp_ch3.adb (Make_Allocator_For_Return): Convert the expression
to the return object's type in the constrained array case as well.

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

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

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 6886bde7bd1..daa96df4b32 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -7181,11 +7181,13 @@ package body Exp_Ch3 is
 
 Alloc_Expr := New_Copy_Tree (Expr);
 
+--  In the constrained array case, deal with a potential sliding.
 --  In the interface case, put back a conversion that we may have
---  remove earlier in the processing.
+--  removed earlier in the processing.
 
-if Is_Interface (Typ)
-  and then Is_Class_Wide_Type (Etype (Alloc_Expr))
+if (Ekind (Typ) = E_Array_Subtype
+ or else (Is_Interface (Typ)
+   and then Is_Class_Wide_Type (Etype (Alloc_Expr
   and then Typ /= Etype (Alloc_Expr)
 then
Alloc_Expr := Convert_To (Typ, Alloc_Expr);
-- 
2.34.1



[COMMITTED] ada: Update copyright years.

2023-01-16 Thread Marc Poulhiès via Gcc-patches
gcc/ada/

* gcc-interface/Make-lang.in: Update copyright years.
* gcc-interface/Makefile.in: Likewise.
* gcc-interface/ada-builtin-types.def: Likewise.
* gcc-interface/ada-builtins.def: Likewise.
* gcc-interface/ada-tree.def: Likewise.
* gcc-interface/ada-tree.h: Likewise.
* gcc-interface/ada.h: Likewise.
* gcc-interface/config-lang.in: Likewise.
* gcc-interface/cuintp.cc: Likewise.
* gcc-interface/decl.cc: Likewise.
* gcc-interface/gadaint.h: Likewise.
* gcc-interface/gigi.h: Likewise.
* gcc-interface/lang-specs.h: Likewise.
* gcc-interface/lang.opt: Likewise.
* gcc-interface/misc.cc: Likewise.
* gcc-interface/system.ads: Likewise.
* gcc-interface/targtyps.cc: Likewise.
* gcc-interface/trans.cc: Likewise.
* gcc-interface/utils.cc: Likewise.
* gcc-interface/utils2.cc: Likewise.

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

---
 gcc/ada/gcc-interface/Make-lang.in  | 4 +---
 gcc/ada/gcc-interface/Makefile.in   | 2 +-
 gcc/ada/gcc-interface/ada-builtin-types.def | 2 +-
 gcc/ada/gcc-interface/ada-builtins.def  | 2 +-
 gcc/ada/gcc-interface/ada-tree.def  | 2 +-
 gcc/ada/gcc-interface/ada-tree.h| 2 +-
 gcc/ada/gcc-interface/ada.h | 2 +-
 gcc/ada/gcc-interface/config-lang.in| 2 +-
 gcc/ada/gcc-interface/cuintp.cc | 2 +-
 gcc/ada/gcc-interface/decl.cc   | 2 +-
 gcc/ada/gcc-interface/gadaint.h | 2 +-
 gcc/ada/gcc-interface/gigi.h| 2 +-
 gcc/ada/gcc-interface/lang-specs.h  | 2 +-
 gcc/ada/gcc-interface/lang.opt  | 2 +-
 gcc/ada/gcc-interface/misc.cc   | 2 +-
 gcc/ada/gcc-interface/system.ads| 2 +-
 gcc/ada/gcc-interface/targtyps.cc   | 2 +-
 gcc/ada/gcc-interface/trans.cc  | 2 +-
 gcc/ada/gcc-interface/utils.cc  | 2 +-
 gcc/ada/gcc-interface/utils2.cc | 2 +-
 20 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/gcc/ada/gcc-interface/Make-lang.in 
b/gcc/ada/gcc-interface/Make-lang.in
index c81daae9c4a..9507f2f0920 100644
--- a/gcc/ada/gcc-interface/Make-lang.in
+++ b/gcc/ada/gcc-interface/Make-lang.in
@@ -1,7 +1,5 @@
 # Top level -*- makefile -*- fragment for GNU Ada (GNAT).
-#   Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-#   2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
-#   Free Software Foundation, Inc.
+# Copyright (C) 2009-2023 Free Software Foundation, Inc.
 
 #This file is part of GCC.
 
diff --git a/gcc/ada/gcc-interface/Makefile.in 
b/gcc/ada/gcc-interface/Makefile.in
index 5137ebaa0c6..da6a56fcec8 100644
--- a/gcc/ada/gcc-interface/Makefile.in
+++ b/gcc/ada/gcc-interface/Makefile.in
@@ -1,5 +1,5 @@
 # Makefile for GNU Ada Compiler (GNAT).
-#   Copyright (C) 1994-2018 Free Software Foundation, Inc.
+#   Copyright (C) 1994-2023 Free Software Foundation, Inc.
 
 #This file is part of GCC.
 
diff --git a/gcc/ada/gcc-interface/ada-builtin-types.def 
b/gcc/ada/gcc-interface/ada-builtin-types.def
index 000d4290429..b8925f5c90b 100644
--- a/gcc/ada/gcc-interface/ada-builtin-types.def
+++ b/gcc/ada/gcc-interface/ada-builtin-types.def
@@ -1,7 +1,7 @@
 /* This file contains the type definitions for the builtins exclusively
used in the GNU Ada compiler.
 
-   Copyright (C) 2019-2022 Free Software Foundation, Inc.
+   Copyright (C) 2019-2023 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
diff --git a/gcc/ada/gcc-interface/ada-builtins.def 
b/gcc/ada/gcc-interface/ada-builtins.def
index 8ba89a80e70..cf3d6a13273 100644
--- a/gcc/ada/gcc-interface/ada-builtins.def
+++ b/gcc/ada/gcc-interface/ada-builtins.def
@@ -1,7 +1,7 @@
 /* This file contains the definitions for the builtins exclusively used
in the GNU Ada compiler.
 
-   Copyright (C) 2019-2022 Free Software Foundation, Inc.
+   Copyright (C) 2019-2023 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
diff --git a/gcc/ada/gcc-interface/ada-tree.def 
b/gcc/ada/gcc-interface/ada-tree.def
index 7fc95cb74c5..ff88e54793f 100644
--- a/gcc/ada/gcc-interface/ada-tree.def
+++ b/gcc/ada/gcc-interface/ada-tree.def
@@ -6,7 +6,7 @@
  *  *
  *  Specification   *
  *  *
- *Copyright (C) 1992-2009, Free Software Foundation, Inc.   *
+ *Copyright (C) 1992-2023, Free Software Foundation, Inc.   *
  *  *
  * GNAT is free software;  you can  redistribute it  and/or modify it under *
  * terms of the  GNU General Public License as published  by the Free Soft- *
diff --git a/gcc/ada/gcc-interface/ada-tree.h 

[COMMITTED] ada: Fix pessimization of some CW objects initialized with function call

2023-01-16 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

The recent removal of the unconditional call to Remove_Side_Effects on the
expression of an object declaration or an allocator with a class-wide type
has introduced a pessimization in the former case for function calls that
return a specific tagged type, because the object ultimately created on the
primary stack has changed from being of a specific tagged type to being of
the class-wide type, the latter type always formally requiring finalization.

With the current finalization machinery, this means that a dispatching call
to the Deep_Finalize routine is generated, which is unnecessary.  Although
this is a generic finalization issue with class-wide objects, this restores
the previous behavior in this case to fix the pessimization for now.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration): For a class-wide non-
interface stand-alone object initialized by a function call, call
Remove_Side_Effects on the expression to capture the result.

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

---
 gcc/ada/exp_ch3.adb | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 6bc76aec5d1..6886bde7bd1 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -7797,6 +7797,25 @@ package body Exp_Ch3 is
  --  Common case of explicit object initialization
 
  else
+--  Small optimization: if the expression is a function call and
+--  the object is stand-alone, not declared at library level and of
+--  a class-wide type, then we capture the result of the call into
+--  a temporary, with the benefit that, if the result's type does
+--  not need finalization, nothing will be finalized and, if it
+--  does, the temporary only will be finalized by means of a direct
+--  call to the Finalize primitive if the result's type is not a
+--  class-wide type; whereas, in both cases, the stand-alone object
+--  itself would be finalized by means of a dispatching call to the
+--  Deep_Finalize routine.
+
+if Nkind (Expr_Q) = N_Function_Call
+  and then not Special_Ret_Obj
+  and then not Is_Library_Level_Entity (Def_Id)
+  and then Is_Class_Wide_Type (Typ)
+then
+   Remove_Side_Effects (Expr_Q);
+end if;
+
 --  In most cases, we must check that the initial value meets any
 --  constraint imposed by the declared type. However, there is one
 --  very important exception to this rule. If the entity has an
-- 
2.34.1



[COMMITTED] ada: Fix benign pasto in new predicate

2023-01-16 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

gcc/ada/

* exp_util.adb (Make_CW_Equivalent_Type.Has_Tag_Of_Type): Fix pasto.

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

---
 gcc/ada/exp_util.adb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index da5e84958ca..f6d91ca4a0e 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -9521,7 +9521,7 @@ package body Exp_Util is
 return True;
 
  else
-case Nkind (E) is
+case Nkind (Exp) is
--  The tag of a component or an aggregate of a specific tagged
--  type T identifies T.
 
-- 
2.34.1



[COMMITTED] ada: Put back conversion to interface in more cases

2023-01-16 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

This needs to be done for all expressions with class-wide type.

gcc/ada/

* exp_ch3.adb (Make_Allocator_For_Return): Put back an interface
conversion for expressions with non-interface class-wide type.

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

---
 gcc/ada/exp_ch3.adb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index c866a9c40f5..84594ed106b 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -7185,7 +7185,7 @@ package body Exp_Ch3 is
 --  remove earlier in the processing.
 
 if Is_Interface (Typ)
-  and then Is_Interface (Etype (Alloc_Expr))
+  and then Is_Class_Wide_Type (Etype (Alloc_Expr))
   and then Typ /= Etype (Alloc_Expr)
 then
Alloc_Expr := Convert_To (Typ, Alloc_Expr);
-- 
2.34.1



[COMMITTED] ada: Further optimize interface objects initialized with function calls

2023-01-16 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

This further optimizes the usual case of (class-wide) interface objects that
are initialized with calls to functions whose result type is the type of the
objects (this is not necessary as any result type implementing the interface
would do) by avoiding a back-and-forth displacement of the objects' address.

This exposed a latent issue whereby the displacement was missing in the case
of a simple return statement whose expression is a call to a function whose
result type is a specific tagged type that needs finalization.

And, in order to avoid pessimizing the expanded code, this in turn required
avoiding to create temporaries for allocators by calling Remove_Side_Effects
up front, in the common cases when they are not necessary.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration): Do not generate a back-
and-forth displacement of the object's address when using a renaming
for an interface object with an expression of the same type.
* exp_ch4.adb (Expand_Allocator_Expression): Do not remove the side
effects of the expression up front for the simple allocators. Do not
call the Adjust primitive if the expression is a function call.
* exp_ch6.adb (Expand_Ctrl_Function_Call): Do not expand the call
unnecessarily for a special return object.
(Expand_Simple_Function_Return): Restore the displacement of the
return object's address in the case where the expression is the call
to a function whose result type is a type that needs finalization.
* exp_util.adb (Expand_Subtype_From_Expr): Do not remove the side
effects of the expression before calling Make_Subtype_From_Expr.
(Make_CW_Equivalent_Type): If the expression has the tag of its type
and this type has a uniform size, use 'Object_Size of this type in
lieu of 'Size of the expression to compute the expression's size.

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

---
 gcc/ada/exp_ch3.adb  |  7 +++
 gcc/ada/exp_ch4.adb  | 18 +++---
 gcc/ada/exp_ch6.adb  | 22 ++
 gcc/ada/exp_util.adb | 36 +++-
 4 files changed, 51 insertions(+), 32 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 84594ed106b..bbb53fc6e49 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -7589,6 +7589,13 @@ package body Exp_Ch3 is
   Typ => Base_Typ);
end if;
 
+--  Renaming an expression of the object's type is immediate
+
+elsif Rewrite_As_Renaming
+  and then Base_Type (Etype (Expr_Q)) = Base_Type (Typ)
+then
+   null;
+
 elsif Tagged_Type_Expansion then
declare
   Iface : constant Entity_Id := Root_Type (Typ);
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index d3a4f574866..31823eaeca7 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -698,11 +698,14 @@ package body Exp_Ch4 is
  --  recursion and inappropriate call to Initialize.
 
  --  We don't want to remove side effects when the expression must be
- --  built in place. In the case of a build-in-place function call,
- --  that could lead to a duplication of the call, which was already
- --  substituted for the allocator.
+ --  built in place and we don't need it when there is no storage pool
+ --  or this is a return/secondary stack allocation.
 
- if not Aggr_In_Place then
+ if not Aggr_In_Place
+   and then Present (Storage_Pool (N))
+   and then not Is_RTE (Storage_Pool (N), RE_RS_Pool)
+   and then not Is_RTE (Storage_Pool (N), RE_SS_Pool)
+ then
 Remove_Side_Effects (Exp);
  end if;
 
@@ -747,7 +750,7 @@ package body Exp_Ch4 is
 
  --  Processing for allocators returning non-interface types
 
- if not Is_Interface (Directly_Designated_Type (PtrT)) then
+ if not Is_Interface (DesigT) then
 if Aggr_In_Place then
Temp_Decl :=
  Make_Object_Declaration (Loc,
@@ -960,8 +963,9 @@ package body Exp_Ch4 is
 
  if Needs_Finalization (DesigT)
and then Needs_Finalization (T)
-   and then not Aggr_In_Place
and then not Is_Limited_View (T)
+   and then not Aggr_In_Place
+   and then Nkind (Exp) /= N_Function_Call
and then not For_Special_Return_Object (N)
  then
 --  An unchecked conversion is needed in the classwide case because
@@ -993,7 +997,7 @@ package body Exp_Ch4 is
  --  component containing the secondary dispatch table of the interface
  --  type.
 
- if Is_Interface (Directly_Designated_Type (PtrT)) then
+ if Is_Interface (DesigT) then
 Displace_Allocator_Pointer (N);
  end if;
 
diff --git 

[COMMITTED] ada: Use static references to tag in more cases for interface objects

2023-01-16 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

This extends the use of static references to the interface tag in more cases
for (class-wide) interface objects, e.g. for initialization expressions that
are qualified aggregates or nondispatching calls returning a specific tagged
type implementing the interface.

gcc/ada/

* exp_util.ads (Has_Tag_Of_Type): Declare.
* exp_util.adb (Has_Tag_Of_Type): Move to package level.  Recurse on
qualified expressions.
* exp_ch3.adb (Expand_N_Object_Declaration): Use a static reference
to the interface tag in more cases for class-wide interface objects.

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

---
 gcc/ada/exp_ch3.adb  |  72 +---
 gcc/ada/exp_util.adb | 112 ++-
 gcc/ada/exp_util.ads |   4 ++
 3 files changed, 95 insertions(+), 93 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index bbb53fc6e49..6bc76aec5d1 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -7564,7 +7564,7 @@ package body Exp_Ch3 is
Expr_Q := Expr;
 end if;
 
---  We may use a renaming if the initializing expression is a
+--  We may use a renaming if the initialization expression is a
 --  captured function call that meets a few conditions.
 
 Rewrite_As_Renaming := Is_Renamable_Function_Call (Expr_Q);
@@ -7621,41 +7621,6 @@ package body Exp_Ch3 is
 
   Obj_Id := Make_Temporary (Loc, 'D', Expr_Q);
 
-  --  Replace
-  -- CW : I'Class := Obj;
-  --  by
-  -- Dnn : Typ := Obj;
-  -- type Ityp is not null access I'Class;
-  -- Rnn : constant Ityp := Ityp (Dnn.I_Tag'Address);
-  -- CW  : I'Class renames Rnn.all;
-
-  if Comes_From_Source (Expr_Q)
-and then Is_Entity_Name (Expr_Q)
-and then not Is_Interface (Expr_Typ)
-and then Interface_Present_In_Ancestor (Expr_Typ, Typ)
-and then (Expr_Typ = Etype (Expr_Typ)
-   or else not
- Is_Variable_Size_Record (Etype (Expr_Typ)))
-  then
- --  Copy the object
-
- Insert_Action (N,
-   Make_Object_Declaration (Loc,
- Defining_Identifier => Obj_Id,
- Object_Definition   =>
-   New_Occurrence_Of (Expr_Typ, Loc),
- Expression  => Relocate_Node (Expr_Q)));
-
- --  Statically reference the tag associated with the
- --  interface
-
- Tag_Comp :=
-   Make_Selected_Component (Loc,
- Prefix=> New_Occurrence_Of (Obj_Id, Loc),
- Selector_Name =>
-   New_Occurrence_Of
- (Find_Interface_Tag (Expr_Typ, Iface), Loc));
-
   --  Replace
   -- IW : I'Class := Expr;
   --  by
@@ -7665,7 +7630,7 @@ package body Exp_Ch3 is
   -- Ityp!(Displace (Dnn'Address, I'Tag));
   -- IW : I'Class renames Rnn.all;
 
-  elsif Rewrite_As_Renaming then
+  if Rewrite_As_Renaming then
  New_Expr :=
Make_Explicit_Dereference (Loc,
  Unchecked_Convert_To (RTE (RE_Tag_Ptr),
@@ -7697,6 +7662,37 @@ package body Exp_Ch3 is
  (Node (First_Elmt (Access_Disp_Table (Iface))),
   Loc)));
 
+  --  Replace
+  -- IW : I'Class := Expr;
+  --  by
+  -- Dnn : Typ := Expr;
+  -- type Ityp is not null access I'Class;
+  -- Rnn : constant Ityp := Ityp (Dnn.I_Tag'Address);
+  -- IW  : I'Class renames Rnn.all;
+
+  elsif Has_Tag_Of_Type (Expr_Q)
+and then Interface_Present_In_Ancestor (Expr_Typ, Typ)
+and then (Expr_Typ = Etype (Expr_Typ)
+   or else not
+ Is_Variable_Size_Record (Etype (Expr_Typ)))
+  then
+ Insert_Action (N,
+   Make_Object_Declaration (Loc,
+ Defining_Identifier => Obj_Id,
+ Object_Definition   =>
+   New_Occurrence_Of (Expr_Typ, Loc),
+ Expression  => Relocate_Node (Expr_Q)));
+
+ --  Statically reference the tag associated with the
+ --  interface
+
+ 

[COMMITTED] ada: Fix premature finalization of temporaries for interface objects

2023-01-16 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

This restores the proper finalization of temporaries for interface objects
in the case where the initializing expression is not of an interface type.

It turns out that neither Is_Temporary_For_Interface_Object nor its previous
incarnation are sufficient to catch all the various cases, so it is replaced
by a small enhancement to Is_Aliased, which is more robust.

gcc/ada/

* exp_util.adb (Is_Temporary_For_Interface_Object): Delete.
(Is_Finalizable_Transient.Is_Aliased): Deal with the specific case
of temporaries generated for interface objects.

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

---
 gcc/ada/exp_util.adb | 45 +---
 1 file changed, 17 insertions(+), 28 deletions(-)

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index f86b93819ac..da5e84958ca 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -168,11 +168,6 @@ package body Exp_Util is
--  Force evaluation of bounds of a slice, which may be given by a range
--  or by a subtype indication with or without a constraint.
 
-   function Is_Temporary_For_Interface_Object
- (Obj_Id : Entity_Id) return Boolean;
-   --  Determine whether Obj_Id is a temporary created for the handling of a
-   --  (class-wide) interface object.
-
function Is_Uninitialized_Aggregate
  (Exp : Node_Id;
   T   : Entity_Id) return Boolean;
@@ -8397,6 +8392,23 @@ package body Exp_Util is
Search (Name (Ren_Decl));
 end if;
 
+--  For renamings generated by Expand_N_Object_Declaration to deal
+--  with (class-wide) interface objects, there is an intermediate
+--  temporary of an anonymous access type used to hold the result
+--  of the displacement of the address of the renamed object.
+
+if Present (Ren_Obj)
+  and then Ekind (Ren_Obj) = E_Constant
+  and then Is_Itype (Etype (Ren_Obj))
+  and then Ekind (Etype (Ren_Obj)) = E_Anonymous_Access_Type
+  and then
+Is_Class_Wide_Type (Directly_Designated_Type (Etype (Ren_Obj)))
+  and then
+Is_Interface (Directly_Designated_Type (Etype (Ren_Obj)))
+then
+   Search (Constant_Value (Ren_Obj));
+end if;
+
 return Ren_Obj;
  end Find_Renamed_Object;
 
@@ -8638,11 +8650,6 @@ package body Exp_Util is
 
   and then not Initialized_By_Aliased_BIP_Func_Call (Obj_Id)
 
-  --  Do not consider temporaries created for (class-wide) interface
-  --  objects because they must exist as long as the object is around.
-
-  and then not Is_Temporary_For_Interface_Object (Obj_Id)
-
   --  Do not consider iterators because those are treated as normal
   --  controlled objects and are processed by the usual finalization
   --  machinery. This avoids the double finalization of an iterator.
@@ -9150,24 +9157,6 @@ package body Exp_Util is
 and then Has_Controlling_Result (Id);
end Is_Secondary_Stack_Thunk;
 
-   ---
-   -- Is_Temporary_For_Interface_Object --
-   ---
-
-   function Is_Temporary_For_Interface_Object
- (Obj_Id : Entity_Id) return Boolean
-   is
-  Expr : constant Node_Id := Expression (Declaration_Node (Obj_Id));
-
-   begin
-  --  This must be kept synchronized with Expand_N_Object_Declaration
-
-  return Is_Class_Wide_Type (Etype (Obj_Id))
-and then Present (Expr)
-and then Nkind (Expr) = N_Unchecked_Type_Conversion
-and then Is_RTE (Etype (Expression (Expr)), RE_Tag);
-   end Is_Temporary_For_Interface_Object;
-

-- Is_Uninitialized_Aggregate --

-- 
2.34.1



[COMMITTED] ada: Lift restriction on optimization of aliased objects

2023-01-16 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

It turns out that the only blocking case is an aliased object whose nominal
subtype is an unconstrained array because the bounds must be allocated.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration): Also optimize aliased
objects if their nominal subtype is not an unconstrained array.

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

---
 gcc/ada/exp_ch3.adb | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 536ae0c36e4..c866a9c40f5 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -7965,10 +7965,10 @@ package body Exp_Ch3 is
 
   Is_Entity_Name (Original_Node (Obj_Def))
 
---  The aliased case has to be excluded because the expression
---  will not be aliased in the general case.
+--  Nor if it is effectively an unconstrained declaration
 
-and then not Aliased_Present (N)
+and then not (Is_Array_Type (Typ)
+   and then Is_Constr_Subt_For_UN_Aliased (Typ))
 
 --  We may use a renaming if the initializing expression is a
 --  captured function call that meets a few conditions.
-- 
2.34.1



[COMMITTED] ada: Optimize interface objects initialized with function calls

2023-01-16 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

This optimizes the implementation of (class-wide) interface objects that are
initialized with function calls, by avoiding an unnecessary copy operation.
This also removes useless access checks generated by the expansion of return
statements involving class-wide types.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration): Factor out conditions
needed for an initializating expression that is a function call to
be renamable into the Is_Renamable_Function_Call predicate.
Use it to implement the renaming in the case of class-wide interface
objects.  Remove an interface conversion on all paths, separate and
optimize the renaming path in the special expansion for interfaces.
(Is_Renamable_Function_Call): New predicate.
(Make_Allocator_For_Return): Put back an interface conversion.
* exp_ch6.adb (Apply_CW_Accessibility_Check): Remove useless access
checks on RE_Tag_Ptr.

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

---
 gcc/ada/exp_ch3.adb | 283 ++--
 gcc/ada/exp_ch6.adb |  30 ++---
 2 files changed, 187 insertions(+), 126 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index f107b7ed36c..536ae0c36e4 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -6306,6 +6306,38 @@ package body Exp_Ch3 is
   --  Generate all initialization actions for return object Def_Id. Any
   --  new code is inserted after node After.
 
+  function Is_Renamable_Function_Call (Expr : Node_Id) return Boolean;
+  --  If we are not at library level and the object declaration originally
+  --  appears in the form:
+
+  --Obj : Typ := Func (...);
+
+  --  and has been rewritten as the dereference of a captured reference
+  --  to the function result built either on the primary or the secondary
+  --  stack, then the declaration can be rewritten as the renaming of this
+  --  dereference:
+
+  --type Ann is access all Typ;
+  --Rnn : constant Axx := Func (...)'reference;
+  --Obj : Typ renames Rnn.all;
+
+  --  This will avoid making an extra copy and, in the case where Typ needs
+  --  finalization, a pair of calls to the Adjust and Finalize primitives,
+  --  or Deep_Adjust and Deep_Finalize routines, depending on whether Typ
+  --  has components that themselves need finalization.
+
+  --  However, in the case of a special return object, we need to make sure
+  --  that the object Rnn is recognized by the Is_Related_To_Func_Return
+  --  predicate; otherwise, if it is of a type that needs finalization,
+  --  then Requires_Cleanup_Actions would return true because of this and
+  --  Build_Finalizer would finalize it prematurely because of this (see
+  --  also Expand_Simple_Function_Return for the same test in the case of
+  --  a simple return).
+
+  --  Finally, in the case of a special return object, we also need to make
+  --  sure that the two functions return on the same stack, otherwise we
+  --  would create a dangling reference.
+
   function Make_Allocator_For_Return (Expr : Node_Id) return Node_Id;
   --  Make an allocator for a return object initialized with Expr
 
@@ -7100,12 +7132,28 @@ package body Exp_Ch3 is
  end if;
   end Initialize_Return_Object;
 
+  
+  -- Is_Renamable_Function_Call --
+  
+
+  function Is_Renamable_Function_Call (Expr : Node_Id) return Boolean is
+  begin
+ return not Is_Library_Level_Entity (Def_Id)
+   and then Is_Captured_Function_Call (Expr)
+   and then (not Special_Ret_Obj
+  or else
+(Is_Related_To_Func_Return (Entity (Prefix (Expr)))
+  and then Needs_Secondary_Stack (Etype (Expr)) =
+   Needs_Secondary_Stack (Etype (Func_Id;
+  end Is_Renamable_Function_Call;
+
   ---
   -- Make_Allocator_For_Return --
   ---
 
   function Make_Allocator_For_Return (Expr : Node_Id) return Node_Id is
- Alloc : Node_Id;
+ Alloc  : Node_Id;
+ Alloc_Expr : Entity_Id;
 
   begin
  --  If the return object's declaration includes an expression and the
@@ -7131,6 +7179,18 @@ package body Exp_Ch3 is
Apply_CW_Accessibility_Check (Expr, Func_Id);
 end if;
 
+Alloc_Expr := New_Copy_Tree (Expr);
+
+--  In the interface case, put back a conversion that we may have
+--  remove earlier in the processing.
+
+if Is_Interface (Typ)
+  and then Is_Interface (Etype (Alloc_Expr))
+  and then Typ /= Etype (Alloc_Expr)
+then
+   Alloc_Expr := Convert_To (Typ, 

Re: [PATCH] libgccjit: Fix a failing test

2023-01-16 Thread Guillaume Gomez via Gcc-patches
Ping David.

Le jeu. 5 janv. 2023 à 23:37, Guillaume Gomez 
a écrit :

> Ping David.
>
> Le sam. 24 déc. 2022 à 21:01, Guillaume Gomez 
> a écrit :
>
>> Ping David
>>
>> Le jeu. 15 déc. 2022 à 11:34, Guillaume Gomez 
>> a écrit :
>>
>>> Forgot it indeed, thanks for notifying me!
>>>
>>> I modified the commit message to add it and added it into this email.
>>>
>>> Le mer. 14 déc. 2022 à 16:12, Antoni Boucher  a
>>> écrit :
>>>
 Thanks!

 In your patch, you're missing this line at the end of the commit
 message:

Signed-off-by: Guillaume Gomez 

 On Wed, 2022-12-14 at 14:39 +0100, Guillaume Gomez via Jit wrote:
 > Hi,
 >
 > This fixes bug 107999.
 >
 > Thanks in advance for the review.




lrealpath() patch to fix symlinks resolution for win32

2023-01-16 Thread i.nixman--- via Gcc-patches


hello,

I just finished with https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108350

could anyone review and apply the attached patch please?


GCC master was succesfully bootstrapped as x86_64-w64-mingw32.



best!
diff --git a/libiberty/lrealpath.c b/libiberty/lrealpath.c
index 3c7053b0b70..8858619e854 100644
--- a/libiberty/lrealpath.c
+++ b/libiberty/lrealpath.c
@@ -68,8 +68,138 @@ extern char *canonicalize_file_name (const char *);
   /* cygwin has realpath, so it won't get here.  */ 
 # if defined (_WIN32)
 #  define WIN32_LEAN_AND_MEAN
-#  include  /* for GetFullPathName */
-# endif
+#  include  /* for GetFullPathName/GetFinalPathNameByHandle/
+  CreateFile/CloseHandle */
+#  define WIN32_REPLACE_SLASHES(_ptr, _len) \
+ for (unsigned i = 0; i != (_len); ++i) \
+   if ((_ptr)[i] == '\\') (_ptr)[i] = '/';
+
+#  define WIN32_UNC_PREFIX "//?/UNC/"
+#  define WIN32_UNC_PREFIX_LEN (sizeof(WIN32_UNC_PREFIX)-1)
+#  define WIN32_IS_UNC_PREFIX(ptr) \
+  (0 == memcmp(ptr, WIN32_UNC_PREFIX, WIN32_UNC_PREFIX_LEN))
+
+#  define WIN32_NON_UNC_PREFIX "//?/"
+#  define WIN32_NON_UNC_PREFIX_LEN (sizeof(WIN32_NON_UNC_PREFIX)-1)
+#  define WIN32_IS_NON_UNC_PREFIX(ptr) \
+  (0 == memcmp(ptr, WIN32_NON_UNC_PREFIX, WIN32_NON_UNC_PREFIX_LEN))
+
+# define WIN32_IS_SPECIAL_NUL_FILE(ptr) \
+  (0 == memcmp(ptr, "NUL", 3) || 0 == memcmp(ptr, "nul", 3))
+
+/* Get full path name without symlinks resolution.
+   It also converts all forward slashes to back slashes.
+*/
+char* get_full_path_name(const char *filename) {
+  DWORD len;
+  char *buf, *ptr, *res;
+
+  /* determining the required buffer size.
+ from the man: `If the lpBuffer buffer is too small to contain
+ the path, the return value is the size, in TCHARs, of the buffer
+ that is required to hold the path _and_the_terminating_null_character_`
+  */
+  len = GetFullPathName(filename, 0, NULL, NULL);
+
+  if ( len == 0 )
+return strdup(filename);
+
+  buf = (char *)malloc(len);
+
+  /* no point to check the result again */
+  len = GetFullPathName(filename, len, buf, NULL);
+  buf[len] = 0;
+
+  /* replace slashes */
+  WIN32_REPLACE_SLASHES(buf, len);
+
+  /* calculate offset based on prefix type */
+  len = WIN32_IS_UNC_PREFIX(buf)
+? (WIN32_UNC_PREFIX_LEN - 2)
+: WIN32_IS_NON_UNC_PREFIX(buf)
+  ? WIN32_NON_UNC_PREFIX_LEN
+  : 0
+  ;
+
+  ptr = buf + len;
+  if ( WIN32_IS_UNC_PREFIX(buf) ) {
+ptr[0] = '/';
+ptr[1] = '/';
+  }
+
+  res = strdup(ptr);
+
+  free(buf);
+
+  return res;
+}
+
+# if _WIN32_WINNT >= 0x0600
+
+/* Get full path name WITH symlinks resolution.
+   It also converts all forward slashes to back slashes.
+*/
+char* get_final_path_name(HANDLE fh) {
+  DWORD len;
+  char *buf, *ptr, *res;
+
+  /* determining the required buffer size.
+ from the  man: `If the function fails because lpszFilePath is too
+ small to hold the string plus the terminating null character,
+ the return value is the required buffer size, in TCHARs. This
+ value _includes_the_size_of_the_terminating_null_character_`.
+ but in my testcase I have path with 26 chars, the function
+ returns 26 also, ie without the trailing zero-char...
+  */
+  len = GetFinalPathNameByHandle(
+ fh
+,NULL
+,0
+,FILE_NAME_NORMALIZED | VOLUME_NAME_DOS
+  );
+
+  if ( len == 0 )
+return NULL;
+
+  len += 1; /* for zero-char */
+  buf = (char *)malloc(len);
+
+  /* no point to check the result again */
+  len = GetFinalPathNameByHandle(
+ fh
+,buf
+,len
+,FILE_NAME_NORMALIZED | VOLUME_NAME_DOS
+  );
+  buf[len] = 0;
+
+  /* replace slashes */
+  WIN32_REPLACE_SLASHES(buf, len);
+
+  /* calculate offset based on prefix type */
+  len = WIN32_IS_UNC_PREFIX(buf)
+? (WIN32_UNC_PREFIX_LEN - 2)
+: WIN32_IS_NON_UNC_PREFIX(buf)
+  ? WIN32_NON_UNC_PREFIX_LEN
+  : 0
+  ;
+
+  ptr = buf + len;
+  if ( WIN32_IS_UNC_PREFIX(buf) ) {
+ptr[0] = '/';
+ptr[1] = '/';
+  }
+
+  res = strdup(ptr);
+
+  free(buf);
+
+  return res;
+}
+
+# endif // _WIN32_WINNT >= 0x0600
+
+# endif // _WIN32
 #endif
 
 char *
@@ -128,30 +258,51 @@ lrealpath (const char *filename)
   }
 #endif
 
-  /* The MS Windows method.  If we don't have realpath, we assume we
- don't have symlinks and just canonicalize to a Windows absolute
- path.  GetFullPath converts ../ and ./ in relative paths to
- absolute paths, filling in current drive if one is not given
- or using the current directory of a specified drive (eg, "E:foo").
- It also converts all forward slashes to back slashes.  */
+  /* The MS Windows method */
 #if defined (_WIN32)
   {
-char buf[MAX_PATH];
-char* basename;
-DWORD len = GetFullPathName (filename, MAX_PATH, buf, );
-if (len == 0 || len > MAX_PATH - 1)
-  return strdup (filename);
-else
-  {
-	/* The file system is case-preserving but case-insensitive,
-	   Canonicalize to lowercase, using the codepage associated
-	   with the process 

Re: [PATCH 9/8] middle-end: Allow build_popcount_expr to use an IFN

2023-01-16 Thread Andrew Carlotti via Gcc-patches
Erm, ignore this - I just rediscovered the approval in a different mail
folder. I forgot that Outlook's automatic email dedpulication meant that
messages CC'd to me end up in one of two different folders at random
when I want them in both.


On Mon, Jan 16, 2023 at 02:03:29PM +, Andrew Carlotti via Gcc-patches wrote:
> Hi Richard
> 
> I accidentally pushed this patch earlier in the mistaken belief that
> you'd already approved it. It looks uncontroversial to me - it just adds
> IFN support to build_popcount_expr, analogous to the changes you
> suggested and approved for build_cltz_expr (and adjusts testcases
> accordingly). I might have incorporated it into an earlier patch in this
> series, if I hadn't already pushed that earlier patch.
> 
> Is this OK to leave in master now?
> 
> Thanks,
> Andrew
> 
> On Thu, Dec 22, 2022 at 05:43:21PM +, Andrew Carlotti via Gcc-patches 
> wrote:
> > Bootstrapped and regression tested on aarch64-unknown-linux-gnu and
> > x86_64-pc-linux-gnu - ok to merge?
> > 
> > gcc/ChangeLog:
> > 
> > * tree-ssa-loop-niter.cc (build_popcount_expr): Add IFN support.
> > 
> > gcc/testsuite/ChangeLog:
> > 
> > * g++.dg/tree-ssa/pr86544.C: Add .POPCOUNT to tree scan regex.
> > * gcc.dg/tree-ssa/popcount.c: Likewise.
> > * gcc.dg/tree-ssa/popcount2.c: Likewise.
> > * gcc.dg/tree-ssa/popcount3.c: Likewise.
> > * gcc.target/aarch64/popcount4.c: Likewise.
> > * gcc.target/i386/pr95771.c: Likewise, and...
> > * gcc.target/i386/pr95771-2.c: ...split int128 test from above,
> > since this would emit just a single IFN if a TI optab is added.
> > 
> > ---
> > 
> > diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr86544.C 
> > b/gcc/testsuite/g++.dg/tree-ssa/pr86544.C
> > index 
> > ef438916a8019320564f444ace08e2f4b4190684..50befb36bac75de1cfa282e38358278b3288bd1c
> >  100644
> > --- a/gcc/testsuite/g++.dg/tree-ssa/pr86544.C
> > +++ b/gcc/testsuite/g++.dg/tree-ssa/pr86544.C
> > @@ -12,5 +12,5 @@ int PopCount (long b) {
> >  return c;
> >  }
> >  
> > -/* { dg-final { scan-tree-dump-times "__builtin_popcount" 1 "optimized" } 
> > } */
> > +/* { dg-final { scan-tree-dump-times "__builtin_popcount|\\.POPCOUNT" 1 
> > "optimized" } } */
> >  /* { dg-final { scan-tree-dump-times "if" 0 "phiopt4" } } */
> > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/popcount.c 
> > b/gcc/testsuite/gcc.dg/tree-ssa/popcount.c
> > index 
> > b4694109411a4631697463519acbe7d9df65bf6e..efd906a0f5447f0beb3752eded3756999b02e6e6
> >  100644
> > --- a/gcc/testsuite/gcc.dg/tree-ssa/popcount.c
> > +++ b/gcc/testsuite/gcc.dg/tree-ssa/popcount.c
> > @@ -39,4 +39,4 @@ void PopCount3 (long b1) {
> >}
> >  }
> >  
> > -/* { dg-final { scan-tree-dump-times "__builtin_popcount" 3 "optimized" } 
> > } */
> > +/* { dg-final { scan-tree-dump-times "__builtin_popcount|\\.POPCOUNT" 3 
> > "optimized" } } */
> > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/popcount2.c 
> > b/gcc/testsuite/gcc.dg/tree-ssa/popcount2.c
> > index 
> > ef73e345573de721833e98e89c252640a55f7c60..ae38a329bd4d868a762300d3218d68864c0fc4be
> >  100644
> > --- a/gcc/testsuite/gcc.dg/tree-ssa/popcount2.c
> > +++ b/gcc/testsuite/gcc.dg/tree-ssa/popcount2.c
> > @@ -26,4 +26,4 @@ int main()
> >return 0;
> >  }
> >  
> > -/* { dg-final { scan-tree-dump-times "__builtin_popcount" 1 "optimized" } 
> > } */
> > +/* { dg-final { scan-tree-dump-times "__builtin_popcount|\\.POPCOUNT" 1 
> > "optimized" } } */
> > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/popcount3.c 
> > b/gcc/testsuite/gcc.dg/tree-ssa/popcount3.c
> > index 
> > ef438916a8019320564f444ace08e2f4b4190684..50befb36bac75de1cfa282e38358278b3288bd1c
> >  100644
> > --- a/gcc/testsuite/gcc.dg/tree-ssa/popcount3.c
> > +++ b/gcc/testsuite/gcc.dg/tree-ssa/popcount3.c
> > @@ -12,5 +12,5 @@ int PopCount (long b) {
> >  return c;
> >  }
> >  
> > -/* { dg-final { scan-tree-dump-times "__builtin_popcount" 1 "optimized" } 
> > } */
> > +/* { dg-final { scan-tree-dump-times "__builtin_popcount|\\.POPCOUNT" 1 
> > "optimized" } } */
> >  /* { dg-final { scan-tree-dump-times "if" 0 "phiopt4" } } */
> > diff --git a/gcc/testsuite/gcc.target/aarch64/popcount4.c 
> > b/gcc/testsuite/gcc.target/aarch64/popcount4.c
> > index 
> > ee55b2e335223053ca024e95b7a13aa4af32550e..8aa15ff018d4b5fc6bb59e52af20d5c33cea2ee0
> >  100644
> > --- a/gcc/testsuite/gcc.target/aarch64/popcount4.c
> > +++ b/gcc/testsuite/gcc.target/aarch64/popcount4.c
> > @@ -11,4 +11,4 @@ int PopCount (long b) {
> >  return c;
> >  }
> >  
> > -/* { dg-final { scan-tree-dump-times "__builtin_popcount" 0 "optimized" } 
> > } */
> > +/* { dg-final { scan-tree-dump-times "__builtin_popcount|\\.POPCOUNT" 0 
> > "optimized" } } */
> > diff --git a/gcc/testsuite/gcc.target/i386/pr95771-2.c 
> > b/gcc/testsuite/gcc.target/i386/pr95771-2.c
> > new file mode 100644
> > index 
> > ..1db9dc94d0b66477667624012221d6844c141a26
> > --- /dev/null
> > +++ 

Re: [PATCH 9/8] middle-end: Allow build_popcount_expr to use an IFN

2023-01-16 Thread Andrew Carlotti via Gcc-patches
Hi Richard

I accidentally pushed this patch earlier in the mistaken belief that
you'd already approved it. It looks uncontroversial to me - it just adds
IFN support to build_popcount_expr, analogous to the changes you
suggested and approved for build_cltz_expr (and adjusts testcases
accordingly). I might have incorporated it into an earlier patch in this
series, if I hadn't already pushed that earlier patch.

Is this OK to leave in master now?

Thanks,
Andrew

On Thu, Dec 22, 2022 at 05:43:21PM +, Andrew Carlotti via Gcc-patches wrote:
> Bootstrapped and regression tested on aarch64-unknown-linux-gnu and
> x86_64-pc-linux-gnu - ok to merge?
> 
> gcc/ChangeLog:
> 
>   * tree-ssa-loop-niter.cc (build_popcount_expr): Add IFN support.
> 
> gcc/testsuite/ChangeLog:
> 
>   * g++.dg/tree-ssa/pr86544.C: Add .POPCOUNT to tree scan regex.
>   * gcc.dg/tree-ssa/popcount.c: Likewise.
>   * gcc.dg/tree-ssa/popcount2.c: Likewise.
>   * gcc.dg/tree-ssa/popcount3.c: Likewise.
>   * gcc.target/aarch64/popcount4.c: Likewise.
>   * gcc.target/i386/pr95771.c: Likewise, and...
>   * gcc.target/i386/pr95771-2.c: ...split int128 test from above,
>   since this would emit just a single IFN if a TI optab is added.
> 
> ---
> 
> diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr86544.C 
> b/gcc/testsuite/g++.dg/tree-ssa/pr86544.C
> index 
> ef438916a8019320564f444ace08e2f4b4190684..50befb36bac75de1cfa282e38358278b3288bd1c
>  100644
> --- a/gcc/testsuite/g++.dg/tree-ssa/pr86544.C
> +++ b/gcc/testsuite/g++.dg/tree-ssa/pr86544.C
> @@ -12,5 +12,5 @@ int PopCount (long b) {
>  return c;
>  }
>  
> -/* { dg-final { scan-tree-dump-times "__builtin_popcount" 1 "optimized" } } 
> */
> +/* { dg-final { scan-tree-dump-times "__builtin_popcount|\\.POPCOUNT" 1 
> "optimized" } } */
>  /* { dg-final { scan-tree-dump-times "if" 0 "phiopt4" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/popcount.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/popcount.c
> index 
> b4694109411a4631697463519acbe7d9df65bf6e..efd906a0f5447f0beb3752eded3756999b02e6e6
>  100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/popcount.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/popcount.c
> @@ -39,4 +39,4 @@ void PopCount3 (long b1) {
>}
>  }
>  
> -/* { dg-final { scan-tree-dump-times "__builtin_popcount" 3 "optimized" } } 
> */
> +/* { dg-final { scan-tree-dump-times "__builtin_popcount|\\.POPCOUNT" 3 
> "optimized" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/popcount2.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/popcount2.c
> index 
> ef73e345573de721833e98e89c252640a55f7c60..ae38a329bd4d868a762300d3218d68864c0fc4be
>  100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/popcount2.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/popcount2.c
> @@ -26,4 +26,4 @@ int main()
>return 0;
>  }
>  
> -/* { dg-final { scan-tree-dump-times "__builtin_popcount" 1 "optimized" } } 
> */
> +/* { dg-final { scan-tree-dump-times "__builtin_popcount|\\.POPCOUNT" 1 
> "optimized" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/popcount3.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/popcount3.c
> index 
> ef438916a8019320564f444ace08e2f4b4190684..50befb36bac75de1cfa282e38358278b3288bd1c
>  100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/popcount3.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/popcount3.c
> @@ -12,5 +12,5 @@ int PopCount (long b) {
>  return c;
>  }
>  
> -/* { dg-final { scan-tree-dump-times "__builtin_popcount" 1 "optimized" } } 
> */
> +/* { dg-final { scan-tree-dump-times "__builtin_popcount|\\.POPCOUNT" 1 
> "optimized" } } */
>  /* { dg-final { scan-tree-dump-times "if" 0 "phiopt4" } } */
> diff --git a/gcc/testsuite/gcc.target/aarch64/popcount4.c 
> b/gcc/testsuite/gcc.target/aarch64/popcount4.c
> index 
> ee55b2e335223053ca024e95b7a13aa4af32550e..8aa15ff018d4b5fc6bb59e52af20d5c33cea2ee0
>  100644
> --- a/gcc/testsuite/gcc.target/aarch64/popcount4.c
> +++ b/gcc/testsuite/gcc.target/aarch64/popcount4.c
> @@ -11,4 +11,4 @@ int PopCount (long b) {
>  return c;
>  }
>  
> -/* { dg-final { scan-tree-dump-times "__builtin_popcount" 0 "optimized" } } 
> */
> +/* { dg-final { scan-tree-dump-times "__builtin_popcount|\\.POPCOUNT" 0 
> "optimized" } } */
> diff --git a/gcc/testsuite/gcc.target/i386/pr95771-2.c 
> b/gcc/testsuite/gcc.target/i386/pr95771-2.c
> new file mode 100644
> index 
> ..1db9dc94d0b66477667624012221d6844c141a26
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr95771-2.c
> @@ -0,0 +1,17 @@
> +/* PR tree-optimization/95771 */
> +/* { dg-do compile } */
> +/* { dg-require-effective-target int128 } */
> +/* { dg-options "-O2 -mpopcnt -fdump-tree-optimized" } */
> +/* { dg-final { scan-tree-dump " = __builtin_popcount| = \\.POPCOUNT" 
> "optimized" } } */
> +
> +int
> +corge (unsigned __int128 x)
> +{
> +  int i = 0;
> +  while (x)
> +{
> +  x &= x - 1;
> +  ++i;
> +}
> +  return i;
> +}
> diff --git a/gcc/testsuite/gcc.target/i386/pr95771.c 
> b/gcc/testsuite/gcc.target/i386/pr95771.c
> 

Re: [PATCH] RISC-V: Call DCE to remove redundant instructions created by the PASS

2023-01-16 Thread Kito Cheng via Gcc-patches
After discussing with Ju.Zhe, we decided to rearrange the pass of vsetvl
insertion instead of call run_fast_dce within this pass.

On Tue, Jan 10, 2023 at 7:21 AM  wrote:

> From: Ju-Zhe Zhong 
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vsetvl.cc (pass_vsetvl::done): Add DCE.
> * config/riscv/t-riscv: Add DCE.
>
> ---
>  gcc/config/riscv/riscv-vsetvl.cc | 2 ++
>  gcc/config/riscv/t-riscv | 2 +-
>  2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc
> b/gcc/config/riscv/riscv-vsetvl.cc
> index 7d8c3a32aaa..7aa2852b456 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -87,6 +87,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "predict.h"
>  #include "profile-count.h"
>  #include "riscv-vsetvl.h"
> +#include "dce.h"
>
>  using namespace rtl_ssa;
>  using namespace riscv_vector;
> @@ -2627,6 +2628,7 @@ pass_vsetvl::done (void)
> cleanup_cfg (0);
>delete crtl->ssa;
>crtl->ssa = nullptr;
> +  run_fast_dce ();
>  }
>m_vector_manager->release ();
>delete m_vector_manager;
> diff --git a/gcc/config/riscv/t-riscv b/gcc/config/riscv/t-riscv
> index d30e0235356..c95f4aff358 100644
> --- a/gcc/config/riscv/t-riscv
> +++ b/gcc/config/riscv/t-riscv
> @@ -54,7 +54,7 @@ riscv-c.o: $(srcdir)/config/riscv/riscv-c.cc $(CONFIG_H)
> $(SYSTEM_H) \
>  riscv-vsetvl.o: $(srcdir)/config/riscv/riscv-vsetvl.cc \
>$(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) $(REGS_H) \
>$(TARGET_H) tree-pass.h df.h rtl-ssa.h cfgcleanup.h insn-config.h \
> -  insn-attr.h insn-opinit.h tm-constrs.h cfgrtl.h cfganal.h lcm.h \
> +  insn-attr.h insn-opinit.h tm-constrs.h cfgrtl.h cfganal.h lcm.h dce.h \
>predict.h profile-count.h $(srcdir)/config/riscv/riscv-vsetvl.h
> $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
> $(srcdir)/config/riscv/riscv-vsetvl.cc
> --
> 2.36.1
>
>


Re: [PATCH 8/9] solaris2: Don't add crtfastmath.o for -shared

2023-01-16 Thread Rainer Orth
Hi Richard,

> Don't add crtfastmath.o for -shared to avoid altering the FP
> environment when loading a shared library.
>
>   PR target/55522
>   * config/sol2.h (ENDFILE_SPEC): Don't add crtfastmath.o for -shared.

tested on i386-pc-solaris2.11 and sparc-sun-solaris2.11.

Ok.

Thanks.
Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


Re: [committed] libstdc++: Do not include in concurrency headers

2023-01-16 Thread Rainer Orth
Hi Jonathan,

> On Fri, 13 Jan 2023 at 16:39, Jonathan Wakely wrote:
>>
>> On Fri, 13 Jan 2023 at 15:08, Rainer Orth wrote:
>> >
>> > Hi Jonathan,
>> >
>> > > The , , and  headers use
>> > > std::errc constants, but don't use std::system_error itself. They only
>> > > use the __throw_system_error(int) function, which is defined in
>> > > .
>> > >
>> > > By including the header for the errc constants instead of the whole of
>> > >  we avoid depending on the whole std::string definition.
>> >
>> > it seems this patch broke many tests on Solaris, e.g.
>> >
>> > FAIL: 29_atomics/atomic/requirements/types_neg.cc (test for excess errors)
>> > Excess errors:
>> > /var/gcc/regression/master/11.4-gcc/build/i386-pc-solaris2.11/libstdc++-v3/include/bits/std_mutex.h:157:
>> > error: 'EBUSY' was not declared in this scope
>> >
>>
>> Oops, testing this patch now.
>
> Pushed to trunk - thanks for the report!

great, thanks for the quick fix.

Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


[PATCH] rs6000: Fix typo on vec_vsubcuq in rs6000-overload.def [PR108396]

2023-01-16 Thread Kewen.Lin via Gcc-patches
Hi,

As Andrew pointed out in PR108396, there is one typo in
rs6000-overload.def on built-in function vec_vsubcuq:

  [VEC_VSUBCUQ, vec_vsubcuqP, __builtin_vec_vsubcuq]

"vec_vsubcuqP" should be "vec_vsubcuq", this typo caused
us to define vec_vsubcuqP in rs6000-vecdefines.h instead
of vec_vsubcuq, so that compiler is not able to realize
the built-in function name vec_vsubcuq any more.

Testing is ongoing, since this is obvious I'll commit
this once everything goes well in testing, and then
backport this in a week or so.

BR,
Kewen
-
Co-authored-By: Andrew Pinski 

PR target/108396

gcc/ChangeLog:

* config/rs6000/rs6000-overload.def (VEC_VSUBCUQ): Fix typo
vec_vsubcuqP with vec_vsubcuq.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr108396.c: New test.
---
 gcc/config/rs6000/rs6000-overload.def   |  2 +-
 gcc/testsuite/gcc.target/powerpc/pr108396.c | 14 ++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108396.c

diff --git a/gcc/config/rs6000/rs6000-overload.def 
b/gcc/config/rs6000/rs6000-overload.def
index 44e2945aaa0..9135b8d6966 100644
--- a/gcc/config/rs6000/rs6000-overload.def
+++ b/gcc/config/rs6000/rs6000-overload.def
@@ -5930,7 +5930,7 @@
   unsigned int __builtin_vec_scalar_test_data_class_sp (float, const int);
 VSTDCSP  VSTDCSP_DEPR1

-[VEC_VSUBCUQ, vec_vsubcuqP, __builtin_vec_vsubcuq]
+[VEC_VSUBCUQ, vec_vsubcuq, __builtin_vec_vsubcuq]
   vsq __builtin_vec_vsubcuq (vsq, vsq);
 VSUBCUQ  VSUBCUQ_DEPR1
   vuq __builtin_vec_vsubcuq (vuq, vuq);
diff --git a/gcc/testsuite/gcc.target/powerpc/pr108396.c 
b/gcc/testsuite/gcc.target/powerpc/pr108396.c
new file mode 100644
index 000..a783f0823a6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr108396.c
@@ -0,0 +1,14 @@
+/* { dg-require-effective-target powerpc_p8vector_ok } */
+/* { dg-require-effective-target int128 } */
+/* { dg-options "-mdejagnu-cpu=power8" } */
+
+/* Verify there is no error message.  */
+
+#include 
+
+vector unsigned __int128
+vsubcuq (vector unsigned __int128 a, vector unsigned __int128 b)
+{
+  return vec_vsubcuq (a, b);
+}
+
--
2.27.0


Re: [PATCH] rs6000: Teach rs6000_opaque_type_invalid_use_p about gcall [PR108348]

2023-01-16 Thread Kewen.Lin via Gcc-patches
Hi Segher!

on 2023/1/16 18:40, Segher Boessenkool wrote:
> Hi!
> 
> On Mon, Jan 16, 2023 at 05:20:56PM +0800, Kewen.Lin wrote:
>> on 2023/1/16 16:49, Segher Boessenkool wrote:
 +/* { dg-require-effective-target powerpc_p9modulo_ok } */
>>>
>>> Please use a saner selector?  If one doesn't exist yet, make a new one?
>>> Something that just says "p9", not "modulo".
>>
>> The has_arch_pwr9 looks not suitable here as it doesn't check
>> the assembler behavior?
> 
> ?  What assembler behaviour?

I should have said assembler "support", selector powerpc_p9modulo_ok
checks if assembler supports some insn or not, but has_arch_pwr9
doesn't.

> 
>> Do you have some instruction in mind
>> for being used as the tested instruction mnemonic like modsw?
> 
> It should not test *any* instruction?
> 
> Ah.  There is no *_ok wanted or needed at all.  You simply are required
> to use a new enough binutils to fit your GCC.  During development you
> probably want something, but that should not end up in the public trees.
> You can always use -mcpu=power9.  If your toolchain is broken that will
> throw some pretty obvious errors your way; this is fine.  A user can
> always say -mcpu=power9.

> The *_ok things should only be used for features that can be disabled
> during configuration, or features that we *want* users to be able to
> turn off (like FP, VMX, VSX, or HMT or QP float, that kind of thing).
> That gives quite enough permutations to test already, we do not need to
> create a whole bunch extra for no reason :-)

Thanks for the explanation!!  I meant to use powerpc_p9modulo_ok to
exclude those cases where we can't use -mcpu=power9, as you explained we
should not worry about it!?  Since the test point requires altivec support
(which is implied when specifying -mcpu=power9, I didn't explicitly specify
it before), I think I could use powerpc_altivec_ok to replace
powerpc_p9modulo_ok here, does it sound good to you?

BR,
Kewen


Re: [PATCH] libgcc: Fix uninitialized RA signing on AArch64 [PR107678]

2023-01-16 Thread Martin Liška
On 1/12/23 19:57, Jakub Jelinek via Gcc-patches wrote:
> On Tue, Jan 10, 2023 at 04:33:59PM +, Wilco Dijkstra via Gcc-patches 
> wrote:
>> Hi Szabolcs,
>>
>>> i would keep the assert: how[reg] must be either UNSAVED or UNDEFINED
>>> here, other how[reg] means the toggle cfi instruction is mixed with
>>> incompatible instructions for the pseudo reg.
>>>
>>> and i would add a comment about this e.g. saying that UNSAVED/UNDEFINED
>>> how[reg] is used for tracking the return address signing status and
>>> other how[reg] is not allowed here.
>>
>> I've added the assert back and updated the comment.
> 
> BTW, the patch doesn't apply to trunk cleanly (since the January 2nd
> r13-4955-gcb775ecd6e437 commit).

@Wilco, can you please send the rebased patch for patch review? We would
need in out openSUSE package soon.

Thank you,
Martin

> 
>> v3: Improve comments, add assert.
>>
>> A recent change only initializes the regs.how[] during Dwarf unwinding
>> which resulted in an uninitialized offset used in return address signing
>> and random failures during unwinding.  The fix is to encode the return
>> address signing state in REG_UNSAVED and REG_UNDEFINED.
>>
>> Passes bootstrap & regress, OK for commit?
>>
>> libgcc/
>> PR target/107678
>> * unwind-dw2.c (execute_cfa_program): Use REG_UNSAVED/UNDEFINED
>> to encode return address signing state.
>> * config/aarch64/aarch64-unwind.h (aarch64_demangle_return_addr)
>> Check current return address signing state.
>> (aarch64_frob_update_contex): Remove.
> 
>   Jakub
> 



Re: [PATCH] IPA: do not release body if still needed

2023-01-16 Thread Martin Liška
On 1/14/23 22:36, Jan Hubicka wrote:
>> Hi.
>>
>> Noticed during building of libbackend.a with the LTO partial linking.
>>
>> The function release_body is called even if clone_of is a clone
>> of a another function and thus it shares tree declaration. We should
>> preserve it in that situation.
>>
>> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>>
>> Ready to be installed?
>> Thanks,
>> Martin
>>
>>  PR ipa/107944
>>
>> gcc/ChangeLog:
>>
>>  * cgraph.cc (cgraph_node::remove): Do not release body
>>  if a node is clone of another node.
>> ---
>>  gcc/cgraph.cc | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
>> index f15cb47c8b8..2e7d77ffd6c 100644
>> --- a/gcc/cgraph.cc
>> +++ b/gcc/cgraph.cc
>> @@ -1893,7 +1893,7 @@ cgraph_node::remove (void)
>>else if (clone_of)
>>  {
>>clone_of->clones = next_sibling_clone;
>> -  if (!clone_of->analyzed && !clone_of->clones && !clones)
>> +  if (!clone_of->analyzed && !clone_of->clones && !clones && 
>> !clone_of->clone_of)
>>  clone_of->release_body ();
> 
> It is interesting that the problem reproduced only after almost 20
> years.  But I suppose it is because we materialize clones in parituclar
> order.

Well, it started with r13-48-g27ee75dbe81bb7 where Martin add a new code
that calls the release_body function. So it's pretty new.

> 
> I think there are two ways to fix it.  Either declare release_body to be
> applicable only to the master clone and avoid calling it here (as you
> do) or make release_body do nothing when called on a clone.
> I guess it makes sense to keep your approach but please add sanity check
> to release_body that clone_of == NULL with a comment.

I do support Martin's enhanced version of the patch.

Cheers,
Martin

> 
> OK with that change.
> Honza
>>  }
>>if (next_sibling_clone)
>> -- 
>> 2.38.1
>>



GCC 13.0.1 Status Report (2023-01-16), Stage 4 in effect now

2023-01-16 Thread Richard Biener via Gcc-patches


Status
==

The GCC development branch which will become GCC 13 is now in
regression and documentation fixing mode (Stage 4) until we
reach zero P1 regressions and branch for the release.


Quality Data


Priority  #   Change from last report
---   ---
P1   37   +   4
P2  497   +  24
P3   88   -  25
P4  256   +   3
P5   24   -   1
---   ---
Total P1-P3 622   +   3
Total   902   +   5


Previous Report
===

https://gcc.gnu.org/pipermail/gcc/2022-November/239994.html


[wwwdocs] Document new libstdc++ header dependency changes

2023-01-16 Thread Jonathan Wakely via Gcc-patches
Pushed to wwwdocs.

-- >8 --

---
 htdocs/gcc-13/porting_to.html | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/htdocs/gcc-13/porting_to.html b/htdocs/gcc-13/porting_to.html
index 7a67c0b0..9a9a3147 100644
--- a/htdocs/gcc-13/porting_to.html
+++ b/htdocs/gcc-13/porting_to.html
@@ -34,12 +34,26 @@ including the right headers will no longer compile.
 
 
 The following headers are used less widely in libstdc++ and may need to
-be included explicitly when compiled with GCC 13:
+be included explicitly when compiling with GCC 13:
 
 
+ string
+  (for std::string, std::to_string,
+  std::stoi etc.)
+
+ system_error
+  (for std::error_code, std::error_category,
+  std::system_error).
+
  cstdint
   (for std::int8_t, std::int32_t etc.)
 
+ cstdio
+  (for std::printf, std::fopen etc.)
+
+ cstdlib
+  (for std::strtol, std::malloc etc.)
+
 
 
 Implicit move rules change
-- 
2.39.0



Re: [PATCH] rs6000: Teach rs6000_opaque_type_invalid_use_p about gcall [PR108348]

2023-01-16 Thread Segher Boessenkool
Hi!

On Mon, Jan 16, 2023 at 05:20:56PM +0800, Kewen.Lin wrote:
> on 2023/1/16 16:49, Segher Boessenkool wrote:
> >> +/* { dg-require-effective-target powerpc_p9modulo_ok } */
> > 
> > Please use a saner selector?  If one doesn't exist yet, make a new one?
> > Something that just says "p9", not "modulo".
> 
> The has_arch_pwr9 looks not suitable here as it doesn't check
> the assembler behavior?

?  What assembler behaviour?

> Do you have some instruction in mind
> for being used as the tested instruction mnemonic like modsw?

It should not test *any* instruction?

Ah.  There is no *_ok wanted or needed at all.  You simply are required
to use a new enough binutils to fit your GCC.  During development you
probably want something, but that should not end up in the public trees.
You can always use -mcpu=power9.  If your toolchain is broken that will
throw some pretty obvious errors your way; this is fine.  A user can
always say -mcpu=power9.

The *_ok things should only be used for features that can be disabled
during configuration, or features that we *want* users to be able to
turn off (like FP, VMX, VSX, or HMT or QP float, that kind of thing).
That gives quite enough permutations to test already, we do not need to
create a whole bunch extra for no reason :-)

> Maybe later we can deprecate -mmodulo like we get rid of
> -mdirect-move, then we can rename p9modulo_ok to p9_ok here?  :)

We can (and should!) make that compiler flag a stub, yes.  But currently
it is used in places as a sneaky way to do -mcpu=power9.  So it is a bit
more work :-(


Segher


[committed] contrib: Yet another update-copyright.py tweak [PR108413]

2023-01-16 Thread Jakub Jelinek via Gcc-patches
Hi!

Ignore __builtins.di like object.d is already ignored.

Committed as obvious.
The modula 2 issue remains...

2023-01-16  Jakub Jelinek  

PR other/108413
* update-copyright.py (LibPhobosFilter): Add __builtins.di to
skipped files.

--- contrib/update-copyright.py
+++ contrib/update-copyright.py
@@ -638,8 +638,9 @@ class LibPhobosFilter (GenericFilter):
 GenericFilter.__init__ (self)
 
 self.skip_files |= set ([
-# Source module imported from upstream.
+# Source modules imported from upstream.
 'object.d',
+'__builtins.di'
 ])
 
 self.skip_dirs |= set ([


Jakub



[committed] libstdc++: Fix copyright notice to use usual form [PR108413]

2023-01-16 Thread Jonathan Wakely via Gcc-patches
Pushed to trunk. Backport to gcc-12 for follow (for the first two parts
of the change, tzdb.cc isn't on the branch).

-- >8 --

libstdc++-v3/ChangeLog:

PR libstdc++/108413
* include/c_compatibility/stdatomic.h: Change copyright line to
be consistent with other headers contributed under DCO terms.
* include/std/expected: Add full stop to copyright line.
* src/c++20/tzdb.cc: Likewise.
---
 libstdc++-v3/include/c_compatibility/stdatomic.h | 2 +-
 libstdc++-v3/include/std/expected| 2 +-
 libstdc++-v3/src/c++20/tzdb.cc   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/c_compatibility/stdatomic.h 
b/libstdc++-v3/include/c_compatibility/stdatomic.h
index a51a84c2054..b565a1c1ab1 100644
--- a/libstdc++-v3/include/c_compatibility/stdatomic.h
+++ b/libstdc++-v3/include/c_compatibility/stdatomic.h
@@ -1,6 +1,6 @@
 // C compatibility header  -*- C++ -*-
 
-// Copyright (C) 2022 The GCC developers
+// Copyright The GNU Toolchain Authors.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
diff --git a/libstdc++-v3/include/std/expected 
b/libstdc++-v3/include/std/expected
index 555779581f2..9a52e2574bf 100644
--- a/libstdc++-v3/include/std/expected
+++ b/libstdc++-v3/include/std/expected
@@ -1,6 +1,6 @@
 //  -*- C++ -*-
 
-// Copyright The GNU Toolchain Authors
+// Copyright The GNU Toolchain Authors.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc
index eaaea367f4f..2ce53d38768 100644
--- a/libstdc++-v3/src/c++20/tzdb.cc
+++ b/libstdc++-v3/src/c++20/tzdb.cc
@@ -1,6 +1,6 @@
 // chrono::tzdb -*- C++ -*-
 
-// Copyright The GNU Toolchain Authors
+// Copyright The GNU Toolchain Authors.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
-- 
2.39.0



[committed] doc: Fix grammar typo in description of malloc attribute

2023-01-16 Thread Jonathan Wakely via Gcc-patches
Committed as obvious.

-- >8 --

gcc/ChangeLog:

* doc/extend.texi (Common Function Attributes): Fix grammar.
---
 gcc/doc/extend.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 1103e9936f7..867ef07ea4b 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -3383,7 +3383,7 @@ Attribute @code{malloc} indicates that a function is 
@code{malloc}-like,
 i.e., that the pointer @var{P} returned by the function cannot alias any
 other pointer valid when the function returns, and moreover no
 pointers to valid objects occur in any storage addressed by @var{P}. In
-addition, the GCC predicts that a function with the attribute returns
+addition, GCC predicts that a function with the attribute returns
 non-null in most cases.
 
 Independently, the form of the attribute with one or two arguments
-- 
2.39.0



[committed] riscv: Fix up Copyright lines [PR108413]

2023-01-16 Thread Jakub Jelinek via Gcc-patches
Hi!

These 2 files had incorrectly formatted Copyright lines (no space between
Copyright and (C)) which makes update-copyright.py upset.

Tested on x86_64-linux with update-copyright --this-year, committed to trunk
as obvious.

2023-01-16  Jakub Jelinek  

PR other/108413
* config/riscv/riscv-vsetvl.h: Add space in between Copyright and (C).
* config/riscv/riscv-vsetvl.cc: Likewise.

--- gcc/config/riscv/riscv-vsetvl.h.jj  2023-01-02 09:44:08.289083750 +0100
+++ gcc/config/riscv/riscv-vsetvl.h 2023-01-16 11:05:55.036614938 +0100
@@ -1,5 +1,5 @@
 /* VSETVL pass header for RISC-V 'V' Extension for GNU compiler.
-   Copyright(C) 2022-2023 Free Software Foundation, Inc.
+   Copyright (C) 2022-2023 Free Software Foundation, Inc.
Contributed by Juzhe Zhong (juzhe.zh...@rivai.ai), RiVAI Technologies Ltd.
 
 This file is part of GCC.
--- gcc/config/riscv/riscv-vsetvl.cc.jj 2023-01-02 09:44:04.914132528 +0100
+++ gcc/config/riscv/riscv-vsetvl.cc2023-01-16 11:06:00.436535618 +0100
@@ -1,5 +1,5 @@
 /* VSETVL pass for RISC-V 'V' Extension for GNU compiler.
-   Copyright(C) 2022-2023 Free Software Foundation, Inc.
+   Copyright (C) 2022-2023 Free Software Foundation, Inc.
Contributed by Juzhe Zhong (juzhe.zh...@rivai.ai), RiVAI Technologies Ltd.
 
 This file is part of GCC.

Jakub



Re: [PATCH] contrib: Partial fix for failed update-copyright --this year [PR108413]

2023-01-16 Thread Richard Biener via Gcc-patches
On Mon, 16 Jan 2023, Jakub Jelinek wrote:

> Hi!
> 
> As mentioned on IRC or in PR108413, the last update-copyright.py --this year
> failed and that is why we are in a strange state where some copyrights have
> been updated and others have not.
> The full list of errors I got was I think:
> gcc/m2/mc-boot/GmcOptions.c: unrecognised copyright: comment (f, (const char 
> *) "Copyright (C) ''2021'' Free Software Foundation, Inc.", 53);
> gcc/m2/mc-boot/GmcOptions.c: unrecognised copyright: comment (f, (const char 
> *) "Copyright (C) ''2021'' Free Software Foundation, Inc.", 53);
> gcc/testsuite/gm2/switches/pedantic-params/pass/Strings.mod: unrecognised 
> copyright holder: Faculty of Information Technology,
> gcc/testsuite/gm2/switches/pedantic-params/pass/Strings2.mod: unrecognised 
> copyright holder: Faculty of Information Technology,
> libphobos/libdruntime/__builtins.di: unrecognised copyright: * Copyright: 
> Copyright Digital Mars 2022
> libstdc++-v3/src/c++17/fast_float/fast_float.h: unrecognised copyright 
> holder: The fast_float authors
> libstdc++-v3/include/c_compatibility/stdatomic.h: unrecognised copyright 
> holder: The GCC developers
> 
> The following patch deals with the gcc/testsuite/gm2 ones and
> with the fast_float.h one, ok for trunk?

OK

> Not really sure what we should do in the GmcOptions.c case
> (perhaps obfuscate it in the source somehow by splitting
> the string literals into different substrings
> Perhaps "Copy" "right (" "C) ''..." would do it?  Or do we want
> to bump there each year (manually or by the script)?
> E.g. in gcc.cc we have
>   printf ("Copyright %s 2023 Free Software Foundation, Inc.\n",
>   _("(C)"));
> which also prints (C) nicer in Unicode if possible and is updated
> by hand each year.
> 
> I have no idea about the libphobos case, we have tons of
> libphobos/src/std/format/spec.d:Copyright: Copyright The D Language 
> Foundation 2000-2013.
> libphobos/src/std/random.d:Copyright: Copyright Andrei Alexandrescu 2008 - 
> 2009, Joseph Rushton Wakeling 2012.
> etc. lines and those aren't reported as errors.
> 
> And the last one is that I think for The GCC developers we should treat it
> similarly like FSF and bump copyright on it.
> Would
> canon_gcc = 'The GCC developers'
> self.add_package_author ('The GCC developers', canon_gcc)
> self.add_package_author ('The GCC Developers', canon_gcc)
> or something similar do the trick?
> 
> 2023-01-16  Jakub Jelinek  
> 
>   PR other/108413
>   * update-copyright.py (TestsuiteFilter): Add .mod and .rs extensions.
>   (GCCCopyright): Add 'The fast_float authors' as external author.
> 
> --- contrib/update-copyright.py.jj2023-01-06 10:01:50.217579023 +0100
> +++ contrib/update-copyright.py   2023-01-16 10:39:08.786185284 +0100
> @@ -596,6 +596,8 @@ class TestsuiteFilter (GenericFilter):
>  '.go',
>  '.inc',
>  '.java',
> +'.mod',
> +'.rs'
>  ])
>  
>  def skip_file (self, dir, filename):
> @@ -733,6 +735,7 @@ class GCCCopyright (Copyright):
>  self.add_external_author ('Stephen L. Moshier')
>  self.add_external_author ('Sun Microsystems, Inc. All rights 
> reserved.')
>  self.add_external_author ('The D Language Foundation, All Rights 
> Reserved')
> +self.add_external_author ('The fast_float authors')
>  self.add_external_author ('The Go Authors.  All rights reserved.')
>  self.add_external_author ('The Go Authors. All rights reserved.')
>  self.add_external_author ('The Go Authors.')
> 
>   Jakub
> 
> 

-- 
Richard Biener 
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)


[PATCH] contrib: Partial fix for failed update-copyright --this year [PR108413]

2023-01-16 Thread Jakub Jelinek via Gcc-patches
Hi!

As mentioned on IRC or in PR108413, the last update-copyright.py --this year
failed and that is why we are in a strange state where some copyrights have
been updated and others have not.
The full list of errors I got was I think:
gcc/m2/mc-boot/GmcOptions.c: unrecognised copyright: comment (f, (const char *) 
"Copyright (C) ''2021'' Free Software Foundation, Inc.", 53);
gcc/m2/mc-boot/GmcOptions.c: unrecognised copyright: comment (f, (const char *) 
"Copyright (C) ''2021'' Free Software Foundation, Inc.", 53);
gcc/testsuite/gm2/switches/pedantic-params/pass/Strings.mod: unrecognised 
copyright holder: Faculty of Information Technology,
gcc/testsuite/gm2/switches/pedantic-params/pass/Strings2.mod: unrecognised 
copyright holder: Faculty of Information Technology,
libphobos/libdruntime/__builtins.di: unrecognised copyright: * Copyright: 
Copyright Digital Mars 2022
libstdc++-v3/src/c++17/fast_float/fast_float.h: unrecognised copyright holder: 
The fast_float authors
libstdc++-v3/include/c_compatibility/stdatomic.h: unrecognised copyright 
holder: The GCC developers

The following patch deals with the gcc/testsuite/gm2 ones and
with the fast_float.h one, ok for trunk?

Not really sure what we should do in the GmcOptions.c case
(perhaps obfuscate it in the source somehow by splitting
the string literals into different substrings
Perhaps "Copy" "right (" "C) ''..." would do it?  Or do we want
to bump there each year (manually or by the script)?
E.g. in gcc.cc we have
  printf ("Copyright %s 2023 Free Software Foundation, Inc.\n",
  _("(C)"));
which also prints (C) nicer in Unicode if possible and is updated
by hand each year.

I have no idea about the libphobos case, we have tons of
libphobos/src/std/format/spec.d:Copyright: Copyright The D Language Foundation 
2000-2013.
libphobos/src/std/random.d:Copyright: Copyright Andrei Alexandrescu 2008 - 
2009, Joseph Rushton Wakeling 2012.
etc. lines and those aren't reported as errors.

And the last one is that I think for The GCC developers we should treat it
similarly like FSF and bump copyright on it.
Would
canon_gcc = 'The GCC developers'
self.add_package_author ('The GCC developers', canon_gcc)
self.add_package_author ('The GCC Developers', canon_gcc)
or something similar do the trick?

2023-01-16  Jakub Jelinek  

PR other/108413
* update-copyright.py (TestsuiteFilter): Add .mod and .rs extensions.
(GCCCopyright): Add 'The fast_float authors' as external author.

--- contrib/update-copyright.py.jj  2023-01-06 10:01:50.217579023 +0100
+++ contrib/update-copyright.py 2023-01-16 10:39:08.786185284 +0100
@@ -596,6 +596,8 @@ class TestsuiteFilter (GenericFilter):
 '.go',
 '.inc',
 '.java',
+'.mod',
+'.rs'
 ])
 
 def skip_file (self, dir, filename):
@@ -733,6 +735,7 @@ class GCCCopyright (Copyright):
 self.add_external_author ('Stephen L. Moshier')
 self.add_external_author ('Sun Microsystems, Inc. All rights 
reserved.')
 self.add_external_author ('The D Language Foundation, All Rights 
Reserved')
+self.add_external_author ('The fast_float authors')
 self.add_external_author ('The Go Authors.  All rights reserved.')
 self.add_external_author ('The Go Authors. All rights reserved.')
 self.add_external_author ('The Go Authors.')

Jakub



[PATCH/RFC] rs6000: Remove optimize_for_speed check for implicit TARGET_SAVE_TOC_INDIRECT [PR108184]

2023-01-16 Thread Kewen.Lin via Gcc-patches
Hi,

Now we will check optimize_function_for_speed_p (cfun) for
TARGET_SAVE_TOC_INDIRECT if it's implicitly enabled.  But
the effect of -msave-toc-indirect is actually to save the
TOC in the prologue for indirect calls rather than inline,
it's also good for optimize_function_for_size?  So this
patch is to remove the check of optimize_function_for_speed
and make it work for both optimizing for size and speed.

Bootstrapped and regtested on powerpc64-linux-gnu P8,
powerpc64le-linux-gnu P{9,10} and powerpc-ibm-aix.

Any thoughts?

Thanks in advance!

Kewen
-
gcc/ChangeLog:

* config/rs6000/rs6000.cc (rs6000_call_aix): Remove the check of
optimize_function_for_speed_p for implicit SAVE_TOC_INDIRECT.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr108184-3.c: Adjust.
---
 gcc/config/rs6000/rs6000.cc   |  5 +
 gcc/testsuite/gcc.target/powerpc/pr108184-3.c | 17 -
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index f47d21980a9..870525347d5 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -25688,10 +25688,7 @@ rs6000_call_aix (rtx value, rtx func_desc, rtx tlsarg, 
rtx cookie)

  /* Can we optimize saving the TOC in the prologue or
 do we need to do it at every call?  */
- if (TARGET_SAVE_TOC_INDIRECT
- && !cfun->calls_alloca
- && (rs6000_isa_flags_explicit & OPTION_MASK_SAVE_TOC_INDIRECT
- || optimize_function_for_speed_p (cfun)))
+ if (TARGET_SAVE_TOC_INDIRECT && !cfun->calls_alloca)
cfun->machine->save_toc_in_prologue = true;
  else
{
diff --git a/gcc/testsuite/gcc.target/powerpc/pr108184-3.c 
b/gcc/testsuite/gcc.target/powerpc/pr108184-3.c
index ceaa96e4421..a1ce3a18855 100644
--- a/gcc/testsuite/gcc.target/powerpc/pr108184-3.c
+++ b/gcc/testsuite/gcc.target/powerpc/pr108184-3.c
@@ -2,15 +2,22 @@
 /* { dg-require-effective-target fpic } */
 /* { dg-options "-fpic -mno-pcrel -O2" } */

-/* Verify it doesn't imply -msave-toc-indirect, so
-   it doesn't take effect and we have two separated
-   toc savings for these two long calls.  */
+/* Verify -msave-toc-indirect is implicitly enabled
+   for both optimizing for speed and size, so one
+   toc saving for each function.  */

 void foo (void) __attribute__((__longcall__));
 int baz (void) __attribute__((__longcall__));

-__attribute__ ((cold)) int
-bar (void)
+__attribute__ ((cold, noipa)) int
+bar1 (void)
+{
+  foo ();
+  return baz () + 1;
+}
+
+__attribute__ ((noipa)) int
+bar2 (void)
 {
   foo ();
   return baz () + 1;
--
2.27.0


Re: [PATCH] rs6000: Teach rs6000_opaque_type_invalid_use_p about gcall [PR108348]

2023-01-16 Thread Kewen.Lin via Gcc-patches
Hi Segher,

Thanks for the review comments!

on 2023/1/16 16:49, Segher Boessenkool wrote:
> Hi!
> 
> On Mon, Jan 16, 2023 at 04:33:36PM +0800, Kewen.Lin wrote:
>> PR108348 shows one special case that MMA opaque types are
>> used in function arguments and treated as pass by reference,
>> it results in one copying from argument to a temp variable,
>> since this copying happens before rs6000_function_arg check,
>> it can cause ICE without MMA support then.  This patch is to
>> teach function rs6000_opaque_type_invalid_use_p to check if
>> any function argument in a gcall stmt has the invalid use of
>> MMA opaque types.
>>
>> btw, I checked the handling on return value, it doesn't have
>> this kind of issue as its checking and error emission is quite
>> early, so this doesn't handle function return value.
>>
>> Bootstrapped and regtested on powerpc64-linux-gnu P8 and
>> powerpc64le-linux-gnu P9 and P10.
>>
>> I'm going to push this soon if no objections.
> 
> Looks okay.  Some testcase stuff though:
> 
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.target/powerpc/pr108348-1.c
>> @@ -0,0 +1,23 @@
>> +/* { dg-require-effective-target powerpc_p9modulo_ok } */
> 
> Please use a saner selector?  If one doesn't exist yet, make a new one?
> Something that just says "p9", not "modulo".

The has_arch_pwr9 looks not suitable here as it doesn't check
the assembler behavior?  Do you have some instruction in mind
for being used as the tested instruction mnemonic like modsw?

Maybe later we can deprecate -mmodulo like we get rid of
-mdirect-move, then we can rename p9modulo_ok to p9_ok here?  :)

BR,
Kewen


[PATCH v2] rs6000: Don't use optimize_function_for_speed_p too early [PR108184]

2023-01-16 Thread Kewen.Lin via Gcc-patches
Hi,

As Honza pointed out in [1], the current uses of function
optimize_function_for_speed_p in rs6000_option_override_internal
are too early, since the query results from the functions
optimize_function_for_{speed,size}_p could be changed later due
to profile feedback and some function attributes handlings etc.

This patch is to move optimize_function_for_speed_p to all the
use places of the corresponding flags, which follows the existing
practices.  Maybe we can cache it somewhere at an appropriate
timing, but that's another thing.

Comparing with v1[2], this version added one test case for
SAVE_TOC_INDIRECT as Segher questioned and suggested, and it
also considered the possibility of explicit option (see test
cases pr108184-2.c and pr108184-4.c).  I believe that excepting
for the intentional change on optimize_function_for_{speed,
size}_p, there is no other function change.

[1] https://gcc.gnu.org/pipermail/gcc-patches/2022-November/607527.html
[2] https://gcc.gnu.org/pipermail/gcc-patches/2023-January/609379.html

Bootstrapped and regtested on powerpc64-linux-gnu P8,
powerpc64le-linux-gnu P{9,10} and powerpc-ibm-aix.

Is it ok for trunk?

BR,
Kewen
-
gcc/ChangeLog:

* config/rs6000/rs6000.cc (rs6000_option_override_internal): Remove
all optimize_function_for_speed_p uses.
(fusion_gpr_load_p): Call optimize_function_for_speed_p along
with TARGET_P8_FUSION_SIGN.
(expand_fusion_gpr_load): Likewise.
(rs6000_call_aix): Call optimize_function_for_speed_p along with
TARGET_SAVE_TOC_INDIRECT.
* config/rs6000/predicates.md (fusion_gpr_mem_load): Call
optimize_function_for_speed_p along with TARGET_P8_FUSION_SIGN.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr108184-1.c: New test.
* gcc.target/powerpc/pr108184-2.c: New test.
* gcc.target/powerpc/pr108184-3.c: New test.
* gcc.target/powerpc/pr108184-4.c: New test.
---
 gcc/config/rs6000/predicates.md   |  5 +++-
 gcc/config/rs6000/rs6000.cc   | 19 +-
 gcc/testsuite/gcc.target/powerpc/pr108184-1.c | 16 
 gcc/testsuite/gcc.target/powerpc/pr108184-2.c | 15 +++
 gcc/testsuite/gcc.target/powerpc/pr108184-3.c | 25 +++
 gcc/testsuite/gcc.target/powerpc/pr108184-4.c | 24 ++
 6 files changed, 97 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108184-1.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108184-2.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108184-3.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108184-4.c

diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index a1764018545..9f84468db84 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -1878,7 +1878,10 @@ (define_predicate "fusion_gpr_mem_load"

   /* Handle sign/zero extend.  */
   if (GET_CODE (op) == ZERO_EXTEND
-  || (TARGET_P8_FUSION_SIGN && GET_CODE (op) == SIGN_EXTEND))
+  || (TARGET_P8_FUSION_SIGN
+ && GET_CODE (op) == SIGN_EXTEND
+ && (rs6000_isa_flags_explicit & OPTION_MASK_P8_FUSION_SIGN
+ || optimize_function_for_speed_p (cfun
 {
   op = XEXP (op, 0);
   mode = GET_MODE (op);
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 6ac3adcec6b..f47d21980a9 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -3997,8 +3997,7 @@ rs6000_option_override_internal (bool global_init_p)
   /* If we can shrink-wrap the TOC register save separately, then use
  -msave-toc-indirect unless explicitly disabled.  */
   if ((rs6000_isa_flags_explicit & OPTION_MASK_SAVE_TOC_INDIRECT) == 0
-  && flag_shrink_wrap_separate
-  && optimize_function_for_speed_p (cfun))
+  && flag_shrink_wrap_separate)
 rs6000_isa_flags |= OPTION_MASK_SAVE_TOC_INDIRECT;

   /* Enable power8 fusion if we are tuning for power8, even if we aren't
@@ -4032,7 +4031,6 @@ rs6000_option_override_internal (bool global_init_p)
  zero extending load, and an explicit sign extension.  */
   if (TARGET_P8_FUSION
   && !(rs6000_isa_flags_explicit & OPTION_MASK_P8_FUSION_SIGN)
-  && optimize_function_for_speed_p (cfun)
   && optimize >= 3)
 rs6000_isa_flags |= OPTION_MASK_P8_FUSION_SIGN;

@@ -25690,7 +25688,10 @@ rs6000_call_aix (rtx value, rtx func_desc, rtx tlsarg, 
rtx cookie)

  /* Can we optimize saving the TOC in the prologue or
 do we need to do it at every call?  */
- if (TARGET_SAVE_TOC_INDIRECT && !cfun->calls_alloca)
+ if (TARGET_SAVE_TOC_INDIRECT
+ && !cfun->calls_alloca
+ && (rs6000_isa_flags_explicit & OPTION_MASK_SAVE_TOC_INDIRECT
+ || optimize_function_for_speed_p (cfun)))
cfun->machine->save_toc_in_prologue = true;
  else
{
@@ -27557,7 +27558,10 @@ fusion_gpr_load_p 

Re: [PATCH] rs6000: Teach rs6000_opaque_type_invalid_use_p about gcall [PR108348]

2023-01-16 Thread Segher Boessenkool
Hi!

On Mon, Jan 16, 2023 at 04:33:36PM +0800, Kewen.Lin wrote:
> PR108348 shows one special case that MMA opaque types are
> used in function arguments and treated as pass by reference,
> it results in one copying from argument to a temp variable,
> since this copying happens before rs6000_function_arg check,
> it can cause ICE without MMA support then.  This patch is to
> teach function rs6000_opaque_type_invalid_use_p to check if
> any function argument in a gcall stmt has the invalid use of
> MMA opaque types.
> 
> btw, I checked the handling on return value, it doesn't have
> this kind of issue as its checking and error emission is quite
> early, so this doesn't handle function return value.
> 
> Bootstrapped and regtested on powerpc64-linux-gnu P8 and
> powerpc64le-linux-gnu P9 and P10.
> 
> I'm going to push this soon if no objections.

Looks okay.  Some testcase stuff though:

> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/pr108348-1.c
> @@ -0,0 +1,23 @@
> +/* { dg-require-effective-target powerpc_p9modulo_ok } */

Please use a saner selector?  If one doesn't exist yet, make a new one?
Something that just says "p9", not "modulo".

Thanks,


Segher


[PATCH] rs6000: Teach rs6000_opaque_type_invalid_use_p about gcall [PR108348]

2023-01-16 Thread Kewen.Lin via Gcc-patches
Hi,
 
PR108348 shows one special case that MMA opaque types are
used in function arguments and treated as pass by reference,
it results in one copying from argument to a temp variable,
since this copying happens before rs6000_function_arg check,
it can cause ICE without MMA support then.  This patch is to
teach function rs6000_opaque_type_invalid_use_p to check if
any function argument in a gcall stmt has the invalid use of
MMA opaque types.

btw, I checked the handling on return value, it doesn't have
this kind of issue as its checking and error emission is quite
early, so this doesn't handle function return value.

Bootstrapped and regtested on powerpc64-linux-gnu P8 and
powerpc64le-linux-gnu P9 and P10.

I'm going to push this soon if no objections.

BR,
Kewen
-
PR target/108348

gcc/ChangeLog:

* config/rs6000/rs6000.cc (rs6000_opaque_type_invalid_use_p): Add the
support for invalid uses of MMA opaque type in function arguments.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr108348-1.c: New test.
* gcc.target/powerpc/pr108348-2.c: New test.
---
 gcc/config/rs6000/rs6000.cc   | 19 +++
 gcc/testsuite/gcc.target/powerpc/pr108348-1.c | 23 +++
 gcc/testsuite/gcc.target/powerpc/pr108348-2.c | 23 +++
 3 files changed, 61 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108348-1.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108348-2.c

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 86b879038f7..b69a676fb6c 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -28922,9 +28922,9 @@ constant_generates_xxspltidp (vec_const_128bit_type 
*vsx_const)
__vector_pair built-in types.  They are target specific and
only available when MMA is supported.  With MMA supported, it
simply returns true, otherwise it checks if the given gimple
-   STMT is an assignment or asm stmt and uses either of these two
-   opaque types unexpectedly, if yes, it would raise an error
-   message and returns true, otherwise it returns false.  */
+   STMT is an assignment, asm or call stmt and uses either of
+   these two opaque types unexpectedly, if yes, it would raise
+   an error message and returns true, otherwise it returns false.  */

 bool
 rs6000_opaque_type_invalid_use_p (gimple *stmt)
@@ -28953,7 +28953,7 @@ rs6000_opaque_type_invalid_use_p (gimple *stmt)
   if (stmt)
 {
   /* The usage of MMA opaque types is very limited for now,
-to check with gassign and gasm is enough so far.  */
+to check with gassign, gasm and gcall is enough so far.  */
   if (gassign *ga = dyn_cast (stmt))
{
  tree lhs = gimple_assign_lhs (ga);
@@ -28982,6 +28982,17 @@ rs6000_opaque_type_invalid_use_p (gimple *stmt)
return true;
}
}
+  else if (gcall *gc = dyn_cast (stmt))
+   {
+ unsigned nargs = gimple_call_num_args (gc);
+ for (unsigned i = 0; i < nargs; i++)
+   {
+ tree arg = gimple_call_arg (gc, i);
+ tree type = TREE_TYPE (arg);
+ if (check_and_error_invalid_use (type))
+   return true;
+   }
+   }
 }

   return false;
diff --git a/gcc/testsuite/gcc.target/powerpc/pr108348-1.c 
b/gcc/testsuite/gcc.target/powerpc/pr108348-1.c
new file mode 100644
index 000..25588a280a6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr108348-1.c
@@ -0,0 +1,23 @@
+/* { dg-require-effective-target powerpc_p9modulo_ok } */
+/* If the default cpu type is power10 or later, type __vector_quad is
+   supported.  To keep the test point available all the time, this case
+   specifies -mdejagnu-cpu=power9 here.  This needs -mabi=no-altivec
+   to do the copying for pass-by-reference function argument on 32 bit
+   environment.  */
+/* { dg-options "-mdejagnu-cpu=power9 -mabi=no-altivec" } */
+
+/* Verify there is no ICE on 32 bit and don't check the error messages
+   on unsupported type since they could be fragile and are not test
+   points of this case.  */
+
+/* { dg-excess-errors "pr108348-1" } */
+
+extern void bar (__vector_quad v);
+
+void
+foo (void)
+{
+  __vector_quad v;
+  bar (v);
+}
+
diff --git a/gcc/testsuite/gcc.target/powerpc/pr108348-2.c 
b/gcc/testsuite/gcc.target/powerpc/pr108348-2.c
new file mode 100644
index 000..2f6c736382c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr108348-2.c
@@ -0,0 +1,23 @@
+/* { dg-require-effective-target powerpc_p9modulo_ok } */
+/* If the default cpu type is power10 or later, type __vector_pair is
+   supported.  To keep the test point available all the time, this case
+   specifies -mdejagnu-cpu=power9 here.  This needs -mabi=no-altivec
+   to do the copying for pass-by-reference function argument on 32 bit
+   environment.  */
+/* { dg-options "-mdejagnu-cpu=power9 -mabi=no-altivec" } */
+
+/* Verify there is 

Re: [PATCH] PR tree-optimization/108359 - Utilize op1 == op2 when invoking range-ops folding.

2023-01-16 Thread Jakub Jelinek via Gcc-patches
On Mon, Jan 16, 2023 at 08:19:25AM +0100, Richard Biener wrote:
> +  // If op1 and op2 are equivalences, then we don't need a complete cross
> +  // product, just pairs of matching elements.
> +  if (relation_equiv_p (rel) && lh == rh && num_lh <= 16)
> +{
> +  int_range_max tmp;
> +  r.set_undefined ();
> +  for (unsigned x = 0; x < num_lh; ++x)
> +   {
> + wide_int lh_lb = lh.lower_bound (x);
> + wide_int lh_ub = lh.upper_bound (x);
> + wi_fold_in_parts_equiv (tmp, type, lh_lb, lh_ub);
> 
> and that does
> 
> +  widest_int lh_range = wi::sub (widest_int::from (lh_ub, TYPE_SIGN (type)),
> +widest_int::from (lh_lb, TYPE_SIGN (type)));
> +  // if there are 1 to 8 values in the LH range, split them up.
> +  r.set_undefined ();
> +  if (lh_range >= 0 && lh_range <= 7)
> +{
> +  for (unsigned x = 0; x <= lh_range; x++)
> 
> which in total limits the number of sub-ranges in the output but in an
> odd way.  It's also all-or-nothing.  IIRC there's a hard limit on the
> number of sub-ranges in the output anyway via int_range, so
> why not use that and always do the first loop over the sub-ranges
> of the inputs and the second loop over the range members but
> stop when we reach N-1 and then use wi_fold on the remainds?
> 
> Your above code suggests we go up to 112 sub-ranges and once
> we'd reach 113 we'd fold down to a single.
> 
> Maybe my "heuristic" wouldn't be much better, but then somehow
> breaking the heuristic down to a single magic number would be
> better, esp. since .union_ will undo some of the breakup when
> reaching N?

The <= X in the first case is what I've suggested, the previous
behavior didn't suffer from this all or nothing case, but I was worried
because the behavior is that we create many subranges and then in the
end just merge the last ones into a single subrange such that it fits
into the limit.  So we could create 255 * 8 subranges and then merge the
last 255 * 7 + 1 into one.
We could call that wi_fold_in_parts_equiv only if r.num_parts () <
m_max_ranges and wi_fold otherwise...

Jakub



Re: [PATCH] xtensa: Eliminate the use of callee-saved register that saves and restores only once

2023-01-16 Thread Max Filippov via Gcc-patches
Hi Suwa-san,

On Sun, Jan 15, 2023 at 6:53 PM Takayuki 'January June' Suwa
 wrote:
>
> In the case of the CALL0 ABI, values that must be retained before and
> after function calls are placed in the callee-saved registers (A12
> through A15) and referenced later.  However, it is often the case that
> the save and the reference are each only once and a simple register-
> register move.
>
> e.g. in the following example, if there are no other occurrences of
> register A14:
>
> ;; before
> ; prologue {
>   ...
> s32i.n  a14, sp, 16
>   ...
> ; } prologue
>   ...
> mov.n   a14, a6
>   ...
> call0   foo
>   ...
> mov.n   a8, a14
>   ...
> ; epilogue {
>   ...
> l32i.n  a14, sp, 16
>   ...
> ; } epilogue
>
> It can be possible like this:
>
> ;; after
> ; prologue {
>   ...
> (deleted)
>   ...
> ; } prologue
>   ...
> s32i.n  a6, sp, 16
>   ...
> call0   foo
>   ...
> l32i.n  a8, sp, 16
>   ...
> ; epilogue {
>   ...
> (deleted)
>   ...
> ; } epilogue
>
> This patch introduces a new peephole2 pattern that implements the above.
>
> gcc/ChangeLog:
>
> * config/xtensa/xtensa.md: New peephole2 pattern that eliminates
> the use of callee-saved register that saves and restores only once
> for other register, by using its stack slot directly.
> ---
>  gcc/config/xtensa/xtensa.md | 58 +
>  1 file changed, 58 insertions(+)

This change introduces a bunch of test failures in cases where alloca
or similar mechanisms are used in a function and a15 is used as a
stack frame pointer. E.g., gcc.c-torture/execute/pr82210.c has the
following diff:

@@ -20,9 +20,8 @@
   srlia10, a10, 4
   sllia10, a10, 4
   s32i.n  a12, sp, 8
-   s32i.n  a15, sp, 0
   s32i.n  a0, sp, 12
-   mov.n   a15, sp
+   s32i.n  sp, sp, 0
   sub sp, sp, a10
   mov.n   a6, sp
   mov.n   a12, a6
@@ -59,11 +58,10 @@
   addi.n  a2, a2, 4
   bne a12, a13, .L6
.L1:
-   mov.n   sp, a15
+   l32i.n  sp, sp, 0
   l32i.n  a0, sp, 12
   l32i.n  a12, sp, 8
   l32i.n  a13, sp, 4
-   l32i.n  a15, sp, 0
   addisp, sp, 16
   ret.n
   .size   foo, .-foo

-- 
Thanks.
-- Max


Re: [PATCH] rs6000: Teach rs6000_opaque_type_invalid_use_p about inline asm [PR108272]

2023-01-16 Thread Kewen.Lin via Gcc-patches
on 2023/1/6 17:26, Kewen.Lin via Gcc-patches wrote:
> Hi,
> 
> As PR108272 shows, there are some invalid uses of MMA opaque
> types in inline asm statements.  This patch is to teach the
> function rs6000_opaque_type_invalid_use_p for inline asm,
> check and error any invalid use of MMA opaque types in input
> and output operands.
> 
> Bootstrapped and regtested on powerpc64-linux-gnu P8 and
> powerpc64le-linux-gnu P9 and P10.
> 
> I'm going to push this next week if no objections.

Committed the attached one in r13-5184-g074b0c03eabeb8.

BR,
Kewen

Subject: [PATCH] rs6000: Teach rs6000_opaque_type_invalid_use_p about inline 
asm [PR108272]

As PR108272 shows, there are some invalid uses of MMA opaque
types in inline asm statements.  This patch is to teach the
function rs6000_opaque_type_invalid_use_p for inline asm,
check and error any invalid use of MMA opaque types in input
and output operands.

PR target/108272

gcc/ChangeLog:

* config/rs6000/rs6000.cc (rs6000_opaque_type_invalid_use_p): Add the
support for invalid uses in inline asm, factor out the checking and
erroring to lambda function check_and_error_invalid_use.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr108272-1.c: New test.
* gcc.target/powerpc/pr108272-2.c: New test.
* gcc.target/powerpc/pr108272-3.c: New test.
* gcc.target/powerpc/pr108272-4.c: New test.
---
 gcc/config/rs6000/rs6000.cc   | 51 +++
 gcc/testsuite/gcc.target/powerpc/pr108272-1.c | 17 +++
 gcc/testsuite/gcc.target/powerpc/pr108272-2.c | 17 +++
 gcc/testsuite/gcc.target/powerpc/pr108272-3.c | 17 +++
 gcc/testsuite/gcc.target/powerpc/pr108272-4.c | 18 +++
 5 files changed, 110 insertions(+), 10 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108272-1.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108272-2.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108272-3.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108272-4.c

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 3baa2c3b7b0..4287a6b1a61 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -28928,9 +28928,9 @@ constant_generates_xxspltidp (vec_const_128bit_type 
*vsx_const)
__vector_pair built-in types.  They are target specific and
only available when MMA is supported.  With MMA supported, it
simply returns true, otherwise it checks if the given gimple
-   STMT is an assignment stmt and uses either of these two opaque
-   types unexpectedly, if yes, it would raise an error message
-   and returns true, otherwise it returns false.  */
+   STMT is an assignment or asm stmt and uses either of these two
+   opaque types unexpectedly, if yes, it would raise an error
+   message and returns true, otherwise it returns false.  */
 
 bool
 rs6000_opaque_type_invalid_use_p (gimple *stmt)
@@ -28938,23 +28938,54 @@ rs6000_opaque_type_invalid_use_p (gimple *stmt)
   if (TARGET_MMA)
 return false;
 
+  /* If the given TYPE is one MMA opaque type, emit the corresponding
+ error messages and return true, otherwise return false.  */
+  auto check_and_error_invalid_use = [](tree type)
+  {
+tree mv = TYPE_MAIN_VARIANT (type);
+if (mv == vector_quad_type_node)
+  {
+   error ("type %<__vector_quad%> requires the %qs option", "-mmma");
+   return true;
+  }
+else if (mv == vector_pair_type_node)
+  {
+   error ("type %<__vector_pair%> requires the %qs option", "-mmma");
+   return true;
+  }
+return false;
+  };
+
   if (stmt)
 {
   /* The usage of MMA opaque types is very limited for now,
-to check with gassign is enough so far.  */
+to check with gassign and gasm is enough so far.  */
   if (gassign *ga = dyn_cast (stmt))
{
  tree lhs = gimple_assign_lhs (ga);
  tree type = TREE_TYPE (lhs);
- if (type == vector_quad_type_node)
+ if (check_and_error_invalid_use (type))
+   return true;
+   }
+  else if (gasm *gs = dyn_cast (stmt))
+   {
+ unsigned ninputs = gimple_asm_ninputs (gs);
+ for (unsigned i = 0; i < ninputs; i++)
{
- error ("type %<__vector_quad%> requires the %qs option", "-mmma");
- return true;
+ tree op = gimple_asm_input_op (gs, i);
+ tree val = TREE_VALUE (op);
+ tree type = TREE_TYPE (val);
+ if (check_and_error_invalid_use (type))
+   return true;
}
- else if (type == vector_pair_type_node)
+ unsigned noutputs = gimple_asm_noutputs (gs);
+ for (unsigned i = 0; i < noutputs; i++)
{
- error ("type %<__vector_pair%> requires the %qs option", "-mmma");
- return true;
+ tree op = gimple_asm_output_op (gs, i);
+ tree val = TREE_VALUE (op);
+ tree 

Re: [wwwdocs] gcc-13/changes.html + projects/gomp/: OpenMP update

2023-01-16 Thread Tobias Burnus

Hi Gerald,

On 14.01.23 22:47, Gerald Pfeifer wrote:


I made a couple of incremental edits. See below for what I just pushed
(and please speak up if you see any issues).

commit 2f870cba58c81449beb618a9030824360a25


...


--- a/htdocs/gcc-13/changes.html
+++ b/htdocs/gcc-13/changes.html
@@ -54,10 +54,10 @@ a work-in-progress.


...


+  requires directive are now accepted. However, the
requires_offload, unified_address
-  and unified_shared_memory clauses cause that the
-  only available device is the initial device (the host). Fortran now
+  and unified_shared_memory clauses imply the initial
+  device (= the host) as the only available device. Fortran now


I really stumble over the "as" – that sounds wrong and I fail to parse this 
part.
I think it should be "is".

On the technical side, in principle, available devices are the host (aka "initial 
device") –
and all installed** (nonhost) devices – in our case nvptx and (amd)gcn GPUs.

However, when using 'requires', all installed devices which do not fulfill
the requirement(s) are removed from the list of available devices. In case of
'dynamic_allocators', all devices support it, in case of 'reverse_offload' all 
installed
amdgcn devices are filtered out and, for unified-shared memory,* neither nvptx 
nor
amdgcn support it – and are removed from the list – such that at the end, only
the host remains. (Hence, device code ('target regions') will run on the host
→ host fallback.)

BTW: Before the release, further updates to changes.html are required. – For 
instance,
as alluded in the previous paragraph, 'reverse offload' is (now) supported for 
nvptx.
(But not yet with amdgcn.)

Tobias

(*) There is support for unified-shared memory for both nvptx and gcn,
but the existing patches either have to be reviewed or to be revised.

(**) I coined the term 'installed device'. OpenMP since TR11 contains some
definitions for 'available devices' – which consists of the union of supported
and accessible devices (possibly after sorting and further filtering). Namely:

accessible devices – The host device and all non-host devices accessible for 
execution.

supported devices – The host device and all non-host devices supported by the
implementation for execution of target code for which the device-related 
requirements
of the requires directive are fulfilled.

The available-devices-var is in turn by default "*" – where "* expands to all 
accessible
and supported devices". (The device list can be further filtered and sorted via
the environment variable OMP_AVAILABLE_DEVICES.)

-
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