Skip to content

Commit

Permalink
Attempt to keep Clang out of other compiler paths (GH #147)
Browse files Browse the repository at this point in the history
  • Loading branch information
noloader committed Jun 25, 2023
1 parent 0d9cd94 commit a89a27b
Show file tree
Hide file tree
Showing 38 changed files with 131 additions and 131 deletions.
4 changes: 2 additions & 2 deletions algparam.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class AlgorithmParametersTemplate : public AlgorithmParametersBase
}
}

#if defined(DEBUG_NEW) && (_MSC_VER >= 1300)
#if defined(DEBUG_NEW) && (CRYPTOPP_MSC_VERSION >= 1300)
# pragma push_macro("new")
# undef new
#endif
Expand All @@ -404,7 +404,7 @@ class AlgorithmParametersTemplate : public AlgorithmParametersBase
CRYPTOPP_UNUSED(p); // silence warning
}

#if defined(DEBUG_NEW) && (_MSC_VER >= 1300)
#if defined(DEBUG_NEW) && (CRYPTOPP_MSC_VERSION >= 1300)
# pragma pop_macro("new")
#endif

Expand Down
34 changes: 17 additions & 17 deletions arm_simd.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/// \since Crypto++ 8.6
inline uint32_t CRC32B (uint32_t crc, uint8_t val)
{
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
return __crc32b(crc, val);
#else
__asm__ ("crc32b %w0, %w0, %w1 \n\t"
Expand All @@ -45,7 +45,7 @@ inline uint32_t CRC32B (uint32_t crc, uint8_t val)
/// \since Crypto++ 8.6
inline uint32_t CRC32W (uint32_t crc, uint32_t val)
{
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
return __crc32w(crc, val);
#else
__asm__ ("crc32w %w0, %w0, %w1 \n\t"
Expand All @@ -61,7 +61,7 @@ inline uint32_t CRC32W (uint32_t crc, uint32_t val)
/// \since Crypto++ 8.6
inline uint32_t CRC32Wx4 (uint32_t crc, const uint32_t vals[4])
{
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
return __crc32w(__crc32w(__crc32w(__crc32w(
crc, vals[0]), vals[1]), vals[2]), vals[3]);
#else
Expand All @@ -85,7 +85,7 @@ inline uint32_t CRC32Wx4 (uint32_t crc, const uint32_t vals[4])
/// \since Crypto++ 8.6
inline uint32_t CRC32CB (uint32_t crc, uint8_t val)
{
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
return __crc32cb(crc, val);
#else
__asm__ ("crc32cb %w0, %w0, %w1 \n\t"
Expand All @@ -101,7 +101,7 @@ inline uint32_t CRC32CB (uint32_t crc, uint8_t val)
/// \since Crypto++ 8.6
inline uint32_t CRC32CW (uint32_t crc, uint32_t val)
{
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
return __crc32cw(crc, val);
#else
__asm__ ("crc32cw %w0, %w0, %w1 \n\t"
Expand All @@ -117,7 +117,7 @@ inline uint32_t CRC32CW (uint32_t crc, uint32_t val)
/// \since Crypto++ 8.6
inline uint32_t CRC32CWx4 (uint32_t crc, const uint32_t vals[4])
{
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
return __crc32cw(__crc32cw(__crc32cw(__crc32cw(
crc, vals[0]), vals[1]), vals[2]), vals[3]);
#else
Expand Down Expand Up @@ -151,7 +151,7 @@ inline uint32_t CRC32CWx4 (uint32_t crc, const uint32_t vals[4])
/// \since Crypto++ 8.0
inline uint64x2_t PMULL_00(const uint64x2_t a, const uint64x2_t b)
{
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
const __n64 x = { vgetq_lane_u64(a, 0) };
const __n64 y = { vgetq_lane_u64(b, 0) };
return vmull_p64(x, y);
Expand Down Expand Up @@ -181,7 +181,7 @@ inline uint64x2_t PMULL_00(const uint64x2_t a, const uint64x2_t b)
/// \since Crypto++ 8.0
inline uint64x2_t PMULL_01(const uint64x2_t a, const uint64x2_t b)
{
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
const __n64 x = { vgetq_lane_u64(a, 0) };
const __n64 y = { vgetq_lane_u64(b, 1) };
return vmull_p64(x, y);
Expand Down Expand Up @@ -211,7 +211,7 @@ inline uint64x2_t PMULL_01(const uint64x2_t a, const uint64x2_t b)
/// \since Crypto++ 8.0
inline uint64x2_t PMULL_10(const uint64x2_t a, const uint64x2_t b)
{
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
const __n64 x = { vgetq_lane_u64(a, 1) };
const __n64 y = { vgetq_lane_u64(b, 0) };
return vmull_p64(x, y);
Expand Down Expand Up @@ -241,7 +241,7 @@ inline uint64x2_t PMULL_10(const uint64x2_t a, const uint64x2_t b)
/// \since Crypto++ 8.0
inline uint64x2_t PMULL_11(const uint64x2_t a, const uint64x2_t b)
{
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
const __n64 x = { vgetq_lane_u64(a, 1) };
const __n64 y = { vgetq_lane_u64(b, 1) };
return vmull_p64(x, y);
Expand All @@ -266,7 +266,7 @@ inline uint64x2_t PMULL_11(const uint64x2_t a, const uint64x2_t b)
/// \since Crypto++ 8.0
inline uint64x2_t PMULL(const uint64x2_t a, const uint64x2_t b)
{
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
const __n64 x = { vgetq_lane_u64(a, 0) };
const __n64 y = { vgetq_lane_u64(b, 0) };
return vmull_p64(x, y);
Expand All @@ -291,7 +291,7 @@ inline uint64x2_t PMULL(const uint64x2_t a, const uint64x2_t b)
/// \since Crypto++ 8.0
inline uint64x2_t PMULL_HIGH(const uint64x2_t a, const uint64x2_t b)
{
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
const __n64 x = { vgetq_lane_u64(a, 1) };
const __n64 y = { vgetq_lane_u64(b, 1) };
return vmull_p64(x, y);
Expand Down Expand Up @@ -320,7 +320,7 @@ template <unsigned int C>
inline uint64x2_t VEXT_U8(uint64x2_t a, uint64x2_t b)
{
// https://github.com/weidai11/cryptopp/issues/366
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
return vreinterpretq_u64_u8(vextq_u8(
vreinterpretq_u8_u64(a), vreinterpretq_u8_u64(b), C));
#else
Expand Down Expand Up @@ -349,7 +349,7 @@ inline uint64x2_t VEXT_U8(uint64x2_t a, uint64x2_t b)
/// \since Crypto++ 8.6
inline uint64x2_t VEOR3(uint64x2_t a, uint64x2_t b, uint64x2_t c)
{
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
return veor3q_u64(a, b, c);
#else
uint64x2_t r;
Expand All @@ -370,7 +370,7 @@ inline uint64x2_t VEOR3(uint64x2_t a, uint64x2_t b, uint64x2_t c)
/// \since Crypto++ 8.6
inline uint64x2_t VXAR(uint64x2_t a, uint64x2_t b, const int c)
{
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
return vxarq_u64(a, b, c);
#else
uint64x2_t r;
Expand All @@ -392,7 +392,7 @@ inline uint64x2_t VXAR(uint64x2_t a, uint64x2_t b, const int c)
template <unsigned int C>
inline uint64x2_t VXAR(uint64x2_t a, uint64x2_t b)
{
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
return vxarq_u64(a, b, C);
#else
uint64x2_t r;
Expand All @@ -412,7 +412,7 @@ inline uint64x2_t VXAR(uint64x2_t a, uint64x2_t b)
/// \since Crypto++ 8.6
inline uint64x2_t VRAX1(uint64x2_t a, uint64x2_t b)
{
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
return vrax1q_u64(a, b);
#else
uint64x2_t r;
Expand Down
2 changes: 1 addition & 1 deletion chacha_avx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern const char CHACHA_AVX_FNAME[] = __FILE__;
// https://github.com/weidai11/cryptopp/issues/735. The
// 649 issue affects AES but it is the same here. The 735
// issue is ChaCha AVX2 cut-in where it surfaced again.
#if (_MSC_VER >= 1910) && (_MSC_VER <= 1916)
#if (CRYPTOPP_MSC_VERSION >= 1910) && (CRYPTOPP_MSC_VERSION <= 1916)
# ifndef CRYPTOPP_DEBUG
# pragma optimize("", off)
# pragma optimize("ts", on)
Expand Down
4 changes: 2 additions & 2 deletions config_align.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

// How to allocate 16-byte aligned memory (for SSE2)
// posix_memalign see https://forum.kde.org/viewtopic.php?p=66274
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
#define CRYPTOPP_MM_MALLOC_AVAILABLE
#elif defined(__linux__) || defined(__sun__) || defined(__CYGWIN__)
#define CRYPTOPP_MEMALIGN_AVAILABLE
Expand All @@ -59,7 +59,7 @@
// CRYPTOPP_ALIGN_DATA may not be reliable on AIX.
#if defined(CRYPTOPP_CXX11_ALIGNAS)
#define CRYPTOPP_ALIGN_DATA(x) alignas(x)
#elif defined(_MSC_VER)
#elif defined(CRYPTOPP_MSC_VERSION)
#define CRYPTOPP_ALIGN_DATA(x) __declspec(align(x))
#elif defined(__GNUC__) || defined(__clang__) || (__SUNPRO_CC >= 0x5100)
#define CRYPTOPP_ALIGN_DATA(x) __attribute__((aligned(x)))
Expand Down
6 changes: 3 additions & 3 deletions config_asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@
#endif

// 32-bit SunCC does not enable SSE2 by default.
#if !defined(CRYPTOPP_DISABLE_SSE2) && (defined(_MSC_VER) || CRYPTOPP_GCC_VERSION >= 30300 || defined(__SSE2__) || (__SUNPRO_CC >= 0x5100))
#if !defined(CRYPTOPP_DISABLE_SSE2) && (defined(CRYPTOPP_MSC_VERSION) || CRYPTOPP_GCC_VERSION >= 30300 || defined(__SSE2__) || (__SUNPRO_CC >= 0x5100))
#define CRYPTOPP_SSE2_INTRIN_AVAILABLE 1
#endif

#if !defined(CRYPTOPP_DISABLE_SSSE3)
# if defined(__SSSE3__) || (_MSC_VER >= 1500) || \
# if defined(__SSSE3__) || (CRYPTOPP_MSC_VERSION >= 1500) || \
(CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1000) || (__SUNPRO_CC >= 0x5110) || \
(CRYPTOPP_LLVM_CLANG_VERSION >= 20300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40000)
#define CRYPTOPP_SSSE3_AVAILABLE 1
Expand Down Expand Up @@ -312,7 +312,7 @@
#endif

// Buggy Microsoft compiler, https://github.com/weidai11/cryptopp/issues/1096
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
# undef CRYPTOPP_ARM_SHA1_AVAILABLE
# undef CRYPTOPP_ARM_SHA2_AVAILABLE
#endif
Expand Down
2 changes: 1 addition & 1 deletion config_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
/// \details CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY is defined when neither
/// <tt>_MSC_VER</tt> nor <tt>__BORLANDC__</tt> are defined.
#define CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY ...
#elif defined(_MSC_VER) || defined(__BORLANDC__)
#elif defined(CRYPTOPP_MSC_VERSION) || defined(__BORLANDC__)
#define CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY 1
#else
#define CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY 1
Expand Down
8 changes: 4 additions & 4 deletions config_cxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

// You may need to force include a C++ header on Android when using STLPort
// to ensure _STLPORT_VERSION is defined
#if (defined(_MSC_VER) && _MSC_VER <= 1300) || \
#if (defined(CRYPTOPP_MSC_VERSION) && CRYPTOPP_MSC_VERSION <= 1300) || \
defined(__MWERKS__) || \
(defined(_STLPORT_VERSION) && ((_STLPORT_VERSION < 0x450) || defined(_STLP_NO_UNCAUGHT_EXCEPT_SUPPORT)) || \
(__cplusplus >= 202002L))
Expand All @@ -58,7 +58,7 @@
#endif

// C++11 macro version, https://stackoverflow.com/q/7223991/608639
#if ((_MSC_VER >= 1600) || (__cplusplus >= 201103L)) && !defined(_STLPORT_VERSION)
#if ((CRYPTOPP_MSC_VERSION >= 1600) || (__cplusplus >= 201103L)) && !defined(_STLPORT_VERSION)
# define CRYPTOPP_CXX11 1
#endif

Expand All @@ -76,14 +76,14 @@

// C++14 macro version, https://stackoverflow.com/q/26089319/608639
#if defined(CRYPTOPP_CXX11) && !defined(CRYPTOPP_NO_CXX14)
# if ((_MSC_VER >= 1900) || (__cplusplus >= 201402L)) && !defined(_STLPORT_VERSION)
# if ((CRYPTOPP_MSC_VERSION >= 1900) || (__cplusplus >= 201402L)) && !defined(_STLPORT_VERSION)
# define CRYPTOPP_CXX14 1
# endif
#endif

// C++17 macro version, https://stackoverflow.com/q/38456127/608639
#if defined(CRYPTOPP_CXX14) && !defined(CRYPTOPP_NO_CXX17)
# if ((_MSC_VER >= 1900) || (__cplusplus >= 201703L)) && !defined(_STLPORT_VERSION)
# if ((CRYPTOPP_MSC_VERSION >= 1900) || (__cplusplus >= 201703L)) && !defined(_STLPORT_VERSION)
# define CRYPTOPP_CXX17 1
# endif
#endif
Expand Down
4 changes: 2 additions & 2 deletions config_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ typedef signed int sword32;
/// where the cpu is slow even with a 64-bit cpu.
#define CRYPTOPP_BOOL_SLOW_WORD64 ...

#elif defined(_MSC_VER) || defined(__BORLANDC__)
#elif defined(CRYPTOPP_MSC_VERSION) || defined(__BORLANDC__)
typedef signed __int64 sword64;
typedef unsigned __int64 word64;
#define SW64LIT(x) x##i64
Expand Down Expand Up @@ -215,7 +215,7 @@ CRYPTOPP_CONST_OR_CONSTEXPR lword LWORD_MAX = W64LIT(0xffffffffffffffff);
#else
// define hword, word, and dword. these are used for multiprecision integer arithmetic
// Intel compiler won't have _umul128 until version 10.0. See http://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/30231625.aspx
#if (defined(_MSC_VER) && (!defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1000) && (defined(_M_X64) || defined(_M_IA64))) || (defined(__DECCXX) && defined(__alpha__)) || (defined(__INTEL_COMPILER) && defined(__x86_64__)) || (defined(__SUNPRO_CC) && defined(__x86_64__))
#if (defined(CRYPTOPP_MSC_VERSION) && (!defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1000) && (defined(_M_X64) || defined(_M_IA64))) || (defined(__DECCXX) && defined(__alpha__)) || (defined(__INTEL_COMPILER) && defined(__x86_64__)) || (defined(__SUNPRO_CC) && defined(__x86_64__))
typedef word32 hword;
typedef word64 word;
#else
Expand Down
8 changes: 4 additions & 4 deletions config_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
#endif

// how to disable inlining
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
# define CRYPTOPP_NOINLINE_DOTDOTDOT
# define CRYPTOPP_NOINLINE __declspec(noinline)
#elif defined(__xlc__) || defined(__xlC__) || defined(__ibmxl__)
Expand Down Expand Up @@ -169,14 +169,14 @@
#endif

// Warnings
#ifdef _MSC_VER
#ifdef CRYPTOPP_MSC_VERSION
// 4127: conditional expression is constant
// 4512: assignment operator not generated
// 4661: no suitable definition provided for explicit template instantiation request
// 4910: '__declspec(dllexport)' and 'extern' are incompatible on an explicit instantiation
# pragma warning(disable: 4127 4512 4661 4910)
// _MSC_VER 1920 is VS2019
# if _MSC_VER >= 1920
// CRYPTOPP_MSC_VERSION 1920 is VS2019
# if CRYPTOPP_MSC_VERSION >= 1920
// 5054: operator '|': deprecated between enumerations of different types
# pragma warning(disable: 5054)
# endif
Expand Down
7 changes: 3 additions & 4 deletions config_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
// https://www.cryptopp.com/wiki/Release_Process#Self_Tests
// The problems with Clang pretending to be other compilers is
// discussed at http://github.com/weidai11/cryptopp/issues/147.
#if (defined(_MSC_VER) && defined(__clang__) && \
!(defined( __clang_analyzer__)) && !defined(__INTEL_LLVM_COMPILER))
#if (defined(_MSC_VER) && defined(__clang__))
# error: "Unsupported configuration"
#endif

Expand All @@ -50,14 +49,14 @@
#endif

// Microsoft compilers
#if defined(_MSC_VER) || defined(__fastcall)
#if defined(CRYPTOPP_MSC_VERSION) || defined(__fastcall)
#define CRYPTOPP_FASTCALL __fastcall
#else
#define CRYPTOPP_FASTCALL
#endif

// Microsoft compilers
#if defined(_MSC_VER)
#if defined(CRYPTOPP_MSC_VERSION)
#define CRYPTOPP_NO_VTABLE __declspec(novtable)
#else
#define CRYPTOPP_NO_VTABLE
Expand Down
8 changes: 4 additions & 4 deletions config_ver.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,23 @@
// code paths that it cannot compile. Unset Clang to save the grief.
// Also see http://github.com/weidai11/cryptopp/issues/147.

#if defined(__GNUC__)
#if defined(__GNUC__) && !defined(__clang__)
# undef CRYPTOPP_APPLE_CLANG_VERSION
# undef CRYPTOPP_LLVM_CLANG_VERSION
# define CRYPTOPP_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif

#if defined(__xlc__) || defined(__xlC__)
#if defined(__xlc__) || defined(__xlC__) && !defined(__clang__)
# undef CRYPTOPP_LLVM_CLANG_VERSION
# define CRYPTOPP_XLC_VERSION ((__xlC__ / 256) * 10000 + (__xlC__ % 256) * 100)
#endif

#ifdef __INTEL_COMPILER
#if defined(__INTEL_COMPILER) && !defined(__clang__)
# undef CRYPTOPP_LLVM_CLANG_VERSION
# define CRYPTOPP_INTEL_VERSION (__INTEL_COMPILER)
#endif

#ifdef _MSC_VER
#if defined(_MSC_VER) && !defined(__clang__)
# undef CRYPTOPP_LLVM_CLANG_VERSION
# define CRYPTOPP_MSC_VERSION (_MSC_VER)
#endif
Expand Down
Loading

1 comment on commit a89a27b

@noloader
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config_ver.h sets up the Crypto++ specific defines, like CRYPTOPP_MSC_VERSION. The config file is what ensures Clang does not cross-pollinate into other compilers.

Please sign in to comment.