Module Name: src Committed By: rillig Date: Sun Apr 10 12:14:10 UTC 2022
Modified Files: src/tests/usr.bin/xlint/lint1: gcc_typeof.c src/usr.bin/xlint/lint1: cgram.y decl.c lint1.h Log Message: lint: fix assertion failure on duplicate qualifiers from __typeof__ To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/gcc_typeof.c cvs rdiff -u -r1.393 -r1.394 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.276 -r1.277 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.150 -r1.151 src/usr.bin/xlint/lint1/lint1.h 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/gcc_typeof.c diff -u src/tests/usr.bin/xlint/lint1/gcc_typeof.c:1.3 src/tests/usr.bin/xlint/lint1/gcc_typeof.c:1.4 --- src/tests/usr.bin/xlint/lint1/gcc_typeof.c:1.3 Sun Jul 25 15:58:24 2021 +++ src/tests/usr.bin/xlint/lint1/gcc_typeof.c Sun Apr 10 12:14:10 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: gcc_typeof.c,v 1.3 2021/07/25 15:58:24 rillig Exp $ */ +/* $NetBSD: gcc_typeof.c,v 1.4 2022/04/10 12:14:10 rillig Exp $ */ # 3 "gcc_typeof.c" /* @@ -31,3 +31,13 @@ cast(double(*fn)(double)) /* identity cast */ take_function_double_returning_double((double (*)(double))fn); } + +/* + * Since cgram 1.58 from 2014-02-18, when support for __typeof__ was added, + * and before cgram.y 1.394 from 2022-04-10, lint ran into an assertion + * failure when encountering a redundant type qualifier 'const' or 'volatile' + * in a declaration using __typeof__. Seen in sys/sys/lwp.h on x86_64, in + * the call atomic_load_consume(&l->l_mutex). + */ +int *volatile lock; +const volatile __typeof__(lock) *lock_pointer = &lock; Index: src/usr.bin/xlint/lint1/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.393 src/usr.bin/xlint/lint1/cgram.y:1.394 --- src/usr.bin/xlint/lint1/cgram.y:1.393 Sat Apr 9 23:41:22 2022 +++ src/usr.bin/xlint/lint1/cgram.y Sun Apr 10 12:14:10 2022 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.393 2022/04/09 23:41:22 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.394 2022/04/10 12:14:10 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.y,v 1.393 2022/04/09 23:41:22 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.394 2022/04/10 12:14:10 rillig Exp $"); #endif #include <limits.h> @@ -878,7 +878,8 @@ notype_type_specifier: /* see C99 6.7.2 $$ = gettyp($1); } | T_TYPEOF T_LPAREN expression T_RPAREN { /* GCC extension */ - $$ = $3->tn_type; + $$ = block_dup_type($3->tn_type); + $$->t_typeof = true; } | struct_or_union_specifier { end_declaration_level(); Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.276 src/usr.bin/xlint/lint1/decl.c:1.277 --- src/usr.bin/xlint/lint1/decl.c:1.276 Sat Apr 9 23:41:22 2022 +++ src/usr.bin/xlint/lint1/decl.c Sun Apr 10 12:14:10 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.276 2022/04/09 23:41:22 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.277 2022/04/10 12:14:10 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: decl.c,v 1.276 2022/04/09 23:41:22 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.277 2022/04/10 12:14:10 rillig Exp $"); #endif #include <sys/param.h> @@ -815,12 +815,13 @@ end_type(void) dcs_adjust_storage_class(); - if (dcs->d_const && dcs->d_type->t_const) { + if (dcs->d_const && dcs->d_type->t_const && !dcs->d_type->t_typeof) { lint_assert(dcs->d_type->t_typedef); /* typedef already qualified with '%s' */ warning(68, "const"); } - if (dcs->d_volatile && dcs->d_type->t_volatile) { + if (dcs->d_volatile && dcs->d_type->t_volatile && + !dcs->d_type->t_typeof) { lint_assert(dcs->d_type->t_typedef); /* typedef already qualified with '%s' */ warning(68, "volatile"); Index: src/usr.bin/xlint/lint1/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.150 src/usr.bin/xlint/lint1/lint1.h:1.151 --- src/usr.bin/xlint/lint1/lint1.h:1.150 Sat Apr 9 23:41:22 2022 +++ src/usr.bin/xlint/lint1/lint1.h Sun Apr 10 12:14:10 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.150 2022/04/09 23:41:22 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.151 2022/04/10 12:14:10 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -143,6 +143,7 @@ struct lint1_type { bool t_proto:1; /* function prototype (t_args valid) */ bool t_vararg:1; /* prototype with '...' */ bool t_typedef:1; /* type defined with typedef */ + bool t_typeof:1; /* type defined with GCC's __typeof__ */ bool t_bitfield:1; /* * Either the type is currently an enum (having t_tspec ENUM), or