Module Name:    src
Committed By:   rillig
Date:           Fri Jun 30 09:26:03 UTC 2023

Modified Files:
        src/tests/usr.bin/xlint/lint1: d_alignof.c
        src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: make alignof(incomplete enum) an error


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/d_alignof.c
cvs rdiff -u -r1.534 -r1.535 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/d_alignof.c
diff -u src/tests/usr.bin/xlint/lint1/d_alignof.c:1.9 src/tests/usr.bin/xlint/lint1/d_alignof.c:1.10
--- src/tests/usr.bin/xlint/lint1/d_alignof.c:1.9	Fri Jun 30 09:21:52 2023
+++ src/tests/usr.bin/xlint/lint1/d_alignof.c	Fri Jun 30 09:26:03 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_alignof.c,v 1.9 2023/06/30 09:21:52 rillig Exp $	*/
+/*	$NetBSD: d_alignof.c,v 1.10 2023/06/30 09:26:03 rillig Exp $	*/
 # 3 "d_alignof.c"
 
 /* https://gcc.gnu.org/onlinedocs/gcc/Alignment.html */
@@ -105,7 +105,7 @@ alignof_variants(void)
 
 	/* expect+1: warning: enum 'incomplete_enum' never defined [235] */
 	enum incomplete_enum;
-	/* expect+1: error: negative array dimension (-4) [20] */
+	/* expect+1: error: cannot take size/alignment of incomplete type [143] */
 	typedef int incomplete_enum[-(int)__alignof(enum incomplete_enum)];
 
 	struct bit_fields {

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.534 src/usr.bin/xlint/lint1/tree.c:1.535
--- src/usr.bin/xlint/lint1/tree.c:1.534	Fri Jun 30 08:48:38 2023
+++ src/usr.bin/xlint/lint1/tree.c	Fri Jun 30 09:26:03 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.534 2023/06/30 08:48:38 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.535 2023/06/30 09:26:03 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.534 2023/06/30 08:48:38 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.535 2023/06/30 09:26:03 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -4095,39 +4095,26 @@ type_size_in_bits(const type_t *tp)
 tnode_t *
 build_alignof(const type_t *tp)
 {
-	switch (tp->t_tspec) {
-	case ARRAY:
-		break;
-
-	case FUNC:
+	if (tp->t_tspec == FUNC) {
 		/* cannot take size/alignment of function type '%s' */
 		error(144, type_name(tp));
 		return NULL;
-
-	case STRUCT:
-	case UNION:
-		if (is_incomplete(tp)) {
-			/* cannot take size/alignment of incomplete type */
-			error(143);
-			return NULL;
-		}
-		break;
-	case ENUM:
-		break;
-	default:
-		if (tp->t_bitfield) {
-			/* cannot take size/alignment of bit-field */
-			error(145);
-			return NULL;
-		}
-		if (tp->t_tspec == VOID) {
-			/* cannot take size/alignment of void */
-			error(146);
-			return NULL;
-		}
-		break;
 	}
-
+	if (tp->t_tspec == VOID) {
+		/* cannot take size/alignment of void */
+		error(146);
+		return NULL;
+	}
+	if (is_incomplete(tp)) {
+		/* cannot take size/alignment of incomplete type */
+		error(143);
+		return NULL;
+	}
+	if (tp->t_bitfield) {
+		/* cannot take size/alignment of bit-field */
+		error(145);
+		return NULL;
+	}
 	return build_integer_constant(SIZEOF_TSPEC,
 	    (int64_t)alignment_in_bits(tp) / CHAR_SIZE);
 }

Reply via email to