diff mbox series

Avoid UBSAN -fsanitize=enum errors on GCC memmodel enum (PR rtl-optimization/84643)

Message ID 20180319193920.GP8577@tucnak
State New
Headers show
Series Avoid UBSAN -fsanitize=enum errors on GCC memmodel enum (PR rtl-optimization/84643) | expand

Commit Message

Jakub Jelinek March 19, 2018, 7:39 p.m. UTC
Hi!

The enum memmodel doesn't declare the target specific enumerators,
which are just defines in i386.h, but as those are above any
enumerators in the generic enum, it is strictly speaking UB when
values with that enum memmodel type have the higher target dependent bits
set.  This patch just makes sure that the enumerator is full signed 32-bit.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2018-03-19  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/84643
	* memmodel.h (enum memmodel): Add MEMMODEL_MAX enumerator.


	Jakub

Comments

Richard Biener March 19, 2018, 8:35 p.m. UTC | #1
On March 19, 2018 8:39:20 PM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>The enum memmodel doesn't declare the target specific enumerators,
>which are just defines in i386.h, but as those are above any
>enumerators in the generic enum, it is strictly speaking UB when
>values with that enum memmodel type have the higher target dependent
>bits
>set.  This patch just makes sure that the enumerator is full signed
>32-bit.
>
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK. 

Richard. 

>2018-03-19  Jakub Jelinek  <jakub@redhat.com>
>
>	PR rtl-optimization/84643
>	* memmodel.h (enum memmodel): Add MEMMODEL_MAX enumerator.
>
>--- gcc/memmodel.h.jj	2018-01-03 10:19:55.495534012 +0100
>+++ gcc/memmodel.h	2018-03-19 10:31:42.980812157 +0100
>@@ -45,7 +45,9 @@ enum memmodel
>   MEMMODEL_LAST = 6,
>   MEMMODEL_SYNC_ACQUIRE = MEMMODEL_ACQUIRE | MEMMODEL_SYNC,
>   MEMMODEL_SYNC_RELEASE = MEMMODEL_RELEASE | MEMMODEL_SYNC,
>-  MEMMODEL_SYNC_SEQ_CST = MEMMODEL_SEQ_CST | MEMMODEL_SYNC
>+  MEMMODEL_SYNC_SEQ_CST = MEMMODEL_SEQ_CST | MEMMODEL_SYNC,
>+  /* Say that all the higher bits are valid target extensions.  */
>+  MEMMODEL_MAX = INTTYPE_MAXIMUM (int)
> };
> 
> /* Return the memory model from a host integer.  */
>
>	Jakub
diff mbox series

Patch

--- gcc/memmodel.h.jj	2018-01-03 10:19:55.495534012 +0100
+++ gcc/memmodel.h	2018-03-19 10:31:42.980812157 +0100
@@ -45,7 +45,9 @@  enum memmodel
   MEMMODEL_LAST = 6,
   MEMMODEL_SYNC_ACQUIRE = MEMMODEL_ACQUIRE | MEMMODEL_SYNC,
   MEMMODEL_SYNC_RELEASE = MEMMODEL_RELEASE | MEMMODEL_SYNC,
-  MEMMODEL_SYNC_SEQ_CST = MEMMODEL_SEQ_CST | MEMMODEL_SYNC
+  MEMMODEL_SYNC_SEQ_CST = MEMMODEL_SEQ_CST | MEMMODEL_SYNC,
+  /* Say that all the higher bits are valid target extensions.  */
+  MEMMODEL_MAX = INTTYPE_MAXIMUM (int)
 };
 
 /* Return the memory model from a host integer.  */