<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">Hi Jan,</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">The fallback for intptr_t is unnecessary.  According to libc/include/sys/_intsup.h, gcc 3.2 or higher should support</div><div class="gmail_default" style="font-family:verdana,sans-serif">the intptr info we need plus there is an #error statement if it isn't.  So, the code should just use intptr_t.  </div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">-- Jeff J.</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Thu, Jul 16, 2026 at 7:40 PM Jan Dubiec <<a href="mailto:jdx@o2.pl">jdx@o2.pl</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Compiling the library for a 16-bit target results in numerous warnings<br>
(some of which are shown below) in the mem*, str*, and several other<br>
functions. The existing code incorrectly assumes that pointers are 32<br>
bits wide. This patch removes that assumption and fixes the resulting<br>
warnings.<br>
<br>
[...]<br>
  CC       libc/string/libc_a-memchr.o<br>
In file included from ../../../../../../../newlib/newlib/libc/string/memchr.c:35:<br>
../../../../../../../newlib/newlib/libc/string/memchr.c: In function 'memchr':<br>
../../../../../../../newlib/newlib/libc/string/local.h:24:25: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]<br>
   24 | #define UNALIGNED_X(X) ((long)(X) & (sizeof (long) - 1))<br>
      |                         ^<br>
../../../../../../../newlib/newlib/libc/string/memchr.c:50:10: note: in expansion of macro 'UNALIGNED_X'<br>
   50 |   while (UNALIGNED_X(src))<br>
      |          ^~~~~~~~~~~<br>
  CC       libc/string/libc_a-memcmp.o<br>
In file included from ../../../../../../../newlib/newlib/libc/string/memcmp.c:33:<br>
../../../../../../../newlib/newlib/libc/string/memcmp.c: In function 'memcmp':<br>
../../../../../../../newlib/newlib/libc/string/local.h:33:5: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]<br>
   33 |   (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))<br>
      |     ^<br>
../../../../../../../newlib/newlib/libc/string/memcmp.c:63:38: note: in expansion of macro 'UNALIGNED_X_Y'<br>
   63 |   if (!TOO_SMALL_LITTLE_BLOCK(n) && !UNALIGNED_X_Y(s1,s2))<br>
      |                                      ^~~~~~~~~~~~~<br>
../../../../../../../newlib/newlib/libc/string/local.h:33:39: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]<br>
   33 |   (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))<br>
      |                                       ^<br>
../../../../../../../newlib/newlib/libc/string/memcmp.c:63:38: note: in expansion of macro 'UNALIGNED_X_Y'<br>
   63 |   if (!TOO_SMALL_LITTLE_BLOCK(n) && !UNALIGNED_X_Y(s1,s2))<br>
      |                                      ^~~~~~~~~~~~~<br>
[...]<br>
<br>
Signed-off-by: Jan Dubiec <<a href="mailto:jdx@o2.pl" target="_blank">jdx@o2.pl</a>><br>
---<br>
 newlib/libc/string/local.h | 19 +++++++++++++++++--<br>
 1 file changed, 17 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/newlib/libc/string/local.h b/newlib/libc/string/local.h<br>
index 012a30d16..79436ab69 100644<br>
--- a/newlib/libc/string/local.h<br>
+++ b/newlib/libc/string/local.h<br>
@@ -1,5 +1,6 @@<br>
 #include <_ansi.h><br>
 #include <../ctype/local.h><br>
+#include <stdint.h><br>
<br>
 /* internal function to compute width of wide char. */<br>
 int __wcwidth (wint_t);<br>
@@ -17,11 +18,24 @@ int __wcwidth (wint_t);<br>
 # define __inhibit_loop_to_libcall<br>
 #endif<br>
<br>
+#ifdef __INTPTR_TYPE__<br>
+  #define INTPTRTYPE intptr_t<br>
+#else<br>
+  /* Fallback, just in case there is no intptr_t on a target... */<br>
+  #if __SIZEOF_POINTER__ > __SIZEOF_SHORT__<br>
+    /* 32-bit targets; the default */<br>
+       #define INTPTRTYPE long<br>
+  #else<br>
+    /* 16-bit targets; we silently assume sizeof(short)==2 and sizeof(long)==4 */<br>
+       #define INTPTRTYPE short<br>
+  #endif<br>
+#endif<br>
+<br>
 /* Nonzero if X is not aligned on a "long" boundary.<br>
  * This macro is used to skip a few bytes to find an aligned pointer.<br>
  * It's better to keep it as is even if _HAVE_HW_MISALIGNED_ACCESS is enabled,<br>
  * to avoid small performance penalties (if they are not zero).  */<br>
-#define UNALIGNED_X(X) ((long)(X) & (sizeof (long) - 1))<br>
+#define UNALIGNED_X(X) ((long)(INTPTRTYPE)(X) & (sizeof (long) - 1))<br>
<br>
 #ifdef _HAVE_HW_MISALIGNED_ACCESS<br>
 /* Hardware performs unaligned operations with little<br>
@@ -30,7 +44,8 @@ int __wcwidth (wint_t);<br>
 #else /* _HAVE_HW_MISALIGNED_ACCESS */<br>
 /* Nonzero if either X or Y is not aligned on a "long" boundary.  */<br>
 #define UNALIGNED_X_Y(X, Y) \<br>
-  (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))<br>
+  (((long)(INTPTRTYPE)X & (sizeof (long) - 1)) | \<br>
+   ((long)(INTPTRTYPE)Y & (sizeof (long) - 1)))<br>
 #endif /* _HAVE_HW_MISALIGNED_ACCESS */<br>
<br>
 /* How many bytes are copied each iteration of the word copy loop.  */<br>
-- <br>
2.54.0<br>
<br>
</blockquote></div>