Skip to contentSkip to conversation

Fix handling of typedefs with several declarators

PATCH New Al Viro 1 participant 1 message Mar 9, 2009 Sparse checker

lore
Share & tools
lore

Al Viro

author
#0 lore raw

PATCH 9/18 Fix handling of typedefs with several declarators

We set MOD_USERTYPE only on the first one, so declaration_specifiers didn't recognize something like

	unsigned P;

where P had been such a typedef as redefinition (see the testcase).

---
 parse.c                    |    3 +++
 validation/multi_typedef.c |   15 +++++++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)
 create mode 100644 validation/multi_typedef.c
parse.c +3 -0
index 7b1cfb6..1435fde 100644
@@ -2365,6 +2365,9 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis
 			return token;
 		}
 
+		if (is_typedef)
+			decl->ctype.modifiers |= MOD_USERTYPE;
+
 		bind_symbol(decl, ident, is_typedef ? NS_TYPEDEF: NS_SYMBOL);
 
 		/* Function declarations are automatically extern unless specifically static */
validation/multi_typedef.c new file +15 -0
new file mode 100644
index 0000000..d9ffd0f
@@ -0,0 +1,15 @@
+typedef int T, *P;
+static void f(void)
+{
+	unsigned P = 0;
+	unsigned x = P;
+}
+static void g(void)
+{
+	int P = 0;
+	int x = P;
+}
+/*
+ * check-name: typedefs with many declarators
+ * check-description: we didn't recognize P above as a typedef
+ */
Signature · 1 line
1.5.6.5