From 64134e60b348bb1686986e217f4020d6d108ed46 Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Fri, 19 Oct 2018 16:37:31 +0200 Subject: Add FDK_FALLTHROUGH macro to prevent implicit-fallthrough compiler warnings Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc Change-Id: I9f9064fb63ac40e18f245c00b7375b4874f2925b --- libSYS/include/machine_type.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'libSYS/include') diff --git a/libSYS/include/machine_type.h b/libSYS/include/machine_type.h index be8de37..b66d5ad 100644 --- a/libSYS/include/machine_type.h +++ b/libSYS/include/machine_type.h @@ -379,6 +379,17 @@ it. Hence, a fully platform-independant way to use alignment is not supported. #define LNK_SECTION_L1_DATA_A #define LNK_SECTION_L1_DATA_B +/************************************************** + * Macros regarding static code analysis + **************************************************/ +#if defined(__clang__) +#define FDK_FALLTHROUGH [[clang::fallthrough]] +#elif defined(__GNUC__) && (__GNUC__ >= 7) +#define FDK_FALLTHROUGH __attribute__((fallthrough)) +#else +#define FDK_FALLTHROUGH +#endif + #ifdef _MSC_VER /* * Sometimes certain features are excluded from compilation and therefore the -- cgit v1.2.3 From f285813ec15e7c6f8e4839c9eb4f6b0cd2da1990 Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Mon, 21 Jan 2019 16:09:05 +0200 Subject: Fix FDK_FALLTHROUGH for apple clang In the apple branded version of clang, the [[clang::fallthrough]] attribute isn't supported. Directly exposing __has_cpp_attribute(clang::fallthrough) to the preprocessor breaks when building in C mode with GCC, which forces wrapping it in an extra layer of #ifdef __cplusplus. --- libSYS/include/machine_type.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'libSYS/include') diff --git a/libSYS/include/machine_type.h b/libSYS/include/machine_type.h index b66d5ad..bd97669 100644 --- a/libSYS/include/machine_type.h +++ b/libSYS/include/machine_type.h @@ -382,13 +382,22 @@ it. Hence, a fully platform-independant way to use alignment is not supported. /************************************************** * Macros regarding static code analysis **************************************************/ -#if defined(__clang__) +#ifdef __cplusplus +#if !defined(__has_cpp_attribute) +#define __has_cpp_attribute(x) 0 +#endif +#if defined(__clang__) && __has_cpp_attribute(clang::fallthrough) #define FDK_FALLTHROUGH [[clang::fallthrough]] -#elif defined(__GNUC__) && (__GNUC__ >= 7) +#endif +#endif + +#ifndef FDK_FALLTHROUGH +#if defined(__GNUC__) && (__GNUC__ >= 7) #define FDK_FALLTHROUGH __attribute__((fallthrough)) #else #define FDK_FALLTHROUGH #endif +#endif #ifdef _MSC_VER /* -- cgit v1.2.3