Skip to content

Commit

Permalink
Use C++'s standardized [[noreturn]] attribute
Browse files Browse the repository at this point in the history
Summary:Use C++'s standardized `[[noreturn]]` attribute.

All supported compilers (and some unsupported compilers) also support the standardized syntax.

GCC >= 4.8, Clang >= 3.0, and MSVC >= 2015 have direct support for the C++'s standardized way of writing the attribute.

Clang - http://goo.gl/ftJGVM
GCC 4.8.2 - http://goo.gl/ORCVOD
ICC 13.0.1 - http://goo.gl/I5tn5I
MSVC 2015 - https://msdn.microsoft.com/en-us/library/hh567368.aspx

(Regardling Clang, earlier versions may support it. 3.0 was the earliest Clang version listed at godbolt.com, so that's as far back as I went.)

Therefore, we no longer need to use the compiler-specific syntaxes, or use preprocessor macros with per-compiler definitions:

    __attribute__((__noreturn__))
    __attribute__((noreturn))
    __declspec(noreturn)

Reviewed By: Orvid

Differential Revision: D3073621

fb-gh-sync-id: 32d4771d1bf1974693b8574fa2d39c9559872945
shipit-source-id: 32d4771d1bf1974693b8574fa2d39c9559872945
  • Loading branch information
yfeldblum authored and Hhvm Bot committed Mar 23, 2016
1 parent 6dfadf0 commit ca92861
Show file tree
Hide file tree
Showing 36 changed files with 117 additions and 122 deletions.
8 changes: 4 additions & 4 deletions hphp/runtime/base/array-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,10 @@ void decRefArr(ArrayData* arr) {
arr->decRefAndRelease();
}

ATTRIBUTE_NORETURN void throwInvalidArrayKeyException(const TypedValue* key);
ATTRIBUTE_NORETURN void throwOOBArrayKeyException(TypedValue key);
ATTRIBUTE_NORETURN void throwOOBArrayKeyException(int64_t key);
ATTRIBUTE_NORETURN void throwOOBArrayKeyException(const StringData* key);
[[noreturn]] void throwInvalidArrayKeyException(const TypedValue* key);
[[noreturn]] void throwOOBArrayKeyException(TypedValue key);
[[noreturn]] void throwOOBArrayKeyException(int64_t key);
[[noreturn]] void throwOOBArrayKeyException(const StringData* key);

///////////////////////////////////////////////////////////////////////////////
}
Expand Down
26 changes: 13 additions & 13 deletions hphp/runtime/base/builtin-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void NEVER_INLINE throw_invalid_property_name(const String& name);
void NEVER_INLINE throw_null_get_object_prop();
void NEVER_INLINE raise_null_object_prop();

ATTRIBUTE_NORETURN
[[noreturn]]
void throw_exception(const Object& e);

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -122,15 +122,15 @@ Variant o_invoke_failed(const char *cls, const char *meth,
bool is_constructor_name(const char* func);
void throw_instance_method_fatal(const char *name);

ATTRIBUTE_NORETURN void throw_invalid_operation_exception(StringData*);
ATTRIBUTE_NORETURN void throw_arithmetic_error(StringData*);
ATTRIBUTE_NORETURN void throw_division_by_zero_error(StringData*);
ATTRIBUTE_NORETURN void throw_iterator_not_valid();
ATTRIBUTE_NORETURN void throw_collection_modified();
ATTRIBUTE_NORETURN void throw_collection_property_exception();
ATTRIBUTE_NORETURN void throw_collection_compare_exception();
ATTRIBUTE_NORETURN void throw_param_is_not_container();
ATTRIBUTE_NORETURN
[[noreturn]] void throw_invalid_operation_exception(StringData*);
[[noreturn]] void throw_arithmetic_error(StringData*);
[[noreturn]] void throw_division_by_zero_error(StringData*);
[[noreturn]] void throw_iterator_not_valid();
[[noreturn]] void throw_collection_modified();
[[noreturn]] void throw_collection_property_exception();
[[noreturn]] void throw_collection_compare_exception();
[[noreturn]] void throw_param_is_not_container();
[[noreturn]]
void throw_cannot_modify_immutable_object(const char* className);
void check_collection_compare(const ObjectData* obj);
void check_collection_compare(const ObjectData* obj1, const ObjectData* obj2);
Expand All @@ -140,14 +140,14 @@ Object create_object_only(const String& s);
Object create_object(const String& s, const Array &params, bool init = true);
Object init_object(const String& s, const Array &params, ObjectData* o);

ATTRIBUTE_NORETURN void throw_object(const Object& e);
[[noreturn]] void throw_object(const Object& e);
#if ((__GNUC__ != 4) || (__GNUC_MINOR__ != 8) || __GNUC_PATCHLEVEL__ >= 2)
// gcc-4.8.1 has a bug that causes incorrect code if we
// define this function.
ATTRIBUTE_NORETURN void throw_object(Object&& e);
[[noreturn]] void throw_object(Object&& e);
#endif

ATTRIBUTE_NORETURN inline
[[noreturn]] inline
void throw_object(const String& s, const Array& params, bool init = true) {
throw_object(create_object(s, params, init));
}
Expand Down
2 changes: 1 addition & 1 deletion hphp/runtime/base/enum-cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct EnumCache {
static void deleteValues(const Class* klass);

// Helper that raises a PHP exception
ATTRIBUTE_NORETURN static void failLookup(const Variant& msg);
[[noreturn]] static void failLookup(const Variant& msg);

private:
// Class* to intptr_ti key helpers
Expand Down
2 changes: 1 addition & 1 deletion hphp/runtime/base/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void throw_not_supported(const char* feature, const char* reason) {

///////////////////////////////////////////////////////////////////////////////

ATTRIBUTE_NORETURN
[[noreturn]]
void raise_fatal_error(const char* msg,
const Array& bt /* = null_array */,
bool recoverable /* = false */,
Expand Down
10 changes: 5 additions & 5 deletions hphp/runtime/base/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct FatalErrorException : ExtendedException {
bool m_recoverable{false};
};

ATTRIBUTE_NORETURN
[[noreturn]]
void raise_fatal_error(const char* msg, const Array& bt = null_array,
bool recoverable = false, bool silent = false,
bool throws = true);
Expand Down Expand Up @@ -165,10 +165,10 @@ struct PhpFileDoesNotExistException : ExtendedException {
*
* In newer code you'll generally want to use raise_error.
*/
ATTRIBUTE_NORETURN void throw_null_pointer_exception();
ATTRIBUTE_NORETURN void throw_invalid_object_type(const char* clsName);
ATTRIBUTE_NORETURN void throw_not_implemented(const char* feature);
ATTRIBUTE_NORETURN
[[noreturn]] void throw_null_pointer_exception();
[[noreturn]] void throw_invalid_object_type(const char* clsName);
[[noreturn]] void throw_not_implemented(const char* feature);
[[noreturn]]
void throw_not_supported(const char* feature, const char* reason);

//////////////////////////////////////////////////////////////////////
Expand Down
14 changes: 7 additions & 7 deletions hphp/runtime/base/req-ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ struct Resource;
struct Object;
struct Variant;

ATTRIBUTE_NORETURN extern void throw_null_pointer_exception();
ATTRIBUTE_NORETURN void throw_invalid_object_type(ResourceData* p);
ATTRIBUTE_NORETURN void throw_invalid_object_type(ObjectData* p);
ATTRIBUTE_NORETURN void throw_invalid_object_type(const Variant& p);
ATTRIBUTE_NORETURN void throw_invalid_object_type(const Resource& p);
ATTRIBUTE_NORETURN void throw_invalid_object_type(const Object& p);
[[noreturn]] extern void throw_null_pointer_exception();
[[noreturn]] void throw_invalid_object_type(ResourceData* p);
[[noreturn]] void throw_invalid_object_type(ObjectData* p);
[[noreturn]] void throw_invalid_object_type(const Variant& p);
[[noreturn]] void throw_invalid_object_type(const Resource& p);
[[noreturn]] void throw_invalid_object_type(const Object& p);
template <typename T>
ATTRIBUTE_NORETURN void throw_invalid_object_type(const req::ptr<T>& p);
[[noreturn]] void throw_invalid_object_type(const req::ptr<T>& p);
template <typename T>
void throw_invalid_object_type(const req::ptr<T>& p) {
throw_invalid_object_type(p.get());
Expand Down
6 changes: 3 additions & 3 deletions hphp/runtime/base/runtime-error.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ enum class ErrorMode {
UPGRADEABLE_ERROR = WARNING | USER_WARNING | NOTICE | USER_NOTICE
};

ATTRIBUTE_NORETURN void raise_error(const std::string&);
ATTRIBUTE_NORETURN void raise_error(ATTRIBUTE_PRINTF_STRING const char*, ...)
[[noreturn]] void raise_error(const std::string&);
[[noreturn]] void raise_error(ATTRIBUTE_PRINTF_STRING const char*, ...)
ATTRIBUTE_PRINTF(1, 2);
ATTRIBUTE_NORETURN void raise_error_without_first_frame(const std::string&);
[[noreturn]] void raise_error_without_first_frame(const std::string&);
void raise_recoverable_error(const std::string &msg);
void raise_recoverable_error(ATTRIBUTE_PRINTF_STRING const char *fmt, ...)
ATTRIBUTE_PRINTF(1, 2);
Expand Down
2 changes: 1 addition & 1 deletion hphp/runtime/base/tv-arith.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace HPHP {

namespace {

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throw_bad_array_operand() {
throw ExtendedException("Invalid operand type was used: "
"cannot perform this operation with arrays");
Expand Down
2 changes: 1 addition & 1 deletion hphp/runtime/base/variable-serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static void serializeArray(const ArrayData*, VariableSerializer*,
static void serializeResource(const ResourceData*, VariableSerializer*);
static void serializeString(const String&, VariableSerializer*);

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
static void throwNestingException() {
throw ExtendedException("Nesting level too deep - recursive dependency?");
}
Expand Down
44 changes: 22 additions & 22 deletions hphp/runtime/base/variable-unserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,54 +57,54 @@ void unserializeSet(ObjectData*, VariableUnserializer*, int64_t sz,
void unserializePair(ObjectData*, VariableUnserializer*, int64_t sz,
char type);

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwUnexpectedSep(char expect, char actual) {
throw Exception("Expected '%c' but got '%c'", expect, actual);
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwOutOfRange(int64_t id) {
throw Exception("Id %" PRId64 " out of range", id);
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwUnexpectedStr(const char* expect, folly::StringPiece& actual) {
throw Exception("Expected '%s' but got '%.*s'", expect,
(int)actual.size(), actual.data());
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwUnknownType(char type) {
throw Exception("Unknown type '%c'", type);
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwInvalidPair() {
throw Exception("Pair objects must have exactly 2 elements");
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwInvalidOFormat(const String& clsName) {
throw Exception("%s does not support the 'O' serialization format",
clsName.data());
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwMangledPrivateProperty() {
throw Exception("Mangled private object property");
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwUnterminatedProperty() {
throw Exception("Object property not terminated properly");
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwNotCollection(const String& clsName) {
throw Exception("%s is not a collection class", clsName.data());
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwUnexpectedType(const String& key, const ObjectData* obj,
const Variant& type) {
auto msg = folly::format(
Expand All @@ -117,67 +117,67 @@ void throwUnexpectedType(const String& key, const ObjectData* obj,
throw Exception(msg);
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwUnexpectedType(const StringData* key, const ObjectData* obj,
const Variant& type) {
String str(key->data(), key->size(), CopyString);
throwUnexpectedType(str, obj, type);
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwArraySizeOutOfBounds() {
throw Exception("Array size out of bounds");
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwInvalidKey() {
throw Exception("Invalid key");
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwUnterminatedElement() {
throw Exception("Array element not terminated properly");
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwLargeStringSize(int64_t size) {
throw Exception("Size of serialized string (%ld) exceeds max", size);
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwNegativeStringSize(int64_t size) {
throw Exception("Size of serialized string (%ld) must not be negative", size);
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwBadFormat(const ObjectData* obj, char type) {
throw Exception("%s does not support the '%c' serialization format",
header_names[(int)obj->headerKind()], type);
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwInvalidHashKey(const ObjectData* obj) {
throw Exception("%s values must be integers or strings",
header_names[(int)obj->headerKind()]);
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwColRKey() {
throw Exception("Referring to collection keys using the 'r' encoding "
"is not supported");
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwColRefValue() {
throw Exception("Collection values cannot be taken by reference");
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwColRefKey() {
throw Exception("Collection keys cannot be taken by reference");
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwUnexpectedEOB() {
throw Exception("Unexpected end of buffer during unserialization");
}
Expand Down
8 changes: 4 additions & 4 deletions hphp/runtime/ext/asio/ext_await-all-wait-handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ req::ptr<c_AwaitAllWaitHandle> c_AwaitAllWaitHandle::Alloc(int32_t cnt) {
namespace {
StaticString s_awaitAll("<await-all>");

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void failArray() {
SystemLib::throwInvalidArgumentExceptionObject(
"Expected dependencies to be an array");
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void failMap() {
SystemLib::throwInvalidArgumentExceptionObject(
"Expected dependencies to be a Map");
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void failVector() {
SystemLib::throwInvalidArgumentExceptionObject(
"Expected dependencies to be a Vector");
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void failWaitHandle() {
SystemLib::throwInvalidArgumentExceptionObject(
"Expected dependencies to be a collection of WaitHandle instances");
Expand Down
4 changes: 2 additions & 2 deletions hphp/runtime/ext/asio/ext_condition-wait-handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ namespace {
"ConditionWaitHandle not notified by its child");
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwNotNotifiedException() {
SystemLib::throwInvalidArgumentExceptionObject(
"ConditionWaitHandle not notified by its child");
}

NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void failAlreadyFinished() {
SystemLib::throwInvalidArgumentExceptionObject(
"Unable to notify ConditionWaitHandle that has already finished");
Expand Down
2 changes: 1 addition & 1 deletion hphp/runtime/ext/asio/ext_waitable-wait-handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct c_WaitableWaitHandle : c_WaitHandle {
void detectCycle(c_WaitableWaitHandle* child) const;

private:
NEVER_INLINE ATTRIBUTE_NORETURN
[[noreturn]] NEVER_INLINE
void throwCycleException(c_WaitableWaitHandle* child) const;
};

Expand Down
4 changes: 2 additions & 2 deletions hphp/runtime/ext/collections/ext_collections-idl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const Cell container_as_cell(const Variant& container) {

///////////////////////////////////////////////////////////////////////////////

ATTRIBUTE_NORETURN
[[noreturn]]
static void throwIntOOB(int64_t key, bool isVector = false);

void throwIntOOB(int64_t key, bool isVector /* = false */) {
Expand All @@ -84,7 +84,7 @@ void throwOOB(int64_t key) {
throwIntOOB(key, true);
}

ATTRIBUTE_NORETURN static void throwStrOOB(StringData* key);
[[noreturn]] static void throwStrOOB(StringData* key);

void throwStrOOB(StringData* key) {
constexpr size_t maxDisplaySize = 100;
Expand Down
Loading

0 comments on commit ca92861

Please sign in to comment.