llvm.org GIT mirror llvm / 7acd886
Use std::error_code instead of llvm::error_code. The idea of this patch is to turn llvm/Support/system_error.h into a transitional header that just brings in the erorr_code api to the llvm namespace. I will remove it shortly afterwards. The cases where the general idea needed some tweaking: * std::errc is a namespace in msvc, so we cannot use "using std::errc". I could add an #ifdef, but there were not that many uses, so I just added std:: to them in this patch. * Template specialization had to be moved to the std namespace in this patch set already. * The msvc implementation of default_error_condition doesn't seem to provide the same transformations as we need. Not too surprising since the standard doesn't actually say what "equivalent" means. I fixed the problem by keeping our old mapping and using it at error_code construction time. Despite these shortcomings I think this is still a good thing. Some reasons: * The different implementations of system_error might improve over time. * It removes 925 lines of code from llvm already. * It removes 6313 bytes from the text segment of the clang binary when it is built with gcc and 2816 bytes when building with clang and libstdc++. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210687 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
37 changed file(s) with 217 addition(s) and 1142 deletion(s). Raw diff Collapse all Expand all
3434
3535 } // end namespace object.
3636
37 template <> struct is_error_code_enum : std::true_type {};
38
3937 } // end namespace llvm.
4038
39 namespace std {
40 template <>
41 struct is_error_code_enum : std::true_type {};
42 }
43
4144 #endif
4141 return error_code(static_cast(E), instrprof_category());
4242 }
4343
44 template <> struct is_error_code_enum : std::true_type {};
45
4644 } // end namespace llvm
4745
46 namespace std {
47 template <>
48 struct is_error_code_enum : std::true_type {};
49 }
50
4851 #endif // LLVM_PROFILEDATA_INSTRPROF_H_
1919 #include "llvm/Support/FileSystem.h"
2020
2121 namespace llvm {
22 class error_code;
23
2422 /// FileOutputBuffer - This interface provides simple way to create an in-memory
2523 /// buffer which will be written to a file. During the lifetime of these
2624 /// objects, the content or existence of the specified file is undefined. That
1818 #include "llvm/Support/CBindingWrapping.h"
1919 #include "llvm/Support/Compiler.h"
2020 #include "llvm/Support/DataTypes.h"
21 #include "llvm/Support/system_error.h"
2122 #include
2223
2324 namespace llvm {
24
25 class error_code;
26
2725 /// MemoryBuffer - This interface provides simple read-only access to a block
2826 /// of memory, and provides simple methods for reading files and standard input
2927 /// into a memory buffer. In addition to basic access to the characters in the
1818 #include "llvm/Support/system_error.h"
1919
2020 namespace llvm {
21 class error_code;
2221 namespace sys {
2322
2423 /// This is the OS-specific separator for PATH like environment variables:
0 //===-- WindowsError.h - Support for mapping windows errors to posix-------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_SUPPORT_WINDOWS_ERROR_H
10 #define LLVM_SUPPORT_WINDOWS_ERROR_H
11
12 #ifdef _MSC_VER
13 #include
14
15 namespace llvm {
16 std::error_code mapWindowsError(unsigned EV);
17 }
18 #endif
19
20 #endif
66 //
77 //===----------------------------------------------------------------------===//
88 //
9 // This was lifted from libc++ and modified for C++03. This is called
10 // system_error even though it does not define that class because that's what
11 // it's called in C++0x. We don't define system_error because it is only used
12 // for exception handling, which we don't use in LLVM.
9 // This is a temporary file to help with the transition to std::error_code.
1310 //
1411 //===----------------------------------------------------------------------===//
1512
1613 #ifndef LLVM_SUPPORT_SYSTEM_ERROR_H
1714 #define LLVM_SUPPORT_SYSTEM_ERROR_H
1815
19 #include "llvm/Support/Compiler.h"
20
21 /*
22 system_error synopsis
23
24 namespace std
25 {
26
27 class error_category
28 {
29 public:
30 virtual ~error_category();
31
32 error_category(const error_category&) = delete;
33 error_category& operator=(const error_category&) = delete;
34
35 virtual const char* name() const = 0;
36 virtual error_condition default_error_condition(int ev) const;
37 virtual bool equivalent(int code, const error_condition& condition) const;
38 virtual bool equivalent(const error_code& code, int condition) const;
39 virtual std::string message(int ev) const = 0;
40
41 bool operator==(const error_category& rhs) const;
42 bool operator!=(const error_category& rhs) const;
43 bool operator<(const error_category& rhs) const;
44 };
45
46 const error_category& generic_category();
47 const error_category& system_category();
48
49 template struct is_error_code_enum
50 : public std::false_type {};
51
52 template struct is_error_condition_enum
53 : public std::false_type {};
54
55 class error_code
56 {
57 public:
58 // constructors:
59 error_code();
60 error_code(int val, const error_category& cat);
61 template
62 error_code(ErrorCodeEnum e);
63
64 // modifiers:
65 void assign(int val, const error_category& cat);
66 template
67 error_code& operator=(ErrorCodeEnum e);
68 void clear();
69
70 // observers:
71 int value() const;
72 const error_category& category() const;
73 error_condition default_error_condition() const;
74 std::string message() const;
75 explicit operator bool() const;
76 };
77
78 // non-member functions:
79 bool operator<(const error_code& lhs, const error_code& rhs);
80 template
81 basic_ostream&
82 operator<<(basic_ostream& os, const error_code& ec);
83
84 class error_condition
85 {
86 public:
87 // constructors:
88 error_condition();
89 error_condition(int val, const error_category& cat);
90 template
91 error_condition(ErrorConditionEnum e);
92
93 // modifiers:
94 void assign(int val, const error_category& cat);
95 template
96 error_condition& operator=(ErrorConditionEnum e);
97 void clear();
98
99 // observers:
100 int value() const;
101 const error_category& category() const;
102 std::string message() const;
103 explicit operator bool() const;
104 };
105
106 bool operator<(const error_condition& lhs, const error_condition& rhs);
107
108 class system_error
109 : public runtime_error
110 {
111 public:
112 system_error(error_code ec, const std::string& what_arg);
113 system_error(error_code ec, const char* what_arg);
114 system_error(error_code ec);
115 system_error(int ev, const error_category& ecat, const std::string& what_arg);
116 system_error(int ev, const error_category& ecat, const char* what_arg);
117 system_error(int ev, const error_category& ecat);
118
119 const error_code& code() const throw();
120 const char* what() const throw();
121 };
122
123 enum class errc
124 {
125 address_family_not_supported, // EAFNOSUPPORT
126 address_in_use, // EADDRINUSE
127 address_not_available, // EADDRNOTAVAIL
128 already_connected, // EISCONN
129 argument_list_too_long, // E2BIG
130 argument_out_of_domain, // EDOM
131 bad_address, // EFAULT
132 bad_file_descriptor, // EBADF
133 bad_message, // EBADMSG
134 broken_pipe, // EPIPE
135 connection_aborted, // ECONNABORTED
136 connection_already_in_progress, // EALREADY
137 connection_refused, // ECONNREFUSED
138 connection_reset, // ECONNRESET
139 cross_device_link, // EXDEV
140 destination_address_required, // EDESTADDRREQ
141 device_or_resource_busy, // EBUSY
142 directory_not_empty, // ENOTEMPTY
143 executable_format_error, // ENOEXEC
144 file_exists, // EEXIST
145 file_too_large, // EFBIG
146 filename_too_long, // ENAMETOOLONG
147 function_not_supported, // ENOSYS
148 host_unreachable, // EHOSTUNREACH
149 identifier_removed, // EIDRM
150 illegal_byte_sequence, // EILSEQ
151 inappropriate_io_control_operation, // ENOTTY
152 interrupted, // EINTR
153 invalid_argument, // EINVAL
154 invalid_seek, // ESPIPE
155 io_error, // EIO
156 is_a_directory, // EISDIR
157 message_size, // EMSGSIZE
158 network_down, // ENETDOWN
159 network_reset, // ENETRESET
160 network_unreachable, // ENETUNREACH
161 no_buffer_space, // ENOBUFS
162 no_child_process, // ECHILD
163 no_link, // ENOLINK
164 no_lock_available, // ENOLCK
165 no_message_available, // ENODATA
166 no_message, // ENOMSG
167 no_protocol_option, // ENOPROTOOPT
168 no_space_on_device, // ENOSPC
169 no_stream_resources, // ENOSR
170 no_such_device_or_address, // ENXIO
171 no_such_device, // ENODEV
172 no_such_file_or_directory, // ENOENT
173 no_such_process, // ESRCH
174 not_a_directory, // ENOTDIR
175 not_a_socket, // ENOTSOCK
176 not_a_stream, // ENOSTR
177 not_connected, // ENOTCONN
178 not_enough_memory, // ENOMEM
179 not_supported, // ENOTSUP
180 operation_canceled, // ECANCELED
181 operation_in_progress, // EINPROGRESS
182 operation_not_permitted, // EPERM
183 operation_not_supported, // EOPNOTSUPP
184 operation_would_block, // EWOULDBLOCK
185 owner_dead, // EOWNERDEAD
186 permission_denied, // EACCES
187 protocol_error, // EPROTO
188 protocol_not_supported, // EPROTONOSUPPORT
189 read_only_file_system, // EROFS
190 resource_deadlock_would_occur, // EDEADLK
191 resource_unavailable_try_again, // EAGAIN
192 result_out_of_range, // ERANGE
193 state_not_recoverable, // ENOTRECOVERABLE
194 stream_timeout, // ETIME
195 text_file_busy, // ETXTBSY
196 timed_out, // ETIMEDOUT
197 too_many_files_open_in_system, // ENFILE
198 too_many_files_open, // EMFILE
199 too_many_links, // EMLINK
200 too_many_symbolic_link_levels, // ELOOP
201 value_too_large, // EOVERFLOW
202 wrong_protocol_type // EPROTOTYPE
203 };
204
205 template <> struct is_error_condition_enum : std::true_type { }
206
207 error_code make_error_code(errc e);
208 error_condition make_error_condition(errc e);
209
210 // Comparison operators:
211 bool operator==(const error_code& lhs, const error_code& rhs);
212 bool operator==(const error_code& lhs, const error_condition& rhs);
213 bool operator==(const error_condition& lhs, const error_code& rhs);
214 bool operator==(const error_condition& lhs, const error_condition& rhs);
215 bool operator!=(const error_code& lhs, const error_code& rhs);
216 bool operator!=(const error_code& lhs, const error_condition& rhs);
217 bool operator!=(const error_condition& lhs, const error_code& rhs);
218 bool operator!=(const error_condition& lhs, const error_condition& rhs);
219
220 template <> struct hash;
221
222 } // std
223
224 */
225
226 #include "llvm/Config/llvm-config.h"
227 #include
228 #include
229
230 // This must be here instead of a .inc file because it is used in the definition
231 // of the enum values below.
232 #ifdef LLVM_ON_WIN32
233
234 // The following numbers were taken from VS2010.
235 # ifndef EAFNOSUPPORT
236 # define EAFNOSUPPORT 102
237 # endif
238 # ifndef EADDRINUSE
239 # define EADDRINUSE 100
240 # endif
241 # ifndef EADDRNOTAVAIL
242 # define EADDRNOTAVAIL 101
243 # endif
244 # ifndef EISCONN
245 # define EISCONN 113
246 # endif
247 # ifndef E2BIG
248 # define E2BIG 7
249 # endif
250 # ifndef EDOM
251 # define EDOM 33
252 # endif
253 # ifndef EFAULT
254 # define EFAULT 14
255 # endif
256 # ifndef EBADF
257 # define EBADF 9
258 # endif
259 # ifndef EBADMSG
260 # define EBADMSG 104
261 # endif
262 # ifndef EPIPE
263 # define EPIPE 32
264 # endif
265 # ifndef ECONNABORTED
266 # define ECONNABORTED 106
267 # endif
268 # ifndef EALREADY
269 # define EALREADY 103
270 # endif
271 # ifndef ECONNREFUSED
272 # define ECONNREFUSED 107
273 # endif
274 # ifndef ECONNRESET
275 # define ECONNRESET 108
276 # endif
277 # ifndef EXDEV
278 # define EXDEV 18
279 # endif
280 # ifndef EDESTADDRREQ
281 # define EDESTADDRREQ 109
282 # endif
283 # ifndef EBUSY
284 # define EBUSY 16
285 # endif
286 # ifndef ENOTEMPTY
287 # define ENOTEMPTY 41
288 # endif
289 # ifndef ENOEXEC
290 # define ENOEXEC 8
291 # endif
292 # ifndef EEXIST
293 # define EEXIST 17
294 # endif
295 # ifndef EFBIG
296 # define EFBIG 27
297 # endif
298 # ifndef ENAMETOOLONG
299 # define ENAMETOOLONG 38
300 # endif
301 # ifndef ENOSYS
302 # define ENOSYS 40
303 # endif
304 # ifndef EHOSTUNREACH
305 # define EHOSTUNREACH 110
306 # endif
307 # ifndef EIDRM
308 # define EIDRM 111
309 # endif
310 # ifndef EILSEQ
311 # define EILSEQ 42
312 # endif
313 # ifndef ENOTTY
314 # define ENOTTY 25
315 # endif
316 # ifndef EINTR
317 # define EINTR 4
318 # endif
319 # ifndef EINVAL
320 # define EINVAL 22
321 # endif
322 # ifndef ESPIPE
323 # define ESPIPE 29
324 # endif
325 # ifndef EIO
326 # define EIO 5
327 # endif
328 # ifndef EISDIR
329 # define EISDIR 21
330 # endif
331 # ifndef EMSGSIZE
332 # define EMSGSIZE 115
333 # endif
334 # ifndef ENETDOWN
335 # define ENETDOWN 116
336 # endif
337 # ifndef ENETRESET
338 # define ENETRESET 117
339 # endif
340 # ifndef ENETUNREACH
341 # define ENETUNREACH 118
342 # endif
343 # ifndef ENOBUFS
344 # define ENOBUFS 119
345 # endif
346 # ifndef ECHILD
347 # define ECHILD 10
348 # endif
349 # ifndef ENOLINK
350 # define ENOLINK 121
351 # endif
352 # ifndef ENOLCK
353 # define ENOLCK 39
354 # endif
355 # ifndef ENODATA
356 # define ENODATA 120
357 # endif
358 # ifndef ENOMSG
359 # define ENOMSG 122
360 # endif
361 # ifndef ENOPROTOOPT
362 # define ENOPROTOOPT 123
363 # endif
364 # ifndef ENOSPC
365 # define ENOSPC 28
366 # endif
367 # ifndef ENOSR
368 # define ENOSR 124
369 # endif
370 # ifndef ENXIO
371 # define ENXIO 6
372 # endif
373 # ifndef ENODEV
374 # define ENODEV 19
375 # endif
376 # ifndef ENOENT
377 # define ENOENT 2
378 # endif
379 # ifndef ESRCH
380 # define ESRCH 3
381 # endif
382 # ifndef ENOTDIR
383 # define ENOTDIR 20
384 # endif
385 # ifndef ENOTSOCK
386 # define ENOTSOCK 128
387 # endif
388 # ifndef ENOSTR
389 # define ENOSTR 125
390 # endif
391 # ifndef ENOTCONN
392 # define ENOTCONN 126
393 # endif
394 # ifndef ENOMEM
395 # define ENOMEM 12
396 # endif
397 # ifndef ENOTSUP
398 # define ENOTSUP 129
399 # endif
400 # ifndef ECANCELED
401 # define ECANCELED 105
402 # endif
403 # ifndef EINPROGRESS
404 # define EINPROGRESS 112
405 # endif
406 # ifndef EPERM
407 # define EPERM 1
408 # endif
409 # ifndef EOPNOTSUPP
410 # define EOPNOTSUPP 130
411 # endif
412 # ifndef EWOULDBLOCK
413 # define EWOULDBLOCK 140
414 # endif
415 # ifndef EOWNERDEAD
416 # define EOWNERDEAD 133
417 # endif
418 # ifndef EACCES
419 # define EACCES 13
420 # endif
421 # ifndef EPROTO
422 # define EPROTO 134
423 # endif
424 # ifndef EPROTONOSUPPORT
425 # define EPROTONOSUPPORT 135
426 # endif
427 # ifndef EROFS
428 # define EROFS 30
429 # endif
430 # ifndef EDEADLK
431 # define EDEADLK 36
432 # endif
433 # ifndef EAGAIN
434 # define EAGAIN 11
435 # endif
436 # ifndef ERANGE
437 # define ERANGE 34
438 # endif
439 # ifndef ENOTRECOVERABLE
440 # define ENOTRECOVERABLE 127
441 # endif
442 # ifndef ETIME
443 # define ETIME 137
444 # endif
445 # ifndef ETXTBSY
446 # define ETXTBSY 139
447 # endif
448 # ifndef ETIMEDOUT
449 # define ETIMEDOUT 138
450 # endif
451 # ifndef ENFILE
452 # define ENFILE 23
453 # endif
454 # ifndef EMFILE
455 # define EMFILE 24
456 # endif
457 # ifndef EMLINK
458 # define EMLINK 31
459 # endif
460 # ifndef ELOOP
461 # define ELOOP 114
462 # endif
463 # ifndef EOVERFLOW
464 # define EOVERFLOW 132
465 # endif
466 # ifndef EPROTOTYPE
467 # define EPROTOTYPE 136
468 # endif
469 #endif
16 #include
47017
47118 namespace llvm {
472
473 // is_error_code_enum
474
475 template struct is_error_code_enum : public std::false_type {};
476
477 // is_error_condition_enum
478
479 template struct is_error_condition_enum : public std::false_type {};
480
481 // Some error codes are not present on all platforms, so we provide equivalents
482 // for them:
483
484 enum class errc {
485 address_family_not_supported = EAFNOSUPPORT,
486 address_in_use = EADDRINUSE,
487 address_not_available = EADDRNOTAVAIL,
488 already_connected = EISCONN,
489 argument_list_too_long = E2BIG,
490 argument_out_of_domain = EDOM,
491 bad_address = EFAULT,
492 bad_file_descriptor = EBADF,
493 #ifdef EBADMSG
494 bad_message = EBADMSG,
495 #else
496 bad_message = EINVAL,
497 #endif
498 broken_pipe = EPIPE,
499 connection_aborted = ECONNABORTED,
500 connection_already_in_progress = EALREADY,
501 connection_refused = ECONNREFUSED,
502 connection_reset = ECONNRESET,
503 cross_device_link = EXDEV,
504 destination_address_required = EDESTADDRREQ,
505 device_or_resource_busy = EBUSY,
506 directory_not_empty = ENOTEMPTY,
507 executable_format_error = ENOEXEC,
508 file_exists = EEXIST,
509 file_too_large = EFBIG,
510 filename_too_long = ENAMETOOLONG,
511 function_not_supported = ENOSYS,
512 host_unreachable = EHOSTUNREACH,
513 identifier_removed = EIDRM,
514 illegal_byte_sequence = EILSEQ,
515 inappropriate_io_control_operation = ENOTTY,
516 interrupted = EINTR,
517 invalid_argument = EINVAL,
518 invalid_seek = ESPIPE,
519 io_error = EIO,
520 is_a_directory = EISDIR,
521 message_size = EMSGSIZE,
522 network_down = ENETDOWN,
523 network_reset = ENETRESET,
524 network_unreachable = ENETUNREACH,
525 no_buffer_space = ENOBUFS,
526 no_child_process = ECHILD,
527 #ifdef ENOLINK
528 no_link = ENOLINK,
529 #else
530 no_link = EINVAL,
531 #endif
532 no_lock_available = ENOLCK,
533 #ifdef ENODATA
534 no_message_available = ENODATA,
535 #else
536 no_message_available = ENOMSG,
537 #endif
538 no_message = ENOMSG,
539 no_protocol_option = ENOPROTOOPT,
540 no_space_on_device = ENOSPC,
541 #ifdef ENOSR
542 no_stream_resources = ENOSR,
543 #else
544 no_stream_resources = ENOMEM,
545 #endif
546 no_such_device_or_address = ENXIO,
547 no_such_device = ENODEV,
548 no_such_file_or_directory = ENOENT,
549 no_such_process = ESRCH,
550 not_a_directory = ENOTDIR,
551 not_a_socket = ENOTSOCK,
552 #ifdef ENOSTR
553 not_a_stream = ENOSTR,
554 #else
555 not_a_stream = EINVAL,
556 #endif
557 not_connected = ENOTCONN,
558 not_enough_memory = ENOMEM,
559 not_supported = ENOTSUP,
560 #ifdef ECANCELED
561 operation_canceled = ECANCELED,
562 #else
563 operation_canceled = EINVAL,
564 #endif
565 operation_in_progress = EINPROGRESS,
566 operation_not_permitted = EPERM,
567 operation_not_supported = EOPNOTSUPP,
568 operation_would_block = EWOULDBLOCK,
569 #ifdef EOWNERDEAD
570 owner_dead = EOWNERDEAD,
571 #else
572 owner_dead = EINVAL,
573 #endif
574 permission_denied = EACCES,
575 #ifdef EPROTO
576 protocol_error = EPROTO,
577 #else
578 protocol_error = EINVAL,
579 #endif
580 protocol_not_supported = EPROTONOSUPPORT,
581 read_only_file_system = EROFS,
582 resource_deadlock_would_occur = EDEADLK,
583 resource_unavailable_try_again = EAGAIN,
584 result_out_of_range = ERANGE,
585 #ifdef ENOTRECOVERABLE
586 state_not_recoverable = ENOTRECOVERABLE,
587 #else
588 state_not_recoverable = EINVAL,
589 #endif
590 #ifdef ETIME
591 stream_timeout = ETIME,
592 #else
593 stream_timeout = ETIMEDOUT,
594 #endif
595 text_file_busy = ETXTBSY,
596 timed_out = ETIMEDOUT,
597 too_many_files_open_in_system = ENFILE,
598 too_many_files_open = EMFILE,
599 too_many_links = EMLINK,
600 too_many_symbolic_link_levels = ELOOP,
601 value_too_large = EOVERFLOW,
602 wrong_protocol_type = EPROTOTYPE
603 };
604
605
606 template <> struct is_error_condition_enum : std::true_type { };
607
608 class error_condition;
609 class error_code;
610
611 // class error_category
612
613 class _do_message;
614
615 class error_category
616 {
617 public:
618 virtual ~error_category();
619
620 error_category();
621 private:
622 error_category(const error_category&) LLVM_DELETED_FUNCTION;
623 error_category& operator=(const error_category&) LLVM_DELETED_FUNCTION;
624
625 public:
626 virtual const char* name() const LLVM_NOEXCEPT = 0;
627 virtual error_condition default_error_condition(int _ev) const LLVM_NOEXCEPT;
628 virtual bool
629 equivalent(int _code, const error_condition &_condition) const LLVM_NOEXCEPT;
630 virtual bool equivalent(const error_code &_code,
631 int _condition) const LLVM_NOEXCEPT;
632 virtual std::string message(int _ev) const = 0;
633
634 bool operator==(const error_category& _rhs) const {return this == &_rhs;}
635
636 bool operator!=(const error_category& _rhs) const {return !(*this == _rhs);}
637
638 bool operator< (const error_category& _rhs) const {return this < &_rhs;}
639
640 friend class _do_message;
641 };
642
643 class _do_message : public error_category
644 {
645 public:
646 std::string message(int ev) const override;
647 };
648
649 const error_category& generic_category();
650 const error_category& system_category();
651
652 class error_condition
653 {
654 int _val_;
655 const error_category* _cat_;
656 public:
657 error_condition() : _val_(0), _cat_(&generic_category()) {}
658
659 error_condition(int _val, const error_category& _cat)
660 : _val_(_val), _cat_(&_cat) {}
661
662 template
663 error_condition(E _e, typename std::enable_if<
664 is_error_condition_enum::value
665 >::type* = 0)
666 {*this = make_error_condition(_e);}
667
668 void assign(int _val, const error_category& _cat) {
669 _val_ = _val;
670 _cat_ = &_cat;
671 }
672
673 template
674 typename std::enable_if::value,
675 error_condition &>::type
676 operator=(E _e) {
677 *this = make_error_condition(_e);
678 return *this;
679 }
680
681 void clear() {
682 _val_ = 0;
683 _cat_ = &generic_category();
684 }
685
686 int value() const {return _val_;}
687
688 const error_category& category() const {return *_cat_;}
689 std::string message() const;
690
691 LLVM_EXPLICIT operator bool() const { return _val_ != 0; }
692 };
693
694 inline error_condition make_error_condition(errc _e) {
695 return error_condition(static_cast(_e), generic_category());
19 using std::error_code;
20 using std::is_error_condition_enum;
21 using std::is_error_code_enum;
22 using std::system_category;
23 using std::generic_category;
24 using std::error_category;
25 using std::make_error_code;
26 using std::error_condition;
69627 }
69728
698 inline bool operator<(const error_condition& _x, const error_condition& _y) {
699 return _x.category() < _y.category()
700 || (_x.category() == _y.category() && _x.value() < _y.value());
701 }
702
703 // error_code
704
705 class error_code {
706 int _val_;
707 const error_category* _cat_;
708 public:
709 error_code() : _val_(0), _cat_(&system_category()) {}
710
711 error_code(int _val, const error_category& _cat)
712 : _val_(_val), _cat_(&_cat) {}
713
714 template
715 error_code(E _e, typename std::enable_if<
716 is_error_code_enum::value
717 >::type* = 0) {
718 *this = make_error_code(_e);
719 }
720
721 void assign(int _val, const error_category& _cat) {
722 _val_ = _val;
723 _cat_ = &_cat;
724 }
725
726 template
727 typename std::enable_if::value, error_code &>::type
728 operator=(E _e) {
729 *this = make_error_code(_e);
730 return *this;
731 }
732
733 void clear() {
734 _val_ = 0;
735 _cat_ = &system_category();
736 }
737
738 int value() const {return _val_;}
739
740 const error_category& category() const {return *_cat_;}
741
742 error_condition default_error_condition() const
743 {return _cat_->default_error_condition(_val_);}
744
745 std::string message() const;
746
747 LLVM_EXPLICIT operator bool() const {
748 return _val_ != 0;
749 }
750 };
751
752 inline error_code make_error_code(errc _e) {
753 return error_code(static_cast(_e), generic_category());
754 }
755
756 inline bool operator<(const error_code& _x, const error_code& _y) {
757 return _x.category() < _y.category()
758 || (_x.category() == _y.category() && _x.value() < _y.value());
759 }
760
761 inline bool operator==(const error_code& _x, const error_code& _y) {
762 return _x.category() == _y.category() && _x.value() == _y.value();
763 }
764
765 inline bool operator==(const error_code& _x, const error_condition& _y) {
766 return _x.category().equivalent(_x.value(), _y)
767 || _y.category().equivalent(_x, _y.value());
768 }
769
770 inline bool operator==(const error_condition& _x, const error_code& _y) {
771 return _y == _x;
772 }
773
774 inline bool operator==(const error_condition& _x, const error_condition& _y) {
775 return _x.category() == _y.category() && _x.value() == _y.value();
776 }
777
778 inline bool operator!=(const error_code& _x, const error_code& _y) {
779 return !(_x == _y);
780 }
781
782 inline bool operator!=(const error_code& _x, const error_condition& _y) {
783 return !(_x == _y);
784 }
785
786 inline bool operator!=(const error_condition& _x, const error_code& _y) {
787 return !(_x == _y);
788 }
789
790 inline bool operator!=(const error_condition& _x, const error_condition& _y) {
791 return !(_x == _y);
792 }
793 } // end namespace llvm
794
79529 #endif
4949 error_condition _object_error_category::default_error_condition(int EV) const {
5050 if (static_cast(EV) == object_error::success)
5151 return error_condition();
52 return errc::invalid_argument;
52 return std::errc::invalid_argument;
5353 }
5454
5555 const error_category &object::object_category() {
5454 error_condition default_error_condition(int EV) const LLVM_NOEXCEPT override {
5555 if (static_cast(EV) == instrprof_error::success)
5656 return error_condition();
57 return errc::invalid_argument;
57 return std::errc::invalid_argument;
5858 }
5959 };
6060 }
8282 RWMutex.cpp
8383 SearchForAddressOfSpecialSymbol.cpp
8484 Signals.cpp
85 system_error.cpp
8685 TargetRegistry.cpp
8786 ThreadLocal.cpp
8887 Threading.cpp
8988 TimeValue.cpp
9089 Valgrind.cpp
9190 Watchdog.cpp
91 WindowsError.cpp
9292
9393 ADDITIONAL_HEADERS
9494 Unix/Host.inc
9999 Unix/Program.inc
100100 Unix/RWMutex.inc
101101 Unix/Signals.inc
102 Unix/system_error.inc
103102 Unix/ThreadLocal.inc
104103 Unix/TimeValue.inc
105104 Unix/Watchdog.inc
112111 Windows/Program.inc
113112 Windows/RWMutex.inc
114113 Windows/Signals.inc
115 Windows/system_error.inc
116114 Windows/ThreadLocal.inc
117115 Windows/TimeValue.inc
118116 Windows/Watchdog.inc
5050 if (EC)
5151 return EC;
5252 else
53 return make_error_code(errc::operation_not_permitted);
53 return make_error_code(std::errc::operation_not_permitted);
5454 }
5555
5656 // Delete target file.
113113 if (Out.has_error()) {
114114 // We failed to write out PID, so make up an excuse, remove the
115115 // unique lock file, and fail.
116 Error = make_error_code(errc::no_space_on_device);
116 Error = make_error_code(std::errc::no_space_on_device);
117117 sys::fs::remove(UniqueLockFileName.c_str());
118118 return;
119119 }
126126 if (!EC)
127127 return;
128128
129 if (EC != errc::file_exists) {
129 if (EC != std::errc::file_exists) {
130130 Error = EC;
131131 return;
132132 }
360360 if (!Buf) {
361361 // Failed to create a buffer. The only way it can fail is if
362362 // new(std::nothrow) returns 0.
363 return make_error_code(errc::not_enough_memory);
363 return make_error_code(std::errc::not_enough_memory);
364364 }
365365
366366 std::unique_ptr SB(Buf);
203203 if (error_code EC =
204204 sys::fs::openFileForWrite(Twine(ResultPath.begin()), ResultFD,
205205 sys::fs::F_RW | sys::fs::F_Excl, Mode)) {
206 if (EC == errc::file_exists)
206 if (EC == std::errc::file_exists)
207207 goto retry_random_path;
208208 return EC;
209209 }
223223
224224 case FS_Dir: {
225225 if (error_code EC = sys::fs::create_directory(ResultPath.begin(), false)) {
226 if (EC == errc::file_exists)
226 if (EC == std::errc::file_exists)
227227 goto retry_random_path;
228228 return EC;
229229 }
828828 error_code EC = create_directory(P, IgnoreExisting);
829829 // If we succeeded, or had any error other than the parent not existing, just
830830 // return it.
831 if (EC != errc::no_such_file_or_directory)
831 if (EC != std::errc::no_such_file_or_directory)
832832 return EC;
833833
834834 // We failed because of a no_such_file_or_directory, try to create the
895895 SmallString<32> Buffer;
896896
897897 if (error_code ec = get_magic(path, Magic.size(), Buffer)) {
898 if (ec == errc::value_too_large) {
898 if (ec == std::errc::value_too_large) {
899899 // Magic.size() > file_size(Path).
900900 result = false;
901901 return error_code();
10421042 error_code identify_magic(const Twine &path, file_magic &result) {
10431043 SmallString<32> Magic;
10441044 error_code ec = get_magic(path, Magic.capacity(), Magic);
1045 if (ec && ec != errc::value_too_large)
1045 if (ec && ec != std::errc::value_too_large)
10461046 return ec;
10471047
10481048 result = identify_magic(Magic);
316316 // effectively prevents LLVM from erasing things like /dev/null, any block
317317 // special file, or other things that aren't "regular" files.
318318 if (!S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode) && !S_ISLNK(buf.st_mode))
319 return make_error_code(errc::operation_not_permitted);
319 return make_error_code(std::errc::operation_not_permitted);
320320
321321 if (::remove(p.begin()) == -1) {
322322 if (errno != ENOENT || !IgnoreNonExisting)
401401 file_status &Result) {
402402 if (StatRet != 0) {
403403 error_code ec(errno, generic_category());
404 if (ec == errc::no_such_file_or_directory)
404 if (ec == std::errc::no_such_file_or_directory)
405405 Result = file_status(file_type::file_not_found);
406406 else
407407 Result = file_status(file_type::status_error);
465465 return error_code();
466466 #else
467467 #warning Missing futimes() and futimens()
468 return make_error_code(errc::not_supported);
468 return make_error_code(std::errc::not_supported);
469469 #endif
470470 }
471471
509509 , Mapping() {
510510 // Make sure that the requested size fits within SIZE_T.
511511 if (length > std::numeric_limits::max()) {
512 ec = make_error_code(errc::invalid_argument);
512 ec = make_error_code(std::errc::invalid_argument);
513513 return;
514514 }
515515
538538 , Mapping() {
539539 // Make sure that the requested size fits within SIZE_T.
540540 if (length > std::numeric_limits::max()) {
541 ec = make_error_code(errc::invalid_argument);
541 ec = make_error_code(std::errc::invalid_argument);
542542 return;
543543 }
544544
644644 if (std::feof(file) != 0) {
645645 std::fclose(file);
646646 result.set_size(size);
647 return make_error_code(errc::value_too_large);
647 return make_error_code(std::errc::value_too_large);
648648 }
649649 }
650650 std::fclose(file);
+0
-34
lib/Support/Unix/system_error.inc less more
None //===- llvm/Support/Unix/system_error.inc - Unix error_code ------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides the Unix specific implementation of the error_code
10 // and error_condition classes.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 //=== WARNING: Implementation here must contain only generic UNIX code that
16 //=== is guaranteed to work on *all* UNIX variants.
17 //===----------------------------------------------------------------------===//
18
19 using namespace llvm;
20
21 std::string
22 _system_error_category::message(int ev) const {
23 return _do_message::message(ev);
24 }
25
26 error_condition
27 _system_error_category::default_error_condition(int ev) const {
28 #ifdef ELAST
29 if (ev > ELAST)
30 return error_condition(ev, system_category());
31 #endif // ELAST
32 return error_condition(ev, generic_category());
33 }
1616 //===----------------------------------------------------------------------===//
1717
1818 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/Support/WindowsError.h"
1920 #include
2021 #include
2122 #include
4445 using llvm::sys::windows::UTF16ToUTF8;
4546
4647 static error_code windows_error(DWORD E) {
47 return error_code(E, system_category());
48 return mapWindowsError(E);
4849 }
4950
5051 static error_code TempDir(SmallVectorImpl &Result) {
192193
193194 file_status ST;
194195 if (error_code EC = status(path, ST)) {
195 if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting)
196 if (EC != std::errc::no_such_file_or_directory || !IgnoreNonExisting)
196197 return EC;
197198 return error_code();
198199 }
204205 if (ST.type() == file_type::directory_file) {
205206 if (!::RemoveDirectoryW(c_str(path_utf16))) {
206207 error_code EC = windows_error(::GetLastError());
207 if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting)
208 if (EC != std::errc::no_such_file_or_directory || !IgnoreNonExisting)
208209 return EC;
209210 }
210211 return error_code();
211212 }
212213 if (!::DeleteFileW(c_str(path_utf16))) {
213214 error_code EC = windows_error(::GetLastError());
214 if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting)
215 if (EC != std::errc::no_such_file_or_directory || !IgnoreNonExisting)
215216 return EC;
216217 }
217218 return error_code();
515516 _close(FileDescriptor);
516517 } else
517518 ::CloseHandle(FileHandle);
518 return make_error_code(errc::invalid_argument);
519 return make_error_code(std::errc::invalid_argument);
519520 }
520521
521522 DWORD flprotect;
651652 if (closefd)
652653 _close(FileDescriptor);
653654 FileDescriptor = 0;
654 ec = make_error_code(errc::bad_file_descriptor);
655 ec = make_error_code(std::errc::bad_file_descriptor);
655656 return;
656657 }
657658
814815 if (LastError != ERROR_ACCESS_DENIED)
815816 return EC;
816817 if (is_directory(Name))
817 return make_error_code(errc::is_a_directory);
818 return make_error_code(std::errc::is_a_directory);
818819 return EC;
819820 }
820821
866867 if (LastError != ERROR_ACCESS_DENIED)
867868 return EC;
868869 if (is_directory(Name))
869 return make_error_code(errc::is_a_directory);
870 return make_error_code(std::errc::is_a_directory);
870871 return EC;
871872 }
872873
1212
1313 #include "llvm/Support/Allocator.h"
1414 #include "llvm/Support/ErrorHandling.h"
15 #include "llvm/Support/WindowsError.h"
1516 #include
1617
1718 // The Windows.h header must be after LLVM and standard headers.
179180 }
180181
181182 static error_code windows_error(DWORD E) {
182 return error_code(E, system_category());
183 return mapWindowsError(E);
183184 }
184185
185186 error_code
+0
-141
lib/Support/Windows/system_error.inc less more
None //===- llvm/Support/Win32/system_error.inc - Windows error_code --*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides the Windows specific implementation of the error_code
10 // and error_condition classes.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 //=== WARNING: Implementation here must contain only generic Windows code that
16 //=== is guaranteed to work on *all* Windows variants.
17 //===----------------------------------------------------------------------===//
18
19 #include
20 #include
21
22 using namespace llvm;
23
24 std::string
25 _system_error_category::message(int ev) const {
26 LPVOID lpMsgBuf = 0;
27 DWORD retval = ::FormatMessageA(
28 FORMAT_MESSAGE_ALLOCATE_BUFFER |
29 FORMAT_MESSAGE_FROM_SYSTEM |
30 FORMAT_MESSAGE_IGNORE_INSERTS,
31 NULL,
32 ev,
33 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
34 (LPSTR) &lpMsgBuf,
35 0,
36 NULL);
37 if (retval == 0) {
38 ::LocalFree(lpMsgBuf);
39 return std::string("Unknown error");
40 }
41
42 std::string str( static_cast(lpMsgBuf) );
43 ::LocalFree(lpMsgBuf);
44
45 while (str.size()
46 && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r'))
47 str.erase( str.size()-1 );
48 if (str.size() && str[str.size()-1] == '.')
49 str.erase( str.size()-1 );
50 return str;
51 }
52
53 // I'd rather not double the line count of the following.
54 #define MAP_ERR_TO_COND(x, y) case x: return make_error_condition(errc::y)
55
56 error_condition
57 _system_error_category::default_error_condition(int ev) const {
58 switch (ev) {
59 // Windows system -> posix_errno decode table ---------------------------//
60 // see WinError.h comments for descriptions of errors
61 MAP_ERR_TO_COND(ERROR_ACCESS_DENIED, permission_denied);
62 MAP_ERR_TO_COND(ERROR_ALREADY_EXISTS, file_exists);
63 MAP_ERR_TO_COND(ERROR_BAD_UNIT, no_such_device);
64 MAP_ERR_TO_COND(ERROR_BUFFER_OVERFLOW, filename_too_long);
65 MAP_ERR_TO_COND(ERROR_BUSY, device_or_resource_busy);
66 MAP_ERR_TO_COND(ERROR_BUSY_DRIVE, device_or_resource_busy);
67 MAP_ERR_TO_COND(ERROR_CANNOT_MAKE, permission_denied);
68 MAP_ERR_TO_COND(ERROR_CANTOPEN, io_error);
69 MAP_ERR_TO_COND(ERROR_CANTREAD, io_error);
70 MAP_ERR_TO_COND(ERROR_CANTWRITE, io_error);
71 MAP_ERR_TO_COND(ERROR_CURRENT_DIRECTORY, permission_denied);
72 MAP_ERR_TO_COND(ERROR_DEV_NOT_EXIST, no_such_device);
73 MAP_ERR_TO_COND(ERROR_DEVICE_IN_USE, device_or_resource_busy);
74 MAP_ERR_TO_COND(ERROR_DIR_NOT_EMPTY, directory_not_empty);
75 MAP_ERR_TO_COND(ERROR_DIRECTORY, invalid_argument);
76 MAP_ERR_TO_COND(ERROR_DISK_FULL, no_space_on_device);
77 MAP_ERR_TO_COND(ERROR_FILE_EXISTS, file_exists);
78 MAP_ERR_TO_COND(ERROR_FILE_NOT_FOUND, no_such_file_or_directory);
79 MAP_ERR_TO_COND(ERROR_HANDLE_DISK_FULL, no_space_on_device);
80 MAP_ERR_TO_COND(ERROR_HANDLE_EOF, value_too_large);
81 MAP_ERR_TO_COND(ERROR_INVALID_ACCESS, permission_denied);
82 MAP_ERR_TO_COND(ERROR_INVALID_DRIVE, no_such_device);
83 MAP_ERR_TO_COND(ERROR_INVALID_FUNCTION, function_not_supported);
84 MAP_ERR_TO_COND(ERROR_INVALID_HANDLE, invalid_argument);
85 MAP_ERR_TO_COND(ERROR_INVALID_NAME, invalid_argument);
86 MAP_ERR_TO_COND(ERROR_LOCK_VIOLATION, no_lock_available);
87 MAP_ERR_TO_COND(ERROR_LOCKED, no_lock_available);
88 MAP_ERR_TO_COND(ERROR_NEGATIVE_SEEK, invalid_argument);
89 MAP_ERR_TO_COND(ERROR_NOACCESS, permission_denied);
90 MAP_ERR_TO_COND(ERROR_NOT_ENOUGH_MEMORY, not_enough_memory);
91 MAP_ERR_TO_COND(ERROR_NOT_READY, resource_unavailable_try_again);
92 MAP_ERR_TO_COND(ERROR_NOT_SAME_DEVICE, cross_device_link);
93 MAP_ERR_TO_COND(ERROR_OPEN_FAILED, io_error);
94 MAP_ERR_TO_COND(ERROR_OPEN_FILES, device_or_resource_busy);
95 MAP_ERR_TO_COND(ERROR_OPERATION_ABORTED, operation_canceled);
96 MAP_ERR_TO_COND(ERROR_OUTOFMEMORY, not_enough_memory);
97 MAP_ERR_TO_COND(ERROR_PATH_NOT_FOUND, no_such_file_or_directory);
98 MAP_ERR_TO_COND(ERROR_BAD_NETPATH, no_such_file_or_directory);
99 MAP_ERR_TO_COND(ERROR_READ_FAULT, io_error);
100 MAP_ERR_TO_COND(ERROR_RETRY, resource_unavailable_try_again);
101 MAP_ERR_TO_COND(ERROR_SEEK, io_error);
102 MAP_ERR_TO_COND(ERROR_SHARING_VIOLATION, permission_denied);
103 MAP_ERR_TO_COND(ERROR_TOO_MANY_OPEN_FILES, too_many_files_open);
104 MAP_ERR_TO_COND(ERROR_WRITE_FAULT, io_error);
105 MAP_ERR_TO_COND(ERROR_WRITE_PROTECT, permission_denied);
106 MAP_ERR_TO_COND(ERROR_SEM_TIMEOUT, timed_out);
107 MAP_ERR_TO_COND(WSAEACCES, permission_denied);
108 MAP_ERR_TO_COND(WSAEADDRINUSE, address_in_use);
109 MAP_ERR_TO_COND(WSAEADDRNOTAVAIL, address_not_available);
110 MAP_ERR_TO_COND(WSAEAFNOSUPPORT, address_family_not_supported);
111 MAP_ERR_TO_COND(WSAEALREADY, connection_already_in_progress);
112 MAP_ERR_TO_COND(WSAEBADF, bad_file_descriptor);
113 MAP_ERR_TO_COND(WSAECONNABORTED, connection_aborted);
114 MAP_ERR_TO_COND(WSAECONNREFUSED, connection_refused);
115 MAP_ERR_TO_COND(WSAECONNRESET, connection_reset);
116 MAP_ERR_TO_COND(WSAEDESTADDRREQ, destination_address_required);
117 MAP_ERR_TO_COND(WSAEFAULT, bad_address);
118 MAP_ERR_TO_COND(WSAEHOSTUNREACH, host_unreachable);
119 MAP_ERR_TO_COND(WSAEINPROGRESS, operation_in_progress);
120 MAP_ERR_TO_COND(WSAEINTR, interrupted);
121 MAP_ERR_TO_COND(WSAEINVAL, invalid_argument);
122 MAP_ERR_TO_COND(WSAEISCONN, already_connected);
123 MAP_ERR_TO_COND(WSAEMFILE, too_many_files_open);
124 MAP_ERR_TO_COND(WSAEMSGSIZE, message_size);
125 MAP_ERR_TO_COND(WSAENAMETOOLONG, filename_too_long);
126 MAP_ERR_TO_COND(WSAENETDOWN, network_down);
127 MAP_ERR_TO_COND(WSAENETRESET, network_reset);
128 MAP_ERR_TO_COND(WSAENETUNREACH, network_unreachable);
129 MAP_ERR_TO_COND(WSAENOBUFS, no_buffer_space);
130 MAP_ERR_TO_COND(WSAENOPROTOOPT, no_protocol_option);
131 MAP_ERR_TO_COND(WSAENOTCONN, not_connected);
132 MAP_ERR_TO_COND(WSAENOTSOCK, not_a_socket);
133 MAP_ERR_TO_COND(WSAEOPNOTSUPP, operation_not_supported);
134 MAP_ERR_TO_COND(WSAEPROTONOSUPPORT, protocol_not_supported);
135 MAP_ERR_TO_COND(WSAEPROTOTYPE, wrong_protocol_type);
136 MAP_ERR_TO_COND(WSAETIMEDOUT, timed_out);
137 MAP_ERR_TO_COND(WSAEWOULDBLOCK, operation_would_block);
138 default: return error_condition(ev, system_category());
139 }
140 }
0 //===-- WindowsError.cpp - Support for mapping windows errors to posix-----===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements a mapping from windows errors to posix ones.
10 // The standard doesn't define what the equivalence is from system
11 // errors to generic ones. The one implemented in msvc is too conservative
12 // for llvm, so we do an extra mapping when constructing an error_code
13 // from an windows error. This allows the rest of llvm to simple checks
14 // like "EC == std::errc::file_exists" and have it work on both posix and
15 // windows.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifdef _MSC_VER
20
21 #include
22
23 #include "llvm/Support/WindowsError.h"
24
25 // I'd rather not double the line count of the following.
26 #define MAP_ERR_TO_COND(x, y) \
27 case x: \
28 return std::make_error_code(std::errc::y)
29
30 std::error_code llvm::mapWindowsError(unsigned EV) {
31 switch (EV) {
32 MAP_ERR_TO_COND(ERROR_ACCESS_DENIED, permission_denied);
33 MAP_ERR_TO_COND(ERROR_ALREADY_EXISTS, file_exists);
34 MAP_ERR_TO_COND(ERROR_BAD_UNIT, no_such_device);
35 MAP_ERR_TO_COND(ERROR_BUFFER_OVERFLOW, filename_too_long);
36 MAP_ERR_TO_COND(ERROR_BUSY, device_or_resource_busy);
37 MAP_ERR_TO_COND(ERROR_BUSY_DRIVE, device_or_resource_busy);
38 MAP_ERR_TO_COND(ERROR_CANNOT_MAKE, permission_denied);
39 MAP_ERR_TO_COND(ERROR_CANTOPEN, io_error);
40 MAP_ERR_TO_COND(ERROR_CANTREAD, io_error);
41 MAP_ERR_TO_COND(ERROR_CANTWRITE, io_error);
42 MAP_ERR_TO_COND(ERROR_CURRENT_DIRECTORY, permission_denied);
43 MAP_ERR_TO_COND(ERROR_DEV_NOT_EXIST, no_such_device);
44 MAP_ERR_TO_COND(ERROR_DEVICE_IN_USE, device_or_resource_busy);
45 MAP_ERR_TO_COND(ERROR_DIR_NOT_EMPTY, directory_not_empty);
46 MAP_ERR_TO_COND(ERROR_DIRECTORY, invalid_argument);
47 MAP_ERR_TO_COND(ERROR_DISK_FULL, no_space_on_device);
48 MAP_ERR_TO_COND(ERROR_FILE_EXISTS, file_exists);
49 MAP_ERR_TO_COND(ERROR_FILE_NOT_FOUND, no_such_file_or_directory);
50 MAP_ERR_TO_COND(ERROR_HANDLE_DISK_FULL, no_space_on_device);
51 MAP_ERR_TO_COND(ERROR_HANDLE_EOF, value_too_large);
52 MAP_ERR_TO_COND(ERROR_INVALID_ACCESS, permission_denied);
53 MAP_ERR_TO_COND(ERROR_INVALID_DRIVE, no_such_device);
54 MAP_ERR_TO_COND(ERROR_INVALID_FUNCTION, function_not_supported);
55 MAP_ERR_TO_COND(ERROR_INVALID_HANDLE, invalid_argument);
56 MAP_ERR_TO_COND(ERROR_INVALID_NAME, invalid_argument);
57 MAP_ERR_TO_COND(ERROR_LOCK_VIOLATION, no_lock_available);
58 MAP_ERR_TO_COND(ERROR_LOCKED, no_lock_available);
59 MAP_ERR_TO_COND(ERROR_NEGATIVE_SEEK, invalid_argument);
60 MAP_ERR_TO_COND(ERROR_NOACCESS, permission_denied);
61 MAP_ERR_TO_COND(ERROR_NOT_ENOUGH_MEMORY, not_enough_memory);
62 MAP_ERR_TO_COND(ERROR_NOT_READY, resource_unavailable_try_again);
63 MAP_ERR_TO_COND(ERROR_NOT_SAME_DEVICE, cross_device_link);
64 MAP_ERR_TO_COND(ERROR_OPEN_FAILED, io_error);
65 MAP_ERR_TO_COND(ERROR_OPEN_FILES, device_or_resource_busy);
66 MAP_ERR_TO_COND(ERROR_OPERATION_ABORTED, operation_canceled);
67 MAP_ERR_TO_COND(ERROR_OUTOFMEMORY, not_enough_memory);
68 MAP_ERR_TO_COND(ERROR_PATH_NOT_FOUND, no_such_file_or_directory);
69 MAP_ERR_TO_COND(ERROR_BAD_NETPATH, no_such_file_or_directory);
70 MAP_ERR_TO_COND(ERROR_READ_FAULT, io_error);
71 MAP_ERR_TO_COND(ERROR_RETRY, resource_unavailable_try_again);
72 MAP_ERR_TO_COND(ERROR_SEEK, io_error);
73 MAP_ERR_TO_COND(ERROR_SHARING_VIOLATION, permission_denied);
74 MAP_ERR_TO_COND(ERROR_TOO_MANY_OPEN_FILES, too_many_files_open);
75 MAP_ERR_TO_COND(ERROR_WRITE_FAULT, io_error);
76 MAP_ERR_TO_COND(ERROR_WRITE_PROTECT, permission_denied);
77 MAP_ERR_TO_COND(ERROR_SEM_TIMEOUT, timed_out);
78 MAP_ERR_TO_COND(WSAEACCES, permission_denied);
79 MAP_ERR_TO_COND(WSAEADDRINUSE, address_in_use);
80 MAP_ERR_TO_COND(WSAEADDRNOTAVAIL, address_not_available);
81 MAP_ERR_TO_COND(WSAEAFNOSUPPORT, address_family_not_supported);
82 MAP_ERR_TO_COND(WSAEALREADY, connection_already_in_progress);
83 MAP_ERR_TO_COND(WSAEBADF, bad_file_descriptor);
84 MAP_ERR_TO_COND(WSAECONNABORTED, connection_aborted);
85 MAP_ERR_TO_COND(WSAECONNREFUSED, connection_refused);
86 MAP_ERR_TO_COND(WSAECONNRESET, connection_reset);
87 MAP_ERR_TO_COND(WSAEDESTADDRREQ, destination_address_required);
88 MAP_ERR_TO_COND(WSAEFAULT, bad_address);
89 MAP_ERR_TO_COND(WSAEHOSTUNREACH, host_unreachable);
90 MAP_ERR_TO_COND(WSAEINPROGRESS, operation_in_progress);
91 MAP_ERR_TO_COND(WSAEINTR, interrupted);
92 MAP_ERR_TO_COND(WSAEINVAL, invalid_argument);
93 MAP_ERR_TO_COND(WSAEISCONN, already_connected);
94 MAP_ERR_TO_COND(WSAEMFILE, too_many_files_open);
95 MAP_ERR_TO_COND(WSAEMSGSIZE, message_size);
96 MAP_ERR_TO_COND(WSAENAMETOOLONG, filename_too_long);
97 MAP_ERR_TO_COND(WSAENETDOWN, network_down);
98 MAP_ERR_TO_COND(WSAENETRESET, network_reset);
99 MAP_ERR_TO_COND(WSAENETUNREACH, network_unreachable);
100 MAP_ERR_TO_COND(WSAENOBUFS, no_buffer_space);
101 MAP_ERR_TO_COND(WSAENOPROTOOPT, no_protocol_option);
102 MAP_ERR_TO_COND(WSAENOTCONN, not_connected);
103 MAP_ERR_TO_COND(WSAENOTSOCK, not_a_socket);
104 MAP_ERR_TO_COND(WSAEOPNOTSUPP, operation_not_supported);
105 MAP_ERR_TO_COND(WSAEPROTONOSUPPORT, protocol_not_supported);
106 MAP_ERR_TO_COND(WSAEPROTOTYPE, wrong_protocol_type);
107 MAP_ERR_TO_COND(WSAETIMEDOUT, timed_out);
108 MAP_ERR_TO_COND(WSAEWOULDBLOCK, operation_would_block);
109 default:
110 return std::error_code(EV, std::system_category());
111 }
112 }
113
114 #endif
7373 Node *N = DocIterator->getRoot();
7474 if (!N) {
7575 assert(Strm->failed() && "Root is NULL iff parsing failed");
76 EC = make_error_code(errc::invalid_argument);
76 EC = make_error_code(std::errc::invalid_argument);
7777 return false;
7878 }
7979
123123 // nodes are present.
124124 if (!CurrentNode) {
125125 if (Required)
126 EC = make_error_code(errc::invalid_argument);
126 EC = make_error_code(std::errc::invalid_argument);
127127 return false;
128128 }
129129
299299
300300 void Input::setError(Node *node, const Twine &message) {
301301 Strm->printError(node, message);
302 EC = make_error_code(errc::invalid_argument);
302 EC = make_error_code(std::errc::invalid_argument);
303303 }
304304
305305 Input::HNode *Input::createHNodes(Node *N) {
+0
-121
lib/Support/system_error.cpp less more
None //===---------------------- system_error.cpp ------------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This was lifted from libc++ and modified for C++03.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/Support/system_error.h"
14 #include "llvm/Support/Errno.h"
15 #include
16 #include
17
18 namespace llvm {
19
20 // class error_category
21
22 error_category::error_category() {
23 }
24
25 error_category::~error_category() {
26 }
27
28 error_condition
29 error_category::default_error_condition(int ev) const {
30 return error_condition(ev, *this);
31 }
32
33 bool
34 error_category::equivalent(int code, const error_condition& condition) const {
35 return default_error_condition(code) == condition;
36 }
37
38 bool
39 error_category::equivalent(const error_code& code, int condition) const {
40 return *this == code.category() && code.value() == condition;
41 }
42
43 std::string
44 _do_message::message(int ev) const {
45 return std::string(sys::StrError(ev));
46 }
47
48 class _generic_error_category : public _do_message {
49 public:
50 const char* name() const LLVM_NOEXCEPT override;
51 std::string message(int ev) const override;
52 };
53
54 const char*
55 _generic_error_category::name() const {
56 return "generic";
57 }
58
59 std::string
60 _generic_error_category::message(int ev) const {
61 #ifdef ELAST
62 if (ev > ELAST)
63 return std::string("unspecified generic_category error");
64 #endif // ELAST
65 return _do_message::message(ev);
66 }
67
68 const error_category&
69 generic_category() {
70 static _generic_error_category s;
71 return s;
72 }
73
74 class _system_error_category : public _do_message {
75 public:
76 const char* name() const LLVM_NOEXCEPT override;
77 std::string message(int ev) const override;
78 error_condition default_error_condition(int ev) const override;
79 };
80
81 const char*
82 _system_error_category::name() const {
83 return "system";
84 }
85
86 // std::string _system_error_category::message(int ev) const {
87 // Is in Platform/system_error.inc
88
89 // error_condition _system_error_category::default_error_condition(int ev) const
90 // Is in Platform/system_error.inc
91
92 const error_category&
93 system_category() {
94 static _system_error_category s;
95 return s;
96 }
97
98 // error_condition
99
100 std::string
101 error_condition::message() const {
102 return _cat_->message(_val_);
103 }
104
105 // error_code
106
107 std::string
108 error_code::message() const {
109 return _cat_->message(_val_);
110 }
111
112 } // end namespace llvm
113
114 // Include the truly platform-specific parts of this class.
115 #if defined(LLVM_ON_UNIX)
116 #include "Unix/system_error.inc"
117 #endif
118 #if defined(LLVM_ON_WIN32)
119 #include "Windows/system_error.inc"
120 #endif
0 ;RUN: rm -f %T/test.a
11 ;RUN: not llvm-ar r %T/test.a . 2>&1 | FileCheck %s
2 ;CHECK: .: Is a directory
2 ;CHECK: .: {{I|i}}s a directory
33
44 ;RUN: rm -f %T/test.a
55 ;RUN: touch %T/a-very-long-file-name
452452 // Linux cannot open directories with open(2), although
453453 // cygwin and *bsd can.
454454 if (NewStatus.type() == sys::fs::file_type::directory_file)
455 failIfError(make_error_code(errc::is_a_directory), NewFilename);
455 failIfError(make_error_code(std::errc::is_a_directory), NewFilename);
456456
457457 return NewFD;
458458 }
938938 // Create or open the archive object.
939939 std::unique_ptr Buf;
940940 error_code EC = MemoryBuffer::getFile(ArchiveName, Buf, -1, false);
941 if (EC && EC != llvm::errc::no_such_file_or_directory) {
941 if (EC && EC != std::errc::no_such_file_or_directory) {
942942 errs() << ToolName << ": error opening '" << ArchiveName
943943 << "': " << EC.message() << "!\n";
944944 return 1;
956956 return 0;
957957 }
958958
959 assert(EC == llvm::errc::no_such_file_or_directory);
959 assert(EC == std::errc::no_such_file_or_directory);
960960
961961 if (!shouldCreateArchive(Operation)) {
962962 failIfError(EC, Twine("error loading '") + ArchiveName + "'");
115115
116116 std::unique_ptr GCDA_Buff;
117117 if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) {
118 if (ec != errc::no_such_file_or_directory) {
118 if (ec != std::errc::no_such_file_or_directory) {
119119 errs() << InputGCDA << ": " << ec.message() << "\n";
120120 return 1;
121121 }
2121 class ObjectFile;
2222 class RelocationRef;
2323 }
24 class error_code;
2524
2625 extern cl::opt TripleName;
2726 extern cl::opt ArchName;
4949 error_condition _readobj_error_category::default_error_condition(int EV) const {
5050 if (static_cast(EV) == readobj_error::success)
5151 return error_condition();
52 return errc::invalid_argument;
52 return std::errc::invalid_argument;
5353 }
5454
5555 namespace llvm {
3232 return error_code(static_cast(e), readobj_category());
3333 }
3434
35 template <> struct is_error_code_enum : std::true_type { };
36
3735 } // namespace llvm
3836
37 namespace std {
38 template <> struct is_error_code_enum : std::true_type {};
39 }
40
3941 #endif
99 #ifndef LLVM_READOBJ_OBJDUMPER_H
1010 #define LLVM_READOBJ_OBJDUMPER_H
1111
12 #include "llvm/Support/system_error.h"
13
1214 #include
1315
1416 namespace llvm {
1618 namespace object {
1719 class ObjectFile;
1820 }
19
20 class error_code;
2121
2222 class StreamWriter;
2323
1616 namespace object {
1717 class RelocationRef;
1818 }
19
20 class error_code;
2119
2220 // Various helper functions.
2321 bool error(error_code ec);
310310 getDarwinDWARFResourceForPath(Path);
311311 BinaryOrErr = createBinary(ResourcePath);
312312 error_code EC = BinaryOrErr.getError();
313 if (EC != errc::no_such_file_or_directory && !error(EC)) {
313 if (EC != std::errc::no_such_file_or_directory && !error(EC)) {
314314 DbgBin = BinaryOrErr.get();
315315 ParsedBinariesAndObjects.push_back(std::unique_ptr(DbgBin));
316316 }
4141 _obj2yaml_error_category::default_error_condition(int ev) const {
4242 if (static_cast(ev) == obj2yaml_error::success)
4343 return error_condition();
44 return errc::invalid_argument;
44 return std::errc::invalid_argument;
4545 }
4646
4747 namespace llvm {
2626 return error_code(static_cast(e), obj2yaml_category());
2727 }
2828
29 template <> struct is_error_code_enum : std::true_type { };
30
3129 } // namespace llvm
3230
31 namespace std {
32 template <> struct is_error_code_enum : std::true_type {};
33 }
34
3335 #endif
1515 namespace {
1616
1717 ErrorOr t1() {return 1;}
18 ErrorOr t2() { return errc::invalid_argument; }
18 ErrorOr t2() { return std::errc::invalid_argument; }
1919
2020 TEST(ErrorOr, SimpleValue) {
2121 ErrorOr a = t1();
2929
3030 a = t2();
3131 EXPECT_FALSE(a);
32 EXPECT_EQ(errc::invalid_argument, a.getError());
32 EXPECT_EQ(std::errc::invalid_argument, a.getError());
3333 #ifdef EXPECT_DEBUG_DEATH
3434 EXPECT_DEBUG_DEATH(*a, "Cannot get value when an error exists");
3535 #endif
353353 ASSERT_NO_ERROR(fs::remove(Twine(TempPath2)));
354354 ASSERT_NO_ERROR(fs::remove(Twine(TempPath2)));
355355 ASSERT_EQ(fs::remove(Twine(TempPath2), false),
356 errc::no_such_file_or_directory);
356 std::errc::no_such_file_or_directory);
357357
358358 error_code EC = fs::status(TempPath2.c_str(), B);
359 EXPECT_EQ(EC, errc::no_such_file_or_directory);
359 EXPECT_EQ(EC, std::errc::no_such_file_or_directory);
360360 EXPECT_EQ(B.type(), fs::file_type::file_not_found);
361361
362362 // Make sure Temp2 doesn't exist.
396396 "abcdefghijklmnopqrstuvwxyz3abcdefghijklmnopqrstuvwxyz2"
397397 "abcdefghijklmnopqrstuvwxyz1abcdefghijklmnopqrstuvwxyz0";
398398 EXPECT_EQ(fs::createUniqueFile(Twine(Path270), FileDescriptor, TempPath),
399 error_code(ERROR_PATH_NOT_FOUND, system_category()));
399 std::errc::no_such_file_or_directory);
400400 #endif
401401 }
402402
404404 ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory) + "foo"));
405405 ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory) + "foo"));
406406 ASSERT_EQ(fs::create_directory(Twine(TestDirectory) + "foo", false),
407 errc::file_exists);
407 std::errc::file_exists);
408408 ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "foo"));
409409 }
410410
5757 // This is an approximation, on error we don't know in general if the file
5858 // existed or not.
5959 llvm::error_code EC = sys::fs::remove(Path, false);
60 return EC != llvm::errc::no_such_file_or_directory;
60 return EC != std::errc::no_such_file_or_directory;
6161 }
6262
6363 char * current_dir() {
4242 #include "llvm/Support/raw_ostream.h"
4343 #include "llvm/Support/system_error.h"
4444 #include "llvm/Support/type_traits.h"
45 #include "llvm/Support/WindowsError.h"
4546 #include
4647 #include
4748 #include
168169 typedef ScopedHandle FileScopedHandle;
169170 }
170171
171 static error_code windows_error(unsigned E) {
172 return error_code(E, system_category());
173 }
172 static error_code windows_error(DWORD E) { return mapWindowsError(E); }
174173
175174 static error_code GetFileNameFromHandle(HANDLE FileHandle,
176175 std::string& Name) {
425424 if (!success) {
426425 ec = windows_error(::GetLastError());
427426
428 if (ec == errc::timed_out) {
427 if (ec == std::errc::timed_out) {
429428 errs() << ToolName << ": Process timed out.\n";
430429 ::TerminateProcess(ProcessInfo.hProcess, -1);
431430 // Otherwise other stuff starts failing...