diff options
author | Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> | 2021-07-12 13:58:10 +0100 |
---|---|---|
committer | Werner Lemberg <wl@gnu.org> | 2021-07-15 12:09:04 +0200 |
commit | f7c6a06cb7458c8972955ebd698058d0957a0a47 (patch) | |
tree | 3cec558295d06f5478796e4b587a2fba1b95b70b | |
parent | 5d27b10f4c6c8e140bd48a001b98037ac0d54118 (diff) | |
download | freetype2-f7c6a06cb7458c8972955ebd698058d0957a0a47.tar.gz |
Support architectures where `long` is smaller than pointers.
I am currently trying to compile FreeType for CHERI-extended ISAs
(CHERI-RISC-V and Arm's Morello), but I am getting compiler warnings
from the `FT_UINT_TO_POINTER` macro. When compiling with the CHERI
Clang compiler, not using `uinptr_t` for casts between integers an
pointers results in the following `-Werror` build failures:
```
In file included from .../src/truetype/truetype.c:22:
.../src/truetype/ttgload.c:1925:22: error:
cast from provenance-free integer type to pointer type will
give pointer that can not be dereferenced
[-Werror,-Wcheri-capability-misuse]
node->data = FT_UINT_TO_POINTER( glyph_index );
^
.../include/freetype/internal/compiler-macros.h:79:34: note:
expanded from macro 'FT_UINT_TO_POINTER'
```
* include/freetype/internal/compiler-macros.h (FT_UINT_TO_POINTER):
The ISO C standard compliant fix for this would be to use
`uintptr_t` from `stdint.h`, but I am not sure if this is supported
by the minimum compiler version. Therefore, use the
compiler-defined `__UINTPTR_TYPE__` macro (supported in GCC 4.6+ and
Clang since about 3.0) before checking for `_WIN64` and falling back
to `unsigned long`.
-rw-r--r-- | ChangeLog | 30 | ||||
-rw-r--r-- | include/freetype/internal/compiler-macros.h | 12 |
2 files changed, 39 insertions, 3 deletions
@@ -1,3 +1,33 @@ +2021-07-15 Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> + + Support architectures where `long` is smaller than pointers. + + I am currently trying to compile FreeType for CHERI-extended ISAs + (CHERI-RISC-V and Arm's Morello), but I am getting compiler warnings + from the `FT_UINT_TO_POINTER` macro. When compiling with the CHERI + Clang compiler, not using `uinptr_t` for casts between integers an + pointers results in the following `-Werror` build failures: + + ``` + In file included from .../src/truetype/truetype.c:22: + .../src/truetype/ttgload.c:1925:22: error: + cast from provenance-free integer type to pointer type will + give pointer that can not be dereferenced + [-Werror,-Wcheri-capability-misuse] + node->data = FT_UINT_TO_POINTER( glyph_index ); + ^ + .../include/freetype/internal/compiler-macros.h:79:34: note: + expanded from macro 'FT_UINT_TO_POINTER' + ``` + + * include/freetype/internal/compiler-macros.h (FT_UINT_TO_POINTER): + The ISO C standard compliant fix for this would be to use + `uintptr_t` from `stdint.h`, but I am not sure if this is supported + by the minimum compiler version. Therefore, use the + compiler-defined `__UINTPTR_TYPE__` macro (supported in GCC 4.6+ and + Clang since about 3.0) before checking for `_WIN64` and falling back + to `unsigned long`. + 2021-07-13 Oleg Oshmyan <chortos@inbox.lv> [base] Fix `FT_Open_Face`'s handling of user-supplied streams. diff --git a/include/freetype/internal/compiler-macros.h b/include/freetype/internal/compiler-macros.h index 0eb5e247c..d8b61b3dc 100644 --- a/include/freetype/internal/compiler-macros.h +++ b/include/freetype/internal/compiler-macros.h @@ -71,12 +71,18 @@ FT_BEGIN_HEADER */ #define FT_DUMMY_STMNT FT_BEGIN_STMNT FT_END_STMNT -#ifdef _WIN64 +#ifdef __UINTPTR_TYPE__ + /* + * GCC and Clang both provide a `__UINTPTR_TYPE__` that can be used to + * avoid a dependency on `stdint.h`. + */ +# define FT_UINT_TO_POINTER( x ) (void *)(__UINTPTR_TYPE__)(x) +#elif defined( _WIN64 ) /* only 64bit Windows uses the LLP64 data model, i.e., */ /* 32-bit integers, 64-bit pointers. */ -#define FT_UINT_TO_POINTER( x ) (void *)(unsigned __int64)(x) +# define FT_UINT_TO_POINTER( x ) (void *)(unsigned __int64)(x) #else -#define FT_UINT_TO_POINTER( x ) (void *)(unsigned long)(x) +# define FT_UINT_TO_POINTER( x ) (void *)(unsigned long)(x) #endif /* |