diff options
| -rw-r--r-- | c/lex.c | 3 | ||||
| -rw-r--r-- | c/lex.h | 4 | ||||
| -rw-r--r-- | io.c | 7 |
3 files changed, 10 insertions, 4 deletions
@@ -1668,6 +1668,7 @@ tryinclude(struct lexer *lx, const struct span *span, char *path) case LXOK: new.save = xmalloc(sizeof *new.save); lx->inclnerror = nerror; + lx->inclnwarn = nwarn; memcpy(new.save, lx, sizeof *lx); *lx = new; @@ -2036,7 +2037,7 @@ Begin: markfileonce(lx->fileid, lx->inclguard); } struct lexer *sv = lx->save; - if (sv->inclnerror != nerror) { + if (sv->inclnerror != nerror || sv->inclnwarn != nwarn) { int line; const char *f = getfilepos(&line, NULL, sv->fileid, sv->chridx-2); note(NULL, "in file included from %s:%d", f, line); @@ -88,7 +88,7 @@ struct token { */ }; -extern int nerror; +extern int nerror, nwarn; struct lexer { struct lexer *save; short fileid; @@ -102,7 +102,7 @@ struct lexer { struct arena **tmparena; bool firstdirective; short nppcnd0; - short inclnerror; + short inclnerror, inclnwarn; internstr inclguard; uchar chrbuf[1<<10]; uint chridxbuf[1<<10]; @@ -1111,7 +1111,7 @@ fatal(const struct span *span, const char *fmt, ...) exit(1); } -int nerror; +int nerror, nwarn; enum { MAXERROR = 20 }; void @@ -1136,9 +1136,14 @@ warn(const struct span *span, const char *fmt, ...) if (ccopt.wnone) return; if (ccopt.werror) ++nerror; + else ++nwarn; va_start(ap, fmt); vdiag(span, ccopt.werror ? DGERROR : DGWARN, fmt, ap); va_end(ap); + if (nerror > MAXERROR) { + efmt("Too many errors emitted, stopping now.\n"); + exit(1); + } } void |