embeddedartistry / libc

libc targeted for embedded systems usage. Reduced set of functionality (due to embedded nature). Chosen for portability and quick bringup.
MIT License
510 stars 67 forks source link

Resolve warnings on aarch64 #132

Closed phillipjohnston closed 2 years ago

phillipjohnston commented 4 years ago

The following warnings are generated in Clang when compiling with an aarch64 cross-file:

12:22:27 {pj/demo} libc$ make
[35/532] Compiling C object 'src/e88f707@@printf@sta/.._printf_printf.c.o'.
../printf/printf.c:493:28: warning: shift count >= width of type [-Wshift-count-overflow]
  int exp2 = (int)((conv.U >> 52U) & 0x07FFU) - 1023;           // effectively log2
                           ^  ~~~
../printf/printf.c:501:36: warning: shift count >= width of type [-Wshift-count-overflow]
  conv.U = (uint64_t)(exp2 + 1023) << 52U;
                                   ^  ~~~
2 warnings generated.
[100/532] Compiling C object 'src/e88f707@@c@sta/stdlib_strtol.c.o'.
../src/stdlib/strtol.c:158:44: warning: implicit conversion from 'long long' to 'unsigned long' changes value from 9223372036854775807 to 4294967295 [-Wconstant-conversion]
        cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
               ~                                  ^~~~~~~~
../arch/aarch64/include/_limits.h:5:18: note: expanded from macro 'LONG_MAX'
#define LONG_MAX 0x7fffffffffffffffL
                 ^~~~~~~~~~~~~~~~~~~
1 warning generated.
[102/532] Compiling C object 'src/e88f707@@c@sta/stdlib_strtoul.c.o'.
../src/stdlib/strtoul.c:126:26: warning: overflow in expression; result is -2 with type 'long long' [-Winteger-overflow]
        cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
                                ^
../include/limits.h:61:24: note: expanded from macro 'ULONG_MAX'
#define ULONG_MAX (2UL * LONG_MAX + 1)
                       ^
../src/stdlib/strtoul.c:127:32: warning: overflow in expression; result is -2 with type 'long long' [-Winteger-overflow]
        cutlim = (int)((unsigned long)ULONG_MAX % (unsigned long)base);
                                      ^
../include/limits.h:61:24: note: expanded from macro 'ULONG_MAX'
#define ULONG_MAX (2UL * LONG_MAX + 1)
                       ^
../src/stdlib/strtoul.c:161:9: warning: overflow in expression; result is -2 with type 'long long' [-Winteger-overflow]
                acc = ULONG_MAX;
                      ^
../include/limits.h:61:24: note: expanded from macro 'ULONG_MAX'
#define ULONG_MAX (2UL * LONG_MAX + 1)
                       ^
3 warnings generated.
[127/532] Compiling C object 'src/e88f707@@c@sta/string_strlen.c.o'.
../src/string/strlen.c:58:37: warning: implicit conversion from 'long long' to 'unsigned long' changes value from 72340172838076673 to 16843009 [-Wconstant-conversion]
static const unsigned long mask01 = 0x0101010101010101;
                           ~~~~~~   ^~~~~~~~~~~~~~~~~~
../src/string/strlen.c:59:37: warning: implicit conversion from 'unsigned long long' to 'unsigned long' changes value from 9259542123273814144 to 2155905152 [-Wconstant-conversion]
static const unsigned long mask80 = 0x8080808080808080;
                           ~~~~~~   ^~~~~~~~~~~~~~~~~~
2 warnings generated.
[396/532] Compiling C object 'src/e88f707@@c_hosted@sta/stdlib_strtol.c.o'.
../src/stdlib/strtol.c:158:44: warning: implicit conversion from 'long long' to 'unsigned long' changes value from 9223372036854775807 to 4294967295 [-Wconstant-conversion]
        cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
               ~                                  ^~~~~~~~
../arch/aarch64/include/_limits.h:5:18: note: expanded from macro 'LONG_MAX'
#define LONG_MAX 0x7fffffffffffffffL
                 ^~~~~~~~~~~~~~~~~~~
1 warning generated.
[397/532] Compiling C object 'src/e88f707@@c_hosted@sta/stdlib_strtoul.c.o'.
../src/stdlib/strtoul.c:126:26: warning: overflow in expression; result is -2 with type 'long long' [-Winteger-overflow]
        cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
                                ^
../include/limits.h:61:24: note: expanded from macro 'ULONG_MAX'
#define ULONG_MAX (2UL * LONG_MAX + 1)
                       ^
../src/stdlib/strtoul.c:127:32: warning: overflow in expression; result is -2 with type 'long long' [-Winteger-overflow]
        cutlim = (int)((unsigned long)ULONG_MAX % (unsigned long)base);
                                      ^
../include/limits.h:61:24: note: expanded from macro 'ULONG_MAX'
#define ULONG_MAX (2UL * LONG_MAX + 1)
                       ^
../src/stdlib/strtoul.c:161:9: warning: overflow in expression; result is -2 with type 'long long' [-Winteger-overflow]
                acc = ULONG_MAX;
                      ^
../include/limits.h:61:24: note: expanded from macro 'ULONG_MAX'
#define ULONG_MAX (2UL * LONG_MAX + 1)
                       ^
3 warnings generated.
[423/532] Compiling C object 'src/e88f707@@c_hosted@sta/string_strlen.c.o'.
../src/string/strlen.c:58:37: warning: implicit conversion from 'long long' to 'unsigned long' changes value from 72340172838076673 to 16843009 [-Wconstant-conversion]
static const unsigned long mask01 = 0x0101010101010101;
                           ~~~~~~   ^~~~~~~~~~~~~~~~~~
../src/string/strlen.c:59:37: warning: implicit conversion from 'unsigned long long' to 'unsigned long' changes value from 9259542123273814144 to 2155905152 [-Wconstant-conversion]
static const unsigned long mask80 = 0x8080808080808080;
                           ~~~~~~   ^~~~~~~~~~~~~~~~~~
2 warnings generated.
eyalroz commented 3 years ago

Well, this libc uses mpaland/printf; these warnings, along with many actual bugs and even a case of undefined behavior, are all resolved in the unified fork I've been working on. See also issue #159 where I suggested adopting it.

phillipjohnston commented 3 years ago

Just noting for my future self: the first warning is printf, but the rest are problems within libc for aarch64

phillipjohnston commented 2 years ago

Resolved all of these.