From: Ian Rogers Date: Tue, 30 Sep 2014 22:43:59 +0000 (-0700) Subject: Enable -Wunreachable-code X-Git-Tag: android-x86-7.1-r1~889^2~2978^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=07140838a3ee44a6056cacdc78f2930e019107da;p=android-x86%2Fart.git Enable -Wunreachable-code Caught bugs in DeoptimizeStackVisitor and assemble_x86 SIB encoding. Add UNREACHABLE macro to document code expected to be unreachable. Bug: 17731047 Change-Id: I2e363fe5b38a1246354d98be18c902a6031c0b9e --- diff --git a/build/Android.common_build.mk b/build/Android.common_build.mk index 0dcefead3..386128e00 100644 --- a/build/Android.common_build.mk +++ b/build/Android.common_build.mk @@ -158,6 +158,7 @@ art_cflags := \ -Wno-unused-parameter \ -Wstrict-aliasing \ -fstrict-aliasing \ + -Wunreachable-code \ -fvisibility=protected ART_TARGET_CLANG_CFLAGS := diff --git a/compiler/dex/quick/x86/assemble_x86.cc b/compiler/dex/quick/x86/assemble_x86.cc index ab1608be9..dce2b73ff 100644 --- a/compiler/dex/quick/x86/assemble_x86.cc +++ b/compiler/dex/quick/x86/assemble_x86.cc @@ -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; diff --git a/runtime/base/macros.h b/runtime/base/macros.h index fae9271d9..b66d528d1 100644 --- a/runtime/base/macros.h +++ b/runtime/base/macros.h @@ -179,6 +179,7 @@ char (&ArraySizeHelper(T (&array)[N]))[N]; #define WARN_UNUSED __attribute__((warn_unused_result)) template void UNUSED(const T&) {} +#define UNREACHABLE __builtin_unreachable // Annotalysis thread-safety analysis support. #if defined(__SUPPORT_TS_ANNOTATION__) || defined(__clang__) diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index cc77c508a..2cf3820ac 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -2269,9 +2269,7 @@ mirror::Class* ClassLinker::FindClass(Thread* self, const char* descriptor, return soa.Decode(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 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 klass) { diff --git a/runtime/mirror/object.cc b/runtime/mirror/object.cc index a1177d645..57069ab26 100644 --- a/runtime/mirror/object.cc +++ b/runtime/mirror/object.cc @@ -187,8 +187,7 @@ int32_t Object::IdentityHashCode() const { } } } - LOG(FATAL) << "Unreachable"; - return 0; + UNREACHABLE(); } void Object::CheckFieldAssignmentImpl(MemberOffset field_offset, Object* new_value) { diff --git a/runtime/parsed_options.cc b/runtime/parsed_options.cc index 2bd994dc5..d82002683 100644 --- a/runtime/parsed_options.cc +++ b/runtime/parsed_options.cc @@ -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; diff --git a/runtime/quick_exception_handler.cc b/runtime/quick_exception_handler.cc index 43d21de76..2c158ba96 100644 --- a/runtime/quick_exception_handler.cc +++ b/runtime/quick_exception_handler.cc @@ -230,7 +230,7 @@ class DeoptimizeStackVisitor FINAL : public StackVisitor { reinterpret_cast(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));