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: set the return type of __builtin_*...



details:   https://anonhg.NetBSD.org/src/rev/f5f756e23895
branches:  trunk
changeset: 1023333:f5f756e23895
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Sep 03 22:48:49 2021 +0000

description:
lint: set the return type of __builtin_*_overflow to bool, not int

Needed for inetd.c in strict bool mode.

diffstat:

 tests/usr.bin/xlint/lint1/gcc_builtin_overflow.c   |   8 ++++--
 tests/usr.bin/xlint/lint1/gcc_builtin_overflow.exp |   3 +-
 usr.bin/xlint/lint1/tree.c                         |  27 ++++++++++++++++++++-
 3 files changed, 31 insertions(+), 7 deletions(-)

diffs (87 lines):

diff -r 5f05e9f35251 -r f5f756e23895 tests/usr.bin/xlint/lint1/gcc_builtin_overflow.c
--- a/tests/usr.bin/xlint/lint1/gcc_builtin_overflow.c  Fri Sep 03 22:44:08 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_builtin_overflow.c  Fri Sep 03 22:48:49 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gcc_builtin_overflow.c,v 1.1 2021/09/03 22:44:09 rillig Exp $  */
+/*     $NetBSD: gcc_builtin_overflow.c,v 1.2 2021/09/03 22:48:49 rillig Exp $  */
 # 3 "gcc_builtin_overflow.c"
 
 /*
@@ -15,11 +15,13 @@
 {
        int sum;
 
-       /* expect+1: error: controlling expression must be bool, not 'int' [333] */
        if (__builtin_add_overflow(1, 2, &sum))
                return;
 
-       /* expect+1: error: controlling expression must be bool, not 'int' [333] */
        if (__builtin_add_overflow_p(1, 2, 12345))
                return;
+
+       /* expect+1: error: controlling expression must be bool, not 'int' [333] */
+       if (__builtin_other(1, 2, 12345))
+               return;
 }
diff -r 5f05e9f35251 -r f5f756e23895 tests/usr.bin/xlint/lint1/gcc_builtin_overflow.exp
--- a/tests/usr.bin/xlint/lint1/gcc_builtin_overflow.exp        Fri Sep 03 22:44:08 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_builtin_overflow.exp        Fri Sep 03 22:48:49 2021 +0000
@@ -1,2 +1,1 @@
-gcc_builtin_overflow.c(19): error: controlling expression must be bool, not 'int' [333]
-gcc_builtin_overflow.c(23): error: controlling expression must be bool, not 'int' [333]
+gcc_builtin_overflow.c(25): error: controlling expression must be bool, not 'int' [333]
diff -r 5f05e9f35251 -r f5f756e23895 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Fri Sep 03 22:44:08 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Fri Sep 03 22:48:49 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.371 2021/09/03 22:27:32 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.372 2021/09/03 22:48:49 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.371 2021/09/03 22:27:32 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.372 2021/09/03 22:48:49 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -215,6 +215,25 @@
        return false;
 }
 
+static bool
+str_endswith(const char *haystack, const char *needle)
+{
+       size_t hlen = strlen(haystack);
+       size_t nlen = strlen(needle);
+
+       return nlen <= hlen &&
+              memcmp(haystack + hlen - nlen, needle, nlen) == 0;
+}
+
+/* https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html */
+static bool
+is_gcc_bool_builtin(const char *name)
+{
+       return strncmp(name, "__builtin_", 10) == 0 &&
+              (str_endswith(name, "_overflow") ||
+               str_endswith(name, "_overflow_p"));
+}
+
 static void
 build_name_call(sym_t *sym)
 {
@@ -225,6 +244,10 @@
                 * they are regular functions compatible with
                 * non-prototype calling conventions.
                 */
+
+               if (is_gcc_bool_builtin(sym->s_name))
+                       sym->s_type = gettyp(BOOL);
+
        } else if (Sflag) {
                /* function '%s' implicitly declared to return int */
                error(215, sym->s_name);



Home | Main Index | Thread Index | Old Index