aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/pre-process.c
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-07-18 23:03:22 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-07-19 01:11:21 +0200
commite140005c44ef962f5ee2a72735ea727e5db7f7f6 (patch)
tree34db810c67998ece9bd68b336548d1330c0470bd /pre-process.c
parentdd6c3980de7daa8112a0791df730b04f2fcb3c5c (diff)
downloadsparse-dev-e140005c44ef962f5ee2a72735ea727e5db7f7f6.tar.gz
prepend diagnostics with source's path and include chain
When a diagnostic is issued for a problem in an included file, the message show the include's path but it's often needed to (quickly) know the chain of include files involved. So, if the path associated with the diagnostic is different than the path oft he source file and different from the path of the previous message, prepend the message with a note showing the source file's path. And, if any intermediate include file is concerned, display the include chain (possibly truncated or not displayed at all if too long). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'pre-process.c')
-rw-r--r--pre-process.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/pre-process.c b/pre-process.c
index 403e3507..6f4bf897 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -894,7 +894,7 @@ static void set_stream_include_path(struct stream *stream)
#define PATH_MAX 4096 // for Hurd where it's not defined
#endif
-static int try_include(const char *path, const char *filename, int flen, struct token **where, const char **next_path)
+static int try_include(struct position pos, const char *path, const char *filename, int flen, struct token **where, const char **next_path)
{
int fd;
int plen = strlen(path);
@@ -911,7 +911,7 @@ static int try_include(const char *path, const char *filename, int flen, struct
fd = open(fullname, O_RDONLY);
if (fd >= 0) {
char *streamname = xmemdup(fullname, plen + flen);
- *where = tokenize(streamname, fd, *where, next_path);
+ *where = tokenize(streamname, fd, pos.stream, *where, next_path);
close(fd);
return 1;
}
@@ -923,7 +923,7 @@ static int do_include_path(const char **pptr, struct token **list, struct token
const char *path;
while ((path = *pptr++) != NULL) {
- if (!try_include(path, filename, flen, list, pptr))
+ if (!try_include(token->pos, path, filename, flen, list, pptr))
continue;
return 1;
}
@@ -966,7 +966,7 @@ static int handle_include_path(struct stream *stream, struct token **list, struc
/* Absolute path? */
if (filename[0] == '/') {
- if (try_include("", filename, flen, list, includepath))
+ if (try_include(token->pos, "", filename, flen, list, includepath))
return 0;
goto out;
}
@@ -2091,7 +2091,7 @@ static void create_arglist(struct symbol *sym, int count)
static void init_preprocessor(void)
{
int i;
- int stream = init_stream("preprocessor", -1, includepath);
+ int stream = init_stream("preprocessor", -1, includepath, -1);
static struct {
const char *name;
int (*handler)(struct stream *, struct token **, struct token *);