From: Nick Lewycky Date: Thu, 7 Mar 2013 08:28:53 +0000 (+0000) Subject: Add flags for additional control over coverage generation. Pick the version X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0f815f1f91e5cf0726fd8296445038fec3bed80b;p=clang Add flags for additional control over coverage generation. Pick the version string to be emitted, and two properties about the files themselves. Use $PWD to absolut-ify the path to the coverage file. Yes, this is what GCC does. Reverts my own r175706. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176617 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index d1b21fdafb..b1e5bfa267 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -149,6 +149,12 @@ def femit_coverage_data: Flag<["-"], "femit-coverage-data">, def coverage_file : Separate<["-"], "coverage-file">, HelpText<"Emit coverage data to this filename. The extension will be replaced.">; def coverage_file_EQ : Joined<["-"], "coverage-file=">, Alias; +def coverage_cfg_checksum : Flag<["-"], "coverage-cfg-checksum">, + HelpText<"Emit CFG checksum for functions in .gcno files.">; +def coverage_function_names_in_data : Flag<["-"], "coverage-function-names-in-data">, + HelpText<"Emit function names in .gcda files.">; +def coverage_version_EQ : Joined<["-"], "coverage-version=">, + HelpText<"Four-byte version string for gcov files.">; def fuse_register_sized_bitfield_access: Flag<["-"], "fuse-register-sized-bitfield-access">, HelpText<"Use register sized accesses to bit-fields, when possible.">; def relaxed_aliasing : Flag<["-"], "relaxed-aliasing">, diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index bbb75ab736..333fa1e88f 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -30,6 +30,8 @@ CODEGENOPT(Name, Bits, Default) CODEGENOPT(AsmVerbose , 1, 0) ///< -dA, -fverbose-asm. CODEGENOPT(ObjCAutoRefCountExceptions , 1, 0) ///< Whether ARC should be EH-safe. +CODEGENOPT(CoverageExtraChecksum, 1, 0) ///< Whether we need a second checksum for functions in GCNO files. +CODEGENOPT(CoverageFunctionNamesInData, 1, 0) ///< Whether we should include function names in GCDA files. CODEGENOPT(CUDAIsDevice , 1, 0) ///< Set when compiling for CUDA device. CODEGENOPT(CXAAtExit , 1, 1) ///< Use __cxa_atexit for calling destructors. CODEGENOPT(CXXCtorDtorAliases, 1, 0) ///< Emit complete ctors/dtors as linker diff --git a/include/clang/Frontend/CodeGenOptions.h b/include/clang/Frontend/CodeGenOptions.h index bda777dfd3..d0bbf30918 100644 --- a/include/clang/Frontend/CodeGenOptions.h +++ b/include/clang/Frontend/CodeGenOptions.h @@ -78,6 +78,9 @@ public: /// replaced. std::string CoverageFile; + /// The version string to put into coverage files. + char CoverageVersion[4]; + /// Enable additional debugging information. std::string DebugPass; @@ -134,6 +137,7 @@ public: #include "clang/Frontend/CodeGenOptions.def" RelocationModel = "pic"; + memcpy(CoverageVersion, "*204", 4); } }; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 5dce1ad9e2..62b1febd52 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -2332,8 +2332,15 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (Output.isFilename()) { CmdArgs.push_back("-coverage-file"); SmallString<128> CoverageFilename(Output.getFilename()); - if (!C.getArgs().hasArg(options::OPT_no_canonical_prefixes)) - llvm::sys::fs::make_absolute(CoverageFilename); + if (llvm::sys::path::is_relative(CoverageFilename.str())) { + if (const char *pwd = ::getenv("PWD")) { + if (llvm::sys::path::is_absolute(pwd)) { + SmallString<128> Pwd(pwd); + llvm::sys::path::append(Pwd, CoverageFilename.str()); + CoverageFilename.swap(Pwd); + } + } + } CmdArgs.push_back(Args.MakeArgString(CoverageFilename)); } } diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index d856c31a05..3c5954a696 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -380,12 +380,31 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.VerifyModule = !Args.hasArg(OPT_disable_llvm_verifier); Opts.SanitizeRecover = !Args.hasArg(OPT_fno_sanitize_recover); - Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions); - Opts.InstrumentForProfiling = Args.hasArg(OPT_pg); Opts.EmitGcovArcs = Args.hasArg(OPT_femit_coverage_data); Opts.EmitGcovNotes = Args.hasArg(OPT_femit_coverage_notes); - Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info); + if (Opts.EmitGcovArcs || Opts.EmitGcovNotes) { Opts.CoverageFile = Args.getLastArgValue(OPT_coverage_file); + Opts.CoverageExtraChecksum = Args.hasArg(OPT_coverage_cfg_checksum); + Opts.CoverageFunctionNamesInData = + Args.hasArg(OPT_coverage_function_names_in_data); + if (Args.hasArg(OPT_coverage_version_EQ)) { + StringRef CoverageVersion = Args.getLastArgValue(OPT_coverage_version_EQ); + if (CoverageVersion.size() != 4) { + Diags.Report(diag::err_drv_invalid_value) + << Args.getLastArg(OPT_coverage_version_EQ)->getAsString(Args) + << CoverageVersion; + } else { + Opts.CoverageVersion[0] = CoverageVersion[3]; + Opts.CoverageVersion[1] = CoverageVersion[2]; + Opts.CoverageVersion[2] = CoverageVersion[1]; + Opts.CoverageVersion[3] = CoverageVersion[0]; + } + } + } + + Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions); + Opts.InstrumentForProfiling = Args.hasArg(OPT_pg); + Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info); Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir); Opts.LinkBitcodeFile = Args.getLastArgValue(OPT_mlink_bitcode_file); Opts.SanitizerBlacklistFile = Args.getLastArgValue(OPT_fsanitize_blacklist);