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: make alignof(incomplete enum) an e...
details: https://anonhg.NetBSD.org/src/rev/b61975f9a4da
branches: trunk
changeset: 377184:b61975f9a4da
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Jun 30 09:26:03 2023 +0000
description:
lint: make alignof(incomplete enum) an error
diffstat:
tests/usr.bin/xlint/lint1/d_alignof.c | 4 +-
usr.bin/xlint/lint1/tree.c | 49 ++++++++++++----------------------
2 files changed, 20 insertions(+), 33 deletions(-)
diffs (92 lines):
diff -r 4c79719c7ced -r b61975f9a4da tests/usr.bin/xlint/lint1/d_alignof.c
--- a/tests/usr.bin/xlint/lint1/d_alignof.c Fri Jun 30 09:21:52 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/d_alignof.c Fri Jun 30 09:26:03 2023 +0000
@@ -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 {
diff -r 4c79719c7ced -r b61975f9a4da usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Fri Jun 30 09:21:52 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c Fri Jun 30 09:26:03 2023 +0000
@@ -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);
}
Home |
Main Index |
Thread Index |
Old Index