diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -174,7 +174,7 @@ std::string DebugCompilationDir; /// The string to embed in coverage mapping as the current working directory. - std::string ProfileCompilationDir; + std::string CoverageCompilationDir; /// The string to embed in the debug information for the compile unit, if /// non-empty. @@ -185,7 +185,7 @@ std::string RecordCommandLine; std::map DebugPrefixMap; - std::map ProfilePrefixMap; + std::map CoveragePrefixMap; /// The ABI to use for passing floating point arguments. std::string FloatABI; diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1102,10 +1102,10 @@ def fdebug_compilation_dir : Separate<["-"], "fdebug-compilation-dir">, Group, Flags<[CC1Option, CC1AsOption, CoreOption]>, Alias; -def fprofile_compilation_dir_EQ : Joined<["-"], "fprofile-compilation-dir=">, +def fcoverage_compilation_dir_EQ : Joined<["-"], "fcoverage-compilation-dir=">, Group, Flags<[CC1Option, CC1AsOption, CoreOption]>, HelpText<"The compilation directory to embed in the coverage mapping.">, - MarshallingInfoString>; + MarshallingInfoString>; def ffile_compilation_dir_EQ : Joined<["-"], "ffile-compilation-dir=">, Group, HelpText<"The compilation directory to embed in the debug info and coverage mapping.">; defm debug_info_for_profiling : BoolFOption<"debug-info-for-profiling", @@ -2666,10 +2666,10 @@ : Joined<["-"], "fdebug-prefix-map=">, Group, Flags<[CC1Option,CC1AsOption]>, HelpText<"remap file source paths in debug info">; -def fprofile_prefix_map_EQ - : Joined<["-"], "fprofile-prefix-map=">, Group, +def fcoverage_prefix_map_EQ + : Joined<["-"], "fcoverage-prefix-map=">, Group, Flags<[CC1Option]>, - HelpText<"remap file source paths in coverage info">; + HelpText<"remap file source paths in coverage mapping">; def ffile_prefix_map_EQ : Joined<["-"], "ffile-prefix-map=">, Group, HelpText<"remap file source paths in debug info and predefined preprocessor macros">; diff --git a/clang/lib/CodeGen/CoverageMappingGen.h b/clang/lib/CodeGen/CoverageMappingGen.h --- a/clang/lib/CodeGen/CoverageMappingGen.h +++ b/clang/lib/CodeGen/CoverageMappingGen.h @@ -93,7 +93,7 @@ llvm::SmallDenseMap FileEntries; std::vector FunctionNames; std::vector FunctionRecords; - std::map ProfilePrefixMap; + std::map CoveragePrefixMap; std::string getCurrentDirname(); std::string normalizeFilename(StringRef Filename); diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -1603,12 +1603,12 @@ CoverageMappingModuleGen::CoverageMappingModuleGen( CodeGenModule &CGM, CoverageSourceInfo &SourceInfo) : CGM(CGM), SourceInfo(SourceInfo) { - ProfilePrefixMap = CGM.getCodeGenOpts().ProfilePrefixMap; + CoveragePrefixMap = CGM.getCodeGenOpts().CoveragePrefixMap; } std::string CoverageMappingModuleGen::getCurrentDirname() { - if (!CGM.getCodeGenOpts().ProfileCompilationDir.empty()) - return CGM.getCodeGenOpts().ProfileCompilationDir; + if (!CGM.getCodeGenOpts().CoverageCompilationDir.empty()) + return CGM.getCodeGenOpts().CoverageCompilationDir; SmallString<256> CWD; llvm::sys::fs::current_path(CWD); @@ -1618,7 +1618,7 @@ std::string CoverageMappingModuleGen::normalizeFilename(StringRef Filename) { llvm::SmallString<256> Path(Filename); llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true); - for (const auto &Entry : ProfilePrefixMap) { + for (const auto &Entry : CoveragePrefixMap) { if (llvm::sys::path::replace_path_prefix(Path, Entry.first, Entry.second)) break; } diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -657,16 +657,16 @@ } /// Add a CC1 and CC1AS option to specify the coverage file path prefix map. -static void addProfilePrefixMapArg(const Driver &D, const ArgList &Args, +static void addCoveragePrefixMapArg(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs) { for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ, - options::OPT_fprofile_prefix_map_EQ)) { + options::OPT_fcoverage_prefix_map_EQ)) { StringRef Map = A->getValue(); if (Map.find('=') == StringRef::npos) D.Diag(diag::err_drv_invalid_argument_to_option) << Map << A->getOption().getName(); else - CmdArgs.push_back(Args.MakeArgString("-fprofile-prefix-map=" + Map)); + CmdArgs.push_back(Args.MakeArgString("-fcoverage-prefix-map=" + Map)); A->claim(); } } @@ -861,11 +861,11 @@ } if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ, - options::OPT_fprofile_compilation_dir_EQ)) { + options::OPT_fcoverage_compilation_dir_EQ)) { A->render(Args, CmdArgs); } else if (llvm::ErrorOr CWD = D.getVFS().getCurrentWorkingDirectory()) { - Args.MakeArgString("-fprofile-compilation-dir=" + *CWD); + Args.MakeArgString("-fcoverage-compilation-dir=" + *CWD); } if (Args.hasArg(options::OPT_fprofile_exclude_files_EQ)) { @@ -1391,7 +1391,7 @@ } addMacroPrefixMapArg(D, Args, CmdArgs); - addProfilePrefixMapArg(D, Args, CmdArgs); + addCoveragePrefixMapArg(D, Args, CmdArgs); } // FIXME: Move to target hook. diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1361,8 +1361,8 @@ GenerateArg(Args, OPT_fdebug_prefix_map_EQ, Prefix.first + "=" + Prefix.second, SA); - for (const auto &Prefix : Opts.ProfilePrefixMap) - GenerateArg(Args, OPT_fprofile_prefix_map_EQ, + for (const auto &Prefix : Opts.CoveragePrefixMap) + GenerateArg(Args, OPT_fcoverage_prefix_map_EQ, Prefix.first + "=" + Prefix.second, SA); if (Opts.NewStructPathTBAA) @@ -1636,9 +1636,9 @@ {std::string(Split.first), std::string(Split.second)}); } - for (const auto &Arg : Args.getAllArgValues(OPT_fprofile_prefix_map_EQ)) { + for (const auto &Arg : Args.getAllArgValues(OPT_fcoverage_prefix_map_EQ)) { auto Split = StringRef(Arg).split('='); - Opts.ProfilePrefixMap.insert( + Opts.CoveragePrefixMap.insert( {std::string(Split.first), std::string(Split.second)}); } diff --git a/clang/test/CodeGen/coverage-compilation-dir.c b/clang/test/CodeGen/coverage-compilation-dir.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/coverage-compilation-dir.c @@ -0,0 +1,7 @@ +// RUN: mkdir -p %t.dir && cd %t.dir +// RUN: cp %s rel.c +// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-compilation-dir=/nonsense -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false rel.c -o - | FileCheck -check-prefix=CHECK-NONSENSE %s + +// CHECK-NONSENSE: nonsense + +void f() {} diff --git a/clang/test/CodeGen/profile-compilation-dir.c b/clang/test/CodeGen/profile-compilation-dir.c deleted file mode 100644 --- a/clang/test/CodeGen/profile-compilation-dir.c +++ /dev/null @@ -1,7 +0,0 @@ -// RUN: mkdir -p %t.dir && cd %t.dir -// RUN: cp %s rel.c -// RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-compilation-dir=/nonsense -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false rel.c -o - | FileCheck -check-prefix=CHECK-NONSENSE %s - -// CHECK-NONSENSE: nonsense - -void f() {} diff --git a/clang/test/Driver/debug-prefix-map.c b/clang/test/Driver/debug-prefix-map.c --- a/clang/test/Driver/debug-prefix-map.c +++ b/clang/test/Driver/debug-prefix-map.c @@ -1,39 +1,39 @@ // RUN: %clang -### -fdebug-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-INVALID // RUN: %clang -### -fmacro-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-INVALID -// RUN: %clang -### -fprofile-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-PROFILE-INVALID +// RUN: %clang -### -fcoverage-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-COVERAGE-INVALID // RUN: %clang -### -ffile-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-FILE-INVALID // RUN: %clang -### -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE // RUN: %clang -### -fmacro-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE -// RUN: %clang -### -fprofile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-PROFILE-SIMPLE +// RUN: %clang -### -fcoverage-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-COVERAGE-SIMPLE // RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE // RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE -// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-PROFILE-SIMPLE +// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-COVERAGE-SIMPLE // RUN: %clang -### -fdebug-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX // RUN: %clang -### -fmacro-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX -// RUN: %clang -### -fprofile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-PROFILE-COMPLEX +// RUN: %clang -### -fcoverage-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-COVERAGE-COMPLEX // RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX // RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX -// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-PROFILE-COMPLEX +// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-COVERAGE-COMPLEX // RUN: %clang -### -fdebug-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY // RUN: %clang -### -fmacro-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY -// RUN: %clang -### -fprofile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-PROFILE-EMPTY +// RUN: %clang -### -fcoverage-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-COVERAGE-EMPTY // RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY // RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY -// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-PROFILE-EMPTY +// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-COVERAGE-EMPTY // CHECK-DEBUG-INVALID: error: invalid argument 'old' to -fdebug-prefix-map // CHECK-MACRO-INVALID: error: invalid argument 'old' to -fmacro-prefix-map -// CHECK-PROFILE-INVALID: error: invalid argument 'old' to -fprofile-prefix-map +// CHECK-COVERAGE-INVALID: error: invalid argument 'old' to -fcoverage-prefix-map // CHECK-FILE-INVALID: error: invalid argument 'old' to -ffile-prefix-map // CHECK-DEBUG-SIMPLE: fdebug-prefix-map=old=new // CHECK-MACRO-SIMPLE: fmacro-prefix-map=old=new -// CHECK-PROFILE-SIMPLE: fprofile-prefix-map=old=new +// CHECK-COVERAGE-SIMPLE: fcoverage-prefix-map=old=new // CHECK-DEBUG-COMPLEX: fdebug-prefix-map=old=n=ew // CHECK-MACRO-COMPLEX: fmacro-prefix-map=old=n=ew -// CHECK-PROFILE-COMPLEX: fprofile-prefix-map=old=n=ew +// CHECK-COVERAGE-COMPLEX: fcoverage-prefix-map=old=n=ew // CHECK-DEBUG-EMPTY: fdebug-prefix-map=old= // CHECK-MACRO-EMPTY: fmacro-prefix-map=old= -// CHECK-PROFILE-EMPTY: fprofile-prefix-map=old= +// CHECK-COVERAGE-EMPTY: fcoverage-prefix-map=old= diff --git a/clang/test/Profile/coverage-prefix-map.c b/clang/test/Profile/coverage-prefix-map.c new file mode 100644 --- /dev/null +++ b/clang/test/Profile/coverage-prefix-map.c @@ -0,0 +1,21 @@ +// %s expands to an absolute path, so to test relative paths we need to create a +// clean directory, put the source there, and cd into it. +// RUN: rm -rf %t +// RUN: mkdir -p %t/root/nested +// RUN: echo "void f1() {}" > %t/root/nested/coverage-prefix-map.c +// RUN: cd %t/root + +// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name coverage-prefix-map.c %t/root/nested/coverage-prefix-map.c -o - | FileCheck --check-prefix=ABSOLUTE %s +// +// ABSOLUTE: @__llvm_coverage_mapping = {{.*"\\02.*root.*nested.*coverage-prefix-map\.c}} + +// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name coverage-prefix-map.c ../root/nested/coverage-prefix-map.c -o - | FileCheck --check-prefix=RELATIVE %s +// +// RELATIVE: @__llvm_coverage_mapping = {{.*"\\02.*}}..{{/|\\+}}root{{/|\\+}}nested{{.*coverage-prefix-map\.c}} + +// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name coverage-prefix-map.c %t/root/nested/coverage-prefix-map.c -fcoverage-prefix-map=%/t/root=. -o - | FileCheck --check-prefix=COVERAGE-PREFIX-MAP %s +// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name coverage-prefix-map.c ../root/nested/coverage-prefix-map.c -fcoverage-prefix-map=../root=. -o - | FileCheck --check-prefix=COVERAGE-PREFIX-MAP %s +// COVERAGE-PREFIX-MAP: @__llvm_coverage_mapping = {{.*"\\02.*}}.{{/|\\+}}nested{{.*coverage-prefix-map\.c}} + +// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name coverage-prefix-map.c %t/root/nested/coverage-prefix-map.c -fcoverage-compilation-dir=/custom -fcoverage-prefix-map=/custom=/nonsense -o - | FileCheck --check-prefix=COVERAGE-COMPILATION-DIR %s +// COVERAGE-COMPILATION-DIR: @__llvm_coverage_mapping = {{.*"\\02.*}}nonsense diff --git a/clang/test/Profile/profile-prefix-map.c b/clang/test/Profile/profile-prefix-map.c deleted file mode 100644 --- a/clang/test/Profile/profile-prefix-map.c +++ /dev/null @@ -1,21 +0,0 @@ -// %s expands to an absolute path, so to test relative paths we need to create a -// clean directory, put the source there, and cd into it. -// RUN: rm -rf %t -// RUN: mkdir -p %t/root/nested -// RUN: echo "void f1() {}" > %t/root/nested/profile-prefix-map.c -// RUN: cd %t/root - -// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c %t/root/nested/profile-prefix-map.c -o - | FileCheck --check-prefix=ABSOLUTE %s -// -// ABSOLUTE: @__llvm_coverage_mapping = {{.*"\\02.*root.*nested.*profile-prefix-map\.c}} - -// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c ../root/nested/profile-prefix-map.c -o - | FileCheck --check-prefix=RELATIVE %s -// -// RELATIVE: @__llvm_coverage_mapping = {{.*"\\02.*}}..{{/|\\+}}root{{/|\\+}}nested{{.*profile-prefix-map\.c}} - -// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c %t/root/nested/profile-prefix-map.c -fprofile-prefix-map=%/t/root=. -o - | FileCheck --check-prefix=PROFILE-PREFIX-MAP %s -// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c ../root/nested/profile-prefix-map.c -fprofile-prefix-map=../root=. -o - | FileCheck --check-prefix=PROFILE-PREFIX-MAP %s -// PROFILE-PREFIX-MAP: @__llvm_coverage_mapping = {{.*"\\02.*}}.{{/|\\+}}nested{{.*profile-prefix-map\.c}} - -// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c %t/root/nested/profile-prefix-map.c -fprofile-compilation-dir=/custom -fprofile-prefix-map=/custom=/nonsense -o - | FileCheck --check-prefix=PROFILE-COMPILATION-DIR %s -// PROFILE-COMPILATION-DIR: @__llvm_coverage_mapping = {{.*"\\02.*}}nonsense