Skip to content

[llvm] clang-format a few llvm/Support headers #138703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

andrurogerz
Copy link
Contributor

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.

@andrurogerz andrurogerz marked this pull request as ready for review May 6, 2025 18:25
@llvmbot
Copy link
Member

llvmbot commented May 6, 2025

@llvm/pr-subscribers-llvm-support

Author: Andrew Rogers (andrurogerz)

Changes

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.


Patch is 42.47 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/138703.diff

4 Files Affected:

  • (modified) llvm/include/llvm/Support/ErrorHandling.h (+45-46)
  • (modified) llvm/include/llvm/Support/FileUtilities.h (+69-71)
  • (modified) llvm/include/llvm/Support/Program.h (+209-208)
  • (modified) llvm/include/llvm/Support/Signals.h (+100-99)
diff --git a/llvm/include/llvm/Support/ErrorHandling.h b/llvm/include/llvm/Support/ErrorHandling.h
index 85daaee10458c..d66993b5b2d7a 100644
--- a/llvm/include/llvm/Support/ErrorHandling.h
+++ b/llvm/include/llvm/Support/ErrorHandling.h
@@ -17,47 +17,46 @@
 #include "llvm/Support/Compiler.h"
 
 namespace llvm {
-  class StringRef;
-  class Twine;
-
-  /// An error handler callback.
-  typedef void (*fatal_error_handler_t)(void *user_data,
-                                        const char *reason,
-                                        bool gen_crash_diag);
-
-  /// install_fatal_error_handler - Installs a new error handler to be used
-  /// whenever a serious (non-recoverable) error is encountered by LLVM.
-  ///
-  /// If no error handler is installed the default is to print the error message
-  /// to stderr, and call exit(1).  If an error handler is installed then it is
-  /// the handler's responsibility to log the message, it will no longer be
-  /// printed to stderr.  If the error handler returns, then exit(1) will be
-  /// called.
-  ///
-  /// It is dangerous to naively use an error handler which throws an exception.
-  /// Even though some applications desire to gracefully recover from arbitrary
-  /// faults, blindly throwing exceptions through unfamiliar code isn't a way to
-  /// achieve this.
-  ///
-  /// \param user_data - An argument which will be passed to the install error
-  /// handler.
-  void install_fatal_error_handler(fatal_error_handler_t handler,
-                                   void *user_data = nullptr);
-
-  /// Restores default error handling behaviour.
-  void remove_fatal_error_handler();
-
-  /// ScopedFatalErrorHandler - This is a simple helper class which just
-  /// calls install_fatal_error_handler in its constructor and
-  /// remove_fatal_error_handler in its destructor.
-  struct ScopedFatalErrorHandler {
-    explicit ScopedFatalErrorHandler(fatal_error_handler_t handler,
-                                     void *user_data = nullptr) {
-      install_fatal_error_handler(handler, user_data);
-    }
-
-    ~ScopedFatalErrorHandler() { remove_fatal_error_handler(); }
-  };
+class StringRef;
+class Twine;
+
+/// An error handler callback.
+typedef void (*fatal_error_handler_t)(void *user_data, const char *reason,
+                                      bool gen_crash_diag);
+
+/// install_fatal_error_handler - Installs a new error handler to be used
+/// whenever a serious (non-recoverable) error is encountered by LLVM.
+///
+/// If no error handler is installed the default is to print the error message
+/// to stderr, and call exit(1).  If an error handler is installed then it is
+/// the handler's responsibility to log the message, it will no longer be
+/// printed to stderr.  If the error handler returns, then exit(1) will be
+/// called.
+///
+/// It is dangerous to naively use an error handler which throws an exception.
+/// Even though some applications desire to gracefully recover from arbitrary
+/// faults, blindly throwing exceptions through unfamiliar code isn't a way to
+/// achieve this.
+///
+/// \param user_data - An argument which will be passed to the install error
+/// handler.
+void install_fatal_error_handler(fatal_error_handler_t handler,
+                                 void *user_data = nullptr);
+
+/// Restores default error handling behaviour.
+void remove_fatal_error_handler();
+
+/// ScopedFatalErrorHandler - This is a simple helper class which just
+/// calls install_fatal_error_handler in its constructor and
+/// remove_fatal_error_handler in its destructor.
+struct ScopedFatalErrorHandler {
+  explicit ScopedFatalErrorHandler(fatal_error_handler_t handler,
+                                   void *user_data = nullptr) {
+    install_fatal_error_handler(handler, user_data);
+  }
+
+  ~ScopedFatalErrorHandler() { remove_fatal_error_handler(); }
+};
 
 /// @deprecated Use reportFatalInternalError() or reportFatalUsageError()
 /// instead.
@@ -139,10 +138,10 @@ void install_out_of_memory_new_handler();
 /// This function calls abort(), and prints the optional message to stderr.
 /// Use the llvm_unreachable macro (that adds location info), instead of
 /// calling this function directly.
-[[noreturn]] void
-llvm_unreachable_internal(const char *msg = nullptr, const char *file = nullptr,
-                          unsigned line = 0);
-}
+[[noreturn]] void llvm_unreachable_internal(const char *msg = nullptr,
+                                            const char *file = nullptr,
+                                            unsigned line = 0);
+} // namespace llvm
 
 /// Marks that the current location is not supposed to be reachable.
 /// 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,
 /// diagnostics for unreachable code paths, and allows compilers to omit
 /// unnecessary code.
 #ifndef NDEBUG
-#define llvm_unreachable(msg) \
+#define llvm_unreachable(msg)                                                  \
   ::llvm::llvm_unreachable_internal(msg, __FILE__, __LINE__)
 #elif !defined(LLVM_BUILTIN_UNREACHABLE)
 #define llvm_unreachable(msg) ::llvm::llvm_unreachable_internal()
diff --git a/llvm/include/llvm/Support/FileUtilities.h b/llvm/include/llvm/Support/FileUtilities.h
index 9707724d63170..c5a8457ca3fbb 100644
--- a/llvm/include/llvm/Support/FileUtilities.h
+++ b/llvm/include/llvm/Support/FileUtilities.h
@@ -22,81 +22,79 @@
 
 namespace llvm {
 
-  /// DiffFilesWithTolerance - Compare the two files specified, returning 0 if
-  /// the files match, 1 if they are different, and 2 if there is a file error.
-  /// This function allows you to specify an absolute and relative FP error that
-  /// is allowed to exist.  If you specify a string to fill in for the error
-  /// option, it will set the string to an error message if an error occurs, or
-  /// if the files are different.
-  ///
-  int DiffFilesWithTolerance(StringRef FileA,
-                             StringRef FileB,
-                             double AbsTol, double RelTol,
-                             std::string *Error = nullptr);
-
-
-  /// FileRemover - This class is a simple object meant to be stack allocated.
-  /// If an exception is thrown from a region, the object removes the filename
-  /// specified (if deleteIt is true).
-  ///
-  class FileRemover {
-    SmallString<128> Filename;
-    bool DeleteIt;
-  public:
-    FileRemover() : DeleteIt(false) {}
-
-    explicit FileRemover(const Twine& filename, bool deleteIt = true)
+/// DiffFilesWithTolerance - Compare the two files specified, returning 0 if
+/// the files match, 1 if they are different, and 2 if there is a file error.
+/// This function allows you to specify an absolute and relative FP error that
+/// is allowed to exist.  If you specify a string to fill in for the error
+/// option, it will set the string to an error message if an error occurs, or
+/// if the files are different.
+///
+int DiffFilesWithTolerance(StringRef FileA, StringRef FileB, double AbsTol,
+                           double RelTol, std::string *Error = nullptr);
+
+/// FileRemover - This class is a simple object meant to be stack allocated.
+/// If an exception is thrown from a region, the object removes the filename
+/// specified (if deleteIt is true).
+///
+class FileRemover {
+  SmallString<128> Filename;
+  bool DeleteIt;
+
+public:
+  FileRemover() : DeleteIt(false) {}
+
+  explicit FileRemover(const Twine &filename, bool deleteIt = true)
       : DeleteIt(deleteIt) {
-      filename.toVector(Filename);
-    }
+    filename.toVector(Filename);
+  }
 
-    ~FileRemover() {
-      if (DeleteIt) {
-        // Ignore problems deleting the file.
-        sys::fs::remove(Filename);
-      }
+  ~FileRemover() {
+    if (DeleteIt) {
+      // Ignore problems deleting the file.
+      sys::fs::remove(Filename);
     }
-
-    /// setFile - Give ownership of the file to the FileRemover so it will
-    /// be removed when the object is destroyed.  If the FileRemover already
-    /// had ownership of a file, remove it first.
-    void setFile(const Twine& filename, bool deleteIt = true) {
-      if (DeleteIt) {
-        // Ignore problems deleting the file.
-        sys::fs::remove(Filename);
-      }
-
-      Filename.clear();
-      filename.toVector(Filename);
-      DeleteIt = deleteIt;
+  }
+
+  /// setFile - Give ownership of the file to the FileRemover so it will
+  /// be removed when the object is destroyed.  If the FileRemover already
+  /// had ownership of a file, remove it first.
+  void setFile(const Twine &filename, bool deleteIt = true) {
+    if (DeleteIt) {
+      // Ignore problems deleting the file.
+      sys::fs::remove(Filename);
     }
 
-    /// releaseFile - Take ownership of the file away from the FileRemover so it
-    /// will not be removed when the object is destroyed.
-    void releaseFile() { DeleteIt = false; }
-  };
-
-  /// FilePermssionsApplier helps to copy permissions from an input file to
-  /// an output one. It memorizes the status of the input file and can apply
-  /// permissions and dates to the output file.
-  class FilePermissionsApplier {
-  public:
-    static Expected<FilePermissionsApplier> create(StringRef InputFilename);
-
-    /// Apply stored permissions to the \p OutputFilename.
-    /// Copy LastAccess and ModificationTime if \p CopyDates is true.
-    /// Overwrite stored permissions if \p OverwritePermissions is specified.
-    Error
-    apply(StringRef OutputFilename, bool CopyDates = false,
-          std::optional<sys::fs::perms> OverwritePermissions = std::nullopt);
-
-  private:
-    FilePermissionsApplier(StringRef InputFilename, sys::fs::file_status Status)
-        : InputFilename(InputFilename), InputStatus(Status) {}
-
-    StringRef InputFilename;
-    sys::fs::file_status InputStatus;
-  };
-} // End llvm namespace
+    Filename.clear();
+    filename.toVector(Filename);
+    DeleteIt = deleteIt;
+  }
+
+  /// releaseFile - Take ownership of the file away from the FileRemover so it
+  /// will not be removed when the object is destroyed.
+  void releaseFile() { DeleteIt = false; }
+};
+
+/// FilePermssionsApplier helps to copy permissions from an input file to
+/// an output one. It memorizes the status of the input file and can apply
+/// permissions and dates to the output file.
+class FilePermissionsApplier {
+public:
+  static Expected<FilePermissionsApplier> create(StringRef InputFilename);
+
+  /// Apply stored permissions to the \p OutputFilename.
+  /// Copy LastAccess and ModificationTime if \p CopyDates is true.
+  /// Overwrite stored permissions if \p OverwritePermissions is specified.
+  Error
+  apply(StringRef OutputFilename, bool CopyDates = false,
+        std::optional<sys::fs::perms> OverwritePermissions = std::nullopt);
+
+private:
+  FilePermissionsApplier(StringRef InputFilename, sys::fs::file_status Status)
+      : InputFilename(InputFilename), InputStatus(Status) {}
+
+  StringRef InputFilename;
+  sys::fs::file_status InputStatus;
+};
+} // namespace llvm
 
 #endif
diff --git a/llvm/include/llvm/Support/Program.h b/llvm/include/llvm/Support/Program.h
index 9df94eb604c7d..d05d95559761a 100644
--- a/llvm/include/llvm/Support/Program.h
+++ b/llvm/include/llvm/Support/Program.h
@@ -1,4 +1,5 @@
-//===- llvm/Support/Program.h ------------------------------------*- C++ -*-===//
+//===- llvm/Support/Program.h ------------------------------------*- C++
+//-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -26,222 +27,222 @@ namespace llvm {
 class BitVector;
 namespace sys {
 
-  /// This is the OS-specific separator for PATH like environment variables:
-  // a colon on Unix or a semicolon on Windows.
+/// This is the OS-specific separator for PATH like environment variables:
+// a colon on Unix or a semicolon on Windows.
 #if defined(LLVM_ON_UNIX)
-  const char EnvPathSeparator = ':';
-#elif defined (_WIN32)
-  const char EnvPathSeparator = ';';
+const char EnvPathSeparator = ':';
+#elif defined(_WIN32)
+const char EnvPathSeparator = ';';
 #endif
 
 #if defined(_WIN32)
-  typedef unsigned long procid_t; // Must match the type of DWORD on Windows.
-  typedef void *process_t;        // Must match the type of HANDLE on Windows.
+typedef unsigned long procid_t; // Must match the type of DWORD on Windows.
+typedef void *process_t;        // Must match the type of HANDLE on Windows.
 #else
-  typedef ::pid_t procid_t;
-  typedef procid_t process_t;
+typedef ::pid_t procid_t;
+typedef procid_t process_t;
 #endif
 
-  /// This struct encapsulates information about a process.
-  struct ProcessInfo {
-    enum : procid_t { InvalidPid = 0 };
-
-    procid_t Pid;      /// The process identifier.
-    process_t Process; /// Platform-dependent process object.
-
-    /// The return code, set after execution.
-    int ReturnCode;
-
-    ProcessInfo();
-  };
-
-  /// This struct encapsulates information about a process execution.
-  struct ProcessStatistics {
-    std::chrono::microseconds TotalTime;
-    std::chrono::microseconds UserTime;
-    uint64_t PeakMemory = 0; ///< Maximum resident set size in KiB.
-  };
-
-  /// Find the first executable file \p Name in \p Paths.
-  ///
-  /// This does not perform hashing as a shell would but instead stats each PATH
-  /// entry individually so should generally be avoided. Core LLVM library
-  /// functions and options should instead require fully specified paths.
-  ///
-  /// \param Name name of the executable to find. If it contains any system
-  ///   slashes, it will be returned as is.
-  /// \param Paths optional list of paths to search for \p Name. If empty it
-  ///   will use the system PATH environment instead.
-  ///
-  /// \returns The fully qualified path to the first \p Name in \p Paths if it
-  ///   exists. \p Name if \p Name has slashes in it. Otherwise an error.
-  ErrorOr<std::string>
-  findProgramByName(StringRef Name, ArrayRef<StringRef> Paths = {});
-
-  // These functions change the specified standard stream (stdin or stdout) mode
-  // based on the Flags. They return errc::success if the specified stream was
-  // changed. Otherwise, a platform dependent error is returned.
-  std::error_code ChangeStdinMode(fs::OpenFlags Flags);
-  std::error_code ChangeStdoutMode(fs::OpenFlags Flags);
-
-  // These functions change the specified standard stream (stdin or stdout) to
-  // binary mode. They return errc::success if the specified stream
-  // was changed. Otherwise a platform dependent error is returned.
-  std::error_code ChangeStdinToBinary();
-  std::error_code ChangeStdoutToBinary();
-
-  /// This function executes the program using the arguments provided.  The
-  /// invoked program will inherit the stdin, stdout, and stderr file
-  /// descriptors, the environment and other configuration settings of the
-  /// invoking program.
-  /// This function waits for the program to finish, so should be avoided in
-  /// library functions that aren't expected to block. Consider using
-  /// ExecuteNoWait() instead.
-  /// \returns an integer result code indicating the status of the program.
-  /// A zero or positive value indicates the result code of the program.
-  /// -1 indicates failure to execute
-  /// -2 indicates a crash during execution or timeout
-  int ExecuteAndWait(
-      StringRef Program, ///< Path of the program to be executed. It is
-      ///< presumed this is the result of the findProgramByName method.
-      ArrayRef<StringRef> Args, ///< An array of strings that are passed to the
-      ///< program.  The first element should be the name of the program.
-      ///< The array should **not** be terminated by an empty StringRef.
-      std::optional<ArrayRef<StringRef>> Env =
-          std::nullopt, ///< An optional vector of
-      ///< strings to use for the program's environment. If not provided, the
-      ///< current program's environment will be used.  If specified, the
-      ///< vector should **not** be terminated by an empty StringRef.
-      ArrayRef<std::optional<StringRef>> Redirects = {}, ///<
-      ///< An array of optional paths. Should have a size of zero or three.
-      ///< If the array is empty, no redirections are performed.
-      ///< Otherwise, the inferior process's stdin(0), stdout(1), and stderr(2)
-      ///< will be redirected to the corresponding paths, if the optional path
-      ///< is present (not \c std::nullopt).
-      ///< When an empty path is passed in, the corresponding file descriptor
-      ///< will be disconnected (ie, /dev/null'd) in a portable way.
-      unsigned SecondsToWait = 0, ///< If non-zero, this specifies the amount
-      ///< of time to wait for the child process to exit. If the time
-      ///< expires, the child is killed and this call returns. If zero,
-      ///< this function will wait until the child finishes or forever if
-      ///< it doesn't.
-      unsigned MemoryLimit = 0, ///< If non-zero, this specifies max. amount
-      ///< of memory can be allocated by process. If memory usage will be
-      ///< higher limit, the child is killed and this call returns. If zero
-      ///< - no memory limit.
-      std::string *ErrMsg = nullptr, ///< If non-zero, provides a pointer to a
-      ///< string instance in which error messages will be returned. If the
-      ///< string is non-empty upon return an error occurred while invoking the
-      ///< program.
-      bool *ExecutionFailed = nullptr,
-      std::optional<ProcessStatistics> *ProcStat = nullptr, ///< If non-zero,
-      /// provides a pointer to a structure in which process execution
-      /// statistics will be stored.
-      BitVector *AffinityMask = nullptr ///< CPUs or processors the new
-                                        /// program shall run on.
-  );
-
-  /// Similar to \ref ExecuteAndWait, but returns immediately.
-  /// \returns The \ref ProcessInfo of the newly launched process.
-  /// \note On Microsoft Windows systems, users will need to either call
-  /// \ref Wait until the process has finished executing or win32's CloseHandle
-  /// API on ProcessInfo.ProcessHandle to avoid memory leaks.
-  ProcessInfo ExecuteNoWait(
-      StringRef Program, ArrayRef<StringRef> Args,
-      std::optional<ArrayRef<StringRef>> Env,
-      ArrayRef<std::optional<StringRef>> Redirects = {},
-      unsigned MemoryLimit = 0, std::string *ErrMsg = nullptr,
-      bool *ExecutionFailed = nullptr, BitVector *AffinityMask = nullptr,
-      /// If true the executed program detatches from the controlling
-      /// terminal. I/O streams such as llvm::outs, llvm::errs, and stdin will
-      /// be closed until redirected to another output location
-      bool DetachProcess = false);
-
-  /// Return true if the given arguments fit within system-specific
-  /// argument length limits.
-  bool commandLineFitsWithinSystemLimits(StringRef Program,
-                                         ArrayRef<StringRef> Args);
-
-  /// Return true if the given arguments fit within system-specific
-  /// argument length limits.
-  bool commandLineFitsWithinSystemLimits(StringRef Program,
-                                         ArrayRef<const char *> Args);
-
-  /// File encoding options when writing contents that a non-UTF8 tool will
-  /// read (on Windows systems). For UNIX, we always use UTF-8.
-  enum WindowsEncodingMethod {
-    /// UTF-8 is the LLVM native encoding, being the same as "do not perform
-    /// encoding conversion".
-    WEM_UTF8,
-    WEM_CurrentCodePage,
-    WEM_UTF16
-  };
-
-  /// Saves the UTF8-encoded \p contents string into the file \p FileName
-  /// using a specific encoding.
-  ///
-  /// This write file function adds the possibility to choose which encoding
-  /// to use when writing a text file. On Windows, this is important when
-  /// writing files with internationalization support with an encoding that is
-  /// different from the one used in LLVM (UTF-8). We use this when writing
-  /// response files, since GCC tools on MinGW only understand legacy code
-  /// pages, and VisualStudio tools only understand UTF-16.
-  /// For UNIX, using different encodings is silently ignored, since all tools
-  /// work well with UTF-8.
-  /// This function assumes that you only use UTF-8 *text* data and will co...
[truncated]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants