Module Name: src
Committed By: rillig
Date: Sun Aug 29 15:49:04 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_215.c
src/usr.bin/xlint/lint1: decl.c externs1.h tree.c
Log Message:
lint: add __sync_ and _mm_ as prefixes for builtin functions
These two additions cover all cases that occur in the current NetBSD
build on x86_64. This allows build_name to use the usual pattern 'if
Sflag then error else if sflag then warning'. That function currently
issues a warning in C99 as well, even though C99 prohibits implicit
function declarations.
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/msg_215.c
cvs rdiff -u -r1.227 -r1.228 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.136 -r1.137 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.360 -r1.361 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/msg_215.c
diff -u src/tests/usr.bin/xlint/lint1/msg_215.c:1.9 src/tests/usr.bin/xlint/lint1/msg_215.c:1.10
--- src/tests/usr.bin/xlint/lint1/msg_215.c:1.9 Wed Jun 30 14:42:13 2021
+++ src/tests/usr.bin/xlint/lint1/msg_215.c Sun Aug 29 15:49:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_215.c,v 1.9 2021/06/30 14:42:13 rillig Exp $ */
+/* $NetBSD: msg_215.c,v 1.10 2021/08/29 15:49:04 rillig Exp $ */
# 3 "msg_215.c"
// Test for message: function '%s' implicitly declared to return int [215]
@@ -15,7 +15,7 @@ struct str {
/* ARGSUSED */
void
-test(struct str str)
+test(struct str str, const double *p_double)
{
/* expect+1: warning: function 'name' implicitly declared to return int [215] */
name();
@@ -31,4 +31,9 @@ test(struct str str)
/* https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html */
__builtin_whatever(123, "string");
__atomic_whatever(123, "string");
+ /* obsolete but still in use, as of 2021 */
+ __sync_whatever(123, "string");
+
+ /* https://software.intel.com/sites/landingpage/IntrinsicsGuide/ */
+ _mm_load_sd(p_double);
}
Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.227 src/usr.bin/xlint/lint1/decl.c:1.228
--- src/usr.bin/xlint/lint1/decl.c:1.227 Sat Aug 28 16:36:54 2021
+++ src/usr.bin/xlint/lint1/decl.c Sun Aug 29 15:49:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.227 2021/08/28 16:36:54 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.228 2021/08/29 15:49:04 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.227 2021/08/28 16:36:54 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.228 2021/08/29 15:49:04 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 if (!is_gcc_builtin(dsym->s_name)) {
+ } else if (!is_compiler_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.136 src/usr.bin/xlint/lint1/externs1.h:1.137
--- src/usr.bin/xlint/lint1/externs1.h:1.136 Sat Aug 28 16:36:54 2021
+++ src/usr.bin/xlint/lint1/externs1.h Sun Aug 29 15:49:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.136 2021/08/28 16:36:54 rillig Exp $ */
+/* $NetBSD: externs1.h,v 1.137 2021/08/29 15:49:04 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -234,7 +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 bool is_compiler_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.360 src/usr.bin/xlint/lint1/tree.c:1.361
--- src/usr.bin/xlint/lint1/tree.c:1.360 Sat Aug 28 16:51:57 2021
+++ src/usr.bin/xlint/lint1/tree.c Sun Aug 29 15:49:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.360 2021/08/28 16:51:57 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.361 2021/08/29 15:49:04 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.360 2021/08/28 16:51:57 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.361 2021/08/29 15:49:04 rillig Exp $");
#endif
#include <float.h>
@@ -192,17 +192,28 @@ fallback_symbol(sym_t *sym)
}
/*
- * 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
+ * Functions that are predeclared by GCC or other compilers can be called
+ * with arbitrary arguments. Since lint usually runs after a successful
+ * compilation, it's the compiler's job to catch any errors.
*/
bool
-is_gcc_builtin(const char *name)
+is_compiler_builtin(const char *name)
{
- return strncmp(name, "__atomic_", 9) == 0 ||
- strncmp(name, "__builtin_", 10) == 0;
+ /* https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html */
+ if (strncmp(name, "__atomic_", 9) == 0 ||
+ strncmp(name, "__builtin_", 10) == 0)
+ return true;
+
+ /* https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html */
+ /* obsolete but still in use, as of 2021 */
+ if (strncmp(name, "__sync_", 7) == 0)
+ return true;
+
+ /* https://software.intel.com/sites/landingpage/IntrinsicsGuide/ */
+ if (strncmp(name, "_mm_", 4) == 0)
+ return true;
+
+ return false;
}
/*
@@ -218,7 +229,7 @@ build_name(sym_t *sym, int follow_token)
sym->s_scl = EXTERN;
sym->s_def = DECL;
if (follow_token == T_LPAREN) {
- if (gflag && is_gcc_builtin(sym->s_name)) {
+ if (gflag && is_compiler_builtin(sym->s_name)) {
/*
* Do not warn about these, just assume that
* they are regular functions compatible with
@@ -3945,7 +3956,8 @@ 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 && !is_gcc_builtin(ln->tn_left->tn_sym->s_name))
+ if (!szof &&
+ !is_compiler_builtin(ln->tn_left->tn_sym->s_name))
outcall(tn, vctx || tctx, rvdisc);
break;
case EQ: