[Patch for compiler-rt] Make int_endianness.h work in an OS-independent way

Ed Schouten ed at 80386.nl
Thu Feb 12 05:43:04 PST 2015


Hi there,

While porting compiler-rt to a different platform, I noticed that
int_endianness.h attempts to determine the endianness of the target
platform by operating system. As far as I know, this is not needed in the
general case, as both GCC and Clang provide the same built-in endianness
macros. These macros are already used for Linux.

Attached is a patch that changes int_endianness.h to move the construct
used for Linux to the top and prefer them over any OS-dependent construct.
In theory we could now remove some of the OS-dependent checks below, but
let's leave them as is for now.

Thanks,
-- 
Ed Schouten <ed at 80386.nl>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150212/45410cb8/attachment.html>
-------------- next part --------------
Index: lib/builtins/int_endianness.h
===================================================================
--- lib/builtins/int_endianness.h	(revision 228919)
+++ lib/builtins/int_endianness.h	(working copy)
@@ -16,6 +16,20 @@
 #ifndef INT_ENDIANNESS_H
 #define INT_ENDIANNESS_H
 
+#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
+    defined(__ORDER_LITTLE_ENDIAN__)
+
+/* Clang and GCC provide built-in endianness definitions. */
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#define _YUGA_LITTLE_ENDIAN 0
+#define _YUGA_BIG_ENDIAN    1
+#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define _YUGA_LITTLE_ENDIAN 1
+#define _YUGA_BIG_ENDIAN    0
+#endif /* __BYTE_ORDER__ */
+
+#else /* Compilers other than Clang or GCC. */
+
 #if defined(__SVR4) && defined(__sun)
 #include <sys/byteorder.h>
 
@@ -84,18 +98,6 @@
 
 /* .. */
 
-#if defined(__linux__)
-
-#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-#define _YUGA_LITTLE_ENDIAN 0
-#define _YUGA_BIG_ENDIAN    1
-#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-#define _YUGA_LITTLE_ENDIAN 1
-#define _YUGA_BIG_ENDIAN    0
-#endif /* __BYTE_ORDER__ */
-
-#endif /* GNU/Linux */
-
 #if defined(_WIN32)
 
 #define _YUGA_LITTLE_ENDIAN 1
@@ -103,6 +105,8 @@
 
 #endif /* Windows */
 
+#endif /* Clang or GCC. */
+
 /* . */
 
 #if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN)


More information about the llvm-commits mailing list