diff options
author | Chad Loder <cloder@cvs.openbsd.org> | 2005-12-09 03:13:09 +0000 |
---|---|---|
committer | Chad Loder <cloder@cvs.openbsd.org> | 2005-12-09 03:13:09 +0000 |
commit | fcfc4619f43f2a8a510568741bbb756fd53314bd (patch) | |
tree | c36798489b8f59d9d330123c7a3bcf99cb148d99 | |
parent | c0ea7c6295aadb2855f44c100b134f0657ce9640 (diff) |
Don't ever complain when assigning a char literal to a char lvalue,
regardless of sign/unsign differences. In other words, even though C
treats char literals as ints, if the rvalue is a literal inside single
quotes, and the lvalue is any kind of char, then assume the programmer
knows what he is doing.
-rw-r--r-- | usr.bin/xlint/lint1/lint1.h | 3 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/scan.l | 7 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/tree.c | 23 |
3 files changed, 25 insertions, 8 deletions
diff --git a/usr.bin/xlint/lint1/lint1.h b/usr.bin/xlint/lint1/lint1.h index dcce2425c0d..b752cb41938 100644 --- a/usr.bin/xlint/lint1/lint1.h +++ b/usr.bin/xlint/lint1/lint1.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lint1.h,v 1.8 2005/12/07 01:55:12 cloder Exp $ */ +/* $OpenBSD: lint1.h,v 1.9 2005/12/09 03:13:08 cloder Exp $ */ /* $NetBSD: lint1.h,v 1.6 1995/10/02 17:31:41 jpo Exp $ */ /* @@ -89,6 +89,7 @@ typedef struct attrnode { */ typedef struct { tspec_t v_tspec; + tspec_t v_lspec; /* the underlying type of a literal */ int v_ansiu; /* set if an integer constant is unsigned in ANSI C */ union { diff --git a/usr.bin/xlint/lint1/scan.l b/usr.bin/xlint/lint1/scan.l index 7bc59f7b37e..c154c8cc321 100644 --- a/usr.bin/xlint/lint1/scan.l +++ b/usr.bin/xlint/lint1/scan.l @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: scan.l,v 1.21 2005/12/07 01:55:12 cloder Exp $ */ +/* $OpenBSD: scan.l,v 1.22 2005/12/09 03:13:08 cloder Exp $ */ /* $NetBSD: scan.l,v 1.8 1995/10/23 13:38:51 jpo Exp $ */ /* @@ -34,7 +34,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: scan.l,v 1.21 2005/12/07 01:55:12 cloder Exp $"; +static char rcsid[] = "$OpenBSD: scan.l,v 1.22 2005/12/09 03:13:08 cloder Exp $"; #endif #include <stdlib.h> @@ -688,7 +688,7 @@ operator(int t, op_t o) } /* - * Called if lex found a leading \'. + * Called if lex found a leading '. */ static int ccon(void) @@ -724,6 +724,7 @@ ccon(void) yylval.y_val = xcalloc(1, sizeof (val_t)); yylval.y_val->v_tspec = INT; + yylval.y_val->v_lspec = CHAR; yylval.y_val->v_quad = val; return (T_CON); diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c index a1f4893d1d5..67dfdebc1c0 100644 --- a/usr.bin/xlint/lint1/tree.c +++ b/usr.bin/xlint/lint1/tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tree.c,v 1.18 2005/11/29 19:50:33 cloder Exp $ */ +/* $OpenBSD: tree.c,v 1.19 2005/12/09 03:13:08 cloder Exp $ */ /* $NetBSD: tree.c,v 1.12 1995/10/02 17:37:57 jpo Exp $ */ /* @@ -33,7 +33,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: tree.c,v 1.18 2005/11/29 19:50:33 cloder Exp $"; +static char rcsid[] = "$OpenBSD: tree.c,v 1.19 2005/12/09 03:13:08 cloder Exp $"; #endif #include <stdlib.h> @@ -256,6 +256,7 @@ getcnode(type_t *tp, val_t *v) n->tn_type = tp; n->tn_val = tgetblk(sizeof (val_t)); n->tn_val->v_tspec = tp->t_tspec; + n->tn_val->v_lspec = v->v_lspec; n->tn_val->v_ansiu = v->v_ansiu; n->tn_val->v_u = v->v_u; free(v); @@ -2017,7 +2018,14 @@ cvtcon(op_t op, int arg, type_t *tp, val_t *nv, val_t *v) * i = c; ** yields -128 ** * i = (unsigned char)c; ** yields 128 ** */ - if (op == ASSIGN && tp->t_isfield) { + if ((nt == CHAR || nt == UCHAR || nt == SCHAR) && + v->v_lspec == CHAR) { + /* + * Don't warn when assigning a character + * literal to any kind of character (signed, + * unsigned, or unspecified). + */ + } else if (op == ASSIGN && tp->t_isfield) { /* precision lost in bit-field assignment */ warning(166); } else if (op == ASSIGN) { @@ -2041,7 +2049,14 @@ cvtcon(op_t op, int arg, type_t *tp, val_t *nv, val_t *v) warning(119, tyname(gettyp(ot)), tyname(tp)); } } else if (nv->v_quad != v->v_quad) { - if (op == ASSIGN && tp->t_isfield) { + if ((nt == CHAR || nt == UCHAR || nt == SCHAR) && + v->v_lspec == CHAR) { + /* + * Don't warn when assigning a character + * literal to any kind of character (signed, + * unsigned, or unspecified). + */ + } else if (op == ASSIGN && tp->t_isfield) { /* precision lost in bit-field assignment */ warning(166); } else if (op == INIT && tp->t_isfield) { |