Skip to content

Commit 29e09af

Browse files
authored
[llvm] clang-format a few llvm/Support headers (#138703)
Reformat a few header files under llvm/Support/llvm/include with `clang-format` in preparation for a codemod (#136014). This is just a formatting change; no functionality is impacted.
1 parent e16e068 commit 29e09af

File tree

4 files changed

+421
-424
lines changed

4 files changed

+421
-424
lines changed

llvm/include/llvm/Support/ErrorHandling.h

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,46 @@
1717
#include "llvm/Support/Compiler.h"
1818

1919
namespace llvm {
20-
class StringRef;
21-
class Twine;
22-
23-
/// An error handler callback.
24-
typedef void (*fatal_error_handler_t)(void *user_data,
25-
const char *reason,
26-
bool gen_crash_diag);
27-
28-
/// install_fatal_error_handler - Installs a new error handler to be used
29-
/// whenever a serious (non-recoverable) error is encountered by LLVM.
30-
///
31-
/// If no error handler is installed the default is to print the error message
32-
/// to stderr, and call exit(1). If an error handler is installed then it is
33-
/// the handler's responsibility to log the message, it will no longer be
34-
/// printed to stderr. If the error handler returns, then exit(1) will be
35-
/// called.
36-
///
37-
/// It is dangerous to naively use an error handler which throws an exception.
38-
/// Even though some applications desire to gracefully recover from arbitrary
39-
/// faults, blindly throwing exceptions through unfamiliar code isn't a way to
40-
/// achieve this.
41-
///
42-
/// \param user_data - An argument which will be passed to the install error
43-
/// handler.
44-
void install_fatal_error_handler(fatal_error_handler_t handler,
45-
void *user_data = nullptr);
46-
47-
/// Restores default error handling behaviour.
48-
void remove_fatal_error_handler();
49-
50-
/// ScopedFatalErrorHandler - This is a simple helper class which just
51-
/// calls install_fatal_error_handler in its constructor and
52-
/// remove_fatal_error_handler in its destructor.
53-
struct ScopedFatalErrorHandler {
54-
explicit ScopedFatalErrorHandler(fatal_error_handler_t handler,
55-
void *user_data = nullptr) {
56-
install_fatal_error_handler(handler, user_data);
57-
}
58-
59-
~ScopedFatalErrorHandler() { remove_fatal_error_handler(); }
60-
};
20+
class StringRef;
21+
class Twine;
22+
23+
/// An error handler callback.
24+
typedef void (*fatal_error_handler_t)(void *user_data, const char *reason,
25+
bool gen_crash_diag);
26+
27+
/// install_fatal_error_handler - Installs a new error handler to be used
28+
/// whenever a serious (non-recoverable) error is encountered by LLVM.
29+
///
30+
/// If no error handler is installed the default is to print the error message
31+
/// to stderr, and call exit(1). If an error handler is installed then it is
32+
/// the handler's responsibility to log the message, it will no longer be
33+
/// printed to stderr. If the error handler returns, then exit(1) will be
34+
/// called.
35+
///
36+
/// It is dangerous to naively use an error handler which throws an exception.
37+
/// Even though some applications desire to gracefully recover from arbitrary
38+
/// faults, blindly throwing exceptions through unfamiliar code isn't a way to
39+
/// achieve this.
40+
///
41+
/// \param user_data - An argument which will be passed to the install error
42+
/// handler.
43+
void install_fatal_error_handler(fatal_error_handler_t handler,
44+
void *user_data = nullptr);
45+
46+
/// Restores default error handling behaviour.
47+
void remove_fatal_error_handler();
48+
49+
/// ScopedFatalErrorHandler - This is a simple helper class which just
50+
/// calls install_fatal_error_handler in its constructor and
51+
/// remove_fatal_error_handler in its destructor.
52+
struct ScopedFatalErrorHandler {
53+
explicit ScopedFatalErrorHandler(fatal_error_handler_t handler,
54+
void *user_data = nullptr) {
55+
install_fatal_error_handler(handler, user_data);
56+
}
57+
58+
~ScopedFatalErrorHandler() { remove_fatal_error_handler(); }
59+
};
6160

6261
/// @deprecated Use reportFatalInternalError() or reportFatalUsageError()
6362
/// instead.
@@ -139,10 +138,10 @@ void install_out_of_memory_new_handler();
139138
/// This function calls abort(), and prints the optional message to stderr.
140139
/// Use the llvm_unreachable macro (that adds location info), instead of
141140
/// calling this function directly.
142-
[[noreturn]] void
143-
llvm_unreachable_internal(const char *msg = nullptr, const char *file = nullptr,
144-
unsigned line = 0);
145-
}
141+
[[noreturn]] void llvm_unreachable_internal(const char *msg = nullptr,
142+
const char *file = nullptr,
143+
unsigned line = 0);
144+
} // namespace llvm
146145

147146
/// Marks that the current location is not supposed to be reachable.
148147
/// In !NDEBUG builds, prints the message and location info to stderr.
@@ -162,7 +161,7 @@ llvm_unreachable_internal(const char *msg = nullptr, const char *file = nullptr,
162161
/// diagnostics for unreachable code paths, and allows compilers to omit
163162
/// unnecessary code.
164163
#ifndef NDEBUG
165-
#define llvm_unreachable(msg) \
164+
#define llvm_unreachable(msg) \
166165
::llvm::llvm_unreachable_internal(msg, __FILE__, __LINE__)
167166
#elif !defined(LLVM_BUILTIN_UNREACHABLE)
168167
#define llvm_unreachable(msg) ::llvm::llvm_unreachable_internal()

llvm/include/llvm/Support/FileUtilities.h

Lines changed: 69 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -22,81 +22,79 @@
2222

2323
namespace llvm {
2424

25-
/// DiffFilesWithTolerance - Compare the two files specified, returning 0 if
26-
/// the files match, 1 if they are different, and 2 if there is a file error.
27-
/// This function allows you to specify an absolute and relative FP error that
28-
/// is allowed to exist. If you specify a string to fill in for the error
29-
/// option, it will set the string to an error message if an error occurs, or
30-
/// if the files are different.
31-
///
32-
int DiffFilesWithTolerance(StringRef FileA,
33-
StringRef FileB,
34-
double AbsTol, double RelTol,
35-
std::string *Error = nullptr);
36-
37-
38-
/// FileRemover - This class is a simple object meant to be stack allocated.
39-
/// If an exception is thrown from a region, the object removes the filename
40-
/// specified (if deleteIt is true).
41-
///
42-
class FileRemover {
43-
SmallString<128> Filename;
44-
bool DeleteIt;
45-
public:
46-
FileRemover() : DeleteIt(false) {}
47-
48-
explicit FileRemover(const Twine& filename, bool deleteIt = true)
25+
/// DiffFilesWithTolerance - Compare the two files specified, returning 0 if
26+
/// the files match, 1 if they are different, and 2 if there is a file error.
27+
/// This function allows you to specify an absolute and relative FP error that
28+
/// is allowed to exist. If you specify a string to fill in for the error
29+
/// option, it will set the string to an error message if an error occurs, or
30+
/// if the files are different.
31+
///
32+
int DiffFilesWithTolerance(StringRef FileA, StringRef FileB, double AbsTol,
33+
double RelTol, std::string *Error = nullptr);
34+
35+
/// FileRemover - This class is a simple object meant to be stack allocated.
36+
/// If an exception is thrown from a region, the object removes the filename
37+
/// specified (if deleteIt is true).
38+
///
39+
class FileRemover {
40+
SmallString<128> Filename;
41+
bool DeleteIt;
42+
43+
public:
44+
FileRemover() : DeleteIt(false) {}
45+
46+
explicit FileRemover(const Twine &filename, bool deleteIt = true)
4947
: DeleteIt(deleteIt) {
50-
filename.toVector(Filename);
51-
}
48+
filename.toVector(Filename);
49+
}
5250

53-
~FileRemover() {
54-
if (DeleteIt) {
55-
// Ignore problems deleting the file.
56-
sys::fs::remove(Filename);
57-
}
51+
~FileRemover() {
52+
if (DeleteIt) {
53+
// Ignore problems deleting the file.
54+
sys::fs::remove(Filename);
5855
}
59-
60-
/// setFile - Give ownership of the file to the FileRemover so it will
61-
/// be removed when the object is destroyed. If the FileRemover already
62-
/// had ownership of a file, remove it first.
63-
void setFile(const Twine& filename, bool deleteIt = true) {
64-
if (DeleteIt) {
65-
// Ignore problems deleting the file.
66-
sys::fs::remove(Filename);
67-
}
68-
69-
Filename.clear();
70-
filename.toVector(Filename);
71-
DeleteIt = deleteIt;
56+
}
57+
58+
/// setFile - Give ownership of the file to the FileRemover so it will
59+
/// be removed when the object is destroyed. If the FileRemover already
60+
/// had ownership of a file, remove it first.
61+
void setFile(const Twine &filename, bool deleteIt = true) {
62+
if (DeleteIt) {
63+
// Ignore problems deleting the file.
64+
sys::fs::remove(Filename);
7265
}
7366

74-
/// releaseFile - Take ownership of the file away from the FileRemover so it
75-
/// will not be removed when the object is destroyed.
76-
void releaseFile() { DeleteIt = false; }
77-
};
78-
79-
/// FilePermssionsApplier helps to copy permissions from an input file to
80-
/// an output one. It memorizes the status of the input file and can apply
81-
/// permissions and dates to the output file.
82-
class FilePermissionsApplier {
83-
public:
84-
static Expected<FilePermissionsApplier> create(StringRef InputFilename);
85-
86-
/// Apply stored permissions to the \p OutputFilename.
87-
/// Copy LastAccess and ModificationTime if \p CopyDates is true.
88-
/// Overwrite stored permissions if \p OverwritePermissions is specified.
89-
Error
90-
apply(StringRef OutputFilename, bool CopyDates = false,
91-
std::optional<sys::fs::perms> OverwritePermissions = std::nullopt);
92-
93-
private:
94-
FilePermissionsApplier(StringRef InputFilename, sys::fs::file_status Status)
95-
: InputFilename(InputFilename), InputStatus(Status) {}
96-
97-
StringRef InputFilename;
98-
sys::fs::file_status InputStatus;
99-
};
100-
} // End llvm namespace
67+
Filename.clear();
68+
filename.toVector(Filename);
69+
DeleteIt = deleteIt;
70+
}
71+
72+
/// releaseFile - Take ownership of the file away from the FileRemover so it
73+
/// will not be removed when the object is destroyed.
74+
void releaseFile() { DeleteIt = false; }
75+
};
76+
77+
/// FilePermssionsApplier helps to copy permissions from an input file to
78+
/// an output one. It memorizes the status of the input file and can apply
79+
/// permissions and dates to the output file.
80+
class FilePermissionsApplier {
81+
public:
82+
static Expected<FilePermissionsApplier> create(StringRef InputFilename);
83+
84+
/// Apply stored permissions to the \p OutputFilename.
85+
/// Copy LastAccess and ModificationTime if \p CopyDates is true.
86+
/// Overwrite stored permissions if \p OverwritePermissions is specified.
87+
Error
88+
apply(StringRef OutputFilename, bool CopyDates = false,
89+
std::optional<sys::fs::perms> OverwritePermissions = std::nullopt);
90+
91+
private:
92+
FilePermissionsApplier(StringRef InputFilename, sys::fs::file_status Status)
93+
: InputFilename(InputFilename), InputStatus(Status) {}
94+
95+
StringRef InputFilename;
96+
sys::fs::file_status InputStatus;
97+
};
98+
} // namespace llvm
10199

102100
#endif

0 commit comments

Comments
 (0)