Support Clang
authorOlivier Dion <odion@efficios.com>
Mon, 7 Oct 2024 16:22:03 +0000 (12:22 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 23 Oct 2024 15:36:40 +0000 (11:36 -0400)
Most of the warnings emitted where due to either gcc extension or C99
extension used in C++.  Turn-off these warnings by using _Pragma.

Change-Id: I0421d888154df1a98543cc0c0fb7e4b448d25da1
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/side/endian.h
include/side/instrumentation-c-api.h
include/side/macros.h
src/side.c
tests/unit/c-native-types.h
tests/unit/test.c

index c89d486c22decba87bf5204287b99b2ee94ed00b..8cd2997fcf787f283ebf9364bc96ce6304830375 100644 (file)
 #endif
 
 #if (defined(__linux__) || defined(__CYGWIN__))
-#include <endian.h>
-#include <byteswap.h>
-
-#define side_bswap_16(x)               bswap_16(x)
-#define side_bswap_32(x)               bswap_32(x)
-#define side_bswap_64(x)               bswap_64(x)
+#define side_bswap_16(x)               __builtin_bswap16(x)
+#define side_bswap_32(x)               __builtin_bswap32(x)
+#define side_bswap_64(x)               __builtin_bswap64(x)
 
 #define SIDE_BYTE_ORDER                        __BYTE_ORDER
 #define SIDE_LITTLE_ENDIAN             __LITTLE_ENDIAN
index 244b8412501e276015de1da94711422d43960649..2e17d49fa5b9c5a33dbe6cfde23c2c2e0d5a096e 100644 (file)
 /*
  * The forward declaration linkage is always the same in C. In C++ however, it
  * is necessary to not use the same linkage as the declaration.
+ *
+ * Rationale for disabled diagnostics:
+ *
+ *   -Wsection:
+ *      Clang complains about redeclared sections.
  */
 #define _side_define_event(_forward_decl_linkage, _linkage, _identifier, _provider, _event, _loglevel, _fields, _flags, _attr...) \
+       SIDE_PUSH_DIAGNOSTIC()                                          \
+       SIDE_DIAGNOSTIC(ignored "-Wsection")                            \
        _forward_decl_linkage struct side_event_description __attribute__((section("side_event_description"))) \
                _identifier;                                                    \
        _forward_decl_linkage struct side_event_state_0 __attribute__((section("side_event_state"))) \
                .end = {}                                               \
        };                                                              \
        static const struct side_event_description __attribute__((section("side_event_description_ptr"), used)) \
-                       *side_event_ptr__##_identifier = &(_identifier)
+       *side_event_ptr__##_identifier = &(_identifier);                \
+       SIDE_POP_DIAGNOSTIC() SIDE_ACCEPT_COMMA()
 
 /*
  * In C++, it is not possible to forward declare a static variable.  Use
index 84afe285eb2c58b99177aefbe788bb60f7dd259a..b0388d3ce862280a27d93fd7b2cc98a93a9de34b 100644 (file)
 /* Same as SIDE_CAT, but can expand SIDE_CAT within the expansion itself. */
 #define SIDE_CAT2_PRIMITIVE(x, y...) x ## y
 #define SIDE_CAT2(x, y...) SIDE_CAT2_PRIMITIVE(x, y)
+
+/* Accept a trailing comma. */
+#define SIDE_ACCEPT_COMMA(...) side_static_assert(1, "", _)
+
+/*
+ * The diagnostic macros can be used to turn-off warnings using inline _Pragma.
+ */
+#if defined(__clang__)
+
+#  define SIDE_DIAGNOSTIC(x)                   \
+       _Pragma(SIDE_STR(clang diagnostic x))
+
+#elif defined(__GNUC__)
+
+#  define SIDE_DIAGNOSTIC(x)                   \
+       _Pragma(SIDE_STR(GCC diagnostic x))
+
+#endif
+
+#ifdef __cplusplus
+#  define SIDE_DIAGNOSTIC_C(...)
+#  define SIDE_DIAGNOSTIC_CXX SIDE_DIAGNOSTIC
+#else
+#  define SIDE_DIAGNOSTIC_C SIDE_DIAGNOSTIC
+#  define SIDE_DIAGNOSTIC_CXX(...)
+#endif
+
+#define SIDE_PUSH_DIAGNOSTIC()                                         \
+       SIDE_DIAGNOSTIC(push)                                           \
+       SIDE_DIAGNOSTIC(ignored "-Wpragmas")
+
+#define SIDE_POP_DIAGNOSTIC()                  \
+    SIDE_DIAGNOSTIC(pop)
+
 /*
  * Define a unique identifier in the compilation unit.
  */
 #  define SIDE_PTR_INIT(...)                                   \
        {                                                       \
                .v = {                                          \
-                       [0] = (__VA_ARGS__),                    \
-                       [1] = 0,                                \
-                       [2] = 0,                                \
-                       [3] = 0,                                \
+                       (__VA_ARGS__),                          \
+                       0,                                      \
+                       0,                                      \
+                       0,                                      \
                },                                              \
        }
 # else
 #  define SIDE_PTR_INIT(...)                                   \
        {                                                       \
                .v = {                                          \
-                       [0] = 0,                                \
-                       [1] = 0,                                \
-                       [2] = 0,                                \
-                       [3] = (__VA_ARGS__),                    \
+                       0,                                      \
+                       0,                                      \
+                       0,                                      \
+                       (__VA_ARGS__),                          \
                },                                              \
        }
 # endif
 #  define SIDE_PTR_INIT(...)                                   \
        {                                                       \
                .v = {                                          \
-                       [0] = (__VA_ARGS__),                    \
-                       [1] = 0,                                \
+                       (__VA_ARGS__),                          \
+                       0,                                      \
                },                                              \
        }
 # else
 #  define SIDE_PTR_INIT(...)                                   \
        {                                                       \
                .v = {                                          \
-                       [0] = 0,                                \
-                       [1] = (__VA_ARGS__),                    \
+                        0,                                     \
+                       (__VA_ARGS__),                          \
                },                                              \
        }
 # endif
 # define SIDE_PTR_INIT(...)                                    \
        {                                                       \
                .v = {                                          \
-                       [0] = (__VA_ARGS__),                    \
+                       (__VA_ARGS__),                          \
                },                                              \
        }
 #else
index d8b58a851bdf8219fe2c5efe0746ccb060abd280..c34e5472fe5b0997ec6000c0000e17910e595331 100644 (file)
@@ -490,7 +490,7 @@ void side_event_remove_callbacks(struct side_event_description *desc)
         * unreachable.
         */
        es0->nr_callbacks = 0;
-       side_rcu_assign_pointer(es0->callbacks, &side_empty_callback);
+       side_rcu_assign_pointer(es0->callbacks, (struct side_callback *)&side_empty_callback);
        /*
         * No need to wait for grace period because instrumentation is
         * unreachable.
index ad03e2c13274f1023dba42d79ffef4dec703384c..a536bf98d98cf99bee3998cab99cc568b84b8b62 100644 (file)
@@ -18,6 +18,9 @@ X(unsigned long long, ULLONG_MAX, ulong_long);
 X(float, FLT_MIN, float);
 X(double, DBL_MIN, double);
 
-#ifdef __SIZEOF_LONG_DOUBLE__
+#if defined(__SIZEOF_LONG_DOUBLE) &&                           \
+       ((__SIZEOF_LONG_DOUBLE__ <= 4 && __HAVE_FLOAT32) ||     \
+        (__SIZEOF_LONG_DOUBLE__ <= 8 && __HAVE_FLOAT64) ||     \
+        (__SIZEOF_LONG_DOUBLE__ <= 16 && __HAVE_FLOAT128))
 X(long double, LDBL_MIN, long_double);
 #endif
index e0df0951cb69305b646ee98ae11c9ae765b725b4..d6b11ad0d0e04f8f91fae867788de140d42a55f7 100644 (file)
@@ -1741,11 +1741,11 @@ void test_gather_structnest(void)
                                .c = { 0, 1, 2, 3 },
                        },
                        .nestarray = {
-                               [0] = {
+                               {
                                        .b = 77,
                                        .c = { 11, 12, 13, 14 },
                                },
-                               [1] = {
+                               {
                                        .b = 88,
                                        .c = { 15, 16, 17, 18 },
                                },
This page took 0.030119 seconds and 4 git commands to generate.