[PATCH 3/3] teach sparse about __BYTE_ORDER__ & __ORDER_{BIG,LITTLE}_ENDIAN__

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Some macros, structures definitions, ... depends on the
endianness. This is generaly done via some header file
but these headers need information from the compiler via
the macros __BYTE_ORDER__, itself being defined to
__ORDER_BIG_ENDIAN__ or __ORDER_LITTLE_ENDIAN__.

Let sparse predefine these macros like compilers do.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 lib.c                      | 6 ++++++
 validation/endian-big.c    | 3 +++
 validation/endian-little.c | 3 +++
 3 files changed, 12 insertions(+)

diff --git a/lib.c b/lib.c
index daf7d0219..de6350439 100644
--- a/lib.c
+++ b/lib.c
@@ -964,6 +964,12 @@ static void predefined_macros(void)
 
 	add_pre_buffer("#weak_define __%s_ENDIAN__ 1\n",
 		arch_big_endian ? "BIG" : "LITTLE");
+
+	add_pre_buffer("#weak_define __ORDER_LITTLE_ENDIAN__ 1234\n");
+	add_pre_buffer("#weak_define __ORDER_BIG_ENDIAN__ 4321\n");
+	add_pre_buffer("#weak_define __ORDER_PDP_ENDIAN__ 3412\n");
+	add_pre_buffer("#weak_define __BYTE_ORDER__ __ORDER_%s_ENDIAN__\n",
+		arch_big_endian ? "BIG" : "LITTLE");
 }
 
 void declare_builtin_functions(void)
diff --git a/validation/endian-big.c b/validation/endian-big.c
index d535748cd..ebf95df70 100644
--- a/validation/endian-big.c
+++ b/validation/endian-big.c
@@ -4,6 +4,9 @@
 #if (__BIG_ENDIAN__ != 1)
 #error "__BIG_ENDIAN__ not correctly defined!"
 #endif
+#if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__)
+#error "__BYTE_ORDER__ not correctly defined!"
+#endif
 
 /*
  * check-name: endian-big.c
diff --git a/validation/endian-little.c b/validation/endian-little.c
index cc4a14f73..57ef69866 100644
--- a/validation/endian-little.c
+++ b/validation/endian-little.c
@@ -4,6 +4,9 @@
 #if (__LITTLE_ENDIAN__ != 1)
 #error "__LITTLE_ENDIAN__ not correctly defined!"
 #endif
+#if (__BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__)
+#error "__BYTE_ORDER__ not correctly defined!"
+#endif
 
 /*
  * check-name: endian-little.c
-- 
2.13.0

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux