diff options
37 files changed, 217 insertions, 1142 deletions
diff --git a/include/llvm/Object/Error.h b/include/llvm/Object/Error.h index 5359f498b2..15824f8e11 100644 --- a/include/llvm/Object/Error.h +++ b/include/llvm/Object/Error.h @@ -35,8 +35,11 @@ inline error_code make_error_code(object_error e) { } // end namespace object. -template <> struct is_error_code_enum<object::object_error> : std::true_type {}; - } // end namespace llvm. +namespace std { +template <> +struct is_error_code_enum<llvm::object::object_error> : std::true_type {}; +} + #endif diff --git a/include/llvm/ProfileData/InstrProf.h b/include/llvm/ProfileData/InstrProf.h index b08084cd68..755ba36bca 100644 --- a/include/llvm/ProfileData/InstrProf.h +++ b/include/llvm/ProfileData/InstrProf.h @@ -42,8 +42,11 @@ inline error_code make_error_code(instrprof_error E) { return error_code(static_cast<int>(E), instrprof_category()); } -template <> struct is_error_code_enum<instrprof_error> : std::true_type {}; - } // end namespace llvm +namespace std { +template <> +struct is_error_code_enum<llvm::instrprof_error> : std::true_type {}; +} + #endif // LLVM_PROFILEDATA_INSTRPROF_H_ diff --git a/include/llvm/Support/FileOutputBuffer.h b/include/llvm/Support/FileOutputBuffer.h index a8a48fa3fe..40a883ab3b 100644 --- a/include/llvm/Support/FileOutputBuffer.h +++ b/include/llvm/Support/FileOutputBuffer.h @@ -20,8 +20,6 @@ #include "llvm/Support/FileSystem.h" namespace llvm { -class error_code; - /// FileOutputBuffer - This interface provides simple way to create an in-memory /// buffer which will be written to a file. During the lifetime of these /// objects, the content or existence of the specified file is undefined. That diff --git a/include/llvm/Support/MemoryBuffer.h b/include/llvm/Support/MemoryBuffer.h index 5810c47beb..ddb1a992d1 100644 --- a/include/llvm/Support/MemoryBuffer.h +++ b/include/llvm/Support/MemoryBuffer.h @@ -19,12 +19,10 @@ #include "llvm/Support/CBindingWrapping.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/DataTypes.h" +#include "llvm/Support/system_error.h" #include <memory> namespace llvm { - -class error_code; - /// MemoryBuffer - This interface provides simple read-only access to a block /// of memory, and provides simple methods for reading files and standard input /// into a memory buffer. In addition to basic access to the characters in the diff --git a/include/llvm/Support/Program.h b/include/llvm/Support/Program.h index 9160b7dd92..4cf90ab732 100644 --- a/include/llvm/Support/Program.h +++ b/include/llvm/Support/Program.h @@ -19,7 +19,6 @@ #include "llvm/Support/system_error.h" namespace llvm { -class error_code; namespace sys { /// This is the OS-specific separator for PATH like environment variables: diff --git a/include/llvm/Support/WindowsError.h b/include/llvm/Support/WindowsError.h new file mode 100644 index 0000000000..5fae79eeeb --- /dev/null +++ b/include/llvm/Support/WindowsError.h @@ -0,0 +1,21 @@ +//===-- WindowsError.h - Support for mapping windows errors to posix-------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_SUPPORT_WINDOWS_ERROR_H +#define LLVM_SUPPORT_WINDOWS_ERROR_H + +#ifdef _MSC_VER +#include <system_error> + +namespace llvm { +std::error_code mapWindowsError(unsigned EV); +} +#endif + +#endif diff --git a/include/llvm/Support/system_error.h b/include/llvm/Support/system_error.h index dd67d4f79d..9aa00d8745 100644 --- a/include/llvm/Support/system_error.h +++ b/include/llvm/Support/system_error.h @@ -7,790 +7,24 @@ // //===----------------------------------------------------------------------===// // -// This was lifted from libc++ and modified for C++03. This is called -// system_error even though it does not define that class because that's what -// it's called in C++0x. We don't define system_error because it is only used -// for exception handling, which we don't use in LLVM. +// This is a temporary file to help with the transition to std::error_code. // //===----------------------------------------------------------------------===// #ifndef LLVM_SUPPORT_SYSTEM_ERROR_H #define LLVM_SUPPORT_SYSTEM_ERROR_H -#include "llvm/Support/Compiler.h" - -/* - system_error synopsis - -namespace std -{ - -class error_category -{ -public: - virtual ~error_category(); - - error_category(const error_category&) = delete; - error_category& operator=(const error_category&) = delete; - - virtual const char* name() const = 0; - virtual error_condition default_error_condition(int ev) const; - virtual bool equivalent(int code, const error_condition& condition) const; - virtual bool equivalent(const error_code& code, int condition) const; - virtual std::string message(int ev) const = 0; - - bool operator==(const error_category& rhs) const; - bool operator!=(const error_category& rhs) const; - bool operator<(const error_category& rhs) const; -}; - -const error_category& generic_category(); -const error_category& system_category(); - -template <class T> struct is_error_code_enum - : public std::false_type {}; - -template <class T> struct is_error_condition_enum - : public std::false_type {}; - -class error_code -{ -public: - // constructors: - error_code(); - error_code(int val, const error_category& cat); - template <class ErrorCodeEnum> - error_code(ErrorCodeEnum e); - - // modifiers: - void assign(int val, const error_category& cat); - template <class ErrorCodeEnum> - error_code& operator=(ErrorCodeEnum e); - void clear(); - - // observers: - int value() const; - const error_category& category() const; - error_condition default_error_condition() const; - std::string message() const; - explicit operator bool() const; -}; - -// non-member functions: -bool operator<(const error_code& lhs, const error_code& rhs); -template <class charT, class traits> - basic_ostream<charT,traits>& - operator<<(basic_ostream<charT,traits>& os, const error_code& ec); - -class error_condition -{ -public: - // constructors: - error_condition(); - error_condition(int val, const error_category& cat); - template <class ErrorConditionEnum> - error_condition(ErrorConditionEnum e); - - // modifiers: - void assign(int val, const error_category& cat); - template <class ErrorConditionEnum> - error_condition& operator=(ErrorConditionEnum e); - void clear(); - - // observers: - int value() const; - const error_category& category() const; - std::string message() const; - explicit operator bool() const; -}; - -bool operator<(const error_condition& lhs, const error_condition& rhs); - -class system_error - : public runtime_error -{ -public: - system_error(error_code ec, const std::string& what_arg); - system_error(error_code ec, const char* what_arg); - system_error(error_code ec); - system_error(int ev, const error_category& ecat, const std::string& what_arg); - system_error(int ev, const error_category& ecat, const char* what_arg); - system_error(int ev, const error_category& ecat); - - const error_code& code() const throw(); - const char* what() const throw(); -}; - -enum class errc -{ - address_family_not_supported, // EAFNOSUPPORT - address_in_use, // EADDRINUSE - address_not_available, // EADDRNOTAVAIL - already_connected, // EISCONN - argument_list_too_long, // E2BIG - argument_out_of_domain, // EDOM - bad_address, // EFAULT - bad_file_descriptor, // EBADF - bad_message, // EBADMSG - broken_pipe, // EPIPE - connection_aborted, // ECONNABORTED - connection_already_in_progress, // EALREADY - connection_refused, // ECONNREFUSED - connection_reset, // ECONNRESET - cross_device_link, // EXDEV - destination_address_required, // EDESTADDRREQ - device_or_resource_busy, // EBUSY - directory_not_empty, // ENOTEMPTY - executable_format_error, // ENOEXEC - file_exists, // EEXIST - file_too_large, // EFBIG - filename_too_long, // ENAMETOOLONG - function_not_supported, // ENOSYS - host_unreachable, // EHOSTUNREACH - identifier_removed, // EIDRM - illegal_byte_sequence, // EILSEQ - inappropriate_io_control_operation, // ENOTTY - interrupted, // EINTR - invalid_argument, // EINVAL - invalid_seek, // ESPIPE - io_error, // EIO - is_a_directory, // EISDIR - message_size, // EMSGSIZE - network_down, // ENETDOWN - network_reset, // ENETRESET - network_unreachable, // ENETUNREACH - no_buffer_space, // ENOBUFS - no_child_process, // ECHILD - no_link, // ENOLINK - no_lock_available, // ENOLCK - no_message_available, // ENODATA - no_message, // ENOMSG - no_protocol_option, // ENOPROTOOPT - no_space_on_device, // ENOSPC - no_stream_resources, // ENOSR - no_such_device_or_address, // ENXIO - no_such_device, // ENODEV - no_such_file_or_directory, // ENOENT - no_such_process, // ESRCH - not_a_directory, // ENOTDIR - not_a_socket, // ENOTSOCK - not_a_stream, // ENOSTR - not_connected, // ENOTCONN - not_enough_memory, // ENOMEM - not_supported, // ENOTSUP - operation_canceled, // ECANCELED - operation_in_progress, // EINPROGRESS - operation_not_permitted, // EPERM - operation_not_supported, // EOPNOTSUPP - operation_would_block, // EWOULDBLOCK - owner_dead, // EOWNERDEAD - permission_denied, // EACCES - protocol_error, // EPROTO - protocol_not_supported, // EPROTONOSUPPORT - read_only_file_system, // EROFS - resource_deadlock_would_occur, // EDEADLK - resource_unavailable_try_again, // EAGAIN - result_out_of_range, // ERANGE - state_not_recoverable, // ENOTRECOVERABLE - stream_timeout, // ETIME - text_file_busy, // ETXTBSY - timed_out, // ETIMEDOUT - too_many_files_open_in_system, // ENFILE - too_many_files_open, // EMFILE - too_many_links, // EMLINK - too_many_symbolic_link_levels, // ELOOP - value_too_large, // EOVERFLOW - wrong_protocol_type // EPROTOTYPE -}; - -template <> struct is_error_condition_enum<errc> : std::true_type { } - -error_code make_error_code(errc e); -error_condition make_error_condition(errc e); - -// Comparison operators: -bool operator==(const error_code& lhs, const error_code& rhs); -bool operator==(const error_code& lhs, const error_condition& rhs); -bool operator==(const error_condition& lhs, const error_code& rhs); -bool operator==(const error_condition& lhs, const error_condition& rhs); -bool operator!=(const error_code& lhs, const error_code& rhs); -bool operator!=(const error_code& lhs, const error_condition& rhs); -bool operator!=(const error_condition& lhs, const error_code& rhs); -bool operator!=(const error_condition& lhs, const error_condition& rhs); - -template <> struct hash<std::error_code>; - -} // std - -*/ - -#include "llvm/Config/llvm-config.h" -#include <cerrno> -#include <string> - -// This must be here instead of a .inc file because it is used in the definition -// of the enum values below. -#ifdef LLVM_ON_WIN32 - - // The following numbers were taken from VS2010. -# ifndef EAFNOSUPPORT -# define EAFNOSUPPORT 102 -# endif -# ifndef EADDRINUSE -# define EADDRINUSE 100 -# endif -# ifndef EADDRNOTAVAIL -# define EADDRNOTAVAIL 101 -# endif -# ifndef EISCONN -# define EISCONN 113 -# endif -# ifndef E2BIG -# define E2BIG 7 -# endif -# ifndef EDOM -# define EDOM 33 -# endif -# ifndef EFAULT -# define EFAULT 14 -# endif -# ifndef EBADF -# define EBADF 9 -# endif -# ifndef EBADMSG -# define EBADMSG 104 -# endif -# ifndef EPIPE -# define EPIPE 32 -# endif -# ifndef ECONNABORTED -# define ECONNABORTED 106 -# endif -# ifndef EALREADY -# define EALREADY 103 -# endif -# ifndef ECONNREFUSED -# define ECONNREFUSED 107 -# endif -# ifndef ECONNRESET -# define ECONNRESET 108 -# endif -# ifndef EXDEV -# define EXDEV 18 -# endif -# ifndef EDESTADDRREQ -# define EDESTADDRREQ 109 -# endif -# ifndef EBUSY -# define EBUSY 16 -# endif -# ifndef ENOTEMPTY -# define ENOTEMPTY 41 -# endif -# ifndef ENOEXEC -# define ENOEXEC 8 -# endif -# ifndef EEXIST -# define EEXIST 17 -# endif -# ifndef EFBIG -# define EFBIG 27 -# endif -# ifndef ENAMETOOLONG -# define ENAMETOOLONG 38 -# endif -# ifndef ENOSYS -# define ENOSYS 40 -# endif -# ifndef EHOSTUNREACH -# define EHOSTUNREACH 110 -# endif -# ifndef EIDRM -# define EIDRM 111 -# endif -# ifndef EILSEQ -# define EILSEQ 42 -# endif -# ifndef ENOTTY -# define ENOTTY 25 -# endif -# ifndef EINTR -# define EINTR 4 -# endif -# ifndef EINVAL -# define EINVAL 22 -# endif -# ifndef ESPIPE -# define ESPIPE 29 -# endif -# ifndef EIO -# define EIO 5 -# endif -# ifndef EISDIR -# define EISDIR 21 -# endif -# ifndef EMSGSIZE -# define EMSGSIZE 115 -# endif -# ifndef ENETDOWN -# define ENETDOWN 116 -# endif -# ifndef ENETRESET -# define ENETRESET 117 -# endif -# ifndef ENETUNREACH -# define ENETUNREACH 118 -# endif -# ifndef ENOBUFS -# define ENOBUFS 119 -# endif -# ifndef ECHILD -# define ECHILD 10 -# endif -# ifndef ENOLINK -# define ENOLINK 121 -# endif -# ifndef ENOLCK -# define ENOLCK 39 -# endif -# ifndef ENODATA -# define ENODATA 120 -# endif -# ifndef ENOMSG -# define ENOMSG 122 -# endif -# ifndef ENOPROTOOPT -# define ENOPROTOOPT 123 -# endif -# ifndef ENOSPC -# define ENOSPC 28 -# endif -# ifndef ENOSR -# define ENOSR 124 -# endif -# ifndef ENXIO -# define ENXIO 6 -# endif -# ifndef ENODEV -# define ENODEV 19 -# endif -# ifndef ENOENT -# define ENOENT 2 -# endif -# ifndef ESRCH -# define ESRCH 3 -# endif -# ifndef ENOTDIR -# define ENOTDIR 20 -# endif -# ifndef ENOTSOCK -# define ENOTSOCK 128 -# endif -# ifndef ENOSTR -# define ENOSTR 125 -# endif -# ifndef ENOTCONN -# define ENOTCONN 126 -# endif -# ifndef ENOMEM -# define ENOMEM 12 -# endif -# ifndef ENOTSUP -# define ENOTSUP 129 -# endif -# ifndef ECANCELED -# define ECANCELED 105 -# endif -# ifndef EINPROGRESS -# define EINPROGRESS 112 -# endif -# ifndef EPERM -# define EPERM 1 -# endif -# ifndef EOPNOTSUPP -# define EOPNOTSUPP 130 -# endif -# ifndef EWOULDBLOCK -# define EWOULDBLOCK 140 -# endif -# ifndef EOWNERDEAD -# define EOWNERDEAD 133 -# endif -# ifndef EACCES -# define EACCES 13 -# endif -# ifndef EPROTO -# define EPROTO 134 -# endif -# ifndef EPROTONOSUPPORT -# define EPROTONOSUPPORT 135 -# endif -# ifndef EROFS -# define EROFS 30 -# endif -# ifndef EDEADLK -# define EDEADLK 36 -# endif -# ifndef EAGAIN -# define EAGAIN 11 -# endif -# ifndef ERANGE -# define ERANGE 34 -# endif -# ifndef ENOTRECOVERABLE -# define ENOTRECOVERABLE 127 -# endif -# ifndef ETIME -# define ETIME 137 -# endif -# ifndef ETXTBSY -# define ETXTBSY 139 -# endif -# ifndef ETIMEDOUT -# define ETIMEDOUT 138 -# endif -# ifndef ENFILE -# define ENFILE 23 -# endif -# ifndef EMFILE -# define EMFILE 24 -# endif -# ifndef EMLINK -# define EMLINK 31 -# endif -# ifndef ELOOP -# define ELOOP 114 -# endif -# ifndef EOVERFLOW -# define EOVERFLOW 132 -# endif -# ifndef EPROTOTYPE -# define EPROTOTYPE 136 -# endif -#endif +#include <system_error> namespace llvm { - -// is_error_code_enum - -template <class Tp> struct is_error_code_enum : public std::false_type {}; - -// is_error_condition_enum - -template <class Tp> struct is_error_condition_enum : public std::false_type {}; - -// Some error codes are not present on all platforms, so we provide equivalents -// for them: - -enum class errc { - address_family_not_supported = EAFNOSUPPORT, - address_in_use = EADDRINUSE, - address_not_available = EADDRNOTAVAIL, - already_connected = EISCONN, - argument_list_too_long = E2BIG, - argument_out_of_domain = EDOM, - bad_address = EFAULT, - bad_file_descriptor = EBADF, -#ifdef EBADMSG - bad_message = EBADMSG, -#else - bad_message = EINVAL, -#endif - broken_pipe = EPIPE, - connection_aborted = ECONNABORTED, - connection_already_in_progress = EALREADY, - connection_refused = ECONNREFUSED, - connection_reset = ECONNRESET, - cross_device_link = EXDEV, - destination_address_required = EDESTADDRREQ, - device_or_resource_busy = EBUSY, - directory_not_empty = ENOTEMPTY, - executable_format_error = ENOEXEC, - file_exists = EEXIST, - file_too_large = EFBIG, - filename_too_long = ENAMETOOLONG, - function_not_supported = ENOSYS, - host_unreachable = EHOSTUNREACH, - identifier_removed = EIDRM, - illegal_byte_sequence = EILSEQ, - inappropriate_io_control_operation = ENOTTY, - interrupted = EINTR, - invalid_argument = EINVAL, - invalid_seek = ESPIPE, - io_error = EIO, - is_a_directory = EISDIR, - message_size = EMSGSIZE, - network_down = ENETDOWN, - network_reset = ENETRESET, - network_unreachable = ENETUNREACH, - no_buffer_space = ENOBUFS, - no_child_process = ECHILD, -#ifdef ENOLINK - no_link = ENOLINK, -#else - no_link = EINVAL, -#endif - no_lock_available = ENOLCK, -#ifdef ENODATA - no_message_available = ENODATA, -#else - no_message_available = ENOMSG, -#endif - no_message = ENOMSG, - no_protocol_option = ENOPROTOOPT, - no_space_on_device = ENOSPC, -#ifdef ENOSR - no_stream_resources = ENOSR, -#else - no_stream_resources = ENOMEM, -#endif - no_such_device_or_address = ENXIO, - no_such_device = ENODEV, - no_such_file_or_directory = ENOENT, - no_such_process = ESRCH, - not_a_directory = ENOTDIR, - not_a_socket = ENOTSOCK, -#ifdef ENOSTR - not_a_stream = ENOSTR, -#else - not_a_stream = EINVAL, -#endif - not_connected = ENOTCONN, - not_enough_memory = ENOMEM, - not_supported = ENOTSUP, -#ifdef ECANCELED - operation_canceled = ECANCELED, -#else - operation_canceled = EINVAL, -#endif - operation_in_progress = EINPROGRESS, - operation_not_permitted = EPERM, - operation_not_supported = EOPNOTSUPP, - operation_would_block = EWOULDBLOCK, -#ifdef EOWNERDEAD - owner_dead = EOWNERDEAD, -#else - owner_dead = EINVAL, -#endif - permission_denied = EACCES, -#ifdef EPROTO - protocol_error = EPROTO, -#else - protocol_error = EINVAL, -#endif - protocol_not_supported = EPROTONOSUPPORT, - read_only_file_system = EROFS, - resource_deadlock_would_occur = EDEADLK, - resource_unavailable_try_again = EAGAIN, - result_out_of_range = ERANGE, -#ifdef ENOTRECOVERABLE - state_not_recoverable = ENOTRECOVERABLE, -#else - state_not_recoverable = EINVAL, -#endif -#ifdef ETIME - stream_timeout = ETIME, -#else - stream_timeout = ETIMEDOUT, -#endif - text_file_busy = ETXTBSY, - timed_out = ETIMEDOUT, - too_many_files_open_in_system = ENFILE, - too_many_files_open = EMFILE, - too_many_links = EMLINK, - too_many_symbolic_link_levels = ELOOP, - value_too_large = EOVERFLOW, - wrong_protocol_type = EPROTOTYPE -}; - - -template <> struct is_error_condition_enum<errc> : std::true_type { }; - -class error_condition; -class error_code; - -// class error_category - -class _do_message; - -class error_category -{ -public: - virtual ~error_category(); - - error_category(); -private: - error_category(const error_category&) LLVM_DELETED_FUNCTION; - error_category& operator=(const error_category&) LLVM_DELETED_FUNCTION; - -public: - virtual const char* name() const LLVM_NOEXCEPT = 0; - virtual error_condition default_error_condition(int _ev) const LLVM_NOEXCEPT; - virtual bool - equivalent(int _code, const error_condition &_condition) const LLVM_NOEXCEPT; - virtual bool equivalent(const error_code &_code, - int _condition) const LLVM_NOEXCEPT; - virtual std::string message(int _ev) const = 0; - - bool operator==(const error_category& _rhs) const {return this == &_rhs;} - - bool operator!=(const error_category& _rhs) const {return !(*this == _rhs);} - - bool operator< (const error_category& _rhs) const {return this < &_rhs;} - - friend class _do_message; -}; - -class _do_message : public error_category -{ -public: - std::string message(int ev) const override; -}; - -const error_category& generic_category(); -const error_category& system_category(); - -class error_condition -{ - int _val_; - const error_category* _cat_; -public: - error_condition() : _val_(0), _cat_(&generic_category()) {} - - error_condition(int _val, const error_category& _cat) - : _val_(_val), _cat_(&_cat) {} - - template <class E> - error_condition(E _e, typename std::enable_if< - is_error_condition_enum<E>::value - >::type* = 0) - {*this = make_error_condition(_e);} - - void assign(int _val, const error_category& _cat) { - _val_ = _val; - _cat_ = &_cat; - } - - template <class E> - typename std::enable_if<is_error_condition_enum<E>::value, - error_condition &>::type - operator=(E _e) { - *this = make_error_condition(_e); - return *this; - } - - void clear() { - _val_ = 0; - _cat_ = &generic_category(); - } - - int value() const {return _val_;} - - const error_category& category() const {return *_cat_;} - std::string message() const; - - LLVM_EXPLICIT operator bool() const { return _val_ != 0; } -}; - -inline error_condition make_error_condition(errc _e) { - return error_condition(static_cast<int>(_e), generic_category()); -} - -inline bool operator<(const error_condition& _x, const error_condition& _y) { - return _x.category() < _y.category() - || (_x.category() == _y.category() && _x.value() < _y.value()); -} - -// error_code - -class error_code { - int _val_; - const error_category* _cat_; -public: - error_code() : _val_(0), _cat_(&system_category()) {} - - error_code(int _val, const error_category& _cat) - : _val_(_val), _cat_(&_cat) {} - - template <class E> - error_code(E _e, typename std::enable_if< - is_error_code_enum<E>::value - >::type* = 0) { - *this = make_error_code(_e); - } - - void assign(int _val, const error_category& _cat) { - _val_ = _val; - _cat_ = &_cat; - } - - template <class E> - typename std::enable_if<is_error_code_enum<E>::value, error_code &>::type - operator=(E _e) { - *this = make_error_code(_e); - return *this; - } - - void clear() { - _val_ = 0; - _cat_ = &system_category(); - } - - int value() const {return _val_;} - - const error_category& category() const {return *_cat_;} - - error_condition default_error_condition() const - {return _cat_->default_error_condition(_val_);} - - std::string message() const; - - LLVM_EXPLICIT operator bool() const { - return _val_ != 0; - } -}; - -inline error_code make_error_code(errc _e) { - return error_code(static_cast<int>(_e), generic_category()); -} - -inline bool operator<(const error_code& _x, const error_code& _y) { - return _x.category() < _y.category() - || (_x.category() == _y.category() && _x.value() < _y.value()); -} - -inline bool operator==(const error_code& _x, const error_code& _y) { - return _x.category() == _y.category() && _x.value() == _y.value(); -} - -inline bool operator==(const error_code& _x, const error_condition& _y) { - return _x.category().equivalent(_x.value(), _y) - || _y.category().equivalent(_x, _y.value()); -} - -inline bool operator==(const error_condition& _x, const error_code& _y) { - return _y == _x; -} - -inline bool operator==(const error_condition& _x, const error_condition& _y) { - return _x.category() == _y.category() && _x.value() == _y.value(); -} - -inline bool operator!=(const error_code& _x, const error_code& _y) { - return !(_x == _y); -} - -inline bool operator!=(const error_code& _x, const error_condition& _y) { - return !(_x == _y); -} - -inline bool operator!=(const error_condition& _x, const error_code& _y) { - return !(_x == _y); -} - -inline bool operator!=(const error_condition& _x, const error_condition& _y) { - return !(_x == _y); +using std::error_code; +using std::is_error_condition_enum; +using std::is_error_code_enum; +using std::system_category; +using std::generic_category; +using std::error_category; +using std::make_error_code; +using std::error_condition; } -} // end namespace llvm #endif diff --git a/lib/Object/Error.cpp b/lib/Object/Error.cpp index 6bcc6f9a78..a373cff195 100644 --- a/lib/Object/Error.cpp +++ b/lib/Object/Error.cpp @@ -50,7 +50,7 @@ std::string _object_error_category::message(int EV) const { error_condition _object_error_category::default_error_condition(int EV) const { if (static_cast<object_error>(EV) == object_error::success) return error_condition(); - return errc::invalid_argument; + return std::errc::invalid_argument; } const error_category &object::object_category() { diff --git a/lib/ProfileData/InstrProf.cpp b/lib/ProfileData/InstrProf.cpp index 94a79e9ed0..eed517df05 100644 --- a/lib/ProfileData/InstrProf.cpp +++ b/lib/ProfileData/InstrProf.cpp @@ -55,7 +55,7 @@ class InstrProfErrorCategoryType : public error_category { error_condition default_error_condition(int EV) const LLVM_NOEXCEPT override { if (static_cast<instrprof_error>(EV) == instrprof_error::success) return error_condition(); - return errc::invalid_argument; + return std::errc::invalid_argument; } }; } diff --git a/lib/Support/CMakeLists.txt b/lib/Support/CMakeLists.txt index 7f93a6c595..9febb84f2b 100644 --- a/lib/Support/CMakeLists.txt +++ b/lib/Support/CMakeLists.txt @@ -83,13 +83,13 @@ add_llvm_library(LLVMSupport RWMutex.cpp SearchForAddressOfSpecialSymbol.cpp Signals.cpp - system_error.cpp TargetRegistry.cpp ThreadLocal.cpp Threading.cpp TimeValue.cpp Valgrind.cpp Watchdog.cpp + WindowsError.cpp ADDITIONAL_HEADERS Unix/Host.inc @@ -100,7 +100,6 @@ add_llvm_library(LLVMSupport Unix/Program.inc Unix/RWMutex.inc Unix/Signals.inc - Unix/system_error.inc Unix/ThreadLocal.inc Unix/TimeValue.inc Unix/Watchdog.inc @@ -113,7 +112,6 @@ add_llvm_library(LLVMSupport Windows/Program.inc Windows/RWMutex.inc Windows/Signals.inc - Windows/system_error.inc Windows/ThreadLocal.inc Windows/TimeValue.inc Windows/Watchdog.inc diff --git a/lib/Support/FileOutputBuffer.cpp b/lib/Support/FileOutputBuffer.cpp index 5f74d00c6b..b869054338 100644 --- a/lib/Support/FileOutputBuffer.cpp +++ b/lib/Support/FileOutputBuffer.cpp @@ -51,7 +51,7 @@ error_code FileOutputBuffer::create(StringRef FilePath, if (EC) return EC; else - return make_error_code(errc::operation_not_permitted); + return make_error_code(std::errc::operation_not_permitted); } // Delete target file. diff --git a/lib/Support/LockFileManager.cpp b/lib/Support/LockFileManager.cpp index 05e75cff1a..2b7fc812d5 100644 --- a/lib/Support/LockFileManager.cpp +++ b/lib/Support/LockFileManager.cpp @@ -114,7 +114,7 @@ LockFileManager::LockFileManager(StringRef FileName) if (Out.has_error()) { // We failed to write out PID, so make up an excuse, remove the // unique lock file, and fail. - Error = make_error_code(errc::no_space_on_device); + Error = make_error_code(std::errc::no_space_on_device); sys::fs::remove(UniqueLockFileName.c_str()); return; } @@ -127,7 +127,7 @@ LockFileManager::LockFileManager(StringRef FileName) if (!EC) return; - if (EC != errc::file_exists) { + if (EC != std::errc::file_exists) { Error = EC; return; } diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp index b7298090db..1f69326a1d 100644 --- a/lib/Support/MemoryBuffer.cpp +++ b/lib/Support/MemoryBuffer.cpp @@ -361,7 +361,7 @@ static error_code getOpenFileImpl(int FD, const char *Filename, if (!Buf) { // Failed to create a buffer. The only way it can fail is if // new(std::nothrow) returns 0. - return make_error_code(errc::not_enough_memory); + return make_error_code(std::errc::not_enough_memory); } std::unique_ptr<MemoryBuffer> SB(Buf); diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index 76bee47984..a9ac88e5d3 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -204,7 +204,7 @@ retry_random_path: if (error_code EC = sys::fs::openFileForWrite(Twine(ResultPath.begin()), ResultFD, sys::fs::F_RW | sys::fs::F_Excl, Mode)) { - if (EC == errc::file_exists) + if (EC == std::errc::file_exists) goto retry_random_path; return EC; } @@ -224,7 +224,7 @@ retry_random_path: case FS_Dir: { if (error_code EC = sys::fs::create_directory(ResultPath.begin(), false)) { - if (EC == errc::file_exists) + if (EC == std::errc::file_exists) goto retry_random_path; return EC; } @@ -829,7 +829,7 @@ error_code create_directories(const Twine &Path, bool IgnoreExisting) { error_code EC = create_directory(P, IgnoreExisting); // If we succeeded, or had any error other than the parent not existing, just // return it. - if (EC != errc::no_such_file_or_directory) + if (EC != std::errc::no_such_file_or_directory) return EC; // We failed because of a no_such_file_or_directory, try to create the @@ -896,7 +896,7 @@ error_code has_magic(const Twine &path, const Twine &magic, bool &result) { SmallString<32> Buffer; if (error_code ec = get_magic(path, Magic.size(), Buffer)) { - if (ec == errc::value_too_large) { + if (ec == std::errc::value_too_large) { // Magic.size() > file_size(Path). result = false; return error_code(); @@ -1043,7 +1043,7 @@ error_code has_magic(const Twine &path, const Twine &magic, bool &result) { error_code identify_magic(const Twine &path, file_magic &result) { SmallString<32> Magic; error_code ec = get_magic(path, Magic.capacity(), Magic); - if (ec && ec != errc::value_too_large) + if (ec && ec != std::errc::value_too_large) return ec; result = identify_magic(Magic); diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc index 11ea10e120..ef291db52d 100644 --- a/lib/Support/Unix/Path.inc +++ b/lib/Support/Unix/Path.inc @@ -317,7 +317,7 @@ error_code remove(const Twine &path, bool IgnoreNonExisting) { // effectively prevents LLVM from erasing things like /dev/null, any block // special file, or other things that aren't "regular" files. if (!S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode) && !S_ISLNK(buf.st_mode)) - return make_error_code(errc::operation_not_permitted); + return make_error_code(std::errc::operation_not_permitted); if (::remove(p.begin()) == -1) { if (errno != ENOENT || !IgnoreNonExisting) @@ -402,7 +402,7 @@ static error_code fillStatus(int StatRet, const struct stat &Status, file_status &Result) { if (StatRet != 0) { error_code ec(errno, generic_category()); - if (ec == errc::no_such_file_or_directory) + if (ec == std::errc::no_such_file_or_directory) Result = file_status(file_type::file_not_found); else Result = file_status(file_type::status_error); @@ -466,7 +466,7 @@ error_code setLastModificationAndAccessTime(int FD, TimeValue Time) { return error_code(); #else #warning Missing futimes() and futimens() - return make_error_code(errc::not_supported); + return make_error_code(std::errc::not_supported); #endif } @@ -510,7 +510,7 @@ mapped_file_region::mapped_file_region(const Twine &path, , Mapping() { // Make sure that the requested size fits within SIZE_T. if (length > std::numeric_limits<size_t>::max()) { - ec = make_error_code(errc::invalid_argument); + ec = make_error_code(std::errc::invalid_argument); return; } @@ -539,7 +539,7 @@ mapped_file_region::mapped_file_region(int fd, , Mapping() { // Make sure that the requested size fits within SIZE_T. if (length > std::numeric_limits<size_t>::max()) { - ec = make_error_code(errc::invalid_argument); + ec = make_error_code(std::errc::invalid_argument); return; } @@ -645,7 +645,7 @@ error_code get_magic(const Twine &path, uint32_t len, if (std::feof(file) != 0) { std::fclose(file); result.set_size(size); - return make_error_code(errc::value_too_large); + return make_error_code(std::errc::value_too_large); } } std::fclose(file); diff --git a/lib/Support/Unix/system_error.inc b/lib/Support/Unix/system_error.inc deleted file mode 100644 index 681e919edb..0000000000 --- a/lib/Support/Unix/system_error.inc +++ /dev/null @@ -1,34 +0,0 @@ -//===- llvm/Support/Unix/system_error.inc - Unix error_code ------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file provides the Unix specific implementation of the error_code -// and error_condition classes. -// -//===----------------------------------------------------------------------===// - -//===----------------------------------------------------------------------===// -//=== WARNING: Implementation here must contain only generic UNIX code that -//=== is guaranteed to work on *all* UNIX variants. -//===----------------------------------------------------------------------===// - -using namespace llvm; - -std::string -_system_error_category::message(int ev) const { - return _do_message::message(ev); -} - -error_condition -_system_error_category::default_error_condition(int ev) const { -#ifdef ELAST - if (ev > ELAST) - return error_condition(ev, system_category()); -#endif // ELAST - return error_condition(ev, generic_category()); -} diff --git a/lib/Support/Windows/Path.inc b/lib/Support/Windows/Path.inc index a819156871..fb484778e6 100644 --- a/lib/Support/Windows/Path.inc +++ b/lib/Support/Windows/Path.inc @@ -17,6 +17,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/STLExtras.h" +#include "llvm/Support/WindowsError.h" #include <fcntl.h> #include <io.h> #include <sys/stat.h> @@ -45,7 +46,7 @@ using llvm::sys::windows::UTF8ToUTF16; using llvm::sys::windows::UTF16ToUTF8; static error_code windows_error(DWORD E) { - return error_code(E, system_category()); + return mapWindowsError(E); } static error_code TempDir(SmallVectorImpl<char> &Result) { @@ -193,7 +194,7 @@ error_code remove(const Twine &path, bool IgnoreNonExisting) { file_status ST; if (error_code EC = status(path, ST)) { - if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting) + if (EC != std::errc::no_such_file_or_directory || !IgnoreNonExisting) return EC; return error_code(); } @@ -205,14 +206,14 @@ error_code remove(const Twine &path, bool IgnoreNonExisting) { if (ST.type() == file_type::directory_file) { if (!::RemoveDirectoryW(c_str(path_utf16))) { error_code EC = windows_error(::GetLastError()); - if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting) + if (EC != std::errc::no_such_file_or_directory || !IgnoreNonExisting) return EC; } return error_code(); } if (!::DeleteFileW(c_str(path_utf16))) { error_code EC = windows_error(::GetLastError()); - if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting) + if (EC != std::errc::no_such_file_or_directory || !IgnoreNonExisting) return EC; } return error_code(); @@ -516,7 +517,7 @@ error_code mapped_file_region::init(int FD, bool CloseFD, uint64_t Offset) { _close(FileDescriptor); } else ::CloseHandle(FileHandle); - return make_error_code(errc::invalid_argument); + return make_error_code(std::errc::invalid_argument); } DWORD flprotect; @@ -652,7 +653,7 @@ mapped_file_region::mapped_file_region(int fd, if (closefd) _close(FileDescriptor); FileDescriptor = 0; - ec = make_error_code(errc::bad_file_descriptor); + ec = make_error_code(std::errc::bad_file_descriptor); return; } @@ -815,7 +816,7 @@ error_code openFileForRead(const Twine &Name, int &ResultFD) { if (LastError != ERROR_ACCESS_DENIED) return EC; if (is_directory(Name)) - return make_error_code(errc::is_a_directory); + return make_error_code(std::errc::is_a_directory); return EC; } @@ -867,7 +868,7 @@ error_code openFileForWrite(const Twine &Name, int &ResultFD, if (LastError != ERROR_ACCESS_DENIED) return EC; if (is_directory(Name)) - return make_error_code(errc::is_a_directory); + return make_error_code(std::errc::is_a_directory); return EC; } diff --git a/lib/Support/Windows/Process.inc b/lib/Support/Windows/Process.inc index 9707cf103f..0be871c695 100644 --- a/lib/Support/Windows/Process.inc +++ b/lib/Support/Windows/Process.inc @@ -13,6 +13,7 @@ #include "llvm/Support/Allocator.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/WindowsError.h" #include <malloc.h> // The Windows.h header must be after LLVM and standard headers. @@ -180,7 +181,7 @@ Optional<std::string> Process::GetEnv(StringRef Name) { } static error_code windows_error(DWORD E) { - return error_code(E, system_category()); + return mapWindowsError(E); } error_code diff --git a/lib/Support/Windows/system_error.inc b/lib/Support/Windows/system_error.inc deleted file mode 100644 index 89492efad3..0000000000 --- a/lib/Support/Windows/system_error.inc +++ /dev/null @@ -1,141 +0,0 @@ -//===- llvm/Support/Win32/system_error.inc - Windows error_code --*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file provides the Windows specific implementation of the error_code -// and error_condition classes. -// -//===----------------------------------------------------------------------===// - -//===----------------------------------------------------------------------===// -//=== WARNING: Implementation here must contain only generic Windows code that -//=== is guaranteed to work on *all* Windows variants. -//===----------------------------------------------------------------------===// - -#include <windows.h> -#include <winerror.h> - -using namespace llvm; - -std::string -_system_error_category::message(int ev) const { - LPVOID lpMsgBuf = 0; - DWORD retval = ::FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - ev, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPSTR) &lpMsgBuf, - 0, - NULL); - if (retval == 0) { - ::LocalFree(lpMsgBuf); - return std::string("Unknown error"); - } - - std::string str( static_cast<LPCSTR>(lpMsgBuf) ); - ::LocalFree(lpMsgBuf); - - while (str.size() - && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r')) - str.erase( str.size()-1 ); - if (str.size() && str[str.size()-1] == '.') - str.erase( str.size()-1 ); - return str; -} - -// I'd rather not double the line count of the following. -#define MAP_ERR_TO_COND(x, y) case x: return make_error_condition(errc::y) - -error_condition -_system_error_category::default_error_condition(int ev) const { - switch (ev) { - // Windows system -> posix_errno decode table ---------------------------// - // see WinError.h comments for descriptions of errors - MAP_ERR_TO_COND(ERROR_ACCESS_DENIED, permission_denied); - MAP_ERR_TO_COND(ERROR_ALREADY_EXISTS, file_exists); - MAP_ERR_TO_COND(ERROR_BAD_UNIT, no_such_device); - MAP_ERR_TO_COND(ERROR_BUFFER_OVERFLOW, filename_too_long); - MAP_ERR_TO_COND(ERROR_BUSY, device_or_resource_busy); - MAP_ERR_TO_COND(ERROR_BUSY_DRIVE, device_or_resource_busy); - MAP_ERR_TO_COND(ERROR_CANNOT_MAKE, permission_denied); - MAP_ERR_TO_COND(ERROR_CANTOPEN, io_error); - MAP_ERR_TO_COND(ERROR_CANTREAD, io_error); - MAP_ERR_TO_COND(ERROR_CANTWRITE, io_error); - MAP_ERR_TO_COND(ERROR_CURRENT_DIRECTORY, permission_denied); - MAP_ERR_TO_COND(ERROR_DEV_NOT_EXIST, no_such_device); - MAP_ERR_TO_COND(ERROR_DEVICE_IN_USE, device_or_resource_busy); - MAP_ERR_TO_COND(ERROR_DIR_NOT_EMPTY, directory_not_empty); - MAP_ERR_TO_COND(ERROR_DIRECTORY, invalid_argument); - MAP_ERR_TO_COND(ERROR_DISK_FULL, no_space_on_device); - MAP_ERR_TO_COND(ERROR_FILE_EXISTS, file_exists); - MAP_ERR_TO_COND(ERROR_FILE_NOT_FOUND, no_such_file_or_directory); - MAP_ERR_TO_COND(ERROR_HANDLE_DISK_FULL, no_space_on_device); - MAP_ERR_TO_COND(ERROR_HANDLE_EOF, value_too_large); - MAP_ERR_TO_COND(ERROR_INVALID_ACCESS, permission_denied); - MAP_ERR_TO_COND(ERROR_INVALID_DRIVE, no_such_device); - MAP_ERR_TO_COND(ERROR_INVALID_FUNCTION, function_not_supported); - MAP_ERR_TO_COND(ERROR_INVALID_HANDLE, invalid_argument); - MAP_ERR_TO_COND(ERROR_INVALID_NAME, invalid_argument); - MAP_ERR_TO_COND(ERROR_LOCK_VIOLATION, no_lock_available); - MAP_ERR_TO_COND(ERROR_LOCKED, no_lock_available); - MAP_ERR_TO_COND(ERROR_NEGATIVE_SEEK, invalid_argument); - MAP_ERR_TO_COND(ERROR_NOACCESS, permission_denied); - MAP_ERR_TO_COND(ERROR_NOT_ENOUGH_MEMORY, not_enough_memory); - MAP_ERR_TO_COND(ERROR_NOT_READY, resource_unavailable_try_again); - MAP_ERR_TO_COND(ERROR_NOT_SAME_DEVICE, cross_device_link); - MAP_ERR_TO_COND(ERROR_OPEN_FAILED, io_error); - MAP_ERR_TO_COND(ERROR_OPEN_FILES, device_or_resource_busy); - MAP_ERR_TO_COND(ERROR_OPERATION_ABORTED, operation_canceled); - MAP_ERR_TO_COND(ERROR_OUTOFMEMORY, not_enough_memory); - MAP_ERR_TO_COND(ERROR_PATH_NOT_FOUND, no_such_file_or_directory); - MAP_ERR_TO_COND(ERROR_BAD_NETPATH, no_such_file_or_directory); - MAP_ERR_TO_COND(ERROR_READ_FAULT, io_error); - MAP_ERR_TO_COND(ERROR_RETRY, resource_unavailable_try_again); - MAP_ERR_TO_COND(ERROR_SEEK, io_error); - MAP_ERR_TO_COND(ERROR_SHARING_VIOLATION, permission_denied); - MAP_ERR_TO_COND(ERROR_TOO_MANY_OPEN_FILES, too_many_files_open); - MAP_ERR_TO_COND(ERROR_WRITE_FAULT, io_error); - MAP_ERR_TO_COND(ERROR_WRITE_PROTECT, permission_denied); - MAP_ERR_TO_COND(ERROR_SEM_TIMEOUT, timed_out); - MAP_ERR_TO_COND(WSAEACCES, permission_denied); - MAP_ERR_TO_COND(WSAEADDRINUSE, address_in_use); - MAP_ERR_TO_COND(WSAEADDRNOTAVAIL, address_not_available); - MAP_ERR_TO_COND(WSAEAFNOSUPPORT, address_family_not_supported); - MAP_ERR_TO_COND(WSAEALREADY, connection_already_in_progress); - MAP_ERR_TO_COND(WSAEBADF, bad_file_descriptor); - MAP_ERR_TO_COND(WSAECONNABORTED, connection_aborted); - MAP_ERR_TO_COND(WSAECONNREFUSED, connection_refused); - MAP_ERR_TO_COND(WSAECONNRESET, connection_reset); - MAP_ERR_TO_COND(WSAEDESTADDRREQ, destination_address_required); - MAP_ERR_TO_COND(WSAEFAULT, bad_address); - MAP_ERR_TO_COND(WSAEHOSTUNREACH, host_unreachable); - MAP_ERR_TO_COND(WSAEINPROGRESS, operation_in_progress); - MAP_ERR_TO_COND(WSAEINTR, interrupted); - MAP_ERR_TO_COND(WSAEINVAL, invalid_argument); - MAP_ERR_TO_COND(WSAEISCONN, already_connected); - MAP_ERR_TO_COND(WSAEMFILE, too_many_files_open); - MAP_ERR_TO_COND(WSAEMSGSIZE, message_size); - MAP_ERR_TO_COND(WSAENAMETOOLONG, filename_too_long); - MAP_ERR_TO_COND(WSAENETDOWN, network_down); - MAP_ERR_TO_COND(WSAENETRESET, network_reset); - MAP_ERR_TO_COND(WSAENETUNREACH, network_unreachable); - MAP_ERR_TO_COND(WSAENOBUFS, no_buffer_space); - MAP_ERR_TO_COND(WSAENOPROTOOPT, no_protocol_option); - MAP_ERR_TO_COND(WSAENOTCONN, not_connected); - MAP_ERR_TO_COND(WSAENOTSOCK, not_a_socket); - MAP_ERR_TO_COND(WSAEOPNOTSUPP, operation_not_supported); - MAP_ERR_TO_COND(WSAEPROTONOSUPPORT, protocol_not_supported); - MAP_ERR_TO_COND(WSAEPROTOTYPE, wrong_protocol_type); - MAP_ERR_TO_COND(WSAETIMEDOUT, timed_out); - MAP_ERR_TO_COND(WSAEWOULDBLOCK, operation_would_block); - default: return error_condition(ev, system_category()); - } -} diff --git a/lib/Support/WindowsError.cpp b/lib/Support/WindowsError.cpp new file mode 100644 index 0000000000..59c575ff9e --- /dev/null +++ b/lib/Support/WindowsError.cpp @@ -0,0 +1,115 @@ +//===-- WindowsError.cpp - Support for mapping windows errors to posix-----===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements a mapping from windows errors to posix ones. +// The standard doesn't define what the equivalence is from system +// errors to generic ones. The one implemented in msvc is too conservative +// for llvm, so we do an extra mapping when constructing an error_code +// from an windows error. This allows the rest of llvm to simple checks +// like "EC == std::errc::file_exists" and have it work on both posix and +// windows. +// +//===----------------------------------------------------------------------===// + +#ifdef _MSC_VER + +#include <winerror.h> + +#include "llvm/Support/WindowsError.h" + +// I'd rather not double the line count of the following. +#define MAP_ERR_TO_COND(x, y) \ + case x: \ + return std::make_error_code(std::errc::y) + +std::error_code llvm::mapWindowsError(unsigned EV) { + switch (EV) { + MAP_ERR_TO_COND(ERROR_ACCESS_DENIED, permission_denied); + MAP_ERR_TO_COND(ERROR_ALREADY_EXISTS, file_exists); + MAP_ERR_TO_COND(ERROR_BAD_UNIT, no_such_device); + MAP_ERR_TO_COND(ERROR_BUFFER_OVERFLOW, filename_too_long); + MAP_ERR_TO_COND(ERROR_BUSY, device_or_resource_busy); + MAP_ERR_TO_COND(ERROR_BUSY_DRIVE, device_or_resource_busy); + MAP_ERR_TO_COND(ERROR_CANNOT_MAKE, permission_denied); + MAP_ERR_TO_COND(ERROR_CANTOPEN, io_error); + MAP_ERR_TO_COND(ERROR_CANTREAD, io_error); + MAP_ERR_TO_COND(ERROR_CANTWRITE, io_error); + MAP_ERR_TO_COND(ERROR_CURRENT_DIRECTORY, permission_denied); + MAP_ERR_TO_COND(ERROR_DEV_NOT_EXIST, no_such_device); + MAP_ERR_TO_COND(ERROR_DEVICE_IN_USE, device_or_resource_busy); + MAP_ERR_TO_COND(ERROR_DIR_NOT_EMPTY, directory_not_empty); + MAP_ERR_TO_COND(ERROR_DIRECTORY, invalid_argument); + MAP_ERR_TO_COND(ERROR_DISK_FULL, no_space_on_device); + MAP_ERR_TO_COND(ERROR_FILE_EXISTS, file_exists); + MAP_ERR_TO_COND(ERROR_FILE_NOT_FOUND, no_such_file_or_directory); + MAP_ERR_TO_COND(ERROR_HANDLE_DISK_FULL, no_space_on_device); + MAP_ERR_TO_COND(ERROR_HANDLE_EOF, value_too_large); + MAP_ERR_TO_COND(ERROR_INVALID_ACCESS, permission_denied); + MAP_ERR_TO_COND(ERROR_INVALID_DRIVE, no_such_device); + MAP_ERR_TO_COND(ERROR_INVALID_FUNCTION, function_not_supported); + MAP_ERR_TO_COND(ERROR_INVALID_HANDLE, invalid_argument); + MAP_ERR_TO_COND(ERROR_INVALID_NAME, invalid_argument); + MAP_ERR_TO_COND(ERROR_LOCK_VIOLATION, no_lock_available); + MAP_ERR_TO_COND(ERROR_LOCKED, no_lock_available); + MAP_ERR_TO_COND(ERROR_NEGATIVE_SEEK, invalid_argument); + MAP_ERR_TO_COND(ERROR_NOACCESS, permission_denied); + MAP_ERR_TO_COND(ERROR_NOT_ENOUGH_MEMORY, not_enough_memory); + MAP_ERR_TO_COND(ERROR_NOT_READY, resource_unavailable_try_again); + MAP_ERR_TO_COND(ERROR_NOT_SAME_DEVICE, cross_device_link); + MAP_ERR_TO_COND(ERROR_OPEN_FAILED, io_error); + MAP_ERR_TO_COND(ERROR_OPEN_FILES, device_or_resource_busy); + MAP_ERR_TO_COND(ERROR_OPERATION_ABORTED, operation_canceled); + MAP_ERR_TO_COND(ERROR_OUTOFMEMORY, not_enough_memory); + MAP_ERR_TO_COND(ERROR_PATH_NOT_FOUND, no_such_file_or_directory); + MAP_ERR_TO_COND(ERROR_BAD_NETPATH, no_such_file_or_directory); + MAP_ERR_TO_COND(ERROR_READ_FAULT, io_error); + MAP_ERR_TO_COND(ERROR_RETRY, resource_unavailable_try_again); + MAP_ERR_TO_COND(ERROR_SEEK, io_error); + MAP_ERR_TO_COND(ERROR_SHARING_VIOLATION, permission_denied); + MAP_ERR_TO_COND(ERROR_TOO_MANY_OPEN_FILES, too_many_files_open); + MAP_ERR_TO_COND(ERROR_WRITE_FAULT, io_error); + MAP_ERR_TO_COND(ERROR_WRITE_PROTECT, permission_denied); + MAP_ERR_TO_COND(ERROR_SEM_TIMEOUT, timed_out); + MAP_ERR_TO_COND(WSAEACCES, permission_denied); + MAP_ERR_TO_COND(WSAEADDRINUSE, address_in_use); + MAP_ERR_TO_COND(WSAEADDRNOTAVAIL, address_not_available); + MAP_ERR_TO_COND(WSAEAFNOSUPPORT, address_family_not_supported); + MAP_ERR_TO_COND(WSAEALREADY, connection_already_in_progress); + MAP_ERR_TO_COND(WSAEBADF, bad_file_descriptor); + MAP_ERR_TO_COND(WSAECONNABORTED, connection_aborted); + MAP_ERR_TO_COND(WSAECONNREFUSED, connection_refused); + MAP_ERR_TO_COND(WSAECONNRESET, connection_reset); + MAP_ERR_TO_COND(WSAEDESTADDRREQ, destination_address_required); + MAP_ERR_TO_COND(WSAEFAULT, bad_address); + MAP_ERR_TO_COND(WSAEHOSTUNREACH, host_unreachable); + MAP_ERR_TO_COND(WSAEINPROGRESS, operation_in_progress); + MAP_ERR_TO_COND(WSAEINTR, interrupted); + MAP_ERR_TO_COND(WSAEINVAL, invalid_argument); + MAP_ERR_TO_COND(WSAEISCONN, already_connected); + MAP_ERR_TO_COND(WSAEMFILE, too_many_files_open); + MAP_ERR_TO_COND(WSAEMSGSIZE, message_size); + MAP_ERR_TO_COND(WSAENAMETOOLONG, filename_too_long); + MAP_ERR_TO_COND(WSAENETDOWN, network_down); + MAP_ERR_TO_COND(WSAENETRESET, network_reset); + MAP_ERR_TO_COND(WSAENETUNREACH, network_unreachable); + MAP_ERR_TO_COND(WSAENOBUFS, no_buffer_space); + MAP_ERR_TO_COND(WSAENOPROTOOPT, no_protocol_option); + MAP_ERR_TO_COND(WSAENOTCONN, not_connected); + MAP_ERR_TO_COND(WSAENOTSOCK, not_a_socket); + MAP_ERR_TO_COND(WSAEOPNOTSUPP, operation_not_supported); + MAP_ERR_TO_COND(WSAEPROTONOSUPPORT, protocol_not_supported); + MAP_ERR_TO_COND(WSAEPROTOTYPE, wrong_protocol_type); + MAP_ERR_TO_COND(WSAETIMEDOUT, timed_out); + MAP_ERR_TO_COND(WSAEWOULDBLOCK, operation_would_block); + default: + return std::error_code(EV, std::system_category()); + } +} + +#endif diff --git a/lib/Support/YAMLTraits.cpp b/lib/Support/YAMLTraits.cpp index 20f8b245c9..ed80eac76a 100644 --- a/lib/Support/YAMLTraits.cpp +++ b/lib/Support/YAMLTraits.cpp @@ -74,7 +74,7 @@ bool Input::setCurrentDocument() { Node *N = DocIterator->getRoot(); if (!N) { assert(Strm->failed() && "Root is NULL iff parsing failed"); - EC = make_error_code(errc::invalid_argument); + EC = make_error_code(std::errc::invalid_argument); return false; } @@ -124,7 +124,7 @@ bool Input::preflightKey(const char *Key, bool Required, bool, bool &UseDefault, // nodes are present. if (!CurrentNode) { if (Required) - EC = make_error_code(errc::invalid_argument); + EC = make_error_code(std::errc::invalid_argument); return false; } @@ -300,7 +300,7 @@ void Input::setError(HNode *hnode, const Twine &message) { void Input::setError(Node *node, const Twine &message) { Strm->printError(node, message); - EC = make_error_code(errc::invalid_argument); + EC = make_error_code(std::errc::invalid_argument); } Input::HNode *Input::createHNodes(Node *N) { diff --git a/lib/Support/system_error.cpp b/lib/Support/system_error.cpp deleted file mode 100644 index 46b501eea0..0000000000 --- a/lib/Support/system_error.cpp +++ /dev/null @@ -1,121 +0,0 @@ -//===---------------------- system_error.cpp ------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This was lifted from libc++ and modified for C++03. -// -//===----------------------------------------------------------------------===// - -#include "llvm/Support/system_error.h" -#include "llvm/Support/Errno.h" -#include <cstring> -#include <string> - -namespace llvm { - -// class error_category - -error_category::error_category() { -} - -error_category::~error_category() { -} - -error_condition -error_category::default_error_condition(int ev) const { - return error_condition(ev, *this); -} - -bool -error_category::equivalent(int code, const error_condition& condition) const { - return default_error_condition(code) == condition; -} - -bool -error_category::equivalent(const error_code& code, int condition) const { - return *this == code.category() && code.value() == condition; -} - -std::string -_do_message::message(int ev) const { - return std::string(sys::StrError(ev)); -} - -class _generic_error_category : public _do_message { -public: - const char* name() const LLVM_NOEXCEPT override; - std::string message(int ev) const override; -}; - -const char* -_generic_error_category::name() const { - return "generic"; -} - -std::string -_generic_error_category::message(int ev) const { -#ifdef ELAST - if (ev > ELAST) - return std::string("unspecified generic_category error"); -#endif // ELAST - return _do_message::message(ev); -} - -const error_category& -generic_category() { - static _generic_error_category s; - return s; -} - -class _system_error_category : public _do_message { -public: - const char* name() const LLVM_NOEXCEPT override; - std::string message(int ev) const override; - error_condition default_error_condition(int ev) const override; -}; - -const char* -_system_error_category::name() const { - return "system"; -} - -// std::string _system_error_category::message(int ev) const { -// Is in Platform/system_error.inc - -// error_condition _system_error_category::default_error_condition(int ev) const -// Is in Platform/system_error.inc - -const error_category& -system_category() { - static _system_error_category s; - return s; -} - -// error_condition - -std::string -error_condition::message() const { - return _cat_->message(_val_); -} - -// error_code - -std::string -error_code::message() const { - return _cat_->message(_val_); -} - -} // end namespace llvm - -// Include the truly platform-specific parts of this class. -#if defined(LLVM_ON_UNIX) -#include "Unix/system_error.inc" -#endif -#if defined(LLVM_ON_WIN32) -#include "Windows/system_error.inc" -#endif diff --git a/test/Object/directory.ll b/test/Object/directory.ll index 48eefcb6ec..c4b0bbf20e 100644 --- a/test/Object/directory.ll +++ b/test/Object/directory.ll @@ -1,6 +1,6 @@ ;RUN: rm -f %T/test.a ;RUN: not llvm-ar r %T/test.a . 2>&1 | FileCheck %s -;CHECK: .: Is a directory +;CHECK: .: {{I|i}}s a directory ;RUN: rm -f %T/test.a ;RUN: touch %T/a-very-long-file-name diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index ea85d5d3c9..77914c5792 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -453,7 +453,7 @@ int NewArchiveIterator::getFD() const { // Linux cannot open directories with open(2), although // cygwin and *bsd can. if (NewStatus.type() == sys::fs::file_type::directory_file) - failIfError(make_error_code(errc::is_a_directory), NewFilename); + failIfError(make_error_code(std::errc::is_a_directory), NewFilename); return NewFD; } @@ -939,7 +939,7 @@ static int performOperation(ArchiveOperation Operation) { // Create or open the archive object. std::unique_ptr<MemoryBuffer> Buf; error_code EC = MemoryBuffer::getFile(ArchiveName, Buf, -1, false); - if (EC && EC != llvm::errc::no_such_file_or_directory) { + if (EC && EC != std::errc::no_such_file_or_directory) { errs() << ToolName << ": error opening '" << ArchiveName << "': " << EC.message() << "!\n"; return 1; @@ -957,7 +957,7 @@ static int performOperation(ArchiveOperation Operation) { return 0; } - assert(EC == llvm::errc::no_such_file_or_directory); + assert(EC == std::errc::no_such_file_or_directory); if (!shouldCreateArchive(Operation)) { failIfError(EC, Twine("error loading '") + ArchiveName + "'"); diff --git a/tools/llvm-cov/llvm-cov.cpp b/tools/llvm-cov/llvm-cov.cpp index 9463609ae3..f15b9a0265 100644 --- a/tools/llvm-cov/llvm-cov.cpp +++ b/tools/llvm-cov/llvm-cov.cpp @@ -116,7 +116,7 @@ int main(int argc, char **argv) { std::unique_ptr<MemoryBuffer> GCDA_Buff; if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) { - if (ec != errc::no_such_file_or_directory) { + if (ec != std::errc::no_such_file_or_directory) { errs() << InputGCDA << ": " << ec.message() << "\n"; return 1; } diff --git a/tools/llvm-objdump/llvm-objdump.h b/tools/llvm-objdump/llvm-objdump.h index b716a264c8..30f2eea81f 100644 --- a/tools/llvm-objdump/llvm-objdump.h +++ b/tools/llvm-objdump/llvm-objdump.h @@ -22,7 +22,6 @@ namespace object { class ObjectFile; class RelocationRef; } -class error_code; extern cl::opt<std::string> TripleName; extern cl::opt<std::string> ArchName; diff --git a/tools/llvm-readobj/Error.cpp b/tools/llvm-readobj/Error.cpp index a68ebeb58e..a276fcedb8 100644 --- a/tools/llvm-readobj/Error.cpp +++ b/tools/llvm-readobj/Error.cpp @@ -50,7 +50,7 @@ std::string _readobj_error_category::message(int EV) const { error_condition _readobj_error_category::default_error_condition(int EV) const { if (static_cast<readobj_error>(EV) == readobj_error::success) return error_condition(); - return errc::invalid_argument; + return std::errc::invalid_argument; } namespace llvm { diff --git a/tools/llvm-readobj/Error.h b/tools/llvm-readobj/Error.h index ebf652e9a1..b3aab327cb 100644 --- a/tools/llvm-readobj/Error.h +++ b/tools/llvm-readobj/Error.h @@ -33,8 +33,10 @@ inline error_code make_error_code(readobj_error e) { return error_code(static_cast<int>(e), readobj_category()); } -template <> struct is_error_code_enum<readobj_error> : std::true_type { }; - } // namespace llvm +namespace std { +template <> struct is_error_code_enum<llvm::readobj_error> : std::true_type {}; +} + #endif diff --git a/tools/llvm-readobj/ObjDumper.h b/tools/llvm-readobj/ObjDumper.h index 9e0fd2f990..0c7eb5109f 100644 --- a/tools/llvm-readobj/ObjDumper.h +++ b/tools/llvm-readobj/ObjDumper.h @@ -10,6 +10,8 @@ #ifndef LLVM_READOBJ_OBJDUMPER_H #define LLVM_READOBJ_OBJDUMPER_H +#include "llvm/Support/system_error.h" + #include <memory> namespace llvm { @@ -18,8 +20,6 @@ namespace object { class ObjectFile; } -class error_code; - class StreamWriter; class ObjDumper { diff --git a/tools/llvm-readobj/llvm-readobj.h b/tools/llvm-readobj/llvm-readobj.h index cc5c85d8da..61ee0d4ed4 100644 --- a/tools/llvm-readobj/llvm-readobj.h +++ b/tools/llvm-readobj/llvm-readobj.h @@ -18,8 +18,6 @@ namespace llvm { class RelocationRef; } - class error_code; - // Various helper functions. bool error(error_code ec); bool relocAddressLess(object::RelocationRef A, diff --git a/tools/llvm-symbolizer/LLVMSymbolize.cpp b/tools/llvm-symbolizer/LLVMSymbolize.cpp index 3e71111b00..125e63f225 100644 --- a/tools/llvm-symbolizer/LLVMSymbolize.cpp +++ b/tools/llvm-symbolizer/LLVMSymbolize.cpp @@ -311,7 +311,7 @@ LLVMSymbolizer::getOrCreateBinary(const std::string &Path) { getDarwinDWARFResourceForPath(Path); BinaryOrErr = createBinary(ResourcePath); error_code EC = BinaryOrErr.getError(); - if (EC != errc::no_such_file_or_directory && !error(EC)) { + if (EC != std::errc::no_such_file_or_directory && !error(EC)) { DbgBin = BinaryOrErr.get(); ParsedBinariesAndObjects.push_back(std::unique_ptr<Binary>(DbgBin)); } diff --git a/tools/obj2yaml/Error.cpp b/tools/obj2yaml/Error.cpp index 3aa472fc3d..ab615ee193 100644 --- a/tools/obj2yaml/Error.cpp +++ b/tools/obj2yaml/Error.cpp @@ -42,7 +42,7 @@ error_condition _obj2yaml_error_category::default_error_condition(int ev) const { if (static_cast<obj2yaml_error>(ev) == obj2yaml_error::success) return error_condition(); - return errc::invalid_argument; + return std::errc::invalid_argument; } namespace llvm { diff --git a/tools/obj2yaml/Error.h b/tools/obj2yaml/Error.h index 4aaf5c7942..7180d54307 100644 --- a/tools/obj2yaml/Error.h +++ b/tools/obj2yaml/Error.h @@ -27,8 +27,10 @@ inline error_code make_error_code(obj2yaml_error e) { return error_code(static_cast<int>(e), obj2yaml_category()); } -template <> struct is_error_code_enum<obj2yaml_error> : std::true_type { }; - } // namespace llvm +namespace std { +template <> struct is_error_code_enum<llvm::obj2yaml_error> : std::true_type {}; +} + #endif diff --git a/unittests/Support/ErrorOrTest.cpp b/unittests/Support/ErrorOrTest.cpp index 7ace5e3e81..976a95379a 100644 --- a/unittests/Support/ErrorOrTest.cpp +++ b/unittests/Support/ErrorOrTest.cpp @@ -16,7 +16,7 @@ using namespace llvm; namespace { ErrorOr<int> t1() {return 1;} -ErrorOr<int> t2() { return errc::invalid_argument; } +ErrorOr<int> t2() { return std::errc::invalid_argument; } TEST(ErrorOr, SimpleValue) { ErrorOr<int> a = t1(); @@ -30,7 +30,7 @@ TEST(ErrorOr, SimpleValue) { a = t2(); EXPECT_FALSE(a); - EXPECT_EQ(errc::invalid_argument, a.getError()); + EXPECT_EQ(std::errc::invalid_argument, a.getError()); #ifdef EXPECT_DEBUG_DEATH EXPECT_DEBUG_DEATH(*a, "Cannot get value when an error exists"); #endif diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp index 660ea3663a..d116acae2a 100644 --- a/unittests/Support/Path.cpp +++ b/unittests/Support/Path.cpp @@ -354,10 +354,10 @@ TEST_F(FileSystemTest, TempFiles) { ASSERT_NO_ERROR(fs::remove(Twine(TempPath2))); ASSERT_NO_ERROR(fs::remove(Twine(TempPath2))); ASSERT_EQ(fs::remove(Twine(TempPath2), false), - errc::no_such_file_or_directory); + std::errc::no_such_file_or_directory); error_code EC = fs::status(TempPath2.c_str(), B); - EXPECT_EQ(EC, errc::no_such_file_or_directory); + EXPECT_EQ(EC, std::errc::no_such_file_or_directory); EXPECT_EQ(B.type(), fs::file_type::file_not_found); // Make sure Temp2 doesn't exist. @@ -397,7 +397,7 @@ TEST_F(FileSystemTest, TempFiles) { "abcdefghijklmnopqrstuvwxyz3abcdefghijklmnopqrstuvwxyz2" "abcdefghijklmnopqrstuvwxyz1abcdefghijklmnopqrstuvwxyz0"; EXPECT_EQ(fs::createUniqueFile(Twine(Path270), FileDescriptor, TempPath), - error_code(ERROR_PATH_NOT_FOUND, system_category())); + std::errc::no_such_file_or_directory); #endif } @@ -405,7 +405,7 @@ TEST_F(FileSystemTest, CreateDir) { ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory) + "foo")); ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory) + "foo")); ASSERT_EQ(fs::create_directory(Twine(TestDirectory) + "foo", false), - errc::file_exists); + std::errc::file_exists); ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "foo")); } diff --git a/unittests/Transforms/DebugIR/DebugIR.cpp b/unittests/Transforms/DebugIR/DebugIR.cpp index 49ea09f7c6..5860e31b9d 100644 --- a/unittests/Transforms/DebugIR/DebugIR.cpp +++ b/unittests/Transforms/DebugIR/DebugIR.cpp @@ -58,7 +58,7 @@ bool removeIfExists(StringRef Path) { // This is an approximation, on error we don't know in general if the file // existed or not. llvm::error_code EC = sys::fs::remove(Path, false); - return EC != llvm::errc::no_such_file_or_directory; + return EC != std::errc::no_such_file_or_directory; } char * current_dir() { diff --git a/utils/KillTheDoctor/KillTheDoctor.cpp b/utils/KillTheDoctor/KillTheDoctor.cpp index f236c5ffc9..2b66066b43 100644 --- a/utils/KillTheDoctor/KillTheDoctor.cpp +++ b/utils/KillTheDoctor/KillTheDoctor.cpp @@ -43,6 +43,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Support/system_error.h" #include "llvm/Support/type_traits.h" +#include "llvm/Support/WindowsError.h" #include <algorithm> #include <cerrno> #include <cstdlib> @@ -169,9 +170,7 @@ namespace { typedef ScopedHandle<FileHandle> FileScopedHandle; } -static error_code windows_error(unsigned E) { - return error_code(E, system_category()); -} +static error_code windows_error(DWORD E) { return mapWindowsError(E); } static error_code GetFileNameFromHandle(HANDLE FileHandle, std::string& Name) { @@ -426,7 +425,7 @@ int main(int argc, char **argv) { if (!success) { ec = windows_error(::GetLastError()); - if (ec == errc::timed_out) { + if (ec == std::errc::timed_out) { errs() << ToolName << ": Process timed out.\n"; ::TerminateProcess(ProcessInfo.hProcess, -1); // Otherwise other stuff starts failing... |