OSDN Git Service

Enable -Wunreachable-code
authorIan Rogers <irogers@google.com>
Tue, 30 Sep 2014 22:43:59 +0000 (15:43 -0700)
committerIan Rogers <irogers@google.com>
Tue, 30 Sep 2014 22:43:59 +0000 (15:43 -0700)
Caught bugs in DeoptimizeStackVisitor and assemble_x86 SIB encoding.
Add UNREACHABLE macro to document code expected to be unreachable.
Bug: 17731047

Change-Id: I2e363fe5b38a1246354d98be18c902a6031c0b9e

build/Android.common_build.mk
compiler/dex/quick/x86/assemble_x86.cc
runtime/base/macros.h
runtime/class_linker.cc
runtime/mirror/object.cc
runtime/parsed_options.cc
runtime/quick_exception_handler.cc

index 0dcefea..386128e 100644 (file)
@@ -158,6 +158,7 @@ art_cflags := \
   -Wno-unused-parameter \
   -Wstrict-aliasing \
   -fstrict-aliasing \
+  -Wunreachable-code \
   -fvisibility=protected
 
 ART_TARGET_CLANG_CFLAGS :=
index ab1608b..dce2b73 100644 (file)
@@ -580,7 +580,7 @@ static bool HasSib(const X86EncodingMap* entry) {
         case kX86CallA: return true;
         default: return false;
       }
-    case kPcRel: return true;
+    case kPcRel:
        switch (entry->opcode) {
          case kX86PcRelLoadRA: return true;
          default: return false;
index fae9271..b66d528 100644 (file)
@@ -179,6 +179,7 @@ char (&ArraySizeHelper(T (&array)[N]))[N];
 #define WARN_UNUSED __attribute__((warn_unused_result))
 
 template<typename T> void UNUSED(const T&) {}
+#define UNREACHABLE  __builtin_unreachable
 
 // Annotalysis thread-safety analysis support.
 #if defined(__SUPPORT_TS_ANNOTATION__) || defined(__clang__)
index cc77c50..2cf3820 100644 (file)
@@ -2269,9 +2269,7 @@ mirror::Class* ClassLinker::FindClass(Thread* self, const char* descriptor,
       return soa.Decode<mirror::Class*>(result.get());
     }
   }
-
-  ThrowNoClassDefFoundError("Class %s not found", PrintableString(descriptor).c_str());
-  return nullptr;
+  UNREACHABLE();
 }
 
 mirror::Class* ClassLinker::DefineClass(Thread* self, const char* descriptor,
@@ -4340,7 +4338,7 @@ bool ClassLinker::WaitForInitializeClass(Handle<mirror::Class> klass, Thread* se
     LOG(FATAL) << "Unexpected class status. " << PrettyClass(klass.Get()) << " is "
         << klass->GetStatus();
   }
-  LOG(FATAL) << "Not Reached" << PrettyClass(klass.Get());
+  UNREACHABLE();
 }
 
 bool ClassLinker::ValidateSuperClassDescriptors(Handle<mirror::Class> klass) {
index a1177d6..57069ab 100644 (file)
@@ -187,8 +187,7 @@ int32_t Object::IdentityHashCode() const {
       }
     }
   }
-  LOG(FATAL) << "Unreachable";
-  return 0;
+  UNREACHABLE();
 }
 
 void Object::CheckFieldAssignmentImpl(MemberOffset field_offset, Object* new_value) {
index 2bd994d..d820026 100644 (file)
@@ -932,7 +932,7 @@ bool ParsedOptions::ParseDouble(const std::string& option, char after_char,
   }
   bool sane_val = true;
   double value;
-  if (false) {
+  if ((false)) {
     // TODO: this doesn't seem to work on the emulator.  b/15114595
     std::stringstream iss(substring);
     iss >> value;
index 43d21de..2c158ba 100644 (file)
@@ -230,7 +230,7 @@ class DeoptimizeStackVisitor FINAL : public StackVisitor {
                                       reinterpret_cast<mirror::Object*>(GetVReg(m, reg, kind)));
           break;
         case kLongLoVReg:
-          if (GetVRegKind(reg + 1, kinds), kLongHiVReg) {
+          if (GetVRegKind(reg + 1, kinds) == kLongHiVReg) {
             // Treat it as a "long" register pair.
             new_frame->SetVRegLong(reg, GetVRegPair(m, reg, kLongLoVReg, kLongHiVReg));
           } else {
@@ -238,14 +238,14 @@ class DeoptimizeStackVisitor FINAL : public StackVisitor {
           }
           break;
         case kLongHiVReg:
-          if (GetVRegKind(reg - 1, kinds), kLongLoVReg) {
+          if (GetVRegKind(reg - 1, kinds) == kLongLoVReg) {
             // Nothing to do: we treated it as a "long" register pair.
           } else {
             new_frame->SetVReg(reg, GetVReg(m, reg, kind));
           }
           break;
         case kDoubleLoVReg:
-          if (GetVRegKind(reg + 1, kinds), kDoubleHiVReg) {
+          if (GetVRegKind(reg + 1, kinds) == kDoubleHiVReg) {
             // Treat it as a "double" register pair.
             new_frame->SetVRegLong(reg, GetVRegPair(m, reg, kDoubleLoVReg, kDoubleHiVReg));
           } else {
@@ -253,7 +253,7 @@ class DeoptimizeStackVisitor FINAL : public StackVisitor {
           }
           break;
         case kDoubleHiVReg:
-          if (GetVRegKind(reg - 1, kinds), kDoubleLoVReg) {
+          if (GetVRegKind(reg - 1, kinds) == kDoubleLoVReg) {
             // Nothing to do: we treated it as a "double" register pair.
           } else {
             new_frame->SetVReg(reg, GetVReg(m, reg, kind));