From cc4147ec2fe2c311fa0a3c7486a380a00d3ebf1b Mon Sep 17 00:00:00 2001 From: Joshua Root Date: Mon, 24 Jul 2023 22:43:42 +1000 Subject: [PATCH] Check if clang has __builtin_bswap16 (#1932) Some older versions of clang do not in fact have this builtin. Co-authored-by: Toby Peterson --- libarchive/archive_read_support_format_lha.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libarchive/archive_read_support_format_lha.c b/libarchive/archive_read_support_format_lha.c index fa907a346..1c64b2900 100644 --- a/libarchive/archive_read_support_format_lha.c +++ b/libarchive/archive_read_support_format_lha.c @@ -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)) -- 2.47.2