Module Name:    src
Committed By:   rillig
Date:           Sat Jul 10 10:30:26 UTC 2021

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

Log Message:
lint: fix assertion failure for malformed member declaration


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_249.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_249.exp
cvs rdiff -u -r1.285 -r1.286 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/msg_249.c
diff -u src/tests/usr.bin/xlint/lint1/msg_249.c:1.5 src/tests/usr.bin/xlint/lint1/msg_249.c:1.6
--- src/tests/usr.bin/xlint/lint1/msg_249.c:1.5	Thu Jul  8 20:11:15 2021
+++ src/tests/usr.bin/xlint/lint1/msg_249.c	Sat Jul 10 10:30:26 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_249.c,v 1.5 2021/07/08 20:11:15 rillig Exp $	*/
+/*	$NetBSD: msg_249.c,v 1.6 2021/07/10 10:30:26 rillig Exp $	*/
 # 3 "msg_249.c"
 
 // Test for message: syntax error '%s' [249]
@@ -45,3 +45,15 @@ access_declaration_after_syntax_error(vo
 {
 	return &recover_from_rparen;
 }
+
+struct cover_member_declaration {
+	/* cover 'noclass_declmods ... notype_member_decls' */
+	const noclass_declmods;
+
+	/* cover 'noclass_declspecs ...' */
+	const int noclass_declspecs;
+
+	/* cover 'noclass_declmods deftyp ...' */
+	/* expect+1: error: syntax error 'unnamed member' [249] */
+	const;
+};

Index: src/tests/usr.bin/xlint/lint1/msg_249.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_249.exp:1.4 src/tests/usr.bin/xlint/lint1/msg_249.exp:1.5
--- src/tests/usr.bin/xlint/lint1/msg_249.exp:1.4	Thu Jul  8 18:02:22 2021
+++ src/tests/usr.bin/xlint/lint1/msg_249.exp	Sat Jul 10 10:30:26 2021
@@ -1,3 +1,4 @@
 msg_249.c(10): error: syntax error '"' [249]
 msg_249.c(19): error: syntax error '"' [249]
 msg_249.c(33): error: syntax error ')' [249]
+msg_249.c(58): error: syntax error 'unnamed member' [249]

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.285 src/usr.bin/xlint/lint1/cgram.y:1.286
--- src/usr.bin/xlint/lint1/cgram.y:1.285	Sat Jul 10 09:53:00 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 10:30:26 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.285 2021/07/10 09:53:00 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.286 2021/07/10 10:30:26 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.285 2021/07/10 09:53:00 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.286 2021/07/10 10:30:26 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -690,18 +690,21 @@ member_declaration:
 	  }
 	| noclass_declmods deftyp type_attribute_opt {
 		symtyp = FVFT;
-		/* struct or union member must be named */
 		if (!Sflag)
 			/* anonymous struct/union members is a C9X feature */
 			warning(49);
-		/* add all the members of the anonymous struct/union */
-		lint_assert(is_struct_or_union(dcs->d_type->t_tspec));
-		$$ = dcs->d_type->t_str->sou_first_member;
-		anonymize($$);
+		if (is_struct_or_union(dcs->d_type->t_tspec)) {
+			$$ = dcs->d_type->t_str->sou_first_member;
+			/* add all the members of the anonymous struct/union */
+			anonymize($$);
+		} else {
+			/* syntax error '%s' */
+			error(249, "unnamed member");
+			$$ = NULL;
+		}
 	  }
 	| noclass_declspecs deftyp type_attribute_opt {
 		symtyp = FVFT;
-		/* struct or union member must be named */
 		if (!Sflag)
 			/* anonymous struct/union members is a C9X feature */
 			warning(49);

Reply via email to