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: in GCC mode, declare alloca and va...



details:   https://anonhg.NetBSD.org/src/rev/e5e9b848e1cd
branches:  trunk
changeset: 1027711:e5e9b848e1cd
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Dec 17 00:05:24 2021 +0000

description:
lint: in GCC mode, declare alloca and variants

The prototype declarations define the correct parameter types of these
functions so that they are no longer subject to the default argument
promotions (C11 6.5.2.2p6).

The GCC builtins are only recognized in GCC mode (-g).

diffstat:

 usr.bin/xlint/lint1/main1.c |  14 ++++++++++++--
 usr.bin/xlint/lint1/tree.c  |  18 ++++--------------
 2 files changed, 16 insertions(+), 16 deletions(-)

diffs (90 lines):

diff -r 49fe1603305f -r e5e9b848e1cd usr.bin/xlint/lint1/main1.c
--- a/usr.bin/xlint/lint1/main1.c       Thu Dec 16 23:46:21 2021 +0000
+++ b/usr.bin/xlint/lint1/main1.c       Fri Dec 17 00:05:24 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main1.c,v 1.57 2021/08/28 13:29:26 rillig Exp $        */
+/*     $NetBSD: main1.c,v 1.58 2021/12/17 00:05:24 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: main1.c,v 1.57 2021/08/28 13:29:26 rillig Exp $");
+__RCSID("$NetBSD: main1.c,v 1.58 2021/12/17 00:05:24 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -133,7 +133,17 @@
 static FILE *
 gcc_builtins(void)
 {
+       /* https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html */
        static const char builtins[] =
+           "typedef typeof(sizeof(0)) __lint_size_t;\n"
+
+           "void *alloca(__lint_size_t);\n"
+           "void *__builtin_alloca(__lint_size_t);\n"
+           "void *__builtin_alloca_with_align"
+               "(__lint_size_t, __lint_size_t);\n"
+           "void *__builtin_alloca_with_align_and_max"
+               "(__lint_size_t, __lint_size_t, __lint_size_t);\n"
+
            "int __builtin_isinf(long double);\n"
            "int __builtin_isnan(long double);\n"
            "int __builtin_copysign(long double, long double);\n";
diff -r 49fe1603305f -r e5e9b848e1cd usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Thu Dec 16 23:46:21 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Fri Dec 17 00:05:24 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.399 2021/12/16 23:46:21 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.400 2021/12/17 00:05:24 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.399 2021/12/16 23:46:21 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.400 2021/12/17 00:05:24 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -203,6 +203,7 @@
        if (gflag) {
                if (strncmp(name, "__atomic_", 9) == 0 ||
                    strncmp(name, "__builtin_", 10) == 0 ||
+                   strcmp(name, "alloca") == 0 ||
                    /* obsolete but still in use, as of 2021 */
                    strncmp(name, "__sync_", 7) == 0)
                        return true;
@@ -234,14 +235,6 @@
                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)
 {
@@ -252,11 +245,8 @@
                 * they are regular functions compatible with
                 * non-prototype calling conventions.
                 */
-
-               if (is_gcc_bool_builtin(sym->s_name))
+               if (gflag && 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