Fix statement-before-declaration warnings for the core code.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4906 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_debuginfo/dwarf.c b/coregrind/m_debuginfo/dwarf.c
index 54ed384..e2794c7 100644
--- a/coregrind/m_debuginfo/dwarf.c
+++ b/coregrind/m_debuginfo/dwarf.c
@@ -1630,8 +1630,8 @@
 
 static Short read_Short ( UChar* data )
 {
-   vg_assert(host_is_little_endian());
    Short r = 0;
+   vg_assert(host_is_little_endian());
    r = data[0] 
        | ( ((UInt)data[1]) << 8 );
    return r;
@@ -1639,8 +1639,8 @@
 
 static Int read_Int ( UChar* data )
 {
-   vg_assert(host_is_little_endian());
    Int r = 0;
+   vg_assert(host_is_little_endian());
    r = data[0] 
        | ( ((UInt)data[1]) << 8 ) 
        | ( ((UInt)data[2]) << 16 ) 
@@ -1650,8 +1650,8 @@
 
 static Long read_Long ( UChar* data )
 {
-   vg_assert(host_is_little_endian());
    Long r = 0;
+   vg_assert(host_is_little_endian());
    r = data[0] 
        | ( ((ULong)data[1]) << 8 ) 
        | ( ((ULong)data[2]) << 16 ) 
@@ -1665,8 +1665,8 @@
 
 static UShort read_UShort ( UChar* data )
 {
-   vg_assert(host_is_little_endian());
    UInt r = 0;
+   vg_assert(host_is_little_endian());
    r = data[0] 
        | ( ((UInt)data[1]) << 8 );
    return r;
@@ -1674,8 +1674,8 @@
 
 static UInt read_UInt ( UChar* data )
 {
-   vg_assert(host_is_little_endian());
    UInt r = 0;
+   vg_assert(host_is_little_endian());
    r = data[0] 
        | ( ((UInt)data[1]) << 8 ) 
        | ( ((UInt)data[2]) << 16 ) 
@@ -1685,8 +1685,8 @@
 
 static ULong read_ULong ( UChar* data )
 {
-   vg_assert(host_is_little_endian());
    ULong r = 0;
+   vg_assert(host_is_little_endian());
    r = data[0] 
        | ( ((ULong)data[1]) << 8 ) 
        | ( ((ULong)data[2]) << 16 ) 
@@ -2236,6 +2236,9 @@
       previously-seen CIE.
    */
    while (True) {
+      UChar* ciefde_start;
+      UInt   ciefde_len;
+      UInt   cie_pointer;
 
       /* Are we done? */
       if (data == ehframe + ehframe_sz)
@@ -2250,12 +2253,12 @@
       /* Ok, we must be looking at the start of a new CIE or FDE.
          Figure out which it is. */
 
-      UChar* ciefde_start = data;
+      ciefde_start = data;
       if (VG_(clo_trace_cfi)) 
          VG_(printf)("\ncie/fde.start   = %p (ehframe + 0x%x)\n", 
                      ciefde_start, ciefde_start - ehframe);
 
-      UInt ciefde_len = read_UInt(data); data += sizeof(UInt);
+      ciefde_len = read_UInt(data); data += sizeof(UInt);
       if (VG_(clo_trace_cfi)) 
          VG_(printf)("cie/fde.length  = %d\n", ciefde_len);
 
@@ -2269,7 +2272,7 @@
          goto bad;
       }
 
-      UInt cie_pointer = read_UInt(data); 
+      cie_pointer = read_UInt(data); 
       data += sizeof(UInt); /* XXX see XXX below */
       if (VG_(clo_trace_cfi)) 
          VG_(printf)("cie.pointer     = %d\n", cie_pointer);
@@ -2277,7 +2280,9 @@
       /* If cie_pointer is zero, we've got a CIE; else it's an FDE. */
       if (cie_pointer == 0) {
 
-         Int this_CIE;
+         Int    this_CIE;
+         UChar  cie_version;
+         UChar* cie_augmentation;
 
          /* --------- CIE --------- */
 	 if (VG_(clo_trace_cfi)) 
@@ -2299,7 +2304,7 @@
             later when looking at an FDE. */
          the_CIEs[this_CIE].offset = ciefde_start - ehframe;
 
-         UChar cie_version = read_UChar(data); data += sizeof(UChar);
+         cie_version = read_UChar(data); data += sizeof(UChar);
          if (VG_(clo_trace_cfi))
             VG_(printf)("cie.version     = %d\n", (Int)cie_version);
          if (cie_version != 1) {
@@ -2307,7 +2312,7 @@
             goto bad;
          }
 
-         UChar* cie_augmentation = data;
+         cie_augmentation = data;
          data += 1 + VG_(strlen)(cie_augmentation);
          if (VG_(clo_trace_cfi)) 
             VG_(printf)("cie.augment     = \"%s\"\n", cie_augmentation);
@@ -2408,9 +2413,13 @@
       } else {
 
          UnwindContext ctx, restore_ctx;
-         Int  cie;
-         UInt look_for;
-         Bool ok;
+         Int    cie;
+         UInt   look_for;
+         Bool   ok;
+         Addr   fde_initloc;
+         UWord  fde_arange;
+         UChar* fde_instrs;
+         Int    fde_ilen;
 
          /* --------- FDE --------- */
 
@@ -2433,14 +2442,14 @@
             goto bad;
 	 }
 
-         Addr fde_initloc 
+         fde_initloc 
             = read_encoded_Addr(data, the_CIEs[cie].address_encoding,
                                 &nbytes, ehframe, ehframe_addr);
          data += nbytes;
          if (VG_(clo_trace_cfi)) 
             VG_(printf)("fde.initloc     = %p\n", (void*)fde_initloc);
 
-         UWord fde_arange 
+         fde_arange 
             = read_encoded_Addr(data, the_CIEs[cie].address_encoding & 0xf,
                                 &nbytes, ehframe, ehframe_addr);
          data += nbytes;
@@ -2452,8 +2461,8 @@
             data += nbytes;
          }
 
-         UChar* fde_instrs = data;
-         Int    fde_ilen   = ciefde_start + ciefde_len + sizeof(UInt) - data;
+         fde_instrs = data;
+         fde_ilen   = ciefde_start + ciefde_len + sizeof(UInt) - data;
          if (VG_(clo_trace_cfi)) {
             VG_(printf)("fde.instrs      = %p\n", fde_instrs);
             VG_(printf)("fde.ilen        = %d\n", (Int)fde_ilen);
diff --git a/coregrind/m_debuginfo/symtab.c b/coregrind/m_debuginfo/symtab.c
index e9b804a..8ee1c4d 100644
--- a/coregrind/m_debuginfo/symtab.c
+++ b/coregrind/m_debuginfo/symtab.c
@@ -498,6 +498,8 @@
 void ML_(addCfiSI) ( SegInfo* si, CfiSI* cfisi )
 {
    static const Bool debug = False;
+   UInt   new_sz, i;
+   CfiSI* new_tab;
 
    if (debug) {
       VG_(printf)("adding CfiSI: ");
@@ -506,9 +508,6 @@
 
    vg_assert(cfisi->len > 0 && cfisi->len < 2000000);
 
-   UInt   new_sz, i;
-   CfiSI* new_tab;
-
    /* Rule out ones which are completely outside the segment.  These
       probably indicate some kind of bug, but for the meantime ignore
       them. */
diff --git a/coregrind/m_libcfile.c b/coregrind/m_libcfile.c
index 2da5753..f86f2e2 100644
--- a/coregrind/m_libcfile.c
+++ b/coregrind/m_libcfile.c
@@ -212,8 +212,7 @@
    OffT off = VG_(lseek)( fd, (OffT)offset, VKI_SEEK_SET);
    if (off != 0)
       return VG_(mk_SysRes_Error)( VKI_EINVAL );
-   SysRes res = VG_(do_syscall3)(__NR_read, fd, (UWord)buf, count );
-   return res;
+   return VG_(do_syscall3)(__NR_read, fd, (UWord)buf, count );
 }
 
 /* Create and open (-rw------) a tmp file name incorporating said arg.
diff --git a/coregrind/m_main.c b/coregrind/m_main.c
index 26e8701..a76bc47 100644
--- a/coregrind/m_main.c
+++ b/coregrind/m_main.c
@@ -114,7 +114,7 @@
 
    HChar** cpp;
    HChar** ret;
-   HChar*  preload_tool_path;;
+   HChar*  preload_tool_path;
    Int     envc, i;
 
    /* Alloc space for the vgpreload_core.so path and vgpreload_<tool>.so
@@ -417,6 +417,7 @@
      Addr  anon_start  = clstack_start;
      Addr  resvn_start = anon_start - resvn_size;
      SizeT inner_HACK  = 0;
+     Bool  ok;
 
      vg_assert(VG_IS_PAGE_ALIGNED(anon_size));
      vg_assert(VG_IS_PAGE_ALIGNED(resvn_size));
@@ -434,12 +435,12 @@
 
      /* Create a shrinkable reservation followed by an anonymous
         segment.  Together these constitute a growdown stack. */
-     Bool ok = VG_(am_create_reservation)(
-                  resvn_start,
-                  resvn_size -inner_HACK,
-                  SmUpper, 
-                  anon_size +inner_HACK
-               );
+     ok = VG_(am_create_reservation)(
+             resvn_start,
+             resvn_size -inner_HACK,
+             SmUpper, 
+             anon_size +inner_HACK
+          );
      vg_assert(ok);
      /* allocate a stack - mmap enough space for the stack */
      res = VG_(am_mmap_anon_fixed_client)(
@@ -1468,8 +1469,10 @@
    results of a run which encompasses multiple processes. */
 static void print_preamble(Bool logging_to_fd, const char* toolname)
 {
-   Int i;
-   
+   HChar* xpre  = VG_(clo_xml) ? "  <line>" : "";
+   HChar* xpost = VG_(clo_xml) ? "</line>" : "";
+   Int    i;
+
    if (VG_(clo_xml)) {
       VG_(message)(Vg_UserMsg, "<?xml version=\"1.0\"?>");
       VG_(message)(Vg_UserMsg, "");
@@ -1479,9 +1482,6 @@
       VG_(message)(Vg_UserMsg, "");
    }
 
-   HChar* xpre  = VG_(clo_xml) ? "  <line>" : "";
-   HChar* xpost = VG_(clo_xml) ? "</line>" : "";
-
    if (VG_(clo_verbosity > 0)) {
 
       if (VG_(clo_xml))
diff --git a/coregrind/m_mallocfree.c b/coregrind/m_mallocfree.c
index 47c4873..7511392 100644
--- a/coregrind/m_mallocfree.c
+++ b/coregrind/m_mallocfree.c
@@ -607,8 +607,8 @@
 static
 UInt pszB_to_listNo ( SizeT pszB )
 {
-   vg_assert(0 == pszB % VG_MIN_MALLOC_SZB);
    SizeT n = pszB / VG_MIN_MALLOC_SZB;
+   vg_assert(0 == pszB % VG_MIN_MALLOC_SZB);
 
    // The first 13 lists hold blocks of size VG_MIN_MALLOC_SZB * list_num.
    // The final 5 hold bigger blocks.
diff --git a/coregrind/m_oset.c b/coregrind/m_oset.c
index c3570ee..695d45d 100644
--- a/coregrind/m_oset.c
+++ b/coregrind/m_oset.c
@@ -433,11 +433,13 @@
 // avl_insert() which doesn't return a Bool.
 void VG_(OSet_Insert)(AvlTree* t, void* e)
 {
+   AvlNode* n;
+
    vg_assert(t);
 
    // Initialise.  Even though OSet_AllocNode zeroes these fields, we should
    // do it again in case a node is removed and then re-added to the tree.
-   AvlNode* n = node_of_elem(e);
+   n          = node_of_elem(e);
    n->left    = 0;
    n->right   = 0;
    n->balance = 0;
@@ -532,9 +534,9 @@
    Int  cmpres = cmp_key_root(t, n);
 
    if (cmpres < 0) {
+      AvlTree left_subtree;
       // Remove from the left subtree
       vg_assert(t->root->left);
-      AvlTree left_subtree;
       // Only need to set the used fields in the subtree.
       left_subtree.root   = t->root->left;
       left_subtree.cmp    = t->cmp;
diff --git a/coregrind/m_syswrap/syswrap-amd64-linux.c b/coregrind/m_syswrap/syswrap-amd64-linux.c
index c18cd42..e4804e1 100644
--- a/coregrind/m_syswrap/syswrap-amd64-linux.c
+++ b/coregrind/m_syswrap/syswrap-amd64-linux.c
@@ -107,6 +107,8 @@
 static void run_a_thread_NORETURN ( Word tidW )
 {
    ThreadId tid = (ThreadId)tidW;
+   VgSchedReturnCode src;
+   Int c;
 
    VG_(debugLog)(1, "syswrap-amd64-linux", 
                     "run_a_thread_NORETURN(tid=%lld): "
@@ -114,14 +116,14 @@
                        (ULong)tidW);
 
    /* Run the thread all the way through. */
-   VgSchedReturnCode src = ML_(thread_wrapper)(tid);  
+   src = ML_(thread_wrapper)(tid);  
 
    VG_(debugLog)(1, "syswrap-amd64-linux", 
                     "run_a_thread_NORETURN(tid=%lld): "
                        "ML_(thread_wrapper) done\n",
                        (ULong)tidW);
 
-   Int c = VG_(count_living_threads)();
+   c = VG_(count_living_threads)();
    vg_assert(c >= 1); /* stay sane */
 
    if (c == 1) {
@@ -138,13 +140,15 @@
 
    } else {
 
+      ThreadState *tst;
+
       VG_(debugLog)(1, "syswrap-amd64-linux", 
                        "run_a_thread_NORETURN(tid=%lld): "
                           "not last one standing\n",
                           (ULong)tidW);
 
       /* OK, thread is dead, but others still exist.  Just exit. */
-      ThreadState *tst = VG_(get_ThreadState)(tid);
+      tst = VG_(get_ThreadState)(tid);
 
       /* This releases the run lock */
       VG_(exit_thread)(tid);
@@ -220,10 +224,12 @@
 */
 void VG_(main_thread_wrapper_NORETURN)(ThreadId tid)
 {
+   Addr rsp;
+
    VG_(debugLog)(1, "syswrap-amd64-linux", 
                     "entering VG_(main_thread_wrapper_NORETURN)\n");
 
-   Addr rsp = allocstack(tid);
+   rsp = allocstack(tid);
 
    /* If we can't even allocate the first thread's stack, we're hosed.
       Give up. */
diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c
index d92b085..005197f 100644
--- a/coregrind/m_syswrap/syswrap-generic.c
+++ b/coregrind/m_syswrap/syswrap-generic.c
@@ -1095,9 +1095,9 @@
                                    UWord arg2, UWord arg3 )
 {
    SysRes r = res;
-   vg_assert(!res.isError); /* guaranteed by caller */
    Int fd1 = ((Int*)arg3)[0];
    Int fd2 = ((Int*)arg3)[1];
+   vg_assert(!res.isError); /* guaranteed by caller */
    POST_MEM_WRITE( arg3, 2*sizeof(int) );
    if (!ML_(fd_allowed)(fd1, "socketcall.socketpair", tid, True) ||
        !ML_(fd_allowed)(fd2, "socketcall.socketpair", tid, True)) {
@@ -4761,8 +4761,8 @@
       int poll(struct pollfd *ufds, unsigned int nfds, int timeout) 
    */
    UInt i;
-   *flags |= SfMayBlock;
    struct vki_pollfd* ufds = (struct vki_pollfd *)ARG1;
+   *flags |= SfMayBlock;
    PRINT("sys_poll ( %p, %d, %d )\n", ARG1,ARG2,ARG3);
    PRE_REG_READ3(long, "poll",
                  struct pollfd *, ufds, unsigned int, nfds, long, timeout);
diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c
index a9d81ba..3220635 100644
--- a/coregrind/m_syswrap/syswrap-linux.c
+++ b/coregrind/m_syswrap/syswrap-linux.c
@@ -54,14 +54,14 @@
 // scheduler-return-code.
 VgSchedReturnCode ML_(thread_wrapper)(Word /*ThreadId*/ tidW)
 {
-   VG_(debugLog)(1, "core_os", 
-                    "ML_(thread_wrapper)(tid=%lld): entry\n", 
-                    (ULong)tidW);
-
    VgSchedReturnCode ret;
    ThreadId     tid = (ThreadId)tidW;
    ThreadState* tst = VG_(get_ThreadState)(tid);
 
+   VG_(debugLog)(1, "core_os", 
+                    "ML_(thread_wrapper)(tid=%lld): entry\n", 
+                    (ULong)tidW);
+
    vg_assert(tst->status == VgTs_Init);
 
    /* make sure we get the CPU lock before doing anything significant */
diff --git a/coregrind/m_syswrap/syswrap-main.c b/coregrind/m_syswrap/syswrap-main.c
index 821164e..4439329 100644
--- a/coregrind/m_syswrap/syswrap-main.c
+++ b/coregrind/m_syswrap/syswrap-main.c
@@ -405,10 +405,10 @@
 void putSyscallStatusIntoGuestState ( /*IN*/ SyscallStatus*     canonical,
                                       /*OUT*/VexGuestArchState* gst_vanilla )
 {
-   vg_assert(canonical->what == SsSuccess 
-             || canonical->what == SsFailure);
 #if defined(VGP_x86_linux)
    VexGuestX86State* gst = (VexGuestX86State*)gst_vanilla;
+   vg_assert(canonical->what == SsSuccess 
+             || canonical->what == SsFailure);
    if (canonical->what == SsFailure) {
       /* This isn't exactly right, in that really a Failure with res
          not in the range 1 .. 4095 is unrepresentable in the
@@ -419,6 +419,8 @@
    }
 #elif defined(VGP_amd64_linux)
    VexGuestAMD64State* gst = (VexGuestAMD64State*)gst_vanilla;
+   vg_assert(canonical->what == SsSuccess 
+             || canonical->what == SsFailure);
    if (canonical->what == SsFailure) {
       /* This isn't exactly right, in that really a Failure with res
          not in the range 1 .. 4095 is unrepresentable in the
@@ -432,6 +434,9 @@
    VexGuestPPC32State* gst = (VexGuestPPC32State*)gst_vanilla;
    UInt old_cr = LibVEX_GuestPPC32_get_CR(gst);
 
+   vg_assert(canonical->what == SsSuccess 
+             || canonical->what == SsFailure);
+
    gst->guest_GPR3 = canonical->val;
 
    if (canonical->what == SsFailure) {