Cleanup: Remove 100+ compiler warnings.

This is a big cleanup that removes compiler warnings by performing
the following:

- Remove unused functions or variables.
- Change pointer cast to be alias safe using unions.
- Use __attribute__((unused)) on some local variable definitions
  when their usage depends on conditional defines that are not
  always true when compiling the same source several times.
- Fix a couple array indexing bugs.

There are still a few warnings from the JSON lexer, libjpeg and
the TCG helpers though, but the overall compilation is much cleaner.

BUG=NONE

Change-Id: Ic4483e6402b266ecfd7bca8c92a73d8fcf392a1f
diff --git a/Makefile.common b/Makefile.common
index b47d1e6..7d49b49 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -654,7 +654,7 @@
 endif
 
 BLOCK_CFLAGS += $(EMULATOR_COMMON_CFLAGS)
-BLOCK_CFLAGS += -DCONFIG_BDRV_WHITELIST=""
+BLOCK_CFLAGS += -DCONFIG_BDRV_WHITELIST=\"\"
 
 ##############################################################################
 ##############################################################################
diff --git a/android/avd/info.c b/android/avd/info.c
index c3660d7..8640a62 100644
--- a/android/avd/info.c
+++ b/android/avd/info.c
@@ -1020,7 +1020,7 @@
     }
 
     /* Set hw.useext4=yes, if the Ext4 file system is used. */
-    const char* p = avdInfo_getSystemInitImagePath(i);
+    char* p = avdInfo_getSystemInitImagePath(i);
     if (path_isExt4Image(p)) {
         hw->hw_useext4 = 1;
     }
diff --git a/android/console.c b/android/console.c
index ccd0426..a6b2239 100644
--- a/android/console.c
+++ b/android/console.c
@@ -2265,8 +2265,7 @@
     double  params[ NUM_GEO_PARAMS ];
     int     n_satellites = 1;
 
-    static  int     last_time = 0;
-    static  double  last_altitude = 0.;
+    static  int last_time = 0;
 
     if (!p)
         p = "";
@@ -2367,7 +2366,6 @@
         /* optional altitude + bogus diff */
         if (top_param >= GEO_ALT) {
             stralloc_add_format( s, ",%.1g,M,0.,M", params[GEO_ALT] );
-            last_altitude = params[GEO_ALT];
         } else {
             stralloc_add_str( s, ",,,," );
         }
diff --git a/android/hw-pipe-net.c b/android/hw-pipe-net.c
index c9db019..5da3918 100644
--- a/android/hw-pipe-net.c
+++ b/android/hw-pipe-net.c
@@ -482,7 +482,6 @@
 static void*
 openglesPipe_init( void* hwpipe, void* _looper, const char* args )
 {
-    char temp[32];
     NetPipe *pipe;
 
     if (!_opengles_init) {
diff --git a/android/hw-qemud.c b/android/hw-qemud.c
index df2d5ac..191ce01 100644
--- a/android/hw-qemud.c
+++ b/android/hw-qemud.c
@@ -48,8 +48,9 @@
  */
 #define QEMUD_SAVE_VERSION 2
 
+#ifndef min
 #define min(a, b) (((a) < (b)) ? (a) : (b))
-
+#endif
 
 /* define SUPPORT_LEGACY_QEMUD to 1 if you want to support
  * talking to a legacy qemud daemon. See docs/ANDROID-QEMUD.TXT
@@ -1542,8 +1543,6 @@
 qemud_multiplexer_init( QemudMultiplexer*  mult,
                         CharDriverState*   serial_cs )
 {
-    QemudClient*  control;
-
     /* initialize serial handler */
     qemud_serial_init( mult->serial,
                        serial_cs,
@@ -1551,13 +1550,13 @@
                        mult );
 
     /* setup listener for channel 0 */
-    control = qemud_client_alloc( 0,
-                                  NULL,
-                                  mult,
-                                  qemud_multiplexer_control_recv,
-                                  NULL, NULL, NULL,
-                                  mult->serial,
-                                  &mult->clients );
+    qemud_client_alloc(0,
+                       NULL,
+                       mult,
+                       qemud_multiplexer_control_recv,
+                       NULL, NULL, NULL,
+                       mult->serial,
+                       &mult->clients );
 }
 
 /* the global multiplexer state */
diff --git a/android/main-common.c b/android/main-common.c
index 07e7ab0..e2d1e5e 100644
--- a/android/main-common.c
+++ b/android/main-common.c
@@ -1048,8 +1048,6 @@
      */
     if (opts->avd == NULL && !android_build_out)
     {
-        char   dataDirIsSystem = 0;
-
         if (!opts->sysdir) {
             opts->sysdir = _getSdkImagePath("system.img");
             if (!opts->sysdir) {
@@ -1084,7 +1082,6 @@
         /* if no data directory is specified, use the system directory */
         if (!opts->datadir) {
             opts->datadir   = android_strdup(opts->sysdir);
-            dataDirIsSystem = 1;
             D("autoconfig: -datadir %s", opts->sysdir);
         }
 
diff --git a/android/main-emulator.c b/android/main-emulator.c
index 8ae9fa8..2fe1290 100644
--- a/android/main-emulator.c
+++ b/android/main-emulator.c
@@ -68,10 +68,6 @@
 static char* getSharedLibraryPath(const char* progName, const char* libName);
 static void  prependSharedLibraryPath(const char* prefix);
 
-#ifdef _WIN32
-static char* quotePath(const char* path);
-#endif
-
 /* The execv() definition in mingw is slightly bogus.
  * It takes a second argument of type 'const char* const*'
  * while POSIX mandates char** instead.
@@ -194,6 +190,7 @@
     return errno;
 }
 
+#ifndef _WIN32
 static int
 getHostOSBitness()
 {
@@ -217,6 +214,7 @@
   */
     return system("file -L \"$SHELL\" | grep -q \"x86[_-]64\"") == 0 ? 64 : 32;
 }
+#endif  // !_WIN32
 
 /* Find the target-specific emulator binary. This will be something
  * like  <programDir>/emulator-<targetArch>, where <programDir> is
@@ -411,19 +409,3 @@
     setenv("LD_LIBRARY_PATH", temp, 1);
 #endif
 }
-
-#ifdef _WIN32
-static char*
-quotePath(const char* path)
-{
-    int   len = strlen(path);
-    char* ret = malloc(len+3);
-
-    ret[0] = '"';
-    memcpy(ret+1, path, len);
-    ret[len+1] = '"';
-    ret[len+2] = '\0';
-
-    return ret;
-}
-#endif /* _WIN32 */
diff --git a/android/skin/image.h b/android/skin/image.h
index a94a372..b62ad29 100644
--- a/android/skin/image.h
+++ b/android/skin/image.h
@@ -30,9 +30,9 @@
 
 /* a descriptor for a given skin image */
 typedef struct SkinImageDesc {
-    const char*      path;      /* image file path (must be .png) */
-    AndroidRotation  rotation;  /* rotation */
-    int              blend;     /* blending, 0..256 value */
+    const char*   path;      /* image file path (must be .png) */
+    SkinRotation  rotation;  /* rotation */
+    int           blend;     /* blending, 0..256 value */
 } SkinImageDesc;
 
 #define  SKIN_BLEND_NONE   0
diff --git a/android/skin/surface.c b/android/skin/surface.c
index 4424bd8..6c52c86 100644
--- a/android/skin/surface.c
+++ b/android/skin/surface.c
@@ -539,12 +539,10 @@
     ARGB_DECL_ZERO();
 
     for ( ; dst < end; dst++ ) {
-        ARGB_DECL(s);
         ARGB_DECL(d);
         ARGB_DECL(v);
         uint32_t  alpha;
 
-        ARGB_READ(s,src);
         alpha = (src[0] >> 24);
         if (alpha > 0) {
             ARGB_READ(d,dst);
@@ -564,11 +562,9 @@
 
     for ( ; dst < end; dst++ ) {
         ARGB_DECL(s);
-        ARGB_DECL(d);
         ARGB_DECL(v);
         uint32_t  alpha;
 
-        ARGB_READ(d,dst);
         alpha = (dst[0] >> 24);
         if (alpha < 255) {
             ARGB_READ(s,src);
diff --git a/android/utils/dll.c b/android/utils/dll.c
index a46a462..0319fdb 100644
--- a/android/utils/dll.c
+++ b/android/utils/dll.c
@@ -35,31 +35,6 @@
 
 #include <windows.h>
 
-/* This function is used to revert all forward slashes (/) in a path
- * string into unquoted backwards one (\). This is necessary because
- * LoadLibrary() and AddDllDirectory() do not support forward slashes.
- *
- * Caller must free the result string
- */
-static char*
-reverse_slashes( const char* path )
-{
-    int   len    = strlen(path);
-    char* result = malloc(len+1);
-    int   nn;
-
-    for (nn = 0; nn < len; nn++) {
-        int ch = path[nn];
-        if (ch == '/') {
-            ch = '\\';
-        }
-        result[nn] = (char)ch;
-    }
-    result[nn] = '\0';
-
-    return result;
-}
-
 ADynamicLibrary*
 adynamicLibrary_open( const char*  libraryName,
                       char**       pError)
diff --git a/android/utils/eintr_wrapper.c b/android/utils/eintr_wrapper.c
index 2562e5c..b3c3696 100644
--- a/android/utils/eintr_wrapper.c
+++ b/android/utils/eintr_wrapper.c
@@ -27,4 +27,4 @@
             MAX_EINTR_LOOP_COUNT,
             call);
 }
-#endif  // !_WIN32
\ No newline at end of file
+#endif  // !_WIN32
diff --git a/android/utils/path.c b/android/utils/path.c
index 0847787..f1a146f 100644
--- a/android/utils/path.c
+++ b/android/utils/path.c
@@ -638,8 +638,6 @@
 {
     const char* sysPath = getenv("PATH");
     char        temp[PATH_MAX];
-    int         count;
-    int         slen;
     const char* p;
 
     /* If the file contains a directory separator, don't search */
@@ -664,9 +662,7 @@
      * Items are separated by DIR_SEP, and two successive separators
      * correspond to an empty item that will be ignored.
      * Also compute the required string storage length. */
-    count   = 0;
-    slen    = 0;
-    p       = sysPath;
+    p = sysPath;
 
     while (*p) {
         char* p2 = strchr(p, DIR_SEP);
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 546634d..2311988 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -547,7 +547,7 @@
      * some cases like ENOSPC for allocating a new refcount block)
      */
     if (ret < 0) {
-        int dummy;
+        int __attribute__((unused)) dummy;
         dummy = update_refcount(bs, offset, cluster_offset - offset, -addend);
     }
 
diff --git a/cpus.c b/cpus.c
index c4e8eea..d76f94a 100644
--- a/cpus.c
+++ b/cpus.c
@@ -28,6 +28,7 @@
 #include "exec/gdbstub.h"
 #include "sysemu/dma.h"
 #include "sysemu/kvm.h"
+#include "exec/exec-all.h"
 #include "exec/hax.h"
 
 #include "sysemu/cpus.h"
diff --git a/disas/mips.c b/disas/mips.c
index 2106b57..86c476b 100644
--- a/disas/mips.c
+++ b/disas/mips.c
@@ -572,6 +572,7 @@
 
 /* MIPS ISA defines, use instead of hardcoding ISA level.  */
 
+#ifndef ISA_MIPS1
 #define       ISA_UNKNOWN     0               /* Gas internal use.  */
 #define       ISA_MIPS1       (INSN_ISA1)
 #define       ISA_MIPS2       (ISA_MIPS1 | INSN_ISA2)
@@ -584,7 +585,7 @@
 
 #define       ISA_MIPS32R2    (ISA_MIPS32 | INSN_ISA32R2)
 #define       ISA_MIPS64R2    (ISA_MIPS64 | INSN_ISA32R2 | INSN_ISA64R2)
-
+#endif  // ISA_MIPS1
 
 /* CPU defines, use instead of hardcoding processor number. Keep this
    in sync with bfd/archures.c in order for machine selection to work.  */
@@ -608,13 +609,17 @@
 #define CPU_R8000	8000
 #define CPU_R10000	10000
 #define CPU_R12000	12000
+
 #define CPU_MIPS16	16
+#define CPU_SB1         12310201        /* octal 'SB', 01.  */
+
+#ifndef CPU_MIPS32
 #define CPU_MIPS32	32
 #define CPU_MIPS32R2	33
 #define CPU_MIPS5       5
 #define CPU_MIPS64      64
 #define CPU_MIPS64R2	65
-#define CPU_SB1         12310201        /* octal 'SB', 01.  */
+#endif  // !CPU_MIPS32
 
 /* Test for membership in an ISA including chip specific ISAs.  INSN
    is pointer to an element of the opcode table; ISA is the specified
diff --git a/exec.c b/exec.c
index b8b1b6f..ba53ad0 100644
--- a/exec.c
+++ b/exec.c
@@ -2575,12 +2575,11 @@
          * make sure that sufficient amount of memory is available in
          * advance.
          */
-        if (hax_enabled())
-        {
-            int ret;
-            ret = hax_populate_ram((uint64_t)new_block->host, size);
-            if (ret < 0)
-            {
+        if (hax_enabled()) {
+            int ret = hax_populate_ram(
+                    (uint64_t)(uintptr_t)new_block->host,
+                    size);
+            if (ret < 0) {
                 fprintf(stderr, "Hax failed to populate ram\n");
                 exit(-1);
             }
@@ -3269,7 +3268,7 @@
 
 /* physical memory access (slow version, mainly for debug) */
 #if defined(CONFIG_USER_ONLY)
-void cpu_physical_memory_rw(hwaddr addr, uint8_t *buf,
+void cpu_physical_memory_rw(hwaddr addr, void *buf,
                             int len, int is_write)
 {
     int l, flags;
@@ -3322,7 +3321,7 @@
     }
 }
 
-void cpu_physical_memory_rw(hwaddr addr, uint8_t *buf,
+void cpu_physical_memory_rw(hwaddr addr, void *buf,
                             int len, int is_write)
 {
     int l, io_index;
@@ -3330,6 +3329,7 @@
     uint32_t val;
     hwaddr page;
     unsigned long pd;
+    uint8_t* buf8 = (uint8_t*)buf;
     PhysPageDesc *p;
 
     while (len > 0) {
@@ -3354,17 +3354,17 @@
                    potential bugs */
                 if (l >= 4 && ((addr1 & 3) == 0)) {
                     /* 32 bit write access */
-                    val = ldl_p(buf);
+                    val = ldl_p(buf8);
                     io_mem_write[io_index][2](io_mem_opaque[io_index], addr1, val);
                     l = 4;
                 } else if (l >= 2 && ((addr1 & 1) == 0)) {
                     /* 16 bit write access */
-                    val = lduw_p(buf);
+                    val = lduw_p(buf8);
                     io_mem_write[io_index][1](io_mem_opaque[io_index], addr1, val);
                     l = 2;
                 } else {
                     /* 8 bit write access */
-                    val = ldub_p(buf);
+                    val = ldub_p(buf8);
                     io_mem_write[io_index][0](io_mem_opaque[io_index], addr1, val);
                     l = 1;
                 }
@@ -3373,7 +3373,7 @@
                 addr1 = (pd & TARGET_PAGE_MASK) + (addr & ~TARGET_PAGE_MASK);
                 /* RAM case */
                 ptr = qemu_get_ram_ptr(addr1);
-                memcpy(ptr, buf, l);
+                memcpy(ptr, buf8, l);
                 invalidate_and_set_dirty(addr1, l);
             }
         } else {
@@ -3387,40 +3387,41 @@
                 if (l >= 4 && ((addr1 & 3) == 0)) {
                     /* 32 bit read access */
                     val = io_mem_read[io_index][2](io_mem_opaque[io_index], addr1);
-                    stl_p(buf, val);
+                    stl_p(buf8, val);
                     l = 4;
                 } else if (l >= 2 && ((addr1 & 1) == 0)) {
                     /* 16 bit read access */
                     val = io_mem_read[io_index][1](io_mem_opaque[io_index], addr1);
-                    stw_p(buf, val);
+                    stw_p(buf8, val);
                     l = 2;
                 } else {
                     /* 8 bit read access */
                     val = io_mem_read[io_index][0](io_mem_opaque[io_index], addr1);
-                    stb_p(buf, val);
+                    stb_p(buf8, val);
                     l = 1;
                 }
             } else {
                 /* RAM case */
                 ptr = qemu_get_ram_ptr(pd & TARGET_PAGE_MASK) +
                     (addr & ~TARGET_PAGE_MASK);
-                memcpy(buf, ptr, l);
+                memcpy(buf8, ptr, l);
             }
         }
         len -= l;
-        buf += l;
+        buf8 += l;
         addr += l;
     }
 }
 
 /* used for ROM loading : can write in RAM and ROM */
 void cpu_physical_memory_write_rom(hwaddr addr,
-                                   const uint8_t *buf, int len)
+                                   const void *buf, int len)
 {
     int l;
     uint8_t *ptr;
     hwaddr page;
     unsigned long pd;
+    const uint8_t* buf8 = (const uint8_t*)buf;
     PhysPageDesc *p;
 
     while (len > 0) {
@@ -3444,11 +3445,11 @@
             addr1 = (pd & TARGET_PAGE_MASK) + (addr & ~TARGET_PAGE_MASK);
             /* ROM/RAM case */
             ptr = qemu_get_ram_ptr(addr1);
-            memcpy(ptr, buf, l);
+            memcpy(ptr, buf8, l);
             invalidate_and_set_dirty(addr1, l);
         }
         len -= l;
-        buf += l;
+        buf8 += l;
         addr += l;
     }
 }
@@ -3803,11 +3804,12 @@
 
 /* virtual memory access for debug (includes writing to ROM) */
 int cpu_memory_rw_debug(CPUState *env, target_ulong addr,
-                        uint8_t *buf, int len, int is_write)
+                        void *buf, int len, int is_write)
 {
     int l;
     hwaddr phys_addr;
     target_ulong page;
+    uint8_t* buf8 = (uint8_t*)buf;
 
     while (len > 0) {
         page = addr & TARGET_PAGE_MASK;
@@ -3821,12 +3823,12 @@
         phys_addr += (addr & ~TARGET_PAGE_MASK);
 #if !defined(CONFIG_USER_ONLY)
         if (is_write)
-            cpu_physical_memory_write_rom(phys_addr, buf, l);
+            cpu_physical_memory_write_rom(phys_addr, buf8, l);
         else
 #endif
-            cpu_physical_memory_rw(phys_addr, buf, l, is_write);
+            cpu_physical_memory_rw(phys_addr, buf8, l, is_write);
         len -= l;
-        buf += l;
+        buf8 += l;
         addr += l;
     }
     return 0;
diff --git a/gdbstub.c b/gdbstub.c
index 2678301..2173f5e 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -28,11 +28,13 @@
 #include <fcntl.h>
 
 #include "qemu.h"
+#include "hw/hw.h"
 #else
 #include "monitor/monitor.h"
 #include "sysemu/char.h"
 #include "sysemu/sysemu.h"
 #include "exec/gdbstub.h"
+#include "exec/exec-all.h"
 #endif
 
 #define MAX_PACKET_LENGTH 4096
@@ -1989,7 +1991,7 @@
             env->watchpoint_hit = NULL;
             return;
         }
-	tb_flush(env);
+        tb_flush(env);
         ret = GDB_SIGNAL_TRAP;
     } else {
         ret = GDB_SIGNAL_INT;
diff --git a/hw/android/android_mips.c b/hw/android/android_mips.c
index a7b7b20..c55ef76 100644
--- a/hw/android/android_mips.c
+++ b/hw/android/android_mips.c
@@ -16,6 +16,7 @@
 #include "sysemu/sysemu.h"
 #include "hw/mips/mips.h"
 #include "hw/android/goldfish/device.h"
+#include "hw/android/goldfish/pipe.h"
 #include "android/globals.h"
 #include "audio/audio.h"
 #include "sysemu/blockdev.h"
@@ -124,7 +125,8 @@
     if (initrd_size > 0)
         sprintf (kernel_cmd, "%s rd_start=0x" TARGET_FMT_lx " rd_size=%li",
                        kernel_cmdline,
-                       PHYS_TO_VIRT(initrd_offset), initrd_size);
+                       (hwaddr)PHYS_TO_VIRT(initrd_offset),
+                       (long int)initrd_size);
     else
         strcpy (kernel_cmd, kernel_cmdline);
 
diff --git a/hw/android/goldfish/mmc.c b/hw/android/goldfish/mmc.c
index abab65d..4d861bb 100644
--- a/hw/android/goldfish/mmc.c
+++ b/hw/android/goldfish/mmc.c
@@ -214,7 +214,6 @@
 
 static void goldfish_mmc_do_command(struct goldfish_mmc_state *s, uint32_t cmd, uint32_t arg)
 {
-    int result;
     int new_status = MMC_STAT_END_OF_CMD;
     int opcode = cmd & 63;
 
@@ -371,7 +370,7 @@
                 if (arg & 511) fprintf(stderr, "offset %d is not multiple of 512 when reading\n", arg);
                 arg /= s->block_length;
             }
-            result = goldfish_mmc_bdrv_read(s, arg, s->buffer_address, s->block_count);
+            goldfish_mmc_bdrv_read(s, arg, s->buffer_address, s->block_count);
             new_status |= MMC_STAT_END_OF_DATA;
             s->resp[0] = SET_R1_CURRENT_STATE(4) | R1_READY_FOR_DATA; // 2304
             break;
@@ -389,7 +388,7 @@
                 arg /= s->block_length;
             }
             // arg is byte offset
-            result = goldfish_mmc_bdrv_write(s, arg, s->buffer_address, s->block_count);
+            goldfish_mmc_bdrv_write(s, arg, s->buffer_address, s->block_count);
 //            bdrv_flush(s->bs);
             new_status |= MMC_STAT_END_OF_DATA;
             s->resp[0] = SET_R1_CURRENT_STATE(4) | R1_READY_FOR_DATA; // 2304
diff --git a/hw/android/goldfish/timer.c b/hw/android/goldfish/timer.c
index 6204866..6e9c55f 100644
--- a/hw/android/goldfish/timer.c
+++ b/hw/android/goldfish/timer.c
@@ -175,17 +175,12 @@
 static void goldfish_rtc_write(void *opaque, hwaddr offset, uint32_t value)
 {
     struct rtc_state *s = (struct rtc_state *)opaque;
-    int64_t alarm;
     switch(offset) {
         case 0x8:
             s->alarm_low = value;
-            alarm = s->alarm_low | (int64_t)s->alarm_high << 32;
-            //printf("next alarm at %lld, tps %lld\n", alarm, ticks_per_sec);
-            //qemu_mod_timer(s->timer, alarm);
             break;
         case 0xc:
             s->alarm_high = value;
-            //printf("alarm_high %d\n", s->alarm_high);
             break;
         case 0x10:
             goldfish_device_set_irq(&s->dev, 0, 0);
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 46f2e0b..846ddb1 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -192,7 +192,6 @@
     int is_linux = 0;
     uint64_t elf_entry;
     hwaddr entry;
-    int big_endian;
 
     /* Load the kernel.  */
     if (!info->kernel_filename) {
@@ -204,12 +203,6 @@
         info->nb_cpus = 1;
     env->boot_info = info;
 
-#ifdef TARGET_WORDS_BIGENDIAN
-    big_endian = 1;
-#else
-    big_endian = 0;
-#endif
-
     /* Assume that raw images are linux kernels, and ELF images are not.  */
     kernel_size = load_elf(info->kernel_filename, 0, &elf_entry, NULL, NULL);
     entry = elf_entry;
diff --git a/hw/bt/sdp.c b/hw/bt/sdp.c
index 56395b6..1531007 100644
--- a/hw/bt/sdp.c
+++ b/hw/bt/sdp.c
@@ -764,6 +764,9 @@
     }
 }
 
+#undef TRUE
+#undef FALSE
+
 #define LAST { .type = 0 }
 #define SERVICE(name, attrs)				\
     static struct sdp_def_service_s glue(glue(sdp_service_, name), _s) = { \
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index a7e6355..f11bd09 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -753,7 +753,7 @@
 
     /* generate bootsector to set up the initial register state */
     real_seg = real_addr >> 4;
-    seg[0] = seg[2] = seg[3] = seg[4] = seg[4] = real_seg;
+    seg[0] = seg[2] = seg[3] = seg[4] = seg[5] = real_seg;
     seg[1] = real_seg+0x20;	/* CS */
     memset(gpr, 0, sizeof gpr);
     gpr[4] = cmdline_addr-real_addr-16;	/* SP (-16 is paranoia) */
@@ -886,7 +886,7 @@
     ram_addr_t below_4g_mem_size, above_4g_mem_size = 0;
     int bios_size, isa_bios_size, oprom_area_size;
     PCIBus *pci_bus;
-    int piix3_devfn = -1;
+    int __attribute__((unused)) piix3_devfn = -1;
     CPUState *env;
     qemu_irq *cpu_irq;
     qemu_irq *i8259;
diff --git a/hw/net/smc91c111.c b/hw/net/smc91c111.c
index 30ea00f..755a296 100644
--- a/hw/net/smc91c111.c
+++ b/hw/net/smc91c111.c
@@ -237,7 +237,6 @@
     int i;
     int len;
     int control;
-    int add_crc;
     int packetnum;
     uint8_t *p;
 
@@ -276,8 +275,6 @@
             memcpy(p + len, &crc, 4);
             len += 4;
         }
-#else
-        add_crc = 0;
 #endif
         if (s->ctr & CTR_AUTO_RELEASE)
             /* Race?  */
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 18f73ce..aabc41a 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -721,6 +721,11 @@
     PCIIORegion *r;
     const pci_class_desc *desc;
 
+    typedef union {
+        uint16_t* ptr16;
+        void* ptr;
+    } u16;
+
     monitor_printf(mon, "  Bus %2d, device %3d, function %d:\n",
                    d->bus->bus_num, d->devfn >> 3, d->devfn & 7);
     class = le16_to_cpu(*((uint16_t *)(d->config + PCI_CLASS_DEVICE)));
@@ -733,9 +738,12 @@
     } else {
         monitor_printf(mon, "Class %04x", class);
     }
+    u16 vendor_id = { .ptr = d->config + PCI_VENDOR_ID };
+    u16 device_id = { .ptr = d->config + PCI_DEVICE_ID };
+
     monitor_printf(mon, ": PCI device %04x:%04x\n",
-           le16_to_cpu(*((uint16_t *)(d->config + PCI_VENDOR_ID))),
-           le16_to_cpu(*((uint16_t *)(d->config + PCI_DEVICE_ID))));
+           le16_to_cpu(*vendor_id.ptr16),
+           le16_to_cpu(*device_id.ptr16));
 
     if (d->config[PCI_INTERRUPT_PIN] != 0) {
         monitor_printf(mon, "      IRQ %d.\n",
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 482ad49..253ba19 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -351,7 +351,7 @@
     uint64_t nb_sectors;
     uint64_t lba;
     uint32_t len;
-    int cmdlen;
+    int __attribute__((unused)) cmdlen;
     int is_write;
     uint8_t command;
     uint8_t *outbuf;
diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c
index 46d0912..dcb7a07 100644
--- a/hw/usb/dev-hub.c
+++ b/hw/usb/dev-hub.c
@@ -366,11 +366,9 @@
         {
             unsigned int n = index - 1;
             USBHubPort *port;
-            USBDevice *dev;
             if (n >= s->nb_ports)
                 goto fail;
             port = &s->ports[n];
-            dev = port->port.dev;
             switch(value) {
             case PORT_ENABLE:
                 port->wPortStatus &= ~PORT_STAT_ENABLE;
diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
index 8328f1b..53754ac 100644
--- a/hw/usb/hcd-ohci.c
+++ b/hw/usb/hcd-ohci.c
@@ -604,7 +604,7 @@
 {
     int dir;
     size_t len = 0;
-    const char *str = NULL;
+    const char * __attribute__((unused)) str = NULL;
     int pid;
     int ret;
     int i;
@@ -839,7 +839,7 @@
 {
     int dir;
     size_t len = 0;
-    const char *str = NULL;
+    const char * __attribute__((unused)) str = NULL;
     int pid;
     int ret;
     int i;
diff --git a/hw/usb/usb-linux.c b/hw/usb/usb-linux.c
index 05b9b27..644bede 100644
--- a/hw/usb/usb-linux.c
+++ b/hw/usb/usb-linux.c
@@ -307,7 +307,7 @@
 static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
 {
     int dev_descr_len, config_descr_len;
-    int interface, nb_interfaces, nb_configurations;
+    int interface, nb_interfaces;
     int ret, i;
 
     if (configuration == 0) /* address state - ignore */
@@ -319,7 +319,6 @@
     dev_descr_len = dev->descr[0];
     if (dev_descr_len > dev->descr_len)
         goto fail;
-    nb_configurations = dev->descr[17];
 
     i += dev_descr_len;
     while (i < dev->descr_len) {
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index e4dea7b..a922ebb 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -1036,7 +1036,7 @@
 #endif
 
 int cpu_memory_rw_debug(CPUState *env, target_ulong addr,
-                        uint8_t *buf, int len, int is_write);
+                        void *buf, int len, int is_write);
 
 void cpu_inject_x86_mce(CPUState *cenv, int bank, uint64_t status,
                         uint64_t mcg_status, uint64_t addr, uint64_t misc);
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 251a718..0e58222 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -29,8 +29,8 @@
 typedef uint32_t CPUReadMemoryFunc(void *opaque, hwaddr addr);
 
 void cpu_register_physical_memory_log(hwaddr start_addr,
-                                         ram_addr_t size,
-                                         ram_addr_t phys_offset,
+                                      ram_addr_t size,
+                                      ram_addr_t phys_offset,
                                       ram_addr_t region_offset,
                                       bool log_dirty);
 
@@ -70,17 +70,17 @@
                            void *opaque);
 void cpu_unregister_io_memory(int table_address);
 
-void cpu_physical_memory_rw(hwaddr addr, uint8_t *buf,
+void cpu_physical_memory_rw(hwaddr addr, void *buf,
                             int len, int is_write);
 static inline void cpu_physical_memory_read(hwaddr addr,
-                                            uint8_t *buf, int len)
+                                            void *buf, int len)
 {
     cpu_physical_memory_rw(addr, buf, len, 0);
 }
 static inline void cpu_physical_memory_write(hwaddr addr,
-                                             const uint8_t *buf, int len)
+                                             const void *buf, int len)
 {
-    cpu_physical_memory_rw(addr, (uint8_t *)buf, len, 1);
+    cpu_physical_memory_rw(addr, (void*)buf, len, 1);
 }
 void *cpu_physical_memory_map(hwaddr addr,
                               hwaddr *plen,
@@ -102,7 +102,7 @@
 void stq_phys(hwaddr addr, uint64_t val);
 
 void cpu_physical_memory_write_rom(hwaddr addr,
-                                   const uint8_t *buf, int len);
+                                   const void *buf, int len);
 
 #define IO_MEM_SHIFT       3
 
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index d6d8110..3fe88fe 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -148,4 +148,9 @@
 #define ffs __builtin_ffs
 #endif
 
+/* in osdep.c */
+#ifdef _WIN32
+int asprintf(char**, const char*, ...);
+#endif
+
 #endif
diff --git a/kvm-all.c b/kvm-all.c
index e510d39..bb89229 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -228,8 +228,8 @@
 
     if (mem == NULL)  {
             fprintf(stderr, "BUG: %s: invalid parameters " TARGET_FMT_plx "-"
-                    TARGET_FMT_plx "\n", __func__, phys_addr,
-                    phys_addr + size - 1);
+                    TARGET_FMT_plx "\n", __func__, (hwaddr)phys_addr,
+                    (hwaddr)(phys_addr + size - 1));
             return -EINVAL;
     }
 
diff --git a/monitor.c b/monitor.c
index 6b32668..e48a559 100644
--- a/monitor.c
+++ b/monitor.c
@@ -637,7 +637,7 @@
                         hwaddr addr, int is_physical)
 {
     CPUState *env;
-    int nb_per_line, l, line_size, i, max_digits, len;
+    int l, line_size, i, max_digits, len;
     uint8_t buf[16];
     uint64_t v;
 
@@ -676,7 +676,6 @@
         line_size = 8;
     else
         line_size = 16;
-    nb_per_line = line_size / wsize;
     max_digits = 0;
 
     switch(format) {
diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c
index 56e7a66..dd04142 100644
--- a/qobject/json-lexer.c
+++ b/qobject/json-lexer.c
@@ -103,7 +103,8 @@
         ['u'] = IN_DQ_UCODE0,
     },
     [IN_DQ_STRING] = {
-        [1 ... 0xFF] = IN_DQ_STRING,
+        [1 ... 0xBF] = IN_DQ_STRING,
+        [0xC2 ... 0xF4] = IN_DQ_STRING,
         ['\\'] = IN_DQ_STRING_ESCAPE,
         ['"'] = JSON_STRING,
     },
@@ -142,7 +143,8 @@
         ['u'] = IN_SQ_UCODE0,
     },
     [IN_SQ_STRING] = {
-        [1 ... 0xFF] = IN_SQ_STRING,
+        [1 ... 0xBF] = IN_SQ_STRING,
+        [0xC2 ... 0xF4] = IN_SQ_STRING,
         ['\\'] = IN_SQ_STRING_ESCAPE,
         ['\''] = JSON_STRING,
     },
diff --git a/slirp-android/tftp.c b/slirp-android/tftp.c
index 307610b..dfb8db3 100644
--- a/slirp-android/tftp.c
+++ b/slirp-android/tftp.c
@@ -178,7 +178,6 @@
   SockAddress saddr, daddr;
   struct mbuf *m;
   struct tftp_t *tp;
-  int nobytes;
 
   m = m_get();
 
@@ -204,8 +203,6 @@
                           spt->client_ip,
                           spt->client_port );
 
-  nobytes = 2;
-
   m->m_len = sizeof(struct tftp_t) - 514 + 3 + strlen(msg) -
         sizeof(struct ip) - sizeof(struct udphdr);
 
@@ -378,10 +375,9 @@
 
 	  if (tsize == 0 && tftp_prefix) {
 	      char buffer[1024];
-	      int len;
 
-	      len = snprintf(buffer, sizeof(buffer), "%s/%s",
-			     tftp_prefix, spt->filename);
+	      snprintf(buffer, sizeof(buffer), "%s/%s",
+                       tftp_prefix, spt->filename);
 
 	      if (stat(buffer, &stat_p) == 0)
 		  tsize = stat_p.st_size;
diff --git a/target-arm/helper.c b/target-arm/helper.c
index cc6afa0..d4d7612 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -290,10 +290,10 @@
     /* On ARMv7-M the CPSR_I is the value of the PRIMASK register, and is
        clear at reset.  Initial SP and PC are loaded from ROM.  */
     if (IS_M(env)) {
-        uint32_t pc;
-        uint8_t *rom;
         env->uncached_cpsr &= ~CPSR_I;
 #ifndef CONFIG_ANDROID  /* No hw/loader.h and no ROM support for now on Android */
+        uint32_t pc;
+        uint8_t *rom;
         rom = rom_ptr(0);
         if (rom) {
             /* We should really use ldl_phys here, in case the guest
diff --git a/target-i386/hax-all.c b/target-i386/hax-all.c
index 339fd55..861d194 100644
--- a/target-i386/hax-all.c
+++ b/target-i386/hax-all.c
@@ -16,6 +16,7 @@
  * Some portion of code from KVM is used in this file.
  */
 
+#include "hw/hw.h"
 #include "target-i386/hax-i386.h"
 
 #define HAX_EMUL_ONE    0x1
diff --git a/target-i386/hax-windows.c b/target-i386/hax-windows.c
index a2ace34..bccbd0a 100644
--- a/target-i386/hax-windows.c
+++ b/target-i386/hax-windows.c
@@ -50,11 +50,13 @@
 hax_fd hax_mod_open(void)
 {
     int ret;
-    hax_fd fd;
+    hax_fd fd = INVALID_HANDLE_VALUE;
 
     ret = hax_open_device(&fd);
-    if (ret != 0)
+    if (ret != 0) {
         dprint("Open HAX device failed\n");
+        return INVALID_HANDLE_VALUE;
+    }
 
     return fd;
 }
@@ -115,7 +117,7 @@
 
     info.pa_start = start_addr;
     info.size = size;
-    info.va = (uint64_t)qemu_get_ram_ptr(phys_offset);
+    info.va = (uint64_t)(uintptr_t)qemu_get_ram_ptr(phys_offset);
     info.flags = (flags & IO_MEM_ROM) ? 1 : 0;
 
     hDeviceVM = hax_global.vm->fd;
@@ -373,8 +375,8 @@
         ret = -EINVAL;
         return ret;
     }
-    vcpu->tunnel = (struct hax_tunnel *)(info.va);
-    vcpu->iobuf = (unsigned char *)(info.io_va);
+    vcpu->tunnel = (struct hax_tunnel *)(uintptr_t)(info.va);
+    vcpu->iobuf = (unsigned char *)(uintptr_t)(info.io_va);
     return 0;
 }
 
diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c
index 45e1005..a217dfc 100644
--- a/target-i386/op_helper.c
+++ b/target-i386/op_helper.c
@@ -282,7 +282,7 @@
     int tss_limit, tss_limit_max, type, old_tss_limit_max, old_type, v1, v2, i;
     target_ulong tss_base;
     uint32_t new_regs[8], new_segs[6];
-    uint32_t new_eflags, new_eip, new_cr3, new_ldt, new_trap;
+    uint32_t new_eflags, new_eip, new_cr3, new_ldt;
     uint32_t old_eflags, eflags_mask;
     SegmentCache *dt;
     int index;
@@ -336,7 +336,7 @@
         for(i = 0; i < 6; i++)
             new_segs[i] = lduw_kernel(tss_base + (0x48 + i * 4));
         new_ldt = lduw_kernel(tss_base + 0x60);
-        new_trap = ldl_kernel(tss_base + 0x64);
+        ldl_kernel(tss_base + 0x64);
     } else {
         /* 16 bit */
         new_cr3 = 0;
@@ -349,7 +349,6 @@
         new_ldt = lduw_kernel(tss_base + 0x2a);
         new_segs[R_FS] = 0;
         new_segs[R_GS] = 0;
-        new_trap = 0;
     }
 
     /* NOTE: we must avoid memory exceptions during the task switch,
@@ -5444,15 +5443,13 @@
 void helper_enter_mmx(void)
 {
     env->fpstt = 0;
-    *(uint32_t *)(env->fptags) = 0;
-    *(uint32_t *)(env->fptags + 4) = 0;
+    memset(env->fptags, 0, sizeof(env->fptags));
 }
 
 void helper_emms(void)
 {
     /* set to empty state */
-    *(uint32_t *)(env->fptags) = 0x01010101;
-    *(uint32_t *)(env->fptags + 4) = 0x01010101;
+    memset(env->fptags, 1, sizeof(env->fptags));
 }
 
 /* XXX: suppress */
diff --git a/target-i386/translate.c b/target-i386/translate.c
index 2b6617e..c1c3afe 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -4044,7 +4044,10 @@
     int shift, ot;
     int modrm, reg, rm, mod, reg_addr, op, opreg, offset_addr, val;
     target_ulong next_eip, tval;
-    int rex_w, rex_r;
+#ifdef TARGET_X86_64
+    int rex_w = -1;
+#endif
+    int rex_r;
 
     if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP)))
         tcg_gen_debug_insn_start(pc_start);
@@ -4053,7 +4056,6 @@
     aflag = s->code32;
     dflag = s->code32;
     s->override = -1;
-    rex_w = -1;
     rex_r = 0;
 #ifdef TARGET_X86_64
     s->rex_x = 0;
@@ -7606,7 +7608,7 @@
     target_ulong pc_ptr;
     uint16_t *gen_opc_end;
     CPUBreakpoint *bp;
-    int j, lj, cflags;
+    int j, lj;
     uint64_t flags;
     target_ulong pc_start;
     target_ulong cs_base;
@@ -7617,7 +7619,6 @@
     pc_start = tb->pc;
     cs_base = tb->cs_base;
     flags = tb->flags;
-    cflags = tb->cflags;
 
     dc->pe = (flags >> HF_PE_SHIFT) & 1;
     dc->code32 = (flags >> HF_CS32_SHIFT) & 1;
diff --git a/target-mips/helper.c b/target-mips/helper.c
index fe97355..7de79d1 100644
--- a/target-mips/helper.c
+++ b/target-mips/helper.c
@@ -340,6 +340,9 @@
     return ldl_phys(linux_pte_info.pgd_current_p);
 }
 
+// in target-mips/op_helper.c
+extern void r4k_helper_ptw_tlbrefill(CPUState*);
+
 static inline int cpu_mips_tlb_refill(CPUState *env, target_ulong address, int rw ,
                                       int mmu_idx, int is_softmmu)
 {
@@ -347,9 +350,8 @@
     target_ulong saved_badvaddr,saved_entryhi,saved_context;
 
     target_ulong pgd_addr,pt_addr,index;
-    target_ulong fault_addr,ptw_phys;
+    target_ulong fault_addr, ptw_phys;
     target_ulong elo_even,elo_odd;
-    uint32_t page_valid;
     int ret;
 
     saved_badvaddr = env->CP0_BadVAddr;
@@ -366,7 +368,6 @@
     env->hflags = MIPS_HFLAG_KM;
 
     fault_addr = env->CP0_BadVAddr;
-    page_valid = 0;
 
     pgd_addr = cpu_mips_get_pgd(env);
     if (unlikely(!pgd_addr))
@@ -442,7 +443,7 @@
     hwaddr physical;
     int prot;
 #endif
-    int exception = 0, error_code = 0;
+    //int exception = 0, error_code = 0;
     int access_type;
     int ret = 0;
 
diff --git a/target-mips/op_helper.c b/target-mips/op_helper.c
index ce31a48..310821c 100644
--- a/target-mips/op_helper.c
+++ b/target-mips/op_helper.c
@@ -283,7 +283,7 @@
 
     lladdr = cpu_mips_translate_address(env, address, rw);
 
-    if (lladdr == -1LL) {
+    if (lladdr == (hwaddr)-1LL) {
         cpu_loop_exit();
     } else {
         return lladdr;
@@ -1656,8 +1656,6 @@
     target_ulong VPN;
     uint8_t ASID;
     int i;
-    target_ulong addr;
-    target_ulong end;
 
     ASID = env->CP0_EntryHi & 0xFF;
     for (i = 0; i < env->tlb->nb_tlb; i++) {
diff --git a/target-mips/translate.c b/target-mips/translate.c
index 9d20fbf..75f6ca7 100755
--- a/target-mips/translate.c
+++ b/target-mips/translate.c
@@ -980,7 +980,7 @@
 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
                       int base, int16_t offset)
 {
-    const char *opn = "ldst";
+    const char * __attribute__((unused)) opn = "ldst";
     TCGv t0 = tcg_temp_new();
     TCGv t1 = tcg_temp_new();
 
@@ -1137,7 +1137,7 @@
 static void gen_st_cond (DisasContext *ctx, uint32_t opc, int rt,
                          int base, int16_t offset)
 {
-    const char *opn = "st_cond";
+    const char * __attribute__((unused)) opn = "st_cond";
     TCGv t0, t1;
 
     t0 = tcg_temp_local_new();
@@ -1178,7 +1178,7 @@
 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
                           int base, int16_t offset)
 {
-    const char *opn = "flt_ldst";
+    const char * __attribute__((unused)) opn = "flt_ldst";
     TCGv t0 = tcg_temp_new();
 
     if (base == 0) {
@@ -1251,7 +1251,7 @@
                            int rt, int rs, int16_t imm)
 {
     target_ulong uimm = (target_long)imm; /* Sign extend to 32/64 bits */
-    const char *opn = "imm arith";
+    const char * __attribute__((unused)) opn = "imm arith";
 
     if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
         /* If no destination, treat it as a NOP.
@@ -1337,7 +1337,7 @@
 static void gen_logic_imm (CPUState *env, uint32_t opc, int rt, int rs, int16_t imm)
 {
     target_ulong uimm;
-    const char *opn = "imm logic";
+    const char * __attribute__((unused)) opn = "imm logic";
 
     if (rt == 0) {
         /* If no destination, treat it as a NOP. */
@@ -1379,7 +1379,7 @@
 static void gen_slt_imm (CPUState *env, uint32_t opc, int rt, int rs, int16_t imm)
 {
     target_ulong uimm = (target_long)imm; /* Sign extend to 32/64 bits */
-    const char *opn = "imm arith";
+    const char * __attribute__((unused)) opn = "imm arith";
     TCGv t0;
 
     if (rt == 0) {
@@ -1408,7 +1408,7 @@
                           int rt, int rs, int16_t imm)
 {
     target_ulong uimm = ((uint16_t)imm) & 0x1f;
-    const char *opn = "imm shift";
+    const char* __attribute__((unused)) opn = "imm shift";
     TCGv t0;
 
     if (rt == 0) {
@@ -1546,7 +1546,7 @@
 static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
                        int rd, int rs, int rt)
 {
-    const char *opn = "arith";
+    const char* __attribute__((unused)) opn = "arith";
 
     if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
        && opc != OPC_DADD && opc != OPC_DSUB) {
@@ -1726,7 +1726,7 @@
 /* Conditional move */
 static void gen_cond_move (CPUState *env, uint32_t opc, int rd, int rs, int rt)
 {
-    const char *opn = "cond move";
+    const char* __attribute__((unused)) opn = "cond move";
     int l1;
 
     if (rd == 0) {
@@ -1763,7 +1763,7 @@
 /* Logic */
 static void gen_logic (CPUState *env, uint32_t opc, int rd, int rs, int rt)
 {
-    const char *opn = "logic";
+    const char* __attribute__((unused)) opn = "logic";
 
     if (rd == 0) {
         /* If no destination, treat it as a NOP. */
@@ -1823,7 +1823,7 @@
 /* Set on lower than */
 static void gen_slt (CPUState *env, uint32_t opc, int rd, int rs, int rt)
 {
-    const char *opn = "slt";
+    const char* __attribute__((unused)) opn = "slt";
     TCGv t0, t1;
 
     if (rd == 0) {
@@ -1855,7 +1855,7 @@
 static void gen_shift (CPUState *env, DisasContext *ctx, uint32_t opc,
                        int rd, int rs, int rt)
 {
-    const char *opn = "shifts";
+    const char* __attribute__((unused)) opn = "shifts";
     TCGv t0, t1;
 
     if (rd == 0) {
@@ -1965,7 +1965,7 @@
 /* Arithmetic on HI/LO registers */
 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
 {
-    const char *opn = "hilo";
+    const char* __attribute__((unused)) opn = "hilo";
 
     if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
         /* Treat as NOP. */
@@ -2002,7 +2002,7 @@
 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
                         int rs, int rt)
 {
-    const char *opn = "mul/div";
+    const char* __attribute__((unused)) opn = "mul/div";
     TCGv t0, t1;
 
     switch (opc) {
@@ -2237,7 +2237,7 @@
 static void gen_mul_vr54xx (DisasContext *ctx, uint32_t opc,
                             int rd, int rs, int rt)
 {
-    const char *opn = "mul vr54xx";
+    const char* __attribute__((unused)) opn = "mul vr54xx";
     TCGv t0 = tcg_temp_new();
     TCGv t1 = tcg_temp_new();
 
@@ -2317,7 +2317,7 @@
 static void gen_cl (DisasContext *ctx, uint32_t opc,
                     int rd, int rs)
 {
-    const char *opn = "CLx";
+    const char* __attribute__((unused)) opn = "CLx";
     TCGv t0;
 
     if (rd == 0) {
@@ -2897,7 +2897,7 @@
 
 static void gen_mfc0 (CPUState *env, DisasContext *ctx, TCGv arg, int reg, int sel)
 {
-    const char *rn = "invalid";
+    const char * __attribute__((unused)) rn = "invalid";
 
     if (sel != 0)
         check_insn(env, ctx, ISA_MIPS32);
@@ -3474,7 +3474,7 @@
 
 static void gen_mtc0 (CPUState *env, DisasContext *ctx, TCGv arg, int reg, int sel)
 {
-    const char *rn = "invalid";
+    const char * __attribute__((unused)) rn = "invalid";
 
     if (sel != 0)
         check_insn(env, ctx, ISA_MIPS32);
@@ -5551,7 +5551,7 @@
 
 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
 {
-    const char *opn = "ldst";
+    const char* __attribute__((unused)) opn = "ldst";
 
     switch (opc) {
     case OPC_MFC0:
@@ -5676,7 +5676,7 @@
                                  int32_t cc, int32_t offset)
 {
     target_ulong btarget;
-    const char *opn = "cp1 cond branch";
+    const char* __attribute__((unused)) opn = "cp1 cond branch";
     TCGv_i32 t0 = tcg_temp_new_i32();
 
     if (cc != 0)
@@ -5792,7 +5792,7 @@
 
 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
 {
-    const char *opn = "cp1 move";
+    const char* __attribute__((unused)) opn = "cp1 move";
     TCGv t0 = tcg_temp_new();
 
     switch (opc) {
@@ -5973,7 +5973,7 @@
 static void gen_farith (DisasContext *ctx, uint32_t op1,
                         int ft, int fs, int fd, int cc)
 {
-    const char *opn = "farith";
+    const char* __attribute__((unused)) opn = "farith";
     const char *condnames[] = {
             "c.f",
             "c.un",
@@ -7243,8 +7243,8 @@
 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
                            int fd, int fs, int base, int index)
 {
-    const char *opn = "extended float load/store";
-    int store = 0;
+    const char* __attribute__((unused)) opn = "extended float load/store";
+    int __attribute__((unused)) store = 0;
     TCGv t0 = tcg_temp_new();
 
     if (base == 0) {
@@ -7345,7 +7345,7 @@
 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
                             int fd, int fr, int fs, int ft)
 {
-    const char *opn = "flt3_arith";
+    const char* __attribute__((unused)) opn = "flt3_arith";
 
     switch (opc) {
     case OPC_ALNV_PS:
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 1d83a5e..b0d4c95 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -596,7 +596,7 @@
                    int sizemask, TCGArg ret, int nargs, TCGArg *args)
 {
 #ifdef TCG_TARGET_I386
-    int call_type;
+    int __attribute__((unused)) call_type;
 #endif
     int i;
     int real_args;
diff --git a/telephony/gsm.c b/telephony/gsm.c
index b55578d..6670101 100644
--- a/telephony/gsm.c
+++ b/telephony/gsm.c
@@ -1207,11 +1207,11 @@
 {
     bytes_t   end    = data + datalen;
     bytes_t   footer = end - ADN_FOOTER_SIZE;
-    int       ton    = 0x81;
+    //int       ton    = 0x81;
     cbytes_t  number = (cbytes_t) rec->adn.number;
 
     if (number[0] == '+') {
-        ton     = 0x91;
+        //ton     = 0x91;
         number += 1;
     }
     footer[0] = (strlen((const char*)number)+1)/2 + 1;
diff --git a/ui/vnc-android.c b/ui/vnc-android.c
index cf52bfe..ff54557 100644
--- a/ui/vnc-android.c
+++ b/ui/vnc-android.c
@@ -1045,17 +1045,16 @@
  */
 void vnc_client_write(void *opaque)
 {
-    long ret;
     VncState *vs = opaque;
 
 #ifdef CONFIG_VNC_SASL
     if (vs->sasl.conn &&
         vs->sasl.runSSF &&
-        !vs->sasl.waitWriteSSF)
-        ret = vnc_client_write_sasl(vs);
-    else
+        !vs->sasl.waitWriteSSF) {
+        vnc_client_write_sasl(vs);
+    } else
 #endif /* CONFIG_VNC_SASL */
-        ret = vnc_client_write_plain(vs);
+        vnc_client_write_plain(vs);
 }
 
 void vnc_read_when(VncState *vs, VncReadEvent *func, size_t expecting)
@@ -2189,15 +2188,14 @@
     const char *options;
     int password = 0;
     int reverse = 0;
-    int to_port = 0;
 #ifdef CONFIG_VNC_TLS
     int tls = 0, x509 = 0;
 #endif
 #ifdef CONFIG_VNC_SASL
     int sasl = 0;
     int saslErr;
-#endif
     int acl = 0;
+#endif
 
     if (!vnc_display)
         return -1;
@@ -2216,7 +2214,7 @@
         } else if (strncmp(options, "reverse", 7) == 0) {
             reverse = 1;
         } else if (strncmp(options, "to=", 3) == 0) {
-            to_port = atoi(options+3) + 5900;
+            //to_port = atoi(options+3) + 5900;
 #ifdef CONFIG_VNC_SASL
         } else if (strncmp(options, "sasl", 4) == 0) {
             sasl = 1; /* Require SASL auth */
@@ -2255,7 +2253,9 @@
             }
 #endif
         } else if (strncmp(options, "acl", 3) == 0) {
+#ifdef CONFIG_VNC_SASL
             acl = 1;
+#endif
         }
     }
 
diff --git a/vl-android.c b/vl-android.c
index 3e0d189..fdc2508 100644
--- a/vl-android.c
+++ b/vl-android.c
@@ -2524,7 +2524,7 @@
     const char *gdbstub_dev = NULL;
     uint32_t boot_devices_bitmap = 0;
     int i;
-    int snapshot, linux_boot, net_boot;
+    int snapshot, linux_boot, __attribute__((unused)) net_boot;
     const char *icount_option = NULL;
     const char *initrd_filename;
     const char *kernel_filename, *kernel_cmdline;