CVS commit: src

2021-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May  3 05:24:45 UTC 2021

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

Log Message:
lint: fix parsing of __typeof__ after statement in ({ ... })

Since C99, declarations and statements can be freely mixed, and GCC
supported this even before 1999.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 \
src/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.c \
src/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.exp
cvs rdiff -u -r1.225 -r1.226 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/gcc_typeof_after_statement.c
diff -u src/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.c:1.1 src/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.c:1.2
--- src/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.c:1.1	Thu Apr 22 22:43:26 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.c	Mon May  3 05:24:44 2021
@@ -1,9 +1,9 @@
-/*	$NetBSD: gcc_typeof_after_statement.c,v 1.1 2021/04/22 22:43:26 rillig Exp $	*/
+/*	$NetBSD: gcc_typeof_after_statement.c,v 1.2 2021/05/03 05:24:44 rillig Exp $	*/
 # 3 "gcc_typeof_after_statement.c"
 
 /*
- * As of 2021-04-23, lint cannot parse typeof(...) if there is a statement
- * before it.
+ * Before cgram.y 1.226 from 2021-05-03, lint could not parse typeof(...) if
+ * there was a statement before it.
  */
 
 void *
@@ -12,12 +12,11 @@ example(void **ptr)
 	return ({
 		if (*ptr != (void *)0)
 			ptr++;
-
-		/* FIXME: This is a legitimate use case. */
-		/* expect+1: syntax error '__typeof__' [249] */
 		__typeof__(*ptr) ret = *ptr;
-		/* expect+1: 'ret' undefined [99] */
 		ret;
-		/* expect+1: illegal combination of pointer (pointer to void) and integer (int) [183] */
 	});
 }
+
+/* Just to keep the .exp file. */
+/* expect+1: static function unused declared but not defined */
+static void unused(void);
Index: src/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.exp
diff -u src/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.exp:1.1 src/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.exp:1.2
--- src/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.exp:1.1	Thu Apr 22 22:43:26 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.exp	Mon May  3 05:24:44 2021
@@ -1,3 +1 @@
-gcc_typeof_after_statement.c(18): error: syntax error '__typeof__' [249]
-gcc_typeof_after_statement.c(20): error: 'ret' undefined [99]
-gcc_typeof_after_statement.c(22): warning: illegal combination of pointer (pointer to void) and integer (int) [183]
+gcc_typeof_after_statement.c(22): warning: static function unused declared but not defined [290]

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.225 src/usr.bin/xlint/lint1/cgram.y:1.226
--- src/usr.bin/xlint/lint1/cgram.y:1.225	Sun May  2 20:53:13 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Mon May  3 05:24:44 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.225 2021/05/02 20:53:13 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.226 2021/05/03 05:24:44 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.225 2021/05/02 20:53:13 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.226 2021/05/03 05:24:44 rillig Exp $");
 #endif
 
 #include 
@@ -123,7 +123,7 @@ anonymize(sym_t *s)
 }
 %}
 
-%expect 189
+%expect 181
 
 %union {
 	val_t	*y_val;
@@ -323,8 +323,8 @@ anonymize(sym_t *s)
 %type			parameter_type_list
 %type			parameter_declaration
 %type		expr
-%type		expr_statement_val
-%type		expr_statement_list
+%type		gcc_statement_expr_list
+%type		gcc_statement_expr_item
 %type		term
 %type		generic_expr
 %type		func_arg_list
@@ -1614,33 +1614,6 @@ expr_statement:
 	  }
 	;
 
-/*
- * The following two productions are used to implement
- * ({ [[decl-list] stmt-list] }).
- * XXX: This is not well tested.
- */
-expr_statement_val:
-	  expr T_SEMI {
-		/* XXX: We should really do that only on the last name */
-		if ($1->tn_op == NAME)
-			$1->tn_sym->s_used = true;
-		$$ = $1;
-		expr($1, false, false, false, false);
-		seen_fallthrough = false;
-	  }
-	| non_expr_statement {
-		$$ = expr_zalloc_tnode();
-		$$->tn_type = gettyp(VOID);
-	  }
-	;
-
-expr_statement_list:
-	  expr_statement_val
-	| expr_statement_list expr_statement_val {
-		$$ = $2;
-	  }
-	;
-
 selection_statement:		/* C99 6.8.4 */
 	  if_without_else {
 		save_warning_flags();
@@ -1831,20 +1804,6 @@ read_until_rparen:
 	  }
 	;
 
-declaration_list_opt:
-	  /* empty */
-	| declaration_list
-	;
-
-declaration_list:
-	  declaration {
-		clear_warning_flags();
-	  }
-	| declaration_list declaration {
-		clear_warning_flags();
-	  }
-	;
-
 

CVS commit: src/tests/usr.bin/xlint/lint1

2021-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May  3 03:50:43 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: t_integration.sh

Log Message:
tests/lint: remove outdated comment

The test d_gcc_extension is already activated in line 121.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/tests/usr.bin/xlint/lint1/t_integration.sh

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/t_integration.sh
diff -u src/tests/usr.bin/xlint/lint1/t_integration.sh:1.47 src/tests/usr.bin/xlint/lint1/t_integration.sh:1.48
--- src/tests/usr.bin/xlint/lint1/t_integration.sh:1.47	Sun May  2 21:22:09 2021
+++ src/tests/usr.bin/xlint/lint1/t_integration.sh	Mon May  3 03:50:43 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.47 2021/05/02 21:22:09 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.48 2021/05/03 03:50:43 rillig Exp $
 #
 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -158,9 +158,6 @@ test_case d_gcc_compound_statements1
 test_case d_gcc_compound_statements2
 test_case d_gcc_compound_statements3
 
-# XXX: Because of polymorphic __builtin_isnan and expression has null effect
-# test_case gcc_extension "Checks GCC __extension__ and __typeof__"
-
 test_case d_cvt_in_ternary
 test_case d_cvt_constant
 test_case d_ellipsis_in_switch



CVS commit: src/usr.bin/xlint/lint1

2021-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May  3 03:46:55 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: lex.c

Log Message:
lint: fix compiler warning about signedness mismatch

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/xlint/lint1/lex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.31 src/usr.bin/xlint/lint1/lex.c:1.32
--- src/usr.bin/xlint/lint1/lex.c:1.31	Sat May  1 00:08:44 2021
+++ src/usr.bin/xlint/lint1/lex.c	Mon May  3 03:46:55 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.31 2021/05/01 00:08:44 christos Exp $ */
+/* $NetBSD: lex.c,v 1.32 2021/05/03 03:46:55 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: lex.c,v 1.31 2021/05/01 00:08:44 christos Exp $");
+__RCSID("$NetBSD: lex.c,v 1.32 2021/05/03 03:46:55 rillig Exp $");
 #endif
 
 #include 
@@ -261,7 +261,7 @@ symt_t	symtyp;
 
 
 static void
-add_keyword(struct kwtab *kw, int deco)
+add_keyword(struct kwtab *kw, u_int deco)
 {
 	sym_t *sym;
 	size_t h;



CVS commit: src

2021-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May  2 22:07:49 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: gcc_bit_field_types.c
gcc_bit_field_types.exp
src/usr.bin/xlint/lint1: decl.c

Log Message:
lint: allow large integer types for bit-fields in GCC mode

These types are explicitly allowed by GCC.

I'm not sure which of the flags -g and -p should be stronger.  That is,
if both -g and -p are given, should 'unsigned char' be allowed as a
bit-field type since -g would allow it, or should it be warned about
since -p warns about it?  For now, continue to warn about these.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c \
src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp
cvs rdiff -u -r1.179 -r1.180 src/usr.bin/xlint/lint1/decl.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_bit_field_types.c
diff -u src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c:1.2 src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c:1.3
--- src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c:1.2	Sun May  2 21:47:28 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c	Sun May  2 22:07:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: gcc_bit_field_types.c,v 1.2 2021/05/02 21:47:28 rillig Exp $	*/
+/*	$NetBSD: gcc_bit_field_types.c,v 1.3 2021/05/02 22:07:49 rillig Exp $	*/
 # 3 "gcc_bit_field_types.c"
 
 /*
@@ -13,9 +13,9 @@
 struct example {
 	int int_flag: 1;
 	unsigned int unsigned_int_flag: 1;
-	long long_flag: 1;	/* expect: 35 *//*FIXME*/
-	unsigned long unsigned_long_flag: 1;	/* expect: 35 *//*FIXME*/
-	long long long_long_flag: 1;	/* expect: 35 *//*FIXME*/
-	unsigned long long unsigned_long_long_flag: 1;	/* expect: 35 *//*FIXME*/
-	double double_flag: 1;	/* expect: 35 */
+	long long_flag: 1;
+	unsigned long unsigned_long_flag: 1;
+	long long long_long_flag: 1;
+	unsigned long long unsigned_long_long_flag: 1;
+	double double_flag: 1;	/* expect: illegal bit-field type 'double' */
 };
Index: src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp
diff -u src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp:1.2 src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp:1.3
--- src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp:1.2	Sun May  2 21:47:28 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp	Sun May  2 22:07:49 2021
@@ -1,5 +1 @@
-gcc_bit_field_types.c(16): warning: illegal bit-field type 'long' [35]
-gcc_bit_field_types.c(17): warning: illegal bit-field type 'unsigned long' [35]
-gcc_bit_field_types.c(18): warning: illegal bit-field type 'long long' [35]
-gcc_bit_field_types.c(19): warning: illegal bit-field type 'unsigned long long' [35]
 gcc_bit_field_types.c(20): warning: illegal bit-field type 'double' [35]

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.179 src/usr.bin/xlint/lint1/decl.c:1.180
--- src/usr.bin/xlint/lint1/decl.c:1.179	Sun May  2 21:48:53 2021
+++ src/usr.bin/xlint/lint1/decl.c	Sun May  2 22:07:49 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.179 2021/05/02 21:48:53 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.180 2021/05/02 22:07:49 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.179 2021/05/02 21:48:53 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.180 2021/05/02 22:07:49 rillig Exp $");
 #endif
 
 #include 
@@ -1121,7 +1121,7 @@ check_bit_field_type(sym_t *dsym,  type_
 		 * regardless of BITFIELDTYPE. Integer types not dealt with
 		 * above are okay only if BITFIELDTYPE is in effect.
 		 */
-		if (!bitfieldtype_ok || !is_integer(t)) {
+		if (!(bitfieldtype_ok || gflag) || !is_integer(t)) {
 			/* illegal bit-field type '%s' */
 			warning(35, type_name(tp));
 			int sz = tp->t_flen;



CVS commit: src/usr.bin/xlint/lint1

2021-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May  2 21:48:53 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: decl.c

Log Message:
lint: extract check_bit_field_type from declare_bit_field

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.178 -r1.179 src/usr.bin/xlint/lint1/decl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.178 src/usr.bin/xlint/lint1/decl.c:1.179
--- src/usr.bin/xlint/lint1/decl.c:1.178	Sun Apr 18 17:36:18 2021
+++ src/usr.bin/xlint/lint1/decl.c	Sun May  2 21:48:53 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.178 2021/04/18 17:36:18 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.179 2021/05/02 21:48:53 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.178 2021/04/18 17:36:18 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.179 2021/05/02 21:48:53 rillig Exp $");
 #endif
 
 #include 
@@ -1094,10 +1094,10 @@ check_type(sym_t *sym)
  * implementation-defined type".
  */
 static void
-declare_bit_field(sym_t *dsym, tspec_t *inout_t, type_t **const inout_tp)
+check_bit_field_type(sym_t *dsym,  type_t **const inout_tp, tspec_t *inout_t)
 {
-	tspec_t t = *inout_t;
 	type_t *tp = *inout_tp;
+	tspec_t t = *inout_t;
 
 	if (t == CHAR || t == UCHAR || t == SCHAR ||
 	t == SHORT || t == USHORT || t == ENUM) {
@@ -1128,9 +1128,20 @@ declare_bit_field(sym_t *dsym, tspec_t *
 			dsym->s_type = tp = dup_type(gettyp(t = INT));
 			if ((tp->t_flen = sz) > size_in_bits(t))
 tp->t_flen = size_in_bits(t);
+			*inout_t = t;
+			*inout_tp = tp;
 		}
 	}
+}
+
+static void
+declare_bit_field(sym_t *dsym, tspec_t *inout_t, type_t **const inout_tp)
+{
 
+	check_bit_field_type(dsym, inout_tp, inout_t);
+
+	type_t *const tp = *inout_tp;
+	tspec_t const t = *inout_t;
 	if (tp->t_flen < 0 || tp->t_flen > (ssize_t)size_in_bits(t)) {
 		/* illegal bit-field size: %d */
 		error(36, tp->t_flen);
@@ -1146,9 +1157,6 @@ declare_bit_field(sym_t *dsym, tspec_t *
 		dsym->s_type->t_bitfield = false;
 		dsym->s_bitfield = false;
 	}
-
-	*inout_t = t;
-	*inout_tp = tp;
 }
 
 /*



CVS commit: src/tests/usr.bin/xlint/lint1

2021-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May  2 21:47:28 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: gcc_bit_field_types.c
gcc_bit_field_types.exp

Log Message:
tests/lint: fix test for GCC bit-field types

The whole purpose of this test is to try the message about invalid
bit-field types in GCC mode.  Therefore, use the default lint1-flags
that include -g.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c \
src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp

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_bit_field_types.c
diff -u src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c:1.1 src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c:1.2
--- src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c:1.1	Sun May  2 21:22:09 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c	Sun May  2 21:47:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: gcc_bit_field_types.c,v 1.1 2021/05/02 21:22:09 rillig Exp $	*/
+/*	$NetBSD: gcc_bit_field_types.c,v 1.2 2021/05/02 21:47:28 rillig Exp $	*/
 # 3 "gcc_bit_field_types.c"
 
 /*
@@ -10,12 +10,6 @@
  * See msg_035.c.
  */
 
-// Test for message: illegal bit-field type '%s' [35]
-
-/* Omit -g, see gcc_bit_field_types.c. */
-/* lint1-flags: -Sw */
-
-/* Try all types from tspec_t. */
 struct example {
 	int int_flag: 1;
 	unsigned int unsigned_int_flag: 1;
Index: src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp
diff -u src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp:1.1 src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp:1.2
--- src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp:1.1	Sun May  2 21:22:09 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp	Sun May  2 21:47:28 2021
@@ -1,5 +1,5 @@
-gcc_bit_field_types.c(22): warning: illegal bit-field type 'long' [35]
-gcc_bit_field_types.c(23): warning: illegal bit-field type 'unsigned long' [35]
-gcc_bit_field_types.c(24): warning: illegal bit-field type 'long long' [35]
-gcc_bit_field_types.c(25): warning: illegal bit-field type 'unsigned long long' [35]
-gcc_bit_field_types.c(26): warning: illegal bit-field type 'double' [35]
+gcc_bit_field_types.c(16): warning: illegal bit-field type 'long' [35]
+gcc_bit_field_types.c(17): warning: illegal bit-field type 'unsigned long' [35]
+gcc_bit_field_types.c(18): warning: illegal bit-field type 'long long' [35]
+gcc_bit_field_types.c(19): warning: illegal bit-field type 'unsigned long long' [35]
+gcc_bit_field_types.c(20): warning: illegal bit-field type 'double' [35]



CVS commit: src/sys/dev/audio

2021-05-02 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Sun May  2 21:37:32 UTC 2021

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
audio: Only score hardware formats by channel count at count<=2

Scoring by channel count makes sense when you are using hardware that
supports mono and stereo formats. However, if your hardware also supports
surround formats, defaulting to those might be confusing. So, don't
prefer them.

Problem reported and fix tested by tcmart14 with a 2015 model Macbook Pro.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/dev/audio/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.94 src/sys/dev/audio/audio.c:1.95
--- src/sys/dev/audio/audio.c:1.94	Mon Apr 26 19:59:58 2021
+++ src/sys/dev/audio/audio.c	Sun May  2 21:37:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.94 2021/04/26 19:59:58 thorpej Exp $	*/
+/*	$NetBSD: audio.c,v 1.95 2021/05/02 21:37:32 nia Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.94 2021/04/26 19:59:58 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.95 2021/05/02 21:37:32 nia Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -6574,7 +6574,10 @@ audio_hw_probe(struct audio_softc *sc, a
 		query.fmt.precision == AUDIO_INTERNAL_BITS) {
 			score += 0x10;
 		}
-		score += query.fmt.channels;
+
+		/* Do not prefer surround formats */
+		if (query.fmt.channels <= 2)
+			score += query.fmt.channels;
 
 		if (score < cand_score) {
 			DPRINTF(1, "fmt[%d] skip; score 0x%x < 0x%x\n", i,



CVS commit: src

2021-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May  2 21:22:09 UTC 2021

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: Makefile msg_035.c msg_035.exp
t_integration.sh
Added Files:
src/tests/usr.bin/xlint/lint1: gcc_bit_field_types.c
gcc_bit_field_types.exp

Log Message:
tests/lint: add test for bit-field types in GCC mode


To generate a diff of this commit:
cvs rdiff -u -r1.1048 -r1.1049 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.54 -r1.55 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c \
src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_035.c
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/msg_035.exp
cvs rdiff -u -r1.46 -r1.47 src/tests/usr.bin/xlint/lint1/t_integration.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1048 src/distrib/sets/lists/tests/mi:1.1049
--- src/distrib/sets/lists/tests/mi:1.1048	Sun May  2 20:44:46 2021
+++ src/distrib/sets/lists/tests/mi	Sun May  2 21:22:09 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1048 2021/05/02 20:44:46 rillig Exp $
+# $NetBSD: mi,v 1.1049 2021/05/02 21:22:09 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6195,6 +6195,8 @@
 ./usr/tests/usr.bin/xlint/lint1/gcc_attribute.exp		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.exp	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c		tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.c	tests-usr.bin-tests	compattestfile,atf

Index: src/tests/usr.bin/xlint/lint1/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.54 src/tests/usr.bin/xlint/lint1/Makefile:1.55
--- src/tests/usr.bin/xlint/lint1/Makefile:1.54	Sun May  2 20:44:46 2021
+++ src/tests/usr.bin/xlint/lint1/Makefile	Sun May  2 21:22:09 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.54 2021/05/02 20:44:46 rillig Exp $
+# $NetBSD: Makefile,v 1.55 2021/05/02 21:22:09 rillig Exp $
 
 NOMAN=		# defined
 MAX_MESSAGE=	343		# see lint1/err.c
@@ -109,6 +109,8 @@ FILES+=		gcc_attribute.c
 FILES+=		gcc_attribute.exp
 FILES+=		gcc_attribute_aligned.c
 FILES+=		gcc_attribute_aligned.exp
+FILES+=		gcc_bit_field_types.c
+FILES+=		gcc_bit_field_types.exp
 FILES+=		gcc_init_compound_literal.c
 FILES+=		gcc_init_compound_literal.exp
 FILES+=		gcc_typeof_after_statement.c

Index: src/tests/usr.bin/xlint/lint1/msg_035.c
diff -u src/tests/usr.bin/xlint/lint1/msg_035.c:1.8 src/tests/usr.bin/xlint/lint1/msg_035.c:1.9
--- src/tests/usr.bin/xlint/lint1/msg_035.c:1.8	Mon Apr  5 01:35:34 2021
+++ src/tests/usr.bin/xlint/lint1/msg_035.c	Sun May  2 21:22:09 2021
@@ -1,8 +1,11 @@
-/*	$NetBSD: msg_035.c,v 1.8 2021/04/05 01:35:34 rillig Exp $	*/
+/*	$NetBSD: msg_035.c,v 1.9 2021/05/02 21:22:09 rillig Exp $	*/
 # 3 "msg_035.c"
 
 // Test for message: illegal bit-field type '%s' [35]
 
+/* Omit -g, see gcc_bit_field_types.c. */
+/* lint1-flags: -Sw */
+
 /*
  * In traditional C, only unsigned int is a portable bit-field type.
  *

Index: src/tests/usr.bin/xlint/lint1/msg_035.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_035.exp:1.10 src/tests/usr.bin/xlint/lint1/msg_035.exp:1.11
--- src/tests/usr.bin/xlint/lint1/msg_035.exp:1.10	Sun Mar 21 20:44:59 2021
+++ src/tests/usr.bin/xlint/lint1/msg_035.exp	Sun May  2 21:22:09 2021
@@ -1,19 +1,19 @@
-msg_035.c(41): warning: illegal bit-field type 'long' [35]
-msg_035.c(42): warning: illegal bit-field type 'unsigned long' [35]
-msg_035.c(43): warning: illegal bit-field type 'long long' [35]
-msg_035.c(44): warning: illegal bit-field type 'unsigned long long' [35]
-msg_035.c(47): warning: illegal bit-field type 'float' [35]
-msg_035.c(48): warning: illegal bit-field type 'double' [35]
-msg_035.c(49): warning: illegal bit-field type 'long double' [35]
-msg_035.c(50): error: void type for 'void_flag' [19]
-msg_035.c(50): error: zero size bit-field [37]
-msg_035.c(51): warning: illegal bit-field type 'struct typedef example_struct' [35]
-msg_035.c(52): warning: illegal bit-field type 'union typedef example_union' [35]
-msg_035.c(54): warning: illegal bit-field type 'pointer to void' [35]
-msg_035.c(55): warning: illegal bit-field type 'array[4] of unsigned int' [35]

CVS commit: src/usr.bin/xlint/xlint

2021-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May  2 21:05:42 UTC 2021

Modified Files:
src/usr.bin/xlint/xlint: lint.1 xlint.c

Log Message:
lint: on request, keep the preprocessor output

Previously, the simplest way of getting the preprocessed translation
unit was to run lint with the additional flag -V, which outputs the
command line of the C preprocessor, among other things.  That command
line does not include the proper quoting though, so it cannot be used
verbatim as a shell command if the command line contains spaces such as
in -Du64="unsigned long long".

In the common situation where lint is run via a Makefile, the option -V
had to be added in the Makefile itself since there is no make variable
for additional user-settable lint flags.  This is not straight-forward
enough.

Adding another command line option for this purpose would reduce the
remaining namespace for options.  Most of the 52 letters are already
used up.

To make this situation as simple as possible, preserve the output of the
C preprocessor depending on an environment variable.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/usr.bin/xlint/xlint/lint.1
cvs rdiff -u -r1.62 -r1.63 src/usr.bin/xlint/xlint/xlint.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/xlint/lint.1
diff -u src/usr.bin/xlint/xlint/lint.1:1.43 src/usr.bin/xlint/xlint/lint.1:1.44
--- src/usr.bin/xlint/xlint/lint.1:1.43	Wed Apr 14 20:06:40 2021
+++ src/usr.bin/xlint/xlint/lint.1	Sun May  2 21:05:42 2021
@@ -1,4 +1,4 @@
-.\" $NetBSD: lint.1,v 1.43 2021/04/14 20:06:40 rillig Exp $
+.\" $NetBSD: lint.1,v 1.44 2021/05/02 21:05:42 rillig Exp $
 .\"
 .\" Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
 .\" Copyright (c) 1994, 1995 Jochen Pohl
@@ -579,6 +579,11 @@ option must exist.
 If this environment variable is undefined, then the default path
 .Pa /usr/libdata/lint
 will be used to search for the libraries.
+.It Ev LINT_KEEP_CPPOUT_ON_ERROR
+If
+.Nm
+exits unsuccessfully, do no delete the output from the C preprocessor,
+allowing for manual inspection.
 .It Ev TMPDIR
 Usually the path for temporary files can be redefined by setting
 this environment variable.

Index: src/usr.bin/xlint/xlint/xlint.c
diff -u src/usr.bin/xlint/xlint/xlint.c:1.62 src/usr.bin/xlint/xlint/xlint.c:1.63
--- src/usr.bin/xlint/xlint/xlint.c:1.62	Sun Apr 18 22:51:25 2021
+++ src/usr.bin/xlint/xlint/xlint.c	Sun May  2 21:05:42 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: xlint.c,v 1.62 2021/04/18 22:51:25 rillig Exp $ */
+/* $NetBSD: xlint.c,v 1.63 2021/05/02 21:05:42 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: xlint.c,v 1.62 2021/04/18 22:51:25 rillig Exp $");
+__RCSID("$NetBSD: xlint.c,v 1.63 2021/05/02 21:05:42 rillig Exp $");
 #endif
 
 #include 
@@ -260,8 +260,13 @@ terminate(int signo)
 
 	if (cppoutfd != -1)
 		(void)close(cppoutfd);
-	if (cppout != NULL)
-		(void)remove(cppout);
+	if (cppout != NULL) {
+		if (signo != 0 && getenv("LINT_KEEP_CPPOUT_ON_ERROR") != NULL)
+			printf("lint: preprocessor output kept in %s\n",
+			cppout);
+		else
+			(void)remove(cppout);
+	}
 
 	if (p1out != NULL) {
 		for (i = 0; p1out[i] != NULL; i++)



CVS commit: src/usr.bin/xlint/lint1

2021-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May  2 20:53:14 UTC 2021

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

Log Message:
lint: sort GCC attributes alphabetically in the grammar

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.224 -r1.225 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/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.224 src/usr.bin/xlint/lint1/cgram.y:1.225
--- src/usr.bin/xlint/lint1/cgram.y:1.224	Sat May  1 07:25:07 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun May  2 20:53:13 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.224 2021/05/01 07:25:07 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.225 2021/05/02 20:53:13 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.224 2021/05/01 07:25:07 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.225 2021/05/02 20:53:13 rillig Exp $");
 #endif
 
 #include 
@@ -553,60 +553,60 @@ type_attribute_bounded_type:
 
 type_attribute_spec:
 	  /* empty */
-	| T_AT_DEPRECATED T_LPAREN string T_RPAREN
-	| T_AT_DEPRECATED
+	| T_AT_ALWAYS_INLINE
+	| T_AT_ALIAS T_LPAREN string T_RPAREN
 	| T_AT_ALIGNED T_LPAREN constant_expr T_RPAREN
+	| T_AT_ALIGNED
 	| T_AT_ALLOC_SIZE T_LPAREN constant_expr T_COMMA constant_expr T_RPAREN
 	| T_AT_ALLOC_SIZE T_LPAREN constant_expr T_RPAREN
 	| T_AT_BOUNDED T_LPAREN type_attribute_bounded_type
 	  T_COMMA constant_expr T_COMMA constant_expr T_RPAREN
-	| T_AT_SENTINEL T_LPAREN constant_expr T_RPAREN
-	| T_AT_SENTINEL
-	| T_AT_FORMAT_ARG T_LPAREN constant_expr T_RPAREN
-	| T_AT_NONNULL
-	| T_AT_NONNULL T_LPAREN constant_expr_list_opt T_RPAREN
-	| T_AT_NONSTRING
-	| T_AT_MODE T_LPAREN T_NAME T_RPAREN
-	| T_AT_ALIAS T_LPAREN string T_RPAREN
-	| T_AT_OPTIMIZE T_LPAREN string T_RPAREN
-	| T_AT_PCS T_LPAREN string T_RPAREN
-	| T_AT_SECTION T_LPAREN string T_RPAREN
-	| T_AT_TLS_MODEL T_LPAREN string T_RPAREN
-	| T_AT_ALIGNED
+	| T_AT_COLD
+	| T_AT_COMMON
 	| T_AT_CONSTRUCTOR T_LPAREN constant_expr T_RPAREN
 	| T_AT_CONSTRUCTOR
+	| T_AT_DEPRECATED T_LPAREN string T_RPAREN
+	| T_AT_DEPRECATED
 	| T_AT_DESTRUCTOR T_LPAREN constant_expr T_RPAREN
 	| T_AT_DESTRUCTOR
+	| T_AT_FALLTHROUGH {
+		fallthru(1);
+	}
+	| T_AT_FORMAT T_LPAREN type_attribute_format_type T_COMMA
+	constant_expr T_COMMA constant_expr T_RPAREN
+	| T_AT_FORMAT_ARG T_LPAREN constant_expr T_RPAREN
+	| T_AT_GNU_INLINE
 	| T_AT_MALLOC
 	| T_AT_MAY_ALIAS
-	| T_AT_NO_INSTRUMENT_FUNCTION
+	| T_AT_MODE T_LPAREN T_NAME T_RPAREN
 	| T_AT_NOINLINE
+	| T_AT_NONNULL T_LPAREN constant_expr_list_opt T_RPAREN
+	| T_AT_NONNULL
+	| T_AT_NONSTRING
 	| T_AT_NORETURN
 	| T_AT_NOTHROW
-	| T_AT_COLD
-	| T_AT_COMMON
-	| T_AT_RETURNS_TWICE
+	| T_AT_NO_INSTRUMENT_FUNCTION
+	| T_AT_OPTIMIZE T_LPAREN string T_RPAREN
 	| T_AT_PACKED {
 		addpacked();
 	  }
+	| T_AT_PCS T_LPAREN string T_RPAREN
 	| T_AT_PURE
+	| T_AT_RETURNS_TWICE
+	| T_AT_SECTION T_LPAREN string T_RPAREN
+	| T_AT_SENTINEL T_LPAREN constant_expr T_RPAREN
+	| T_AT_SENTINEL
+	| T_AT_TLS_MODEL T_LPAREN string T_RPAREN
 	| T_AT_TUNION
-	| T_AT_GNU_INLINE
-	| T_AT_ALWAYS_INLINE
-	| T_AT_FORMAT T_LPAREN type_attribute_format_type T_COMMA
-	constant_expr T_COMMA constant_expr T_RPAREN
-	| T_AT_USED {
+	| T_AT_UNUSED {
 		add_attr_used();
 	  }
-	| T_AT_UNUSED {
+	| T_AT_USED {
 		add_attr_used();
 	  }
+	| T_AT_VISIBILITY T_LPAREN constant_expr T_RPAREN
 	| T_AT_WARN_UNUSED_RESULT
 	| T_AT_WEAK
-	| T_AT_VISIBILITY T_LPAREN constant_expr T_RPAREN
-	| T_AT_FALLTHROUGH {
-		fallthru(1);
-	}
 	| T_QUAL {
 		if ($1 != CONST)
 			yyerror("Bad attribute");



CVS commit: src

2021-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May  2 20:44:47 UTC 2021

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: Makefile t_integration.sh
Added Files:
src/tests/usr.bin/xlint/lint1: gcc_attribute_aligned.c
gcc_attribute_aligned.exp

Log Message:
tests/lint: demonstrate missing support for __packed __aligned


To generate a diff of this commit:
cvs rdiff -u -r1.1047 -r1.1048 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.53 -r1.54 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c \
src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.exp
cvs rdiff -u -r1.45 -r1.46 src/tests/usr.bin/xlint/lint1/t_integration.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1047 src/distrib/sets/lists/tests/mi:1.1048
--- src/distrib/sets/lists/tests/mi:1.1047	Fri Apr 30 23:49:36 2021
+++ src/distrib/sets/lists/tests/mi	Sun May  2 20:44:46 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1047 2021/04/30 23:49:36 rillig Exp $
+# $NetBSD: mi,v 1.1048 2021/05/02 20:44:46 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6193,6 +6193,8 @@
 ./usr/tests/usr.bin/xlint/lint1/feat_stacktrace.exp		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/gcc_attribute.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/gcc_attribute.exp		tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c		tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.c	tests-usr.bin-tests	compattestfile,atf

Index: src/tests/usr.bin/xlint/lint1/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.53 src/tests/usr.bin/xlint/lint1/Makefile:1.54
--- src/tests/usr.bin/xlint/lint1/Makefile:1.53	Fri Apr 30 23:49:36 2021
+++ src/tests/usr.bin/xlint/lint1/Makefile	Sun May  2 20:44:46 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.53 2021/04/30 23:49:36 rillig Exp $
+# $NetBSD: Makefile,v 1.54 2021/05/02 20:44:46 rillig Exp $
 
 NOMAN=		# defined
 MAX_MESSAGE=	343		# see lint1/err.c
@@ -107,6 +107,8 @@ FILES+=		feat_stacktrace.c
 FILES+=		feat_stacktrace.exp
 FILES+=		gcc_attribute.c
 FILES+=		gcc_attribute.exp
+FILES+=		gcc_attribute_aligned.c
+FILES+=		gcc_attribute_aligned.exp
 FILES+=		gcc_init_compound_literal.c
 FILES+=		gcc_init_compound_literal.exp
 FILES+=		gcc_typeof_after_statement.c

Index: src/tests/usr.bin/xlint/lint1/t_integration.sh
diff -u src/tests/usr.bin/xlint/lint1/t_integration.sh:1.45 src/tests/usr.bin/xlint/lint1/t_integration.sh:1.46
--- src/tests/usr.bin/xlint/lint1/t_integration.sh:1.45	Fri Apr 30 23:49:36 2021
+++ src/tests/usr.bin/xlint/lint1/t_integration.sh	Sun May  2 20:44:46 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.45 2021/04/30 23:49:36 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.46 2021/05/02 20:44:46 rillig Exp $
 #
 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -180,6 +180,7 @@ test_case d_long_double_int
 test_case emit
 
 test_case gcc_attribute
+test_case gcc_attribute_aligned
 test_case gcc_init_compound_literal
 test_case gcc_typeof_after_statement
 

Added files:

Index: src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c:1.1
--- /dev/null	Sun May  2 20:44:47 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c	Sun May  2 20:44:46 2021
@@ -0,0 +1,44 @@
+/*	$NetBSD: gcc_attribute_aligned.c,v 1.1 2021/05/02 20:44:46 rillig Exp $	*/
+# 3 "gcc_attribute_aligned.c"
+
+/*
+ * Test size computations on aligned and packed structs.
+ */
+
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+
+/* from sys/arch/x86/include/cpu_extended_state.h */
+
+union fp_addr {
+	uint64_t fa_64;
+	struct {
+		uint32_t fa_off;
+		uint16_t fa_seg;
+		uint16_t fa_opcode;
+	} fa_32;
+} __attribute__((packed)) __attribute__((aligned(4)));
+
+struct fpacc87 {
+	uint64_t f87_mantissa;
+	uint16_t f87_exp_sign;
+} __attribute__((packed)) __attribute__((aligned(2)));
+
+struct save87 {
+	uint16_t s87_cw __attribute__((aligned(4)));
+	uint16_t s87_sw __attribute__((aligned(4)));
+	uint16_t s87_tw __attribute__((aligned(4)));
+	union fp_addr s87_ip;
+	union fp_addr s87_dp;
+	struct fpacc87 s87_ac[8];
+};
+
+struct {
+	unsigned int sizeof_fp_addr: sizeof(union fp_addr) == 8 ? 1 : -1;
+
+	unsigned 

CVS commit: src/sys/conf

2021-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May  2 20:11:43 UTC 2021

Modified Files:
src/sys/conf: lint.mk

Log Message:
sys/conf/lint.mk: fix order of command line options

The option -o must come before the first filename.

Now it is possible to lint kern_exec.c at least.  The next failure is in
netbsd32_machdep.c:

netbsd32_machdep.c(395): error: illegal bit-field size: 255 [36]

That line in netbsd32_process_read_fpregs reads:

__CTASSERT(sizeof(*regs) == sizeof(struct save87));

This is probably a bug in lint.  The struct save87 contains 3 uint16_t,
followed by a union containing a uint64_t, followed by a packed struct
with size 10.  The combination of packed and padding is suspicious.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/conf/lint.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/conf/lint.mk
diff -u src/sys/conf/lint.mk:1.3 src/sys/conf/lint.mk:1.4
--- src/sys/conf/lint.mk:1.3	Sun May  2 19:51:57 2021
+++ src/sys/conf/lint.mk	Sun May  2 20:11:43 2021
@@ -1,4 +1,4 @@
-# $NetBSD: lint.mk,v 1.3 2021/05/02 19:51:57 rillig Exp $
+# $NetBSD: lint.mk,v 1.4 2021/05/02 20:11:43 rillig Exp $
 
 ##
 ## lint
@@ -9,7 +9,7 @@
 ALLSFILES?=	${MD_SFILES} ${SFILES}
 LINTSTUBS?=	${ALLSFILES:T:R:C/^.*$/LintStub_&.c/g}
 KERNLINTFLAGS?=	-bceghnxzFS
-NORMAL_LN?=	${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i $< -o $@
+NORMAL_LN?=	${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} -o $@ -i $<
 
 _lsrc=${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
 LOBJS?= ${_lsrc:T:S/.c$/.ln/g} ${LIBKERNLN} ${SYSLIBCOMPATLN}



CVS commit: src/sys/conf

2021-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May  2 19:51:57 UTC 2021

Modified Files:
src/sys/conf: lint.mk

Log Message:
sys/conf/lint.mk: allow GCC extensions in the kernel

The syntax errors due to the __asm statements are now gone.  The file
kern_exec.c only produces a few warnings now.  But after running that
file through lint1, the main lint complains about wrong usage.  This is
due to this call:

${LINT} ... -i $< -o $@

The main lint has never supported -o after the first filename, so it
complains.  It would have been helpful if lint had given any hint as to
which option was invalid.  Anyway, the next step is to reorder the
arguments.  As it is now, the code can never have worked.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/conf/lint.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/conf/lint.mk
diff -u src/sys/conf/lint.mk:1.2 src/sys/conf/lint.mk:1.3
--- src/sys/conf/lint.mk:1.2	Sun May  2 19:29:30 2021
+++ src/sys/conf/lint.mk	Sun May  2 19:51:57 2021
@@ -1,4 +1,4 @@
-# $NetBSD: lint.mk,v 1.2 2021/05/02 19:29:30 rillig Exp $
+# $NetBSD: lint.mk,v 1.3 2021/05/02 19:51:57 rillig Exp $
 
 ##
 ## lint
@@ -8,7 +8,7 @@
 .PATH: $S
 ALLSFILES?=	${MD_SFILES} ${SFILES}
 LINTSTUBS?=	${ALLSFILES:T:R:C/^.*$/LintStub_&.c/g}
-KERNLINTFLAGS?=	-bcehnxzFS
+KERNLINTFLAGS?=	-bceghnxzFS
 NORMAL_LN?=	${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i $< -o $@
 
 _lsrc=${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}



CVS commit: src/sys/conf

2021-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May  2 19:29:30 UTC 2021

Modified Files:
src/sys/conf: lint.mk

Log Message:
sys/conf/lint.mk: a small step for linting the kernel

Due to the missing path, the following commands had failed:

$ cd src/sys/arch/amd64/compile/GENERIC
$ nbmake-amd64-lint kern_exec.ln
nbmake: don't know how to make kern/kern_exec.c. Stop

After fixing the path, "make kern_exec.ln" fails with:

sys/kern/kern_exec.c(65): error: syntax error '"' [249]

The affected line contains:

__KERNEL_RCSID(0, "...");

The macro __KERNEL_RCSID expands to __asm("some strings").  Since
KERNLINTFLAGS is missing the -g, lint does not recognize __asm as
keyword and tries to parse it as an identifier instead, expecting a
variable or function declaration.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/conf/lint.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/conf/lint.mk
diff -u src/sys/conf/lint.mk:1.1 src/sys/conf/lint.mk:1.2
--- src/sys/conf/lint.mk:1.1	Sat Aug 29 16:27:07 2015
+++ src/sys/conf/lint.mk	Sun May  2 19:29:30 2021
@@ -1,10 +1,11 @@
-# $NetBSD: lint.mk,v 1.1 2015/08/29 16:27:07 uebayasi Exp $
+# $NetBSD: lint.mk,v 1.2 2021/05/02 19:29:30 rillig Exp $
 
 ##
 ## lint
 ##
 
 .if !target(lint)
+.PATH: $S
 ALLSFILES?=	${MD_SFILES} ${SFILES}
 LINTSTUBS?=	${ALLSFILES:T:R:C/^.*$/LintStub_&.c/g}
 KERNLINTFLAGS?=	-bcehnxzFS



CVS commit: src/sys

2021-05-02 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun May  2 19:13:43 UTC 2021

Modified Files:
src/sys/kern: kern_event.c
src/sys/sys: eventvar.h

Log Message:
implement fo_restart hook for kqueue descriptors, so that close(2)
on the descriptor won't block indefinitely if other thread is currently
blocked on the same kqueue in kevent(2)

done similarily to pipes and sockets, i.e. using flag on the potentially
shared kqueue structure hooked off file_t - this is somewhat suboptimal
if the application dup(2)ped the descriptor, but this should be rare
enough to not really matter

usually this causes the kevent(2) to end up returning EBADF since
on the syscall restart the descriptor is not there anymore; if
dup(2)ped the kevent(2) call can continue successfully if the closed
kqueue descriptor was other than the one used for the kevent(2)
call

PR kern/46248 by Julian Fagir


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 src/sys/kern/kern_event.c
cvs rdiff -u -r1.8 -r1.9 src/sys/sys/eventvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_event.c
diff -u src/sys/kern/kern_event.c:1.117 src/sys/kern/kern_event.c:1.118
--- src/sys/kern/kern_event.c:1.117	Wed Jan 27 06:59:08 2021
+++ src/sys/kern/kern_event.c	Sun May  2 19:13:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_event.c,v 1.117 2021/01/27 06:59:08 skrll Exp $	*/
+/*	$NetBSD: kern_event.c,v 1.118 2021/05/02 19:13:43 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.117 2021/01/27 06:59:08 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.118 2021/05/02 19:13:43 jdolecek Exp $");
 
 #include 
 #include 
@@ -90,6 +90,7 @@ static int	kqueue_poll(file_t *, int);
 static int	kqueue_kqfilter(file_t *, struct knote *);
 static int	kqueue_stat(file_t *, struct stat *);
 static int	kqueue_close(file_t *);
+static void	kqueue_restart(file_t *);
 static int	kqueue_register(struct kqueue *, struct kevent *);
 static void	kqueue_doclose(struct kqueue *, struct klist *, int);
 
@@ -125,7 +126,7 @@ static const struct fileops kqueueops = 
 	.fo_stat = kqueue_stat,
 	.fo_close = kqueue_close,
 	.fo_kqfilter = kqueue_kqfilter,
-	.fo_restart = fnullop_restart,
+	.fo_restart = kqueue_restart,
 };
 
 static const struct filterops kqread_filtops = {
@@ -501,7 +502,7 @@ filt_kqueue(struct knote *kn, long hint)
 
 	if (hint != NOTE_SUBMIT)
 		mutex_spin_enter(>kq_lock);
-	kn->kn_data = kq->kq_count;
+	kn->kn_data = KQ_COUNT(kq);
 	rv = (kn->kn_data > 0);
 	if (hint != NOTE_SUBMIT)
 		mutex_spin_exit(>kq_lock);
@@ -1328,12 +1329,12 @@ static void
 kqueue_check(const char *func, size_t line, const struct kqueue *kq)
 {
 	const struct knote *kn;
-	int count;
+	u_int count;
 	int nmarker;
 	char buf[128];
 
 	KASSERT(mutex_owned(>kq_lock));
-	KASSERT(kq->kq_count >= 0);
+	KASSERT(KQ_COUNT(kq) < UINT_MAX / 2);
 
 	count = 0;
 	nmarker = 0;
@@ -1353,22 +1354,14 @@ kqueue_check(const char *func, size_t li
 func, line, kq, kn, KN_FMT(buf, kn));
 			}
 			count++;
-			if (count > kq->kq_count) {
+			if (count > KQ_COUNT(kq)) {
 panic("%s,%zu: kq=%p kq->kq_count(%d) != "
 "count(%d), nmarker=%d",
-				func, line, kq, kq->kq_count, count,
+				func, line, kq, KQ_COUNT(kq), count,
 nmarker);
 			}
 		} else {
 			nmarker++;
-#if 0
-			if (nmarker > 1) {
-panic("%s,%zu: kq=%p too many markers: "
-"%d != %d, nmarker=%d",
-func, line, kq, kq->kq_count, count,
-nmarker);
-			}
-#endif
 		}
 	}
 }
@@ -1377,6 +1370,18 @@ kqueue_check(const char *func, size_t li
 #define	kq_check(a)	/* nothing */
 #endif /* defined(DEBUG) */
 
+static void
+kqueue_restart(file_t *fp)
+{
+	struct kqueue *kq = fp->f_kqueue;
+	KASSERT(kq != NULL);
+
+	mutex_spin_enter(>kq_lock);
+	kq->kq_count |= KQ_RESTART;
+	cv_broadcast(>kq_cv);
+	mutex_spin_exit(>kq_lock);
+}
+
 /*
  * Scan through the list of events on fp (for a maximum of maxevents),
  * returning the results in to ulistp. Timeout is determined by tsp; if
@@ -1426,14 +1431,19 @@ kqueue_scan(file_t *fp, size_t maxevents
 	mutex_spin_enter(>kq_lock);
  retry:
 	kevp = kevbuf;
-	if (kq->kq_count == 0) {
+	if (KQ_COUNT(kq) == 0) {
 		if (timeout >= 0) {
 			error = cv_timedwait_sig(>kq_cv,
 			>kq_lock, timeout);
 			if (error == 0) {
- if (tsp == NULL || (timeout =
- gettimeleft(, )) > 0)
+if (KQ_COUNT(kq) == 0 &&
+(kq->kq_count & KQ_RESTART)) {
+	/* return to clear file reference */
+	error = ERESTART;
+} else if (tsp == NULL || (timeout =
+gettimeleft(, )) > 0) {
 	goto retry;
+}
 			} else {
 /* don't restart after signals... */
 if (error == ERESTART)
@@ -1689,7 +1699,7 @@ kqueue_poll(file_t *fp, int events)
 	revents = 0;
 	if (events & (POLLIN | 

CVS commit: src/sys/stand/efiboot/bootriscv64

2021-05-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun May  2 15:22:27 UTC 2021

Added Files:
src/sys/stand/efiboot/bootriscv64: Makefile efibootriscv64.c

Log Message:
Add RISC-V 64-bit support.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/bootriscv64/Makefile \
src/sys/stand/efiboot/bootriscv64/efibootriscv64.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/sys/stand/efiboot/bootriscv64/Makefile
diff -u /dev/null src/sys/stand/efiboot/bootriscv64/Makefile:1.1
--- /dev/null	Sun May  2 15:22:27 2021
+++ src/sys/stand/efiboot/bootriscv64/Makefile	Sun May  2 15:22:27 2021
@@ -0,0 +1,20 @@
+# $NetBSD: Makefile,v 1.1 2021/05/02 15:22:27 jmcneill Exp $
+
+PROG=		bootriscv64.efi
+OBJFMT=		binary
+NEWVERSWHAT=	"efiboot (riscv64)"
+GNUEFIARCH=	riscv64
+LIBGNUEFI_ARCH=	riscv64
+
+EXTRA_SOURCES=	efibootriscv64.c
+
+COPTS+=		-mcmodel=medany
+AFLAGS+=	-x assembler-with-cpp
+CFLAGS+=	-DEFIBOOT_ALIGN=0x20
+CFLAGS+=	-DEFIBOOT_MODULE_MACHINE=\"riscv\"
+
+.include "${.CURDIR}/../Makefile.efiboot"
+
+release: check_RELEASEDIR
+	${HOST_INSTALL_FILE} -m ${BINMODE} ${PROG} \
+		${RELEASEDIR}/${RELEASEMACHINEDIR}/installation/misc
Index: src/sys/stand/efiboot/bootriscv64/efibootriscv64.c
diff -u /dev/null src/sys/stand/efiboot/bootriscv64/efibootriscv64.c:1.1
--- /dev/null	Sun May  2 15:22:27 2021
+++ src/sys/stand/efiboot/bootriscv64/efibootriscv64.c	Sun May  2 15:22:27 2021
@@ -0,0 +1,78 @@
+/* $NetBSD: efibootriscv64.c,v 1.1 2021/05/02 15:22:27 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2021 Jared McNeill 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "../efiboot.h"
+#include "../efifdt.h"
+
+#include 
+
+#include 
+#include 
+
+typedef void (*riscv_kernel_entry_t)(register_t, register_t);
+
+static uint32_t
+efi_fdt_get_boot_hartid(void)
+{
+	const int chosen = fdt_path_offset(efi_fdt_data(), "/chosen");
+	const uint32_t *data;
+
+	data = fdt_getprop(efi_fdt_data(), chosen, "boot-hartid", NULL);
+	if (data == NULL) {
+		return 0;	/* XXX */
+	}
+
+	return fdt32_to_cpu(*data);
+}
+
+void
+efi_boot_kernel(u_long marks[MARK_MAX])
+{
+	riscv_kernel_entry_t entry_fn;
+	register_t hart_id; /* a0 */
+	register_t fdt_start; /* a1 */
+
+	entry_fn = (riscv_kernel_entry_t)(uintptr_t)marks[MARK_ENTRY];
+
+	hart_id = efi_fdt_get_boot_hartid();
+	fdt_start = (register_t)efi_fdt_data();
+
+	asm volatile("fence rw,rw; fence.i" ::: "memory");
+
+	entry_fn(hart_id, fdt_start);
+}
+
+void
+efi_md_show(void)
+{
+}
+
+void
+efi_dcache_flush(u_long start, u_long size)
+{
+}



CVS commit: src/games/countmail

2021-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May  2 13:10:36 UTC 2021

Modified Files:
src/games/countmail: countmail

Log Message:
countmail: remove outdated comments

Using the shell builtin 'read' command was necessarily slow because it
is specified to read a single byte at a time.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/games/countmail/countmail

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/countmail/countmail
diff -u src/games/countmail/countmail:1.7 src/games/countmail/countmail:1.8
--- src/games/countmail/countmail:1.7	Mon Apr 28 20:22:53 2008
+++ src/games/countmail/countmail	Sun May  2 13:10:36 2021
@@ -1,5 +1,5 @@
 #!/bin/sh
-#	$NetBSD: countmail,v 1.7 2008/04/28 20:22:53 martin Exp $
+#	$NetBSD: countmail,v 1.8 2021/05/02 13:10:36 rillig Exp $
 
 #
 # Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
@@ -30,29 +30,10 @@
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
-# Count the messages in your mailbox, using only POSIX shell builtins.
+# Count the messages in your mailbox.
 #
-# Caveats:
-#
-# The read loop is horrendously slow on every implementation I've
-# tried.  I suggest using from(1) and wc(1) instead, though these are
-# not shell builtins.
-
-# for krb.
-#set -- `from -t`
-#v=$3
-set -- `from 2>/dev/null |wc -l`
+set -- `from 2>/dev/null | wc -l`
 v=$1
-#v=`from | wc -l`
-
-#v=0
-#exec 0

CVS commit: src/games/fish

2021-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May  2 12:25:56 UTC 2021

Modified Files:
src/games/fish: fish.c

Log Message:
fish: remove trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/games/fish/fish.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/fish/fish.c
diff -u src/games/fish/fish.c:1.25 src/games/fish/fish.c:1.26
--- src/games/fish/fish.c:1.25	Sun May  2 12:24:59 2021
+++ src/games/fish/fish.c	Sun May  2 12:25:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: fish.c,v 1.25 2021/05/02 12:24:59 rillig Exp $	*/
+/*	$NetBSD: fish.c,v 1.26 2021/05/02 12:25:55 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 19
 #if 0
 static char sccsid[] = "@(#)fish.c	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: fish.c,v 1.25 2021/05/02 12:24:59 rillig Exp $");
+__RCSID("$NetBSD: fish.c,v 1.26 2021/05/02 12:25:55 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -120,7 +120,7 @@ main(int argc, char **argv)
 	}
 	printplayer(USER);
 	(void)printf("get to start.\n");
-	
+
 	for (;;) {
 		move = usermove();
 		if (!comphand[move]) {
@@ -243,12 +243,12 @@ promove(void)
 max = i;
 break;
 			}
-		while (++i < RANKS) 
+		while (++i < RANKS)
 			if (comphand[i] != CARDS &&
 			comphand[i] > comphand[max])
 max = i;
 		return(max);
-	} 
+	}
 	if (arc4random_uniform(1024) == 0723) {
 		for (i = 0; i < RANKS; ++i)
 			if (userhand[i] && comphand[i])
@@ -369,7 +369,7 @@ printhand(const int *hand)
 
 	for (book = i = 0; i < RANKS; i++)
 		if (hand[i] < CARDS)
-			for (j = hand[i]; --j >= 0;) 
+			for (j = hand[i]; --j >= 0;)
 PRC(i);
 		else
 			++book;



CVS commit: src/games/fish

2021-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May  2 12:24:59 UTC 2021

Modified Files:
src/games/fish: fish.c

Log Message:
fish: use arc4random_uniform for drawing random numbers

Thanks nia@ for the hint.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/games/fish/fish.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/fish/fish.c
diff -u src/games/fish/fish.c:1.24 src/games/fish/fish.c:1.25
--- src/games/fish/fish.c:1.24	Sat May  1 21:10:57 2021
+++ src/games/fish/fish.c	Sun May  2 12:24:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: fish.c,v 1.24 2021/05/01 21:10:57 rillig Exp $	*/
+/*	$NetBSD: fish.c,v 1.25 2021/05/02 12:24:59 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 19
 #if 0
 static char sccsid[] = "@(#)fish.c	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: fish.c,v 1.24 2021/05/01 21:10:57 rillig Exp $");
+__RCSID("$NetBSD: fish.c,v 1.25 2021/05/02 12:24:59 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -54,7 +54,6 @@ __RCSID("$NetBSD: fish.c,v 1.24 2021/05/
 #include 
 #include 
 #include 
-#include 
 #include 
 #include "pathnames.h"
 
@@ -87,7 +86,6 @@ static int gofish(int, int, int *);
 static void goodmove(int, int, int *, int *);
 static void init(void);
 static void instructions(void);
-static int nrandom(int);
 static void printhand(const int *);
 static void printplayer(int);
 static int promove(void);
@@ -112,11 +110,10 @@ main(int argc, char **argv)
 			usage();
 		}
 
-	srandom(time(NULL));
 	instructions();
 	init();
 
-	if (nrandom(2) == 1) {
+	if (arc4random_uniform(2) == 1) {
 		printplayer(COMPUTER);
 		(void)printf("get to start.\n");
 		goto istart;
@@ -200,11 +197,11 @@ usermove(void)
 			continue;
 		}
 
-		if (nrandom(3) == 1)
+		if (arc4random_uniform(3) == 1)
 			(void)printf("You don't have any of those!\n");
 		else
 			(void)printf("You don't have any %s's!\n", cards[n]);
-		if (nrandom(4) == 1)
+		if (arc4random_uniform(4) == 1)
 			(void)printf("No cheating!\n");
 		(void)printf("Guess again.\n");
 	}
@@ -240,7 +237,7 @@ promove(void)
 			userasked[i] = 0;
 			return(i);
 		}
-	if (nrandom(3) == 1) {
+	if (arc4random_uniform(3) == 1) {
 		for (i = 0;; ++i)
 			if (comphand[i] && comphand[i] != CARDS) {
 max = i;
@@ -252,7 +249,7 @@ promove(void)
 max = i;
 		return(max);
 	} 
-	if (nrandom(1024) == 0723) {
+	if (arc4random_uniform(1024) == 0723) {
 		for (i = 0; i < RANKS; ++i)
 			if (userhand[i] && comphand[i])
 return(i);
@@ -341,11 +338,11 @@ chkwinner(int player, const int *hand)
 	(void)printf("\nI have %d, you have %d.\n", cb, ub);
 	if (ub > cb) {
 		(void)printf("\nYou win!!!\n");
-		if (nrandom(1024) == 0723)
+		if (arc4random_uniform(1024) == 0723)
 			(void)printf("Cheater, cheater, pumpkin eater!\n");
 	} else if (cb > ub) {
 		(void)printf("\nI win!!!\n");
-		if (nrandom(1024) == 0723)
+		if (arc4random_uniform(1024) == 0723)
 			(void)printf("Hah!  Stupid peasant!\n");
 	} else
 		(void)printf("\nTie!\n");
@@ -419,7 +416,7 @@ init(void)
 	for (i = 0; i < TOTCARDS; ++i)
 		deck[i] = i % RANKS;
 	for (i = 0; i < TOTCARDS - 1; ++i) {
-		j = nrandom(TOTCARDS-i);
+		j = arc4random_uniform(TOTCARDS-i);
 		if (j == 0)
 			continue;
 		temp = deck[i];
@@ -432,18 +429,6 @@ init(void)
 	}
 }
 
-static int
-nrandom(int n)
-{
-	long r;
-
-	for (;;) {
-		r = random();
-		if (r < RANDOM_MAX - RANDOM_MAX % n)
-			return (int)(r % n);
-	}
-}
-
 static void
 instructions(void)
 {



CVS commit: src/tests/lib/libc/gen/posix_spawn

2021-05-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun May  2 11:18:11 UTC 2021

Modified Files:
src/tests/lib/libc/gen/posix_spawn: h_spawn.c t_spawnattr.c

Log Message:
Add test for POSIX_SPAWN_RESETIDS flag


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/gen/posix_spawn/h_spawn.c
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/gen/posix_spawn/t_spawnattr.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/lib/libc/gen/posix_spawn/h_spawn.c
diff -u src/tests/lib/libc/gen/posix_spawn/h_spawn.c:1.1 src/tests/lib/libc/gen/posix_spawn/h_spawn.c:1.2
--- src/tests/lib/libc/gen/posix_spawn/h_spawn.c:1.1	Mon Feb 13 21:03:08 2012
+++ src/tests/lib/libc/gen/posix_spawn/h_spawn.c	Sun May  2 11:18:11 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: h_spawn.c,v 1.1 2012/02/13 21:03:08 martin Exp $ */
+/* $NetBSD: h_spawn.c,v 1.2 2021/05/02 11:18:11 martin Exp $ */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -32,6 +32,8 @@
 
 #include 
 #include 
+#include 
+#include 
 
 int
 main(int argc, char **argv)
@@ -39,11 +41,25 @@ main(int argc, char **argv)
 	unsigned long ret;
 	char *endp;
 
-	if (argc < 2) {
+	if (argc == 2 && strcmp(argv[1], "--resetids") == 0) {
+		if (getuid() != geteuid() || getgid() != getegid()) {
+			fprintf(stderr, "uid/gid do not match effective ids, "
+			"uid: %d euid: %d gid: %d egid: %d\n",
+			getuid(), geteuid(), getgid(), getegid());
+			exit(255);
+		}
+		return 0;
+	} else if (argc != 2) {
 		fprintf(stderr, "usage:\n\t%s (retcode)\n", getprogname());
 		exit(255);
 	}
 	ret = strtoul(argv[1], , 10);
+	if (*endp != 0) {
+		fprintf(stderr,
+		"invalid arg: %s\n"
+		"usage:\n\t%s (retcode)\n", endp, getprogname());
+		exit(255);
+	}
 
 	fprintf(stderr, "%s exiting with status %lu\n", getprogname(), ret);
 	return ret;

Index: src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c
diff -u src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c:1.3 src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c:1.4
--- src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c:1.3	Thu Dec 21 03:31:43 2017
+++ src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c	Sun May  2 11:18:11 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: t_spawnattr.c,v 1.3 2017/12/21 03:31:43 christos Exp $ */
+/* $NetBSD: t_spawnattr.c,v 1.4 2021/05/02 11:18:11 martin Exp $ */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -165,9 +165,43 @@ ATF_TC_BODY(t_spawnattr, tc)
 	posix_spawnattr_destroy();
 }
 
+ATF_TC(t_spawn_resetids);
+
+ATF_TC_HEAD(t_spawn_resetids, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"posix_spawn a child and with POSIX_SPAWN_RESETIDS flag");
+}
+
+ATF_TC_BODY(t_spawn_resetids, tc)
+{
+	char buf[FILENAME_MAX];
+	char * const args[] = {
+	 __UNCONST("h_spawn"), __UNCONST("--resetids"), NULL
+	};
+	posix_spawnattr_t attr;
+	int err, status;
+	pid_t pid;
+
+	posix_spawnattr_init();
+	posix_spawnattr_setflags(, POSIX_SPAWN_RESETIDS);
+
+	snprintf(buf, sizeof buf, "%s/h_spawn",
+	atf_tc_get_config_var(tc, "srcdir"));
+
+	err = posix_spawn(, buf, NULL, , args, NULL);
+	ATF_REQUIRE(err == 0);
+	ATF_REQUIRE(pid > 0);
+	waitpid(pid, , 0);
+	ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 0);
+
+	posix_spawnattr_destroy();
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 	ATF_TP_ADD_TC(tp, t_spawnattr);
+	ATF_TP_ADD_TC(tp, t_spawn_resetids);
 
 	return atf_no_error();
 }



CVS commit: [netbsd-9] src/doc

2021-05-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun May  2 10:44:31 UTC 2021

Modified Files:
src/doc [netbsd-9]: CHANGES-9.2

Log Message:
Ticket #1264


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.75 -r1.1.2.76 src/doc/CHANGES-9.2

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/doc/CHANGES-9.2
diff -u src/doc/CHANGES-9.2:1.1.2.75 src/doc/CHANGES-9.2:1.1.2.76
--- src/doc/CHANGES-9.2:1.1.2.75	Fri Apr 30 14:08:16 2021
+++ src/doc/CHANGES-9.2	Sun May  2 10:44:31 2021
@@ -1,4 +1,4 @@
-# $NetBSD: CHANGES-9.2,v 1.1.2.75 2021/04/30 14:08:16 martin Exp $
+# $NetBSD: CHANGES-9.2,v 1.1.2.76 2021/05/02 10:44:31 martin Exp $
 
 A complete list of changes from the NetBSD 9.1 release to the NetBSD 9.2
 release:
@@ -3056,3 +3056,9 @@ usr.bin/make/make.h1.105
 	Avoid depending on common symbols.
 	[mrg, ticket #1263]
 
+external/cddl/osnet/dist/cmd/zfs/zfs.8		1.2
+external/cddl/osnet/dist/cmd/zpool/zpool.8	1.2
+
+	zfs: Fix references to FreeBSD in manual pages.
+	[nia, ticket #1264]
+



CVS commit: [netbsd-9] src/external/cddl/osnet/dist/cmd

2021-05-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun May  2 10:43:37 UTC 2021

Modified Files:
src/external/cddl/osnet/dist/cmd/zfs [netbsd-9]: zfs.8
src/external/cddl/osnet/dist/cmd/zpool [netbsd-9]: zpool.8

Log Message:
Pull up following revision(s) (requested by nia in ticket #1264):

external/cddl/osnet/dist/cmd/zfs/zfs.8: revision 1.2
external/cddl/osnet/dist/cmd/zpool/zpool.8: revision 1.2

zfs: Fix up references to FreeBSD


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.1.2.1 src/external/cddl/osnet/dist/cmd/zfs/zfs.8
cvs rdiff -u -r1.1 -r1.1.2.1 src/external/cddl/osnet/dist/cmd/zpool/zpool.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/cddl/osnet/dist/cmd/zfs/zfs.8
diff -u src/external/cddl/osnet/dist/cmd/zfs/zfs.8:1.1 src/external/cddl/osnet/dist/cmd/zfs/zfs.8:1.1.2.1
--- src/external/cddl/osnet/dist/cmd/zfs/zfs.8:1.1	Mon Jun 24 08:27:20 2019
+++ src/external/cddl/osnet/dist/cmd/zfs/zfs.8	Sun May  2 10:43:37 2021
@@ -285,12 +285,6 @@
 .Op Fl FHt
 .Ar snapshot
 .Op Ar snapshot Ns | Ns Ar filesystem
-.Nm
-.Cm jail
-.Ar jailid Ns | Ns Ar jailname filesystem
-.Nm
-.Cm unjail
-.Ar jailid Ns | Ns Ar jailname filesystem
 .Sh DESCRIPTION
 The
 .Nm
@@ -445,32 +439,6 @@ If a file system's mount point is set to
 .Tn ZFS
 makes no attempt to manage the file system, and the administrator is
 responsible for mounting and unmounting the file system.
-.Ss Jails
-.No A Tn ZFS
-dataset can be attached to a jail by using the
-.Qq Nm Cm jail
-subcommand. You cannot attach a dataset to one jail and the children of the
-same dataset to another jails. To allow management of the dataset from within
-a jail, the
-.Sy jailed
-property has to be set and the jail needs access to the
-.Pa /dev/zfs
-device. The
-.Sy quota
-property cannot be changed from within a jail. See
-.Xr jail 8
-for information on how to allow mounting
-.Tn ZFS
-datasets from within a jail.
-.Pp
-.No A Tn ZFS
-dataset can be detached from a jail using the
-.Qq Nm Cm unjail
-subcommand.
-.Pp
-After a dataset is attached to a jail and the jailed property is set, a jailed
-file system cannot be mounted outside the jail, since the jail administrator
-might have set the mount point to an unacceptable value.
 .Ss Deduplication
 Deduplication is the process for removing redundant data at the block-level,
 reducing the total amount of data stored. If a file system has the
@@ -1070,7 +1038,7 @@ signature to make sure the block content
 The
 .Sy devices
 property is currently not supported on
-.Fx .
+.Nx .
 .It Sy exec Ns = Ns Cm on | off
 Controls whether processes can be executed from within this file system. The
 default value is
@@ -1079,7 +1047,7 @@ default value is
 The
 .Sy mlslabel
 property is currently not supported on
-.Fx .
+.Nx .
 .It Sy filesystem_limit Ns = Ns Ar count | Cm none
 Limits the number of filesystems and volumes that can exist under this point in
 the dataset tree.
@@ -1118,7 +1086,7 @@ shared file systems are unshared and sha
 The
 .Sy nbmand
 property is currently not supported on
-.Fx .
+.Nx .
 .It Sy primarycache Ns = Ns Cm all | none | metadata
 Controls what is cached in the primary cache (ARC). If this property is set to
 .Cm all ,
@@ -1343,7 +1311,7 @@ bit is respected for the file system. Th
 The
 .Sy sharesmb
 property currently has no effect on
-.Fx .
+.Nx .
 .It Sy sharenfs Ns = Ns Cm on | off | Ar opts
 Controls whether the file system is shared via
 .Tn NFS ,
@@ -1493,17 +1461,12 @@ during volume creation and pool import.
 The
 .Sy vscan
 property is currently not supported on
-.Fx .
+.Nx .
 .It Sy xattr Ns = Ns Cm off | on
 The
 .Sy xattr
 property is currently not supported on
-.Fx .
-.It Sy jailed Ns = Ns Cm off | on
-Controls whether the dataset is managed from a jail. See the
-.Qq Sx Jails
-section for more information. The default value is
-.Cm off .
+.Nx .
 .El
 .Pp
 The following three properties cannot be changed after the file system is
@@ -2360,7 +2323,7 @@ The default is
 The default can be changed to include group types.
 .It Fl i
 Translate SID to POSIX ID. This flag currently has no effect on
-.Fx .
+.Nx .
 .El
 .It Xo
 .Nm
@@ -2405,7 +2368,7 @@ file systems.
 Report mount progress.
 .It Fl O
 Perform an overlay mount. Overlay mounts are not supported on
-.Fx .
+.Nx .
 .It Fl o Ar property Ns Oo , Ns Ar property Oc Ns ...
 An optional, comma-separated list of mount options to use temporarily for the
 duration of the mount. See the
@@ -2416,7 +2379,7 @@ Mount all available
 .Tn ZFS
 file systems.
 This command may be executed on
-.Fx
+.Nx
 system startup by
 .Pa /etc/rc.d/zfs .
 For more information, see variable
@@ -2467,7 +2430,7 @@ file systems that have the
 .Sy sharenfs
 property set.
 This command may be executed on
-.Fx
+.Nx
 system startup by
 .Pa /etc/rc.d/zfs .
 For more information, see variable
@@ -2500,7 +2463,7 @@ file systems that have 

CVS commit: src/sys/kern

2021-05-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun May  2 10:23:56 UTC 2021

Modified Files:
src/sys/kern: kern_exec.c

Log Message:
Fix copy in handling of POSIX_SPAWN_RESETIDS in posix_spawn(3)


To generate a diff of this commit:
cvs rdiff -u -r1.504 -r1.505 src/sys/kern/kern_exec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_exec.c
diff -u src/sys/kern/kern_exec.c:1.504 src/sys/kern/kern_exec.c:1.505
--- src/sys/kern/kern_exec.c:1.504	Sat Dec  5 18:17:01 2020
+++ src/sys/kern/kern_exec.c	Sun May  2 10:23:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.504 2020/12/05 18:17:01 thorpej Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.505 2021/05/02 10:23:55 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.504 2020/12/05 18:17:01 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.505 2021/05/02 10:23:55 martin Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -2172,7 +2172,7 @@ handle_posix_spawn_attrs(struct posix_sp
 
 	/* Reset user ID's */
 	if (attrs->sa_flags & POSIX_SPAWN_RESETIDS) {
-		error = do_setresuid(l, -1, kauth_cred_getgid(l->l_cred), -1,
+		error = do_setresgid(l, -1, kauth_cred_getgid(l->l_cred), -1,
 		 ID_E_EQ_R | ID_E_EQ_S);
 		if (error)
 			return error;



CVS commit: src/doc

2021-05-02 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun May  2 08:18:38 UTC 2021

Modified Files:
src/doc: 3RDPARTY

Log Message:
gcc-11.1.0 is out.


To generate a diff of this commit:
cvs rdiff -u -r1.1800 -r1.1801 src/doc/3RDPARTY

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/doc/3RDPARTY
diff -u src/doc/3RDPARTY:1.1800 src/doc/3RDPARTY:1.1801
--- src/doc/3RDPARTY:1.1800	Thu Apr 29 17:29:06 2021
+++ src/doc/3RDPARTY	Sun May  2 08:18:38 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: 3RDPARTY,v 1.1800 2021/04/29 17:29:06 christos Exp $
+#	$NetBSD: 3RDPARTY,v 1.1801 2021/05/02 08:18:38 wiz Exp $
 #
 # This file contains a list of the software that has been integrated into
 # NetBSD where we are not the primary maintainer.
@@ -450,7 +450,7 @@ There is a flex2netbsd script to help ne
 
 Package:	gcc
 Version:	9.3.0/10.3.0
-Current Vers:	9.3.0/10.3.0
+Current Vers:	9.3.0/10.3.0/11.1.0
 Maintainer:	FSF
 Archive Site:	ftp://ftp.gnu.org/gnu/gcc/
 Home Page:	http://www.gnu.org/software/gcc/