| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: init.c,v 1.192 2021/04/02 14:32:27 rillig Exp $ */ | | 1 | /* $NetBSD: init.c,v 1.193 2021/04/02 14:50:47 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.192 2021/04/02 14:32:27 rillig Exp $"); | | 41 | __RCSID("$NetBSD: init.c,v 1.193 2021/04/02 14:50:47 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 }; |
| @@ -107,56 +107,55 @@ struct designator { | | | @@ -107,56 +107,55 @@ struct designator { |
107 | * C99 6.7.8p6, 6.7.8p7 | | 107 | * C99 6.7.8p6, 6.7.8p7 |
108 | */ | | 108 | */ |
109 | struct designation { | | 109 | struct designation { |
110 | struct designator *dn_head; | | 110 | struct designator *dn_head; |
111 | struct designator *dn_tail; | | 111 | struct designator *dn_tail; |
112 | }; | | 112 | }; |
113 | | | 113 | |
114 | /* | | 114 | /* |
115 | * Describes a single brace level of an ongoing initialization. | | 115 | * Describes a single brace level of an ongoing initialization. |
116 | * | | 116 | * |
117 | * See C99 6.7.8p17. | | 117 | * See C99 6.7.8p17. |
118 | */ | | 118 | */ |
119 | struct brace_level { | | 119 | struct brace_level { |
120 | /* | | 120 | const type_t *bl_type; /* The type of the current object that |
121 | * The type of the current object that is initialized at this brace | | 121 | * is initialized at this brace |
122 | * level. | | 122 | * level. */ |
123 | */ | | 123 | |
124 | const type_t *bl_type; | | 124 | struct designation bl_designation; /* .member[123].member */ |
125 | | | 125 | |
126 | const sym_t *bl_member; /* for structs and unions */ | | 126 | const sym_t *bl_member; /* for structs and unions */ |
127 | size_t bl_subscript; /* for arrays */ | | 127 | size_t bl_subscript; /* for arrays */ |
128 | bool bl_scalar_done: 1; /* for scalars */ | | 128 | bool bl_scalar_done: 1; /* for scalars */ |
129 | bool bl_confused: 1; /* skip further checks */ | | 129 | bool bl_confused: 1; /* skip further checks */ |
130 | struct designation bl_designation; /* .member[123].member */ | | | |
131 | | | 130 | |
132 | struct brace_level *bl_enclosing; | | 131 | struct brace_level *bl_enclosing; |
133 | }; | | 132 | }; |
134 | | | 133 | |
135 | struct initialization { | | 134 | struct initialization { |
| | | 135 | /* The symbol that is to be initialized. */ |
| | | 136 | sym_t *in_sym; |
| | | 137 | |
| | | 138 | /* The innermost brace level. */ |
| | | 139 | struct brace_level *in_brace_level; |
| | | 140 | |
136 | /* | | 141 | /* |
137 | * Is set as soon as a fatal error occurred in the initialization. | | 142 | * Is set as soon as a fatal error occurred in the initialization. |
138 | * The effect is that the rest of the initialization is ignored | | 143 | * The effect is that the rest of the initialization is ignored |
139 | * (parsed by yacc, expression trees built, but no initialization | | 144 | * (parsed by yacc, expression trees built, but no initialization |
140 | * takes place). | | 145 | * takes place). |
141 | */ | | 146 | */ |
142 | bool in_err; | | 147 | bool in_err; |
143 | | | 148 | |
144 | /* The symbol that is to be initialized. */ | | | |
145 | sym_t *in_sym; | | | |
146 | | | | |
147 | /* The innermost brace level. */ | | | |
148 | struct brace_level *in_brace_level; | | | |
149 | | | | |
150 | struct initialization *in_enclosing; | | 149 | struct initialization *in_enclosing; |
151 | }; | | 150 | }; |
152 | | | 151 | |
153 | | | 152 | |
154 | #ifdef DEBUG | | 153 | #ifdef DEBUG |
155 | static int debug_indentation = 0; | | 154 | static int debug_indentation = 0; |
156 | #endif | | 155 | #endif |
157 | | | 156 | |
158 | | | 157 | |
159 | #ifdef DEBUG | | 158 | #ifdef DEBUG |
160 | | | 159 | |
161 | static void __printflike(1, 2) | | 160 | static void __printflike(1, 2) |
162 | debug_printf(const char *fmt, ...) | | 161 | debug_printf(const char *fmt, ...) |