Skip to contentSkip to conversation

lib: utils/serial: Fix compilation errors with LLVM

PATCH New [email protected] 2 participants 2 messages Nov 10, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: utils/serial: Fix compilation errors with LLVM

From: zhangleizheng <[email protected]>

Fix: "Getting compilation error on generic firmware #269"
opensbi/lib/utils/serial/semihosting.c:158:12: error: result of comparison of constant -1 with expression of type 'char' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
ret = ch > -1 ? ch : -1;

Using clang16 as the compiler.

---
 lib/utils/serial/semihosting.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/utils/serial/semihosting.c +2 -2
index 5012fa1..27dba6f 100644
@@ -150,11 +150,11 @@ static void semihosting_putc(char ch)
 
 static int semihosting_getc(void)
 {
-	char ch = 0;
+	signed char ch = 0;
 	int ret;
 
 	if (semihosting_infd < 0)  {
-		ch = semihosting_trap(SYSREADC, NULL);
+		ch = (signed char)semihosting_trap(SYSREADC, NULL);
 		ret = ch > -1 ? ch : -1;
 	} else
 		ret = semihosting_read(semihosting_infd, &ch, 1) > 0 ? ch : -1;
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 lib: utils/serial: Fix compilation errors with LLVM

? 2022-11-10???? 10:11 +0800?1220749046 at qq.com???

Quoted 11 lines

From: zhangleizheng <[email protected]>

Fix: "Getting compilation error on generic firmware #269"
???? opensbi/lib/utils/serial/semihosting.c:158:12: error: result ???? of comparison of constant -1 with expression of type 'char' ???? is always true [-Werror,-Wtautological-constant-out-of-range-compare] ??????? ret = ch > -1 ? ch : -1;

Using clang16 as the compiler.

repeat with
https://lists.infradead.org/pipermail/opensbi/2022-November/003543.html
https://lists.infradead.org/pipermail/opensbi/2022-November/003552.html

Regards,
Xiang W

Quoted 26 lines

---
?lib/utils/serial/semihosting.c | 4 ++--
?1 file changed, 2 insertions(+), 2 deletions(-)

lib/utils/serial/semihosting.c +0 -0
index 5012fa1..27dba6f 100644
@@ -150,11 +150,11 @@ static void semihosting_putc(char ch)

?
?static int semihosting_getc(void)
?{
-???????char ch = 0;
+???????signed char ch = 0;
????????int ret;
?
????????if (semihosting_infd < 0)? {
-???????????????ch = semihosting_trap(SYSREADC, NULL); +???????????????ch = (signed char)semihosting_trap(SYSREADC, NULL); ????????????????ret = ch > -1 ? ch : -1;
????????} else
????????????????ret = semihosting_read(semihosting_infd, &ch, 1) > 0 ? ch : -1;

Signature · 1 line
2.17.1