diff --git a/src/libsysprof-capture/mapped-ring-buffer.c b/src/libsysprof-capture/mapped-ring-buffer.c index b7b56796..c7f2ce2c 100644 --- a/src/libsysprof-capture/mapped-ring-buffer.c +++ b/src/libsysprof-capture/mapped-ring-buffer.c @@ -55,7 +55,7 @@ typedef struct _MappedRingHeader uint32_t size; } MappedRingHeader; -static_assert (sizeof (MappedRingHeader) == 16, "MappedRingHeader changed size"); +SYSPROF_STATIC_ASSERT (sizeof (MappedRingHeader) == 16, "MappedRingHeader changed size"); /* * MappedRingBuffer is used to wrap both the reader and writer diff --git a/src/libsysprof-capture/sysprof-address.h b/src/libsysprof-capture/sysprof-address.h index 098bcc31..29ad0d48 100644 --- a/src/libsysprof-capture/sysprof-address.h +++ b/src/libsysprof-capture/sysprof-address.h @@ -67,8 +67,8 @@ SYSPROF_BEGIN_DECLS typedef uint64_t SysprofAddress; -static_assert (sizeof (SysprofAddress) >= sizeof (void *), - "Address space is too big"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofAddress) >= sizeof (void *), + "Address space is too big"); typedef enum { diff --git a/src/libsysprof-capture/sysprof-capture-types.h b/src/libsysprof-capture/sysprof-capture-types.h index 2031fc7e..eaba4461 100644 --- a/src/libsysprof-capture/sysprof-capture-types.h +++ b/src/libsysprof-capture/sysprof-capture-types.h @@ -80,8 +80,7 @@ SYSPROF_BEGIN_DECLS #define SYSPROF_CAPTURE_ADDRESS_FORMAT "0x%016" PRIx64 -static_assert (sizeof (void *) == sizeof (uintptr_t), - "UINTPTR_MAX can’t be used to determine sizeof(void*) at compile time"); +SYSPROF_STATIC_ASSERT (sizeof (void *) == sizeof (uintptr_t), "UINTPTR_MAX can’t be used to determine sizeof(void*) at compile time"); #if UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFu # define SYSPROF_CAPTURE_JITMAP_MARK SYSPROF_UINT64_CONSTANT(0xE000000000000000) #elif UINTPTR_MAX == 0xFFFFFFFF @@ -335,27 +334,27 @@ typedef struct } SysprofCaptureAllocation SYSPROF_ALIGNED_END(1); -static_assert (sizeof (SysprofCaptureFileHeader) == 256, "SysprofCaptureFileHeader changed size"); -static_assert (sizeof (SysprofCaptureFrame) == 24, "SysprofCaptureFrame changed size"); -static_assert (sizeof (SysprofCaptureMap) == 56, "SysprofCaptureMap changed size"); -static_assert (sizeof (SysprofCaptureJitmap) == 28, "SysprofCaptureJitmap changed size"); -static_assert (sizeof (SysprofCaptureProcess) == 24, "SysprofCaptureProcess changed size"); -static_assert (sizeof (SysprofCaptureSample) == 32, "SysprofCaptureSample changed size"); -static_assert (sizeof (SysprofCaptureFork) == 28, "SysprofCaptureFork changed size"); -static_assert (sizeof (SysprofCaptureExit) == 24, "SysprofCaptureExit changed size"); -static_assert (sizeof (SysprofCaptureTimestamp) == 24, "SysprofCaptureTimestamp changed size"); -static_assert (sizeof (SysprofCaptureCounter) == 128, "SysprofCaptureCounter changed size"); -static_assert (sizeof (SysprofCaptureCounterValues) == 96, "SysprofCaptureCounterValues changed size"); -static_assert (sizeof (SysprofCaptureCounterDefine) == 32, "SysprofCaptureCounterDefine changed size"); -static_assert (sizeof (SysprofCaptureCounterSet) == 32, "SysprofCaptureCounterSet changed size"); -static_assert (sizeof (SysprofCaptureMark) == 96, "SysprofCaptureMark changed size"); -static_assert (sizeof (SysprofCaptureMetadata) == 64, "SysprofCaptureMetadata changed size"); -static_assert (sizeof (SysprofCaptureLog) == 64, "SysprofCaptureLog changed size"); -static_assert (sizeof (SysprofCaptureFileChunk) == 284, "SysprofCaptureFileChunk changed size"); -static_assert (sizeof (SysprofCaptureAllocation) == 48, "SysprofCaptureAllocation changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureFileHeader) == 256, "SysprofCaptureFileHeader changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureFrame) == 24, "SysprofCaptureFrame changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureMap) == 56, "SysprofCaptureMap changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureJitmap) == 28, "SysprofCaptureJitmap changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureProcess) == 24, "SysprofCaptureProcess changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureSample) == 32, "SysprofCaptureSample changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureFork) == 28, "SysprofCaptureFork changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureExit) == 24, "SysprofCaptureExit changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureTimestamp) == 24, "SysprofCaptureTimestamp changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureCounter) == 128, "SysprofCaptureCounter changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureCounterValues) == 96, "SysprofCaptureCounterValues changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureCounterDefine) == 32, "SysprofCaptureCounterDefine changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureCounterSet) == 32, "SysprofCaptureCounterSet changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureMark) == 96, "SysprofCaptureMark changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureMetadata) == 64, "SysprofCaptureMetadata changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureLog) == 64, "SysprofCaptureLog changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureFileChunk) == 284, "SysprofCaptureFileChunk changed size"); +SYSPROF_STATIC_ASSERT (sizeof (SysprofCaptureAllocation) == 48, "SysprofCaptureAllocation changed size"); -static_assert ((offsetof (SysprofCaptureAllocation, addrs) % SYSPROF_CAPTURE_ALIGN) == 0, "SysprofCaptureAllocation.addrs is not aligned"); -static_assert ((offsetof (SysprofCaptureSample, addrs) % SYSPROF_CAPTURE_ALIGN) == 0, "SysprofCaptureSample.addrs is not aligned"); +SYSPROF_STATIC_ASSERT ((offsetof (SysprofCaptureAllocation, addrs) % SYSPROF_CAPTURE_ALIGN) == 0, "SysprofCaptureAllocation.addrs is not aligned"); +SYSPROF_STATIC_ASSERT ((offsetof (SysprofCaptureSample, addrs) % SYSPROF_CAPTURE_ALIGN) == 0, "SysprofCaptureSample.addrs is not aligned"); static inline int sysprof_capture_address_compare (SysprofCaptureAddress a, diff --git a/src/libsysprof-capture/sysprof-macros.h b/src/libsysprof-capture/sysprof-macros.h index f025458d..218414c6 100644 --- a/src/libsysprof-capture/sysprof-macros.h +++ b/src/libsysprof-capture/sysprof-macros.h @@ -70,6 +70,12 @@ #define SYSPROF_GNUC_CHECK_VERSION(major, minor) 0 #endif +#if SYSPROF_GNUC_CHECK_VERSION(4, 6) +# define SYSPROF_STATIC_ASSERT(expr, msg) _Static_assert(expr, msg) +#else +# define SYSPROF_STATIC_ASSERT(expr, msg) ((void) sizeof (char[(expr) ? 1 : -1])) +#endif + #if INT_MAX == LONG_MAX #define SYSPROF_INT64_CONSTANT(x) x##ULL #define SYSPROF_UINT64_CONSTANT(x) x##LL