Skip to contentSkip to conversation

lib: utils/serial: Fix semihosting compile error using LLVM

PATCH New Anup Patel 4 participants 4 messages Nov 8, 2022 – Nov 15, 2022

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

PATCH v2 1/1 lib: utils/serial: Fix semihosting compile error using LLVM

We fix the following semihosting compile error observed using LLVM:
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;
                      ~~ ^ ~~
Fixes 7f09fba86e43 ("lib: utils/serial: add semihosting support")
---
 lib/utils/serial/semihosting.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/utils/serial/semihosting.c +2 -2
index 5012fa1..86fa296 100644
@@ -154,8 +154,8 @@ static int semihosting_getc(void)
 	int ret;
 
 	if (semihosting_infd < 0)  {
-		ch = semihosting_trap(SYSREADC, NULL);
-		ret = ch > -1 ? ch : -1;
+		ret = semihosting_trap(SYSREADC, NULL);
+		ret = ret < 0 ? -1 : ret;
 	} else
 		ret = semihosting_read(semihosting_infd, &ch, 1) > 0 ? ch : -1;
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/1 lib: utils/serial: Fix semihosting compile error using LLVM

? 2022-11-08???? 17:40 +0530?Anup Patel???

Quoted 8 lines

We fix the following semihosting compile error observed using LLVM:
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;
????????????????????? ~~ ^ ~~

Fixes 7f09fba86e43 ("lib: utils/serial: add semihosting support")

LGTM

Quoted 23 lines

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

lib/utils/serial/semihosting.c +0 -0
index 5012fa1..86fa296 100644
@@ -154,8 +154,8 @@ static int semihosting_getc(void)
 ????????int ret;

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

Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 1/1 lib: utils/serial: Fix semihosting compile error using LLVM

In reply to Anup Patel
Quoted 12 lines · Anup Patel

We fix the following semihosting compile error observed using LLVM:
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;
                      ~~ ^ ~~
Fixes 7f09fba86e43 ("lib: utils/serial: add semihosting support")
---
 lib/utils/serial/semihosting.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Applied
#3 lore raw

PATCH v2 1/1 lib: utils/serial: Fix semihosting compile error using LLVM

In reply to Anup Patel
Quoted 8 lines · Anup Patel

We fix the following semihosting compile error observed using LLVM:
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;
                      ~~ ^ ~~
Fixes 7f09fba86e43 ("lib: utils/serial: add semihosting support")

Applied this patch to the riscv/opensbi repo.

Regards,
Anup

Quoted 22 lines
---
 lib/utils/serial/semihosting.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/utils/serial/semihosting.c +2 -3
index 5012fa1..86fa296 100644
@@ -154,8 +154,8 @@ static int semihosting_getc(void)
        int ret;
 
        if (semihosting_infd < 0)  {
-               ch = semihosting_trap(SYSREADC, NULL);
-               ret = ch > -1 ? ch : -1;
+               ret = semihosting_trap(SYSREADC, NULL);
+               ret = ret < 0 ? -1 : ret;
        } else
                ret = semihosting_read(semihosting_infd, &ch, 1) > 0 ? ch : -1;
 
--

2.34.1