aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/SourceManager.cpp
diff options
context:
space:
mode:
authorBoaz Brickner <brickner@google.com>2024-11-13 07:58:11 +0100
committerGitHub <noreply@github.com>2024-11-13 07:58:11 +0100
commit9a365bc9a0dc92f25c0f1fdc25925b442dfe1455 (patch)
tree6712f96e102eb4d9b28eeccd8d66cf336201ad59 /clang/lib/Basic/SourceManager.cpp
parentedfa75de33433de29f438fbea4145ec6ae20e020 (diff)
downloadllvm-9a365bc9a0dc92f25c0f1fdc25925b442dfe1455.zip
llvm-9a365bc9a0dc92f25c0f1fdc25925b442dfe1455.tar.gz
llvm-9a365bc9a0dc92f25c0f1fdc25925b442dfe1455.tar.bz2
[Clang] [NFC] Add "human" diagnostic argument format (#115835)
This allows formatting large integers in a human friendly way. Example: "5321584" -> "5.32M". Use it where such human numbers are generated manually today.
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r--clang/lib/Basic/SourceManager.cpp35
1 files changed, 4 insertions, 31 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index af60348..9b983ce 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -29,7 +29,6 @@
#include "llvm/Support/Endian.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
@@ -2228,28 +2227,6 @@ LLVM_DUMP_METHOD void SourceManager::dump() const {
}
}
-// 123 -> "123".
-// 1234 -> "1.23k".
-// 123456 -> "123.46k".
-// 1234567 -> "1.23M".
-// 1234567890 -> "1.23G".
-// 1234567890123 -> "1.23T".
-static std::string humanizeNumber(uint64_t Number) {
- static constexpr std::array<std::pair<uint64_t, char>, 4> Units = {
- {{1'000'000'000'000UL, 'T'},
- {1'000'000'000UL, 'G'},
- {1'000'000UL, 'M'},
- {1'000UL, 'k'}}};
-
- for (const auto &[UnitSize, UnitSign] : Units) {
- if (Number >= UnitSize) {
- return llvm::formatv("{0:F}{1}", Number / static_cast<double>(UnitSize),
- UnitSign);
- }
- }
- return std::to_string(Number);
-}
-
void SourceManager::noteSLocAddressSpaceUsage(
DiagnosticsEngine &Diag, std::optional<unsigned> MaxNotes) const {
struct Info {
@@ -2319,9 +2296,8 @@ void SourceManager::noteSLocAddressSpaceUsage(
int UsagePercent = static_cast<int>(100.0 * double(LocalUsage + LoadedUsage) /
MaxLoadedOffset);
Diag.Report(SourceLocation(), diag::note_total_sloc_usage)
- << LocalUsage << humanizeNumber(LocalUsage) << LoadedUsage
- << humanizeNumber(LoadedUsage) << (LocalUsage + LoadedUsage)
- << humanizeNumber(LocalUsage + LoadedUsage) << UsagePercent;
+ << LocalUsage << LoadedUsage << (LocalUsage + LoadedUsage)
+ << UsagePercent;
// Produce notes on sloc address space usage for each file with a high usage.
uint64_t ReportedSize = 0;
@@ -2329,17 +2305,14 @@ void SourceManager::noteSLocAddressSpaceUsage(
llvm::make_range(SortedUsage.begin(), SortedEnd)) {
Diag.Report(FileInfo.Loc, diag::note_file_sloc_usage)
<< FileInfo.Inclusions << FileInfo.DirectSize
- << humanizeNumber(FileInfo.DirectSize)
- << (FileInfo.TotalSize - FileInfo.DirectSize)
- << humanizeNumber(FileInfo.TotalSize - FileInfo.DirectSize);
+ << (FileInfo.TotalSize - FileInfo.DirectSize);
ReportedSize += FileInfo.TotalSize;
}
// Describe any remaining usage not reported in the per-file usage.
if (ReportedSize != CountedSize) {
Diag.Report(SourceLocation(), diag::note_file_misc_sloc_usage)
- << (SortedUsage.end() - SortedEnd) << CountedSize - ReportedSize
- << humanizeNumber(CountedSize - ReportedSize);
+ << (SortedUsage.end() - SortedEnd) << CountedSize - ReportedSize;
}
}