Module Name:    src
Committed By:   rillig
Date:           Sat Aug 28 16:36:54 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: emit.exp-ln
        src/usr.bin/xlint/lint1: decl.c externs1.h tree.c

Log Message:
lint: do not emit GCC builtin functions

Lint1 no longer emits declarations of GCC builtin functions and calls to
them.

Previously, lint generated 3421 useless warnings in a default NetBSD
build, like this:

        __atomic_load_n, arg 1 used inconsistently
            acl.c(216)[pointer to unsigned int]
            rbtdb.c(921)[pointer to unsigned short]

This was because lint just doesn't understand that these functions are
type-generic, which is indeed unusual in C.

These useless warnings made the lint output more frightening than it
should actually be.  Together with the strange formatting of the
diagnostics (space-space-tab after the main message, two spaces and two
colons between the occurrences, symbols are listed in hashcode order),
this creates the impression that lint is not intended to be a
user-friendly tool.

For now, fix the excess warnings, leaving the other items for later.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/emit.exp-ln
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.135 -r1.136 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.357 -r1.358 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/emit.exp-ln
diff -u src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.3 src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.4
--- src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.3	Sat Aug 28 16:21:24 2021
+++ src/tests/usr.bin/xlint/lint1/emit.exp-ln	Sat Aug 28 16:36:54 2021
@@ -1,6 +1,3 @@
-1d-1.1e15__builtin_isinfF1lDI
-2d-1.2e15__builtin_isnanF1lDI
-3d-1.3e18__builtin_copysignF2lDlDI
 0semit.c
 Semit.c
 47d0.47e12extern__BoolB
@@ -59,7 +56,4 @@ Semit.c
 163c0.163s2"%%"i9my_printff2PcCPCV
 164c0.164s2"%\a%\b%\f%\n%\r%\t%\v%\177"i9my_printff2PcCPCV
 159d0.159d14cover_outqcharF0V
-177c0.177p2i16__builtin_expectf2III
-178c0.178p1i17__builtin_bswap32f1II
-180c0.180z3i13__atomic_loadf3PLPLII
 173d0.173d17call_gcc_builtinsF2IPLV

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.226 src/usr.bin/xlint/lint1/decl.c:1.227
--- src/usr.bin/xlint/lint1/decl.c:1.226	Sat Aug 28 12:59:25 2021
+++ src/usr.bin/xlint/lint1/decl.c	Sat Aug 28 16:36:54 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.226 2021/08/28 12:59:25 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.227 2021/08/28 16:36:54 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.226 2021/08/28 12:59:25 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.227 2021/08/28 16:36:54 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1972,7 +1972,7 @@ declare_extern(sym_t *dsym, bool initflg
 		 */
 		rval = dsym->s_type->t_subt->t_tspec != VOID;
 		outfdef(dsym, &dsym->s_def_pos, rval, false, NULL);
-	} else {
+	} else if (!is_gcc_builtin(dsym->s_name)) {
 		outsym(dsym, dsym->s_scl, dsym->s_def);
 	}
 

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.135 src/usr.bin/xlint/lint1/externs1.h:1.136
--- src/usr.bin/xlint/lint1/externs1.h:1.135	Sat Aug 28 13:11:10 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Sat Aug 28 16:36:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.135 2021/08/28 13:11:10 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.136 2021/08/28 16:36:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -234,6 +234,7 @@ extern	const char *scl_name(scl_t);
 extern	const tnode_t *before_conversion(const tnode_t *);
 extern	type_t	*derive_type(type_t *, tspec_t);
 extern	type_t	*expr_derive_type(type_t *, tspec_t);
+extern	bool	is_gcc_builtin(const char *);
 extern	tnode_t	*build_constant(type_t *, val_t *);
 extern	tnode_t	*build_name(sym_t *, int);
 extern	tnode_t	*build_string(strg_t *);

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.357 src/usr.bin/xlint/lint1/tree.c:1.358
--- src/usr.bin/xlint/lint1/tree.c:1.357	Sat Aug 28 15:36:54 2021
+++ src/usr.bin/xlint/lint1/tree.c	Sat Aug 28 16:36:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.357 2021/08/28 15:36:54 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.358 2021/08/28 16:36:54 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.357 2021/08/28 15:36:54 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.358 2021/08/28 16:36:54 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -191,8 +191,14 @@ fallback_symbol(sym_t *sym)
 	error(99, sym->s_name);
 }
 
-/* https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html */
-static bool
+/*
+ * Functions that are predeclared by GCC can be called with arbitrary
+ * arguments.  Since lint usually runs after a successful compilation, it's
+ * the compiler's job to catch any errors.
+ *
+ * https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html
+ */
+bool
 is_gcc_builtin(const char *name)
 {
 	return strncmp(name, "__atomic_", 9) == 0 ||
@@ -3939,7 +3945,7 @@ check_expr_misc(const tnode_t *tn, bool 
 	case CALL:
 		lint_assert(ln->tn_op == ADDR);
 		lint_assert(ln->tn_left->tn_op == NAME);
-		if (!szof)
+		if (!szof && !is_gcc_builtin(ln->tn_left->tn_sym->s_name))
 			outcall(tn, vctx || tctx, rvdisc);
 		break;
 	case EQ:

Reply via email to