From 3dc05418538c719fea48b906bfa4febe5296e126 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Thu, 5 May 2011 00:08:20 +0000 Subject: [PATCH] Preserve the full name of the file, so that '-c -o foo.pic.o' produces foo.pic.gcno instead of foo.gcno. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130899 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/CC1Options.td | 6 +++--- include/clang/Frontend/CodeGenOptions.h | 5 +++-- lib/CodeGen/CodeGenModule.cpp | 12 ++++++------ lib/CodeGen/CodeGenModule.h | 4 ++-- lib/Driver/Tools.cpp | 8 ++------ lib/Frontend/CompilerInvocation.cpp | 2 +- 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 7908b8f106..3c0c3c5a13 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -140,9 +140,9 @@ 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_dir : Separate<"-coverage-dir">, - HelpText<"Emit coverage data to this directory.">; -def coverage_dir_EQ : Joined<"-coverage-dir=">, Alias; +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 relaxed_aliasing : Flag<"-relaxed-aliasing">, HelpText<"Turn off Type Based Alias Analysis">; def masm_verbose : Flag<"-masm-verbose">, diff --git a/include/clang/Frontend/CodeGenOptions.h b/include/clang/Frontend/CodeGenOptions.h index 7221f0d554..1c686c76df 100644 --- a/include/clang/Frontend/CodeGenOptions.h +++ b/include/clang/Frontend/CodeGenOptions.h @@ -95,8 +95,9 @@ public: /// The code model to use (-mcmodel). std::string CodeModel; - /// The directory in which to place coverage data files. - std::string CoverageDir; + /// The filename with path we use for coverage files. The extension will be + /// replaced. + std::string CoverageFile; /// Enable additional debugging information. std::string DebugPass; diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 22df86aca2..4ce12ecd60 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -134,7 +134,7 @@ void CodeGenModule::Release() { EmitDeclMetadata(); if (getCodeGenOpts().EmitGcovArcs || getCodeGenOpts().EmitGcovNotes) - EmitCoverageDir(); + EmitCoverageFile(); } void CodeGenModule::UpdateCompletedType(const TagDecl *TD) { @@ -2219,16 +2219,16 @@ void CodeGenFunction::EmitDeclMetadata() { } } -void CodeGenModule::EmitCoverageDir() { - if (!getCodeGenOpts().CoverageDir.empty()) { +void CodeGenModule::EmitCoverageFile() { + if (!getCodeGenOpts().CoverageFile.empty()) { if (llvm::NamedMDNode *CUNode = TheModule.getNamedMetadata("llvm.dbg.cu")) { llvm::NamedMDNode *GCov = TheModule.getOrInsertNamedMetadata("llvm.gcov"); llvm::LLVMContext &Ctx = TheModule.getContext(); - llvm::MDString *CoverageDir = - llvm::MDString::get(Ctx, getCodeGenOpts().CoverageDir); + llvm::MDString *CoverageFile = + llvm::MDString::get(Ctx, getCodeGenOpts().CoverageFile); for (int i = 0, e = CUNode->getNumOperands(); i != e; ++i) { llvm::MDNode *CU = CUNode->getOperand(i); - llvm::Value *node[] = { CoverageDir, CU }; + llvm::Value *node[] = { CoverageFile, CU }; llvm::MDNode *N = llvm::MDNode::get(Ctx, node); GCov->addOperand(N); } diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index 65ee922279..ce708c88d0 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -735,9 +735,9 @@ private: void EmitDeclMetadata(); - /// EmitCoverageDir - Emit the llvm.gcov metadata used to tell LLVM where + /// EmitCoverageFile - Emit the llvm.gcov metadata used to tell LLVM where /// to emit the .gcno and .gcda files in a way that persists in .bc files. - void EmitCoverageDir(); + void EmitCoverageFile(); /// MayDeferGeneration - Determine if the given decl can be emitted /// lazily; this is only relevant for definitions. The given decl diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index f4e0f2e359..239edb5db4 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1306,12 +1306,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (C.getArgs().hasArg(options::OPT_c) || C.getArgs().hasArg(options::OPT_S)) { if (Output.isFilename()) { - llvm::StringRef CoverageDir = - llvm::sys::path::parent_path(Output.getFilename()); - if (!CoverageDir.empty()) { - CmdArgs.push_back("-coverage-dir"); - CmdArgs.push_back(Args.MakeArgString(CoverageDir)); - } + CmdArgs.push_back("-coverage-file"); + CmdArgs.push_back(Args.MakeArgString(Output.getFilename())); } } diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 180ce3efcb..924e5ed4cb 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -974,7 +974,7 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.InstrumentForProfiling = Args.hasArg(OPT_pg); Opts.EmitGcovArcs = Args.hasArg(OPT_femit_coverage_data); Opts.EmitGcovNotes = Args.hasArg(OPT_femit_coverage_notes); - Opts.CoverageDir = Args.getLastArgValue(OPT_coverage_dir); + Opts.CoverageFile = Args.getLastArgValue(OPT_coverage_file); if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) { llvm::StringRef Name = A->getValue(Args);