Module Name: src Committed By: rillig Date: Wed Jan 4 05:08:23 UTC 2023
Modified Files: src/tests/usr.bin/xlint/lint1: op_colon.c src/usr.bin/xlint/lint1: tree.c Log Message: lint: fix the result type of '?:' for void pointers The change from 2015-07-29 was wrong since that rule only applies to null pointer constants but not to other void pointers. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/op_colon.c cvs rdiff -u -r1.485 -r1.486 src/usr.bin/xlint/lint1/tree.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/op_colon.c diff -u src/tests/usr.bin/xlint/lint1/op_colon.c:1.4 src/tests/usr.bin/xlint/lint1/op_colon.c:1.5 --- src/tests/usr.bin/xlint/lint1/op_colon.c:1.4 Tue Jan 3 22:02:20 2023 +++ src/tests/usr.bin/xlint/lint1/op_colon.c Wed Jan 4 05:08:22 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: op_colon.c,v 1.4 2023/01/03 22:02:20 rillig Exp $ */ +/* $NetBSD: op_colon.c,v 1.5 2023/01/04 05:08:22 rillig Exp $ */ # 3 "op_colon.c" /* @@ -7,12 +7,12 @@ /* lint1-extra-flags: -p */ -struct unknown { +struct canary { int member; }; void -sink(struct unknown *); +sink(struct canary); void test_merge_qualifiers(_Bool cond, int *p, const int *c, volatile int *v, @@ -66,10 +66,8 @@ c99_6_5_15_p8( const char *c_cp ) { - /* FIXME: expect+2: ... 'pointer to const void' ... */ - /* FIXME: expect+2: ... 'pointer to const void' ... */ - /* expect+2: ... 'pointer to const int' ... */ - /* expect+2: ... 'pointer to const int' ... */ + /* expect+2: ... 'pointer to const void' ... */ + /* expect+2: ... 'pointer to const void' ... */ sink(cond ? c_vp : c_ip); sink(cond ? c_ip : c_vp); @@ -83,10 +81,8 @@ c99_6_5_15_p8( sink(cond ? c_ip : v_ip); sink(cond ? v_ip : c_ip); - /* FIXME: expect+2: ... 'pointer to const void' ... */ - /* FIXME: expect+2: ... 'pointer to const void' ... */ - /* expect+2: ... 'pointer to const char' ... */ - /* expect+2: ... 'pointer to const char' ... */ + /* expect+2: ... 'pointer to const void' ... */ + /* expect+2: ... 'pointer to const void' ... */ sink(cond ? vp : c_cp); sink(cond ? c_cp : vp); @@ -95,10 +91,8 @@ c99_6_5_15_p8( sink(cond ? ip : c_ip); sink(cond ? c_ip : ip); - /* FIXME: expect+2: ... 'pointer to void' ... */ - /* FIXME: expect+2: ... 'pointer to void' ... */ - /* expect+2: ... 'pointer to int' ... */ - /* expect+2: ... 'pointer to int' ... */ + /* expect+2: ... 'pointer to void' ... */ + /* expect+2: ... 'pointer to void' ... */ sink(cond ? vp : ip); sink(cond ? ip : vp); } Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.485 src/usr.bin/xlint/lint1/tree.c:1.486 --- src/usr.bin/xlint/lint1/tree.c:1.485 Tue Jan 3 21:14:14 2023 +++ src/usr.bin/xlint/lint1/tree.c Wed Jan 4 05:08:22 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.485 2023/01/03 21:14:14 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.486 2023/01/04 05:08:22 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.485 2023/01/03 21:14:14 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.486 2023/01/04 05:08:22 rillig Exp $"); #endif #include <float.h> @@ -3303,11 +3303,8 @@ build_colon(bool sys, tnode_t *ln, tnode lt = ln->tn_type->t_tspec; rt = rn->tn_type->t_tspec; - /* - * Arithmetic types are balanced, all other type combinations - * still need to be handled. - */ if (is_arithmetic(lt) && is_arithmetic(rt)) { + /* The operands were already balanced in build_binary. */ tp = ln->tn_type; } else if (lt == BOOL && rt == BOOL) { tp = ln->tn_type; @@ -3331,10 +3328,14 @@ build_colon(bool sys, tnode_t *ln, tnode if (lt != PTRDIFF_TSPEC) ln = convert(NOOP, 0, gettyp(PTRDIFF_TSPEC), ln); tp = rn->tn_type; - } else if (lt == PTR && ln->tn_type->t_subt->t_tspec == VOID) { + } else if (lt == PTR && is_null_pointer(rn)) { + tp = merge_qualifiers(ln->tn_type, rn->tn_type); + } else if (rt == PTR && is_null_pointer(ln)) { tp = merge_qualifiers(rn->tn_type, ln->tn_type); - } else if (rt == PTR && rn->tn_type->t_subt->t_tspec == VOID) { + } else if (lt == PTR && ln->tn_type->t_subt->t_tspec == VOID) { tp = merge_qualifiers(ln->tn_type, rn->tn_type); + } else if (rt == PTR && rn->tn_type->t_subt->t_tspec == VOID) { + tp = merge_qualifiers(rn->tn_type, ln->tn_type); } else { /* * XXX For now we simply take the left type. This is