From a62dbf88d8a3c04446db833a1eb80a620cb1514d Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Mon, 29 Jan 2018 13:05:51 -0500 Subject: [PATCH] Move OPENSSL_FALLTHROUGH to internal headers. Having it in base.h pollutes the global namespace a bit and, in particular, causes clang to give unhelpful suggestions in consuming projects. Change-Id: I6ca1a88bdd1701f0c49192a0df56ac0953c7067c Reviewed-on: https://boringssl-review.googlesource.com/25464 Commit-Queue: Steven Valdez Reviewed-by: Steven Valdez CQ-Verified: CQ bot account: commit-bot@chromium.org --- crypto/bio/fd.c | 1 + crypto/bio/file.c | 2 ++ crypto/cipher_extra/e_rc2.c | 2 ++ crypto/fipsmodule/des/internal.h | 2 ++ crypto/internal.h | 14 ++++++++++++++ decrepit/macros.h | 2 ++ include/openssl/base.h | 14 -------------- 7 files changed, 23 insertions(+), 14 deletions(-) diff --git a/crypto/bio/fd.c b/crypto/bio/fd.c index ea5bfd8c..fed5228f 100644 --- a/crypto/bio/fd.c +++ b/crypto/bio/fd.c @@ -73,6 +73,7 @@ OPENSSL_MSVC_PRAGMA(warning(pop)) #include #include "internal.h" +#include "../internal.h" static int bio_fd_non_fatal_error(int err) { diff --git a/crypto/bio/file.c b/crypto/bio/file.c index 278be188..f61dbe4f 100644 --- a/crypto/bio/file.c +++ b/crypto/bio/file.c @@ -81,6 +81,8 @@ #include #include +#include "../internal.h" + #define BIO_FP_READ 0x02 #define BIO_FP_WRITE 0x04 diff --git a/crypto/cipher_extra/e_rc2.c b/crypto/cipher_extra/e_rc2.c index 0b2caf55..221a9c92 100644 --- a/crypto/cipher_extra/e_rc2.c +++ b/crypto/cipher_extra/e_rc2.c @@ -57,6 +57,8 @@ #include #include +#include "../internal.h" + #define c2l(c, l) \ do { \ diff --git a/crypto/fipsmodule/des/internal.h b/crypto/fipsmodule/des/internal.h index 4d65ff1d..1ae3f22a 100644 --- a/crypto/fipsmodule/des/internal.h +++ b/crypto/fipsmodule/des/internal.h @@ -59,6 +59,8 @@ #include +#include "../../internal.h" + #if defined(__cplusplus) extern "C" { #endif diff --git a/crypto/internal.h b/crypto/internal.h index 95b8d289..067f3bb0 100644 --- a/crypto/internal.h +++ b/crypto/internal.h @@ -172,6 +172,20 @@ typedef __uint128_t uint128_t; #define OPENSSL_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) +// Have a generic fall-through for different versions of C/C++. +#if defined(__cplusplus) && __cplusplus >= 201703L +#define OPENSSL_FALLTHROUGH [[fallthrough]] +#elif defined(__cplusplus) && __cplusplus >= 201103L && defined(__clang__) +#define OPENSSL_FALLTHROUGH [[clang::fallthrough]] +#elif defined(__cplusplus) && __cplusplus >= 201103L && defined(__GNUC__) && \ + __GNUC__ >= 7 +#define OPENSSL_FALLTHROUGH [[gnu::fallthrough]] +#elif defined(__GNUC__) && __GNUC__ >= 7 // gcc 7 +#define OPENSSL_FALLTHROUGH __attribute__ ((fallthrough)) +#else // C++11 on gcc 6, and all other cases +#define OPENSSL_FALLTHROUGH +#endif + // buffers_alias returns one if |a| and |b| alias and zero otherwise. static inline int buffers_alias(const uint8_t *a, size_t a_len, const uint8_t *b, size_t b_len) { diff --git a/decrepit/macros.h b/decrepit/macros.h index c4ebeec9..7888f0d1 100644 --- a/decrepit/macros.h +++ b/decrepit/macros.h @@ -57,6 +57,8 @@ #ifndef OPENSSL_HEADER_DECREPIT_MACROS_H #define OPENSSL_HEADER_DECREPIT_MACROS_H +#include "../crypto/internal.h" + // NOTE - c is not incremented as per n2l #define n2ln(c, l1, l2, n) \ diff --git a/include/openssl/base.h b/include/openssl/base.h index dea069ab..8db72d81 100644 --- a/include/openssl/base.h +++ b/include/openssl/base.h @@ -223,20 +223,6 @@ extern "C" { #endif #endif -// Have a generic fall-through for different versions of C/C++. -#if defined(__cplusplus) && __cplusplus >= 201703L -#define OPENSSL_FALLTHROUGH [[fallthrough]] -#elif defined(__cplusplus) && __cplusplus >= 201103L && defined(__clang__) -#define OPENSSL_FALLTHROUGH [[clang::fallthrough]] -#elif defined(__cplusplus) && __cplusplus >= 201103L && defined(__GNUC__) && \ - __GNUC__ >= 7 -#define OPENSSL_FALLTHROUGH [[gnu::fallthrough]] -#elif defined(__GNUC__) && __GNUC__ >= 7 // gcc 7 -#define OPENSSL_FALLTHROUGH __attribute__ ((fallthrough)) -#else // C++11 on gcc 6, and all other cases -#define OPENSSL_FALLTHROUGH -#endif - // CRYPTO_THREADID is a dummy value. typedef int CRYPTO_THREADID;