Re: [PATCH] Remove conditional STATIC_ASSERT.

2022-05-09 Thread Richard Biener via Gcc-patches
On Mon, May 9, 2022 at 10:46 AM Martin Liška  wrote:
>
> On 5/5/22 15:08, Richard Biener wrote:
> > On Thu, May 5, 2022 at 2:41 PM Martin Liška  wrote:
> >>
> >> On 5/5/22 14:29, Richard Biener wrote:
> >>> Can we then use static_assert (...) instead and remove the
> >>> macro?
> >>
> >> Oh yes, we can ;)
> >>
> >>> Do we have C compiled code left (I think we might,
> >>> otherwise we'd not have __cplusplus guards in system.h),
> >>> in which case the #if should change to #ifdef __cplusplus?
> >>
> >> No, there's no such a consumer of the macro.
> >
> > OK, but for C uses it should still be different so my suggestion
> > to change to #ifdef __cplusplus remains.  OTOH then the change
> > is somewhat pointless.
>
> Sure, so something like this?

Works for me.

Richard.

> Thanks,
> Martin
>
> >
> >> What about the updated version of the patch?
> >>
> >> Cheers,
> >> Martin


Re: [PATCH] Remove conditional STATIC_ASSERT.

2022-05-09 Thread Martin Liška
On 5/5/22 15:08, Richard Biener wrote:
> On Thu, May 5, 2022 at 2:41 PM Martin Liška  wrote:
>>
>> On 5/5/22 14:29, Richard Biener wrote:
>>> Can we then use static_assert (...) instead and remove the
>>> macro?
>>
>> Oh yes, we can ;)
>>
>>> Do we have C compiled code left (I think we might,
>>> otherwise we'd not have __cplusplus guards in system.h),
>>> in which case the #if should change to #ifdef __cplusplus?
>>
>> No, there's no such a consumer of the macro.
> 
> OK, but for C uses it should still be different so my suggestion
> to change to #ifdef __cplusplus remains.  OTOH then the change
> is somewhat pointless.

Sure, so something like this?

Thanks,
Martin

> 
>> What about the updated version of the patch?
>>
>> Cheers,
>> Martin
From 100b7a3de69605ab7e80680e6a6e651e31366bc5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Li=C5=A1ka?= 
Date: Thu, 5 May 2022 14:18:58 +0200
Subject: [PATCH] Simplify STATIC_ASSERT macro.

For C++, use always __static_assert and for C, use the negative array
index.

gcc/ChangeLog:

	* basic-block.h (STATIC_ASSERT): Use normal STATIC_ASSERT.
	* system.h (STATIC_ASSERT): Define as static_assert for C++
	and fallback to array index in C.
---
 gcc/basic-block.h | 5 +
 gcc/system.h  | 3 +--
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/gcc/basic-block.h b/gcc/basic-block.h
index e3fff1f6975..21a9b24dbf9 100644
--- a/gcc/basic-block.h
+++ b/gcc/basic-block.h
@@ -158,10 +158,7 @@ struct GTY((chain_next ("%h.next_bb"), chain_prev ("%h.prev_bb"))) basic_block_d
 /* This ensures that struct gimple_bb_info is smaller than
struct rtl_bb_info, so that inlining the former into basic_block_def
is the better choice.  */
-typedef int __assert_gimple_bb_smaller_rtl_bb
-  [(int) sizeof (struct rtl_bb_info)
-   - (int) sizeof (struct gimple_bb_info)];
-
+STATIC_ASSERT (sizeof (rtl_bb_info) >= sizeof (gimple_bb_info));
 
 #define BB_FREQ_MAX 1
 
diff --git a/gcc/system.h b/gcc/system.h
index 1121af485a4..1c783c5331d 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -835,8 +835,7 @@ extern void fancy_abort (const char *, int, const char *)
 #define STATIC_CONSTANT_P(X) (false && (X))
 #endif
 
-/* static_assert (COND, MESSAGE) is available in C++11 onwards.  */
-#if __cplusplus >= 201103L
+#ifdef __cplusplus
 #define STATIC_ASSERT(X) \
   static_assert ((X), #X)
 #else
-- 
2.36.0



Re: [PATCH] Remove conditional STATIC_ASSERT.

2022-05-05 Thread Richard Biener via Gcc-patches
On Thu, May 5, 2022 at 2:41 PM Martin Liška  wrote:
>
> On 5/5/22 14:29, Richard Biener wrote:
> > Can we then use static_assert (...) instead and remove the
> > macro?
>
> Oh yes, we can ;)
>
> > Do we have C compiled code left (I think we might,
> > otherwise we'd not have __cplusplus guards in system.h),
> > in which case the #if should change to #ifdef __cplusplus?
>
> No, there's no such a consumer of the macro.

OK, but for C uses it should still be different so my suggestion
to change to #ifdef __cplusplus remains.  OTOH then the change
is somewhat pointless.

> What about the updated version of the patch?
>
> Cheers,
> Martin


Re: [PATCH] Remove conditional STATIC_ASSERT.

2022-05-05 Thread Martin Liška
On 5/5/22 14:51, Pedro Alves wrote:
> On 2022-05-05 13:41, Martin Liška wrote:
>> On 5/5/22 14:29, Richard Biener wrote:
>>> Can we then use static_assert (...) instead and remove the
>>> macro?
>>
>> Oh yes, we can ;)
>>
>>> Do we have C compiled code left (I think we might,
>>> otherwise we'd not have __cplusplus guards in system.h),
>>> in which case the #if should change to #ifdef __cplusplus?
>>
>> No, there's no such a consumer of the macro.
>>
>> What about the updated version of the patch?
> 
> static_assert without the second/message parameter requires C++17:
> 
>   https://en.cppreference.com/w/cpp/language/static_assert

Oh, you are correct :) Thanks:

/home/marxin/Programming/gcc/gcc/wide-int.h: In static member function ‘static 
wide_int wi::int_traits::get_binary_result(const T1&, const 
T2&)’:
/home/marxin/Programming/gcc/gcc/wide-int.h:1205:60: warning: ‘static_assert’ 
without a message only available with ‘-std=c++17’ or ‘-std=gnu++17’ 
[-Wpedantic]
 1205 |  || wi::int_traits ::precision_type != 
FLEXIBLE_PRECISION);

> 
> The macro expanded to always have a message argument.


That said, we should go with the original version of the patch.

Cheers,
Martin


Re: [PATCH] Remove conditional STATIC_ASSERT.

2022-05-05 Thread Pedro Alves
On 2022-05-05 13:41, Martin Liška wrote:
> On 5/5/22 14:29, Richard Biener wrote:
>> Can we then use static_assert (...) instead and remove the
>> macro?
> 
> Oh yes, we can ;)
> 
>> Do we have C compiled code left (I think we might,
>> otherwise we'd not have __cplusplus guards in system.h),
>> in which case the #if should change to #ifdef __cplusplus?
> 
> No, there's no such a consumer of the macro.
> 
> What about the updated version of the patch?

static_assert without the second/message parameter requires C++17:

  https://en.cppreference.com/w/cpp/language/static_assert

The macro expanded to always have a message argument.


Re: [PATCH] Remove conditional STATIC_ASSERT.

2022-05-05 Thread Martin Liška
On 5/5/22 14:29, Richard Biener wrote:
> Can we then use static_assert (...) instead and remove the
> macro?

Oh yes, we can ;)

> Do we have C compiled code left (I think we might,
> otherwise we'd not have __cplusplus guards in system.h),
> in which case the #if should change to #ifdef __cplusplus?

No, there's no such a consumer of the macro.

What about the updated version of the patch?

Cheers,
MartinFrom a610603daddd45de3a6a218006ffa6d1f8855e1c Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Wed, 4 May 2022 21:17:54 +0200
Subject: [PATCH] Start using static_assert.

As we require a c++11 compliant compiler, static_assert is always
available.

gcc/ChangeLog:

	* system.h (STATIC_ASSERT): Remove.
	* basic-block.h (STATIC_ASSERT): Use normal static_assert.

gcc/ChangeLog:

	* basic-block.h (static_assert): Use static_assert directly.
	* bitmap.h (Traits>::base_bitmap_view): Likewise.
	* common/config/i386/i386-common.cc (STATIC_ASSERT): Likewise.
	(static_assert): Likewise.
	* config/aarch64/aarch64-sve-builtins-shapes.cc (struct binary_imm_narrowb_base): Likewise.
	(struct binary_imm_narrowt_base): Likewise.
	(struct unary_narrowb_base): Likewise.
	(struct unary_narrowt_base): Likewise.
	* config/i386/i386-builtins.cc (BDESC_VERIFYS): Likewise.
	* config/i386/i386-options.cc (STATIC_ASSERT): Likewise.
	(static_assert): Likewise.
	* config/i386/i386.h (STATIC_ASSERT): Likewise.
	(static_assert): Likewise.
	* dumpfile.cc (make_item_for_dump_dec): Likewise.
	* expmed.cc (make_tree): Likewise.
	* input.h (STATIC_ASSERT): Likewise.
	(static_assert): Likewise.
	* ira-build.cc (ira_conflict_vector_profitable_p): Likewise.
	* lto-streamer.h (STATIC_ASSERT): Likewise.
	(static_assert): Likewise.
	* lto-wrapper.cc: Likewise.
	* poly-int.h (C>::poly_int): Likewise.
	(maybe_eq): Likewise.
	(print_dec): Likewise.
	* profile-count.cc (profile_count::to_frequency): Likewise.
	* rtl.h (subreg_shape::unique_id): Likewise.
	* system.h (STATIC_ASSERT): Likewise.
	* tree.h (TYPE_VECTOR_SUBPARTS): Likewise.
	(SET_TYPE_VECTOR_SUBPARTS): Likewise.
	* wide-int.h (wide_int_storage::wide_int_storage): Likewise.
	(wide_int_storage>::get_binary_result): Likewise.
	(N>::set_len): Likewise.
	(wi::mask): Likewise.
	(wi::shifted_mask): Likewise.

gcc/c-family/ChangeLog:

	* c-omp.cc (c_omp_split_clauses): Use static_assert directly.

gcc/cp/ChangeLog:

	* cp-tree.h (STATIC_ASSERT): Use static_assert directly.

gcc/fortran/ChangeLog:

	* openmp.cc (resolve_omp_clauses): Use static_assert directly.
---
 gcc/basic-block.h  |  5 +
 gcc/bitmap.h   |  2 +-
 gcc/c-family/c-omp.cc  |  2 +-
 gcc/common/config/i386/i386-common.cc  |  2 +-
 .../aarch64/aarch64-sve-builtins-shapes.cc |  8 
 gcc/config/i386/i386-builtins.cc   |  2 +-
 gcc/config/i386/i386-options.cc|  2 +-
 gcc/config/i386/i386.h |  2 +-
 gcc/cp/cp-tree.h   |  2 +-
 gcc/dumpfile.cc|  2 +-
 gcc/expmed.cc  |  2 +-
 gcc/fortran/openmp.cc  |  2 +-
 gcc/input.h|  2 +-
 gcc/ira-build.cc   |  2 +-
 gcc/lto-streamer.h |  2 +-
 gcc/lto-wrapper.cc |  2 +-
 gcc/poly-int.h | 10 +-
 gcc/profile-count.cc   |  2 +-
 gcc/rtl.h  |  6 +++---
 gcc/system.h   |  9 -
 gcc/tree.h |  4 ++--
 gcc/wide-int.h | 18 +-
 22 files changed, 39 insertions(+), 51 deletions(-)

diff --git a/gcc/basic-block.h b/gcc/basic-block.h
index e3fff1f6975..fe81b6d90cc 100644
--- a/gcc/basic-block.h
+++ b/gcc/basic-block.h
@@ -158,10 +158,7 @@ struct GTY((chain_next ("%h.next_bb"), chain_prev ("%h.prev_bb"))) basic_block_d
 /* This ensures that struct gimple_bb_info is smaller than
struct rtl_bb_info, so that inlining the former into basic_block_def
is the better choice.  */
-typedef int __assert_gimple_bb_smaller_rtl_bb
-  [(int) sizeof (struct rtl_bb_info)
-   - (int) sizeof (struct gimple_bb_info)];
-
+static_assert (sizeof (rtl_bb_info) >= sizeof (gimple_bb_info));
 
 #define BB_FREQ_MAX 1
 
diff --git a/gcc/bitmap.h b/gcc/bitmap.h
index e7bf67a5474..3c61c6dcfb7 100644
--- a/gcc/bitmap.h
+++ b/gcc/bitmap.h
@@ -1005,7 +1005,7 @@ base_bitmap_view::base_bitmap_view (const T ,
   /* The code currently assumes that each element of ARRAY corresponds
  to exactly one bitmap_element.  */
   const size_t array_element_bits = CHAR_BIT * sizeof (array_element_type);
-  STATIC_ASSERT (BITMAP_ELEMENT_ALL_BITS % array_element_bits == 0);
+  static_assert (BITMAP_ELEMENT_ALL_BITS % 

Re: [PATCH] Remove conditional STATIC_ASSERT.

2022-05-05 Thread Richard Biener via Gcc-patches
On Thu, May 5, 2022 at 2:20 PM Martin Liška  wrote:
>
> As we require a c++11 compliant compiler, the #if __cplusplus >= 201103L
> conditional build is always true.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?

Can we then use static_assert (...) instead and remove the
macro?  Do we have C compiled code left (I think we might,
otherwise we'd not have __cplusplus guards in system.h),
in which case the #if should change to #ifdef __cplusplus?

Thanks,
Richard.

> Thanks,
> Martin
>
> gcc/ChangeLog:
>
> * basic-block.h (STATIC_ASSERT): Use normal STATIC_ASSERT.
> * system.h (STATIC_ASSERT): Define always as static_assert.
> ---
>  gcc/basic-block.h | 5 +
>  gcc/system.h  | 9 +
>  2 files changed, 2 insertions(+), 12 deletions(-)
>
> diff --git a/gcc/basic-block.h b/gcc/basic-block.h
> index e3fff1f6975..21a9b24dbf9 100644
> --- a/gcc/basic-block.h
> +++ b/gcc/basic-block.h
> @@ -158,10 +158,7 @@ struct GTY((chain_next ("%h.next_bb"), chain_prev 
> ("%h.prev_bb"))) basic_block_d
>  /* This ensures that struct gimple_bb_info is smaller than
> struct rtl_bb_info, so that inlining the former into basic_block_def
> is the better choice.  */
> -typedef int __assert_gimple_bb_smaller_rtl_bb
> -  [(int) sizeof (struct rtl_bb_info)
> -   - (int) sizeof (struct gimple_bb_info)];
> -
> +STATIC_ASSERT (sizeof (rtl_bb_info) >= sizeof (gimple_bb_info));
>
>  #define BB_FREQ_MAX 1
>
> diff --git a/gcc/system.h b/gcc/system.h
> index 1688b763ef5..48145951337 100644
> --- a/gcc/system.h
> +++ b/gcc/system.h
> @@ -801,14 +801,7 @@ extern void fancy_abort (const char *, int, const char *)
>
>  #define STATIC_CONSTANT_P(X) (__builtin_constant_p (X) && (X))
>
> -/* static_assert (COND, MESSAGE) is available in C++11 onwards.  */
> -#if __cplusplus >= 201103L
> -#define STATIC_ASSERT(X) \
> -  static_assert ((X), #X)
> -#else
> -#define STATIC_ASSERT(X) \
> -  typedef int assertion1[(X) ? 1 : -1] ATTRIBUTE_UNUSED
> -#endif
> +#define STATIC_ASSERT(X) static_assert ((X), #X)
>
>  /* Provide a fake boolean type.  We make no attempt to use the
> C99 _Bool, as it may not be available in the bootstrap compiler,
> --
> 2.36.0
>


[PATCH] Remove conditional STATIC_ASSERT.

2022-05-05 Thread Martin Liška
As we require a c++11 compliant compiler, the #if __cplusplus >= 201103L
conditional build is always true.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

gcc/ChangeLog:

* basic-block.h (STATIC_ASSERT): Use normal STATIC_ASSERT.
* system.h (STATIC_ASSERT): Define always as static_assert.
---
 gcc/basic-block.h | 5 +
 gcc/system.h  | 9 +
 2 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/gcc/basic-block.h b/gcc/basic-block.h
index e3fff1f6975..21a9b24dbf9 100644
--- a/gcc/basic-block.h
+++ b/gcc/basic-block.h
@@ -158,10 +158,7 @@ struct GTY((chain_next ("%h.next_bb"), chain_prev 
("%h.prev_bb"))) basic_block_d
 /* This ensures that struct gimple_bb_info is smaller than
struct rtl_bb_info, so that inlining the former into basic_block_def
is the better choice.  */
-typedef int __assert_gimple_bb_smaller_rtl_bb
-  [(int) sizeof (struct rtl_bb_info)
-   - (int) sizeof (struct gimple_bb_info)];
-
+STATIC_ASSERT (sizeof (rtl_bb_info) >= sizeof (gimple_bb_info));
 
 #define BB_FREQ_MAX 1
 
diff --git a/gcc/system.h b/gcc/system.h
index 1688b763ef5..48145951337 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -801,14 +801,7 @@ extern void fancy_abort (const char *, int, const char *)
 
 #define STATIC_CONSTANT_P(X) (__builtin_constant_p (X) && (X))
 
-/* static_assert (COND, MESSAGE) is available in C++11 onwards.  */
-#if __cplusplus >= 201103L
-#define STATIC_ASSERT(X) \
-  static_assert ((X), #X)
-#else
-#define STATIC_ASSERT(X) \
-  typedef int assertion1[(X) ? 1 : -1] ATTRIBUTE_UNUSED
-#endif
+#define STATIC_ASSERT(X) static_assert ((X), #X)
 
 /* Provide a fake boolean type.  We make no attempt to use the
C99 _Bool, as it may not be available in the bootstrap compiler,
-- 
2.36.0