]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Check if clang has __builtin_bswap16 (#1932)
authorJoshua Root <jmr@macports.org>
Mon, 24 Jul 2023 12:43:42 +0000 (22:43 +1000)
committerGitHub <noreply@github.com>
Mon, 24 Jul 2023 12:43:42 +0000 (14:43 +0200)
Some older versions of clang do not in fact have this builtin.

Co-authored-by: Toby Peterson <toby@macports.org>
libarchive/archive_read_support_format_lha.c

index fa907a34640806ea94beda31a1e8f073d8e9d8a9..1c64b2900b8e051e149d1f63c0a682317e29bef7 100644 (file)
@@ -1818,13 +1818,16 @@ lha_crc16(uint16_t crc, const void *pp, size_t len)
                /* This if statement expects compiler optimization will
                 * remove the statement which will not be executed. */
 #undef bswap16
+#ifndef __has_builtin
+#define __has_builtin(x) 0
+#endif
 #if defined(_MSC_VER) && _MSC_VER >= 1400  /* Visual Studio */
 #  define bswap16(x) _byteswap_ushort(x)
 #elif defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || __GNUC__ > 4)
 /* GCC 4.8 and later has __builtin_bswap16() */
 #  define bswap16(x) __builtin_bswap16(x)
-#elif defined(__clang__)
-/* All clang versions have __builtin_bswap16() */
+#elif defined(__clang__) && __has_builtin(__builtin_bswap16)
+/* Newer clang versions have __builtin_bswap16() */
 #  define bswap16(x) __builtin_bswap16(x)
 #else
 #  define bswap16(x) ((((x) >> 8) & 0xff) | ((x) << 8))