| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: decl.c,v 1.246 2022/02/27 08:31:26 rillig Exp $ */ | | 1 | /* $NetBSD: decl.c,v 1.247 2022/02/27 10:31:58 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,27 +28,27 @@ | | | @@ -28,27 +28,27 @@ |
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.246 2022/02/27 08:31:26 rillig Exp $"); | | 41 | __RCSID("$NetBSD: decl.c,v 1.247 2022/02/27 10:31:58 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; |
| @@ -149,52 +149,49 @@ scl_name(scl_t scl) | | | @@ -149,52 +149,49 @@ scl_name(scl_t scl) |
149 | "none", "extern", "static", "auto", "register", "typedef", | | 149 | "none", "extern", "static", "auto", "register", "typedef", |
150 | "struct", "union", "enum", "member of struct", "member of union", | | 150 | "struct", "union", "enum", "member of struct", "member of union", |
151 | "compile-time constant", "abstract", | | 151 | "compile-time constant", "abstract", |
152 | "old-style function argument", "prototype argument", "inline" | | 152 | "old-style function argument", "prototype argument", "inline" |
153 | }; | | 153 | }; |
154 | | | 154 | |
155 | return names[scl]; | | 155 | return names[scl]; |
156 | } | | 156 | } |
157 | #endif | | 157 | #endif |
158 | | | 158 | |
159 | /* | | 159 | /* |
160 | * Returns a shared type structure for arithmetic types and void. | | 160 | * Returns a shared type structure for arithmetic types and void. |
161 | * | | 161 | * |
162 | * It's important to duplicate this structure (using dup_type() or | | 162 | * It's important to duplicate this structure using block_dup_type or |
163 | * expr_dup_type()) if it is to be modified (adding qualifiers or anything | | 163 | * expr_dup_type if it is to be modified (adding qualifiers or anything |
164 | * else). | | 164 | * else). |
165 | */ | | 165 | */ |
166 | type_t * | | 166 | type_t * |
167 | gettyp(tspec_t t) | | 167 | gettyp(tspec_t t) |
168 | { | | 168 | { |
169 | | | 169 | |
170 | /* TODO: make the return type 'const' */ | | 170 | /* TODO: make the return type 'const' */ |
171 | return &typetab[t]; | | 171 | return &typetab[t]; |
172 | } | | 172 | } |
173 | | | 173 | |
174 | type_t * | | 174 | type_t * |
175 | dup_type(const type_t *tp) | | 175 | block_dup_type(const type_t *tp) |
176 | { | | 176 | { |
177 | type_t *ntp; | | 177 | type_t *ntp; |
178 | | | 178 | |
179 | ntp = block_zero_alloc(sizeof(*ntp)); | | 179 | ntp = block_zero_alloc(sizeof(*ntp)); |
180 | *ntp = *tp; | | 180 | *ntp = *tp; |
181 | return ntp; | | 181 | return ntp; |
182 | } | | 182 | } |
183 | | | 183 | |
184 | /* | | 184 | /* Duplicate a type, free the allocated memory after the expression. */ |
185 | * Use expr_dup_type() instead of dup_type() inside expressions (if the | | | |
186 | * allocated memory should be freed after the expr). | | | |
187 | */ | | | |
188 | type_t * | | 185 | type_t * |
189 | expr_dup_type(const type_t *tp) | | 186 | expr_dup_type(const type_t *tp) |
190 | { | | 187 | { |
191 | type_t *ntp; | | 188 | type_t *ntp; |
192 | | | 189 | |
193 | ntp = expr_zero_alloc(sizeof(*ntp)); | | 190 | ntp = expr_zero_alloc(sizeof(*ntp)); |
194 | *ntp = *tp; | | 191 | *ntp = *tp; |
195 | return ntp; | | 192 | return ntp; |
196 | } | | 193 | } |
197 | | | 194 | |
198 | /* | | 195 | /* |
199 | * Return the unqualified version of the type. The returned type is freed at | | 196 | * Return the unqualified version of the type. The returned type is freed at |
200 | * the end of the current expression. | | 197 | * the end of the current expression. |
| @@ -441,60 +438,60 @@ merge_signedness(tspec_t t, tspec_t s) | | | @@ -441,60 +438,60 @@ merge_signedness(tspec_t t, tspec_t s) |
441 | static type_t * | | 438 | static type_t * |
442 | tdeferr(type_t *td, tspec_t t) | | 439 | tdeferr(type_t *td, tspec_t t) |
443 | { | | 440 | { |
444 | tspec_t t2; | | 441 | tspec_t t2; |
445 | | | 442 | |
446 | t2 = td->t_tspec; | | 443 | t2 = td->t_tspec; |
447 | | | 444 | |
448 | if ((t == SIGNED || t == UNSIGN) && | | 445 | if ((t == SIGNED || t == UNSIGN) && |
449 | (t2 == CHAR || t2 == SHORT || t2 == INT || | | 446 | (t2 == CHAR || t2 == SHORT || t2 == INT || |
450 | t2 == LONG || t2 == QUAD)) { | | 447 | t2 == LONG || t2 == QUAD)) { |
451 | if (!tflag) | | 448 | if (!tflag) |
452 | /* modifying typedef with '%s'; only qualifiers... */ | | 449 | /* modifying typedef with '%s'; only qualifiers... */ |
453 | warning(5, tspec_name(t)); | | 450 | warning(5, tspec_name(t)); |
454 | td = dup_type(gettyp(merge_signedness(t2, t))); | | 451 | td = block_dup_type(gettyp(merge_signedness(t2, t))); |
455 | td->t_typedef = true; | | 452 | td->t_typedef = true; |
456 | return td; | | 453 | return td; |
457 | } | | 454 | } |
458 | | | 455 | |
459 | if (t == SHORT && (t2 == INT || t2 == UINT)) { | | 456 | if (t == SHORT && (t2 == INT || t2 == UINT)) { |
460 | /* modifying typedef with '%s'; only qualifiers allowed */ | | 457 | /* modifying typedef with '%s'; only qualifiers allowed */ |
461 | warning(5, "short"); | | 458 | warning(5, "short"); |
462 | td = dup_type(gettyp(t2 == INT ? SHORT : USHORT)); | | 459 | td = block_dup_type(gettyp(t2 == INT ? SHORT : USHORT)); |
463 | td->t_typedef = true; | | 460 | td->t_typedef = true; |
464 | return td; | | 461 | return td; |
465 | } | | 462 | } |
466 | | | 463 | |
467 | if (t == LONG && | | 464 | if (t == LONG && |
468 | (t2 == INT || t2 == UINT || t2 == LONG || t2 == ULONG || | | 465 | (t2 == INT || t2 == UINT || t2 == LONG || t2 == ULONG || |
469 | t2 == FLOAT || t2 == DOUBLE || t2 == DCOMPLEX)) { | | 466 | t2 == FLOAT || t2 == DOUBLE || t2 == DCOMPLEX)) { |
470 | /* modifying typedef with '%s'; only qualifiers allowed */ | | 467 | /* modifying typedef with '%s'; only qualifiers allowed */ |
471 | warning(5, "long"); | | 468 | warning(5, "long"); |
472 | if (t2 == INT) { | | 469 | if (t2 == INT) { |
473 | td = gettyp(LONG); | | 470 | td = gettyp(LONG); |
474 | } else if (t2 == UINT) { | | 471 | } else if (t2 == UINT) { |
475 | td = gettyp(ULONG); | | 472 | td = gettyp(ULONG); |
476 | } else if (t2 == LONG) { | | 473 | } else if (t2 == LONG) { |
477 | td = gettyp(QUAD); | | 474 | td = gettyp(QUAD); |
478 | } else if (t2 == ULONG) { | | 475 | } else if (t2 == ULONG) { |
479 | td = gettyp(UQUAD); | | 476 | td = gettyp(UQUAD); |
480 | } else if (t2 == FLOAT) { | | 477 | } else if (t2 == FLOAT) { |
481 | td = gettyp(DOUBLE); | | 478 | td = gettyp(DOUBLE); |
482 | } else if (t2 == DOUBLE) { | | 479 | } else if (t2 == DOUBLE) { |
483 | td = gettyp(LDOUBLE); | | 480 | td = gettyp(LDOUBLE); |
484 | } else if (t2 == DCOMPLEX) { | | 481 | } else if (t2 == DCOMPLEX) { |
485 | td = gettyp(LCOMPLEX); | | 482 | td = gettyp(LCOMPLEX); |
486 | } | | 483 | } |
487 | td = dup_type(td); | | 484 | td = block_dup_type(td); |
488 | td->t_typedef = true; | | 485 | td->t_typedef = true; |
489 | return td; | | 486 | return td; |
490 | } | | 487 | } |
491 | | | 488 | |
492 | /* Anything else is not accepted. */ | | 489 | /* Anything else is not accepted. */ |
493 | dcs->d_invalid_type_combination = true; | | 490 | dcs->d_invalid_type_combination = true; |
494 | return td; | | 491 | return td; |
495 | } | | 492 | } |
496 | | | 493 | |
497 | /* | | 494 | /* |
498 | * Remember the symbol of a typedef name (2nd arg) in a struct, union | | 495 | * Remember the symbol of a typedef name (2nd arg) in a struct, union |
499 | * or enum tag if the typedef name is the first defined for this tag. | | 496 | * or enum tag if the typedef name is the first defined for this tag. |
500 | * | | 497 | * |
| @@ -854,27 +851,27 @@ end_type(void) | | | @@ -854,27 +851,27 @@ end_type(void) |
854 | | | 851 | |
855 | if (dcs->d_const && dcs->d_type->t_const) { | | 852 | if (dcs->d_const && dcs->d_type->t_const) { |
856 | lint_assert(dcs->d_type->t_typedef); | | 853 | lint_assert(dcs->d_type->t_typedef); |
857 | /* typedef already qualified with '%s' */ | | 854 | /* typedef already qualified with '%s' */ |
858 | warning(68, "const"); | | 855 | warning(68, "const"); |
859 | } | | 856 | } |
860 | if (dcs->d_volatile && dcs->d_type->t_volatile) { | | 857 | if (dcs->d_volatile && dcs->d_type->t_volatile) { |
861 | lint_assert(dcs->d_type->t_typedef); | | 858 | lint_assert(dcs->d_type->t_typedef); |
862 | /* typedef already qualified with '%s' */ | | 859 | /* typedef already qualified with '%s' */ |
863 | warning(68, "volatile"); | | 860 | warning(68, "volatile"); |
864 | } | | 861 | } |
865 | | | 862 | |
866 | if (dcs->d_const || dcs->d_volatile) { | | 863 | if (dcs->d_const || dcs->d_volatile) { |
867 | dcs->d_type = dup_type(dcs->d_type); | | 864 | dcs->d_type = block_dup_type(dcs->d_type); |
868 | dcs->d_type->t_const |= dcs->d_const; | | 865 | dcs->d_type->t_const |= dcs->d_const; |
869 | dcs->d_type->t_volatile |= dcs->d_volatile; | | 866 | dcs->d_type->t_volatile |= dcs->d_volatile; |
870 | } | | 867 | } |
871 | } | | 868 | } |
872 | | | 869 | |
873 | /* | | 870 | /* |
874 | * Return the length of a type in bits. | | 871 | * Return the length of a type in bits. |
875 | * | | 872 | * |
876 | * Printing a message if the outermost dimension of an array is 0 must | | 873 | * Printing a message if the outermost dimension of an array is 0 must |
877 | * be done by the caller. All other problems are reported by length() | | 874 | * be done by the caller. All other problems are reported by length() |
878 | * if name is not NULL. | | 875 | * if name is not NULL. |
879 | */ | | 876 | */ |
880 | int | | 877 | int |
| @@ -985,29 +982,30 @@ check_type(sym_t *sym) | | | @@ -985,29 +982,30 @@ check_type(sym_t *sym) |
985 | * a better warning is printed in funcdef(). | | 982 | * a better warning is printed in funcdef(). |
986 | */ | | 983 | */ |
987 | if (t == FUNC && !tp->t_proto && | | 984 | if (t == FUNC && !tp->t_proto && |
988 | !(to == NOTSPEC && sym->s_osdef)) { | | 985 | !(to == NOTSPEC && sym->s_osdef)) { |
989 | if (sflag && hflag) | | 986 | if (sflag && hflag) |
990 | /* function declaration is not a prototype */ | | 987 | /* function declaration is not a prototype */ |
991 | warning(287); | | 988 | warning(287); |
992 | } | | 989 | } |
993 | if (to == FUNC) { | | 990 | if (to == FUNC) { |
994 | if (t == FUNC || t == ARRAY) { | | 991 | if (t == FUNC || t == ARRAY) { |
995 | /* function returns illegal type */ | | 992 | /* function returns illegal type */ |
996 | error(15); | | 993 | error(15); |
997 | if (t == FUNC) { | | 994 | if (t == FUNC) { |
998 | *tpp = derive_type(*tpp, PTR); | | 995 | *tpp = block_derive_type(*tpp, PTR); |
999 | } else { | | 996 | } else { |
1000 | *tpp = derive_type((*tpp)->t_subt, PTR); | | 997 | *tpp = block_derive_type( |
| | | 998 | (*tpp)->t_subt, PTR); |
1001 | } | | 999 | } |
1002 | return; | | 1000 | return; |
1003 | } else if (tp->t_const || tp->t_volatile) { | | 1001 | } else if (tp->t_const || tp->t_volatile) { |
1004 | if (sflag) { /* XXX or better !tflag ? */ | | 1002 | if (sflag) { /* XXX or better !tflag ? */ |
1005 | /* function cannot return const... */ | | 1003 | /* function cannot return const... */ |
1006 | warning(228); | | 1004 | warning(228); |
1007 | } | | 1005 | } |
1008 | } | | 1006 | } |
1009 | } if (to == ARRAY) { | | 1007 | } if (to == ARRAY) { |
1010 | if (t == FUNC) { | | 1008 | if (t == FUNC) { |
1011 | /* array of function is illegal */ | | 1009 | /* array of function is illegal */ |
1012 | error(16); | | 1010 | error(16); |
1013 | *tpp = gettyp(INT); | | 1011 | *tpp = gettyp(INT); |
| @@ -1095,27 +1093,27 @@ check_bit_field_type(sym_t *dsym, type_ | | | @@ -1095,27 +1093,27 @@ check_bit_field_type(sym_t *dsym, type_ |
1095 | } | | 1093 | } |
1096 | } else if (t != INT && t != UINT && t != BOOL) { | | 1094 | } else if (t != INT && t != UINT && t != BOOL) { |
1097 | /* | | 1095 | /* |
1098 | * Non-integer types are always illegal for bitfields, | | 1096 | * Non-integer types are always illegal for bitfields, |
1099 | * regardless of BITFIELDTYPE. Integer types not dealt with | | 1097 | * regardless of BITFIELDTYPE. Integer types not dealt with |
1100 | * above are okay only if BITFIELDTYPE is in effect. | | 1098 | * above are okay only if BITFIELDTYPE is in effect. |
1101 | */ | | 1099 | */ |
1102 | if (!(bitfieldtype_ok || gflag) || !is_integer(t)) { | | 1100 | if (!(bitfieldtype_ok || gflag) || !is_integer(t)) { |
1103 | unsigned int sz; | | 1101 | unsigned int sz; |
1104 | | | 1102 | |
1105 | /* illegal bit-field type '%s' */ | | 1103 | /* illegal bit-field type '%s' */ |
1106 | warning(35, type_name(tp)); | | 1104 | warning(35, type_name(tp)); |
1107 | sz = tp->t_flen; | | 1105 | sz = tp->t_flen; |
1108 | dsym->s_type = tp = dup_type(gettyp(t = INT)); | | 1106 | dsym->s_type = tp = block_dup_type(gettyp(t = INT)); |
1109 | if ((tp->t_flen = sz) > size_in_bits(t)) | | 1107 | if ((tp->t_flen = sz) > size_in_bits(t)) |
1110 | tp->t_flen = size_in_bits(t); | | 1108 | tp->t_flen = size_in_bits(t); |
1111 | *inout_t = t; | | 1109 | *inout_t = t; |
1112 | *inout_tp = tp; | | 1110 | *inout_tp = tp; |
1113 | } | | 1111 | } |
1114 | } | | 1112 | } |
1115 | } | | 1113 | } |
1116 | | | 1114 | |
1117 | static void | | 1115 | static void |
1118 | declare_bit_field(sym_t *dsym, tspec_t *inout_t, type_t **const inout_tp) | | 1116 | declare_bit_field(sym_t *dsym, tspec_t *inout_t, type_t **const inout_tp) |
1119 | { | | 1117 | { |
1120 | type_t *tp; | | 1118 | type_t *tp; |
1121 | tspec_t t; | | 1119 | tspec_t t; |
| @@ -1165,27 +1163,27 @@ declarator_1_struct_union(sym_t *dsym) | | | @@ -1165,27 +1163,27 @@ declarator_1_struct_union(sym_t *dsym) |
1165 | rmsym(dcs->d_redeclared_symbol); | | 1163 | rmsym(dcs->d_redeclared_symbol); |
1166 | } | | 1164 | } |
1167 | } | | 1165 | } |
1168 | | | 1166 | |
1169 | check_type(dsym); | | 1167 | check_type(dsym); |
1170 | | | 1168 | |
1171 | t = (tp = dsym->s_type)->t_tspec; | | 1169 | t = (tp = dsym->s_type)->t_tspec; |
1172 | | | 1170 | |
1173 | if (dsym->s_bitfield) { | | 1171 | if (dsym->s_bitfield) { |
1174 | declare_bit_field(dsym, &t, &tp); | | 1172 | declare_bit_field(dsym, &t, &tp); |
1175 | } else if (t == FUNC) { | | 1173 | } else if (t == FUNC) { |
1176 | /* function illegal in structure or union */ | | 1174 | /* function illegal in structure or union */ |
1177 | error(38); | | 1175 | error(38); |
1178 | dsym->s_type = tp = derive_type(tp, t = PTR); | | 1176 | dsym->s_type = tp = block_derive_type(tp, t = PTR); |
1179 | } | | 1177 | } |
1180 | | | 1178 | |
1181 | /* | | 1179 | /* |
1182 | * bit-fields of length 0 are not warned about because length() | | 1180 | * bit-fields of length 0 are not warned about because length() |
1183 | * does not return the length of the bit-field but the length | | 1181 | * does not return the length of the bit-field but the length |
1184 | * of the type the bit-field is packed in (it's ok) | | 1182 | * of the type the bit-field is packed in (it's ok) |
1185 | */ | | 1183 | */ |
1186 | if ((sz = length(dsym->s_type, dsym->s_name)) == 0) { | | 1184 | if ((sz = length(dsym->s_type, dsym->s_name)) == 0) { |
1187 | if (t == ARRAY && dsym->s_type->t_dim == 0) { | | 1185 | if (t == ARRAY && dsym->s_type->t_dim == 0) { |
1188 | /* zero sized array in struct is a C99 extension: %s */ | | 1186 | /* zero sized array in struct is a C99 extension: %s */ |
1189 | c99ism(39, dsym->s_name); | | 1187 | c99ism(39, dsym->s_name); |
1190 | } | | 1188 | } |
1191 | } | | 1189 | } |
| @@ -1249,27 +1247,27 @@ align(unsigned int al, unsigned int len) | | | @@ -1249,27 +1247,27 @@ align(unsigned int al, unsigned int len) |
1249 | */ | | 1247 | */ |
1250 | sym_t * | | 1248 | sym_t * |
1251 | bitfield(sym_t *dsym, int len) | | 1249 | bitfield(sym_t *dsym, int len) |
1252 | { | | 1250 | { |
1253 | | | 1251 | |
1254 | if (dsym == NULL) { | | 1252 | if (dsym == NULL) { |
1255 | dsym = block_zero_alloc(sizeof(*dsym)); | | 1253 | dsym = block_zero_alloc(sizeof(*dsym)); |
1256 | dsym->s_name = unnamed; | | 1254 | dsym->s_name = unnamed; |
1257 | dsym->s_kind = FMEMBER; | | 1255 | dsym->s_kind = FMEMBER; |
1258 | dsym->s_scl = MOS; | | 1256 | dsym->s_scl = MOS; |
1259 | dsym->s_type = gettyp(UINT); | | 1257 | dsym->s_type = gettyp(UINT); |
1260 | dsym->s_block_level = -1; | | 1258 | dsym->s_block_level = -1; |
1261 | } | | 1259 | } |
1262 | dsym->s_type = dup_type(dsym->s_type); | | 1260 | dsym->s_type = block_dup_type(dsym->s_type); |
1263 | dsym->s_type->t_bitfield = true; | | 1261 | dsym->s_type->t_bitfield = true; |
1264 | dsym->s_type->t_flen = len; | | 1262 | dsym->s_type->t_flen = len; |
1265 | dsym->s_bitfield = true; | | 1263 | dsym->s_bitfield = true; |
1266 | return dsym; | | 1264 | return dsym; |
1267 | } | | 1265 | } |
1268 | | | 1266 | |
1269 | /* | | 1267 | /* |
1270 | * A sequence of asterisks and qualifiers, from right to left. For example, | | 1268 | * A sequence of asterisks and qualifiers, from right to left. For example, |
1271 | * 'const ***volatile **const volatile' results in [cvp, p, vp, p, p]. The | | 1269 | * 'const ***volatile **const volatile' results in [cvp, p, vp, p, p]. The |
1272 | * leftmost 'const' is not included in this list, it is stored in dcs->d_const | | 1270 | * leftmost 'const' is not included in this list, it is stored in dcs->d_const |
1273 | * instead. | | 1271 | * instead. |
1274 | */ | | 1272 | */ |
1275 | qual_ptr * | | 1273 | qual_ptr * |
| @@ -2004,27 +2002,27 @@ declare_extern(sym_t *dsym, bool initflg | | | @@ -2004,27 +2002,27 @@ declare_extern(sym_t *dsym, bool initflg |
2004 | | | 2002 | |
2005 | /* once a function is inline, it remains inline */ | | 2003 | /* once a function is inline, it remains inline */ |
2006 | if (rdsym->s_inline) | | 2004 | if (rdsym->s_inline) |
2007 | dsym->s_inline = true; | | 2005 | dsym->s_inline = true; |
2008 | | | 2006 | |
2009 | complete_type(dsym, rdsym); | | 2007 | complete_type(dsym, rdsym); |
2010 | | | 2008 | |
2011 | } | | 2009 | } |
2012 | | | 2010 | |
2013 | rmsym(rdsym); | | 2011 | rmsym(rdsym); |
2014 | } | | 2012 | } |
2015 | | | 2013 | |
2016 | if (dsym->s_scl == TYPEDEF) { | | 2014 | if (dsym->s_scl == TYPEDEF) { |
2017 | dsym->s_type = dup_type(dsym->s_type); | | 2015 | dsym->s_type = block_dup_type(dsym->s_type); |
2018 | dsym->s_type->t_typedef = true; | | 2016 | dsym->s_type->t_typedef = true; |
2019 | settdsym(dsym->s_type, dsym); | | 2017 | settdsym(dsym->s_type, dsym); |
2020 | } | | 2018 | } |
2021 | | | 2019 | |
2022 | } | | 2020 | } |
2023 | | | 2021 | |
2024 | void | | 2022 | void |
2025 | declare(sym_t *decl, bool initflg, sbuf_t *renaming) | | 2023 | declare(sym_t *decl, bool initflg, sbuf_t *renaming) |
2026 | { | | 2024 | { |
2027 | | | 2025 | |
2028 | if (dcs->d_ctx == EXTERN) { | | 2026 | if (dcs->d_ctx == EXTERN) { |
2029 | declare_extern(decl, initflg, renaming); | | 2027 | declare_extern(decl, initflg, renaming); |
2030 | } else if (dcs->d_ctx == OLD_STYLE_ARG || dcs->d_ctx == PROTO_ARG) { | | 2028 | } else if (dcs->d_ctx == OLD_STYLE_ARG || dcs->d_ctx == PROTO_ARG) { |
| @@ -2360,33 +2358,33 @@ void | | | @@ -2360,33 +2358,33 @@ void |
2360 | complete_type(sym_t *dsym, sym_t *ssym) | | 2358 | complete_type(sym_t *dsym, sym_t *ssym) |
2361 | { | | 2359 | { |
2362 | type_t **dstp, *src; | | 2360 | type_t **dstp, *src; |
2363 | type_t *dst; | | 2361 | type_t *dst; |
2364 | | | 2362 | |
2365 | dstp = &dsym->s_type; | | 2363 | dstp = &dsym->s_type; |
2366 | src = ssym->s_type; | | 2364 | src = ssym->s_type; |
2367 | | | 2365 | |
2368 | while ((dst = *dstp) != NULL) { | | 2366 | while ((dst = *dstp) != NULL) { |
2369 | lint_assert(src != NULL); | | 2367 | lint_assert(src != NULL); |
2370 | lint_assert(dst->t_tspec == src->t_tspec); | | 2368 | lint_assert(dst->t_tspec == src->t_tspec); |
2371 | if (dst->t_tspec == ARRAY) { | | 2369 | if (dst->t_tspec == ARRAY) { |
2372 | if (dst->t_dim == 0 && src->t_dim != 0) { | | 2370 | if (dst->t_dim == 0 && src->t_dim != 0) { |
2373 | *dstp = dst = dup_type(dst); | | 2371 | *dstp = dst = block_dup_type(dst); |
2374 | dst->t_dim = src->t_dim; | | 2372 | dst->t_dim = src->t_dim; |
2375 | setcomplete(dst, true); | | 2373 | setcomplete(dst, true); |
2376 | } | | 2374 | } |
2377 | } else if (dst->t_tspec == FUNC) { | | 2375 | } else if (dst->t_tspec == FUNC) { |
2378 | if (!dst->t_proto && src->t_proto) { | | 2376 | if (!dst->t_proto && src->t_proto) { |
2379 | *dstp = dst = dup_type(dst); | | 2377 | *dstp = dst = block_dup_type(dst); |
2380 | dst->t_proto = true; | | 2378 | dst->t_proto = true; |
2381 | dst->t_args = src->t_args; | | 2379 | dst->t_args = src->t_args; |
2382 | } | | 2380 | } |
2383 | } | | 2381 | } |
2384 | dstp = &dst->t_subt; | | 2382 | dstp = &dst->t_subt; |
2385 | src = src->t_subt; | | 2383 | src = src->t_subt; |
2386 | } | | 2384 | } |
2387 | } | | 2385 | } |
2388 | | | 2386 | |
2389 | /* | | 2387 | /* |
2390 | * Completes the declaration of a single argument. | | 2388 | * Completes the declaration of a single argument. |
2391 | */ | | 2389 | */ |
2392 | sym_t * | | 2390 | sym_t * |
| @@ -2411,32 +2409,32 @@ declare_argument(sym_t *sym, bool initfl | | | @@ -2411,32 +2409,32 @@ declare_argument(sym_t *sym, bool initfl |
2411 | error(53, sym->s_name); | | 2409 | error(53, sym->s_name); |
2412 | sym->s_arg = true; | | 2410 | sym->s_arg = true; |
2413 | } | | 2411 | } |
2414 | | | 2412 | |
2415 | if (initflg) { | | 2413 | if (initflg) { |
2416 | /* cannot initialize parameter: %s */ | | 2414 | /* cannot initialize parameter: %s */ |
2417 | error(52, sym->s_name); | | 2415 | error(52, sym->s_name); |
2418 | } | | 2416 | } |
2419 | | | 2417 | |
2420 | if (sym->s_type == NULL) /* for c(void()) */ | | 2418 | if (sym->s_type == NULL) /* for c(void()) */ |
2421 | sym->s_type = gettyp(VOID); | | 2419 | sym->s_type = gettyp(VOID); |
2422 | | | 2420 | |
2423 | if ((t = sym->s_type->t_tspec) == ARRAY) { | | 2421 | if ((t = sym->s_type->t_tspec) == ARRAY) { |
2424 | sym->s_type = derive_type(sym->s_type->t_subt, PTR); | | 2422 | sym->s_type = block_derive_type(sym->s_type->t_subt, PTR); |
2425 | } else if (t == FUNC) { | | 2423 | } else if (t == FUNC) { |
2426 | if (tflag) | | 2424 | if (tflag) |
2427 | /* a function is declared as an argument: %s */ | | 2425 | /* a function is declared as an argument: %s */ |
2428 | warning(50, sym->s_name); | | 2426 | warning(50, sym->s_name); |
2429 | sym->s_type = derive_type(sym->s_type, PTR); | | 2427 | sym->s_type = block_derive_type(sym->s_type, PTR); |
2430 | } else if (t == FLOAT) { | | 2428 | } else if (t == FLOAT) { |
2431 | if (tflag) | | 2429 | if (tflag) |
2432 | sym->s_type = gettyp(DOUBLE); | | 2430 | sym->s_type = gettyp(DOUBLE); |
2433 | } | | 2431 | } |
2434 | | | 2432 | |
2435 | if (dcs->d_inline) | | 2433 | if (dcs->d_inline) |
2436 | /* argument declared inline: %s */ | | 2434 | /* argument declared inline: %s */ |
2437 | warning(269, sym->s_name); | | 2435 | warning(269, sym->s_name); |
2438 | | | 2436 | |
2439 | /* | | 2437 | /* |
2440 | * Arguments must have complete types. length() prints the needed | | 2438 | * Arguments must have complete types. length() prints the needed |
2441 | * error messages (null dimension is impossible because arrays are | | 2439 | * error messages (null dimension is impossible because arrays are |
2442 | * converted to pointers). | | 2440 | * converted to pointers). |
| @@ -2745,27 +2743,27 @@ declare_local(sym_t *dsym, bool initflg) | | | @@ -2745,27 +2743,27 @@ declare_local(sym_t *dsym, bool initflg) |
2745 | outsym(dsym, dsym->s_ext_sym->s_scl, dsym->s_def); | | 2743 | outsym(dsym, dsym->s_ext_sym->s_scl, dsym->s_def); |
2746 | } | | 2744 | } |
2747 | } | | 2745 | } |
2748 | | | 2746 | |
2749 | if (dcs->d_redeclared_symbol != NULL) | | 2747 | if (dcs->d_redeclared_symbol != NULL) |
2750 | check_local_redeclaration(dsym, dcs->d_redeclared_symbol); | | 2748 | check_local_redeclaration(dsym, dcs->d_redeclared_symbol); |
2751 | | | 2749 | |
2752 | if (initflg && !check_init(dsym)) { | | 2750 | if (initflg && !check_init(dsym)) { |
2753 | dsym->s_def = DEF; | | 2751 | dsym->s_def = DEF; |
2754 | mark_as_set(dsym); | | 2752 | mark_as_set(dsym); |
2755 | } | | 2753 | } |
2756 | | | 2754 | |
2757 | if (dsym->s_scl == TYPEDEF) { | | 2755 | if (dsym->s_scl == TYPEDEF) { |
2758 | dsym->s_type = dup_type(dsym->s_type); | | 2756 | dsym->s_type = block_dup_type(dsym->s_type); |
2759 | dsym->s_type->t_typedef = true; | | 2757 | dsym->s_type->t_typedef = true; |
2760 | settdsym(dsym->s_type, dsym); | | 2758 | settdsym(dsym->s_type, dsym); |
2761 | } | | 2759 | } |
2762 | | | 2760 | |
2763 | /* | | 2761 | /* |
2764 | * Before we can check the size we must wait for a initialization | | 2762 | * Before we can check the size we must wait for a initialization |
2765 | * which may follow. | | 2763 | * which may follow. |
2766 | */ | | 2764 | */ |
2767 | } | | 2765 | } |
2768 | | | 2766 | |
2769 | /* | | 2767 | /* |
2770 | * Processes (re)declarations of external symbols inside blocks. | | 2768 | * Processes (re)declarations of external symbols inside blocks. |
2771 | */ | | 2769 | */ |