From patchwork Mon Jul 13 01:10:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Dubiec X-Patchwork-Id: 138995 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8587A4BA2E11 for ; Mon, 13 Jul 2026 01:11:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8587A4BA2E11 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=o2.pl header.i=@o2.pl header.a=rsa-sha256 header.s=20241105 header.b=GQEpqCiS X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mx-out.tlen.pl (mx-out.tlen.pl [193.222.135.142]) by sourceware.org (Postfix) with ESMTPS id 17C214BA2E05 for ; Mon, 13 Jul 2026 01:11:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17C214BA2E05 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=o2.pl Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=o2.pl ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 17C214BA2E05 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=193.222.135.142 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783905074; cv=none; b=nwYxUlNlrSl9AS6xUVwUqNdlmzaGTtSW6C0CA8DWOdlh2CobQvOQRFfiV+M58fXm7dS/FJ7lH+lrRllcXDoHTRh8sdq64waJf4TbNYmV4dvkUGJfKEeqRs1/FemNI2xhWVNgJShTDvLZqFEpTqjORd9CGpMJP14dPSDTPzqJXgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783905074; c=relaxed/simple; bh=iYciX6r5rGqeSoVq5X39laXBW7w18NrqFyEVfv+q1A8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=cXHAsdFM93XuNUYyyAJVhkituFR7yHg6N/JSbFgbSx3DQHvJHSdD2vGQBCgi1Qcal5yiTqoPjSK+wXynUaeaaxwtIy0gXXwT70OyFmrhwqYQvjhnGMPqQoyAo71C4ckzUYM9iXzFMTMiRz1JeKDVCy7HjXufco9gsK/gR8mP3MM= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=o2.pl header.i=@o2.pl header.a=rsa-sha256 header.s=20241105 header.b=GQEpqCiS DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 17C214BA2E05 Received: (wp-smtpd smtp.tlen.pl 48757 invoked from network); 13 Jul 2026 03:11:12 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=o2.pl; s=20241105; t=1783905072; bh=gYY0oHWi31YIc/qKVSdUGoYrlSCNkgtbvE7BibDqiw8=; h=From:To:Cc:Subject; b=GQEpqCiSrIBgK1sAgobi4qnx+xrf1YXUUTvEjQETqag3n/Ws5R2OJS+9PVMockh9G NaQkunwXfxtdb8GJZPa3gbGA09EHWefy/Z6UhzXHUjqL5NWrK/UQ8jyfZ2j7wwoDwt nE4PkM7RTMtfZKGkXdg06PmltkgAiCuMrSiilBtgtSZHVUDimy2eW2XnK4lDNDW53u oSAeXnfHiZE26xpQYZsZJeT4I4GSQfoCrc2g6VcwZ+dl8EK1dv1692E2dsB5wZidxB fuP/7saP8YDu1LRLFDvBQZDl/psz/kdiapK7KnwQ3Id9NfK8ECDP7YN8wnGzxCpbiG YlYgBqorO2GNQ== Received: from ip-94-42-225-247.multimo.pl (HELO jdxpc) (jdx@o2.pl@[94.42.225.247]) (envelope-sender ) by smtp.tlen.pl (WP-SMTPD) with TLS_AES_256_GCM_SHA384 encrypted SMTP for ; 13 Jul 2026 03:11:12 +0200 From: Jan Dubiec To: newlib@sourceware.org Cc: Jan Dubiec Subject: [PATCH] Fix newlib/testsuite/newlib.search/hsearchtest.c compilation for 16-bit targets. Date: Mon, 13 Jul 2026 03:10:28 +0200 Message-ID: <20260713011103.744588-1-jdx@o2.pl> X-Mailer: git-send-email 2.54.0 MIME-Version: 1.0 X-WP-DKIM-Status: good (id: o2.pl) X-WP-MailID: 84caaee8c52c740649e1202fec1c6897 X-WP-AV: skaner antywirusowy Poczty o2 X-WP-SPAM: NO 0000001 [8TLs] X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: newlib-bounces~patchwork=sourceware.org@sourceware.org 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/hsearchtest.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 = (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 == 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 == 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 == 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") == 0 && (long)ep->data == 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") == 0 && (long)ep2->data == 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 --- 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 #include #include +#include + +#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] = 'a' + i; e.key = strdup(ch); /* ptr to provided key is kept! */ TEST(e.key != NULL); - e.data = (void *)(long)i; + e.data = (void *)(INTPTRTYPE)i; ep = hsearch(e, ENTER); TEST(ep != NULL); TEST(strcmp(ep->key, ch) == 0); - TEST((long)ep->data == i); + TEST((INTPTRTYPE)ep->data == i); } /* e.key should be constant from here on down. */ @@ -93,16 +101,16 @@ main(int argc, char *argv[]) ep = hsearch(e, FIND); TEST(ep != NULL); TEST(strcmp(ep->key, ch) == 0); - TEST((long)ep->data == i); + TEST((INTPTRTYPE)ep->data == i); } /* Check duplicate entry. Should _not_ overwrite existing data. */ ch[0] = 'a'; - e.data = (void *)(long)12345; + e.data = (void *)(INTPTRTYPE)12345; ep = hsearch(e, FIND); TEST(ep != NULL); TEST(strcmp(ep->key, ch) == 0); - TEST((long)ep->data == 0); + TEST((INTPTRTYPE)ep->data == 0); /* Check for something that's not there. */ ch[0] = 'A'; @@ -115,9 +123,9 @@ main(int argc, char *argv[]) ch[0] = 'b'; ep2 = hsearch(e, FIND); TEST(ep != NULL); - TEST(strcmp(ep->key, "a") == 0 && (long)ep->data == 0); + TEST(strcmp(ep->key, "a") == 0 && (INTPTRTYPE)ep->data == 0); TEST(ep2 != NULL); - TEST(strcmp(ep2->key, "b") == 0 && (long)ep2->data == 1); + TEST(strcmp(ep2->key, "b") == 0 && (INTPTRTYPE)ep2->data == 1); hdestroy();