Skip to content

Commit e8a2c1a

Browse files
author
Andres Wearden
committed
added three llvm-lit tests, testing the --merge-binary-coverage flag and the --show-arch-executables flag
1 parent d9006f2 commit e8a2c1a

21 files changed

+349
-146
lines changed

llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,7 @@ class CoverageMapping {
10181018
DenseMap<std::pair<size_t, hash_code>, unsigned> RecordIndices;
10191019
uint64_t DebugCount = 0;
10201020
std::vector<FunctionRecord> AllFunctionRegions;
1021+
StringRef ObjectFilename;
10211022

10221023

10231024
std::map<std::pair<std::string, std::string>, std::vector<uint64_t>> AggregatedCounts;
@@ -1073,6 +1074,12 @@ class CoverageMapping {
10731074
Arch = StringRef(NewArch);
10741075
}
10751076

1077+
void setObjectFilename(StringRef ObjectFilename){
1078+
this->ObjectFilename = StringRef(ObjectFilename);
1079+
}
1080+
1081+
const StringRef &getObjectFilename() const { return this->ObjectFilename; }
1082+
10761083
CoverageMapping(const CoverageMapping &) = delete;
10771084
CoverageMapping &operator=(const CoverageMapping &) = delete;
10781085

llvm/include/llvm/ProfileData/InstrProf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,8 @@ class InstrProfSymtab {
646646

647647
uint64_t HashValue = IndexedInstrProf::ComputeHash(SymbolName);
648648
std::string HashStr(std::to_string(HashValue));
649-
//if ObjectFilename is not empty from the --object-aware-hashing flag, add ObjectFilename to hash context
649+
// if ObjectFilename is not empty from the --object-aware-hashing flag, add
650+
// ObjectFilename to hash context
650651
if(!ObjectFilename.empty()){
651652
std::string CombinedStr = HashStr + ":" + ObjectFilename.str();
652653
StringRef HashRef = CombinedStr;

llvm/include/llvm/ProfileData/InstrProfReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class InstrProfReader {
162162
LLVM_ABI void accumulateCounts(CountSumOrPercent &Sum, bool IsCS);
163163

164164
protected:
165-
//Storing ObjectFilename Information as a string
165+
// Storing ObjectFilename Information as a string
166166
std::string ObjectFilename;
167167

168168
std::unique_ptr<InstrProfSymtab> Symtab;

llvm/lib/ProfileData/Coverage/CoverageMapping.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "llvm/Support/ScopedPrinter.h"
3333
#include "llvm/Support/VirtualFileSystem.h"
3434
#include "llvm/Support/raw_ostream.h"
35+
#include "llvm/Object/ObjectFile.h"
3536
#include <algorithm>
3637
#include <cassert>
3738
#include <cmath>
@@ -825,6 +826,7 @@ class MCDCDecisionRecorder {
825826

826827
} // namespace
827828

829+
828830
Error CoverageMapping::loadFunctionRecord(
829831
const CoverageMappingRecord &Record,
830832
const std::optional<std::reference_wrapper<IndexedInstrProfReader>>
@@ -954,13 +956,13 @@ Error CoverageMapping::loadFunctionRecord(
954956
auto FilenamesHash = hash_combine_range(Record.Filenames);
955957
std::string HashStr = OrigFuncName.str();
956958
if(ShowArchExecutables){
957-
HashStr += ":" + Arch.str();
959+
HashStr += ":" + ObjectFilename.str();
958960
}else{
959961
auto LogicalFuncKey = std::make_pair(FilenamesHash, hash_value(OrigFuncName));
960962
auto It = RecordIndices.find(LogicalFuncKey);
961963
if (It != RecordIndices.end()) {
962964
auto &ExistingFunction = Functions[It->second];
963-
// Create a map of existing regions for efficient lookup.
965+
// Create a map of existing regions for lookup.
964966
// The key uniquely identifies the source region.
965967
using RegionKey = std::tuple<unsigned, unsigned, unsigned, unsigned, unsigned>;
966968
std::map<RegionKey, CountedRegion *> ExistingRegionsMap;
@@ -987,9 +989,7 @@ Error CoverageMapping::loadFunctionRecord(
987989
ExistingFunction.CountedRegions.push_back(NewRegion);
988990
}
989991
}
990-
// Since we modified an existing function, we don't add a new one.
991-
// We just need to make sure we don't add the new 'Function' object later.
992-
// The logic below this block needs to be adjusted to handle this.
992+
993993
return Error::success();
994994
}
995995
RecordIndices.insert({LogicalFuncKey, Functions.size()});
@@ -1048,7 +1048,7 @@ Error CoverageMapping::loadFromReaders(
10481048
std::optional<std::reference_wrapper<IndexedInstrProfReader>>
10491049
&ProfileReader,
10501050
CoverageMapping &Coverage, StringRef Arch, StringRef ObjectFilename, bool ShowArchExecutables, bool MergeBinaryCoverage) {
1051-
1051+
10521052
assert(!Coverage.SingleByteCoverage || !ProfileReader ||
10531053
*Coverage.SingleByteCoverage ==
10541054
ProfileReader.value().get().hasSingleByteCoverage());
@@ -1447,16 +1447,16 @@ class SegmentBuilder {
14471447

14481448
sortNestedRegions(Regions);
14491449

1450-
1451-
//check to see if a skipped region from executable A is within a CodeRegion from executable B,
1452-
//promote to CodeRegion if skipped region does not show up on any other executable.
1450+
// check to see if a skipped region from executable A is within a CodeRegion
1451+
// from executable B, promote to CodeRegion if skipped region does not show
1452+
// up on any other executable.
14531453
for(auto *I = Regions.begin(); I != Regions.end(); ++I){
14541454
bool FoundMatchInOtherBinary = false;
14551455
for(auto *J = I + 1; J != Regions.end(); ++J){
1456-
if(I->ObjectFilename != J->ObjectFilename &&
1457-
J->Kind == CounterMappingRegion::SkippedRegion
1458-
&& I->Kind != CounterMappingRegion::SkippedRegion &&
1459-
J->startLoc() >= I->startLoc() && J->endLoc() <= I->endLoc()){
1456+
if (I->ObjectFilename != J->ObjectFilename &&
1457+
J->Kind == CounterMappingRegion::SkippedRegion &&
1458+
I->Kind != CounterMappingRegion::SkippedRegion &&
1459+
J->startLoc() >= I->startLoc() && J->endLoc() <= I->endLoc()) {
14601460
for(auto *K = J + 1; K != Regions.end(); ++K){
14611461
if(K->ObjectFilename == I->ObjectFilename &&
14621462
J->startLoc() == K->startLoc() && J->endLoc() == K->endLoc()){
@@ -1527,7 +1527,7 @@ static SmallBitVector gatherFileIDs(StringRef SourceFile,
15271527
static std::optional<unsigned>
15281528
findMainViewFileID(const FunctionRecord &Function) {
15291529
SmallBitVector IsNotExpandedFile(Function.Filenames.size(), true);
1530-
for (const auto &CR : Function.CountedRegions){
1530+
for (const auto &CR : Function.CountedRegions) {
15311531
if (CR.Kind == CounterMappingRegion::ExpansionRegion)
15321532
IsNotExpandedFile[CR.ExpandedFileID] = false;
15331533
}

llvm/lib/ProfileData/InstrProf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ Error InstrProfSymtab::create(StringRef NameStrings) {
622622
}
623623

624624
Error InstrProfSymtab::create(StringRef FuncNameStrings,
625-
StringRef VTableNameStrings) {
625+
StringRef VTableNameStrings) {
626626
if (Error E = readAndDecodeStrings(FuncNameStrings, std::bind(&InstrProfSymtab::addFuncName, this, std::placeholders::_1)))
627627
return E;
628628

llvm/lib/ProfileData/InstrProfReader.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ Expected<std::unique_ptr<InstrProfReader>> InstrProfReader::create(
159159
const InstrProfCorrelator *Correlator,
160160
const object::BuildIDFetcher *BIDFetcher,
161161
const InstrProfCorrelator::ProfCorrelatorKind BIDFetcherCorrelatorKind,
162-
std::function<void(Error)> Warn,
163-
StringRef ObjectFilename) {
162+
std::function<void(Error)> Warn, StringRef ObjectFilename) {
164163
// Set up the buffer to read.
165164
auto BufferOrError = setupMemoryBuffer(Path, FS);
166165
if (Error E = BufferOrError.takeError())
@@ -196,7 +195,7 @@ Expected<std::unique_ptr<InstrProfReader>> InstrProfReader::create(
196195

197196
// Initialize the reader and return the result.
198197

199-
//Pass the ObjectFilename to Result
198+
// Pass the ObjectFilename to Result
200199
if(Result){
201200
Result->setObjectFilename(ObjectFilename);
202201
}
@@ -536,8 +535,7 @@ bool RawInstrProfReader<IntPtrT>::hasFormat(const MemoryBuffer &DataBuffer) {
536535
llvm::byteswap(RawInstrProf::getMagic<IntPtrT>()) == Magic;
537536
}
538537

539-
template <class IntPtrT>
540-
Error RawInstrProfReader<IntPtrT>::readHeader() {
538+
template <class IntPtrT> Error RawInstrProfReader<IntPtrT>::readHeader() {
541539
if (!hasFormat(*DataBuffer))
542540
return error(instrprof_error::bad_magic);
543541
if (DataBuffer->getBufferSize() < sizeof(RawInstrProf::Header))

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,11 @@ void InstrProfWriter::overlapRecord(NamedInstrProfRecord &&Other,
195195
Dest.overlap(Other, Overlap, FuncLevelOverlap, ValueCutoff);
196196
}
197197

198-
199-
200198
void InstrProfWriter::addRecord(StringRef Name, uint64_t Hash,
201199
InstrProfRecord &&I, uint64_t Weight,
202200
function_ref<void(Error)> Warn, StringRef ObjectFilename) {
203201
auto &ProfileDataMap = FunctionData[Name];
204-
//add objectFilename to hash value if --object-aware-hashing is used
202+
// add objectFilename to hash value if --object-aware-hashing is used
205203
if(!ObjectFilename.empty()){
206204
std::string HashStr = std::to_string(Hash) + ":" + ObjectFilename.str();
207205
llvm::StringRef HashRef(HashStr);

llvm/test/tools/llvm-cov/Inputs/fb.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
int foo() { return 0; }
2+
3+
int bar() { return 0; }
4+
5+
int bun() { return 0; }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
int baz() { return 0; }
2+
int main() { return 1; }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extern int foo();
2+
extern int bar();
3+
extern int bun();
4+
5+
6+
int main() {
7+
return foo() + bar() + bun();
8+
}

0 commit comments

Comments
 (0)