Module Name: src
Committed By: rillig
Date: Fri Sep 3 22:48:49 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: gcc_builtin_overflow.c
gcc_builtin_overflow.exp
src/usr.bin/xlint/lint1: tree.c
Log Message:
lint: set the return type of __builtin_*_overflow to bool, not int
Needed for inetd.c in strict bool mode.
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/gcc_builtin_overflow.c \
src/tests/usr.bin/xlint/lint1/gcc_builtin_overflow.exp
cvs rdiff -u -r1.371 -r1.372 src/usr.bin/xlint/lint1/tree.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/usr.bin/xlint/lint1/gcc_builtin_overflow.c
diff -u src/tests/usr.bin/xlint/lint1/gcc_builtin_overflow.c:1.1 src/tests/usr.bin/xlint/lint1/gcc_builtin_overflow.c:1.2
--- src/tests/usr.bin/xlint/lint1/gcc_builtin_overflow.c:1.1 Fri Sep 3 22:44:09 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_builtin_overflow.c Fri Sep 3 22:48:49 2021
@@ -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 @@ is_overflow(void)
{
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;
}
Index: src/tests/usr.bin/xlint/lint1/gcc_builtin_overflow.exp
diff -u src/tests/usr.bin/xlint/lint1/gcc_builtin_overflow.exp:1.1 src/tests/usr.bin/xlint/lint1/gcc_builtin_overflow.exp:1.2
--- src/tests/usr.bin/xlint/lint1/gcc_builtin_overflow.exp:1.1 Fri Sep 3 22:44:09 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_builtin_overflow.exp Fri Sep 3 22:48:49 2021
@@ -1,2 +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]
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.371 src/usr.bin/xlint/lint1/tree.c:1.372
--- src/usr.bin/xlint/lint1/tree.c:1.371 Fri Sep 3 22:27:32 2021
+++ src/usr.bin/xlint/lint1/tree.c Fri Sep 3 22:48:49 2021
@@ -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 @@ is_compiler_builtin(const char *name)
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 @@ build_name_call(sym_t *sym)
* 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);