Mon Dec 6 23:26:28 2021 UTC ()
lint: fix return type of GCC's __builtin_alloca

Needed for libgmp.


(rillig)
diff -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.c
diff -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.exp
diff -r1.396 -r1.397 src/usr.bin/xlint/lint1/tree.c

cvs diff -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.c (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.c 2021/12/06 23:20:26 1.1
+++ src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.c 2021/12/06 23:26:28 1.2
@@ -1,21 +1,23 @@ @@ -1,21 +1,23 @@
1/* $NetBSD: gcc_builtin_alloca.c,v 1.1 2021/12/06 23:20:26 rillig Exp $ */ 1/* $NetBSD: gcc_builtin_alloca.c,v 1.2 2021/12/06 23:26:28 rillig Exp $ */
2# 3 "gcc_builtin_alloca.c" 2# 3 "gcc_builtin_alloca.c"
3 3
4/* 4/*
5 * Test for the GCC builtin functions __builtin_alloca*, which unlike most 5 * Test for the GCC builtin functions __builtin_alloca*, which unlike most
6 * other builtin functions return a pointer instead of int. 6 * other builtin functions return a pointer instead of int.
7 * 7 *
8 * https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html 8 * https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
9 */ 9 */
10 10
11void 11void
12example(void) 12example(void)
13{ 13{
14 /* expect+1: warning: illegal combination of pointer (pointer to char) and integer (int) [183] */ 
15 char *ptr = __builtin_alloca(8); 14 char *ptr = __builtin_alloca(8);
16 ptr[4] = '4'; 15 ptr[4] = '4';
17 16
18 /* expect+1: warning: illegal combination of pointer (pointer to char) and integer (int) [183] */ 
19 char *aligned_ptr = __builtin_alloca_with_align(8, 64); 17 char *aligned_ptr = __builtin_alloca_with_align(8, 64);
20 aligned_ptr[0] = '\0'; 18 aligned_ptr[0] = '\0';
 19
 20 /* expect+1: warning: illegal combination of pointer (pointer to char) and integer (int) [183] */
 21 char *unknown = __builtin_allocate(8);
 22 unknown[0] = '\0';
21} 23}

cvs diff -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/Attic/gcc_builtin_alloca.exp (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/Attic/gcc_builtin_alloca.exp 2021/12/06 23:20:26 1.1
+++ src/tests/usr.bin/xlint/lint1/Attic/gcc_builtin_alloca.exp 2021/12/06 23:26:28 1.2

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

--- src/usr.bin/xlint/lint1/tree.c 2021/12/04 00:01:24 1.396
+++ src/usr.bin/xlint/lint1/tree.c 2021/12/06 23:26:28 1.397
@@ -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
53static tnode_t *build_integer_constant(tspec_t, int64_t); 53static 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 */
229static bool 229static bool
230is_gcc_bool_builtin(const char *name) 230is_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 */
 238static bool
 239is_gcc_void_pointer_builtin(const char *name)
 240{
 241 return strcmp(name, "__builtin_alloca") == 0 ||
 242 strncmp(name, "__builtin_alloca_", 17) == 0;
 243}
 244
237static void 245static void
238build_name_call(sym_t *sym) 246build_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