summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2021-02-28 02:29:28 +0000
committerrillig <rillig@NetBSD.org>2021-02-28 02:29:28 +0000
commit6dfbdbf53a8165db6e62044279e2a577d161e445 (patch)
tree76580fa7a6e786bbd6166089aee305af57850640
parent5f80ac5abd0fe732e233d5971a75432921e0ab57 (diff)
lint: output precise type information for struct/union/enum
Previously, 'typedef enum { E } name' was output as 'name', which omitted the information that this was an enum type. Now it is output as 'enum typedef name'. Previously, 'typedef struct { int member; } name' was output as 'struct <unnamed>', which omitted the typedef name. Now it is output as 'struct typedef name'.
-rw-r--r--tests/usr.bin/xlint/lint1/msg_210.exp2
-rw-r--r--tests/usr.bin/xlint/lint1/msg_245.exp2
-rw-r--r--usr.bin/xlint/common/tyname.c62
3 files changed, 41 insertions, 25 deletions
diff --git a/tests/usr.bin/xlint/lint1/msg_210.exp b/tests/usr.bin/xlint/lint1/msg_210.exp
index 54f9d326308..868a8cee011 100644
--- a/tests/usr.bin/xlint/lint1/msg_210.exp
+++ b/tests/usr.bin/xlint/lint1/msg_210.exp
@@ -1,2 +1,2 @@
msg_210.c(23): warning: enum type mismatch between 'enum A' and 'enum B' in initialization [210]
-msg_210.c(25): warning: enum type mismatch between 'C' and 'D' in initialization [210]
+msg_210.c(25): warning: enum type mismatch between 'enum typedef C' and 'enum typedef D' in initialization [210]
diff --git a/tests/usr.bin/xlint/lint1/msg_245.exp b/tests/usr.bin/xlint/lint1/msg_245.exp
index 9bc6db39525..3f1f386651e 100644
--- a/tests/usr.bin/xlint/lint1/msg_245.exp
+++ b/tests/usr.bin/xlint/lint1/msg_245.exp
@@ -1,3 +1,3 @@
msg_245.c(29): warning: incompatible structure pointers: 'pointer to struct tag_and_typedef_tag' '==' 'pointer to struct only_tag' [245]
-msg_245.c(30): warning: incompatible structure pointers: 'pointer to struct tag_and_typedef_tag' '==' 'pointer to struct <unnamed>' [245]
+msg_245.c(30): warning: incompatible structure pointers: 'pointer to struct tag_and_typedef_tag' '==' 'pointer to struct typedef only_typedef' [245]
msg_245.c(31): warning: incompatible structure pointers: 'pointer to struct tag_and_typedef_tag' '==' 'pointer to struct <unnamed>' [245]
diff --git a/usr.bin/xlint/common/tyname.c b/usr.bin/xlint/common/tyname.c
index 267a86e95a3..a368e0d51de 100644
--- a/usr.bin/xlint/common/tyname.c
+++ b/usr.bin/xlint/common/tyname.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tyname.c,v 1.31 2021/02/21 14:19:27 rillig Exp $ */
+/* $NetBSD: tyname.c,v 1.32 2021/02/28 02:29:28 rillig Exp $ */
/*-
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tyname.c,v 1.31 2021/02/21 14:19:27 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.32 2021/02/28 02:29:28 rillig Exp $");
#endif
#include <limits.h>
@@ -280,6 +280,40 @@ type_name_of_function(buffer *buf, const type_t *tp)
buf_add(buf, type_name(tp->t_subt));
}
+static void
+type_name_of_struct_or_union(buffer *buf, const type_t *tp)
+{
+ buf_add(buf, " ");
+#ifdef t_str
+ if (tp->t_str->sou_tag->s_name == unnamed &&
+ tp->t_str->sou_first_typedef != NULL) {
+ buf_add(buf, "typedef ");
+ buf_add(buf, tp->t_str->sou_first_typedef->s_name);
+ } else {
+ buf_add(buf, tp->t_str->sou_tag->s_name);
+ }
+#else
+ buf_add(buf, tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name);
+#endif
+}
+
+static void
+type_name_of_enum(buffer *buf, const type_t *tp)
+{
+ buf_add(buf, " ");
+#ifdef t_enum
+ if (tp->t_enum->en_tag->s_name == unnamed &&
+ tp->t_enum->en_first_typedef != NULL) {
+ buf_add(buf, "typedef ");
+ buf_add(buf, tp->t_enum->en_first_typedef->s_name);
+ } else {
+ buf_add(buf, tp->t_enum->en_tag->s_name);
+ }
+#else
+ buf_add(buf, tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name);
+#endif
+}
+
const char *
type_name(const type_t *tp)
{
@@ -302,6 +336,7 @@ type_name(const type_t *tp)
buf_add(&buf, "const ");
if (tp->t_volatile)
buf_add(&buf, "volatile ");
+
buf_add(&buf, tspec_name(t));
switch (t) {
@@ -337,30 +372,11 @@ type_name(const type_t *tp)
buf_add(&buf, type_name(tp->t_subt));
break;
case ENUM:
-#ifdef t_enum
- if (tp->t_enum->en_tag->s_name == unnamed &&
- tp->t_enum->en_first_typedef != NULL) {
- buf.len -= strlen(tspec_name(t));
- buf_add(&buf, tp->t_enum->en_first_typedef->s_name);
- } else {
- buf_add(&buf, " ");
- buf_add(&buf, tp->t_enum->en_tag->s_name);
- }
-#else
- buf_add(&buf, " ");
- buf_add(&buf,
- tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name);
-#endif
+ type_name_of_enum(&buf, tp);
break;
case STRUCT:
case UNION:
- buf_add(&buf, " ");
-#ifdef t_str
- buf_add(&buf, tp->t_str->sou_tag->s_name);
-#else
- buf_add(&buf,
- tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name);
-#endif
+ type_name_of_struct_or_union(&buf, tp);
break;
case ARRAY:
buf_add(&buf, " of ");