Summary: The .clang-tidy file is copied from the top-level LLVM source directory. Also fix warnings generated by clang-format: * Moved SimpleHostPlatformDevice.h so its header include guard could have the right format. * Changed signatures of methods taking llvm::Twine by value to take it by const ref instead. * Add "noexcept" to some move constructors and assignment operators. * Removed a bunch of places where single-statement loops and conditionals were surrounded with braces. (This was not found by the current clang-tidy, but with a local patch that I hope to upstream soon.) Reviewers: jlebar, jprice Subscribers: parallel_libs-commits Differential Revision: https://reviews.llvm.org/D24468 llvm-svn: 281374
71 lines
1.8 KiB
C++
71 lines
1.8 KiB
C++
//===-- Error.cpp - Error handling ----------------------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
/// Types for returning recoverable errors.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "streamexecutor/Error.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
namespace {
|
|
|
|
// An error with a string message describing the cause.
|
|
class StreamExecutorError : public llvm::ErrorInfo<StreamExecutorError> {
|
|
public:
|
|
StreamExecutorError(llvm::StringRef Message) : Message(Message.str()) {}
|
|
|
|
void log(llvm::raw_ostream &OS) const override { OS << Message; }
|
|
|
|
std::error_code convertToErrorCode() const override {
|
|
llvm_unreachable(
|
|
"StreamExecutorError does not support conversion to std::error_code");
|
|
}
|
|
|
|
std::string getErrorMessage() const { return Message; }
|
|
|
|
static char ID;
|
|
|
|
private:
|
|
std::string Message;
|
|
};
|
|
|
|
char StreamExecutorError::ID = 0;
|
|
|
|
} // namespace
|
|
|
|
namespace streamexecutor {
|
|
|
|
Error make_error(const Twine &Message) {
|
|
return llvm::make_error<StreamExecutorError>(Message.str());
|
|
}
|
|
|
|
std::string consumeAndGetMessage(Error &&E) {
|
|
if (!E)
|
|
return "success";
|
|
std::string Message;
|
|
llvm::handleAllErrors(std::move(E),
|
|
[&Message](const StreamExecutorError &SEE) {
|
|
Message = SEE.getErrorMessage();
|
|
});
|
|
return Message;
|
|
}
|
|
|
|
void dieIfError(Error &&E) {
|
|
if (E) {
|
|
std::fprintf(stderr, "Error encountered: %s.\n",
|
|
streamexecutor::consumeAndGetMessage(std::move(E)).c_str());
|
|
std::exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
} // namespace streamexecutor
|