X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FFileUtilities.cpp;h=1736b0d5c31e2b0d99f23bb7158d624a990ab9b9;hb=92f7e8d92581e031beeee3dc6c170f5c2cc7ea18;hp=ad4ab8f004f3a015aa8a35b5d0a91f08a84763c2;hpb=30493372f3d403c9637eb479e7d0c4388b715c41;p=oota-llvm.git diff --git a/lib/Support/FileUtilities.cpp b/lib/Support/FileUtilities.cpp index ad4ab8f004f..1736b0d5c31 100644 --- a/lib/Support/FileUtilities.cpp +++ b/lib/Support/FileUtilities.cpp @@ -16,7 +16,6 @@ #include "llvm/System/Path.h" #include "llvm/System/MappedFile.h" #include "llvm/ADT/StringExtras.h" -#include #include #include using namespace llvm; @@ -85,7 +84,13 @@ static bool CompareNumbers(char *&F1P, char *&F2P, char *F1End, char *F2End, } if (F1NumEnd == F1P || F2NumEnd == F2P) { - if (ErrorMsg) *ErrorMsg = "Comparison failed, not a numeric difference."; + if (ErrorMsg) { + *ErrorMsg = "FP Comparison failed, not a numeric difference between '"; + *ErrorMsg += F1P[0]; + *ErrorMsg += "' and '"; + *ErrorMsg += F2P[0]; + *ErrorMsg += "'"; + } return true; } @@ -101,8 +106,9 @@ static bool CompareNumbers(char *&F1P, char *&F2P, char *F1End, char *F2End, Diff = 0; // Both zero. if (Diff > RelTolerance) { if (ErrorMsg) { - *ErrorMsg = "Compared: " + ftostr(V1) + " and " + ftostr(V2) + - ": diff = " + ftostr(Diff) + "\n"; + *ErrorMsg = "Compared: " + ftostr(V1) + " and " + ftostr(V2) + "\n"; + *ErrorMsg += "abs. diff = " + ftostr(std::abs(V1-V2)) + + " rel.diff = " + ftostr(Diff) + "\n"; *ErrorMsg += "Out of tolerance: rel/abs: " + ftostr(RelTolerance) + "/" + ftostr(AbsTolerance); } @@ -142,27 +148,32 @@ static void PadFileIfNeeded(char *&FileStart, char *&FileEnd, char *&FP) { /// error occurs, allowing the caller to distinguish between a failed diff and a /// file system error. /// -int llvm::DiffFilesWithTolerance(const sys::Path &FileA, - const sys::Path &FileB, +int llvm::DiffFilesWithTolerance(const sys::PathWithStatus &FileA, + const sys::PathWithStatus &FileB, double AbsTol, double RelTol, std::string *Error) { - sys::FileStatus FileAStat, FileBStat; - if (FileA.getFileStatus(FileAStat, Error)) + const sys::FileStatus *FileAStat = FileA.getFileStatus(false, Error); + if (!FileAStat) return 2; - if (FileB.getFileStatus(FileBStat, Error)) + const sys::FileStatus *FileBStat = FileB.getFileStatus(false, Error); + if (!FileBStat) return 2; // Check for zero length files because some systems croak when you try to // mmap an empty file. - size_t A_size = FileAStat.getSize(); - size_t B_size = FileBStat.getSize(); + size_t A_size = FileAStat->getSize(); + size_t B_size = FileBStat->getSize(); // If they are both zero sized then they're the same if (A_size == 0 && B_size == 0) return 0; + // If only one of them is zero sized then they can't be the same - if ((A_size == 0 || B_size == 0)) + if ((A_size == 0 || B_size == 0)) { + if (Error) + *Error = "Files differ: one is zero-sized, the other isn't"; return 1; + } // Now its safe to mmap the files into memory becasue both files // have a non-zero size. @@ -190,8 +201,11 @@ int llvm::DiffFilesWithTolerance(const sys::Path &FileA, if (std::memcmp(File1Start, File2Start, A_size) == 0) return 0; - if (AbsTol == 0 && RelTol == 0) + if (AbsTol == 0 && RelTol == 0) { + if (Error) + *Error = "Files differ without tolerance allowance"; return 1; // Files different! + } } char *OrigFile1Start = File1Start;