Sun Jan 3 18:35:51 2021 UTC ()
lint: remove redundant include of externs1.h

It is already included by lint1.h.


(rillig)
diff -r1.7 -r1.8 src/usr.bin/xlint/lint1/print.c
diff -r1.118 -r1.119 src/usr.bin/xlint/lint1/tree.c

cvs diff -r1.7 -r1.8 src/usr.bin/xlint/lint1/Attic/print.c (switch to unified diff)

--- src/usr.bin/xlint/lint1/Attic/print.c 2020/12/30 10:56:51 1.7
+++ src/usr.bin/xlint/lint1/Attic/print.c 2021/01/03 18:35:51 1.8
@@ -1,154 +1,153 @@ @@ -1,154 +1,153 @@
1/* $NetBSD: print.c,v 1.7 2020/12/30 10:56:51 rillig Exp $ */ 1/* $NetBSD: print.c,v 1.8 2021/01/03 18:35:51 rillig Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas. 8 * by Christos Zoulas.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#if HAVE_NBTOOL_CONFIG_H 32#if HAVE_NBTOOL_CONFIG_H
33#include "nbtool_config.h" 33#include "nbtool_config.h"
34#endif 34#endif
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37#ifndef lint 37#ifndef lint
38__RCSID("$NetBSD: print.c,v 1.7 2020/12/30 10:56:51 rillig Exp $"); 38__RCSID("$NetBSD: print.c,v 1.8 2021/01/03 18:35:51 rillig Exp $");
39#endif 39#endif
40 40
41#include <stdio.h> 41#include <stdio.h>
42 42
43#include "lint1.h" 43#include "lint1.h"
44#include "externs1.h" 
45 44
46static const char *str_op_t[] = 45static const char *str_op_t[] =
47{ 46{
48 "*noop*", 47 "*noop*",
49 "->", 48 "->",
50 ".", 49 ".",
51 "!", 50 "!",
52 "~", 51 "~",
53 "++", 52 "++",
54 "--", 53 "--",
55 "++<", 54 "++<",
56 "--<", 55 "--<",
57 "++>", 56 "++>",
58 "-->", 57 "-->",
59 "+", 58 "+",
60 "-", 59 "-",
61 "*", 60 "*",
62 "&", 61 "&",
63 "*", 62 "*",
64 "/", 63 "/",
65 "%", 64 "%",
66 "+", 65 "+",
67 "-", 66 "-",
68 "<<", 67 "<<",
69 ">>", 68 ">>",
70 "<", 69 "<",
71 "<=", 70 "<=",
72 ">", 71 ">",
73 ">=", 72 ">=",
74 "==", 73 "==",
75 "!=", 74 "!=",
76 "&", 75 "&",
77 "^", 76 "^",
78 "|", 77 "|",
79 "&&", 78 "&&",
80 "||", 79 "||",
81 "?", 80 "?",
82 ":", 81 ":",
83 "=", 82 "=",
84 "*=", 83 "*=",
85 "/=", 84 "/=",
86 "%=", 85 "%=",
87 "+=", 86 "+=",
88 "-=", 87 "-=",
89 "<<=", 88 "<<=",
90 ">>=", 89 ">>=",
91 "&=", 90 "&=",
92 "^=", 91 "^=",
93 "|=", 92 "|=",
94 "*name*", 93 "*name*",
95 "*constant*", 94 "*constant*",
96 "*string*", 95 "*string*",
97 "*field select*", 96 "*field select*",
98 "*call*", 97 "*call*",
99 ",", 98 ",",
100 "*(cast)*", 99 "*(cast)*",
101 "*icall*", 100 "*icall*",
102 "*load*", 101 "*load*",
103 "*push*", 102 "*push*",
104 "return", 103 "return",
105 "*init*", 104 "*init*",
106 "*case*", 105 "*case*",
107 "*farg*", 106 "*farg*",
108}; 107};
109 108
110char * 109char *
111print_tnode(char *buf, size_t bufsiz, const tnode_t *tn) 110print_tnode(char *buf, size_t bufsiz, const tnode_t *tn)
112{ 111{
113 strg_t *st; 112 strg_t *st;
114 val_t *v; 113 val_t *v;
115 sym_t *s; 114 sym_t *s;
116 switch (tn->tn_op) { 115 switch (tn->tn_op) {
117 case NAME: 116 case NAME:
118 s = tn->tn_sym; 117 s = tn->tn_sym;
119 (void)snprintf(buf, bufsiz, "%s", s->s_name); 118 (void)snprintf(buf, bufsiz, "%s", s->s_name);
120 break; 119 break;
121 case CON: 120 case CON:
122 v = tn->tn_val; 121 v = tn->tn_val;
123 switch (v->v_tspec) { 122 switch (v->v_tspec) {
124 case FLOAT: 123 case FLOAT:
125 case DOUBLE: 124 case DOUBLE:
126 case LDOUBLE: 125 case LDOUBLE:
127 (void)snprintf(buf, bufsiz, "%Lg", v->v_ldbl); 126 (void)snprintf(buf, bufsiz, "%Lg", v->v_ldbl);
128 break; 127 break;
129 default: 128 default:
130 (void)snprintf(buf, bufsiz, v->v_ansiu ? "%llu" : 129 (void)snprintf(buf, bufsiz, v->v_ansiu ? "%llu" :
131 "%lld", (unsigned long long)v->v_quad); 130 "%lld", (unsigned long long)v->v_quad);
132 break; 131 break;
133 } 132 }
134 break; 133 break;
135 134
136 case STRING: 135 case STRING:
137 st = tn->tn_string; 136 st = tn->tn_string;
138 switch (st->st_tspec) { 137 switch (st->st_tspec) {
139 case CHAR: 138 case CHAR:
140 case SCHAR: 139 case SCHAR:
141 case UCHAR: 140 case UCHAR:
142 (void)snprintf(buf, bufsiz, "\"%s\"", st->st_cp); 141 (void)snprintf(buf, bufsiz, "\"%s\"", st->st_cp);
143 break; 142 break;
144 default: 143 default:
145 (void)snprintf(buf, bufsiz, "\"*wide string*\""); 144 (void)snprintf(buf, bufsiz, "\"*wide string*\"");
146 break; 145 break;
147 } 146 }
148 break; 147 break;
149 default: 148 default:
150 (void)snprintf(buf, bufsiz, "%s", str_op_t[tn->tn_op]); 149 (void)snprintf(buf, bufsiz, "%s", str_op_t[tn->tn_op]);
151 break; 150 break;
152 } 151 }
153 return buf; 152 return buf;
154} 153}

cvs diff -r1.118 -r1.119 src/usr.bin/xlint/lint1/tree.c (switch to unified diff)

--- src/usr.bin/xlint/lint1/tree.c 2021/01/03 17:42:45 1.118
+++ src/usr.bin/xlint/lint1/tree.c 2021/01/03 18:35:51 1.119
@@ -1,1051 +1,1050 @@ @@ -1,1051 +1,1050 @@
1/* $NetBSD: tree.c,v 1.118 2021/01/03 17:42:45 rillig Exp $ */ 1/* $NetBSD: tree.c,v 1.119 2021/01/03 18:35:51 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.
15 * 3. All advertising materials mentioning features or use of this software 15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement: 16 * must display the following acknowledgement:
17 * This product includes software developed by Jochen Pohl for 17 * This product includes software developed by Jochen Pohl for
18 * The NetBSD Project. 18 * The NetBSD Project.
19 * 4. The name of the author may not be used to endorse or promote products 19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission. 20 * derived from this software without specific prior written permission.
21 * 21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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.118 2021/01/03 17:42:45 rillig Exp $"); 40__RCSID("$NetBSD: tree.c,v 1.119 2021/01/03 18:35:51 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#include "externs1.h" 
53 52
54static tnode_t *new_int_const_node(tspec_t, int64_t); 53static tnode_t *new_int_const_node(tspec_t, int64_t);
55static void check_pointer_comparison(op_t, tnode_t *, tnode_t *); 54static void check_pointer_comparison(op_t, tnode_t *, tnode_t *);
56static int check_assign_types_compatible(op_t, int, tnode_t *, tnode_t *); 55static int check_assign_types_compatible(op_t, int, tnode_t *, tnode_t *);
57static void check_bad_enum_operation(op_t, tnode_t *, tnode_t *); 56static void check_bad_enum_operation(op_t, tnode_t *, tnode_t *);
58static void check_enum_type_mismatch(op_t, int, tnode_t *, tnode_t *); 57static void check_enum_type_mismatch(op_t, int, tnode_t *, tnode_t *);
59static void check_enum_int_mismatch(op_t, int, tnode_t *, tnode_t *); 58static void check_enum_int_mismatch(op_t, int, tnode_t *, tnode_t *);
60static tnode_t *new_tnode(op_t, type_t *, tnode_t *, tnode_t *); 59static tnode_t *new_tnode(op_t, type_t *, tnode_t *, tnode_t *);
61static void balance(op_t, tnode_t **, tnode_t **); 60static void balance(op_t, tnode_t **, tnode_t **);
62static void warn_incompatible_types(op_t, tspec_t, tspec_t); 61static void warn_incompatible_types(op_t, tspec_t, tspec_t);
63static void warn_incompatible_pointers(mod_t *, type_t *, type_t *); 62static void warn_incompatible_pointers(mod_t *, type_t *, type_t *);
64static void merge_qualifiers(type_t **, type_t *, type_t *); 63static void merge_qualifiers(type_t **, type_t *, type_t *);
65static int has_constant_member(type_t *); 64static int has_constant_member(type_t *);
66static void check_prototype_conversion(int, tspec_t, tspec_t, type_t *, 65static void check_prototype_conversion(int, tspec_t, tspec_t, type_t *,
67 tnode_t *); 66 tnode_t *);
68static void check_integer_conversion(op_t, int, tspec_t, tspec_t, type_t *, 67static void check_integer_conversion(op_t, int, tspec_t, tspec_t, type_t *,
69 tnode_t *); 68 tnode_t *);
70static void check_pointer_integer_conversion(op_t, tspec_t, type_t *, 69static void check_pointer_integer_conversion(op_t, tspec_t, type_t *,
71 tnode_t *); 70 tnode_t *);
72static void check_pointer_conversion(op_t, tnode_t *, type_t *); 71static void check_pointer_conversion(op_t, tnode_t *, type_t *);
73static tnode_t *build_struct_access(op_t, tnode_t *, tnode_t *); 72static tnode_t *build_struct_access(op_t, tnode_t *, tnode_t *);
74static tnode_t *build_prepost_incdec(op_t, tnode_t *); 73static tnode_t *build_prepost_incdec(op_t, tnode_t *);
75static tnode_t *build_real_imag(op_t, tnode_t *); 74static tnode_t *build_real_imag(op_t, tnode_t *);
76static tnode_t *build_ampersand(tnode_t *, int); 75static tnode_t *build_ampersand(tnode_t *, int);
77static tnode_t *build_plus_minus(op_t, tnode_t *, tnode_t *); 76static tnode_t *build_plus_minus(op_t, tnode_t *, tnode_t *);
78static tnode_t *build_bit_shift(op_t, tnode_t *, tnode_t *); 77static tnode_t *build_bit_shift(op_t, tnode_t *, tnode_t *);
79static tnode_t *build_colon(tnode_t *, tnode_t *); 78static tnode_t *build_colon(tnode_t *, tnode_t *);
80static tnode_t *build_assignment(op_t, tnode_t *, tnode_t *); 79static tnode_t *build_assignment(op_t, tnode_t *, tnode_t *);
81static tnode_t *plength(type_t *); 80static tnode_t *plength(type_t *);
82static tnode_t *fold(tnode_t *); 81static tnode_t *fold(tnode_t *);
83static tnode_t *fold_test(tnode_t *); 82static tnode_t *fold_test(tnode_t *);
84static tnode_t *fold_float(tnode_t *); 83static tnode_t *fold_float(tnode_t *);
85static tnode_t *check_function_arguments(type_t *, tnode_t *); 84static tnode_t *check_function_arguments(type_t *, tnode_t *);
86static tnode_t *check_prototype_argument(int, type_t *, tnode_t *); 85static tnode_t *check_prototype_argument(int, type_t *, tnode_t *);
87static void check_null_effect(tnode_t *); 86static void check_null_effect(tnode_t *);
88static void display_expression(tnode_t *, int); 87static void display_expression(tnode_t *, int);
89static void check_array_index(tnode_t *, int); 88static void check_array_index(tnode_t *, int);
90static void check_integer_comparison(op_t, tnode_t *, tnode_t *); 89static void check_integer_comparison(op_t, tnode_t *, tnode_t *);
91static void check_precedence_confusion(tnode_t *); 90static void check_precedence_confusion(tnode_t *);
92 91
93extern sig_atomic_t fpe; 92extern sig_atomic_t fpe;
94 93
95#if 0 94#if 0
96static char * 95static char *
97dumpnode(char *buf, size_t len, tnode_t *tn) { 96dumpnode(char *buf, size_t len, tnode_t *tn) {
98 const char *n = getopname(tn->tn_op); 97 const char *n = getopname(tn->tn_op);
99 const char *s; 98 const char *s;
100 99
101 switch (tn->tn_op) { 100 switch (tn->tn_op) {
102 case NAME: 101 case NAME:
103 s = tn->tn_sym->s_name; 102 s = tn->tn_sym->s_name;
104 break; 103 break;
105 case CON: 104 case CON:
106 case STRING: 105 case STRING:
107 s = "*"; /* todo */ 106 s = "*"; /* todo */
108 break; 107 break;
109 default: 108 default:
110 s = NULL; 109 s = NULL;
111 break; 110 break;
112 } 111 }
113 char lb[1024]; 112 char lb[1024];
114 char rb[1024]; 113 char rb[1024];
115 114
116 if (s == NULL && tn->tn_left != NULL) 115 if (s == NULL && tn->tn_left != NULL)
117 dumpnode(lb, sizeof(lb), tn->tn_left); 116 dumpnode(lb, sizeof(lb), tn->tn_left);
118 else 117 else
119 strcpy(lb, "(null)"); 118 strcpy(lb, "(null)");
120 119
121 if (s == NULL && tn->tn_right != NULL) 120 if (s == NULL && tn->tn_right != NULL)
122 dumpnode(rb, sizeof(rb), tn->tn_right); 121 dumpnode(rb, sizeof(rb), tn->tn_right);
123 else 122 else
124 strcpy(rb, "(null)"); 123 strcpy(rb, "(null)");
125 124
126 125
127 snprintf(buf, len, "%s: (%s) = %s [%s, %s]", n, 126 snprintf(buf, len, "%s: (%s) = %s [%s, %s]", n,
128 type_name(tn->tn_type), s, lb, rb); 127 type_name(tn->tn_type), s, lb, rb);
129 return buf; 128 return buf;
130} 129}
131#endif 130#endif
132 131
133/* 132/*
134 * Increase degree of reference. 133 * Increase degree of reference.
135 * This is most often used to change type "T" in type "pointer to T". 134 * This is most often used to change type "T" in type "pointer to T".
136 */ 135 */
137type_t * 136type_t *
138incref(type_t *tp, tspec_t t) 137incref(type_t *tp, tspec_t t)
139{ 138{
140 type_t *tp2; 139 type_t *tp2;
141 140
142 tp2 = getblk(sizeof (type_t)); 141 tp2 = getblk(sizeof (type_t));
143 tp2->t_tspec = t; 142 tp2->t_tspec = t;
144 tp2->t_subt = tp; 143 tp2->t_subt = tp;
145 return tp2; 144 return tp2;
146} 145}
147 146
148/* 147/*
149 * same for use in expressions 148 * same for use in expressions
150 */ 149 */
151type_t * 150type_t *
152tincref(type_t *tp, tspec_t t) 151tincref(type_t *tp, tspec_t t)
153{ 152{
154 type_t *tp2; 153 type_t *tp2;
155 154
156 tp2 = tgetblk(sizeof (type_t)); 155 tp2 = tgetblk(sizeof (type_t));
157 tp2->t_tspec = t; 156 tp2->t_tspec = t;
158 tp2->t_subt = tp; 157 tp2->t_subt = tp;
159 return tp2; 158 return tp2;
160} 159}
161 160
162/* 161/*
163 * Create a node for a constant. 162 * Create a node for a constant.
164 */ 163 */
165tnode_t * 164tnode_t *
166getcnode(type_t *tp, val_t *v) 165getcnode(type_t *tp, val_t *v)
167{ 166{
168 tnode_t *n; 167 tnode_t *n;
169 168
170 n = getnode(); 169 n = getnode();
171 n->tn_op = CON; 170 n->tn_op = CON;
172 n->tn_type = tp; 171 n->tn_type = tp;
173 n->tn_val = tgetblk(sizeof (val_t)); 172 n->tn_val = tgetblk(sizeof (val_t));
174 n->tn_val->v_tspec = tp->t_tspec; 173 n->tn_val->v_tspec = tp->t_tspec;
175 n->tn_val->v_ansiu = v->v_ansiu; 174 n->tn_val->v_ansiu = v->v_ansiu;
176 n->tn_val->v_u = v->v_u; 175 n->tn_val->v_u = v->v_u;
177 free(v); 176 free(v);
178 return n; 177 return n;
179} 178}
180 179
181/* 180/*
182 * Create a node for a integer constant. 181 * Create a node for a integer constant.
183 */ 182 */
184static tnode_t * 183static tnode_t *
185new_int_const_node(tspec_t t, int64_t q) 184new_int_const_node(tspec_t t, int64_t q)
186{ 185{
187 tnode_t *n; 186 tnode_t *n;
188 187
189 n = getnode(); 188 n = getnode();
190 n->tn_op = CON; 189 n->tn_op = CON;
191 n->tn_type = gettyp(t); 190 n->tn_type = gettyp(t);
192 n->tn_val = tgetblk(sizeof (val_t)); 191 n->tn_val = tgetblk(sizeof (val_t));
193 n->tn_val->v_tspec = t; 192 n->tn_val->v_tspec = t;
194 n->tn_val->v_quad = q; 193 n->tn_val->v_quad = q;
195 return n; 194 return n;
196} 195}
197 196
198/* 197/*
199 * Create a node for a name (symbol table entry). 198 * Create a node for a name (symbol table entry).
200 * ntok is the token which follows the name. 199 * ntok is the token which follows the name.
201 */ 200 */
202tnode_t * 201tnode_t *
203getnnode(sym_t *sym, int ntok) 202getnnode(sym_t *sym, int ntok)
204{ 203{
205 tnode_t *n; 204 tnode_t *n;
206 205
207 if (sym->s_scl == NOSCL) { 206 if (sym->s_scl == NOSCL) {
208 sym->s_scl = EXTERN; 207 sym->s_scl = EXTERN;
209 sym->s_def = DECL; 208 sym->s_def = DECL;
210 if (ntok == T_LPAREN) { 209 if (ntok == T_LPAREN) {
211 if (sflag) { 210 if (sflag) {
212 /* function implicitly declared to ... */ 211 /* function implicitly declared to ... */
213 warning(215); 212 warning(215);
214 } 213 }
215 /* 214 /*
216 * XXX if tflag is set the symbol should be 215 * XXX if tflag is set the symbol should be
217 * exported to level 0 216 * exported to level 0
218 */ 217 */
219 sym->s_type = incref(sym->s_type, FUNC); 218 sym->s_type = incref(sym->s_type, FUNC);
220 } else { 219 } else {
221 if (!blklev) { 220 if (!blklev) {
222 /* %s undefined */ 221 /* %s undefined */
223 error(99, sym->s_name); 222 error(99, sym->s_name);
224 } else { 223 } else {
225 int fixtype; 224 int fixtype;
226 if (strcmp(sym->s_name, "__FUNCTION__") == 0 || 225 if (strcmp(sym->s_name, "__FUNCTION__") == 0 ||
227 strcmp(sym->s_name, "__PRETTY_FUNCTION__") 226 strcmp(sym->s_name, "__PRETTY_FUNCTION__")
228 == 0) { 227 == 0) {
229 /* __FUNCTION__/__PRETTY_FUNCTION... */ 228 /* __FUNCTION__/__PRETTY_FUNCTION... */
230 gnuism(316); 229 gnuism(316);
231 fixtype = 1; 230 fixtype = 1;
232 } else if (strcmp(sym->s_name, "__func__") == 0) { 231 } else if (strcmp(sym->s_name, "__func__") == 0) {
233 if (!Sflag) 232 if (!Sflag)
234 /* __func__ is a C9X feature */ 233 /* __func__ is a C9X feature */
235 warning(317); 234 warning(317);
236 fixtype = 1; 235 fixtype = 1;
237 } else { 236 } else {
238 /* %s undefined */ 237 /* %s undefined */
239 error(99, sym->s_name); 238 error(99, sym->s_name);
240 fixtype = 0; 239 fixtype = 0;
241 } 240 }
242 if (fixtype) { 241 if (fixtype) {
243 sym->s_type = incref(gettyp(CHAR), PTR); 242 sym->s_type = incref(gettyp(CHAR), PTR);
244 sym->s_type->t_const = 1; 243 sym->s_type->t_const = 1;
245 } 244 }
246 } 245 }
247 } 246 }
248 } 247 }
249 248
250 if (sym->s_kind != FVFT && sym->s_kind != FMEMBER) 249 if (sym->s_kind != FVFT && sym->s_kind != FMEMBER)
251 LERROR("getnnode(%d)", sym->s_kind); 250 LERROR("getnnode(%d)", sym->s_kind);
252 251
253 n = getnode(); 252 n = getnode();
254 n->tn_type = sym->s_type; 253 n->tn_type = sym->s_type;
255 if (sym->s_scl != ENUMCON) { 254 if (sym->s_scl != ENUMCON) {
256 n->tn_op = NAME; 255 n->tn_op = NAME;
257 n->tn_sym = sym; 256 n->tn_sym = sym;
258 if (sym->s_kind == FVFT && sym->s_type->t_tspec != FUNC) 257 if (sym->s_kind == FVFT && sym->s_type->t_tspec != FUNC)
259 n->tn_lvalue = 1; 258 n->tn_lvalue = 1;
260 } else { 259 } else {
261 n->tn_op = CON; 260 n->tn_op = CON;
262 n->tn_val = tgetblk(sizeof (val_t)); 261 n->tn_val = tgetblk(sizeof (val_t));
263 *n->tn_val = sym->s_value; 262 *n->tn_val = sym->s_value;
264 } 263 }
265 264
266 return n; 265 return n;
267} 266}
268 267
269/* 268/*
270 * Create a node for a string. 269 * Create a node for a string.
271 */ 270 */
272tnode_t * 271tnode_t *
273getsnode(strg_t *strg) 272getsnode(strg_t *strg)
274{ 273{
275 size_t len; 274 size_t len;
276 tnode_t *n; 275 tnode_t *n;
277 276
278 len = strg->st_len; 277 len = strg->st_len;
279 278
280 n = getnode(); 279 n = getnode();
281 280
282 n->tn_op = STRING; 281 n->tn_op = STRING;
283 n->tn_type = tincref(gettyp(strg->st_tspec), ARRAY); 282 n->tn_type = tincref(gettyp(strg->st_tspec), ARRAY);
284 n->tn_type->t_dim = len + 1; 283 n->tn_type->t_dim = len + 1;
285 n->tn_lvalue = 1; 284 n->tn_lvalue = 1;
286 285
287 n->tn_string = tgetblk(sizeof (strg_t)); 286 n->tn_string = tgetblk(sizeof (strg_t));
288 n->tn_string->st_tspec = strg->st_tspec; 287 n->tn_string->st_tspec = strg->st_tspec;
289 n->tn_string->st_len = len; 288 n->tn_string->st_len = len;
290 289
291 if (strg->st_tspec == CHAR) { 290 if (strg->st_tspec == CHAR) {
292 n->tn_string->st_cp = tgetblk(len + 1); 291 n->tn_string->st_cp = tgetblk(len + 1);
293 (void)memcpy(n->tn_string->st_cp, strg->st_cp, len + 1); 292 (void)memcpy(n->tn_string->st_cp, strg->st_cp, len + 1);
294 free(strg->st_cp); 293 free(strg->st_cp);
295 } else { 294 } else {
296 n->tn_string->st_wcp = tgetblk((len + 1) * sizeof (wchar_t)); 295 n->tn_string->st_wcp = tgetblk((len + 1) * sizeof (wchar_t));
297 (void)memcpy(n->tn_string->st_wcp, strg->st_wcp, 296 (void)memcpy(n->tn_string->st_wcp, strg->st_wcp,
298 (len + 1) * sizeof (wchar_t)); 297 (len + 1) * sizeof (wchar_t));
299 free(strg->st_wcp); 298 free(strg->st_wcp);
300 } 299 }
301 free(strg); 300 free(strg);
302 301
303 return n; 302 return n;
304} 303}
305 304
306/* 305/*
307 * Returns a symbol which has the same name as the msym argument and is a 306 * Returns a symbol which has the same name as the msym argument and is a
308 * member of the struct or union specified by the tn argument. 307 * member of the struct or union specified by the tn argument.
309 */ 308 */
310sym_t * 309sym_t *
311struct_or_union_member(tnode_t *tn, op_t op, sym_t *msym) 310struct_or_union_member(tnode_t *tn, op_t op, sym_t *msym)
312{ 311{
313 str_t *str; 312 str_t *str;
314 type_t *tp; 313 type_t *tp;
315 sym_t *sym, *csym; 314 sym_t *sym, *csym;
316 int eq; 315 int eq;
317 tspec_t t; 316 tspec_t t;
318 317
319 /* 318 /*
320 * Remove the member if it was unknown until now (Which means 319 * Remove the member if it was unknown until now (Which means
321 * that no defined struct or union has a member with the same name). 320 * that no defined struct or union has a member with the same name).
322 */ 321 */
323 if (msym->s_scl == NOSCL) { 322 if (msym->s_scl == NOSCL) {
324 /* undefined struct/union member: %s */ 323 /* undefined struct/union member: %s */
325 error(101, msym->s_name); 324 error(101, msym->s_name);
326 rmsym(msym); 325 rmsym(msym);
327 msym->s_kind = FMEMBER; 326 msym->s_kind = FMEMBER;
328 msym->s_scl = MOS; 327 msym->s_scl = MOS;
329 msym->s_styp = tgetblk(sizeof (str_t)); 328 msym->s_styp = tgetblk(sizeof (str_t));
330 msym->s_styp->stag = tgetblk(sizeof (sym_t)); 329 msym->s_styp->stag = tgetblk(sizeof (sym_t));
331 msym->s_styp->stag->s_name = unnamed; 330 msym->s_styp->stag->s_name = unnamed;
332 msym->s_value.v_tspec = INT; 331 msym->s_value.v_tspec = INT;
333 return msym; 332 return msym;
334 } 333 }
335 334
336 /* Set str to the tag of which msym is expected to be a member. */ 335 /* Set str to the tag of which msym is expected to be a member. */
337 str = NULL; 336 str = NULL;
338 t = (tp = tn->tn_type)->t_tspec; 337 t = (tp = tn->tn_type)->t_tspec;
339 if (op == POINT) { 338 if (op == POINT) {
340 if (t == STRUCT || t == UNION) 339 if (t == STRUCT || t == UNION)
341 str = tp->t_str; 340 str = tp->t_str;
342 } else if (op == ARROW && t == PTR) { 341 } else if (op == ARROW && t == PTR) {
343 t = (tp = tp->t_subt)->t_tspec; 342 t = (tp = tp->t_subt)->t_tspec;
344 if (t == STRUCT || t == UNION) 343 if (t == STRUCT || t == UNION)
345 str = tp->t_str; 344 str = tp->t_str;
346 } 345 }
347 346
348 /* 347 /*
349 * If this struct/union has a member with the name of msym, return 348 * If this struct/union has a member with the name of msym, return
350 * return this it. 349 * return this it.
351 */ 350 */
352 if (str != NULL) { 351 if (str != NULL) {
353 for (sym = msym; sym != NULL; sym = sym->s_link) { 352 for (sym = msym; sym != NULL; sym = sym->s_link) {
354 if (sym->s_scl != MOS && sym->s_scl != MOU) 353 if (sym->s_scl != MOS && sym->s_scl != MOU)
355 continue; 354 continue;
356 if (sym->s_styp != str) 355 if (sym->s_styp != str)
357 continue; 356 continue;
358 if (strcmp(sym->s_name, msym->s_name) != 0) 357 if (strcmp(sym->s_name, msym->s_name) != 0)
359 continue; 358 continue;
360 return sym; 359 return sym;
361 } 360 }
362 } 361 }
363 362
364 /* 363 /*
365 * Set eq to 0 if there are struct/union members with the same name 364 * Set eq to 0 if there are struct/union members with the same name
366 * and different types and/or offsets. 365 * and different types and/or offsets.
367 */ 366 */
368 eq = 1; 367 eq = 1;
369 for (csym = msym; csym != NULL; csym = csym->s_link) { 368 for (csym = msym; csym != NULL; csym = csym->s_link) {
370 if (csym->s_scl != MOS && csym->s_scl != MOU) 369 if (csym->s_scl != MOS && csym->s_scl != MOU)
371 continue; 370 continue;
372 if (strcmp(msym->s_name, csym->s_name) != 0) 371 if (strcmp(msym->s_name, csym->s_name) != 0)
373 continue; 372 continue;
374 for (sym = csym->s_link ; sym != NULL; sym = sym->s_link) { 373 for (sym = csym->s_link ; sym != NULL; sym = sym->s_link) {
375 int w; 374 int w;
376 375
377 if (sym->s_scl != MOS && sym->s_scl != MOU) 376 if (sym->s_scl != MOS && sym->s_scl != MOU)
378 continue; 377 continue;
379 if (strcmp(csym->s_name, sym->s_name) != 0) 378 if (strcmp(csym->s_name, sym->s_name) != 0)
380 continue; 379 continue;
381 if (csym->s_value.v_quad != sym->s_value.v_quad) { 380 if (csym->s_value.v_quad != sym->s_value.v_quad) {
382 eq = 0; 381 eq = 0;
383 break; 382 break;
384 } 383 }
385 w = 0; 384 w = 0;
386 eq = eqtype(csym->s_type, sym->s_type, 0, 0, &w) && !w; 385 eq = eqtype(csym->s_type, sym->s_type, 0, 0, &w) && !w;
387 if (!eq) 386 if (!eq)
388 break; 387 break;
389 if (csym->s_bitfield != sym->s_bitfield) { 388 if (csym->s_bitfield != sym->s_bitfield) {
390 eq = 0; 389 eq = 0;
391 break; 390 break;
392 } 391 }
393 if (csym->s_bitfield) { 392 if (csym->s_bitfield) {
394 type_t *tp1, *tp2; 393 type_t *tp1, *tp2;
395 394
396 tp1 = csym->s_type; 395 tp1 = csym->s_type;
397 tp2 = sym->s_type; 396 tp2 = sym->s_type;
398 if (tp1->t_flen != tp2->t_flen) { 397 if (tp1->t_flen != tp2->t_flen) {
399 eq = 0; 398 eq = 0;
400 break; 399 break;
401 } 400 }
402 if (tp1->t_foffs != tp2->t_foffs) { 401 if (tp1->t_foffs != tp2->t_foffs) {
403 eq = 0; 402 eq = 0;
404 break; 403 break;
405 } 404 }
406 } 405 }
407 } 406 }
408 if (!eq) 407 if (!eq)
409 break; 408 break;
410 } 409 }
411 410
412 /* 411 /*
413 * Now handle the case in which the left operand refers really 412 * Now handle the case in which the left operand refers really
414 * to a struct/union, but the right operand is not member of it. 413 * to a struct/union, but the right operand is not member of it.
415 */ 414 */
416 if (str != NULL) { 415 if (str != NULL) {
417 if (eq && tflag) { 416 if (eq && tflag) {
418 /* illegal member use: %s */ 417 /* illegal member use: %s */
419 warning(102, msym->s_name); 418 warning(102, msym->s_name);
420 } else { 419 } else {
421 /* illegal member use: %s */ 420 /* illegal member use: %s */
422 error(102, msym->s_name); 421 error(102, msym->s_name);
423 } 422 }
424 return msym; 423 return msym;
425 } 424 }
426 425
427 /* 426 /*
428 * Now the left operand of ARROW does not point to a struct/union 427 * Now the left operand of ARROW does not point to a struct/union
429 * or the left operand of POINT is no struct/union. 428 * or the left operand of POINT is no struct/union.
430 */ 429 */
431 if (eq) { 430 if (eq) {
432 if (op == POINT) { 431 if (op == POINT) {
433 if (tflag) { 432 if (tflag) {
434 /* left operand of '.' must be struct/... */ 433 /* left operand of '.' must be struct/... */
435 warning(103); 434 warning(103);
436 } else { 435 } else {
437 /* left operand of '.' must be struct/... */ 436 /* left operand of '.' must be struct/... */
438 error(103); 437 error(103);
439 } 438 }
440 } else { 439 } else {
441 /* left operand of "->" must be pointer to ... */ 440 /* left operand of "->" must be pointer to ... */
442 if (tflag && tn->tn_type->t_tspec == PTR) { 441 if (tflag && tn->tn_type->t_tspec == PTR) {
443 /* left operand of '->' must be pointer ... */ 442 /* left operand of '->' must be pointer ... */
444 warning(104, type_name(tn->tn_type)); 443 warning(104, type_name(tn->tn_type));
445 } else { 444 } else {
446 /* left operand of '->' must be pointer ... */ 445 /* left operand of '->' must be pointer ... */
447 error(104, type_name(tn->tn_type)); 446 error(104, type_name(tn->tn_type));
448 } 447 }
449 } 448 }
450 } else { 449 } else {
451 if (tflag) { 450 if (tflag) {
452 /* non-unique member requires struct/union %s */ 451 /* non-unique member requires struct/union %s */
453 error(105, op == POINT ? "object" : "pointer"); 452 error(105, op == POINT ? "object" : "pointer");
454 } else { 453 } else {
455 /* unacceptable operand of '%s' */ 454 /* unacceptable operand of '%s' */
456 error(111, modtab[op].m_name); 455 error(111, modtab[op].m_name);
457 } 456 }
458 } 457 }
459 458
460 return msym; 459 return msym;
461} 460}
462 461
463/* 462/*
464 * Create a tree node. Called for most operands except function calls, 463 * Create a tree node. Called for most operands except function calls,
465 * sizeof and casts. 464 * sizeof and casts.
466 * 465 *
467 * op operator 466 * op operator
468 * ln left operand 467 * ln left operand
469 * rn if not NULL, right operand 468 * rn if not NULL, right operand
470 */ 469 */
471tnode_t * 470tnode_t *
472build(op_t op, tnode_t *ln, tnode_t *rn) 471build(op_t op, tnode_t *ln, tnode_t *rn)
473{ 472{
474 mod_t *mp; 473 mod_t *mp;
475 tnode_t *ntn; 474 tnode_t *ntn;
476 type_t *rtp; 475 type_t *rtp;
477 476
478 mp = &modtab[op]; 477 mp = &modtab[op];
479 478
480 /* If there was an error in one of the operands, return. */ 479 /* If there was an error in one of the operands, return. */
481 if (ln == NULL || (mp->m_binary && rn == NULL)) 480 if (ln == NULL || (mp->m_binary && rn == NULL))
482 return NULL; 481 return NULL;
483 482
484 /* 483 /*
485 * Apply class conversions to the left operand, but only if its 484 * Apply class conversions to the left operand, but only if its
486 * value is needed or it is compared with null. 485 * value is needed or it is compared with null.
487 */ 486 */
488 if (mp->m_vctx || mp->m_tctx) 487 if (mp->m_vctx || mp->m_tctx)
489 ln = cconv(ln); 488 ln = cconv(ln);
490 /* 489 /*
491 * The right operand is almost always in a test or value context, 490 * The right operand is almost always in a test or value context,
492 * except if it is a struct or union member. 491 * except if it is a struct or union member.
493 */ 492 */
494 if (mp->m_binary && op != ARROW && op != POINT) 493 if (mp->m_binary && op != ARROW && op != POINT)
495 rn = cconv(rn); 494 rn = cconv(rn);
496 495
497 /* 496 /*
498 * Print some warnings for comparisons of unsigned values with 497 * Print some warnings for comparisons of unsigned values with
499 * constants lower than or equal to null. This must be done 498 * constants lower than or equal to null. This must be done
500 * before promote() because otherwise unsigned char and unsigned 499 * before promote() because otherwise unsigned char and unsigned
501 * short would be promoted to int. Also types are tested to be 500 * short would be promoted to int. Also types are tested to be
502 * CHAR, which would also become int. 501 * CHAR, which would also become int.
503 */ 502 */
504 if (mp->m_comp) 503 if (mp->m_comp)
505 check_integer_comparison(op, ln, rn); 504 check_integer_comparison(op, ln, rn);
506 505
507 /* 506 /*
508 * Promote the left operand if it is in a test or value context 507 * Promote the left operand if it is in a test or value context
509 */ 508 */
510 if (mp->m_vctx || mp->m_tctx) 509 if (mp->m_vctx || mp->m_tctx)
511 ln = promote(op, 0, ln); 510 ln = promote(op, 0, ln);
512 /* 511 /*
513 * Promote the right operand, but only if it is no struct or 512 * Promote the right operand, but only if it is no struct or
514 * union member, or if it is not to be assigned to the left operand 513 * union member, or if it is not to be assigned to the left operand
515 */ 514 */
516 if (mp->m_binary && op != ARROW && op != POINT && 515 if (mp->m_binary && op != ARROW && op != POINT &&
517 op != ASSIGN && op != RETURN) { 516 op != ASSIGN && op != RETURN) {
518 rn = promote(op, 0, rn); 517 rn = promote(op, 0, rn);
519 } 518 }
520 519
521 /* 520 /*
522 * If the result of the operation is different for signed or 521 * If the result of the operation is different for signed or
523 * unsigned operands and one of the operands is signed only in 522 * unsigned operands and one of the operands is signed only in
524 * ANSI C, print a warning. 523 * ANSI C, print a warning.
525 */ 524 */
526 if (mp->m_tlansiu && ln->tn_op == CON && ln->tn_val->v_ansiu) { 525 if (mp->m_tlansiu && ln->tn_op == CON && ln->tn_val->v_ansiu) {
527 /* ANSI C treats constant as unsigned, op %s */ 526 /* ANSI C treats constant as unsigned, op %s */
528 warning(218, mp->m_name); 527 warning(218, mp->m_name);
529 ln->tn_val->v_ansiu = 0; 528 ln->tn_val->v_ansiu = 0;
530 } 529 }
531 if (mp->m_transiu && rn->tn_op == CON && rn->tn_val->v_ansiu) { 530 if (mp->m_transiu && rn->tn_op == CON && rn->tn_val->v_ansiu) {
532 /* ANSI C treats constant as unsigned, op %s */ 531 /* ANSI C treats constant as unsigned, op %s */
533 warning(218, mp->m_name); 532 warning(218, mp->m_name);
534 rn->tn_val->v_ansiu = 0; 533 rn->tn_val->v_ansiu = 0;
535 } 534 }
536 535
537 /* Make sure both operands are of the same type */ 536 /* Make sure both operands are of the same type */
538 if (mp->m_balance || (tflag && (op == SHL || op == SHR))) 537 if (mp->m_balance || (tflag && (op == SHL || op == SHR)))
539 balance(op, &ln, &rn); 538 balance(op, &ln, &rn);
540 539
541 /* 540 /*
542 * Check types for compatibility with the operation and mutual 541 * Check types for compatibility with the operation and mutual
543 * compatibility. Return if there are serious problems. 542 * compatibility. Return if there are serious problems.
544 */ 543 */
545 if (!typeok(op, 0, ln, rn)) 544 if (!typeok(op, 0, ln, rn))
546 return NULL; 545 return NULL;
547 546
548 /* And now create the node. */ 547 /* And now create the node. */
549 switch (op) { 548 switch (op) {
550 case POINT: 549 case POINT:
551 case ARROW: 550 case ARROW:
552 ntn = build_struct_access(op, ln, rn); 551 ntn = build_struct_access(op, ln, rn);
553 break; 552 break;
554 case INCAFT: 553 case INCAFT:
555 case DECAFT: 554 case DECAFT:
556 case INCBEF: 555 case INCBEF:
557 case DECBEF: 556 case DECBEF:
558 ntn = build_prepost_incdec(op, ln); 557 ntn = build_prepost_incdec(op, ln);
559 break; 558 break;
560 case AMPER: 559 case AMPER:
561 ntn = build_ampersand(ln, 0); 560 ntn = build_ampersand(ln, 0);
562 break; 561 break;
563 case STAR: 562 case STAR:
564 ntn = new_tnode(STAR, ln->tn_type->t_subt, ln, NULL); 563 ntn = new_tnode(STAR, ln->tn_type->t_subt, ln, NULL);
565 break; 564 break;
566 case PLUS: 565 case PLUS:
567 case MINUS: 566 case MINUS:
568 ntn = build_plus_minus(op, ln, rn); 567 ntn = build_plus_minus(op, ln, rn);
569 break; 568 break;
570 case SHL: 569 case SHL:
571 case SHR: 570 case SHR:
572 ntn = build_bit_shift(op, ln, rn); 571 ntn = build_bit_shift(op, ln, rn);
573 break; 572 break;
574 case COLON: 573 case COLON:
575 ntn = build_colon(ln, rn); 574 ntn = build_colon(ln, rn);
576 break; 575 break;
577 case ASSIGN: 576 case ASSIGN:
578 case MULASS: 577 case MULASS:
579 case DIVASS: 578 case DIVASS:
580 case MODASS: 579 case MODASS:
581 case ADDASS: 580 case ADDASS:
582 case SUBASS: 581 case SUBASS:
583 case SHLASS: 582 case SHLASS:
584 case SHRASS: 583 case SHRASS:
585 case ANDASS: 584 case ANDASS:
586 case XORASS: 585 case XORASS:
587 case ORASS: 586 case ORASS:
588 case RETURN: 587 case RETURN:
589 ntn = build_assignment(op, ln, rn); 588 ntn = build_assignment(op, ln, rn);
590 break; 589 break;
591 case COMMA: 590 case COMMA:
592 case QUEST: 591 case QUEST:
593 ntn = new_tnode(op, rn->tn_type, ln, rn); 592 ntn = new_tnode(op, rn->tn_type, ln, rn);
594 break; 593 break;
595 case REAL: 594 case REAL:
596 case IMAG: 595 case IMAG:
597 ntn = build_real_imag(op, ln); 596 ntn = build_real_imag(op, ln);
598 break; 597 break;
599 default: 598 default:
600 rtp = mp->m_logical ? gettyp(INT) : ln->tn_type; 599 rtp = mp->m_logical ? gettyp(INT) : ln->tn_type;
601 lint_assert(mp->m_binary || rn == NULL); 600 lint_assert(mp->m_binary || rn == NULL);
602 ntn = new_tnode(op, rtp, ln, rn); 601 ntn = new_tnode(op, rtp, ln, rn);
603 break; 602 break;
604 } 603 }
605 604
606 /* Return if an error occurred. */ 605 /* Return if an error occurred. */
607 if (ntn == NULL) 606 if (ntn == NULL)
608 return NULL; 607 return NULL;
609 608
610 /* Print a warning if precedence confusion is possible */ 609 /* Print a warning if precedence confusion is possible */
611 if (mp->m_tpconf) 610 if (mp->m_tpconf)
612 check_precedence_confusion(ntn); 611 check_precedence_confusion(ntn);
613 612
614 /* 613 /*
615 * Print a warning if one of the operands is in a context where 614 * Print a warning if one of the operands is in a context where
616 * it is compared with null and if this operand is a constant. 615 * it is compared with null and if this operand is a constant.
617 */ 616 */
618 if (mp->m_tctx) { 617 if (mp->m_tctx) {
619 if (ln->tn_op == CON || 618 if (ln->tn_op == CON ||
620 ((mp->m_binary && op != QUEST) && rn->tn_op == CON)) { 619 ((mp->m_binary && op != QUEST) && rn->tn_op == CON)) {
621 if (hflag && !constcond_flag) 620 if (hflag && !constcond_flag)
622 /* constant in conditional context */ 621 /* constant in conditional context */
623 warning(161); 622 warning(161);
624 } 623 }
625 } 624 }
626 625
627 /* Fold if the operator requires it */ 626 /* Fold if the operator requires it */
628 if (mp->m_fold) { 627 if (mp->m_fold) {
629 if (ln->tn_op == CON && (!mp->m_binary || rn->tn_op == CON)) { 628 if (ln->tn_op == CON && (!mp->m_binary || rn->tn_op == CON)) {
630 if (mp->m_tctx) { 629 if (mp->m_tctx) {
631 ntn = fold_test(ntn); 630 ntn = fold_test(ntn);
632 } else if (tspec_is_float(ntn->tn_type->t_tspec)) { 631 } else if (tspec_is_float(ntn->tn_type->t_tspec)) {
633 ntn = fold_float(ntn); 632 ntn = fold_float(ntn);
634 } else { 633 } else {
635 ntn = fold(ntn); 634 ntn = fold(ntn);
636 } 635 }
637 } else if (op == QUEST && ln->tn_op == CON) { 636 } else if (op == QUEST && ln->tn_op == CON) {
638 ntn = ln->tn_val->v_quad ? rn->tn_left : rn->tn_right; 637 ntn = ln->tn_val->v_quad ? rn->tn_left : rn->tn_right;
639 } 638 }
640 } 639 }
641 640
642 return ntn; 641 return ntn;
643} 642}
644 643
645/* 644/*
646 * Perform class conversions. 645 * Perform class conversions.
647 * 646 *
648 * Arrays of type T are converted into pointers to type T. 647 * Arrays of type T are converted into pointers to type T.
649 * Functions are converted to pointers to functions. 648 * Functions are converted to pointers to functions.
650 * Lvalues are converted to rvalues. 649 * Lvalues are converted to rvalues.
651 */ 650 */
652tnode_t * 651tnode_t *
653cconv(tnode_t *tn) 652cconv(tnode_t *tn)
654{ 653{
655 type_t *tp; 654 type_t *tp;
656 655
657 /* 656 /*
658 * Array-lvalue (array of type T) is converted into rvalue 657 * Array-lvalue (array of type T) is converted into rvalue
659 * (pointer to type T) 658 * (pointer to type T)
660 */ 659 */
661 if (tn->tn_type->t_tspec == ARRAY) { 660 if (tn->tn_type->t_tspec == ARRAY) {
662 if (!tn->tn_lvalue) { 661 if (!tn->tn_lvalue) {
663 /* XXX print correct operator */ 662 /* XXX print correct operator */
664 /* %soperand of '%s' must be lvalue */ 663 /* %soperand of '%s' must be lvalue */
665 gnuism(114, "", modtab[AMPER].m_name); 664 gnuism(114, "", modtab[AMPER].m_name);
666 } 665 }
667 tn = new_tnode(AMPER, tincref(tn->tn_type->t_subt, PTR), 666 tn = new_tnode(AMPER, tincref(tn->tn_type->t_subt, PTR),
668 tn, NULL); 667 tn, NULL);
669 } 668 }
670 669
671 /* 670 /*
672 * Expression of type function (function with return value of type T) 671 * Expression of type function (function with return value of type T)
673 * in rvalue-expression (pointer to function with return value 672 * in rvalue-expression (pointer to function with return value
674 * of type T) 673 * of type T)
675 */ 674 */
676 if (tn->tn_type->t_tspec == FUNC) 675 if (tn->tn_type->t_tspec == FUNC)
677 tn = build_ampersand(tn, 1); 676 tn = build_ampersand(tn, 1);
678 677
679 /* lvalue to rvalue */ 678 /* lvalue to rvalue */
680 if (tn->tn_lvalue) { 679 if (tn->tn_lvalue) {
681 tp = tduptyp(tn->tn_type); 680 tp = tduptyp(tn->tn_type);
682 tp->t_const = tp->t_volatile = 0; 681 tp->t_const = tp->t_volatile = 0;
683 tn = new_tnode(LOAD, tp, tn, NULL); 682 tn = new_tnode(LOAD, tp, tn, NULL);
684 } 683 }
685 684
686 return tn; 685 return tn;
687} 686}
688 687
689/* 688/*
690 * Perform most type checks. First the types are checked using 689 * Perform most type checks. First the types are checked using
691 * the information from modtab[]. After that it is done by hand for 690 * the information from modtab[]. After that it is done by hand for
692 * more complicated operators and type combinations. 691 * more complicated operators and type combinations.
693 * 692 *
694 * If the types are ok, typeok() returns 1, otherwise 0. 693 * If the types are ok, typeok() returns 1, otherwise 0.
695 */ 694 */
696int 695int
697typeok(op_t op, int arg, tnode_t *ln, tnode_t *rn) 696typeok(op_t op, int arg, tnode_t *ln, tnode_t *rn)
698{ 697{
699 mod_t *mp; 698 mod_t *mp;
700 tspec_t lt, rt = NOTSPEC, lst = NOTSPEC, rst = NOTSPEC, olt = NOTSPEC, 699 tspec_t lt, rt = NOTSPEC, lst = NOTSPEC, rst = NOTSPEC, olt = NOTSPEC,
701 ort = NOTSPEC; 700 ort = NOTSPEC;
702 type_t *ltp, *rtp = NULL, *lstp = NULL, *rstp = NULL; 701 type_t *ltp, *rtp = NULL, *lstp = NULL, *rstp = NULL;
703 tnode_t *tn; 702 tnode_t *tn;
704 703
705 mp = &modtab[op]; 704 mp = &modtab[op];
706 705
707 lint_assert((ltp = ln->tn_type) != NULL); 706 lint_assert((ltp = ln->tn_type) != NULL);
708 707
709 if ((lt = ltp->t_tspec) == PTR) 708 if ((lt = ltp->t_tspec) == PTR)
710 lst = (lstp = ltp->t_subt)->t_tspec; 709 lst = (lstp = ltp->t_subt)->t_tspec;
711 if (mp->m_binary) { 710 if (mp->m_binary) {
712 lint_assert((rtp = rn->tn_type) != NULL); 711 lint_assert((rtp = rn->tn_type) != NULL);
713 if ((rt = rtp->t_tspec) == PTR) 712 if ((rt = rtp->t_tspec) == PTR)
714 rst = (rstp = rtp->t_subt)->t_tspec; 713 rst = (rstp = rtp->t_subt)->t_tspec;
715 } 714 }
716 715
717 if (mp->m_requires_integer) { 716 if (mp->m_requires_integer) {
718 if (!tspec_is_int(lt) || (mp->m_binary && !tspec_is_int(rt))) { 717 if (!tspec_is_int(lt) || (mp->m_binary && !tspec_is_int(rt))) {
719 warn_incompatible_types(op, lt, rt); 718 warn_incompatible_types(op, lt, rt);
720 return 0; 719 return 0;
721 } 720 }
722 } else if (mp->m_requires_integer_or_complex) { 721 } else if (mp->m_requires_integer_or_complex) {
723 if ((!tspec_is_int(lt) && !tspec_is_complex(lt)) || 722 if ((!tspec_is_int(lt) && !tspec_is_complex(lt)) ||
724 (mp->m_binary && 723 (mp->m_binary &&
725 (!tspec_is_int(rt) && !tspec_is_complex(rt)))) { 724 (!tspec_is_int(rt) && !tspec_is_complex(rt)))) {
726 warn_incompatible_types(op, lt, rt); 725 warn_incompatible_types(op, lt, rt);
727 return 0; 726 return 0;
728 } 727 }
729 } else if (mp->m_requires_scalar) { 728 } else if (mp->m_requires_scalar) {
730 if (!tspec_is_scalar(lt) || 729 if (!tspec_is_scalar(lt) ||
731 (mp->m_binary && !tspec_is_scalar(rt))) { 730 (mp->m_binary && !tspec_is_scalar(rt))) {
732 warn_incompatible_types(op, lt, rt); 731 warn_incompatible_types(op, lt, rt);
733 return 0; 732 return 0;
734 } 733 }
735 } else if (mp->m_requires_arith) { 734 } else if (mp->m_requires_arith) {
736 if (!tspec_is_arith(lt) || 735 if (!tspec_is_arith(lt) ||
737 (mp->m_binary && !tspec_is_arith(rt))) { 736 (mp->m_binary && !tspec_is_arith(rt))) {
738 warn_incompatible_types(op, lt, rt); 737 warn_incompatible_types(op, lt, rt);
739 return 0; 738 return 0;
740 } 739 }
741 } 740 }
742 741
743 if (op == SHL || op == SHR || op == SHLASS || op == SHRASS) { 742 if (op == SHL || op == SHR || op == SHLASS || op == SHRASS) {
744 /* 743 /*
745 * For these operations we need the types before promotion 744 * For these operations we need the types before promotion
746 * and balancing. 745 * and balancing.
747 */ 746 */
748 for (tn=ln; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left) 747 for (tn=ln; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left)
749 continue; 748 continue;
750 olt = tn->tn_type->t_tspec; 749 olt = tn->tn_type->t_tspec;
751 for (tn=rn; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left) 750 for (tn=rn; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left)
752 continue; 751 continue;
753 ort = tn->tn_type->t_tspec; 752 ort = tn->tn_type->t_tspec;
754 } 753 }
755 754
756 switch (op) { 755 switch (op) {
757 case POINT: 756 case POINT:
758 /* 757 /*
759 * Most errors required by ANSI C are reported in 758 * Most errors required by ANSI C are reported in
760 * struct_or_union_member(). 759 * struct_or_union_member().
761 * Here we only must check for totally wrong things. 760 * Here we only must check for totally wrong things.
762 */ 761 */
763 if (lt == FUNC || lt == VOID || ltp->t_isfield || 762 if (lt == FUNC || lt == VOID || ltp->t_isfield ||
764 ((lt != STRUCT && lt != UNION) && !ln->tn_lvalue)) { 763 ((lt != STRUCT && lt != UNION) && !ln->tn_lvalue)) {
765 /* Without tflag we got already an error */ 764 /* Without tflag we got already an error */
766 if (tflag) 765 if (tflag)
767 /* unacceptable operand of '%s' */ 766 /* unacceptable operand of '%s' */
768 error(111, mp->m_name); 767 error(111, mp->m_name);
769 return 0; 768 return 0;
770 } 769 }
771 /* Now we have an object we can create a pointer to */ 770 /* Now we have an object we can create a pointer to */
772 break; 771 break;
773 case ARROW: 772 case ARROW:
774 if (lt != PTR && !(tflag && tspec_is_int(lt))) { 773 if (lt != PTR && !(tflag && tspec_is_int(lt))) {
775 /* Without tflag we got already an error */ 774 /* Without tflag we got already an error */
776 if (tflag) 775 if (tflag)
777 /* unacceptable operand of '%s' */ 776 /* unacceptable operand of '%s' */
778 error(111, mp->m_name); 777 error(111, mp->m_name);
779 return 0; 778 return 0;
780 } 779 }
781 break; 780 break;
782 case INCAFT: 781 case INCAFT:
783 case DECAFT: 782 case DECAFT:
784 case INCBEF: 783 case INCBEF:
785 case DECBEF: 784 case DECBEF:
786 /* operands have scalar types (checked above) */ 785 /* operands have scalar types (checked above) */
787 if (!ln->tn_lvalue) { 786 if (!ln->tn_lvalue) {
788 if (ln->tn_op == CVT && ln->tn_cast && 787 if (ln->tn_op == CVT && ln->tn_cast &&
789 ln->tn_left->tn_op == LOAD) { 788 ln->tn_left->tn_op == LOAD) {
790 if (ln->tn_type->t_tspec == PTR) 789 if (ln->tn_type->t_tspec == PTR)
791 break; 790 break;
792 /* a cast does not yield an lvalue */ 791 /* a cast does not yield an lvalue */
793 error(163); 792 error(163);
794 } 793 }
795 /* %soperand of '%s' must be lvalue */ 794 /* %soperand of '%s' must be lvalue */
796 error(114, "", mp->m_name); 795 error(114, "", mp->m_name);
797 return 0; 796 return 0;
798 } else if (ltp->t_const) { 797 } else if (ltp->t_const) {
799 if (!tflag) 798 if (!tflag)
800 /* %soperand of '%s' must be modifiable ... */ 799 /* %soperand of '%s' must be modifiable ... */
801 warning(115, "", mp->m_name); 800 warning(115, "", mp->m_name);
802 } 801 }
803 break; 802 break;
804 case AMPER: 803 case AMPER:
805 if (lt == ARRAY || lt == FUNC) { 804 if (lt == ARRAY || lt == FUNC) {
806 /* ok, a warning comes later (in build_ampersand()) */ 805 /* ok, a warning comes later (in build_ampersand()) */
807 } else if (!ln->tn_lvalue) { 806 } else if (!ln->tn_lvalue) {
808 if (ln->tn_op == CVT && ln->tn_cast && 807 if (ln->tn_op == CVT && ln->tn_cast &&
809 ln->tn_left->tn_op == LOAD) { 808 ln->tn_left->tn_op == LOAD) {
810 if (ln->tn_type->t_tspec == PTR) 809 if (ln->tn_type->t_tspec == PTR)
811 break; 810 break;
812 /* a cast does not yield an lvalue */ 811 /* a cast does not yield an lvalue */
813 error(163); 812 error(163);
814 } 813 }
815 /* %soperand of '%s' must be lvalue */ 814 /* %soperand of '%s' must be lvalue */
816 error(114, "", mp->m_name); 815 error(114, "", mp->m_name);
817 return 0; 816 return 0;
818 } else if (tspec_is_scalar(lt)) { 817 } else if (tspec_is_scalar(lt)) {
819 if (ltp->t_isfield) { 818 if (ltp->t_isfield) {
820 /* cannot take address of bit-field */ 819 /* cannot take address of bit-field */
821 error(112); 820 error(112);
822 return 0; 821 return 0;
823 } 822 }
824 } else if (lt != STRUCT && lt != UNION) { 823 } else if (lt != STRUCT && lt != UNION) {
825 /* unacceptable operand of '%s' */ 824 /* unacceptable operand of '%s' */
826 error(111, mp->m_name); 825 error(111, mp->m_name);
827 return 0; 826 return 0;
828 } 827 }
829 if (ln->tn_op == NAME && ln->tn_sym->s_reg) { 828 if (ln->tn_op == NAME && ln->tn_sym->s_reg) {
830 /* cannot take address of register %s */ 829 /* cannot take address of register %s */
831 error(113, ln->tn_sym->s_name); 830 error(113, ln->tn_sym->s_name);
832 return 0; 831 return 0;
833 } 832 }
834 break; 833 break;
835 case STAR: 834 case STAR:
836 /* until now there were no type checks for this operator */ 835 /* until now there were no type checks for this operator */
837 if (lt != PTR) { 836 if (lt != PTR) {
838 /* cannot dereference non-pointer type */ 837 /* cannot dereference non-pointer type */
839 error(96); 838 error(96);
840 return 0; 839 return 0;
841 } 840 }
842 break; 841 break;
843 case PLUS: 842 case PLUS:
844 /* operands have scalar types (checked above) */ 843 /* operands have scalar types (checked above) */
845 if ((lt == PTR && !tspec_is_int(rt)) || 844 if ((lt == PTR && !tspec_is_int(rt)) ||
846 (rt == PTR && !tspec_is_int(lt))) { 845 (rt == PTR && !tspec_is_int(lt))) {
847 warn_incompatible_types(op, lt, rt); 846 warn_incompatible_types(op, lt, rt);
848 return 0; 847 return 0;
849 } 848 }
850 break; 849 break;
851 case MINUS: 850 case MINUS:
852 /* operands have scalar types (checked above) */ 851 /* operands have scalar types (checked above) */
853 if (lt == PTR && (!tspec_is_int(rt) && rt != PTR)) { 852 if (lt == PTR && (!tspec_is_int(rt) && rt != PTR)) {
854 warn_incompatible_types(op, lt, rt); 853 warn_incompatible_types(op, lt, rt);
855 return 0; 854 return 0;
856 } else if (rt == PTR && lt != PTR) { 855 } else if (rt == PTR && lt != PTR) {
857 warn_incompatible_types(op, lt, rt); 856 warn_incompatible_types(op, lt, rt);
858 return 0; 857 return 0;
859 } 858 }
860 if (lt == PTR && rt == PTR) { 859 if (lt == PTR && rt == PTR) {
861 if (!eqtype(lstp, rstp, 1, 0, NULL)) { 860 if (!eqtype(lstp, rstp, 1, 0, NULL)) {
862 /* illegal pointer subtraction */ 861 /* illegal pointer subtraction */
863 error(116); 862 error(116);
864 } 863 }
865 } 864 }
866 break; 865 break;
867 case SHR: 866 case SHR:
868 /* operands have integer types (checked above) */ 867 /* operands have integer types (checked above) */
869 if (pflag && !tspec_is_uint(lt)) { 868 if (pflag && !tspec_is_uint(lt)) {
870 /* 869 /*
871 * The left operand is signed. This means that 870 * The left operand is signed. This means that
872 * the operation is (possibly) nonportable. 871 * the operation is (possibly) nonportable.
873 */ 872 */
874 if (ln->tn_op != CON) { 873 if (ln->tn_op != CON) {
875 /* bitop. on signed value poss. nonportable */ 874 /* bitop. on signed value poss. nonportable */
876 warning(117); 875 warning(117);
877 } else if (ln->tn_val->v_quad < 0) { 876 } else if (ln->tn_val->v_quad < 0) {
878 /* bitop. on signed value nonportable */ 877 /* bitop. on signed value nonportable */
879 warning(120); 878 warning(120);
880 } 879 }
881 } else if (!tflag && !sflag && 880 } else if (!tflag && !sflag &&
882 !tspec_is_uint(olt) && tspec_is_uint(ort)) { 881 !tspec_is_uint(olt) && tspec_is_uint(ort)) {
883 /* 882 /*
884 * The left operand would become unsigned in 883 * The left operand would become unsigned in
885 * traditional C. 884 * traditional C.
886 */ 885 */
887 if (hflag && 886 if (hflag &&
888 (ln->tn_op != CON || ln->tn_val->v_quad < 0)) { 887 (ln->tn_op != CON || ln->tn_val->v_quad < 0)) {
889 /* semantics of '%s' change in ANSI C; ... */ 888 /* semantics of '%s' change in ANSI C; ... */
890 warning(118, mp->m_name); 889 warning(118, mp->m_name);
891 } 890 }
892 } else if (!tflag && !sflag && 891 } else if (!tflag && !sflag &&
893 !tspec_is_uint(olt) && !tspec_is_uint(ort) && 892 !tspec_is_uint(olt) && !tspec_is_uint(ort) &&
894 psize(lt) < psize(rt)) { 893 psize(lt) < psize(rt)) {
895 /* 894 /*
896 * In traditional C the left operand would be extended, 895 * In traditional C the left operand would be extended,
897 * possibly with 1, and then shifted. 896 * possibly with 1, and then shifted.
898 */ 897 */
899 if (hflag && 898 if (hflag &&
900 (ln->tn_op != CON || ln->tn_val->v_quad < 0)) { 899 (ln->tn_op != CON || ln->tn_val->v_quad < 0)) {
901 /* semantics of '%s' change in ANSI C; ... */ 900 /* semantics of '%s' change in ANSI C; ... */
902 warning(118, mp->m_name); 901 warning(118, mp->m_name);
903 } 902 }
904 } 903 }
905 goto shift; 904 goto shift;
906 case SHL: 905 case SHL:
907 /* 906 /*
908 * ANSI C does not perform balancing for shift operations, 907 * ANSI C does not perform balancing for shift operations,
909 * but traditional C does. If the width of the right operand 908 * but traditional C does. If the width of the right operand
910 * is greater than the width of the left operand, than in 909 * is greater than the width of the left operand, than in
911 * traditional C the left operand would be extended to the 910 * traditional C the left operand would be extended to the
912 * width of the right operand. For SHL this may result in 911 * width of the right operand. For SHL this may result in
913 * different results. 912 * different results.
914 */ 913 */
915 if (psize(lt) < psize(rt)) { 914 if (psize(lt) < psize(rt)) {
916 /* 915 /*
917 * XXX If both operands are constant, make sure 916 * XXX If both operands are constant, make sure
918 * that there is really a difference between 917 * that there is really a difference between
919 * ANSI C and traditional C. 918 * ANSI C and traditional C.
920 */ 919 */
921 if (hflag) 920 if (hflag)
922 /* semantics of '%s' change in ANSI C; ... */ 921 /* semantics of '%s' change in ANSI C; ... */
923 warning(118, mp->m_name); 922 warning(118, mp->m_name);
924 } 923 }
925 shift: 924 shift:
926 if (rn->tn_op == CON) { 925 if (rn->tn_op == CON) {
927 if (!tspec_is_uint(rt) && rn->tn_val->v_quad < 0) { 926 if (!tspec_is_uint(rt) && rn->tn_val->v_quad < 0) {
928 /* negative shift */ 927 /* negative shift */
929 warning(121); 928 warning(121);
930 } else if ((uint64_t)rn->tn_val->v_quad == (uint64_t)size(lt)) { 929 } else if ((uint64_t)rn->tn_val->v_quad == (uint64_t)size(lt)) {
931 /* shift equal to size of object */ 930 /* shift equal to size of object */
932 warning(267); 931 warning(267);
933 } else if ((uint64_t)rn->tn_val->v_quad > (uint64_t)size(lt)) { 932 } else if ((uint64_t)rn->tn_val->v_quad > (uint64_t)size(lt)) {
934 /* shift greater than size of object */ 933 /* shift greater than size of object */
935 warning(122); 934 warning(122);
936 } 935 }
937 } 936 }
938 break; 937 break;
939 case EQ: 938 case EQ:
940 case NE: 939 case NE:
941 /* 940 /*
942 * Accept some things which are allowed with EQ and NE, 941 * Accept some things which are allowed with EQ and NE,
943 * but not with ordered comparisons. 942 * but not with ordered comparisons.
944 */ 943 */
945 if (lt == PTR && ((rt == PTR && rst == VOID) || 944 if (lt == PTR && ((rt == PTR && rst == VOID) ||
946 tspec_is_int(rt))) { 945 tspec_is_int(rt))) {
947 if (rn->tn_op == CON && rn->tn_val->v_quad == 0) 946 if (rn->tn_op == CON && rn->tn_val->v_quad == 0)
948 break; 947 break;
949 } 948 }
950 if (rt == PTR && ((lt == PTR && lst == VOID) || 949 if (rt == PTR && ((lt == PTR && lst == VOID) ||
951 tspec_is_int(lt))) { 950 tspec_is_int(lt))) {
952 if (ln->tn_op == CON && ln->tn_val->v_quad == 0) 951 if (ln->tn_op == CON && ln->tn_val->v_quad == 0)
953 break; 952 break;
954 } 953 }
955 /* FALLTHROUGH */ 954 /* FALLTHROUGH */
956 case LT: 955 case LT:
957 case GT: 956 case GT:
958 case LE: 957 case LE:
959 case GE: 958 case GE:
960 if ((lt == PTR || rt == PTR) && lt != rt) { 959 if ((lt == PTR || rt == PTR) && lt != rt) {
961 if (tspec_is_int(lt) || tspec_is_int(rt)) { 960 if (tspec_is_int(lt) || tspec_is_int(rt)) {
962 const char *lx = lt == PTR ? 961 const char *lx = lt == PTR ?
963 "pointer" : "integer"; 962 "pointer" : "integer";
964 const char *rx = rt == PTR ? 963 const char *rx = rt == PTR ?
965 "pointer" : "integer"; 964 "pointer" : "integer";
966 /* illegal combination of %s (%s) and ... */ 965 /* illegal combination of %s (%s) and ... */
967 warning(123, lx, type_name(ltp), 966 warning(123, lx, type_name(ltp),
968 rx, type_name(rtp), mp->m_name); 967 rx, type_name(rtp), mp->m_name);
969 } else { 968 } else {
970 warn_incompatible_types(op, lt, rt); 969 warn_incompatible_types(op, lt, rt);
971 return 0; 970 return 0;
972 } 971 }
973 } else if (lt == PTR && rt == PTR) { 972 } else if (lt == PTR && rt == PTR) {
974 check_pointer_comparison(op, ln, rn); 973 check_pointer_comparison(op, ln, rn);
975 } 974 }
976 break; 975 break;
977 case QUEST: 976 case QUEST:
978 if (!tspec_is_scalar(lt)) { 977 if (!tspec_is_scalar(lt)) {
979 /* first operand must have scalar type, op ? : */ 978 /* first operand must have scalar type, op ? : */
980 error(170); 979 error(170);
981 return 0; 980 return 0;
982 } 981 }
983 while (rn->tn_op == CVT) 982 while (rn->tn_op == CVT)
984 rn = rn->tn_left; 983 rn = rn->tn_left;
985 lint_assert(rn->tn_op == COLON); 984 lint_assert(rn->tn_op == COLON);
986 break; 985 break;
987 case COLON: 986 case COLON:
988 if (tspec_is_arith(lt) && tspec_is_arith(rt)) 987 if (tspec_is_arith(lt) && tspec_is_arith(rt))
989 break; 988 break;
990 989
991 if (lt == STRUCT && rt == STRUCT && ltp->t_str == rtp->t_str) 990 if (lt == STRUCT && rt == STRUCT && ltp->t_str == rtp->t_str)
992 break; 991 break;
993 if (lt == UNION && rt == UNION && ltp->t_str == rtp->t_str) 992 if (lt == UNION && rt == UNION && ltp->t_str == rtp->t_str)
994 break; 993 break;
995 994
996 /* combination of any pointer and 0, 0L or (void *)0 is ok */ 995 /* combination of any pointer and 0, 0L or (void *)0 is ok */
997 if (lt == PTR && ((rt == PTR && rst == VOID) || 996 if (lt == PTR && ((rt == PTR && rst == VOID) ||
998 tspec_is_int(rt))) { 997 tspec_is_int(rt))) {
999 if (rn->tn_op == CON && rn->tn_val->v_quad == 0) 998 if (rn->tn_op == CON && rn->tn_val->v_quad == 0)
1000 break; 999 break;
1001 } 1000 }
1002 if (rt == PTR && ((lt == PTR && lst == VOID) || 1001 if (rt == PTR && ((lt == PTR && lst == VOID) ||
1003 tspec_is_int(lt))) { 1002 tspec_is_int(lt))) {
1004 if (ln->tn_op == CON && ln->tn_val->v_quad == 0) 1003 if (ln->tn_op == CON && ln->tn_val->v_quad == 0)
1005 break; 1004 break;
1006 } 1005 }
1007 1006
1008 if ((lt == PTR && tspec_is_int(rt)) || 1007 if ((lt == PTR && tspec_is_int(rt)) ||
1009 (tspec_is_int(lt) && rt == PTR)) { 1008 (tspec_is_int(lt) && rt == PTR)) {
1010 const char *lx = lt == PTR ? "pointer" : "integer"; 1009 const char *lx = lt == PTR ? "pointer" : "integer";
1011 const char *rx = rt == PTR ? "pointer" : "integer"; 1010 const char *rx = rt == PTR ? "pointer" : "integer";
1012 /* illegal combination of %s (%s) and %s (%s), op %s */ 1011 /* illegal combination of %s (%s) and %s (%s), op %s */
1013 warning(123, lx, type_name(ltp), 1012 warning(123, lx, type_name(ltp),
1014 rx, type_name(rtp), mp->m_name); 1013 rx, type_name(rtp), mp->m_name);
1015 break; 1014 break;
1016 } 1015 }
1017 1016
1018 if (lt == VOID || rt == VOID) { 1017 if (lt == VOID || rt == VOID) {
1019 if (lt != VOID || rt != VOID) 1018 if (lt != VOID || rt != VOID)
1020 /* incompatible types in conditional */ 1019 /* incompatible types in conditional */
1021 warning(126); 1020 warning(126);
1022 break; 1021 break;
1023 } 1022 }
1024 1023
1025 if (lt == PTR && rt == PTR && ((lst == VOID && rst == FUNC) || 1024 if (lt == PTR && rt == PTR && ((lst == VOID && rst == FUNC) ||
1026 (lst == FUNC && rst == VOID))) { 1025 (lst == FUNC && rst == VOID))) {
1027 /* (void *)0 handled above */ 1026 /* (void *)0 handled above */
1028 if (sflag) 1027 if (sflag)
1029 /* ANSI C forbids conv. of %s to %s, op %s */ 1028 /* ANSI C forbids conv. of %s to %s, op %s */
1030 warning(305, "function pointer", "'void *'", 1029 warning(305, "function pointer", "'void *'",
1031 mp->m_name); 1030 mp->m_name);
1032 break; 1031 break;
1033 } 1032 }
1034 1033
1035 if (rt == PTR && lt == PTR) { 1034 if (rt == PTR && lt == PTR) {
1036 if (eqptrtype(lstp, rstp, 1)) 1035 if (eqptrtype(lstp, rstp, 1))
1037 break; 1036 break;
1038 if (!eqtype(lstp, rstp, 1, 0, NULL)) 1037 if (!eqtype(lstp, rstp, 1, 0, NULL))
1039 warn_incompatible_pointers(mp, ltp, rtp); 1038 warn_incompatible_pointers(mp, ltp, rtp);
1040 break; 1039 break;
1041 } 1040 }
1042 1041
1043 /* incompatible types in conditional */ 1042 /* incompatible types in conditional */
1044 error(126); 1043 error(126);
1045 return 0; 1044 return 0;
1046 1045
1047 case ASSIGN: 1046 case ASSIGN:
1048 case INIT: 1047 case INIT:
1049 case FARG: 1048 case FARG:
1050 case RETURN: 1049 case RETURN:
1051 if (!check_assign_types_compatible(op, arg, ln, rn)) 1050 if (!check_assign_types_compatible(op, arg, ln, rn))