| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: decl.c,v 1.207 2021/07/15 23:54:22 rillig Exp $ */ | | 1 | /* $NetBSD: decl.c,v 1.208 2021/07/23 16:43:11 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. | | 4 | * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. |
5 | * Copyright (c) 1994, 1995 Jochen Pohl | | 5 | * Copyright (c) 1994, 1995 Jochen Pohl |
6 | * All Rights Reserved. | | 6 | * All Rights Reserved. |
7 | * | | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | | 8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | | 9 | * modification, are permitted provided that the following conditions |
10 | * are met: | | 10 | * are met: |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
| @@ -28,53 +28,53 @@ | | | @@ -28,53 +28,53 @@ |
28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | */ | | 33 | */ |
34 | | | 34 | |
35 | #if HAVE_NBTOOL_CONFIG_H | | 35 | #if HAVE_NBTOOL_CONFIG_H |
36 | #include "nbtool_config.h" | | 36 | #include "nbtool_config.h" |
37 | #endif | | 37 | #endif |
38 | | | 38 | |
39 | #include <sys/cdefs.h> | | 39 | #include <sys/cdefs.h> |
40 | #if defined(__RCSID) && !defined(lint) | | 40 | #if defined(__RCSID) && !defined(lint) |
41 | __RCSID("$NetBSD: decl.c,v 1.207 2021/07/15 23:54:22 rillig Exp $"); | | 41 | __RCSID("$NetBSD: decl.c,v 1.208 2021/07/23 16:43:11 rillig Exp $"); |
42 | #endif | | 42 | #endif |
43 | | | 43 | |
44 | #include <sys/param.h> | | 44 | #include <sys/param.h> |
45 | #include <limits.h> | | 45 | #include <limits.h> |
46 | #include <stdlib.h> | | 46 | #include <stdlib.h> |
47 | #include <string.h> | | 47 | #include <string.h> |
48 | | | 48 | |
49 | #include "lint1.h" | | 49 | #include "lint1.h" |
50 | | | 50 | |
51 | const char *unnamed = "<unnamed>"; | | 51 | const char *unnamed = "<unnamed>"; |
52 | | | 52 | |
53 | /* shared type structures for arithmetic types and void */ | | 53 | /* shared type structures for arithmetic types and void */ |
54 | static type_t *typetab; | | 54 | static type_t *typetab; |
55 | | | 55 | |
56 | /* value of next enumerator during declaration of enum types */ | | 56 | /* value of next enumerator during declaration of enum types */ |
57 | int enumval; | | 57 | int enumval; |
58 | | | 58 | |
59 | /* | | 59 | /* |
60 | * pointer to top element of a stack which contains information local | | 60 | * pointer to top element of a stack which contains information local |
61 | * to nested declarations | | 61 | * to nested declarations |
62 | */ | | 62 | */ |
63 | dinfo_t *dcs; | | 63 | dinfo_t *dcs; |
64 | | | 64 | |
65 | static type_t *tdeferr(type_t *, tspec_t); | | 65 | static type_t *tdeferr(type_t *, tspec_t); |
66 | static void settdsym(type_t *, sym_t *); | | 66 | static void settdsym(type_t *, sym_t *); |
67 | static void align(int, int); | | 67 | static void align(u_int, u_int); |
68 | static sym_t *newtag(sym_t *, scl_t, bool, bool); | | 68 | static sym_t *newtag(sym_t *, scl_t, bool, bool); |
69 | static bool eqargs(const type_t *, const type_t *, bool *); | | 69 | static bool eqargs(const type_t *, const type_t *, bool *); |
70 | static bool mnoarg(const type_t *, bool *); | | 70 | static bool mnoarg(const type_t *, bool *); |
71 | static bool check_old_style_definition(sym_t *, sym_t *); | | 71 | static bool check_old_style_definition(sym_t *, sym_t *); |
72 | static bool check_prototype_declaration(sym_t *, sym_t *); | | 72 | static bool check_prototype_declaration(sym_t *, sym_t *); |
73 | static sym_t *new_style_function(sym_t *, sym_t *); | | 73 | static sym_t *new_style_function(sym_t *, sym_t *); |
74 | static void old_style_function(sym_t *, sym_t *); | | 74 | static void old_style_function(sym_t *, sym_t *); |
75 | static void declare_external_in_block(sym_t *); | | 75 | static void declare_external_in_block(sym_t *); |
76 | static bool check_init(sym_t *); | | 76 | static bool check_init(sym_t *); |
77 | static void check_argument_usage(bool, sym_t *); | | 77 | static void check_argument_usage(bool, sym_t *); |
78 | static void check_variable_usage(bool, sym_t *); | | 78 | static void check_variable_usage(bool, sym_t *); |
79 | static void check_label_usage(sym_t *); | | 79 | static void check_label_usage(sym_t *); |
80 | static void check_tag_usage(sym_t *); | | 80 | static void check_tag_usage(sym_t *); |
| @@ -1144,27 +1144,27 @@ declare_bit_field(sym_t *dsym, tspec_t * | | | @@ -1144,27 +1144,27 @@ declare_bit_field(sym_t *dsym, tspec_t * |
1144 | dsym->s_bitfield = false; | | 1144 | dsym->s_bitfield = false; |
1145 | } | | 1145 | } |
1146 | } | | 1146 | } |
1147 | | | 1147 | |
1148 | /* | | 1148 | /* |
1149 | * Process the declarator of a struct/union element. | | 1149 | * Process the declarator of a struct/union element. |
1150 | */ | | 1150 | */ |
1151 | sym_t * | | 1151 | sym_t * |
1152 | declarator_1_struct_union(sym_t *dsym) | | 1152 | declarator_1_struct_union(sym_t *dsym) |
1153 | { | | 1153 | { |
1154 | type_t *tp; | | 1154 | type_t *tp; |
1155 | tspec_t t; | | 1155 | tspec_t t; |
1156 | int sz; | | 1156 | int sz; |
1157 | int o = 0; /* Appease GCC */ | | 1157 | u_int o = 0; /* Appease GCC */ |
1158 | | | 1158 | |
1159 | lint_assert(dsym->s_scl == MOS || dsym->s_scl == MOU); | | 1159 | lint_assert(dsym->s_scl == MOS || dsym->s_scl == MOU); |
1160 | | | 1160 | |
1161 | if (dcs->d_redeclared_symbol != NULL) { | | 1161 | if (dcs->d_redeclared_symbol != NULL) { |
1162 | /* should be ensured by storesym() */ | | 1162 | /* should be ensured by storesym() */ |
1163 | lint_assert(dcs->d_redeclared_symbol->s_scl == MOS || | | 1163 | lint_assert(dcs->d_redeclared_symbol->s_scl == MOS || |
1164 | dcs->d_redeclared_symbol->s_scl == MOU); | | 1164 | dcs->d_redeclared_symbol->s_scl == MOU); |
1165 | | | 1165 | |
1166 | if (dsym->s_styp == dcs->d_redeclared_symbol->s_styp) { | | 1166 | if (dsym->s_styp == dcs->d_redeclared_symbol->s_styp) { |
1167 | /* duplicate member name: %s */ | | 1167 | /* duplicate member name: %s */ |
1168 | error(33, dsym->s_name); | | 1168 | error(33, dsym->s_name); |
1169 | rmsym(dcs->d_redeclared_symbol); | | 1169 | rmsym(dcs->d_redeclared_symbol); |
1170 | } | | 1170 | } |
| @@ -1221,29 +1221,29 @@ declarator_1_struct_union(sym_t *dsym) | | | @@ -1221,29 +1221,29 @@ declarator_1_struct_union(sym_t *dsym) |
1221 | * structure element. | | 1221 | * structure element. |
1222 | */ | | 1222 | */ |
1223 | bitfieldtype_ok = false; | | 1223 | bitfieldtype_ok = false; |
1224 | | | 1224 | |
1225 | return dsym; | | 1225 | return dsym; |
1226 | } | | 1226 | } |
1227 | | | 1227 | |
1228 | /* | | 1228 | /* |
1229 | * Aligns next structure element as required. | | 1229 | * Aligns next structure element as required. |
1230 | * | | 1230 | * |
1231 | * al contains the required alignment, len the length of a bit-field. | | 1231 | * al contains the required alignment, len the length of a bit-field. |
1232 | */ | | 1232 | */ |
1233 | static void | | 1233 | static void |
1234 | align(int al, int len) | | 1234 | align(u_int al, u_int len) |
1235 | { | | 1235 | { |
1236 | int no; | | 1236 | u_int no; |
1237 | | | 1237 | |
1238 | /* | | 1238 | /* |
1239 | * The alignment of the current element becomes the alignment of | | 1239 | * The alignment of the current element becomes the alignment of |
1240 | * the struct/union if it is larger than the current alignment | | 1240 | * the struct/union if it is larger than the current alignment |
1241 | * of the struct/union. | | 1241 | * of the struct/union. |
1242 | */ | | 1242 | */ |
1243 | if (al > dcs->d_sou_align_in_bits) | | 1243 | if (al > dcs->d_sou_align_in_bits) |
1244 | dcs->d_sou_align_in_bits = al; | | 1244 | dcs->d_sou_align_in_bits = al; |
1245 | | | 1245 | |
1246 | no = (dcs->d_offset + (al - 1)) & ~(al - 1); | | 1246 | no = (dcs->d_offset + (al - 1)) & ~(al - 1); |
1247 | if (len == 0 || dcs->d_offset + len > no) | | 1247 | if (len == 0 || dcs->d_offset + len > no) |
1248 | dcs->d_offset = no; | | 1248 | dcs->d_offset = no; |
1249 | } | | 1249 | } |