From 545c687c4b06b403915b92f422ddad737a6357b9 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 19 Oct 2020 22:17:32 -0700 Subject: [PATCH] [gcov] Unify driver and CC1 option names for -ftest-coverage & -fprofile-arcs No need to use -femit-coverage-notes and -femit-coverage-data. --- clang/include/clang/Driver/Options.td | 8 ++------ clang/lib/Driver/ToolChains/Clang.cpp | 4 ++-- clang/lib/Frontend/CompilerInvocation.cpp | 4 ++-- clang/test/CodeGen/code-coverage-tsan.c | 2 +- clang/test/CodeGen/code-coverage.c | 12 ++++++------ clang/test/Driver/coverage.c | 6 +++--- clang/test/Driver/cuda-no-pgo-or-coverage.cu | 14 +++++++------- 7 files changed, 23 insertions(+), 27 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 12e0b2a9c302..f0664e15f88c 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1794,7 +1794,7 @@ def fpass_plugin_EQ : Joined<["-"], "fpass-plugin=">, HelpText<"Load pass plugin from a dynamic shared object file (only with new pass manager).">; defm preserve_as_comments : OptOutFFlag<"preserve-as-comments", "", "Do not preserve comments in inline assembly">; -def fprofile_arcs : Flag<["-"], "fprofile-arcs">, Group, Flags<[LinkOption]>; +def fprofile_arcs : Flag<["-"], "fprofile-arcs">, Group, Flags<[CC1Option,LinkOption]>; def fno_profile_arcs : Flag<["-"], "fno-profile-arcs">, Group; def framework : Separate<["-"], "framework">, Flags<[LinkerInput]>; def frandom_seed_EQ : Joined<["-"], "frandom-seed=">, Group; @@ -1899,7 +1899,7 @@ def foptimization_record_passes_EQ : Joined<["-"], "foptimization-record-passes= HelpText<"Only include passes which match a specified regular expression in the generated optimization record (by default, include all passes)">, MetaVarName<"">; -def ftest_coverage : Flag<["-"], "ftest-coverage">, Group; +def ftest_coverage : Flag<["-"], "ftest-coverage">, Flags<[CC1Option]>, Group; def fno_test_coverage : Flag<["-"], "fno-test-coverage">, Group; def fvectorize : Flag<["-"], "fvectorize">, Group, HelpText<"Enable the loop vectorization passes">; @@ -3791,10 +3791,6 @@ def fdump_vtable_layouts : Flag<["-"], "fdump-vtable-layouts">, HelpText<"Dump the layouts of all vtables that will be emitted in a translation unit">; def fmerge_functions : Flag<["-"], "fmerge-functions">, HelpText<"Permit merging of identical functions when optimizing.">; -def femit_coverage_notes : Flag<["-"], "femit-coverage-notes">, - HelpText<"Emit a gcov coverage notes file when compiling.">; -def femit_coverage_data: Flag<["-"], "femit-coverage-data">, - HelpText<"Instrument the program to emit gcov coverage data when run.">; def coverage_data_file : Separate<["-"], "coverage-data-file">, HelpText<"Emit coverage data to this filename.">; def coverage_data_file_EQ : Joined<["-"], "coverage-data-file=">, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 927dc1c9cf83..934b02c698b7 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -831,9 +831,9 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C, Args.hasArg(options::OPT_coverage); bool EmitCovData = TC.needsGCovInstrumentation(Args); if (EmitCovNotes) - CmdArgs.push_back("-femit-coverage-notes"); + CmdArgs.push_back("-ftest-coverage"); if (EmitCovData) - CmdArgs.push_back("-femit-coverage-data"); + CmdArgs.push_back("-fprofile-arcs"); if (Args.hasFlag(options::OPT_fcoverage_mapping, options::OPT_fno_coverage_mapping, false)) { diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 80f2d435d4fa..c3b5edca9497 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1052,8 +1052,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.ControlFlowGuardNoChecks = Args.hasArg(OPT_cfguard_no_checks); Opts.ControlFlowGuard = Args.hasArg(OPT_cfguard); - Opts.EmitGcovArcs = Args.hasArg(OPT_femit_coverage_data); - Opts.EmitGcovNotes = Args.hasArg(OPT_femit_coverage_notes); + Opts.EmitGcovNotes = Args.hasArg(OPT_ftest_coverage); + Opts.EmitGcovArcs = Args.hasArg(OPT_fprofile_arcs); if (Opts.EmitGcovArcs || Opts.EmitGcovNotes) { Opts.CoverageDataFile = std::string(Args.getLastArgValue(OPT_coverage_data_file)); diff --git a/clang/test/CodeGen/code-coverage-tsan.c b/clang/test/CodeGen/code-coverage-tsan.c index 47eabaa375e5..baaf1049dc7d 100644 --- a/clang/test/CodeGen/code-coverage-tsan.c +++ b/clang/test/CodeGen/code-coverage-tsan.c @@ -1,6 +1,6 @@ /// -fprofile-update=atomic (implied by -fsanitize=thread) requires the /// (potentially concurrent) counter updates to be atomic. -// RUN: %clang_cc1 %s -triple x86_64 -emit-llvm -fprofile-update=atomic -femit-coverage-notes -femit-coverage-data \ +// RUN: %clang_cc1 %s -triple x86_64 -emit-llvm -fprofile-update=atomic -ftest-coverage -fprofile-arcs \ // RUN: -coverage-notes-file /dev/null -coverage-data-file /dev/null -o - | FileCheck %s // CHECK-LABEL: void @foo() diff --git a/clang/test/CodeGen/code-coverage.c b/clang/test/CodeGen/code-coverage.c index 39c4556b9ff4..200f3650b752 100644 --- a/clang/test/CodeGen/code-coverage.c +++ b/clang/test/CodeGen/code-coverage.c @@ -2,17 +2,17 @@ /// 3.4 redesigns the format and changed .da to .gcda /// 4.7 enables cfg_checksum. /// 4.8 (default, compatible with gcov 7) emits the exit block the second. -// RUN: %clang_cc1 -emit-llvm -disable-red-zone -femit-coverage-data -coverage-version='304*' %s -o - | \ +// RUN: %clang_cc1 -emit-llvm -disable-red-zone -fprofile-arcs -coverage-version='304*' %s -o - | \ // RUN: FileCheck --check-prefixes=CHECK,304 %s -// RUN: %clang_cc1 -emit-llvm -disable-red-zone -femit-coverage-data -coverage-version='407*' %s -o - | \ +// RUN: %clang_cc1 -emit-llvm -disable-red-zone -fprofile-arcs -coverage-version='407*' %s -o - | \ // RUN: FileCheck --check-prefixes=CHECK,407 %s -// RUN: %clang_cc1 -emit-llvm -disable-red-zone -femit-coverage-data %s -o - | \ +// RUN: %clang_cc1 -emit-llvm -disable-red-zone -fprofile-arcs %s -o - | \ // RUN: FileCheck --check-prefixes=CHECK,408 %s -// RUN: %clang_cc1 -emit-llvm -disable-red-zone -femit-coverage-data -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 +// RUN: %clang_cc1 -emit-llvm -disable-red-zone -fprofile-arcs -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 -// RUN: %clang_cc1 -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -femit-coverage-data %s 2>&1 | FileCheck --check-prefix=NEWPM %s -// RUN: %clang_cc1 -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -femit-coverage-data -O3 %s 2>&1 | FileCheck --check-prefix=NEWPM-O3 %s +// RUN: %clang_cc1 -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -fprofile-arcs %s 2>&1 | FileCheck --check-prefix=NEWPM %s +// RUN: %clang_cc1 -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -fprofile-arcs -O3 %s 2>&1 | FileCheck --check-prefix=NEWPM-O3 %s // NEWPM-NOT: Running pass // NEWPM: Running pass: GCOVProfilerPass diff --git a/clang/test/Driver/coverage.c b/clang/test/Driver/coverage.c index f8f493715581..b1a0456e7152 100644 --- a/clang/test/Driver/coverage.c +++ b/clang/test/Driver/coverage.c @@ -1,16 +1,16 @@ // RUN: %clang -### -S -ftest-coverage %s 2>&1 | FileCheck --check-prefix=TEST-COVERAGE %s // RUN: %clang -### -S -ftest-coverage -fno-test-coverage %s 2>&1 | FileCheck --check-prefix=NO-TEST-COVERAGE %s -// TEST-COVERAGE: "-femit-coverage-notes" +// TEST-COVERAGE: "-ftest-coverage" // TEST-COVERAGE: "-coverage-notes-file" "{{.*}}{{/|\\\\}}coverage.gcno" // NO-TEST-COVERAGE-NOT: "-coverage-notes-file" // RUN: %clang -### -S -fprofile-arcs %s 2>&1 | FileCheck --check-prefix=PROFILE-ARCS %s // RUN: %clang -### -S -fprofile-arcs -fno-profile-arcs %s 2>&1 | FileCheck --check-prefix=NO-PROFILE-ARCS %s -// PROFILE-ARCS: "-femit-coverage-data" +// PROFILE-ARCS: "-fprofile-arcs" // PROFILE-ARCS: "-coverage-notes-file" "{{.*}}{{/|\\\\}}coverage.c" -// NO-PROFILE-ARCS-NOT: "-femit-coverage-data" +// NO-PROFILE-ARCS-NOT: "-ftest-coverage" // RUN: %clang -### -S -fprofile-arcs %s -o /foo/bar.o 2>&1 | FileCheck --check-prefix=GCNO-LOCATION %s // RUN: %clang_cl -### /c --coverage /Fo/foo/bar.obj -- %s 2>&1 | FileCheck --check-prefix=GCNO-LOCATION %s diff --git a/clang/test/Driver/cuda-no-pgo-or-coverage.cu b/clang/test/Driver/cuda-no-pgo-or-coverage.cu index 952838a98d9d..0c98d587c00c 100644 --- a/clang/test/Driver/cuda-no-pgo-or-coverage.cu +++ b/clang/test/Driver/cuda-no-pgo-or-coverage.cu @@ -5,23 +5,23 @@ // // XRUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \ // XRUN: -fprofile-generate %s 2>&1 | \ -// XRUN: FileCheck --check-prefixes=CHECK,PROF %s +// XRUN: FileCheck --check-prefixes=CHECK,PROF %s // // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \ // RUN: -fprofile-instr-generate %s 2>&1 | \ -// RUN: FileCheck -allow-deprecated-dag-overlap --check-prefixes=CHECK,PROF %s +// RUN: FileCheck --check-prefixes=CHECK,PROF %s // // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \ // RUN: -coverage %s 2>&1 | \ -// RUN: FileCheck -allow-deprecated-dag-overlap --check-prefixes=CHECK,GCOV %s +// RUN: FileCheck --check-prefixes=CHECK,GCOV %s // // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \ // RUN: -ftest-coverage %s 2>&1 | \ -// RUN: FileCheck -allow-deprecated-dag-overlap --check-prefixes=CHECK,GCOV %s +// RUN: FileCheck --check-prefixes=CHECK,GCOV %s // // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \ // RUN: -fprofile-instr-generate -fcoverage-mapping %s 2>&1 | \ -// RUN: FileCheck -allow-deprecated-dag-overlap --check-prefixes=CHECK,PROF,GCOV %s +// RUN: FileCheck --check-prefixes=CHECK,PROF %s // // // CHECK-NOT: error: unsupported option '-fprofile @@ -30,5 +30,5 @@ // CHECK-NOT: "-f{{[^"]*coverage.*}}" // CHECK-NOT: "-fprofile{{[^"]*}}" // CHECK: "-triple" "x86_64-unknown-linux-gnu" -// PROF-DAG: "-fprofile{{.*}}" -// GCOV-DAG: "-f{{(coverage|emit-coverage).*}}" +// PROF: "-fprofile{{.*}}" +// GCOV: "-ftest-coverage"