]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/generic/lru: try to resolve alignof warnings
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 12 Apr 2019 07:22:15 +0000 (09:22 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Thu, 18 Apr 2019 06:55:50 +0000 (06:55 +0000)
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
lib/generic/lru.h

index feb0c2c4e9f57632aecffb1732894c08e60eba5a..b2d02f0a1d36d58e4f8332cb4f5f1ee193759420 100644 (file)
@@ -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);
index 8555a0a469e7e198c3e29aa965aeb539de757b52..135419a9d1c65d637ef7e01777acf9170946837d 100644 (file)
@@ -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"
  * @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). */