Skip to content

Commit 82fecab

Browse files
committed
[gcov] Bump default version to 11.1
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.
1 parent 30b73ed commit 82fecab

15 files changed

+41
-74
lines changed

clang/include/clang/Basic/CodeGenOptions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
186186
std::string ProfileExcludeFiles;
187187

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

191191
/// Enable additional debugging information.
192192
std::string DebugPass;

clang/lib/Basic/CodeGenOptions.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ CodeGenOptions::CodeGenOptions() {
1717
#include "clang/Basic/CodeGenOptions.def"
1818

1919
RelocationModel = llvm::Reloc::PIC_;
20-
memcpy(CoverageVersion, "408*", 4);
2120
}
2221

2322
void CodeGenOptions::resetNonModularOptions(StringRef ModuleFormat) {
@@ -54,7 +53,6 @@ void CodeGenOptions::resetNonModularOptions(StringRef ModuleFormat) {
5453
}
5554

5655
RelocationModel = llvm::Reloc::PIC_;
57-
memcpy(CoverageVersion, "408*", 4);
5856
}
5957

6058
} // end namespace clang

clang/lib/Frontend/CompilerInvocation.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ void CompilerInvocationBase::GenerateCodeGenArgs(const CodeGenOptions &Opts,
16911691
}
16921692
}
16931693

1694-
if (memcmp(Opts.CoverageVersion, "408*", 4) != 0)
1694+
if (memcmp(Opts.CoverageVersion, "0000", 4))
16951695
GenerateArg(Consumer, OPT_coverage_version_EQ,
16961696
StringRef(Opts.CoverageVersion, 4));
16971697

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

2010-
memcpy(Opts.CoverageVersion, "408*", 4);
20112010
if (Opts.CoverageNotesFile.size() || Opts.CoverageDataFile.size()) {
20122011
if (Args.hasArg(OPT_coverage_version_EQ)) {
20132012
StringRef CoverageVersion = Args.getLastArgValue(OPT_coverage_version_EQ);

clang/test/CodeGen/code-coverage.c

+10-16
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@
33
/// 4.7 enables cfg_checksum.
44
/// 4.8 (default, compatible with gcov 7) emits the exit block the second.
55
// RUN: rm -rf %t && mkdir %t && cd %t
6-
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-red-zone -coverage-data-file=/dev/null -coverage-version='304*' %s -o - | \
7-
// RUN: FileCheck --check-prefixes=CHECK,CHECK-CTOR-INIT,304 %s
8-
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-red-zone -coverage-data-file=/dev/null -coverage-version='407*' %s -o - | \
9-
// RUN: FileCheck --check-prefixes=CHECK,CHECK-CTOR-INIT,407 %s
6+
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-red-zone -coverage-data-file=/dev/null -coverage-version='B21*' %s -o - | \
7+
// RUN: FileCheck --check-prefixes=CHECK,CHECK-CTOR-INIT,1210 %s
108
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-red-zone -coverage-data-file=/dev/null %s -o - | \
11-
// RUN: FileCheck --check-prefixes=CHECK,CHECK-CTOR-INIT,408 %s
12-
// RUN: %clang_cc1 -triple powerpc64-ibm-aix -emit-llvm -disable-red-zone -coverage-data-file=/dev/null -coverage-version='304*' %s -o - | \
13-
// RUN: FileCheck --check-prefixes=CHECK,CHECK-RT-INIT,304 %s
14-
// RUN: %clang_cc1 -triple powerpc64-ibm-aix -emit-llvm -disable-red-zone -coverage-data-file=/dev/null -coverage-version='407*' %s -o - | \
15-
// RUN: FileCheck --check-prefixes=CHECK,CHECK-RT-INIT,407 %s
9+
// RUN: FileCheck --check-prefixes=CHECK,CHECK-CTOR-INIT,1110 %s
10+
// RUN: %clang_cc1 -triple powerpc64-ibm-aix -emit-llvm -disable-red-zone -coverage-data-file=/dev/null -coverage-version='B21*' %s -o - | \
11+
// RUN: FileCheck --check-prefixes=CHECK,CHECK-RT-INIT,1210 %s
1612
// RUN: %clang_cc1 -triple powerpc64-ibm-aix -emit-llvm -disable-red-zone -coverage-data-file=/dev/null %s -o - | \
17-
// RUN: FileCheck --check-prefixes=CHECK,CHECK-RT-INIT,408 %s
13+
// RUN: FileCheck --check-prefixes=CHECK,CHECK-RT-INIT,1110 %s
1814

1915
// 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
2016

@@ -48,12 +44,10 @@ int test2(int b) {
4844
// 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]+}} }]
4945

5046
// CHECK: @__llvm_internal_gcov_emit_file_info = internal unnamed_addr constant [1 x %file_info]
51-
/// 0x3330342a '3' '0' '4' '*'
52-
// 304-SAME: i32 858797098
53-
/// 0x3430372a '4' '0' '7' '*'
54-
// 407-SAME: i32 875575082
55-
/// 0x3430382a '4' '0' '8' '*'
56-
// 408-SAME: i32 875575338
47+
/// 0x4231312a 'B' '1' '1' '*'
48+
// 1110-SAME: i32 1110520106
49+
/// 0x4232312a 'B' '2' '1' '*'
50+
// 1210-SAME: i32 1110585642
5751

5852
// Check for gcov initialization function pointers.
5953
// CHECK-RT-INIT: @__llvm_covinit_functions = private constant { ptr, ptr } { ptr @__llvm_gcov_writeout, ptr @__llvm_gcov_reset }, section "__llvm_covinit"

compiler-rt/test/profile/Inputs/instrprof-gcov-exceptions.cpp.gcov

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// CHECK-NEXT: -: 0:Graph:instrprof-gcov-exceptions.gcno
33
// CHECK-NEXT: -: 0:Data:instrprof-gcov-exceptions.gcda
44
// CHECK-NEXT: -: 0:Runs:1
5-
// CHECK-NEXT: -: 0:Programs:1
65
// CHECK-NEXT: -: 1:#include <string>
76
// CHECK-NEXT: -: 2:
87
// CHECK-NEXT: 1: 3:void asd(std::string i) {

compiler-rt/test/profile/Inputs/instrprof-gcov-multiple-bbs-single-line.c.gcov

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// CHECK-NEXT: -: 0:Graph:instrprof-gcov-multiple-bbs-single-line.gcno
33
// CHECK-NEXT: -: 0:Data:instrprof-gcov-multiple-bbs-single-line.gcda
44
// CHECK-NEXT: -: 0:Runs:1
5-
// CHECK-NEXT: -: 0:Programs:1
65
// CHECK-NEXT:function main called 1 returned 100% blocks executed 77%
76
// CHECK-NEXT: 1: 1:int main(void)
87
// CHECK-NEXT: -: 2:{

compiler-rt/test/profile/Inputs/instrprof-gcov-one-line-function.c.gcov

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// CHECK-NEXT: -: 0:Graph:instrprof-gcov-one-line-function.gcno
33
// CHECK-NEXT: -: 0:Data:instrprof-gcov-one-line-function.gcda
44
// CHECK-NEXT: -: 0:Runs:1
5-
// CHECK-NEXT: -: 0:Programs:1
65
// CHECK-NEXT: 1: 1:void foo() { }
76
// CHECK-NEXT: -: 2:
87
// CHECK-NEXT: 1: 3:void bar() { }

compiler-rt/test/profile/Inputs/instrprof-gcov-switch1.c.gcov

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// CHECK-NEXT: -: 0:Graph:instrprof-gcov-switch1.gcno
33
// CHECK-NEXT: -: 0:Data:instrprof-gcov-switch1.gcda
44
// CHECK-NEXT: -: 0:Runs:1
5-
// CHECK-NEXT: -: 0:Programs:1
65
// CHECK-NEXT: 1: 1:int main(void)
76
// CHECK-NEXT: -: 2:{
87
// CHECK-NEXT: 1: 3: int i = 22;

compiler-rt/test/profile/Inputs/instrprof-gcov-switch2.c.gcov

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// CHECK-NEXT: -: 0:Graph:instrprof-gcov-switch2.gcno
33
// CHECK-NEXT: -: 0:Data:instrprof-gcov-switch2.gcda
44
// CHECK-NEXT: -: 0:Runs:1
5-
// CHECK-NEXT: -: 0:Programs:1
65
// CHECK-NEXT: 1: 1:int main(void)
76
// CHECK-NEXT: -: 2:{
87
// CHECK-NEXT: 1: 3: int i = 22;

compiler-rt/test/profile/Inputs/instrprof-shared-lib_in-loop.c.gcov

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// CHECK-NEXT: -: 0:Graph:instrprof-shared-lib.gcno
33
// CHECK-NEXT: -: 0:Data:instrprof-shared-lib.gcda
44
// CHECK-NEXT: -: 0:Runs:1
5-
// CHECK-NEXT: -: 0:Programs:1
65
// CHECK-NEXT: -: 1:int g1 = 0;
76
// CHECK-NEXT: -: 2:int g2 = 1;
87
// CHECK-NEXT: -: 3:

compiler-rt/test/profile/Inputs/instrprof-shared-main.c.gcov

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// CHECK-NEXT: -: 0:Graph:instrprof-shared-main.gcno
33
// CHECK-NEXT: -: 0:Data:instrprof-shared-main.gcda
44
// CHECK-NEXT: -: 0:Runs:1
5-
// CHECK-NEXT: -: 0:Programs:1
65
// CHECK-NEXT: -: 1:extern int g1, g2;
76
// CHECK-NEXT: -: 2:extern void foo(int n);
87
// CHECK-NEXT: -: 3:

compiler-rt/test/profile/gcov-__gcov_flush-terminate.c

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// RUN: llvm-cov gcov -t gcov-__gcov_flush-terminate.gcda | FileCheck %s
99

1010
// CHECK: -: 0:Runs:1
11-
// CHECK-NEXT: -: 0:Programs:1
1211

1312
void __gcov_dump(void);
1413
void __gcov_reset(void);

llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp

+24-40
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ enum : uint32_t {
6161
};
6262

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

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

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

344342
std::string FunctionNameAndLine;
345343
raw_string_ostream FNLOS(FunctionNameAndLine);
@@ -363,44 +361,28 @@ namespace {
363361
void writeOut(uint32_t CfgChecksum) {
364362
write(GCOV_TAG_FUNCTION);
365363
SmallString<128> Filename = getFilename(SP);
366-
uint32_t BlockLen =
367-
2 + (Version >= 47) + wordsOfString(getFunctionName(SP));
368-
if (Version < 80)
369-
BlockLen += wordsOfString(Filename) + 1;
370-
else
371-
BlockLen += 1 + wordsOfString(Filename) + 3 + (Version >= 90);
364+
uint32_t BlockLen = 3 + wordsOfString(getFunctionName(SP));
365+
BlockLen += 1 + wordsOfString(Filename) + 4;
372366

373367
write(BlockLen);
374368
write(Ident);
375369
write(FuncChecksum);
376-
if (Version >= 47)
377-
write(CfgChecksum);
370+
write(CfgChecksum);
378371
writeString(getFunctionName(SP));
379-
if (Version < 80) {
380-
writeString(Filename);
381-
write(SP->getLine());
382-
} else {
383-
write(SP->isArtificial()); // artificial
384-
writeString(Filename);
385-
write(SP->getLine()); // start_line
386-
write(0); // start_column
387-
// EndLine is the last line with !dbg. It is not the } line as in GCC,
388-
// but good enough.
389-
write(EndLine);
390-
if (Version >= 90)
391-
write(0); // end_column
392-
}
372+
373+
write(SP->isArtificial()); // artificial
374+
writeString(Filename);
375+
write(SP->getLine()); // start_line
376+
write(0); // start_column
377+
// EndLine is the last line with !dbg. It is not the } line as in GCC,
378+
// but good enough.
379+
write(EndLine);
380+
write(0); // end_column
393381

394382
// Emit count of blocks.
395383
write(GCOV_TAG_BLOCKS);
396-
if (Version < 80) {
397-
write(Blocks.size() + 2);
398-
for (int i = Blocks.size() + 2; i; --i)
399-
write(0);
400-
} else {
401-
write(1);
402-
write(Blocks.size() + 2);
403-
}
384+
write(1);
385+
write(Blocks.size() + 2);
404386
LLVM_DEBUG(dbgs() << (Blocks.size() + 1) << " blocks\n");
405387

406388
// Emit edges between blocks.
@@ -767,14 +749,18 @@ bool GCOVProfiler::emitProfileNotes(
767749
function_ref<BlockFrequencyInfo *(Function &F)> GetBFI,
768750
function_ref<BranchProbabilityInfo *(Function &F)> GetBPI,
769751
function_ref<const TargetLibraryInfo &(Function &F)> GetTLI) {
770-
int Version;
771752
{
772753
uint8_t c3 = Options.Version[0];
773754
uint8_t c2 = Options.Version[1];
774755
uint8_t c1 = Options.Version[2];
775756
Version = c3 >= 'A' ? (c3 - 'A') * 100 + (c2 - '0') * 10 + c1 - '0'
776757
: (c3 - '0') * 10 + c1 - '0';
777758
}
759+
// Emit .gcno files that are compatible with GCC 11.1.
760+
if (Version < 111) {
761+
Version = 111;
762+
memcpy(Options.Version, "B11*", 4);
763+
}
778764

779765
bool EmitGCDA = Options.EmitData;
780766
for (unsigned i = 0, e = CUNode->getNumOperands(); i != e; ++i) {
@@ -973,10 +959,8 @@ bool GCOVProfiler::emitProfileNotes(
973959
out.write(Tmp, 4);
974960
}
975961
write(Stamp);
976-
if (Version >= 90)
977-
writeString(""); // unuseful current_working_directory
978-
if (Version >= 80)
979-
write(0); // unuseful has_unexecuted_blocks
962+
writeString("."); // unuseful current_working_directory
963+
write(0); // unuseful has_unexecuted_blocks
980964

981965
for (auto &Func : Funcs)
982966
Func->writeOut(Stamp);

llvm/test/Transforms/GCOVProfiling/exit-block.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

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

1414
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
1515
target triple = "x86_64-unknown-linux-gnu"

llvm/test/Transforms/GCOVProfiling/version.ll

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
; RUN: cat %t/little.txt %s %t/version.txt > %t/2
66

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

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

1919
define void @test() !dbg !5 {
2020
ret void, !dbg !8

0 commit comments

Comments
 (0)