Skip to contentSkip to conversation

spapr_drc: fix clang -fsanitizer=shift warning

PATCH In review Michael Roth 2 participants 2 messages Jul 21, 2015 – Sep 2, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spapr_drc: fix clang -fsanitizer=shift warning

Current code for generating DRC type mask generates the following warning with clang -fsanitizer=undefined -fsanitizer=shift:

runtime error: left shift of negative value -1

Fix this by calculating the mask like a sane person would.

---
 hw/ppc/spapr_drc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr_drc.c +1 -1
index ee87432..0e7d725 100644
@@ -32,7 +32,7 @@
 
 #define DRC_CONTAINER_PATH "/dr-connector"
 #define DRC_INDEX_TYPE_SHIFT 28
-#define DRC_INDEX_ID_MASK (~(~0 << DRC_INDEX_TYPE_SHIFT))
+#define DRC_INDEX_ID_MASK ((1 << DRC_INDEX_TYPE_SHIFT) - 1)
 
 static sPAPRDRConnectorTypeShift get_type_shift(sPAPRDRConnectorType type)
 {
Signature · 1 line
1.9.1
#1 lore raw
Quoted 8 lines · Michael Roth

Current code for generating DRC type mask generates the following warning with clang -fsanitizer=undefined -fsanitizer=shift:

runtime error: left shift of negative value -1

Fix this by calculating the mask like a sane person would.

Sorry I missed this before - please CC me on patches to the spapr code. I actually already wrote an equivalent patch and put it in spapr-next.

Quoted 17 lines
---
 hw/ppc/spapr_drc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr_drc.c +1 -1
index ee87432..0e7d725 100644
@@ -32,7 +32,7 @@
 
 #define DRC_CONTAINER_PATH "/dr-connector"
 #define DRC_INDEX_TYPE_SHIFT 28
-#define DRC_INDEX_ID_MASK (~(~0 << DRC_INDEX_TYPE_SHIFT))
+#define DRC_INDEX_ID_MASK ((1 << DRC_INDEX_TYPE_SHIFT) - 1)
 
 static sPAPRDRConnectorTypeShift get_type_shift(sPAPRDRConnectorType type)
 {
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson