linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] memops need long offsets
@ 2020-10-20 16:44 Luc Van Oostenryck
  0 siblings, 0 replies; only message in thread
From: Luc Van Oostenryck @ 2020-10-20 16:44 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

These days, declaring arrays bigger than 2GB or doing pointer
arithmetic with an offset larger than 2^31 is maybe not usual but
certainly not outrageous.

However, currently Sparse silently truncates 32 bits the offsets
of memory accesses.

So, fix this by using 64-bit offsets for memory accesses.
Also, use a signed type since these offsets can be negative.

Note: I had a really nice (real) example for this but the margin
      of this patch is too small for it (but now I've lost it).

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 linearize.c | 6 +++---
 linearize.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/linearize.c b/linearize.c
index 1081bda86425..b7da35fa0ede 100644
--- a/linearize.c
+++ b/linearize.c
@@ -426,10 +426,10 @@ const char *show_instruction(struct instruction *insn)
 		break;
 	}	
 	case OP_LOAD:
-		buf += sprintf(buf, "%s <- %d[%s]", show_pseudo(insn->target), insn->offset, show_pseudo(insn->src));
+		buf += sprintf(buf, "%s <- %lld[%s]", show_pseudo(insn->target), insn->offset, show_pseudo(insn->src));
 		break;
 	case OP_STORE:
-		buf += sprintf(buf, "%s -> %d[%s]", show_pseudo(insn->target), insn->offset, show_pseudo(insn->src));
+		buf += sprintf(buf, "%s -> %lld[%s]", show_pseudo(insn->target), insn->offset, show_pseudo(insn->src));
 		break;
 	case OP_INLINED_CALL:
 	case OP_CALL: {
@@ -925,7 +925,7 @@ struct access_data {
 	struct symbol *type;		// ctype
 	struct symbol *btype;		// base type of bitfields
 	pseudo_t address;		// pseudo containing address ..
-	unsigned int offset;		// byte offset
+	long long offset;		// byte offset
 };
 
 static int linearize_simple_address(struct entrypoint *ep,
diff --git a/linearize.h b/linearize.h
index 76efd0b47ffa..d8cbc3f339b4 100644
--- a/linearize.h
+++ b/linearize.h
@@ -117,7 +117,7 @@ struct instruction {
 		};
 		struct /* memops */ {
 			pseudo_t addr;			/* alias .src */
-			unsigned int offset;
+			long long offset;
 			unsigned int is_volatile:1;
 		};
 		struct /* binops and sel */ {
-- 
2.28.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-10-20 16:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-20 16:44 [PATCH] memops need long offsets Luc Van Oostenryck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).