lint: fix assertion failure on duplicate qualifiers from __typeof__

This commit is contained in:
rillig 2022-04-10 12:14:10 +00:00
parent ae26e95f81
commit 508315abb6
4 changed files with 22 additions and 9 deletions

View File

@ -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" # 3 "gcc_typeof.c"
/* /*
@ -31,3 +31,13 @@ cast(double(*fn)(double))
/* identity cast */ /* identity cast */
take_function_double_returning_double((double (*)(double))fn); 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;

View File

@ -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. * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@ -35,7 +35,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint) #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 #endif
#include <limits.h> #include <limits.h>
@ -878,7 +878,8 @@ notype_type_specifier: /* see C99 6.7.2 */
$$ = gettyp($1); $$ = gettyp($1);
} }
| T_TYPEOF T_LPAREN expression T_RPAREN { /* GCC extension */ | 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 { | struct_or_union_specifier {
end_declaration_level(); end_declaration_level();

View File

@ -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. * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@ -38,7 +38,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint) #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 #endif
#include <sys/param.h> #include <sys/param.h>
@ -815,12 +815,13 @@ end_type(void)
dcs_adjust_storage_class(); 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); lint_assert(dcs->d_type->t_typedef);
/* typedef already qualified with '%s' */ /* typedef already qualified with '%s' */
warning(68, "const"); 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); lint_assert(dcs->d_type->t_typedef);
/* typedef already qualified with '%s' */ /* typedef already qualified with '%s' */
warning(68, "volatile"); warning(68, "volatile");

View File

@ -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. * 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_proto:1; /* function prototype (t_args valid) */
bool t_vararg:1; /* prototype with '...' */ bool t_vararg:1; /* prototype with '...' */
bool t_typedef:1; /* type defined with typedef */ bool t_typedef:1; /* type defined with typedef */
bool t_typeof:1; /* type defined with GCC's __typeof__ */
bool t_bitfield:1; bool t_bitfield:1;
/* /*
* Either the type is currently an enum (having t_tspec ENUM), or * Either the type is currently an enum (having t_tspec ENUM), or