[gcc r15-4167] ssa-math-opts, i386: Handle most unordered values rather than just 2 [PR116896]

2024-10-08 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:ff889b35935d5e796cf308fb2368d4e319c60ece

commit r15-4167-gff889b35935d5e796cf308fb2368d4e319c60ece
Author: Jakub Jelinek 
Date:   Tue Oct 8 10:40:29 2024 +0200

ssa-math-opts, i386: Handle most unordered values rather than just 2 
[PR116896]

On Mon, Oct 07, 2024 at 10:32:57AM +0200, Richard Biener wrote:
> > They are implementation defined, -1, 0, 1, 2 is defined by libstdc++:
> > using type = signed char;
> > enum class _Ord : type { equivalent = 0, less = -1, greater = 1 };
> > enum class _Ncmp : type { _Unordered = 2 };
> > https://eel.is/c++draft/cmp#categories.pre-1 documents them as
> > enum class ord { equal = 0, equivalent = equal, less = -1, greater = 1 
}; // exposition only
> > enum class ncmp { unordered = -127 };   
  // exposition only
> > and now looking at it, LLVM's libc++ takes that literally and uses
> > -1, 0, 1, -127.  One can't use <=> operator without including 
> > which provides the enums, so I think if all we care about is libstdc++,
> > then just hardcoding -1, 0, 1, 2 is fine, if we want to also optimize
> > libc++ when used with gcc, we could support -1, 0, 1, -127 as another
> > option.
> > Supporting arbitrary 4 values doesn't make sense, at least on x86 the
> > only reason to do the conversion to int in an optab is a good sequence
> > to turn the flag comparisons to -1, 0, 1.  So, either we do nothing
> > more than the patch, or add handle both 2 and -127 for unordered,
> > or add support for arbitrary value for the unordered case except
> > -1, 0, 1 (then -1 could mean signed int, 1 unsigned int, 0 do the jumps
> > and any other value what should be returned for unordered.

Here is an incremental patch which adds support for (almost) arbitrary
unordered constant value.  It changes the .SPACESHIP and spaceship4
optab conventions, so 0 means use branches, floating point, -1, 0, 1, 2
results consumed by tree-ssa-math-opts.cc emitted comparisons, -1
means signed int comparisons, -1, 0, 1 results, 1 means unsigned int
comparisons, -1, 0, 1 results, and for constant other than -1, 0, 1
which fit into [-128, 127] converted to the PHI type are otherwise
specified as the last argument (then it is -1, 0, 1, C results).

2024-10-08  Jakub Jelinek  

PR middle-end/116896
* tree-ssa-math-opts.cc (optimize_spaceship): Handle unordered 
values
other than 2, but they still need to be signed char range possibly
converted to the PHI result and can't be in [-1, 1] range.  Use
last .SPACESHIP argument of 1 for unsigned int comparisons, -1 for
signed int, 0 for floating point branches and any other for floating
point with that value as unordered.
* config/i386/i386-expand.cc (ix86_expand_fp_spaceship): Use op2 
rather
const2_rtx if op2 is not const0_rtx for unordered result.
(ix86_expand_int_spaceship): Change INTVAL (op2) == 1 tests to
INTVAL (op2) != -1.
* doc/md.texi (spaceship@var{m}4): Document the above changes.

* gcc.target/i386/pr116896.c: New test.

Diff:
---
 gcc/config/i386/i386-expand.cc   |  8 ++---
 gcc/doc/md.texi  |  7 ++--
 gcc/testsuite/gcc.target/i386/pr116896.c | 59 
 gcc/tree-ssa-math-opts.cc| 42 +--
 4 files changed, 100 insertions(+), 16 deletions(-)

diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index 81dd50649007..32840113cf60 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -3234,7 +3234,7 @@ ix86_expand_fp_spaceship (rtx dest, rtx op0, rtx op1, rtx 
op2)
   if (l2)
 {
   emit_label (l2);
-  emit_move_insn (dest, const2_rtx);
+  emit_move_insn (dest, op2 == const0_rtx ? const2_rtx : op2);
 }
   emit_label (lend);
 }
@@ -3250,11 +3250,11 @@ ix86_expand_int_spaceship (rtx dest, rtx op0, rtx op1, 
rtx op2)
  operands nor optimize CC mode - we need a mode usable for both
  LT and GT resp. LTU and GTU comparisons with the same unswapped
  operands.  */
-  rtx flags = gen_rtx_REG (INTVAL (op2) == 1 ? CCGCmode : CCmode, FLAGS_REG);
+  rtx flags = gen_rtx_REG (INTVAL (op2) != 1 ? CCGCmode : CCmode, FLAGS_REG);
   rtx tmp = gen_rtx_COMPARE (GET_MODE (flags), op0, op1);
   emit_insn (gen_rtx_SET (flags, tmp));
   rtx lt_tmp = gen_reg_rtx (QImode);
-  ix86_expand_setcc (lt_tmp, INTVAL (op2) == 1 ? LT : LTU, flags,
+  ix86_expand_setcc (lt_tmp, INTVAL (op2) != 1 ? LT : LTU, flags,
 const0_rtx);
   if (GET_MODE (dest) != QImode)
 {
@@ -3264,7 +3264,7 @@ ix86_expand_int_spaceship (rtx dest, rtx op0, rtx op1, 
rtx op2)
   lt_tmp = tmp;
 }
   rtx gt_tmp = gen_reg_rtx (QImode);
-  ix86_expand_setcc

[gcc r15-4125] libcpp: Use constexpr for _cpp_trigraph_map initialization for C++14

2024-10-07 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:e4c0595ec4ed3cd2f6fb471081a9d2d3960e1672

commit r15-4125-ge4c0595ec4ed3cd2f6fb471081a9d2d3960e1672
Author: Jakub Jelinek 
Date:   Mon Oct 7 21:25:22 2024 +0200

libcpp: Use constexpr for _cpp_trigraph_map initialization for C++14

The _cpp_trigraph_map initialization used to be done for C99+ using
designated initializers, but can't be done that way for C++ because
the designated initializer support in C++ as array designators are just
an extension there and don't allow skipping anything nor going backwards.

But, we can get the same effect using C++14 constexpr constructor.
With the following patch we get rid of the runtime initialization
and the array can be in .rodata.

2024-10-07  Jakub Jelinek  

* internal.h (_cpp_trigraph_map_s): New type for C++14 or later.
(_cpp_trigraph_map_d): New variable for C++14 or later.
(_cpp_trigraph_map): Define to _cpp_trigraph_map_d.map for C++14 or
later.
* init.cc (init_trigraph_map): Define to nothing for C++14 or later.
(TRIGRAPH_MAP, END, s): Define differently for C++14 or later.

Diff:
---
 libcpp/init.cc| 13 +++--
 libcpp/internal.h |  6 ++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/libcpp/init.cc b/libcpp/init.cc
index 2c80d63a491d..3e4a2bc0ae79 100644
--- a/libcpp/init.cc
+++ b/libcpp/init.cc
@@ -41,8 +41,8 @@ static void read_original_directory (cpp_reader *);
 static void post_options (cpp_reader *);
 
 /* If we have designated initializers (GCC >2.7) these tables can be
-   initialized, constant data.  Otherwise, they have to be filled in at
-   runtime.  */
+   initialized, constant data.  Similarly for C++14 and later.
+   Otherwise, they have to be filled in at runtime.  */
 #if HAVE_DESIGNATED_INITIALIZERS
 
 #define init_trigraph_map()  /* Nothing.  */
@@ -52,6 +52,15 @@ __extension__ const uchar _cpp_trigraph_map[UCHAR_MAX + 1] = 
{
 #define END };
 #define s(p, v) [p] = v,
 
+#elif __cpp_constexpr >= 201304L
+
+#define init_trigraph_map()  /* Nothing.  */
+#define TRIGRAPH_MAP \
+constexpr _cpp_trigraph_map_s::_cpp_trigraph_map_s () : map {} {
+#define END } \
+constexpr _cpp_trigraph_map_s _cpp_trigraph_map_d;
+#define s(p, v) map[p] = v;
+
 #else
 
 #define TRIGRAPH_MAP uchar _cpp_trigraph_map[UCHAR_MAX + 1] = { 0 }; \
diff --git a/libcpp/internal.h b/libcpp/internal.h
index b69a0377f024..2379fbba8996 100644
--- a/libcpp/internal.h
+++ b/libcpp/internal.h
@@ -668,6 +668,12 @@ struct cpp_embed_params
compiler that supports C99.  */
 #if HAVE_DESIGNATED_INITIALIZERS
 extern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
+#elif __cpp_constexpr >= 201304L
+extern const struct _cpp_trigraph_map_s {
+  unsigned char map[UCHAR_MAX + 1];
+  constexpr _cpp_trigraph_map_s ();
+} _cpp_trigraph_map_d;
+#define _cpp_trigraph_map _cpp_trigraph_map_d.map
 #else
 extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
 #endif


[gcc r15-4117] gcc: Remove executable permissions of testcases and *.md files

2024-10-07 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:0d64f9b2390b4799649269474e6d9ab9b1e3870e

commit r15-4117-g0d64f9b2390b4799649269474e6d9ab9b1e3870e
Author: Jakub Jelinek 
Date:   Mon Oct 7 14:30:21 2024 +0200

gcc: Remove executable permissions of testcases and *.md files

I've noticed some files were marked as executable, as can be
seen with
find . \( -name \*.[chSC] -o -name \*.md -o -name \*.cc \) -a -perm /111 | 
xargs ls -l

This commit fixes that.

2024-10-07  Jakub Jelinek  

gcc/
* config/riscv/vector-crypto.md: Remove executable permissions.
gcc/testsuite/
* gcc.target/aarch64/uxtl-combine-1.c: Remove executable 
permissions.
* gcc.target/aarch64/uxtl-combine-2.c: Likewise.
* gcc.target/aarch64/uxtl-combine-3.c: Likewise.
* gcc.target/aarch64/uxtl-combine-4.c: Likewise.
* gcc.target/aarch64/uxtl-combine-5.c: Likewise.
* gcc.target/aarch64/uxtl-combine-6.c: Likewise.
* gcc.target/gcn/complex.c: Likewise.
* gcc.target/i386/avx2-bf16-vec-absneg.c: Likewise.
* gcc.target/i386/avx512f-bf16-vec-absneg.c: Likewise.
* gcc.target/i386/pr104371-2.c: Likewise.
* gcc.target/i386/pr115146.c: Likewise.
* gcc.target/i386/vpermt2-special-bf16-shufflue.c: Likewise.
* g++.target/i386/pr107563-a.C: Likewise.
* g++.target/i386/pr107563-b.C: Likewise.

Diff:
---
 gcc/config/riscv/vector-crypto.md | 0
 gcc/testsuite/g++.target/i386/pr107563-a.C| 0
 gcc/testsuite/g++.target/i386/pr107563-b.C| 0
 gcc/testsuite/gcc.target/aarch64/uxtl-combine-1.c | 0
 gcc/testsuite/gcc.target/aarch64/uxtl-combine-2.c | 0
 gcc/testsuite/gcc.target/aarch64/uxtl-combine-3.c | 0
 gcc/testsuite/gcc.target/aarch64/uxtl-combine-4.c | 0
 gcc/testsuite/gcc.target/aarch64/uxtl-combine-5.c | 0
 gcc/testsuite/gcc.target/aarch64/uxtl-combine-6.c | 0
 gcc/testsuite/gcc.target/gcn/complex.c| 0
 gcc/testsuite/gcc.target/i386/avx2-bf16-vec-absneg.c  | 0
 gcc/testsuite/gcc.target/i386/avx512f-bf16-vec-absneg.c   | 0
 gcc/testsuite/gcc.target/i386/pr104371-2.c| 0
 gcc/testsuite/gcc.target/i386/pr115146.c  | 0
 gcc/testsuite/gcc.target/i386/vpermt2-special-bf16-shufflue.c | 0
 15 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/gcc/config/riscv/vector-crypto.md 
b/gcc/config/riscv/vector-crypto.md
old mode 100755
new mode 100644
diff --git a/gcc/testsuite/g++.target/i386/pr107563-a.C 
b/gcc/testsuite/g++.target/i386/pr107563-a.C
old mode 100755
new mode 100644
diff --git a/gcc/testsuite/g++.target/i386/pr107563-b.C 
b/gcc/testsuite/g++.target/i386/pr107563-b.C
old mode 100755
new mode 100644
diff --git a/gcc/testsuite/gcc.target/aarch64/uxtl-combine-1.c 
b/gcc/testsuite/gcc.target/aarch64/uxtl-combine-1.c
old mode 100755
new mode 100644
diff --git a/gcc/testsuite/gcc.target/aarch64/uxtl-combine-2.c 
b/gcc/testsuite/gcc.target/aarch64/uxtl-combine-2.c
old mode 100755
new mode 100644
diff --git a/gcc/testsuite/gcc.target/aarch64/uxtl-combine-3.c 
b/gcc/testsuite/gcc.target/aarch64/uxtl-combine-3.c
old mode 100755
new mode 100644
diff --git a/gcc/testsuite/gcc.target/aarch64/uxtl-combine-4.c 
b/gcc/testsuite/gcc.target/aarch64/uxtl-combine-4.c
old mode 100755
new mode 100644
diff --git a/gcc/testsuite/gcc.target/aarch64/uxtl-combine-5.c 
b/gcc/testsuite/gcc.target/aarch64/uxtl-combine-5.c
old mode 100755
new mode 100644
diff --git a/gcc/testsuite/gcc.target/aarch64/uxtl-combine-6.c 
b/gcc/testsuite/gcc.target/aarch64/uxtl-combine-6.c
old mode 100755
new mode 100644
diff --git a/gcc/testsuite/gcc.target/gcn/complex.c 
b/gcc/testsuite/gcc.target/gcn/complex.c
old mode 100755
new mode 100644
diff --git a/gcc/testsuite/gcc.target/i386/avx2-bf16-vec-absneg.c 
b/gcc/testsuite/gcc.target/i386/avx2-bf16-vec-absneg.c
old mode 100755
new mode 100644
diff --git a/gcc/testsuite/gcc.target/i386/avx512f-bf16-vec-absneg.c 
b/gcc/testsuite/gcc.target/i386/avx512f-bf16-vec-absneg.c
old mode 100755
new mode 100644
diff --git a/gcc/testsuite/gcc.target/i386/pr104371-2.c 
b/gcc/testsuite/gcc.target/i386/pr104371-2.c
old mode 100755
new mode 100644
diff --git a/gcc/testsuite/gcc.target/i386/pr115146.c 
b/gcc/testsuite/gcc.target/i386/pr115146.c
old mode 100755
new mode 100644
diff --git a/gcc/testsuite/gcc.target/i386/vpermt2-special-bf16-shufflue.c 
b/gcc/testsuite/gcc.target/i386/vpermt2-special-bf16-shufflue.c
old mode 100755
new mode 100644


[gcc r15-4105] ssa-math-opts, i386: Improve spaceship expansion [PR116896]

2024-10-07 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:37554bacfd38b1466278b529d9e70a44d7b1b909

commit r15-4105-g37554bacfd38b1466278b529d9e70a44d7b1b909
Author: Jakub Jelinek 
Date:   Mon Oct 7 10:50:39 2024 +0200

ssa-math-opts, i386: Improve spaceship expansion [PR116896]

The PR notes that we don't emit optimal code for C++ spaceship
operator if the result is returned as an integer rather than the
result just being compared against different values and different
code executed based on that.
So e.g. for
template 
auto foo (T x, T y) { return x <=> y; }
for both floating point types, signed integer types and unsigned integer
types.  auto in that case is std::strong_ordering or std::partial_ordering,
which are fancy C++ abstractions around struct with signed char member
which is -1, 0, 1 for the strong ordering and -1, 0, 1, 2 for the partial
ordering (but for -ffast-math 2 is never the case).
I'm afraid functions like that are fairly common and unless they are
inlined, we really need to map the comparison to those -1, 0, 1 or
-1, 0, 1, 2 values.

Now, for floating point spaceship I've in the past already added an
optimization (with tree-ssa-math-opts.cc discovery and named optab, the
optab only defined on x86 though right now), which ensures there is just
a single comparison instruction and then just tests based on flags.
Now, if we have code like:
  auto a = x <=> y;
  if (a == std::partial_ordering::less)
bar ();
  else if (a == std::partial_ordering::greater)
baz ();
  else if (a == std::partial_ordering::equivalent)
qux ();
  else if (a == std::partial_ordering::unordered)
corge ();
etc., that results in decent code generation, the spaceship named pattern
on x86 optimizes for the jumps, so emits comparisons on the flags, followed
by setting the result to -1, 0, 1, 2 and subsequent jump pass optimizes that
well.  But if the result needs to be stored into an integer and just
returned that way or there are no immediate jumps based on it (or turned
into some non-standard integer values like -42, 0, 36, 75 etc.), then CE
doesn't do a good job for that, we end up with say
comiss  %xmm1, %xmm0
jp  .L4
seta%al
movl$0, %edx
leal-1(%rax,%rax), %eax
cmove   %edx, %eax
ret
.L4:
movl$2, %eax
ret
The jp is good, that is the unlikely case and can't be easily handled in
straight line code due to the layout of the flags, but the rest uses cmov
which often isn't a win and a weird math.
With the patch below we can get instead
xorl%eax, %eax
comiss  %xmm1, %xmm0
jp  .L2
seta%al
sbbl$0, %eax
ret
.L2:
movl$2, %eax
ret

The patch changes the discovery in the generic code, by detecting if
the future .SPACESHIP result is just used in a PHI with -1, 0, 1 or
-1, 0, 1, 2 values (the latter for HONOR_NANS) and passes that as a flag in
a new argument to .SPACESHIP ifn, so that the named pattern is told whether
it should optimize for branches or for loading the result into a -1, 0, 1
(, 2) integer.  Additionally, it doesn't detect just floating point <=>
anymore, but also integer and unsigned integer, but in those cases only
if an integer -1, 0, 1 is wanted (otherwise == and > or similar comparisons
result in good code).
The backend then can for those integer or unsigned integer <=>s return
effectively (x > y) - (x < y) in a way that is efficient on the target
(so for x86 with ensuring zero initialization first when needed before
setcc; one for floating point and unsigned, where there is just one setcc
and the second one optimized into sbb instruction, two for the signed int
case).  So e.g. for signed int we now emit
xorl%edx, %edx
xorl%eax, %eax
cmpl%esi, %edi
setl%dl
setg%al
subl%edx, %eax
ret
and for unsigned
xorl%eax, %eax
cmpl%esi, %edi
seta%al
sbbb$0, %al
ret

Note, I wonder if other targets wouldn't benefit from defining the
named optab too...

2024-10-07  Jakub Jelinek  

PR middle-end/116896
* optabs.def (spaceship_optab): Use spaceship$a4 rather than
spaceship$a3.
* internal-fn.cc (expand_SPACESHIP): Expect 3 call arguments
rather than 2, expand the last one, expect 4 operands of
spaceship_optab.
* tree-ssa-math-opts.cc: Include cfghooks.h.
(optimize_spaceship): Check if a single PHI is initialized to
-1, 0, 1, 2 or -1, 0, 1 values, in that cas

[gcc r15-4069] testsuite: Fix up unevalstr2.C test

2024-10-04 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:c679cafb0d7e58fd699f9f73e736417765f349bc

commit r15-4069-gc679cafb0d7e58fd699f9f73e736417765f349bc
Author: Jakub Jelinek 
Date:   Fri Oct 4 15:24:24 2024 +0200

testsuite: Fix up unevalstr2.C test

The CWG2521 changes adjusted the unevalstr1.C test but didn't adjust
unevalstr2.C test, which now FAILs in C++23 mode.

The intent in both of those tests was to test the separate (now deprecated)
syntax, so instead of removing the space between closing " and _ I've
adjusted the testcase to expect those 17 extra warnings.  And I've also
adjusted the unevalstr1.C testcase to do the same, when it is removed from
C++29 or whatever, that can be just guarded by #if.

But it is actually useful to also test the UDL variant without space between
closing " and _, so I've added new test coverage for that too to both tests.

2024-10-04  Jakub Jelinek  

* g++.dg/cpp26/unevalstr1.C: Revert the 2024-10-03 changes, instead
expect extra warnings.  Add another set of tests without space
between " and _.
* g++.dg/cpp26/unevalstr2.C: Expect extra warnings for C++23.  Add
another set of tests without space between " and _.

Diff:
---
 gcc/testsuite/g++.dg/cpp26/unevalstr1.C | 70 +
 gcc/testsuite/g++.dg/cpp26/unevalstr2.C | 42 ++--
 2 files changed, 92 insertions(+), 20 deletions(-)

diff --git a/gcc/testsuite/g++.dg/cpp26/unevalstr1.C 
b/gcc/testsuite/g++.dg/cpp26/unevalstr1.C
index 5317d696de8e..478c5ee330da 100644
--- a/gcc/testsuite/g++.dg/cpp26/unevalstr1.C
+++ b/gcc/testsuite/g++.dg/cpp26/unevalstr1.C
@@ -83,21 +83,57 @@ extern "\o{0103}" { int f14 (); }   // { dg-error "numeric 
escape sequence in unev
 [[nodiscard ("\x{20}")]] int h19 ();   // { dg-error "numeric escape sequence 
in unevaluated string" }
 [[nodiscard ("\h")]] int h20 ();   // { dg-error "unknown escape sequence" 
}
 
-float operator ""_my0 (const char *);
-float operator "" ""_my1 (const char *);
-float operator L""_my2 (const char *); // { dg-error "invalid encoding prefix 
in literal operator" }
-float operator u""_my3 (const char *); // { dg-error "invalid encoding prefix 
in literal operator" }
-float operator U""_my4 (const char *); // { dg-error "invalid encoding prefix 
in literal operator" }
-float operator u8""_my5 (const char *);// { dg-error "invalid encoding 
prefix in literal operator" }
-float operator L"" ""_my6 (const char *);  // { dg-error "invalid encoding 
prefix in literal operator" }
-float operator u"" ""_my7 (const char *);  // { dg-error "invalid encoding 
prefix in literal operator" }
-float operator U"" ""_my8 (const char *);  // { dg-error "invalid encoding 
prefix in literal operator" }
-float operator u8"" ""_my9 (const char *); // { dg-error "invalid encoding 
prefix in literal operator" }
-float operator "" L""_my10 (const char *); // { dg-error "invalid encoding 
prefix in literal operator" }
-float operator "" u""_my11 (const char *); // { dg-error "invalid encoding 
prefix in literal operator" }
-float operator "" U""_my12 (const char *); // { dg-error "invalid encoding 
prefix in literal operator" }
-float operator "" u8""_my13 (const char *);// { dg-error "invalid encoding 
prefix in literal operator" }
-float operator "\0"_my14 (const char *);   // { dg-error "expected empty 
string after 'operator' keyword" }
-float operator "\x00"_my15 (const char *); // { dg-error "expected empty 
string after 'operator' keyword" }
-float operator "\h"_my16 (const char *);   // { dg-error "expected empty 
string after 'operator' keyword" }
+float operator "" _my0 (const char *);
+float operator "" "" _my1 (const char *);
+float operator L"" _my2 (const char *);// { dg-error "invalid 
encoding prefix in literal operator" }
+float operator u"" _my3 (const char *);// { dg-error "invalid 
encoding prefix in literal operator" }
+float operator U"" _my4 (const char *);// { dg-error "invalid 
encoding prefix in literal operator" }
+float operator u8"" _my5 (const char *);   // { dg-error "invalid encoding 
prefix in literal operator" }
+float operator L"" "" _my6 (const char *); // { dg-error "invalid encoding 
prefix in literal operator" }
+float operator u"" "" _my7 (const char *); // { dg-error "invalid encoding 
prefix in literal operator" }
+float operator U"" "" _my8 (const char *); // { dg-error "invalid encoding 
prefix in literal operator" }
+float operator u8"" "" _my9 (const char *);// { dg-error "invalid encoding 
prefix in literal operator" }
+float operator "" L"" _my10 (const char *);// { dg-error "invalid encoding 
prefix in literal operator" }
+float operator "" u"" _my11 (const char *);// { dg-error "invalid encoding 
prefix in literal operator" }
+float operator "" U"" _my12 (const char *);// { dg-

[gcc r15-4064] diagnostic, pch: Fix up the new diagnostic PCH methods for ubsan checking [PR116936]

2024-10-04 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:f82055f8247478d9e2c00f2a442248e42188b8d1

commit r15-4064-gf82055f8247478d9e2c00f2a442248e42188b8d1
Author: Jakub Jelinek 
Date:   Fri Oct 4 14:02:13 2024 +0200

diagnostic, pch: Fix up the new diagnostic PCH methods for ubsan checking 
[PR116936]

The PR notes that the new pch_save/pch_restore methods I've added
recently invoke UB if either m_classification_history.address ()
or m_push_list.address () is NULL (which can happen if those vectors
are empty (and in the pch_save case nothing has been pushed into them
before either).  While the corresponding length is necessarily 0,
fwrite (NULL, something, 0, f) or
fread (NULL, something, 0, f) still invoke UB.

The following patch fixes that by not calling fwrite/fread if the
corresponding length is 0.

2024-10-04  Jakub Jelinek  

PR pch/116936
* diagnostic.cc (diagnostic_option_classifier::pch_save): Only call
fwrite if corresponding length is non-zero.
(diagnostic_option_classifier::pch_restore): Only call fread if
corresponding length is non-zero.

Diff:
---
 gcc/diagnostic.cc | 24 ++--
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index 73ed2ea154cc..27ac2bd67b9b 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -167,11 +167,13 @@ diagnostic_option_classifier::pch_save (FILE *f)
   unsigned int lengths[2] = { m_classification_history.length (),
  m_push_list.length () };
   if (fwrite (lengths, sizeof (lengths), 1, f) != 1
-  || fwrite (m_classification_history.address (),
-sizeof (diagnostic_classification_change_t),
-lengths[0], f) != lengths[0]
-  || fwrite (m_push_list.address (), sizeof (int),
-lengths[1], f) != lengths[1])
+  || (lengths[0]
+ && fwrite (m_classification_history.address (),
+sizeof (diagnostic_classification_change_t),
+lengths[0], f) != lengths[0])
+  || (lengths[1]
+ && fwrite (m_push_list.address (), sizeof (int),
+lengths[1], f) != lengths[1]))
 return -1;
   return 0;
 }
@@ -189,11 +191,13 @@ diagnostic_option_classifier::pch_restore (FILE *f)
   gcc_checking_assert (m_push_list.is_empty ());
   m_classification_history.safe_grow (lengths[0]);
   m_push_list.safe_grow (lengths[1]);
-  if (fread (m_classification_history.address (),
-sizeof (diagnostic_classification_change_t),
-lengths[0], f) != lengths[0]
-  || fread (m_push_list.address (), sizeof (int),
-   lengths[1], f) != lengths[1])
+  if ((lengths[0]
+   && fread (m_classification_history.address (),
+sizeof (diagnostic_classification_change_t),
+lengths[0], f) != lengths[0])
+  || (lengths[1]
+ && fread (m_push_list.address (), sizeof (int),
+   lengths[1], f) != lengths[1]))
 return -1;
   return 0;
 }


[gcc r15-4063] i386: Fix up ix86_expand_int_compare with TImode comparisons of SUBREGs from V8{H, B}Fmode against ze

2024-10-04 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:92e9e971ced90af5a825ae4b35ad6c98c9ab86da

commit r15-4063-g92e9e971ced90af5a825ae4b35ad6c98c9ab86da
Author: Jakub Jelinek 
Date:   Fri Oct 4 13:12:45 2024 +0200

i386: Fix up ix86_expand_int_compare with TImode comparisons of SUBREGs 
from V8{H,B}Fmode against zero [PR116921]

The following testcase ICEs, because the ix86_expand_int_compare
optimization to use {,v}ptest assumes there are instructions for all
16-byte vector modes.  That isn't the case, we only have one for
V16QI, V8HI, V4SI, V2DI, V1TI, V4SF and V2DF, not for
V8HF nor V8BF.

The following patch fixes that by using the V8HI instruction instead
for those 2 modes.  tmp can't be a SUBREG, because it is SUBREG_REG
of another SUBREG, so we don't need to worry about gen_lowpart
failing.

2024-10-04  Jakub Jelinek  

PR target/116921
* config/i386/i386-expand.cc (ix86_expand_int_compare): Add a SUBREG
to V8HImode from V8HFmode or V8BFmode before generating a ptest.

* gcc.target/i386/pr116921.c: New test.

Diff:
---
 gcc/config/i386/i386-expand.cc   |  2 ++
 gcc/testsuite/gcc.target/i386/pr116921.c | 12 
 2 files changed, 14 insertions(+)

diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index 39ee9b8662ad..a9f83a299e3a 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -3095,6 +3095,8 @@ ix86_expand_int_compare (enum rtx_code code, rtx op0, rtx 
op1)
   && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op0))) == 16)
 {
   tmp = SUBREG_REG (op0);
+  if (GET_MODE (tmp) == V8HFmode || GET_MODE (tmp) == V8BFmode)
+   tmp = gen_lowpart (V8HImode, tmp);
   tmp = gen_rtx_UNSPEC (CCZmode, gen_rtvec (2, tmp, tmp), UNSPEC_PTEST);
 }
   else
diff --git a/gcc/testsuite/gcc.target/i386/pr116921.c 
b/gcc/testsuite/gcc.target/i386/pr116921.c
new file mode 100644
index ..8cd4cf93b76d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr116921.c
@@ -0,0 +1,12 @@
+/* PR target/116921 */
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-O2 -msse4" } */
+
+long x;
+_Float16 __attribute__((__vector_size__ (16))) f;
+
+void
+foo (void)
+{
+  x -= !(__int128) (f / 2);
+}


[gcc r15-4062] i386: Fix up *minmax3_2 splitter [PR116925]

2024-10-04 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:67b750c20e1f9428ef89a6fed0103e912bea8679

commit r15-4062-g67b750c20e1f9428ef89a6fed0103e912bea8679
Author: Jakub Jelinek 
Date:   Fri Oct 4 12:36:52 2024 +0200

i386: Fix up *minmax3_2 splitter [PR116925]

While *minmax3_1 correctly uses
   if (MEM_P (operands[1]))
 operands[1] = force_reg (mode, operands[1]);
to ensure operands[1] is not a MEM, *minmax3_2 does it wrongly
by calling force_reg but ignoring its return value.

The following borderingly obvious patch fixes that.

Didn't find similar other errors in the backend with force_reg calls.

2024-10-04  Jakub Jelinek  

PR target/116925
* config/i386/sse.md (*minmax3_2): Assign force_reg result
back to operands[2] instead of throwing it away.

* g++.target/i386/avx-pr116925.C: New test.

Diff:
---
 gcc/config/i386/sse.md   |  2 +-
 gcc/testsuite/g++.target/i386/avx-pr116925.C | 12 
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 183c1953f913..d6e2135423d0 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -3269,7 +3269,7 @@
  u = UNSPEC_IEEE_MAX;
 
if (MEM_P (operands[2]))
- force_reg (mode, operands[2]);
+ operands[2] = force_reg (mode, operands[2]);
rtvec v = gen_rtvec (2, operands[2], operands[1]);
rtx tmp = gen_rtx_UNSPEC (mode, v, u);
emit_move_insn (operands[0], tmp);
diff --git a/gcc/testsuite/g++.target/i386/avx-pr116925.C 
b/gcc/testsuite/g++.target/i386/avx-pr116925.C
new file mode 100644
index ..b2d6fc1856bf
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/avx-pr116925.C
@@ -0,0 +1,12 @@
+// PR target/116925
+// { dg-do compile }
+// { dg-options "-O2 -mavx -ffloat-store" }
+
+typedef float V __attribute__((vector_size (16)));
+V a, b, c;
+
+void
+foo ()
+{
+  c = a > b ? a : b;
+}


[gcc r15-4010] libcpp: Implement clang -Wheader-guard warning [PR96842]

2024-10-02 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:5943a2fa1bc5407332a91976c145446cdb8ded7b

commit r15-4010-g5943a2fa1bc5407332a91976c145446cdb8ded7b
Author: Jakub Jelinek 
Date:   Wed Oct 2 10:53:35 2024 +0200

libcpp: Implement clang -Wheader-guard warning [PR96842]

The following patch implements the clang -Wheader-guard warning, which warns
if a valid multiple inclusion header guard's #ifndef/#if !defined directive
is immediately (no other non-line directives nor other (non-comment)
tokens in between) followed by #define directive for some different macro,
which in get_suggestion rules is close enough to the actual header guard
macro (i.e. likely misspelling), the #define is object-like with empty
definition (I've followed what clang implements) and the macro isn't defined
later on (at least not on the final #endif at the end of a header).

In this case it emits a warning, so that
  #ifndef STDIO_H
  #define STDOI_H
  ...
  #endif
or similar misspellings can be caught.

clang enables this warning by default, but I've put it into -Wall instead
as it still seems to be a style warning, nothing more severe; if a header
doesn't survive multiple inclusion because of the misspelling, users will
get different diagnostics.

2024-10-02  Jakub Jelinek  

PR preprocessor/96842
libcpp/
* include/cpplib.h (struct cpp_options): Add warn_header_guard 
member.
(enum cpp_warning_reason): Add CPP_W_HEADER_GUARD enumerator.
* internal.h (struct cpp_reader): Add mi_def_cmacro, mi_loc and
mi_def_loc members.
(_cpp_defined_macro_p): Constify type pointed by argument type.
Formatting fix.
* init.cc (cpp_create_reader): Clear
CPP_OPTION (pfile, warn_header_guard).
* directives.cc (struct if_stack): Add def_loc and mi_def_cmacro
members.
(DIRECTIVE_TABLE): Add IF_COND flag to define.
(do_define): Set ifs->mi_def_cmacro on a define immediately 
following
#ifndef directive for the guard.  Clear pfile->mi_valid.  Formatting
fix.
(do_endif): Copy over pfile->mi_def_cmacro and pfile->mi_def_loc
if ifs->mi_def_cmacro is set and pfile->mi_cmacro isn't a defined
macro.
(push_conditional): Clear mi_def_cmacro and mi_def_loc members.
* files.cc (_cpp_pop_file_buffer): Emit -Wheader-guard diagnostics.
gcc/
* doc/invoke.texi (Wheader-guard): Document.
gcc/c-family/
* c.opt (Wheader-guard): New option.
* c.opt.urls: Regenerated.
* c-ppoutput.cc (init_pp_output): Initialize also 
cb->get_suggestion.
gcc/testsuite/
* c-c++-common/cpp/Wheader-guard-1.c: New test.
* c-c++-common/cpp/Wheader-guard-1-1.h: New test.
* c-c++-common/cpp/Wheader-guard-1-2.h: New test.
* c-c++-common/cpp/Wheader-guard-1-3.h: New test.
* c-c++-common/cpp/Wheader-guard-1-4.h: New test.
* c-c++-common/cpp/Wheader-guard-1-5.h: New test.
* c-c++-common/cpp/Wheader-guard-1-6.h: New test.
* c-c++-common/cpp/Wheader-guard-1-7.h: New test.
* c-c++-common/cpp/Wheader-guard-1-8.h: New test.
* c-c++-common/cpp/Wheader-guard-1-9.h: New test.
* c-c++-common/cpp/Wheader-guard-1-10.h: New test.
* c-c++-common/cpp/Wheader-guard-1-11.h: New test.
* c-c++-common/cpp/Wheader-guard-1-12.h: New test.
* c-c++-common/cpp/Wheader-guard-2.c: New test.
* c-c++-common/cpp/Wheader-guard-2.h: New test.
* c-c++-common/cpp/Wheader-guard-3.c: New test.
* c-c++-common/cpp/Wheader-guard-3.h: New test.

Diff:
---
 gcc/c-family/c-ppoutput.cc |  1 +
 gcc/c-family/c.opt |  4 +++
 gcc/c-family/c.opt.urls|  3 ++
 gcc/doc/invoke.texi| 15 +++-
 gcc/testsuite/c-c++-common/cpp/Wheader-guard-1-1.h |  5 +++
 .../c-c++-common/cpp/Wheader-guard-1-10.h  |  5 +++
 .../c-c++-common/cpp/Wheader-guard-1-11.h  |  5 +++
 .../c-c++-common/cpp/Wheader-guard-1-12.h  |  5 +++
 gcc/testsuite/c-c++-common/cpp/Wheader-guard-1-2.h |  4 +++
 gcc/testsuite/c-c++-common/cpp/Wheader-guard-1-3.h |  4 +++
 gcc/testsuite/c-c++-common/cpp/Wheader-guard-1-4.h |  3 ++
 gcc/testsuite/c-c++-common/cpp/Wheader-guard-1-5.h |  5 +++
 gcc/testsuite/c-c++-common/cpp/Wheader-guard-1-6.h |  8 +
 gcc/testsuite/c-c++-common/cpp/Wheader-guard-1-7.h |  4 +++
 gcc/testsuite/c-c++-common/cpp/Wheader-guard-1-8.h |  5 +++
 gcc/testsuite/c-c++-common/cpp/Wheader-guard-1-9.h |  5 +++
 gcc/testsuite/c-c++-common/cpp/Wheader-guard-1.c   | 19 ++
 gcc/testsuite/c-c++-common/cpp/Wheader-guard-2.c   | 10 ++
 gcc/testsuite/c-c++-common/cpp/

[gcc r15-4009] opts: Fix up regenerate-opt-urls dependencies

2024-10-02 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:ba53ccad554bb4f3c2b0e457a18557ae0f54b05e

commit r15-4009-gba53ccad554bb4f3c2b0e457a18557ae0f54b05e
Author: Jakub Jelinek 
Date:   Wed Oct 2 10:14:50 2024 +0200

opts: Fix up regenerate-opt-urls dependencies

It seems that we currently require
1) enabling at least c,c++,fortran,d in --enable-languages
2) first doing make html
before one can successfully regenerate-opt-urls, otherwise without 2)
one gets
make regenerate-opt-urls
make: *** No rule to make target 
'/home/jakub/src/gcc/obj12x/gcc/HTML/gcc-15.0.0/gcc/Option-Index.html', needed 
by 'regenerate-opt-urls'.  Stop.
or say if not configuring d after make html one still gets
make regenerate-opt-urls
make: *** No rule to make target 
'/home/jakub/src/gcc/obj12x/gcc/HTML/gcc-15.0.0/gdc/Option-Index.html', needed 
by 'regenerate-opt-urls'.  Stop.

Now, I believe neither 1) nor 2) is really necessary.
The regenerate-opt-urls goal has dependency on 3 Option-Index.html files,
but those files don't have dependencies how to generate them.
make html has dependency on $(HTMLS_BUILD) which adds
$(build_htmldir)/gcc/index.html and lang.html among other things, where
the former actually builds not just index.html but also Option-Index.html
and tons of other files, and lang.html is filled in by configure depending
on configured languages, so sometimes will include gfortran.html and
sometimes d.html.

The following patch adds dependencies of the Option-Index.html on their
corresponding index.html files and that is all that seems to be needed,
make regenerate-opt-urls then works even without prior make html and
even if just a subset of c/c++, fortran and d is enabled.

2024-10-02  Jakub Jelinek  

* Makefile.in ($(OPT_URLS_HTML_DEPS)): Add dependencies of the
Option-Index.html files on the corresponding index.html files.
Don't mention the requirement that all languages that have their own
HTML manuals to be enabled.

Diff:
---
 gcc/Makefile.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 68fda1a75918..059cf2e8f79f 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -3640,12 +3640,12 @@ $(build_htmldir)/gccinstall/index.html: 
$(TEXI_GCCINSTALL_FILES)
$(SHELL) $(srcdir)/doc/install.texi2html
 
 # Regenerate the .opt.urls files from the generated html, and from the .opt
-# files.  Doing so requires all languages that have their own HTML manuals
-# to be enabled.
+# files.
 .PHONY: regenerate-opt-urls
 OPT_URLS_HTML_DEPS = $(build_htmldir)/gcc/Option-Index.html \
$(build_htmldir)/gdc/Option-Index.html \
$(build_htmldir)/gfortran/Option-Index.html
+$(OPT_URLS_HTML_DEPS): %/Option-Index.html: %/index.html
 
 regenerate-opt-urls: $(srcdir)/regenerate-opt-urls.py $(OPT_URLS_HTML_DEPS)
$(srcdir)/regenerate-opt-urls.py $(build_htmldir) $(shell dirname 
$(srcdir))


[gcc r15-3984] range-cache: Fix ICE on SSA_NAME with def_stmt not yet in the IL [PR116898]

2024-10-01 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:bdbd0607d5933cdecbf7e009a42f1d9486dddf44

commit r15-3984-gbdbd0607d5933cdecbf7e009a42f1d9486dddf44
Author: Jakub Jelinek 
Date:   Tue Oct 1 09:49:49 2024 +0200

range-cache: Fix ICE on SSA_NAME with def_stmt not yet in the IL [PR116898]

Some passes like the bitint lowering queue some statements on edges and only
commit them at the end of the pass.  If they use ranger at the same time,
the ranger might see such SSA_NAMEs and ICE on those.  The following patch
instead just punts on them.

2024-10-01  Jakub Jelinek  

PR middle-end/116898
* gimple-range-cache.cc (ranger_cache::block_range): If a SSA_NAME
with NULL def_bb isn't SSA_NAME_IS_DEFAULT_DEF, return false instead
of failing assertion.  Formatting fix.

* gcc.dg/bitint-110.c: New test.

Diff:
---
 gcc/gimple-range-cache.cc |  9 ++---
 gcc/testsuite/gcc.dg/bitint-110.c | 20 
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index 43949894cbed..c0b8916e85af 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -1284,13 +1284,16 @@ ranger_cache::block_range (vrange &r, basic_block bb, 
tree name, bool calc)
   gimple *def_stmt = SSA_NAME_DEF_STMT (name);
   basic_block def_bb = NULL;
   if (def_stmt)
-   def_bb = gimple_bb (def_stmt);;
+   def_bb = gimple_bb (def_stmt);
   if (!def_bb)
{
  // If we get to the entry block, this better be a default def
  // or range_on_entry was called for a block not dominated by
- // the def.  
- gcc_checking_assert (SSA_NAME_IS_DEFAULT_DEF (name));
+ // the def.  But it could be also SSA_NAME defined by a statement
+ // not yet in the IL (such as queued edge insertion), in that case
+ // just punt.
+ if (!SSA_NAME_IS_DEFAULT_DEF (name))
+   return false;
  def_bb = ENTRY_BLOCK_PTR_FOR_FN (cfun);
}
 
diff --git a/gcc/testsuite/gcc.dg/bitint-110.c 
b/gcc/testsuite/gcc.dg/bitint-110.c
new file mode 100644
index ..4ba2f93856e5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/bitint-110.c
@@ -0,0 +1,20 @@
+/* PR middle-end/116898 */
+/* { dg-do compile { target bitint575 } } */
+/* { dg-options "-O -finstrument-functions -fnon-call-exceptions" } */
+
+_BitInt(127) a;
+_BitInt(511) b;
+
+void
+foo (_BitInt(31) c)
+{
+  do
+{
+  c %= b;
+again:
+}
+  while (c);
+  a /= 0;  /* { dg-warning "division by zero" } */
+  c -= a;
+  goto again;
+}


[gcc r15-3985] range-cache: Fix ranger ICE if number of bbs increases [PR116899]

2024-10-01 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:de25f1729d212c11d6e2955130f4eb1d272b5ce7

commit r15-3985-gde25f1729d212c11d6e2955130f4eb1d272b5ce7
Author: Jakub Jelinek 
Date:   Tue Oct 1 09:52:20 2024 +0200

range-cache: Fix ranger ICE if number of bbs increases [PR116899]

Ranger cache during initialization reserves number of basic block slots
in the m_workback vector (in an inefficient way by doing create (0)
and safe_grow_cleared (n) and truncate (0) rather than say create (n)
or reserve (n) after create).  The problem is that some passes split bbs 
and/or
create new basic blocks and so when one is unlucky, the quick_push into that
vector can ICE.

The following patch replaces those 4 quick_push calls with safe_push.

I've also gathered some statistics from compiling 63 gcc sources (picked 
those
that dependent on gimple-range-cache.h just because I had to rebuild them 
once
for the instrumentation), and that showed that in 81% of cases nothing has
been pushed into the vector at all (and note, not everything was small, 
there
were even cases with 1+ basic blocks), another 18.5% of cases had just 
1-4
elements in the vector at most, 0.08% had 5-8 and 19 out of 305386 cases
had at most 9-11 elements, nothing more.  So, IMHO reserving number of basic
block in the vector is a waste of compile time memory and with the safe_push
calls, the patch just initializes the vector to vNULL.

2024-10-01  Jakub Jelinek  

PR middle-end/116899
* gimple-range-cache.cc (ranger_cache::ranger_cache): Set m_workback
to vNULL instead of creating it, growing and then truncating.
(ranger_cache::fill_block_cache): Use safe_push rather than 
quick_push
on m_workback.
(ranger_cache::range_from_dom): Likewise.

* gcc.dg/bitint-111.c: New test.

Diff:
---
 gcc/gimple-range-cache.cc | 12 +---
 gcc/testsuite/gcc.dg/bitint-111.c | 16 
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index c0b8916e85af..035076be5d87 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -997,9 +997,7 @@ update_list::pop ()
 
 ranger_cache::ranger_cache (int not_executable_flag, bool use_imm_uses)
 {
-  m_workback.create (0);
-  m_workback.safe_grow_cleared (last_basic_block_for_fn (cfun));
-  m_workback.truncate (0);
+  m_workback = vNULL;
   m_temporal = new temporal_cache;
 
   // If DOM info is available, spawn an oracle as well.
@@ -1560,7 +1558,7 @@ ranger_cache::fill_block_cache (tree name, basic_block 
bb, basic_block def_bb)
   // Visit each block back to the DEF.  Initialize each one to UNDEFINED.
   // m_visited at the end will contain all the blocks that we needed to set
   // the range_on_entry cache for.
-  m_workback.quick_push (bb);
+  m_workback.safe_push (bb);
   undefined.set_undefined ();
   m_on_entry.set_bb_range (name, bb, undefined);
   gcc_checking_assert (m_update->empty_p ());
@@ -1634,7 +1632,7 @@ ranger_cache::fill_block_cache (tree name, basic_block 
bb, basic_block def_bb)
  // the list.
  gcc_checking_assert (!m_on_entry.bb_range_p (name, pred));
  m_on_entry.set_bb_range (name, pred, undefined);
- m_workback.quick_push (pred);
+ m_workback.safe_push (pred);
}
 }
 
@@ -1729,7 +1727,7 @@ ranger_cache::range_from_dom (vrange &r, tree name, 
basic_block start_bb,
 
   // This block has an outgoing range.
   if (gori ().has_edge_range_p (name, bb))
-   m_workback.quick_push (prev_bb);
+   m_workback.safe_push (prev_bb);
   else
{
  // Normally join blocks don't carry any new range information on
@@ -1753,7 +1751,7 @@ ranger_cache::range_from_dom (vrange &r, tree name, 
basic_block start_bb,
break;
  }
  if (all_dom)
-   m_workback.quick_push (prev_bb);
+   m_workback.safe_push (prev_bb);
}
}
 
diff --git a/gcc/testsuite/gcc.dg/bitint-111.c 
b/gcc/testsuite/gcc.dg/bitint-111.c
new file mode 100644
index ..3cc23684c844
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/bitint-111.c
@@ -0,0 +1,16 @@
+/* PR middle-end/116899 */
+/* { dg-do compile { target bitint575 } } */
+/* { dg-options "-O2" } */
+
+float f;
+_BitInt(255) b;
+
+void
+foo (signed char c)
+{
+  for (;;)
+{
+  c %= (unsigned _BitInt(512)) 0;  /* { dg-warning "division by zero" } */
+  f /= b >= c;
+}
+}


[gcc r15-3950] cselib: Discard useless locs of preserved VALUEs [PR116627]

2024-09-29 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:73726725ae03995ef8b61622c954f7ca70416f79

commit r15-3950-g73726725ae03995ef8b61622c954f7ca70416f79
Author: Jakub Jelinek 
Date:   Sun Sep 29 21:52:32 2024 +0200

cselib: Discard useless locs of preserved VALUEs [PR116627]

remove_useless_values iteratively discards useless locs (locs of
cselib_val which refer to non-preserved VALUEs with no locations),
which in turn can make further values useless until no further VALUEs
are made useless and then discards the useless VALUEs.

Preserved VALUEs (something done during var-tracking only I think)
live in a different hash table, cselib_preserved_hash_table rather
than cselib_hash_table.  cselib_find_slot first looks up slot in
cselib_preserved_hash_table and only if not found looks it up in
cselib_hash_table (and INSERTs only into the latter), whereas preservation
of a VALUE results in move of a cselib_val from the latter to the former
hash table.

The testcase in the PR (apparently too fragile, it only reproduces on 14
branch with various flags on a single arch, not on trunk) ICEs, because
we have a preserved VALUE (QImode with (const_int 0) as one of the locs).
In a different BB SImode r2 is looked up, a non-preserved VALUE is created
for it, and the r13-2916 added code attempts to lookup also SUBREGs of that
in narrower modes, among those QImode, so adds to that SImode r2
non-preserve VALUE a new loc of (subreg:QI (value:SI) 0).  That SImode
value is considered useless, so remove_useless_value discards it, but
nothing discarded it from the preserved VALUE's loc_list, so when looking
something up in the hash table we ICE trying to derevence CSELIB_VAL
of the discarded VALUE.

I think we need to discuard useless locs even from the preserved VALUEs.
That IMHO shouldn't create any further useless VALUEs, the preserved
VALUEs are never useless, so we don't need to iterate with it, can do it
just once, but IMHO it needs to be done because actually
discard_useless_values.

The following patch does that.

2024-09-29  Jakub Jelinek  

PR target/116627
* cselib.cc (remove_useless_values): Discard useless locs
even from preserved cselib_vals in cselib_preserved_hash_table
hash table.

Diff:
---
 gcc/cselib.cc | 5 +
 1 file changed, 5 insertions(+)

diff --git a/gcc/cselib.cc b/gcc/cselib.cc
index 7beaca424244..e6a36e892bb4 100644
--- a/gcc/cselib.cc
+++ b/gcc/cselib.cc
@@ -751,6 +751,11 @@ remove_useless_values (void)
   }
   *p = &dummy_val;
 
+  if (cselib_preserve_constants)
+cselib_preserved_hash_table->traverse  (NULL);
+  gcc_assert (!values_became_useless);
+
   n_useless_values += n_useless_debug_values;
   n_debug_values -= n_useless_debug_values;
   n_useless_debug_values = 0;


[gcc r15-3929] diagnostic: Save/restore diagnostic context history and push/pop state for PCH [PR116847]

2024-09-27 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:64072e60b1599ae7d347c2cdee46c3b0e37fc338

commit r15-3929-g64072e60b1599ae7d347c2cdee46c3b0e37fc338
Author: Jakub Jelinek 
Date:   Fri Sep 27 16:07:40 2024 +0200

diagnostic: Save/restore diagnostic context history and push/pop state for 
PCH [PR116847]

The following patch on top of the just posted cleanup patch
saves/restores the m_classification_history and m_push_list
vectors for PCH.  Without that as the testcase shows during parsing
of the templates we don't report ignored diagnostics, but after loading
PCH header when instantiating those templates those warnings can be
emitted.  This doesn't show up on x86_64-linux build because configure
injects there -fcf-protection -mshstk flags during library build (and so
also during PCH header creation), but make check doesn't use those flags
and so the PCH header is ignored.

2024-09-26  Jakub Jelinek  

PR libstdc++/116847
gcc/
* diagnostic.h (diagnostic_option_classifier): Add pch_save and
pch_restore method declarations.
(diagnostic_context): Add pch_save and pch_restore inline method
definitions.
* diagnostic.cc (diagnostic_option_classifier::pch_save): New 
method.
(diagnostic_option_classifier::pch_restore): Likewise.
gcc/c-family/
* c-pch.cc: Include diagnostic.h.
(c_common_write_pch): Call global_dc->pch_save.
(c_common_read_pch): Call global_dc->pch_restore.
gcc/testsuite/
* g++.dg/pch/pr116847.C: New test.
* g++.dg/pch/pr116847.Hs: New test.

Diff:
---
 gcc/c-family/c-pch.cc|  8 +++-
 gcc/diagnostic.cc| 40 
 gcc/diagnostic.h | 15 ++
 gcc/testsuite/g++.dg/pch/pr116847.C  | 10 +
 gcc/testsuite/g++.dg/pch/pr116847.Hs |  8 
 5 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/gcc/c-family/c-pch.cc b/gcc/c-family/c-pch.cc
index 9bcfdc804215..f104575d3d08 100644
--- a/gcc/c-family/c-pch.cc
+++ b/gcc/c-family/c-pch.cc
@@ -28,6 +28,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "c-pragma.h"
 #include "langhooks.h"
 #include "hosthooks.h"
+#include "diagnostic.h"
 
 /* This is a list of flag variables that must match exactly, and their
names for the error message.  The possible values for *flag_var must
@@ -178,7 +179,8 @@ c_common_write_pch (void)
   cpp_write_pch_state (parse_in, pch_outfile);
   timevar_pop (TV_PCH_CPP_SAVE);
 
-  if (fseek (pch_outfile, 0, SEEK_SET) != 0
+  if (global_dc->pch_save (pch_outfile) < 0
+  || fseek (pch_outfile, 0, SEEK_SET) != 0
   || fwrite (get_ident (), IDENT_LENGTH, 1, pch_outfile) != 1)
 fatal_error (input_location, "cannot write %s: %m", pch_file);
 
@@ -359,6 +361,10 @@ c_common_read_pch (cpp_reader *pfile, const char *name,
   linemap_line_start (line_table, saved_loc.line, 0);
 
   timevar_pop (TV_PCH_CPP_RESTORE);
+
+  if (global_dc->pch_restore (f) < 0)
+fatal_error (input_location, "cannot read %s: %m", name);
+
   fclose (f);
 
   if (cpp_result != 0)
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index ffe61f73d196..9462fe67a063 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -156,6 +156,46 @@ diagnostic_option_classifier::fini ()
   m_push_list.release ();
 }
 
+/* Save the diagnostic_option_classifier state to F for PCH
+   output.  Returns 0 on success, -1 on error.  */
+
+int
+diagnostic_option_classifier::pch_save (FILE *f)
+{
+  unsigned int lengths[2] = { m_classification_history.length (),
+ m_push_list.length () };
+  if (fwrite (lengths, sizeof (lengths), 1, f) != 1
+  || fwrite (m_classification_history.address (),
+sizeof (diagnostic_classification_change_t),
+lengths[0], f) != lengths[0]
+  || fwrite (m_push_list.address (), sizeof (int),
+lengths[1], f) != lengths[1])
+return -1;
+  return 0;
+}
+
+/* Read the diagnostic_option_classifier state from F for PCH
+   read.  Returns 0 on success, -1 on error.  */
+
+int
+diagnostic_option_classifier::pch_restore (FILE *f)
+{
+  unsigned int lengths[2];
+  if (fread (lengths, sizeof (lengths), 1, f) != 1)
+return -1;
+  gcc_checking_assert (m_classification_history.is_empty ());
+  gcc_checking_assert (m_push_list.is_empty ());
+  m_classification_history.safe_grow (lengths[0]);
+  m_push_list.safe_grow (lengths[1]);
+  if (fread (m_classification_history.address (),
+sizeof (diagnostic_classification_change_t),
+lengths[0], f) != lengths[0]
+  || fread (m_push_list.address (), sizeof (int),
+   lengths[1], f) != lengths[1])
+return -1;
+  return 0;
+}
+
 /* Save all diagnostic classifications in a stack.  */
 
 void
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index c3300fc96340..3087b19f9ea9 100644
-

[gcc r15-3928] diagnostic: Use vec instead of custom array reallocations for m_classification_history/m_push_list [

2024-09-27 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:ddc72ba6c6c2c84a1a95340840bd5fde1f2bde44

commit r15-3928-gddc72ba6c6c2c84a1a95340840bd5fde1f2bde44
Author: Jakub Jelinek 
Date:   Fri Sep 27 16:06:29 2024 +0200

diagnostic: Use vec instead of custom array reallocations for 
m_classification_history/m_push_list [PR116847]

diagnostic.h already relies on vec.h, it uses auto_vec in one spot.

The following patch converts m_classification_history and m_push_list
hand-managed arrays to vec templates.
The main advantage is exponential rather than linear reallocation,
e.g. with current libstdc++ headers if one includes all the standard
headers there could be ~ 300 reallocations of the m_classification_history
array (sure, not all of them will result in actually copying the data, but
still).
In addition to that it fixes some formatting issues in the code.

2024-09-26  Jakub Jelinek  

PR libstdc++/116847
* diagnostic.h (diagnostic_option_classifier): Change type
of m_classification_history from diagnostic_classification_change_t 
*
to vec.  Change type of
m_push_list from int * to vec.  Remove 
m_n_classification_history
and m_n_push members.
* diagnostic.cc (diagnostic_option_classifier::init): Set 
m_push_list
to vNULL rather than nullptr.  Don't initialize m_n_push.  
Initialize
m_classification_history to vNULL.
(diagnostic_option_classifier::fini): Call release () method on
m_push_list instead of free on it.  Call release () on
m_classification_history.  Don't clear m_n_push.
(diagnostic_option_classifier::push): Adjust for m_push_list and
m_classification_history being vectors rather than custom allocated
arrays with counter.
(diagnostic_option_classifier::pop): Likewise.
(classify_diagnostic): Adjust for m_classification_history being
vector rather than custom allocated array with counter.
(update_effective_level_from_pragmas): Likewise.

Diff:
---
 gcc/diagnostic.cc | 68 +++
 gcc/diagnostic.h  |  8 ++-
 2 files changed, 30 insertions(+), 46 deletions(-)

diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index 152eb9d35a8e..ffe61f73d196 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -143,8 +143,8 @@ diagnostic_option_classifier::init (int n_opts)
   m_classify_diagnostic = XNEWVEC (diagnostic_t, n_opts);
   for (int i = 0; i < n_opts; i++)
 m_classify_diagnostic[i] = DK_UNSPECIFIED;
-  m_push_list = nullptr;
-  m_n_push = 0;
+  m_push_list = vNULL;
+  m_classification_history = vNULL;
 }
 
 void
@@ -152,8 +152,8 @@ diagnostic_option_classifier::fini ()
 {
   XDELETEVEC (m_classify_diagnostic);
   m_classify_diagnostic = nullptr;
-  free (m_push_list);
-  m_n_push = 0;
+  m_classification_history.release ();
+  m_push_list.release ();
 }
 
 /* Save all diagnostic classifications in a stack.  */
@@ -161,8 +161,7 @@ diagnostic_option_classifier::fini ()
 void
 diagnostic_option_classifier::push ()
 {
-  m_push_list = (int *) xrealloc (m_push_list, (m_n_push + 1) * sizeof (int));
-  m_push_list[m_n_push ++] = m_n_classification_history;
+  m_push_list.safe_push (m_classification_history.length ());
 }
 
 /* Restore the topmost classification set off the stack.  If the stack
@@ -173,19 +172,13 @@ diagnostic_option_classifier::pop (location_t where)
 {
   int jump_to;
 
-  if (m_n_push)
-jump_to = m_push_list [-- m_n_push];
+  if (!m_push_list.is_empty ())
+jump_to = m_push_list.pop ();
   else
 jump_to = 0;
 
-  const int i = m_n_classification_history;
-  m_classification_history =
-(diagnostic_classification_change_t *) xrealloc (m_classification_history, 
(i + 1)
-* sizeof 
(diagnostic_classification_change_t));
-  m_classification_history[i].location = where;
-  m_classification_history[i].option = jump_to;
-  m_classification_history[i].kind = DK_POP;
-  m_n_classification_history ++;
+  diagnostic_classification_change_t v = { where, jump_to, DK_POP };
+  m_classification_history.safe_push (v);
 }
 
 /* Initialize the diagnostic message outputting machinery.  */
@@ -880,31 +873,27 @@ classify_diagnostic (const diagnostic_context *context,
  the pragmas were.  */
   if (where != UNKNOWN_LOCATION)
 {
-  int i;
+  unsigned i;
 
   /* Record the command-line status, so we can reset it back on DK_POP. */
   if (old_kind == DK_UNSPECIFIED)
{
- old_kind = !context->option_enabled_p (option_id)
-   ? DK_IGNORED : DK_ANY;
+ old_kind = (!context->option_enabled_p (option_id)
+ ? DK_IGNORED : DK_ANY);
  m_classify_diagnostic[option_id.m_idx] = old_kind;
}
 
-  for (i = m_n_classification_history - 1; i >= 0; i --)
-   if (m_c

[gcc r15-3891] pretty-print: Fix up allocate_object

2024-09-26 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:9dc1ab9062e93ae178830d66d5850406777a477d

commit r15-3891-g9dc1ab9062e93ae178830d66d5850406777a477d
Author: Jakub Jelinek 
Date:   Thu Sep 26 11:55:13 2024 +0200

pretty-print: Fix up allocate_object

On Thu, Aug 29, 2024 at 06:58:12PM -0400, David Malcolm wrote:
> The following patch rewrites the internals of pp_format.

> The tokens and token lists are allocated on the chunk_obstack, and so
> there's no additional heap activity required, with the memory reclaimed
> when the chunk_obstack is freed after phase 3 of formatting.

> +static void *
> +allocate_object (size_t sz, obstack &s)
> +{
> +  /* We must not be half-way through an object.  */
> +  gcc_assert (obstack_base (&s) == obstack_next_free (&s));
> +
> +  obstack_grow (&s, obstack_base (&s), sz);
> +  void *buf = obstack_finish (&s);
> +  return buf;
>  }

I think this is wrong.  I hoped it would be the reason of the
unexpected libstdc++ warnings on certain architectures after
seeing
==4027220== Source and destination overlap in memcpy(0x4627154, 0x4627154, 
12)
==4027220==at 0x404B93E: memcpy (vg_replace_strmem.c:1123)
==4027220==by 0xAAD5618: allocate_object(unsigned int, obstack&) 
(pretty-print.cc:1183)
==4027220==by 0xAAD8C0E: operator new (pretty-print.cc:1210)
==4027220==by 0xAAD8C0E: make (pretty-print-format-impl.h:305)
==4027220==by 0xAAD8C0E: format_phase_1 (pretty-print.cc:1659)
==4027220==by 0xAAD8C0E: pretty_printer::format(text_info&) 
(pretty-print.cc:1618)
==4027220==by 0xAAA840E: pp_format (pretty-print.h:583)
==4027220==by 0xAAA840E: 
diagnostic_context::report_diagnostic(diagnostic_info*) (diagnostic.cc:1260)
==4027220==by 0xAAA8703: 
diagnostic_context::diagnostic_impl(rich_location*, diagnostic_metadata const*, 
diagnostic_option_id, char const*, char**, diagnostic_t) (diagnostic.cc:1404)
==4027220==by 0xAAB8682: warning(diagnostic_option_id, char const*, 
...) (diagnostic-global-context.cc:166)
==4027220==by 0x97725F5: warn_deprecated_use(tree_node*, tree_node*) 
(tree.cc:12485)
==4027220==by 0x8B6694B: mark_used(tree_node*, int) (decl2.cc:6121)
==4027220==by 0x8C9E25E: tsubst_expr(tree_node*, tree_node*, int, 
tree_node*) [clone .part.0] (pt.cc:21626)
==4027220==by 0x8C9E5E6: tsubst_expr(tree_node*, tree_node*, int, 
tree_node*) [clone .part.0] (pt.cc:20935)
==4027220==by 0x8C9E1D7: tsubst_expr(tree_node*, tree_node*, int, 
tree_node*) [clone .part.0] (pt.cc:20424)
==4027220==by 0x8C9DF2E: tsubst_expr(tree_node*, tree_node*, int, 
tree_node*) [clone .part.0] (pt.cc:20496)
==4027220==
etc. valgrind warnings, unfortunately it is not, but still
I think this is a bug.
If the obstack has enough space in it, i.e. if obstack_room (&s) >= sz,
then obstack_grow from obstack_base will copy uninitialized bytes
through memcpy (obstack_base (&s), obstack_base (&s), sz);
(which pedantically isn't valid due to the overlap, and so
the reason why valgrind complains, but in reality I think most
implementations can handle it fine, after all, we also use it for
structure assignments which could have full or no overlap but never
partial).
If obstack_room (&s) < sz, then obstack_grow will first
_obstack_newchunk (&s, sz); which will allocate new memory and
copy the existing data of the object (but the above assertion
guartantees it will copy 0 bytes) and then the memcpy copies
sz bytes from the old base to the new (if unlucky, that could crash
as there could be end of page and unmapped next page in between).

I think we should use obstack_blank instead of obstack_grow, which
does everything obstack_grow does, except for the memcpy of the
uninitialized data.

2024-09-25  Jakub Jelinek  

* pretty-print.cc (allocate_object): Use obstack_blank rather than
obstack_grow.

Diff:
---
 gcc/pretty-print.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/pretty-print.cc b/gcc/pretty-print.cc
index 0cd9b4d0a416..68c145e2d532 100644
--- a/gcc/pretty-print.cc
+++ b/gcc/pretty-print.cc
@@ -1180,7 +1180,7 @@ allocate_object (size_t sz, obstack &s)
   /* We must not be half-way through an object.  */
   gcc_assert (obstack_base (&s) == obstack_next_free (&s));
 
-  obstack_grow (&s, obstack_base (&s), sz);
+  obstack_blank (&s, sz);
   void *buf = obstack_finish (&s);
   return buf;
 }


[gcc r15-3876] i386: Add GENERIC and GIMPLE folders of __builtin_ia32_{min, max}* [PR116738]

2024-09-25 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:cc40795d8956d78e719a6acc83d5abad7032a6c3

commit r15-3876-gcc40795d8956d78e719a6acc83d5abad7032a6c3
Author: Jakub Jelinek 
Date:   Wed Sep 25 20:17:11 2024 +0200

i386: Add GENERIC and GIMPLE folders of __builtin_ia32_{min,max}* [PR116738]

The following patch adds GENERIC and GIMPLE folders for various
x86 min/max builtins.
As discussed, these builtins have effectively x < y ? x : y
(or x > y ? x : y) behavior.
The GENERIC folding is done if all the (relevant) arguments are
constants (such as VECTOR_CST for vectors) and is done because
the GIMPLE folding can't easily handle masking, rounding and the
ss/sd cases (in a way that it would be pattern recognized back to the
corresponding instructions).  The GIMPLE folding is also done just
for TARGET_SSE4 or later when optimizing, otherwise it is apparently
not matched back.

2024-09-25  Jakub Jelinek  

PR target/116738
* config/i386/i386.cc (ix86_fold_builtin): Handle
IX86_BUILTIN_M{IN,AX}{S,P}{S,H,D}*.
(ix86_gimple_fold_builtin): Handle IX86_BUILTIN_M{IN,AX}P{S,H,D}*.

* gcc.target/i386/avx512f-pr116738-1.c: New test.
* gcc.target/i386/avx512f-pr116738-2.c: New test.

Diff:
---
 gcc/config/i386/i386.cc| 195 +
 gcc/testsuite/gcc.target/i386/avx512f-pr116738-1.c |  56 ++
 gcc/testsuite/gcc.target/i386/avx512f-pr116738-2.c |  15 ++
 3 files changed, 266 insertions(+)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index cfa84ed013d9..ad2e7b447ffa 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -18514,6 +18514,8 @@ ix86_fold_builtin (tree fndecl, int n_args,
= (enum ix86_builtins) DECL_MD_FUNCTION_CODE (fndecl);
   enum rtx_code rcode;
   bool is_vshift;
+  enum tree_code tcode;
+  bool is_scalar;
   unsigned HOST_WIDE_INT mask;
 
   switch (fn_code)
@@ -18963,6 +18965,131 @@ ix86_fold_builtin (tree fndecl, int n_args,
}
  break;
 
+   case IX86_BUILTIN_MINSS:
+   case IX86_BUILTIN_MINSH_MASK:
+ tcode = LT_EXPR;
+ is_scalar = true;
+ goto do_minmax;
+
+   case IX86_BUILTIN_MAXSS:
+   case IX86_BUILTIN_MAXSH_MASK:
+ tcode = GT_EXPR;
+ is_scalar = true;
+ goto do_minmax;
+
+   case IX86_BUILTIN_MINPS:
+   case IX86_BUILTIN_MINPD:
+   case IX86_BUILTIN_MINPS256:
+   case IX86_BUILTIN_MINPD256:
+   case IX86_BUILTIN_MINPS512:
+   case IX86_BUILTIN_MINPD512:
+   case IX86_BUILTIN_MINPS128_MASK:
+   case IX86_BUILTIN_MINPD128_MASK:
+   case IX86_BUILTIN_MINPS256_MASK:
+   case IX86_BUILTIN_MINPD256_MASK:
+   case IX86_BUILTIN_MINPH128_MASK:
+   case IX86_BUILTIN_MINPH256_MASK:
+   case IX86_BUILTIN_MINPH512_MASK:
+ tcode = LT_EXPR;
+ is_scalar = false;
+ goto do_minmax;
+
+   case IX86_BUILTIN_MAXPS:
+   case IX86_BUILTIN_MAXPD:
+   case IX86_BUILTIN_MAXPS256:
+   case IX86_BUILTIN_MAXPD256:
+   case IX86_BUILTIN_MAXPS512:
+   case IX86_BUILTIN_MAXPD512:
+   case IX86_BUILTIN_MAXPS128_MASK:
+   case IX86_BUILTIN_MAXPD128_MASK:
+   case IX86_BUILTIN_MAXPS256_MASK:
+   case IX86_BUILTIN_MAXPD256_MASK:
+   case IX86_BUILTIN_MAXPH128_MASK:
+   case IX86_BUILTIN_MAXPH256_MASK:
+   case IX86_BUILTIN_MAXPH512_MASK:
+ tcode = GT_EXPR;
+ is_scalar = false;
+   do_minmax:
+ gcc_assert (n_args >= 2);
+ if (TREE_CODE (args[0]) != VECTOR_CST
+ || TREE_CODE (args[1]) != VECTOR_CST)
+   break;
+ mask = HOST_WIDE_INT_M1U;
+ if (n_args > 2)
+   {
+ gcc_assert (n_args >= 4);
+ /* This is masked minmax.  */
+ if (TREE_CODE (args[3]) != INTEGER_CST
+ || TREE_SIDE_EFFECTS (args[2]))
+   break;
+ mask = TREE_INT_CST_LOW (args[3]);
+ unsigned elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0]));
+ mask |= HOST_WIDE_INT_M1U << elems;
+ if (mask != HOST_WIDE_INT_M1U
+ && TREE_CODE (args[2]) != VECTOR_CST)
+   break;
+ if (n_args >= 5)
+   {
+ if (!tree_fits_uhwi_p (args[4]))
+   break;
+ if (tree_to_uhwi (args[4]) != 4
+ && tree_to_uhwi (args[4]) != 8)
+   break;
+   }
+ if (mask == (HOST_WIDE_INT_M1U << elems))
+   return args[2];
+   }
+ /* Punt on NaNs, unless exceptions are disabled.  */
+ if (HONOR_NANS (args[0])
+ && (n_args < 5 || tree_to_uhwi (args[4]) != 8))
+   for (int i = 0; i < 2; ++i)
+ {
+   unsigned count = vector_cst_encoded_nelts (args[i]);
+   for (unsig

[gcc r15-3869] c++: Add testcase for DR 2874

2024-09-25 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:7cf85d137ba8f83a54438f53f557225485c3f695

commit r15-3869-g7cf85d137ba8f83a54438f53f557225485c3f695
Author: Jakub Jelinek 
Date:   Wed Sep 25 16:08:33 2024 +0200

c++: Add testcase for DR 2874

Seems we already allow the partial specializations the way the DR clarifies,
so this patch just adds a testcase which verifies that.

2024-09-25  Jakub Jelinek  

* g++.dg/DRs/dr2874.C: New test.

Diff:
---
 gcc/testsuite/g++.dg/DRs/dr2874.C | 13 +
 1 file changed, 13 insertions(+)

diff --git a/gcc/testsuite/g++.dg/DRs/dr2874.C 
b/gcc/testsuite/g++.dg/DRs/dr2874.C
new file mode 100644
index ..10981291c0ec
--- /dev/null
+++ b/gcc/testsuite/g++.dg/DRs/dr2874.C
@@ -0,0 +1,13 @@
+// DR 2874 - Qualified declarations of partial specializations
+// { dg-do compile { target c++11 } }
+
+namespace N {
+  template 
+  struct A;
+}
+
+template <>
+struct N::A ;
+
+template 
+struct N::A ;


[gcc r15-3868] c++: Add testcase for DR 2836

2024-09-25 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:0564d9501ebf11c9f0c541ac79054a38ec791d8c

commit r15-3868-g0564d9501ebf11c9f0c541ac79054a38ec791d8c
Author: Jakub Jelinek 
Date:   Wed Sep 25 16:07:50 2024 +0200

c++: Add testcase for DR 2836

Seems we already handle it the way the DR clarifies, if double/long double
and std::float64_t have the same mode, foo has long double type (while
x + y would be _Float64 in C23), so this patch just adds a testcase which
verifies that.

2024-09-25  Jakub Jelinek  

* g++.dg/DRs/dr2836.C: New test.

Diff:
---
 gcc/testsuite/g++.dg/DRs/dr2836.C | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/gcc/testsuite/g++.dg/DRs/dr2836.C 
b/gcc/testsuite/g++.dg/DRs/dr2836.C
new file mode 100644
index ..88e35a7f3052
--- /dev/null
+++ b/gcc/testsuite/g++.dg/DRs/dr2836.C
@@ -0,0 +1,30 @@
+// DR 2836 - Conversion rank of long double and extended floating-point types
+// { dg-do compile { target c++23 } }
+// { dg-additional-options "-mlong-double-64" { target powerpc*-*-* s390*-*-* 
} }
+
+#include 
+
+#if defined (__STDCPP_FLOAT64_T__) \
+&& __LDBL_MAX_EXP__ == __FLT64_MAX_EXP__ \
+&& __LDBL_MANT_DIG__ == __FLT64_MANT_DIG__ \
+&& __DBL_MAX_EXP__ == __FLT64_MAX_EXP__ \
+&& __DBL_MANT_DIG__ == __FLT64_MANT_DIG__
+auto
+foo (long double x, std::float64_t y)
+{
+  return x + y;
+}
+
+template struct integral_constant {
+  static constexpr T value = v;
+};
+typedef integral_constant false_type;
+typedef integral_constant true_type;
+template
+struct is_same : false_type {};
+template 
+struct is_same : true_type {};
+
+static_assert (is_same ::value);
+
+#endif


[gcc r15-3867] c++: Add testcase for DR 2728

2024-09-25 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:340ef96560da93891418c39d38b5d90f6bd47053

commit r15-3867-g340ef96560da93891418c39d38b5d90f6bd47053
Author: Jakub Jelinek 
Date:   Wed Sep 25 16:07:11 2024 +0200

c++: Add testcase for DR 2728

Seems we already handle delete expressions the way the DR clarifies,
so this patch just adds a testcase which verifies that.

2024-09-25  Jakub Jelinek  

* g++.dg/DRs/dr2728.C: New test.

Diff:
---
 gcc/testsuite/g++.dg/DRs/dr2728.C | 20 
 1 file changed, 20 insertions(+)

diff --git a/gcc/testsuite/g++.dg/DRs/dr2728.C 
b/gcc/testsuite/g++.dg/DRs/dr2728.C
new file mode 100644
index ..3061b8445fc1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/DRs/dr2728.C
@@ -0,0 +1,20 @@
+// DR 2728 - Evaluation of conversions in a delete-expression
+// { dg-do run }
+
+struct S {
+  S (int *x) : p (x) {}
+  operator int * () const { ++s; return p; }
+  int *p;
+  static int s;
+};
+int S::s;
+
+int
+main ()
+{
+  int *a = new int;
+  S s (a);
+  delete s;
+  if (S::s != 1)
+__builtin_abort ();
+}


[gcc r15-3843] options: Regenerate c.opt.urls

2024-09-24 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:1762b7f89eb9d8a1f150ab294344e945c0870399

commit r15-3843-g1762b7f89eb9d8a1f150ab294344e945c0870399
Author: Jakub Jelinek 
Date:   Tue Sep 24 22:21:26 2024 +0200

options: Regenerate c.opt.urls

Forgot to regenerate URLs for the C++23 P2718R0 patch.

2024-09-24  Jakub Jelinek  

* c.opt.urls: Regenerate.

Diff:
---
 gcc/c-family/c.opt.urls | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/c-family/c.opt.urls b/gcc/c-family/c.opt.urls
index 2f1e9f95271b..084dfd297c5a 100644
--- a/gcc/c-family/c.opt.urls
+++ b/gcc/c-family/c.opt.urls
@@ -1268,6 +1268,9 @@ 
UrlSuffix(gcc/C_002b_002b-Dialect-Options.html#index-fno-pretty-templates)
 fprintf-return-value
 UrlSuffix(gcc/Optimize-Options.html#index-fno-printf-return-value)
 
+frange-for-ext-temps
+UrlSuffix(gcc/C_002b_002b-Dialect-Options.html#index-frange-for-ext-temps)
+
 freplace-objc-classes
 
UrlSuffix(gcc/Objective-C-and-Objective-C_002b_002b-Dialect-Options.html#index-freplace-objc-classes)


[gcc r15-3840] c++: Implement C++23 P2718R0 - Wording for P2644R1 Fix for Range-based for Loop [PR107637]

2024-09-24 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:650e91566561870f3d1c8d5b92e6613296ee1a8d

commit r15-3840-g650e91566561870f3d1c8d5b92e6613296ee1a8d
Author: Jakub Jelinek 
Date:   Tue Sep 24 20:19:50 2024 +0200

c++: Implement C++23 P2718R0 - Wording for P2644R1 Fix for Range-based for 
Loop [PR107637]

The following patch implements the C++23 P2718R0 paper
- Wording for P2644R1 Fix for Range-based for Loop.
The patch introduces a new option, -f{,no-}range-for-ext-temps so that
user can control the behavior even in older C++ versions.
The option is on by default in C++23 and later (-fno-range-for-ext-temps
is an error in that case) and in the -std=gnu++11 ... -std=gnu++20 modes
(one can use -fno-range-for-ext-temps to request previous behavior in that
case), and is not enabled by default in -std=c++11 ... -std=c++20 modes
but one can explicitly enable it with -frange-for-ext-temps.
As all the temporaries from __for_range initialization should have life
extended until the end of __for_range scope, this patch disables (for
-frange-for-ext-temps and if !processing_template_decl) CLEANUP_POINT_EXPR 
wrapping
of the __for_range declaration, also disables -Wdangling-reference warning
as well as the rest of extend_ref_init_temps (we know the __for_range 
temporary
is not TREE_STATIC and as all the temporaries from the initializer will be 
life
extended, we shouldn't try to handle temporaries referenced by references 
any
differently) and adds an extra push_stmt_list/pop_stmt_list before
cp_finish_decl of __for_range and after end of the for body and wraps all
that into CLEANUP_POINT_EXPR.
I had to repeat that also for OpenMP range loops because those are handled
differently.

2024-09-24  Jakub Jelinek  

PR c++/107637
gcc/
* omp-general.cc (find_combined_omp_for, find_nested_loop_xform):
Handle CLEANUP_POINT_EXPR like TRY_FINALLY_EXPR.
* doc/invoke.texi (frange-for-ext-temps): Document.  Add
-fconcepts to the C++ option list.
gcc/c-family/
* c.opt (frange-for-ext-temps): New option.
* c-opts.cc (c_common_post_options): Set flag_range_for_ext_temps
for C++23 or later or for C++11 or later in !flag_iso mode if
the option wasn't set by user.
* c-cppbuiltin.cc (c_cpp_builtins): Change __cpp_range_based_for
value for flag_range_for_ext_temps from 201603L to 202212L in C++17
or later.
* c-omp.cc (c_find_nested_loop_xform_r): Handle CLEANUP_POINT_EXPR
like TRY_FINALLY_EXPR.
gcc/cp/
* cp-tree.h: Implement C++23 P2718R0 - Wording for P2644R1 Fix for
Range-based for Loop.
(cp_convert_omp_range_for): Add bool tmpl_p argument.
(find_range_for_decls): Declare.
* parser.cc (cp_convert_range_for): For flag_range_for_ext_temps 
call
push_stmt_list () before cp_finish_decl for range_temp and save it
temporarily to FOR_INIT_STMT.
(cp_convert_omp_range_for): Add tmpl_p argument.  If set, remember
DECL_NAME of range_temp and for cp_finish_decl call restore it 
before
clearing it again, if unset, don't adjust DECL_NAME of range_temp at
all.
(cp_parser_omp_loop_nest): For flag_range_for_ext_temps range for 
add
CLEANUP_POINT_EXPR around sl.  Call find_range_for_decls and adjust
DECL_NAMEs for range fors if not processing_template_decl.  Adjust
cp_convert_omp_range_for caller.  Remove superfluous backslash at 
the
end of line.
* decl.cc (initialize_local_var): For flag_range_for_ext_temps
temporarily clear stmts_are_full_exprs_p rather than set for
for_range__identifier decls.
* call.cc (extend_ref_init_temps): For flag_range_for_ext_temps 
return
init early for for_range__identifier decls.
* semantics.cc (find_range_for_decls): New function.
(finish_for_stmt): Use it.  For flag_range_for_ext_temps if
cp_convert_range_for set FOR_INIT_STMT, pop_stmt_list it and wrap
into CLEANUP_POINT_EXPR.
* pt.cc (tsubst_omp_for_iterator): Adjust tsubst_omp_for_iterator
caller.
(tsubst_stmt) : For flag_range_for_ext_temps if there
are any range fors in the loop nest, add push_stmt_list starting
before the initializations, pop_stmt_list it after the body and wrap
into CLEANUP_POINT_EXPR.  Change DECL_NAME of range for temps from
NULL to for_range_identifier.
gcc/testsuite/
* g++.dg/cpp23/range-for1.C: New test.
* g++.dg/cpp23/range-for2.C: New test.
* g++.dg/cpp23/range-for3.C: New test.
* g++.dg/cpp23/range-for4.C: New test.
* g++.dg/cpp23/range-for5.C: New t

[gcc r15-3838] i386: Fix comment typo

2024-09-24 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:dab450021569811402e02917d7dc1f05fb4626c7

commit r15-3838-gdab450021569811402e02917d7dc1f05fb4626c7
Author: Jakub Jelinek 
Date:   Tue Sep 24 19:00:38 2024 +0200

i386: Fix comment typo

Found a comment typo, fixed as obvious.

2024-09-24  Jakub Jelinek  

* config/i386/i386-expand.cc (ix86_expand_round_builtin): Fix 
comment
typo, insead -> instead.

Diff:
---
 gcc/config/i386/i386-expand.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index 124cb976ec87..39ee9b8662ad 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -12748,7 +12748,7 @@ ix86_expand_round_builtin (const struct 
builtin_description *d,
  /* Skip erasing embedded rounding for below expanders who
 generates multiple insns.  In ix86_erase_embedded_rounding
 the pattern will be transformed to a single set, and emit_insn
-appends the set insead of insert it to chain.  So the insns
+appends the set instead of insert it to chain.  So the insns
 emitted inside define_expander would be ignored.  */
  switch (icode)
{


[gcc r15-3728] i386: Fix up _mm_min_ss etc. handling of zeros and NaNs [PR116738]

2024-09-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:624d3af025e820ede7ec4334f7a2d5d4731c99a9

commit r15-3728-g624d3af025e820ede7ec4334f7a2d5d4731c99a9
Author: Jakub Jelinek 
Date:   Fri Sep 20 09:14:29 2024 +0200

i386: Fix up _mm_min_ss etc. handling of zeros and NaNs [PR116738]

min/max patterns for intrinsics which on x86 result in the second
input operand if the two operands are both zeros or one or both of them
are a NaN shouldn't use SMIN/SMAX RTL, because that is similarly to
MIN_EXPR/MAX_EXPR undefined what will be the result in those cases.

The following patch adds an expander which uses either a new pattern with
UNSPEC_IEEE_M{AX,IN} or use the S{MIN,MAX} representation of the same.

2024-09-20  Uros Bizjak  
Jakub Jelinek  

PR target/116738
* config/i386/subst.md (mask_scalar_operand_arg34,
mask_scalar_expand_op3, round_saeonly_scalar_mask_arg3): New
subst attributes.
* config/i386/sse.md

(_vm3):
Change from define_insn to define_expand, rename the old define_insn
to ...

(*_vm3):
... this.

(_ieee_vm3):
New define_insn.

* gcc.target/i386/sse-pr116738.c: New test.

Diff:
---
 gcc/config/i386/sse.md   | 41 +++-
 gcc/config/i386/subst.md |  3 ++
 gcc/testsuite/gcc.target/i386/sse-pr116738.c | 28 +++
 3 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index ff4f33b7b637..29b0ea3507d5 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -,7 +,27 @@
   (const_string "*")))
(set_attr "mode" "")])
 
-(define_insn 
"_vm3"
+(define_expand 
"_vm3"
+  [(set (match_operand:VFH_128 0 "register_operand")
+   (vec_merge:VFH_128
+ (smaxmin:VFH_128
+   (match_operand:VFH_128 1 "register_operand")
+   (match_operand:VFH_128 2 "nonimmediate_operand"))
+(match_dup 1)
+(const_int 1)))]
+  "TARGET_SSE"
+{
+  if (!flag_finite_math_only || flag_signed_zeros)
+{
+  emit_insn 
(gen__ieee_vm3
+(operands[0], operands[1], operands[2]
+ 
+ ));
+  DONE;
+}
+})
+
+(define_insn 
"*_vm3"
   [(set (match_operand:VFH_128 0 "register_operand" "=x,v")
(vec_merge:VFH_128
  (smaxmin:VFH_128
@@ -3351,6 +3371,25 @@
(set_attr "prefix" "")
(set_attr "mode" "")])
 
+(define_insn 
"_ieee_vm3"
+  [(set (match_operand:VFH_128 0 "register_operand" "=x,v")
+   (vec_merge:VFH_128
+ (unspec:VFH_128
+   [(match_operand:VFH_128 1 "register_operand" "0,v")
+(match_operand:VFH_128 2 "nonimmediate_operand" 
"xm,")]
+   IEEE_MAXMIN)
+(match_dup 1)
+(const_int 1)))]
+  "TARGET_SSE"
+  "@
+   \t{%2, %0|%0, %2}
+   v\t{%2, 
%1, %0|%0, %1, 
%2}"
+  [(set_attr "isa" "noavx,avx")
+   (set_attr "type" "sse")
+   (set_attr "btver2_sse_attr" "maxmin")
+   (set_attr "prefix" "")
+   (set_attr "mode" "")])
+
 (define_mode_attr addsub_cst [(V4DF "5") (V2DF "1")
   (V4SF "5") (V8SF "85")])
 
diff --git a/gcc/config/i386/subst.md b/gcc/config/i386/subst.md
index ca5341320ea8..3722b0d2d53d 100644
--- a/gcc/config/i386/subst.md
+++ b/gcc/config/i386/subst.md
@@ -366,6 +366,8 @@
 (define_subst_attr "mask_scalarcz_operand4" "mask_scalarcz" "" "%{%5%}%N4")
 (define_subst_attr "mask_scalar4_dest_false_dep_for_glc_cond" "mask_scalar" 
"1" "operands[4] == CONST0_RTX(mode)")
 (define_subst_attr "mask_scalarc_dest_false_dep_for_glc_cond" "mask_scalarc" 
"1" "operands[3] == CONST0_RTX(V8HFmode)")
+(define_subst_attr "mask_scalar_operand_arg34" "mask_scalar" "" ", 
operands[3], operands[4]")
+(define_subst_attr "mask_scalar_expand_op3" "mask_scalar" "3" "5")
 
 (define_subst "mask_scalar"
   [(set (match_operand:SUBST_V 0)
@@ -473,6 +475,7 @@
 (define_subst_attr "round_saeonly_scalar_constraint" "round_saeonly_scalar" 
"vm" "v")
 (define_subst_attr "round_saeonly_scalar_prefix" "round_saeonly_scalar" "vex" 
"evex")
 (define_subst_attr "round_saeonly_scalar_nimm_predicate" 
"round_saeonly_scalar" "nonimmediate_operand" "register_operand")
+(define_subst_attr "round_saeonly_scalar_mask_arg3" "round_saeonly_scalar" "" 
", operands[]")
 
 (define_subst "round_saeonly_scalar"
   [(set (match_operand:SUBST_V 0)
diff --git a/gcc/testsuite/gcc.target/i386/sse-pr116738.c 
b/gcc/testsuite/gcc.target/i386/sse-pr116738.c
new file mode 100644
index ..5b31bf247488
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/sse-pr116738.c
@@ -0,0 +1,28 @@
+/* PR target/116738 */
+/* { dg-do run } */
+/* { dg-options "-O2 -msse" } */
+/* { dg-require-effective-target sse } */
+
+#include "sse-check.h"
+
+static inline float
+clamp (float f)
+{
+  __m128 v = _mm_set_ss (f);
+  __m128 zero = _mm_setzero_ps ();
+  __

[gcc r15-3718] dwarf2asm: Use constexpr for eh_data_format_name initialization for C++14

2024-09-19 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:16dda95e39fa04e5ab43486a980e8866ee12efd7

commit r15-3718-g16dda95e39fa04e5ab43486a980e8866ee12efd7
Author: Jakub Jelinek 
Date:   Thu Sep 19 17:53:27 2024 +0200

dwarf2asm: Use constexpr for eh_data_format_name initialization for C++14

Similarly to the previous patch, dwarf2asm.cc had
HAVE_DESIGNATED_INITIALIZERS support, and as fallback a huge switch.
The switch from what I can see is expanded as a jump table with 256
label pointers and code at those labels then loads addresses of
string literals.
The following patch instead uses a table with 256 const char * pointers,
NULL for ICE, non-NULL for returning something, similarly to the
HAVE_DESIGNATED_INITIALIZERS case.

2024-09-19  Jakub Jelinek  

* dwarf2asm.cc (eh_data_format_name): Use constexpr initialization
of format_names table for C++14 instead of a large switch.

Diff:
---
 gcc/dwarf2asm.cc | 19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/gcc/dwarf2asm.cc b/gcc/dwarf2asm.cc
index 6c835bafbc46..72e831af99ed 100644
--- a/gcc/dwarf2asm.cc
+++ b/gcc/dwarf2asm.cc
@@ -488,14 +488,22 @@ eh_data_format_name (int format)
 {
 #if HAVE_DESIGNATED_INITIALIZERS
 #define S(p, v)[p] = v,
+#elif __cpp_constexpr >= 201304L
+#define S(p, v)names[p] = v;
 #else
 #define S(p, v)case p: return v;
 #endif
 
 #if HAVE_DESIGNATED_INITIALIZERS
   __extension__ static const char * const format_names[256] = {
+#elif __cpp_constexpr >= 201304L
+  static constexpr struct format_names_s {
+const char *names[256];
+constexpr format_names_s () : names {}
+{
 #else
-  switch (format) {
+  switch (format)
+{
 #endif
 
   S(DW_EH_PE_absptr, "absolute")
@@ -635,8 +643,15 @@ eh_data_format_name (int format)
   gcc_assert (format >= 0 && format < 0x100 && format_names[format]);
 
   return format_names[format];
+#elif __cpp_constexpr >= 201304L
+}
+  } format_names;
+
+  gcc_assert (format >= 0 && format < 0x100 && format_names.names[format]);
+
+  return format_names.names[format];
 #else
-  }
+}
   gcc_unreachable ();
 #endif
 }


[gcc r13-9025] testsuite: Fix up builtin-clear-padding-3.c for -funsigned-char

2024-09-13 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:504c8e4dc26501fb68f0ae784b45dba0f68b4f4a

commit r13-9025-g504c8e4dc26501fb68f0ae784b45dba0f68b4f4a
Author: Jakub Jelinek 
Date:   Thu Jul 18 09:22:10 2024 +0200

testsuite: Fix up builtin-clear-padding-3.c for -funsigned-char

As reported on gcc-regression, this test FAILs on aarch64, but my
r15-2090 change didn't change anything on the generated assembly,
just added the forgotten dg-do run directive to the test, so the
test has been failing forever, just we didn't know it.

I can actually reproduce it on x86_64 with -funsigned-char too,
s2.b.a has int type and -1 is stored to it, so we should compare
it against -1 rather than (char) -1; the latter is appropriate for
testing char fields into which we've stored -1.

2024-07-18  Jakub Jelinek  

* c-c++-common/torture/builtin-clear-padding-3.c (main): Compare
s2.b.a against -1 rather than (char) -1.

(cherry picked from commit 958ee138748fae4371e453eb9b357f576abbe83e)

Diff:
---
 gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c 
b/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
index 27bf8f6dd734..2c673169e134 100644
--- a/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
+++ b/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
@@ -34,7 +34,7 @@ main ()
   foo (&s1, 0);
   foo (&s2, 0);
   __builtin_clear_padding (&s2);
-  if (s2.b.a != (char) -1)
+  if (s2.b.a != -1)
 __builtin_abort ();
   __builtin_clear_padding (&s2.b.a);
   __builtin_memset (&s2.b.a + 1, 0, sizeof (union U) - sizeof (s2.b.a));


[gcc(refs/vendors/redhat/heads/gcc-13-branch)] Merge commit 'r13-9024-g973c6ea242cea7d95c2888ec6dde39b5cbb9dbb3' into redhat/gcc-13-branch

2024-09-13 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:2fcca36eb1d34066437939cf1b54810a75dd553f

commit 2fcca36eb1d34066437939cf1b54810a75dd553f
Merge: 03b1a31f9807 973c6ea242ce
Author: Jakub Jelinek 
Date:   Fri Sep 13 16:15:02 2024 +0200

Merge commit 'r13-9024-g973c6ea242cea7d95c2888ec6dde39b5cbb9dbb3' into 
redhat/gcc-13-branch

Diff:

 gcc/ChangeLog  | 627 +
 gcc/DATESTAMP  |   2 +-
 gcc/c-family/ChangeLog |  10 +
 gcc/c-family/c-warn.cc |  13 +-
 gcc/c/ChangeLog|  10 +
 gcc/common/config/aarch64/aarch64-common.cc|  35 +-
 gcc/config/aarch64/aarch64-c.cc|   7 +-
 gcc/config/aarch64/aarch64-cores.def   |   2 +
 gcc/config/aarch64/aarch64-sve-builtins-base.cc|  25 +-
 gcc/config/aarch64/aarch64-sve.md  |  20 +-
 gcc/config/aarch64/aarch64-tune.md |   2 +-
 gcc/config/aarch64/aarch64.cc  |  52 +-
 gcc/config/aarch64/aarch64.h   |  10 +-
 gcc/config/aarch64/aarch64.md  |   4 +-
 gcc/config/alpha/alpha.md  |  10 +-
 gcc/config/arm/arm.cc  |  87 ++-
 gcc/config/arm/mve.md  |   2 +-
 gcc/config/avr/avr-dimode.md   |  26 +-
 gcc/config/avr/avr-protos.h|   2 +-
 gcc/config/avr/avr.cc  |  46 +-
 gcc/config/avr/avr.md  |  42 +-
 gcc/config/i386/avx512dqintrin.h   |  16 +-
 gcc/config/i386/avx512fp16intrin.h |   4 +-
 gcc/config/i386/avx512vlbwintrin.h |   4 +-
 gcc/config/i386/avx512vlintrin.h   |   2 +-
 gcc/config/i386/constraints.md |   2 +-
 gcc/config/i386/i386-options.cc|  77 ++-
 gcc/config/i386/i386.cc|  48 +-
 gcc/config/i386/i386.md|   2 +-
 gcc/config/i386/prfchiintrin.h |   9 +
 gcc/config/i386/x86-tune-costs.h   |   4 +-
 gcc/config/loongarch/loongarch.cc  |   2 +-
 gcc/config/loongarch/loongarch.h   |   7 -
 gcc/config/pa/pa.cc|   1 +
 gcc/config/pa/pa.md|  18 -
 gcc/config/riscv/riscv.cc  |   5 +-
 gcc/config/rs6000/altivec.md   | 222 ++--
 gcc/config/rs6000/rs6000-logue.cc  |  54 +-
 gcc/config/rs6000/rs6000.cc|  41 +-
 gcc/config/rs6000/rs6000.md|  21 +-
 gcc/config/rs6000/vsx.md   |  28 +-
 gcc/config/s390/3931.md|   7 -
 gcc/config/s390/s390.md|   5 +-
 gcc/config/s390/vector.md  |   6 +-
 gcc/config/sh/sh.cc|  12 +-
 gcc/cp/ChangeLog   |  17 +
 gcc/cp/method.cc   |   1 +
 gcc/cp/typeck.cc   |  22 +-
 gcc/cse.cc |   4 +-
 gcc/doc/invoke.texi|  18 +-
 gcc/expmed.cc  |   4 +-
 gcc/fortran/ChangeLog  | 100 
 gcc/fortran/dependency.cc  |  32 ++
 gcc/fortran/expr.cc|   5 +
 gcc/fortran/gfortran.h |   4 +
 gcc/fortran/iresolve.cc|   4 +
 gcc/fortran/trans-array.cc |  52 +-
 gcc/fortran/trans-expr.cc  |  49 +-
 gcc/fortran/trans-intrinsic.cc |  80 ++-
 gcc/fortran/trans-stmt.cc  |  43 +-
 gcc/fortran/trans-types.cc |   4 +-
 gcc/gimple-fold.cc |  12 +-
 gcc/ipa-icf-gimple.cc  |   4 +
 gcc/ipa-modref.cc  |   4 +-
 gcc/jit/ChangeLog  |   9 +
 gcc/jit/jit-recording.cc   |   1 +
 gcc/opt-suggestions.cc |   2 +-
 gcc/opts-common.cc |   6 +-
 gcc/testsuite/ChangeLog| 421 ++
 gcc/testsuite/c-c++-common/Warray-compare-3.c  |  13 +
 .../c-c++-common/torture/builtin-clear-padding-1.c |   1 +
 .../c-c++-common/torture/builtin-clear-padding-2.c |   1 +
 .../c-c++-common/torture/builtin-clear-padding-3.c |   1 +
 .../c-c++-common/torture/builtin-clear-padding-4.c |   4 +-
 .../c-c++-common/torture/builtin-clear-padding-5.c |   1 +
 .../c-c++-common/torture/builtin-clear-padding-6.c |  28 +
 gcc/testsuite/c-c++-common/to

[gcc/redhat/heads/gcc-13-branch] (187 commits) Merge commit 'r13-9024-g973c6ea242cea7d95c2888ec6dde39b5cbb

2024-09-13 Thread Jakub Jelinek via Gcc-cvs
The branch 'redhat/heads/gcc-13-branch' was updated to point to:

 2fcca36eb1d3... Merge commit 'r13-9024-g973c6ea242cea7d95c2888ec6dde39b5cbb

It previously pointed to:

 03b1a31f9807... Merge commit 'r13-8838-g7813d94393f60ac641265cb3fc3a446f9f3

Diff:

Summary of changes (added commits):
---

  2fcca36... Merge commit 'r13-9024-g973c6ea242cea7d95c2888ec6dde39b5cbb
  973c6ea... c++: Fix get_member_function_from_ptrfunc with -fsanitize=b (*)
  9b4a7d9... libiberty: Fix up > 64K section handling in simple_object_e (*)
  e5839ca... i386: Fix up __builtin_ia32_b{extr{,i}_u{32,64},zhi_{s,d}i} (*)
  e5a9c15... testsuite: Fix up pr116034.c test for big/pdp endian [PR116 (*)
  aaa82d6... ssa: Fix up maybe_rewrite_mem_ref_base complex type handlin (*)
  1880ff0... gimple-fold: Fix up __builtin_clear_padding lowering [PR115 (*)
  ff84211... Daily bump. (*)
  934245a... Daily bump. (*)
  2d7b4df... Daily bump. (*)
  5ceea2a... libstdc++: Fix std::chrono::tzdb to work with vanguard form (*)
  e9b2f1f... libstdc++: Support link chains in std::chrono::tzdb::locate (*)
  2913d33... [libstdc++] define zoneinfo_dir_override on vxworks (*)
  04a8e50... Daily bump. (*)
  0a16b1b... doc: Enhance Intel CPU documentation (*)
  61fd9b0... Daily bump. (*)
  fbcc672... Daily bump. (*)
  750bb0c... Daily bump. (*)
  8ad345a... Daily bump. (*)
  e83df98... ipa: Don't disable function parameter analysis for fat LTO (*)
  c56dc83... Arm: Fix incorrect tailcall-generation for indirect calls [ (*)
  5a081da... Daily bump. (*)
  cc2c50b... Daily bump. (*)
  e152aee... i386: Fix vfpclassph non-optimizied intrin (*)
  f364a43... RISC-V: fix TARGET_PROMOTE_FUNCTION_MODE hook for libcalls (*)
  032b6e3... Daily bump. (*)
  5e049ad... Check avx upper register for parallel. (*)
  d9decdc... Daily bump. (*)
  85f323c... Daily bump. (*)
  9b9e33e... Daily bump. (*)
  d473609... Daily bump. (*)
  2c88e24... Daily bump. (*)
  154639f... Daily bump. (*)
  d4e36c7... Daily bump. (*)
  4f26b4f... Daily bump. (*)
  891a312... Daily bump. (*)
  bdb1cb6... Daily bump. (*)
  ea9c508... Fix testcase failure. (*)
  aea3742... Align ix86_{move_max,store_max} with vectorizer. (*)
  39d5de3... Daily bump. (*)
  3e5cf9f... [testsuite] [arm] [vect] adjust mve-vshr test [PR113281] (*)
  95c2bc2... Daily bump. (*)
  9f54144... Daily bump. (*)
  e469654... Compare loop bounds in ipa-icf (*)
  49bcfb7... Daily bump. (*)
  58c8882... AVR: target/116407 - Fix linker error "relocation truncated (*)
  b8fe699... Daily bump. (*)
  2466e10... Daily bump. (*)
  959d652... aarch64: Fix bogus cnot optimisation [PR114603] (*)
  22c6a11... aarch64: Fix expansion of svsudot [PR114607] (*)
  73d22be... Daily bump. (*)
  8796e33... Daily bump. (*)
  a79d7cc... Daily bump. (*)
  7b0e478... Daily bump. (*)
  617562e... Refine constraint "Bk" to define_special_memory_constraint. (*)
  3689565... Daily bump. (*)
  3008807... Daily bump. (*)
  419c533... Daily bump. (*)
  12ba140... c++: local class memfn synth from uneval context [PR113063] (*)
  7830d92... Daily bump. (*)
  617bbae... Daily bump. (*)
  9d36882... Daily bump. (*)
  f6624ad... hppa: Fix (plus (plus (mult (a) (mem_shadd_constant)) (b))  (*)
  73064a2... sh: Don't call make_insn_raw in sh_recog_treg_set_expr [PR1 (*)
  87cb011... Daily bump. (*)
  bf0673e... libgomp: Remove bogus warnings from privatized-ref-2.f90. (*)
  7195144... Fortran: Suppress bogus used uninitialized warnings [PR1088 (*)
  dcc9a85... Daily bump. (*)
  991acbd... Daily bump. (*)
  4e0846d... Daily bump. (*)
  65b8906... Daily bump. (*)
  7928ec5... Daily bump. (*)
  fa6c24e... Daily bump. (*)
  d80abba... i386: Add non-optimize prefetchi intrins (*)
  320a9c5... Daily bump. (*)
  b2ab34b... i386: Use _mm_setzero_ps/d instead of _mm_avx512_setzero_ps (*)
  bb15c4c... i386: Fix AVX512 intrin macro typo (*)
  69272e4... Daily bump. (*)
  920adcb... Daily bump. (*)
  4e03c89... Daily bump. (*)
  f280772... Daily bump. (*)
  58b3e55... Daily bump. (*)
  46d68bc... libstdc++: Fix std::vector for -std=gnu++14 -fconcept (*)
  9a4603d... rs6000: Catch unsupported ABI errors when using -mrop-prote (*)
  63b1b3e... rs6000: Error on CPUs and ABIs that don't support the ROP p (*)
  77fd352... rs6000: ROP - Emit hashst and hashchk insns on Power8 and l (*)
  bc51e5a... rs6000: Compute rop_hash_save_offset for non-Altivec compil (*)
  9bbdec4... rs6000: Update ELFv2 stack frame comment showing the correc (*)
  0575d3b... Daily bump. (*)
  b352766... Fixup unaligned load/store cost for znver4 (*)
  dec571e... i386: Change prefetchi output template (*)
  e504184... [powerpc] [testsuite] reorder dg directives [PR106069] (*)
  8a470d7... Daily bump. (*)
  4ce7c81... [PR115565] cse: Don't use a valid regno for non-register in (*)
  9778ad5... Daily bump. (*)
  ae6d5dc... Fortran: character array constructor with >= 4 constant ele (*)
  44e07e4... Daily bump. (*)
  a23deb1... Avoid undefined behaviour in build_option_suggestions (*)

[gcc r15-3628] c++: Don't emit deprecated/unavailable attribute diagnostics when creating cdtor thunks [PR116678]

2024-09-13 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:b7b67732e20217196f2a13a10fc3df4605b2b2ab

commit r15-3628-gb7b67732e20217196f2a13a10fc3df4605b2b2ab
Author: Jakub Jelinek 
Date:   Fri Sep 13 16:13:01 2024 +0200

c++: Don't emit deprecated/unavailable attribute diagnostics when creating 
cdtor thunks [PR116678]

Another spot where we mark_used a function (in this case ctor or dtor)
even when it is just artificially used inside of thunks (emitted on mingw
with -Os for the testcase).

2024-09-13  Jakub Jelinek  

PR c++/116678
* optimize.cc: Include decl.h.
(maybe_thunk_body): Temporarily change deprecated_state to
UNAVAILABLE_DEPRECATED_SUPPRESS.

* g++.dg/warn/deprecated-20.C: New test.

Diff:
---
 gcc/cp/optimize.cc|  6 ++
 gcc/testsuite/g++.dg/warn/deprecated-20.C | 16 
 2 files changed, 22 insertions(+)

diff --git a/gcc/cp/optimize.cc b/gcc/cp/optimize.cc
index b8791d8a9635..8429d856728f 100644
--- a/gcc/cp/optimize.cc
+++ b/gcc/cp/optimize.cc
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "target.h"
 #include "cp-tree.h"
+#include "decl.h"
 #include "stringpool.h"
 #include "cgraph.h"
 #include "debug.h"
@@ -287,6 +288,11 @@ maybe_thunk_body (tree fn, bool force)
   if (ctor_omit_inherited_parms (fns[0]))
 return 0;
 
+  /* Don't diagnose deprecated or unavailable cdtors just because they
+ have thunks emitted for them.  */
+  auto du = make_temp_override (deprecated_state,
+   UNAVAILABLE_DEPRECATED_SUPPRESS);
+
   DECL_ABSTRACT_P (fn) = false;
   if (!DECL_WEAK (fn))
 {
diff --git a/gcc/testsuite/g++.dg/warn/deprecated-20.C 
b/gcc/testsuite/g++.dg/warn/deprecated-20.C
new file mode 100644
index ..1911aeff4e37
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/deprecated-20.C
@@ -0,0 +1,16 @@
+// PR c++/116678
+// { dg-do compile }
+// { dg-options "-Os -pedantic" }
+
+struct S
+{
+  [[deprecated]] S () { s = 1; }   // { dg-bogus "'S::S\\\(\\\)' is 
deprecated" }
+  S (int x) { s = x; } // { dg-warning "C\\\+\\\+11 attributes 
only available with" "" { target c++98_only } .-1 }
+  ~S () {}
+  int s;
+};
+
+int
+main ()
+{
+}


[gcc r15-3627] libcpp: Fix up UB in finish_embed

2024-09-13 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:4963eb76918295a08a7c216bea986ab8e65c1cf8

commit r15-3627-g4963eb76918295a08a7c216bea986ab8e65c1cf8
Author: Jakub Jelinek 
Date:   Fri Sep 13 16:11:05 2024 +0200

libcpp: Fix up UB in finish_embed

Jonathan reported on IRC that certain unnamed proprietary static analyzer
is unhappy about the new finish_embed function and it is actually right.
On a testcase like:
 #embed __FILE__ limit (0) if_empty (0)
params->if_empty.count is 1, limit is 0, so count is 0 (we need just
a single token and one fits into pfile->directive_result).  Because
count is 0, we don't allocate toks, so it stays NULL, and then in
1301  if (prefix->count)
1302{
1303  *tok = *prefix->base_run.base;
1304  tok = toks;
1305  tokenrun *cur_run = &prefix->base_run;
1306  while (cur_run)
1307{
1308  size_t cnt = (cur_run->next ? cur_run->limit
1309: prefix->cur_token) - cur_run->base;
1310  cpp_token *t = cur_run->base;
1311  if (cur_run == &prefix->base_run)
1312{
1313  t++;
1314  cnt--;
1315}
1316  memcpy (tok, t, cnt * sizeof (cpp_token));
1317  tok += cnt;
1318  cur_run = cur_run->next;
1319}
1320}
the *tok = *prefix->base_run.base; assignment will copy the only
token.  cur_run is still non-NULL, cnt will be initially 1 and
then decremented to 0, but we invoke UB because we do
memcpy (NULL, cur_run->base + 1, 0 * sizeof (cpp_token));
and then the loop stops because cur_run->next must be NULL.

As we don't really copy anything, toks can be anything non-NULL,
so the following patch fixes that by initializing toks also to
&pfile->directive_result (just something known to be non-NULL).
This should be harmless even for the
 #embed __FILE__ limit (1)
case (no non-empty prefix/suffix) where toks isn't allocated
either, but in that case prefix->count will be 0 and in the
1321  for (size_t i = 0; i < limit; ++i)
1322{
1323  tok->src_loc = params->loc;
1324  tok->type = CPP_NUMBER;
1325  tok->flags = NO_EXPAND;
1326  if (i == 0)
1327tok->flags |= PREV_WHITE;
1328  tok->val.str.text = s;
1329  tok->val.str.len = sprintf ((char *) s, "%d", buffer[i]);
1330  s += tok->val.str.len + 1;
1331  if (tok == &pfile->directive_result)
1332tok = toks;
1333  else
1334tok++;
1335  if (i < limit - 1)
1336{
1337  tok->src_loc = params->loc;
1338  tok->type = CPP_COMMA;
1339  tok->flags = NO_EXPAND;
1340  tok++;
1341}
1342}
loop limit will be 1, so tok is initially &pfile->directive_result,
that is stilled in, then tok = toks; (previously setting tok to NULL,
now to &pfile->directive_result again) and because 0 < 1 - 1 is
false, nothing further will happen and the loop will finish (and as
params->suffix.count will be 0, nothing further will use tok).

2024-09-13  Jakub Jelinek  

* files.cc (finish_embed): Initialize toks to tok rather
than NULL.

Diff:
---
 libcpp/files.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcpp/files.cc b/libcpp/files.cc
index 8aff0149cbee..031169978e72 100644
--- a/libcpp/files.cc
+++ b/libcpp/files.cc
@@ -1284,7 +1284,7 @@ finish_embed (cpp_reader *pfile, _cpp_file *file,
 }
   uchar *s = len ? _cpp_unaligned_alloc (pfile, len) : NULL;
   _cpp_buff *tok_buff = NULL;
-  cpp_token *toks = NULL, *tok = &pfile->directive_result;
+  cpp_token *tok = &pfile->directive_result, *toks = tok;
   size_t count = 0;
   if (limit)
 count = (params->prefix.count + limit * 2 - 1


[gcc r13-9024] c++: Fix get_member_function_from_ptrfunc with -fsanitize=bounds [PR116449]

2024-09-13 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:973c6ea242cea7d95c2888ec6dde39b5cbb9dbb3

commit r13-9024-g973c6ea242cea7d95c2888ec6dde39b5cbb9dbb3
Author: Jakub Jelinek 
Date:   Tue Sep 10 18:32:58 2024 +0200

c++: Fix get_member_function_from_ptrfunc with -fsanitize=bounds [PR116449]

The following testcase is miscompiled, because
get_member_function_from_ptrfunc
emits something like
(((FUNCTION.__pfn & 1) != 0)
 ? ptr + FUNCTION.__delta + FUNCTION.__pfn - 1
 : FUNCTION.__pfn) (ptr + FUNCTION.__delta, ...)
or so, so FUNCTION tree is used there 5 times.  There is
if (TREE_SIDE_EFFECTS (function)) function = save_expr (function);
but in this case function doesn't have side-effects, just nested ARRAY_REFs.
Now, if all the FUNCTION trees would be shared, it would work fine,
FUNCTION is evaluated in the first operand of COND_EXPR; but unfortunately
that isn't the case, both the BIT_AND_EXPR shortening and conversion to
bool done for build_conditional_expr actually unshare_expr that first
expression, but none of the other 4 are unshared.  With -fsanitize=bounds,
.UBSAN_BOUNDS calls are added to the ARRAY_REFs and use save_expr to avoid
evaluating the argument multiple times, but because that FUNCTION tree is
first used in the second argument of COND_EXPR (i.e. conditionally), the
SAVE_EXPR initialization is done just there and then the third argument
of COND_EXPR just uses the uninitialized temporary and so does the first
argument computation as well.

The following patch fixes that by doing save_expr even if 
!TREE_SIDE_EFFECTS,
but to avoid doing that too often only if !nonvirtual and if the expression
isn't a simple decl.

2024-09-10  Jakub Jelinek  

PR c++/116449
* typeck.cc (get_member_function_from_ptrfunc): Use save_expr
on instance_ptr and function even if it doesn't have side-effects,
as long as it isn't a decl.

* g++.dg/ubsan/pr116449.C: New test.

(cherry picked from commit 0008050b9d6046ba4e811a03b406fb5d98707cae)

Diff:
---
 gcc/cp/typeck.cc  | 19 ---
 gcc/testsuite/g++.dg/ubsan/pr116449.C | 14 ++
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index 470bb2ee5f71..2b29bdc4d70a 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -4178,10 +4178,23 @@ get_member_function_from_ptrfunc (tree 
*instance_ptrptr, tree function,
   if (!nonvirtual && is_dummy_object (instance_ptr))
nonvirtual = true;
 
-  if (TREE_SIDE_EFFECTS (instance_ptr))
-   instance_ptr = instance_save_expr = save_expr (instance_ptr);
+  /* Use save_expr even when instance_ptr doesn't have side-effects,
+unless it is a simple decl (save_expr won't do anything on
+constants), so that we don't ubsan instrument the expression
+multiple times.  See PR116449.  */
+  if (TREE_SIDE_EFFECTS (instance_ptr)
+ || (!nonvirtual && !DECL_P (instance_ptr)))
+   {
+ instance_save_expr = save_expr (instance_ptr);
+ if (instance_save_expr == instance_ptr)
+   instance_save_expr = NULL_TREE;
+ else
+   instance_ptr = instance_save_expr;
+   }
 
-  if (TREE_SIDE_EFFECTS (function))
+  /* See above comment.  */
+  if (TREE_SIDE_EFFECTS (function)
+ || (!nonvirtual && !DECL_P (function)))
function = save_expr (function);
 
   /* Start by extracting all the information from the PMF itself.  */
diff --git a/gcc/testsuite/g++.dg/ubsan/pr116449.C 
b/gcc/testsuite/g++.dg/ubsan/pr116449.C
new file mode 100644
index ..f13368a51b00
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ubsan/pr116449.C
@@ -0,0 +1,14 @@
+// PR c++/116449
+// { dg-do compile }
+// { dg-options "-O2 -Wall -fsanitize=undefined" }
+
+struct C { void foo (int); void bar (); int c[16]; };
+typedef void (C::*P) ();
+struct D { P d; };
+static D e[1] = { { &C::bar } };
+
+void
+C::foo (int x)
+{
+  (this->*e[c[x]].d) ();
+}


[gcc r13-9020] ssa: Fix up maybe_rewrite_mem_ref_base complex type handling [PR116034]

2024-09-13 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:aaa82d63fed5978a0bc7136a3922d280576ce257

commit r13-9020-gaaa82d63fed5978a0bc7136a3922d280576ce257
Author: Jakub Jelinek 
Date:   Tue Jul 23 10:50:29 2024 +0200

ssa: Fix up maybe_rewrite_mem_ref_base complex type handling [PR116034]

The folding into REALPART_EXPR is correct, used only when the mem_offset
is zero, but for IMAGPART_EXPR it didn't check the exact offset value (just
that it is not 0).
The following patch fixes that by using IMAGPART_EXPR only if the offset
is right and using BITFIELD_REF or whatever else otherwise.

2024-07-23  Jakub Jelinek  
Andrew Pinski  

PR tree-optimization/116034
* tree-ssa.cc (maybe_rewrite_mem_ref_base): Only use IMAGPART_EXPR
if MEM_REF offset is equal to element type size.

* gcc.dg/pr116034.c: New test.

(cherry picked from commit b9cefd67a2a464a3c9413e6b3f28e7dc7a9ef162)

Diff:
---
 gcc/testsuite/gcc.dg/pr116034.c | 22 ++
 gcc/tree-ssa.cc |  5 -
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/pr116034.c b/gcc/testsuite/gcc.dg/pr116034.c
new file mode 100644
index ..9a31de034246
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116034.c
@@ -0,0 +1,22 @@
+/* PR tree-optimization/116034 */
+/* { dg-do run } */
+/* { dg-options "-O1 -fno-strict-aliasing" } */
+
+int g;
+
+static inline int
+foo (_Complex unsigned short c)
+{
+  __builtin_memmove (&g, 1 + (char *) &c, 2);
+  return g;
+}
+
+int
+main ()
+{
+  if (__SIZEOF_SHORT__ == 2
+  && __CHAR_BIT__ == 8
+  && (foo (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__ ? 0x100 : 1)
+ != (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__ ? 1 : 0x100)))
+__builtin_abort ();
+}
diff --git a/gcc/tree-ssa.cc b/gcc/tree-ssa.cc
index b0b3895af1c9..74ede9cc9cf8 100644
--- a/gcc/tree-ssa.cc
+++ b/gcc/tree-ssa.cc
@@ -1529,7 +1529,10 @@ maybe_rewrite_mem_ref_base (tree *tp, bitmap 
suitable_for_renaming)
}
   else if (TREE_CODE (TREE_TYPE (sym)) == COMPLEX_TYPE
   && useless_type_conversion_p (TREE_TYPE (*tp),
-TREE_TYPE (TREE_TYPE (sym
+TREE_TYPE (TREE_TYPE (sym)))
+  && (integer_zerop (TREE_OPERAND (*tp, 1))
+  || tree_int_cst_equal (TREE_OPERAND (*tp, 1),
+ TYPE_SIZE_UNIT (TREE_TYPE (*tp)
{
  *tp = build1 (integer_zerop (TREE_OPERAND (*tp, 1))
? REALPART_EXPR : IMAGPART_EXPR,


[gcc r13-9019] gimple-fold: Fix up __builtin_clear_padding lowering [PR115527]

2024-09-13 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:1880ff0dbd814cf1e7dd53dd810f372a94d66d39

commit r13-9019-g1880ff0dbd814cf1e7dd53dd810f372a94d66d39
Author: Jakub Jelinek 
Date:   Wed Jul 17 11:38:33 2024 +0200

gimple-fold: Fix up __builtin_clear_padding lowering [PR115527]

The builtin-clear-padding-6.c testcase fails as clear_padding_type
doesn't correctly recompute the buf->size and buf->off members after
expanding clearing of an array using a runtime loop.
buf->size should be in that case the offset after which it should continue
with next members or padding before them modulo UNITS_PER_WORD and
buf->off that offset minus buf->size.  That is what the code was doing,
but with off being the start of the loop cleared array, not its end.
So, the last hunk in gimple-fold.cc fixes that.
When adding the testcase, I've noticed that the
c-c++-common/torture/builtin-clear-padding-* tests, although clearly
written as runtime tests to test the builtins at runtime, didn't have
{ dg-do run } directive and were just compile tests because of that.
When adding that to the tests, builtin-clear-padding-1.c was already
failing without that clear_padding_type hunk too, but
builtin-clear-padding-5.c was still failing even after the change.
That is due to a bug in clear_padding_flush which the patch fixes as
well - when clear_padding_flush is called with full=true (that happens
at the end of the whole __builtin_clear_padding or on those array
padding clears done by a runtime loop), it wants to flush all the pending
padding clearings rather than just some.  If it is at the end of the whole
object, it decreases wordsize when needed to make sure the code never writes
including RMW cycles to something outside of the object:
  if ((unsigned HOST_WIDE_INT) (buf->off + i + wordsize)
  > (unsigned HOST_WIDE_INT) buf->sz)
{
  gcc_assert (wordsize > 1);
  wordsize /= 2;
  i -= wordsize;
  continue;
}
but if it is full==true flush in the middle, this doesn't happen, but we
still process just the buffer bytes before the current end.  If that end
is not on a wordsize boundary, e.g. on the builtin-clear-padding-5.c test
the last chunk is 2 bytes, '\0', '\xff', i is 16 and end is 18,
nonzero_last might be equal to the end - i, i.e. 2 here, but still all_ones
might be true, so in some spots we just didn't emit any clearing in that
last chunk.

2024-07-17  Jakub Jelinek  

PR middle-end/115527
* gimple-fold.cc (clear_padding_flush): Introduce endsize
variable and use it instead of wordsize when comparing it against
nonzero_last.
(clear_padding_type): Increment off by sz.

* c-c++-common/torture/builtin-clear-padding-1.c: Add dg-do run
directive.
* c-c++-common/torture/builtin-clear-padding-2.c: Likewise.
* c-c++-common/torture/builtin-clear-padding-3.c: Likewise.
* c-c++-common/torture/builtin-clear-padding-4.c: Likewise.
* c-c++-common/torture/builtin-clear-padding-5.c: Likewise.
* c-c++-common/torture/builtin-clear-padding-6.c: New test.

(cherry picked from commit 8b5919bae11754f4b65a17e63663d3143f9615ac)

Diff:
---
 gcc/gimple-fold.cc | 12 ++
 .../c-c++-common/torture/builtin-clear-padding-1.c |  1 +
 .../c-c++-common/torture/builtin-clear-padding-2.c |  1 +
 .../c-c++-common/torture/builtin-clear-padding-3.c |  1 +
 .../c-c++-common/torture/builtin-clear-padding-4.c |  4 ++--
 .../c-c++-common/torture/builtin-clear-padding-5.c |  1 +
 .../c-c++-common/torture/builtin-clear-padding-6.c | 28 ++
 7 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index a61bfcee4e7a..5bdd1d08a265 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -4235,7 +4235,8 @@ clear_padding_flush (clear_padding_struct *buf, bool full)
  i -= wordsize;
  continue;
}
-  for (size_t j = i; j < i + wordsize && j < end; j++)
+  size_t endsize = end - i > wordsize ? wordsize : end - i;
+  for (size_t j = i; j < i + endsize; j++)
{
  if (buf->buf[j])
{
@@ -4264,12 +4265,12 @@ clear_padding_flush (clear_padding_struct *buf, bool 
full)
   if (padding_bytes)
{
  if (nonzero_first == 0
- && nonzero_last == wordsize
+ && nonzero_last == endsize
  && all_ones)
{
  /* All bits are padding and we had some padding
 before too.  Just extend it.  */
- padding_bytes += wordsize;
+ padding_bytes += endsize;
  continue;
}
  if (all_ones && nonzero_first == 0)
@@ -4309,7 +4310,7 @@ clear_padding_flush (clea

[gcc r13-9023] libiberty: Fix up > 64K section handling in simple_object_elf_copy_lto_debug_section [PR116614]

2024-09-13 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:9b4a7d907d90ba7b7787433ab66eaf6112c33ffb

commit r13-9023-g9b4a7d907d90ba7b7787433ab66eaf6112c33ffb
Author: Jakub Jelinek 
Date:   Sat Sep 7 09:36:53 2024 +0200

libiberty: Fix up > 64K section handling in 
simple_object_elf_copy_lto_debug_section [PR116614]

cat abc.C
  #define A(n) struct T##n {} t##n;
  #define B(n) A(n##0) A(n##1) A(n##2) A(n##3) A(n##4) A(n##5) A(n##6) 
A(n##7) A(n##8) A(n##9)
  #define C(n) B(n##0) B(n##1) B(n##2) B(n##3) B(n##4) B(n##5) B(n##6) 
B(n##7) B(n##8) B(n##9)
  #define D(n) C(n##0) C(n##1) C(n##2) C(n##3) C(n##4) C(n##5) C(n##6) 
C(n##7) C(n##8) C(n##9)
  #define E(n) D(n##0) D(n##1) D(n##2) D(n##3) D(n##4) D(n##5) D(n##6) 
D(n##7) D(n##8) D(n##9)
  E(1) E(2) E(3)
  int main () { return 0; }
./xg++ -B ./ -o abc{.o,.C} -flto -flto-partition=1to1 -O2 -g 
-fdebug-types-section -c
./xgcc -B ./ -o abc{,.o} -flto -flto-partition=1to1 -O2
(not included in testsuite as it takes a while to compile) FAILs with
lto-wrapper: fatal error: Too many copied sections: Operation not supported
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

The following patch fixes that.  Most of the 64K+ section support for
reading and writing was already there years ago (and especially reading used
quite often already) and a further bug fixed in it in the PR104617 fix.

Yet, the fix isn't solely about removing the
  if (new_i - 1 >= SHN_LORESERVE)
{
  *err = ENOTSUP;
  return "Too many copied sections";
}
5 lines, the missing part was that the function only handled reading of
the .symtab_shndx section but not copying/updating of it.
If the result has less than 64K-epsilon sections, that actually wasn't
needed, but e.g. with -fdebug-types-section one can exceed that pretty
easily (reported to us on WebKitGtk build on ppc64le).
Updating the section is slightly more complicated, because it basically
needs to be done in lock step with updating the .symtab section, if one
doesn't need to use SHN_XINDEX in there, the section should (or should be
updated to) contain SHN_UNDEF entry, otherwise needs to have whatever would
be overwise stored but couldn't fit.  But repeating due to that all the
symtab decisions what to discard and how to rewrite it would be ugly.

So, the patch instead emits the .symtab_shndx section (or sections) last
and prepares the content during the .symtab processing and in a second
pass when going just through .symtab_shndx sections just uses the saved
content.

2024-09-07  Jakub Jelinek  

PR lto/116614
* simple-object-elf.c (SHN_COMMON): Align comment with neighbouring
comments.
(SHN_HIRESERVE): Use uppercase hex digits instead of lowercase for
consistency.
(simple_object_elf_find_sections): Formatting fixes.
(simple_object_elf_fetch_attributes): Likewise.
(simple_object_elf_attributes_merge): Likewise.
(simple_object_elf_start_write): Likewise.
(simple_object_elf_write_ehdr): Likewise.
(simple_object_elf_write_shdr): Likewise.
(simple_object_elf_write_to_file): Likewise.
(simple_object_elf_copy_lto_debug_section): Likewise.  Don't fail 
for
new_i - 1 >= SHN_LORESERVE, instead arrange in that case to copy
over .symtab_shndx sections, though emit those last and compute 
their
section content when processing associated .symtab sections.  Handle
simple_object_internal_read failure even in the .symtab_shndx 
reading
case.

(cherry picked from commit bb8dd0980b39cfd601f88703fd356055727ef24d)

Diff:
---
 libiberty/simple-object-elf.c | 210 --
 1 file changed, 143 insertions(+), 67 deletions(-)

diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c
index eee07039984d..501b5ba62aac 100644
--- a/libiberty/simple-object-elf.c
+++ b/libiberty/simple-object-elf.c
@@ -128,9 +128,9 @@ typedef struct {
 
 #define SHN_UNDEF  0   /* Undefined section */
 #define SHN_LORESERVE  0xFF00  /* Begin range of reserved indices */
-#define SHN_COMMON 0xFFF2  /* Associated symbol is in common */
+#define SHN_COMMON 0xFFF2  /* Associated symbol is in common */
 #define SHN_XINDEX 0x  /* Section index is held elsewhere */
-#define SHN_HIRESERVE  0x  /* End of reserved indices */
+#define SHN_HIRESERVE  0x  /* End of reserved indices */
 
 
 /* 32-bit ELF program header.  */
@@ -569,8 +569,8 @@ simple_object_elf_find_sections (simple_object_read *sobj,
 void *data,
 int *err)
 {
-  struct simple_object_elf_read *eor =

[gcc r13-9022] i386: Fix up __builtin_ia32_b{extr{, i}_u{32, 64}, zhi_{s, d}i} folding [PR116287]

2024-09-13 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:e5839cad7886c0277c111d96cc99c400f6f36b9d

commit r13-9022-ge5839cad7886c0277c111d96cc99c400f6f36b9d
Author: Jakub Jelinek 
Date:   Fri Aug 9 14:32:51 2024 +0200

i386: Fix up __builtin_ia32_b{extr{,i}_u{32,64},zhi_{s,d}i} folding 
[PR116287]

The GENERIC folding of these builtins have cases where it folds to a
constant regardless of the value of the first operand.  If so, we need
to use omit_one_operand to avoid throwing away side-effects in the first
operand if any.  The cases which verify the first argument is INTEGER_CST
don't need that, INTEGER_CST doesn't have side-effects.

2024-08-09  Jakub Jelinek  

PR target/116287
* config/i386/i386.cc (ix86_fold_builtin) :
When folding into zero without checking whether first argument is
constant, use omit_one_operand.
(ix86_fold_builtin) : Likewise.

* gcc.target/i386/bmi-pr116287.c: New test.
* gcc.target/i386/bmi2-pr116287.c: New test.
* gcc.target/i386/tbm-pr116287.c: New test.

(cherry picked from commit 6e7088dbe3bf87108a89558ffb7df36df3469206)

Diff:
---
 gcc/config/i386/i386.cc   | 12 +++
 gcc/testsuite/gcc.target/i386/bmi-pr116287.c  | 28 ++
 gcc/testsuite/gcc.target/i386/bmi2-pr116287.c | 24 ++
 gcc/testsuite/gcc.target/i386/tbm-pr116287.c  | 29 +++
 4 files changed, 89 insertions(+), 4 deletions(-)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index a90351ca9c2c..85aa68175aa3 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -18054,9 +18054,11 @@ ix86_fold_builtin (tree fndecl, int n_args,
  unsigned int prec = TYPE_PRECISION (TREE_TYPE (args[0]));
  unsigned int start = tree_to_uhwi (args[1]);
  unsigned int len = (start & 0xff00) >> 8;
+ tree lhs_type = TREE_TYPE (TREE_TYPE (fndecl));
  start &= 0xff;
  if (start >= prec || len == 0)
-   res = 0;
+   return omit_one_operand (lhs_type, build_zero_cst (lhs_type),
+args[0]);
  else if (!tree_fits_uhwi_p (args[0]))
break;
  else
@@ -18065,7 +18067,7 @@ ix86_fold_builtin (tree fndecl, int n_args,
len = prec;
  if (len < HOST_BITS_PER_WIDE_INT)
res &= (HOST_WIDE_INT_1U << len) - 1;
- return build_int_cstu (TREE_TYPE (TREE_TYPE (fndecl)), res);
+ return build_int_cstu (lhs_type, res);
}
  break;
 
@@ -18075,15 +18077,17 @@ ix86_fold_builtin (tree fndecl, int n_args,
  if (tree_fits_uhwi_p (args[1]))
{
  unsigned int idx = tree_to_uhwi (args[1]) & 0xff;
+ tree lhs_type = TREE_TYPE (TREE_TYPE (fndecl));
  if (idx >= TYPE_PRECISION (TREE_TYPE (args[0])))
return args[0];
  if (idx == 0)
-   return build_int_cst (TREE_TYPE (TREE_TYPE (fndecl)), 0);
+   return omit_one_operand (lhs_type, build_zero_cst (lhs_type),
+args[0]);
  if (!tree_fits_uhwi_p (args[0]))
break;
  unsigned HOST_WIDE_INT res = tree_to_uhwi (args[0]);
  res &= ~(HOST_WIDE_INT_M1U << idx);
- return build_int_cstu (TREE_TYPE (TREE_TYPE (fndecl)), res);
+ return build_int_cstu (lhs_type, res);
}
  break;
 
diff --git a/gcc/testsuite/gcc.target/i386/bmi-pr116287.c 
b/gcc/testsuite/gcc.target/i386/bmi-pr116287.c
new file mode 100644
index ..2212cb458d26
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/bmi-pr116287.c
@@ -0,0 +1,28 @@
+/* PR target/116287 */
+/* { dg-do run { target bmi } } */
+/* { dg-options "-O2 -mbmi" } */
+
+#include 
+
+#include "bmi-check.h"
+
+static void
+bmi_test ()
+{
+  unsigned int a = 0;
+  if (__builtin_ia32_bextr_u32 (a++, 0) != 0)
+abort ();
+  if (__builtin_ia32_bextr_u32 (a++, 0x120) != 0)
+abort ();
+  if (a != 2)
+abort ();
+#ifdef __x86_64__
+  unsigned long long b = 0;
+  if (__builtin_ia32_bextr_u64 (b++, 0) != 0)
+abort ();
+  if (__builtin_ia32_bextr_u64 (b++, 0x140) != 0)
+abort ();
+  if (b != 2)
+abort ();
+#endif
+}
diff --git a/gcc/testsuite/gcc.target/i386/bmi2-pr116287.c 
b/gcc/testsuite/gcc.target/i386/bmi2-pr116287.c
new file mode 100644
index ..51c939c39f62
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/bmi2-pr116287.c
@@ -0,0 +1,24 @@
+/* PR target/116287 */
+/* { dg-do run { target bmi2 } } */
+/* { dg-options "-O2 -mbmi2" } */
+
+#include 
+
+#include "bmi2-check.h"
+
+static void
+bmi2_test ()
+{
+  unsigned int a = 0;
+  if (__builtin_ia32_bzhi_si (a++, 0) != 0)
+abort ();
+  if (a != 1)
+abort ();
+#ifdef __x86_64__
+  unsigned long lon

[gcc r13-9021] testsuite: Fix up pr116034.c test for big/pdp endian [PR116061]

2024-09-13 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:e5a9c15266ba70b3a4cbc0f8e6bc8537c9b1c12d

commit r13-9021-ge5a9c15266ba70b3a4cbc0f8e6bc8537c9b1c12d
Author: Jakub Jelinek 
Date:   Wed Jul 24 18:00:05 2024 +0200

testsuite: Fix up pr116034.c test for big/pdp endian [PR116061]

Didn't notice the memmove is into an int variable, so the test
was still failing on big endian.

2024-07-24  Jakub Jelinek  

PR tree-optimization/116034
PR testsuite/116061
* gcc.dg/pr116034.c (g): Change type from int to unsigned short.
(foo): Guard memmove call on __SIZEOF_SHORT__ == 2.

(cherry picked from commit 69e69847e21a8d951ab5f09fd3421449564dba31)

Diff:
---
 gcc/testsuite/gcc.dg/pr116034.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr116034.c b/gcc/testsuite/gcc.dg/pr116034.c
index 9a31de034246..955b4c9e86b8 100644
--- a/gcc/testsuite/gcc.dg/pr116034.c
+++ b/gcc/testsuite/gcc.dg/pr116034.c
@@ -2,12 +2,13 @@
 /* { dg-do run } */
 /* { dg-options "-O1 -fno-strict-aliasing" } */
 
-int g;
+unsigned short int g;
 
 static inline int
 foo (_Complex unsigned short c)
 {
-  __builtin_memmove (&g, 1 + (char *) &c, 2);
+  if (__SIZEOF_SHORT__ == 2)
+__builtin_memmove (&g, 1 + (char *) &c, 2);
   return g;
 }


[gcc/redhat/heads/gcc-14-branch] (22 commits) Merge commit 'r14-10667-g5609246b561ab929b24eeb32965911884b

2024-09-12 Thread Jakub Jelinek via Gcc-cvs
The branch 'redhat/heads/gcc-14-branch' was updated to point to:

 c7a1c1a4bf73... Merge commit 'r14-10667-g5609246b561ab929b24eeb32965911884b

It previously pointed to:

 b30927153ae4... Merge commit 'r14-10646-g24909512101d59807f6d23a9963d64390e

Diff:

Summary of changes (added commits):
---

  c7a1c1a... Merge commit 'r14-10667-g5609246b561ab929b24eeb32965911884b
  5609246... c++: Disable deprecated/unavailable diagnostics when creati (*)
  90a9c36... c++: Fix get_member_function_from_ptrfunc with -fsanitize=b (*)
  c9fd43a... libiberty: Fix up > 64K section handling in simple_object_e (*)
  78a08bf... Daily bump. (*)
  2003f89... libstdc++: Only use std::ios_base_library_init() for ELF [P (*)
  d5d6d3f... libstdc++: std::string move assignment should not use POCCA (*)
  f0f00c4... Daily bump. (*)
  ab884ff... libstdc++: Fix std::chrono::tzdb to work with vanguard form (*)
  8a0f0fc... Daily bump. (*)
  3951efe... doc: Enhance Intel CPU documentation (*)
  9366940... Daily bump. (*)
  149d87f... c++: c->B::m access resolved through current inst [PR116320 (*)
  b5ed381... c++: inherited CTAD fixes [PR116276] (*)
  140aab2... libstdc++: use concrete return type for std::forward_like (*)
  7e0649a... Daily bump. (*)
  0c80216... c++: template depth of lambda in default targ [PR116567] (*)
  1e79541... Daily bump. (*)
  d4d7c4e... Update gcc uk.po (*)
  aedf6f8... Daily bump. (*)
  fe66863... c++: vtable referring to "unavailable" virtual fn [PR116606 (*)
  6abedee... ipa: Don't disable function parameter analysis for fat LTO (*)

(*) This commit already exists in another branch.
Because the reference `refs/vendors/redhat/heads/gcc-14-branch' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc r14-10667] c++: Disable deprecated/unavailable diagnostics when creating thunks for methods with such attribute

2024-09-12 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:5609246b561ab929b24eeb32965911884b58b0df

commit r14-10667-g5609246b561ab929b24eeb32965911884b58b0df
Author: Jakub Jelinek 
Date:   Thu Sep 12 18:22:21 2024 +0200

c++: Disable deprecated/unavailable diagnostics when creating thunks for 
methods with such attributes [PR116636]

On the following testcase, we emit false positive warnings/errors about 
using
the deprecated or unavailable methods when creating thunks for them, even
when nothing (in the testcase so far) actually used those.

The following patch temporarily disables that diagnostics when creating
the thunks.

2024-09-12  Jakub Jelinek  

PR c++/116636
* method.cc: Include decl.h.
(use_thunk): Temporarily change deprecated_state to
UNAVAILABLE_DEPRECATED_SUPPRESS.

* g++.dg/warn/deprecated-19.C: New test.

(cherry picked from commit 4026d89d623e322920b052f7ac0d940ef267dc0f)

Diff:
---
 gcc/cp/method.cc  |  6 ++
 gcc/testsuite/g++.dg/warn/deprecated-19.C | 22 ++
 2 files changed, 28 insertions(+)

diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
index 08a3d34fb016..a2ca83ce354c 100644
--- a/gcc/cp/method.cc
+++ b/gcc/cp/method.cc
@@ -26,6 +26,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "target.h"
 #include "cp-tree.h"
+#include "decl.h"
 #include "stringpool.h"
 #include "cgraph.h"
 #include "varasm.h"
@@ -283,6 +284,11 @@ use_thunk (tree thunk_fndecl, bool emit_p)
   /* Thunks are always addressable; they only appear in vtables.  */
   TREE_ADDRESSABLE (thunk_fndecl) = 1;
 
+  /* Don't diagnose deprecated or unavailable functions just because they
+ have thunks emitted for them.  */
+  auto du = make_temp_override (deprecated_state,
+UNAVAILABLE_DEPRECATED_SUPPRESS);
+
   /* Figure out what function is being thunked to.  It's referenced in
  this translation unit.  */
   TREE_ADDRESSABLE (function) = 1;
diff --git a/gcc/testsuite/g++.dg/warn/deprecated-19.C 
b/gcc/testsuite/g++.dg/warn/deprecated-19.C
new file mode 100644
index ..e49af4f74d0d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/deprecated-19.C
@@ -0,0 +1,22 @@
+// PR c++/116636
+// { dg-do compile { target c++11 } }
+// { dg-options "-pedantic -Wdeprecated" }
+
+struct A {
+  virtual int foo () = 0;
+};
+struct B : virtual A {
+  [[deprecated]] int foo () { return 0; }  // { dg-message "declared here" 
}
+};
+struct C : virtual A {
+  [[gnu::unavailable]] int foo () { return 0; }// { dg-message 
"declared here" }
+};
+
+void
+bar ()
+{
+  B b;
+  b.foo ();// { dg-warning "'virtual int 
B::foo\\\(\\\)' is deprecated" }
+  C c;
+  c.foo ();// { dg-error "'virtual int 
C::foo\\\(\\\)' is unavailable" }
+}


[gcc r14-10666] c++: Fix get_member_function_from_ptrfunc with -fsanitize=bounds [PR116449]

2024-09-12 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:90a9c36dc3ba341cf662ba1d60c939027487fe9a

commit r14-10666-g90a9c36dc3ba341cf662ba1d60c939027487fe9a
Author: Jakub Jelinek 
Date:   Tue Sep 10 18:32:58 2024 +0200

c++: Fix get_member_function_from_ptrfunc with -fsanitize=bounds [PR116449]

The following testcase is miscompiled, because
get_member_function_from_ptrfunc
emits something like
(((FUNCTION.__pfn & 1) != 0)
 ? ptr + FUNCTION.__delta + FUNCTION.__pfn - 1
 : FUNCTION.__pfn) (ptr + FUNCTION.__delta, ...)
or so, so FUNCTION tree is used there 5 times.  There is
if (TREE_SIDE_EFFECTS (function)) function = save_expr (function);
but in this case function doesn't have side-effects, just nested ARRAY_REFs.
Now, if all the FUNCTION trees would be shared, it would work fine,
FUNCTION is evaluated in the first operand of COND_EXPR; but unfortunately
that isn't the case, both the BIT_AND_EXPR shortening and conversion to
bool done for build_conditional_expr actually unshare_expr that first
expression, but none of the other 4 are unshared.  With -fsanitize=bounds,
.UBSAN_BOUNDS calls are added to the ARRAY_REFs and use save_expr to avoid
evaluating the argument multiple times, but because that FUNCTION tree is
first used in the second argument of COND_EXPR (i.e. conditionally), the
SAVE_EXPR initialization is done just there and then the third argument
of COND_EXPR just uses the uninitialized temporary and so does the first
argument computation as well.

The following patch fixes that by doing save_expr even if 
!TREE_SIDE_EFFECTS,
but to avoid doing that too often only if !nonvirtual and if the expression
isn't a simple decl.

2024-09-10  Jakub Jelinek  

PR c++/116449
* typeck.cc (get_member_function_from_ptrfunc): Use save_expr
on instance_ptr and function even if it doesn't have side-effects,
as long as it isn't a decl.

* g++.dg/ubsan/pr116449.C: New test.

(cherry picked from commit 0008050b9d6046ba4e811a03b406fb5d98707cae)

Diff:
---
 gcc/cp/typeck.cc  | 19 ---
 gcc/testsuite/g++.dg/ubsan/pr116449.C | 14 ++
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index 21436f836fa6..3d62943f8647 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -4175,10 +4175,23 @@ get_member_function_from_ptrfunc (tree 
*instance_ptrptr, tree function,
   if (!nonvirtual && is_dummy_object (instance_ptr))
nonvirtual = true;
 
-  if (TREE_SIDE_EFFECTS (instance_ptr))
-   instance_ptr = instance_save_expr = save_expr (instance_ptr);
+  /* Use save_expr even when instance_ptr doesn't have side-effects,
+unless it is a simple decl (save_expr won't do anything on
+constants), so that we don't ubsan instrument the expression
+multiple times.  See PR116449.  */
+  if (TREE_SIDE_EFFECTS (instance_ptr)
+ || (!nonvirtual && !DECL_P (instance_ptr)))
+   {
+ instance_save_expr = save_expr (instance_ptr);
+ if (instance_save_expr == instance_ptr)
+   instance_save_expr = NULL_TREE;
+ else
+   instance_ptr = instance_save_expr;
+   }
 
-  if (TREE_SIDE_EFFECTS (function))
+  /* See above comment.  */
+  if (TREE_SIDE_EFFECTS (function)
+ || (!nonvirtual && !DECL_P (function)))
function = save_expr (function);
 
   /* Start by extracting all the information from the PMF itself.  */
diff --git a/gcc/testsuite/g++.dg/ubsan/pr116449.C 
b/gcc/testsuite/g++.dg/ubsan/pr116449.C
new file mode 100644
index ..f13368a51b00
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ubsan/pr116449.C
@@ -0,0 +1,14 @@
+// PR c++/116449
+// { dg-do compile }
+// { dg-options "-O2 -Wall -fsanitize=undefined" }
+
+struct C { void foo (int); void bar (); int c[16]; };
+typedef void (C::*P) ();
+struct D { P d; };
+static D e[1] = { { &C::bar } };
+
+void
+C::foo (int x)
+{
+  (this->*e[c[x]].d) ();
+}


[gcc r14-10665] libiberty: Fix up > 64K section handling in simple_object_elf_copy_lto_debug_section [PR116614]

2024-09-12 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:c9fd43a8df0e30109794e2480e2d8d05d00763c0

commit r14-10665-gc9fd43a8df0e30109794e2480e2d8d05d00763c0
Author: Jakub Jelinek 
Date:   Sat Sep 7 09:36:53 2024 +0200

libiberty: Fix up > 64K section handling in 
simple_object_elf_copy_lto_debug_section [PR116614]

cat abc.C
  #define A(n) struct T##n {} t##n;
  #define B(n) A(n##0) A(n##1) A(n##2) A(n##3) A(n##4) A(n##5) A(n##6) 
A(n##7) A(n##8) A(n##9)
  #define C(n) B(n##0) B(n##1) B(n##2) B(n##3) B(n##4) B(n##5) B(n##6) 
B(n##7) B(n##8) B(n##9)
  #define D(n) C(n##0) C(n##1) C(n##2) C(n##3) C(n##4) C(n##5) C(n##6) 
C(n##7) C(n##8) C(n##9)
  #define E(n) D(n##0) D(n##1) D(n##2) D(n##3) D(n##4) D(n##5) D(n##6) 
D(n##7) D(n##8) D(n##9)
  E(1) E(2) E(3)
  int main () { return 0; }
./xg++ -B ./ -o abc{.o,.C} -flto -flto-partition=1to1 -O2 -g 
-fdebug-types-section -c
./xgcc -B ./ -o abc{,.o} -flto -flto-partition=1to1 -O2
(not included in testsuite as it takes a while to compile) FAILs with
lto-wrapper: fatal error: Too many copied sections: Operation not supported
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

The following patch fixes that.  Most of the 64K+ section support for
reading and writing was already there years ago (and especially reading used
quite often already) and a further bug fixed in it in the PR104617 fix.

Yet, the fix isn't solely about removing the
  if (new_i - 1 >= SHN_LORESERVE)
{
  *err = ENOTSUP;
  return "Too many copied sections";
}
5 lines, the missing part was that the function only handled reading of
the .symtab_shndx section but not copying/updating of it.
If the result has less than 64K-epsilon sections, that actually wasn't
needed, but e.g. with -fdebug-types-section one can exceed that pretty
easily (reported to us on WebKitGtk build on ppc64le).
Updating the section is slightly more complicated, because it basically
needs to be done in lock step with updating the .symtab section, if one
doesn't need to use SHN_XINDEX in there, the section should (or should be
updated to) contain SHN_UNDEF entry, otherwise needs to have whatever would
be overwise stored but couldn't fit.  But repeating due to that all the
symtab decisions what to discard and how to rewrite it would be ugly.

So, the patch instead emits the .symtab_shndx section (or sections) last
and prepares the content during the .symtab processing and in a second
pass when going just through .symtab_shndx sections just uses the saved
content.

2024-09-07  Jakub Jelinek  

PR lto/116614
* simple-object-elf.c (SHN_COMMON): Align comment with neighbouring
comments.
(SHN_HIRESERVE): Use uppercase hex digits instead of lowercase for
consistency.
(simple_object_elf_find_sections): Formatting fixes.
(simple_object_elf_fetch_attributes): Likewise.
(simple_object_elf_attributes_merge): Likewise.
(simple_object_elf_start_write): Likewise.
(simple_object_elf_write_ehdr): Likewise.
(simple_object_elf_write_shdr): Likewise.
(simple_object_elf_write_to_file): Likewise.
(simple_object_elf_copy_lto_debug_section): Likewise.  Don't fail 
for
new_i - 1 >= SHN_LORESERVE, instead arrange in that case to copy
over .symtab_shndx sections, though emit those last and compute 
their
section content when processing associated .symtab sections.  Handle
simple_object_internal_read failure even in the .symtab_shndx 
reading
case.

(cherry picked from commit bb8dd0980b39cfd601f88703fd356055727ef24d)

Diff:
---
 libiberty/simple-object-elf.c | 210 --
 1 file changed, 143 insertions(+), 67 deletions(-)

diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c
index c09c216656c2..5e95297b2fc1 100644
--- a/libiberty/simple-object-elf.c
+++ b/libiberty/simple-object-elf.c
@@ -128,9 +128,9 @@ typedef struct {
 
 #define SHN_UNDEF  0   /* Undefined section */
 #define SHN_LORESERVE  0xFF00  /* Begin range of reserved indices */
-#define SHN_COMMON 0xFFF2  /* Associated symbol is in common */
+#define SHN_COMMON 0xFFF2  /* Associated symbol is in common */
 #define SHN_XINDEX 0x  /* Section index is held elsewhere */
-#define SHN_HIRESERVE  0x  /* End of reserved indices */
+#define SHN_HIRESERVE  0x  /* End of reserved indices */
 
 
 /* 32-bit ELF program header.  */
@@ -569,8 +569,8 @@ simple_object_elf_find_sections (simple_object_read *sobj,
 void *data,
 int *err)
 {
-  struct simple_object_elf_read *eor =

[gcc r15-3610] c++: Disable deprecated/unavailable diagnostics when creating thunks for methods with such attribute

2024-09-12 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:4026d89d623e322920b052f7ac0d940ef267dc0f

commit r15-3610-g4026d89d623e322920b052f7ac0d940ef267dc0f
Author: Jakub Jelinek 
Date:   Thu Sep 12 18:22:21 2024 +0200

c++: Disable deprecated/unavailable diagnostics when creating thunks for 
methods with such attributes [PR116636]

On the following testcase, we emit false positive warnings/errors about 
using
the deprecated or unavailable methods when creating thunks for them, even
when nothing (in the testcase so far) actually used those.

The following patch temporarily disables that diagnostics when creating
the thunks.

2024-09-12  Jakub Jelinek  

PR c++/116636
* method.cc: Include decl.h.
(use_thunk): Temporarily change deprecated_state to
UNAVAILABLE_DEPRECATED_SUPPRESS.

* g++.dg/warn/deprecated-19.C: New test.

Diff:
---
 gcc/cp/method.cc  |  6 ++
 gcc/testsuite/g++.dg/warn/deprecated-19.C | 22 ++
 2 files changed, 28 insertions(+)

diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
index 68a776d2c5a6..21c06c744c9a 100644
--- a/gcc/cp/method.cc
+++ b/gcc/cp/method.cc
@@ -26,6 +26,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "target.h"
 #include "cp-tree.h"
+#include "decl.h"
 #include "stringpool.h"
 #include "cgraph.h"
 #include "varasm.h"
@@ -283,6 +284,11 @@ use_thunk (tree thunk_fndecl, bool emit_p)
   /* Thunks are always addressable; they only appear in vtables.  */
   TREE_ADDRESSABLE (thunk_fndecl) = 1;
 
+  /* Don't diagnose deprecated or unavailable functions just because they
+ have thunks emitted for them.  */
+  auto du = make_temp_override (deprecated_state,
+UNAVAILABLE_DEPRECATED_SUPPRESS);
+
   /* Figure out what function is being thunked to.  It's referenced in
  this translation unit.  */
   TREE_ADDRESSABLE (function) = 1;
diff --git a/gcc/testsuite/g++.dg/warn/deprecated-19.C 
b/gcc/testsuite/g++.dg/warn/deprecated-19.C
new file mode 100644
index ..561f1241e005
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/deprecated-19.C
@@ -0,0 +1,22 @@
+// PR c++/116636
+// { dg-do compile }
+// { dg-options "-pedantic -Wdeprecated" }
+
+struct A {
+  virtual int foo () = 0;
+};
+struct B : virtual A {
+  [[deprecated]] int foo () { return 0; }  // { dg-message "declared here" 
}
+}; // { dg-warning "C\\\+\\\+11 
attributes only available with" "" { target c++98_only } .-1 }
+struct C : virtual A {
+  [[gnu::unavailable]] int foo () { return 0; }// { dg-message 
"declared here" }
+}; // { dg-warning "C\\\+\\\+11 
attributes only available with" "" { target c++98_only } .-1 }
+
+void
+bar ()
+{
+  B b;
+  b.foo ();// { dg-warning "'virtual int 
B::foo\\\(\\\)' is deprecated" }
+  C c;
+  c.foo ();// { dg-error "'virtual int 
C::foo\\\(\\\)' is unavailable" }
+}


[gcc r15-3609] libcpp, v2: Add support for gnu::base64 #embed parameter

2024-09-12 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:ce0aecc7df1ff0be24c278dff5575ec28042ee58

commit r15-3609-gce0aecc7df1ff0be24c278dff5575ec28042ee58
Author: Jakub Jelinek 
Date:   Thu Sep 12 18:17:05 2024 +0200

libcpp, v2: Add support for gnu::base64 #embed parameter

This patch which adds another #embed extension, gnu::base64.

As mentioned in the documentation, this extension is primarily
intended for use by the preprocessor, so that for the larger (say 32+ or
64+ bytes long embeds it doesn't have to emit tens of thousands or
millions of comma separated string literals which would be very expensive
to parse again, but can emit
 #embed "." __gnu__::__base64__( \
 
"Tm9uIGVyYW0gbsOpc2NpdXMsIEJydXRlLCBjdW0sIHF1w6Ygc3VtbWlzIGluZ8OpbmlpcyBleHF1" \
 
"aXNpdMOhcXVlIGRvY3Ryw61uYSBwaGlsw7Nzb3BoaSBHcsOmY28gc2VybcOzbmUgdHJhY3RhdsOt" \
 
"c3NlbnQsIGVhIExhdMOtbmlzIGzDrXR0ZXJpcyBtYW5kYXLDqW11cywgZm9yZSB1dCBoaWMgbm9z" \
 
"dGVyIGxhYm9yIGluIHbDoXJpYXMgcmVwcmVoZW5zacOzbmVzIGluY8O6cnJlcmV0LiBuYW0gcXVp" \
 
"YsO6c2RhbSwgZXQgaWlzIHF1aWRlbSBub24gw6FkbW9kdW0gaW5kw7NjdGlzLCB0b3R1bSBob2Mg" \
 
"ZMOtc3BsaWNldCBwaGlsb3NvcGjDoXJpLiBxdWlkYW0gYXV0ZW0gbm9uIHRhbSBpZCByZXByZWjD" \
 
"qW5kdW50LCBzaSByZW3DrXNzaXVzIGFnw6F0dXIsIHNlZCB0YW50dW0gc3TDumRpdW0gdGFtcXVl" \
 
"IG11bHRhbSDDs3BlcmFtIHBvbsOpbmRhbSBpbiBlbyBub24gYXJiaXRyw6FudHVyLiBlcnVudCDD" \
 
"qXRpYW0sIGV0IGlpIHF1aWRlbSBlcnVkw610aSBHcsOmY2lzIGzDrXR0ZXJpcywgY29udGVtbsOp" \
 
"bnRlcyBMYXTDrW5hcywgcXVpIHNlIGRpY2FudCBpbiBHcsOmY2lzIGxlZ8OpbmRpcyDDs3BlcmFt" \
 
"IG1hbGxlIGNvbnPDum1lcmUuIHBvc3Ryw6ltbyDDoWxpcXVvcyBmdXTDunJvcyBzw7pzcGljb3Is" \
 
"IHF1aSBtZSBhZCDDoWxpYXMgbMOtdHRlcmFzIHZvY2VudCwgZ2VudXMgaG9jIHNjcmliw6luZGks" \
 
"IGV0c2kgc2l0IGVsw6lnYW5zLCBwZXJzw7Nuw6YgdGFtZW4gZXQgZGlnbml0w6F0aXMgZXNzZSBu" \
 "ZWdlbnQu")
with the meaning don't actually load some file, instead base64 decode
(RFC4648 with A-Za-z0-9+/ chars and = padding, no newlines in between)
the string and use that as data.  This is chosen because it should be
-pedantic-errors clean, fairly cheap to decode and then in optimizing
compiler could be handled as similar binary blob to normal #embed,
while the data isn't left somewhere on the disk, so distcc/ccache etc.
can move the preprocessed source without issues.
It makes no sense to support limit and gnu::offset parameters together
with it IMHO, why would somebody waste providing full data and then
threw some away?  prefix/suffix/if_empty are normally supported though,
but not intended to be used by the preprocessor.

This patch adds just the extension side, not the actual emitting of this
during -E or -E -fdirectives-only for now, that will be included in the
upcoming patch.

Compared to the earlier posted version of this extension, this patch
allows the string concatenation in the parameter argument (but still
doesn't allow escapes in the string, why would anyone use them when
only A-Za-z0-9+/= are valid).  The patch also adds support for parsing
this even in -fpreprocessed compilation.

2024-09-12  Jakub Jelinek  

libcpp/
* internal.h (struct cpp_embed_params): Add base64 member.
(_cpp_free_embed_params_tokens): Declare.
* directives.cc (DIRECTIVE_TABLE): Add IN_I flag to T_EMBED.
(save_token_for_embed, _cpp_free_embed_params_tokens): New 
functions.
(EMBED_PARAMS): Add gnu::base64 entry.
(_cpp_parse_embed_params): Parse gnu::base64 parameter.  If
-fpreprocessed without -fdirectives-only, require #embed to have
gnu::base64 parameter.  Diagnose conflict between gnu::base64 and
limit or gnu::offset parameters.
(do_embed): Use _cpp_free_embed_params_tokens.
* files.cc (finish_embed, base64_dec_fn): New functions.
(base64_dec): New array.
(B64D0, B64D1, B64D2, B64D3): Define.
(finish_base64_embed): New function.
(_cpp_stack_embed): Use finish_embed.  Handle params->base64
using finish_base64_embed.
* macro.cc (builtin_has_embed): Call _cpp_free_embed_params_tokens.
gcc/
* doc/cpp.texi (Binary Resource Inclusion): Document gnu::base64
parameter.
gcc/testsuite/
* c-c++-common/cpp/embed-17.c: New test.
* c-c++-common/cpp/embed-18.c: New test.
* c-c++-common/cpp/embed-19.c: New test.
* c-c++-common/cpp/embed-27.c: New test.
* gcc.dg/cpp/embed-6.c: New test.
* gcc.dg/cpp/embed-7.c: New test.

Diff:
---
 gcc/doc/cpp.texi  |  14 +-
 gcc/testsuite/c-c++-common/cpp/embed-17.c | 116 
 gcc/testsuite/c-c++-common/cpp/embed-18.c |  54 
 gcc/testsuite/c-c++-common/cpp/embed-19.c |   5 +
 gcc/testsuite/c-c++-common/cpp/embed-27.c |  64 +
 gcc/testsuite/gcc.dg/cpp/embed-6.c| 

[gcc r15-3600] libcpp: Add support for gnu::offset #embed/__has_embed parameter

2024-09-12 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:44058b847145166715f15e49fa8854f30e852f24

commit r15-3600-g44058b847145166715f15e49fa8854f30e852f24
Author: Jakub Jelinek 
Date:   Thu Sep 12 11:34:06 2024 +0200

libcpp: Add support for gnu::offset #embed/__has_embed parameter

The following patch adds on top of the just posted #embed patch
a first extension, gnu::offset which allows to seek in the data
file (for seekable files, otherwise read and throw away).
I think this is useful e.g. when some binary data start with
some well known header which shouldn't be included in the data etc.

2024-09-12  Jakub Jelinek  

libcpp/
* internal.h (struct cpp_embed_params): Add offset member.
* directives.cc (EMBED_PARAMS): Add gnu::offset entry.
(enum embed_param_kind): Add NUM_EMBED_STD_PARAMS.
(_cpp_parse_embed_params): Use NUM_EMBED_STD_PARAMS rather than
NUM_EMBED_PARAMS when parsing standard parameters.  Parse 
gnu::offset
parameter.
* files.cc (struct _cpp_file): Add offset member.
(_cpp_stack_embed): Handle params->offset.
gcc/
* doc/cpp.texi (Binary Resource Inclusion): Document gnu::offset
#embed parameter.
gcc/testsuite/
* c-c++-common/cpp/embed-15.c: New test.
* c-c++-common/cpp/embed-16.c: New test.
* gcc.dg/cpp/embed-5.c: New test.

Diff:
---
 gcc/doc/cpp.texi  |  8 ++-
 gcc/testsuite/c-c++-common/cpp/embed-15.c | 88 
 gcc/testsuite/c-c++-common/cpp/embed-16.c | 31 ++
 gcc/testsuite/gcc.dg/cpp/embed-5.c|  4 ++
 libcpp/directives.cc  | 40 ++---
 libcpp/files.cc   | 95 ++-
 libcpp/internal.h |  2 +-
 7 files changed, 244 insertions(+), 24 deletions(-)

diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi
index 032b095602d5..612d97e16df8 100644
--- a/gcc/doc/cpp.texi
+++ b/gcc/doc/cpp.texi
@@ -3966,8 +3966,8 @@ treated the same), followed by parameter argument in 
parentheses, like
 with currently supported standard parameters @code{limit}, @code{prefix},
 @code{suffix} and @code{if_empty}, or implementation defined parameters
 specified by a unique vendor prefix followed by @code{::} followed by
-name of the parameter.  GCC will use the @code{gnu} prefix but currently
-doesn't support any extensions.
+name of the parameter.  GCC uses the @code{gnu} prefix for vendor
+parameters and currently supports the @code{gnu::offset} parameter.
 
 The @code{limit} parameter argument is a constant expression which
 specifies the maximum number of bytes included by the directive,
@@ -3977,6 +3977,10 @@ that sequence is not empty and @code{if_empty} argument 
is balanced token
 sequence which is used as expansion for @code{#embed} directive if the
 resource is empty.
 
+The @code{gnu::offset} parameter argument is a constant expression
+which specifies how many bytes to skip from the start of the resource.
+@code{limit} is then counted from that position.
+
 The @code{#embed} directive is not supported in the Traditional Mode
 (@pxref{Traditional Mode}).
 
diff --git a/gcc/testsuite/c-c++-common/cpp/embed-15.c 
b/gcc/testsuite/c-c++-common/cpp/embed-15.c
new file mode 100644
index ..c12aeb31db53
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/embed-15.c
@@ -0,0 +1,88 @@
+/* { dg-do run } */
+/* { dg-options "--embed-dir=${srcdir}/c-c++-common/cpp/embed-dir" } */
+/* { dg-additional-options "-std=gnu99" { target c } } */
+
+#if __has_embed (__FILE__ gnu::offset (4 + FOOBAR) limit (3)) != 
__STDC_EMBED_FOUND__
+#error "__has_embed fail"
+#endif
+
+#embed  limit(1) gnu::offset (0) prefix(int a = ) suffix (;) 
+#embed  limit(1) __gnu__::offset (1 * 1) prefix(int b = ) 
suffix (;) 
+#embed  limit(1) gnu::__offset__ (1 + 1) prefix(int c = ) 
suffix (;) 
+#embed  __limit__(1) __gnu__::__offset__ (1 + (1 \
+  + 1)) __prefix__(int d = ) __suffix__ (;)
+const unsigned char e[] = {
+  #embed  limit(5) gnu::offset (999)
+};
+const unsigned char f[] = {
+  #embed  limit(7) gnu::offset (998)
+};
+const unsigned char g[] = {
+  #embed  limit(8) gnu::offset (998)
+};
+const unsigned char h[] = {
+  #embed  limit(8) gnu::offset (997)
+};
+const unsigned char i[] = {
+  #embed  limit(9) gnu::offset (997)
+};
+const unsigned char j[] = {
+  #embed  limit(30) gnu::offset (990)
+};
+const unsigned char k[] = {
+  #embed  limit(26) gnu::offset (992)
+};
+const unsigned char l[] = {
+  #embed 
+};
+const unsigned char m[] = {
+  #embed  __limit__ (1000) __gnu__::__offset__ (32)
+};
+#if __has_embed ( limit(5) gnu::offset (999)) != 
__STDC_EMBED_FOUND__ \
+|| __has_embed ( limit(5) gnu::offset (999)) != 
__STDC_EMBED_FOUND__ \
+|| __has_embed ( limit(7) gnu::offset (998)) != 
__STDC_EMBED_FOUND__ \
+|| __has_embed ( limit(8) gnu::offset (998)) != 
__STDC_EMBED_FOUND__ \
+   

[gcc r15-3599] libcpp, c-family: Add (dumb) C23 N3017 #embed support [PR105863]

2024-09-12 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:eba6d2aa71a9b59386e5a2453cbe924371626b0b

commit r15-3599-geba6d2aa71a9b59386e5a2453cbe924371626b0b
Author: Jakub Jelinek 
Date:   Thu Sep 12 11:15:38 2024 +0200

libcpp, c-family: Add (dumb) C23 N3017 #embed support [PR105863]

The following patch implements the C23 N3017 "#embed - a scannable,
tooling-friendly binary resource inclusion mechanism" paper.

The implementation is intentionally dumb, in that it doesn't significantly
speed up compilation of larger initializers and doesn't make it possible
to use huge #embeds (like several gigabytes large, that is compile time
and memory still infeasible).
There are 2 reasons for this.  One is that I think like it is implemented
now in the patch is how we should use it for the smaller #embed sizes,
dunno with which boundary, whether 32 bytes or 64 or something like that,
certainly handling the single byte cases which is something that can appear
anywhere in the source where constant integer literal can appear is
desirable and I think for a few bytes it isn't worth it to come up with
something smarter and users would like to e.g. see it in -E readably as
well (perhaps the slow vs. fast boundary should be determined by command
line option).  And the other one is to be able to more easily find
regressions in behavior caused by the optimizations, so we have something
to get back in git to compare against.
I'm definitely willing to work on the optimizations (likely introduce a new
CPP_* token type to refer to a range of libcpp owned memory (start + size)
and similarly some tree which can do the same, and can be at any time e.g.
split into 2 subparts + say INTEGER_CST in between if needed say for
const unsigned char d[] = {
 #embed "2GB.dat" prefix (0, 0, ) suffix (, [0x4000] = 42)
}; still without having to copy around huge amounts of data; STRING_CST
owns the memory it points to and can be only 2GB in size), but would
like to do that incrementally.
And would like to first include some extensions also not included in
this patch, like gnu::offset (off) parameter to allow to skip certain
constant amount of bytes at the start of the files, plus
gnu::base64 ("base64_encoded_data") parameter to add something which can
store more efficiently large amounts of the #embed data in preprocessed
source.

I've been cross-checking all the tests also against the LLVM implementation
https://github.com/llvm/llvm-project/pull/68620
which has been for a few hours even committed to LLVM trunk but reverted
afterwards.  LLVM now has the support committed and I admit I haven't
rechecked whether the behavior on the below mentioned spots have been fixed
in it already or not yet.

The patch uses --embed-dir= option that clang plans to add above and doesn't
use other variants on the search directories yet, plus there are no
default directories at least for the time being where to search for embed
files.  So, #embed "..." works if it is found in the same directory (or
relative to the current file's directory) and #embed "/..." or #embed 
work always, but relative #embed <...> doesn't unless at least one
--embed-dir= is specified.  There is no reason to differentiate between
system and non-system directories, so we don't need -isystem like
counterpart, perhaps -iquote like counterpart could be useful in the future,
dunno what else.  It has --embed-directory=dir and --embed-directory dir
as aliases.

There are some differences beyond clang ICEs, so I'd like to point them out
to make sure there is agreement on the choices in the patch.  They are also
mentioned in the comments of the llvm pull request.

The most important is that the GCC patch (as well as the original thephd.dev
LLVM branch on godbolt) expands #embed (or acts as if it is expanded) into
a mere sequence of numbers like 123,2,35,26 rather then what clang
effectively treats as (unsigned char)123,(unsigned char)2,(unsigned
char)35,(unsigned char)26 but only does that when using integrated
preprocessor, not when using -save-temps where it acts as GCC.
JeanHeyd as the original author agrees that is how it is currently worded in
C23.

Another difference (not tested in the testsuite, not sure how to check for
effective target /dev/urandom nor am sure it is desirable to check that
during testsuite) is how to treat character devices, named pipes etc.
(block devices are errored on).  The original paper uses /dev/urandom
in various examples and seems to assume that unlike regular files the
devices aren't really cached, so
 #embed  limit(1) prefix(int a = ) suffix(;)
 #embed  limit(1) prefix(int b = ) suffix(;)
usually results in a != b.  That is what the godbolt thephd.dev branch
implements too and what this pat

[gcc r15-3574] c++: Fix get_member_function_from_ptrfunc with -fsanitize=bounds [PR116449]

2024-09-10 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:0008050b9d6046ba4e811a03b406fb5d98707cae

commit r15-3574-g0008050b9d6046ba4e811a03b406fb5d98707cae
Author: Jakub Jelinek 
Date:   Tue Sep 10 18:32:58 2024 +0200

c++: Fix get_member_function_from_ptrfunc with -fsanitize=bounds [PR116449]

The following testcase is miscompiled, because
get_member_function_from_ptrfunc
emits something like
(((FUNCTION.__pfn & 1) != 0)
 ? ptr + FUNCTION.__delta + FUNCTION.__pfn - 1
 : FUNCTION.__pfn) (ptr + FUNCTION.__delta, ...)
or so, so FUNCTION tree is used there 5 times.  There is
if (TREE_SIDE_EFFECTS (function)) function = save_expr (function);
but in this case function doesn't have side-effects, just nested ARRAY_REFs.
Now, if all the FUNCTION trees would be shared, it would work fine,
FUNCTION is evaluated in the first operand of COND_EXPR; but unfortunately
that isn't the case, both the BIT_AND_EXPR shortening and conversion to
bool done for build_conditional_expr actually unshare_expr that first
expression, but none of the other 4 are unshared.  With -fsanitize=bounds,
.UBSAN_BOUNDS calls are added to the ARRAY_REFs and use save_expr to avoid
evaluating the argument multiple times, but because that FUNCTION tree is
first used in the second argument of COND_EXPR (i.e. conditionally), the
SAVE_EXPR initialization is done just there and then the third argument
of COND_EXPR just uses the uninitialized temporary and so does the first
argument computation as well.

The following patch fixes that by doing save_expr even if 
!TREE_SIDE_EFFECTS,
but to avoid doing that too often only if !nonvirtual and if the expression
isn't a simple decl.

2024-09-10  Jakub Jelinek  

PR c++/116449
* typeck.cc (get_member_function_from_ptrfunc): Use save_expr
on instance_ptr and function even if it doesn't have side-effects,
as long as it isn't a decl.

* g++.dg/ubsan/pr116449.C: New test.

Diff:
---
 gcc/cp/typeck.cc  | 19 ---
 gcc/testsuite/g++.dg/ubsan/pr116449.C | 14 ++
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index e4e260645f65..b6835286cff3 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -4193,10 +4193,23 @@ get_member_function_from_ptrfunc (tree 
*instance_ptrptr, tree function,
   if (!nonvirtual && is_dummy_object (instance_ptr))
nonvirtual = true;
 
-  if (TREE_SIDE_EFFECTS (instance_ptr))
-   instance_ptr = instance_save_expr = save_expr (instance_ptr);
+  /* Use save_expr even when instance_ptr doesn't have side-effects,
+unless it is a simple decl (save_expr won't do anything on
+constants), so that we don't ubsan instrument the expression
+multiple times.  See PR116449.  */
+  if (TREE_SIDE_EFFECTS (instance_ptr)
+ || (!nonvirtual && !DECL_P (instance_ptr)))
+   {
+ instance_save_expr = save_expr (instance_ptr);
+ if (instance_save_expr == instance_ptr)
+   instance_save_expr = NULL_TREE;
+ else
+   instance_ptr = instance_save_expr;
+   }
 
-  if (TREE_SIDE_EFFECTS (function))
+  /* See above comment.  */
+  if (TREE_SIDE_EFFECTS (function)
+ || (!nonvirtual && !DECL_P (function)))
function = save_expr (function);
 
   /* Start by extracting all the information from the PMF itself.  */
diff --git a/gcc/testsuite/g++.dg/ubsan/pr116449.C 
b/gcc/testsuite/g++.dg/ubsan/pr116449.C
new file mode 100644
index ..f13368a51b00
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ubsan/pr116449.C
@@ -0,0 +1,14 @@
+// PR c++/116449
+// { dg-do compile }
+// { dg-options "-O2 -Wall -fsanitize=undefined" }
+
+struct C { void foo (int); void bar (); int c[16]; };
+typedef void (C::*P) ();
+struct D { P d; };
+static D e[1] = { { &C::bar } };
+
+void
+C::foo (int x)
+{
+  (this->*e[c[x]].d) ();
+}


[gcc r15-3542] testsuite: Fix up pr116588.c test [PR116588]

2024-09-09 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:765875e2c18b8f4c346b754a19e287efaec531a5

commit r15-3542-g765875e2c18b8f4c346b754a19e287efaec531a5
Author: Jakub Jelinek 
Date:   Mon Sep 9 09:37:26 2024 +0200

testsuite: Fix up pr116588.c test [PR116588]

The test as committed without the tree-vrp.cc change only FAILs with
FAIL: gcc.dg/pr116588.c scan-tree-dump-not vrp2 "0 != 0"
The DEBUG code in there was just to make it easier to debug, but doesn't
actually fail when the test is miscompiled.
We don't need such debugging code in simple tests like that, but it is
useful if they abort when miscompiled.

With this patch without the tree-vrp.cc change I see
FAIL: gcc.dg/pr116588.c execution test
FAIL: gcc.dg/pr116588.c scan-tree-dump-not vrp2 "0 != 0"
and with it it passes.

2024-09-09  Jakub Jelinek  

PR tree-optimization/116588
* gcc.dg/pr116588.c: Remove -DDEBUG from dg-options.
(main): Remove debugging code and simplify.

Diff:
---
 gcc/testsuite/gcc.dg/pr116588.c | 13 +++--
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr116588.c b/gcc/testsuite/gcc.dg/pr116588.c
index 6b0678d465ed..481772a54e15 100644
--- a/gcc/testsuite/gcc.dg/pr116588.c
+++ b/gcc/testsuite/gcc.dg/pr116588.c
@@ -1,7 +1,7 @@
 /* PR tree-optimization/116588 */
 /* { dg-do run { target bitint575 } } */
 /* { dg-require-effective-target int128 } */
-/* { dg-options "-O2 -fno-vect-cost-model -fno-tree-dominator-opts 
-fno-tree-fre --param=vrp-block-limit=0  -DDEBUG -fdump-tree-vrp2-details" } */
+/* { dg-options "-O2 -fno-vect-cost-model -fno-tree-dominator-opts 
-fno-tree-fre --param=vrp-block-limit=0 -fdump-tree-vrp2-details" } */
 
 int a;
 __int128 b, c;
@@ -18,15 +18,8 @@ foo (_BitInt (129) e)
 int
 main ()
 {
-  __int128 x = foo (0);
-#ifdef DEBUG
-  for (unsigned i = 0; i < sizeof (x); i++)
-__builtin_printf ("%02x", i[(volatile unsigned char *) &x]);
-  __builtin_printf("\n");
-#else
-  if (x)
-__builtin_abort();
-#endif
+  if (foo (0))
+__builtin_abort ();
 }
 
 /* { dg-final { scan-tree-dump-not "0 != 0" "vrp2" } } */


[gcc r15-3525] libiberty: Fix up > 64K section handling in simple_object_elf_copy_lto_debug_section [PR116614]

2024-09-07 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:bb8dd0980b39cfd601f88703fd356055727ef24d

commit r15-3525-gbb8dd0980b39cfd601f88703fd356055727ef24d
Author: Jakub Jelinek 
Date:   Sat Sep 7 09:36:53 2024 +0200

libiberty: Fix up > 64K section handling in 
simple_object_elf_copy_lto_debug_section [PR116614]

cat abc.C
  #define A(n) struct T##n {} t##n;
  #define B(n) A(n##0) A(n##1) A(n##2) A(n##3) A(n##4) A(n##5) A(n##6) 
A(n##7) A(n##8) A(n##9)
  #define C(n) B(n##0) B(n##1) B(n##2) B(n##3) B(n##4) B(n##5) B(n##6) 
B(n##7) B(n##8) B(n##9)
  #define D(n) C(n##0) C(n##1) C(n##2) C(n##3) C(n##4) C(n##5) C(n##6) 
C(n##7) C(n##8) C(n##9)
  #define E(n) D(n##0) D(n##1) D(n##2) D(n##3) D(n##4) D(n##5) D(n##6) 
D(n##7) D(n##8) D(n##9)
  E(1) E(2) E(3)
  int main () { return 0; }
./xg++ -B ./ -o abc{.o,.C} -flto -flto-partition=1to1 -O2 -g 
-fdebug-types-section -c
./xgcc -B ./ -o abc{,.o} -flto -flto-partition=1to1 -O2
(not included in testsuite as it takes a while to compile) FAILs with
lto-wrapper: fatal error: Too many copied sections: Operation not supported
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

The following patch fixes that.  Most of the 64K+ section support for
reading and writing was already there years ago (and especially reading used
quite often already) and a further bug fixed in it in the PR104617 fix.

Yet, the fix isn't solely about removing the
  if (new_i - 1 >= SHN_LORESERVE)
{
  *err = ENOTSUP;
  return "Too many copied sections";
}
5 lines, the missing part was that the function only handled reading of
the .symtab_shndx section but not copying/updating of it.
If the result has less than 64K-epsilon sections, that actually wasn't
needed, but e.g. with -fdebug-types-section one can exceed that pretty
easily (reported to us on WebKitGtk build on ppc64le).
Updating the section is slightly more complicated, because it basically
needs to be done in lock step with updating the .symtab section, if one
doesn't need to use SHN_XINDEX in there, the section should (or should be
updated to) contain SHN_UNDEF entry, otherwise needs to have whatever would
be overwise stored but couldn't fit.  But repeating due to that all the
symtab decisions what to discard and how to rewrite it would be ugly.

So, the patch instead emits the .symtab_shndx section (or sections) last
and prepares the content during the .symtab processing and in a second
pass when going just through .symtab_shndx sections just uses the saved
content.

2024-09-07  Jakub Jelinek  

PR lto/116614
* simple-object-elf.c (SHN_COMMON): Align comment with neighbouring
comments.
(SHN_HIRESERVE): Use uppercase hex digits instead of lowercase for
consistency.
(simple_object_elf_find_sections): Formatting fixes.
(simple_object_elf_fetch_attributes): Likewise.
(simple_object_elf_attributes_merge): Likewise.
(simple_object_elf_start_write): Likewise.
(simple_object_elf_write_ehdr): Likewise.
(simple_object_elf_write_shdr): Likewise.
(simple_object_elf_write_to_file): Likewise.
(simple_object_elf_copy_lto_debug_section): Likewise.  Don't fail 
for
new_i - 1 >= SHN_LORESERVE, instead arrange in that case to copy
over .symtab_shndx sections, though emit those last and compute 
their
section content when processing associated .symtab sections.  Handle
simple_object_internal_read failure even in the .symtab_shndx 
reading
case.

Diff:
---
 libiberty/simple-object-elf.c | 210 --
 1 file changed, 143 insertions(+), 67 deletions(-)

diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c
index c09c216656c2..5e95297b2fc1 100644
--- a/libiberty/simple-object-elf.c
+++ b/libiberty/simple-object-elf.c
@@ -128,9 +128,9 @@ typedef struct {
 
 #define SHN_UNDEF  0   /* Undefined section */
 #define SHN_LORESERVE  0xFF00  /* Begin range of reserved indices */
-#define SHN_COMMON 0xFFF2  /* Associated symbol is in common */
+#define SHN_COMMON 0xFFF2  /* Associated symbol is in common */
 #define SHN_XINDEX 0x  /* Section index is held elsewhere */
-#define SHN_HIRESERVE  0x  /* End of reserved indices */
+#define SHN_HIRESERVE  0x  /* End of reserved indices */
 
 
 /* 32-bit ELF program header.  */
@@ -569,8 +569,8 @@ simple_object_elf_find_sections (simple_object_read *sobj,
 void *data,
 int *err)
 {
-  struct simple_object_elf_read *eor =
-(struct simple_object_elf_read *) sobj->data;
+  struct simple_object_elf

[gcc r15-3513] c++: Partially implement CWG 2867 - Order of initialization for structured bindings [PR115769]

2024-09-06 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:964577c31df206d780d5cc7bc07189d44de2719e

commit r15-3513-g964577c31df206d780d5cc7bc07189d44de2719e
Author: Jakub Jelinek 
Date:   Fri Sep 6 13:50:47 2024 +0200

c++: Partially implement CWG 2867 - Order of initialization for structured 
bindings [PR115769]

The following patch partially implements CWG 2867
- Order of initialization for structured bindings.
The DR requires that initialization of e is sequenced before r_i and
that r_i initialization is sequenced before r_j for j > i, we already do it
that way, the former ordering is a necessity so that the get calls are
actually emitted on already initialized variable, the rest just because
we implemented it that way, by going through the structured binding
vars in ascending order and doing their initialization.

The hard part not implemented yet is the lifetime extension of the
temporaries from the e initialization to after the get calls (if any).
Unlike the range-for lifetime extension patch which I've posted recently
where IMO we can just ignore lifetime extension of reference bound
temporaries because all the temporaries are extended to the same spot,
here lifetime extension of reference bound temporaries should last until
the end of lifetime of e, while other temporaries only after all the get
calls.

The patch just attempts to deal with automatic structured bindings for now,
I'll post a patch for static locals incrementally and I don't have a patch
for namespace scope structured bindings yet, this patch should just keep
existing behavior for both static locals and namespace scope structured
bindings.

What GCC currently emits is a CLEANUP_POINT_EXPR around the e
initialization, followed optionally by nested CLEANUP_STMTs for cleanups
like the e dtor if any and dtors of lifetime extended temporaries from
reference binding; inside of the CLEANUP_STMT CLEANUP_BODY then the
initialization of the individual variables for the tuple case, again with
optional CLEANUP_STMT if e.g. lifetime extended temporaries from reference
binding are needed in those.

The following patch drops that first CLEANUP_POINT_EXPR and instead
wraps the whole sequence of the e initialization and the individual variable
initialization with get calls after it into a single CLEANUP_POINT_EXPR.
If there are any CLEANUP_STMTs needed, they are all emitted first, with
the CLEANUP_POINT_EXPR for e initialization and the individual variable
initialization inside of those, and a guard variable set after different
phases in those expressions guarding the corresponding cleanups, so that
they aren't invoked until the respective variables are constructed.
This is implemented by cp_finish_decl doing cp_finish_decomp on its own
when !processing_template_decl (otherwise we often don't cp_finish_decl
or process it at a different time from when we want to call
cp_finish_decomp) or unless the decl is erroneous (cp_finish_decl has
too many early returns for erroneous cases, and for those we can actually
call it even multiple times, for the non-erroneous cases
non-processing_template_decl cases we need to call it just once).

The two testcases try to construct various temporaries and variables and
verify the order in which the temporaries and variables are constructed and
destructed.

2024-09-06  Jakub Jelinek  

PR c++/115769
* cp-tree.h: Partially implement CWG 2867 - Order of initialization
for structured bindings.
(cp_finish_decomp): Add TEST_P argument defaulted to false.
* decl.cc (initialize_local_var): Add DECOMP argument, if true,
don't build cleanup and temporarily override stmts_are_full_exprs_p
to 0 rather than 1.  Formatting fix.
(cp_finish_decl): Invoke cp_finish_decomp for structured bindings
here, first with test_p.  For automatic structured binding bases
if the test cp_finish_decomp returned true wrap the initialization
together with what non-test cp_finish_decomp emits with a
CLEANUP_POINT_EXPR, and if there are any CLEANUP_STMTs needed, emit
them around the whole CLEANUP_POINT_EXPR with guard variables for 
the
cleanups.  Call cp_finish_decomp using RAII if not called with
decomp != NULL otherwise.
(cp_finish_decomp): Add TEST_P argument, change return type from
void to bool, if TEST_P is true, return true instead of emitting
actual code for the tuple case, otherwise return false.
* parser.cc (cp_convert_range_for): Don't call cp_finish_decomp
after cp_finish_decl.
(cp_parser_decomposition_declaration): Set DECL_DECOMP_BASE
before cp_finish_decl call.  Don't call cp_finish_decomp after

[gcc r14-10646] libsanitizer: On aarch64 use hint #34 in prologue of libsanitizer functions

2024-09-05 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:24909512101d59807f6d23a9963d64390eca8f60

commit r14-10646-g24909512101d59807f6d23a9963d64390eca8f60
Author: Jakub Jelinek 
Date:   Thu Sep 5 12:20:57 2024 +0200

libsanitizer: On aarch64 use hint #34 in prologue of libsanitizer functions

When gcc is built with -mbranch-protection=standard, running sanitized
programs doesn't work properly on bti enabled kernels.

This has been fixed upstream with
https://github.com/llvm/llvm-project/pull/84061

The following patch cherry picks that from upstream.

For trunk we should eventually do a full merge from upstream, but I'm hoping
they will first fix up the _BitInt libubsan support mess.

2024-09-05  Jakub Jelinek  

* sanitizer_common/sanitizer_asm.h: Cherry-pick llvm-project 
revision
1c792d24e0a228ad49cc004a1c26bbd7cd87f030.
* interception/interception.h: Likewise.

(cherry picked from commit 2379cbb94b2668227c237c94c82e3c49fe39fd0f)

Diff:
---
 libsanitizer/interception/interception.h  |  4 ++--
 libsanitizer/sanitizer_common/sanitizer_asm.h | 14 --
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/libsanitizer/interception/interception.h 
b/libsanitizer/interception/interception.h
index 58e969378a9..73135b34bee 100644
--- a/libsanitizer/interception/interception.h
+++ b/libsanitizer/interception/interception.h
@@ -204,11 +204,11 @@ const interpose_substitution substitution_##func_name[]   
  \
".type  " SANITIZER_STRINGIFY(TRAMPOLINE(func)) ", "
\
  ASM_TYPE_FUNCTION_STR "\n"
\
SANITIZER_STRINGIFY(TRAMPOLINE(func)) ":\n" 
\
-   SANITIZER_STRINGIFY(CFI_STARTPROC) "\n" 
\
+   C_ASM_STARTPROC "\n"
\
C_ASM_TAIL_CALL(SANITIZER_STRINGIFY(TRAMPOLINE(func)),  
\
"__interceptor_"
\
  SANITIZER_STRINGIFY(ASM_PREEMPTIBLE_SYM(func))) "\n"  
\
-   SANITIZER_STRINGIFY(CFI_ENDPROC) "\n"   
\
+   C_ASM_ENDPROC "\n"  
\
".size  " SANITIZER_STRINGIFY(TRAMPOLINE(func)) ", "
\
 ".-" SANITIZER_STRINGIFY(TRAMPOLINE(func)) "\n"
\
  );
diff --git a/libsanitizer/sanitizer_common/sanitizer_asm.h 
b/libsanitizer/sanitizer_common/sanitizer_asm.h
index 3af66a4e449..30e9d15184e 100644
--- a/libsanitizer/sanitizer_common/sanitizer_asm.h
+++ b/libsanitizer/sanitizer_common/sanitizer_asm.h
@@ -42,6 +42,16 @@
 # define CFI_RESTORE(reg)
 #endif
 
+#if defined(__aarch64__) && defined(__ARM_FEATURE_BTI_DEFAULT)
+# define ASM_STARTPROC CFI_STARTPROC; hint #34
+# define C_ASM_STARTPROC SANITIZER_STRINGIFY(CFI_STARTPROC) "\nhint #34"
+#else
+# define ASM_STARTPROC CFI_STARTPROC
+# define C_ASM_STARTPROC SANITIZER_STRINGIFY(CFI_STARTPROC)
+#endif
+#define ASM_ENDPROC CFI_ENDPROC
+#define C_ASM_ENDPROC SANITIZER_STRINGIFY(CFI_ENDPROC)
+
 #if defined(__x86_64__) || defined(__i386__) || defined(__sparc__)
 # define ASM_TAIL_CALL jmp
 #elif defined(__arm__) || defined(__aarch64__) || defined(__mips__) || \
@@ -114,9 +124,9 @@
  .globl __interceptor_trampoline_##name;   
\
  ASM_TYPE_FUNCTION(__interceptor_trampoline_##name);   
\
  __interceptor_trampoline_##name:  
\
- CFI_STARTPROC;
\
+ ASM_STARTPROC;
\
  ASM_TAIL_CALL ASM_PREEMPTIBLE_SYM(__interceptor_##name);  
\
- CFI_ENDPROC;  
\
+ ASM_ENDPROC;  
\
  ASM_SIZE(__interceptor_trampoline_##name)
 #  define ASM_INTERCEPTOR_TRAMPOLINE_SUPPORT 1
 # endif  // Architecture supports interceptor trampoline


[gcc r14-10645] lower-bitint: Fix up __builtin_{add, sub}_overflow{, _p} bitint lowering [PR116501]

2024-09-05 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:73afc3e47e235f3a68abb1c7ce52a9d82003bdab

commit r14-10645-g73afc3e47e235f3a68abb1c7ce52a9d82003bdab
Author: Jakub Jelinek 
Date:   Tue Sep 3 10:20:44 2024 +0200

lower-bitint: Fix up __builtin_{add,sub}_overflow{,_p} bitint lowering 
[PR116501]

The following testcase is miscompiled.  The problem is in the last_ovf step.
The second operand has signed _BitInt(513) type but has the MSB clear,
so range_to_prec returns 512 for it (i.e. it fits into unsigned
_BitInt(512)).  Because of that the last step actually doesn't need to get
the most significant bit from the second operand, but the code was deciding
what to use purely from TYPE_UNSIGNED (type1) - if unsigned, use 0,
otherwise sign-extend the last processed bit; but that in this case was set.
We don't want to treat the positive operand as if it was negative regardless
of the bit below that precision, and precN >= 0 indicates that the operand
is in the [0, inf) range.

2024-09-03  Jakub Jelinek  

PR tree-optimization/116501
* gimple-lower-bitint.cc (bitint_large_huge::lower_addsub_overflow):
In the last_ovf case, use build_zero_cst operand not just when
TYPE_UNSIGNED (typeN), but also when precN >= 0.

* gcc.dg/torture/bitint-73.c: New test.

(cherry picked from commit d4d75a83007e884bfcd632ea3b3269704496f048)

Diff:
---
 gcc/gimple-lower-bitint.cc   |  4 ++--
 gcc/testsuite/gcc.dg/torture/bitint-73.c | 20 
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index b10593035c3..58deaf253e9 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -4192,7 +4192,7 @@ bitint_large_huge::lower_addsub_overflow (tree obj, 
gimple *stmt)
   else
{
  m_data_cnt = data_cnt;
- if (TYPE_UNSIGNED (type0))
+ if (TYPE_UNSIGNED (type0) || prec0 >= 0)
rhs1 = build_zero_cst (m_limb_type);
  else
{
@@ -4210,7 +4210,7 @@ bitint_large_huge::lower_addsub_overflow (tree obj, 
gimple *stmt)
  rhs1 = add_cast (m_limb_type, gimple_assign_lhs (g));
}
}
- if (TYPE_UNSIGNED (type1))
+ if (TYPE_UNSIGNED (type1) || prec1 >= 0)
rhs2 = build_zero_cst (m_limb_type);
  else
{
diff --git a/gcc/testsuite/gcc.dg/torture/bitint-73.c 
b/gcc/testsuite/gcc.dg/torture/bitint-73.c
new file mode 100644
index 000..1e15f391257
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-73.c
@@ -0,0 +1,20 @@
+/* PR tree-optimization/116501 */
+/* { dg-do run { target bitint575 } } */
+/* { dg-options "-std=c23" } */
+/* { dg-skip-if "" { ! run_expensive_tests }  { "*" } { "-O0" "-O2" } } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
+
+_BitInt (4) a;
+
+int
+foo (_BitInt(513) b)
+{
+  return __builtin_sub_overflow_p (a, b, (_BitInt (511)) 0);
+}
+
+int
+main ()
+{
+  if (!foo 
(0xwb))
+__builtin_abort ();
+}


[gcc r14-10644] Don't call clean_symbol_name in create_tmp_var_name [PR116219]

2024-09-05 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:6fb41c27b62b5774108455d13f5b7a67c9cbdfa3

commit r14-10644-g6fb41c27b62b5774108455d13f5b7a67c9cbdfa3
Author: Jakub Jelinek 
Date:   Wed Aug 7 20:14:31 2024 +0200

Don't call clean_symbol_name in create_tmp_var_name [PR116219]

SRA adds fancy names like offset$D94316$_M_impl$D93629$_M_start
where the numbers in there are DECL_UIDs if there are unnamed
FIELD_DECLs etc.
Because -g0 vs. -g can cause differences between the exact DECL_UID
values (add bigger gaps in between them, corresponding decls should
still be ordered the same based on DECL_UID) we make sure such
decls have DECL_NAMELESS set and depending on exact options either don't
dump such names at all or dump_fancy_name sanitizes the D123456$ parts in
there to D$.
Unfortunately in tons of places we then use get_name to grab either user
names or these SRA created names and use that as argument to
create_tmp_var{,_name,_raw} to base other artificial temporary names based
on that.  Those are DECL_NAMELESS too, but unfortunately create_tmp_var_name
starting with

https://gcc.gnu.org/git/?p=gcc.git&a=commit;h=725494f6e4121eace43b7db1202f8ecbf52a8276
calls clean_symbol_name which replaces the $s in there with _s and thus
dump_fancy_name doesn't sanitize it anymore.

I don't see any discussion of that commit (originally to TM branch, later
merged) on the mailing list, but from
   DECL_NAME (new_decl)
 = create_tmp_var_name (IDENTIFIER_POINTER (DECL_NAME (old_decl)));
-  SET_DECL_ASSEMBLER_NAME (new_decl, NULL_TREE);
+  SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
snippet elsewhere in that commit it seems create_tmp_var_name was used at
that point also to determine function names of clones, so presumably the
clean_symbol_name at that point was to ensure the symbol could be emitted
into assembly, maybe in case DECL_NAME is something like C++ operators or
whatever could have there undesirable characters.

Anyway, we don't do that for years anymore, already GCC 4.5 uses for such
purposes clone_function_name which starts of DECL_ASSEMBLER_NAME of the old
function and appends based on supportable symbol suffix separators the
separator and some suffix and/or number, so that part doesn't go through
create_tmp_var_name.

I don't see problems with having the $ and . etc. characters in the names
intended just to make dumps more readable, after all, we already are using
those in the SRA created names.  Those names shouldn't make it into the
assembly in any way, neither debug info nor assembly labels.

There is one theoretical case, where the gimplifier promotes automatic
vars into TREE_STATIC ones and therefore those can then appear in assembly,
just in case it would be on e.g. SRA created names and regimplified later.
Because no cases of promotion of DECL_NAMELESS vars to static was observed 
in
{x86_64,i686,powerpc64le}-linux bootstraps/regtests, the code simply uses
C.NNN names for DECL_NAMELESS vars like it does for !DECL_NAME vars.

Richi mentioned on IRC that the non-cleaned up names might make things
harder to feed stuff back to the GIMPLE FE, but if so, I think it should be
the dumping for GIMPLE FE purposes that cleans those up (but at that point
it should also verify if some such cleaned up names don't collide with
others and somehow deal with those).

2024-08-07  Jakub Jelinek  

PR c++/116219
* gimple-expr.cc (remove_suffix): Formatting fixes.
(create_tmp_var_name): Don't call clean_symbol_name.
* gimplify.cc (gimplify_init_constructor): When promoting automatic
DECL_NAMELESS vars to static, don't preserve their DECL_NAME.

(cherry picked from commit 165e3e7c3ba884345647c0f1c9a3a57a03383651)

Diff:
---
 gcc/gimple-expr.cc | 16 ++--
 gcc/gimplify.cc|  2 +-
 2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/gcc/gimple-expr.cc b/gcc/gimple-expr.cc
index f8d7185530c..0477c9d5f44 100644
--- a/gcc/gimple-expr.cc
+++ b/gcc/gimple-expr.cc
@@ -406,14 +406,12 @@ remove_suffix (char *name, int len)
 {
   int i;
 
-  for (i = 2;  i < 7 && len > i;  i++)
-{
-  if (name[len - i] == '.')
-   {
- name[len - i] = '\0';
- break;
-   }
-}
+  for (i = 2; i < 7 && len > i; i++)
+if (name[len - i] == '.')
+  {
+   name[len - i] = '\0';
+   break;
+  }
 }
 
 /* Create a new temporary name with PREFIX.  Return an identifier.  */
@@ -430,8 +428,6 @@ create_tmp_var_name (const char *prefix)
   char *preftmp = ASTRDUP (prefix);
 
   remove_suffix (preftmp, strlen (preftmp));
-  clean_symbol_name (preftmp);
-
   prefix = preftmp;
 }
 
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 457b33a4293..5753eb90ff5 100644
--- a/gcc/gimplify.cc
+++ b

[gcc r15-3480] libsanitizer: On aarch64 use hint #34 in prologue of libsanitizer functions

2024-09-05 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:2379cbb94b2668227c237c94c82e3c49fe39fd0f

commit r15-3480-g2379cbb94b2668227c237c94c82e3c49fe39fd0f
Author: Jakub Jelinek 
Date:   Thu Sep 5 12:20:57 2024 +0200

libsanitizer: On aarch64 use hint #34 in prologue of libsanitizer functions

When gcc is built with -mbranch-protection=standard, running sanitized
programs doesn't work properly on bti enabled kernels.

This has been fixed upstream with
https://github.com/llvm/llvm-project/pull/84061

The following patch cherry picks that from upstream.

For trunk we should eventually do a full merge from upstream, but I'm hoping
they will first fix up the _BitInt libubsan support mess.

2024-09-05  Jakub Jelinek  

* sanitizer_common/sanitizer_asm.h: Cherry-pick llvm-project 
revision
1c792d24e0a228ad49cc004a1c26bbd7cd87f030.
* interception/interception.h: Likewise.

Diff:
---
 libsanitizer/interception/interception.h  |  4 ++--
 libsanitizer/sanitizer_common/sanitizer_asm.h | 14 --
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/libsanitizer/interception/interception.h 
b/libsanitizer/interception/interception.h
index 58e969378a9..73135b34bee 100644
--- a/libsanitizer/interception/interception.h
+++ b/libsanitizer/interception/interception.h
@@ -204,11 +204,11 @@ const interpose_substitution substitution_##func_name[]   
  \
".type  " SANITIZER_STRINGIFY(TRAMPOLINE(func)) ", "
\
  ASM_TYPE_FUNCTION_STR "\n"
\
SANITIZER_STRINGIFY(TRAMPOLINE(func)) ":\n" 
\
-   SANITIZER_STRINGIFY(CFI_STARTPROC) "\n" 
\
+   C_ASM_STARTPROC "\n"
\
C_ASM_TAIL_CALL(SANITIZER_STRINGIFY(TRAMPOLINE(func)),  
\
"__interceptor_"
\
  SANITIZER_STRINGIFY(ASM_PREEMPTIBLE_SYM(func))) "\n"  
\
-   SANITIZER_STRINGIFY(CFI_ENDPROC) "\n"   
\
+   C_ASM_ENDPROC "\n"  
\
".size  " SANITIZER_STRINGIFY(TRAMPOLINE(func)) ", "
\
 ".-" SANITIZER_STRINGIFY(TRAMPOLINE(func)) "\n"
\
  );
diff --git a/libsanitizer/sanitizer_common/sanitizer_asm.h 
b/libsanitizer/sanitizer_common/sanitizer_asm.h
index 3af66a4e449..30e9d15184e 100644
--- a/libsanitizer/sanitizer_common/sanitizer_asm.h
+++ b/libsanitizer/sanitizer_common/sanitizer_asm.h
@@ -42,6 +42,16 @@
 # define CFI_RESTORE(reg)
 #endif
 
+#if defined(__aarch64__) && defined(__ARM_FEATURE_BTI_DEFAULT)
+# define ASM_STARTPROC CFI_STARTPROC; hint #34
+# define C_ASM_STARTPROC SANITIZER_STRINGIFY(CFI_STARTPROC) "\nhint #34"
+#else
+# define ASM_STARTPROC CFI_STARTPROC
+# define C_ASM_STARTPROC SANITIZER_STRINGIFY(CFI_STARTPROC)
+#endif
+#define ASM_ENDPROC CFI_ENDPROC
+#define C_ASM_ENDPROC SANITIZER_STRINGIFY(CFI_ENDPROC)
+
 #if defined(__x86_64__) || defined(__i386__) || defined(__sparc__)
 # define ASM_TAIL_CALL jmp
 #elif defined(__arm__) || defined(__aarch64__) || defined(__mips__) || \
@@ -114,9 +124,9 @@
  .globl __interceptor_trampoline_##name;   
\
  ASM_TYPE_FUNCTION(__interceptor_trampoline_##name);   
\
  __interceptor_trampoline_##name:  
\
- CFI_STARTPROC;
\
+ ASM_STARTPROC;
\
  ASM_TAIL_CALL ASM_PREEMPTIBLE_SYM(__interceptor_##name);  
\
- CFI_ENDPROC;  
\
+ ASM_ENDPROC;  
\
  ASM_SIZE(__interceptor_trampoline_##name)
 #  define ASM_INTERCEPTOR_TRAMPOLINE_SUPPORT 1
 # endif  // Architecture supports interceptor trampoline


[gcc r15-3476] vrp: Fix up diagnostics wording

2024-09-05 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:e9e4777ca2415a73e8db64a406c06a79add621e5

commit r15-3476-ge9e4777ca2415a73e8db64a406c06a79add621e5
Author: Jakub Jelinek 
Date:   Thu Sep 5 11:06:12 2024 +0200

vrp: Fix up diagnostics wording

I've noticed non-standard wording of this diagnostics when looking at
a miscompilation with --param=vrp-block-limit=0.

Diagnostics generally shouldn't start with uppercase letter (unless
the upper case would appear also in the middle of a sentence) and shouldn't
be separate sentences with dot as separator, ; is IMHO more frequently used.

2024-09-05  Jakub Jelinek  

* tree-vrp.cc (pass_vrp::execute): Start diagnostics with
lowercase u rather than capital U, use semicolon instead of dot.

Diff:
---
 gcc/tree-vrp.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
index e184e9af51e..23946c57413 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -1337,7 +1337,7 @@ public:
{
  use_fvrp = true;
  warning (OPT_Wdisabled_optimization,
-  "Using fast VRP algorithm. %d basic blocks"
+  "using fast VRP algorithm; %d basic blocks"
   " exceeds %<--param=vrp-block-limit=%d%> limit",
   n_basic_blocks_for_fn (fun),
   param_vrp_block_limit);


[gcc r15-3408] lower-bitint: Fix up __builtin_{add, sub}_overflow{, _p} bitint lowering [PR116501]

2024-09-03 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:d4d75a83007e884bfcd632ea3b3269704496f048

commit r15-3408-gd4d75a83007e884bfcd632ea3b3269704496f048
Author: Jakub Jelinek 
Date:   Tue Sep 3 10:20:44 2024 +0200

lower-bitint: Fix up __builtin_{add,sub}_overflow{,_p} bitint lowering 
[PR116501]

The following testcase is miscompiled.  The problem is in the last_ovf step.
The second operand has signed _BitInt(513) type but has the MSB clear,
so range_to_prec returns 512 for it (i.e. it fits into unsigned
_BitInt(512)).  Because of that the last step actually doesn't need to get
the most significant bit from the second operand, but the code was deciding
what to use purely from TYPE_UNSIGNED (type1) - if unsigned, use 0,
otherwise sign-extend the last processed bit; but that in this case was set.
We don't want to treat the positive operand as if it was negative regardless
of the bit below that precision, and precN >= 0 indicates that the operand
is in the [0, inf) range.

2024-09-03  Jakub Jelinek  

PR tree-optimization/116501
* gimple-lower-bitint.cc (bitint_large_huge::lower_addsub_overflow):
In the last_ovf case, use build_zero_cst operand not just when
TYPE_UNSIGNED (typeN), but also when precN >= 0.

* gcc.dg/torture/bitint-73.c: New test.

Diff:
---
 gcc/gimple-lower-bitint.cc   |  4 ++--
 gcc/testsuite/gcc.dg/torture/bitint-73.c | 20 
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index b10593035c36..58deaf253e93 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -4192,7 +4192,7 @@ bitint_large_huge::lower_addsub_overflow (tree obj, 
gimple *stmt)
   else
{
  m_data_cnt = data_cnt;
- if (TYPE_UNSIGNED (type0))
+ if (TYPE_UNSIGNED (type0) || prec0 >= 0)
rhs1 = build_zero_cst (m_limb_type);
  else
{
@@ -4210,7 +4210,7 @@ bitint_large_huge::lower_addsub_overflow (tree obj, 
gimple *stmt)
  rhs1 = add_cast (m_limb_type, gimple_assign_lhs (g));
}
}
- if (TYPE_UNSIGNED (type1))
+ if (TYPE_UNSIGNED (type1) || prec1 >= 0)
rhs2 = build_zero_cst (m_limb_type);
  else
{
diff --git a/gcc/testsuite/gcc.dg/torture/bitint-73.c 
b/gcc/testsuite/gcc.dg/torture/bitint-73.c
new file mode 100644
index ..1e15f3912574
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-73.c
@@ -0,0 +1,20 @@
+/* PR tree-optimization/116501 */
+/* { dg-do run { target bitint575 } } */
+/* { dg-options "-std=c23" } */
+/* { dg-skip-if "" { ! run_expensive_tests }  { "*" } { "-O0" "-O2" } } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
+
+_BitInt (4) a;
+
+int
+foo (_BitInt(513) b)
+{
+  return __builtin_sub_overflow_p (a, b, (_BitInt (511)) 0);
+}
+
+int
+main ()
+{
+  if (!foo 
(0xwb))
+__builtin_abort ();
+}


[gcc r15-3387] testsuite: Fix optimize_one.c FAIL on i686-linux

2024-09-02 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:b64980b0776c8e061696832e74e300e3c720

commit r15-3387-gb64980b0776c8e061696832e74e300e3c720
Author: Jakub Jelinek 
Date:   Mon Sep 2 20:14:49 2024 +0200

testsuite: Fix optimize_one.c FAIL on i686-linux

The test FAILs on i686-linux because -mfpmath=sse is used without
-msse2 being enabled.

2024-09-02  Jakub Jelinek  

* gcc.target/i386/optimize_one.c: Add -msse2 to dg-options.

Diff:
---
 gcc/testsuite/gcc.target/i386/optimize_one.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/i386/optimize_one.c 
b/gcc/testsuite/gcc.target/i386/optimize_one.c
index 62728d3c5ba4..3a682ed4028f 100644
--- a/gcc/testsuite/gcc.target/i386/optimize_one.c
+++ b/gcc/testsuite/gcc.target/i386/optimize_one.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -mfpmath=sse" } */
+/* { dg-options "-O2 -mfpmath=sse -msse2" } */
 /* { dg-final { scan-assembler-times "comi" 1 } } */
 /* { dg-final { scan-assembler-times "set" 1 } } */


[gcc r15-3364] ranger: Fix up range computation for CLZ [PR116486]

2024-09-02 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:25d51fb7d098a9ac8880ccb2121d889815680177

commit r15-3364-g25d51fb7d098a9ac8880ccb2121d889815680177
Author: Jakub Jelinek 
Date:   Mon Sep 2 09:44:09 2024 +0200

ranger: Fix up range computation for CLZ [PR116486]

The initial CLZ gimple-range-op.cc implementation handled just the
case where second argument to .CLZ is equal to prec, but in
r15-1014 I've added also handling of the -1 case.  As the following
testcase shows, incorrectly though for the case where the first argument
has [0,0] range.  If the second argument is prec, then the result should
be [prec,prec] and that was handled correctly, but when the second argument
is -1, the result should be [-1,-1] but instead it was incorrectly computed
as [prec-1,prec-1] (when second argument is prec, mini is 0 and maxi is
prec, while when second argument is -1, mini is -1 and maxi is prec-1).

Fixed thusly (the actual handling is then similar to the CTZ [0,0] case).

2024-09-02  Jakub Jelinek  

PR middle-end/116486
* gimple-range-op.cc (cfn_clz::fold_range): If lh is [0,0]
and mini is -1, return [-1,-1] range rather than [prec-1,prec-1].

* gcc.dg/bitint-109.c: New test.

Diff:
---
 gcc/gimple-range-op.cc|  6 --
 gcc/testsuite/gcc.dg/bitint-109.c | 25 +
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc
index d1c527191f4a..68a7df8d01bc 100644
--- a/gcc/gimple-range-op.cc
+++ b/gcc/gimple-range-op.cc
@@ -972,8 +972,10 @@ cfn_clz::fold_range (irange &r, tree type, const irange 
&lh,
 {
   // If CLZ_DEFINED_VALUE_AT_ZERO is 2 with VALUE of prec,
   // return [prec, prec] or [-1, -1], otherwise ignore the range.
-  if (maxi == prec || mini == -1)
-   mini = maxi;
+  if (maxi == prec)
+   mini = prec;
+  else if (mini == -1)
+   maxi = -1;
 }
   else if (mini >= 0)
 mini = newmini;
diff --git a/gcc/testsuite/gcc.dg/bitint-109.c 
b/gcc/testsuite/gcc.dg/bitint-109.c
new file mode 100644
index ..84c4314cdf9d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/bitint-109.c
@@ -0,0 +1,25 @@
+/* PR middle-end/116486 */
+/* { dg-do run { target bitint } } */
+/* { dg-options "-O2 -fno-tree-ccp" } */
+
+unsigned u;
+
+#if __BITINT_MAXWIDTH__ >= 129
+#define N 0x1uwb
+#else
+#define N 0xuwb
+#endif
+
+int
+foo (void)
+{
+  return __builtin_stdc_first_leading_one (u / N);
+}
+
+int
+main ()
+{
+  int x = foo ();
+  if (x)
+__builtin_abort ();
+}


[gcc r15-3331] c++: Add unsequenced C++ testcase

2024-08-31 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:afd9558b94eb78ef3e9a8818f2d57f9311e99b4f

commit r15-3331-gafd9558b94eb78ef3e9a8818f2d57f9311e99b4f
Author: Jakub Jelinek 
Date:   Sat Aug 31 16:03:20 2024 +0200

c++: Add unsequenced C++ testcase

This is the testcase I wrote originally and which on top of the
https://gcc.gnu.org/pipermail/gcc-patches/2024-August/659154.html
patch didn't behave the way I wanted (no warning and no optimizations of
[[unsequenced]] function templates which don't have pointer/reference
arguments.
Posting this separately, because it depends on the above mentioned
patch as well as the PR116175
https://gcc.gnu.org/pipermail/gcc-patches/2024-August/659157.html
patch.

2024-08-31  Jakub Jelinek  

* g++.dg/ext/attr-unsequenced-1.C: New test.

Diff:
---
 gcc/testsuite/g++.dg/ext/attr-unsequenced-1.C | 53 +++
 1 file changed, 53 insertions(+)

diff --git a/gcc/testsuite/g++.dg/ext/attr-unsequenced-1.C 
b/gcc/testsuite/g++.dg/ext/attr-unsequenced-1.C
new file mode 100644
index ..8e640a8cec1e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attr-unsequenced-1.C
@@ -0,0 +1,53 @@
+// { dg-do compile { target c++11 } }
+// { dg-options "-O2 -fdump-tree-optimized" } */
+// { dg-final { scan-tree-dump-times " bar \\\(1, 2, 3\\\);" 1 
"optimized" } }
+// { dg-final { scan-tree-dump-times " bar \\\(4, 5, 6\\\);" 1 
"optimized" } }
+
+template 
+[[gnu::noipa]] U
+foo (T x, T y, T z) [[gnu::unsequenced]]
+{
+  *x = 1;
+  *y = 2;
+  *z = 3;
+}
+
+template 
+[[gnu::noipa]] T
+bar (T x, T y, T z) [[gnu::unsequenced]]
+{
+  return x + y + z;
+}
+
+int
+baz () [[gnu::unsequenced]]
+{
+  int x, y, z;
+  foo  (&x, &y, &z);
+  return x;
+}
+
+int
+qux () [[gnu::unsequenced]]
+{
+  int a = bar (1, 2, 3);
+  int b = bar (1, 2, 3);
+  int c = bar (1, 2, 3);
+  int d = bar (4, 5, 6);
+  int e = bar (4, 5, 6);
+  int f = bar (4, 5, 6);
+  return a + b + c + d + e + f;
+}
+
+template 
+[[gnu::noipa]] U
+corge (T x, T y, T z) [[gnu::unsequenced]] // { dg-warning "'unsequenced' 
attribute on function type without pointer arguments returning 'void'" }
+{
+  x += y + z;
+}
+
+void
+freddy ()
+{
+  corge  (1, 2, 3);
+}


[gcc r15-3330] c: Add support for unsequenced and reproducible attributes

2024-08-31 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:dd346b613886aea9761dbb5e7a8d6c47922750b2

commit r15-3330-gdd346b613886aea9761dbb5e7a8d6c47922750b2
Author: Jakub Jelinek 
Date:   Sat Aug 31 15:58:23 2024 +0200

c: Add support for unsequenced and reproducible attributes

C23 added in N2956 ( https://open-std.org/JTC1/SC22/WG14/www/docs/n2956.htm 
)
two new attributes, which are described as similar to GCC const and pure
attributes, but they aren't really same and it seems that even the paper
is missing some of the differences.
The paper says unsequenced is the same as const on functions without pointer
arguments and reproducible is the same as pure on such functions (except
that they are function type attributes rather than function
declaration ones), but it seems the paper doesn't consider the finiteness 
GCC
relies on (aka non-DECL_LOOPING_CONST_OR_PURE_P) - the paper only talks
about using the attributes for CSE etc., not for DCE.

The following patch introduces (for now limited) support for those
attributes, both as standard C23 attributes and as GNU extensions (the
difference is that the patch is then less strict on where it allows them,
like other function type attributes they can be specified on function
declarations as well and apply to the type, while C23 standard ones must
go on the function declarators (i.e. after closing paren after function
parameters) or in type specifiers of function type.

If function doesn't have any pointer/reference arguments, the patch
adds additional internal attribute with " noptr" suffix which then is used
by flags_from_decl_or_type to handle those easy cases as
ECF_CONST|ECF_LOOPING_CONST_OR_PURE or
ECF_PURE|ECF_LOOPING_CONST_OR_PURE
The harder cases aren't handled right now, I'd hope they can be handled
incrementally.

I wonder whether we shouldn't emit a warning for the
gcc.dg/c23-attr-{reproducible,unsequenced}-5.c cases, while the standard
clearly specifies that composite types should union the attributes and it
is what GCC implements for decades, for ?: that feels dangerous for the
new attributes, it would be much better to be conservative on say
(cond ? unsequenced_function : normal_function) (args)

There is no diagnostics on incorrect [[unsequenced]] or [[reproducible]]
function definitions, while I think diagnosing non-const static/TLS
declarations in the former could be easy, the rest feels hard.  E.g. the
const/pure discovery can just punt on everything it doesn't understand,
but complete diagnostics would need to understand it.

2024-08-31  Jakub Jelinek  

PR c/116130
gcc/
* doc/extend.texi (unsequenced, reproducible): Document new function
type attributes.
* calls.cc (flags_from_decl_or_type): Handle "unsequenced noptr" and
"reproducible noptr" attributes.
gcc/c-family/
* c-attribs.cc (c_common_gnu_attributes): Add entries for
"unsequenced", "reproducible", "unsequenced noptr" and
"reproducible noptr" attributes.
(handle_unsequenced_attribute): New function.
(handle_reproducible_attribute): Likewise.
* c-common.h (handle_unsequenced_attribute): Declare.
(handle_reproducible_attribute): Likewise.
* c-lex.cc (c_common_has_attribute): Return 202311 for standard
unsequenced and reproducible attributes.
gcc/c/
* c-decl.cc (handle_std_unsequenced_attribute): New function.
(handle_std_reproducible_attribute): Likewise.
(std_attributes): Add entries for "unsequenced" and "reproducible"
attributes.
(c_warn_type_attributes): Add TYPE argument.  Allow unsequenced
or reproducible attributes if it is FUNCTION_TYPE.
(groktypename): Adjust c_warn_type_attributes caller.
(grokdeclarator): Likewise.
(finish_declspecs): Likewise.
* c-parser.cc (c_parser_declaration_or_fndef): Likewise.
* c-tree.h (c_warn_type_attributes): Add TYPE argument.
gcc/testsuite/
* c-c++-common/attr-reproducible-1.c: New test.
* c-c++-common/attr-reproducible-2.c: New test.
* c-c++-common/attr-unsequenced-1.c: New test.
* c-c++-common/attr-unsequenced-2.c: New test.
* gcc.dg/c23-attr-reproducible-1.c: New test.
* gcc.dg/c23-attr-reproducible-2.c: New test.
* gcc.dg/c23-attr-reproducible-3.c: New test.
* gcc.dg/c23-attr-reproducible-4.c: New test.
* gcc.dg/c23-attr-reproducible-5.c: New test.
* gcc.dg/c23-attr-reproducible-5-aux.c: New file.
* gcc.dg/c23-attr-unsequenced-1.c: New test.
* gcc.dg/c23-attr-unsequenced-2.c: New test.
* gcc.dg/c23-attr-unsequenced-3.c: New test.

[gcc r15-3315] c++: Allow standard attributes after closing square bracket in new-type-id [PR110345]

2024-08-30 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:b748e2eed0df9e691a530a0b8faea9f673bdf2b5

commit r15-3315-gb748e2eed0df9e691a530a0b8faea9f673bdf2b5
Author: Jakub Jelinek 
Date:   Fri Aug 30 09:40:34 2024 +0200

c++: Allow standard attributes after closing square bracket in new-type-id 
[PR110345]

For C++ 26 P2552R3 I went through all the spots (except modules) where
attribute-specifier-seq appears in the grammar and tried to construct
a testcase in all those spots, for now for [[deprecated]] attribute.

The first thing I found is that we aren't parsing standard attributes in
noptr-new-declarator - https://eel.is/c++draft/expr.new#1

The following patch parses it there, for the non-outermost arrays
applies normally the attributes to the array type, for the outermost
where we just set *nelts and don't really build an array type just
warns that we ignore those attributes (or, do you think we should
just build an array type in that case and just take its element type?).

2024-08-30  Jakub Jelinek  

PR c++/110345
* parser.cc (make_array_declarator): Add STD_ATTRS argument, set
declarator->std_attributes to it.
(cp_parser_new_type_id): Warn on non-ignored std_attributes on the
array declarator which is being omitted.
(cp_parser_direct_new_declarator): Parse standard attributes after
closing square bracket, pass it to make_array_declarator.
(cp_parser_direct_declarator): Pass std_attrs to 
make_array_declarator
instead of setting declarator->std_attributes manually.

* g++.dg/cpp0x/gen-attrs-80.C: New test.
* g++.dg/cpp0x/gen-attrs-81.C: New test.

Diff:
---
 gcc/cp/parser.cc  | 28 
 gcc/testsuite/g++.dg/cpp0x/gen-attrs-80.C | 10 ++
 gcc/testsuite/g++.dg/cpp0x/gen-attrs-81.C | 11 +++
 3 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 918072dbf637..632d3dc5ecf4 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -1689,7 +1689,7 @@ static cp_declarator *make_call_declarator
   (cp_declarator *, tree, cp_cv_quals, cp_virt_specifiers, cp_ref_qualifier,
tree, tree, tree, tree, tree, location_t);
 static cp_declarator *make_array_declarator
-  (cp_declarator *, tree);
+  (cp_declarator *, tree, tree);
 static cp_declarator *make_pointer_declarator
   (cp_cv_quals, cp_declarator *, tree);
 static cp_declarator *make_reference_declarator
@@ -1904,10 +1904,11 @@ make_call_declarator (cp_declarator *target,
 }
 
 /* Make a declarator for an array of BOUNDS elements, each of which is
-   defined by ELEMENT.  */
+   defined by ELEMENT.  STD_ATTRS contains attributes that appertain to
+   the array type.  */
 
 cp_declarator *
-make_array_declarator (cp_declarator *element, tree bounds)
+make_array_declarator (cp_declarator *element, tree bounds, tree std_attrs)
 {
   cp_declarator *declarator;
 
@@ -1923,6 +1924,8 @@ make_array_declarator (cp_declarator *element, tree 
bounds)
   else
 declarator->parameter_pack_p = false;
 
+  declarator->std_attributes = std_attrs;
+
   return declarator;
 }
 
@@ -9789,6 +9792,15 @@ cp_parser_new_type_id (cp_parser* parser, tree *nelts)
   if (*nelts == error_mark_node)
*nelts = integer_one_node;
 
+  /* FIXME: Maybe build even the outermost array type and strip
+it, to diagnose the attributes on it.  Problem is that VLAs aren't
+pedantically allowed except for this case.  */
+  if (*nelts
+ && declarator->std_attributes
+ && any_nonignored_attribute_p (declarator->std_attributes))
+   warning (OPT_Wattributes, "attributes ignored on outermost array "
+ "type in new expression");
+
   if (*nelts == NULL_TREE)
/* Leave [] in the declarator.  */;
   else if (outer_declarator)
@@ -9843,8 +9855,8 @@ cp_parser_new_declarator_opt (cp_parser* parser)
 /* Parse a direct-new-declarator.
 
direct-new-declarator:
- [ expression ]
- direct-new-declarator [constant-expression]
+ [ expression ] attribute-specifier-seq [opt]
+ direct-new-declarator [constant-expression] attribute-specifier-seq [opt]
 
*/
 
@@ -9891,8 +9903,9 @@ cp_parser_direct_new_declarator (cp_parser* parser)
   /* Look for the closing `]'.  */
   cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
 
+  tree attrs = cp_parser_std_attribute_spec_seq (parser);
   /* Add this bound to the declarator.  */
-  declarator = make_array_declarator (declarator, expression);
+  declarator = make_array_declarator (declarator, expression, attrs);
 
   /* If the next token is not a `[', then there are no more
 bounds.  */
@@ -24339,8 +24352,7 @@ cp_parser_direct_declarator (cp_parser* parser,
}
 
  attrs = cp_parser_std_attribute_spec_seq (parser)

[gcc r15-3048] libcpp: Adjust lang_defaults

2024-08-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:447c32c5142a60278230f81ae6e50e41ef6d988e

commit r15-3048-g447c32c5142a60278230f81ae6e50e41ef6d988e
Author: Jakub Jelinek 
Date:   Tue Aug 20 22:25:57 2024 +0200

libcpp: Adjust lang_defaults

The table over the years turned to be very wide, 147 columns
and any addition would add a couple of new ones.
We need a 28x23 bit matrix right now.

This patch changes the formatting, so that we need just 2 columns
per new feature and so we have some room for expansion.
In addition, the patch changes it to bitfields, which reduces
.rodata by 532 bytes (so 5.75x reduction of the variable) and
on x86_64-linux grows the cpp_set_lang function by 26 bytes (8.4%
growth).

2024-08-20  Jakub Jelinek  

* init.cc (struct lang_flags): Change all members from char
typed fields to unsigned bit-fields.
(lang_defaults): Change formatting of the initializer so that it
fits to 68 columns rather than 147.

Diff:
---
 libcpp/init.cc | 112 ++---
 1 file changed, 59 insertions(+), 53 deletions(-)

diff --git a/libcpp/init.cc b/libcpp/init.cc
index 9ae06a9595d9..2dfd9d7e0623 100644
--- a/libcpp/init.cc
+++ b/libcpp/init.cc
@@ -77,61 +77,67 @@ END
requires.  */
 struct lang_flags
 {
-  char c99;
-  char cplusplus;
-  char extended_numbers;
-  char extended_identifiers;
-  char c11_identifiers;
-  char xid_identifiers;
-  char std;
-  char digraphs;
-  char uliterals;
-  char rliterals;
-  char user_literals;
-  char binary_constants;
-  char digit_separators;
-  char trigraphs;
-  char utf8_char_literals;
-  char va_opt;
-  char scope;
-  char dfp_constants;
-  char size_t_literals;
-  char elifdef;
-  char warning_directive;
-  char delimited_escape_seqs;
-  char true_false;
+  unsigned int c99 : 1;
+  unsigned int cplusplus : 1;
+  unsigned int extended_numbers : 1;
+  unsigned int extended_identifiers : 1;
+  unsigned int c11_identifiers : 1;
+  unsigned int xid_identifiers : 1;
+  unsigned int std : 1;
+  unsigned int digraphs : 1;
+  unsigned int uliterals : 1;
+  unsigned int rliterals : 1;
+  unsigned int user_literals : 1;
+  unsigned int binary_constants : 1;
+  unsigned int digit_separators : 1;
+  unsigned int trigraphs : 1;
+  unsigned int utf8_char_literals : 1;
+  unsigned int va_opt : 1;
+  unsigned int scope : 1;
+  unsigned int dfp_constants : 1;
+  unsigned int size_t_literals : 1;
+  unsigned int elifdef : 1;
+  unsigned int warning_directive : 1;
+  unsigned int delimited_escape_seqs : 1;
+  unsigned int true_false : 1;
 };
 
-static const struct lang_flags lang_defaults[] =
-{ /*  c99 c++ xnum xid c11 xidid std digr ulit rlit udlit bincst 
digsep trig u8chlit vaopt scope dfp szlit elifdef warndir delim trufal */
-  /* GNUC89   */  { 0,  0,  1,  0,  0,  0,0,  1,   0,   0,   0,0, 
0, 0,   0,  1,   1, 0,   0,   0,  0,  0,0 },
-  /* GNUC99   */  { 1,  0,  1,  1,  0,  0,0,  1,   1,   1,   0,0, 
0, 0,   0,  1,   1, 0,   0,   0,  0,  0,0 },
-  /* GNUC11   */  { 1,  0,  1,  1,  1,  0,0,  1,   1,   1,   0,0, 
0, 0,   0,  1,   1, 0,   0,   0,  0,  0,0 },
-  /* GNUC17   */  { 1,  0,  1,  1,  1,  0,0,  1,   1,   1,   0,0, 
0, 0,   0,  1,   1, 0,   0,   0,  0,  0,0 },
-  /* GNUC23   */  { 1,  0,  1,  1,  1,  1,0,  1,   1,   1,   0,1, 
1, 0,   1,  1,   1, 1,   0,   1,  1,  0,1 },
-  /* GNUC2Y   */  { 1,  0,  1,  1,  1,  1,0,  1,   1,   1,   0,1, 
1, 0,   1,  1,   1, 1,   0,   1,  1,  0,1 },
-  /* STDC89   */  { 0,  0,  0,  0,  0,  0,1,  0,   0,   0,   0,0, 
0, 1,   0,  0,   0, 0,   0,   0,  0,  0,0 },
-  /* STDC94   */  { 0,  0,  0,  0,  0,  0,1,  1,   0,   0,   0,0, 
0, 1,   0,  0,   0, 0,   0,   0,  0,  0,0 },
-  /* STDC99   */  { 1,  0,  1,  1,  0,  0,1,  1,   0,   0,   0,0, 
0, 1,   0,  0,   0, 0,   0,   0,  0,  0,0 },
-  /* STDC11   */  { 1,  0,  1,  1,  1,  0,1,  1,   1,   0,   0,0, 
0, 1,   0,  0,   0, 0,   0,   0,  0,  0,0 },
-  /* STDC17   */  { 1,  0,  1,  1,  1,  0,1,  1,   1,   0,   0,0, 
0, 1,   0,  0,   0, 0,   0,   0,  0,  0,0 },
-  /* STDC23   */  { 1,  0,  1,  1,  1,  1,1,  1,   1,   0,   0,1, 
1, 0,   1,  1,   1, 1,   0,   1,  1,  0,1 },
-  /* STDC2Y   */  { 1,  0,  1,  1,  1,  1,1,  1,   1,   0,   0,1, 
1, 0,   1,  1,   1, 1,   0,   1,  1,  0,1 },
-  /* GNUCXX   */  { 0,  1,  1,  1,  0,  1,0,  1,   0,   0,   0,0, 
0, 0,   0,  1,   1, 0,   0,   0,  0,  0,1 },
-  /* CXX98*/  { 0,  1,  0,  1,  0,  1,1,  1,   0,   0,   0

[gcc r15-3046] c++: Appertain standard attributes after array closing square bracket to array type rather than decl

2024-08-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:d05949558ef1c8eeeb07399174a64f968f70e3ee

commit r15-3046-gd05949558ef1c8eeeb07399174a64f968f70e3ee
Author: Jakub Jelinek 
Date:   Tue Aug 20 22:17:41 2024 +0200

c++: Appertain standard attributes after array closing square bracket to 
array type rather than declarator [PR110345]

For C++ 26 P2552R3 I went through all the spots (except modules) where
attribute-specifier-seq appears in the grammar and tried to construct
a testcase in all those spots, for now for [[deprecated]] attribute.

This is the second issue I found.  The comment already correctly says that
attributes after closing ] appertain to the array type, but we were
appending them to returned_attrs, so effectively applying them to the
declarator (as if they appeared right after declarator-id).

2024-08-20  Jakub Jelinek  

PR c++/110345
* decl.cc (grokdeclarator): Apply declarator->std_attributes
for cdk_array to type, rather than chaining it to returned_attrs.

* g++.dg/cpp0x/gen-attrs-82.C: New test.
* g++.dg/gomp/attrs-3.C (foo): Expect different diagnostics for
omp::directive attribute after closing square bracket of an 
automatic
declaration and add a test with the attribute after array's
declarator-id.

Diff:
---
 gcc/cp/decl.cc| 5 ++---
 gcc/testsuite/g++.dg/cpp0x/gen-attrs-82.C | 4 
 gcc/testsuite/g++.dg/gomp/attrs-3.C   | 3 ++-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 12139e1d8627..7ab73f1031d7 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -13317,9 +13317,8 @@ grokdeclarator (const cp_declarator *declarator,
/* [dcl.array]/1:
 
   The optional attribute-specifier-seq appertains to the
-  array.  */
-   returned_attrs = attr_chainon (returned_attrs,
-  declarator->std_attributes);
+  array type.  */
+   decl_attributes (&type, declarator->std_attributes, 0);
  break;
 
case cdk_function:
diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-82.C 
b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-82.C
new file mode 100644
index ..67c1a2098430
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-82.C
@@ -0,0 +1,4 @@
+// { dg-do compile { target c++11 } }
+
+int a [[gnu::common]] [2];
+int b[2] [[gnu::common]];  // { dg-warning "'common' attribute does not 
apply to types" }
diff --git a/gcc/testsuite/g++.dg/gomp/attrs-3.C 
b/gcc/testsuite/g++.dg/gomp/attrs-3.C
index 7aab6370d499..5658b3a86895 100644
--- a/gcc/testsuite/g++.dg/gomp/attrs-3.C
+++ b/gcc/testsuite/g++.dg/gomp/attrs-3.C
@@ -35,6 +35,7 @@ foo ()
   int *[[omp::directive (threadprivate (t3))]] c;  // { dg-warning 
"'omp::directive' scoped attribute directive ignored" }
   int &[[omp::directive (threadprivate (t4))]] d = b;  // { dg-warning 
"'omp::directive' scoped attribute directive ignored" }
   typedef int T [[omp::directive (threadprivate (t5))]];   // { dg-error 
"'omp::directive' not allowed to be specified in this context" }
-  int e[10] [[omp::directive (threadprivate (t6))]];   // { dg-error 
"'omp::directive' not allowed to be specified in this context" }
+  int e [[omp::directive (threadprivate (t6))]] [10];  // { dg-error 
"'omp::directive' not allowed to be specified in this context" }
+  int f[10] [[omp::directive (threadprivate (t6))]];   // { dg-warning 
"'omp::directive' scoped attribute directive ignored" }
   struct [[omp::directive (threadprivate (t7))]] S {}; // { dg-error 
"'omp::directive' not allowed to be specified in this context" }
 }


[gcc r15-3045] c++: Parse and ignore attributes on base specifiers [PR110345]

2024-08-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:1db5ca04da365ac57f7d788a85055edcf13da708

commit r15-3045-g1db5ca04da365ac57f7d788a85055edcf13da708
Author: Jakub Jelinek 
Date:   Tue Aug 20 22:15:03 2024 +0200

c++: Parse and ignore attributes on base specifiers [PR110345]

For C++ 26 P2552R3 I went through all the spots (except modules) where
attribute-specifier-seq appears in the grammar and tried to construct
a testcase in all those spots, for now for [[deprecated]] attribute.

This is the third issue I found.

https://eel.is/c++draft/class.derived#general-1 has attribute-specifier-seq
at the start of base-specifier.  The following patch parses it there and
warns about those.

2024-08-20  Jakub Jelinek  

PR c++/110345
* parser.cc (cp_parser_base_specifier): Parse standard attributes
at the start and emit a warning if there are any non-ignored ones.

* g++.dg/cpp0x/gen-attrs-83.C: New test.

Diff:
---
 gcc/cp/parser.cc  | 17 -
 gcc/testsuite/g++.dg/cpp0x/gen-attrs-83.C | 10 ++
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index c43889803482..28ebf2beb60a 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -28995,11 +28995,12 @@ cp_parser_base_clause (cp_parser* parser)
 /* Parse a base-specifier.
 
base-specifier:
- :: [opt] nested-name-specifier [opt] class-name
- virtual access-specifier [opt] :: [opt] nested-name-specifier
-   [opt] class-name
- access-specifier virtual [opt] :: [opt] nested-name-specifier
-   [opt] class-name
+ attribute-specifier-seq [opt] :: [opt] nested-name-specifier [opt]
+   class-name
+ attribute-specifier-seq [opt] virtual access-specifier [opt] :: [opt]
+   nested-name-specifier [opt] class-name
+ attribute-specifier-seq [opt] access-specifier virtual [opt] :: [opt]
+   nested-name-specifier [opt] class-name
 
Returns a TREE_LIST.  The TREE_PURPOSE will be one of
ACCESS_{DEFAULT,PUBLIC,PROTECTED,PRIVATE}_[VIRTUAL]_NODE to
@@ -29017,6 +29018,12 @@ cp_parser_base_specifier (cp_parser* parser)
   bool class_scope_p, template_p;
   tree access = access_default_node;
   tree type;
+  location_t attrs_loc = cp_lexer_peek_token (parser->lexer)->location;
+  tree std_attrs = cp_parser_std_attribute_spec_seq (parser);
+
+  if (std_attrs != NULL_TREE && any_nonignored_attribute_p (std_attrs))
+warning_at (attrs_loc, OPT_Wattributes,
+   "attributes on base specifiers are ignored");
 
   /* Process the optional `virtual' and `access-specifier'.  */
   while (!done)
diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-83.C 
b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-83.C
new file mode 100644
index ..0ff1965d0ecf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-83.C
@@ -0,0 +1,10 @@
+// { dg-do compile { target c++11 } }
+
+struct A {};
+struct B {};
+struct C {};
+struct D : [[]] [[]] A,
+  [[]] virtual public B, [[]] [[]] [[]] public virtual C {};
+struct E : [[gnu::deprecated]] A,  // { dg-warning 
"attributes on base specifiers are ignored" }
+  [[gnu::deprecated]] virtual public B,// { dg-warning 
"attributes on base specifiers are ignored" }
+  [[gnu::deprecated]] public virtual C {}; // { dg-warning 
"attributes on base specifiers are ignored" }


[gcc r15-2948] c++: Pedwarn on [[]]; at class scope [PR110345]

2024-08-16 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:2f90f3850eaf9d703d9eb63d5f0347158aa11027

commit r15-2948-g2f90f3850eaf9d703d9eb63d5f0347158aa11027
Author: Jakub Jelinek 
Date:   Fri Aug 16 11:43:18 2024 +0200

c++: Pedwarn on [[]]; at class scope [PR110345]

For C++ 26 P2552R3 I went through all the spots (except modules) where
attribute-specifier-seq appears in the grammar and tried to construct
a testcase in all those spots, for now for [[deprecated]] attribute.

The fourth issue is that we just emit (when enabled) -Wextra-semi warning
not just for lone semicolon at class scope (correct), but also for
[[]]; or [[whatever]]; there too.
While just semicolon is valid in C++11 and newer,
https://eel.is/c++draft/class.mem#nt:member-declaration
allows empty-declaration, unlike namespace scope or block scope
something like attribute-declaration or empty statement with attributes
applied for it aren't supported.
While syntactically it matches
attribute-specifier-seq [opt] decl-specifier-seq [opt] 
member-declarator-list [opt] ;
with the latter two omitted, there is
https://eel.is/c++draft/class.mem#general-3
which says that is not valid.

So, the following patch emits a pedwarn in that case.

2024-08-16  Jakub Jelinek  

PR c++/110345
* parser.cc (cp_parser_member_declaration): Call 
maybe_warn_extra_semi
only if it is empty-declaration, if there are some tokens like
attribute, pedwarn that the declaration doesn't declare anything.

* g++.dg/cpp0x/gen-attrs-84.C: New test.

Diff:
---
 gcc/cp/parser.cc  | 6 +-
 gcc/testsuite/g++.dg/cpp0x/gen-attrs-84.C | 8 
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 852efe45076..c9654cfff9d 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -28259,7 +28259,11 @@ cp_parser_member_declaration (cp_parser* parser)
   if (!decl_specifiers.any_specifiers_p)
{
  cp_token *token = cp_lexer_peek_token (parser->lexer);
- maybe_warn_extra_semi (token->location, extra_semi_kind::member);
+ if (decl_spec_token_start == token)
+   maybe_warn_extra_semi (token->location, extra_semi_kind::member);
+ else
+   pedwarn (decl_spec_token_start->location, OPT_Wpedantic,
+"declaration does not declare anything");
}
   else
{
diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-84.C 
b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-84.C
new file mode 100644
index 000..c573918cd06
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-84.C
@@ -0,0 +1,8 @@
+// { dg-do compile { target c++11 } }
+
+struct A {
+  [[]];// { dg-error "declaration does not declare 
anything" }
+};
+struct B {
+  [[gnu::deprecated]]; // { dg-error "declaration does not declare anything" }
+};


[gcc r15-2939] fortran: Fix bootstrap in resolve.cc [PR116387]

2024-08-15 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:0f8b11968472ff12674d67fd856610646b373bd0

commit r15-2939-g0f8b11968472ff12674d67fd856610646b373bd0
Author: Jakub Jelinek 
Date:   Thu Aug 15 22:50:07 2024 +0200

fortran: Fix bootstrap in resolve.cc [PR116387]

The r15-2934 change broke bootstrap:
../../gcc/fortran/resolve.cc: In function ‘bool 
resolve_operator(gfc_expr*)’:
../../gcc/fortran/resolve.cc:4649:22: error: too many arguments for format 
[-Werror=format-extra-args]
 4649 |   gfc_error ("Inconsistent coranks for operator at %%L and 
%%L",
  |  
^~

The following patch fixes that by using %L rather than %%L, the call has 2
location arguments.

2024-08-15  Jakub Jelinek  

PR bootstrap/116387
* resolve.cc (resolve_operator): Use %L rather than %%L in format
string.

Diff:
---
 gcc/fortran/resolve.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 71312e0e415..12973c6bc85 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -4646,7 +4646,7 @@ resolve_operator (gfc_expr *e)
}
   else
{
- gfc_error ("Inconsistent coranks for operator at %%L and %%L",
+ gfc_error ("Inconsistent coranks for operator at %L and %L",
 &op1->where, &op2->where);
  return false;
}


[gcc r15-2866] testsuite: Fix up sse3-addsubps.c

2024-08-10 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:9d5c500c4fac9b65c95176d98203ec83b207d39d

commit r15-2866-g9d5c500c4fac9b65c95176d98203ec83b207d39d
Author: Jakub Jelinek 
Date:   Sat Aug 10 10:49:29 2024 +0200

testsuite: Fix up sse3-addsubps.c

The testcase uses sizeof (vals) / sizeof (vals) as the number of vals to
handle (though, handles 8 vals at a time).  That is an obvious typo,
all similar testcases use sizeof (vals) / sizeof (vals[0]) properly.

2024-08-10  Jakub Jelinek  

* gcc.target/powerpc/sse3-addsubps.c (TEST): Divide by
sizeof (vals[0]) rather than sizeof (vals).

Diff:
---
 gcc/testsuite/gcc.target/powerpc/sse3-addsubps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/powerpc/sse3-addsubps.c 
b/gcc/testsuite/gcc.target/powerpc/sse3-addsubps.c
index b341ba8e74b5..ab20448436a9 100644
--- a/gcc/testsuite/gcc.target/powerpc/sse3-addsubps.c
+++ b/gcc/testsuite/gcc.target/powerpc/sse3-addsubps.c
@@ -77,7 +77,7 @@ TEST (void)
   int i;
   int fail = 0;
 
-  for (i = 0; i < sizeof (vals) / sizeof (vals); i += 8)
+  for (i = 0; i < sizeof (vals) / sizeof (vals[0]); i += 8)
 {
   p1[0] = vals[i+0];
   p1[1] = vals[i+1];


[gcc r14-10575] i386: Fix up __builtin_ia32_b{extr{, i}_u{32, 64}, zhi_{s, d}i} folding [PR116287]

2024-08-09 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:b0dd13efca673355dd2a0c5646452c2f23f86029

commit r14-10575-gb0dd13efca673355dd2a0c5646452c2f23f86029
Author: Jakub Jelinek 
Date:   Fri Aug 9 14:32:51 2024 +0200

i386: Fix up __builtin_ia32_b{extr{,i}_u{32,64},zhi_{s,d}i} folding 
[PR116287]

The GENERIC folding of these builtins have cases where it folds to a
constant regardless of the value of the first operand.  If so, we need
to use omit_one_operand to avoid throwing away side-effects in the first
operand if any.  The cases which verify the first argument is INTEGER_CST
don't need that, INTEGER_CST doesn't have side-effects.

2024-08-09  Jakub Jelinek  

PR target/116287
* config/i386/i386.cc (ix86_fold_builtin) :
When folding into zero without checking whether first argument is
constant, use omit_one_operand.
(ix86_fold_builtin) : Likewise.

* gcc.target/i386/bmi-pr116287.c: New test.
* gcc.target/i386/bmi2-pr116287.c: New test.
* gcc.target/i386/tbm-pr116287.c: New test.

(cherry picked from commit 6e7088dbe3bf87108a89558ffb7df36df3469206)

Diff:
---
 gcc/config/i386/i386.cc   | 12 +++
 gcc/testsuite/gcc.target/i386/bmi-pr116287.c  | 28 ++
 gcc/testsuite/gcc.target/i386/bmi2-pr116287.c | 24 ++
 gcc/testsuite/gcc.target/i386/tbm-pr116287.c  | 29 +++
 4 files changed, 89 insertions(+), 4 deletions(-)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 35a282433892..6f89891d3cb5 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -18671,9 +18671,11 @@ ix86_fold_builtin (tree fndecl, int n_args,
  unsigned int prec = TYPE_PRECISION (TREE_TYPE (args[0]));
  unsigned int start = tree_to_uhwi (args[1]);
  unsigned int len = (start & 0xff00) >> 8;
+ tree lhs_type = TREE_TYPE (TREE_TYPE (fndecl));
  start &= 0xff;
  if (start >= prec || len == 0)
-   res = 0;
+   return omit_one_operand (lhs_type, build_zero_cst (lhs_type),
+args[0]);
  else if (!tree_fits_uhwi_p (args[0]))
break;
  else
@@ -18682,7 +18684,7 @@ ix86_fold_builtin (tree fndecl, int n_args,
len = prec;
  if (len < HOST_BITS_PER_WIDE_INT)
res &= (HOST_WIDE_INT_1U << len) - 1;
- return build_int_cstu (TREE_TYPE (TREE_TYPE (fndecl)), res);
+ return build_int_cstu (lhs_type, res);
}
  break;
 
@@ -18692,15 +18694,17 @@ ix86_fold_builtin (tree fndecl, int n_args,
  if (tree_fits_uhwi_p (args[1]))
{
  unsigned int idx = tree_to_uhwi (args[1]) & 0xff;
+ tree lhs_type = TREE_TYPE (TREE_TYPE (fndecl));
  if (idx >= TYPE_PRECISION (TREE_TYPE (args[0])))
return args[0];
  if (idx == 0)
-   return build_int_cst (TREE_TYPE (TREE_TYPE (fndecl)), 0);
+   return omit_one_operand (lhs_type, build_zero_cst (lhs_type),
+args[0]);
  if (!tree_fits_uhwi_p (args[0]))
break;
  unsigned HOST_WIDE_INT res = tree_to_uhwi (args[0]);
  res &= ~(HOST_WIDE_INT_M1U << idx);
- return build_int_cstu (TREE_TYPE (TREE_TYPE (fndecl)), res);
+ return build_int_cstu (lhs_type, res);
}
  break;
 
diff --git a/gcc/testsuite/gcc.target/i386/bmi-pr116287.c 
b/gcc/testsuite/gcc.target/i386/bmi-pr116287.c
new file mode 100644
index ..2212cb458d26
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/bmi-pr116287.c
@@ -0,0 +1,28 @@
+/* PR target/116287 */
+/* { dg-do run { target bmi } } */
+/* { dg-options "-O2 -mbmi" } */
+
+#include 
+
+#include "bmi-check.h"
+
+static void
+bmi_test ()
+{
+  unsigned int a = 0;
+  if (__builtin_ia32_bextr_u32 (a++, 0) != 0)
+abort ();
+  if (__builtin_ia32_bextr_u32 (a++, 0x120) != 0)
+abort ();
+  if (a != 2)
+abort ();
+#ifdef __x86_64__
+  unsigned long long b = 0;
+  if (__builtin_ia32_bextr_u64 (b++, 0) != 0)
+abort ();
+  if (__builtin_ia32_bextr_u64 (b++, 0x140) != 0)
+abort ();
+  if (b != 2)
+abort ();
+#endif
+}
diff --git a/gcc/testsuite/gcc.target/i386/bmi2-pr116287.c 
b/gcc/testsuite/gcc.target/i386/bmi2-pr116287.c
new file mode 100644
index ..51c939c39f62
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/bmi2-pr116287.c
@@ -0,0 +1,24 @@
+/* PR target/116287 */
+/* { dg-do run { target bmi2 } } */
+/* { dg-options "-O2 -mbmi2" } */
+
+#include 
+
+#include "bmi2-check.h"
+
+static void
+bmi2_test ()
+{
+  unsigned int a = 0;
+  if (__builtin_ia32_bzhi_si (a++, 0) != 0)
+abort ();
+  if (a != 1)
+abort ();
+#ifdef __x86_64__
+  unsigned long lo

[gcc r15-2847] i386: Fix up __builtin_ia32_b{extr{, i}_u{32, 64}, zhi_{s, d}i} folding [PR116287]

2024-08-09 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:6e7088dbe3bf87108a89558ffb7df36df3469206

commit r15-2847-g6e7088dbe3bf87108a89558ffb7df36df3469206
Author: Jakub Jelinek 
Date:   Fri Aug 9 14:32:51 2024 +0200

i386: Fix up __builtin_ia32_b{extr{,i}_u{32,64},zhi_{s,d}i} folding 
[PR116287]

The GENERIC folding of these builtins have cases where it folds to a
constant regardless of the value of the first operand.  If so, we need
to use omit_one_operand to avoid throwing away side-effects in the first
operand if any.  The cases which verify the first argument is INTEGER_CST
don't need that, INTEGER_CST doesn't have side-effects.

2024-08-09  Jakub Jelinek  

PR target/116287
* config/i386/i386.cc (ix86_fold_builtin) :
When folding into zero without checking whether first argument is
constant, use omit_one_operand.
(ix86_fold_builtin) : Likewise.

* gcc.target/i386/bmi-pr116287.c: New test.
* gcc.target/i386/bmi2-pr116287.c: New test.
* gcc.target/i386/tbm-pr116287.c: New test.

Diff:
---
 gcc/config/i386/i386.cc   | 12 +++
 gcc/testsuite/gcc.target/i386/bmi-pr116287.c  | 28 ++
 gcc/testsuite/gcc.target/i386/bmi2-pr116287.c | 24 ++
 gcc/testsuite/gcc.target/i386/tbm-pr116287.c  | 29 +++
 4 files changed, 89 insertions(+), 4 deletions(-)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 02e282904410..f044826269ca 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -18549,9 +18549,11 @@ ix86_fold_builtin (tree fndecl, int n_args,
  unsigned int prec = TYPE_PRECISION (TREE_TYPE (args[0]));
  unsigned int start = tree_to_uhwi (args[1]);
  unsigned int len = (start & 0xff00) >> 8;
+ tree lhs_type = TREE_TYPE (TREE_TYPE (fndecl));
  start &= 0xff;
  if (start >= prec || len == 0)
-   res = 0;
+   return omit_one_operand (lhs_type, build_zero_cst (lhs_type),
+args[0]);
  else if (!tree_fits_uhwi_p (args[0]))
break;
  else
@@ -18560,7 +18562,7 @@ ix86_fold_builtin (tree fndecl, int n_args,
len = prec;
  if (len < HOST_BITS_PER_WIDE_INT)
res &= (HOST_WIDE_INT_1U << len) - 1;
- return build_int_cstu (TREE_TYPE (TREE_TYPE (fndecl)), res);
+ return build_int_cstu (lhs_type, res);
}
  break;
 
@@ -18570,15 +18572,17 @@ ix86_fold_builtin (tree fndecl, int n_args,
  if (tree_fits_uhwi_p (args[1]))
{
  unsigned int idx = tree_to_uhwi (args[1]) & 0xff;
+ tree lhs_type = TREE_TYPE (TREE_TYPE (fndecl));
  if (idx >= TYPE_PRECISION (TREE_TYPE (args[0])))
return args[0];
  if (idx == 0)
-   return build_int_cst (TREE_TYPE (TREE_TYPE (fndecl)), 0);
+   return omit_one_operand (lhs_type, build_zero_cst (lhs_type),
+args[0]);
  if (!tree_fits_uhwi_p (args[0]))
break;
  unsigned HOST_WIDE_INT res = tree_to_uhwi (args[0]);
  res &= ~(HOST_WIDE_INT_M1U << idx);
- return build_int_cstu (TREE_TYPE (TREE_TYPE (fndecl)), res);
+ return build_int_cstu (lhs_type, res);
}
  break;
 
diff --git a/gcc/testsuite/gcc.target/i386/bmi-pr116287.c 
b/gcc/testsuite/gcc.target/i386/bmi-pr116287.c
new file mode 100644
index ..2212cb458d26
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/bmi-pr116287.c
@@ -0,0 +1,28 @@
+/* PR target/116287 */
+/* { dg-do run { target bmi } } */
+/* { dg-options "-O2 -mbmi" } */
+
+#include 
+
+#include "bmi-check.h"
+
+static void
+bmi_test ()
+{
+  unsigned int a = 0;
+  if (__builtin_ia32_bextr_u32 (a++, 0) != 0)
+abort ();
+  if (__builtin_ia32_bextr_u32 (a++, 0x120) != 0)
+abort ();
+  if (a != 2)
+abort ();
+#ifdef __x86_64__
+  unsigned long long b = 0;
+  if (__builtin_ia32_bextr_u64 (b++, 0) != 0)
+abort ();
+  if (__builtin_ia32_bextr_u64 (b++, 0x140) != 0)
+abort ();
+  if (b != 2)
+abort ();
+#endif
+}
diff --git a/gcc/testsuite/gcc.target/i386/bmi2-pr116287.c 
b/gcc/testsuite/gcc.target/i386/bmi2-pr116287.c
new file mode 100644
index ..51c939c39f62
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/bmi2-pr116287.c
@@ -0,0 +1,24 @@
+/* PR target/116287 */
+/* { dg-do run { target bmi2 } } */
+/* { dg-options "-O2 -mbmi2" } */
+
+#include 
+
+#include "bmi2-check.h"
+
+static void
+bmi2_test ()
+{
+  unsigned int a = 0;
+  if (__builtin_ia32_bzhi_si (a++, 0) != 0)
+abort ();
+  if (a != 1)
+abort ();
+#ifdef __x86_64__
+  unsigned long long b = 0;
+  if (__builtin_ia32_bzhi_di (b++, 0) != 0)
+abort ();
+  if (b 

[gcc r15-2843] c-family: Add some more ARRAY_SIZE uses

2024-08-09 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:723e0f724e0c884a31ddf4a688604e7163ed31f2

commit r15-2843-g723e0f724e0c884a31ddf4a688604e7163ed31f2
Author: Jakub Jelinek 
Date:   Fri Aug 9 09:34:50 2024 +0200

c-family: Add some more ARRAY_SIZE uses

These two spots were just non-standard, because they divided
sizeof (omp_pragmas_simd) by sizeof (*omp_pragmas) and not
the expected sizeof (*omp_pragmas_simd) and so weren't converted
into ARRAY_SIZE.  Both of the latter sizes are the same though,
as both arrays have the same type, so this patch doesn't change
anything but readability.

2024-08-09  Jakub Jelinek  

* c-pragma.cc (c_pp_lookup_pragma): Use ARRAY_SIZE in
n_omp_pragmas_simd initializer.
(init_pragmas): Likewise.

Diff:
---
 gcc/c-family/c-pragma.cc | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc
index 25251c2b69f9..ed2a7a00e9eb 100644
--- a/gcc/c-family/c-pragma.cc
+++ b/gcc/c-family/c-pragma.cc
@@ -1565,8 +1565,7 @@ c_pp_lookup_pragma (unsigned int id, const char **space, 
const char **name)
 {
   const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas);
   const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas);
-  const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
-/ sizeof (*omp_pragmas);
+  const int n_omp_pragmas_simd = ARRAY_SIZE (omp_pragmas_simd);
   int i;
 
   for (i = 0; i < n_oacc_pragmas; ++i)
@@ -1807,8 +1806,7 @@ init_pragma (void)
}
   if (flag_openmp || flag_openmp_simd)
{
- const int n_omp_pragmas_simd
-   = sizeof (omp_pragmas_simd) / sizeof (*omp_pragmas);
+ const int n_omp_pragmas_simd = ARRAY_SIZE (omp_pragmas_simd);
  int i;
 
  for (i = 0; i < n_omp_pragmas_simd; ++i)


[gcc r15-2815] c++, libstdc++: Implement C++26 P2747R2 - constexpr placement new [PR115744]

2024-08-08 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:afa3a4a52cf91485477e4aaa5f05987ec7ff869d

commit r15-2815-gafa3a4a52cf91485477e4aaa5f05987ec7ff869d
Author: Jakub Jelinek 
Date:   Thu Aug 8 11:05:36 2024 +0200

c++, libstdc++: Implement C++26 P2747R2 - constexpr placement new [PR115744]

With the PR115754 fix in, constexpr placement new mostly just works,
so this patch just adds constexpr keyword to the placement new operators
in , adds FTMs and testsuite coverage.

There is one accepts-invalid though, the
new (p + 1) int[]{2, 3};  // error (in this paper)
case from the paper.  Can we handle that incrementally?
The problem with that is I think calling operator new now that it is
constexpr should be fine even in that case in constant expressions, so
int *p = std::allocator{}.allocate(3);
int *q = operator new[] (sizeof (int) * 2, p + 1);
should be ok, so it can't be easily the placement new operator call
itself on whose constexpr evaluation we try something special, it should
be on the new expression, but constexpr.cc actually sees only
<<< Unknown tree: expr_stmt
  (void) (TARGET_EXPR (b) + 4>>, TARGET_EXPR )>,   int * D.2643;
  <<< Unknown tree: expr_stmt
(void) (D.2643 = (int *) D.2642) >>>;
and that is just fine by the preexisting constexpr evaluation rules.

Should build_new_1 emit some extra cast for the array cases with placement
new in maybe_constexpr_fn (current_function_decl) that the existing P2738
code would catch?

2024-08-08  Jakub Jelinek  

PR c++/115744
gcc/c-family/
* c-cppbuiltin.cc (c_cpp_builtins): Change __cpp_constexpr
from 202306L to 202406L for C++26.
gcc/testsuite/
* g++.dg/cpp2a/construct_at.h (operator new, operator new[]):
Use constexpr instead of inline if __cpp_constexpr >= 202406L.
* g++.dg/cpp26/constexpr-new1.C: New test.
* g++.dg/cpp26/constexpr-new2.C: New test.
* g++.dg/cpp26/constexpr-new3.C: New test.
* g++.dg/cpp26/feat-cxx26.C (__cpp_constexpr): Adjust expected
value.
libstdc++-v3/
* libsupc++/new (__glibcxx_want_constexpr_new): Define before
including bits/version.h.
(_GLIBCXX_PLACEMENT_CONSTEXPR): Define.
(operator new, operator new[]): Use it for placement new instead
of inline.
* include/bits/version.def (constexpr_new): New FTM.
* include/bits/version.h: Regenerate.

Diff:
---
 gcc/c-family/c-cppbuiltin.cc|  2 +-
 gcc/testsuite/g++.dg/cpp26/constexpr-new1.C | 66 ++
 gcc/testsuite/g++.dg/cpp26/constexpr-new2.C | 73 +
 gcc/testsuite/g++.dg/cpp26/constexpr-new3.C | 47 +++
 gcc/testsuite/g++.dg/cpp26/feat-cxx26.C |  4 +-
 gcc/testsuite/g++.dg/cpp2a/construct_at.h   | 15 +-
 libstdc++-v3/include/bits/version.def   |  9 
 libstdc++-v3/include/bits/version.h | 10 
 libstdc++-v3/libsupc++/new  | 15 +-
 9 files changed, 235 insertions(+), 6 deletions(-)

diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc
index a80372c89914..97c3ecb7d161 100644
--- a/gcc/c-family/c-cppbuiltin.cc
+++ b/gcc/c-family/c-cppbuiltin.cc
@@ -1091,7 +1091,7 @@ c_cpp_builtins (cpp_reader *pfile)
   if (cxx_dialect > cxx23)
{
  /* Set feature test macros for C++26.  */
- cpp_define (pfile, "__cpp_constexpr=202306L");
+ cpp_define (pfile, "__cpp_constexpr=202406L");
  cpp_define (pfile, "__cpp_static_assert=202306L");
  cpp_define (pfile, "__cpp_placeholder_variables=202306L");
  cpp_define (pfile, "__cpp_structured_bindings=202403L");
diff --git a/gcc/testsuite/g++.dg/cpp26/constexpr-new1.C 
b/gcc/testsuite/g++.dg/cpp26/constexpr-new1.C
new file mode 100644
index ..131b718efa5b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp26/constexpr-new1.C
@@ -0,0 +1,66 @@
+// C++26 P2747R2 - constexpr placement new
+// { dg-do compile { target c++26 } }
+
+#include "../cpp2a/construct_at.h"
+
+struct S {
+  constexpr S () : a (42), b (43) {}
+  constexpr S (int c, int d) : a (c), b (d) {}
+  int a, b;
+};
+struct T {
+  int a, b;
+};
+
+constexpr bool
+foo ()
+{
+  std::allocator a;
+  auto b = a.allocate (3);
+  ::new (b) int ();
+  ::new (b + 1) int (1);
+  ::new (b + 2) int {2};
+  if (b[0] != 0 || b[1] != 1 || b[2] != 2)
+return false;
+  a.deallocate (b, 3);
+  std::allocator c;
+  auto d = c.allocate (4);
+  ::new (d) S;
+  ::new (d + 1) S ();
+  ::new (d + 2) S (7, 8);
+  ::new (d + 3) S { 9, 10 };
+  if (d[0].a != 42 || d[0].b != 43
+  || d[1].a != 42 || d[1].b != 43
+  || d[2].a != 7 || d[2].b != 8
+  || d[3].a != 9 || d[3].b != 10)
+return false;
+  d[0].~S ();
+  d[1].~S ();
+  d[2].~S ();
+  d[3].~S ();
+  c.deallocate (d, 4);
+  std::allocator e;
+  auto f 

[gcc r15-2800] Don't call clean_symbol_name in create_tmp_var_name [PR116219]

2024-08-07 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:165e3e7c3ba884345647c0f1c9a3a57a03383651

commit r15-2800-g165e3e7c3ba884345647c0f1c9a3a57a03383651
Author: Jakub Jelinek 
Date:   Wed Aug 7 20:14:31 2024 +0200

Don't call clean_symbol_name in create_tmp_var_name [PR116219]

SRA adds fancy names like offset$D94316$_M_impl$D93629$_M_start
where the numbers in there are DECL_UIDs if there are unnamed
FIELD_DECLs etc.
Because -g0 vs. -g can cause differences between the exact DECL_UID
values (add bigger gaps in between them, corresponding decls should
still be ordered the same based on DECL_UID) we make sure such
decls have DECL_NAMELESS set and depending on exact options either don't
dump such names at all or dump_fancy_name sanitizes the D123456$ parts in
there to D$.
Unfortunately in tons of places we then use get_name to grab either user
names or these SRA created names and use that as argument to
create_tmp_var{,_name,_raw} to base other artificial temporary names based
on that.  Those are DECL_NAMELESS too, but unfortunately create_tmp_var_name
starting with

https://gcc.gnu.org/git/?p=gcc.git&a=commit;h=725494f6e4121eace43b7db1202f8ecbf52a8276
calls clean_symbol_name which replaces the $s in there with _s and thus
dump_fancy_name doesn't sanitize it anymore.

I don't see any discussion of that commit (originally to TM branch, later
merged) on the mailing list, but from
   DECL_NAME (new_decl)
 = create_tmp_var_name (IDENTIFIER_POINTER (DECL_NAME (old_decl)));
-  SET_DECL_ASSEMBLER_NAME (new_decl, NULL_TREE);
+  SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
snippet elsewhere in that commit it seems create_tmp_var_name was used at
that point also to determine function names of clones, so presumably the
clean_symbol_name at that point was to ensure the symbol could be emitted
into assembly, maybe in case DECL_NAME is something like C++ operators or
whatever could have there undesirable characters.

Anyway, we don't do that for years anymore, already GCC 4.5 uses for such
purposes clone_function_name which starts of DECL_ASSEMBLER_NAME of the old
function and appends based on supportable symbol suffix separators the
separator and some suffix and/or number, so that part doesn't go through
create_tmp_var_name.

I don't see problems with having the $ and . etc. characters in the names
intended just to make dumps more readable, after all, we already are using
those in the SRA created names.  Those names shouldn't make it into the
assembly in any way, neither debug info nor assembly labels.

There is one theoretical case, where the gimplifier promotes automatic
vars into TREE_STATIC ones and therefore those can then appear in assembly,
just in case it would be on e.g. SRA created names and regimplified later.
Because no cases of promotion of DECL_NAMELESS vars to static was observed 
in
{x86_64,i686,powerpc64le}-linux bootstraps/regtests, the code simply uses
C.NNN names for DECL_NAMELESS vars like it does for !DECL_NAME vars.

Richi mentioned on IRC that the non-cleaned up names might make things
harder to feed stuff back to the GIMPLE FE, but if so, I think it should be
the dumping for GIMPLE FE purposes that cleans those up (but at that point
it should also verify if some such cleaned up names don't collide with
others and somehow deal with those).

2024-08-07  Jakub Jelinek  

PR c++/116219
* gimple-expr.cc (remove_suffix): Formatting fixes.
(create_tmp_var_name): Don't call clean_symbol_name.
* gimplify.cc (gimplify_init_constructor): When promoting automatic
DECL_NAMELESS vars to static, don't preserve their DECL_NAME.

Diff:
---
 gcc/gimple-expr.cc | 16 ++--
 gcc/gimplify.cc|  2 +-
 2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/gcc/gimple-expr.cc b/gcc/gimple-expr.cc
index f8d7185530c6..0477c9d5f448 100644
--- a/gcc/gimple-expr.cc
+++ b/gcc/gimple-expr.cc
@@ -406,14 +406,12 @@ remove_suffix (char *name, int len)
 {
   int i;
 
-  for (i = 2;  i < 7 && len > i;  i++)
-{
-  if (name[len - i] == '.')
-   {
- name[len - i] = '\0';
- break;
-   }
-}
+  for (i = 2; i < 7 && len > i; i++)
+if (name[len - i] == '.')
+  {
+   name[len - i] = '\0';
+   break;
+  }
 }
 
 /* Create a new temporary name with PREFIX.  Return an identifier.  */
@@ -430,8 +428,6 @@ create_tmp_var_name (const char *prefix)
   char *preftmp = ASTRDUP (prefix);
 
   remove_suffix (preftmp, strlen (preftmp));
-  clean_symbol_name (preftmp);
-
   prefix = preftmp;
 }
 
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 30bfecf67e5e..71cc6c38d807 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -5599,7 +5599,7 @@ gimplify_init_constructor (tree *exp

[gcc r15-2798] c++: Implement CWG2387 - Linkage of const-qualified variable template [PR109126]

2024-08-07 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:82cd63a63eaa61a4ed5c4029a1869be7446ecb3c

commit r15-2798-g82cd63a63eaa61a4ed5c4029a1869be7446ecb3c
Author: Jakub Jelinek 
Date:   Wed Aug 7 19:08:07 2024 +0200

c++: Implement CWG2387 - Linkage of const-qualified variable template 
[PR109126]

The following patch attempts to implement DR2387 by making variable
templates including their specialization TREE_PUBLIC when at file
scope and they don't have static storage class.

2024-08-07  Jakub Jelinek  

PR c++/109126
* decl.cc (grokvardecl): Implement CWG 2387 - Linkage of
const-qualified variable template.  Set TREE_PUBLIC on variable
templates with const qualified types unless static is present.

* g++.dg/DRs/dr2387.C: New test.
* g++.dg/DRs/dr2387-aux.cc: New file.

Diff:
---
 gcc/cp/decl.cc |  2 ++
 gcc/testsuite/g++.dg/DRs/dr2387-aux.cc | 25 +
 gcc/testsuite/g++.dg/DRs/dr2387.C  | 22 ++
 3 files changed, 49 insertions(+)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 86d2bfab22dc..a468bfdb7b67 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -11225,6 +11225,8 @@ grokvardecl (tree type,
|| ! constp
|| volatilep
|| inlinep
+   || in_template_context
+   || processing_specialization
|| module_attach_p ()));
   TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
 }
diff --git a/gcc/testsuite/g++.dg/DRs/dr2387-aux.cc 
b/gcc/testsuite/g++.dg/DRs/dr2387-aux.cc
new file mode 100644
index ..7a78ac230157
--- /dev/null
+++ b/gcc/testsuite/g++.dg/DRs/dr2387-aux.cc
@@ -0,0 +1,25 @@
+// DR 2387
+
+template 
+extern const int a;
+template 
+static const int b = N;
+template 
+extern const int c;
+template 
+extern const volatile int d;
+template 
+extern const int e;
+extern const int *pa, *pb, *pc, *pe;
+extern const volatile int *pd;
+
+int
+main ()
+{
+  if (pa != &a <42>
+  || pb == &b <42>
+  || pc != &c <42>
+  || pd != &d <42>
+  || pe != &e <43>)
+__builtin_abort ();
+}
diff --git a/gcc/testsuite/g++.dg/DRs/dr2387.C 
b/gcc/testsuite/g++.dg/DRs/dr2387.C
new file mode 100644
index ..afbe618d5179
--- /dev/null
+++ b/gcc/testsuite/g++.dg/DRs/dr2387.C
@@ -0,0 +1,22 @@
+// DR 2387
+// { dg-do run { target c++14 } }
+// { dg-additional-sources "dr2387-aux.cc" }
+
+template 
+const int a = N;
+template 
+static const int b = N;
+template 
+extern const int c = N;
+template 
+const volatile int d = N;
+template 
+const int e = N;
+template <>
+const int e <43> = 44;
+
+const int *pa = &a <42>;
+const int *pb = &b <42>;
+const int *pc = &c <42>;
+const volatile int *pd = &d <42>;
+const int *pe = &e <43>;


[gcc r15-2790] c++: Fix up handling of dependent (late) attributes on function/method types [PR116175]

2024-08-07 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:9426ce98ccb35a43b4f3e8ea14dcbf2f5de5dc48

commit r15-2790-g9426ce98ccb35a43b4f3e8ea14dcbf2f5de5dc48
Author: Jakub Jelinek 
Date:   Wed Aug 7 09:48:07 2024 +0200

c++: Fix up handling of dependent (late) attributes on function/method 
types [PR116175]

When working on unsequenced/reproducible attributes, I've noticed that on
templates for some attributes decl_attributes isn't called at all, so they
are kept in TYPE_ATTRIBUTES without any verification/transformations and
also without argument substitution.

The following patch fixes that for FUNCTION/METHOD_TYPE attributes.
The included testcase ICEs without the pt.cc changes.

2024-08-07  Jakub Jelinek  

PR c++/116175
* pt.cc (apply_late_template_attributes): For function/method types
call cp_build_type_attribute_variant on the non-dependent 
attributes.
(rebuild_function_or_method_type): Add ARGS argument.  Use
apply_late_template_attributes rather than
cp_build_type_attribute_variant.
(maybe_rebuild_function_decl_type): Add ARGS argument, pass it to
rebuild_function_or_method_type.
(tsubst_function_decl): Adjust caller.
(tsubst_function_type): Adjust rebuild_function_or_method_type 
caller.

* g++.dg/ext/attr-format4.C: New test.

Diff:
---
 gcc/cp/pt.cc| 24 
 gcc/testsuite/g++.dg/ext/attr-format4.C | 12 
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 2db59213c549..542962b6387f 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -12201,6 +12201,8 @@ apply_late_template_attributes (tree *decl_p, tree 
attributes, int attr_flags,
  to our attributes parameter.  */
   gcc_assert (*p == attributes);
 }
+  else if (FUNC_OR_METHOD_TYPE_P (*decl_p))
+p = NULL;
   else
 {
   p = &TYPE_ATTRIBUTES (*decl_p);
@@ -12219,7 +12221,10 @@ apply_late_template_attributes (tree *decl_p, tree 
attributes, int attr_flags,
   tree nondep = t;
 
   /* Apply any non-dependent attributes.  */
-  *p = nondep;
+  if (p)
+*p = nondep;
+  else if (nondep)
+*decl_p = cp_build_type_attribute_variant (*decl_p, nondep);
 
   if (nondep == attributes)
 return true;
@@ -14377,8 +14382,9 @@ lookup_explicit_specifier (tree v)
identical to T.  */
 
 static tree
-rebuild_function_or_method_type (tree t, tree return_type, tree arg_types,
-tree raises, tsubst_flags_t complain)
+rebuild_function_or_method_type (tree t, tree args, tree return_type,
+tree arg_types, tree raises,
+tsubst_flags_t complain)
 {
   gcc_assert (FUNC_OR_METHOD_TYPE_P (t));
 
@@ -14411,7 +14417,9 @@ rebuild_function_or_method_type (tree t, tree 
return_type, tree arg_types,
   new_type = build_method_type_directly (r, return_type,
 TREE_CHAIN (arg_types));
 }
-  new_type = cp_build_type_attribute_variant (new_type, TYPE_ATTRIBUTES (t));
+  if (!apply_late_template_attributes (&new_type, TYPE_ATTRIBUTES (t), 0,
+  args, complain, NULL_TREE))
+return error_mark_node;
 
   cp_ref_qualifier rqual = type_memfn_rqual (t);
   bool late_return_type_p = TYPE_HAS_LATE_RETURN_TYPE (t);
@@ -14424,7 +14432,7 @@ rebuild_function_or_method_type (tree t, tree 
return_type, tree arg_types,
resolution for Core issues 1001/1322.  */
 
 static void
-maybe_rebuild_function_decl_type (tree decl)
+maybe_rebuild_function_decl_type (tree decl, tree args)
 {
   bool function_type_needs_rebuilding = false;
   if (tree parm_list = FUNCTION_FIRST_USER_PARM (decl))
@@ -14476,7 +14484,7 @@ maybe_rebuild_function_decl_type (tree decl)
 *q = void_list_node;
 
   TREE_TYPE (decl)
-= rebuild_function_or_method_type (fntype,
+= rebuild_function_or_method_type (fntype, args,
   TREE_TYPE (fntype), new_parm_type_list,
   TYPE_RAISES_EXCEPTIONS (fntype), 
tf_none);
 }
@@ -14659,7 +14667,7 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t 
complain,
   DECL_ARGUMENTS (r) = parms;
   DECL_RESULT (r) = NULL_TREE;
 
-  maybe_rebuild_function_decl_type (r);
+  maybe_rebuild_function_decl_type (r, args);
 
   TREE_STATIC (r) = 0;
   TREE_PUBLIC (r) = TREE_PUBLIC (t);
@@ -15927,7 +15935,7 @@ tsubst_function_type (tree t,
 }
 
   /* Construct a new type node and return it.  */
-  return rebuild_function_or_method_type (t, return_type, arg_types,
+  return rebuild_function_or_method_type (t, args, return_type, arg_types,
  /*raises=*/NULL_TREE, complain);
 }
 
diff --git a/gcc/testsuite/g++.dg/ext/attr-format4.C 
b/gcc/testsuite/g++.dg/ext/attr-format4.C
new file mode 100644
index 00

[gcc r15-2753] testsuite: Fix up pr116037.c test [PR116245]

2024-08-06 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:df4062c54b0b3c5f5c6a1f1a2454abf965100e3a

commit r15-2753-gdf4062c54b0b3c5f5c6a1f1a2454abf965100e3a
Author: Jakub Jelinek 
Date:   Tue Aug 6 11:52:35 2024 +0200

testsuite: Fix up pr116037.c test [PR116245]

The test FAILs on big endian targets, because VV is a vector of unsigned 
__int128
and VC vector of unsigned char and so ((VC) vv)[0] is 0x01 on little endian
but 0xff on big endian and PDP endian.
As I believe it is intentional to test it as it is written on little endian,
the following patch just adds another case for big endian and for other
endians instead of figuring out what exactly to fetch it fetches the whole
unsigned __int128 and casts it to unsigned char.  Not that pdp11 has
__int128 support...

2024-08-06  Jakub Jelinek  

PR rtl-optimization/116037
PR testsuite/116245
* gcc.dg/torture/pr116037.c (foo): Fix up for big end middle endian.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr116037.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/torture/pr116037.c 
b/gcc/testsuite/gcc.dg/torture/pr116037.c
index 86ab50de4b2f..5bab24107fc2 100644
--- a/gcc/testsuite/gcc.dg/torture/pr116037.c
+++ b/gcc/testsuite/gcc.dg/torture/pr116037.c
@@ -16,7 +16,13 @@ VL vl;
 VV
 foo (unsigned long long x, VV vv)
 {
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
   x &= -((VC) vv)[0];
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+  x &= -((VC) vv)[sizeof (__int128) - 1];
+#else
+  x &= -(unsigned char) (vv[0]);
+#endif
   vi *= (VI) (VS){ -vs[0], vc[0], vs[1], vi[7], vs[7], vl[7], x, vi[5] };
   return x + vv;
 }


[gcc r14-10567] wide-int: Fix up mul_internal overflow checking [PR116224]

2024-08-06 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:f2b5ca6be855cede3f0d35d2a1aff08d3c342ac2

commit r14-10567-gf2b5ca6be855cede3f0d35d2a1aff08d3c342ac2
Author: Jakub Jelinek 
Date:   Tue Aug 6 11:09:33 2024 +0200

wide-int: Fix up mul_internal overflow checking [PR116224]

The following testcase is miscompiled, because wi::mul for (_BitInt(65))-15
times (_BitInt(65))-15 computes the right value (_BitInt(65))225, but
sets *overflow to wi::OVF_UNKNOWN as that it overflowed when it didn't.

Even signed operands are unpacked as unsigned but because they are
implicitly sign-extended from the represented value (the operands
obviously have len==1), we get
0xfff1, 0x, 0x1, 0x0
in both u and v (0x1 because that is exactly 65 bits).
We then multiply these.  Next step is because both the high and
overflow handling expects the high half to start at a limb boundary
the bits of the result starting with bit 65 are shifted up by 63 such
that the bits relevant for high/need_overflow start at the half of the
4th half wide int limb.
Because both operands are negative that part is then adjusted.

The reason mul_internal says there is overflow is because of the unspecified
garbage in the most significant bits of the result which the adjusting
doesn't clean up.  65 bit multiplication needs 65 bits of result and 65 bits
of the high part, can't produce more, so the following patch fixes it by
checking for the overflow only in those first 65 bits of the high part, not
anything beyond that.  If it was a highpart multiply, we'd have ignored that
as well (canonicalized).

2024-08-06  Jakub Jelinek  

PR tree-optimization/116224
* wide-int.cc (wi::mul_internal): If prec isn't multiple of
HOST_BITS_PER_WIDE_INT, for need_overflow checking only look at
the least significant prec bits starting with r[half_blocks_needed].

* gcc.dg/torture/bitint-72.c: New test.

(cherry picked from commit 69093fd8aa682a1b906e80b3c5f10956e692b7c4)

Diff:
---
 gcc/testsuite/gcc.dg/torture/bitint-72.c | 28 
 gcc/wide-int.cc  | 19 ++-
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/torture/bitint-72.c 
b/gcc/testsuite/gcc.dg/torture/bitint-72.c
new file mode 100644
index ..101018b00eeb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-72.c
@@ -0,0 +1,28 @@
+/* PR tree-optimization/116224 */
+/* { dg-do run { target bitint } } */
+/* { dg-options "-std=c23" } */
+/* { dg-skip-if "" { ! run_expensive_tests }  { "*" } { "-O0" "-O2" } } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
+
+#if __BITINT_MAXWIDTH__ >= 65
+#define N 65
+#else
+#define N 63
+#endif
+
+signed char g;
+
+int
+foo (signed char c, int i, _BitInt(N) b)
+{
+  __builtin_memmove (&g, &b, 1);
+  return b / i / c;
+}
+
+int
+main ()
+{
+  int x = foo (-15, -15, 900);
+  if (x != 4)
+__builtin_abort ();
+}
diff --git a/gcc/wide-int.cc b/gcc/wide-int.cc
index 9c6eba807aad..5bd16a595643 100644
--- a/gcc/wide-int.cc
+++ b/gcc/wide-int.cc
@@ -1574,7 +1574,24 @@ wi::mul_internal (HOST_WIDE_INT *val, const 
HOST_WIDE_INT *op1val,
  top &= mask;
}
 
-  for (i = half_blocks_needed; i < half_blocks_needed * 2; i++)
+  unsigned int end = half_blocks_needed * 2;
+  shift = prec % HOST_BITS_PER_WIDE_INT;
+  if (shift)
+   {
+ /* For overflow checking only look at the first prec bits
+starting with r[half_blocks_needed].  */
+ if (shift <= HOST_BITS_PER_HALF_WIDE_INT)
+   --end;
+ shift %= HOST_BITS_PER_HALF_WIDE_INT;
+ if (shift)
+   {
+ if (top)
+   r[end - 1] |= ((~(unsigned HOST_HALF_WIDE_INT) 0) << shift);
+ else
+   r[end - 1] &= (((unsigned HOST_HALF_WIDE_INT) 1) << shift) - 1;
+   }
+   }
+  for (i = half_blocks_needed; i < end; i++)
if (((HOST_WIDE_INT)(r[i] & mask)) != top)
  /* FIXME: Signed overflow type is not implemented yet.  */
  *overflow = (sgn == UNSIGNED) ? wi::OVF_OVERFLOW : wi::OVF_UNKNOWN;


[gcc r14-10566] libquadmath: Fix up libquadmath/math/sqrtq.c compilation in some powerpc* configurations [PR116007]

2024-08-06 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:3fe5720430a9ba61ed7562aac4d758cc77d49a28

commit r14-10566-g3fe5720430a9ba61ed7562aac4d758cc77d49a28
Author: Jakub Jelinek 
Date:   Sat Aug 3 20:37:54 2024 +0200

libquadmath: Fix up libquadmath/math/sqrtq.c compilation in some powerpc* 
configurations [PR116007]

My PR114623 change started using soft-fp.h and quad.h for the sqrtq 
implementation.
Unfortunately, that seems to fail building in some powerpc* configurations, 
where
TFmode isn't available.
quad.h has:
 #ifndef TFtype
 typedef float TFtype __attribute__ ((mode (TF)));
 #endif
and uses TFtype.  quad.h has:
 /* Define the complex type corresponding to __float128
("_Complex __float128" is not allowed) */
 #if (!defined(_ARCH_PPC)) || defined(__LONG_DOUBLE_IEEE128__)
 typedef _Complex float __attribute__((mode(TC))) __complex128;
 #else
 typedef _Complex float __attribute__((mode(KC))) __complex128;
 #endif
with the conditional and KCmode use added during porting of libquadmath
to powerpc*, so I've just defined TFtype for powerpc when 
__LONG_DOUBLE_IEEE128__
isn't defined; I could define it to float __attribute__ ((mode (KF))) but it
seemed easier to just define it to __float128 which should do the same 
thing.

2024-08-03  Jakub Jelinek  

PR target/116007
* math/sqrtq.c (TFtype): For PowerPC without __LONG_DOUBLE_IEEE128__
define to __float128 before including soft-fp.h and quad.h.

(cherry picked from commit 3ac02e67503ccffa3dfeeffc0a60fce6bdaca43b)

Diff:
---
 libquadmath/math/sqrtq.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libquadmath/math/sqrtq.c b/libquadmath/math/sqrtq.c
index 8ca2828d42ce..a58998a06670 100644
--- a/libquadmath/math/sqrtq.c
+++ b/libquadmath/math/sqrtq.c
@@ -9,6 +9,9 @@
 && defined(FE_TOWARDZERO) \
 && defined(FE_INEXACT)
 #define USE_SOFT_FP 1
+#if defined(_ARCH_PPC) && !defined(__LONG_DOUBLE_IEEE128__)
+#define TFtype __float128
+#endif
 #include "../../libgcc/soft-fp/soft-fp.h"
 #include "../../libgcc/soft-fp/quad.h"
 #endif


[gcc r14-10565] fortran: Fix up pasto in gfc_get_array_descr_info

2024-08-06 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:cad2693096cd2395409aada5c26b56e3aeb6e849

commit r14-10565-gcad2693096cd2395409aada5c26b56e3aeb6e849
Author: Jakub Jelinek 
Date:   Thu Aug 1 20:23:15 2024 +0200

fortran: Fix up pasto in gfc_get_array_descr_info

A static analyzer found a pasto in gfc_get_array_descr_info.
The code does
  t = base_decl;
  if (!integer_zerop (dtype_off))
t = fold_build_pointer_plus (t, dtype_off);
  dtype = TYPE_MAIN_VARIANT (get_dtype_type_node ());
  field = gfc_advance_chain (TYPE_FIELDS (dtype), GFC_DTYPE_RANK);
  rank_off = byte_position (field);
  if (!integer_zerop (dtype_off))
t = fold_build_pointer_plus (t, rank_off);
i.e. uses the same !integer_zerop check between both, while it should
be checking rank_off in the latter case.
This actually doesn't change anything on the generated code, because
both the dtype_off and rank_off aren't zero,
typedef struct dtype_type
{
  size_t elem_len;
  int version;
  signed char rank;
  signed char type;
  signed short attribute;
}
dtype_type;
struct {
  type *base_addr;
  size_t offset;
  dtype_type dtype;
  index_type span;
  descriptor_dimension dim[];
};
dtype_off is 16 on 64-bit arches and 8 on 32-bit ones and rank_off is
12 on 64-bit arches and 8 on 32-bit arches, so this patch is just to
pacify those static analyzers or be prepared if the ABI changes in the
future.  Because in the current ABI both of those are actually non-zero,
doing
if (!integer_zerop (something)) t = fold_build_pointer_plus (t, something);
actually isn't an optimization, it will consume more compile time.  If
the ABI changes and we forget to readd it, nothing bad happens,
fold_build_pointer_plus handles 0 addends fine, just takes some compile
time to handle that.
I've kept this if (!integer_zerop (data_off)) guard earlier because
data_off is 0 in the current ABI, so it is an optimization there.

2024-08-01  Jakub Jelinek  

* trans-types.cc (gfc_get_array_descr_info): Don't test if
!integer_zerop (dtype_off), use fold_build_pointer_plus
unconditionally.

(cherry picked from commit 90fe402a89910d4fbe0efc15cf05cf6c0306586a)

Diff:
---
 gcc/fortran/trans-types.cc | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index 8466c595e065..61523c7d162b 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -3527,14 +3527,11 @@ gfc_get_array_descr_info (const_tree type, struct 
array_descr_info *info)
 {
   rank = 1;
   info->ndimensions = 1;
-  t = base_decl;
-  if (!integer_zerop (dtype_off))
-   t = fold_build_pointer_plus (t, dtype_off);
+  t = fold_build_pointer_plus (base_decl, dtype_off);
   dtype = TYPE_MAIN_VARIANT (get_dtype_type_node ());
   field = gfc_advance_chain (TYPE_FIELDS (dtype), GFC_DTYPE_RANK);
   rank_off = byte_position (field);
-  if (!integer_zerop (dtype_off))
-   t = fold_build_pointer_plus (t, rank_off);
+  t = fold_build_pointer_plus (t, rank_off);
 
   t = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (field)), t);
   t = build1 (INDIRECT_REF, TREE_TYPE (field), t);


[gcc r15-2752] wide-int: Fix up mul_internal overflow checking [PR116224]

2024-08-06 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:69093fd8aa682a1b906e80b3c5f10956e692b7c4

commit r15-2752-g69093fd8aa682a1b906e80b3c5f10956e692b7c4
Author: Jakub Jelinek 
Date:   Tue Aug 6 11:09:33 2024 +0200

wide-int: Fix up mul_internal overflow checking [PR116224]

The following testcase is miscompiled, because wi::mul for (_BitInt(65))-15
times (_BitInt(65))-15 computes the right value (_BitInt(65))225, but
sets *overflow to wi::OVF_UNKNOWN as that it overflowed when it didn't.

Even signed operands are unpacked as unsigned but because they are
implicitly sign-extended from the represented value (the operands
obviously have len==1), we get
0xfff1, 0x, 0x1, 0x0
in both u and v (0x1 because that is exactly 65 bits).
We then multiply these.  Next step is because both the high and
overflow handling expects the high half to start at a limb boundary
the bits of the result starting with bit 65 are shifted up by 63 such
that the bits relevant for high/need_overflow start at the half of the
4th half wide int limb.
Because both operands are negative that part is then adjusted.

The reason mul_internal says there is overflow is because of the unspecified
garbage in the most significant bits of the result which the adjusting
doesn't clean up.  65 bit multiplication needs 65 bits of result and 65 bits
of the high part, can't produce more, so the following patch fixes it by
checking for the overflow only in those first 65 bits of the high part, not
anything beyond that.  If it was a highpart multiply, we'd have ignored that
as well (canonicalized).

2024-08-06  Jakub Jelinek  

PR tree-optimization/116224
* wide-int.cc (wi::mul_internal): If prec isn't multiple of
HOST_BITS_PER_WIDE_INT, for need_overflow checking only look at
the least significant prec bits starting with r[half_blocks_needed].

* gcc.dg/torture/bitint-72.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/torture/bitint-72.c | 28 
 gcc/wide-int.cc  | 19 ++-
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/torture/bitint-72.c 
b/gcc/testsuite/gcc.dg/torture/bitint-72.c
new file mode 100644
index ..101018b00eeb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-72.c
@@ -0,0 +1,28 @@
+/* PR tree-optimization/116224 */
+/* { dg-do run { target bitint } } */
+/* { dg-options "-std=c23" } */
+/* { dg-skip-if "" { ! run_expensive_tests }  { "*" } { "-O0" "-O2" } } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
+
+#if __BITINT_MAXWIDTH__ >= 65
+#define N 65
+#else
+#define N 63
+#endif
+
+signed char g;
+
+int
+foo (signed char c, int i, _BitInt(N) b)
+{
+  __builtin_memmove (&g, &b, 1);
+  return b / i / c;
+}
+
+int
+main ()
+{
+  int x = foo (-15, -15, 900);
+  if (x != 4)
+__builtin_abort ();
+}
diff --git a/gcc/wide-int.cc b/gcc/wide-int.cc
index 9c6eba807aad..5bd16a595643 100644
--- a/gcc/wide-int.cc
+++ b/gcc/wide-int.cc
@@ -1574,7 +1574,24 @@ wi::mul_internal (HOST_WIDE_INT *val, const 
HOST_WIDE_INT *op1val,
  top &= mask;
}
 
-  for (i = half_blocks_needed; i < half_blocks_needed * 2; i++)
+  unsigned int end = half_blocks_needed * 2;
+  shift = prec % HOST_BITS_PER_WIDE_INT;
+  if (shift)
+   {
+ /* For overflow checking only look at the first prec bits
+starting with r[half_blocks_needed].  */
+ if (shift <= HOST_BITS_PER_HALF_WIDE_INT)
+   --end;
+ shift %= HOST_BITS_PER_HALF_WIDE_INT;
+ if (shift)
+   {
+ if (top)
+   r[end - 1] |= ((~(unsigned HOST_HALF_WIDE_INT) 0) << shift);
+ else
+   r[end - 1] &= (((unsigned HOST_HALF_WIDE_INT) 1) << shift) - 1;
+   }
+   }
+  for (i = half_blocks_needed; i < end; i++)
if (((HOST_WIDE_INT)(r[i] & mask)) != top)
  /* FIXME: Signed overflow type is not implemented yet.  */
  *overflow = (sgn == UNSIGNED) ? wi::OVF_OVERFLOW : wi::OVF_UNKNOWN;


[gcc r15-2708] libquadmath: Fix up libquadmath/math/sqrtq.c compilation in some powerpc* configurations [PR116007]

2024-08-03 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:3ac02e67503ccffa3dfeeffc0a60fce6bdaca43b

commit r15-2708-g3ac02e67503ccffa3dfeeffc0a60fce6bdaca43b
Author: Jakub Jelinek 
Date:   Sat Aug 3 20:37:54 2024 +0200

libquadmath: Fix up libquadmath/math/sqrtq.c compilation in some powerpc* 
configurations [PR116007]

My PR114623 change started using soft-fp.h and quad.h for the sqrtq 
implementation.
Unfortunately, that seems to fail building in some powerpc* configurations, 
where
TFmode isn't available.
quad.h has:
 #ifndef TFtype
 typedef float TFtype __attribute__ ((mode (TF)));
 #endif
and uses TFtype.  quad.h has:
 /* Define the complex type corresponding to __float128
("_Complex __float128" is not allowed) */
 #if (!defined(_ARCH_PPC)) || defined(__LONG_DOUBLE_IEEE128__)
 typedef _Complex float __attribute__((mode(TC))) __complex128;
 #else
 typedef _Complex float __attribute__((mode(KC))) __complex128;
 #endif
with the conditional and KCmode use added during porting of libquadmath
to powerpc*, so I've just defined TFtype for powerpc when 
__LONG_DOUBLE_IEEE128__
isn't defined; I could define it to float __attribute__ ((mode (KF))) but it
seemed easier to just define it to __float128 which should do the same 
thing.

2024-08-03  Jakub Jelinek  

PR target/116007
* math/sqrtq.c (TFtype): For PowerPC without __LONG_DOUBLE_IEEE128__
define to __float128 before including soft-fp.h and quad.h.

Diff:
---
 libquadmath/math/sqrtq.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libquadmath/math/sqrtq.c b/libquadmath/math/sqrtq.c
index 8ca2828d42ce..a58998a06670 100644
--- a/libquadmath/math/sqrtq.c
+++ b/libquadmath/math/sqrtq.c
@@ -9,6 +9,9 @@
 && defined(FE_TOWARDZERO) \
 && defined(FE_INEXACT)
 #define USE_SOFT_FP 1
+#if defined(_ARCH_PPC) && !defined(__LONG_DOUBLE_IEEE128__)
+#define TFtype __float128
+#endif
 #include "../../libgcc/soft-fp/soft-fp.h"
 #include "../../libgcc/soft-fp/quad.h"
 #endif


[gcc/redhat/heads/gcc-14-branch] (176 commits) Merge commit 'r14-10541-gc6372417e50bf4d094dac720b5f091c0d4

2024-08-01 Thread Jakub Jelinek via Gcc-cvs
The branch 'redhat/heads/gcc-14-branch' was updated to point to:

 43d4666d3d94... Merge commit 'r14-10541-gc6372417e50bf4d094dac720b5f091c0d4

It previously pointed to:

 6eada54ba865... Merge commit 'r14-10366-g37bbd2c1667c70387f5fa6b52f461d57a2

Diff:

Summary of changes (added commits):
---

  43d4666... Merge commit 'r14-10541-gc6372417e50bf4d094dac720b5f091c0d4
  c637241... libstdc++: Add [[nodiscard]] to some std::locale functions (*)
  c79e73e... libstdc++: Add missing constexpr to __atomic_impl::__clear_ (*)
  8d52ae3... libstdc++: Initialize base in test allocator's constructor (*)
  d8e5645... libstdc++: Fix std::tr2::dynamic_bitset shift operations [P (*)
  a78480c... libstdc++: Remove std::basic_format_args default constructo (*)
  85d07df... libstdc++: Make std::basic_format_context non-copyable [PR1 (*)
  7d269e3... libstdc++: Make std::any_cast ill-formed (LWG 3305) (*)
  095be59... libstdc++: Define __cpp_lib_ranges in  (*)
  11b5ad5... libstdc++: Use direct-initialization for std::vector' (*)
  5fcdb36... libstdc++: Use __glibcxx_ranges_as_const to guard P2278R4 c (*)
  a1e1665... libstdc++: Use reserved form of [[__likely__]] in  (*)
  9ba75a6... libstdc++: Fix  and  for -std=gnu++14 -fc (*)
  ce84aba... libstdc++: Fix std::vector for -std=gnu++14 -fconcept (*)
  973097d... i386: Fix up *_vinsert= 4 constant ele (*)
  187eec8... Fix Xcode 16 build break with NULL != nullptr (*)
  0abce41... RISC-V: Split vwadd.wx and vwsub.wx and add helpers. (*)
  937713a... RISC-V: Do not allow v0 as dest when merging [PR115068]. (*)
  3a7e796... RISC-V: Add -X to link spec (*)
  92003fa... RISC-V: Fix parsing of Zic* extensions (*)
  68ef0c3... RISC-V: Bugfix ICE for RVV intrinisc vfw on _Float16 scalar (*)
  c38dbfc... RISC-V: Fix missing boolean_expression in zmmul extension (*)
  4db3875... RISC-V: Bugfix vec_extract v mode iterator restriction mism (*)
  87346ed... RISC-V: Bugfix vec_extract vls mode iterator restriction mi (*)
  c32995c... [PATCH] RISC-V: Fix unrecognizable pattern in riscv_expand_ (*)
  2d7dda8... RISC-V: Use tu policy for first-element vec_set [PR115725]. (*)
  b218c42... [RISC-V] add implied extension repeatly until stable (*)
  a2a2916... Daily bump. (*)
  493035c... eh: ICE with std::initializer_list and ASan [PR115865] (*)
  747c4b5... Do not use caller-saved registers for COMDAT functions (*)
  c314867... c++: ICE with __has_unique_object_representations [PR115476 (*)
  a4c9ade... i386: PR target/115351: RTX costs for *concatditi3 and *ins (*)
  b0452ed... analyzer: fix ICE seen with -fsanitize=undefined [PR114899] (*)
  0b7ec50... Fix points_to_local_or_readonly_memory_p wrt TARGET_MEM_REF (*)
  0f593e4... PR tree-optimization/113673: Avoid load merging when potent (*)
  0fbad21... testsuite: Fix up builtin-clear-padding-3.c for -funsigned- (*)
  f0c3a1c... c++/modules: Conditionally start timer during lazy load [PR (*)
  4871b0f... Daily bump. (*)
  1bbfe78... c++: constrained partial spec type context [PR111890] (*)
  2249c63... c++: alias template with dependent attributes [PR115897] (*)
  79c5a09... c++: bad 'this' conversion for nullary memfn [PR106760] (*)
  3a963d4... alpha: Fix duplicate !tlsgd!62 assemble error [PR115526] (*)
  01dfc5b... bitint: Use gsi_insert_on_edge rather than gsi_insert_on_ed (*)
  d668f87... gimple-fold: Fix up __builtin_clear_padding lowering [PR115 (*)
  297ea7e... c++: Fix ICE on constexpr placement new [PR115754] (*)
  bf64404... vect: Merge loop mask and cond_op mask in fold-left reducti (*)
  c58bede... tree-optimization/115868 - ICE with .MASK_CALL in simdclone (*)
  5fad0b5... c++/modules: Propagate BINDING_VECTOR_*_DUPS_P on realloc [ (*)
  4039c74... Daily bump. (*)
  59ed01d... tree-optimization/115841 - reduction epilogue placement iss (*)
  06829e5... tree-optimization/115843 - fix wrong-code with fully-masked (*)
  e01012c... tree-optimization/115701 - fix maybe_duplicate_ssa_info_at_ (*)
  6f74a5f... tree-optimization/115701 - factor out maybe_duplicate_ssa_i (*)
  ca275b6... tree-optimization/115867 - ICE with simdcall vectorization  (*)
  4a04110... Fixup unaligned load/store cost for znver5 (*)
  d702a95... Fixup unaligned load/store cost for znver4 (*)
  c8fdef7... [alpha] adjust MEM alignment for block move [PR115459] (*)
  b3cff83... RISC-V: Allow adding enabled extension via target arch attr (*)
  0e1f599... RISC-V: Rewrite target attribute handling (*)
  b604d59... RISC-V: Fix comment/naming in attribute parsing code (*)
  20fb450... RISC-V: Deduplicate arch subset list processing (*)
  ea5907d... RISC-V: testsuite: Properly gate LTO tests (*)
  7bc63f1... [i386] adjust flag_omit_frame_pointer in a single function  (*)
  102bcf1... [i386] restore recompute to override opts after change [PR1 (*)
  1fff665... x86: Update branch hint for Redwood Cove. (*)
  0fcadb3... Daily bump. (*)
  71ec9ed... Fortran: improve attribute conflict checking [PR93635] (*)
  13bfc38... Fix SSA_NAME leak due 

[gcc r15-2648] fortran: Fix up pasto in gfc_get_array_descr_info

2024-08-01 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:90fe402a89910d4fbe0efc15cf05cf6c0306586a

commit r15-2648-g90fe402a89910d4fbe0efc15cf05cf6c0306586a
Author: Jakub Jelinek 
Date:   Thu Aug 1 20:23:15 2024 +0200

fortran: Fix up pasto in gfc_get_array_descr_info

A static analyzer found a pasto in gfc_get_array_descr_info.
The code does
  t = base_decl;
  if (!integer_zerop (dtype_off))
t = fold_build_pointer_plus (t, dtype_off);
  dtype = TYPE_MAIN_VARIANT (get_dtype_type_node ());
  field = gfc_advance_chain (TYPE_FIELDS (dtype), GFC_DTYPE_RANK);
  rank_off = byte_position (field);
  if (!integer_zerop (dtype_off))
t = fold_build_pointer_plus (t, rank_off);
i.e. uses the same !integer_zerop check between both, while it should
be checking rank_off in the latter case.
This actually doesn't change anything on the generated code, because
both the dtype_off and rank_off aren't zero,
typedef struct dtype_type
{
  size_t elem_len;
  int version;
  signed char rank;
  signed char type;
  signed short attribute;
}
dtype_type;
struct {
  type *base_addr;
  size_t offset;
  dtype_type dtype;
  index_type span;
  descriptor_dimension dim[];
};
dtype_off is 16 on 64-bit arches and 8 on 32-bit ones and rank_off is
12 on 64-bit arches and 8 on 32-bit arches, so this patch is just to
pacify those static analyzers or be prepared if the ABI changes in the
future.  Because in the current ABI both of those are actually non-zero,
doing
if (!integer_zerop (something)) t = fold_build_pointer_plus (t, something);
actually isn't an optimization, it will consume more compile time.  If
the ABI changes and we forget to readd it, nothing bad happens,
fold_build_pointer_plus handles 0 addends fine, just takes some compile
time to handle that.
I've kept this if (!integer_zerop (data_off)) guard earlier because
data_off is 0 in the current ABI, so it is an optimization there.

2024-08-01  Jakub Jelinek  

* trans-types.cc (gfc_get_array_descr_info): Don't test if
!integer_zerop (dtype_off), use fold_build_pointer_plus
unconditionally.

Diff:
---
 gcc/fortran/trans-types.cc | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index 59d72136a0de..e6da8e1a58b7 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -3599,14 +3599,11 @@ gfc_get_array_descr_info (const_tree type, struct 
array_descr_info *info)
 {
   rank = 1;
   info->ndimensions = 1;
-  t = base_decl;
-  if (!integer_zerop (dtype_off))
-   t = fold_build_pointer_plus (t, dtype_off);
+  t = fold_build_pointer_plus (base_decl, dtype_off);
   dtype = TYPE_MAIN_VARIANT (get_dtype_type_node ());
   field = gfc_advance_chain (TYPE_FIELDS (dtype), GFC_DTYPE_RANK);
   rank_off = byte_position (field);
-  if (!integer_zerop (dtype_off))
-   t = fold_build_pointer_plus (t, rank_off);
+  t = fold_build_pointer_plus (t, rank_off);
 
   t = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (field)), t);
   t = build1 (INDIRECT_REF, TREE_TYPE (field), t);


[gcc r15-2645] c++: Fix up error recovery of invalid structured bindings used in conditions [PR116113]

2024-08-01 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:295b729da5aa430a8c5df1422644159ca8bf8dcb

commit r15-2645-g295b729da5aa430a8c5df1422644159ca8bf8dcb
Author: Jakub Jelinek 
Date:   Thu Aug 1 18:49:39 2024 +0200

c++: Fix up error recovery of invalid structured bindings used in 
conditions [PR116113]

The following testcase ICEs, because for structured binding error recovery
DECL_DECOMP_BASE is kept NULL and the newly added code to pick up saved
value from the base assumes that on structured binding bases the
TARGET_EXPR will be always there (that is the case if there are no errors).

The following patch fixes it by testing DECL_DECOMP_BASE before
dereferencing it, another option would be not to do that if
error_operand_p (cond).

2024-08-01  Jakub Jelinek  

PR c++/116113
* semantics.cc (maybe_convert_cond): Check DECL_DECOMP_BASE
is non-NULL before dereferencing it.
(finish_switch_cond): Likewise.

* g++.dg/cpp26/decomp11.C: New test.

Diff:
---
 gcc/cp/semantics.cc   |  2 ++
 gcc/testsuite/g++.dg/cpp26/decomp11.C | 19 +++
 2 files changed, 21 insertions(+)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index a9abf32e01ff..669da4ad9698 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -972,6 +972,7 @@ maybe_convert_cond (tree cond)
  result in a TARGET_EXPR, pick it up from there.  */
   if (DECL_DECOMPOSITION_P (cond)
   && DECL_DECOMP_IS_BASE (cond)
+  && DECL_DECOMP_BASE (cond)
   && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
 cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
 
@@ -1714,6 +1715,7 @@ finish_switch_cond (tree cond, tree switch_stmt)
 conversion result in a TARGET_EXPR, pick it up from there.  */
   if (DECL_DECOMPOSITION_P (cond)
  && DECL_DECOMP_IS_BASE (cond)
+ && DECL_DECOMP_BASE (cond)
  && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
   cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
diff --git a/gcc/testsuite/g++.dg/cpp26/decomp11.C 
b/gcc/testsuite/g++.dg/cpp26/decomp11.C
new file mode 100644
index ..985f40f2f335
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp26/decomp11.C
@@ -0,0 +1,19 @@
+// PR c++/116113
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+extern int b[];
+
+void
+foo ()
+{
+  auto [a] = b;// { dg-error "is incomplete" }
+   // { dg-warning "structured bindings only available with" "" { 
target c++14_down } .-1 }
+  if (a)
+;
+  switch (a)
+{
+default:
+  break;
+}
+}


[gcc r14-10528] i386: Fix up *_vinsert_0 [PR115981]

2024-08-01 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:973097d801a30385cd39a570624eefa7547f8ff3

commit r14-10528-g973097d801a30385cd39a570624eefa7547f8ff3
Author: Jakub Jelinek 
Date:   Thu Aug 1 10:32:54 2024 +0200

i386: Fix up *_vinsert_0 [PR115981]

The r14-537 change started canonicalizing VEC_MERGE operands based on
swap_commutative_operands_p or if they have the same precedence least
significant bit of the third operand.
The *_vinsert_0 pattern was
added for combine matching and no longer triggers after that change,
as it used the reg_or_0_operand as the first operand and VEC_DUPLICATE
as the second.
Now, reg_or_0_operand could be a REG, SUBREG of object or CONST_VECTOR.
REG has commutative_operand_precedence -1 or -2, SUBREG of object -3,
CONST_VECTOR -4, while VEC_DUPLICATE has 0, so VEC_DUPLICATE will always
go first and REG, SUBREG or CONST_VECTOR second.

This patch swaps the operands so that it matches again.

2024-08-01  Jakub Jelinek  

PR target/115981
* config/i386/sse.md
(*_vinsert_0): Swap the
first two VEC_MERGE operands, renumber match_operands and test
for 0xF or 0x3 rather than 0xFFF0 or 0xFC immediate.

* gcc.target/i386/avx512dq-pr90991-1.c: Add tests for no separate
zero extension instructions.
* gcc.target/i386/avx512dq-pr90991-2.c: Likewise.

(cherry picked from commit df2b444a233e93b987adec76655ab89589b3fa10)

Diff:
---
 gcc/config/i386/sse.md | 42 +++---
 gcc/testsuite/gcc.target/i386/avx512dq-pr90991-1.c |  3 ++
 gcc/testsuite/gcc.target/i386/avx512dq-pr90991-2.c |  3 ++
 3 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 1bf50726e830..073aae293d4c 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -19124,47 +19124,47 @@
 (define_insn "*_vinsert_0"
   [(set (match_operand:AVX512_VEC 0 "register_operand" "=v,x,Yv")
(vec_merge:AVX512_VEC
- (match_operand:AVX512_VEC 1 "reg_or_0_operand" "v,C,C")
  (vec_duplicate:AVX512_VEC
-   (match_operand: 2 "nonimmediate_operand" 
"vm,xm,vm"))
+   (match_operand: 1 "nonimmediate_operand" 
"vm,xm,vm"))
+ (match_operand:AVX512_VEC 2 "reg_or_0_operand" "v,C,C")
  (match_operand:SI 3 "const_int_operand")))]
   "TARGET_AVX512F
&& (INTVAL (operands[3])
-   == (GET_MODE_UNIT_SIZE (mode) == 4 ? 0xFFF0 : 0xFC))"
+   == (GET_MODE_UNIT_SIZE (mode) == 4 ? 0xF : 0x3))"
 {
   if (which_alternative == 0)
-return "vinsert\t{$0, %2, %1, %0|%0, %1, %2, 0}";
+return "vinsert\t{$0, %1, %2, %0|%0, %2, %1, 0}";
   bool egpr_used = (TARGET_APX_EGPR
-   && x86_extended_rex2reg_mentioned_p (operands[2]));
-  const char *align_templ = egpr_used ? "vmovaps\t{%2, %x0|%x0, %2}"
- : "vmovdqa\t{%2, %x0|%x0, %2}";
-  const char *unalign_templ = egpr_used ? "vmovups\t{%2, %x0|%x0, %2}"
-   : "vmovdqu\t{%2, %x0|%x0, %2}";
+   && x86_extended_rex2reg_mentioned_p (operands[1]));
+  const char *align_templ = egpr_used ? "vmovaps\t{%1, %x0|%x0, %1}"
+ : "vmovdqa\t{%1, %x0|%x0, %1}";
+  const char *unalign_templ = egpr_used ? "vmovups\t{%1, %x0|%x0, %1}"
+   : "vmovdqu\t{%1, %x0|%x0, %1}";
   switch (mode)
 {
 case E_V8DFmode:
-  if (misaligned_operand (operands[2], mode))
-   return "vmovupd\t{%2, %x0|%x0, %2}";
+  if (misaligned_operand (operands[1], mode))
+   return "vmovupd\t{%1, %x0|%x0, %1}";
   else
-   return "vmovapd\t{%2, %x0|%x0, %2}";
+   return "vmovapd\t{%1, %x0|%x0, %1}";
 case E_V16SFmode:
-  if (misaligned_operand (operands[2], mode))
-   return "vmovups\t{%2, %x0|%x0, %2}";
+  if (misaligned_operand (operands[1], mode))
+   return "vmovups\t{%1, %x0|%x0, %1}";
   else
-   return "vmovaps\t{%2, %x0|%x0, %2}";
+   return "vmovaps\t{%1, %x0|%x0, %1}";
 case E_V8DImode:
-  if (misaligned_operand (operands[2], mode))
-   return which_alternative == 2 ? "vmovdqu64\t{%2, %x0|%x0, %2}"
+  if (misaligned_operand (operands[1], mode))
+   return which_alternative == 2 ? "vmovdqu64\t{%1, %x0|%x0, %1}"
  : unalign_templ;
   else
-   return which_alternative == 2 ? "vmovdqa64\t{%2, %x0|%x0, %2}"
+   return which_alternative == 2 ? "vmovdqa64\t{%1, %x0|%x0, %1}"
  : align_templ;
 case E_V16SImode:
-  if (misaligned_operand (operands[2], mode))
-   return which_alternative == 2 ? "vmovdqu32\t{%2, %x0|%x0, %2}"
+  if (misaligned_operand (operands[1], mode))
+   return which_alternative == 2 ? "vmovdqu32\t{%1, %x0|%x0, %1}"
  : unal

[gcc r14-10527] Bump BASE-VER.

2024-08-01 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:fb2f72db27b96fba73ed525d1e14a141663f82cc

commit r14-10527-gfb2f72db27b96fba73ed525d1e14a141663f82cc
Author: Jakub Jelinek 
Date:   Thu Aug 1 11:17:40 2024 +0200

Bump BASE-VER.

2024-08-01  Jakub Jelinek  

* BASE-VER: Set to 14.2.1.

Diff:
---
 gcc/BASE-VER | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/BASE-VER b/gcc/BASE-VER
index 07ea9fa43814..dab6a80f4a88 100644
--- a/gcc/BASE-VER
+++ b/gcc/BASE-VER
@@ -1 +1 @@
-14.2.0
+14.2.1


[gcc r15-2473] i386: Fix up *_vinsert_0 [PR115981]

2024-08-01 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:df2b444a233e93b987adec76655ab89589b3fa10

commit r15-2473-gdf2b444a233e93b987adec76655ab89589b3fa10
Author: Jakub Jelinek 
Date:   Thu Aug 1 10:32:54 2024 +0200

i386: Fix up *_vinsert_0 [PR115981]

The r14-537 change started canonicalizing VEC_MERGE operands based on
swap_commutative_operands_p or if they have the same precedence least
significant bit of the third operand.
The *_vinsert_0 pattern was
added for combine matching and no longer triggers after that change,
as it used the reg_or_0_operand as the first operand and VEC_DUPLICATE
as the second.
Now, reg_or_0_operand could be a REG, SUBREG of object or CONST_VECTOR.
REG has commutative_operand_precedence -1 or -2, SUBREG of object -3,
CONST_VECTOR -4, while VEC_DUPLICATE has 0, so VEC_DUPLICATE will always
go first and REG, SUBREG or CONST_VECTOR second.

This patch swaps the operands so that it matches again.

2024-08-01  Jakub Jelinek  

PR target/115981
* config/i386/sse.md
(*_vinsert_0): Swap the
first two VEC_MERGE operands, renumber match_operands and test
for 0xF or 0x3 rather than 0xFFF0 or 0xFC immediate.

* gcc.target/i386/avx512dq-pr90991-1.c: Add tests for no separate
zero extension instructions.
* gcc.target/i386/avx512dq-pr90991-2.c: Likewise.

Diff:
---
 gcc/config/i386/sse.md | 42 +++---
 gcc/testsuite/gcc.target/i386/avx512dq-pr90991-1.c |  3 ++
 gcc/testsuite/gcc.target/i386/avx512dq-pr90991-2.c |  3 ++
 3 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index f54e966bdbb2..baaec6897496 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -19692,47 +19692,47 @@
 (define_insn "*_vinsert_0"
   [(set (match_operand:AVX512_VEC 0 "register_operand" "=v,x,Yv")
(vec_merge:AVX512_VEC
- (match_operand:AVX512_VEC 1 "reg_or_0_operand" "v,C,C")
  (vec_duplicate:AVX512_VEC
-   (match_operand: 2 "nonimmediate_operand" 
"vm,xm,vm"))
+   (match_operand: 1 "nonimmediate_operand" 
"vm,xm,vm"))
+ (match_operand:AVX512_VEC 2 "reg_or_0_operand" "v,C,C")
  (match_operand:SI 3 "const_int_operand")))]
   "TARGET_AVX512F
&& (INTVAL (operands[3])
-   == (GET_MODE_UNIT_SIZE (mode) == 4 ? 0xFFF0 : 0xFC))"
+   == (GET_MODE_UNIT_SIZE (mode) == 4 ? 0xF : 0x3))"
 {
   if (which_alternative == 0)
-return "vinsert\t{$0, %2, %1, %0|%0, %1, %2, 0}";
+return "vinsert\t{$0, %1, %2, %0|%0, %2, %1, 0}";
   bool egpr_used = (TARGET_APX_EGPR
-   && x86_extended_rex2reg_mentioned_p (operands[2]));
-  const char *align_templ = egpr_used ? "vmovaps\t{%2, %x0|%x0, %2}"
- : "vmovdqa\t{%2, %x0|%x0, %2}";
-  const char *unalign_templ = egpr_used ? "vmovups\t{%2, %x0|%x0, %2}"
-   : "vmovdqu\t{%2, %x0|%x0, %2}";
+   && x86_extended_rex2reg_mentioned_p (operands[1]));
+  const char *align_templ = egpr_used ? "vmovaps\t{%1, %x0|%x0, %1}"
+ : "vmovdqa\t{%1, %x0|%x0, %1}";
+  const char *unalign_templ = egpr_used ? "vmovups\t{%1, %x0|%x0, %1}"
+   : "vmovdqu\t{%1, %x0|%x0, %1}";
   switch (mode)
 {
 case E_V8DFmode:
-  if (misaligned_operand (operands[2], mode))
-   return "vmovupd\t{%2, %x0|%x0, %2}";
+  if (misaligned_operand (operands[1], mode))
+   return "vmovupd\t{%1, %x0|%x0, %1}";
   else
-   return "vmovapd\t{%2, %x0|%x0, %2}";
+   return "vmovapd\t{%1, %x0|%x0, %1}";
 case E_V16SFmode:
-  if (misaligned_operand (operands[2], mode))
-   return "vmovups\t{%2, %x0|%x0, %2}";
+  if (misaligned_operand (operands[1], mode))
+   return "vmovups\t{%1, %x0|%x0, %1}";
   else
-   return "vmovaps\t{%2, %x0|%x0, %2}";
+   return "vmovaps\t{%1, %x0|%x0, %1}";
 case E_V8DImode:
-  if (misaligned_operand (operands[2], mode))
-   return which_alternative == 2 ? "vmovdqu64\t{%2, %x0|%x0, %2}"
+  if (misaligned_operand (operands[1], mode))
+   return which_alternative == 2 ? "vmovdqu64\t{%1, %x0|%x0, %1}"
  : unalign_templ;
   else
-   return which_alternative == 2 ? "vmovdqa64\t{%2, %x0|%x0, %2}"
+   return which_alternative == 2 ? "vmovdqa64\t{%1, %x0|%x0, %1}"
  : align_templ;
 case E_V16SImode:
-  if (misaligned_operand (operands[2], mode))
-   return which_alternative == 2 ? "vmovdqu32\t{%2, %x0|%x0, %2}"
+  if (misaligned_operand (operands[1], mode))
+   return which_alternative == 2 ? "vmovdqu32\t{%1, %x0|%x0, %1}"
  : unalign_templ;
   else
-   return which_alternative == 2 ? "vmovdqa32\t{%2,

[gcc r15-2375] testsuite: Fix up consteval-prop21.C for 32-bit targets [PR115986]

2024-07-29 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:331f23540eec39fc1e665f573c4aac258bba6043

commit r15-2375-g331f23540eec39fc1e665f573c4aac258bba6043
Author: Jakub Jelinek 
Date:   Mon Jul 29 09:33:09 2024 +0200

testsuite: Fix up consteval-prop21.C for 32-bit targets [PR115986]

The test fails on 32-bit targets (which don't support __int128 type).
Using unsigned long long instead still ICEs before the fix and passes
after it on those targets.

2024-07-29  Jakub Jelinek  

PR c++/115986
* g++.dg/cpp2a/consteval-prop21.C (operator "" _c): Use
unsigned long long rather than __uint128_t for return type if int128
is unsupported.

Diff:
---
 gcc/testsuite/g++.dg/cpp2a/consteval-prop21.C | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval-prop21.C 
b/gcc/testsuite/g++.dg/cpp2a/consteval-prop21.C
index debbda4f4259..36da1bd91f3a 100644
--- a/gcc/testsuite/g++.dg/cpp2a/consteval-prop21.C
+++ b/gcc/testsuite/g++.dg/cpp2a/consteval-prop21.C
@@ -5,7 +5,13 @@ template 
 constexpr int b(T) {
   return 0;
 }
-consteval __uint128_t operator"" _c(const char*) { return 0; }
+consteval
+#ifdef __SIZEOF_INT128__
+__uint128_t
+#else
+unsigned long long
+#endif
+operator"" _c(const char*) { return 0; }
 constexpr char e() {
   long f = true ? 0 : b(long(1));
   return b(f);


[gcc r15-2350] testsuite: Fix up ucn-1.C for C++26

2024-07-26 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:2fb5bbe5ee9c148cd7d1068b18be66cc52054812

commit r15-2350-g2fb5bbe5ee9c148cd7d1068b18be66cc52054812
Author: Jakub Jelinek 
Date:   Fri Jul 26 21:01:03 2024 +0200

testsuite: Fix up ucn-1.C for C++26

On Fri, Jul 26, 2024 at 11:43:13AM -0400, Jason Merrill wrote:
> I'm now seeing a -std=c++26 failure on g++.dg/cpp/ucn-1.C.

I don't remember seeing it when I wrote the patch, but today I see it as
well.

2024-07-26  Jakub Jelinek  

* g++.dg/cpp/ucn-1.C (main): Expect error on c\u0024c identifier 
also
for C++26.

Diff:
---
 gcc/testsuite/g++.dg/cpp/ucn-1.C | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/cpp/ucn-1.C b/gcc/testsuite/g++.dg/cpp/ucn-1.C
index 9596a4296505..8277d2effd52 100644
--- a/gcc/testsuite/g++.dg/cpp/ucn-1.C
+++ b/gcc/testsuite/g++.dg/cpp/ucn-1.C
@@ -9,7 +9,7 @@ int main()
 
   int c\u0041c;// { dg-error "not valid in an identifier" }
// $ is OK on most targets; not part of basic source char set
-  int c\u0024c;// { dg-error "not valid in an identifier" "" { target 
{ powerpc-ibm-aix* } } }
+  int c\u0024c;// { dg-error "not valid in an identifier" "" { target 
{ { powerpc-ibm-aix* } || c++26 } } }
 
   U"\uD800"; // { dg-error "not a valid universal character" }


[gcc r15-2322] c++: Implement C++26 P2558R2 - Add @, $, and ` to the basic character set [PR110343]

2024-07-25 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:29341f21ce1eb7cdb8cd468e4ceb0d07cf2775e0

commit r15-2322-g29341f21ce1eb7cdb8cd468e4ceb0d07cf2775e0
Author: Jakub Jelinek 
Date:   Thu Jul 25 21:36:31 2024 +0200

c++: Implement C++26 P2558R2 - Add @, $, and ` to the basic character set 
[PR110343]

The following patch implements the easy parts of the paper.
When @$` are added to the basic character set, it means that
R"@$`()@$`" should now be valid (here I've noticed most of the
raw string tests were tested solely with -std=c++11 or -std=gnu++11
and I've tried to change that), and on the other side even if
by extension $ is allowed in identifiers, \u0024 or \U0024
or \u{24} should not be, similarly how \u0041 is not allowed.

The paper in 3.1 claims though that
 #include 

 #define STR(x) #x

int main()
{
  printf("%s", STR(\u0060)); // U+0060 is ` GRAVE ACCENT
}
should have been accepted before this paper (and rejected after it),
but g++ rejects it.

I've tried to understand it, but am confused on what is the right
behavior and why.

Consider
 #define STR(x) #x
const char *a = "\u00b7";
const char *b = STR(\u00b7);
const char *c = "\u0041";
const char *d = STR(\u0041);
const char *e = STR(a\u00b7);
const char *f = STR(a\u0041);
const char *g = STR(a \u00b7);
const char *h = STR(a \u0041);
const char *i = "\u066d";
const char *j = STR(\u066d);
const char *k = "\u0040";
const char *l = STR(\u0040);
const char *m = STR(a\u066d);
const char *n = STR(a\u0040);
const char *o = STR(a \u066d);
const char *p = STR(a \u0040);

Neither clang nor gcc emit any diagnostics on the a, c, i and k
initializers, those are certainly valid (c is invalid in C23 though).  g++
emits with -pedantic-errors errors on all the others, while clang++ on the
ones with STR involving \u0041, \u0040 and a\u0066d.  The chosen values are
\u0040 '@' as something being changed by this paper, \u0041 'A' as basic
character set char valid in identifiers before/after, \u00b7 as an example
of character which is pedantically valid in identifiers if not at the start
and \u066d s something pedantically not valid in identifiers.

Now, https://eel.is/c++draft/lex.charset#6 says that UCN used outside of a
string/character literal which corresponds to basic character set character
(or control character) is ill-formed, that would make d, f, h cases invalid
for C++ and l, n, p cases invalid for C++26.

https://eel.is/c++draft/lex.name states which characters can appear at the
start of the identifier and which can appear after the start.  And
https://eel.is/c++draft/lex.pptoken states that preprocessing-token is
either identifier, or tons of other things, or "each non-whitespace
character that cannot be one of the above"

Then https://eel.is/c++draft/lex.pptoken#1 says that this last category is
invalid if the preprocessing token is being converted into token.

And https://eel.is/c++draft/lex.pptoken#2 includes "If any character not in
the basic character set matches the last category, the program is
ill-formed."

Now, e.g.  for the C++23 STR(\u0040) case, \u0040 is there not in the basic
character set, so valid outside of the literals (not the case anymore in
C++26), but it isn't nondigit and doesn't have XID_Start property, so it
isn't IMHO an identifier and so must be the "each non-whitespace character
that cannot be one of the above" case.  Why doesn't the above mentioned
https://eel.is/c++draft/lex.pptoken#2 sentence make that invalid?  Ignoring
that, I'd say it would be then stringized and that feels like it is what
clang++ is doing.  Now, e.g.  for the STR(a\u066d) case, I wonder why that
isn't lexed as a identifier followed by \u066d "each non-whitespace
character that cannot be one of the above" token and stringified similarly,
clang++ rejects that.

What GCC libcpp seems to be doing is that if that forms_identifier_p calls
_cpp_valid_utf8 or _cpp_valid_ucn with an argument which tells it is first
or second+ in identifier, and e.g.  _cpp_valid_ucn then for UCNs valid in
string literals calls
  else if (identifier_pos)
{
  int validity = ucn_valid_in_identifier (pfile, result, nst);

  if (validity == 0)
cpp_error (pfile, CPP_DL_ERROR,
   "universal character %.*s is not valid in an identifier",
   (int) (str - base), base);
  else if (validity == 2 && identifier_pos == 1)
cpp_error (pfile, CPP_DL_ERROR,
   "universal character %.*s is not valid at the start of an identifier",
   (int) (str - base), base);
}
so basically all those invalid in identifiers cases emit an error and
pretend to be 

[gcc r15-2276] c++: Mostly concepts related formatting fixes

2024-07-24 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:d2fc64c85788c135419cc3dcf5b4fa64558af547

commit r15-2276-gd2fc64c85788c135419cc3dcf5b4fa64558af547
Author: Jakub Jelinek 
Date:   Wed Jul 24 19:46:58 2024 +0200

c++: Mostly concepts related formatting fixes

When playing with P2963R3, while reading and/or modifying code I've fixed
various comment or code formatting issues (and in 3 spots also comment
wording), but including that in the WIP P2963R3 patch made that patch
totally unreadable because these changes were 4 times the size of the
actual code changes.

So, here it is separated to a pure formatting + comment wording patch.

2024-07-24  Jakub Jelinek  

* constraint.cc (subst_info::quiet, subst_info::noisy): Formatting
fixes.
(known_non_bool_p): Comment formatting fixes.
(unpack_concept_check): Likewise.
(resolve_function_concept_overload): Likewise.
(resolve_function_concept_check): Likewise.
(resolve_concept_check): Likewise.
(deduce_constrained_parameter): Likewise.
(finish_type_constraints): Likewise.
(get_returned_expression): Likewise.
(get_variable_initializer): Likewise.
(norm_info::update_context, norm_info::ctx_params): Formatting
fixes.
(norm_info::context): Comment formatting fixes.
(normalize_logical_operation): Likewise.  Formatting fix.
(normalize_concept_check): Comment formatting fixes.
(normalize_atom): Likewise.
(normalize_expression): Likewise.
(get_normalized_constraints_from_info): Likewise.
(get_normalized_constraints_from_decl): Likewise.  Formatting
fixes.
(atomic_constraints_identical_p): Comment formatting fixes.
(constraints_equivalent_p): Formatting fixes.
(inchash::add_constraint): Likewise.
(associate_classtype_constraints): Comment formatting fixes.
(get_constraints): Likewise.
(set_constraints): Likewise.
(build_concept_check_arguments): Likewise.
(build_function_check): Likewise.
(build_concept_check): Likewise.
(finish_shorthand_constraint): Likewise.
(get_shorthand_constraints): Likewise.
(check_constraint_variables): Likewise.
(tsubst_constraint_variables): Likewise.
(tsubst_requires_expr): Likewise.
(get_mapped_args): Likewise.  Formatting fixes.
(satisfy_atom): Comment formatting fixes.
(satisfy_constraint_r): Comment wording and formatting fixes.
(satisfy_normalized_constraints): Comment formatting fixes.
(satisfy_declaration_constraints): Likewise.
(evaluate_concept_check): Likewise.
(finish_requires_expr): Likewise.
(finish_compound_requirement): Likewise.
(check_function_concept): Likewise.
(equivalently_constrained): Likewise.
(more_constrained): Likewise.
(diagnose_atomic_constraint): Likewise.
* cp-tree.h (TREE_LANG_FLAG_0): Fix a comment error,
FOLD_EXPR_MODIFY_P instead of FOLD_EXPR_MODOP_P.
(DECL_MAIN_FREESTANDING_P, DECL_MAIN_P): Comment formatting fixes.
(enum cpp0x_warn_str): Likewise.
(enum composite_pointer_operation): Likewise.
(enum expr_list_kind): Likewise.
(enum impl_conv_rhs): Likewise.
(enum impl_conv_void): Likewise.
(struct deferred_access_check): Likewise.
(ATOMIC_CONSTR_EXPR): Likewise.
(FUNCTION_REF_QUALIFIED): Likewise.
(DECL_DEPENDENT_P): Likewise.
(FOLD_EXPR_MODIFY_P): Likewise.
(FOLD_EXPR_OP_RAW): Likewise.
(FOLD_EXPR_PACK): Likewise.
(FOLD_EXPR_INIT): Likewise.
(TYPE_WAS_UNNAMED): Likewise.
(class cp_unevaluated): Likewise.
(struct ovl_op_info_t assertion): Likewise.
(cp_declarator::function::requires_clause): Likewise.
(variable_template_p): Likewise.
(concept_definition_p): Likewise.
* logic.cc (clause::clause): Likewise.
(clause::replace): Likewise.
(clause::insert): Likewise.  Formatting fixes.
(struct formula): Comment formatting fixes.
(formula::branch): Likewise.
(debug): Formatting fixes.
(dnf_size_r): Comment formatting fixes.
(cnf_size_r): Likewise.
(dnf_size): Likewise.
(cnf_size): Likewise.
(branch_clause): Likewise.
(decompose_term): Likewise.  Formatting fixes.
(struct subsumption_entry): Comment formatting fixes.
(subsumption_cache): Likewise.
(save_subsumption): Likewise.  Formatting fixes.
(sub

[gcc r14-10507] testsuite: Fix up pr116034.c test for big/pdp endian [PR116061]

2024-07-24 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:181f40f5cf8510a16191e4768dadbe2cb7a5c095

commit r14-10507-g181f40f5cf8510a16191e4768dadbe2cb7a5c095
Author: Jakub Jelinek 
Date:   Wed Jul 24 18:00:05 2024 +0200

testsuite: Fix up pr116034.c test for big/pdp endian [PR116061]

Didn't notice the memmove is into an int variable, so the test
was still failing on big endian.

2024-07-24  Jakub Jelinek  

PR tree-optimization/116034
PR testsuite/116061
* gcc.dg/pr116034.c (g): Change type from int to unsigned short.
(foo): Guard memmove call on __SIZEOF_SHORT__ == 2.

(cherry picked from commit 69e69847e21a8d951ab5f09fd3421449564dba31)

Diff:
---
 gcc/testsuite/gcc.dg/pr116034.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr116034.c b/gcc/testsuite/gcc.dg/pr116034.c
index 9a31de034246..955b4c9e86b8 100644
--- a/gcc/testsuite/gcc.dg/pr116034.c
+++ b/gcc/testsuite/gcc.dg/pr116034.c
@@ -2,12 +2,13 @@
 /* { dg-do run } */
 /* { dg-options "-O1 -fno-strict-aliasing" } */
 
-int g;
+unsigned short int g;
 
 static inline int
 foo (_Complex unsigned short c)
 {
-  __builtin_memmove (&g, 1 + (char *) &c, 2);
+  if (__SIZEOF_SHORT__ == 2)
+__builtin_memmove (&g, 1 + (char *) &c, 2);
   return g;
 }


[gcc r15-2274] testsuite: Fix up pr116034.c test for big/pdp endian [PR116061]

2024-07-24 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:69e69847e21a8d951ab5f09fd3421449564dba31

commit r15-2274-g69e69847e21a8d951ab5f09fd3421449564dba31
Author: Jakub Jelinek 
Date:   Wed Jul 24 18:00:05 2024 +0200

testsuite: Fix up pr116034.c test for big/pdp endian [PR116061]

Didn't notice the memmove is into an int variable, so the test
was still failing on big endian.

2024-07-24  Jakub Jelinek  

PR tree-optimization/116034
PR testsuite/116061
* gcc.dg/pr116034.c (g): Change type from int to unsigned short.
(foo): Guard memmove call on __SIZEOF_SHORT__ == 2.

Diff:
---
 gcc/testsuite/gcc.dg/pr116034.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr116034.c b/gcc/testsuite/gcc.dg/pr116034.c
index 9a31de034246..955b4c9e86b8 100644
--- a/gcc/testsuite/gcc.dg/pr116034.c
+++ b/gcc/testsuite/gcc.dg/pr116034.c
@@ -2,12 +2,13 @@
 /* { dg-do run } */
 /* { dg-options "-O1 -fno-strict-aliasing" } */
 
-int g;
+unsigned short int g;
 
 static inline int
 foo (_Complex unsigned short c)
 {
-  __builtin_memmove (&g, 1 + (char *) &c, 2);
+  if (__SIZEOF_SHORT__ == 2)
+__builtin_memmove (&g, 1 + (char *) &c, 2);
   return g;
 }


[gcc r14-10501] ssa: Fix up maybe_rewrite_mem_ref_base complex type handling [PR116034]

2024-07-23 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:084768c865cd50a6f7ff177db2dbdbb7aadaeee0

commit r14-10501-g084768c865cd50a6f7ff177db2dbdbb7aadaeee0
Author: Jakub Jelinek 
Date:   Tue Jul 23 10:50:29 2024 +0200

ssa: Fix up maybe_rewrite_mem_ref_base complex type handling [PR116034]

The folding into REALPART_EXPR is correct, used only when the mem_offset
is zero, but for IMAGPART_EXPR it didn't check the exact offset value (just
that it is not 0).
The following patch fixes that by using IMAGPART_EXPR only if the offset
is right and using BITFIELD_REF or whatever else otherwise.

2024-07-23  Jakub Jelinek  
Andrew Pinski  

PR tree-optimization/116034
* tree-ssa.cc (maybe_rewrite_mem_ref_base): Only use IMAGPART_EXPR
if MEM_REF offset is equal to element type size.

* gcc.dg/pr116034.c: New test.

(cherry picked from commit b9cefd67a2a464a3c9413e6b3f28e7dc7a9ef162)

Diff:
---
 gcc/testsuite/gcc.dg/pr116034.c | 22 ++
 gcc/tree-ssa.cc |  5 -
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/pr116034.c b/gcc/testsuite/gcc.dg/pr116034.c
new file mode 100644
index ..9a31de034246
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116034.c
@@ -0,0 +1,22 @@
+/* PR tree-optimization/116034 */
+/* { dg-do run } */
+/* { dg-options "-O1 -fno-strict-aliasing" } */
+
+int g;
+
+static inline int
+foo (_Complex unsigned short c)
+{
+  __builtin_memmove (&g, 1 + (char *) &c, 2);
+  return g;
+}
+
+int
+main ()
+{
+  if (__SIZEOF_SHORT__ == 2
+  && __CHAR_BIT__ == 8
+  && (foo (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__ ? 0x100 : 1)
+ != (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__ ? 1 : 0x100)))
+__builtin_abort ();
+}
diff --git a/gcc/tree-ssa.cc b/gcc/tree-ssa.cc
index 27ab9cfac823..f4fa4e98c5d0 100644
--- a/gcc/tree-ssa.cc
+++ b/gcc/tree-ssa.cc
@@ -1506,7 +1506,10 @@ maybe_rewrite_mem_ref_base (tree *tp, bitmap 
suitable_for_renaming)
}
   else if (TREE_CODE (TREE_TYPE (sym)) == COMPLEX_TYPE
   && useless_type_conversion_p (TREE_TYPE (*tp),
-TREE_TYPE (TREE_TYPE (sym
+TREE_TYPE (TREE_TYPE (sym)))
+  && (integer_zerop (TREE_OPERAND (*tp, 1))
+  || tree_int_cst_equal (TREE_OPERAND (*tp, 1),
+ TYPE_SIZE_UNIT (TREE_TYPE (*tp)
{
  *tp = build1 (integer_zerop (TREE_OPERAND (*tp, 1))
? REALPART_EXPR : IMAGPART_EXPR,


[gcc r15-2220] ssa: Fix up maybe_rewrite_mem_ref_base complex type handling [PR116034]

2024-07-23 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:b9cefd67a2a464a3c9413e6b3f28e7dc7a9ef162

commit r15-2220-gb9cefd67a2a464a3c9413e6b3f28e7dc7a9ef162
Author: Jakub Jelinek 
Date:   Tue Jul 23 10:50:29 2024 +0200

ssa: Fix up maybe_rewrite_mem_ref_base complex type handling [PR116034]

The folding into REALPART_EXPR is correct, used only when the mem_offset
is zero, but for IMAGPART_EXPR it didn't check the exact offset value (just
that it is not 0).
The following patch fixes that by using IMAGPART_EXPR only if the offset
is right and using BITFIELD_REF or whatever else otherwise.

2024-07-23  Jakub Jelinek  
Andrew Pinski  

PR tree-optimization/116034
* tree-ssa.cc (maybe_rewrite_mem_ref_base): Only use IMAGPART_EXPR
if MEM_REF offset is equal to element type size.

* gcc.dg/pr116034.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/pr116034.c | 22 ++
 gcc/tree-ssa.cc |  5 -
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/pr116034.c b/gcc/testsuite/gcc.dg/pr116034.c
new file mode 100644
index ..9a31de034246
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116034.c
@@ -0,0 +1,22 @@
+/* PR tree-optimization/116034 */
+/* { dg-do run } */
+/* { dg-options "-O1 -fno-strict-aliasing" } */
+
+int g;
+
+static inline int
+foo (_Complex unsigned short c)
+{
+  __builtin_memmove (&g, 1 + (char *) &c, 2);
+  return g;
+}
+
+int
+main ()
+{
+  if (__SIZEOF_SHORT__ == 2
+  && __CHAR_BIT__ == 8
+  && (foo (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__ ? 0x100 : 1)
+ != (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__ ? 1 : 0x100)))
+__builtin_abort ();
+}
diff --git a/gcc/tree-ssa.cc b/gcc/tree-ssa.cc
index 27ab9cfac823..f4fa4e98c5d0 100644
--- a/gcc/tree-ssa.cc
+++ b/gcc/tree-ssa.cc
@@ -1506,7 +1506,10 @@ maybe_rewrite_mem_ref_base (tree *tp, bitmap 
suitable_for_renaming)
}
   else if (TREE_CODE (TREE_TYPE (sym)) == COMPLEX_TYPE
   && useless_type_conversion_p (TREE_TYPE (*tp),
-TREE_TYPE (TREE_TYPE (sym
+TREE_TYPE (TREE_TYPE (sym)))
+  && (integer_zerop (TREE_OPERAND (*tp, 1))
+  || tree_int_cst_equal (TREE_OPERAND (*tp, 1),
+ TYPE_SIZE_UNIT (TREE_TYPE (*tp)
{
  *tp = build1 (integer_zerop (TREE_OPERAND (*tp, 1))
? REALPART_EXPR : IMAGPART_EXPR,


[gcc r15-2219] c++: Remove CHECK_CONSTR

2024-07-23 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:58756c9f5507e5db0eaddcbaaa2de7f39c34b5d0

commit r15-2219-g58756c9f5507e5db0eaddcbaaa2de7f39c34b5d0
Author: Jakub Jelinek 
Date:   Tue Jul 23 10:39:08 2024 +0200

c++: Remove CHECK_CONSTR

On Mon, Jul 22, 2024 at 11:48:51AM -0400, Patrick Palka wrote:
> FWIW this tree code seems to be a vestige of the initial Concepts TS
> implementation and is effectively unused, we can remove it outright.

Here is a patch which removes that.

2024-07-23  Jakub Jelinek  

* cp-tree.def (CHECK_CONSTR): Remove.
* cp-tree.h (CHECK_CONSTR_CONCEPT, CHECK_CONSTR_ARGS): Remove.
* cp-objcp-common.cc (cp_common_init_ts): Don't handle CHECK_CONSTR.
* tree.cc (cp_tree_equal): Likewise.
* error.cc (dump_expr): Likewise.
* cxx-pretty-print.cc (cxx_pretty_printer::expression): Likewise.
(pp_cxx_check_constraint): Remove.
(pp_cxx_constraint): Don't handle CHECK_CONSTR.

Diff:
---
 gcc/cp/cp-objcp-common.cc  |  1 -
 gcc/cp/cp-tree.def |  8 
 gcc/cp/cp-tree.h   |  8 
 gcc/cp/cxx-pretty-print.cc | 28 
 gcc/cp/error.cc|  1 -
 gcc/cp/tree.cc |  5 -
 6 files changed, 51 deletions(-)

diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc
index 86e0b49d46b8..cd379514991d 100644
--- a/gcc/cp/cp-objcp-common.cc
+++ b/gcc/cp/cp-objcp-common.cc
@@ -701,7 +701,6 @@ cp_common_init_ts (void)
   MARK_TS_EXP (UNARY_RIGHT_FOLD_EXPR);
 
   /* Constraints.  */
-  MARK_TS_EXP (CHECK_CONSTR);
   MARK_TS_EXP (COMPOUND_REQ);
   MARK_TS_EXP (CONJ_CONSTR);
   MARK_TS_EXP (DISJ_CONSTR);
diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def
index a0a47c3950fa..18f75108c7bd 100644
--- a/gcc/cp/cp-tree.def
+++ b/gcc/cp/cp-tree.def
@@ -538,14 +538,6 @@ DEFTREECODE (ATOMIC_CONSTR, "atomic_constr", 
tcc_expression, 1)
 DEFTREECODE (CONJ_CONSTR, "conj_constr", tcc_expression, 2)
 DEFTREECODE (DISJ_CONSTR, "disj_constr", tcc_expression, 2)
 
-/* A check constraint represents the checking of a concept
-   C. It has two operands: the template defining the concept
-   and a sequence of template arguments.
-
-   CHECK_CONSTR_CONCEPT has the concept definition
-   CHECK_CONSTR_ARGS are the template arguments.   */
-DEFTREECODE (CHECK_CONSTR, "check_constr", tcc_expression, 2)
-
 /* The co_await expression is used to support coroutines.
 
   Op 0 is the cast expresssion (potentially modified by the
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 609d8941cf72..76ac9c31763c 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -1723,14 +1723,6 @@ check_constraint_info (tree t)
 #define ATOMIC_CONSTR_EXPR(NODE) \
   CONSTR_EXPR (ATOMIC_CONSTR_CHECK (NODE))
 
-/* The concept of a concept check. */
-#define CHECK_CONSTR_CONCEPT(NODE) \
-  TREE_OPERAND (TREE_CHECK (NODE, CHECK_CONSTR), 0)
-
-/* The template arguments of a concept check. */
-#define CHECK_CONSTR_ARGS(NODE) \
-  TREE_OPERAND (TREE_CHECK (NODE, CHECK_CONSTR), 1)
-
 /* Whether a PARM_DECL represents a local parameter in a
requires-expression.  */
 #define CONSTRAINT_VAR_P(NODE) \
diff --git a/gcc/cp/cxx-pretty-print.cc b/gcc/cp/cxx-pretty-print.cc
index 806aebff174b..e690354e08e9 100644
--- a/gcc/cp/cxx-pretty-print.cc
+++ b/gcc/cp/cxx-pretty-print.cc
@@ -1257,7 +1257,6 @@ cxx_pretty_printer::expression (tree t)
   break;
 
 case ATOMIC_CONSTR:
-case CHECK_CONSTR:
 case CONJ_CONSTR:
 case DISJ_CONSTR:
   pp_cxx_constraint (this, t);
@@ -2815,29 +2814,6 @@ pp_cxx_nested_requirement (cxx_pretty_printer *pp, tree 
t)
   pp_cxx_semicolon (pp);
 }
 
-void
-pp_cxx_check_constraint (cxx_pretty_printer *pp, tree t)
-{
-  tree decl = CHECK_CONSTR_CONCEPT (t);
-  tree tmpl = DECL_TI_TEMPLATE (decl);
-  tree args = CHECK_CONSTR_ARGS (t);
-  tree id = build_nt (TEMPLATE_ID_EXPR, tmpl, args);
-
-  if (TREE_CODE (decl) == CONCEPT_DECL)
-pp->expression (id);
-  else if (VAR_P (decl))
-pp->expression (id);
-  else if (TREE_CODE (decl) == FUNCTION_DECL)
-{
-  tree call = build_vl_exp (CALL_EXPR, 2);
-  TREE_OPERAND (call, 0) = integer_two_node;
-  TREE_OPERAND (call, 1) = id;
-  pp->expression (call);
-}
-  else
-gcc_unreachable ();
-}
-
 /* Output the "[with ...]" clause for a parameter mapping of an atomic
constraint.   */
 
@@ -2917,10 +2893,6 @@ pp_cxx_constraint (cxx_pretty_printer *pp, tree t)
   pp_cxx_atomic_constraint (pp, t);
   break;
 
-case CHECK_CONSTR:
-  pp_cxx_check_constraint (pp, t);
-  break;
-
 case CONJ_CONSTR:
   pp_cxx_conjunction (pp, t);
   break;
diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
index 6d99cb277038..d80bac822ba2 100644
--- a/gcc/cp/error.cc
+++ b/gcc/cp/error.cc
@@ -3095,7 +3095,6 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
   break;
 
 case ATOMIC_CONSTR:
-case CHECK_CONSTR:
 case CONJ_CONSTR:
 case DISJ

[gcc r15-2206] c++: Some cp-tree.def comment fixes

2024-07-22 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:6f81b7fa799642a4bfb9912fa756285bea72ce8c

commit r15-2206-g6f81b7fa799642a4bfb9912fa756285bea72ce8c
Author: Jakub Jelinek 
Date:   Mon Jul 22 19:47:17 2024 +0200

c++: Some cp-tree.def comment fixes

While reading the fold expression and concept tree comments, I found
various spots referring to non-existent macros etc.

The following patch attempts to sync that with what is actually implemented.

2024-07-22  Jakub Jelinek  

* cp-tree.def (UNARY_LEFT_FOLD_EXPR): Use FOLD_EXPR_MODIFY_P instead
of FOLD_EXPR_MOD_P or FOLDEXPR_MOD_P in the comment.  Comment
formatting fixes.
(ATOMIC_CONSTEXPR): Use CONSTR_INFO instead of ATOMIC_CONSTR_INFO
and ATOMIC_CONSTR_MAP instead of ATOMIC_CONSTR_PARMS in the comment.
Comment formatting fixes.
(CONJ_CONSTR): Remove comment about third operand.  Use CONSTR_INFO
instead of CONJ_CONSTR_INFO and DISJ_CONSTR_INFO.
(CHECK_CONSTR): Use CHECK_CONSTR_ARGS instead of
CHECK_CONSTR_ARGUMENTS.

Diff:
---
 gcc/cp/cp-tree.def | 23 +++
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def
index 3a7ac29636da..a0a47c3950fa 100644
--- a/gcc/cp/cp-tree.def
+++ b/gcc/cp/cp-tree.def
@@ -412,17 +412,17 @@ DEFTREECODE (ARGUMENT_PACK_SELECT, 
"argument_pack_select", tcc_exceptional, 0)
 /* Fold expressions allow the expansion of a template argument pack
over a binary operator.
 
-   FOLD_EXPR_MOD_P is true when the fold operation is a compound assignment
+   FOLD_EXPR_MODIFY_P is true when the fold operation is a compound assignment
operator.
 
FOLD_EXPR_OP is an INTEGER_CST storing the tree code for the folded
-   expression. Note that when FOLDEXPR_MOD_P is true, the operator is
+   expression.  Note that when FOLD_EXPR_MODIFY_P is true, the operator is
a compound assignment operator for that kind of expression.
 
FOLD_EXPR_PACK is an expression containing an unexpanded parameter pack;
when expanded, each term becomes an argument of the folded expression.
 
-   In a BINARY_FOLD_EXPRESSION, FOLD_EXPR_INIT is the non-pack argument. */
+   In a BINARY_FOLD_EXPRESSION, FOLD_EXPR_INIT is the non-pack argument.  */
 DEFTREECODE (UNARY_LEFT_FOLD_EXPR, "unary_left_fold_expr", tcc_expression, 2)
 DEFTREECODE (UNARY_RIGHT_FOLD_EXPR, "unary_right_fold_expr", tcc_expression, 2)
 DEFTREECODE (BINARY_LEFT_FOLD_EXPR, "binary_left_fold_expr", tcc_expression, 3)
@@ -518,24 +518,23 @@ DEFTREECODE (NESTED_REQ, "nested_req", tcc_expression, 1)
 
 /* Constraints are modeled as kinds of expressions.
The operands of a constraint can be either types or expressions.
-   Unlike expressions, constraints do not have a type. */
+   Unlike expressions, constraints do not have a type.  */
 
 /* An atomic constraint evaluates an expression E. The operand of the
-   constraint is its parameter mapping. The actual expression is stored
+   constraint is its parameter mapping.  The actual expression is stored
in the context.
 
-   ATOMIC_CONSTR_INFO provides source info to support diagnostics.
+   CONSTR_INFO provides source info to support diagnostics.
ATOMIC_CONSTR_EXPR has the expression to be evaluated.
-   ATOMIC_CONSTR_PARMS is the parameter mapping for the atomic constraint
+   ATOMIC_CONSTR_MAP is the parameter mapping for the atomic constraint
and is stored in the type field.  */
 DEFTREECODE (ATOMIC_CONSTR, "atomic_constr", tcc_expression, 1)
 
 /* The conjunction and disjunction of two constraints, respectively.
-   Operands are accessed using TREE_OPERAND. The third operand provides
-   source info for diagnostics.
+   Operands are accessed using TREE_OPERAND.
 
-   CONJ_CONSTR_INFO and DISJ_CONSTR_INFO provide access to the source
-   information of constraints, which is stored in the TREE_TYPE.  */
+   CONSTR_INFO provides access to the source information of constraints,
+   which is stored in the TREE_TYPE.  */
 DEFTREECODE (CONJ_CONSTR, "conj_constr", tcc_expression, 2)
 DEFTREECODE (DISJ_CONSTR, "disj_constr", tcc_expression, 2)
 
@@ -544,7 +543,7 @@ DEFTREECODE (DISJ_CONSTR, "disj_constr", tcc_expression, 2)
and a sequence of template arguments.
 
CHECK_CONSTR_CONCEPT has the concept definition
-   CHECK_CONSTR_ARGUMENTS are the template arguments */
+   CHECK_CONSTR_ARGS are the template arguments.   */
 DEFTREECODE (CHECK_CONSTR, "check_constr", tcc_expression, 2)
 
 /* The co_await expression is used to support coroutines.


[gcc(refs/vendors/redhat/heads/gcc-11-branch)] Merge commit 'r11-11584-g5cc4c42a0d4de08715c2eef8715ad5b2e92a23b6' into redhat/gcc-11-branch

2024-07-19 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:a985e3068a6f8045f8a6f2d2d5ae75f5eb0a8767

commit a985e3068a6f8045f8a6f2d2d5ae75f5eb0a8767
Merge: 9e6808abff4d 5cc4c42a0d4d
Author: Jakub Jelinek 
Date:   Fri Jul 19 09:22:05 2024 +0200

Merge commit 'r11-11584-g5cc4c42a0d4de08715c2eef8715ad5b2e92a23b6' into 
redhat/gcc-11-branch

Diff:

 ChangeLog  |4 +
 c++tools/ChangeLog |4 +
 config/ChangeLog   |4 +
 contrib/ChangeLog  |4 +
 contrib/header-tools/ChangeLog |4 +
 contrib/reghunt/ChangeLog  |4 +
 contrib/regression/ChangeLog   |4 +
 fixincludes/ChangeLog  |   23 +
 fixincludes/fixincl.x  |   53 +-
 fixincludes/inclhack.def   |   12 +
 fixincludes/tests/base/math.h  |6 +
 gcc/BASE-VER   |2 +-
 gcc/ChangeLog  | 1171 
 gcc/DATESTAMP  |2 +-
 gcc/ada/ChangeLog  |   27 +
 gcc/ada/exp_ch4.adb|2 -
 gcc/ada/exp_ch7.adb|   13 +
 gcc/ada/exp_util.adb   |   15 +-
 gcc/ada/gcc-interface/Makefile.in  |4 +-
 gcc/ada/sem_res.adb|   14 +-
 gcc/analyzer/ChangeLog |4 +
 gcc/asan.c |   41 +-
 gcc/attribs.c  |   22 +-
 gcc/bb-reorder.c   |3 +-
 gcc/brig/ChangeLog |4 +
 gcc/builtins.c |   16 +-
 gcc/c-family/ChangeLog |   56 +
 gcc/c-family/c-attribs.c   |   32 +-
 gcc/c-family/c-common.c|7 +-
 gcc/c-family/c-lex.c   |   33 +-
 gcc/c-family/c-opts.c  |4 +-
 gcc/c-family/c-pch.c   |5 +-
 gcc/c/ChangeLog|   14 +
 gcc/c/c-decl.c |   15 +
 gcc/cfgexpand.c|   32 +-
 gcc/cfgrtl.c   |   24 +-
 gcc/cfgrtl.h   |1 +
 gcc/cgraph.h   |9 +-
 gcc/cgraphunit.c   |2 +
 gcc/combine.c  |6 +-
 gcc/common/config/i386/cpuinfo.h   |   16 +-
 gcc/common/config/i386/i386-common.c   |   35 +-
 gcc/common/config/i386/i386-cpuinfo.h  |1 +
 gcc/config.gcc |   10 +-
 gcc/config.in  |   12 +
 gcc/config/aarch64/aarch64-c.c |5 +
 gcc/config/aarch64/aarch64-cores.def   |2 +
 gcc/config/aarch64/aarch64-tune.md |2 +-
 gcc/config/aarch64/aarch64.c   |   33 +-
 gcc/config/aarch64/aarch64.md  |   35 +-
 gcc/config/aarch64/arm_neon.h  |  469 +---
 gcc/config/aarch64/iterators.md|3 +
 gcc/config/alpha/alpha.md  |   21 +-
 gcc/config/alpha/constraints.md|2 +-
 gcc/config/arm/arm.c   |  129 +++
 gcc/config/arm/mve.md  |2 +-
 gcc/config/arm/neon.md |4 +-
 gcc/config/darwin-protos.h |   11 +
 gcc/config/darwin-sections.def |4 +-
 gcc/config/darwin.c|  223 +++-
 gcc/config/darwin.h|   77 +-
 gcc/config/darwin.opt  |4 +
 gcc/config/i386/amxtileintrin.h|4 +-
 gcc/config/i386/driver-i386.c  |5 +
 gcc/config/i386/i386-builtin.def   |4 +
 gcc/config/i386/i386-c.c   |7 +
 gcc/config/i386/i386-expand.c  |   38 +
 gcc/config/i386/i386-options.c |   10 +-
 gcc/config/i386/i386.c |   75 +-
 gcc/config/i386/i386.h |   18 +
 gcc/config/i386/i386.md|   29 +-
 gcc/config/i386/mmx.md |5 +-
 gcc/config/i386/x86-tune-costs.h   |  134 +++
 gcc/config/i386/x86-tune-sched.c   |2 +
 gcc/config/i386/x86-tune.def   |   12 +-
 gcc/config/i386/{znver1.md => znver.md}

[gcc/redhat/heads/gcc-11-branch] (428 commits) Merge commit 'r11-11584-g5cc4c42a0d4de08715c2eef8715ad5b2e9

2024-07-19 Thread Jakub Jelinek via Gcc-cvs
The branch 'redhat/heads/gcc-11-branch' was updated to point to:

 a985e3068a6f... Merge commit 'r11-11584-g5cc4c42a0d4de08715c2eef8715ad5b2e9

It previously pointed to:

 9e6808abff4d... Merge commit 'r11-11157-gbacfe9e21fefc68de46ba62fd4498b98f5

Diff:

Summary of changes (added commits):
---

  a985e30... Merge commit 'r11-11584-g5cc4c42a0d4de08715c2eef8715ad5b2e9
  5cc4c42... Update ChangeLog and version files for release (*)
  a8de69b... Daily bump. (*)
  39f89e0... testsuite: Fix up builtin-clear-padding-3.c for -funsigned- (*)
  f443de1... Daily bump. (*)
  3eec2d7... gimple-fold: Fix up __builtin_clear_padding lowering [PR115 (*)
  a31ac7b... Daily bump. (*)
  bcb2a35... Fixup unaligned load/store cost for znver4 (*)
  90c53dc... Daily bump. (*)
  232a2a6... Daily bump. (*)
  bfd6710... Daily bump. (*)
  a5c5418... Daily bump. (*)
  30ffca5... libstdc++: Add missing exports for ppc64le --with-long-doub (*)
  3916b88... Daily bump. (*)
  1e0d60c... libstdc++: Reverse arguments in constraint for std::optiona (*)
  f75f982... mve: Fix vsetq_lane for 64-bit elements with lane 1 [PR 115 (*)
  1fc7fc7... Daily bump. (*)
  d67566c... middle-end: Fix stalled swapped condition code value [PR115 (*)
  69ce8e4... libstdc++: Destroy allocators in re-inserted container node (*)
  7a6a436... Daily bump. (*)
  ee69d6e... aarch64: PR target/115475 Implement missing __ARM_FEATURE_S (*)
  d32cfe3... aarch64: PR target/115457 Implement missing __ARM_FEATURE_B (*)
  c98bd71... Daily bump. (*)
  c2c216d... c++: Add testcase for this PR [PR97990] (*)
  e787939... middle-end/112732 - stray TYPE_ALIAS_SET in type variant (*)
  77cc621... Daily bump. (*)
  43bc354... Daily bump. (*)
  0fd3669... Daily bump. (*)
  9df0997... Daily bump. (*)
  5f2b94f... Daily bump. (*)
  ce71301... hppa: Fix ICE caused by mismatched predicate and constraint (*)
  2c8c0b3... Daily bump. (*)
  3e299e4... Daily bump. (*)
  33880e4... Daily bump. (*)
  cff23ee... Daily bump. (*)
  378f50f... libcc1: fix  include (*)
  5a419c2... Include safe-ctype.h after C++ standard headers, to avoid o (*)
  d08739d... Ada, Darwin : Use DSYMUTIL_FOR_TARGET in libgnat/gnarl buil (*)
  834a5eb... Daily bump. (*)
  95dd793... Daily bump. (*)
  6e33ffd... libstdc++: fix typo in acinclude.m4. (*)
  f4cdbf1... c++, coroutines: Improve check for throwing final await [PR (*)
  1d57792... coroutines: Fail with a sorry when presented with a VLA [PR (*)
  f647906... coroutines: Pass lvalues to user-defined operator new [PR 1 (*)
  57482ca... coroutines: Await expressions are not allowed in handlers [ (*)
  bb94360... Add support for -mcpu=grace (*)
  9286341... Daily bump. (*)
  b8af813... Daily bump. (*)
  7d60b93... libstdc++: Replace reference to mainline in release branch  (*)
  bd4ce2d... Daily bump. (*)
  5497016... rs6000: Don't clobber return value when eh_return called [P (*)
  40e8a65... Daily bump. (*)
  35d173f... Daily bump. (*)
  7429b52... Daily bump. (*)
  87cda03... libstdc++: Fix test on x86_64 and non-simd targets (*)
  0d0f181... middle-end/110176 - wrong zext (bool) <= (int) 4294967295u  (*)
  8d7ff01... tree-optimization/111070 - fix ICE with recent ifcombine fi (*)
  bae5dcf... tree-optimization/111039 - abnormals and bit test merging (*)
  80ded4e... debug/111080 - avoid outputting debug info for unused restr (*)
  ce653fa... tree-optimization/111445 - simple_iv simplification fault (*)
  20fe647... tree-optimization/112495 - alias versioning and address spa (*)
  ffaa61e... tree-optimization/112505 - bit-precision induction vectoriz (*)
  33e6997... debug/112718 - reset all type units with -ffat-lto-objects (*)
  7e4dedb... tree-optimization/112793 - SLP of constant/external code-ge (*)
  70ebb2e... tree-optimization/114027 - fix testcase (*)
  b6a0292... tree-optimization/114027 - conditional reduction chain (*)
  a43c9be... middle-end/114734 - wrong code with expand_call_mem_ref (*)
  dae4d8e... Daily bump. (*)
  a0b92a5... libstdc++: Fix find_last_set(simd_mask) to ignore padding b (*)
  a0dac8f... diagnostics: Fix add_misspelling_candidates [PR115440] (*)
  5736bc0... c: Fix up pointer types to may_alias structures [PR114493] (*)
  b724525... fold-const: Fix up CLZ handling in tree_call_nonnegative_wa (*)
  2922060... builtins: Force SAVE_EXPR for __builtin_{add,sub,mul}_overf (*)
  82bb4ee... combine: Fix up simplify_compare_const [PR115092] (*)
  e4bd955... tree-inline: Remove .ASAN_MARK calls when inlining function (*)
  6bb5036... gimple-ssa-sprintf: Use [0, 1] range for %lc with (wint_t)  (*)
  0ff2aad... openmp: Copy DECL_LANG_SPECIFIC and DECL_LANG_FLAG_? to tre (*)
  1fc4a91... rtlanal: Fix set_noop_p for volatile loads or stores [PR114 (*)
  2e93226... internal-fn: Temporarily disable flag_trapv during .{ADD,SU (*)
  139f129... attribs: Don't crash on NULL TREE_TYPE in diag_attr_exclusi (*)
  6ec50f5... c++: Fix bogus warnings about ignored annotations [PR114691 (*)
  043d5fc... asan, v3: Fix up handl

[gcc r15-2152] c++: Add [dcl.init.aggr] examples to testsuite

2024-07-18 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:cea6473e48b4cfbf16f7b4a804f1562f8da8f25b

commit r15-2152-gcea6473e48b4cfbf16f7b4a804f1562f8da8f25b
Author: Jakub Jelinek 
Date:   Fri Jul 19 08:53:47 2024 +0200

c++: Add [dcl.init.aggr] examples to testsuite

When working on the #embed optimization support, I went recently through
all of reshape_init_r* and today I read in detail all the P3106R1 changes
and I believe we implement it that way for years.
To double check that, I've added tests with the current [dcl.init.aggr]
examples but tested in all the languages from C++98 to C++26, of course
guarded as needed for constructs which require newer versions of C++.
The examples come in two tests, one is a runtime test for the non-erroneous
examples, the other is a compile time test for the diagnostics.
The former one includes mostly intact examples with runtime checking (both
to test what is written in the section exactly and to test at least
something with C++98) and then when useful also adds constexpr tests with
static_asserts for C++11 and later.

Tested on x86_64-linux and i686-linux with
GXX_TESTSUITE_STDS=98,11,14,17,20,23,26 make check-g++ 
RUNTESTFLAGS='dg.exp=aggr-init*.C'

Also tested on GCC 11 branch with
GXX_TESTSUITE_STDS=98,11,14,17,20,2b make check-g++ 
RUNTESTFLAGS='dg.exp=aggr-init*.C'
where just the " is a GCC extension" part of one error is left out,
otherwise it passes the same, ditto with clang 14 (of course with different
diagnostics, but verified it emits diagnostics on the right lines), so I
believe we can claim implementation of this DR paper, either in all versions
or at least in GCC 11+.

2024-07-19  Jakub Jelinek  

PR c++/114460
* g++.dg/cpp26/aggr-init1.C: New test.
* g++.dg/cpp26/aggr-init2.C: New test.

Diff:
---
 gcc/testsuite/g++.dg/cpp26/aggr-init1.C | 341 
 gcc/testsuite/g++.dg/cpp26/aggr-init2.C |  67 +++
 2 files changed, 408 insertions(+)

diff --git a/gcc/testsuite/g++.dg/cpp26/aggr-init1.C 
b/gcc/testsuite/g++.dg/cpp26/aggr-init1.C
new file mode 100644
index ..a692462caf69
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp26/aggr-init1.C
@@ -0,0 +1,341 @@
+// P3106R1 - Clarifying rules for brace elision in aggregate initialization
+// Examples from C++26 [dcl.init.aggr]
+// { dg-do run }
+
+extern "C" void abort ();
+
+namespace N1 {
+#if __cpp_designated_initializers >= 201707L
+  struct C {
+union {
+  int a;
+  const char* p;
+};
+int x;
+  } c = { .a = 1, .x = 3 };
+  constexpr C c2 = { .a = 1, .x = 3 };
+  static_assert (c2.a == 1 && c2.x == 3, "");
+#endif
+
+  bool
+  test ()
+  {
+#if __cpp_designated_initializers >= 201707L
+return c.a == 1 && c.x == 3;
+#else
+return true;
+#endif
+  }
+}
+
+namespace N2 {
+  struct A {
+int x;
+struct B {
+  int i;
+  int j;
+} b;
+  } a = { 1, { 2, 3 } };
+
+#if __cplusplus >= 201703L
+  struct base1 { int b1, b2 = 42; };
+  struct base2 {
+base2 () { b3 = 42; }
+int b3;
+  };
+  struct derived : base1, base2 {
+int d;
+  };
+
+  derived d1 { { 1, 2 }, {}, 4 };
+  derived d2 { {}, {}, 4 };
+#endif
+
+  bool
+  test ()
+  {
+return a.x == 1 && a.b.i == 2 && a.b.j == 3
+#if __cplusplus >= 201703L
+  && d1.b1 == 1 && d1.b2 == 2 && d1.b3 == 42 && d1.d == 4
+  && d2.b1 == 0 && d2.b2 == 42 && d2.b3 == 42 && d2.d == 4
+#endif
+  ;
+  }
+
+#if __cplusplus >= 201703L
+  constexpr A a2 = { 1, { 2, 3 } };
+  static_assert (a2.x == 1 && a2.b.i == 2 && a2.b.j == 3, "");
+
+  struct base3 {
+#if __cplusplus >= 202002L
+constexpr base3 () { b3 = 42; }
+#else
+constexpr base3 () : b3 (42) {}
+#endif
+int b3;
+  };
+  struct derived2 : base1, base3 {
+int d;
+  };
+  constexpr derived2 d3 { { 1, 2}, {}, 4};
+  constexpr derived2 d4 { {}, {}, 4 };
+  static_assert (d3.b1 == 1 && d3.b2 == 2 && d3.b3 == 42 && d3.d == 4, "");
+  static_assert (d4.b1 == 0 && d4.b2 == 42 && d4.b3 == 42 && d4.d == 4, "");
+#endif
+}
+
+namespace N3 {
+#if __cplusplus >= 201402L
+  struct S { int a; const char *b; int c; int d = b[a]; };
+  S ss = { 1, "asdf" };
+  constexpr S ss2 = { 1, "asdf" };
+  static_assert (ss2.a == 1 && ss2.b[0] == 'a' && ss2.b[3] == 'f' && ss2.c == 
0 && ss2.d == 's', "");
+
+#if __cpp_designated_initializers >= 201707L
+  struct string { int s = -42; };
+  struct A {
+string a;
+int b = 42;
+int c = -1;
+  };
+  static_assert (A { .c = 21 }.a.s == -42 && A { .c = 21 }.b == 42 && A { .c = 
21 }.c == 21, "");
+#endif
+#endif
+
+  bool
+  test ()
+  {
+#if __cplusplus >= 201402L
+return ss.a == 1 && __builtin_strcmp (ss.b, "asdf") == 0 && ss.c == 0 && 
ss.d == 's';
+#else
+return true;
+#endif
+  }
+}
+
+namespace N4 {
+  int x[] = { 1, 3, 5 };
+
+  bool
+  test ()
+  {
+return sizeof (x) == 3 * sizeof (int) && x[0] == 1 && x[1] == 3 && x[2] == 
5;
+  }

[gcc r11-11582] testsuite: Fix up builtin-clear-padding-3.c for -funsigned-char

2024-07-18 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:39f89e0daf6933fc888b79aa15f358b145c212ee

commit r11-11582-g39f89e0daf6933fc888b79aa15f358b145c212ee
Author: Jakub Jelinek 
Date:   Thu Jul 18 09:22:10 2024 +0200

testsuite: Fix up builtin-clear-padding-3.c for -funsigned-char

As reported on gcc-regression, this test FAILs on aarch64, but my
r15-2090 change didn't change anything on the generated assembly,
just added the forgotten dg-do run directive to the test, so the
test has been failing forever, just we didn't know it.

I can actually reproduce it on x86_64 with -funsigned-char too,
s2.b.a has int type and -1 is stored to it, so we should compare
it against -1 rather than (char) -1; the latter is appropriate for
testing char fields into which we've stored -1.

2024-07-18  Jakub Jelinek  

* c-c++-common/torture/builtin-clear-padding-3.c (main): Compare
s2.b.a against -1 rather than (char) -1.

(cherry picked from commit 958ee138748fae4371e453eb9b357f576abbe83e)

Diff:
---
 gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c 
b/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
index 27bf8f6dd734..2c673169e134 100644
--- a/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
+++ b/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
@@ -34,7 +34,7 @@ main ()
   foo (&s1, 0);
   foo (&s2, 0);
   __builtin_clear_padding (&s2);
-  if (s2.b.a != (char) -1)
+  if (s2.b.a != -1)
 __builtin_abort ();
   __builtin_clear_padding (&s2.b.a);
   __builtin_memset (&s2.b.a + 1, 0, sizeof (union U) - sizeof (s2.b.a));


[gcc r15-2136] testsuite: Add dg-do run to more tests

2024-07-18 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:e217e7dbdc1040e7ee160796e9ca1ef12a0dd1cb

commit r15-2136-ge217e7dbdc1040e7ee160796e9ca1ef12a0dd1cb
Author: Sam James 
Date:   Thu Jul 18 10:00:17 2024 +0200

testsuite: Add dg-do run to more tests

All of these are for wrong-code bugs.  Confirmed to be used before but
with no execution.

2024-07-18  Sam James  

PR c++/53288
PR c++/57437
PR c/65345
PR libstdc++/88101
PR tree-optimization/96369
PR tree-optimization/102124
PR tree-optimization/108692
* c-c++-common/pr96369.c: Add dg-do run directive.
* gcc.dg/torture/pr102124.c: Ditto.
* gcc.dg/pr108692.c: Ditto.
* gcc.dg/atomic/pr65345-4.c: Ditto.
* g++.dg/cpp0x/lambda/lambda-return1.C: Ditto.
* g++.dg/init/lifetime4.C: Ditto.
* g++.dg/torture/builtin-clear-padding-1.C: Ditto.
* g++.dg/torture/builtin-clear-padding-2.C: Ditto.
* g++.dg/torture/builtin-clear-padding-3.C: Ditto.
* g++.dg/torture/builtin-clear-padding-4.C: Ditto.
* g++.dg/torture/builtin-clear-padding-5.C: Ditto.

Diff:
---
 gcc/testsuite/c-c++-common/pr96369.c   | 2 +-
 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-return1.C | 1 +
 gcc/testsuite/g++.dg/init/lifetime4.C  | 2 +-
 gcc/testsuite/g++.dg/torture/builtin-clear-padding-1.C | 1 +
 gcc/testsuite/g++.dg/torture/builtin-clear-padding-2.C | 1 +
 gcc/testsuite/g++.dg/torture/builtin-clear-padding-3.C | 1 +
 gcc/testsuite/g++.dg/torture/builtin-clear-padding-4.C | 1 +
 gcc/testsuite/g++.dg/torture/builtin-clear-padding-5.C | 1 +
 gcc/testsuite/gcc.dg/atomic/pr65345-4.c| 1 +
 gcc/testsuite/gcc.dg/pr108692.c| 2 +-
 gcc/testsuite/gcc.dg/torture/pr102124.c| 1 +
 11 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/pr96369.c 
b/gcc/testsuite/c-c++-common/pr96369.c
index 8c468d9fec2f..ec58a3fc6c92 100644
--- a/gcc/testsuite/c-c++-common/pr96369.c
+++ b/gcc/testsuite/c-c++-common/pr96369.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O" } */
 
 int main()
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-return1.C 
b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-return1.C
index 4b353b64c37e..df533e9a87cc 100644
--- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-return1.C
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-return1.C
@@ -1,4 +1,5 @@
 // PR c++/57437
+// { dg-do run } */
 // { dg-require-effective-target c++11 }
 
 struct A {
diff --git a/gcc/testsuite/g++.dg/init/lifetime4.C 
b/gcc/testsuite/g++.dg/init/lifetime4.C
index 4106af7070cc..3e4825fff52f 100644
--- a/gcc/testsuite/g++.dg/init/lifetime4.C
+++ b/gcc/testsuite/g++.dg/init/lifetime4.C
@@ -1,5 +1,5 @@
 // PR c++/53288
-// { dg-do compile { target c++11 } }
+// { dg-do run { target c++11 } }
 
 struct B {
B(int data) : _data(data) { }
diff --git a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-1.C 
b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-1.C
index 625a047ab1c7..f62dedc6fa6d 100644
--- a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-1.C
+++ b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-1.C
@@ -1,4 +1,5 @@
 /* PR libstdc++/88101 */
+/* { dg-do run } */
 
 struct S {} s1, s2;
 struct T : public S { char a; short b; char c; } t1, t2;
diff --git a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-2.C 
b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-2.C
index 19cc78f66104..3cb55cff8d3e 100644
--- a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-2.C
+++ b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-2.C
@@ -1,4 +1,5 @@
 /* PR libstdc++/88101 */
+/* { dg-do run } */
 
 #include 
 
diff --git a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-3.C 
b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-3.C
index d528196bf2dc..fe81e095e082 100644
--- a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-3.C
+++ b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-3.C
@@ -1,4 +1,5 @@
 /* PR libstdc++/88101 */
+/* { dg-do run } */
 
 struct D { int a; int : 24; int b : 8; };
 struct E {};
diff --git a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-4.C 
b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-4.C
index 5936cdf876b2..88bd6bac65ec 100644
--- a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-4.C
+++ b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-4.C
@@ -1,4 +1,5 @@
 // PR middle-end/101586
+// { dg-do run }
 
 struct A { char a; };
 struct B : virtual A {};
diff --git a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-5.C 
b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-5.C
index b5f019147816..0795011077aa 100644
--- a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-5.C
+++ b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-5.C
@@ -1,4 +1,5 @@
 // PR tree-optimization/102586
+// { dg-do run }
 // { d

[gcc r14-10454] testsuite: Fix up builtin-clear-padding-3.c for -funsigned-char

2024-07-18 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:0fbad21b0705f748076a715d0b756996f4cadcc8

commit r14-10454-g0fbad21b0705f748076a715d0b756996f4cadcc8
Author: Jakub Jelinek 
Date:   Thu Jul 18 09:22:10 2024 +0200

testsuite: Fix up builtin-clear-padding-3.c for -funsigned-char

As reported on gcc-regression, this test FAILs on aarch64, but my
r15-2090 change didn't change anything on the generated assembly,
just added the forgotten dg-do run directive to the test, so the
test has been failing forever, just we didn't know it.

I can actually reproduce it on x86_64 with -funsigned-char too,
s2.b.a has int type and -1 is stored to it, so we should compare
it against -1 rather than (char) -1; the latter is appropriate for
testing char fields into which we've stored -1.

2024-07-18  Jakub Jelinek  

* c-c++-common/torture/builtin-clear-padding-3.c (main): Compare
s2.b.a against -1 rather than (char) -1.

(cherry picked from commit 958ee138748fae4371e453eb9b357f576abbe83e)

Diff:
---
 gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c 
b/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
index 27bf8f6dd734..2c673169e134 100644
--- a/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
+++ b/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
@@ -34,7 +34,7 @@ main ()
   foo (&s1, 0);
   foo (&s2, 0);
   __builtin_clear_padding (&s2);
-  if (s2.b.a != (char) -1)
+  if (s2.b.a != -1)
 __builtin_abort ();
   __builtin_clear_padding (&s2.b.a);
   __builtin_memset (&s2.b.a + 1, 0, sizeof (union U) - sizeof (s2.b.a));


  1   2   3   4   5   >