From 5827a84bf2874531fd15716aa9686e18ce16f54d Mon Sep 17 00:00:00 2001 From: rillig Date: Sat, 2 Jan 2021 17:17:00 +0000 Subject: [PATCH] lint: fix message 308 "Invalid type for _Complex" Previously, lint aborted since it didn't expect tspec_name to be called with NOTSPEC, which at that point was the only possible value of dcs->d_cmod. --- tests/usr.bin/xlint/lint1/msg_035.c | 4 ++-- tests/usr.bin/xlint/lint1/msg_035.exp | 2 ++ tests/usr.bin/xlint/lint1/msg_308.c | 11 ++++------- tests/usr.bin/xlint/lint1/msg_308.exp | 4 +++- usr.bin/xlint/lint1/decl.c | 12 +++++++----- usr.bin/xlint/lint1/err.c | 6 +++--- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/tests/usr.bin/xlint/lint1/msg_035.c b/tests/usr.bin/xlint/lint1/msg_035.c index ae302b18dfe1..4c7271b3cea1 100644 --- a/tests/usr.bin/xlint/lint1/msg_035.c +++ b/tests/usr.bin/xlint/lint1/msg_035.c @@ -1,4 +1,4 @@ -/* $NetBSD: msg_035.c,v 1.4 2021/01/02 16:33:39 rillig Exp $ */ +/* $NetBSD: msg_035.c,v 1.5 2021/01/02 17:17:00 rillig Exp $ */ # 3 "msg_035.c" // Test for message: illegal bit-field type [35] @@ -54,7 +54,7 @@ struct example { void *pointer_flag: 1; unsigned int array_flag[4]: 1; example_function function_flag: 1; -// FIXME: aborts: _Complex complex_flag: 1; + _Complex complex_flag: 1; float _Complex float_complex_flag: 1; double _Complex double_complex_flag: 1; long double _Complex long_double_complex_flag: 1; diff --git a/tests/usr.bin/xlint/lint1/msg_035.exp b/tests/usr.bin/xlint/lint1/msg_035.exp index 4ff566fa7b1d..cfdfc4b69d6a 100644 --- a/tests/usr.bin/xlint/lint1/msg_035.exp +++ b/tests/usr.bin/xlint/lint1/msg_035.exp @@ -12,6 +12,8 @@ msg_035.c(52): warning: illegal bit-field type [35] msg_035.c(54): warning: illegal bit-field type [35] msg_035.c(55): warning: illegal bit-field type [35] msg_035.c(56): warning: illegal bit-field type [35] +msg_035.c(57): Invalid type for _Complex [308] +msg_035.c(57): warning: illegal bit-field type [35] msg_035.c(58): warning: illegal bit-field type [35] msg_035.c(59): warning: illegal bit-field type [35] msg_035.c(60): warning: illegal bit-field type [35] diff --git a/tests/usr.bin/xlint/lint1/msg_308.c b/tests/usr.bin/xlint/lint1/msg_308.c index 674756ccbf61..09b7a79bbb4d 100644 --- a/tests/usr.bin/xlint/lint1/msg_308.c +++ b/tests/usr.bin/xlint/lint1/msg_308.c @@ -1,13 +1,10 @@ -/* $NetBSD: msg_308.c,v 1.2 2021/01/02 16:55:45 rillig Exp $ */ +/* $NetBSD: msg_308.c,v 1.3 2021/01/02 17:17:00 rillig Exp $ */ # 3 "msg_308.c" -// Test for message: Invalid type %s for _Complex [308] +// Test for message: Invalid type for _Complex [308] float _Complex float_complex; double _Complex double_complex; long double _Complex long_double_complex; -// FIXME: aborts: _Complex plain_complex; -// FIXME: aborts: int _Complex int_complex; - -TODO: "Add example code that triggers the above message." -TODO: "Add example code that almost triggers the above message." +_Complex plain_complex; +int _Complex int_complex; diff --git a/tests/usr.bin/xlint/lint1/msg_308.exp b/tests/usr.bin/xlint/lint1/msg_308.exp index 80d5a274183f..44cdec4df5b9 100644 --- a/tests/usr.bin/xlint/lint1/msg_308.exp +++ b/tests/usr.bin/xlint/lint1/msg_308.exp @@ -1 +1,3 @@ -msg_308.c(12): syntax error ':' [249] +msg_308.c(9): Invalid type for _Complex [308] +msg_308.c(10): Invalid type for _Complex [308] +msg_308.c(10): illegal type combination [4] diff --git a/usr.bin/xlint/lint1/decl.c b/usr.bin/xlint/lint1/decl.c index 6ed9c26455f5..f46e30f0cc76 100644 --- a/usr.bin/xlint/lint1/decl.c +++ b/usr.bin/xlint/lint1/decl.c @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.99 2021/01/02 16:33:39 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.100 2021/01/02 17:17:00 rillig 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.99 2021/01/02 16:33:39 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.100 2021/01/02 17:17:00 rillig Exp $"); #endif #include @@ -303,9 +303,11 @@ add_type(type_t *tp) t = FCOMPLEX; else if (dcs->d_cmod == DOUBLE) t = DCOMPLEX; - else - /* Invalid type %s for _Complex */ - error(308, tspec_name(dcs->d_cmod)); + else { + /* Invalid type for _Complex */ + error(308); + t = DCOMPLEX; /* just as a fallback */ + } dcs->d_cmod = NOTSPEC; } diff --git a/usr.bin/xlint/lint1/err.c b/usr.bin/xlint/lint1/err.c index 03346b1eded7..823f108c584e 100644 --- a/usr.bin/xlint/lint1/err.c +++ b/usr.bin/xlint/lint1/err.c @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.59 2020/12/30 01:33:30 rillig Exp $ */ +/* $NetBSD: err.c,v 1.60 2021/01/02 17:17:00 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: err.c,v 1.59 2020/12/30 01:33:30 rillig Exp $"); +__RCSID("$NetBSD: err.c,v 1.60 2021/01/02 17:17:00 rillig Exp $"); #endif #include @@ -367,7 +367,7 @@ const char *msgs[] = { "ANSI C forbids conversion of %s to %s, op %s", /* 305 */ "constant truncated by conversion, op %s", /* 306 */ "static variable %s set but not used", /* 307 */ - "Invalid type %s for _Complex", /* 308 */ + "Invalid type for _Complex", /* 308 */ "extra bits set to 0 in conversion of '%s' to '%s', op %s", /* 309 */ "symbol renaming can't be used on function arguments", /* 310 */ "symbol renaming can't be used on automatic variables", /* 311 */