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>,
	Mark Rutland <mark.rutland@arm.com>,
	Stephen Boyd <stephen.boyd@linaro.org>,
	Will Deacon <will.deacon@arm.com>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 1/5] use option: '-Woverride-init'
Date: Wed, 22 Feb 2017 16:30:02 +0100	[thread overview]
Message-ID: <20170222153006.3035-2-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170222153006.3035-1-luc.vanoostenryck@gmail.com>

Sparse warns unconditionally about overlapping initilalizers.

Introduces a warning flag to control this, use the same name
as GCC's and enabled it by default.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 expand.c                        |  3 +++
 lib.c                           |  2 ++
 lib.h                           |  1 +
 validation/Woverride-init-def.c | 14 ++++++++++++++
 validation/Woverride-init-no.c  | 12 ++++++++++++
 validation/Woverride-init-yes.c | 14 ++++++++++++++
 6 files changed, 46 insertions(+)
 create mode 100644 validation/Woverride-init-def.c
 create mode 100644 validation/Woverride-init-no.c
 create mode 100644 validation/Woverride-init-yes.c

diff --git a/expand.c b/expand.c
index 7af12707e..7457c94dd 100644
--- a/expand.c
+++ b/expand.c
@@ -916,6 +916,9 @@ static void verify_nonoverlapping(struct expression_list **list)
 	struct expression *a = NULL;
 	struct expression *b;
 
+	if (!Woverride_init)
+		return;
+
 	FOR_EACH_PTR(*list, b) {
 		if (!b->ctype || !b->ctype->bit_size)
 			continue;
diff --git a/lib.c b/lib.c
index d47325243..a20f68aa2 100644
--- a/lib.c
+++ b/lib.c
@@ -231,6 +231,7 @@ int Wsparse_error = 0;
 int Wnon_pointer_null = 1;
 int Wold_initializer = 1;
 int Wone_bit_signed_bitfield = 1;
+int Woverride_init = 1;
 int Wparen_string = 0;
 int Wptr_subtraction_blows = 0;
 int Wreturn_void = 0;
@@ -480,6 +481,7 @@ static const struct warning {
 	{ "non-pointer-null", &Wnon_pointer_null },
 	{ "old-initializer", &Wold_initializer },
 	{ "one-bit-signed-bitfield", &Wone_bit_signed_bitfield },
+	{ "override-init", &Woverride_init },
 	{ "paren-string", &Wparen_string },
 	{ "ptr-subtraction-blows", &Wptr_subtraction_blows },
 	{ "return-void", &Wreturn_void },
diff --git a/lib.h b/lib.h
index 095b1f517..35edd3217 100644
--- a/lib.h
+++ b/lib.h
@@ -117,6 +117,7 @@ extern int Winit_cstring;
 extern int Wnon_pointer_null;
 extern int Wold_initializer;
 extern int Wone_bit_signed_bitfield;
+extern int Woverride_init;
 extern int Wparen_string;
 extern int Wptr_subtraction_blows;
 extern int Wreturn_void;
diff --git a/validation/Woverride-init-def.c b/validation/Woverride-init-def.c
new file mode 100644
index 000000000..95ecf33be
--- /dev/null
+++ b/validation/Woverride-init-def.c
@@ -0,0 +1,14 @@
+static int array[] = {
+	[1] = 3,
+	[1] = 1,		/* check-should-warn */
+};
+
+/*
+ * check-name: Woverride-init-def
+ * check-command: sparse $file
+ *
+ * check-error-start
+Woverride-init-def.c:2:10: warning: Initializer entry defined twice
+Woverride-init-def.c:3:10:   also defined here
+ * check-error-end
+ */
diff --git a/validation/Woverride-init-no.c b/validation/Woverride-init-no.c
new file mode 100644
index 000000000..ba4d82b9f
--- /dev/null
+++ b/validation/Woverride-init-no.c
@@ -0,0 +1,12 @@
+static int array[] = {
+	[1] = 3,
+	[1] = 1,		/* check-should-warn */
+};
+
+/*
+ * check-name: Woverride-init-no
+ * check-command: sparse -Wno-override-init $file
+ *
+ * check-error-start
+ * check-error-end
+ */
diff --git a/validation/Woverride-init-yes.c b/validation/Woverride-init-yes.c
new file mode 100644
index 000000000..c04a836be
--- /dev/null
+++ b/validation/Woverride-init-yes.c
@@ -0,0 +1,14 @@
+static int array[] = {
+	[1] = 3,
+	[1] = 1,		/* check-should-warn */
+};
+
+/*
+ * check-name: Woverride-init-yes
+ * check-command: sparse -Woverride-init $file
+ *
+ * check-error-start
+Woverride-init-yes.c:2:10: warning: Initializer entry defined twice
+Woverride-init-yes.c:3:10:   also defined here
+ * check-error-end
+ */
-- 
2.11.1


  reply	other threads:[~2017-02-22 15:57 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-17 16:51 [PATCH] arm64: traps: Mark __le16, __le32, __user variables properly Stephen Boyd
2017-02-17 16:51 ` Stephen Boyd
2017-02-17 17:31 ` Russell King - ARM Linux
2017-02-17 17:31   ` Russell King - ARM Linux
2017-02-17 17:46   ` Stephen Boyd
2017-02-19  1:58 ` Luc Van Oostenryck
2017-02-19  1:58   ` Luc Van Oostenryck
2017-02-20  8:47   ` Stephen Boyd
2017-02-20 10:04     ` Luc Van Oostenryck
2017-02-20 10:04       ` Luc Van Oostenryck
2017-02-20 10:49     ` Mark Rutland
2017-02-20 10:49       ` Mark Rutland
2017-02-20 21:33       ` Luc Van Oostenryck
2017-02-20 21:33         ` Luc Van Oostenryck
2017-02-21 11:03         ` Will Deacon
2017-02-21 11:03           ` Will Deacon
2017-02-22 13:00           ` Luc Van Oostenryck
2017-02-22 13:00             ` Luc Van Oostenryck
2017-02-22 15:30           ` [PATCH 0/5] improve detection of overlapping initializers Luc Van Oostenryck
2017-02-22 15:30             ` Luc Van Oostenryck [this message]
2017-02-22 15:30             ` [PATCH 2/5] add test case for warnings about " Luc Van Oostenryck
2017-02-22 15:30             ` [PATCH 3/5] allow to warn on all " Luc Van Oostenryck
2017-02-22 15:30             ` [PATCH 4/5] fix checking of overlapping initializer Luc Van Oostenryck
2017-02-22 15:30             ` [PATCH 5/5] ignore whole-range " Luc Van Oostenryck
2017-02-27 16:34               ` Christopher Li
2017-02-27 21:38                 ` Luc Van Oostenryck

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=20170222153006.3035-2-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=sparse@chrisli.org \
    --cc=stephen.boyd@linaro.org \
    --cc=will.deacon@arm.com \
    /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.