This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Avoid UBSAN -fsanitize=enum errors on GCC memmodel enum (PR rtl-optimization/84643)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Biener <rguenther at suse dot de>, Jeff Law <law at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 19 Mar 2018 20:39:20 +0100
- Subject: [PATCH] Avoid UBSAN -fsanitize=enum errors on GCC memmodel enum (PR rtl-optimization/84643)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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