[PATCH 03/16] bitfield: extract linearize_bitfield_extract()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



linearize_load_gen() is complex because it not only has to do
the loading of a value from some address but it also has to
handle the extraction of bitfields.

Isolate this operation in a separate function in order to
facilitate the incoming changes there.
---
 linearize.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/linearize.c b/linearize.c
index 938dbc07b..273a534f2 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1061,6 +1061,19 @@ static pseudo_t add_symbol_address(struct entrypoint *ep, struct symbol *sym)
 	return target;
 }
 
+static pseudo_t linearize_bitfield_extract(struct entrypoint *ep,
+		pseudo_t val, struct symbol *ctype, struct symbol *btype)
+{
+	unsigned int off = ctype->bit_offset;
+
+	if (off) {
+		pseudo_t shift = value_pseudo(off);
+		val = add_binary_op(ep, btype, OP_LSR, val, shift);
+	}
+	val = cast_pseudo(ep, val, btype, ctype);
+	return val;
+}
+
 static pseudo_t linearize_load_gen(struct entrypoint *ep, struct access_data *ad)
 {
 	struct symbol *ctype = ad->type;
@@ -1071,13 +1084,8 @@ static pseudo_t linearize_load_gen(struct entrypoint *ep, struct access_data *ad
 		return VOID;
 
 	new = add_load(ep, ad);
-	if (ctype->bit_offset) {
-		pseudo_t shift = value_pseudo(ctype->bit_offset);
-		pseudo_t newval = add_binary_op(ep, btype, OP_LSR, new, shift);
-		new = newval;
-	}
 	if (ctype->bit_size != type_size(btype))
-		new = cast_pseudo(ep, new, btype, ctype);
+		new = linearize_bitfield_extract(ep, new, ctype, btype);
 	return new;
 }
 
-- 
2.18.0

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



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux