-#ifdef __GNUC__
-# if defined(__CYGWIN__) || defined(__WIN32__)
-# define WIMLIBAPI __declspec(dllexport)
-# else
-# define WIMLIBAPI __attribute__((visibility("default")))
-# endif
-# define _always_inline_attribute inline __attribute__((always_inline))
-# define _packed_attribute __attribute__((packed))
-# define _format_attribute(type, format_str, args_start) \
- /*__attribute__((format(type, format_str, args_start))) */
-# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
-# define _cold_attribute __attribute__((cold))
-# else
-# define _cold_attribute
-# endif
-# define _malloc_attribute __attribute__((malloc))
-# define _warn_unused_result_attribute __attribute__((warn_unused_result))
-# define _aligned_attribute(size) __attribute__((aligned(size)))
-# define likely(x) __builtin_expect(!!(x), 1)
-# define unlikely(x) __builtin_expect(!!(x), 0)
-# define inline inline __attribute__((always_inline))
-# define prefetch(x) __builtin_prefetch(x)
-# define is_constant(x) __builtin_constant_p(x)
+/* Is the compiler GCC of the specified version or later? This always returns
+ * false for clang, since clang is "frozen" at GNUC 4.2. The __has_*
+ * feature-test macros should be used to detect clang functionality instead. */
+#define GCC_PREREQ(major, minor) \
+ (!defined(__clang__) && !defined(__INTEL_COMPILER) && \
+ (__GNUC__ > major || \
+ (__GNUC__ == major && __GNUC_MINOR__ >= minor)))
+
+/* Feature-test macros defined by recent versions of clang. */
+#ifndef __has_attribute
+# define __has_attribute(attribute) 0
+#endif
+#ifndef __has_feature
+# define __has_feature(feature) 0
+#endif
+#ifndef __has_builtin
+# define __has_builtin(builtin) 0
+#endif
+
+/* Declare that the annotated function should be exported from the shared
+ * library (or DLL). */
+#ifdef __WIN32__
+# define WIMLIBAPI __declspec(dllexport)
+#else
+# define WIMLIBAPI __attribute__((visibility("default")))
+#endif
+
+/* Declare that the annotated function should always be inlined. This might be
+ * desirable in highly tuned code, e.g. compression codecs. */
+#define forceinline inline __attribute__((always_inline))
+
+/* Declare that the annotated function should *not* be inlined. */
+#define noinline __attribute__((noinline))
+
+/* Functionally the same as 'noinline', but documents that the reason for not
+ * inlining is to prevent the annotated function from being inlined into a
+ * recursive function, thereby increasing its stack usage. */
+#define noinline_for_stack noinline
+
+/* Hint that the expression is usually true. */
+#define likely(expr) __builtin_expect(!!(expr), 1)
+
+/* Hint that the expression is usually false. */
+#define unlikely(expr) __builtin_expect(!!(expr), 0)
+
+/* Prefetch into L1 cache for read. */
+#define prefetchr(addr) __builtin_prefetch((addr), 0)
+
+/* Prefetch into L1 cache for write. */
+#define prefetchw(addr) __builtin_prefetch((addr), 1)
+
+/* Declare that the members of the annotated struct are tightly packed, and the
+ * struct itself may be misaligned. */
+#define _packed_attribute __attribute__((packed))
+
+/* Declare that the annotated variable, or variables of the annotated type, are
+ * to be aligned on n-byte boundaries. */
+#define _aligned_attribute(n) __attribute__((aligned(n)))
+
+/* Declare that pointers to the annotated type may alias other pointers. */
+#define _may_alias_attribute __attribute__((may_alias))
+
+/* Hint that the annotated function is rarely called. */
+#if GCC_PREREQ(4, 4) || __has_attribute(cold)
+# define _cold_attribute __attribute__((cold))
+#else
+# define _cold_attribute
+#endif
+
+/* Hint that the annotated function is malloc-like: any non-null pointer it
+ * returns will not alias any pointer previously in use by the program. */
+#define _malloc_attribute __attribute__((malloc))
+
+/* Hint that the annotated function takes a printf()-like format string and
+ * arguments. This is currently disabled on Windows because MinGW does not
+ * support this attribute on functions taking wide-character strings. */
+#ifdef __WIN32__
+# define _format_attribute(type, format_str, format_start)