From patchwork Thu Jul 16 23:38:01 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Dubiec X-Patchwork-Id: 139371 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 94B364BA23C6 for ; Thu, 16 Jul 2026 23:40:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 94B364BA23C6 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=sHg8CG5h X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mx-out.tlen.pl (mx-out.tlen.pl [193.222.135.148]) by sourceware.org (Postfix) with ESMTPS id 046304BA2E10 for ; Thu, 16 Jul 2026 23:39:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 046304BA2E10 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 046304BA2E10 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=193.222.135.148 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784245178; cv=none; b=mVq9rkUOgJqx0EOPmqwbvpe2jIpAo7djHw5ny0DZEzJpk07xJ1Cwe4XsFEuM8wBtMZ52s1HH9Ucvv8snEzn9KFq+58BiB+bmpnxBGwcXXkmWHaDTBAxrkNS/kxQANy+NgTchn/Hr9ZM97mL3/Ut2NiHUScJgOY1aMC6KQHdDAd0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784245178; c=relaxed/simple; bh=jsYNJ3O0PyiOXMI/pmt2Gx62DnUCobxjgGz6fzQum7A=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=EbFC3seZFidQ1r/c5JfktXrvsVexn6IrEA5HnDS65lwbmtawVzXsF+ct2SlCPajy9QOyRPQiIME2h/eDzs/Fl+kLPSeoF8klI/pd7JuFsOEbEf7XbV8DGgfWdNiamP7/8QIjLJB/oT/d6A/lMJnn0m0lchFmB3CvAMW6avD9EZk= 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=sHg8CG5h DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 046304BA2E10 Received: (wp-smtpd smtp.tlen.pl 28621 invoked from network); 17 Jul 2026 01:39:35 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=o2.pl; s=20241105; t=1784245175; bh=UUip07zXAr6OmPgzrNfBzkNzZ2qh3GAbWUPBApc7g14=; h=From:To:Cc:Subject; b=sHg8CG5h2hbOFDECv03drTn8WHl4RZYMFHi/ArLNxWo/rcvErx1ZDIR8ObThrCP51 tI3Mhch2y8+Ahq30pQIHvHvTCufaxK5VwRmxpuhtN5qbPw0Maczh+Vr596+sRxwJ5y DU/7JoX4nmEYTWl1mIRXBSKCsa9HR7Q7DsAireTh+Py5ptcx1iHxj4KDmt2b35giLf NZWXH6EcwwM1mSuiVSKa5BNED7zFSWPjYD4FZhT8FjvPvSTuZm8lRsdvpFN1dpyh19 RBTuQvPZZWl85/nDe4UkbyJz4KvGtybp3fgcjLPx3Re+V+VbyJUQEEedHEomhqj3Oh wGImHn9V9rSwg== Received: from ip-94-42-231-121.multimo.pl (HELO jdxpc) (jdx@o2.pl@[94.42.231.121]) (envelope-sender ) by smtp.tlen.pl (WP-SMTPD) with TLS_AES_256_GCM_SHA384 encrypted SMTP for ; 17 Jul 2026 01:39:35 +0200 From: Jan Dubiec To: newlib@sourceware.org Cc: Jan Dubiec Subject: [PATCH] Silence -Wpointer-to-int-cast warnings in newlib/libc/string/local.h. Date: Fri, 17 Jul 2026 01:38:01 +0200 Message-ID: <20260716233918.1010059-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: fcd6562f91616179c678c55095fef7c3 X-WP-AV: skaner antywirusowy Poczty o2 X-WP-SPAM: NO 0000002 [gYGj] X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, 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 Compiling the library for a 16-bit target results in numerous warnings (some of which are shown below) in the mem*, str*, and several other functions. The existing code incorrectly assumes that pointers are 32 bits wide. This patch removes that assumption and fixes the resulting warnings. [...] CC libc/string/libc_a-memchr.o In file included from ../../../../../../../newlib/newlib/libc/string/memchr.c:35: ../../../../../../../newlib/newlib/libc/string/memchr.c: In function 'memchr': ../../../../../../../newlib/newlib/libc/string/local.h:24:25: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] 24 | #define UNALIGNED_X(X) ((long)(X) & (sizeof (long) - 1)) | ^ ../../../../../../../newlib/newlib/libc/string/memchr.c:50:10: note: in expansion of macro 'UNALIGNED_X' 50 | while (UNALIGNED_X(src)) | ^~~~~~~~~~~ CC libc/string/libc_a-memcmp.o In file included from ../../../../../../../newlib/newlib/libc/string/memcmp.c:33: ../../../../../../../newlib/newlib/libc/string/memcmp.c: In function 'memcmp': ../../../../../../../newlib/newlib/libc/string/local.h:33:5: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] 33 | (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) | ^ ../../../../../../../newlib/newlib/libc/string/memcmp.c:63:38: note: in expansion of macro 'UNALIGNED_X_Y' 63 | if (!TOO_SMALL_LITTLE_BLOCK(n) && !UNALIGNED_X_Y(s1,s2)) | ^~~~~~~~~~~~~ ../../../../../../../newlib/newlib/libc/string/local.h:33:39: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] 33 | (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) | ^ ../../../../../../../newlib/newlib/libc/string/memcmp.c:63:38: note: in expansion of macro 'UNALIGNED_X_Y' 63 | if (!TOO_SMALL_LITTLE_BLOCK(n) && !UNALIGNED_X_Y(s1,s2)) | ^~~~~~~~~~~~~ [...] Signed-off-by: Jan Dubiec --- newlib/libc/string/local.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/newlib/libc/string/local.h b/newlib/libc/string/local.h index 012a30d16..79436ab69 100644 --- a/newlib/libc/string/local.h +++ b/newlib/libc/string/local.h @@ -1,5 +1,6 @@ #include <_ansi.h> #include <../ctype/local.h> +#include /* internal function to compute width of wide char. */ int __wcwidth (wint_t); @@ -17,11 +18,24 @@ int __wcwidth (wint_t); # define __inhibit_loop_to_libcall #endif +#ifdef __INTPTR_TYPE__ + #define INTPTRTYPE intptr_t +#else + /* Fallback, just in case there is no intptr_t on a target... */ + #if __SIZEOF_POINTER__ > __SIZEOF_SHORT__ + /* 32-bit targets; the default */ + #define INTPTRTYPE long + #else + /* 16-bit targets; we silently assume sizeof(short)==2 and sizeof(long)==4 */ + #define INTPTRTYPE short + #endif +#endif + /* Nonzero if X is not aligned on a "long" boundary. * This macro is used to skip a few bytes to find an aligned pointer. * It's better to keep it as is even if _HAVE_HW_MISALIGNED_ACCESS is enabled, * to avoid small performance penalties (if they are not zero). */ -#define UNALIGNED_X(X) ((long)(X) & (sizeof (long) - 1)) +#define UNALIGNED_X(X) ((long)(INTPTRTYPE)(X) & (sizeof (long) - 1)) #ifdef _HAVE_HW_MISALIGNED_ACCESS /* Hardware performs unaligned operations with little @@ -30,7 +44,8 @@ int __wcwidth (wint_t); #else /* _HAVE_HW_MISALIGNED_ACCESS */ /* Nonzero if either X or Y is not aligned on a "long" boundary. */ #define UNALIGNED_X_Y(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) + (((long)(INTPTRTYPE)X & (sizeof (long) - 1)) | \ + ((long)(INTPTRTYPE)Y & (sizeof (long) - 1))) #endif /* _HAVE_HW_MISALIGNED_ACCESS */ /* How many bytes are copied each iteration of the word copy loop. */