[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-sparse
Subject:    [PATCH 2/2] Remove the redundant attribute from ctype
From:       Christopher Li <sparse () chrisli ! org>
Date:       2013-02-27 15:23:13
Message-ID: CANeU7QnxXTB8edDF9C72U==HHcWSVmprw4Rd+C4OWV3Y8B9TCg () mail ! gmail ! com
[Download RAW message or body]

This change removes the attribute data store in ctype struct.

Chris

["0002-Remove-the-redundant-attribute-from-ctype-structure.patch" (application/octet-stream)]

From 2fe91880451e17d3becefeb9eccc4e30a2f6e040 Mon Sep 17 00:00:00 2001
From: Christopher Li <sparse@chrisli.org>
Date: Sun, 24 Feb 2013 20:17:37 -0800
Subject: [PATCH 2/2] Remove the redundant attribute from ctype structure.

Signed-off-by: Christopher Li <sparse@chrisli.org>
---
 evaluate.c   | 23 -----------------------
 linearize.c  |  1 -
 parse.c      |  4 ----
 show-parse.c |  3 ---
 sparse.c     |  1 -
 symbol.h     | 26 --------------------------
 6 files changed, 58 deletions(-)

diff --git a/evaluate.c b/evaluate.c
index 3e087e6..f3f6572 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -185,7 +185,6 @@ static struct symbol *base_type(struct symbol *node, unsigned long *modp, unsign
 	mod = 0; as = 0;
 	while (node) {
 		mod |= node->ctype.modifiers;
-		check_sym(node);
 		as |= node->ctype.attribute->as;
 		if (node->type == SYM_NODE) {
 			node = node->ctype.base_type;
@@ -618,16 +617,12 @@ const char *type_difference(struct ctype *c1, struct ctype *c2,
 	int move1 = 1, move2 = 1;
 	mod1 |= c1->modifiers;
 	mod2 |= c2->modifiers;
-	check_attr(c1);
-	check_attr(c2);
 
 	for (;;) {
 		unsigned long diff;
 		int type;
 		struct symbol *base1 = t1->ctype.base_type;
 		struct symbol *base2 = t2->ctype.base_type;
-		check_sym(t1);
-		check_sym(t2);
 
 		/*
 		 * FIXME! Collect alignment and context too here!
@@ -704,8 +699,6 @@ const char *type_difference(struct ctype *c1, struct ctype *c2,
 			as1 = t1->ctype.attribute->as;
 			mod2 = t2->ctype.modifiers;
 			as2 = t2->ctype.attribute->as;
-			check_sym(t1);
-			check_sym(t2);
 			break;
 		case SYM_FN: {
 			struct symbol *arg1, *arg2;
@@ -719,8 +712,6 @@ const char *type_difference(struct ctype *c1, struct ctype *c2,
 			as1 = t1->ctype.attribute->as;
 			mod2 = t2->ctype.modifiers;
 			as2 = t2->ctype.attribute->as;
-			check_sym(t1);
-			check_sym(t2);
 
 			if (base1->variadic != base2->variadic)
 				return "incompatible variadic arguments";
@@ -1052,8 +1043,6 @@ static struct symbol *evaluate_compare(struct expression *expr)
 
 	/* they also have special treatment for pointers to void */
 	if (expr->op == SPECIAL_EQUAL || expr->op == SPECIAL_NOTEQUAL) {
-		check_sym(ltype);
-		check_sym(rtype);
 		if (ltype->ctype.attribute->as == rtype->ctype.attribute->as) {
 			if (lbase == &void_ctype) {
 				right = cast_to(right, ltype);
@@ -1158,8 +1147,6 @@ static struct symbol *evaluate_conditional_expression(struct expression *expr)
 			goto Err;
 		}
 		/* OK, it's pointer on pointer */
-		check_sym(ltype);
-		check_sym(rtype);
 		if (ltype->ctype.attribute->as != rtype->ctype.attribute->as) {
 			typediff = "different address spaces";
 			goto Err;
@@ -1350,8 +1337,6 @@ static int compatible_assignment_types(struct expression *expr, struct symbol *t
 			 * we do not remove qualifiers from pointed to [C]
 			 * or mix address spaces [sparse].
 			 */
-			check_sym(t);
-			check_sym(s);
 			if (t->ctype.attribute->as != s->ctype.attribute->as) {
 				typediff = "different address spaces";
 				goto Err;
@@ -1478,12 +1463,10 @@ static void examine_fn_arguments(struct symbol *fn)
 					ptr->ctype = arg->ctype;
 				else
 					ptr->ctype.base_type = arg;
-				check_sym(s);
 				merge_attr(&ptr->ctype, &s->ctype);
 				ptr->ctype.modifiers |= s->ctype.modifiers & MOD_PTRINHERIT;
 
 				s->ctype.base_type = ptr;
-				s->ctype.as = 0;
 				s->ctype.attribute = &null_attr;
 				s->ctype.modifiers &= ~MOD_PTRINHERIT;
 				s->bit_size = 0;
@@ -1502,7 +1485,6 @@ static struct symbol *convert_to_as_mod(struct symbol *sym, int as, int mod)
 {
 	/* Take the modifiers of the pointer, and apply them to the member */
 	mod |= sym->ctype.modifiers;
-	check_sym(sym);
 	if (sym->ctype.attribute->as != as || sym->ctype.modifiers != mod) {
 		struct symbol *newsym = alloc_symbol(sym->pos, SYM_NODE);
 		*newsym = *sym;
@@ -1526,7 +1508,6 @@ static struct symbol *create_pointer(struct expression *expr, struct symbol *sym
 	node->ctype.alignment = pointer_alignment;
 
 	access_symbol(sym);
-	check_sym(sym);
 	if (sym->ctype.modifiers & MOD_REGISTER) {
 		warning(expr->pos, "taking address of 'register' variable '%s'", show_ident(sym->ident));
 		sym->ctype.modifiers &= ~MOD_REGISTER;
@@ -1916,12 +1897,10 @@ static struct symbol *evaluate_member_dereference(struct expression *expr)
 
 	ctype = deref->ctype;
 	examine_symbol_type(ctype);
-	check_sym(ctype);
 	address_space = ctype->ctype.attribute->as;
 	mod = ctype->ctype.modifiers;
 	if (ctype->type == SYM_NODE) {
 		ctype = ctype->ctype.base_type;
-		check_sym(ctype);
 		address_space |= ctype->ctype.attribute->as;
 		mod |= ctype->ctype.modifiers;
 	}
@@ -2728,7 +2707,6 @@ static struct symbol *evaluate_cast(struct expression *expr)
 		as1 = -1;
 	else if (class1 == TYPE_PTR) {
 		examine_pointer_target(t1);
-		check_sym(t1);
 		as1 = t1->ctype.attribute->as;
 	}
 
@@ -2736,7 +2714,6 @@ static struct symbol *evaluate_cast(struct expression *expr)
 		as2 = -1;
 	else if (class2 == TYPE_PTR) {
 		examine_pointer_target(t2);
-		check_sym(t2);
 		as2 = t2->ctype.attribute->as;
 	}
 
diff --git a/linearize.c b/linearize.c
index 42df529..be546be 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1240,7 +1240,6 @@ static pseudo_t linearize_call_expression(struct entrypoint *ep, struct expressi
 	add_one_insn(ep, insn);
 
 	if (ctype) {
-		check_attr(ctype);
 		FOR_EACH_PTR(ctype->attribute->contexts, context) {
 			int in = context->in;
 			int out = context->out;
diff --git a/parse.c b/parse.c
index ffd6ad8..c90bae6 100644
--- a/parse.c
+++ b/parse.c
@@ -1361,7 +1361,6 @@ static void apply_ctype(struct position pos, struct ctype *thistype, struct ctyp
 		ctype->alignment = thistype->alignment;
 
 	/* Attribute */
-	check_attr(thistype);
 	merge_attr(ctype, thistype);
 }
 
@@ -1711,13 +1710,10 @@ static struct token *pointer(struct token *token, struct decl_state *ctx)
 		struct symbol *ptr = alloc_symbol(token->pos, SYM_PTR);
 		ptr->ctype.modifiers = ctx->ctype.modifiers;
 		ptr->ctype.base_type = ctx->ctype.base_type;
-		check_attr(&ctx->ctype);
 		merge_attr(&ptr->ctype, &ctx->ctype);
 		ctx->ctype.modifiers = 0;
 		ctx->ctype.base_type = ptr;
-		ctx->ctype.as = 0;
 		ctx->ctype.attribute = &null_attr;
-		ctx->ctype.contexts = NULL;
 		ctx->ctype.alignment = 0;
 
 		token = handle_qualifiers(token->next, ctx);
diff --git a/show-parse.c b/show-parse.c
index ca6232d..47e490b 100644
--- a/show-parse.c
+++ b/show-parse.c
@@ -56,7 +56,6 @@ static void do_debug_symbol(struct symbol *sym, int indent)
 
 	if (!sym)
 		return;
-	check_sym(sym);
 	fprintf(stderr, "%.*s%s%3d:%lu %s %s (as: %d) %p (%s:%d:%d) %s\n",
 		indent, indent_string, typestr[sym->type],
 		sym->bit_size, sym->ctype.alignment,
@@ -64,7 +63,6 @@ static void do_debug_symbol(struct symbol *sym, int indent)
 		sym, stream_name(sym->pos.stream), sym->pos.line, sym->pos.pos,
 		builtin_typename(sym) ?: "");
 	i = 0;
-	check_sym(sym);
 	FOR_EACH_PTR(sym->ctype.attribute->contexts, context) {
 		/* FIXME: should print context expression */
 		fprintf(stderr, "< context%d: in=%d, out=%d\n",
@@ -296,7 +294,6 @@ deeper:
 		goto out;
 	}
 
-	check_sym(sym);
 	/* Prepend */
 	switch (sym->type) {
 	case SYM_PTR:
diff --git a/sparse.c b/sparse.c
index fad16ad..351e400 100644
--- a/sparse.c
+++ b/sparse.c
@@ -248,7 +248,6 @@ static void check_context(struct entrypoint *ep)
 
 	check_instructions(ep);
 
-	check_sym(sym);
 	FOR_EACH_PTR(sym->ctype.attribute->contexts, context) {
 		in_context += context->in;
 		out_context += context->out;
diff --git a/symbol.h b/symbol.h
index 192a957..63dc587 100644
--- a/symbol.h
+++ b/symbol.h
@@ -90,8 +90,6 @@ struct ctype {
 	unsigned long modifiers;
 	unsigned long alignment;
 	struct attribute *attribute;
-	struct context_list *contexts;
-	unsigned int as;
 	struct symbol *base_type;
 };
 
@@ -399,7 +397,6 @@ static inline struct attribute *duplicate_attribute(struct attribute *attr)
 
 static inline void attr_set_as(struct ctype *ctype, unsigned int as)
 {
-	ctype->as = as;
 	if (ctype->attribute->as != as) {
 		ctype->attribute = duplicate_attribute(ctype->attribute);
 		ctype->attribute->as = as;
@@ -408,36 +405,13 @@ static inline void attr_set_as(struct ctype *ctype, unsigned int as)
 
 static inline void attr_add_context(struct ctype *ctype, struct context *context)
 {
-	add_ptr_list(&ctype->contexts, context);
 	ctype->attribute = duplicate_attribute(ctype->attribute);
 	add_ptr_list(&ctype->attribute->contexts, context);
 }
 
-/*
- * Check the ctype.as is consistent with the ctype.attribute.
- * This function will get removed with ctype.as eventually.
- */
-static inline void check_attr(struct ctype *ctype)
-{
-	if (!ctype->attribute)
-		die("Empty attribute of %p\n", ctype);
-	if (ctype->as != ctype->attribute->as)
-		die("Attribute as difference %d %d\n", ctype->as, ctype->attribute->as);
-	if (context_list_size(ctype->contexts) != context_list_size(ctype->attribute->contexts))
-		die("Attribute context has different size \n");
-}
-
-static inline void check_sym(struct symbol *sym)
-{
-	check_attr(&sym->ctype);
-}
-
 static inline void merge_attr(struct ctype *dst, struct ctype *src)
 {
 	struct attribute *attr;
-	dst->as |= src->as;
-	concat_ptr_list((struct ptr_list *)src->contexts,
-			(struct ptr_list **)&dst->contexts);
 
 	if (src->attribute == &null_attr)
 		return;
-- 
1.8.1.2


--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic