Linux SPARSE checker discussions
 help / color / mirror / Atom feed
* [PATCH] warnings: ensure the source filename is shown at least once
@ 2020-07-18 18:39 Luc Van Oostenryck
  2020-07-18 20:21 ` Linus Torvalds
  0 siblings, 1 reply; 3+ messages in thread
From: Luc Van Oostenryck @ 2020-07-18 18:39 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

When checking a series of files, if some warnings or errors
are issued but only coming from some includes, it's not possible
to identify which source file is responsible since its filename
is not displayed.

So, if the first warning is from a file other than the source
file, display first a note coming from the source file itself.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 lib.c                         | 13 +++++++++++++
 validation/cast-kinds-check.c |  1 +
 2 files changed, 14 insertions(+)

diff --git a/lib.c b/lib.c
index 4e8d7b451747..b94c2c83c1c5 100644
--- a/lib.c
+++ b/lib.c
@@ -50,6 +50,18 @@
 #include "bits.h"
 
 
+static void show_top_filename(const char *name)
+{
+	static const char *last;
+
+	if (name == base_filename)
+		return;
+	if (name == last)
+		return;
+	fprintf(stderr, "%s: note: in included file:\n", base_filename);
+	last = name;
+}
+
 static void do_warn(const char *type, struct position pos, const char * fmt, va_list args)
 {
 	static char buffer[512];
@@ -63,6 +75,7 @@ static void do_warn(const char *type, struct position pos, const char * fmt, va_
 	name = stream_name(pos.stream);
 		
 	fflush(stdout);
+	show_top_filename(name);
 	fprintf(stderr, "%s:%d:%d: %s%s%s\n",
 		name, pos.line, pos.pos, diag_prefix, type, buffer);
 }
diff --git a/validation/cast-kinds-check.c b/validation/cast-kinds-check.c
index 0c0cd67368a3..32a106d413da 100644
--- a/validation/cast-kinds-check.c
+++ b/validation/cast-kinds-check.c
@@ -6,6 +6,7 @@
  * check-assert: sizeof(long) == 8
  *
  * check-error-start
+cast-kinds-check.c: note: in included file:
 optim/cast-kinds.c:5:45: warning: cast drops bits
 optim/cast-kinds.c:6:47: warning: cast drops bits
 optim/cast-kinds.c:7:46: warning: cast drops bits
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-18 23:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-18 18:39 [PATCH] warnings: ensure the source filename is shown at least once Luc Van Oostenryck
2020-07-18 20:21 ` Linus Torvalds
2020-07-18 23:36   ` Luc Van Oostenryck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox