Fri Apr 2 09:52:36 2021 UTC ()
lint: rename getnode to expr_zalloc_tnode

The new name highlights that the returned memory is only valid in the
scope of the current expression.  This was misleading before since the
other related functions all have a 't' (probably for 'temporary') in
their names.

Also encode in the function name that the returned memory is zeroed out
as that could not be inferred from the old name.

No functional change.


(rillig)
diff -r1.207 -r1.208 src/usr.bin/xlint/lint1/cgram.y
diff -r1.96 -r1.97 src/usr.bin/xlint/lint1/externs1.h
diff -r1.39 -r1.40 src/usr.bin/xlint/lint1/mem1.c
diff -r1.255 -r1.256 src/usr.bin/xlint/lint1/tree.c

cvs diff -r1.207 -r1.208 src/usr.bin/xlint/lint1/cgram.y (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/cgram.y 2021/03/30 14:25:28 1.207
+++ src/usr.bin/xlint/lint1/cgram.y 2021/04/02 09:52:36 1.208
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1%{ 1%{
2/* $NetBSD: cgram.y,v 1.207 2021/03/30 14:25:28 rillig Exp $ */ 2/* $NetBSD: cgram.y,v 1.208 2021/04/02 09:52:36 rillig Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
6 * Copyright (c) 1994, 1995 Jochen Pohl 6 * Copyright (c) 1994, 1995 Jochen Pohl
7 * All Rights Reserved. 7 * All Rights Reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37#if defined(__RCSID) && !defined(lint) 37#if defined(__RCSID) && !defined(lint)
38__RCSID("$NetBSD: cgram.y,v 1.207 2021/03/30 14:25:28 rillig Exp $"); 38__RCSID("$NetBSD: cgram.y,v 1.208 2021/04/02 09:52:36 rillig Exp $");
39#endif 39#endif
40 40
41#include <limits.h> 41#include <limits.h>
42#include <stdlib.h> 42#include <stdlib.h>
43#include <string.h> 43#include <string.h>
44 44
45#include "lint1.h" 45#include "lint1.h"
46 46
47extern char *yytext; 47extern char *yytext;
48 48
49/* 49/*
50 * Contains the level of current declaration, used for symbol table entries. 50 * Contains the level of current declaration, used for symbol table entries.
51 * 0 is the top-level, > 0 is inside a function body. 51 * 0 is the top-level, > 0 is inside a function body.
@@ -1586,27 +1586,27 @@ expr_statement: @@ -1586,27 +1586,27 @@ expr_statement:
1586 * ({ [[decl-list] stmt-list] }). 1586 * ({ [[decl-list] stmt-list] }).
1587 * XXX: This is not well tested. 1587 * XXX: This is not well tested.
1588 */ 1588 */
1589expr_statement_val: 1589expr_statement_val:
1590 expr T_SEMI { 1590 expr T_SEMI {
1591 /* XXX: We should really do that only on the last name */ 1591 /* XXX: We should really do that only on the last name */
1592 if ($1->tn_op == NAME) 1592 if ($1->tn_op == NAME)
1593 $1->tn_sym->s_used = true; 1593 $1->tn_sym->s_used = true;
1594 $$ = $1; 1594 $$ = $1;
1595 expr($1, false, false, false, false); 1595 expr($1, false, false, false, false);
1596 seen_fallthrough = false; 1596 seen_fallthrough = false;
1597 } 1597 }
1598 | non_expr_statement { 1598 | non_expr_statement {
1599 $$ = getnode(); 1599 $$ = expr_zalloc_tnode();
1600 $$->tn_type = gettyp(VOID); 1600 $$->tn_type = gettyp(VOID);
1601 } 1601 }
1602 ; 1602 ;
1603 1603
1604expr_statement_list: 1604expr_statement_list:
1605 expr_statement_val 1605 expr_statement_val
1606 | expr_statement_list expr_statement_val { 1606 | expr_statement_list expr_statement_val {
1607 $$ = $2; 1607 $$ = $2;
1608 } 1608 }
1609 ; 1609 ;
1610 1610
1611selection_statement: /* C99 6.8.4 */ 1611selection_statement: /* C99 6.8.4 */
1612 if_without_else { 1612 if_without_else {

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

--- src/usr.bin/xlint/lint1/externs1.h 2021/04/02 09:39:25 1.96
+++ src/usr.bin/xlint/lint1/externs1.h 2021/04/02 09:52:36 1.97
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: externs1.h,v 1.96 2021/04/02 09:39:25 rillig Exp $ */ 1/* $NetBSD: externs1.h,v 1.97 2021/04/02 09:52:36 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.
@@ -96,27 +96,27 @@ extern int yylex(void); @@ -96,27 +96,27 @@ extern int yylex(void);
96extern const char *record_filename(const char *, size_t); 96extern const char *record_filename(const char *, size_t);
97extern int get_filename_id(const char *); 97extern int get_filename_id(const char *);
98extern void add_directory_replacement(char *); 98extern void add_directory_replacement(char *);
99extern const char *transform_filename(const char *, size_t); 99extern const char *transform_filename(const char *, size_t);
100 100
101extern void initmem(void); 101extern void initmem(void);
102 102
103extern void *getblk(size_t); 103extern void *getblk(size_t);
104extern void *getlblk(size_t, size_t); 104extern void *getlblk(size_t, size_t);
105extern void freeblk(void); 105extern void freeblk(void);
106extern void freelblk(int); 106extern void freelblk(int);
107 107
108extern void *tgetblk(size_t); 108extern void *tgetblk(size_t);
109extern tnode_t *getnode(void); 109extern tnode_t *expr_zalloc_tnode(void);
110extern void tfreeblk(void); 110extern void tfreeblk(void);
111extern struct memory_block *tsave(void); 111extern struct memory_block *tsave(void);
112extern void trestor(struct memory_block *); 112extern void trestor(struct memory_block *);
113 113
114/* 114/*
115 * err.c 115 * err.c
116 */ 116 */
117extern int nerr; 117extern int nerr;
118extern int sytxerr; 118extern int sytxerr;
119extern const char *msgs[]; 119extern const char *msgs[];
120 120
121extern void msglist(void); 121extern void msglist(void);
122extern void error(int, ...); 122extern void error(int, ...);

cvs diff -r1.39 -r1.40 src/usr.bin/xlint/lint1/mem1.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/mem1.c 2021/04/02 09:45:55 1.39
+++ src/usr.bin/xlint/lint1/mem1.c 2021/04/02 09:52:36 1.40
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: mem1.c,v 1.39 2021/04/02 09:45:55 rillig Exp $ */ 1/* $NetBSD: mem1.c,v 1.40 2021/04/02 09:52:36 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: mem1.c,v 1.39 2021/04/02 09:45:55 rillig Exp $"); 40__RCSID("$NetBSD: mem1.c,v 1.40 2021/04/02 09:52:36 rillig Exp $");
41#endif 41#endif
42 42
43#include <sys/types.h> 43#include <sys/types.h>
44#include <sys/param.h> 44#include <sys/param.h>
45#include <stdlib.h> 45#include <stdlib.h>
46#include <string.h> 46#include <string.h>
47#include <unistd.h> 47#include <unistd.h>
48 48
49#include "lint1.h" 49#include "lint1.h"
50 50
51/* 51/*
52 * Filenames allocated by record_filename are shared. 52 * Filenames allocated by record_filename are shared.
53 */ 53 */
@@ -334,27 +334,27 @@ static memory_block *tmblk; @@ -334,27 +334,27 @@ static memory_block *tmblk;
334/* 334/*
335 * Return zero-initialized memory that is freed at the end of the current 335 * Return zero-initialized memory that is freed at the end of the current
336 * expression. 336 * expression.
337 */ 337 */
338void * 338void *
339tgetblk(size_t s) 339tgetblk(size_t s)
340{ 340{
341 341
342 return xgetblk(&tmblk, s); 342 return xgetblk(&tmblk, s);
343} 343}
344 344
345/* Return a freshly allocated tree node. */ 345/* Return a freshly allocated tree node. */
346tnode_t * 346tnode_t *
347getnode(void) 347expr_zalloc_tnode(void)
348{ 348{
349 tnode_t *tn = tgetblk(sizeof *tn); 349 tnode_t *tn = tgetblk(sizeof *tn);
350 tn->tn_from_system_header = in_system_header; 350 tn->tn_from_system_header = in_system_header;
351 return tn; 351 return tn;
352} 352}
353 353
354/* Free all memory which is allocated by the current expression. */ 354/* Free all memory which is allocated by the current expression. */
355void 355void
356tfreeblk(void) 356tfreeblk(void)
357{ 357{
358 358
359 xfreeblk(&tmblk); 359 xfreeblk(&tmblk);
360} 360}

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

--- src/usr.bin/xlint/lint1/tree.c 2021/04/01 15:06:49 1.255
+++ src/usr.bin/xlint/lint1/tree.c 2021/04/02 09:52:36 1.256
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: tree.c,v 1.255 2021/04/01 15:06:49 rillig Exp $ */ 1/* $NetBSD: tree.c,v 1.256 2021/04/02 09:52:36 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.255 2021/04/01 15:06:49 rillig Exp $"); 40__RCSID("$NetBSD: tree.c,v 1.256 2021/04/02 09:52:36 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 *new_integer_constant_node(tspec_t, int64_t); 53static tnode_t *new_integer_constant_node(tspec_t, int64_t);
@@ -171,43 +171,43 @@ tincref(type_t *tp, tspec_t t) @@ -171,43 +171,43 @@ tincref(type_t *tp, tspec_t t)
171 tp2->t_tspec = t; 171 tp2->t_tspec = t;
172 tp2->t_subt = tp; 172 tp2->t_subt = tp;
173 return tp2; 173 return tp2;
174} 174}
175 175
176/* 176/*
177 * Create a node for a constant. 177 * Create a node for a constant.
178 */ 178 */
179tnode_t * 179tnode_t *
180new_constant_node(type_t *tp, val_t *v) 180new_constant_node(type_t *tp, val_t *v)
181{ 181{
182 tnode_t *n; 182 tnode_t *n;
183 183
184 n = getnode(); 184 n = expr_zalloc_tnode();
185 n->tn_op = CON; 185 n->tn_op = CON;
186 n->tn_type = tp; 186 n->tn_type = tp;
187 n->tn_val = tgetblk(sizeof *n->tn_val); 187 n->tn_val = tgetblk(sizeof *n->tn_val);
188 n->tn_val->v_tspec = tp->t_tspec; 188 n->tn_val->v_tspec = tp->t_tspec;
189 n->tn_val->v_ansiu = v->v_ansiu; 189 n->tn_val->v_ansiu = v->v_ansiu;
190 n->tn_val->v_u = v->v_u; 190 n->tn_val->v_u = v->v_u;
191 free(v); 191 free(v);
192 return n; 192 return n;
193} 193}
194 194
195static tnode_t * 195static tnode_t *
196new_integer_constant_node(tspec_t t, int64_t q) 196new_integer_constant_node(tspec_t t, int64_t q)
197{ 197{
198 tnode_t *n; 198 tnode_t *n;
199 199
200 n = getnode(); 200 n = expr_zalloc_tnode();
201 n->tn_op = CON; 201 n->tn_op = CON;
202 n->tn_type = gettyp(t); 202 n->tn_type = gettyp(t);
203 n->tn_val = tgetblk(sizeof *n->tn_val); 203 n->tn_val = tgetblk(sizeof *n->tn_val);
204 n->tn_val->v_tspec = t; 204 n->tn_val->v_tspec = t;
205 n->tn_val->v_quad = q; 205 n->tn_val->v_quad = q;
206 return n; 206 return n;
207} 207}
208 208
209static void 209static void
210fallback_symbol(sym_t *sym) 210fallback_symbol(sym_t *sym)
211{ 211{
212 212
213 if (Tflag && strcmp(sym->s_name, "__lint_false") == 0) { 213 if (Tflag && strcmp(sym->s_name, "__lint_false") == 0) {
@@ -269,51 +269,51 @@ new_name_node(sym_t *sym, int follow_tok @@ -269,51 +269,51 @@ new_name_node(sym_t *sym, int follow_tok
269 } 269 }
270 /* 270 /*
271 * XXX if tflag is set the symbol should be 271 * XXX if tflag is set the symbol should be
272 * exported to level 0 272 * exported to level 0
273 */ 273 */
274 sym->s_type = incref(sym->s_type, FUNC); 274 sym->s_type = incref(sym->s_type, FUNC);
275 } else { 275 } else {
276 fallback_symbol(sym); 276 fallback_symbol(sym);
277 } 277 }
278 } 278 }
279 279
280 lint_assert(sym->s_kind == FVFT || sym->s_kind == FMEMBER); 280 lint_assert(sym->s_kind == FVFT || sym->s_kind == FMEMBER);
281 281
282 n = getnode(); 282 n = expr_zalloc_tnode();
283 n->tn_type = sym->s_type; 283 n->tn_type = sym->s_type;
284 if (sym->s_scl != CTCONST) { 284 if (sym->s_scl != CTCONST) {
285 n->tn_op = NAME; 285 n->tn_op = NAME;
286 n->tn_sym = sym; 286 n->tn_sym = sym;
287 if (sym->s_kind == FVFT && sym->s_type->t_tspec != FUNC) 287 if (sym->s_kind == FVFT && sym->s_type->t_tspec != FUNC)
288 n->tn_lvalue = true; 288 n->tn_lvalue = true;
289 } else { 289 } else {
290 n->tn_op = CON; 290 n->tn_op = CON;
291 n->tn_val = tgetblk(sizeof *n->tn_val); 291 n->tn_val = tgetblk(sizeof *n->tn_val);
292 *n->tn_val = sym->s_value; 292 *n->tn_val = sym->s_value;
293 } 293 }
294 294
295 return n; 295 return n;
296} 296}
297 297
298tnode_t * 298tnode_t *
299new_string_node(strg_t *strg) 299new_string_node(strg_t *strg)
300{ 300{
301 size_t len; 301 size_t len;
302 tnode_t *n; 302 tnode_t *n;
303 303
304 len = strg->st_len; 304 len = strg->st_len;
305 305
306 n = getnode(); 306 n = expr_zalloc_tnode();
307 307
308 n->tn_op = STRING; 308 n->tn_op = STRING;
309 n->tn_type = tincref(gettyp(strg->st_tspec), ARRAY); 309 n->tn_type = tincref(gettyp(strg->st_tspec), ARRAY);
310 n->tn_type->t_dim = len + 1; 310 n->tn_type->t_dim = len + 1;
311 n->tn_lvalue = true; 311 n->tn_lvalue = true;
312 312
313 n->tn_string = tgetblk(sizeof *n->tn_string); 313 n->tn_string = tgetblk(sizeof *n->tn_string);
314 n->tn_string->st_tspec = strg->st_tspec; 314 n->tn_string->st_tspec = strg->st_tspec;
315 n->tn_string->st_len = len; 315 n->tn_string->st_len = len;
316 316
317 if (strg->st_tspec == CHAR) { 317 if (strg->st_tspec == CHAR) {
318 n->tn_string->st_cp = tgetblk(len + 1); 318 n->tn_string->st_cp = tgetblk(len + 1);
319 (void)memcpy(n->tn_string->st_cp, strg->st_cp, len + 1); 319 (void)memcpy(n->tn_string->st_cp, strg->st_cp, len + 1);
@@ -1799,27 +1799,27 @@ check_enum_int_mismatch(op_t op, int arg @@ -1799,27 +1799,27 @@ check_enum_int_mismatch(op_t op, int arg
1799/* 1799/*
1800 * Build and initialize a new node. 1800 * Build and initialize a new node.
1801 */ 1801 */
1802static tnode_t * 1802static tnode_t *
1803new_tnode(op_t op, type_t *type, tnode_t *ln, tnode_t *rn) 1803new_tnode(op_t op, type_t *type, tnode_t *ln, tnode_t *rn)
1804{ 1804{
1805 tnode_t *ntn; 1805 tnode_t *ntn;
1806 tspec_t t; 1806 tspec_t t;
1807#ifdef notyet 1807#ifdef notyet
1808 size_t l; 1808 size_t l;
1809 uint64_t rnum; 1809 uint64_t rnum;
1810#endif 1810#endif
1811 1811
1812 ntn = getnode(); 1812 ntn = expr_zalloc_tnode();
1813 1813
1814 ntn->tn_op = op; 1814 ntn->tn_op = op;
1815 ntn->tn_type = type; 1815 ntn->tn_type = type;
1816 if (ln->tn_from_system_header) 1816 if (ln->tn_from_system_header)
1817 ntn->tn_from_system_header = true; 1817 ntn->tn_from_system_header = true;
1818 if (rn != NULL && rn->tn_from_system_header) 1818 if (rn != NULL && rn->tn_from_system_header)
1819 ntn->tn_from_system_header = true; 1819 ntn->tn_from_system_header = true;
1820 ntn->tn_left = ln; 1820 ntn->tn_left = ln;
1821 ntn->tn_right = rn; 1821 ntn->tn_right = rn;
1822 1822
1823 switch (op) { 1823 switch (op) {
1824#ifdef notyet 1824#ifdef notyet
1825 case SHR: 1825 case SHR:
@@ -2046,27 +2046,27 @@ convert(op_t op, int arg, type_t *tp, tn @@ -2046,27 +2046,27 @@ convert(op_t op, int arg, type_t *tp, tn
2046 2046
2047 if (!tflag && !sflag && op == FARG) 2047 if (!tflag && !sflag && op == FARG)
2048 check_prototype_conversion(arg, nt, ot, tp, tn); 2048 check_prototype_conversion(arg, nt, ot, tp, tn);
2049 if (is_integer(nt) && is_integer(ot)) { 2049 if (is_integer(nt) && is_integer(ot)) {
2050 check_integer_conversion(op, arg, nt, ot, tp, tn); 2050 check_integer_conversion(op, arg, nt, ot, tp, tn);
2051 } else if (nt == PTR && is_null_pointer(tn)) { 2051 } else if (nt == PTR && is_null_pointer(tn)) {
2052 /* a null pointer may be assigned to any pointer. */ 2052 /* a null pointer may be assigned to any pointer. */
2053 } else if (is_integer(nt) && nt != BOOL && ot == PTR) { 2053 } else if (is_integer(nt) && nt != BOOL && ot == PTR) {
2054 check_pointer_integer_conversion(op, nt, tp, tn); 2054 check_pointer_integer_conversion(op, nt, tp, tn);
2055 } else if (nt == PTR && ot == PTR) { 2055 } else if (nt == PTR && ot == PTR) {
2056 check_pointer_conversion(op, tn, tp); 2056 check_pointer_conversion(op, tn, tp);
2057 } 2057 }
2058 2058
2059 ntn = getnode(); 2059 ntn = expr_zalloc_tnode();
2060 ntn->tn_op = CVT; 2060 ntn->tn_op = CVT;
2061 ntn->tn_type = tp; 2061 ntn->tn_type = tp;
2062 ntn->tn_cast = op == CVT; 2062 ntn->tn_cast = op == CVT;
2063 ntn->tn_from_system_header |= tn->tn_from_system_header; 2063 ntn->tn_from_system_header |= tn->tn_from_system_header;
2064 ntn->tn_right = NULL; 2064 ntn->tn_right = NULL;
2065 if (tn->tn_op != CON || nt == VOID) { 2065 if (tn->tn_op != CON || nt == VOID) {
2066 ntn->tn_left = tn; 2066 ntn->tn_left = tn;
2067 } else { 2067 } else {
2068 ntn->tn_op = CON; 2068 ntn->tn_op = CON;
2069 ntn->tn_val = tgetblk(sizeof *ntn->tn_val); 2069 ntn->tn_val = tgetblk(sizeof *ntn->tn_val);
2070 convert_constant(op, arg, ntn->tn_type, ntn->tn_val, 2070 convert_constant(op, arg, ntn->tn_type, ntn->tn_val,
2071 tn->tn_val); 2071 tn->tn_val);
2072 } 2072 }
@@ -3491,27 +3491,27 @@ cast(tnode_t *tn, type_t *tp) @@ -3491,27 +3491,27 @@ cast(tnode_t *tn, type_t *tp)
3491 * XXX ANSI C requires scalar types or void (Plauger & Brodie). 3491 * XXX ANSI C requires scalar types or void (Plauger & Brodie).
3492 * But this seems really questionable. 3492 * But this seems really questionable.
3493 */ 3493 */
3494 } else if (nt == UNION) { 3494 } else if (nt == UNION) {
3495 sym_t *m; 3495 sym_t *m;
3496 struct_or_union *str = tp->t_str; 3496 struct_or_union *str = tp->t_str;
3497 if (!Sflag) { 3497 if (!Sflag) {
3498 /* union cast is a C9X feature */ 3498 /* union cast is a C9X feature */
3499 error(328); 3499 error(328);
3500 return NULL; 3500 return NULL;
3501 } 3501 }
3502 for (m = str->sou_first_member; m != NULL; m = m->s_next) { 3502 for (m = str->sou_first_member; m != NULL; m = m->s_next) {
3503 if (sametype(m->s_type, tn->tn_type)) { 3503 if (sametype(m->s_type, tn->tn_type)) {
3504 tn = getnode(); 3504 tn = expr_zalloc_tnode();
3505 tn->tn_op = CVT; 3505 tn->tn_op = CVT;
3506 tn->tn_type = tp; 3506 tn->tn_type = tp;
3507 tn->tn_cast = true; 3507 tn->tn_cast = true;
3508 tn->tn_right = NULL; 3508 tn->tn_right = NULL;
3509 return tn; 3509 return tn;
3510 } 3510 }
3511 } 3511 }
3512 /* type '%s' is not a member of '%s' */ 3512 /* type '%s' is not a member of '%s' */
3513 error(329, type_name(tn->tn_type), type_name(tp)); 3513 error(329, type_name(tn->tn_type), type_name(tp));
3514 return NULL; 3514 return NULL;
3515 } else if (nt == STRUCT || nt == ARRAY || nt == FUNC) { 3515 } else if (nt == STRUCT || nt == ARRAY || nt == FUNC) {
3516 if (!Sflag || nt == ARRAY || nt == FUNC) { 3516 if (!Sflag || nt == ARRAY || nt == FUNC) {
3517 /* invalid cast expression */ 3517 /* invalid cast expression */