All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Christopher Li <sparse@chrisli.org>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 2/3] teach sparse about __{BIG,LITTLE}_ENDIAN__
Date: Tue, 20 Jun 2017 22:19:30 +0200	[thread overview]
Message-ID: <20170620201931.92864-3-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170620201931.92864-1-luc.vanoostenryck@gmail.com>

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

diff --git a/lib.c b/lib.c
index a22635ecc..daf7d0219 100644
--- a/lib.c
+++ b/lib.c
@@ -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)
diff --git a/validation/endian-big.c b/validation/endian-big.c
new file mode 100644
index 000000000..d535748cd
--- /dev/null
+++ b/validation/endian-big.c
@@ -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
+ */
diff --git a/validation/endian-little.c b/validation/endian-little.c
new file mode 100644
index 000000000..cc4a14f73
--- /dev/null
+++ b/validation/endian-little.c
@@ -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
+ */
-- 
2.13.0


  parent reply	other threads:[~2017-06-20 20:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-20 20:19 [PATCH 0/3] teach sparse about endianness Luc Van Oostenryck
2017-06-20 20:19 ` [PATCH 1/3] teach sparse about -m{big,little}-endian Luc Van Oostenryck
2017-06-20 20:19 ` Luc Van Oostenryck [this message]
2017-06-20 20:19 ` [PATCH 3/3] teach sparse about __BYTE_ORDER__ & __ORDER_{BIG,LITTLE}_ENDIAN__ Luc Van Oostenryck
2017-06-21  4:13 ` [PATCH 0/3] teach sparse about endianness Christopher Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170620201931.92864-3-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=sparse@chrisli.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.