Module Name: src Committed By: rillig Date: Thu Jul 13 23:27:20 UTC 2023
Modified Files: src/usr.bin/xlint/lint1: debug.c decl.c lint1.h Log Message: lint: merge duplicate code for checking duplicate type qualifiers To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.354 -r1.355 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.191 -r1.192 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/usr.bin/xlint/lint1/debug.c diff -u src/usr.bin/xlint/lint1/debug.c:1.54 src/usr.bin/xlint/lint1/debug.c:1.55 --- src/usr.bin/xlint/lint1/debug.c:1.54 Thu Jul 13 23:11:11 2023 +++ src/usr.bin/xlint/lint1/debug.c Thu Jul 13 23:27:20 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.54 2023/07/13 23:11:11 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.55 2023/07/13 23:27:20 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: debug.c,v 1.54 2023/07/13 23:11:11 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.55 2023/07/13 23:27:20 rillig Exp $"); #endif #include <stdlib.h> @@ -432,8 +432,10 @@ debug_decl_level(const decl_level *dl) if (dl->d_sou_align_in_bits != 0) debug_printf(" align=%u", dl->d_sou_align_in_bits); - debug_word(dl->d_const, "const"); - debug_word(dl->d_volatile, "volatile"); + debug_word(dl->d_qual.tq_const, "const"); + debug_word(dl->d_qual.tq_restrict, "restrict"); + debug_word(dl->d_qual.tq_volatile, "volatile"); + debug_word(dl->d_qual.tq_atomic, "atomic"); debug_word(dl->d_inline, "inline"); debug_word(dl->d_multiple_storage_classes, "multiple_storage_classes"); debug_word(dl->d_invalid_type_combination, "invalid_type_combination"); Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.354 src/usr.bin/xlint/lint1/decl.c:1.355 --- src/usr.bin/xlint/lint1/decl.c:1.354 Thu Jul 13 23:11:11 2023 +++ src/usr.bin/xlint/lint1/decl.c Thu Jul 13 23:27:20 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.354 2023/07/13 23:11:11 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.355 2023/07/13 23:27:20 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: decl.c,v 1.354 2023/07/13 23:11:11 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.355 2023/07/13 23:27:20 rillig Exp $"); #endif #include <sys/param.h> @@ -501,21 +501,7 @@ dcs_set_used(void) void dcs_add_qualifiers(type_qualifiers qs) { - - if (qs.tq_const) { - if (dcs->d_const) { - /* duplicate '%s' */ - warning(10, "const"); - } - dcs->d_const = true; - } - if (qs.tq_volatile) { - if (dcs->d_volatile) { - /* duplicate '%s' */ - warning(10, "volatile"); - } - dcs->d_volatile = true; - } + add_type_qualifiers(&dcs->d_qual, qs); } void @@ -628,8 +614,7 @@ dcs_begin_type(void) dcs->d_rank_mod = NO_TSPEC; dcs->d_scl = NOSCL; dcs->d_type = NULL; - dcs->d_const = false; - dcs->d_volatile = false; + dcs->d_qual = (type_qualifiers) { .tq_const = false }; dcs->d_inline = false; dcs->d_multiple_storage_classes = false; dcs->d_invalid_type_combination = false; @@ -740,22 +725,23 @@ dcs_end_type(void) dcs_adjust_storage_class(); - if (dcs->d_const && dcs->d_type->t_const && !dcs->d_type->t_typeof) { + if (dcs->d_qual.tq_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_qual.tq_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"); } - if (dcs->d_const || dcs->d_volatile) { + if (dcs->d_qual.tq_const || dcs->d_qual.tq_volatile) { dcs->d_type = block_dup_type(dcs->d_type); - dcs->d_type->t_const |= dcs->d_const; - dcs->d_type->t_volatile |= dcs->d_volatile; + dcs->d_type->t_const |= dcs->d_qual.tq_const; + dcs->d_type->t_volatile |= dcs->d_qual.tq_volatile; } } @@ -1172,10 +1158,6 @@ qual_ptr * append_qualified_pointer(qual_ptr *p1, qual_ptr *p2) { - if (p2 == NULL) - return p1; - - /* append p1 to p2, keeping p2 */ qual_ptr *tail = p2; while (tail->p_next != NULL) tail = tail->p_next; Index: src/usr.bin/xlint/lint1/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.191 src/usr.bin/xlint/lint1/lint1.h:1.192 --- src/usr.bin/xlint/lint1/lint1.h:1.191 Thu Jul 13 23:11:11 2023 +++ src/usr.bin/xlint/lint1/lint1.h Thu Jul 13 23:27:20 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.191 2023/07/13 23:11:11 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.192 2023/07/13 23:27:20 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -363,8 +363,7 @@ typedef struct decl_level { * trailing padding */ unsigned int d_sou_align_in_bits; /* alignment of the structure * or union being built */ - bool d_const:1; /* const in declaration specifiers */ - bool d_volatile:1; /* volatile in declaration specifiers */ + type_qualifiers d_qual; /* in declaration specifiers */ bool d_inline:1; /* inline in declaration specifiers */ bool d_multiple_storage_classes:1; /* reported in dcs_end_type */ bool d_invalid_type_combination:1;