Re: [PATCH] Fix newlib/testsuite/newlib.search/hsearchtest.c compilation for 16-bit targets.
Jeff Johnston <[email protected]> Tue, 14 Jul 2026 20:08:46 -0400
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <CAOox84sD02pX+94vq88g0Y6NAfOYmJ=vpb86+7eu_8OafYzf1A@mail.gmail.com> |
--00000000000049a1e606569b21cd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Patch merged. -- Jeff J. On Sun, Jul 12, 2026 at 9:11=E2=80=AFPM Jan Dubiec <[email protected]> wrote: > When the test case is compiled for a 16-bit target, the compiler emits > the two warnings shown below, causing the test to fail. The code assumes > that pointers are 32 bits wide, which obviously is not true. This patch > fixes the issue. > > h8300-elf-gcc > /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c -mn > -I/mnt/Works/newlib/newlib/testsuite/include -lm -o > /mnt/Works/xcomp/build-newlib-h8300-linux/h8300-elf/newlib/testsuite/hsea= rchtest.x > /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c: In > function 'main': > /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:80:26: > warning: cast to pointer from integer of different size > [-Wint-to-pointer-cast] > 80 | e.data =3D (void *)(long)i; > | ^ > /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:84:22: > warning: cast from pointer to integer of different size > [-Wpointer-to-int-cast] > 84 | TEST((long)ep->data =3D=3D i); > | ^ > /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:50:19: > note: in definition of macro 'TEST' > 50 | #define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LINE__, #e)= ) > | ^ > /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:96:22: > warning: cast from pointer to integer of different size > [-Wpointer-to-int-cast] > 96 | TEST((long)ep->data =3D=3D i); > | ^ > /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:50:19: > note: in definition of macro 'TEST' > 50 | #define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LINE__, #e)= ) > | ^ > /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:105:14: > warning: cast from pointer to integer of different size > [-Wpointer-to-int-cast] > 105 | TEST((long)ep->data =3D=3D 0); > | ^ > /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:50:19: > note: in definition of macro 'TEST' > 50 | #define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LINE__, #e)= ) > | ^ > /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:118:43: > warning: cast from pointer to integer of different size > [-Wpointer-to-int-cast] > 118 | TEST(strcmp(ep->key, "a") =3D=3D 0 && (long)ep->data =3D= =3D 0); > | ^ > /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:50:19: > note: in definition of macro 'TEST' > 50 | #define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LINE__, #e)= ) > | ^ > /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:120:44: > warning: cast from pointer to integer of different size > [-Wpointer-to-int-cast] > 120 | TEST(strcmp(ep2->key, "b") =3D=3D 0 && (long)ep2->data = =3D=3D 1); > | ^ > /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:50:19: > note: in definition of macro 'TEST' > 50 | #define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LINE__, #e)= ) > | ^ > > Signed-off-by: Jan Dubiec <[email protected]> > --- > newlib/testsuite/newlib.search/hsearchtest.c | 22 +++++++++++++++------- > 1 file changed, 15 insertions(+), 7 deletions(-) > > diff --git a/newlib/testsuite/newlib.search/hsearchtest.c > b/newlib/testsuite/newlib.search/hsearchtest.c > index 515440382..418b0c5d6 100644 > --- a/newlib/testsuite/newlib.search/hsearchtest.c > +++ b/newlib/testsuite/newlib.search/hsearchtest.c > @@ -46,6 +46,14 @@ __COPYRIGHT( > #include <stdlib.h> > #include <stdio.h> > #include <string.h> > +#include <stdint.h> > + > +#ifdef __INTPTR_TYPE__ > + #define INTPTRTYPE intptr_t > +#else > + /* Just in case there is no intptr_t on a target... */ > + #define INTPTRTYPE long > +#endif > > #define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LINE__, #e)= ) > > @@ -77,11 +85,11 @@ main(int argc, char *argv[]) > ch[0] =3D 'a' + i; > e.key =3D strdup(ch); /* ptr to provided key is kept!= */ > TEST(e.key !=3D NULL); > - e.data =3D (void *)(long)i; > + e.data =3D (void *)(INTPTRTYPE)i; > ep =3D hsearch(e, ENTER); > TEST(ep !=3D NULL); > TEST(strcmp(ep->key, ch) =3D=3D 0); > - TEST((long)ep->data =3D=3D i); > + TEST((INTPTRTYPE)ep->data =3D=3D i); > } > > /* e.key should be constant from here on down. */ > @@ -93,16 +101,16 @@ main(int argc, char *argv[]) > ep =3D hsearch(e, FIND); > TEST(ep !=3D NULL); > TEST(strcmp(ep->key, ch) =3D=3D 0); > - TEST((long)ep->data =3D=3D i); > + TEST((INTPTRTYPE)ep->data =3D=3D i); > } > > /* Check duplicate entry. Should _not_ overwrite existing data. > */ > ch[0] =3D 'a'; > - e.data =3D (void *)(long)12345; > + e.data =3D (void *)(INTPTRTYPE)12345; > ep =3D hsearch(e, FIND); > TEST(ep !=3D NULL); > TEST(strcmp(ep->key, ch) =3D=3D 0); > - TEST((long)ep->data =3D=3D 0); > + TEST((INTPTRTYPE)ep->data =3D=3D 0); > > /* Check for something that's not there. */ > ch[0] =3D 'A'; > @@ -115,9 +123,9 @@ main(int argc, char *argv[]) > ch[0] =3D 'b'; > ep2 =3D hsearch(e, FIND); > TEST(ep !=3D NULL); > - TEST(strcmp(ep->key, "a") =3D=3D 0 && (long)ep->data =3D=3D 0); > + TEST(strcmp(ep->key, "a") =3D=3D 0 && (INTPTRTYPE)ep->data =3D=3D= 0); > TEST(ep2 !=3D NULL); > - TEST(strcmp(ep2->key, "b") =3D=3D 0 && (long)ep2->data =3D=3D 1); > + TEST(strcmp(ep2->key, "b") =3D=3D 0 && (INTPTRTYPE)ep2->data =3D= =3D 1); > > hdestroy(); > > -- > 2.54.0 > > --00000000000049a1e606569b21cd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:verdana,= sans-serif">Patch merged.</div><div class=3D"gmail_default" style=3D"font-f= amily:verdana,sans-serif"><br></div><div class=3D"gmail_default" style=3D"f= ont-family:verdana,sans-serif">-- Jeff J.</div></div><br><div class=3D"gmai= l_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Sun= , Jul 12, 2026 at 9:11=E2=80=AFPM Jan Dubiec <<a href=3D"mailto:[email protected]= l">[email protected]</a>> wrote:<br></div><blockquote class=3D"gmail_quote" styl= e=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddin= g-left:1ex">When the test case is compiled for a 16-bit target, the compile= r emits<br> the two warnings shown below, causing the test to fail. The code assumes<br= > that pointers are 32 bits wide, which obviously is not true. This patch<br> fixes the issue.<br> <br> h8300-elf-gcc /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.= c=C2=A0 -mn=C2=A0 =C2=A0 =C2=A0 -I/mnt/Works/newlib/newlib/testsuite/includ= e -lm=C2=A0 -o /mnt/Works/xcomp/build-newlib-h8300-linux/h8300-elf/newlib/t= estsuite/hsearchtest.x<br> /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c: In function= 'main':<br> /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:80:26: warni= ng: cast to pointer from integer of different size [-Wint-to-pointer-cast]<= br> =C2=A0 =C2=A080 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0e.data =3D (void *)(long)i;<br> =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ^<br> /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:84:22: warni= ng: cast from pointer to integer of different size [-Wpointer-to-int-cast]<= br> =C2=A0 =C2=A084 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0TEST((long)ep->data =3D=3D i);<br> =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 ^<br> /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:50:19: note:= in definition of macro 'TEST'<br> =C2=A0 =C2=A050 | #define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LIN= E__, #e))<br> =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0^<br> /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:96:22: warni= ng: cast from pointer to integer of different size [-Wpointer-to-int-cast]<= br> =C2=A0 =C2=A096 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0TEST((long)ep->data =3D=3D i);<br> =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 ^<br> /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:50:19: note:= in definition of macro 'TEST'<br> =C2=A0 =C2=A050 | #define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LIN= E__, #e))<br> =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0^<br> /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:105:14: warn= ing: cast from pointer to integer of different size [-Wpointer-to-int-cast]= <br> =C2=A0 105 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0TEST((long)ep->data =3D=3D= 0);<br> =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ^<br= > /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:50:19: note:= in definition of macro 'TEST'<br> =C2=A0 =C2=A050 | #define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LIN= E__, #e))<br> =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0^<br> /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:118:43: warn= ing: cast from pointer to integer of different size [-Wpointer-to-int-cast]= <br> =C2=A0 118 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0TEST(strcmp(ep->key, "= ;a") =3D=3D 0 && (long)ep->data =3D=3D 0);<br> =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0^<br> /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:50:19: note:= in definition of macro 'TEST'<br> =C2=A0 =C2=A050 | #define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LIN= E__, #e))<br> =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0^<br> /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:120:44: warn= ing: cast from pointer to integer of different size [-Wpointer-to-int-cast]= <br> =C2=A0 120 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0TEST(strcmp(ep2->key, &quo= t;b") =3D=3D 0 && (long)ep2->data =3D=3D 1);<br> =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 ^<br> /mnt/Works/newlib/newlib/testsuite/newlib.search/hsearchtest.c:50:19: note:= in definition of macro 'TEST'<br> =C2=A0 =C2=A050 | #define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LIN= E__, #e))<br> =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0^<br> <br> Signed-off-by: Jan Dubiec <<a href=3D"mailto:[email protected]" target=3D"_blank= ">[email protected]</a>><br> ---<br> =C2=A0newlib/testsuite/newlib.search/hsearchtest.c | 22 +++++++++++++++----= ---<br> =C2=A01 file changed, 15 insertions(+), 7 deletions(-)<br> <br> diff --git a/newlib/testsuite/newlib.search/hsearchtest.c b/newlib/testsuit= e/newlib.search/hsearchtest.c<br> index 515440382..418b0c5d6 100644<br> --- a/newlib/testsuite/newlib.search/hsearchtest.c<br> +++ b/newlib/testsuite/newlib.search/hsearchtest.c<br> @@ -46,6 +46,14 @@ __COPYRIGHT(<br> =C2=A0#include <stdlib.h><br> =C2=A0#include <stdio.h><br> =C2=A0#include <string.h><br> +#include <stdint.h><br> +<br> +#ifdef __INTPTR_TYPE__<br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0#define INTPTRTYPE intptr_t<br> +#else<br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0/* Just in case there is no intptr_t on a targe= t... */<br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0#define INTPTRTYPE long<br> +#endif<br> <br> =C2=A0#define=C2=A0 =C2=A0 =C2=A0 =C2=A0 TEST(e) ((e) ? (void)0 : testfail(= __FILE__, __LINE__, #e))<br> <br> @@ -77,11 +85,11 @@ main(int argc, char *argv[])<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ch[0] =3D 'a= 9; + i;<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 e.key =3D strdup(ch= );=C2=A0 =C2=A0 =C2=A0/* ptr to provided key is kept! */<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 TEST(e.key !=3D NUL= L);<br> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0e.data =3D (void *)= (long)i;<br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0e.data =3D (void *)= (INTPTRTYPE)i;<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ep =3D hsearch(e, E= NTER);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 TEST(ep !=3D NULL);= <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 TEST(strcmp(ep->= key, ch) =3D=3D 0);<br> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0TEST((long)ep->d= ata =3D=3D i);<br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0TEST((INTPTRTYPE)ep= ->data =3D=3D i);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br> <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* e.key should be constant from here on down. = */<br> @@ -93,16 +101,16 @@ main(int argc, char *argv[])<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ep =3D hsearch(e, F= IND);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 TEST(ep !=3D NULL);= <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 TEST(strcmp(ep->= key, ch) =3D=3D 0);<br> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0TEST((long)ep->d= ata =3D=3D i);<br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0TEST((INTPTRTYPE)ep= ->data =3D=3D i);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br> <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Check duplicate entry.=C2=A0 Should _not_ ov= erwrite existing data.=C2=A0 */<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 ch[0] =3D 'a';<br> -=C2=A0 =C2=A0 =C2=A0 =C2=A0e.data =3D (void *)(long)12345;<br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0e.data =3D (void *)(INTPTRTYPE)12345;<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 ep =3D hsearch(e, FIND);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 TEST(ep !=3D NULL);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 TEST(strcmp(ep->key, ch) =3D=3D 0);<br> -=C2=A0 =C2=A0 =C2=A0 =C2=A0TEST((long)ep->data =3D=3D 0);<br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0TEST((INTPTRTYPE)ep->data =3D=3D 0);<br> <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Check for something that's not there. */= <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 ch[0] =3D 'A';<br> @@ -115,9 +123,9 @@ main(int argc, char *argv[])<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 ch[0] =3D 'b';<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 ep2 =3D hsearch(e, FIND);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 TEST(ep !=3D NULL);<br> -=C2=A0 =C2=A0 =C2=A0 =C2=A0TEST(strcmp(ep->key, "a") =3D=3D 0= && (long)ep->data =3D=3D 0);<br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0TEST(strcmp(ep->key, "a") =3D=3D 0= && (INTPTRTYPE)ep->data =3D=3D 0);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 TEST(ep2 !=3D NULL);<br> -=C2=A0 =C2=A0 =C2=A0 =C2=A0TEST(strcmp(ep2->key, "b") =3D=3D = 0 && (long)ep2->data =3D=3D 1);<br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0TEST(strcmp(ep2->key, "b") =3D=3D = 0 && (INTPTRTYPE)ep2->data =3D=3D 1);<br> <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 hdestroy();<br> <br> -- <br> 2.54.0<br> <br> </blockquote></div> --00000000000049a1e606569b21cd--