28 #include <system_error> 33 return (C ==
'+' || C ==
'-');
41 case 'E':
return true;
42 default:
return false;
48 case '0':
case '1':
case '2':
case '3':
case '4':
49 case '5':
case '6':
case '7':
case '8':
case '9':
50 case '.':
return true;
55 static const char *
BackupNumber(
const char *Pos,
const char *FirstChar) {
60 bool HasPeriod =
false;
87 const char *F1End,
const char *F2End,
88 double AbsTolerance,
double RelTolerance,
89 std::string *ErrorMsg) {
90 const char *F1NumEnd, *F2NumEnd;
91 double V1 = 0.0,
V2 = 0.0;
95 while (isspace(static_cast<unsigned char>(*F1P)) && F1P != F1End)
97 while (isspace(static_cast<unsigned char>(*F2P)) && F2P != F2End)
109 V1 = strtod(F1P, const_cast<char**>(&F1NumEnd));
110 V2 = strtod(F2P, const_cast<char**>(&F2NumEnd));
112 if (*F1NumEnd ==
'D' || *F1NumEnd ==
'd') {
116 StrTmp[
static_cast<unsigned>(F1NumEnd-F1P)] =
'e';
118 V1 = strtod(&StrTmp[0], const_cast<char**>(&F1NumEnd));
119 F1NumEnd = F1P + (F1NumEnd-&StrTmp[0]);
122 if (*F2NumEnd ==
'D' || *F2NumEnd ==
'd') {
126 StrTmp[
static_cast<unsigned>(F2NumEnd-F2P)] =
'e';
128 V2 = strtod(&StrTmp[0], const_cast<char**>(&F2NumEnd));
129 F2NumEnd = F2P + (F2NumEnd-&StrTmp[0]);
133 if (F1NumEnd == F1P || F2NumEnd == F2P) {
135 *ErrorMsg =
"FP Comparison failed, not a numeric difference between '";
137 *ErrorMsg +=
"' and '";
154 if (Diff > RelTolerance) {
157 <<
"Compared: " << V1 <<
" and " <<
V2 <<
'\n' 158 <<
"abs. diff = " <<
std::abs(V1-
V2) <<
" rel.diff = " << Diff <<
'\n' 159 <<
"Out of tolerance: rel/abs: " << RelTolerance <<
'/' 167 F1P = F1NumEnd; F2P = F2NumEnd;
181 double AbsTol,
double RelTol,
182 std::string *
Error) {
186 if (std::error_code EC = F1OrErr.
getError()) {
188 *Error = EC.message();
194 if (std::error_code EC = F2OrErr.
getError()) {
196 *Error = EC.message();
206 const char *F1P = File1Start;
207 const char *F2P = File2Start;
212 if (A_size == B_size &&
217 if (AbsTol == 0 && RelTol == 0) {
219 *Error =
"Files differ without tolerance allowance";
223 bool CompareFailed =
false;
226 while (F1P < File1End && F2P < File2End && *F1P == *F2P) {
231 if (F1P >= File1End || F2P >= File2End)
break;
241 if (
CompareNumbers(F1P, F2P, File1End, File2End, AbsTol, RelTol, Error)) {
242 CompareFailed =
true;
249 bool F1AtEnd = F1P >= File1End;
250 bool F2AtEnd = F2P >= File2End;
251 if (!CompareFailed && (!F1AtEnd || !F2AtEnd)) {
260 if (
CompareNumbers(F1P, F2P, File1End, File2End, AbsTol, RelTol, Error))
261 CompareFailed =
true;
264 if (F1P < File1End || F2P < File2End)
265 CompareFailed =
true;
268 return CompareFailed;
272 OS <<
"atomic_write_error: ";
275 OS <<
"failed_to_create_uniq_file";
278 OS <<
"output_stream_error";
281 OS <<
"failed_to_rename_temp_file";
285 "failed_to_rename_temp_file::log()");
303 GeneratedUniqPath)) {
304 return llvm::make_error<AtomicFileWriteError>(
317 return llvm::make_error<AtomicFileWriteError>(
321 if (
const std::error_code
Error =
323 FinalPath.
str().c_str())) {
324 return llvm::make_error<AtomicFileWriteError>(
328 RemoveTmpFileOnFail.releaseFile();
Represents either an error or a value T.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
This class represents lattice values for constants.
std::error_code createUniqueFile(const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, unsigned Mode=all_read|all_write)
Create a uniquely named file.
static const char * BackupNumber(const char *Pos, const char *FirstChar)
size_t getBufferSize() const
void log(raw_ostream &OS) const override
Print an error message to an output stream.
FileRemover - This class is a simple object meant to be stack allocated.
static const char * EndOfNumber(const char *Pos)
EndOfNumber - Return the first character that is not part of the specified number.
int DiffFilesWithTolerance(StringRef FileA, StringRef FileB, double AbsTol, double RelTol, std::string *Error=nullptr)
DiffFilesWithTolerance - Compare the two files specified, returning 0 if the files match...
LLVM_NODISCARD size_t size() const
size - Get the string size.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
static bool CompareNumbers(const char *&F1P, const char *&F2P, const char *F1End, const char *F2End, double AbsTolerance, double RelTolerance, std::string *ErrorMsg)
CompareNumbers - compare two numbers, returning true if they are different.
std::error_code getError() const
static bool isNumberChar(char C)
static bool isSignedChar(char C)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool has_error() const
Return the value of the flag in this raw_fd_ostream indicating whether an output error has been encou...
raw_ostream & write(unsigned char C)
std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
static ErrorSuccess success()
Create a success value.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
const char * getBufferEnd() const
A raw_ostream that writes to a file descriptor.
Merge contiguous icmps into a memcmp
APFloat abs(APFloat X)
Returns the absolute value of the argument.
const char * getBufferStart() const
void close()
Manually flush the stream and close the file.
Provides ErrorOr<T> smart pointer.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
llvm::Error writeFileAtomically(StringRef TempPathModel, StringRef FinalPath, StringRef Buffer)
Creates a unique file with name according to the given TempPathModel, writes content of Buffer to the...
A raw_ostream that writes to an std::string.
Lightweight error class with error context and mandatory checking.
This class implements an extremely fast bulk output stream that can only output to a stream...
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
static bool isExponentChar(char C)
void clear_error()
Set the flag read by has_error() to false.