@@ -961,6 +961,9 @@ static void predefined_macros(void)
predefined_sizeof("FLOAT", bits_in_float);
predefined_sizeof("DOUBLE", bits_in_double);
predefined_sizeof("LONG_DOUBLE", bits_in_longdouble);
+
+ add_pre_buffer("#weak_define __%s_ENDIAN__ 1\n",
+ arch_big_endian ? "BIG" : "LITTLE");
}
void declare_builtin_functions(void)
new file mode 100644
@@ -0,0 +1,11 @@
+#if defined(__LITTLE_ENDIAN__)
+#error "__LITTLE_ENDIAN__ defined!"
+#endif
+#if (__BIG_ENDIAN__ != 1)
+#error "__BIG_ENDIAN__ not correctly defined!"
+#endif
+
+/*
+ * check-name: endian-big.c
+ * check-command: sparse -mbig-endian $file
+ */
new file mode 100644
@@ -0,0 +1,11 @@
+#if defined(__BIG_ENDIAN__)
+#error "__BIG_ENDIAN__ defined!"
+#endif
+#if (__LITTLE_ENDIAN__ != 1)
+#error "__LITTLE_ENDIAN__ not correctly defined!"
+#endif
+
+/*
+ * check-name: endian-little.c
+ * check-command: sparse -mlittle-endian $file
+ */
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 __{BIG,LITTLE}_ENDIAN__. Let sparse predefine these macros like compilers do. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- lib.c | 3 +++ validation/endian-big.c | 11 +++++++++++ validation/endian-little.c | 11 +++++++++++ 3 files changed, 25 insertions(+) create mode 100644 validation/endian-big.c create mode 100644 validation/endian-little.c