From: Olivier Dion Date: Mon, 7 Oct 2024 16:22:03 +0000 (-0400) Subject: Support Clang X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=e0e8feb9822cb292cb242fe8e34bda0fa30bab0e;p=libside.git Support Clang 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 Signed-off-by: Mathieu Desnoyers --- diff --git a/include/side/endian.h b/include/side/endian.h index c89d486..8cd2997 100644 --- a/include/side/endian.h +++ b/include/side/endian.h @@ -40,12 +40,9 @@ #endif #if (defined(__linux__) || defined(__CYGWIN__)) -#include -#include - -#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 diff --git a/include/side/instrumentation-c-api.h b/include/side/instrumentation-c-api.h index 244b841..2e17d49 100644 --- a/include/side/instrumentation-c-api.h +++ b/include/side/instrumentation-c-api.h @@ -1478,8 +1478,15 @@ /* * 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"))) \ @@ -1512,7 +1519,8 @@ .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 diff --git a/include/side/macros.h b/include/side/macros.h index 84afe28..b0388d3 100644 --- a/include/side/macros.h +++ b/include/side/macros.h @@ -26,6 +26,40 @@ /* 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. */ @@ -216,20 +250,20 @@ # 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 @@ -245,16 +279,16 @@ # 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 @@ -267,7 +301,7 @@ # define SIDE_PTR_INIT(...) \ { \ .v = { \ - [0] = (__VA_ARGS__), \ + (__VA_ARGS__), \ }, \ } #else diff --git a/src/side.c b/src/side.c index d8b58a8..c34e547 100644 --- a/src/side.c +++ b/src/side.c @@ -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. diff --git a/tests/unit/c-native-types.h b/tests/unit/c-native-types.h index ad03e2c..a536bf9 100644 --- a/tests/unit/c-native-types.h +++ b/tests/unit/c-native-types.h @@ -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 diff --git a/tests/unit/test.c b/tests/unit/test.c index e0df095..d6b11ad 100644 --- a/tests/unit/test.c +++ b/tests/unit/test.c @@ -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 }, },