Module Name:    src
Committed By:   rillig
Date:           Sat Sep 28 14:25:04 UTC 2024

Modified Files:
        src/tests/usr.bin/xlint/lint1: decl_arg.c
        src/usr.bin/xlint/lint1: cgram.y

Log Message:
lint: allow more than one __attribute__ on a parameter declaration


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/tests/usr.bin/xlint/lint1/decl_arg.c
cvs rdiff -u -r1.508 -r1.509 src/usr.bin/xlint/lint1/cgram.y

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/decl_arg.c
diff -u src/tests/usr.bin/xlint/lint1/decl_arg.c:1.13 src/tests/usr.bin/xlint/lint1/decl_arg.c:1.14
--- src/tests/usr.bin/xlint/lint1/decl_arg.c:1.13	Sun Jan 28 08:17:27 2024
+++ src/tests/usr.bin/xlint/lint1/decl_arg.c	Sat Sep 28 14:25:04 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: decl_arg.c,v 1.13 2024/01/28 08:17:27 rillig Exp $	*/
+/*	$NetBSD: decl_arg.c,v 1.14 2024/09/28 14:25:04 rillig Exp $	*/
 # 3 "decl_arg.c"
 
 /*
@@ -95,10 +95,32 @@ const
 	return arg;
 }
 
-void test_varargs_attribute(
+// The attribute 'unused' belongs to the parameter.
+// The attribute 'format' belongs to the function type.
+void
+param_func_attr_unused(
+    /* FIXME: handle the 'unused' attribute */
+    /* expect+1: warning: parameter 'pr' unused in function 'param_func_attr_unused' [231] */
     void (*pr)(const char *, ...)
+	__attribute__((__unused__))
 	__attribute__((__format__(__printf__, 1, 2)))
-);
+)
+{
+}
+
+// The attribute 'unused' belongs to the parameter.
+// The attribute 'format' belongs to the function type.
+void
+param_func_attr_printf(
+    void (*pr)(const char *, ...)
+	__attribute__((__unused__))
+	__attribute__((__format__(__printf__, 1, 2)))
+)
+{
+	// GCC and Clang already warn about the malformed format string,
+	// so there is nothing left to do for lint.
+	pr("%");
+}
 
 /*
  * XXX: To cover the grammar rule 'direct_notype_param_decl', the parameters

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.508 src/usr.bin/xlint/lint1/cgram.y:1.509
--- src/usr.bin/xlint/lint1/cgram.y:1.508	Sat Sep 28 11:20:29 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Sep 28 14:25:04 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.508 2024/09/28 11:20:29 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.509 2024/09/28 14:25:04 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.508 2024/09/28 11:20:29 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.509 2024/09/28 14:25:04 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -154,7 +154,7 @@ new_attribute(const sbuf_t *prefix, cons
 
 %}
 
-%expect 107
+%expect 110
 
 %union {
 	val_t	*y_val;
@@ -1699,15 +1699,15 @@ abstract_declaration:		/* specific to li
 ;
 
 abstract_decl_param_list:	/* specific to lint */
-	abstract_decl_lparen T_RPAREN type_attribute_opt {
+	abstract_decl_lparen T_RPAREN type_attribute_list_opt {
 		$$ = (parameter_list){ .first = NULL };
 	}
 |	abstract_decl_lparen vararg_parameter_type_list T_RPAREN
-	    type_attribute_opt {
+	    type_attribute_list_opt {
 		$$ = $2;
 		$$.prototype = true;
 	}
-|	abstract_decl_lparen error T_RPAREN type_attribute_opt {
+|	abstract_decl_lparen error T_RPAREN type_attribute_list_opt {
 		$$ = (parameter_list){ .first = NULL };
 	}
 ;

Reply via email to