From 91c91926269b00f82f688011c81fb7ad6633b81d Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Tue, 19 Jan 2021 14:45:53 +0100 Subject: [PATCH] software/include/base: Fix size_t, ptrdiff_t, and (u)intptr_t As per convention, the types of size_t, ptrdiff_t, intptr_t, and uintptr_t should be based on "long" or "int" depending on the platform (32-bit or 64-bit). This fixes compiler warnings of the following type: litex/soc/software/liblitesdcard/sdcard.c: In function 'sdcard_read': litex/soc/software/liblitesdcard/sdcard.c:476:39: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] sdblock2mem_dma_base_write((uint64_t)(uintptr_t) buf); ^ Reported-by: Gabriel Somlo Signed-off-by: Geert Uytterhoeven --- litex/soc/software/include/base/stddef.h | 5 +++++ litex/soc/software/include/base/stdint.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/litex/soc/software/include/base/stddef.h b/litex/soc/software/include/base/stddef.h index 4f9a211f7..858d70b3e 100644 --- a/litex/soc/software/include/base/stddef.h +++ b/litex/soc/software/include/base/stddef.h @@ -11,8 +11,13 @@ extern "C" { #define NULL ((void *)0) #endif +#ifdef __LP64__ typedef unsigned long size_t; typedef long ptrdiff_t; +#else +typedef unsigned int size_t; +typedef int ptrdiff_t; +#endif #define offsetof(type, member) __builtin_offsetof(type, member) diff --git a/litex/soc/software/include/base/stdint.h b/litex/soc/software/include/base/stdint.h index bff5d0983..a17e1739a 100644 --- a/litex/soc/software/include/base/stdint.h +++ b/litex/soc/software/include/base/stdint.h @@ -5,8 +5,13 @@ extern "C" { #endif +#ifdef __LP64__ +typedef long intptr_t; +typedef unsigned long uintptr_t; +#else typedef int intptr_t; typedef unsigned int uintptr_t; +#endif typedef unsigned long long uint64_t; typedef unsigned int uint32_t;