Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: fix return type of GCC's __builtin...



details:   https://anonhg.NetBSD.org/src/rev/d1a7610b88c4
branches:  trunk
changeset: 1026781:d1a7610b88c4
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Dec 06 23:26:28 2021 +0000

description:
lint: fix return type of GCC's __builtin_alloca

Needed for libgmp.

diffstat:

 tests/usr.bin/xlint/lint1/gcc_builtin_alloca.c   |   8 +++++---
 tests/usr.bin/xlint/lint1/gcc_builtin_alloca.exp |   3 +--
 usr.bin/xlint/lint1/tree.c                       |  14 ++++++++++++--
 3 files changed, 18 insertions(+), 7 deletions(-)

diffs (74 lines):

diff -r 6ce6dbc6cc3a -r d1a7610b88c4 tests/usr.bin/xlint/lint1/gcc_builtin_alloca.c
--- a/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.c    Mon Dec 06 23:20:26 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.c    Mon Dec 06 23:26:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gcc_builtin_alloca.c,v 1.1 2021/12/06 23:20:26 rillig Exp $    */
+/*     $NetBSD: gcc_builtin_alloca.c,v 1.2 2021/12/06 23:26:28 rillig Exp $    */
 # 3 "gcc_builtin_alloca.c"
 
 /*
@@ -11,11 +11,13 @@
 void
 example(void)
 {
-       /* expect+1: warning: illegal combination of pointer (pointer to char) and integer (int) [183] */
        char *ptr = __builtin_alloca(8);
        ptr[4] = '4';
 
-       /* expect+1: warning: illegal combination of pointer (pointer to char) and integer (int) [183] */
        char *aligned_ptr = __builtin_alloca_with_align(8, 64);
        aligned_ptr[0] = '\0';
+
+       /* expect+1: warning: illegal combination of pointer (pointer to char) and integer (int) [183] */
+       char *unknown = __builtin_allocate(8);
+       unknown[0] = '\0';
 }
diff -r 6ce6dbc6cc3a -r d1a7610b88c4 tests/usr.bin/xlint/lint1/gcc_builtin_alloca.exp
--- a/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.exp  Mon Dec 06 23:20:26 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.exp  Mon Dec 06 23:26:28 2021 +0000
@@ -1,2 +1,1 @@
-gcc_builtin_alloca.c(15): warning: illegal combination of pointer (pointer to char) and integer (int) [183]
-gcc_builtin_alloca.c(19): warning: illegal combination of pointer (pointer to char) and integer (int) [183]
+gcc_builtin_alloca.c(21): warning: illegal combination of pointer (pointer to char) and integer (int) [183]
diff -r 6ce6dbc6cc3a -r d1a7610b88c4 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Mon Dec 06 23:20:26 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Mon Dec 06 23:26:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.396 2021/12/04 00:01:24 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.397 2021/12/06 23:26:28 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.396 2021/12/04 00:01:24 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.397 2021/12/06 23:26:28 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -234,6 +234,14 @@
                str_endswith(name, "_overflow_p"));
 }
 
+/* https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html */
+static bool
+is_gcc_void_pointer_builtin(const char *name)
+{
+       return strcmp(name, "__builtin_alloca") == 0 ||
+              strncmp(name, "__builtin_alloca_", 17) == 0;
+}
+
 static void
 build_name_call(sym_t *sym)
 {
@@ -247,6 +255,8 @@
 
                if (is_gcc_bool_builtin(sym->s_name))
                        sym->s_type = gettyp(BOOL);
+               else if (is_gcc_void_pointer_builtin(sym->s_name))
+                       sym->s_type = derive_type(gettyp(VOID), PTR);
 
        } else if (Sflag) {
                /* function '%s' implicitly declared to return int */



Home | Main Index | Thread Index | Old Index