From 7c8a9296cc4a42e4f5b07f910d803eb3e801b5b8 Mon Sep 17 00:00:00 2001 From: christos Date: Mon, 2 Mar 2009 20:53:10 +0000 Subject: [PATCH] Don't produce type mismatch warnings if one side of ?: is "[qual] void *" and the other side is "[qual] pointer". --- usr.bin/xlint/lint1/decl.c | 36 +++++++++++++++++++++++++++------- usr.bin/xlint/lint1/externs1.h | 3 ++- usr.bin/xlint/lint1/tree.c | 6 ++++-- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/usr.bin/xlint/lint1/decl.c b/usr.bin/xlint/lint1/decl.c index 2b1caaaaada6..25d36727af4b 100644 --- a/usr.bin/xlint/lint1/decl.c +++ b/usr.bin/xlint/lint1/decl.c @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.44 2008/11/16 07:06:37 dholland Exp $ */ +/* $NetBSD: decl.c,v 1.45 2009/03/02 20:53:10 christos Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: decl.c,v 1.44 2008/11/16 07:06:37 dholland Exp $"); +__RCSID("$NetBSD: decl.c,v 1.45 2009/03/02 20:53:10 christos Exp $"); #endif #include @@ -1994,6 +1994,31 @@ isredec(sym_t *dsym, int *dowarn) return (0); } +static int +chkqual(type_t *tp1, type_t *tp2, int ignqual) +{ + if (tp1->t_const != tp2->t_const && !ignqual && !tflag) + return 0; + + if (tp1->t_volatile != tp2->t_volatile && !ignqual && !tflag) + return 0; + + return 1; +} + +int +eqptrtype(type_t *tp1, type_t *tp2, int ignqual) +{ + if (tp1->t_tspec != VOID && tp2->t_tspec != VOID) + return 0; + + if (!chkqual(tp1, tp2, ignqual)) + return 0; + + return 1; +} + + /* * Checks if two types are compatible. Returns 0 if not, otherwise 1. * @@ -2029,11 +2054,8 @@ eqtype(type_t *tp1, type_t *tp2, int ignqual, int promot, int *dowarn) if (t != tp2->t_tspec) return (0); - if (tp1->t_const != tp2->t_const && !ignqual && !tflag) - return (0); - - if (tp1->t_volatile != tp2->t_volatile && !ignqual && !tflag) - return (0); + if (!chkqual(tp1, tp2, ignqual)) + return 0; if (t == STRUCT || t == UNION) return (tp1->t_str == tp2->t_str); diff --git a/usr.bin/xlint/lint1/externs1.h b/usr.bin/xlint/lint1/externs1.h index 03ee97589a7b..e422d1cd249d 100644 --- a/usr.bin/xlint/lint1/externs1.h +++ b/usr.bin/xlint/lint1/externs1.h @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.24 2008/11/16 07:06:37 dholland Exp $ */ +/* $NetBSD: externs1.h,v 1.25 2009/03/02 20:53:10 christos Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -166,6 +166,7 @@ extern sym_t *ename(sym_t *, int, int); extern void decl1ext(sym_t *, int); extern void cpuinfo(sym_t *, sym_t *); extern int isredec(sym_t *, int *); +extern int eqptrtype(type_t *, type_t *, int); extern int eqtype(type_t *, type_t *, int, int, int *); extern void compltyp(sym_t *, sym_t *); extern sym_t *decl1arg(sym_t *, int); diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c index 043f283c703f..93a1a9b94cc3 100644 --- a/usr.bin/xlint/lint1/tree.c +++ b/usr.bin/xlint/lint1/tree.c @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.54 2008/11/16 07:06:37 dholland Exp $ */ +/* $NetBSD: tree.c,v 1.55 2009/03/02 20:53:11 christos Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: tree.c,v 1.54 2008/11/16 07:06:37 dholland Exp $"); +__RCSID("$NetBSD: tree.c,v 1.55 2009/03/02 20:53:11 christos Exp $"); #endif #include @@ -1105,6 +1105,8 @@ typeok(op_t op, int arg, tnode_t *ln, tnode_t *rn) } if (rt == PTR && lt == PTR) { + if (eqptrtype(lstp, rstp, 1)) + break; if (!eqtype(lstp, rstp, 1, 0, NULL)) illptrc(mp, ltp, rtp); break;