This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]