Sun Feb 27 10:31:58 2022 UTC ()
lint: encode lifetime of allocated memory in function names

No functional change.


(rillig)
diff -r1.246 -r1.247 src/usr.bin/xlint/lint1/decl.c
diff -r1.147 -r1.148 src/usr.bin/xlint/lint1/externs1.h
diff -r1.231 -r1.232 src/usr.bin/xlint/lint1/init.c
diff -r1.405 -r1.406 src/usr.bin/xlint/lint1/tree.c

cvs diff -r1.246 -r1.247 src/usr.bin/xlint/lint1/decl.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/decl.c 2022/02/27 08:31:26 1.246
+++ src/usr.bin/xlint/lint1/decl.c 2022/02/27 10:31:58 1.247
@@ -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
51const char *unnamed = "<unnamed>"; 51const char *unnamed = "<unnamed>";
52 52
53/* shared type structures for arithmetic types and void */ 53/* shared type structures for arithmetic types and void */
54static type_t *typetab; 54static 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 */
166type_t * 166type_t *
167gettyp(tspec_t t) 167gettyp(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
174type_t * 174type_t *
175dup_type(const type_t *tp) 175block_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 */ 
188type_t * 185type_t *
189expr_dup_type(const type_t *tp) 186expr_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)
441static type_t * 438static type_t *
442tdeferr(type_t *td, tspec_t t) 439tdeferr(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 */
880int 877int
@@ -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
1117static void 1115static void
1118declare_bit_field(sym_t *dsym, tspec_t *inout_t, type_t **const inout_tp) 1116declare_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 */
1250sym_t * 1248sym_t *
1251bitfield(sym_t *dsym, int len) 1249bitfield(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 */
1275qual_ptr * 1273qual_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
2024void 2022void
2025declare(sym_t *decl, bool initflg, sbuf_t *renaming) 2023declare(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
2360complete_type(sym_t *dsym, sym_t *ssym) 2358complete_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 */
2392sym_t * 2390sym_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 */

cvs diff -r1.147 -r1.148 src/usr.bin/xlint/lint1/externs1.h (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/externs1.h 2022/02/27 08:31:26 1.147
+++ src/usr.bin/xlint/lint1/externs1.h 2022/02/27 10:31:58 1.148
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: externs1.h,v 1.147 2022/02/27 08:31:26 rillig Exp $ */ 1/* $NetBSD: externs1.h,v 1.148 2022/02/27 10:31:58 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl 4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved. 5 * All Rights Reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -158,27 +158,27 @@ extern void internal_error(const char *, @@ -158,27 +158,27 @@ extern void internal_error(const char *,
158extern void assert_failed(const char *, int, const char *, const char *) 158extern void assert_failed(const char *, int, const char *, const char *)
159 __attribute__((__noreturn__)); 159 __attribute__((__noreturn__));
160extern void update_location(const char *, int, bool, bool); 160extern void update_location(const char *, int, bool, bool);
161 161
162/* 162/*
163 * decl.c 163 * decl.c
164 */ 164 */
165extern dinfo_t *dcs; 165extern dinfo_t *dcs;
166extern const char *unnamed; 166extern const char *unnamed;
167extern int enumval; 167extern int enumval;
168 168
169extern void initdecl(void); 169extern void initdecl(void);
170extern type_t *gettyp(tspec_t); 170extern type_t *gettyp(tspec_t);
171extern type_t *dup_type(const type_t *); 171extern type_t *block_dup_type(const type_t *);
172extern type_t *expr_dup_type(const type_t *); 172extern type_t *expr_dup_type(const type_t *);
173extern type_t *expr_unqualified_type(const type_t *); 173extern type_t *expr_unqualified_type(const type_t *);
174extern bool is_incomplete(const type_t *); 174extern bool is_incomplete(const type_t *);
175extern void setcomplete(type_t *, bool); 175extern void setcomplete(type_t *, bool);
176extern void add_storage_class(scl_t); 176extern void add_storage_class(scl_t);
177extern void add_type(type_t *); 177extern void add_type(type_t *);
178extern void add_qualifier(tqual_t); 178extern void add_qualifier(tqual_t);
179extern void addpacked(void); 179extern void addpacked(void);
180extern void add_attr_used(void); 180extern void add_attr_used(void);
181extern void begin_declaration_level(scl_t); 181extern void begin_declaration_level(scl_t);
182extern void end_declaration_level(void); 182extern void end_declaration_level(void);
183extern void setasm(void); 183extern void setasm(void);
184extern void begin_type(void); 184extern void begin_type(void);
@@ -219,27 +219,27 @@ extern void check_size(sym_t *); @@ -219,27 +219,27 @@ extern void check_size(sym_t *);
219extern void mark_as_set(sym_t *); 219extern void mark_as_set(sym_t *);
220extern void mark_as_used(sym_t *, bool, bool); 220extern void mark_as_used(sym_t *, bool, bool);
221extern void check_usage(dinfo_t *); 221extern void check_usage(dinfo_t *);
222extern void check_usage_sym(bool, sym_t *); 222extern void check_usage_sym(bool, sym_t *);
223extern void check_global_symbols(void); 223extern void check_global_symbols(void);
224extern void print_previous_declaration(int, const sym_t *); 224extern void print_previous_declaration(int, const sym_t *);
225extern int to_int_constant(tnode_t *, bool); 225extern int to_int_constant(tnode_t *, bool);
226extern const char *scl_name(scl_t); 226extern const char *scl_name(scl_t);
227 227
228/* 228/*
229 * tree.c 229 * tree.c
230 */ 230 */
231extern const tnode_t *before_conversion(const tnode_t *); 231extern const tnode_t *before_conversion(const tnode_t *);
232extern type_t *derive_type(type_t *, tspec_t); 232extern type_t *block_derive_type(type_t *, tspec_t);
233extern type_t *expr_derive_type(type_t *, tspec_t); 233extern type_t *expr_derive_type(type_t *, tspec_t);
234extern bool is_compiler_builtin(const char *); 234extern bool is_compiler_builtin(const char *);
235extern tnode_t *build_constant(type_t *, val_t *); 235extern tnode_t *build_constant(type_t *, val_t *);
236extern tnode_t *build_name(sym_t *, bool); 236extern tnode_t *build_name(sym_t *, bool);
237extern tnode_t *build_string(strg_t *); 237extern tnode_t *build_string(strg_t *);
238extern tnode_t *build_generic_selection(const tnode_t *, 238extern tnode_t *build_generic_selection(const tnode_t *,
239 struct generic_association *); 239 struct generic_association *);
240 240
241extern tnode_t *build_binary(tnode_t *, op_t, bool, tnode_t *); 241extern tnode_t *build_binary(tnode_t *, op_t, bool, tnode_t *);
242extern tnode_t *build_unary(op_t, bool, tnode_t *); 242extern tnode_t *build_unary(op_t, bool, tnode_t *);
243extern tnode_t *build_member_access(tnode_t *, op_t, bool, sbuf_t *); 243extern tnode_t *build_member_access(tnode_t *, op_t, bool, sbuf_t *);
244extern tnode_t *cconv(tnode_t *); 244extern tnode_t *cconv(tnode_t *);
245extern bool is_typeok_bool_operand(const tnode_t *); 245extern bool is_typeok_bool_operand(const tnode_t *);

cvs diff -r1.231 -r1.232 src/usr.bin/xlint/lint1/init.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/init.c 2022/02/27 08:31:26 1.231
+++ src/usr.bin/xlint/lint1/init.c 2022/02/27 10:31:58 1.232
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: init.c,v 1.231 2022/02/27 08:31:26 rillig Exp $ */ 1/* $NetBSD: init.c,v 1.232 2022/02/27 10:31:58 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl 4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * Copyright (c) 2021 Roland Illig 5 * Copyright (c) 2021 Roland Illig
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: init.c,v 1.231 2022/02/27 08:31:26 rillig Exp $"); 41__RCSID("$NetBSD: init.c,v 1.232 2022/02/27 10:31:58 rillig Exp $");
42#endif 42#endif
43 43
44#include <stdlib.h> 44#include <stdlib.h>
45#include <string.h> 45#include <string.h>
46 46
47#include "lint1.h" 47#include "lint1.h"
48 48
49 49
50/* 50/*
51 * Initialization of global or local objects, like in: 51 * Initialization of global or local objects, like in:
52 * 52 *
53 * int number = 12345; 53 * int number = 12345;
54 * int number_with_braces = { 12345 }; 54 * int number_with_braces = { 12345 };
@@ -239,27 +239,27 @@ look_up_member(const type_t *tp, const c @@ -239,27 +239,27 @@ look_up_member(const type_t *tp, const c
239 return m; 239 return m;
240 return NULL; 240 return NULL;
241} 241}
242 242
243/* 243/*
244 * C99 6.7.8p22 says that the type of an array of unknown size becomes known 244 * C99 6.7.8p22 says that the type of an array of unknown size becomes known
245 * at the end of its initializer list. 245 * at the end of its initializer list.
246 */ 246 */
247static void 247static void
248update_type_of_array_of_unknown_size(sym_t *sym, size_t size) 248update_type_of_array_of_unknown_size(sym_t *sym, size_t size)
249{ 249{
250 type_t *tp; 250 type_t *tp;
251 251
252 tp = dup_type(sym->s_type); 252 tp = block_dup_type(sym->s_type);
253 tp->t_dim = (int)size; 253 tp->t_dim = (int)size;
254 tp->t_incomplete_array = false; 254 tp->t_incomplete_array = false;
255 sym->s_type = tp; 255 sym->s_type = tp;
256 debug_step("completed array type is '%s'", type_name(sym->s_type)); 256 debug_step("completed array type is '%s'", type_name(sym->s_type));
257} 257}
258 258
259 259
260/* In traditional C, bit-fields can be initialized only by integer constants. */ 260/* In traditional C, bit-fields can be initialized only by integer constants. */
261static void 261static void
262check_bit_field_init(const tnode_t *ln, tspec_t lt, tspec_t rt) 262check_bit_field_init(const tnode_t *ln, tspec_t lt, tspec_t rt)
263{ 263{
264 264
265 if (tflag && 265 if (tflag &&

cvs diff -r1.405 -r1.406 src/usr.bin/xlint/lint1/tree.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/tree.c 2022/02/27 08:31:26 1.405
+++ src/usr.bin/xlint/lint1/tree.c 2022/02/27 10:31:58 1.406
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: tree.c,v 1.405 2022/02/27 08:31:26 rillig Exp $ */ 1/* $NetBSD: tree.c,v 1.406 2022/02/27 10:31:58 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl 4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved. 5 * All Rights Reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#if HAVE_NBTOOL_CONFIG_H 34#if HAVE_NBTOOL_CONFIG_H
35#include "nbtool_config.h" 35#include "nbtool_config.h"
36#endif 36#endif
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39#if defined(__RCSID) && !defined(lint) 39#if defined(__RCSID) && !defined(lint)
40__RCSID("$NetBSD: tree.c,v 1.405 2022/02/27 08:31:26 rillig Exp $"); 40__RCSID("$NetBSD: tree.c,v 1.406 2022/02/27 10:31:58 rillig Exp $");
41#endif 41#endif
42 42
43#include <float.h> 43#include <float.h>
44#include <limits.h> 44#include <limits.h>
45#include <math.h> 45#include <math.h>
46#include <signal.h> 46#include <signal.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <string.h> 48#include <string.h>
49 49
50#include "lint1.h" 50#include "lint1.h"
51#include "cgram.h" 51#include "cgram.h"
52 52
53static tnode_t *build_integer_constant(tspec_t, int64_t); 53static tnode_t *build_integer_constant(tspec_t, int64_t);
@@ -94,27 +94,27 @@ static void check_array_index(tnode_t *, @@ -94,27 +94,27 @@ static void check_array_index(tnode_t *,
94static void check_integer_comparison(op_t, tnode_t *, tnode_t *); 94static void check_integer_comparison(op_t, tnode_t *, tnode_t *);
95static void check_precedence_confusion(tnode_t *); 95static void check_precedence_confusion(tnode_t *);
96 96
97extern sig_atomic_t fpe; 97extern sig_atomic_t fpe;
98 98
99static const char * 99static const char *
100op_name(op_t op) 100op_name(op_t op)
101{ 101{
102 return modtab[op].m_name; 102 return modtab[op].m_name;
103} 103}
104 104
105/* Build 'pointer to tp', 'array of tp' or 'function returning tp'. */ 105/* Build 'pointer to tp', 'array of tp' or 'function returning tp'. */
106type_t * 106type_t *
107derive_type(type_t *tp, tspec_t t) 107block_derive_type(type_t *tp, tspec_t t)
108{ 108{
109 type_t *tp2; 109 type_t *tp2;
110 110
111 tp2 = block_zero_alloc(sizeof(*tp2)); 111 tp2 = block_zero_alloc(sizeof(*tp2));
112 tp2->t_tspec = t; 112 tp2->t_tspec = t;
113 tp2->t_subt = tp; 113 tp2->t_subt = tp;
114 return tp2; 114 return tp2;
115} 115}
116 116
117/* 117/*
118 * Derive 'pointer to tp' or 'function returning tp'. 118 * Derive 'pointer to tp' or 'function returning tp'.
119 * The memory is freed at the end of the current expression. 119 * The memory is freed at the end of the current expression.
120 */ 120 */
@@ -163,36 +163,36 @@ build_integer_constant(tspec_t t, int64_ @@ -163,36 +163,36 @@ build_integer_constant(tspec_t t, int64_
163} 163}
164 164
165static void 165static void
166fallback_symbol(sym_t *sym) 166fallback_symbol(sym_t *sym)
167{ 167{
168 168
169 if (fallback_symbol_strict_bool(sym)) 169 if (fallback_symbol_strict_bool(sym))
170 return; 170 return;
171 171
172 if (block_level > 0 && (strcmp(sym->s_name, "__FUNCTION__") == 0 || 172 if (block_level > 0 && (strcmp(sym->s_name, "__FUNCTION__") == 0 ||
173 strcmp(sym->s_name, "__PRETTY_FUNCTION__") == 0)) { 173 strcmp(sym->s_name, "__PRETTY_FUNCTION__") == 0)) {
174 /* __FUNCTION__/__PRETTY_FUNCTION__ is a GCC extension */ 174 /* __FUNCTION__/__PRETTY_FUNCTION__ is a GCC extension */
175 gnuism(316); 175 gnuism(316);
176 sym->s_type = derive_type(gettyp(CHAR), PTR); 176 sym->s_type = block_derive_type(gettyp(CHAR), PTR);
177 sym->s_type->t_const = true; 177 sym->s_type->t_const = true;
178 return; 178 return;
179 } 179 }
180 180
181 if (block_level > 0 && strcmp(sym->s_name, "__func__") == 0) { 181 if (block_level > 0 && strcmp(sym->s_name, "__func__") == 0) {
182 if (!Sflag) 182 if (!Sflag)
183 /* __func__ is a C9X feature */ 183 /* __func__ is a C9X feature */
184 warning(317); 184 warning(317);
185 sym->s_type = derive_type(gettyp(CHAR), PTR); 185 sym->s_type = block_derive_type(gettyp(CHAR), PTR);
186 sym->s_type->t_const = true; 186 sym->s_type->t_const = true;
187 return; 187 return;
188 } 188 }
189 189
190 /* '%s' undefined */ 190 /* '%s' undefined */
191 error(99, sym->s_name); 191 error(99, sym->s_name);
192} 192}
193 193
194/* 194/*
195 * Functions that are predeclared by GCC or other compilers can be called 195 * Functions that are predeclared by GCC or other compilers can be called
196 * with arbitrary arguments. Since lint usually runs after a successful 196 * with arbitrary arguments. Since lint usually runs after a successful
197 * compilation, it's the compiler's job to catch any errors. 197 * compilation, it's the compiler's job to catch any errors.
198 */ 198 */
@@ -247,27 +247,27 @@ build_name_call(sym_t *sym) @@ -247,27 +247,27 @@ build_name_call(sym_t *sym)
247 */ 247 */
248 if (gflag && is_gcc_bool_builtin(sym->s_name)) 248 if (gflag && is_gcc_bool_builtin(sym->s_name))
249 sym->s_type = gettyp(BOOL); 249 sym->s_type = gettyp(BOOL);
250 250
251 } else if (Sflag) { 251 } else if (Sflag) {
252 /* function '%s' implicitly declared to return int */ 252 /* function '%s' implicitly declared to return int */
253 error(215, sym->s_name); 253 error(215, sym->s_name);
254 } else if (sflag) { 254 } else if (sflag) {
255 /* function '%s' implicitly declared to return int */ 255 /* function '%s' implicitly declared to return int */
256 warning(215, sym->s_name); 256 warning(215, sym->s_name);
257 } 257 }
258 258
259 /* XXX if tflag is set, the symbol should be exported to level 0 */ 259 /* XXX if tflag is set, the symbol should be exported to level 0 */
260 sym->s_type = derive_type(sym->s_type, FUNC); 260 sym->s_type = block_derive_type(sym->s_type, FUNC);
261} 261}
262 262
263/* Create a node for a name (symbol table entry). */ 263/* Create a node for a name (symbol table entry). */
264tnode_t * 264tnode_t *
265build_name(sym_t *sym, bool is_funcname) 265build_name(sym_t *sym, bool is_funcname)
266{ 266{
267 tnode_t *n; 267 tnode_t *n;
268 268
269 if (sym->s_scl == NOSCL) { 269 if (sym->s_scl == NOSCL) {
270 sym->s_scl = EXTERN; 270 sym->s_scl = EXTERN;
271 sym->s_def = DECL; 271 sym->s_def = DECL;
272 if (is_funcname) 272 if (is_funcname)
273 build_name_call(sym); 273 build_name_call(sym);
@@ -4552,27 +4552,27 @@ begin_statement_expr(void) @@ -4552,27 +4552,27 @@ begin_statement_expr(void)
4552{ 4552{
4553 stmt_expr *se = xmalloc(sizeof(*se)); 4553 stmt_expr *se = xmalloc(sizeof(*se));
4554 se->se_mem = expr_save_memory(); 4554 se->se_mem = expr_save_memory();
4555 se->se_sym = NULL; 4555 se->se_sym = NULL;
4556 se->se_enclosing = stmt_exprs; 4556 se->se_enclosing = stmt_exprs;
4557 stmt_exprs = se; 4557 stmt_exprs = se;
4558} 4558}
4559 4559
4560void 4560void
4561do_statement_expr(tnode_t *tn) 4561do_statement_expr(tnode_t *tn)
4562{ 4562{
4563 block_level--; 4563 block_level--;
4564 mem_block_level--; 4564 mem_block_level--;
4565 stmt_exprs->se_sym = mktempsym(dup_type(tn->tn_type)); 4565 stmt_exprs->se_sym = mktempsym(block_dup_type(tn->tn_type));
4566 mem_block_level++; 4566 mem_block_level++;
4567 block_level++; 4567 block_level++;
4568 /* ({ }) is a GCC extension */ 4568 /* ({ }) is a GCC extension */
4569 gnuism(320); 4569 gnuism(320);
4570 4570
4571} 4571}
4572 4572
4573tnode_t * 4573tnode_t *
4574end_statement_expr(void) 4574end_statement_expr(void)
4575{ 4575{
4576 stmt_expr *se = stmt_exprs; 4576 stmt_expr *se = stmt_exprs;
4577 tnode_t *tn = build_name(se->se_sym, false); 4577 tnode_t *tn = build_name(se->se_sym, false);
4578 expr_save_memory(); /* leak */ 4578 expr_save_memory(); /* leak */