Commit ee67a8a3 authored by Vladimír Čunát's avatar Vladimír Čunát Committed by Petr Špaček

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.
parent 809d5b76
......@@ -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);
......
......@@ -64,8 +64,9 @@
#pragma once
#include <assert.h>
#include <stdint.h>
#include <stdalign.h>
#include <stddef.h>
#include <stdint.h>
#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). */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment