[Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110580

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||accepts-invalid

--- Comment #6 from Andrew Pinski  ---
yes my theory is correct and becomes obvious with the error message for:
```

struct s0 {};
struct s1 {};
struct s2 {};
template 
struct t;
template  
struct s3 {
  template 
  static constexpr bool __usable_key = t<_Vp>::v;
  static_assert(__usable_key);
  static_assert(__usable_key);
};
s3 t2;
```
Error message:
```
: In instantiation of 'constexpr const bool s3::__usable_key':
...
: In instantiation of 'constexpr const bool s3::__usable_key':
```
s2 there is definitely incorrect

Re: [PATCH v2 1/2] c++, libstdc++: implement __is_pointer built-in trait

2023-07-09 Thread Ken Matsui via Gcc-patches
Hi,

Here is the benchmark result for is_pointer:

https://github.com/ken-matsui/gcc-benches/blob/main/is_pointer.md#sun-jul--9-103948-pm-pdt-2023

Time: -62.1344%
Peak Memory Usage: -52.4281%
Total Memory Usage: -53.5889%

Sincerely,
Ken Matsui

On Sun, Jul 9, 2023 at 10:38 PM Ken Matsui  wrote:
>
> This patch implements built-in trait for std::is_pointer.
>
> gcc/cp/ChangeLog:
>
> * cp-trait.def: Define __is_pointer.
> * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_POINTER.
> * semantics.cc (trait_expr_value): Likewise.
> (finish_trait_expr): Likewise.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/ext/has-builtin-1.C: Test existence of __is_pointer.
> * g++.dg/ext/is_pointer.C: New test.
> * g++.dg/tm/pr46567.C (__is_pointer): Rename to ...
> (is_pointer): ... this.
> * g++.dg/torture/20070621-1.C: Likewise.
> * g++.dg/torture/pr57107.C: Likewise.
>
> libstdc++-v3/ChangeLog:
>
> * include/bits/cpp_type_traits.h (__is_pointer): Rename to ...
> (is_pointer): ... this.
> * include/bits/deque.tcc: Use is_pointer instead.
> * include/bits/stl_algobase.h: Likewise.
>
> Signed-off-by: Ken Matsui 
> ---
>  gcc/cp/constraint.cc|  3 ++
>  gcc/cp/cp-trait.def |  1 +
>  gcc/cp/semantics.cc |  4 ++
>  gcc/testsuite/g++.dg/ext/has-builtin-1.C|  3 ++
>  gcc/testsuite/g++.dg/ext/is_pointer.C   | 51 +
>  gcc/testsuite/g++.dg/tm/pr46567.C   | 22 -
>  gcc/testsuite/g++.dg/torture/20070621-1.C   |  4 +-
>  gcc/testsuite/g++.dg/torture/pr57107.C  |  4 +-
>  libstdc++-v3/include/bits/cpp_type_traits.h |  6 +--
>  libstdc++-v3/include/bits/deque.tcc |  6 +--
>  libstdc++-v3/include/bits/stl_algobase.h|  6 +--
>  11 files changed, 86 insertions(+), 24 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C
>
> diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
> index 8cf0f2d0974..30266204eb5 100644
> --- a/gcc/cp/constraint.cc
> +++ b/gcc/cp/constraint.cc
> @@ -3751,6 +3751,9 @@ diagnose_trait_expr (tree expr, tree args)
>  case CPTK_IS_UNION:
>inform (loc, "  %qT is not a union", t1);
>break;
> +case CPTK_IS_POINTER:
> +  inform (loc, "  %qT is not a pointer", t1);
> +  break;
>  case CPTK_IS_AGGREGATE:
>inform (loc, "  %qT is not an aggregate", t1);
>break;
> diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
> index 8b7fece0cc8..b7c263e9a77 100644
> --- a/gcc/cp/cp-trait.def
> +++ b/gcc/cp/cp-trait.def
> @@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, 
> "__is_trivially_assignable", 2)
>  DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", 
> -1)
>  DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
>  DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
> +DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1)
>  DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, 
> "__reference_constructs_from_temporary", 2)
>  DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, 
> "__reference_converts_from_temporary", 2)
>  /* FIXME Added space to avoid direct usage in GCC 13.  */
> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
> index 8fb47fd179e..68f8a4fe85b 100644
> --- a/gcc/cp/semantics.cc
> +++ b/gcc/cp/semantics.cc
> @@ -12118,6 +12118,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, 
> tree type2)
>  case CPTK_IS_UNION:
>return type_code1 == UNION_TYPE;
>
> +case CPTK_IS_POINTER:
> +  return TYPE_PTR_P (type1);
> +
>  case CPTK_IS_ASSIGNABLE:
>return is_xible (MODIFY_EXPR, type1, type2);
>
> @@ -12296,6 +12299,7 @@ finish_trait_expr (location_t loc, cp_trait_kind 
> kind, tree type1, tree type2)
>  case CPTK_IS_ENUM:
>  case CPTK_IS_UNION:
>  case CPTK_IS_SAME:
> +case CPTK_IS_POINTER:
>break;
>
>  case CPTK_IS_LAYOUT_COMPATIBLE:
> diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C 
> b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> index f343e153e56..9dace5cbd48 100644
> --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> @@ -146,3 +146,6 @@
>  #if !__has_builtin (__remove_cvref)
>  # error "__has_builtin (__remove_cvref) failed"
>  #endif
> +#if !__has_builtin (__is_pointer)
> +# error "__has_builtin (__is_pointer) failed"
> +#endif
> diff --git a/gcc/testsuite/g++.dg/ext/is_pointer.C 
> b/gcc/testsuite/g++.dg/ext/is_pointer.C
> new file mode 100644
> index 000..d6e39565950
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/ext/is_pointer.C
> @@ -0,0 +1,51 @@
> +// { dg-do compile { target c++11 } }
> +
> +#define SA(X) static_assert((X),#X)
> +
> +SA(!__is_pointer(int));
> +SA(__is_pointer(int*));
> +SA(__is_pointer(int**));
> +
> +SA(__is_pointer(const int*));
> +SA(__is_pointer(const int**));
> +SA(__is_pointer(int* const));
> +SA(__is_pointer(int** 

[Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110580

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||wrong-code

--- Comment #5 from Andrew Pinski  ---
Here is another testcase:
```
struct s0 {};
struct s1 {};
template 
struct t
{
static constexpr bool v = false;
};
template<>
struct t
{
static constexpr bool v = true;
};
template  
struct s3 {
  template 
  static constexpr bool __usable_key = t<_Vp>::v;
  static_assert(__usable_key);
  static_assert(!__usable_key);
};
s3 t2;
```

I get the feeling _Up in the default template argument of __usable_key  is
being replaced with _Key template argument for some reason.

[PATCH v2 2/2] libstdc++: use new built-in trait __is_pointer

2023-07-09 Thread Ken Matsui via Gcc-patches
This patch lets libstdc++ use new built-in trait __is_pointer.

libstdc++-v3/ChangeLog:

* include/std/type_traits (is_pointer): Use __is_pointer
built-in trait.
(is_pointer_v): Likewise.

Signed-off-by: Ken Matsui 
---
 libstdc++-v3/include/std/type_traits | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index 0e7a9c9c7f3..b8291a31d3e 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -515,6 +515,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 struct is_array<_Tp[]>
 : public true_type { };
 
+  /// is_pointer
+#if __has_builtin(__is_pointer)
+  template
+struct is_pointer
+: public __bool_constant<__is_pointer(_Tp)>
+{ };
+#else
   template
 struct __is_pointer_helper
 : public false_type { };
@@ -523,11 +530,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 struct __is_pointer_helper<_Tp*>
 : public true_type { };
 
-  /// is_pointer
   template
 struct is_pointer
 : public __is_pointer_helper<__remove_cv_t<_Tp>>::type
 { };
+#endif
 
   /// is_lvalue_reference
   template
@@ -3168,8 +3175,14 @@ template 
 template 
   inline constexpr bool is_array_v<_Tp[_Num]> = true;
 
+#if __has_builtin(__is_pointer)
+template 
+  inline constexpr bool is_pointer_v = __is_pointer(_Tp);
+#else
 template 
   inline constexpr bool is_pointer_v = is_pointer<_Tp>::value;
+#endif
+
 template 
   inline constexpr bool is_lvalue_reference_v = false;
 template 
-- 
2.41.0



[PATCH v2 1/2] c++, libstdc++: implement __is_pointer built-in trait

2023-07-09 Thread Ken Matsui via Gcc-patches
This patch implements built-in trait for std::is_pointer.

gcc/cp/ChangeLog:

* cp-trait.def: Define __is_pointer.
* constraint.cc (diagnose_trait_expr): Handle CPTK_IS_POINTER.
* semantics.cc (trait_expr_value): Likewise.
(finish_trait_expr): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/ext/has-builtin-1.C: Test existence of __is_pointer.
* g++.dg/ext/is_pointer.C: New test.
* g++.dg/tm/pr46567.C (__is_pointer): Rename to ...
(is_pointer): ... this.
* g++.dg/torture/20070621-1.C: Likewise.
* g++.dg/torture/pr57107.C: Likewise.

libstdc++-v3/ChangeLog:

* include/bits/cpp_type_traits.h (__is_pointer): Rename to ...
(is_pointer): ... this.
* include/bits/deque.tcc: Use is_pointer instead.
* include/bits/stl_algobase.h: Likewise.

Signed-off-by: Ken Matsui 
---
 gcc/cp/constraint.cc|  3 ++
 gcc/cp/cp-trait.def |  1 +
 gcc/cp/semantics.cc |  4 ++
 gcc/testsuite/g++.dg/ext/has-builtin-1.C|  3 ++
 gcc/testsuite/g++.dg/ext/is_pointer.C   | 51 +
 gcc/testsuite/g++.dg/tm/pr46567.C   | 22 -
 gcc/testsuite/g++.dg/torture/20070621-1.C   |  4 +-
 gcc/testsuite/g++.dg/torture/pr57107.C  |  4 +-
 libstdc++-v3/include/bits/cpp_type_traits.h |  6 +--
 libstdc++-v3/include/bits/deque.tcc |  6 +--
 libstdc++-v3/include/bits/stl_algobase.h|  6 +--
 11 files changed, 86 insertions(+), 24 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 8cf0f2d0974..30266204eb5 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3751,6 +3751,9 @@ diagnose_trait_expr (tree expr, tree args)
 case CPTK_IS_UNION:
   inform (loc, "  %qT is not a union", t1);
   break;
+case CPTK_IS_POINTER:
+  inform (loc, "  %qT is not a pointer", t1);
+  break;
 case CPTK_IS_AGGREGATE:
   inform (loc, "  %qT is not an aggregate", t1);
   break;
diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
index 8b7fece0cc8..b7c263e9a77 100644
--- a/gcc/cp/cp-trait.def
+++ b/gcc/cp/cp-trait.def
@@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, 
"__is_trivially_assignable", 2)
 DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1)
 DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
 DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
+DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1)
 DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, 
"__reference_constructs_from_temporary", 2)
 DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, 
"__reference_converts_from_temporary", 2)
 /* FIXME Added space to avoid direct usage in GCC 13.  */
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 8fb47fd179e..68f8a4fe85b 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12118,6 +12118,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree 
type2)
 case CPTK_IS_UNION:
   return type_code1 == UNION_TYPE;
 
+case CPTK_IS_POINTER:
+  return TYPE_PTR_P (type1);
+
 case CPTK_IS_ASSIGNABLE:
   return is_xible (MODIFY_EXPR, type1, type2);
 
@@ -12296,6 +12299,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, 
tree type1, tree type2)
 case CPTK_IS_ENUM:
 case CPTK_IS_UNION:
 case CPTK_IS_SAME:
+case CPTK_IS_POINTER:
   break;
 
 case CPTK_IS_LAYOUT_COMPATIBLE:
diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C 
b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
index f343e153e56..9dace5cbd48 100644
--- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
+++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
@@ -146,3 +146,6 @@
 #if !__has_builtin (__remove_cvref)
 # error "__has_builtin (__remove_cvref) failed"
 #endif
+#if !__has_builtin (__is_pointer)
+# error "__has_builtin (__is_pointer) failed"
+#endif
diff --git a/gcc/testsuite/g++.dg/ext/is_pointer.C 
b/gcc/testsuite/g++.dg/ext/is_pointer.C
new file mode 100644
index 000..d6e39565950
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_pointer.C
@@ -0,0 +1,51 @@
+// { dg-do compile { target c++11 } }
+
+#define SA(X) static_assert((X),#X)
+
+SA(!__is_pointer(int));
+SA(__is_pointer(int*));
+SA(__is_pointer(int**));
+
+SA(__is_pointer(const int*));
+SA(__is_pointer(const int**));
+SA(__is_pointer(int* const));
+SA(__is_pointer(int** const));
+SA(__is_pointer(int* const* const));
+
+SA(__is_pointer(volatile int*));
+SA(__is_pointer(volatile int**));
+SA(__is_pointer(int* volatile));
+SA(__is_pointer(int** volatile));
+SA(__is_pointer(int* volatile* volatile));
+
+SA(__is_pointer(const volatile int*));
+SA(__is_pointer(const volatile int**));
+SA(__is_pointer(const int* volatile));
+SA(__is_pointer(volatile int* const));
+SA(__is_pointer(int* const volatile));
+SA(__is_pointer(const int** volatile));
+SA(__is_pointer(volatile int** const));
+SA(__is_pointer(int** const 

Re: [PATCH 2/2] libstdc++: use new built-in trait __is_pointer

2023-07-09 Thread Ken Matsui via Gcc-patches
Oops! Thank you for pointing that out!

Sincerely,
Ken Matsui

On Sun, Jul 9, 2023 at 10:33 PM Daniel Krügler
 wrote:
>
> Am Mo., 10. Juli 2023 um 07:24 Uhr schrieb Ken Matsui via Libstdc++
> :
> >
> > This patch lets libstdc++ use new built-in trait __is_pointer.
> >
> > libstdc++-v3/ChangeLog:
> >
> > * include/std/type_traits (is_pointer): Use __is_pointer
> > built-in trait.
> > (is_pointer_v): Likewise.
> >
> > Signed-off-by: Ken Matsui 
> > ---
> >  libstdc++-v3/include/std/type_traits | 9 -
> >  1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/libstdc++-v3/include/std/type_traits 
> > b/libstdc++-v3/include/std/type_traits
> > index 0e7a9c9c7f3..d83db98403b 100644
> > --- a/libstdc++-v3/include/std/type_traits
> > +++ b/libstdc++-v3/include/std/type_traits
> > @@ -515,6 +515,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >  struct is_array<_Tp[]>
> >  : public true_type { };
> >
> > +  /// is_pointer
> > +#if __has_builtin(__is_pointer)
> > +  template
> > +struct is_pointer
> > +: public __bool_constant<__is_pointer(_Tp)>
> > +{ };
> > +#else
> >template
> >  struct __is_pointer_helper
> >  : public false_type { };
> > @@ -523,11 +530,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >  struct __is_pointer_helper<_Tp*>
> >  : public true_type { };
> >
> > -  /// is_pointer
> >template
> >  struct is_pointer
> >  : public __is_pointer_helper<__remove_cv_t<_Tp>>::type
> >  { };
> > +#endif
> >
> >/// is_lvalue_reference
> >template
> > --
> > 2.41.0
>
> Shouldn't this adjust is_pointer_v as well?
>
> Thanks,
>
> - Daniel


Re: [PATCH 2/2] libstdc++: use new built-in trait __is_pointer

2023-07-09 Thread Daniel Krügler via Gcc-patches
Am Mo., 10. Juli 2023 um 07:24 Uhr schrieb Ken Matsui via Libstdc++
:
>
> This patch lets libstdc++ use new built-in trait __is_pointer.
>
> libstdc++-v3/ChangeLog:
>
> * include/std/type_traits (is_pointer): Use __is_pointer
> built-in trait.
> (is_pointer_v): Likewise.
>
> Signed-off-by: Ken Matsui 
> ---
>  libstdc++-v3/include/std/type_traits | 9 -
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/libstdc++-v3/include/std/type_traits 
> b/libstdc++-v3/include/std/type_traits
> index 0e7a9c9c7f3..d83db98403b 100644
> --- a/libstdc++-v3/include/std/type_traits
> +++ b/libstdc++-v3/include/std/type_traits
> @@ -515,6 +515,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>  struct is_array<_Tp[]>
>  : public true_type { };
>
> +  /// is_pointer
> +#if __has_builtin(__is_pointer)
> +  template
> +struct is_pointer
> +: public __bool_constant<__is_pointer(_Tp)>
> +{ };
> +#else
>template
>  struct __is_pointer_helper
>  : public false_type { };
> @@ -523,11 +530,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>  struct __is_pointer_helper<_Tp*>
>  : public true_type { };
>
> -  /// is_pointer
>template
>  struct is_pointer
>  : public __is_pointer_helper<__remove_cv_t<_Tp>>::type
>  { };
> +#endif
>
>/// is_lvalue_reference
>template
> --
> 2.41.0

Shouldn't this adjust is_pointer_v as well?

Thanks,

- Daniel


[Bug bootstrap/88623] gcc build uses CXX_FOR_BUILD but files have .c extension

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88623

Andrew Pinski  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|UNCONFIRMED |RESOLVED
   Target Milestone|--- |12.0

--- Comment #6 from Andrew Pinski  ---
All c++ files were renamed at r12-6650-5c69acb32329d49e58c26f .

[PATCH 2/2] libstdc++: use new built-in trait __is_pointer

2023-07-09 Thread Ken Matsui via Gcc-patches
This patch lets libstdc++ use new built-in trait __is_pointer.

libstdc++-v3/ChangeLog:

* include/std/type_traits (is_pointer): Use __is_pointer
built-in trait.
(is_pointer_v): Likewise.

Signed-off-by: Ken Matsui 
---
 libstdc++-v3/include/std/type_traits | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index 0e7a9c9c7f3..d83db98403b 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -515,6 +515,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 struct is_array<_Tp[]>
 : public true_type { };
 
+  /// is_pointer
+#if __has_builtin(__is_pointer)
+  template
+struct is_pointer
+: public __bool_constant<__is_pointer(_Tp)>
+{ };
+#else
   template
 struct __is_pointer_helper
 : public false_type { };
@@ -523,11 +530,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 struct __is_pointer_helper<_Tp*>
 : public true_type { };
 
-  /// is_pointer
   template
 struct is_pointer
 : public __is_pointer_helper<__remove_cv_t<_Tp>>::type
 { };
+#endif
 
   /// is_lvalue_reference
   template
-- 
2.41.0



[PATCH 1/2] c++, libstdc++: implement __is_pointer built-in trait

2023-07-09 Thread Ken Matsui via Gcc-patches
This patch implements built-in trait for std::is_pointer.

gcc/cp/ChangeLog:

* cp-trait.def: Define __is_pointer.
* constraint.cc (diagnose_trait_expr): Handle CPTK_IS_POINTER.
* semantics.cc (trait_expr_value): Likewise.
(finish_trait_expr): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/ext/has-builtin-1.C: Test existence of __is_pointer.
* g++.dg/ext/is_pointer.C: New test.
* g++.dg/tm/pr46567.C (__is_pointer): Rename to ...
(is_pointer): ... this.
* g++.dg/torture/20070621-1.C: Likewise.
* g++.dg/torture/pr57107.C: Likewise.

libstdc++-v3/ChangeLog:

* include/bits/cpp_type_traits.h (__is_pointer): Rename to ...
(is_pointer): ... this.
* include/bits/deque.tcc: Use is_pointer instead.
* include/bits/stl_algobase.h: Likewise.

Signed-off-by: Ken Matsui 
---
 gcc/cp/constraint.cc|  3 ++
 gcc/cp/cp-trait.def |  1 +
 gcc/cp/semantics.cc |  4 ++
 gcc/testsuite/g++.dg/ext/has-builtin-1.C|  3 ++
 gcc/testsuite/g++.dg/ext/is_pointer.C   | 51 +
 gcc/testsuite/g++.dg/tm/pr46567.C   | 22 -
 gcc/testsuite/g++.dg/torture/20070621-1.C   |  4 +-
 gcc/testsuite/g++.dg/torture/pr57107.C  |  4 +-
 libstdc++-v3/include/bits/cpp_type_traits.h |  6 +--
 libstdc++-v3/include/bits/deque.tcc |  6 +--
 libstdc++-v3/include/bits/stl_algobase.h|  6 +--
 11 files changed, 86 insertions(+), 24 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 8cf0f2d0974..30266204eb5 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3751,6 +3751,9 @@ diagnose_trait_expr (tree expr, tree args)
 case CPTK_IS_UNION:
   inform (loc, "  %qT is not a union", t1);
   break;
+case CPTK_IS_POINTER:
+  inform (loc, "  %qT is not a pointer", t1);
+  break;
 case CPTK_IS_AGGREGATE:
   inform (loc, "  %qT is not an aggregate", t1);
   break;
diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
index 8b7fece0cc8..b7c263e9a77 100644
--- a/gcc/cp/cp-trait.def
+++ b/gcc/cp/cp-trait.def
@@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, 
"__is_trivially_assignable", 2)
 DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1)
 DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
 DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
+DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1)
 DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, 
"__reference_constructs_from_temporary", 2)
 DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, 
"__reference_converts_from_temporary", 2)
 /* FIXME Added space to avoid direct usage in GCC 13.  */
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 8fb47fd179e..68f8a4fe85b 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12118,6 +12118,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree 
type2)
 case CPTK_IS_UNION:
   return type_code1 == UNION_TYPE;
 
+case CPTK_IS_POINTER:
+  return TYPE_PTR_P (type1);
+
 case CPTK_IS_ASSIGNABLE:
   return is_xible (MODIFY_EXPR, type1, type2);
 
@@ -12296,6 +12299,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, 
tree type1, tree type2)
 case CPTK_IS_ENUM:
 case CPTK_IS_UNION:
 case CPTK_IS_SAME:
+case CPTK_IS_POINTER:
   break;
 
 case CPTK_IS_LAYOUT_COMPATIBLE:
diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C 
b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
index f343e153e56..9dace5cbd48 100644
--- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
+++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
@@ -146,3 +146,6 @@
 #if !__has_builtin (__remove_cvref)
 # error "__has_builtin (__remove_cvref) failed"
 #endif
+#if !__has_builtin (__is_pointer)
+# error "__has_builtin (__is_pointer) failed"
+#endif
diff --git a/gcc/testsuite/g++.dg/ext/is_pointer.C 
b/gcc/testsuite/g++.dg/ext/is_pointer.C
new file mode 100644
index 000..d6e39565950
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_pointer.C
@@ -0,0 +1,51 @@
+// { dg-do compile { target c++11 } }
+
+#define SA(X) static_assert((X),#X)
+
+SA(!__is_pointer(int));
+SA(__is_pointer(int*));
+SA(__is_pointer(int**));
+
+SA(__is_pointer(const int*));
+SA(__is_pointer(const int**));
+SA(__is_pointer(int* const));
+SA(__is_pointer(int** const));
+SA(__is_pointer(int* const* const));
+
+SA(__is_pointer(volatile int*));
+SA(__is_pointer(volatile int**));
+SA(__is_pointer(int* volatile));
+SA(__is_pointer(int** volatile));
+SA(__is_pointer(int* volatile* volatile));
+
+SA(__is_pointer(const volatile int*));
+SA(__is_pointer(const volatile int**));
+SA(__is_pointer(const int* volatile));
+SA(__is_pointer(volatile int* const));
+SA(__is_pointer(int* const volatile));
+SA(__is_pointer(const int** volatile));
+SA(__is_pointer(volatile int** const));
+SA(__is_pointer(int** const 

[Bug bootstrap/90543] Build failure on MINGW for gcc-9.1.0

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90543

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |9.2

[Bug bootstrap/90543] Build failure on MINGW for gcc-9.1.0

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90543

Andrew Pinski  changed:

   What|Removed |Added

 CC||p...@gcc-bugzilla.mail.kaps
   ||i.fi

--- Comment #19 from Andrew Pinski  ---
*** Bug 3 has been marked as a duplicate of this bug. ***

[Bug bootstrap/88883] [AArch64] gcc/config/aarch64/aarch64.opt: aarch64_branch_protection_string type

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |DUPLICATE

--- Comment #3 from Andrew Pinski  ---
Oh this was fixed already. a dup of bug 90543.

*** This bug has been marked as a duplicate of bug 90543 ***

[Bug bootstrap/88883] [AArch64] gcc/config/aarch64/aarch64.opt: aarch64_branch_protection_string type

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3

--- Comment #2 from Andrew Pinski  ---
For a cross from x86_64-linux-gnu to aarch64-linux-gnu produces:
  if (ptr->x_aarch64_branch_protection_string)
fprintf (file, "%*s%s (%s)\n",
 indent, "",
 "aarch64_branch_protection_string",
 ptr->x_aarch64_branch_protection_string);

[Bug c++/99717] ICE in finish_expr_stmt, at cp/semantics.c:681

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99717

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |WAITING
   Last reconfirmed||2023-07-10
 Ever confirmed|0   |1

--- Comment #1 from Andrew Pinski  ---
Without a testcase, it is going to be hard to reproduce and figure out what was
going on.

[Bug target/97585] Improve documentation for -march=x86-64 to say MMX, SSE, SSE2 are implied

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97585

Andrew Pinski  changed:

   What|Removed |Added

   Severity|normal  |enhancement
 Ever confirmed|0   |1
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2023-07-10

--- Comment #1 from Andrew Pinski  ---
Confirmed.

[Bug target/109954] x86-64's -m32 does not conform to documentation

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109954

Andrew Pinski  changed:

   What|Removed |Added

 CC||memmerto at ca dot ibm.com

--- Comment #21 from Andrew Pinski  ---
*** Bug 95661 has been marked as a duplicate of this bug. ***

[Bug target/95661] Code built with -m32 uses SSE2 instructions

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95661

Andrew Pinski  changed:

   What|Removed |Added

 Resolution|INVALID |DUPLICATE

--- Comment #5 from Andrew Pinski  ---
This is a dup of bug 109954 in the end which was fixed.

*** This bug has been marked as a duplicate of bug 109954 ***

[Bug target/88083] ICE in find_constant_pool_ref_1, at config/s390/s390.c:8231

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88083

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |9.0
 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |FIXED

--- Comment #3 from Andrew Pinski  ---
fixed.

[Bug target/89233] [9 Regression] ICE in change_address_1, at emit-rtl.c:2286

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89233

--- Comment #6 from Andrew Pinski  ---
*** Bug 88615 has been marked as a duplicate of this bug. ***

[Bug target/88615] ICE in change_address_1, at emit-rtl.c:2286

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88615

Andrew Pinski  changed:

   What|Removed |Added

 Resolution|--- |DUPLICATE
 Status|UNCONFIRMED |RESOLVED

--- Comment #2 from Andrew Pinski  ---
Dup of bug 89233 which was fixed in GCC 9 already.

*** This bug has been marked as a duplicate of bug 89233 ***

[Bug debug/88094] ICE: add add_dwarf_attr

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88094

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |11.5
   Last reconfirmed||2023-07-10
 Status|UNCONFIRMED |NEW
 Ever confirmed|0   |1

--- Comment #1 from Andrew Pinski  ---
Confirmed. This is a dup of bug 100530. I am going to mark this as a dup of the
newer bug just because it might/will get more attention because it is filed
against x86_64 and is marked as a regression already.

[Bug tree-optimization/89996] ICE in expand_expr_real_2 with -O3 and address spaces

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89996

Andrew Pinski  changed:

   What|Removed |Added

  Known to fail||6.1.0
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2023-07-10
 Ever confirmed|0   |1

--- Comment #5 from Andrew Pinski  ---
Confirmed. At least for x86_64, it is not a regression.

[Bug tree-optimization/89996] ICE in expand_expr_real_2 with -O3 and address spaces

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89996

--- Comment #4 from Andrew Pinski  ---
Created attachment 55509
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55509=edit
x86_64 testcase

[Bug tree-optimization/89996] ICE in expand_expr_real_2 with -O3 and address spaces

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89996

Andrew Pinski  changed:

   What|Removed |Added

 Target|avr |avr x86_64
Summary|[avr] ICE in|ICE in expand_expr_real_2
   |expand_expr_real_2 with -O3 |with -O3 and address spaces
   |and address spaces  |

--- Comment #3 from Andrew Pinski  ---
Can reproduce on x86_64 with __seg_gs will attach the code in a second.

[Bug tree-optimization/89996] [avr] ICE in expand_expr_real_2 with -O3 and address spaces

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89996

Andrew Pinski  changed:

   What|Removed |Added

  Component|target  |tree-optimization
Summary|[avr] ICE in|[avr] ICE in
   |expand_expr_real_2 with -O3 |expand_expr_real_2 with -O3
   ||and address spaces
  Known to fail||9.2.0

--- Comment #2 from Andrew Pinski  ---
With -fchecking we get:

:23:13: error: type mismatch in 'pointer_plus_expr'
   23 | static void send_document(DESC *d, short err, const char __flash
*err_string,
  | ^
const  char[5] *

const struct 
{
  char ext[5];
  const  char * desc;
  _Bool subst;
}[3] *

sizetype

_5 = _types + _9;
:23: confused by earlier errors, bailing out

This is from laddress.

[Bug target/110591] [i386] (Maybe) Missed optimisation: _cmpccxadd sets flags

2023-07-09 Thread crazylht at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110591

--- Comment #2 from Hongtao.liu  ---
(In reply to Hongtao.liu from comment #1)
> I guess we can add a peephole for this, middle-end optimizer doesn't know
> cmpccxadd set EFLAGS same as cmp.

We already have a peephole for cmpxchg, for cmpxchg it's only valid for
CCZmode, but for cmpccxadd, it should be ok for all CCmode since it sets EFLAGS
exactly the same as CMP. The _CMPCCX_Z in the intrinsic is used as condition of
updating memory.

[Bug target/106966] [12/13/14 Regression] alpha cross build crashes gcc-12 "internal compiler error: in emit_move_insn"

2023-07-09 Thread matoro_gcc_bugzilla at matoro dot tk via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106966

matoro  changed:

   What|Removed |Added

 CC||matoro_gcc_bugzilla@matoro.
   ||tk

--- Comment #9 from matoro  ---
(In reply to Uroš Bizjak from comment #8)
> Created attachment 55504 [details]
> Proposed patch.
> 
> Can someone please bootstrap and test the attached patch?

I can queue this up to test on real hardware.  By bootstrap, do you mean with
--enable-bootstrap, and by test do you mean a full testsuite run or just
checking that it doesn't ICE on the reproducer here?

[Bug target/101469] wrong code with "-O2 -fPIE" for SH

2023-07-09 Thread rin at NetBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101469

--- Comment #10 from Rin Okuyama  ---
(In reply to Oleg Endo from comment #9)
> Sorry for being late for 2 years with this.
...
> Unfortunately GCC 10.5 has just been released recently and that was the last 
> version 10.
> So the patch will be included from GCC version 11.

No problem at all! We will probably ship GCC 10.5 with your fix for NetBSD 10.
And we will switch to GCC 12 for NetBSD-current soon.

> I will commit the patch to all open GCC versions.

I'm looking forward to it :)

I'm really excited to know that we have active GCC developer working on SH!

Thanks,
rin

[Bug target/101469] wrong code with "-O2 -fPIE" for SH

2023-07-09 Thread olegendo at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101469

--- Comment #9 from Oleg Endo  ---
(In reply to Rin Okuyama from comment #8)
> (In reply to Oleg Endo from comment #7)
> 
> Hi Oleg. Thank you very much for your great work!
> 
> I've tested your patch with GCC 10.4.0 in this weekend, and it perfectly
> worked:
> - testcase attached to comment #0 compiled correctly
> - full regression tests on NetBSD/shle-current built by patched GCC
> successfully completed without any regression (compared with system built by
> GCC with that peephole optimization removed)
> - some 3rd party softwares (including perl 5.36.0, ruby 3.10.10, zsh 5.9,
> ...) self-built on shle host by GCC of same code base
> 
> Let me thank you again, Oleg!
> 
> rin

Thanks you so much for getting back!  Sorry for being late for 2 years with
this.  I will commit the patch to all open GCC versions.  Unfortunately GCC
10.5 has just been released recently and that was the last version 10.  So the
patch will be included from GCC version 11.

[Bug target/101469] wrong code with "-O2 -fPIE" for SH

2023-07-09 Thread rin at NetBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101469

--- Comment #8 from Rin Okuyama  ---
(In reply to Oleg Endo from comment #7)

Hi Oleg. Thank you very much for your great work!

I've tested your patch with GCC 10.4.0 in this weekend, and it perfectly
worked:
- testcase attached to comment #0 compiled correctly
- full regression tests on NetBSD/shle-current built by patched GCC
successfully completed without any regression (compared with system built by
GCC with that peephole optimization removed)
- some 3rd party softwares (including perl 5.36.0, ruby 3.10.10, zsh 5.9, ...)
self-built on shle host by GCC of same code base

Let me thank you again, Oleg!

rin

[Bug target/110591] [i386] (Maybe) Missed optimisation: _cmpccxadd sets flags

2023-07-09 Thread crazylht at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110591

--- Comment #1 from Hongtao.liu  ---
I guess we can add a peephole for this, middle-end optimizer doesn't know
cmpccxadd set EFLAGS same as cmp.

[PATCH] Break false dependence for vpternlog by inserting vpxor or setting constraint of input operand to '0'

2023-07-09 Thread liuhongt via Gcc-patches
False dependency happens when destination is only updated by
pternlog. There is no false dependency when destination is also used
in source. So either a pxor should be inserted, or input operand
should be set with constraint '0'.

Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
Ready to push to trunk.

gcc/ChangeLog:

PR target/110438
PR target/110202
* config/i386/predicates.md
(int_float_vector_all_ones_operand): New predicate.
* config/i386/sse.md (*vmov_constm1_pternlog_false_dep): New
define_insn.
(*_cvtmask2_pternlog_false_dep):
Ditto.
(*_cvtmask2_pternlog_false_dep):
Ditto.
(*_cvtmask2): Adjust to
define_insn_and_split to avoid false dependence.
(*_cvtmask2): Ditto.
(one_cmpl2): Adjust constraint
of operands 1 to '0' to avoid false dependence.
(*andnot3): Ditto.
(iornot3): Ditto.
(*3): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr110438.c: New test.
---
 gcc/config/i386/predicates.md|   8 +-
 gcc/config/i386/sse.md   | 113 ---
 gcc/testsuite/gcc.target/i386/pr110438.c |  30 ++
 3 files changed, 135 insertions(+), 16 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr110438.c

diff --git a/gcc/config/i386/predicates.md b/gcc/config/i386/predicates.md
index 7ddbe01a6f9..37d20c6303a 100644
--- a/gcc/config/i386/predicates.md
+++ b/gcc/config/i386/predicates.md
@@ -1192,12 +1192,18 @@ (define_predicate "float_vector_all_ones_operand"
 return false;
 })
 
-/* Return true if operand is a vector constant that is all ones. */
+/* Return true if operand is an integral vector constant that is all ones. */
 (define_predicate "vector_all_ones_operand"
   (and (match_code "const_vector")
(match_test "INTEGRAL_MODE_P (GET_MODE (op))")
(match_test "op == CONSTM1_RTX (GET_MODE (op))")))
 
+/* Return true if operand is a vector constant that is all ones. */
+(define_predicate "int_float_vector_all_ones_operand"
+  (ior (match_operand 0 "vector_all_ones_operand")
+   (match_operand 0 "float_vector_all_ones_operand")
+   (match_test "op == constm1_rtx")))
+
 /* Return true if operand is an 128/256bit all ones vector
that zero-extends to 256/512bit.  */
 (define_predicate "vector_all_ones_zero_extend_half_operand"
diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 418c337a775..56920a3e1d3 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -1382,6 +1382,29 @@ (define_insn "mov_internal"
  ]
  (symbol_ref "true")))])
 
+; False dependency happens on destination register which is not really
+; used when moving all ones to vector register
+(define_split
+  [(set (match_operand:VMOVE 0 "register_operand")
+   (match_operand:VMOVE 1 "int_float_vector_all_ones_operand"))]
+  "TARGET_AVX512F && reload_completed
+  && ( == 64 || EXT_REX_SSE_REG_P (operands[0]))
+  && optimize_function_for_speed_p (cfun)"
+  [(set (match_dup 0) (match_dup 2))
+   (parallel
+ [(set (match_dup 0) (match_dup 1))
+  (unspec [(match_dup 0)] UNSPEC_INSN_FALSE_DEP)])]
+  "operands[2] = CONST0_RTX (mode);")
+
+(define_insn "*vmov_constm1_pternlog_false_dep"
+  [(set (match_operand:VMOVE 0 "register_operand" "=v")
+   (match_operand:VMOVE 1 "int_float_vector_all_ones_operand" 
""))
+   (unspec [(match_operand:VMOVE 2 "register_operand" "0")] 
UNSPEC_INSN_FALSE_DEP)]
+   "TARGET_AVX512VL ||  == 64"
+   "vpternlogd\t{$0xFF, %0, %0, %0|%0, %0, %0, 0xFF}"
+  [(set_attr "type" "sselog1")
+   (set_attr "prefix" "evex")])
+
 ;; If mem_addr points to a memory region with less than whole vector size bytes
 ;; of accessible memory and k is a mask that would prevent reading the 
inaccessible
 ;; bytes from mem_addr, add UNSPEC_MASKLOAD to prevent it to be transformed to 
vpblendd
@@ -9336,7 +9359,7 @@ (define_expand "_cvtmask2"
 operands[3] = CONST0_RTX (mode);
   }")
 
-(define_insn "*_cvtmask2"
+(define_insn_and_split "*_cvtmask2"
   [(set (match_operand:VI48_AVX512VL 0 "register_operand" "=v,v")
(vec_merge:VI48_AVX512VL
  (match_operand:VI48_AVX512VL 2 "vector_all_ones_operand")
@@ -9346,11 +9369,35 @@ (define_insn "*_cvtmask2"
   "@
vpmovm2\t{%1, %0|%0, %1}
vpternlog\t{$0x81, %0, %0, %0%{%1%}%{z%}|%0%{%1%}%{z%}, %0, 
%0, 0x81}"
+  "&& !TARGET_AVX512DQ && reload_completed
+   && optimize_function_for_speed_p (cfun)"
+  [(set (match_dup 0) (match_dup 4))
+   (parallel
+[(set (match_dup 0)
+ (vec_merge:VI48_AVX512VL
+   (match_dup 2)
+   (match_dup 3)
+   (match_dup 1)))
+ (unspec [(match_dup 0)] UNSPEC_INSN_FALSE_DEP)])]
+  "operands[4] = CONST0_RTX (mode);"
   [(set_attr "isa" "avx512dq,*")
(set_attr "length_immediate" "0,1")
(set_attr "prefix" "evex")
(set_attr "mode" "")])
 
+(define_insn "*_cvtmask2_pternlog_false_dep"
+  [(set 

[Bug target/110170] Sub-optimal conditional jumps in conditional-swap with floating point

2023-07-09 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110170

--- Comment #12 from CVS Commits  ---
The master branch has been updated by hongtao Liu :

https://gcc.gnu.org/g:d41a57c46df6f8f7dae0c0a8b349e734806a837b

commit r14-2403-gd41a57c46df6f8f7dae0c0a8b349e734806a837b
Author: liuhongt 
Date:   Mon Jul 3 18:19:19 2023 +0800

Add pre_reload splitter to detect fp min/max pattern.

We have ix86_expand_sse_fp_minmax to detect min/max sematics, but
it requires rtx_equal_p for cmp_op0/cmp_op1 and if_true/if_false, for
the testcase in the PR, there's an extra move from cmp_op0 to if_true,
and it failed ix86_expand_sse_fp_minmax.

This patch adds pre_reload splitter to detect the min/max pattern.

Operands order in MINSS matters for signed zero and NANs, since the
instruction always returns second operand when any operand is NAN or
both operands are zero.

gcc/ChangeLog:

PR target/110170
* config/i386/i386.md (*ieee_max3_1): New pre_reload
splitter to detect fp max pattern.
(*ieee_min3_1): Ditto, but for fp min pattern.

gcc/testsuite/ChangeLog:

* g++.target/i386/pr110170.C: New test.
* gcc.target/i386/pr110170.c: New test.

[Bug c/110609] Bogus -Wmismatched-dealloc when allocator defined & used in same TU w/ -fPIC -fno-semantic-interposition

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110609

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |DUPLICATE

--- Comment #1 from Andrew Pinski  ---
Dup.

*** This bug has been marked as a duplicate of bug 110546 ***

[Bug tree-optimization/110546] Function clone not treated as valid allocator with -Wmismatched-dealloc

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110546

Andrew Pinski  changed:

   What|Removed |Added

 CC||andres at anarazel dot de

--- Comment #2 from Andrew Pinski  ---
*** Bug 110609 has been marked as a duplicate of this bug. ***

[Bug c/110609] New: Bogus -Wmismatched-dealloc when allocator defined & used in same TU w/ -fPIC -fno-semantic-interposition

2023-07-09 Thread andres at anarazel dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110609

Bug ID: 110609
   Summary: Bogus -Wmismatched-dealloc when allocator defined &
used in same TU w/ -fPIC -fno-semantic-interposition
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: andres at anarazel dot de
  Target Milestone: ---

Hi,

Whenever an allocator function annotated with attribute((malloc(freelike)) is
defined and used in the same translation unit and -fno-semantic-interposition
-fPIC are used, bogus mismatched alloc/free warnings ensue.


void somefree(int *);

__attribute__((__malloc__(somefree, 1)))
int *somealloc(void) {
  return 0;
}

void other(void) {
  int *v = somealloc();
  somefree(v);
}
---
gcc -Wmismatched-dealloc -fno-semantic-interposition -fPIC -o a.out -c fd.c.i

fd.c.i: In function ‘other’:
fd.c.i:10:3: warning: ‘somefree’ called on pointer returned from a mismatched
allocation function [-Wmismatched-dealloc]
   10 |   somefree(v);
  |   ^~~
fd.c.i:9:12: note: returned from ‘somealloc.localalias’
9 |   int *v = somealloc();
  |^~~

This appears to happen with all versions supporting -Wmismatched-dealloc,
including today's git head at 3b007164b3e.

Regards,

Andres

[Bug c++/89793] Implicit conversion to std::string is ambiguous on GCC 8.2 but not GCC 7.3

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89793

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||needs-bisection,
   ||rejects-valid

--- Comment #10 from Andrew Pinski  ---
I suspect r9-6526-gdcfa8518868d9e (r8-10080-g32988aac5be4fa4728 on the branch)
fixed this .

[Bug driver/87769] GCC build from source uses headers and libraries from directories host machine.

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87769

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |WORKSFORME

--- Comment #12 from Andrew Pinski  ---
Because pc as the vendor for x86_64-* is the default.

>From config.sub:
# We use `pc' rather than `unknown'
# because (1) that's what they normally are, and
# (2) the word "unknown" tends to confuse beginning users.
i*86 | x86_64)
cpu=$basic_machine
vendor=pc
;;

Re: abi

2023-07-09 Thread André Albergaria Coelho via Gcc

Can we debate in this mailing list?  thanks


On 7/9/23 22:04, Paul Koning wrote:

Because implementing an ABI, or dealing with an incompatibnle change, is hard 
work.



 you could just use one ABI..(that's what you have)..you can use other 
, only at a cost of specifying an ABI version


the abi is text though..so you only have to write a text file



  Also, ABI stability means that old binaries work


when you mean binaries, do you mean ELF files? executable files?



.  So ABI stability isn't so much a requirement for the compiler as it is a 
requirement for any sane operating system.


what does  a calling convention, has to do with syscalls?! and syscalls, 
and calling conventions, have to do with size and layouts?


used wikipedia definition 
..https://en.wikipedia.org/wiki/Application_binary_interface



how can the OS, have a binary interface?!!


for example:

prtinf("abc"),

asm  (say mov $123,%eax)

 binary instruction is 010110101 (for example)...how can the operating 
system know what interface to use?!



say i have 101010110101  1010101010101 , how does the O.S  works on 
binary files?! say how is the syscall used (at binary level)..it had to 
be compiled / assembled



int main() {

    write(123,_ptr,,count);

}

say write syscall is  "101010101001" in binary  ,so how does the O.S 
interfaces this ? does the O.S. separate binary numbers?!?



unless you meant ELF as "binary program"





An OS that changes ABI without an extremely good reason is an OS that 
doesn't care about compatibility, which means it doesn't care about its 
customers.






The MIPS examples I pointed to are a good illustration of this.  The original 
("O32") ABI is for MIPS with 32 bit registers and 32 bit addressing.  N32 and 
N64 were introduced by SGI to support 64 bit registers, and (for N64) 64 bit pointers.  
That's a very compelling benefit.  64 bbit addressing is obvious, and the performance 
benefit from using 64 bit registers on machines that have them is very large.  So there, 
the quite large cost of doing this was totally justified.


The benefit would be for the user...code like it wants (for example, 
return value in %ecx)..which is the ultimate reason to use compilers


and also, the benefit would be to use every ABI possible (choosing the best)



paul


On Jul 9, 2023, at 4:55 PM, André Albergaria Coelho via Gcc  
wrote:

If we can select the ABi for our program (using gcc), why is there a need for 
ABI stability?!

why not put it on a define


#define abi v3

int main() {

}


Each user would just have to compile the code, to follow the abi...no need to 
worry changing it


thanks


andre


andre


gcc-14-20230709 is now available

2023-07-09 Thread GCC Administrator via Gcc
Snapshot gcc-14-20230709 is now available on
  https://gcc.gnu.org/pub/gcc/snapshots/14-20230709/
and on various mirrors, see http://gcc.gnu.org/mirrors.html for details.

This snapshot has been generated from the GCC 14 git branch
with the following options: git://gcc.gnu.org/git/gcc.git branch master 
revision d6c1d7c4009bfe759719675ce3bc03ca503b9bf4

You'll find:

 gcc-14-20230709.tar.xz   Complete GCC

  SHA256=c988390f6ae1855b581e44744f6035c11b6e194a5b53a08edd108bc9f4461c2f
  SHA1=8086ff9b41dc4e8641b11d3f01231342145aa42a

Diffs from 14-20230702 are available in the diffs/ subdirectory.

When a particular snapshot is ready for public consumption the LATEST-14
link is updated and a message is sent to the gcc list.  Please do not use
a snapshot before it has been announced that way.


[Bug target/110598] [14 Regression] wrong code on llvm-14.0.6 due to memcmp being miscompiled

2023-07-09 Thread roger at nextmovesoftware dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110598

Roger Sayle  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |roger at 
nextmovesoftware dot com
 Status|NEW |ASSIGNED

--- Comment #4 from Roger Sayle  ---
Mine.  The new peephole2 is misbehaving with the (odd) RTL sequence:
(insn 62 61 63 2 (set (reg:DI 1 dx [111])
(const_int 0 [0])) "pr110598.c":10:10 90 {*movdi_internal}

(insn 63 62 64 2 (parallel [
(set (reg:DI 1 dx [110])
(xor:DI (reg:DI 1 dx [111])
(reg:DI 1 dx)))
(clobber (reg:CC 17 flags))
]) "pr110598.c":10:10 626 {*xordi_1}
 (expr_list:REG_UNUSED (reg:CC 17 flags)
(nil)))

Doh!  I need to confirm/check that rega != regb.  Interesting that DF doesn't
consider insn 62 as REG_UNUSED (i.e. dead), a classic false dependency.

[Bug bootstrap/110607] Makefile.in builds broken build-tools when CXXFLAGS is defined

2023-07-09 Thread sagebar at web dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110607

--- Comment #2 from sagebar at web dot de ---
@Andrew Pinski

Sorry if this is a known bug. I simply checked the current gcc master
(https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=Makefile.tpl;h=d0fe7e2fb778b3c3fa2cc8742e06cf1f78fdc5f2;hb=HEAD#l183),
which is still affected. I was not aware that a fix was already pending but not
yet merged.

Re: [PATCH v2] Implement new RTL optimizations pass: fold-mem-offsets.

2023-07-09 Thread Hans-Peter Nilsson
On Sun, 9 Jul 2023, Hans-Peter Nilsson wrote:

> On Thu, 15 Jun 2023, Manolis Tsamis wrote:
> 
> > This is a new RTL pass that tries to optimize memory offset calculations
> > by moving them from add immediate instructions to the memory loads/stores.

> It punts on all "use" insns that are not SET.
> Why not use single_set there too?

Also, I don't see insn costs considered?
(Also: typo "immidiate".)

brgds, H-P


[Bug bootstrap/88883] [AArch64] gcc/config/aarch64/aarch64.opt: aarch64_branch_protection_string type

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3

Andrew Pinski  changed:

   What|Removed |Added

  Component|driver  |bootstrap

--- Comment #1 from Andrew Pinski  ---
It should have been recorded as string type in optc-save-gen.awk.

Re: [PATCH v2] Implement new RTL optimizations pass: fold-mem-offsets.

2023-07-09 Thread Hans-Peter Nilsson
On Thu, 15 Jun 2023, Manolis Tsamis wrote:

> This is a new RTL pass that tries to optimize memory offset calculations
> by moving them from add immediate instructions to the memory loads/stores.
> For example it can transform this:
> 
>   addi t4,sp,16
>   add  t2,a6,t4
>   shl  t3,t2,1
>   ld   a2,0(t3)
>   addi a2,1
>   sd   a2,8(t2)
> 
> into the following (one instruction less):
> 
>   add  t2,a6,sp
>   shl  t3,t2,1
>   ld   a2,32(t3)
>   addi a2,1
>   sd   a2,24(t2)
> 
> Although there are places where this is done already, this pass is more
> powerful and can handle the more difficult cases that are currently not
> optimized. Also, it runs late enough and can optimize away unnecessary
> stack pointer calculations.

It punts on all "use" insns that are not SET.
Why not use single_set there too?

brgds, H-P


[Bug libstdc++/86130] Expect SIGSEGV but program just silently exits

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86130

Andrew Pinski  changed:

   What|Removed |Added

 CC||mimomorin at gmail dot com

--- Comment #17 from Andrew Pinski  ---
*** Bug 109891 has been marked as a duplicate of this bug. ***

[Bug libstdc++/109891] Null pointer special handling in ostream's operator << for C-strings

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109891

Andrew Pinski  changed:

   What|Removed |Added

 Resolution|--- |DUPLICATE
 Status|UNCONFIRMED |RESOLVED

--- Comment #10 from Andrew Pinski  ---
Dup of bug 86130.

*** This bug has been marked as a duplicate of bug 86130 ***

[X86 PATCH] Add new insvti_lowpart_1 and insvdi_lowpart_1 patterns.

2023-07-09 Thread Roger Sayle

This patch implements another of Uros' suggestions, to investigate a
insvti_lowpart_1 pattern to improve TImode parameter passing on x86_64.
In PR 88873, the RTL the middle-end expands for passing V2DF in TImode
is subtly different from what it does for V2DI in TImode, sufficiently so
that my explanations for why insvti_lowpart_1 isn't required don't apply
in this case.

This patch adds an insvti_lowpart_1 pattern, complementing the existing
insvti_highpart_1 pattern, and also a 32-bit variant, insvdi_lowpart_1.
Because the middle-end represents 128-bit constants using CONST_WIDE_INT
and 64-bit constants using CONST_INT, it's easiest to treat these as
different patterns, rather than attempt  parameterization.

This patch also includes a peephole2 (actually a pair) to transform
xchg instructions into mov instructions, when one of the destinations
is unused.  This optimization is required to produce the optimal code
sequences below.

For the 64-bit case:

__int128 foo(__int128 x, unsigned long long y)
{
  __int128 m = ~((__int128)~0ull);
  __int128 t = x & m;
  __int128 r = t | y;
  return r;
}

Before:
xchgq   %rdi, %rsi
movq%rdx, %rax
xorl%esi, %esi
xorl%edx, %edx
orq %rsi, %rax
orq %rdi, %rdx
ret

After:
movq%rdx, %rax
movq%rsi, %rdx
ret

For the 32-bit case:

long long bar(long long x, int y)
{
  long long mask = ~0ull << 32;
  long long t = x & mask;
  long long r = t | (unsigned int)y;
  return r;
}

Before:
pushl   %ebx
movl12(%esp), %edx
xorl%ebx, %ebx
xorl%eax, %eax
movl16(%esp), %ecx
orl %ebx, %edx
popl%ebx
orl %ecx, %eax
ret

After:
movl12(%esp), %eax
movl8(%esp), %edx
ret

This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
and make -k check, both with and without --target_board=unix{-m32}
with no new failures.  Ok for mainline?


2023-07-09  Roger Sayle  

gcc/ChangeLog
* config/i386/i386.md (peephole2): Transform xchg insn with a
REG_UNUSED note to a (simple) move.
(*insvti_lowpart_1): New define_insn_and_split.
(*insvdi_lowpart_1): Likewise.

gcc/testsuite/ChangeLog
* gcc.target/i386/insvdi_lowpart-1.c: New test case.
* gcc.target/i386/insvti_lowpart-1.c: Likewise.


Cheers,
Roger
--

diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index e47ced1..ea04d0a 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -3243,6 +3243,30 @@
   [(parallel [(set (match_dup 1) (match_dup 2))
  (set (match_dup 2) (match_dup 1))])])
 
+;; Convert xchg with a REG_UNUSED note to a mov (variant #1).
+(define_peephole2
+  [(parallel [(set (match_operand:SWI 0 "general_reg_operand")
+  (match_operand:SWI 1 "general_reg_operand"))
+ (set (match_dup 1) (match_dup 0))])]
+  "((REGNO (operands[0]) != AX_REG
+ && REGNO (operands[1]) != AX_REG)
+|| optimize_size < 2
+|| !optimize_insn_for_size_p ())
+   && peep2_reg_dead_p (1, operands[0])"
+  [(set (match_dup 1) (match_dup 0))])
+
+;; Convert xchg with a REG_UNUSED note to a mov (variant #2).
+(define_peephole2
+  [(parallel [(set (match_operand:SWI 0 "general_reg_operand")
+  (match_operand:SWI 1 "general_reg_operand"))
+ (set (match_dup 1) (match_dup 0))])]
+  "((REGNO (operands[0]) != AX_REG
+ && REGNO (operands[1]) != AX_REG)
+|| optimize_size < 2
+|| !optimize_insn_for_size_p ())
+   && peep2_reg_dead_p (1, operands[1])"
+  [(set (match_dup 0) (match_dup 1))])
+
 ;; Convert moves to/from AX_REG into xchg with -Oz.
 (define_peephole2
   [(set (match_operand:SWI48 0 "general_reg_operand")
@@ -3573,6 +3597,48 @@
   split_double_concat (TImode, operands[0], operands[4], operands[2]);
   DONE;
 })
+
+(define_insn_and_split "*insvti_lowpart_1"
+  [(set (match_operand:TI 0 "nonimmediate_operand" "=ro,r,r,")
+   (any_or_plus:TI
+ (and:TI
+   (match_operand:TI 1 "nonimmediate_operand" "r,m,r,m")
+   (match_operand:TI 3 "const_scalar_int_operand" "n,n,n,n"))
+ (zero_extend:TI
+   (match_operand:DI 2 "nonimmediate_operand" "r,r,m,m"]
+  "TARGET_64BIT
+   && CONST_WIDE_INT_P (operands[3])
+   && CONST_WIDE_INT_NUNITS (operands[3]) == 2
+   && CONST_WIDE_INT_ELT (operands[3], 0) == 0
+   && CONST_WIDE_INT_ELT (operands[3], 1) == -1"
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+{
+  operands[4] = gen_highpart (DImode, operands[1]);
+  split_double_concat (TImode, operands[0], operands[2], operands[4]);
+  DONE;
+})
+
+(define_insn_and_split "*insvdi_lowpart_1"
+  [(set (match_operand:DI 0 "nonimmediate_operand" "=ro,r,r,")
+   (any_or_plus:DI
+ (and:DI
+   (match_operand:DI 1 "nonimmediate_operand" "r,m,r,m")
+   (match_operand:DI 3 "const_int_operand" "n,n,n,n"))
+ 

[Bug target/108575] Bug in gcc arm non eabi

2023-07-09 Thread ergasies.uni at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108575

--- Comment #7 from Nikos Tosis  ---
thank you for the info, I will try tomorrow to see if I made a mistake in
simulink or its a bug from simulink.

Re: abi

2023-07-09 Thread Paul Koning via Gcc
Because implementing an ABI, or dealing with an incompatibnle change, is hard 
work.  Also, ABI stability means that old binaries work.  So ABI stability 
isn't so much a requirement for the compiler as it is a requirement for any 
sane operating system.  An OS that changes ABI without an extremely good reason 
is an OS that doesn't care about compatibility, which means it doesn't care 
about its customers.

The MIPS examples I pointed to are a good illustration of this.  The original 
("O32") ABI is for MIPS with 32 bit registers and 32 bit addressing.  N32 and 
N64 were introduced by SGI to support 64 bit registers, and (for N64) 64 bit 
pointers.  That's a very compelling benefit.  64 bbit addressing is obvious, 
and the performance benefit from using 64 bit registers on machines that have 
them is very large.  So there, the quite large cost of doing this was totally 
justified.

paul

> On Jul 9, 2023, at 4:55 PM, André Albergaria Coelho via Gcc  
> wrote:
> 
> If we can select the ABi for our program (using gcc), why is there a need for 
> ABI stability?!
> 
> why not put it on a define
> 
> 
> #define abi v3
> 
> int main() {
> 
> }
> 
> 
> Each user would just have to compile the code, to follow the abi...no need to 
> worry changing it
> 
> 
> thanks
> 
> 
> andre
> 



abi

2023-07-09 Thread André Albergaria Coelho via Gcc
If we can select the ABi for our program (using gcc), why is there a 
need for ABI stability?!


why not put it on a define


#define abi v3

int main() {

}


Each user would just have to compile the code, to follow the abi...no 
need to worry changing it



thanks


andre



[Bug target/108575] Bug in gcc arm non eabi

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108575

--- Comment #6 from Andrew Pinski  ---
>The address 2001 1548 exist not in my map file as variable. 

It is a stack address. Since UnitDelay_DSTATE is defined on the stack.

Comment #2 applies here. The code that GCC compiles seems to be corresponding
to the assembly code that GCC is producing too.
rtu_AngleMecIn will contain the address of UnitDelay_DSTATE which is a variable
on stack inside MotorControlLib_step .

[Bug fortran/110288] [11/12/13/14] Regression: segfault in findloc with allocatable array of allocatable characters

2023-07-09 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110288

anlauf at gcc dot gnu.org changed:

   What|Removed |Added

 CC||anlauf at gcc dot gnu.org

--- Comment #2 from anlauf at gcc dot gnu.org ---
Interesting bug.

Modified testcase:

program test
  character(len=:), allocatable, dimension(:) :: array
  array = ["bb", "aa"]
  print *, findloc (array, "aa", dim=1, kind=8)
contains
  subroutine sub (str)
character(*), intent(in) :: str(:)
!   print *, findloc (str, "bb", dim=1, kind=8) ! (un-)comment this line!
  end
end program test

The tree-dump shows for the findloc call:

D.4354 = _gfortran_findloc2_s1 (, &"aa"[1]{lb: 1 sz: 1}, 0, &.array, 2);

Note that we pass an address where we should pass the dereferenced length.

Uncommenting the marked line, we get instead (for the same source line!):

D.4374 = _gfortran_findloc2_s1 (, &"aa"[1]{lb: 1 sz: 1}, 0, .array, 2);

Indeed this variant is fine and runs fine.

[x86 PATCH] Add AVX512 support for STV of SI/DImode rotation by constant.

2023-07-09 Thread Roger Sayle

Following Uros' suggestion, this patch adds support for AVX512VL's
vpro[lr][dq] instructions to the recently added scalar-to-vector (STV)
enhancements to handle DImode and SImode rotations by a constant.

For the test cases:

unsigned long long rot1(unsigned long long x) {
  return (x>>1) | (x<<63);
}

void mem1(unsigned long long *p) {
  *p = rot1(*p);
}

with -m32 -O2 -mavx512vl, we currently generate:

rot1:   movl4(%esp), %eax
movl8(%esp), %edx
movl%eax, %ecx
shrdl   $1, %edx, %eax
shrdl   $1, %ecx, %edx
ret

mem1:   movl4(%esp), %eax
vmovq   (%eax), %xmm0
vpshufd $20, %xmm0, %xmm0
vpsrlq  $1, %xmm0, %xmm0
vpshufd $136, %xmm0, %xmm0
vmovq   %xmm0, (%eax)
ret

with this patch, we now generate:

rot1:   vmovq   4(%esp), %xmm0
vprorq  $1, %xmm0, %xmm0
vmovd   %xmm0, %eax
vpextrd $1, %xmm0, %edx
ret

mem1:   movl4(%esp), %eax
vmovq   (%eax), %xmm0
vprorq  $1, %xmm0, %xmm0
vmovq   %xmm0, (%eax)
ret


This patch has been tested on x86_64-pc-linux-gnu (cascadelake which has
avx512) with make bootstrap and make -k check, both with and without
--target_board=unix{-m32} with no new failures.  Ok for mainline?


2023-07-09  Roger Sayle  

gcc/ChangeLog
* config/i386/i386-features.cc (compute_convert_gain): Tweak
gains/costs for ROTATE/ROTATERT by integer constant on AVX512VL.
(general_scalar_chain::convert_rotate): On TARGET_AVX512F generate
avx512vl_rolv2di or avx412vl_rolv4si when appropriate.

gcc/testsuite/ChangeLog
* gcc.target/i386/avx512vl-stv-rotatedi-1.c: New test case.


Cheers,
Roger
--

diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc
index 2e751d1..4d69251 100644
--- a/gcc/config/i386/i386-features.cc
+++ b/gcc/config/i386/i386-features.cc
@@ -585,7 +585,9 @@ general_scalar_chain::compute_convert_gain ()
  case ROTATE:
  case ROTATERT:
igain += m * ix86_cost->shift_const;
-   if (smode == DImode)
+   if (TARGET_AVX512F)
+ igain -= ix86_cost->sse_op;
+   else if (smode == DImode)
  {
int bits = INTVAL (XEXP (src, 1));
if ((bits & 0x0f) == 0)
@@ -1225,6 +1227,8 @@ general_scalar_chain::convert_rotate (enum rtx_code code, 
rtx op0, rtx op1,
  emit_insn_before (pat, insn);
  result = gen_lowpart (V2DImode, tmp1);
}
+  else if (TARGET_AVX512F)
+   result = simplify_gen_binary (code, V2DImode, op0, op1);
   else if (bits == 16 || bits == 48)
{
  rtx tmp1 = gen_reg_rtx (V8HImode);
@@ -1269,6 +1273,8 @@ general_scalar_chain::convert_rotate (enum rtx_code code, 
rtx op0, rtx op1,
   emit_insn_before (pat, insn);
   result = gen_lowpart (V4SImode, tmp1);
 }
+  else if (TARGET_AVX512F)
+result = simplify_gen_binary (code, V4SImode, op0, op1);
   else
 {
   if (code == ROTATE)
diff --git a/gcc/testsuite/gcc.target/i386/avx512vl-stv-rotatedi-1.c 
b/gcc/testsuite/gcc.target/i386/avx512vl-stv-rotatedi-1.c
new file mode 100644
index 000..2f0ead8
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx512vl-stv-rotatedi-1.c
@@ -0,0 +1,35 @@
+/* { dg-do compile { target ia32 } } */
+/* { dg-options "-O2 -mavx512vl" } */
+
+unsigned long long rot1(unsigned long long x) { return (x>>1) | (x<<63); }
+unsigned long long rot2(unsigned long long x) { return (x>>2) | (x<<62); }
+unsigned long long rot3(unsigned long long x) { return (x>>3) | (x<<61); }
+unsigned long long rot4(unsigned long long x) { return (x>>4) | (x<<60); }
+unsigned long long rot5(unsigned long long x) { return (x>>5) | (x<<59); }
+unsigned long long rot6(unsigned long long x) { return (x>>6) | (x<<58); }
+unsigned long long rot7(unsigned long long x) { return (x>>7) | (x<<57); }
+unsigned long long rot8(unsigned long long x) { return (x>>8) | (x<<56); }
+unsigned long long rot9(unsigned long long x) { return (x>>9) | (x<<55); }
+unsigned long long rot10(unsigned long long x) { return (x>>10) | (x<<54); }
+unsigned long long rot15(unsigned long long x) { return (x>>15) | (x<<49); }
+unsigned long long rot16(unsigned long long x) { return (x>>16) | (x<<48); }
+unsigned long long rot17(unsigned long long x) { return (x>>17) | (x<<47); }
+unsigned long long rot20(unsigned long long x) { return (x>>20) | (x<<44); }
+unsigned long long rot24(unsigned long long x) { return (x>>24) | (x<<40); }
+unsigned long long rot30(unsigned long long x) { return (x>>30) | (x<<34); }
+unsigned long long rot31(unsigned long long x) { return (x>>31) | (x<<33); }
+unsigned long long rot32(unsigned long long x) { return (x>>32) | (x<<32); }
+unsigned long long rot33(unsigned long long x) { return (x>>33) | (x<<31); }
+unsigned long long rot34(unsigned long long x) { return (x>>34) | (x<<30); }
+unsigned long long rot40(unsigned long long x) { return 

[Bug target/69692] STV is disabled even when stack is aligned

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69692

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |12.0
 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |FIXED

--- Comment #1 from Andrew Pinski  ---
Fixed in GCC 12.

[Bug target/63206] Gcc 4.9.1 Generated code needlessly stacks r3

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63206

Andrew Pinski  changed:

   What|Removed |Added

 Resolution|--- |DUPLICATE
 Status|UNCONFIRMED |RESOLVED

--- Comment #4 from Andrew Pinski  ---
Dup of bug 67226.

*** This bug has been marked as a duplicate of bug 67226 ***

[Bug rtl-optimization/67226] Incorrect code generated for tail call, where parameters are structs passed by value, -O2 is used, and target is ARM

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67226

Andrew Pinski  changed:

   What|Removed |Added

 CC||alexandre.nunes at gmail dot 
com

--- Comment #11 from Andrew Pinski  ---
*** Bug 63206 has been marked as a duplicate of this bug. ***

[Bug target/108575] Bug in gcc arm non eabi

2023-07-09 Thread ergasies.uni at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108575

--- Comment #5 from Nikos Tosis  ---
Hi, 

I opened this bug report in January and until today I didn't see any reaction. 
do you need more information about the bug or has been fixed?

[Bug tree-optimization/110600] [14 Regregression] ICE on valid code at -O1 and above on x86_64-linux-gnu: Segmentation fault

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110600

Andrew Pinski  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #4 from Andrew Pinski  ---
Fixed.

[Bug c++/110608] error on evaluation of concept three_way_comparable on recursive variant

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110608

--- Comment #1 from Andrew Pinski  ---
I think GCC is correct here ...

GCC is the only compiler which implements the `satisfaction of atomic
constraint not depending on itself` part of the C++ standard (there are a few
open bugs dealing with that but just left open because maybe the C++ standard
will change).

[Bug bootstrap/110607] Makefile.in builds broken build-tools when CXXFLAGS is defined

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110607

Andrew Pinski  changed:

   What|Removed |Added

 Ever confirmed|0   |1
   Last reconfirmed||2023-07-09
 Status|UNCONFIRMED |NEW

--- Comment #1 from Andrew Pinski  ---


Looks like this has been posted a few times.


Feb this year:
https://inbox.sourceware.org/gcc-patches/20230222123411.419584-1-yash.shi...@windriver.com/

September last year:
https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601344.html
With an approval in November:
https://gcc.gnu.org/pipermail/gcc-patches/2022-November/606922.html

[Bug c++/110608] New: error on evaluation of concept three_way_comparable on recursive variant

2023-07-09 Thread walim at gmx dot net via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110608

Bug ID: 110608
   Summary: error on evaluation of concept three_way_comparable on
recursive variant
   Product: gcc
   Version: 13.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: walim at gmx dot net
  Target Milestone: ---

Created attachment 55508
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55508=edit
reduced demo of the error situation (-std=c++20 or higher must be active to
reproduce the error)

A recursiv variant type with its data type as base will not compile in g++ with
-std=c++20 or higher, because of problems evaluating the concept
three_way_comparable

Found on g++ 13.2 on some linux installations and reproduced in compiler
explorer.
(No such error in clang++ and vc)

[Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110580

--- Comment #4 from Andrew Pinski  ---
Slightly more reduced:
```
#include 

using std::is_same_v;

struct s0 {};
struct s1 {};
template  
struct s3 {
  template 
  static constexpr bool __usable_key = is_same_v<_Vp, _Key>;
  static_assert(!__usable_key);
};
s3 t;

```
If I remove _Vp or remove it from being type dependent, it works.

[Bug driver/110607] New: Makefile.in build broken build-tools when CXXFLAGS is defined

2023-07-09 Thread sagebar at web dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110607

Bug ID: 110607
   Summary: Makefile.in build broken build-tools when CXXFLAGS is
defined
   Product: gcc
   Version: 12.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: driver
  Assignee: unassigned at gcc dot gnu.org
  Reporter: sagebar at web dot de
  Target Milestone: ---

This part in the main makefile:

> 177 # These variables must be set on the make command line for directories
> 178 # built for the build system to override those in BASE_FLAGS_TO_PASS.
> 179 EXTRA_BUILD_FLAGS = \
> 180 CFLAGS="$(CFLAGS_FOR_BUILD)" \
> 181 LDFLAGS="$(LDFLAGS_FOR_BUILD)"

Should instead be:

> 177 # These variables must be set on the make command line for directories
> 178 # built for the build system to override those in BASE_FLAGS_TO_PASS.
> 179 EXTRA_BUILD_FLAGS = \
> 180 CFLAGS="$(CFLAGS_FOR_BUILD)" \
> 181 CXXFLAGS="$(CXXFLAGS_FOR_BUILD)" \
> 182 LDFLAGS="$(LDFLAGS_FOR_BUILD)"

Since some components of the build system are compiled as c++, if one wants to
define custom CXX-flags in cross-compilation situations, these flags then also
get used when building build-tools (which causes breakage)

[Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110580

--- Comment #3 from Andrew Pinski  ---
Reduced all the way:
```
template  struct remove_reference {
  using type = __remove_reference(_Tp);
};
template 
using remove_reference_t = typename remove_reference<_Tp>::type;
template 
inline constexpr bool is_same_v = __is_same(_Tp, _Up);

template  class s3 {
public:
  template >
  static constexpr bool __usable_key = is_same_v;
  template  void f(_Args __args, int t) {
if constexpr (__usable_key<_Args>) {
  const _Key &__k = __args;
}
  }
};
struct s0 {};
struct s1 {};
s1 g();
void createMember(int member, s3 ) { children.f(g(), member); }

```

Or if using the internal type_traits is bad idea here is better testcase:
```

#include 

using namespace std;

template  class s3 {
public:
  template >
  static constexpr bool __usable_key = is_same_v;
  template  void f(_Args __args, int t) {
if constexpr (__usable_key<_Args>) {
  const _Key &__k = __args;
}
  }
};
struct s0 {};
struct s1 {};
s1 g();
void createMember(int member, s3 ) { children.f(g(), member); }
```

Here is a testcase using static assert rather than if constexpr:
```
#include 

using namespace std;

template  class s3 {
public:
  template >
  static constexpr bool __usable_key = is_same_v;
  template  void f(_Args __args, int t) {
static_assert(!__usable_key<_Args>);
  }
};
struct s0 {};
struct s1 {};
s1 g();
void createMember(int member, s3 ) { children.f(g(), member); }
```

[Bug fortran/104649] ICE in gfc_match_formal_arglist, at fortran/decl.cc:6733 since r6-1958-g4668d6f9c00d4767

2023-07-09 Thread pault at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104649

--- Comment #3 from Paul Thomas  ---
(In reply to kargl from comment #2)
> Null pointer dereference.
> 
> 
> diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
> index bd586e75008..8e2cd511c4d 100644
> --- a/gcc/fortran/decl.cc
> +++ b/gcc/fortran/decl.cc
> @@ -6730,12 +6730,20 @@ ok:
> || (p->next == NULL && q->next != NULL))
>   arg_count_mismatch = true;
> else if ((p->sym == NULL && q->sym == NULL)
> - || strcmp (p->sym->name, q->sym->name) == 0)
> + || (p->sym && q->sym
> + && strcmp (p->sym->name, q->sym->name) == 0))
>   continue;
> else
> - gfc_error_now ("Mismatch in MODULE PROCEDURE formal "
> -"argument names (%s/%s) at %C",
> -p->sym->name, q->sym->name);
> + {
> +   if (q->sym)
> + gfc_error_now ("Mismatch in MODULE PROCEDURE formal "
> + "argument names (%qs/%qs) at %C",
> + p->sym->name, q->sym->name);
> +   else
> + gfc_error_now ("Mismatch in MODULE PROCEDURE formal argument "
> + "name, %qs, and alternate return at %C",
> + p->sym->name);
> + }
>   }
>  
>if (arg_count_mismatch)

The second testcase still segfaults and everything is so optimised away that I
cannot figure out why.

Paul

[Bug target/110592] [SPARC] GCC should default to TSO memory model when compiling for sparc32

2023-07-09 Thread ebotcazou at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110592

--- Comment #4 from Eric Botcazou  ---
> Note that this makes it impossible for distributions to default to sparc v7
> with an unmodified gcc.
> 
> Only options are
>  - locally patch (fix) gcc
>  - provide separate distribution binaries for v7 and v8
>  - drop support for v7 completely
> 
> ... which all three sound bad to me.

Well, you need to elaborate a bit here, because the current configuration has
been there for a quarter of century and everybody had apparently survived it
until a couple of days ago.

[PATCH] ci: Add a linux CI

2023-07-09 Thread Tal Regev via Gcc-patches
Description: adding a ci in a github repo. Everytime a user will do a PR to
master branch or releases branches, it will activate the ci on their repo.
for example: https://github.com/talregev/gcc/pull/1. Can help users to
verify their own changes before submitting a patch.

ChangeLog: Add a linux CI

Bootstrapping and testing: I tested it on linux with
host: x86_64-linux-gnu
target: x86_64-linux-gnu
some tests are failing. You can see the results in my CI yourself.

Patch: attach to this email.


linux_ci.patch
Description: Binary data


[Bug lto/110605] Possible lack of error checking in lto-common.cc ?

2023-07-09 Thread dcb314 at hotmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110605

--- Comment #3 from David Binderman  ---

Given the command line:

/home/dcb38/gcc/results.20230706.valgrind/bin/gcc cpgarro.o libpgplot.a

then I get the valgrind error. I have attached cpgarro.o, but libpgplot.a,
even with compression from xz, is 2,248,588 bytes long, so still too large.

Any hints to avoid this file size limit would be most welcome.

[Bug lto/110605] Possible lack of error checking in lto-common.cc ?

2023-07-09 Thread dcb314 at hotmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110605

--- Comment #2 from David Binderman  ---
Created attachment 55507
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55507=edit
object module

[Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110580

Andrew Pinski  changed:

   What|Removed |Added

 Ever confirmed|0   |1
   Last reconfirmed||2023-07-09
 Status|UNCONFIRMED |NEW

--- Comment #2 from Andrew Pinski  ---
Reduced un-preprocessed source:
```
#include 
#include 
#include 

struct NarMember {
  std::map children;
};
std::stack parents;
std::string_view g();
void createMember(NarMember member) {
  parents.top()->children.emplace(g(),
  std::move(member));
}
```

[Bug libstdc++/58338] Add noexcept to functions with a narrow contract

2023-07-09 Thread dangelog at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58338

Giuseppe D'Angelo  changed:

   What|Removed |Added

 CC||dangelog at gmail dot com

--- Comment #17 from Giuseppe D'Angelo  ---
Hi,

How does all of this intersect with the Lakos' Rule (cf. the very recent P2837
and P2861)? I get that implementations have the freedom of strenghtening the
noexcept contract; but is this patch following some specific libstdc++ policy
(documented somewhere) -- such as, if a precondition violation is detected,
libstdc++ just abort()s the process, so technically speaking, it never throws?

[Bug target/110606] New: [10/11/12/13/14] ICE output_operand: '%&' used without any local dynamic TLS references on powerpc64le-linux-gnu

2023-07-09 Thread doko at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110606

Bug ID: 110606
   Summary: [10/11/12/13/14] ICE output_operand: '%&' used without
any local dynamic TLS references on
powerpc64le-linux-gnu
   Product: gcc
   Version: 13.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: target
  Assignee: unassigned at gcc dot gnu.org
  Reporter: doko at gcc dot gnu.org
  Target Milestone: ---

[forwarded from https://bugs.debian.org/1040444]

seen with 10, 11, 12, 13 and trunk, building firefox. 

$ cat Unified_cpp_gfx_skia17.ii
struct SkSTArray {
  int *begin();
  int *end();
};
static void *AllocMemory();
struct IRNode {
  void *operator new(unsigned long) { return AllocMemory(); }
};
struct SwitchCase : IRNode {
  static void MakeDefault() { new SwitchCase(true, 0); }
  SwitchCase(bool, int);
};
SkSTArray __trans_tmp_3;
void inlineStatement() {
  for (int switchCaseStmt : __trans_tmp_3)
SwitchCase::MakeDefault();
}
static thread_local int *sMemPool;
int set_thread_local_memory_pool_memPool;
void detachFromThread() { sMemPool = _thread_local_memory_pool_memPool; }
long AllocMemory_size;
void *AllocMemory() {
  void *__trans_tmp_2;
  if (sMemPool) {
__trans_tmp_2 = operator new(AllocMemory_size);
return __trans_tmp_2;
  }
  void *ptr = operator new(AllocMemory_size);
  return ptr;
}

$ powerpc64le-linux-gnu-g++-13 -c Unified_cpp_gfx_skia17.ii -fno-exceptions
-fno-strict-aliasing -fPIC -O2
during RTL pass: final
Unified_cpp_gfx_skia17.ii: In function ‘void inlineStatement()’:
Unified_cpp_gfx_skia17.ii:17:1: internal compiler error: output_operand: '%&'
used without any local dynamic TLS references
   17 | }
  | ^
0xa06ff3 output_operand_lossage(char const*, ...)
../../src/gcc/final.cc:3190
0xa07373 output_operand(rtx_def*, int)
../../src/gcc/final.cc:3632
0xa07c5c output_asm_insn(char const*, rtx_def**)
../../src/gcc/final.cc:3557
0xa09517 final_scan_insn_1
../../src/gcc/final.cc:2841
0xa09a08 final_scan_insn(rtx_insn*, _IO_FILE*, int, int, int*)
../../src/gcc/final.cc:2887
0xa09c95 final_1
../../src/gcc/final.cc:1979
0xa0a4a6 rest_of_handle_final
../../src/gcc/final.cc:4240
0xa0a4a6 execute
../../src/gcc/final.cc:4318
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.


Configured with: ../src/configure -v --with-pkgversion='Debian 13.1.0-6'
--with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2,rust --prefix=/usr
--with-gcc-major-version-only --program-suffix=-13 --enable-shared
--enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext
--enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/
--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--without-target-system-zlib --with-libphobos-druntime-only=yes
--enable-secureplt --enable-targets=powerpcle-linux --disable-multilib
--enable-multiarch --disable-werror --with-long-double-128
--enable-offload-targets=nvptx-none=/build/gcc-13-cross-pG4N37/gcc-13-cross-6/gcc/debian/tmp-nvptx/usr
--enable-offload-defaulted --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=powerpc64le-linux-gnu
--program-prefix=powerpc64le-linux-gnu-
--includedir=/usr/powerpc64le-linux-gnu/include
--with-build-config=bootstrap-lto-lean --enable-link-serialization=2

[Bug tree-optimization/110603] [14 Regression] GCC, ICE: internal compiler error: in verify_range, at value-range.cc:1104

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110603

Andrew Pinski  changed:

   What|Removed |Added

Summary|GCC, ICE: internal compiler |[14 Regression] GCC, ICE:
   |error: in verify_range, at  |internal compiler error: in
   |value-range.cc:1104 |verify_range, at
   ||value-range.cc:1104
   Keywords||ice-on-valid-code
   Target Milestone|--- |14.0
  Component|c   |tree-optimization

[Bug lto/110605] Possible lack of error checking in lto-common.cc ?

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110605

--- Comment #1 from Andrew Pinski  ---
most likely not a big issue of not checking the return value here as the next
fscanf that is the first thing inside the loop around num_symbols .

[Bug lto/110605] New: Possible lack of error checking in lto-common.cc ?

2023-07-09 Thread dcb314 at hotmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110605

Bug ID: 110605
   Summary: Possible lack of error checking in lto-common.cc ?
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: lto
  Assignee: unassigned at gcc dot gnu.org
  Reporter: dcb314 at hotmail dot com
CC: marxin at gcc dot gnu.org
  Target Milestone: ---

I am investigating a valgrind error in the lto code:

==910546== Conditional jump or move depends on uninitialised value(s)
==910546==at 0x71DF70: lto_resolution_read (lto-common.cc:2126)
==910546==by 0x71DF70: lto_file_read (lto-common.cc:2351)
==910546==by 0x71DF70: read_cgraph_and_symbols(unsigned int, char const**)
(lto-common.cc:2805)
==910546==by 0x706FA9: lto_main() (lto.cc:654)
==910546==by 0xCE0F39: compile_file() (toplev.cc:444)
==910546==by 0x6C26F9: do_compile (toplev.cc:2126)
==910546==by 0x6C26F9: toplev::main(int, char**) (toplev.cc:2282)
==910546==by 0x6C3FDA: main (main.cc:39)

The line 2126 is

^d4ba3b369 (Jonathan Wakely  2022-11-01 09:48:41 + 2126)  if
(strcmp (lto_resolution_str[j], r_str) == 0)

I had a look around and I noticed just before this is:

^d4ba3b369 (Jonathan Wakely  2022-11-01 09:48:41 + 2106)   fscanf
(resolution, "%u", _symbols);

It has no error checking. I think this will produce a warning with
-D_FORTIFY_SOURCE=1.

I can't prove the lack of error checking on the fscanf line is related to
my valgrind problem, but it does look suspicious. Suggest fix.

[Bug target/54089] [SH] Refactor shift patterns

2023-07-09 Thread olegendo at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54089

Oleg Endo  changed:

   What|Removed |Added

  Attachment #28207|0   |1
is obsolete||
  Attachment #28633|0   |1
is obsolete||

--- Comment #99 from Oleg Endo  ---
Created attachment 55506
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55506=edit
proposed patch

(In reply to Alexander Klepikov from comment #98)
> Created attachment 55503 [details]
> Testcase for SH specific loop optimization pass
> 

Thanks.  I'll check it out.
Meanwhile, here's my iteration on your patch.

[Bug c++/110604] New: template argument deduction failed with decltype(lambda)

2023-07-09 Thread ted at lyncon dot se via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110604

Bug ID: 110604
   Summary: template argument deduction failed with
decltype(lambda)
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: ted at lyncon dot se
  Target Milestone: ---

Compiling this in C++20 mode on trunk (https://godbolt.org/z/dW5cf3WrK):
```
template
struct foo {
template
void bar() {}
};

int main() {
[[maybe_unused]] auto v = foo();

v.bar<>();
v.bar();
}
```
Results in the following error:
```
: In function 'int main()':
:10:12: error: no matching function for call to 'foo::bar<>()'
   10 | v.bar<>();
  | ~~~^~
:4:10: note: candidate: 'template void foo<
 >::bar() [with  = void]'
4 | void bar() {}
  |  ^~~
:4:10: note:   template argument deduction/substitution failed:
:11:10: error: no matching function for call to 'foo::bar()'
   11 | v.bar();
  | ~^~
:4:10: note: candidate: 'template void foo<
 >::bar() [with  = void]'
4 | void bar() {}
  |  ^~~
:4:10: note:   template argument deduction/substitution failed:
```
Possibly a duplicate of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102721,
but I'm not 100% sure.

Improve dumping of profile_count

2023-07-09 Thread Jan Hubicka via Gcc-patches
Hi,
dumps of profile_counts are quite hard to interpret since they are 64bit fixed 
point
values.  In many cases one looks at a single function and it is better to think 
of
basic block frequency, that is how many times it is executed each invocatoin. 
This
patch makes CFG dumps to also print this info.

For example:
main()
{
for (int i = 0; i < 10; i++)
t();
}

the -fdump-tree-optimized-blocks-details now prints:
int main ()
{
  unsigned int ivtmp_1;
  unsigned int ivtmp_2;

;;   basic block 2, loop depth 0, count 97603128 (estimated locally, freq 
1.), maybe hot
;;prev block 0, next block 3, flags: (NEW, VISITED)
;;pred:   ENTRY [always]  count:97603128 (estimated locally, freq 
1.) (FALLTHRU,EXECUTABLE)
;;succ:   3 [always]  count:97603128 (estimated locally, freq 1.) 
(FALLTHRU,EXECUTABLE)

;;   basic block 3, loop depth 1, count 976138697 (estimated locally, freq 
10.0011), maybe hot
;;prev block 2, next block 4, flags: (NEW, VISITED)
;;pred:   3 [90.0% (guessed)]  count:878535568 (estimated locally, freq 
9.0011) (TRUE_VALUE,EXECUTABLE)
;;2 [always]  count:97603128 (estimated locally, freq 1.) 
(FALLTHRU,EXECUTABLE)
  # ivtmp_2 = PHI 
  t ();
  ivtmp_1 = ivtmp_2 + 4294967295;
  if (ivtmp_1 != 0)
goto ; [90.00%]
  else
goto ; [10.00%]
;;succ:   3 [90.0% (guessed)]  count:878535568 (estimated locally, freq 
9.0011) (TRUE_VALUE,EXECUTABLE)
;;4 [10.0% (guessed)]  count:97603129 (estimated locally, freq 
1.) (FALSE_VALUE,EXECUTABLE)

;;   basic block 4, loop depth 0, count 97603128 (estimated locally, freq 
1.), maybe hot
;;prev block 3, next block 1, flags: (NEW, VISITED)
;;pred:   3 [10.0% (guessed)]  count:97603129 (estimated locally, freq 
1.) (FALSE_VALUE,EXECUTABLE)
  return 0;
;;succ:   EXIT [always]  count:97603128 (estimated locally, freq 
1.) (EXECUTABLE)

}

Which makes it easier to see that the inner bb is executed 10 times per 
invocation


gcc/ChangeLog:

* cfg.cc (check_bb_profile): Dump counts with relative frequency.
(dump_edge_info): Likewise.
(dump_bb_info): Likewise.
* profile-count.cc (profile_count::dump): Add comma between quality and
freq.

gcc/testsuite/ChangeLog:

* gcc.dg/predict-22.c: Update template.

diff --git a/gcc/cfg.cc b/gcc/cfg.cc
index 740d4f3581d..0de6d6b9e71 100644
--- a/gcc/cfg.cc
+++ b/gcc/cfg.cc
@@ -475,9 +475,9 @@ check_bb_profile (basic_block bb, FILE * file, int indent)
{
  fprintf (file, ";; %sInvalid sum of incoming counts ",
   s_indent);
- sum.dump (file);
+ sum.dump (file, fun);
  fprintf (file, ", should be ");
- bb->count.dump (file);
+ bb->count.dump (file, fun);
  fprintf (file, "\n");
}
 }
@@ -525,7 +525,7 @@ dump_edge_info (FILE *file, edge e, dump_flags_t flags, int 
do_succ)
   if (e->count ().initialized_p () && do_details)
 {
   fputs (" count:", file);
-  e->count ().dump (file);
+  e->count ().dump (file, cfun);
 }
 
   if (e->flags && do_details)
@@ -808,7 +808,7 @@ dump_bb_info (FILE *outf, basic_block bb, int indent, 
dump_flags_t flags,
  if (bb->count.initialized_p ())
{
  fputs (", count ", outf);
- bb->count.dump (outf);
+ bb->count.dump (outf, cfun);
}
  if (maybe_hot_bb_p (fun, bb))
fputs (", maybe hot", outf);
diff --git a/gcc/profile-count.cc b/gcc/profile-count.cc
index 6bf9700d8db..2c07ebc5942 100644
--- a/gcc/profile-count.cc
+++ b/gcc/profile-count.cc
@@ -94,7 +94,7 @@ profile_count::dump (char *buffer, struct function *fun) const
   else if (fun && initialized_p ()
   && fun->cfg
   && ENTRY_BLOCK_PTR_FOR_FN (fun)->count.initialized_p ())
-sprintf (buffer, "%" PRId64 " (%s freq %.4f)", m_val,
+sprintf (buffer, "%" PRId64 " (%s, freq %.4f)", m_val,
 profile_quality_display_names[m_quality],
 to_sreal_scale (ENTRY_BLOCK_PTR_FOR_FN (fun)->count).to_double ());
   else
diff --git a/gcc/testsuite/gcc.dg/predict-22.c 
b/gcc/testsuite/gcc.dg/predict-22.c
index f14c2b68861..1aed03fae79 100644
--- a/gcc/testsuite/gcc.dg/predict-22.c
+++ b/gcc/testsuite/gcc.dg/predict-22.c
@@ -55,5 +55,5 @@ foo (int x, int y, int z)
   baz ();
 }
 /* { dg-final { scan-tree-dump-times "Invalid sum" 0 "optimized"} } */
-/* { dg-final { scan-tree-dump-times "count 0 .precise.," 1 "optimized"} } */
+/* { dg-final { scan-tree-dump-times "count 0 .precise" 1 "optimized"} } */
 /* { dg-final { scan-rtl-dump-times "COLD_PARTITION" 1 "bbpart"} } */


Re: [PATCH 1/2] c++, libstdc++: implement __is_arithmetic built-in trait

2023-07-09 Thread Ken Matsui via Gcc-patches
Hi,

Here is the benchmark result for is_arithmetic:

https://github.com/ken-matsui/gcc-benches/blob/main/is_arithmetic.md#sun-jul--9-055758-am-pdt-2023

Time: -55.2631%
Peak Memory Usage: -38.7701%
Total Memory Usage: -40.5237%

Sincerely,
Ken Matsui

On Sun, Jul 9, 2023 at 5:57 AM Ken Matsui  wrote:
>
> This patch implements built-in trait for std::is_arithmetic.
>
> gcc/cp/ChangeLog:
>
> * cp-trait.def: Define __is_arithmetic.
> * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_ARITHMETIC.
> * semantics.cc (trait_expr_value): Likewise.
> (finish_trait_expr): Likewise.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/ext/has-builtin-1.C: Test existence of __is_arithmetic.
> * g++.dg/ext/is_arithmetic.C: New test.
> * g++.dg/tm/pr46567.C (__is_arithmetic): Rename to ...
> (is_arithmetic): ... this.
> * g++.dg/torture/pr57107.C: Likewise.
>
> libstdc++-v3/ChangeLog:
>
> * include/bits/cpp_type_traits.h (__is_arithmetic): Rename to ...
> (is_arithmetic): ... this.
> * include/c_global/cmath: Use is_arithmetic instead.
> * include/c_std/cmath: Likewise.
> * include/tr1/cmath: Likewise.
>
> Signed-off-by: Ken Matsui 
> ---
>  gcc/cp/constraint.cc|  3 ++
>  gcc/cp/cp-trait.def |  1 +
>  gcc/cp/semantics.cc |  4 ++
>  gcc/testsuite/g++.dg/ext/has-builtin-1.C|  3 ++
>  gcc/testsuite/g++.dg/ext/is_arithmetic.C| 33 ++
>  gcc/testsuite/g++.dg/tm/pr46567.C   |  6 +--
>  gcc/testsuite/g++.dg/torture/pr57107.C  |  4 +-
>  libstdc++-v3/include/bits/cpp_type_traits.h |  4 +-
>  libstdc++-v3/include/c_global/cmath | 48 ++---
>  libstdc++-v3/include/c_std/cmath| 24 +--
>  libstdc++-v3/include/tr1/cmath  | 24 +--
>  11 files changed, 99 insertions(+), 55 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/ext/is_arithmetic.C
>
> diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
> index 8cf0f2d0974..bd517d08843 100644
> --- a/gcc/cp/constraint.cc
> +++ b/gcc/cp/constraint.cc
> @@ -3754,6 +3754,9 @@ diagnose_trait_expr (tree expr, tree args)
>  case CPTK_IS_AGGREGATE:
>inform (loc, "  %qT is not an aggregate", t1);
>break;
> +case CPTK_IS_ARITHMETIC:
> +  inform (loc, "  %qT is not an arithmetic type", t1);
> +  break;
>  case CPTK_IS_TRIVIALLY_COPYABLE:
>inform (loc, "  %qT is not trivially copyable", t1);
>break;
> diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
> index 8b7fece0cc8..a95aeeaf778 100644
> --- a/gcc/cp/cp-trait.def
> +++ b/gcc/cp/cp-trait.def
> @@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, 
> "__is_trivially_assignable", 2)
>  DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", 
> -1)
>  DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
>  DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
> +DEFTRAIT_EXPR (IS_ARITHMETIC, "__is_arithmetic", 1)
>  DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, 
> "__reference_constructs_from_temporary", 2)
>  DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, 
> "__reference_converts_from_temporary", 2)
>  /* FIXME Added space to avoid direct usage in GCC 13.  */
> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
> index 8fb47fd179e..4531f047d73 100644
> --- a/gcc/cp/semantics.cc
> +++ b/gcc/cp/semantics.cc
> @@ -12118,6 +12118,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, 
> tree type2)
>  case CPTK_IS_UNION:
>return type_code1 == UNION_TYPE;
>
> +case CPTK_IS_ARITHMETIC:
> +  return ARITHMETIC_TYPE_P (type1);
> +
>  case CPTK_IS_ASSIGNABLE:
>return is_xible (MODIFY_EXPR, type1, type2);
>
> @@ -12296,6 +12299,7 @@ finish_trait_expr (location_t loc, cp_trait_kind 
> kind, tree type1, tree type2)
>  case CPTK_IS_ENUM:
>  case CPTK_IS_UNION:
>  case CPTK_IS_SAME:
> +case CPTK_IS_ARITHMETIC:
>break;
>
>  case CPTK_IS_LAYOUT_COMPATIBLE:
> diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C 
> b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> index f343e153e56..3d63b0101d1 100644
> --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> @@ -146,3 +146,6 @@
>  #if !__has_builtin (__remove_cvref)
>  # error "__has_builtin (__remove_cvref) failed"
>  #endif
> +#if !__has_builtin (__is_arithmetic)
> +# error "__has_builtin (__is_arithmetic) failed"
> +#endif
> diff --git a/gcc/testsuite/g++.dg/ext/is_arithmetic.C 
> b/gcc/testsuite/g++.dg/ext/is_arithmetic.C
> new file mode 100644
> index 000..fd35831f646
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/ext/is_arithmetic.C
> @@ -0,0 +1,33 @@
> +// { dg-do compile { target c++11 } }
> +
> +#include 
> +
> +using namespace __gnu_test;
> +
> +#define SA(X) static_assert((X),#X)
> +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT)  \
> +  

[Bug target/110592] [SPARC] GCC should default to TSO memory model when compiling for sparc32

2023-07-09 Thread martin at netbsd dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110592

Martin Husemann  changed:

   What|Removed |Added

 CC||martin at netbsd dot org

--- Comment #3 from Martin Husemann  ---
Note that this makes it impossible for distributions to default to sparc v7
with an unmodified gcc.

Only options are
 - locally patch (fix) gcc
 - provide separate distribution binaries for v7 and v8
 - drop support for v7 completely

... which all three sound bad to me.

[PATCH 2/2] libstdc++: use new built-in trait __is_arithmetic

2023-07-09 Thread Ken Matsui via Gcc-patches
This patch lets libstdc++ use new built-in trait __is_arithmetic.

libstdc++-v3/ChangeLog:

* include/std/type_traits (is_arithmetic): Use __is_arithmetic
built-in trait.
(is_arithmetic_v): Likewise.

Signed-off-by: Ken Matsui 
---
 libstdc++-v3/include/std/type_traits | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index 0e7a9c9c7f3..7ebbe04c77b 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -655,10 +655,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { };
 
   /// is_arithmetic
+#if __has_builtin(__is_arithmetic)
+  template
+struct is_arithmetic
+: public __bool_constant<__is_arithmetic(_Tp)>
+{ };
+#else
   template
 struct is_arithmetic
 : public __or_, is_floating_point<_Tp>>::type
 { };
+#endif
 
   /// is_fundamental
   template
@@ -3198,8 +3205,15 @@ template 
   inline constexpr bool is_reference_v<_Tp&> = true;
 template 
   inline constexpr bool is_reference_v<_Tp&&> = true;
+
+#if __has_builtin(__is_arithmetic)
+template 
+  inline constexpr bool is_arithmetic_v = __is_arithmetic(_Tp);
+#else
 template 
   inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
+#endif
+
 template 
   inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
 template 
-- 
2.41.0



☠ Buildbot (Sourceware): gccrust - failed 'grep unexpected ...' (failure) (master)

2023-07-09 Thread builder--- via Gcc-rust
A failed build has been detected on builder gccrust-gentoo-sparc while building 
gccrust.

Full details are available at:
https://builder.sourceware.org/buildbot/#builders/241/builds/818

Build state: failed 'grep unexpected ...' (failure)
Revision: e74cb8201fd0c239607ab598ca1cef266ddd0f61
Worker: gentoo-sparc-big
Build Reason: (unknown)
Blamelist: A. Wilcox , Abdul Rafey 
, Alan Modra , Aldy Hernandez 
, Alex Coplan , Alexander Monakov 
, Alexandre Oliva , Alexandre Oliva 
, Allan McRae , Andre Simoes Dias Vieira 
, Andre Vehreschild , Andre 
Vieira , Andrea Corallo 
, Andreas Krebbel , Andreas 
Schwab , Andreas Schwab , Andrew 
Carlotti , Andrew Carlotti , 
Andrew Jenner , Andrew MacLeod , 
Andrew Pinski , Andrew Pinski , Andrew 
Stubbs , Anthony Green , Antoni 
Boucher , Ard Biesheuvel , Arjun Shankar 
, Arnaud Charlet , Arsen Arsenovic 
, Arsen Arsenović , ArshErgon 
, Artem Klimov , Arthur Cohen 
, Avinash Sonawane , Benno Evers 
, Benson Muite , Bernd 
Kuhls , Bernhard Reutner-Fischer , 
Bernhard Reutner-Fischer , Bill Schmidt 
, Bill Seurer , Björn Schäpers 
, Bob Duff , Boris Yakobowski 
, Bruce Korb , Bruno Haible 
, Cedric Landet , Cesar Philippidis 
, Charalampos Mitrodimas , 
Charles-François Natali , Chenghua Xu 
, Chenghua Xu , Christoph 
Müllner , Christophe Lyon 
, Christophe Lyon , 
Chung-Ju Wu , Chung-Lin Tang , 
Claire Dross , Claudiu Zissulescu , 
Claudiu Zissulescu , Clément Chigot , 
Clément Chigot , CohenArthur , 
Costas Argyris , Cui,Lili , 
Cupertino Miranda , Dan Li 
, Daniel Mercier , Dave 
, Dave Evans , David Edelsohn 
, David Faust , David Malcolm 
, David Seifert , Detlef Vollmann 
, Dimitar Dimitrov , Dimitrij Mijoski 
, Dimitrije Milosevic , 
Dimitrije Milošević , Dmitriy Anisimkov 
, Dongsheng Song , Doug Rupp 
, Ed Catmur , Ed Schonberg 
, Ed Smith-Rowland , Emanuele 
Micheletti , Eric Biggers 
, Eric Botcazou , Eric Botcazou 
, Eric Gallager , Etienne Servais 
, Eugene Rozenfeld , Faisal Abbas 
<90.abbasfai...@gmail.com>, Faisal Abbas , Fedor 
Rybin , Fei Gao , Flavio Cruz 
, Florian Weimer , Francois-Xavier 
Coudert , Francois-Xavier Coudert , 
François Dumont , Frederik Harwath 
, Fritz Reese , Frolov Daniil 
, GCC Administrator , Gaius 
Mulley , Gary Dismukes , 
Georg-Johann Lay , Gerald Pfeifer , Ghjuvan 
Lacambre , Giuliano Belinassi , 
Guillaume Gomez , Guillermo E. Martinez 
, H.J. Lu , Hafiz Abid 
Qadeer , Hans-Peter Nilsson , Haochen 
Gui , Haochen Jiang , Harald 
Anlauf , Hongyu Wang , Hu, Lin1 
, Iain Buclaw , Iain Sandoe 
, Ian Lance Taylor , Ilya Leoshkevich 
, Immad Mir , Immad Mir 
, Indu Bhagat , Iskander 
Shakirzyanov , Jakob Hasse 
<0xja...@users.noreply.github.com>, Jakub Dupak , Jakub 
Jelinek , Jan Beulich , Jan Hubicka 
, Jan-Benedict Glaw , Jason Merrill 
, Javier Miranda , Jeff Chapman II 
, Jeff Law , Jeff Law 
, Jeff Law , Jerry DeLisle 
, Jia-Wei Chen , Jia-wei Chen 
, Jiakun Fan <120090...@link.cuhk.edu.cn>, Jiawei 
, Jin Ma , Jinyang He 
, Jiufu Guo , Joao Azevedo 
, Joel Brobecker , Joel Holdsworth 
, Joel Phillips , Joel 
Teichroeb , Joffrey Huguet , Johannes 
Kanig , Johannes Kliemann , John David 
Anglin , Jonathan Grant , Jonathan Wakely 
, Jonathan Yong <10wa...@gmail.com>, Jonny Grant 
, Jose E. Marchesi , Joseph Myers 
, Josue Nava Bello , José Rui 
Faustino de Sousa , Ju-Zhe Zhong , 
Julia Lapenko , Julian Brown 
, Julien Bortolussi , Junxian 
Zhu , Justin Squirek , 
Juzhe-Zhong , Jørgen Kvalsvik 
, Keef Aragon , 
Kewen Lin , Kewen.Lin , Kim Kuparinen 
, Kito Cheng , Kong 
Lingling , Kwok Cheung Yeung , 
Kyrylo Tkachov , Kévin Le Gouguec 
, LIU Hao , Lewis Hyatt 
, Li Xu , Liaiss Merzougue 
, Liao Shihua , LiaoShihua 
, Lili Cui , Lin Sinan 
, Lin Sinan , Liwei Xu 
, Lorenzo Salvadore , Lulu 
Cheng , Lyra , M V V S Manoj Kumar 
, MAHAD , Maciej W. Rozycki 
, Maciej W. Rozycki , Mahmoud Mohamed 
, Marc Nieper-Wißkirchen , 
Marc Poulhiès , Marc Poulhiès , Marcel 
Vollweiler , Marco Falke , 
Marek Polacek , Mark Mentovai , Mark 
Wielaard , Martin Jambor , Martin Liska 
, Martin Liška , Martin Sebor 
, Martin Uecker , Matthew Jasper 
, Matthias Kretz , Max Filippov 
, Mayshao , Meghan Denny 
, Michael Collison , Michael Eager 
, Michael Meissner , Mikael Morin 
, Mikhail Ablakatov , Monk Chiang 
, Muhammad Mahad , Murray Steele 
, Nathan Sidwell , Nathaniel Shead 
, Navid Rahimi , Nick 
Clifton , Nikos Alexandris , 
Nirmal Patel , Olivier Hainque , Owen 
Avery , Palmer Dabbelt , Pan 
Li , Parthib <94271200+parthib...@users.noreply.github.com>, 
Parthib , Pascal Obry , Pat Haugen 
, Patrick Bernardi , Patrick 
Palka , Paul A. Clarke , Paul Thomas 
, Paul-Antoine Arras , Pekka Seppänen 
, Peter Bergner , Peter Foley 
, Petter Tomner , Philip Herron 
, Philip Herron , 
Philipp Fent , Philipp Tomsich , 
Pierre-Emmanuel Patry , Pierre-Marie de 
Rodat , Piotr Trojanek , Prajwal S N 
, Prathamesh Kulkarni 
, Przemyslaw Wirkus 
, Qian Jianhua , Qian Jianhua 
, Qing Zhao , Quentin Ochem 
, Raiki Tamura , Rainer Orth 
, Rainer Orth , Ramana 

[PATCH 1/2] c++, libstdc++: implement __is_arithmetic built-in trait

2023-07-09 Thread Ken Matsui via Gcc-patches
This patch implements built-in trait for std::is_arithmetic.

gcc/cp/ChangeLog:

* cp-trait.def: Define __is_arithmetic.
* constraint.cc (diagnose_trait_expr): Handle CPTK_IS_ARITHMETIC.
* semantics.cc (trait_expr_value): Likewise.
(finish_trait_expr): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/ext/has-builtin-1.C: Test existence of __is_arithmetic.
* g++.dg/ext/is_arithmetic.C: New test.
* g++.dg/tm/pr46567.C (__is_arithmetic): Rename to ...
(is_arithmetic): ... this.
* g++.dg/torture/pr57107.C: Likewise.

libstdc++-v3/ChangeLog:

* include/bits/cpp_type_traits.h (__is_arithmetic): Rename to ...
(is_arithmetic): ... this.
* include/c_global/cmath: Use is_arithmetic instead.
* include/c_std/cmath: Likewise.
* include/tr1/cmath: Likewise.

Signed-off-by: Ken Matsui 
---
 gcc/cp/constraint.cc|  3 ++
 gcc/cp/cp-trait.def |  1 +
 gcc/cp/semantics.cc |  4 ++
 gcc/testsuite/g++.dg/ext/has-builtin-1.C|  3 ++
 gcc/testsuite/g++.dg/ext/is_arithmetic.C| 33 ++
 gcc/testsuite/g++.dg/tm/pr46567.C   |  6 +--
 gcc/testsuite/g++.dg/torture/pr57107.C  |  4 +-
 libstdc++-v3/include/bits/cpp_type_traits.h |  4 +-
 libstdc++-v3/include/c_global/cmath | 48 ++---
 libstdc++-v3/include/c_std/cmath| 24 +--
 libstdc++-v3/include/tr1/cmath  | 24 +--
 11 files changed, 99 insertions(+), 55 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/is_arithmetic.C

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 8cf0f2d0974..bd517d08843 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3754,6 +3754,9 @@ diagnose_trait_expr (tree expr, tree args)
 case CPTK_IS_AGGREGATE:
   inform (loc, "  %qT is not an aggregate", t1);
   break;
+case CPTK_IS_ARITHMETIC:
+  inform (loc, "  %qT is not an arithmetic type", t1);
+  break;
 case CPTK_IS_TRIVIALLY_COPYABLE:
   inform (loc, "  %qT is not trivially copyable", t1);
   break;
diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
index 8b7fece0cc8..a95aeeaf778 100644
--- a/gcc/cp/cp-trait.def
+++ b/gcc/cp/cp-trait.def
@@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, 
"__is_trivially_assignable", 2)
 DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1)
 DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
 DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
+DEFTRAIT_EXPR (IS_ARITHMETIC, "__is_arithmetic", 1)
 DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, 
"__reference_constructs_from_temporary", 2)
 DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, 
"__reference_converts_from_temporary", 2)
 /* FIXME Added space to avoid direct usage in GCC 13.  */
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 8fb47fd179e..4531f047d73 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12118,6 +12118,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree 
type2)
 case CPTK_IS_UNION:
   return type_code1 == UNION_TYPE;
 
+case CPTK_IS_ARITHMETIC:
+  return ARITHMETIC_TYPE_P (type1);
+
 case CPTK_IS_ASSIGNABLE:
   return is_xible (MODIFY_EXPR, type1, type2);
 
@@ -12296,6 +12299,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, 
tree type1, tree type2)
 case CPTK_IS_ENUM:
 case CPTK_IS_UNION:
 case CPTK_IS_SAME:
+case CPTK_IS_ARITHMETIC:
   break;
 
 case CPTK_IS_LAYOUT_COMPATIBLE:
diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C 
b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
index f343e153e56..3d63b0101d1 100644
--- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
+++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
@@ -146,3 +146,6 @@
 #if !__has_builtin (__remove_cvref)
 # error "__has_builtin (__remove_cvref) failed"
 #endif
+#if !__has_builtin (__is_arithmetic)
+# error "__has_builtin (__is_arithmetic) failed"
+#endif
diff --git a/gcc/testsuite/g++.dg/ext/is_arithmetic.C 
b/gcc/testsuite/g++.dg/ext/is_arithmetic.C
new file mode 100644
index 000..fd35831f646
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_arithmetic.C
@@ -0,0 +1,33 @@
+// { dg-do compile { target c++11 } }
+
+#include 
+
+using namespace __gnu_test;
+
+#define SA(X) static_assert((X),#X)
+#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT)  \
+  SA(TRAIT(TYPE) == EXPECT);   \
+  SA(TRAIT(const TYPE) == EXPECT); \
+  SA(TRAIT(volatile TYPE) == EXPECT);  \
+  SA(TRAIT(const volatile TYPE) == EXPECT)
+
+SA_TEST_CATEGORY(__is_arithmetic, void, false);
+
+SA_TEST_CATEGORY(__is_arithmetic, char, true);
+SA_TEST_CATEGORY(__is_arithmetic, signed char, true);
+SA_TEST_CATEGORY(__is_arithmetic, unsigned char, true);
+SA_TEST_CATEGORY(__is_arithmetic, wchar_t, true);
+SA_TEST_CATEGORY(__is_arithmetic, short, 

[Bug c/110603] New: GCC, ICE: internal compiler error: in verify_range, at value-range.cc:1104

2023-07-09 Thread 141242068 at smail dot nju.edu.cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110603

Bug ID: 110603
   Summary: GCC, ICE: internal compiler error: in verify_range, at
value-range.cc:1104
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: 141242068 at smail dot nju.edu.cn
  Target Milestone: ---

The testing program:
```
typedef long unsigned int size_t;
void *memcpy(void *, const void *, size_t);
int snprintf(char *restrict, size_t, const char *restrict, ...);

extern char a[2];
void test_func_on_line_62(void) {
  memcpy(a, "12", sizeof("12") - 1);
  const int res = snprintf(0, 0, "%s", a);
  if (res <= 3)
do {
  extern void f(void);
  f();
} while (0);
}
```

When attempting to compile it with `gcc-14 -O2 small.c`, gcc-14 crashes:
```
during GIMPLE pass: strlen
: In function 'test_func_on_line_62':
:6:6: internal compiler error: in verify_range, at value-range.cc:1104
6 | void test_func_on_line_62(void) {
  |  ^~~~
0x213b0ee internal_error(char const*, ...)
???:0
0x9ca9f8 fancy_abort(char const*, int, char const*)
???:0
0x13df0f7 irange::set(tree_node*, generic_wide_int const&,
generic_wide_int const&, value_range_kind)
???:0
0x1e24a5d handle_printf_call(gimple_stmt_iterator*, pointer_query&)
???:0
0x12d3d86 strlen_pass::check_and_optimize_call(bool*)
???:0
0x12d4109 strlen_pass::check_and_optimize_stmt(bool*)
???:0
0x12d4494 strlen_pass::before_dom_children(basic_block_def*)
???:0
0x1d98997 dom_walker::walk(basic_block_def*)
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
```

This crash can be verified at https://gcc.godbolt.org/z/439GM47z9

[Bug libstdc++/110602] std::format and friends are accessible without std::

2023-07-09 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110602

--- Comment #4 from Jonathan Wakely  ---
(In reply to kefu chai from comment #0)
> i also tested clang + libstdc++ and clang + libc++. all of these
> combinations compiles.

That's usually a sign the code is valid.

[Bug rtl-optimization/110206] [14 Regression] wrong code with -Os -march=cascadelake since r14-1246

2023-07-09 Thread ubizjak at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110206

Uroš Bizjak  changed:

   What|Removed |Added

   Keywords|needs-bisection |
   Assignee|unassigned at gcc dot gnu.org  |ubizjak at gmail dot com
 Status|NEW |ASSIGNED

--- Comment #11 from Uroš Bizjak  ---
Patch at [1].

[1] https://gcc.gnu.org/pipermail/gcc-patches/2023-July/623933.html

Re: [PATCH 1/2] c++, libstdc++: implement __is_signed built-in trait

2023-07-09 Thread Ken Matsui via Gcc-patches
Hi,

Here is the benchmark result for is_signed:

https://github.com/ken-matsui/gcc-benches/blob/main/is_signed.md#sun-jul--9-014707-am-pdt-2023

Time: -59.439%
Peak Memory Usage: -38.5157%
Total Memory Usage: -41.687%

Sincerely,
Ken Matsui

On Sun, Jul 9, 2023 at 1:47 AM Ken Matsui  wrote:
>
> This patch implements built-in trait for std::is_signed.
>
> gcc/cp/ChangeLog:
>
> * cp-trait.def: Define __is_signed.
> * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SIGNED.
> * semantics.cc (trait_expr_value): Likewise.
> (finish_trait_expr): Likewise.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/ext/has-builtin-1.C: Test existence of __is_signed.
> * g++.dg/ext/is_signed.C: New test.
> * g++.dg/tm/pr46567.C (__is_signed): Rename to ...
> (is_signed): ... this.
>
> libstdc++-v3/ChangeLog:
>
> * include/ext/numeric_traits.h (__is_signed): Rename to ...
> (is_signed): ... this.
> * include/bits/charconv.h: Use is_signed instead.
> * include/bits/locale_facets.tcc: Likewise.
> * include/bits/uniform_int_dist.h: Likewise.
>
> Signed-off-by: Ken Matsui 
> ---
>  gcc/cp/constraint.cc |  3 ++
>  gcc/cp/cp-trait.def  |  1 +
>  gcc/cp/semantics.cc  |  4 ++
>  gcc/testsuite/g++.dg/ext/has-builtin-1.C |  3 ++
>  gcc/testsuite/g++.dg/ext/is_signed.C | 47 
>  gcc/testsuite/g++.dg/tm/pr46567.C| 12 ++---
>  libstdc++-v3/include/bits/charconv.h |  2 +-
>  libstdc++-v3/include/bits/locale_facets.tcc  |  6 +--
>  libstdc++-v3/include/bits/uniform_int_dist.h |  4 +-
>  libstdc++-v3/include/ext/numeric_traits.h| 18 
>  10 files changed, 79 insertions(+), 21 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/ext/is_signed.C
>
> diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
> index 8cf0f2d0974..73fcbfe39e8 100644
> --- a/gcc/cp/constraint.cc
> +++ b/gcc/cp/constraint.cc
> @@ -3751,6 +3751,9 @@ diagnose_trait_expr (tree expr, tree args)
>  case CPTK_IS_UNION:
>inform (loc, "  %qT is not a union", t1);
>break;
> +case CPTK_IS_SIGNED:
> +  inform (loc, "  %qT is not a signed type", t1);
> +  break;
>  case CPTK_IS_AGGREGATE:
>inform (loc, "  %qT is not an aggregate", t1);
>break;
> diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
> index 8b7fece0cc8..576d5528d05 100644
> --- a/gcc/cp/cp-trait.def
> +++ b/gcc/cp/cp-trait.def
> @@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, 
> "__is_trivially_assignable", 2)
>  DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", 
> -1)
>  DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
>  DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
> +DEFTRAIT_EXPR (IS_SIGNED, "__is_signed", 1)
>  DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, 
> "__reference_constructs_from_temporary", 2)
>  DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, 
> "__reference_converts_from_temporary", 2)
>  /* FIXME Added space to avoid direct usage in GCC 13.  */
> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
> index 8fb47fd179e..17aad992f96 100644
> --- a/gcc/cp/semantics.cc
> +++ b/gcc/cp/semantics.cc
> @@ -12118,6 +12118,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, 
> tree type2)
>  case CPTK_IS_UNION:
>return type_code1 == UNION_TYPE;
>
> +case CPTK_IS_SIGNED:
> +  return ARITHMETIC_TYPE_P (type1) && TYPE_SIGN (type1) == SIGNED;
> +
>  case CPTK_IS_ASSIGNABLE:
>return is_xible (MODIFY_EXPR, type1, type2);
>
> @@ -12296,6 +12299,7 @@ finish_trait_expr (location_t loc, cp_trait_kind 
> kind, tree type1, tree type2)
>  case CPTK_IS_ENUM:
>  case CPTK_IS_UNION:
>  case CPTK_IS_SAME:
> +case CPTK_IS_SIGNED:
>break;
>
>  case CPTK_IS_LAYOUT_COMPATIBLE:
> diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C 
> b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> index f343e153e56..a43202d0d59 100644
> --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> @@ -146,3 +146,6 @@
>  #if !__has_builtin (__remove_cvref)
>  # error "__has_builtin (__remove_cvref) failed"
>  #endif
> +#if !__has_builtin (__is_signed)
> +# error "__has_builtin (__is_signed) failed"
> +#endif
> diff --git a/gcc/testsuite/g++.dg/ext/is_signed.C 
> b/gcc/testsuite/g++.dg/ext/is_signed.C
> new file mode 100644
> index 000..a04b548105d
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/ext/is_signed.C
> @@ -0,0 +1,47 @@
> +// { dg-do compile { target c++11 } }
> +
> +#include 
> +
> +using namespace __gnu_test;
> +
> +#define SA(X) static_assert((X),#X)
> +#define SA_TEST_CATEGORY(TRAIT, X, expect) \
> +  SA(TRAIT(X) == expect);  \
> +  SA(TRAIT(const X) == expect);\
> +  SA(TRAIT(volatile X) == expect); \
> +  SA(TRAIT(const volatile X) == expect)
> +
> 

[PATCH] simplify-rtx: Fix invalid simplification with paradoxical subregs [PR110206]

2023-07-09 Thread Uros Bizjak via Gcc-patches
As shown in the PR, simplify_gen_subreg call in simplify_replace_fn_rtx:

(gdb) list
469   if (code == SUBREG)
470 {
471   op0 = simplify_replace_fn_rtx (SUBREG_REG (x),
old_rtx, fn, data);
472   if (op0 == SUBREG_REG (x))
473 return x;
474   op0 = simplify_gen_subreg (GET_MODE (x), op0,
475  GET_MODE (SUBREG_REG (x)),
476  SUBREG_BYTE (x));
477   return op0 ? op0 : x;
478 }

simplifies with following arguments:

(gdb) p debug_rtx (op0)
(const_vector:V4QI [
(const_int -52 [0xffcc]) repeated x4
])
(gdb) p debug_rtx (x)
(subreg:V16QI (reg:V4QI 98) 0)

to:

(gdb) p debug_rtx (op0)
(const_vector:V16QI [
(const_int -52 [0xffcc]) repeated x16
])

This simplification is invalid, it is not possible to get V16QImode vector
from V4QImode vector, even when all elements are duplicates.

The simplification happens in simplify_context::simplify_subreg:

(gdb) list
7558  if (VECTOR_MODE_P (outermode)
7559  && GET_MODE_INNER (outermode) == GET_MODE_INNER (innermode)
7560  && vec_duplicate_p (op, ))
7561return gen_vec_duplicate (outermode, elt);

but the above simplification is valid only for non-paradoxical registers,
where outermode <= innermode.  We should not assume that elements outside
the original register are valid, let alone all duplicates.

PR target/110206

gcc/ChangeLog:

* simplify-rtx.cc (simplify_context::simplify_subreg):
Avoid returning a vector with duplicated value
outside the original register.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr110206.c: New test.

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

OK for master and release branches?

Uros.
diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index d7315d82aa3..87ca25086dc 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -7557,6 +7557,7 @@ simplify_context::simplify_subreg (machine_mode 
outermode, rtx op,
 
   if (VECTOR_MODE_P (outermode)
  && GET_MODE_INNER (outermode) == GET_MODE_INNER (innermode)
+ && !paradoxical_subreg_p (outermode, innermode)
  && vec_duplicate_p (op, ))
return gen_vec_duplicate (outermode, elt);
 
diff --git a/gcc/testsuite/gcc.dg/torture/pr110206.c 
b/gcc/testsuite/gcc.dg/torture/pr110206.c
new file mode 100644
index 000..3a4f221ef47
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr110206.c
@@ -0,0 +1,30 @@
+/* PR target/110206 */
+/* { dg-do run { target x86_64-*-* i?86-*-* } } */
+
+typedef unsigned char __attribute__((__vector_size__ (4))) U;
+typedef unsigned char __attribute__((__vector_size__ (8))) V;
+typedef unsigned short u16;
+
+V g;
+
+void
+__attribute__((noinline))
+foo (U u, u16 c, V *r)
+{
+  if (!c)
+__builtin_abort ();
+  V x = __builtin_shufflevector (u, (204 >> u), 7, 0, 5, 1, 3, 5, 0, 2);
+  V y = __builtin_shufflevector (g, (V) { }, 7, 6, 6, 7, 2, 6, 3, 5);
+  V z = __builtin_shufflevector (y, 204 * x, 3, 9, 8, 1, 4, 6, 14, 5);
+  *r = z;
+}
+
+int
+main (void)
+{
+  V r;
+  foo ((U){4}, 5, );
+  if (r[6] != 0x30)
+__builtin_abort();
+  return 0;
+}


[PATCH 2/2] libstdc++: use new built-in trait __is_signed

2023-07-09 Thread Ken Matsui via Gcc-patches
This patch lets libstdc++ use new built-in trait __is_signed.

libstdc++-v3/ChangeLog:

* include/std/type_traits (is_signed): Use __is_signed built-in trait.
(is_signed_v): Likewise.

Signed-off-by: Ken Matsui 
---
 libstdc++-v3/include/std/type_traits | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index 0e7a9c9c7f3..23ab5a4b1e5 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -865,6 +865,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 : public __bool_constant<__is_abstract(_Tp)>
 { };
 
+  /// is_signed
+#if __has_builtin(__is_signed)
+  template
+struct is_signed
+: public __bool_constant<__is_signed(_Tp)>
+{ };
+#else
   /// @cond undocumented
   template::value>
@@ -877,11 +884,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { };
   /// @endcond
 
-  /// is_signed
   template
 struct is_signed
 : public __is_signed_helper<_Tp>::type
 { };
+#endif
 
   /// is_unsigned
   template
@@ -3240,8 +3247,14 @@ template 
 template 
   inline constexpr bool is_final_v = __is_final(_Tp);
 
+#if __has_builtin(__is_signed)
+template 
+  inline constexpr bool is_signed_v = __is_signed(_Tp);
+#else
 template 
   inline constexpr bool is_signed_v = is_signed<_Tp>::value;
+#endif
+
 template 
   inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
 
-- 
2.41.0



[PATCH 1/2] c++, libstdc++: implement __is_signed built-in trait

2023-07-09 Thread Ken Matsui via Gcc-patches
This patch implements built-in trait for std::is_signed.

gcc/cp/ChangeLog:

* cp-trait.def: Define __is_signed.
* constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SIGNED.
* semantics.cc (trait_expr_value): Likewise.
(finish_trait_expr): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/ext/has-builtin-1.C: Test existence of __is_signed.
* g++.dg/ext/is_signed.C: New test.
* g++.dg/tm/pr46567.C (__is_signed): Rename to ...
(is_signed): ... this.

libstdc++-v3/ChangeLog:

* include/ext/numeric_traits.h (__is_signed): Rename to ...
(is_signed): ... this.
* include/bits/charconv.h: Use is_signed instead.
* include/bits/locale_facets.tcc: Likewise.
* include/bits/uniform_int_dist.h: Likewise.

Signed-off-by: Ken Matsui 
---
 gcc/cp/constraint.cc |  3 ++
 gcc/cp/cp-trait.def  |  1 +
 gcc/cp/semantics.cc  |  4 ++
 gcc/testsuite/g++.dg/ext/has-builtin-1.C |  3 ++
 gcc/testsuite/g++.dg/ext/is_signed.C | 47 
 gcc/testsuite/g++.dg/tm/pr46567.C| 12 ++---
 libstdc++-v3/include/bits/charconv.h |  2 +-
 libstdc++-v3/include/bits/locale_facets.tcc  |  6 +--
 libstdc++-v3/include/bits/uniform_int_dist.h |  4 +-
 libstdc++-v3/include/ext/numeric_traits.h| 18 
 10 files changed, 79 insertions(+), 21 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/is_signed.C

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 8cf0f2d0974..73fcbfe39e8 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3751,6 +3751,9 @@ diagnose_trait_expr (tree expr, tree args)
 case CPTK_IS_UNION:
   inform (loc, "  %qT is not a union", t1);
   break;
+case CPTK_IS_SIGNED:
+  inform (loc, "  %qT is not a signed type", t1);
+  break;
 case CPTK_IS_AGGREGATE:
   inform (loc, "  %qT is not an aggregate", t1);
   break;
diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
index 8b7fece0cc8..576d5528d05 100644
--- a/gcc/cp/cp-trait.def
+++ b/gcc/cp/cp-trait.def
@@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, 
"__is_trivially_assignable", 2)
 DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1)
 DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
 DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
+DEFTRAIT_EXPR (IS_SIGNED, "__is_signed", 1)
 DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, 
"__reference_constructs_from_temporary", 2)
 DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, 
"__reference_converts_from_temporary", 2)
 /* FIXME Added space to avoid direct usage in GCC 13.  */
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 8fb47fd179e..17aad992f96 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12118,6 +12118,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree 
type2)
 case CPTK_IS_UNION:
   return type_code1 == UNION_TYPE;
 
+case CPTK_IS_SIGNED:
+  return ARITHMETIC_TYPE_P (type1) && TYPE_SIGN (type1) == SIGNED;
+
 case CPTK_IS_ASSIGNABLE:
   return is_xible (MODIFY_EXPR, type1, type2);
 
@@ -12296,6 +12299,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, 
tree type1, tree type2)
 case CPTK_IS_ENUM:
 case CPTK_IS_UNION:
 case CPTK_IS_SAME:
+case CPTK_IS_SIGNED:
   break;
 
 case CPTK_IS_LAYOUT_COMPATIBLE:
diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C 
b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
index f343e153e56..a43202d0d59 100644
--- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
+++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
@@ -146,3 +146,6 @@
 #if !__has_builtin (__remove_cvref)
 # error "__has_builtin (__remove_cvref) failed"
 #endif
+#if !__has_builtin (__is_signed)
+# error "__has_builtin (__is_signed) failed"
+#endif
diff --git a/gcc/testsuite/g++.dg/ext/is_signed.C 
b/gcc/testsuite/g++.dg/ext/is_signed.C
new file mode 100644
index 000..a04b548105d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_signed.C
@@ -0,0 +1,47 @@
+// { dg-do compile { target c++11 } }
+
+#include 
+
+using namespace __gnu_test;
+
+#define SA(X) static_assert((X),#X)
+#define SA_TEST_CATEGORY(TRAIT, X, expect) \
+  SA(TRAIT(X) == expect);  \
+  SA(TRAIT(const X) == expect);\
+  SA(TRAIT(volatile X) == expect); \
+  SA(TRAIT(const volatile X) == expect)
+
+SA_TEST_CATEGORY(__is_signed, void, false);
+
+SA_TEST_CATEGORY(__is_signed, bool, bool(-1) < bool(0));
+SA_TEST_CATEGORY(__is_signed, char, char(-1) < char(0));
+SA_TEST_CATEGORY(__is_signed, signed char, true);
+SA_TEST_CATEGORY(__is_signed, unsigned char, false);
+SA_TEST_CATEGORY(__is_signed, wchar_t, wchar_t(-1) < wchar_t(0));
+SA_TEST_CATEGORY(__is_signed, short, true);
+SA_TEST_CATEGORY(__is_signed, unsigned short, false);
+SA_TEST_CATEGORY(__is_signed, int, true);
+SA_TEST_CATEGORY(__is_signed, unsigned int, false);

[Bug target/110588] btl (on x86_64) not always generated

2023-07-09 Thread ubizjak at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110588

Uroš Bizjak  changed:

   What|Removed |Added

   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=107671

--- Comment #2 from Uroš Bizjak  ---
Similar missed optimization is reported in PR107671.

[Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110580

--- Comment #1 from Andrew Pinski  ---
Reducing ...

[Bug libgcc/109712] [13 Regression] Segmentation fault in linear_search_fdes

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109712

--- Comment #32 from Andrew Pinski  ---
(In reply to Florian Weimer from comment #31)
> Will propose a backport to 13 in ~2 weeks.

Any news on the backport? There is aim to release GCC 13.2.0 at the end of
July.