Remove conditional STATIC_ASSERT.

Message ID 60e9783e-d324-2d12-5744-68a3b2e5c96a@suse.cz
State New
Headers
Series Remove conditional STATIC_ASSERT. |

Commit Message

Martin Liška May 5, 2022, 12:18 p.m. UTC
  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(-)
  

Comments

Richard Biener May 5, 2022, 12:29 p.m. UTC | #1
On Thu, May 5, 2022 at 2:20 PM Martin Liška <mliska@suse.cz> 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 10000
>
> 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
>
  
Martin Liška May 5, 2022, 12:41 p.m. UTC | #2
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,
Martin
  
Pedro Alves May 5, 2022, 12:51 p.m. UTC | #3
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.
  
Martin Liška May 5, 2022, 12:56 p.m. UTC | #4
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<wide_int_storage>::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 <T2>::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
  
Richard Biener May 5, 2022, 1:08 p.m. UTC | #5
On Thu, May 5, 2022 at 2:41 PM Martin Liška <mliska@suse.cz> 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
  
Martin Liška May 9, 2022, 8:45 a.m. UTC | #6
On 5/5/22 15:08, Richard Biener wrote:
> On Thu, May 5, 2022 at 2:41 PM Martin Liška <mliska@suse.cz> 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
  
Richard Biener May 9, 2022, 12:05 p.m. UTC | #7
On Mon, May 9, 2022 at 10:46 AM Martin Liška <mliska@suse.cz> wrote:
>
> On 5/5/22 15:08, Richard Biener wrote:
> > On Thu, May 5, 2022 at 2:41 PM Martin Liška <mliska@suse.cz> 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
  

Patch

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 10000
 
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,