From 8119841ec0da8ab088ed23961d3a3e4b25551f18 Mon Sep 17 00:00:00 2001 From: Alex James Date: Tue, 22 Oct 2019 18:32:22 -0500 Subject: commonlib: Use __builtin_offsetof with supported compilers Use __builtin_offsetof (which is treated as a constant expression) with Clang & GCC. This also allows check_member to work with Clang 9. Signed-off-by: Alex James Change-Id: I8b5cb4110c13ee42114ecf65932d7f1e5636210e Reviewed-on: https://review.coreboot.org/c/coreboot/+/36249 Reviewed-by: Aaron Durbin Tested-by: build bot (Jenkins) --- src/commonlib/include/commonlib/helpers.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/commonlib') diff --git a/src/commonlib/include/commonlib/helpers.h b/src/commonlib/include/commonlib/helpers.h index f3b71d7016..ca3b3c58f9 100644 --- a/src/commonlib/include/commonlib/helpers.h +++ b/src/commonlib/include/commonlib/helpers.h @@ -108,16 +108,16 @@ #define GHz (1000 * MHz) #ifndef offsetof +#ifdef __ROMCC__ #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +#else +#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER) +#endif #endif -#if !defined(__clang__) #define check_member(structure, member, offset) _Static_assert( \ offsetof(struct structure, member) == offset, \ "`struct " #structure "` offset for `" #member "` is not " #offset) -#else -#define check_member(structure, member, offset) -#endif /** * container_of - cast a member of a structure out to the containing structure -- cgit v1.2.3