Fix compilation issues with new gcc

(cherry picked from commit efad79fa4121e20ab613e31bde44cc3120f23832)

Conflicts:

	src/compiler/codegen/mips/Mips32/Factory.cc
	src/compiler/codegen/x86/X86/Factory.cc

Change-Id: I5e0e9dc48ba76092cccc70b25668978a08a5449b
diff --git a/build/Android.common.mk b/build/Android.common.mk
index 8e0fd51..201d028 100644
--- a/build/Android.common.mk
+++ b/build/Android.common.mk
@@ -95,8 +95,9 @@
 ART_HOST_NON_DEBUG_CFLAGS := $(art_non_debug_cflags)
 ART_TARGET_NON_DEBUG_CFLAGS := $(art_non_debug_cflags)
 
-# TODO: move -fkeep-inline-functions to art_debug_cflags when target gcc > 4.4
+# TODO: move -fkeep-inline-functions to art_debug_cflags when target gcc > 4.4 (and -lsupc++)
 ART_HOST_DEBUG_CFLAGS := $(art_debug_cflags) -fkeep-inline-functions
+ART_HOST_DEBUG_LDLIBS := -lsupc++
 
 ifneq ($(HOST_OS),linux)
   # Some Mac OS pthread header files are broken with -fkeep-inline-functions.
diff --git a/build/Android.libart.mk b/build/Android.libart.mk
index 2683f14..4ca9937 100644
--- a/build/Android.libart.mk
+++ b/build/Android.libart.mk
@@ -83,6 +83,7 @@
       LOCAL_CFLAGS += $(ART_TARGET_DEBUG_CFLAGS)
     else # host
       LOCAL_CFLAGS += $(ART_HOST_DEBUG_CFLAGS)
+      LOCAL_LDLIBS += $(ART_HOST_DEBUG_LDLIBS)
       LOCAL_STATIC_LIBRARIES := libgtest_host
     endif
   else
@@ -109,7 +110,7 @@
     LOCAL_STATIC_LIBRARIES += libcutils
     LOCAL_SHARED_LIBRARIES += libz-host
     LOCAL_SHARED_LIBRARIES += libdynamic_annotations-host # tsan support
-    LOCAL_LDLIBS := -ldl -lpthread
+    LOCAL_LDLIBS += -ldl -lpthread
     ifeq ($(HOST_OS),linux)
       LOCAL_LDLIBS += -lrt
     endif
diff --git a/src/compiler/codegen/mips/Mips32/Factory.cc b/src/compiler/codegen/mips/Mips32/Factory.cc
index 8b6f185..8f3c1ec 100644
--- a/src/compiler/codegen/mips/Mips32/Factory.cc
+++ b/src/compiler/codegen/mips/Mips32/Factory.cc
@@ -430,7 +430,6 @@
                       int rIndex, int rSrc, int scale, OpSize size)
 {
   LIR *first = NULL;
-  LIR *res;
   MipsOpCode opcode = kMipsNop;
   int rNewIndex = rIndex;
   int tReg = oatAllocTemp(cUnit);
@@ -473,7 +472,7 @@
     default:
       LOG(FATAL) << "Bad case in storeBaseIndexed";
   }
-  res = newLIR3(cUnit, opcode, rSrc, 0, tReg);
+  newLIR3(cUnit, opcode, rSrc, 0, tReg);
   oatFreeTemp(cUnit, rNewIndex);
   return first;
 }
diff --git a/src/compiler/codegen/x86/X86/Factory.cc b/src/compiler/codegen/x86/X86/Factory.cc
index 6f11709..11d662e 100644
--- a/src/compiler/codegen/x86/X86/Factory.cc
+++ b/src/compiler/codegen/x86/X86/Factory.cc
@@ -530,15 +530,12 @@
                           int rSrc, int rSrcHi,
                           OpSize size, int sReg) {
   LIR *store = NULL;
-  LIR *store2 = NULL;
   bool isArray = rIndex != INVALID_REG;
   bool pair = false;
-  bool is64bit = false;
   X86OpCode opcode = kX86Nop;
   switch (size) {
     case kLong:
     case kDouble:
-      is64bit = true;
       if (FPREG(rSrc)) {
         opcode = isArray ? kX86MovsdAR : kX86MovsdMR;
         if (DOUBLEREG(rSrc)) {
@@ -582,18 +579,15 @@
       store = newLIR3(cUnit, opcode, rBase, displacement + LOWORD_OFFSET, rSrc);
     } else {
       store = newLIR3(cUnit, opcode, rBase, displacement + LOWORD_OFFSET, rSrc);
-      store2 = newLIR3(cUnit, opcode, rBase, displacement + HIWORD_OFFSET,
-                       rSrcHi);
+      newLIR3(cUnit, opcode, rBase, displacement + HIWORD_OFFSET, rSrcHi);
     }
   } else {
     if (!pair) {
       store = newLIR5(cUnit, opcode, rBase, rIndex, scale,
                       displacement + LOWORD_OFFSET, rSrc);
     } else {
-      store = newLIR5(cUnit, opcode, rBase, rIndex, scale,
-                      displacement + LOWORD_OFFSET, rSrc);
-      store2 = newLIR5(cUnit, opcode, rBase, rIndex, scale,
-                       displacement + HIWORD_OFFSET, rSrcHi);
+      store = newLIR5(cUnit, opcode, rBase, rIndex, scale, displacement + LOWORD_OFFSET, rSrc);
+      newLIR5(cUnit, opcode, rBase, rIndex, scale, displacement + HIWORD_OFFSET, rSrcHi);
     }
   }
 
diff --git a/src/jdwp/jdwp_handler.cc b/src/jdwp/jdwp_handler.cc
index 73c70cb..cf1e188 100644
--- a/src/jdwp/jdwp_handler.cc
+++ b/src/jdwp/jdwp_handler.cc
@@ -1016,9 +1016,7 @@
  * Get the monitor that the thread is waiting on.
  */
 static JdwpError handleTR_CurrentContendedMonitor(JdwpState*, const uint8_t* buf, int, ExpandBuf*) {
-  ObjectId threadId;
-
-  threadId = ReadObjectId(&buf);
+  ReadObjectId(&buf);  // threadId
 
   // TODO: create an Object to represent the monitor (we're currently
   // just using a raw Monitor struct in the VM)
@@ -1143,8 +1141,7 @@
 }
 
 static JdwpError handleCLR_VisibleClasses(JdwpState*, const uint8_t* buf, int, ExpandBuf* pReply) {
-  ObjectId classLoaderObject;
-  classLoaderObject = ReadObjectId(&buf);
+  ReadObjectId(&buf);  // classLoaderObject
   // TODO: we should only return classes which have the given class loader as a defining or
   // initiating loader. The former would be easy; the latter is hard, because we don't have
   // any such notion.
diff --git a/src/jdwp/jdwp_socket.cc b/src/jdwp/jdwp_socket.cc
index 9ff50f5..01eba12 100644
--- a/src/jdwp/jdwp_socket.cc
+++ b/src/jdwp/jdwp_socket.cc
@@ -558,7 +558,6 @@
   JdwpReqHeader hdr;
   uint32_t length, id;
   uint8_t flags, cmdSet, cmd;
-  uint16_t error;
   bool reply;
   int dataLen;
 
@@ -571,7 +570,7 @@
   flags = Read1(&buf);
   if ((flags & kJDWPFlagReply) != 0) {
     reply = true;
-    error = Read2BE(&buf);
+    Read2BE(&buf);  // error
   } else {
     reply = false;
     cmdSet = Read1(&buf);
diff --git a/src/oat/jni/arm/jni_internal_arm.cc b/src/oat/jni/arm/jni_internal_arm.cc
index 2227742..78c3903 100644
--- a/src/oat/jni/arm/jni_internal_arm.cc
+++ b/src/oat/jni/arm/jni_internal_arm.cc
@@ -71,12 +71,7 @@
 
   // Can either get 3 or 2 arguments into registers
   size_t reg_bytes = (is_static ? 3 : 2) * kPointerSize;
-  // Bytes passed by stack
-  size_t stack_bytes;
-  if (num_arg_array_bytes > reg_bytes) {
-    stack_bytes = num_arg_array_bytes - reg_bytes;
-  } else {
-    stack_bytes = 0;
+  if (num_arg_array_bytes <= reg_bytes) {
     reg_bytes = num_arg_array_bytes;
   }
 
diff --git a/src/oat/runtime/support_stubs.cc b/src/oat/runtime/support_stubs.cc
index ac5d6f9..2a46c8b 100644
--- a/src/oat/runtime/support_stubs.cc
+++ b/src/oat/runtime/support_stubs.cc
@@ -89,8 +89,10 @@
   bool is_static;
   bool is_virtual;
   uint32_t dex_method_idx;
+#if !defined(__i386__)
   const char* shorty;
   uint32_t shorty_len;
+#endif
   if (type == Runtime::kUnknownMethod) {
     DCHECK(called->IsRuntimeMethod());
     // less two as return address may span into next dex instruction
@@ -109,15 +111,19 @@
            (instr_code == Instruction::INVOKE_DIRECT_RANGE));
     DecodedInstruction dec_insn(instr);
     dex_method_idx = dec_insn.vB;
+#if !defined(__i386__)
     shorty = linker->MethodShorty(dex_method_idx, caller, &shorty_len);
+#endif
   } else {
     DCHECK(!called->IsRuntimeMethod());
     is_static = type == Runtime::kStaticMethod;
     is_virtual = false;
     dex_method_idx = called->GetDexMethodIndex();
+#if !defined(__i386__)
     MethodHelper mh(called);
     shorty = mh.GetShorty();
     shorty_len = mh.GetShortyLength();
+#endif
   }
 #if !defined(__i386__)
   // Discover shorty (avoid GCs)
diff --git a/src/oat_writer.cc b/src/oat_writer.cc
index 4d11237..ffdb0c8 100644
--- a/src/oat_writer.cc
+++ b/src/oat_writer.cc
@@ -258,8 +258,10 @@
                                     uint32_t method_idx, const DexFile* dex_file) {
   // derived from CompiledMethod if available
   uint32_t code_offset = 0;
+#if defined(ART_USE_LLVM_COMPILER)
   uint16_t code_elf_idx = static_cast<uint16_t>(-1u);
   uint16_t code_elf_func_idx = static_cast<uint16_t>(-1u);
+#endif
   uint32_t frame_size_in_bytes = kStackAlignment;
   uint32_t core_spill_mask = 0;
   uint32_t fp_spill_mask = 0;
@@ -268,15 +270,19 @@
   uint32_t gc_map_offset = 0;
   // derived from CompiledInvokeStub if available
   uint32_t invoke_stub_offset = 0;
+#if defined(ART_USE_LLVM_COMPILER)
   uint16_t invoke_stub_elf_idx = static_cast<uint16_t>(-1u);
   uint16_t invoke_stub_elf_func_idx = static_cast<uint16_t>(-1u);
+#endif
 
   CompiledMethod* compiled_method =
       compiler_->GetCompiledMethod(Compiler::MethodReference(dex_file, method_idx));
   if (compiled_method != NULL) {
     if (compiled_method->IsExecutableInElf()) {
+#if defined(ART_USE_LLVM_COMPILER)
       code_elf_idx = compiled_method->GetElfIndex();
       code_elf_func_idx = compiled_method->GetElfFuncIndex();
+#endif
       frame_size_in_bytes = compiled_method->GetFrameSizeInBytes();
     } else {
       offset = compiled_method->AlignCode(offset);
@@ -359,8 +365,10 @@
   const CompiledInvokeStub* compiled_invoke_stub = compiler_->FindInvokeStub(is_static, shorty);
   if (compiled_invoke_stub != NULL) {
     if (compiled_invoke_stub->IsExecutableInElf()) {
+#if defined(ART_USE_LLVM_COMPILER)
       invoke_stub_elf_idx = compiled_invoke_stub->GetElfIndex();
       invoke_stub_elf_func_idx = compiled_invoke_stub->GetElfFuncIndex();
+#endif
     } else {
       offset = CompiledMethod::AlignCode(offset, compiler_->GetInstructionSet());
       DCHECK_ALIGNED(offset, kArmAlignment);
@@ -600,10 +608,6 @@
   const CompiledMethod* compiled_method =
       compiler_->GetCompiledMethod(Compiler::MethodReference(&dex_file, method_idx));
 
-  uint32_t frame_size_in_bytes = 0;
-  uint32_t core_spill_mask = 0;
-  uint32_t fp_spill_mask = 0;
-
   OatMethodOffsets method_offsets =
       oat_classes_[oat_class_index]->method_offsets_[class_def_method_index];
 
@@ -647,9 +651,6 @@
         code_offset += code_size;
       }
       DCHECK_CODE_OFFSET();
-      frame_size_in_bytes = compiled_method->GetFrameSizeInBytes();
-      core_spill_mask = compiled_method->GetCoreSpillMask();
-      fp_spill_mask = compiled_method->GetFpSpillMask();
 
       const std::vector<uint32_t>& mapping_table = compiled_method->GetMappingTable();
       size_t mapping_table_size = mapping_table.size() * sizeof(mapping_table[0]);