diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 61982da889ed8..363ee1eb16ac7 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -39,7 +39,6 @@ CODEGENOPT(ObjCAutoRefCountExceptions , 1, 0) ///< Whether ARC should be EH-safe CODEGENOPT(Backchain , 1, 0) ///< -mbackchain CODEGENOPT(ControlFlowGuardNoChecks , 1, 0) ///< -cfguard-no-checks CODEGENOPT(ControlFlowGuard , 1, 0) ///< -cfguard -CODEGENOPT(CoverageExitBlockBeforeBody, 1, 0) ///< Whether to emit the exit block before the body blocks in GCNO files. CODEGENOPT(CXAAtExit , 1, 1) ///< Use __cxa_atexit for calling destructors. CODEGENOPT(RegisterGlobalDtorsWithAtExit, 1, 1) ///< Use atexit or __cxa_atexit to register global destructors. CODEGENOPT(CXXCtorDtorAliases, 1, 0) ///< Emit complete ctors/dtors as linker diff --git a/clang/include/clang/Driver/CC1Options.td b/clang/include/clang/Driver/CC1Options.td index 7e0038e04b01d..526a51085ce79 100644 --- a/clang/include/clang/Driver/CC1Options.td +++ b/clang/include/clang/Driver/CC1Options.td @@ -262,8 +262,6 @@ def coverage_notes_file : Separate<["-"], "coverage-notes-file">, HelpText<"Emit coverage notes to this filename.">; def coverage_notes_file_EQ : Joined<["-"], "coverage-notes-file=">, Alias; -def coverage_exit_block_before_body : Flag<["-"], "coverage-exit-block-before-body">, - HelpText<"Emit the exit block before the body blocks in .gcno files.">; def coverage_version_EQ : Joined<["-"], "coverage-version=">, HelpText<"Four-byte version string for gcov files.">; def test_coverage : Flag<["-"], "test-coverage">, diff --git a/clang/lib/Basic/CodeGenOptions.cpp b/clang/lib/Basic/CodeGenOptions.cpp index 8d3aeda1b91f0..4fc7a535c9eb9 100644 --- a/clang/lib/Basic/CodeGenOptions.cpp +++ b/clang/lib/Basic/CodeGenOptions.cpp @@ -17,7 +17,7 @@ CodeGenOptions::CodeGenOptions() { #include "clang/Basic/CodeGenOptions.def" RelocationModel = llvm::Reloc::PIC_; - memcpy(CoverageVersion, "407*", 4); + memcpy(CoverageVersion, "408*", 4); } bool CodeGenOptions::isNoBuiltinFunc(const char *Name) const { diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 0dc6c08eafe3b..7b876df852b56 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -533,7 +533,6 @@ static Optional getGCOVOptions(const CodeGenOptions &CodeGenOpts) { Options.NoRedZone = CodeGenOpts.DisableRedZone; Options.Filter = CodeGenOpts.ProfileFilterFiles; Options.Exclude = CodeGenOpts.ProfileExcludeFiles; - Options.ExitBlockBeforeBody = CodeGenOpts.CoverageExitBlockBeforeBody; return Options; } diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 649e78e19c937..ff2683c3db709 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1021,8 +1021,6 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, std::string(Args.getLastArgValue(OPT_fprofile_filter_files_EQ)); Opts.ProfileExcludeFiles = std::string(Args.getLastArgValue(OPT_fprofile_exclude_files_EQ)); - Opts.CoverageExitBlockBeforeBody = - Args.hasArg(OPT_coverage_exit_block_before_body); if (Args.hasArg(OPT_coverage_version_EQ)) { StringRef CoverageVersion = Args.getLastArgValue(OPT_coverage_version_EQ); if (CoverageVersion.size() != 4) { diff --git a/llvm/include/llvm/ProfileData/GCOV.h b/llvm/include/llvm/ProfileData/GCOV.h index 467772be5ed53..16c9218d6d8fa 100644 --- a/llvm/include/llvm/ProfileData/GCOV.h +++ b/llvm/include/llvm/ProfileData/GCOV.h @@ -41,7 +41,7 @@ class FileInfo; namespace GCOV { -enum GCOVVersion { V402, V407, V800, V900 }; +enum GCOVVersion { V402, V407, V408, V800, V900 }; /// A struct for passing gcov options between functions. struct Options { @@ -108,8 +108,12 @@ class GCOVBuffer { // PR gcov-profile/48463 Version = GCOV::V800; return true; - } else if (Major > 4 || (Major == 4 && Minor >= 7)) { - // r173147 + } else if (Major > 4 || (Major == 4 && Minor >= 8)) { + // r189778: the exit block moved from the last to the second. + Version = GCOV::V408; + return true; + } else if (Major == 4 && Minor >= 7) { + // r173147: split checksum into cfg checksum and line checksum. Version = GCOV::V407; return true; } else { diff --git a/llvm/include/llvm/Transforms/Instrumentation.h b/llvm/include/llvm/Transforms/Instrumentation.h index 6f594d7690695..04f211da9819b 100644 --- a/llvm/include/llvm/Transforms/Instrumentation.h +++ b/llvm/include/llvm/Transforms/Instrumentation.h @@ -66,10 +66,6 @@ struct GCOVOptions { // Add the 'noredzone' attribute to added runtime library calls. bool NoRedZone; - // Emit the exit block immediately after the start block, rather than after - // all of the function body's blocks. - bool ExitBlockBeforeBody; - // Regexes separated by a semi-colon to filter the files to instrument. std::string Filter; diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp index cad1071df42c1..0a83155007cf3 100644 --- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -50,17 +50,14 @@ using namespace llvm; #define DEBUG_TYPE "insert-gcov-profiling" static cl::opt DefaultGCOVVersion("default-gcov-version", - cl::init("407*"), cl::Hidden, + cl::init("408*"), cl::Hidden, cl::ValueRequired); -static cl::opt DefaultExitBlockBeforeBody("gcov-exit-block-before-body", - cl::init(false), cl::Hidden); GCOVOptions GCOVOptions::getDefault() { GCOVOptions Options; Options.EmitNotes = true; Options.EmitData = true; Options.NoRedZone = false; - Options.ExitBlockBeforeBody = DefaultExitBlockBeforeBody; if (DefaultGCOVVersion.size() != 4) { llvm::report_fatal_error(std::string("Invalid -default-gcov-version: ") + @@ -747,9 +744,9 @@ void GCOVProfiler::emitProfileNotes() { EntryBlock.splitBasicBlock(It); bool UseCfgChecksum = strncmp(Options.Version, "407", 3) >= 0; + bool ExitBlockBeforeBody = strncmp(Options.Version, "408", 3) >= 0; Funcs.push_back(std::make_unique( - SP, &F, &out, FunctionIdent++, UseCfgChecksum, - Options.ExitBlockBeforeBody)); + SP, &F, &out, FunctionIdent++, UseCfgChecksum, ExitBlockBeforeBody)); GCOVFunction &Func = *Funcs.back(); // Add the function line number to the lines of the entry block diff --git a/llvm/test/Transforms/GCOVProfiling/return-block.ll b/llvm/test/Transforms/GCOVProfiling/exit-block.ll similarity index 68% rename from llvm/test/Transforms/GCOVProfiling/return-block.ll rename to llvm/test/Transforms/GCOVProfiling/exit-block.ll index ce665148899e0..202479e72e0c2 100644 --- a/llvm/test/Transforms/GCOVProfiling/return-block.ll +++ b/llvm/test/Transforms/GCOVProfiling/exit-block.ll @@ -1,24 +1,24 @@ ; Inject metadata to set the .gcno file location ; RUN: rm -rf %t && mkdir -p %t -; RUN: echo '!19 = !{!"%/t/return-block.ll", !0}' > %t/1 +; RUN: echo '!19 = !{!"%/t/exit-block.ll", !0}' > %t/1 ; RUN: cat %s %t/1 > %t/2 -; By default, the return block is last. +; By default, the exit block is the second. ; RUN: opt -insert-gcov-profiling -disable-output %t/2 -; RUN: llvm-cov gcov -n -dump %t/return-block.gcno 2>&1 | FileCheck -check-prefix=CHECK -check-prefix=RETURN-LAST %s +; RUN: llvm-cov gcov -n -dump %t/exit-block.gcno 2>&1 | FileCheck --check-prefixes=CHECK,EXIT-SECOND %s -; But we can optionally emit it second, to match newer gcc versions. -; RUN: opt -insert-gcov-profiling -gcov-exit-block-before-body -disable-output %t/2 -; RUN: llvm-cov gcov -n -dump %t/return-block.gcno 2>&1 | FileCheck -check-prefix=CHECK -check-prefix=RETURN-SECOND %s -; RUN: rm %t/return-block.gcno +; But we can optionally emit it last, to match GCC<4.8 (r189778). +; RUN: opt -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: rm %t/exit-block.gcno -; By default, the return block is last. +; By default, the exit block is the second. ; RUN: opt -passes=insert-gcov-profiling -disable-output %t/2 -; RUN: llvm-cov gcov -n -dump %t/return-block.gcno 2>&1 | FileCheck -check-prefix=CHECK -check-prefix=RETURN-LAST %s +; RUN: llvm-cov gcov -n -dump %t/exit-block.gcno 2>&1 | FileCheck --check-prefixes=CHECK,EXIT-SECOND %s -; But we can optionally emit it second, to match newer gcc versions. -; RUN: opt -passes=insert-gcov-profiling -gcov-exit-block-before-body -disable-output %t/2 -; RUN: llvm-cov gcov -n -dump %t/return-block.gcno 2>&1 | FileCheck -check-prefix=CHECK -check-prefix=RETURN-SECOND %s +; 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 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" @@ -55,10 +55,10 @@ attributes #2 = { nounwind } !llvm.ident = !{!13} !0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.6.0 (trunk 223182)", isOptimized: true, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !8, imports: !2) -!1 = !DIFile(filename: ".../llvm/test/Transforms/GCOVProfiling/return-block.ll", directory: "") +!1 = !DIFile(filename: ".../llvm/test/Transforms/GCOVProfiling/exit-block.ll", directory: "") !2 = !{} !4 = distinct !DISubprogram(name: "test", line: 5, isLocal: false, isDefinition: true, isOptimized: true, unit: !0, scopeLine: 5, file: !1, scope: !5, type: !6, retainedNodes: !2) -!5 = !DIFile(filename: ".../llvm/test/Transforms/GCOVProfiling/return-block.ll", directory: "") +!5 = !DIFile(filename: ".../llvm/test/Transforms/GCOVProfiling/exit-block.ll", directory: "") !6 = !DISubroutineType(types: !7) !7 = !{null} !8 = !{!9} @@ -75,10 +75,10 @@ attributes #2 = { nounwind } ; There should be no destination edges for the exit block. ; CHECK: Block : 1 Counter : 0 -; RETURN-LAST: Destination Edges -; RETURN-SECOND-NOT: Destination Edges +; EXIT-LAST: Destination Edges +; EXIT-SECOND-NOT: Destination Edges ; CHECK: Block : 2 Counter : 0 ; CHECK: Block : 4 Counter : 0 -; RETURN-LAST-NOT: Destination Edges -; RETURN-SECOND: Destination Edges +; EXIT-LAST-NOT: Destination Edges +; EXIT-SECOND: Destination Edges ; CHECK-NOT: Block : diff --git a/llvm/test/Transforms/GCOVProfiling/version.ll b/llvm/test/Transforms/GCOVProfiling/version.ll index c1358039b1f61..b7ce1ab93e078 100644 --- a/llvm/test/Transforms/GCOVProfiling/version.ll +++ b/llvm/test/Transforms/GCOVProfiling/version.ll @@ -2,7 +2,7 @@ ; RUN: echo '!9 = !{!"%/t/version.ll", !0}' > %t/1 ; RUN: cat %s %t/1 > %t/2 ; RUN: opt -insert-gcov-profiling -disable-output < %t/2 -; RUN: head -c8 %t/version.gcno | grep '^oncg.704' +; RUN: head -c8 %t/version.gcno | grep '^oncg.804' ; RUN: rm %t/version.gcno ; RUN: not --crash opt -insert-gcov-profiling -default-gcov-version=asdfasdf -disable-output < %t/2 ; RUN: opt -insert-gcov-profiling -default-gcov-version='402*' -disable-output < %t/2 @@ -10,7 +10,7 @@ ; RUN: rm %t/version.gcno ; RUN: opt -passes=insert-gcov-profiling -disable-output < %t/2 -; RUN: head -c8 %t/version.gcno | grep '^oncg.704' +; RUN: head -c8 %t/version.gcno | grep '^oncg.804' ; RUN: rm %t/version.gcno ; RUN: not --crash 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