From ee67a8a3c3a3aa911b732315b7e19337ac89a79e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Fri, 12 Apr 2019 09:22:15 +0200 Subject: [PATCH] lib/generic/lru: try to resolve alignof warnings We run meson with -std=gnu11, but apparently some compiler still complained about it. Unfortunately it wouldn't be easy to use standard C11 in this case. --- lib/generic/lru.c | 2 +- lib/generic/lru.h | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/generic/lru.c b/lib/generic/lru.c index feb0c2c4e..b2d02f0a1 100644 --- a/lib/generic/lru.c +++ b/lib/generic/lru.c @@ -128,7 +128,7 @@ KR_EXPORT struct lru * lru_create_impl(uint max_slots, uint val_alignment, if (!mm_array) { static knot_mm_t mm_array_default = { 0 }; if (!mm_array_default.ctx) - mm_ctx_init_aligned(&mm_array_default, __alignof(struct lru)); + mm_ctx_init_aligned(&mm_array_default, alignof(struct lru)); mm_array = &mm_array_default; } assert(mm_array->alloc != mm_malloc && mm_array->alloc != (knot_mm_alloc_t)mp_alloc); diff --git a/lib/generic/lru.h b/lib/generic/lru.h index 8555a0a46..135419a9d 100644 --- a/lib/generic/lru.h +++ b/lib/generic/lru.h @@ -64,8 +64,9 @@ #pragma once #include -#include +#include #include +#include #include "contrib/ucw/lib.h" #include "lib/utils.h" @@ -94,11 +95,19 @@ * @note The pointers to memory contexts need to remain valid * during the whole life of the structure (or be NULL). */ +/* Pragmas: C11 only standardizes alignof on type names, not on expressions. + * That's a GNU extension; in clang it's supported but may generate warnings. + * It seems hard to disable warnings that are only supported by some compilers. */ #define lru_create(ptable, max_slots, mm_ctx_array, mm_ctx) do { \ (void)(((__typeof__((*(ptable))->pdata_t))0) == (void *)0); /* typecheck lru_t */ \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wpragmas\"") \ + _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"") \ + _Pragma("GCC diagnostic ignored \"-Wgnu-alignof-expression\"") \ *(ptable) = (__typeof__(*(ptable))) \ - lru_create_impl((max_slots), __alignof(*( (*(ptable))->pdata_t )), \ + lru_create_impl((max_slots), alignof(*( (*(ptable))->pdata_t )), \ (mm_ctx_array), (mm_ctx)); \ + _Pragma("GCC diagnostic pop") \ } while (false) /** @brief Free an LRU created by lru_create (it can be NULL). */ -- 2.47.2