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: do not warn about use of implicitl...



details:   https://anonhg.NetBSD.org/src/rev/019f8b779bfb
branches:  trunk
changeset: 380011:019f8b779bfb
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Jun 30 14:42:13 2021 +0000

description:
lint: do not warn about use of implicitly declared GCC builtins

diffstat:

 tests/usr.bin/xlint/lint1/msg_215.c |   6 +++++-
 usr.bin/xlint/lint1/tree.c          |  20 +++++++++++++++++---
 2 files changed, 22 insertions(+), 4 deletions(-)

diffs (66 lines):

diff -r 1e24d8c98bca -r 019f8b779bfb tests/usr.bin/xlint/lint1/msg_215.c
--- a/tests/usr.bin/xlint/lint1/msg_215.c       Wed Jun 30 14:32:41 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_215.c       Wed Jun 30 14:42:13 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_215.c,v 1.8 2021/06/30 14:32:41 rillig Exp $       */
+/*     $NetBSD: msg_215.c,v 1.9 2021/06/30 14:42:13 rillig Exp $       */
 # 3 "msg_215.c"
 
 // Test for message: function '%s' implicitly declared to return int [215]
@@ -27,4 +27,8 @@ test(struct str str)
        /* expect+2: error: type 'struct str' does not have member 'member' [101] */
        /* expect+1: error: illegal function (type int) [149] */
        str.member();
+
+       /* https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html */
+       __builtin_whatever(123, "string");
+       __atomic_whatever(123, "string");
 }
diff -r 1e24d8c98bca -r 019f8b779bfb usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Wed Jun 30 14:32:41 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Wed Jun 30 14:42:13 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.302 2021/06/30 14:32:41 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.303 2021/06/30 14:42:13 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.302 2021/06/30 14:32:41 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.303 2021/06/30 14:42:13 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -232,6 +232,14 @@ fallback_symbol(sym_t *sym)
        error(99, sym->s_name);
 }
 
+/* https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html */
+static bool
+is_gcc_builtin(const char *name)
+{
+       return strncmp(name, "__atomic_", 9) == 0 ||
+              strncmp(name, "__builtin_", 10) == 0;
+}
+
 /*
  * Create a node for a name (symbol table entry).
  * follow_token is the token which follows the name.
@@ -245,7 +253,13 @@ new_name_node(sym_t *sym, int follow_tok
                sym->s_scl = EXTERN;
                sym->s_def = DECL;
                if (follow_token == T_LPAREN) {
-                       if (Sflag) {
+                       if (gflag && is_gcc_builtin(sym->s_name)) {
+                               /*
+                                * Do not warn about these, just assume that
+                                * they are regular functions compatible with
+                                * non-prototype calling conventions.
+                                */
+                       } else if (Sflag) {
                                /* function '%s' implicitly declared to ... */
                                warning(215, sym->s_name);
                        } else if (sflag) {



Home | Main Index | Thread Index | Old Index