]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
DynASM: Fix warnings.
authorMike Pall <mike>
Fri, 2 Jun 2023 10:54:46 +0000 (12:54 +0200)
committerMike Pall <mike>
Fri, 2 Jun 2023 10:54:46 +0000 (12:54 +0200)
Reported by Ilija Tovilo.

dynasm/dasm_arm.h
dynasm/dasm_arm64.h
dynasm/dasm_mips.h
dynasm/dasm_ppc.h
dynasm/dasm_x86.h

index fbfebee09fcb8a4c70201e75611681f0287d55ce..aa16014e0f6e42d9d81a8cef559f2566b9b23c98 100644 (file)
@@ -70,7 +70,7 @@ struct dasm_State {
   size_t lgsize;
   int *pclabels;               /* PC label chains/pos ptrs. */
   size_t pcsize;
-  void **globals;              /* Array of globals (bias -10). */
+  void **globals;              /* Array of globals. */
   dasm_Section *section;       /* Pointer to active section. */
   size_t codesize;             /* Total size of all code sections. */
   int maxsection;              /* 0 <= sectionidx < maxsection. */
@@ -87,7 +87,6 @@ void dasm_init(Dst_DECL, int maxsection)
 {
   dasm_State *D;
   size_t psz = 0;
-  int i;
   Dst_REF = NULL;
   DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));
   D = Dst_REF;
@@ -98,12 +97,7 @@ void dasm_init(Dst_DECL, int maxsection)
   D->pcsize = 0;
   D->globals = NULL;
   D->maxsection = maxsection;
-  for (i = 0; i < maxsection; i++) {
-    D->sections[i].buf = NULL;  /* Need this for pass3. */
-    D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);
-    D->sections[i].bsize = 0;
-    D->sections[i].epos = 0;  /* Wrong, but is recalculated after resize. */
-  }
+  memset((void *)D->sections, 0, maxsection * sizeof(dasm_Section));
 }
 
 /* Free DynASM state. */
@@ -123,7 +117,7 @@ void dasm_free(Dst_DECL)
 void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)
 {
   dasm_State *D = Dst_REF;
-  D->globals = gl - 10;  /* Negative bias to compensate for locals. */
+  D->globals = gl;
   DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));
 }
 
@@ -372,7 +366,7 @@ int dasm_encode(Dst_DECL, void *buffer)
          break;
        case DASM_REL_LG:
          if (n < 0) {
-           n = (int)((ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp - 4);
+           n = (int)((ptrdiff_t)D->globals[-n-10] - (ptrdiff_t)cp - 4);
            goto patchrel;
          }
          /* fallthrough */
@@ -396,7 +390,7 @@ int dasm_encode(Dst_DECL, void *buffer)
          }
          break;
        case DASM_LABEL_LG:
-         ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);
+         ins &= 2047; if (ins >= 20) D->globals[ins-20] = (void *)(base + n);
          break;
        case DASM_LABEL_PC: break;
        case DASM_IMM:
index 47c9c37d630d08d10ed7be70d6632f8800d847fa..e04898f1cf3d6b37ec5a828e963757ee9c5bda49 100644 (file)
@@ -72,7 +72,7 @@ struct dasm_State {
   size_t lgsize;
   int *pclabels;               /* PC label chains/pos ptrs. */
   size_t pcsize;
-  void **globals;              /* Array of globals (bias -10). */
+  void **globals;              /* Array of globals. */
   dasm_Section *section;       /* Pointer to active section. */
   size_t codesize;             /* Total size of all code sections. */
   int maxsection;              /* 0 <= sectionidx < maxsection. */
@@ -89,7 +89,6 @@ void dasm_init(Dst_DECL, int maxsection)
 {
   dasm_State *D;
   size_t psz = 0;
-  int i;
   Dst_REF = NULL;
   DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));
   D = Dst_REF;
@@ -100,12 +99,7 @@ void dasm_init(Dst_DECL, int maxsection)
   D->pcsize = 0;
   D->globals = NULL;
   D->maxsection = maxsection;
-  for (i = 0; i < maxsection; i++) {
-    D->sections[i].buf = NULL;  /* Need this for pass3. */
-    D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);
-    D->sections[i].bsize = 0;
-    D->sections[i].epos = 0;  /* Wrong, but is recalculated after resize. */
-  }
+  memset((void *)D->sections, 0, maxsection * sizeof(dasm_Section));
 }
 
 /* Free DynASM state. */
@@ -125,7 +119,7 @@ void dasm_free(Dst_DECL)
 void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)
 {
   dasm_State *D = Dst_REF;
-  D->globals = gl - 10;  /* Negative bias to compensate for locals. */
+  D->globals = gl;
   DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));
 }
 
@@ -444,7 +438,7 @@ int dasm_encode(Dst_DECL, void *buffer)
          break;
        case DASM_REL_LG:
          if (n < 0) {
-           ptrdiff_t na = (ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp + 4;
+           ptrdiff_t na = (ptrdiff_t)D->globals[-n-10] - (ptrdiff_t)cp + 4;
            n = (int)na;
            CK((ptrdiff_t)n == na, RANGE_REL);
            goto patchrel;
@@ -487,7 +481,7 @@ int dasm_encode(Dst_DECL, void *buffer)
          goto patchrel;
        }
        case DASM_LABEL_LG:
-         ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);
+         ins &= 2047; if (ins >= 20) D->globals[ins-20] = (void *)(base + n);
          break;
        case DASM_LABEL_PC: break;
        case DASM_IMM:
index 3e99a0050748abfad09174df67156f38a2d560ec..495eaa0ee5b3d0adba48449641d7ade253e0c1ae 100644 (file)
@@ -69,7 +69,7 @@ struct dasm_State {
   size_t lgsize;
   int *pclabels;               /* PC label chains/pos ptrs. */
   size_t pcsize;
-  void **globals;              /* Array of globals (bias -10). */
+  void **globals;              /* Array of globals. */
   dasm_Section *section;       /* Pointer to active section. */
   size_t codesize;             /* Total size of all code sections. */
   int maxsection;              /* 0 <= sectionidx < maxsection. */
@@ -86,7 +86,6 @@ void dasm_init(Dst_DECL, int maxsection)
 {
   dasm_State *D;
   size_t psz = 0;
-  int i;
   Dst_REF = NULL;
   DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));
   D = Dst_REF;
@@ -97,12 +96,7 @@ void dasm_init(Dst_DECL, int maxsection)
   D->pcsize = 0;
   D->globals = NULL;
   D->maxsection = maxsection;
-  for (i = 0; i < maxsection; i++) {
-    D->sections[i].buf = NULL;  /* Need this for pass3. */
-    D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);
-    D->sections[i].bsize = 0;
-    D->sections[i].epos = 0;  /* Wrong, but is recalculated after resize. */
-  }
+  memset((void *)D->sections, 0, maxsection * sizeof(dasm_Section));
 }
 
 /* Free DynASM state. */
@@ -122,7 +116,7 @@ void dasm_free(Dst_DECL)
 void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)
 {
   dasm_State *D = Dst_REF;
-  D->globals = gl - 10;  /* Negative bias to compensate for locals. */
+  D->globals = gl;
   DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));
 }
 
@@ -350,7 +344,7 @@ int dasm_encode(Dst_DECL, void *buffer)
          break;
        case DASM_REL_LG:
          if (n < 0) {
-           n = (int)((ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp);
+           n = (int)((ptrdiff_t)D->globals[-n-10] - (ptrdiff_t)cp);
            goto patchrel;
          }
          /* fallthrough */
@@ -369,7 +363,7 @@ int dasm_encode(Dst_DECL, void *buffer)
          }
          break;
        case DASM_LABEL_LG:
-         ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);
+         ins &= 2047; if (ins >= 20) D->globals[ins-20] = (void *)(base + n);
          break;
        case DASM_LABEL_PC: break;
        case DASM_IMMS:
index fdb89bce4e1503b92ae7410de03210fdf8bcbc8c..30b757e312206c81f9998ede412bcf02f947cc5e 100644 (file)
@@ -69,7 +69,7 @@ struct dasm_State {
   size_t lgsize;
   int *pclabels;               /* PC label chains/pos ptrs. */
   size_t pcsize;
-  void **globals;              /* Array of globals (bias -10). */
+  void **globals;              /* Array of globals. */
   dasm_Section *section;       /* Pointer to active section. */
   size_t codesize;             /* Total size of all code sections. */
   int maxsection;              /* 0 <= sectionidx < maxsection. */
@@ -86,7 +86,6 @@ void dasm_init(Dst_DECL, int maxsection)
 {
   dasm_State *D;
   size_t psz = 0;
-  int i;
   Dst_REF = NULL;
   DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));
   D = Dst_REF;
@@ -97,12 +96,7 @@ void dasm_init(Dst_DECL, int maxsection)
   D->pcsize = 0;
   D->globals = NULL;
   D->maxsection = maxsection;
-  for (i = 0; i < maxsection; i++) {
-    D->sections[i].buf = NULL;  /* Need this for pass3. */
-    D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);
-    D->sections[i].bsize = 0;
-    D->sections[i].epos = 0;  /* Wrong, but is recalculated after resize. */
-  }
+  memset((void *)D->sections, 0, maxsection * sizeof(dasm_Section));
 }
 
 /* Free DynASM state. */
@@ -122,7 +116,7 @@ void dasm_free(Dst_DECL)
 void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)
 {
   dasm_State *D = Dst_REF;
-  D->globals = gl - 10;  /* Negative bias to compensate for locals. */
+  D->globals = gl;
   DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));
 }
 
@@ -354,7 +348,7 @@ int dasm_encode(Dst_DECL, void *buffer)
          break;
        case DASM_REL_LG:
          if (n < 0) {
-           n = (int)((ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp);
+           n = (int)((ptrdiff_t)D->globals[-n-10] - (ptrdiff_t)cp);
            goto patchrel;
          }
          /* fallthrough */
@@ -368,7 +362,7 @@ int dasm_encode(Dst_DECL, void *buffer)
          cp[-1] |= ((n+4) & ((ins & 2048) ? 0x0000fffc: 0x03fffffc));
          break;
        case DASM_LABEL_LG:
-         ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);
+         ins &= 2047; if (ins >= 20) D->globals[ins-20] = (void *)(base + n);
          break;
        case DASM_LABEL_PC: break;
        case DASM_IMM:
index f0327302dc3b913b44539da791582925ad67d00d..66a68ea5a4d2734743a1a04b92b5a5e3fde06902 100644 (file)
@@ -68,7 +68,7 @@ struct dasm_State {
   size_t lgsize;
   int *pclabels;               /* PC label chains/pos ptrs. */
   size_t pcsize;
-  void **globals;              /* Array of globals (bias -10). */
+  void **globals;              /* Array of globals. */
   dasm_Section *section;       /* Pointer to active section. */
   size_t codesize;             /* Total size of all code sections. */
   int maxsection;              /* 0 <= sectionidx < maxsection. */
@@ -85,7 +85,6 @@ void dasm_init(Dst_DECL, int maxsection)
 {
   dasm_State *D;
   size_t psz = 0;
-  int i;
   Dst_REF = NULL;
   DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));
   D = Dst_REF;
@@ -96,12 +95,7 @@ void dasm_init(Dst_DECL, int maxsection)
   D->pcsize = 0;
   D->globals = NULL;
   D->maxsection = maxsection;
-  for (i = 0; i < maxsection; i++) {
-    D->sections[i].buf = NULL;  /* Need this for pass3. */
-    D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);
-    D->sections[i].bsize = 0;
-    D->sections[i].epos = 0;  /* Wrong, but is recalculated after resize. */
-  }
+  memset((void *)D->sections, 0, maxsection * sizeof(dasm_Section));
 }
 
 /* Free DynASM state. */
@@ -121,7 +115,7 @@ void dasm_free(Dst_DECL)
 void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)
 {
   dasm_State *D = Dst_REF;
-  D->globals = gl - 10;  /* Negative bias to compensate for locals. */
+  D->globals = gl;
   DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));
 }
 
@@ -445,7 +439,7 @@ int dasm_encode(Dst_DECL, void *buffer)
          break;
        }
        case DASM_REL_LG: p++; if (n >= 0) goto rel_pc;
-         b++; n = (int)(ptrdiff_t)D->globals[-n];
+         b++; n = (int)(ptrdiff_t)D->globals[-n-10];
          /* fallthrough */
        case DASM_REL_A: rel_a:
          n -= (unsigned int)(ptrdiff_t)(cp+4); goto wd; /* !x64 */
@@ -459,7 +453,7 @@ int dasm_encode(Dst_DECL, void *buffer)
        }
        case DASM_IMM_LG:
          p++;
-         if (n < 0) { dasma((ptrdiff_t)D->globals[-n]); break; }
+         if (n < 0) { dasma((ptrdiff_t)D->globals[-n-10]); break; }
          /* fallthrough */
        case DASM_IMM_PC: {
          int *pb = DASM_POS2PTR(D, n);
@@ -469,7 +463,7 @@ int dasm_encode(Dst_DECL, void *buffer)
        case DASM_LABEL_LG: {
          int idx = *p++;
          if (idx >= 10)
-           D->globals[idx] = (void *)(base + (*p == DASM_SETLABEL ? *b : n));
+           D->globals[idx-10] = (void *)(base + (*p == DASM_SETLABEL ? *b : n));
          break;
        }
        case DASM_LABEL_PC: case DASM_SETLABEL: break;