Commit d068574e authored by karl's avatar karl Committed by Commit bot

Reland: Introduce a V8_NORETURN macro and use it to make GCC 4.9.2 happy again.

Without that, it has a few false positives about out-of-bounds array accesses.
Also makes the clang static-analyzer happy.

Original code review from Sven Panne:
https://codereview.chromium.org/790723002/

CQ_INCLUDE_TRYBOTS=tryserver.v8:v8_linux_arm_dbg,v8_linux_arm64_dbg,v8_mac64_dbg,v8_win_compile_dbg

Review URL: https://codereview.chromium.org/1384873002

Cr-Commit-Position: refs/heads/master@{#31105}
parent 13adffcb
...@@ -174,6 +174,7 @@ ...@@ -174,6 +174,7 @@
// supported // supported
// V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported // V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported
// V8_HAS_ATTRIBUTE_NOINLINE - __attribute__((noinline)) supported // V8_HAS_ATTRIBUTE_NOINLINE - __attribute__((noinline)) supported
// V8_HAS_ATTRIBUTE_NORETURN - __attribute__((noreturn)) supported
// V8_HAS_ATTRIBUTE_UNUSED - __attribute__((unused)) supported // V8_HAS_ATTRIBUTE_UNUSED - __attribute__((unused)) supported
// V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported
// V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result)) // V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result))
...@@ -190,6 +191,7 @@ ...@@ -190,6 +191,7 @@
// V8_HAS_DECLSPEC_DEPRECATED - __declspec(deprecated) supported // V8_HAS_DECLSPEC_DEPRECATED - __declspec(deprecated) supported
// V8_HAS_DECLSPEC_NOINLINE - __declspec(noinline) supported // V8_HAS_DECLSPEC_NOINLINE - __declspec(noinline) supported
// V8_HAS_DECLSPEC_SELECTANY - __declspec(selectany) supported // V8_HAS_DECLSPEC_SELECTANY - __declspec(selectany) supported
// V8_HAS_DECLSPEC_NORETURN - __declspec(noreturn) supported
// V8_HAS___FORCEINLINE - __forceinline supported // V8_HAS___FORCEINLINE - __forceinline supported
// //
// Note that testing for compilers and/or features must be done using #if // Note that testing for compilers and/or features must be done using #if
...@@ -212,6 +214,7 @@ ...@@ -212,6 +214,7 @@
# define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline)) # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline))
# define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated)) # define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated))
# define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline)) # define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline))
# define V8_HAS_ATTRIBUTE_NORETURN (__has_attribute(noreturn))
# define V8_HAS_ATTRIBUTE_UNUSED (__has_attribute(unused)) # define V8_HAS_ATTRIBUTE_UNUSED (__has_attribute(unused))
# define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility)) # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility))
# define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \ # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \
...@@ -253,6 +256,7 @@ ...@@ -253,6 +256,7 @@
# define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0)) # define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0))
# define V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE (V8_GNUC_PREREQ(4, 5, 0)) # define V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE (V8_GNUC_PREREQ(4, 5, 0))
# define V8_HAS_ATTRIBUTE_NOINLINE (V8_GNUC_PREREQ(3, 4, 0)) # define V8_HAS_ATTRIBUTE_NOINLINE (V8_GNUC_PREREQ(3, 4, 0))
# define V8_HAS_ATTRIBUTE_NORETURN (V8_GNUC_PREREQ(2, 5, 0))
# define V8_HAS_ATTRIBUTE_UNUSED (V8_GNUC_PREREQ(2, 95, 0)) # define V8_HAS_ATTRIBUTE_UNUSED (V8_GNUC_PREREQ(2, 95, 0))
# define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0)) # define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0))
# define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \ # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \
...@@ -285,6 +289,7 @@ ...@@ -285,6 +289,7 @@
# define V8_HAS_DECLSPEC_DEPRECATED 1 # define V8_HAS_DECLSPEC_DEPRECATED 1
# define V8_HAS_DECLSPEC_NOINLINE 1 # define V8_HAS_DECLSPEC_NOINLINE 1
# define V8_HAS_DECLSPEC_SELECTANY 1 # define V8_HAS_DECLSPEC_SELECTANY 1
# define V8_HAS_DECLSPEC_NORETURN 1
# define V8_HAS___FORCEINLINE 1 # define V8_HAS___FORCEINLINE 1
...@@ -319,6 +324,18 @@ ...@@ -319,6 +324,18 @@
#endif #endif
// A macro used to tell the compiler that a particular function never returns.
// Use like:
// V8_NORETURN void MyAbort() { abort(); }
#if V8_HAS_ATTRIBUTE_NORETURN
# define V8_NORETURN __attribute__((noreturn))
#elif HAS_DECLSPEC_NORETURN
# define V8_NORETURN __declspec(noreturn)
#else
# define V8_NORETURN /* NOT SUPPORTED */
#endif
// A macro (V8_DEPRECATED) to mark classes or functions as deprecated. // A macro (V8_DEPRECATED) to mark classes or functions as deprecated.
#if defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE #if defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE
#define V8_DEPRECATED(message, declarator) \ #define V8_DEPRECATED(message, declarator) \
......
...@@ -29,10 +29,13 @@ namespace internal { ...@@ -29,10 +29,13 @@ namespace internal {
class Arguments BASE_EMBEDDED { class Arguments BASE_EMBEDDED {
public: public:
Arguments(int length, Object** arguments) Arguments(int length, Object** arguments)
: length_(length), arguments_(arguments) { } : length_(length), arguments_(arguments) {
DCHECK_GE(length_, 0);
}
Object*& operator[] (int index) { Object*& operator[] (int index) {
DCHECK(0 <= index && index < length_); DCHECK_GE(index, 0);
DCHECK_LT(static_cast<uint32_t>(index), static_cast<uint32_t>(length_));
return *(reinterpret_cast<Object**>(reinterpret_cast<intptr_t>(arguments_) - return *(reinterpret_cast<Object**>(reinterpret_cast<intptr_t>(arguments_) -
index * kPointerSize)); index * kPointerSize));
} }
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
#include "src/base/build_config.h" #include "src/base/build_config.h"
extern "C" void V8_Fatal(const char* file, int line, const char* format, ...); extern "C" V8_NORETURN void V8_Fatal(const char* file, int line,
const char* format, ...);
// The FATAL, UNREACHABLE and UNIMPLEMENTED macros are useful during // The FATAL, UNREACHABLE and UNIMPLEMENTED macros are useful during
......
...@@ -194,7 +194,7 @@ class OS { ...@@ -194,7 +194,7 @@ class OS {
static void Sleep(TimeDelta interval); static void Sleep(TimeDelta interval);
// Abort the current process. // Abort the current process.
static void Abort(); V8_NORETURN static void Abort();
// Debug break. // Debug break.
static void DebugBreak(); static void DebugBreak();
......
...@@ -446,7 +446,7 @@ AllocationResult NewSpace::AllocateRawAligned(int size_in_bytes, ...@@ -446,7 +446,7 @@ AllocationResult NewSpace::AllocateRawAligned(int size_in_bytes,
AllocationResult NewSpace::AllocateRawUnaligned(int size_in_bytes) { AllocationResult NewSpace::AllocateRawUnaligned(int size_in_bytes) {
Address top = allocation_info_.top(); Address top = allocation_info_.top();
if (allocation_info_.limit() - top < size_in_bytes) { if (allocation_info_.limit() < top + size_in_bytes) {
// See if we can create room. // See if we can create room.
if (!EnsureAllocation(size_in_bytes, kWordAligned)) { if (!EnsureAllocation(size_in_bytes, kWordAligned)) {
return AllocationResult::Retry(); return AllocationResult::Retry();
......
...@@ -157,6 +157,7 @@ static void CheckBytecodeArrayEqual(struct ExpectedSnippet<T> expected, ...@@ -157,6 +157,7 @@ static void CheckBytecodeArrayEqual(struct ExpectedSnippet<T> expected,
switch (Bytecodes::SizeOfOperand(operand_type)) { switch (Bytecodes::SizeOfOperand(operand_type)) {
case OperandSize::kNone: case OperandSize::kNone:
UNREACHABLE(); UNREACHABLE();
return;
case OperandSize::kByte: case OperandSize::kByte:
expected_operand = expected_operand =
static_cast<uint32_t>(expected.bytecode[operand_index]); static_cast<uint32_t>(expected.bytecode[operand_index]);
...@@ -165,6 +166,9 @@ static void CheckBytecodeArrayEqual(struct ExpectedSnippet<T> expected, ...@@ -165,6 +166,9 @@ static void CheckBytecodeArrayEqual(struct ExpectedSnippet<T> expected,
expected_operand = Bytecodes::ShortOperandFromBytes( expected_operand = Bytecodes::ShortOperandFromBytes(
&expected.bytecode[operand_index]); &expected.bytecode[operand_index]);
break; break;
default:
UNREACHABLE();
return;
} }
if (raw_operand != expected_operand) { if (raw_operand != expected_operand) {
std::ostringstream stream; std::ostringstream stream;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment