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 0dcefea..386128e 100644
--- a/build/Android.common_build.mk
+++ b/build/Android.common_build.mk
@@ -158,6 +158,7 @@
-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 ab1608b..dce2b73 100644
--- a/compiler/dex/quick/x86/assemble_x86.cc
+++ b/compiler/dex/quick/x86/assemble_x86.cc
@@ -580,7 +580,7 @@
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 fae9271..b66d528 100644
--- a/runtime/base/macros.h
+++ b/runtime/base/macros.h
@@ -179,6 +179,7 @@
#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__)
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index cc77c50..2cf3820 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -2269,9 +2269,7 @@
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 @@
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) {
diff --git a/runtime/mirror/object.cc b/runtime/mirror/object.cc
index a1177d6..57069ab 100644
--- a/runtime/mirror/object.cc
+++ b/runtime/mirror/object.cc
@@ -187,8 +187,7 @@
}
}
}
- 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 2bd994d..d820026 100644
--- a/runtime/parsed_options.cc
+++ b/runtime/parsed_options.cc
@@ -932,7 +932,7 @@
}
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 43d21de..2c158ba 100644
--- a/runtime/quick_exception_handler.cc
+++ b/runtime/quick_exception_handler.cc
@@ -230,7 +230,7 @@
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 @@
}
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 @@
}
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));