| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: tree.c,v 1.396 2021/12/04 00:01:24 rillig Exp $ */ | | 1 | /* $NetBSD: tree.c,v 1.397 2021/12/06 23:26:28 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.396 2021/12/04 00:01:24 rillig Exp $"); | | 40 | __RCSID("$NetBSD: tree.c,v 1.397 2021/12/06 23:26:28 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 | |
53 | static tnode_t *build_integer_constant(tspec_t, int64_t); | | 53 | static tnode_t *build_integer_constant(tspec_t, int64_t); |
| @@ -224,39 +224,49 @@ str_endswith(const char *haystack, const | | | @@ -224,39 +224,49 @@ str_endswith(const char *haystack, const |
224 | return nlen <= hlen && | | 224 | return nlen <= hlen && |
225 | memcmp(haystack + hlen - nlen, needle, nlen) == 0; | | 225 | memcmp(haystack + hlen - nlen, needle, nlen) == 0; |
226 | } | | 226 | } |
227 | | | 227 | |
228 | /* https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html */ | | 228 | /* https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html */ |
229 | static bool | | 229 | static bool |
230 | is_gcc_bool_builtin(const char *name) | | 230 | is_gcc_bool_builtin(const char *name) |
231 | { | | 231 | { |
232 | return strncmp(name, "__builtin_", 10) == 0 && | | 232 | return strncmp(name, "__builtin_", 10) == 0 && |
233 | (str_endswith(name, "_overflow") || | | 233 | (str_endswith(name, "_overflow") || |
234 | str_endswith(name, "_overflow_p")); | | 234 | str_endswith(name, "_overflow_p")); |
235 | } | | 235 | } |
236 | | | 236 | |
| | | 237 | /* https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html */ |
| | | 238 | static bool |
| | | 239 | is_gcc_void_pointer_builtin(const char *name) |
| | | 240 | { |
| | | 241 | return strcmp(name, "__builtin_alloca") == 0 || |
| | | 242 | strncmp(name, "__builtin_alloca_", 17) == 0; |
| | | 243 | } |
| | | 244 | |
237 | static void | | 245 | static void |
238 | build_name_call(sym_t *sym) | | 246 | build_name_call(sym_t *sym) |
239 | { | | 247 | { |
240 | | | 248 | |
241 | if (is_compiler_builtin(sym->s_name)) { | | 249 | if (is_compiler_builtin(sym->s_name)) { |
242 | /* | | 250 | /* |
243 | * Do not warn about these, just assume that | | 251 | * Do not warn about these, just assume that |
244 | * they are regular functions compatible with | | 252 | * they are regular functions compatible with |
245 | * non-prototype calling conventions. | | 253 | * non-prototype calling conventions. |
246 | */ | | 254 | */ |
247 | | | 255 | |
248 | if (is_gcc_bool_builtin(sym->s_name)) | | 256 | if (is_gcc_bool_builtin(sym->s_name)) |
249 | sym->s_type = gettyp(BOOL); | | 257 | sym->s_type = gettyp(BOOL); |
| | | 258 | else if (is_gcc_void_pointer_builtin(sym->s_name)) |
| | | 259 | sym->s_type = derive_type(gettyp(VOID), PTR); |
250 | | | 260 | |
251 | } else if (Sflag) { | | 261 | } else if (Sflag) { |
252 | /* function '%s' implicitly declared to return int */ | | 262 | /* function '%s' implicitly declared to return int */ |
253 | error(215, sym->s_name); | | 263 | error(215, sym->s_name); |
254 | } else if (sflag) { | | 264 | } else if (sflag) { |
255 | /* function '%s' implicitly declared to return int */ | | 265 | /* function '%s' implicitly declared to return int */ |
256 | warning(215, sym->s_name); | | 266 | warning(215, sym->s_name); |
257 | } | | 267 | } |
258 | | | 268 | |
259 | /* XXX if tflag is set, the symbol should be exported to level 0 */ | | 269 | /* XXX if tflag is set, the symbol should be exported to level 0 */ |
260 | sym->s_type = derive_type(sym->s_type, FUNC); | | 270 | sym->s_type = derive_type(sym->s_type, FUNC); |
261 | } | | 271 | } |
262 | | | 272 | |