Re: [PATCH] [libstdc++] add _GLIBCXX_CLANG to workaround predefined __clang__

2024-06-01 Thread Olivier Hainque



> On 31 May 2024, at 17:52, Alexandre Oliva  wrote:

>> Does the vxworks toolchain need to support the PSTL headers?
> 
> Maybe we can do without them.  I really don't know.  Olivier?

I have no indication that we can not-support these.

We are seeing many cases of C++/Ada combined codebases in a variety
of VxWorks contexts so actual uses seem likely.

>> If not, we could just ignore this file, so the local changes don't
>> need to be re-applied when we import a new version of the header from
>> upstream.
> 
> That sounds desirable indeed.  This change is supposed to spare us
> (AdaCore) from precisely this sort of trouble, so it wouldn't be fair if
> it made this very kind of trouble for our upstream.

Of course, 100% agreed!

Thanks a lot for help in looking into this!

Olivier




[PATCH v2] RISC-V: Add Zfbfmin extension

2024-06-01 Thread Xiao Zeng
1 In the previous patch, the libcall for BF16 was implemented:


2 Riscv provides Zfbfmin extension, which completes the "Scalar BF16 Converts":


3 Implemented replacing libcall with Zfbfmin extension instruction.

4 Reused previous testcases in:

gcc/ChangeLog:

* config/riscv/iterators.md: Add mode_iterator between
floating-point modes and BFmode.
* config/riscv/riscv.cc (riscv_output_move): Handle BFmode move
for zfbfmin.
* config/riscv/riscv.md (truncbf2): New pattern for BFmode.
(extendbfsf2): Dotto.
(*movhf_hardfloat): Add BFmode.
(*mov_hardfloat): Dotto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zfbfmin-bf16_arithmetic.c: New test.
* gcc.target/riscv/zfbfmin-bf16_comparison.c: New test.
* gcc.target/riscv/zfbfmin-bf16_float_libcall_convert.c: New test.
* gcc.target/riscv/zfbfmin-bf16_integer_libcall_convert.c: New test.
---
 gcc/config/riscv/iterators.md |  6 +-
 gcc/config/riscv/riscv.cc |  4 +-
 gcc/config/riscv/riscv.md | 49 --
 .../riscv/zfbfmin-bf16_arithmetic.c   | 35 ++
 .../riscv/zfbfmin-bf16_comparison.c   | 33 ++
 .../zfbfmin-bf16_float_libcall_convert.c  | 45 +
 .../zfbfmin-bf16_integer_libcall_convert.c| 66 +++
 7 files changed, 228 insertions(+), 10 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/zfbfmin-bf16_arithmetic.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/zfbfmin-bf16_comparison.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/zfbfmin-bf16_float_libcall_convert.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/zfbfmin-bf16_integer_libcall_convert.c

diff --git a/gcc/config/riscv/iterators.md b/gcc/config/riscv/iterators.md
index 3c139bc2e30..1e37e843023 100644
--- a/gcc/config/riscv/iterators.md
+++ b/gcc/config/riscv/iterators.md
@@ -78,9 +78,13 @@
 ;; Iterator for floating-point modes that can be loaded into X registers.
 (define_mode_iterator SOFTF [SF (DF "TARGET_64BIT") (HF "TARGET_ZFHMIN")])
 
-;; Iterator for floating-point modes of BF16
+;; Iterator for floating-point modes of BF16.
 (define_mode_iterator HFBF [HF BF])
 
+;; Conversion between floating-point modes and BF16.
+;; SF to BF16 have hardware instructions.
+(define_mode_iterator FBF [HF DF TF])
+
 ;; ---
 ;; Mode attributes
 ;; ---
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 10af38a5a81..c5c4c777349 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -4310,7 +4310,7 @@ riscv_output_move (rtx dest, rtx src)
switch (width)
  {
  case 2:
-   if (TARGET_ZFHMIN)
+   if (TARGET_ZFHMIN || TARGET_ZFBFMIN)
  return "fmv.x.h\t%0,%1";
/* Using fmv.x.s + sign-extend to emulate fmv.x.h.  */
return "fmv.x.s\t%0,%1;slli\t%0,%0,16;srai\t%0,%0,16";
@@ -4366,7 +4366,7 @@ riscv_output_move (rtx dest, rtx src)
switch (width)
  {
  case 2:
-   if (TARGET_ZFHMIN)
+   if (TARGET_ZFHMIN || TARGET_ZFBFMIN)
  return "fmv.h.x\t%0,%z1";
/* High 16 bits should be all-1, otherwise HW will treated
   as a n-bit canonical NaN, but isn't matter for softfloat.  */
diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index 25d341ec987..e57bfcf616a 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -1763,6 +1763,31 @@
   [(set_attr "type" "fcvt")
(set_attr "mode" "HF")])
 
+(define_insn "truncsfbf2"
+  [(set (match_operand:BF0 "register_operand" "=f")
+   (float_truncate:BF
+  (match_operand:SF 1 "register_operand" " f")))]
+  "TARGET_ZFBFMIN"
+  "fcvt.bf16.s\t%0,%1"
+  [(set_attr "type" "fcvt")
+   (set_attr "mode" "BF")])
+
+;; The conversion of HF/DF/TF to BF needs to be done with SF if there is a
+;; chance to generate at least one instruction, otherwise just using
+;; libfunc __trunc[h|d|t]fbf2.
+(define_expand "truncbf2"
+  [(set (match_operand:BF  0 "register_operand" "=f")
+   (float_truncate:BF
+  (match_operand:FBF   1 "register_operand" " f")))]
+  "TARGET_ZFBFMIN"
+  {
+convert_move (operands[0],
+ convert_modes (SFmode, mode, operands[1], 0), 0);
+DONE;
+  }
+  [(set_attr "type" "fcvt")
+   (set_attr "mode" "BF")])
+
 ;;
 ;;  
 ;;
@@ -1907,6 +1932,15 @@
   [(set_attr "type" "fcvt")
(set_attr "mode" "SF")])
 
+(define_insn "extendbfsf2"
+  

Re: Re: [PING] [PATCH] RISC-V: Add Zfbfmin extension

2024-06-01 Thread Xiao Zeng
2024-06-01 12:34  Jeff Law  wrote:
>
>
>
>On 5/30/24 5:38 AM, Xiao Zeng wrote:
>> 1 In the previous patch, the libcall for BF16 was implemented:
>> 
>>
>> 2 Riscv provides Zfbfmin extension, which completes the "Scalar BF16 
>> Converts":
>> 
>>
>> 3 Implemented replacing libcall with Zfbfmin extension instruction.
>>
>> 4 Reused previous testcases in:
>> 
>>
>> gcc/ChangeLog:
>>
>> * config/riscv/riscv.cc (riscv_output_move): Handle BFmode move
>> for zfbfmin.
>> * config/riscv/riscv.md (truncsfbf2): New pattern for BFmode.
>> (trunchfbf2): Dotto.
>> (truncdfbf2): Dotto.
>> (trunctfbf2): Dotto.
>> (extendbfsf2): Dotto.
>> (*movhf_hardfloat): Add BFmode.
>> (*mov_hardfloat): Dotto.
>>
>> gcc/testsuite/ChangeLog:
>>
>> * gcc.target/riscv/zfbfmin-bf16_arithmetic.c: New test.
>> * gcc.target/riscv/zfbfmin-bf16_comparison.c: New test.
>> * gcc.target/riscv/zfbfmin-bf16_float_libcall_convert.c: New test.
>> * gcc.target/riscv/zfbfmin-bf16_integer_libcall_convert.c: New test.
>> ---
>
>>
>
>
>
>> +
>> +;; The conversion of HF/DF/TF to BF needs to be done with SF if there is a
>> +;; chance to generate at least one instruction, otherwise just using
>> +;; libfunc __trunc[h|d|t]fbf2.
>> +(define_expand "trunchfbf2"
>> +  [(set (match_operand:BF    0 "register_operand" "=f")
>> +(float_truncate:BF
>> +   (match_operand:HF 1 "register_operand" " f")))]
>> +  "TARGET_ZFBFMIN"
>> +  {
>> +    convert_move (operands[0],
>> +  convert_modes (SFmode, HFmode, operands[1], 0), 0);
>> +    DONE;
>> +  }
>> +  [(set_attr "type" "fcvt")
>> +   (set_attr "mode" "BF")])
>I would suggest using a mode iterator to avoid explicit pattern duplication. 

>
>Essentially a mode iterator allows you to specify that the pattern
>should be repeated over a series of modes. 
Yes, this will make the code look more concise and avoid redundancy.

>
>It looks like you've deine a conversion from HF, DF, TF.  
Yes.

>So you define an iterator that includes just those modes. 
Yes.

>You would use the mode iterator rather than BF, DF or TF in your pattern.
Fixed.

>
>That just fixes the mode in the pattern. 
>You also need to have the name automagically adjust as well.  Use  in 
>the name.  so the name
>would be somethig like truncbf2. 
Of course, this is necessary.

>
>When you want to reference the mode in code you can do something like
>E_mode 
Yes.

>
>And that will map down to HFmode, BFmode, TFmode appropriately.
>
>I suspect you can do something similar for the extension patterns.
>
>In fact, it looks like you did this for the movehardfloat pattern.
>
>Jeff 
Thank you for Jeff's suggestion. v2 has already been uploaded.


Thanks
Xiao Zeng



Re: [PATCH] [libstdc++] add _GLIBCXX_CLANG to workaround predefined __clang__

2024-06-01 Thread Jonathan Wakely
On Sat, 1 Jun 2024 at 08:35, Olivier Hainque  wrote:
>
>
>
> > On 31 May 2024, at 17:52, Alexandre Oliva  wrote:
>
> >> Does the vxworks toolchain need to support the PSTL headers?
> >
> > Maybe we can do without them.  I really don't know.  Olivier?
>
> I have no indication that we can not-support these.
>
> We are seeing many cases of C++/Ada combined codebases in a variety
> of VxWorks contexts so actual uses seem likely.

If Intel TBB isn't supported on vxworks then the PSTL algos are not
very useful. You can use them, but you won't get any benefits. I'm
unsure of the status of the openmp and simd backends in PSTL, I think
only the TBB backend really works.

>
> >> If not, we could just ignore this file, so the local changes don't
> >> need to be re-applied when we import a new version of the header from
> >> upstream.
> >
> > That sounds desirable indeed.  This change is supposed to spare us
> > (AdaCore) from precisely this sort of trouble, so it wouldn't be fair if
> > it made this very kind of trouble for our upstream.
>
> Of course, 100% agreed!
>
> Thanks a lot for help in looking into this!
>
> Olivier
>
>


Re: [PATCH] [libstdc++] add _GLIBCXX_CLANG to workaround predefined __clang__

2024-06-01 Thread Jonathan Wakely
On Fri, 31 May 2024 at 16:52, Alexandre Oliva  wrote:
>
> On May 31, 2024, Jonathan Wakely  wrote:
>
> > On 31/05/24 11:07 -0300, Alexandre Oliva wrote:
> >> --- a/libstdc++-v3/include/pstl/pstl_config.h
> [...]
> >> -#if defined(__clang__)
> >> +#if defined(__GLIBCXX__) ? defined(_GLIBCXX_CLANG) : defined(__clang__)
>
> > This file is also imported from upstream, like Ryu and fast_float.
>
> Oh, yeah, I should have mentioned this one in the proposed commit
> message.
>
> The problem here was that it wasn't clear c++config would always be
> included, so I figured I'd better be conservative.
>
> > I don't think having a "spurious" definition of _PSTL_CLANG_VERSION
> > here actually matters.
>
> Yeah, no, it's the other macros guarded by __clang__ that I'm concerned
> about, and since the version macro could replace it, I went for it.
>
> > So either don't change this line at all, or just do a simple
> > s/__clang__/_GLIBCXX_CLANG/
>
> If c++config can be counted on, I'd be happy to do that, but I couldn't
> tell that it could.

You can't reach pstl_config.h without going through one of the
standard headers, which all include c++config.h

>
> > Does the vxworks toolchain need to support the PSTL headers?
>
> Maybe we can do without them.  I really don't know.  Olivier?
>
> > If not, we could just ignore this file, so the local changes don't
> > need to be re-applied when we import a new version of the header from
> > upstream.
>
> That sounds desirable indeed.  This change is supposed to spare us
> (AdaCore) from precisely this sort of trouble, so it wouldn't be fair if
> it made this very kind of trouble for our upstream.
>
> >> --- a/libstdc++-v3/include/std/ranges
>
> >> -#ifdef __clang__ // LLVM-61763 workaround
> >> +#ifdef _GLIBCXX_CLANG // LLVM-61763 workaround
>
> > This one doesn't matter, since making these members public for a "fake
> > clang" doesn't really hurt anything. For consistency maybe it makes
> > sense to use _GLIBCXX_CLANG anyway.
>
> Yeah, uniformity would be good to simplify checking for no new
> appearances of __clang__, and to set the example to avoid accidental
> additions thereof.
>
> >> --- a/libstdc++-v3/include/std/variant
>
> >> -#if defined(__clang__) && __clang_major__ <= 7
> >> +#if defined(_GLIBCXX_CLANG) && __clang_major__ <= 7
>
> > I think we could drop this kluge entirely, clang 7 is old now, we
> > generally only support the most recent 3 or 4 clang versions.
>
> Fine with me, but I'd do that in a separate later patch, so that this
> goes in, and if it gets backported, it will cover this change, rather
> than miss it.  Though, as you say, it doesn't matter much either way.
>
> --
> Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
>Free Software Activist   GNU Toolchain Engineer
> More tolerance and less prejudice are key for inclusion and diversity
> Excluding neuro-others for not behaving ""normal"" is *not* inclusive


Re: [PATCH v2] [libstdc++] add _GLIBCXX_CLANG to workaround predefined __clang__

2024-06-01 Thread Jonathan Wakely
On Fri, 31 May 2024 at 18:43, Alexandre Oliva  wrote:
>
> On May 31, 2024, Alexandre Oliva  wrote:
>
> >> So either don't change this line at all, or just do a simple
> >> s/__clang__/_GLIBCXX_CLANG/
>
> > If c++config can be counted on, I'd be happy to do that, but I couldn't
> > tell that it could.
>
> Here's what I've retested on x86_64-linux-gnu and, slightly adjusted for
> gcc-13, on arm-vx7r2.  Ok to install?

OK

If there's any chance of getting the vxworks system headers fixed to
work with GCC properly, that would be nice.

>
>
> [libstdc++] add _GLIBCXX_CLANG to workaround predefined __clang__
>
> A proprietary embedded operating system that uses clang as its primary
> compiler ships headers that require __clang__ to be defined.  Defining
> that macro causes libstdc++ to adopt workarounds that work for clang
> but that break for GCC.
>
> So, introduce a _GLIBCXX_CLANG macro, and a convention to test for it
> rather than for __clang__, so that a GCC variant that adds -D__clang__
> to satisfy system headers can also -D_GLIBCXX_CLANG=0 to avoid
> workarounds that are not meant for GCC.
>
> I've left fast_float and ryu files alone, their tests for __clang__
> don't seem to be harmful for GCC, they don't include bits/c++config,
> and patching such third-party files would just make trouble for
> updating them without visible benefit.  pstl_config.h, though also
> imported, required adjustment.
>
>
> for  libstdc++-v3/ChangeLog
>
> * include/bits/c++config (_GLIBCXX_CLANG): Define or undefine.
> * include/bits/locale_facets_nonio.tcc: Test for it.
> * include/bits/stl_bvector.h: Likewise.
> * include/c_compatibility/stdatomic.h: Likewise.
> * include/experimental/bits/simd.h: Likewise.
> * include/experimental/bits/simd_builtin.h: Likewise.
> * include/experimental/bits/simd_detail.h: Likewise.
> * include/experimental/bits/simd_x86.h: Likewise.
> * include/experimental/simd: Likewise.
> * include/std/complex: Likewise.
> * include/std/ranges: Likewise.
> * include/std/variant: Likewise.
> * include/pstl/pstl_config.h: Likewise.
> ---
>  libstdc++-v3/include/bits/c++config|   13 -
>  libstdc++-v3/include/bits/locale_facets_nonio.tcc  |2 +-
>  libstdc++-v3/include/bits/stl_bvector.h|2 +-
>  libstdc++-v3/include/c_compatibility/stdatomic.h   |2 +-
>  libstdc++-v3/include/experimental/bits/simd.h  |   14 +++---
>  .../include/experimental/bits/simd_builtin.h   |4 ++--
>  .../include/experimental/bits/simd_detail.h|8 
>  libstdc++-v3/include/experimental/bits/simd_x86.h  |   12 ++--
>  libstdc++-v3/include/experimental/simd |2 +-
>  libstdc++-v3/include/pstl/pstl_config.h|4 ++--
>  libstdc++-v3/include/std/complex   |4 ++--
>  libstdc++-v3/include/std/ranges|8 
>  libstdc++-v3/include/std/variant   |2 +-
>  13 files changed, 44 insertions(+), 33 deletions(-)
>
> diff --git a/libstdc++-v3/include/bits/c++config 
> b/libstdc++-v3/include/bits/c++config
> index b57e3f338e92a..6dca2d9467aa5 100644
> --- a/libstdc++-v3/include/bits/c++config
> +++ b/libstdc++-v3/include/bits/c++config
> @@ -481,9 +481,20 @@ _GLIBCXX_END_NAMESPACE_VERSION
>  // Define if compatibility should be provided for -mlong-double-64.
>  #undef _GLIBCXX_LONG_DOUBLE_COMPAT
>
> +// Use an alternate macro to test for clang, so as to provide an easy
> +// workaround for systems (such as vxworks) whose headers require
> +// __clang__ to be defined, even when compiling with GCC.
> +#if !defined _GLIBCXX_CLANG && defined __clang__
> +# define _GLIBCXX_CLANG __clang__
> +// Turn -D_GLIBCXX_CLANG=0 into -U_GLIBCXX_CLANG, so that
> +// _GLIBCXX_CLANG can be tested as defined, just like __clang__.
> +#elif !_GLIBCXX_CLANG
> +# undef _GLIBCXX_CLANG
> +#endif
> +
>  // Define if compatibility should be provided for alternative 128-bit long
>  // double formats. Not possible for Clang until __ibm128 is supported.
> -#ifndef __clang__
> +#ifndef _GLIBCXX_CLANG
>  #undef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
>  #endif
>
> diff --git a/libstdc++-v3/include/bits/locale_facets_nonio.tcc 
> b/libstdc++-v3/include/bits/locale_facets_nonio.tcc
> index 8f67be5a6147b..72136f42f0866 100644
> --- a/libstdc++-v3/include/bits/locale_facets_nonio.tcc
> +++ b/libstdc++-v3/include/bits/locale_facets_nonio.tcc
> @@ -1465,7 +1465,7 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
>ctype<_CharT> const& __ctype = use_facet >(__loc);
>__err = ios_base::goodbit;
>bool __use_state = false;
> -#if __GNUC__ >= 5 && !defined(__clang__)
> +#if __GNUC__ >= 5 && !defined(_GLIBCXX_CLANG)
>  #pragma GCC diagnostic push
>  #pragma GCC diagnostic ignored "-Wpmf-conversions"
>// Nasty hack.  The C++ standard mandates that get invokes the do_get
> diff --git a/libstdc

[patch,avr,applied] Work around PR115307 early expanders generate bloat for isinf

2024-06-01 Thread Georg-Johann Lay

Applied this patch as proposed by Richard.

Johann

--

AVR: tree-optimization/115307 - Work around isinf bloat from early passes.

PR tree-optimization/115307
gcc/
* config/avr/avr.md (SFDF): New mode iterator.
(isinf2) [sf, df]: New expanders.

gcc/testsuite/
* gcc.target/avr/torture/pr115307-isinf.c: New test.


diff --git a/gcc/config/avr/avr.md b/gcc/config/avr/avr.md
index d4fcff46123..75d35d5e14b 100644
--- a/gcc/config/avr/avr.md
+++ b/gcc/config/avr/avr.md
@@ -292,6 +292,8 @@ (define_mode_iterator ORDERED234 [HI SI PSI
 (define_mode_iterator SPLIT34 [SI SF PSI
SQ USQ SA USA])

+(define_mode_iterator SFDF [SF DF])
+
 ;; Where the most significant bit is located.
 (define_mode_attr MSB  [(QI "7") (QQ "7") (UQQ "7")
 (HI "15") (HQ "15") (UHQ "15") (HA "15") (UHA 
"15")

@@ -10047,6 +10049,20 @@ (define_insn_and_split "*extract.subreg.bit"
  (const_int 1)
  (match_dup 2)))])

+
+;; Work around PR115307: Early passes expand isinf/f/l to a bloat.
+;; These passes do not consider costs, and there is no way to
+;; hook in or otherwise disable the generated bloat.
+
+;; isinfsf2  isinfdf2
+(define_expand "isinf2"
+  [(parallel [(match_operand:HI 0)
+  (match_operand:SFDF 1)])]
+  ""
+  {
+FAIL;
+  })
+
 ^L
 ;; Fixed-point instructions
 (include "avr-fixed.md")
diff --git a/gcc/testsuite/gcc.target/avr/torture/pr115307-isinf.c 
b/gcc/testsuite/gcc.target/avr/torture/pr115307-isinf.c

new file mode 100644
index 000..6368bd205c5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/avr/torture/pr115307-isinf.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+
+int call_isinff (float f)
+{
+int isinff (float);
+return isinff (f);
+}
+
+int call_isinf (double f)
+{
+int isinf (double);
+return isinf (f);
+}
+
+int call_isinfl (long double f)
+{
+int isinfl (long double);
+return isinfl (f);
+}
+
+/* { dg-final { scan-assembler-not "unord" } } */



[committed] libstdc++: Replace link to gcc-4.3.2 docs in manual [PR115269]

2024-06-01 Thread Jonathan Wakely
Pushed to trunk. I'll backport this, and link to the appropriate release
branch docs instead of the trunk docs.

-- >8 --

Link to the docs for GCC trunk instead. For the release branches, the
link should be to the docs for appropriate release branch.

Also replace the incomplete/outdated list of explicit -std options with
a single entry for the -std option.

libstdc++-v3/ChangeLog:

PR libstdc++/115269
* doc/xml/manual/using.xml: Replace link to gcc-4.3.2 docs.
Replace list of -std=... options with a single entry for -std.
* doc/html/manual/using.html: Regenerate.
---
 libstdc++-v3/doc/html/manual/using.html | 10 +---
 libstdc++-v3/doc/xml/manual/using.xml   | 33 -
 2 files changed, 11 insertions(+), 32 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/using.html 
b/libstdc++-v3/doc/html/manual/using.html
index d663660b3a4..fcd1b96de0d 100644
--- a/libstdc++-v3/doc/html/manual/using.html
+++ b/libstdc++-v3/doc/html/manual/using.html
@@ -4,7 +4,7 @@
   
  NextChapter 3. UsingTable of ContentsCommand 
OptionsHeadersHeader 
FilesMixing 
HeadersThe C Headers and 
namespace stdPrecompiled 
HeadersMacrosDual ABITroubleshootingNamespacesAvailable 
Namespacesnamespace 
stdUsing Namespace 
CompositionLinkingAlmost
 NothingFinding 
Dynamic or Shared LibrariesExperimental
 Library ExtensionsConcurrencyPrerequisitesThread
 SafetyAtomicsIOStructureDefaultsFutureAlternativesContainersExceptionsException 
SafetyException 
NeutralityMemory 
allocationDoing 
withoutCompatibilityWith 
CWith POSIX thread 
cancellationDebugging SupportUsing g++Debug 
ModeTracking uncaught 
exceptionsMemory Leak 
HuntingNon-memory leaks in Pool and MT 
allocatorsData Race HuntingUsing gdbDebug Versions of Library Binary 
FilesCompile Time 
CheckingCommand Options
   The set of features available in the GNU C++ library is shaped by
-  several http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Invoking-GCC.html"; 
target="_top">GCC
+  several https://gcc.gnu.org/onlinedocs/gcc/Invoking-GCC.html"; target="_top">GCC
   Command Options. Options that impact libstdc++ are
   enumerated and detailed in the table below.
 
@@ -14,9 +14,11 @@
   g++ -std=gnu++17 since GCC 
11, and
   g++ -std=gnu++14 in GCC 6, 
7, 8, 9, and 10, and
   g++ -std=gnu++98 for older 
releases.
-Table 3.1. C++ Command OptionsOption FlagsDescription-std=c++98 or -std=c++03
-  Use the 1998 ISO C++ standard plus 
amendments.-std=gnu++98 or -std=gnu++03
-  As directly above, with GNU 
extensions.-std=c++11Use the 2011 ISO C++ 
standard.-std=gnu++11As directly above, 
with GNU extensions.-std=c++14Use the 2014 ISO C++ 
standard.-std=gnu++14As directly above, 
with GNU extensions.
+Table 3.1. C++ Command OptionsOption FlagsDescription-std
+  
+   Select the C++ standard, and whether to use the base standard
+   or GNU dialect.
+  
-fno-exceptions
   See exception-free dialect
-fno-rtti
diff --git a/libstdc++-v3/doc/xml/manual/using.xml 
b/libstdc++-v3/doc/xml/manual/using.xml
index 8ac7e74034c..74321733e8f 100644
--- a/libstdc++-v3/doc/xml/manual/using.xml
+++ b/libstdc++-v3/doc/xml/manual/using.xml
@@ -7,7 +7,7 @@
 
 
   The set of features available in the GNU C++ library is shaped by
-  several http://www.w3.org/1999/xlink"; 
xlink:href="http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Invoking-GCC.html";>GCC
+  several http://www.w3.org/1999/xlink"; 
xlink:href="https://gcc.gnu.org/onlinedocs/gcc/Invoking-GCC.html";>GCC
   Command Options. Options that impact libstdc++ are
   enumerated and detailed in the table below.
 
@@ -37,35 +37,12 @@
 
   
 
-  -std=c++98 or -std=c++03
+  -std
   
-  Use the 1998 ISO C++ standard plus amendments.
-
-
-
-  -std=gnu++98 or -std=gnu++03
+  
+   Select the C++ standard, and whether to use the base standard
+   or GNU dialect.
   
-  As directly above, with GNU extensions.
-
-
-
-  -std=c++11
-  Use the 2011 ISO C++ standard.
-
-
-
-  -std=gnu++11
-  As directly above, with GNU extensions.
-
-
-
-  -std=c++14
-  Use the 2014 ISO C++ standard.
-
-
-
-  -std=gnu++14
-  As directly above, with GNU extensions.
 
 
 
-- 
2.45.1



[pushed] wwwdocs: news: golang.org has become go.dev

2024-06-01 Thread Gerald Pfeifer
Pushed

Gerald
---
 htdocs/news.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/htdocs/news.html b/htdocs/news.html
index b7a6f479..c319e250 100644
--- a/htdocs/news.html
+++ b/htdocs/news.html
@@ -582,7 +582,7 @@ We are currently accepting student applications.
 
 December 2, 2010
 GCC 4.6 will support
-  the https://golang.org/";>Go programming language.  The
+  the https://go.dev";>Go programming language.  The
   new front end was contributed by Ian Lance Taylor at Google.
 
 November 16, 2010
-- 
2.45.1


[PATCH] libstdc++: Implement C++26 features (P2546R5)

2024-06-01 Thread Jonathan Wakely
Here's an implementation of the C++26  header.

We should really have some tests that invoke GDB and check that the
breakpoint works when a debugger is attached. That seems tricky to do
via the main conformance.exp testsuite. It could be done via the
prettyprinters.exp testsuite, which already uses GDB, but would require
some changes to the gdb-test procedure, which assumes it needs to insert
its own breakpoint at marked spots in the code.

I think we could add this without those tests, and improve it later.

-- >8 --

It would be good to provide a macOS definition of is_debugger_present,
but that isn't included in this change.

libstdc++-v3/ChangeLog:

* config.h.in: Regenerate.
* configure: Regenerate.
* configure.ac: Check for facilities needed by .
* include/Makefile.am: Add new header.
* include/Makefile.in: Regenerate.
* include/bits/version.def (debugging): Add.
* include/bits/version.h: Regenerate.
* src/c++26/Makefile.am: Add new file.
* src/c++26/Makefile.in: Regenerate.
* include/std/debugging: New file.
* src/c++26/debugging.cc: New file.
* testsuite/19_diagnostics/debugging/breakpoint.cc: New test.
* testsuite/19_diagnostics/debugging/breakpoint_if_debugging.cc:
New test.
---
 libstdc++-v3/config.h.in  |   9 ++
 libstdc++-v3/configure|  22 +++
 libstdc++-v3/configure.ac |   9 ++
 libstdc++-v3/include/Makefile.am  |   1 +
 libstdc++-v3/include/Makefile.in  |   1 +
 libstdc++-v3/include/bits/version.def |   9 ++
 libstdc++-v3/include/bits/version.h   |  10 ++
 libstdc++-v3/include/std/debugging|  82 
 libstdc++-v3/src/c++26/Makefile.am|   4 +-
 libstdc++-v3/src/c++26/Makefile.in|   7 +-
 libstdc++-v3/src/c++26/debugging.cc   | 126 ++
 .../19_diagnostics/debugging/breakpoint.cc|   9 ++
 .../debugging/breakpoint_if_debugging.cc  |   9 ++
 13 files changed, 295 insertions(+), 3 deletions(-)
 create mode 100644 libstdc++-v3/include/std/debugging
 create mode 100644 libstdc++-v3/src/c++26/debugging.cc
 create mode 100644 
libstdc++-v3/testsuite/19_diagnostics/debugging/breakpoint.cc
 create mode 100644 
libstdc++-v3/testsuite/19_diagnostics/debugging/breakpoint_if_debugging.cc

diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in
index 486ba450749..07203815459 100644
--- a/libstdc++-v3/config.h.in
+++ b/libstdc++-v3/config.h.in
@@ -70,6 +70,9 @@
 /* Define to 1 if you have the `cosl' function. */
 #undef HAVE_COSL
 
+/* Define to 1 if you have the  header file. */
+#undef HAVE_DEBUGAPI_H
+
 /* Define to 1 if you have the declaration of `strnlen', and to 0 if you
don't. */
 #undef HAVE_DECL_STRNLEN
@@ -436,6 +439,9 @@
 /* Define to 1 if you have the  header file. */
 #undef HAVE_SYS_PARAM_H
 
+/* Define to 1 if you have the  header file. */
+#undef HAVE_SYS_PTRACE_H
+
 /* Define to 1 if you have the  header file. */
 #undef HAVE_SYS_RESOURCE_H
 
@@ -847,6 +853,9 @@
 /* Define if nl_langinfo_l should be used for std::text_encoding. */
 #undef _GLIBCXX_USE_NL_LANGINFO_L
 
+/* Define if /proc/self/status should be used for . */
+#undef _GLIBCXX_USE_PROC_SELF_STATUS
+
 /* Define if pthreads_num_processors_np is available in . */
 #undef _GLIBCXX_USE_PTHREADS_NUM_PROCESSORS_NP
 
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index 5645e991af7..55ddf36a7f1 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -54612,6 +54612,28 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
 
+# For std::is_debugger_present
+case "$target_os" in
+  linux*)
+
+$as_echo "#define _GLIBCXX_USE_PROC_SELF_STATUS 1" >>confdefs.h
+
+;;
+esac
+for ac_header in sys/ptrace.h debugapi.h
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" 
"$ac_includes_default"
+if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
 # Define documentation rules conditionally.
 
 # See if makeinfo has been installed and is modern enough
diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac
index ccb24a82be7..96b412fb7ae 100644
--- a/libstdc++-v3/configure.ac
+++ b/libstdc++-v3/configure.ac
@@ -573,6 +573,15 @@ GLIBCXX_CHECK_FILEBUF_NATIVE_HANDLES
 # For std::text_encoding
 GLIBCXX_CHECK_TEXT_ENCODING
 
+# For std::is_debugger_present
+case "$target_os" in
+  linux*)
+AC_DEFINE([_GLIBCXX_USE_PROC_SELF_STATUS],1,
+ [Define if /proc/self/status should be used for .])
+;;
+esac
+AC_CHECK_HEADERS([sys/ptrace.h debugapi.h])
+
 # Define documentation rules conditionally.
 
 # See if makeinfo has been installed and is modern enough
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Ma

[PATCH] libstdc++: Optimize std::basic_string_view::starts_with

2024-06-01 Thread Jonathan Wakely
We get smaller code at all optimization levels by not creating a
temporary object, just comparing lengths first and then using
traits_type::compare. This does less work than calling substr then
operator==.

libstdc++-v3/ChangeLog:

* include/std/string_view (starts_with(basic_string_view)):
Compare lengths first and then call traits_type::compare
directly.
---
 libstdc++-v3/include/std/string_view | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/string_view 
b/libstdc++-v3/include/std/string_view
index a7c5a126461..740aa9344f0 100644
--- a/libstdc++-v3/include/std/string_view
+++ b/libstdc++-v3/include/std/string_view
@@ -385,7 +385,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   [[nodiscard]]
   constexpr bool
   starts_with(basic_string_view __x) const noexcept
-  { return this->substr(0, __x.size()) == __x; }
+  {
+   return _M_len >= __x._M_len
+ && traits_type::compare(_M_str, __x._M_str, __x._M_len) == 0;
+  }
 
   [[nodiscard]]
   constexpr bool
-- 
2.45.1



[PATCH 2/2] libstdc++: Reuse temporary buffer utils in

2024-06-01 Thread Jonathan Wakely
The non-throwing allocation logic in std::stacktrace duplicates the
logic in , so we can just reuse those utilities.

libstdc++-v3/ChangeLog:

* include/std/stacktrace (basic_stacktrace::_Impl::_M_allocate):
Use __detail::__get_temporary_buffer.
(basic_stacktrace::_Impl::_M_deallocate): Use
__detail::__return_temporary_buffer.
---
 libstdc++-v3/include/std/stacktrace | 29 -
 1 file changed, 4 insertions(+), 25 deletions(-)

diff --git a/libstdc++-v3/include/std/stacktrace 
b/libstdc++-v3/include/std/stacktrace
index 962dbed7a41..e0a543920bc 100644
--- a/libstdc++-v3/include/std/stacktrace
+++ b/libstdc++-v3/include/std/stacktrace
@@ -45,6 +45,7 @@
 #include 
 #include 
 #include 
+#include  // __get_temporary_buffer
 #include 
 
 namespace std _GLIBCXX_VISIBILITY(default)
@@ -545,21 +546,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  return std::min(__size_max, __alloc_max);
}
 
-#if __has_builtin(__builtin_operator_new) >= 201802L
-# define _GLIBCXX_OPERATOR_NEW __builtin_operator_new
-# define _GLIBCXX_OPERATOR_DELETE __builtin_operator_delete
-#else
-# define _GLIBCXX_OPERATOR_NEW ::operator new
-# define _GLIBCXX_OPERATOR_DELETE ::operator delete
-#endif
-
-#if __cpp_sized_deallocation
-# define _GLIBCXX_SIZED_DELETE(T, p, n) \
-  _GLIBCXX_OPERATOR_DELETE((p), (n) * sizeof(T))
-#else
-# define _GLIBCXX_SIZED_DELETE(T, p, n) _GLIBCXX_OPERATOR_DELETE(p)
-#endif
-
// Precondition: _M_frames == nullptr && __n != 0
pointer
_M_allocate(allocator_type& __alloc, size_type __n) noexcept
@@ -570,11 +556,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
  // For std::allocator we use nothrow-new directly so we
  // don't need to handle bad_alloc exceptions.
- size_t __nb = __n * sizeof(value_type);
- void* const __p = _GLIBCXX_OPERATOR_NEW (__nb, nothrow_t{});
+ auto __p = __detail::__get_temporary_buffer(__n);
  if (__p == nullptr) [[unlikely]]
return nullptr;
- _M_frames = static_cast(__p);
+ _M_frames = __p;
}
  else
{
@@ -599,9 +584,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  if (_M_capacity)
{
  if constexpr (is_same_v>)
-   _GLIBCXX_SIZED_DELETE(value_type,
- static_cast(_M_frames),
- _M_capacity);
+   __detail::__return_temporary_buffer(_M_frames, _M_capacity);
  else
__alloc.deallocate(_M_frames, _M_capacity);
  _M_frames = nullptr;
@@ -609,10 +592,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
}
 
-#undef _GLIBCXX_SIZED_DELETE
-#undef _GLIBCXX_OPERATOR_DELETE
-#undef _GLIBCXX_OPERATOR_NEW
-
// Precondition: __n <= _M_size
void
_M_resize(size_type __n, allocator_type& __alloc) noexcept
-- 
2.45.1



[PATCH 1/2] libstdc++: Handle extended alignment in std::get_temporary_buffer [PR105258]

2024-06-01 Thread Jonathan Wakely
I'v refactored the code a bit, adding a new __get_temporary_buffer
helper, because I want to use that in  in [PATCH 2/2].

I considered making __return_temporary_buffer also work for the
non-sized case, using non-sized delete if __len == 0, and then making
std::return_temporary_buffer call __return_temporary_buffer(p, 0). But
that didn't really seem much simpler/clearer, so I didn't do it.

-- >8 --

This adds extended alignment support to std::get_temporary_buffer etc.
so that when std::stable_sort uses a temporary buffer it works for
overaligned types.

Also simplify the _Temporary_buffer type by using RAII for the
allocation, via a new data member. This simplifies the _Temporary_buffer
constructor and destructor by makingthem only responsible for
constructing and destroying the elements, not managing the memory.

libstdc++-v3/ChangeLog:

PR libstdc++/105258
* include/bits/stl_tempbuf.h (__detail::__get_temporary_buffer):
New function to do allocation for get_temporary_buffer, with
extended alignment support.
(__detail::__return_temporary_buffer): Support extended
alignment.
(get_temporary_buffer): Use __get_temporary_buffer.
(return_temporary_buffer): Support extended alignment. Add
deprecated attribute.
(_Temporary_buffer): Move allocation and deallocation into a
subobject and remove try-catch block in constructor.
(__uninitialized_construct_buf): Use argument deduction for
value type.
* testsuite/20_util/temporary_buffer.cc: Add dg-warning for new
deprecated warning.
* testsuite/25_algorithms/stable_sort/overaligned.cc: New test.
---
 libstdc++-v3/include/bits/stl_tempbuf.h   | 128 --
 .../testsuite/20_util/temporary_buffer.cc |   2 +-
 .../25_algorithms/stable_sort/overaligned.cc  |  29 
 3 files changed, 113 insertions(+), 46 deletions(-)
 create mode 100644 
libstdc++-v3/testsuite/25_algorithms/stable_sort/overaligned.cc

diff --git a/libstdc++-v3/include/bits/stl_tempbuf.h 
b/libstdc++-v3/include/bits/stl_tempbuf.h
index 77b121460f9..018ee18de15 100644
--- a/libstdc++-v3/include/bits/stl_tempbuf.h
+++ b/libstdc++-v3/include/bits/stl_tempbuf.h
@@ -66,19 +66,55 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
+#if __has_builtin(__builtin_operator_new) >= 201802L
+# define _GLIBCXX_OPERATOR_NEW __builtin_operator_new
+# define _GLIBCXX_OPERATOR_DELETE __builtin_operator_delete
+#else
+# define _GLIBCXX_OPERATOR_NEW ::operator new
+# define _GLIBCXX_OPERATOR_DELETE ::operator delete
+#endif
+
   namespace __detail
   {
+// Equivalent to std::get_temporary_buffer but won't return a smaller size.
+// It either returns a buffer of __len elements, or a null pointer.
+template
+  inline _Tp*
+  __get_temporary_buffer(ptrdiff_t __len) _GLIBCXX_NOTHROW
+  {
+#if __cpp_aligned_new
+   if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
+ return (_Tp*) _GLIBCXX_OPERATOR_NEW(__len * sizeof(_Tp),
+ align_val_t(alignof(_Tp)),
+ nothrow_t());
+#endif
+   return (_Tp*) _GLIBCXX_OPERATOR_NEW(__len * sizeof(_Tp), nothrow_t());
+  }
+
+// Equivalent to std::return_temporary_buffer but with a size argument.
+// The size is the number of elements, not the number of bytes.
 template
   inline void
   __return_temporary_buffer(_Tp* __p,
size_t __len __attribute__((__unused__)))
   {
 #if __cpp_sized_deallocation
-   ::operator delete(__p, __len * sizeof(_Tp));
+# define _GLIBCXX_SIZED_DEALLOC(T, p, n) (p), (n) * sizeof(T)
 #else
-   ::operator delete(__p);
+# define _GLIBCXX_SIZED_DEALLOC(T, p, n) (p)
 #endif
+
+#if __cpp_aligned_new
+   if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
+ {
+   _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(_Tp, __p, __len),
+align_val_t(alignof(_Tp)));
+   return;
+ }
+#endif
+   _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(_Tp, __p, __len));
   }
+#undef _GLIBCXX_SIZED_DEALLOC
   }
 
   /**
@@ -90,7 +126,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
*  This function tries to obtain storage for @c __len adjacent Tp
*  objects.  The objects themselves are not constructed, of course.
-   *  A pair<> is returned containing the buffer s address and
+   *  A pair<> is returned containing the buffer's address and
*  capacity (in the units of sizeof(_Tp)), or a pair of 0 values if
*  no storage can be obtained.  Note that the capacity obtained
*  may be less than that requested if the memory is unavailable;
@@ -110,13 +146,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   while (__len > 0)
{
- _Tp* __tmp = static_cast<_Tp*>(::operator new(__len * sizeof(_Tp),
-

[PATCH v2 1/2] libstdc++: Handle extended alignment in std::get_temporary_buffer [PR105258]

2024-06-01 Thread Jonathan Wakely
Although it's only used from places where we are allocating a sensible
size, __detail::__get_temporary_buffer should really still check that
len * sizeof(T) doesn't wrap around to zero and allocate a buffer that's
smaller than expected.

This v2 patch is the same as v1 except for adding this check:

   inline _Tp*
   __get_temporary_buffer(ptrdiff_t __len) _GLIBCXX_NOTHROW
   {
+   if (__builtin_expect(__len > (size_t(-1) / sizeof(_Tp)), 0))
+ return 0;
+
 #if __cpp_aligned_new
if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
  return (_Tp*) _GLIBCXX_OPERATOR_NEW(__len * sizeof(_Tp),

-- >8 --

This adds extended alignment support to std::get_temporary_buffer etc.
so that when std::stable_sort uses a temporary buffer it works for
overaligned types.

Also simplify the _Temporary_buffer type by using RAII for the
allocation, via a new data member. This simplifies the _Temporary_buffer
constructor and destructor by makingthem only responsible for
constructing and destroying the elements, not managing the memory.

libstdc++-v3/ChangeLog:

PR libstdc++/105258
* include/bits/stl_tempbuf.h (__detail::__get_temporary_buffer):
New function to do allocation for get_temporary_buffer, with
extended alignment support.
(__detail::__return_temporary_buffer): Support extended
alignment.
(get_temporary_buffer): Use __get_temporary_buffer.
(return_temporary_buffer): Support extended alignment. Add
deprecated attribute.
(_Temporary_buffer): Move allocation and deallocation into a
subobject and remove try-catch block in constructor.
(__uninitialized_construct_buf): Use argument deduction for
value type.
* testsuite/20_util/temporary_buffer.cc: Add dg-warning for new
deprecated warning.
* testsuite/25_algorithms/stable_sort/overaligned.cc: New test.
---
 libstdc++-v3/include/bits/stl_tempbuf.h   | 131 --
 .../testsuite/20_util/temporary_buffer.cc |   2 +-
 .../25_algorithms/stable_sort/overaligned.cc  |  29 
 3 files changed, 116 insertions(+), 46 deletions(-)
 create mode 100644 
libstdc++-v3/testsuite/25_algorithms/stable_sort/overaligned.cc

diff --git a/libstdc++-v3/include/bits/stl_tempbuf.h 
b/libstdc++-v3/include/bits/stl_tempbuf.h
index 77b121460f9..fa03fd27704 100644
--- a/libstdc++-v3/include/bits/stl_tempbuf.h
+++ b/libstdc++-v3/include/bits/stl_tempbuf.h
@@ -66,19 +66,58 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
+#if __has_builtin(__builtin_operator_new) >= 201802L
+# define _GLIBCXX_OPERATOR_NEW __builtin_operator_new
+# define _GLIBCXX_OPERATOR_DELETE __builtin_operator_delete
+#else
+# define _GLIBCXX_OPERATOR_NEW ::operator new
+# define _GLIBCXX_OPERATOR_DELETE ::operator delete
+#endif
+
   namespace __detail
   {
+// Equivalent to std::get_temporary_buffer but won't return a smaller size.
+// It either returns a buffer of __len elements, or a null pointer.
+template
+  inline _Tp*
+  __get_temporary_buffer(ptrdiff_t __len) _GLIBCXX_NOTHROW
+  {
+   if (__builtin_expect(__len > (size_t(-1) / sizeof(_Tp)), 0))
+ return 0;
+
+#if __cpp_aligned_new
+   if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
+ return (_Tp*) _GLIBCXX_OPERATOR_NEW(__len * sizeof(_Tp),
+ align_val_t(alignof(_Tp)),
+ nothrow_t());
+#endif
+   return (_Tp*) _GLIBCXX_OPERATOR_NEW(__len * sizeof(_Tp), nothrow_t());
+  }
+
+// Equivalent to std::return_temporary_buffer but with a size argument.
+// The size is the number of elements, not the number of bytes.
 template
   inline void
   __return_temporary_buffer(_Tp* __p,
size_t __len __attribute__((__unused__)))
   {
 #if __cpp_sized_deallocation
-   ::operator delete(__p, __len * sizeof(_Tp));
+# define _GLIBCXX_SIZED_DEALLOC(T, p, n) (p), (n) * sizeof(T)
 #else
-   ::operator delete(__p);
+# define _GLIBCXX_SIZED_DEALLOC(T, p, n) (p)
 #endif
+
+#if __cpp_aligned_new
+   if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
+ {
+   _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(_Tp, __p, __len),
+align_val_t(alignof(_Tp)));
+   return;
+ }
+#endif
+   _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(_Tp, __p, __len));
   }
+#undef _GLIBCXX_SIZED_DEALLOC
   }
 
   /**
@@ -90,7 +129,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
*  This function tries to obtain storage for @c __len adjacent Tp
*  objects.  The objects themselves are not constructed, of course.
-   *  A pair<> is returned containing the buffer s address and
+   *  A pair<> is returned containing the buffer's address and
*  capacity (in the units of sizeof(_Tp)), or a pair of 0 values if
*  no 

[C PATCH, v3] Fix for redeclared enumerator initialized with different type [PR115109]

2024-06-01 Thread Martin Uecker


This is a new version of the patch.  I changed the overflow warning to
an error and added your other example to the test case.

Bootstrapped and regression tested on x86_64.


c23: Fix for redeclared enumerator initialized with different type 
[PR115109]

c23 specifies that the type of a redeclared enumerator is the one of the
previous declaration.  Convert initializers with different type accordingly
and emit an error when the value does not fit.

2024-06-01 Martin Uecker  

PR c/115109

gcc/c/
* c-decl.cc (build_enumerator): When redeclaring an
enumerator convert value to previous type.  For redeclared
enumerators use underlying type for computing the next value.

gcc/testsuite/
* gcc.dg/pr115109.c: New test.
* gcc.dg/c23-tag-enum-6.c: New test.
* gcc.dg/c23-tag-enum-7.c: New test.

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 64924b87a91..38a4e842307 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -10262,6 +10262,7 @@ build_enumerator (location_t decl_loc, location_t loc,
  struct c_enum_contents *the_enum, tree name, tree value)
 {
   tree decl;
+  tree old_decl;
 
   /* Validate and default VALUE.  */
 
@@ -10321,6 +10322,23 @@ build_enumerator (location_t decl_loc, location_t loc,
 definition.  */
   value = convert (the_enum->enum_type, value);
 }
+  else if (flag_isoc23
+  && (old_decl = lookup_name_in_scope (name, current_scope))
+  && old_decl != error_mark_node
+  && TREE_TYPE (old_decl)
+  && TREE_TYPE (TREE_TYPE (old_decl))
+  && TREE_CODE (old_decl) == CONST_DECL)
+{
+  /* Enumeration constants in a redeclaration have the previous type.  */
+  tree previous_type = TREE_TYPE (DECL_INITIAL (old_decl));
+  if (!int_fits_type_p (value, previous_type))
+   {
+ error_at (loc, "value of redeclared enumerator outside the range "
+"of %qT", previous_type);
+ locate_old_decl (old_decl);
+   }
+  value = convert (previous_type, value);
+}
   else
 {
   /* Even though the underlying type of an enum is unspecified, the
@@ -10387,9 +10405,14 @@ build_enumerator (location_t decl_loc, location_t loc,
 false);
 }
   else
-the_enum->enum_next_value
-  = build_binary_op (EXPR_LOC_OR_LOC (value, input_location),
-PLUS_EXPR, value, integer_one_node, false);
+{
+  /* In a redeclaration the type can already be the enumeral type.  */
+  if (TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE)
+   value = convert (ENUM_UNDERLYING_TYPE (TREE_TYPE (value)), value);
+  the_enum->enum_next_value
+   = build_binary_op (EXPR_LOC_OR_LOC (value, input_location),
+  PLUS_EXPR, value, integer_one_node, false);
+}
   the_enum->enum_overflow = tree_int_cst_lt (the_enum->enum_next_value, value);
   if (the_enum->enum_overflow
   && !ENUM_FIXED_UNDERLYING_TYPE_P (the_enum->enum_type))
diff --git a/gcc/testsuite/gcc.dg/c23-tag-enum-6.c 
b/gcc/testsuite/gcc.dg/c23-tag-enum-6.c
new file mode 100644
index 000..0fa5d7534f3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c23-tag-enum-6.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c23" } */
+
+#include 
+
+enum E : int { a = 1, b = 2 };
+enum E : int { b = _Generic(a, enum E: 2), a = 1 };
+
+enum H { x = 1 };
+enum H { x = 2UL + UINT_MAX }; /* { dg-error "outside the range" } */
+
+enum K : int { z = 1 };
+enum K : int { z = 2UL + UINT_MAX };   /* { dg-error "outside the range" } */
+
+enum F { A = 0, B = UINT_MAX };
+enum F { B = UINT_MAX, A };/* { dg-error "outside the range" } */
+
+enum G : unsigned int { C = 0, D = UINT_MAX };
+enum G : unsigned int { D = UINT_MAX, C }; /* { dg-error 
"overflow" } */
+
diff --git a/gcc/testsuite/gcc.dg/c23-tag-enum-7.c 
b/gcc/testsuite/gcc.dg/c23-tag-enum-7.c
new file mode 100644
index 000..0634c0aa698
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c23-tag-enum-7.c
@@ -0,0 +1,41 @@
+/* { dg-do compile }
+ * { dg-options "-std=c23" } */
+
+#include 
+
+// enumerators are all representable in int
+enum E { a = 1UL, b = _Generic(a, int: 2) };
+static_assert(_Generic(a, int: 1));
+static_assert(_Generic(b, int: 1));
+enum E { a = 1UL, b = _Generic(a, int: 2) };
+static_assert(_Generic(a, int: 1));
+static_assert(_Generic(b, int: 1));
+
+// enumerators are not representable in int
+enum H { c = 1UL << (UINT_WIDTH + 1), d = 2 };
+static_assert(_Generic(c, enum H: 1));
+static_assert(_Generic(d, enum H: 1));
+enum H { c = 1UL << (UINT_WIDTH + 1), d = _Generic(c, enum H: 2) };
+static_assert(_Generic(c, enum H: 1));
+static_assert(_Generic(d, enum H: 1));
+
+// there is an overflow in the first declaration
+enum K { e = UINT_MAX, f, g = _Generic(e, unsigned int: 0) + _Generic(f, 
unsigned long: 1) };
+

Re: [PATCH] c-family: Introduce the -Winvalid-noreturn flag from clang with extra tuneability

2024-06-01 Thread Julian Waters
Hi Jason,

Thanks for the reply! I'll address your comments soon. I have a
question, if there is an option defined in c.opt as an Enum, like
fstrong-eval-order, and the -no variant of the option is passed, would
the Var somehow reflect the negated option? Eg

Winvalid-noreturn=
C ObjC C++ ObjC++ Var(warn_invalid_noreturn) Joined
Enum(invalid_noreturn) Warning

Enum
Name(invalid_noreturn) Type(int)

EnumValue
Enum(invalid_noreturn) String(explicit) Value(0)

Would warn_invalid_noreturn then != 0 if
-Wno-invalid-noreturn=explicit is passed? Or is there a way to make a
warning call depend on 2 different OPT_ entries?

best regards,
Julian

On Sat, Jun 1, 2024 at 4:57 AM Jason Merrill  wrote:
>
> On 5/29/24 09:58, Julian Waters wrote:
> > Currently, gcc warns about noreturn marked functions that return both 
> > explicitly and implicitly, with no way to turn this warning off. clang does 
> > have an option for these classes of warnings, -Winvalid-noreturn. However, 
> > we can do better. Instead of just having 1 option that switches the 
> > warnings for both on and off, we can define an extra layer of granularity, 
> > and have a separate options for implicit returns and explicit returns, as 
> > in -Winvalid-return=explicit and -Winvalid-noreturn=implicit. This patch 
> > adds both to gcc, for compatibility with clang.
>
> Thanks!
>
> > Do note that I am relatively new to gcc's codebase, and as such couldn't 
> > figure out how to cleanly define a general -Winvalid-noreturn warning that 
> > switch both on and off, for better compatibility with clang. If someone 
> > should point out how to do so, I'll happily rewrite my patch.
>
> See -fstrong-eval-order for an example of an option that can be used
> with or without =arg.
>
> > I also do not have write access to gcc, and will need help pushing this 
> > patch once the green light is given
>
> Good to know, I can take care of that.
>
> > best regards,
> > Julian
> >
> > gcc/c-family/ChangeLog:
> >
> >   * c.opt: Introduce -Winvalid-noreturn=explicit and 
> > -Winvalid-noreturn=implicit
> >
> > gcc/ChangeLog:
> >
> >   * tree-cfg.cc (pass_warn_function_return::execute): Use it
> >
> > gcc/c/ChangeLog:
> >
> >   * c-typeck.cc (c_finish_return): Use it
> >   * gimple-parser.cc (c_finish_gimple_return): Use it
> >
> > gcc/config/mingw/ChangeLog:
> >
> >   * mingw32.h (EXTRA_OS_CPP_BUILTINS): Fix semicolons
> >
> > gcc/cp/ChangeLog:
> >
> >   * coroutines.cc (finish_co_return_stmt): Use it
> >   * typeck.cc (check_return_expr): Use it
> >
> > gcc/doc/ChangeLog:
> >
> >   * invoke.texi: Document new options
> >
> >  From 4daf884f8bbc1e318ba93121a6fdf4139da80b64 Mon Sep 17 00:00:00 2001
> > From: TheShermanTanker 
> > Date: Wed, 29 May 2024 21:32:08 +0800
> > Subject: [PATCH] Introduce the -Winvalid-noreturn flag from clang with extra
> >   tuneability
>
> The rationale and ChangeLog entries should be part of the commit message
> (and so the git format-patch output).
>
> >
> > Signed-off-by: TheShermanTanker 
>
> A DCO sign-off can't use a pseudonym, sorry; please either sign off
> using your real name or file a copyright assignment for the pseudonym
> with the FSF.
>
> See https://gcc.gnu.org/contribute.html#legal for more detail.
>
> > ---
> >   gcc/c-family/c.opt |  8 
> >   gcc/c/c-typeck.cc  |  2 +-
> >   gcc/c/gimple-parser.cc |  2 +-
> >   gcc/config/mingw/mingw32.h |  6 +++---
> >   gcc/cp/coroutines.cc   |  2 +-
> >   gcc/cp/typeck.cc   |  2 +-
> >   gcc/doc/invoke.texi| 13 +
> >   gcc/tree-cfg.cc|  2 +-
> >   8 files changed, 29 insertions(+), 8 deletions(-)
> >
> > diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
> > index fb34c3b7031..32a2859fdcc 100644
> > --- a/gcc/c-family/c.opt
> > +++ b/gcc/c-family/c.opt
> > @@ -886,6 +886,14 @@ Winvalid-constexpr
> >   C++ ObjC++ Var(warn_invalid_constexpr) Init(-1) Warning
> >   Warn when a function never produces a constant expression.
> >
> > +Winvalid-noreturn=explicit
> > +C ObjC C++ ObjC++ Warning
> > +Warn when a function marked noreturn returns explicitly.
> > +
> > +Winvalid-noreturn=implicit
> > +C ObjC C++ ObjC++ Warning
> > +Warn when a function marked noreturn returns implicitly.
> > +
> >   Winvalid-offsetof
> >   C++ ObjC++ Var(warn_invalid_offsetof) Init(1) Warning
> >   Warn about invalid uses of the \"offsetof\" macro.
> > diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
> > index ad4c7add562..1941fbc44cb 100644
> > --- a/gcc/c/c-typeck.cc
> > +++ b/gcc/c/c-typeck.cc
> > @@ -11468,7 +11468,7 @@ c_finish_return (location_t loc, tree retval, tree 
> > origtype)
> > location_t xloc = expansion_point_location_if_in_system_header (loc);
> >
> > if (TREE_THIS_VOLATILE (current_function_decl))
> > -warning_at (xloc, 0,
> > +warning_at (xloc, OPT_Winvalid_noreturn_explicit,
> >   "function declared % has a % statement");
> >
> > if (retval)
> > diff --git a/gcc/c/

Re: [PATCH v2] [libstdc++] add _GLIBCXX_CLANG to workaround predefined __clang__

2024-06-01 Thread Jakub Jelinek
On Sat, Jun 01, 2024 at 09:21:53AM +0100, Jonathan Wakely wrote:
> On Fri, 31 May 2024 at 18:43, Alexandre Oliva  wrote:
> >
> > On May 31, 2024, Alexandre Oliva  wrote:
> >
> > >> So either don't change this line at all, or just do a simple
> > >> s/__clang__/_GLIBCXX_CLANG/
> >
> > > If c++config can be counted on, I'd be happy to do that, but I couldn't
> > > tell that it could.
> >
> > Here's what I've retested on x86_64-linux-gnu and, slightly adjusted for
> > gcc-13, on arm-vx7r2.  Ok to install?
> 
> OK
> 
> If there's any chance of getting the vxworks system headers fixed to
> work with GCC properly, that would be nice.

Fixincludes?
That seems like the standard way to workaround bugs in system headers on
proprietary targets.

Jakub



Re: [PATCH] jit: Ensure ssize_t is defined.

2024-06-01 Thread FX Coudert
ping**2 for this one-liner


> Le 11 mai 2024 à 17:16, FX Coudert  a écrit :
> 
> Hi,
> 
> On some targets it seems that ssize_t is not defined by any of the headers 
> transitively included by . This leads to a bootstrap fail when jit 
> is enabled. The attached patch fixes it by include . Other 
> headers in GCC treat  as available on all targets, so we include 
> it unconditionally.
> 
> Tested on x86_64-darwin and x86_64-linux. OK to push?
> 
> FX
> 
> <0001-jit-Ensure-ssize_t-is-defined.patch>



Re: [PATCH] c-family: Introduce the -Winvalid-noreturn flag from clang with extra tuneability

2024-06-01 Thread Eric Gallager
On Sat, Jun 1, 2024 at 11:32 AM Julian Waters  wrote:
>
> Hi Jason,
>
> Thanks for the reply! I'll address your comments soon. I have a
> question, if there is an option defined in c.opt as an Enum, like
> fstrong-eval-order, and the -no variant of the option is passed, would
> the Var somehow reflect the negated option? Eg
>
> Winvalid-noreturn=
> C ObjC C++ ObjC++ Var(warn_invalid_noreturn) Joined
> Enum(invalid_noreturn) Warning
>
> Enum
> Name(invalid_noreturn) Type(int)
>
> EnumValue
> Enum(invalid_noreturn) String(explicit) Value(0)
>
> Would warn_invalid_noreturn then != 0 if
> -Wno-invalid-noreturn=explicit is passed? Or is there a way to make a
> warning call depend on 2 different OPT_ entries?
>
> best regards,
> Julian

This kind of issue is one of the reasons why I think it's better to
just avoid the "=" character in warning option names, and to just make
completely separate options using the "-" character instead... (i.e.,
-Winvalid-noreturn-implicit and -Winvalid-noreturn-explicit)

>
> On Sat, Jun 1, 2024 at 4:57 AM Jason Merrill  wrote:
> >
> > On 5/29/24 09:58, Julian Waters wrote:
> > > Currently, gcc warns about noreturn marked functions that return both 
> > > explicitly and implicitly, with no way to turn this warning off. clang 
> > > does have an option for these classes of warnings, -Winvalid-noreturn. 
> > > However, we can do better. Instead of just having 1 option that switches 
> > > the warnings for both on and off, we can define an extra layer of 
> > > granularity, and have a separate options for implicit returns and 
> > > explicit returns, as in -Winvalid-return=explicit and 
> > > -Winvalid-noreturn=implicit. This patch adds both to gcc, for 
> > > compatibility with clang.
> >
> > Thanks!
> >
> > > Do note that I am relatively new to gcc's codebase, and as such couldn't 
> > > figure out how to cleanly define a general -Winvalid-noreturn warning 
> > > that switch both on and off, for better compatibility with clang. If 
> > > someone should point out how to do so, I'll happily rewrite my patch.
> >
> > See -fstrong-eval-order for an example of an option that can be used
> > with or without =arg.
> >
> > > I also do not have write access to gcc, and will need help pushing this 
> > > patch once the green light is given
> >
> > Good to know, I can take care of that.
> >
> > > best regards,
> > > Julian
> > >
> > > gcc/c-family/ChangeLog:
> > >
> > >   * c.opt: Introduce -Winvalid-noreturn=explicit and 
> > > -Winvalid-noreturn=implicit
> > >
> > > gcc/ChangeLog:
> > >
> > >   * tree-cfg.cc (pass_warn_function_return::execute): Use it
> > >
> > > gcc/c/ChangeLog:
> > >
> > >   * c-typeck.cc (c_finish_return): Use it
> > >   * gimple-parser.cc (c_finish_gimple_return): Use it
> > >
> > > gcc/config/mingw/ChangeLog:
> > >
> > >   * mingw32.h (EXTRA_OS_CPP_BUILTINS): Fix semicolons
> > >
> > > gcc/cp/ChangeLog:
> > >
> > >   * coroutines.cc (finish_co_return_stmt): Use it
> > >   * typeck.cc (check_return_expr): Use it
> > >
> > > gcc/doc/ChangeLog:
> > >
> > >   * invoke.texi: Document new options
> > >
> > >  From 4daf884f8bbc1e318ba93121a6fdf4139da80b64 Mon Sep 17 00:00:00 2001
> > > From: TheShermanTanker 
> > > Date: Wed, 29 May 2024 21:32:08 +0800
> > > Subject: [PATCH] Introduce the -Winvalid-noreturn flag from clang with 
> > > extra
> > >   tuneability
> >
> > The rationale and ChangeLog entries should be part of the commit message
> > (and so the git format-patch output).
> >
> > >
> > > Signed-off-by: TheShermanTanker 
> >
> > A DCO sign-off can't use a pseudonym, sorry; please either sign off
> > using your real name or file a copyright assignment for the pseudonym
> > with the FSF.
> >
> > See https://gcc.gnu.org/contribute.html#legal for more detail.
> >
> > > ---
> > >   gcc/c-family/c.opt |  8 
> > >   gcc/c/c-typeck.cc  |  2 +-
> > >   gcc/c/gimple-parser.cc |  2 +-
> > >   gcc/config/mingw/mingw32.h |  6 +++---
> > >   gcc/cp/coroutines.cc   |  2 +-
> > >   gcc/cp/typeck.cc   |  2 +-
> > >   gcc/doc/invoke.texi| 13 +
> > >   gcc/tree-cfg.cc|  2 +-
> > >   8 files changed, 29 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
> > > index fb34c3b7031..32a2859fdcc 100644
> > > --- a/gcc/c-family/c.opt
> > > +++ b/gcc/c-family/c.opt
> > > @@ -886,6 +886,14 @@ Winvalid-constexpr
> > >   C++ ObjC++ Var(warn_invalid_constexpr) Init(-1) Warning
> > >   Warn when a function never produces a constant expression.
> > >
> > > +Winvalid-noreturn=explicit
> > > +C ObjC C++ ObjC++ Warning
> > > +Warn when a function marked noreturn returns explicitly.
> > > +
> > > +Winvalid-noreturn=implicit
> > > +C ObjC C++ ObjC++ Warning
> > > +Warn when a function marked noreturn returns implicitly.
> > > +
> > >   Winvalid-offsetof
> > >   C++ ObjC++ Var(warn_invalid_offsetof) Init(1) Warning
> > >   Warn about invalid uses of the \"offset

[pushed] analyzer: detect -Wanalyzer-allocation-size at call stmts [PR106203]

2024-06-01 Thread David Malcolm
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Successful run of analyzer integration tests on x86_64-pc-linux-gnu.
Pushed to trunk as r15-969-g2b0a7fe3abfbd4.

gcc/analyzer/ChangeLog:
PR analyzer/106203
* checker-event.h: Include "analyzer/event-loc-info.h".
(struct event_loc_info): Move to its own header file.
* diagnostic-manager.cc
(diagnostic_manager::emit_saved_diagnostic): Move creation of
event_loc_info here from add_final_event, and if we have a
stmt_finder, call its update_event_loc_info method.
* engine.cc (leak_stmt_finder::update_event_loc_info): New.
(exploded_node::detect_leaks): Likewise.
(exploded_node::detect_leaks): Pass nullptr as call_stmt arg to
region_model::pop_frame.
* event-loc-info.h: New file, with content taken from
checker-event.h.
* exploded-graph.h (stmt_finder::update_event_loc_info): New pure
virtual function.
* infinite-loop.cc (infinite_loop_diagnostic::add_final_event):
Update for change to vfunc signature.
* infinite-recursion.cc
(infinite_recursion_diagnostic::add_final_event): Likewise.
* pending-diagnostic.cc (pending_diagnostic::add_final_event):
Pass in the event_loc_info from the caller, rather than generating
it from a gimple stmt and enode.
* pending-diagnostic.h (pending_diagnostic::add_final_event):
Likewise.
* region-model.cc (region_model::on_longjmp): Pass nullptr as
call_stmt arg to region_model::pop_frame.
(region_model::update_for_return_gcall): Likewise, but pass
call_stmt.
(class caller_context): New.
(region_model::pop_frame): Add "call_stmt" argument.  Use it
and the frame_region with a caller_context when setting
result_dst_reg's value so that any diagnostic is reported at the
call stmt in the caller.
(selftest::test_stack_frames): Pass nullptr as call_stmt arg to
region_model::pop_frame.
(selftest::test_alloca): Likewise.
* region-model.h (region_model::pop_frame): Add "call_stmt"
argument.

gcc/testsuite/ChangeLog:
PR analyzer/106203
* c-c++-common/analyzer/allocation-size-1.c (test_9): Remove
xfail.
* c-c++-common/analyzer/allocation-size-2.c (test_8): Likewise.
* gcc.dg/analyzer/allocation-size-multiline-4.c: New test.
* gcc.dg/plugin/analyzer_cpython_plugin.c
(refcnt_stmt_finder::update_event_loc_info): New.

Signed-off-by: David Malcolm 
---
 gcc/analyzer/checker-event.h  | 14 +---
 gcc/analyzer/diagnostic-manager.cc| 13 ++-
 gcc/analyzer/engine.cc|  7 +-
 gcc/analyzer/event-loc-info.h | 41 +
 gcc/analyzer/exploded-graph.h |  1 +
 gcc/analyzer/infinite-loop.cc |  2 +-
 gcc/analyzer/infinite-recursion.cc|  2 +-
 gcc/analyzer/pending-diagnostic.cc|  6 +-
 gcc/analyzer/pending-diagnostic.h |  2 +-
 gcc/analyzer/region-model.cc  | 84 +--
 gcc/analyzer/region-model.h   |  1 +
 .../c-c++-common/analyzer/allocation-size-1.c |  8 +-
 .../c-c++-common/analyzer/allocation-size-2.c |  8 +-
 .../analyzer/allocation-size-multiline-4.c| 64 ++
 .../gcc.dg/plugin/analyzer_cpython_plugin.c   |  5 ++
 15 files changed, 216 insertions(+), 42 deletions(-)
 create mode 100644 gcc/analyzer/event-loc-info.h
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/allocation-size-multiline-4.c

diff --git a/gcc/analyzer/checker-event.h b/gcc/analyzer/checker-event.h
index 7a4510ee81d0..d0935aca9853 100644
--- a/gcc/analyzer/checker-event.h
+++ b/gcc/analyzer/checker-event.h
@@ -23,22 +23,10 @@ along with GCC; see the file COPYING3.  If not see
 
 #include "tree-logical-location.h"
 #include "analyzer/program-state.h"
+#include "analyzer/event-loc-info.h"
 
 namespace ana {
 
-/* A bundle of location information for a checker_event.  */
-
-struct event_loc_info
-{
-  event_loc_info (location_t loc, tree fndecl, int depth)
-  : m_loc (loc), m_fndecl (fndecl), m_depth (depth)
-  {}
-
-  location_t m_loc;
-  tree m_fndecl;
-  int m_depth;
-};
-
 /* An enum for discriminating between the concrete subclasses of
checker_event.  */
 
diff --git a/gcc/analyzer/diagnostic-manager.cc 
b/gcc/analyzer/diagnostic-manager.cc
index da98b9679cbb..20e793d72c19 100644
--- a/gcc/analyzer/diagnostic-manager.cc
+++ b/gcc/analyzer/diagnostic-manager.cc
@@ -1588,8 +1588,17 @@ diagnostic_manager::emit_saved_diagnostic (const 
exploded_graph &eg,
  We use the final enode from the epath, which might be different from
  the sd.m_enode, as the dedupe code doesn't care about enodes, just
  snodes.  */
-  sd.m_d->add_final_event (sd.m_sm, epath->get_final_enode (), sd.m_stmt,
-  sd.m_var, sd

Re: [PATCH] libstdc++: Implement C++26 features (P2546R5)

2024-06-01 Thread Ulrich Drepper
Hey Jon,

I think we should give debuggers a chance to announce themselves by
providing an entry point they can call (in the inferior) which sets a
flag.  A set flag plus a tracer PID would then be a sufficient
indicator.  The remaining code should also stay but some additional
code can be added:

On Sat, Jun 1, 2024 at 12:22 PM Jonathan Wakely  wrote:
> +_GLIBCXX_WEAK_DEFINITION
> +bool
> +std::is_debugger_present() noexcept
> +{
> +#if _GLIBCXX_HOSTED
> +# if _GLIBCXX_USE_PROC_SELF_STATUS
> +  const string_view prefix = "TracerPid:\t";
> +  ifstream in("/proc/self/status");
> +  string line;
> +  while (std::getline(in, line))
> +{
> +  if (!line.starts_with(prefix))
> +   continue;
> +
> +  string_view tracer = line;
> +  tracer.remove_prefix(prefix.size());
> +  if (tracer.size() == 1 && tracer[0] == '0') [[likely]]
> +   return false; // Not being traced.
> +

Here add something like:

   if (debugger_announced)
 return true;


> +  in.close();
> +  string_view cmd;
> +  string proc_dir = "/proc/" + string(tracer) + '/';
> +  in.open(proc_dir + "comm"); // since Linux 2.6.33
> +  if (std::getline(in, line)) [[likely]]
> +   cmd = line;
> +  else
> +   {
> + in.close();
> + in.open(proc_dir + "cmdline");
> + if (std::getline(in, line))
> +   cmd = line.c_str(); // Only up to first '\0'
> + else
> +   return false;
> +   }
> +
> +  for (auto i : {"gdb", "lldb"}) // known debuggers
> +   if (cmd.ends_with(i))
> + return true;
> +
> +  // We found the TracerPid line, no need to do any more work.
> +  return false;
> +}
> +# endif

And then add

namespace {
  bool debugger_announced = false;
}
auto debugger_attached()
{
  debugger_announced = true;
  return std::breakpoint;
}

I suggest to also return the breakpoint function to allow debuggers to
do something clever with it (e.g., set a breakpoint on the entry
instead of having to catch the fallout of the instruction that is
issued in the function (there might be a difference).


With the function any debugger not covered by the existing test can
make itself known.


[pushed] wwwdocs: gcc-*/buildstat: Drop references to "Final Installation" docs

2024-06-01 Thread Gerald Pfeifer
Instructions for reporting a successful build are not actually part
of the "Final Installation" docs (any more) and we have not been
adding new build results for several years.
---
 htdocs/gcc-3.0/buildstat.html | 6 +-
 htdocs/gcc-3.1/buildstat.html | 6 +-
 htdocs/gcc-3.2/buildstat.html | 6 +-
 htdocs/gcc-3.3/buildstat.html | 6 +-
 htdocs/gcc-3.4/buildstat.html | 6 +-
 htdocs/gcc-4.0/buildstat.html | 6 +-
 htdocs/gcc-4.1/buildstat.html | 6 +-
 htdocs/gcc-4.2/buildstat.html | 6 +-
 htdocs/gcc-4.3/buildstat.html | 6 +-
 htdocs/gcc-4.4/buildstat.html | 6 +-
 htdocs/gcc-4.5/buildstat.html | 6 +-
 htdocs/gcc-4.6/buildstat.html | 6 +-
 htdocs/gcc-4.7/buildstat.html | 6 +-
 htdocs/gcc-4.8/buildstat.html | 6 +-
 htdocs/gcc-4.9/buildstat.html | 6 +-
 htdocs/gcc-5/buildstat.html   | 6 +-
 htdocs/gcc-6/buildstat.html   | 6 +-
 htdocs/gcc-7/buildstat.html   | 6 +-
 htdocs/gcc-8/buildstat.html   | 6 +-
 19 files changed, 19 insertions(+), 95 deletions(-)

diff --git a/htdocs/gcc-3.0/buildstat.html b/htdocs/gcc-3.0/buildstat.html
index e751f9a8..442e275a 100644
--- a/htdocs/gcc-3.0/buildstat.html
+++ b/htdocs/gcc-3.0/buildstat.html
@@ -17,11 +17,7 @@ summaries.
 Instructions for running the testsuite and for submitting test results
 are part of
 https://gcc.gnu.org/install/test.html";>
-Installing GCC: Testing.
-Instructions for reporting a successful build, including a list of
-information to include in such a report, are part of
-https://gcc.gnu.org/install/finalinstall.html";>
-Installing GCC: Final Installation.
+Installing GCC: Testing.
 
 
 
diff --git a/htdocs/gcc-3.1/buildstat.html b/htdocs/gcc-3.1/buildstat.html
index 348ab001..f58a6d28 100644
--- a/htdocs/gcc-3.1/buildstat.html
+++ b/htdocs/gcc-3.1/buildstat.html
@@ -17,11 +17,7 @@ summaries.
 Instructions for running the testsuite and for submitting test results
 are part of
 https://gcc.gnu.org/install/test.html";>
-Installing GCC: Testing.
-Instructions for reporting a successful "make bootstrap",
-including a list of information to include in such a report, are part of
-https://gcc.gnu.org/install/finalinstall.html";>
-Installing GCC: Final Installation.
+Installing GCC: Testing.
 
 
 
diff --git a/htdocs/gcc-3.2/buildstat.html b/htdocs/gcc-3.2/buildstat.html
index 31ae26bb..1f6454de 100644
--- a/htdocs/gcc-3.2/buildstat.html
+++ b/htdocs/gcc-3.2/buildstat.html
@@ -17,11 +17,7 @@ summaries.
 Instructions for running the testsuite and for submitting test results
 are part of
 https://gcc.gnu.org/install/test.html";>
-Installing GCC: Testing.
-Instructions for reporting a successful "make bootstrap",
-including a list of information to include in such a report, are part of
-https://gcc.gnu.org/install/finalinstall.html";>
-Installing GCC: Final Installation.
+Installing GCC: Testing.
 
 
 
diff --git a/htdocs/gcc-3.3/buildstat.html b/htdocs/gcc-3.3/buildstat.html
index c2d6c345..093ad9ab 100644
--- a/htdocs/gcc-3.3/buildstat.html
+++ b/htdocs/gcc-3.3/buildstat.html
@@ -17,11 +17,7 @@ summaries.
 Instructions for running the testsuite and for submitting test results
 are part of
 https://gcc.gnu.org/install/test.html";>
-Installing GCC: Testing.
-Instructions for reporting a successful "make bootstrap",
-including a list of information to include in such a report, are part of
-https://gcc.gnu.org/install/finalinstall.html";>
-Installing GCC: Final Installation.
+Installing GCC: Testing.
 
 
 
diff --git a/htdocs/gcc-3.4/buildstat.html b/htdocs/gcc-3.4/buildstat.html
index 02b491ed..1d00b2e4 100644
--- a/htdocs/gcc-3.4/buildstat.html
+++ b/htdocs/gcc-3.4/buildstat.html
@@ -17,11 +17,7 @@ summaries.
 Instructions for running the testsuite and for submitting test results
 are part of
 https://gcc.gnu.org/install/test.html";>
-Installing GCC: Testing.
-Instructions for reporting a successful "make bootstrap",
-including a list of information to include in such a report, are part of
-https://gcc.gnu.org/install/finalinstall.html";>
-Installing GCC: Final Installation.
+Installing GCC: Testing.
 
 
 
diff --git a/htdocs/gcc-4.0/buildstat.html b/htdocs/gcc-4.0/buildstat.html
index 23184f2d..cefb9951 100644
--- a/htdocs/gcc-4.0/buildstat.html
+++ b/htdocs/gcc-4.0/buildstat.html
@@ -17,11 +17,7 @@ summaries.
 Instructions for running the testsuite and for submitting test results
 are part of
 https://gcc.gnu.org/install/test.html";>
-Installing GCC: Testing.
-Instructions for reporting a successful "make bootstrap",
-including a list of information to include in such a report, are part of
-https://gcc.gnu.org/install/finalinstall.html";>
-Installing GCC: Final Installation.
+Installing GCC: Testing.
 
 
 
diff --git a/htdocs/gcc-4.1/buildstat.html b/htdocs/gcc-4.1/buildstat.html
index f319c7f2..f21c9b04 100644
--- a/htdocs/gcc-4.1/buildstat.html
+++ b/htdocs/gcc-4.1/buildstat.html
@@ -17,11 +17,7 @@ summaries.
 Instructions for running the testsuite and for submitting test results
 are part of

Re: [Patch, rs6000, aarch64, middle-end] Add implementation for different targets for pair mem fusion

2024-06-01 Thread Ajit Agarwal
Hello Richard:

On 31/05/24 10:29 pm, Ajit Agarwal wrote:
> Hello Richard:
> 
> On 31/05/24 8:08 pm, Richard Sandiford wrote:
>> Ajit Agarwal  writes:
>>> On 31/05/24 3:23 pm, Richard Sandiford wrote:
 Ajit Agarwal  writes:
> Hello All:
>
> Common infrastructure using generic code for pair mem fusion of different
> targets.
>
> rs6000 target specific specific code implements virtual functions defined
> by generic code.
>
> Code is implemented with pure virtual functions to interface with target
> code.
>
> Target specific code are added in rs6000-mem-fusion.cc and additional 
> virtual
> function implementation required for rs6000 are added in 
> aarch64-ldp-fusion.cc.
>
> Bootstrapped and regtested for aarch64-linux-gnu and powerpc64-linux-gnu.
>
> Thanks & Regards
> Ajit
>
>
> aarch64, rs6000, middle-end: Add implementation for different targets for 
> pair mem fusion
>
> Common infrastructure using generic code for pair mem fusion of different
> targets.
>
> rs6000 target specific specific code implements virtual functions defined
> by generic code.
>
> Code is implemented with pure virtual functions to interface with target
> code.
>
> Target specific code are added in rs6000-mem-fusion.cc and additional 
> virtual
> function implementation required for rs6000 are added in 
> aarch64-ldp-fusion.cc.
>
> 2024-05-31  Ajit Kumar Agarwal  
>
> gcc/ChangeLog:
>
>   * config/aarch64/aarch64-ldp-fusion.cc: Add target specific
>   implementation of additional virtual functions added in pair_fusion
>   struct.
>   * config/rs6000/rs6000-passes.def: New mem fusion pass
>   before pass_early_remat.
>   * config/rs6000/rs6000-mem-fusion.cc: Add new pass.
>   Add target specific implementation using pure virtual
>   functions.
>   * config.gcc: Add new object file.
>   * config/rs6000/rs6000-protos.h: Add new prototype for mem
>   fusion pass.
>   * config/rs6000/t-rs6000: Add new rule.
>   * rtl-ssa/accesses.h: Moved set_is_live_out_use as public
>   from private.
>
> gcc/testsuite/ChangeLog:
>
>   * g++.target/powerpc/me-fusion.C: New test.
>   * g++.target/powerpc/mem-fusion-1.C: New test.
>   * gcc.target/powerpc/mma-builtin-1.c: Modify test.
> ---

 This isn't a complete review, just some initial questions & comments
 about selected parts.

> [...]
> +/* Check whether load can be fusable or not.
> +   Return true if dependent use is UNSPEC otherwise false.  */
> +bool
> +rs6000_pair_fusion::fuseable_load_p (insn_info *info)
> +{
> +  rtx_insn *insn = info->rtl ();
> +
> +  for (rtx note = REG_NOTES (insn); note; note = XEXP (note, 1))
> +if (REG_NOTE_KIND (note) == REG_EQUAL
> + || REG_NOTE_KIND (note) == REG_EQUIV)
> +  return false;

 It's unusual to punt on an optimisation because of a REG_EQUAL/EQUIV
 note.  What's the reason for doing this?  Are you trying to avoid
 fusing pairs before reload that are equivalent to a MEM (i.e. have
 a natural spill slot)?  I think Alex hit a similar situation.

>>>
>>> We have used the above check because of some SPEC benchmarks failing with
>>> with MEM pairs having REG_EQUAL/EQUIV notes.
>>>
>>> By adding the checks the benchmarks passes and also it improves the
>>> performance.
>>>
>>> This checks were added during initial implementation of pair fusion
>>> pass.
>>>
>>> I will investigate further if this check is still required or not.
>>
>> Thanks.  If it does affect SPEC results, it would be good to look
>> at the underlying reason, as a justification for the check.
>>
>> AIUI, the case Alex was due to the way that the RA recognises:
>>
>>   (set (reg R) (mem address-of-a-stack-vare ciable))
>> REG_EQUIV: (mem address-of-a-stack-variable)
>>
>> where the REG_EQUIV is either explicit or detected by the RA.
>> If R needs to be spilled, it can then be spilled to its existing
>> location on the stack.  And if R needs to be spilled in the
>> instruction above (because of register pressure before the first
>> use of R), the RA is able to delete the instruction.
>>
>> But if that is the reason, the condition should be restricted
>> to cases in which the note is a memory.
>>
>> I think Alex had tried something similar and found that it wasn't
>> always effective.
>>
> 
> Sure I will check.

Spec looks good without the above check of REG_EQUIV/REG_EQUAL.
I dont see the above condition in Spec benchmarks any more for 
MEM pairs.
Hence I will remove the above check from the patch and send
new patch without the above check.

Thanks & Regards
Ajit
>>> [...]
> +&& info->is_real ())
> +   {
> + rtx_insn *rtl_insn = info->rtl ();
> + rtx set = single_set (rtl_insn);
>

Re: [PATCH] ifcvt: Clarify if_info.original_cost.

2024-06-01 Thread Stefan Schulze Frielinghaus
On Fri, May 31, 2024 at 10:05:55PM -0600, Jeff Law wrote:
> 
> 
> On 5/31/24 9:03 AM, Robin Dapp wrote:
> > Hi,
> > 
> > before noce_find_if_block processes a block it sets up an if_info
> > structure that holds the original costs.  At that point the costs of
> > the then/else blocks have not been added so we only care about the
> > "if" cost.
> > 
> > The code originally used BRANCH_COST for that but was then changed
> > to COST_N_INSNS (2) - a compare and a jump.
> > This patch computes the jump costs via
> >insn_cost (if_info.jump, ...)
> > which is supposed to incorporate the branch costs and, in case of a CC
> > comparison,
> >pattern_cost (if_info.cond, ...)
> > which is supposed to account for the CC creation.
> > 
> > For compare_and_jump patterns insn_cost should have already computed
> > the right cost.
> > 
> > Does this "split" make sense, generally?
> > 
> > Bootstrapped and regtested on x86, aarch64 and power10.  Regtested
> > on riscv.
> > 
> > Regards
> >   Robin
> > 
> > gcc/ChangeLog:
> > 
> > * ifcvt.cc (noce_process_if_block): Subtract condition pattern
> > cost if applicable.
> > (noce_find_if_block): Use insn_cost and pattern_cost for
> > original cost.
> OK.  Obviously we'll need to be on the lookout for regressions.  My bet is
> on s390 since you already tested the x86, aarch64 & p10 targets :-)

I just gave it a try on s390 where bootstrap and regtest were successful.

Cheers,
Stefan

> 
> 
> jeff
>