mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-24 15:31:22 +01:00
include: types: Use __builtin_offsetof when supported
Clang provides a __builtin_offsetof which can be detected using __has_builtin(). Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> Reviewed-by: Anup Patel <anup.patel@wdc.com>
This commit is contained in:

committed by
Anup Patel

parent
7210e90785
commit
f3a8f603a7
@@ -68,8 +68,14 @@ typedef unsigned long physical_size_t;
|
||||
#define likely(x) __builtin_expect((x), 1)
|
||||
#define unlikely(x) __builtin_expect((x), 0)
|
||||
|
||||
#ifndef __has_builtin
|
||||
#define __has_builtin(...) 0
|
||||
#endif
|
||||
|
||||
#undef offsetof
|
||||
#ifdef __compiler_offsetof
|
||||
#if __has_builtin(__builtin_offsetof)
|
||||
#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE,MEMBER)
|
||||
#elif defined(__compiler_offsetof)
|
||||
#define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE,MEMBER)
|
||||
#else
|
||||
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
||||
|
Reference in New Issue
Block a user