From cdc076e6adf2e8066872d30535c71e128c5375ca Mon Sep 17 00:00:00 2001 From: lemon Date: Thu, 19 Mar 2026 22:09:22 +0100 Subject: io: make -w suppress notes too --- src/a_main.c | 2 +- src/antcc.h | 2 +- src/c.c | 12 ++++++------ src/c_lex.c | 12 ++++++------ src/u_io.c | 5 +++-- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/a_main.c b/src/a_main.c index 6c313a7..33f0919 100644 --- a/src/a_main.c +++ b/src/a_main.c @@ -466,7 +466,7 @@ dolink(void) findlinkcmd(&cmd); if (!strcmp(cmd.p[0], "zig")) { - note(NULL, "using 'zig cc' as a cross-compiler"); + note(DGNOTE, NULL, "using 'zig cc' as a cross-compiler"); } if (task.outft == OFTdll) { vpush(&cmd, "-shared"); diff --git a/src/antcc.h b/src/antcc.h index 2078cfc..a666a95 100644 --- a/src/antcc.h +++ b/src/antcc.h @@ -360,7 +360,7 @@ void vdiag(const Span *, enum diagkind, const char *, va_list); NORETURN void fatal(const Span *, const char *, ...); void error(const Span *, const char *, ...); void warn(const Span *, const char *, ...); -void note(const Span *, const char *, ...); +void note(enum diagkind src, const Span *, const char *, ...); ushort *utf8to16(uint *ulen, Arena **, const uchar *s, size_t len); uint *utf8to32(uint *ulen, Arena **, const uchar *s, size_t len); int utf8enc(char out[4], uint cp); diff --git a/src/c.c b/src/c.c index e7f902e..fcde10e 100644 --- a/src/c.c +++ b/src/c.c @@ -310,11 +310,11 @@ putdecl(CComp *cm, const Decl *decl) Match: if ((cm->env->up != NULL && decl->scls == SCSTATIC) || (l->isdef && decl->isdef)) { error(&decl->span, "redefinition of '%s'", decl->name); - note(&l->span, "previously defined here"); + note(DGERROR, &l->span, "previously defined here"); break; } else if (!redeclarationok(l, decl)) { error(&decl->span, "incompatible redeclaration of '%s'", decl->name); - note(&l->span, "previously declared here"); + note(DGERROR, &l->span, "previously declared here"); break; } if (l->isdef && !decl->isdef) return l - declsbuf.p; @@ -801,7 +801,7 @@ callexpr(CComp *cm, const Span *span_, const Expr *callee) td->nmemb, td->nmemb != 1 ? "s" : ""); printsig = 1; } - if (printsig) note(&callee->span, "function signature is '%ty'", ty); + if (printsig) note(DGERROR, &callee->span, "function signature is '%ty'", ty); ex = mkexpr(ECALL, span, ty.t == TYFUNC ? td->ret : ty, .narg = args.n, .sub = alloc(&cm->exarena, (args.n+1)*sizeof(Expr), 0)); @@ -2229,7 +2229,7 @@ tagtype(CComp *cm, enum toktag kind) &tk, kind); else error(&tk.span, "redefinition of '%tt %s'", kind, tag); - note(&span, "previous definition:"); + note(DGERROR, &span, "previous definition:"); } } if (tt == TYENUM) @@ -2241,7 +2241,7 @@ tagtype(CComp *cm, enum toktag kind) if (t.t != tt) { error(&tk.span, "declaring tagged type %'tk as %tt clashes with previous definition", &tk, kind); - note(&span, "previous definition:"); + note(DGERROR, &span, "previous definition:"); } return t; } @@ -4021,7 +4021,7 @@ genswitch(CComp *cm, Function *fn, const Expr *ex) assert(c->val >= prev); if (c->val == prev) { error(&c->span, "duplicate case value"); - note(&c[-1].span, "previously defined here"); + note(DGERROR, &c[-1].span, "previously defined here"); } } EMITS { diff --git a/src/c_lex.c b/src/c_lex.c index 43e4b18..1c8dc93 100644 --- a/src/c_lex.c +++ b/src/c_lex.c @@ -695,7 +695,7 @@ putmac(internstr name, Macro *mac) warn(&(Span){mac->span}, "redefining builtin macro"); else { warn(&(Span){mac->span}, "redefining macro"); - note(&(Span){slot->span}, "previous definition:"); + note(DGWARN, &(Span){slot->span}, "previous definition:"); } freemac(slot); *slot = *mac; @@ -757,7 +757,7 @@ lxfatal(Lexer *lx, const Span *span, const char *fmt, ...) int n = lx->macstk ? lx->macstk - mstk : 0, i = 0; for (MacroStack *l = lx->macstk; l && l > mstk; --l, ++i) { if (i < 4 || i > n - 5) { - note(&(Span){l->exspan}, "expanded from here"); + note(DGERROR, &(Span){l->exspan}, "expanded from here"); } else if (i == 5) { efmt(" (...) \n"); } @@ -765,7 +765,7 @@ lxfatal(Lexer *lx, const Span *span, const char *fmt, ...) for (Lexer *sv = lx->save; sv; sv = sv->save) { int line; const char *f = getfilepos(&line, NULL, sv->fileid, sv->chridx-2); - note(NULL, "in file included from %s:%d", f, line); + note(DGERROR, NULL, "in file included from %s:%d", f, line); } if (!fmt || span) efmt("Aborting due to previous error.\n"); exit(1); @@ -829,7 +829,7 @@ tokpaste(Lexer *lx, Token *dst, const Token *l, const Token *r) if (dst) { error(&l->span, "pasting %'tk and %'tk does not form a valid preprocessing token", l, r); - note(&r->span, "right-hand side"); + note(DGERROR, &r->span, "right-hand side"); } return 0; } @@ -1553,7 +1553,7 @@ Switch: vlong m = expr(lx, &xu, 1, ignore || !x); if (elex(lx, &tk) != ':') { error(&tk.span, "expected ':'"); - note(&span, "to match conditional expression here"); + note(DGERROR, &span, "to match conditional expression here"); goto Err; } y = expr(lx, &yu, 1, ignore || x); @@ -2175,7 +2175,7 @@ Begin: 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); + note(DGERROR, NULL, "in file included from %s:%d", f, line); } memcpy(lx, sv, sizeof *lx); free(sv); diff --git a/src/u_io.c b/src/u_io.c index c922846..e331f3e 100644 --- a/src/u_io.c +++ b/src/u_io.c @@ -1111,7 +1111,7 @@ vdiag(const Span *span, enum diagkind kind, const char *fmt, va_list ap) if (span && loc == &span->ex && span->sl.len) if (span->ex.file != span->sl.file || !((uint) span->sl.off - span->ex.off < span->ex.len)) - note(&(Span){ span->sl }, "expanded from here"); + note(kind, &(Span){ span->sl }, "expanded from here"); if (--depth == 0) ioflush(&out); } @@ -1165,10 +1165,11 @@ warn(const Span *span, const char *fmt, ...) } void -note(const Span *span, const char *fmt, ...) +note(enum diagkind src, const Span *span, const char *fmt, ...) { va_list ap; + if (ccopt.wnone && src == DGWARN) return; va_start(ap, fmt); vdiag(span, DGNOTE, fmt, ap); va_end(ap); -- cgit v1.2.3