Fix casting issues on macOS

Summary:
`size_t` is platform-dependent, and on macOS it is defined as
`unsigned long long`. This is not the same type as is used in many calls
to templated functions that expect the same type. As a result, on macOS,
calls to `std::max` fail because a template function that takes
`uint64_t, unsigned long long` cannot be found.

To work around the issue:

* Specify explicit `std::max` and `std::min` functions where necessary,
  to work around the compiler trying (and failing) to find a suitable
  instantiation.
* For lambda return types, specify an explicit return type where necessary.
* For `operator ==()` calls, use an explicit cast where necessary.

(cherry picked from FBD15030283)
This commit is contained in:
Brian Gesiak 2019-04-22 11:27:50 -04:00 committed by Maksim Panchenko
parent d9f1bd42fd
commit eba1a67730
6 changed files with 17 additions and 13 deletions

View File

@ -590,14 +590,14 @@ void BinaryContext::printGlobalSymbols(raw_ostream& OS) const {
}
void BinaryContext::assignMemData() {
auto getAddress = [&](const MemInfo &MI) {
auto getAddress = [&](const MemInfo &MI) -> uint64_t {
if (!MI.Addr.IsSymbol)
return MI.Addr.Offset;
if (auto *BD = getBinaryDataByName(MI.Addr.Name))
return BD->getAddress() + MI.Addr.Offset;
return 0ul;
return 0;
};
// Map of sections (or heap/stack) to count/size.

View File

@ -120,7 +120,8 @@ void AlignerPass::alignBlocks(BinaryFunction &Function) {
const auto &BC = Function.getBinaryContext();
const auto FuncCount = std::max(1UL, Function.getKnownExecutionCount());
const auto FuncCount =
std::max<uint64_t>(1, Function.getKnownExecutionCount());
BinaryBasicBlock *PrevBB{nullptr};
for (auto *BB : Function.layout()) {
auto Count = BB->getKnownExecutionCount();
@ -140,7 +141,8 @@ void AlignerPass::alignBlocks(BinaryFunction &Function) {
continue;
const auto BlockSize = BC.computeCodeSize(BB->begin(), BB->end());
const auto BytesToUse = std::min(opts::BlockAlignment - 1UL, BlockSize);
const auto BytesToUse =
std::min<uint64_t>(opts::BlockAlignment - 1, BlockSize);
if (opts::AlignBlocksMinSize && BlockSize < opts::AlignBlocksMinSize)
continue;

View File

@ -1438,7 +1438,8 @@ PrintProgramStats::runOnFunctions(BinaryContext &BC) {
if (!BF.hasValidProfile())
continue;
const auto HotThreshold = std::max(BF.getKnownExecutionCount(), 1UL);
const auto HotThreshold =
std::max<uint64_t>(BF.getKnownExecutionCount(), 1);
bool HotSeen = false;
for (const auto *BB : BF.rlayout()) {
if (!HotSeen && BB->getKnownExecutionCount() > HotThreshold) {

View File

@ -295,7 +295,7 @@ private:
Size.reserve(BF.layout_size());
for (auto BB : BF.layout()) {
size_t Index = BB->getLayoutIndex();
Size.push_back(std::max(BB->estimateSize(), size_t(1)));
Size.push_back(std::max<uint64_t>(BB->estimateSize(), 1));
AllClusters.emplace_back(BB, ExecutionCounts[Index], Size[Index]);
Clusters.push_back(&AllClusters[Index]);
CurCluster.push_back(&AllClusters[Index]);

View File

@ -1444,12 +1444,12 @@ void IndirectCallPromotion::runOnFunctions(BinaryContext &BC) {
<< "BOLT-INFO: ICP percentage of indirect calls that can be "
"optimized = "
<< format("%.1f", (100.0 * TotalNumFrequentCalls) /
std::max(TotalIndirectCalls, 1ul))
std::max<size_t>(TotalIndirectCalls, 1))
<< "%\n"
<< "BOLT-INFO: ICP percentage of indirect callsites that are "
"optimized = "
<< format("%.1f", (100.0 * TotalOptimizedIndirectCallsites) /
std::max(TotalIndirectCallsites, 1ul))
std::max<uint64_t>(TotalIndirectCallsites, 1))
<< "%\n"
<< "BOLT-INFO: ICP number of method load elimination candidates = "
<< TotalMethodLoadEliminationCandidates
@ -1457,17 +1457,17 @@ void IndirectCallPromotion::runOnFunctions(BinaryContext &BC) {
<< "BOLT-INFO: ICP percentage of method calls candidates that have "
"loads eliminated = "
<< format("%.1f", (100.0 * TotalMethodLoadsEliminated) /
std::max(TotalMethodLoadEliminationCandidates, 1ul))
std::max<uint64_t>(TotalMethodLoadEliminationCandidates, 1))
<< "%\n"
<< "BOLT-INFO: ICP percentage of indirect branches that are "
"optimized = "
<< format("%.1f", (100.0 * TotalNumFrequentJmps) /
std::max(TotalIndirectJmps, 1ul))
std::max<uint64_t>(TotalIndirectJmps, 1))
<< "%\n"
<< "BOLT-INFO: ICP percentage of jump table callsites that are "
<< "optimized = "
<< format("%.1f", (100.0 * TotalOptimizedJumpTableCallsites) /
std::max(TotalJumpTableCallsites, 1ul))
std::max<uint64_t>(TotalJumpTableCallsites, 1))
<< "%\n"
<< "BOLT-INFO: ICP number of jump table callsites that can use hot "
<< "indices = " << TotalIndexBasedCandidates
@ -1475,7 +1475,7 @@ void IndirectCallPromotion::runOnFunctions(BinaryContext &BC) {
<< "BOLT-INFO: ICP percentage of jump table callsites that use hot "
"indices = "
<< format("%.1f", (100.0 * TotalIndexBasedJumps) /
std::max(TotalIndexBasedCandidates, 1ul))
std::max<uint64_t>(TotalIndexBasedCandidates, 1))
<< "%\n";
#ifndef NDEBUG

View File

@ -268,7 +268,8 @@ ProfileReader::readProfile(const std::string &FileName,
BinaryFunction &BF) {
if (opts::IgnoreHash && Profile.NumBasicBlocks == BF.size())
return true;
if (!opts::IgnoreHash && Profile.Hash == BF.hash(/*Recompute = */false))
if (!opts::IgnoreHash &&
Profile.Hash == static_cast<uint64_t>(BF.hash(/*Recompute = */false)))
return true;
return false;
};