Skip to content

Commit

Permalink
[gcov] Bump default version to 11.1
Browse files Browse the repository at this point in the history
The gcov version is set to 11.1 (compatible with gcov 9) even if
`-Xclang -coverage-version=` specified version is less than 11.1.

Therefore, we can drop producer support for version < 11.1.
  • Loading branch information
MaskRay committed Jan 3, 2025
1 parent 30b73ed commit 82fecab
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 74 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/CodeGenOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
std::string ProfileExcludeFiles;

/// The version string to put into coverage files.
char CoverageVersion[4];
char CoverageVersion[4] = {'0', '0', '0', '0'};

/// Enable additional debugging information.
std::string DebugPass;
Expand Down
2 changes: 0 additions & 2 deletions clang/lib/Basic/CodeGenOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ CodeGenOptions::CodeGenOptions() {
#include "clang/Basic/CodeGenOptions.def"

RelocationModel = llvm::Reloc::PIC_;
memcpy(CoverageVersion, "408*", 4);
}

void CodeGenOptions::resetNonModularOptions(StringRef ModuleFormat) {
Expand Down Expand Up @@ -54,7 +53,6 @@ void CodeGenOptions::resetNonModularOptions(StringRef ModuleFormat) {
}

RelocationModel = llvm::Reloc::PIC_;
memcpy(CoverageVersion, "408*", 4);
}

} // end namespace clang
3 changes: 1 addition & 2 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,7 @@ void CompilerInvocationBase::GenerateCodeGenArgs(const CodeGenOptions &Opts,
}
}

if (memcmp(Opts.CoverageVersion, "408*", 4) != 0)
if (memcmp(Opts.CoverageVersion, "0000", 4))
GenerateArg(Consumer, OPT_coverage_version_EQ,
StringRef(Opts.CoverageVersion, 4));

Expand Down Expand Up @@ -2007,7 +2007,6 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
} else if (Args.hasArg(OPT_fmemory_profile))
Opts.MemoryProfileOutput = MemProfileBasename;

memcpy(Opts.CoverageVersion, "408*", 4);
if (Opts.CoverageNotesFile.size() || Opts.CoverageDataFile.size()) {
if (Args.hasArg(OPT_coverage_version_EQ)) {
StringRef CoverageVersion = Args.getLastArgValue(OPT_coverage_version_EQ);
Expand Down
26 changes: 10 additions & 16 deletions clang/test/CodeGen/code-coverage.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
/// 4.7 enables cfg_checksum.
/// 4.8 (default, compatible with gcov 7) emits the exit block the second.
// RUN: rm -rf %t && mkdir %t && cd %t
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-red-zone -coverage-data-file=/dev/null -coverage-version='304*' %s -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-CTOR-INIT,304 %s
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-red-zone -coverage-data-file=/dev/null -coverage-version='407*' %s -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-CTOR-INIT,407 %s
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-red-zone -coverage-data-file=/dev/null -coverage-version='B21*' %s -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-CTOR-INIT,1210 %s
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-red-zone -coverage-data-file=/dev/null %s -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-CTOR-INIT,408 %s
// RUN: %clang_cc1 -triple powerpc64-ibm-aix -emit-llvm -disable-red-zone -coverage-data-file=/dev/null -coverage-version='304*' %s -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-RT-INIT,304 %s
// RUN: %clang_cc1 -triple powerpc64-ibm-aix -emit-llvm -disable-red-zone -coverage-data-file=/dev/null -coverage-version='407*' %s -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-RT-INIT,407 %s
// RUN: FileCheck --check-prefixes=CHECK,CHECK-CTOR-INIT,1110 %s
// RUN: %clang_cc1 -triple powerpc64-ibm-aix -emit-llvm -disable-red-zone -coverage-data-file=/dev/null -coverage-version='B21*' %s -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-RT-INIT,1210 %s
// RUN: %clang_cc1 -triple powerpc64-ibm-aix -emit-llvm -disable-red-zone -coverage-data-file=/dev/null %s -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-RT-INIT,408 %s
// RUN: FileCheck --check-prefixes=CHECK,CHECK-RT-INIT,1110 %s

// RUN: %clang_cc1 -emit-llvm -disable-red-zone -coverage-notes-file=aaa.gcno -coverage-data-file=bbb.gcda -debug-info-kind=limited -dwarf-version=4 %s -o - | FileCheck %s --check-prefix GCOV_FILE_INFO

Expand Down Expand Up @@ -48,12 +44,10 @@ int test2(int b) {
// CHECK-SAME: [%emit_function_args_ty { i32 0, i32 {{[-0-9]+}}, i32 {{[-0-9]+}} }, %emit_function_args_ty { i32 1, i32 {{[-0-9]+}}, i32 {{[-0-9]+}} }]

// CHECK: @__llvm_internal_gcov_emit_file_info = internal unnamed_addr constant [1 x %file_info]
/// 0x3330342a '3' '0' '4' '*'
// 304-SAME: i32 858797098
/// 0x3430372a '4' '0' '7' '*'
// 407-SAME: i32 875575082
/// 0x3430382a '4' '0' '8' '*'
// 408-SAME: i32 875575338
/// 0x4231312a 'B' '1' '1' '*'
// 1110-SAME: i32 1110520106
/// 0x4232312a 'B' '2' '1' '*'
// 1210-SAME: i32 1110585642

// Check for gcov initialization function pointers.
// CHECK-RT-INIT: @__llvm_covinit_functions = private constant { ptr, ptr } { ptr @__llvm_gcov_writeout, ptr @__llvm_gcov_reset }, section "__llvm_covinit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// CHECK-NEXT: -: 0:Graph:instrprof-gcov-exceptions.gcno
// CHECK-NEXT: -: 0:Data:instrprof-gcov-exceptions.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: -: 1:#include <string>
// CHECK-NEXT: -: 2:
// CHECK-NEXT: 1: 3:void asd(std::string i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// CHECK-NEXT: -: 0:Graph:instrprof-gcov-multiple-bbs-single-line.gcno
// CHECK-NEXT: -: 0:Data:instrprof-gcov-multiple-bbs-single-line.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT:function main called 1 returned 100% blocks executed 77%
// CHECK-NEXT: 1: 1:int main(void)
// CHECK-NEXT: -: 2:{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// CHECK-NEXT: -: 0:Graph:instrprof-gcov-one-line-function.gcno
// CHECK-NEXT: -: 0:Data:instrprof-gcov-one-line-function.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: 1: 1:void foo() { }
// CHECK-NEXT: -: 2:
// CHECK-NEXT: 1: 3:void bar() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// CHECK-NEXT: -: 0:Graph:instrprof-gcov-switch1.gcno
// CHECK-NEXT: -: 0:Data:instrprof-gcov-switch1.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: 1: 1:int main(void)
// CHECK-NEXT: -: 2:{
// CHECK-NEXT: 1: 3: int i = 22;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// CHECK-NEXT: -: 0:Graph:instrprof-gcov-switch2.gcno
// CHECK-NEXT: -: 0:Data:instrprof-gcov-switch2.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: 1: 1:int main(void)
// CHECK-NEXT: -: 2:{
// CHECK-NEXT: 1: 3: int i = 22;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// CHECK-NEXT: -: 0:Graph:instrprof-shared-lib.gcno
// CHECK-NEXT: -: 0:Data:instrprof-shared-lib.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: -: 1:int g1 = 0;
// CHECK-NEXT: -: 2:int g2 = 1;
// CHECK-NEXT: -: 3:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// CHECK-NEXT: -: 0:Graph:instrprof-shared-main.gcno
// CHECK-NEXT: -: 0:Data:instrprof-shared-main.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: -: 1:extern int g1, g2;
// CHECK-NEXT: -: 2:extern void foo(int n);
// CHECK-NEXT: -: 3:
Expand Down
1 change: 0 additions & 1 deletion compiler-rt/test/profile/gcov-__gcov_flush-terminate.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// RUN: llvm-cov gcov -t gcov-__gcov_flush-terminate.gcda | FileCheck %s

// CHECK: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1

void __gcov_dump(void);
void __gcov_reset(void);
Expand Down
64 changes: 24 additions & 40 deletions llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ enum : uint32_t {
};

static cl::opt<std::string> DefaultGCOVVersion("default-gcov-version",
cl::init("408*"), cl::Hidden,
cl::init("0000"), cl::Hidden,
cl::ValueRequired);

static cl::opt<bool> AtomicCounter("gcov-atomic-counter", cl::Hidden,
Expand Down Expand Up @@ -154,6 +154,7 @@ class GCOVProfiler {
GCOVOptions Options;
llvm::endianness Endian;
raw_ostream *os;
int Version = 0;

// Checksum, produced by hash of EdgeDestinations
SmallVector<uint32_t, 4> FileChecksums;
Expand Down Expand Up @@ -334,12 +335,9 @@ namespace {
: GCOVRecord(P), SP(SP), EndLine(EndLine), Ident(Ident),
Version(Version), EntryBlock(P, 0), ReturnBlock(P, 1) {
LLVM_DEBUG(dbgs() << "Function: " << getFunctionName(SP) << "\n");
bool ExitBlockBeforeBody = Version >= 48;
uint32_t i = ExitBlockBeforeBody ? 2 : 1;
uint32_t i = 2;
for (BasicBlock &BB : *F)
Blocks.insert(std::make_pair(&BB, GCOVBlock(P, i++)));
if (!ExitBlockBeforeBody)
ReturnBlock.Number = i;

std::string FunctionNameAndLine;
raw_string_ostream FNLOS(FunctionNameAndLine);
Expand All @@ -363,44 +361,28 @@ namespace {
void writeOut(uint32_t CfgChecksum) {
write(GCOV_TAG_FUNCTION);
SmallString<128> Filename = getFilename(SP);
uint32_t BlockLen =
2 + (Version >= 47) + wordsOfString(getFunctionName(SP));
if (Version < 80)
BlockLen += wordsOfString(Filename) + 1;
else
BlockLen += 1 + wordsOfString(Filename) + 3 + (Version >= 90);
uint32_t BlockLen = 3 + wordsOfString(getFunctionName(SP));
BlockLen += 1 + wordsOfString(Filename) + 4;

write(BlockLen);
write(Ident);
write(FuncChecksum);
if (Version >= 47)
write(CfgChecksum);
write(CfgChecksum);
writeString(getFunctionName(SP));
if (Version < 80) {
writeString(Filename);
write(SP->getLine());
} else {
write(SP->isArtificial()); // artificial
writeString(Filename);
write(SP->getLine()); // start_line
write(0); // start_column
// EndLine is the last line with !dbg. It is not the } line as in GCC,
// but good enough.
write(EndLine);
if (Version >= 90)
write(0); // end_column
}

write(SP->isArtificial()); // artificial
writeString(Filename);
write(SP->getLine()); // start_line
write(0); // start_column
// EndLine is the last line with !dbg. It is not the } line as in GCC,
// but good enough.
write(EndLine);
write(0); // end_column

// Emit count of blocks.
write(GCOV_TAG_BLOCKS);
if (Version < 80) {
write(Blocks.size() + 2);
for (int i = Blocks.size() + 2; i; --i)
write(0);
} else {
write(1);
write(Blocks.size() + 2);
}
write(1);
write(Blocks.size() + 2);
LLVM_DEBUG(dbgs() << (Blocks.size() + 1) << " blocks\n");

// Emit edges between blocks.
Expand Down Expand Up @@ -767,14 +749,18 @@ bool GCOVProfiler::emitProfileNotes(
function_ref<BlockFrequencyInfo *(Function &F)> GetBFI,
function_ref<BranchProbabilityInfo *(Function &F)> GetBPI,
function_ref<const TargetLibraryInfo &(Function &F)> GetTLI) {
int Version;
{
uint8_t c3 = Options.Version[0];
uint8_t c2 = Options.Version[1];
uint8_t c1 = Options.Version[2];
Version = c3 >= 'A' ? (c3 - 'A') * 100 + (c2 - '0') * 10 + c1 - '0'
: (c3 - '0') * 10 + c1 - '0';
}
// Emit .gcno files that are compatible with GCC 11.1.
if (Version < 111) {
Version = 111;
memcpy(Options.Version, "B11*", 4);
}

bool EmitGCDA = Options.EmitData;
for (unsigned i = 0, e = CUNode->getNumOperands(); i != e; ++i) {
Expand Down Expand Up @@ -973,10 +959,8 @@ bool GCOVProfiler::emitProfileNotes(
out.write(Tmp, 4);
}
write(Stamp);
if (Version >= 90)
writeString(""); // unuseful current_working_directory
if (Version >= 80)
write(0); // unuseful has_unexecuted_blocks
writeString("."); // unuseful current_working_directory
write(0); // unuseful has_unexecuted_blocks

for (auto &Func : Funcs)
Func->writeOut(Stamp);
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/GCOVProfiling/exit-block.ll
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

; But we can optionally emit it last, to match GCC<4.8 (r189778).
; RUN: opt -passes=insert-gcov-profiling -default-gcov-version='407*' -disable-output %t/2
; RUN: llvm-cov gcov -n -dump %t/exit-block.gcno 2>&1 | FileCheck --check-prefixes=CHECK,EXIT-LAST %s
; RUN: llvm-cov gcov -n -dump %t/exit-block.gcno 2>&1 | FileCheck --check-prefixes=CHECK,EXIT-SECOND %s

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand Down
8 changes: 4 additions & 4 deletions llvm/test/Transforms/GCOVProfiling/version.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
; RUN: cat %t/little.txt %s %t/version.txt > %t/2

; RUN: opt -passes=insert-gcov-profiling -disable-output < %t/2
; RUN: head -c8 %t/version.gcno | grep '^oncg.804'
; RUN: head -c8 %t/version.gcno | grep '^oncg.11B'
; RUN: rm %t/version.gcno
; RUN: not opt -passes=insert-gcov-profiling -default-gcov-version=asdfasdf -disable-output < %t/2
; RUN: opt -passes=insert-gcov-profiling -default-gcov-version='402*' -disable-output < %t/2
; RUN: head -c8 %t/version.gcno | grep '^oncg.204'
; RUN: opt -passes=insert-gcov-profiling -default-gcov-version='B21*' -disable-output < %t/2
; RUN: head -c8 %t/version.gcno | grep '^oncg.12B'
; RUN: rm %t/version.gcno

; RUN: cat %t/big.txt %s %t/version.txt > %t/big.ll
; RUN: opt -passes=insert-gcov-profiling -disable-output < %t/big.ll
; RUN: head -c8 %t/version.gcno | grep '^gcno408.'
; RUN: head -c8 %t/version.gcno | grep '^gcnoB11.'

define void @test() !dbg !5 {
ret void, !dbg !8
Expand Down

0 comments on commit 82fecab

Please sign in to comment.