Skip to contentSkip to conversation

flashrom: Fix build with clang

PATCH In review Khem Raj 2 participants 3 messages Mar 16, 2020

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/1 flashrom: Fix build with clang

---
 ...typecast-enum-conversions-explicitly.patch | 69 +++++++++++++++++++
 meta-oe/recipes-bsp/flashrom/flashrom_1.2.bb  |  1 +
 2 files changed, 70 insertions(+)
 create mode 100644 meta-oe/recipes-bsp/flashrom/flashrom/0001-typecast-enum-conversions-explicitly.patch
meta-oe/recipes-bsp/flashrom/flashrom/0001-typecast-enum-conversions-explicitly.patch new file +69 -0
new file mode 100644
index 0000000000..7ac53650f2
@@ -0,0 +1,69 @@
+From 8a236330f2af56bde21e9f69208ea3e59f529f0c Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Sun, 15 Mar 2020 17:02:30 -0700
+Subject: [PATCH] typecast enum conversions explicitly
+
+clang complains like below
+
+libflashrom.c:191:43: error: implicit conversion from enumeration type 'const enum test_state' to different enumeration type 'enum flashrom_test_state' [-Werror,-Wenum-conversion]
+                        supported_boards[i].working = binfo[i].working;
+                                                    ~ ~~~~~~~~~^~~~~~~
+libflashrom.c:229:46: error: implicit conversion from enumeration type 'const enum test_state' to different enumeration type 'enum flashrom_test_state' [-Werror,-Wenum-conversion]
+                        supported_chipsets[i].status = chipset[i].status;
+                                                     ~ ~~~~~~~~~~~^~~~~~
+
+However these enums are exactly same so they can be typecasted
+
+libflashrom.h
+
+/** @ingroup flashrom-query */
+enum flashrom_test_state {
+        FLASHROM_TESTED_OK  = 0,
+        FLASHROM_TESTED_NT  = 1,
+        FLASHROM_TESTED_BAD = 2,
+        FLASHROM_TESTED_DEP = 3,
+        FLASHROM_TESTED_NA  = 4,
+};
+
+flash.h
+
+enum test_state {
+          OK = 0,
+          NT = 1, /* Not tested */
+          BAD,    /* Known to not work */
+          DEP,    /* Support depends on configuration (e.g. Intel flash descriptor) */
+          NA,     /* Not applicable (e.g. write support on ROM chips) */
+  };
+
+Upstream-Status: Pending
+
+Signed-off-by: Khem Raj <[email protected]>
+---
+ libflashrom.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/libflashrom.c b/libflashrom.c
+index 0dec22e..7956685 100644
+--- a/libflashrom.c
++++ b/libflashrom.c
+@@ -188,7 +188,7 @@ struct flashrom_board_info *flashrom_supported_boards(void)
+ 		for (; i < boards_known_size; ++i) {
+ 			supported_boards[i].vendor = binfo[i].vendor;
+ 			supported_boards[i].name = binfo[i].name;
+-			supported_boards[i].working = binfo[i].working;
++			supported_boards[i].working = (enum flashrom_test_state)binfo[i].working;
+ 		}
+ 	} else {
+ 		msg_gerr("Memory allocation error!\n");
+@@ -226,7 +226,7 @@ struct flashrom_chipset_info *flashrom_supported_chipsets(void)
+ 			supported_chipsets[i].chipset = chipset[i].device_name;
+ 			supported_chipsets[i].vendor_id = chipset[i].vendor_id;
+ 			supported_chipsets[i].chipset_id = chipset[i].device_id;
+-			supported_chipsets[i].status = chipset[i].status;
++			supported_chipsets[i].status = (enum flashrom_test_state)chipset[i].status;
+ 	  }
+ 	} else {
+ 		msg_gerr("Memory allocation error!\n");
+-- 
+2.25.1
+
meta-oe/recipes-bsp/flashrom/flashrom_1.2.bb +1 -0
index 17445ac2da..642cec1598 100644
@@ -6,6 +6,7 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
 DEPENDS = "pciutils libusb libusb-compat"
 
 SRC_URI = "https://download.flashrom.org/releases/flashrom-v${PV}.tar.bz2 \
+           file://0001-typecast-enum-conversions-explicitly.patch \
            "
 SRC_URI[md5sum] = "7f8e4b87087eb12ecee0fcc5445b4956"
 SRC_URI[sha256sum] = "e1f8d95881f5a4365dfe58776ce821dfcee0f138f75d0f44f8a3cd032d9ea42b"
Signature · 1 line
2.25.1
#1 lore raw

meta-oe/recipes-bsp/flashrom/flashrom/0001-typecast-enum-conversions-explicitly.patch line 12

Quoted 8 lines · Khem Raj

...

meta-oe/recipes-bsp/flashrom/flashrom/0001-typecast-enum-conversions-explicitly.patch new file +7 -0
+clang complains like below
+
+libflashrom.c:191:43: error: implicit conversion from enumeration type 'const enum test_state' to different enumeration type 'enum flashrom_test_state' [-Werror,-Wenum-conversion]
+                        supported_boards[i].working = binfo[i].working;
+                                                    ~ ~~~~~~~~~^~~~~~~
+libflashrom.c:229:46: error: implicit conversion from enumeration type 'const enum test_state' to different enumeration type 'enum flashrom_test_state' [-Werror,-Wenum-conversion]
+                        supported_chipsets[i].status = chipset[i].status;

Please patch out the -Werror instead.

Quoted 2 lines

...
+However these enums are exactly same so they can be typecasted

If they are the same, the correct fix would be to have only one enum.

Quoted 6 lines

...
+Upstream-Status: Pending
...
+- supported_boards[i].working = binfo[i].working;
++ supported_boards[i].working = (enum flashrom_test_state)binfo[i].working;
...

Working around a compile warning by making the code worse is not an improvement.

Even worse when this is an OE-only workaround.

cu
Adrian

author
#2 lore raw
Quoted 13 lines · Adrian Bunk

meta-oe/recipes-bsp/flashrom/flashrom/0001-typecast-enum-conversions-explicitly.patch line 12

Quoted 8 lines · Khem Raj

...

meta-oe/recipes-bsp/flashrom/flashrom/0001-typecast-enum-conversions-explicitly.patch new file +7 -0
+clang complains like below
+
+libflashrom.c:191:43: error: implicit conversion from enumeration type 'const enum test_state' to different enumeration type 'enum flashrom_test_state' [-Werror,-Wenum-conversion]
+                        supported_boards[i].working = binfo[i].working;
+                                                    ~ ~~~~~~~~~^~~~~~~
+libflashrom.c:229:46: error: implicit conversion from enumeration type 'const enum test_state' to different enumeration type 'enum flashrom_test_state' [-Werror,-Wenum-conversion]
+                        supported_chipsets[i].status = chipset[i].status;

Please patch out the -Werror instead.

I was basing my solution on an upstream commit
https://github.com/flashrom/flashrom/commit/71b706f5
and I have also proposed my patch upstream lets see what feedback flashrom devs have
if you are interested you can follow the pull

https://github.com/flashrom/flashrom/pull/133

Quoted 5 lines
Quoted 2 lines

...
+However these enums are exactly same so they can be typecasted

If they are the same, the correct fix would be to have only one enum.

its not that straight forward and I would leave that to flashrom experts.

Quoted 10 lines
Quoted 6 lines

...
+Upstream-Status: Pending
...

+-                    supported_boards[i].working = binfo[i].working;
++                    supported_boards[i].working = (enum flashrom_test_state)binfo[i].working;

...

Working around a compile warning by making the code worse is not an improvement.

If you think it make it worse, feel free to improve it.

Quoted 4 lines

Even worse when this is an OE-only workaround.

cu
Adrian