From 9123bfddd7a0aa5a1c4f6184d2f668e531e24c00 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 27 Nov 2018 17:31:08 +0000 Subject: [PATCH] Fix linker option for -fprofile-arcs -ftest-coverage Summary: Linux toolchain accidentally added "-u__llvm_runtime_variable" when "-fprofile-arcs -ftest-coverage", this is not added when "--coverage" option is used. Using "-u__llvm_runtime_variable" generates an empty default.profraw file while an application built with "-fprofile-arcs -ftest-coverage" is running. Reviewers: calixte, marco-c, sylvestre.ledru Reviewed By: marco-c Subscribers: vsk, cfe-commits Differential Revision: https://reviews.llvm.org/D54195 llvm-svn: 347677 --- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/test/Driver/clang_f_opts.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp index 59034bc..79deb04 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -1019,7 +1019,7 @@ void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args, // Add linker option -u__llvm_runtime_variable to cause runtime // initialization module to be linked in. - if (!Args.hasArg(options::OPT_coverage)) + if ((!Args.hasArg(options::OPT_coverage)) && (!Args.hasArg(options::OPT_ftest_coverage))) CmdArgs.push_back(Args.MakeArgString( Twine("-u", llvm::getInstrProfRuntimeHookVarName()))); ToolChain::addProfileRTLibs(Args, CmdArgs); diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c index 6536605..3596aab 100644 --- a/clang/test/Driver/clang_f_opts.c +++ b/clang/test/Driver/clang_f_opts.c @@ -85,6 +85,10 @@ // CHECK-PROFILE-DIR-UNUSED-NOT: "-coverage-data-file" "abc // CHECK-PROFILE-DIR-NEITHER-NOT: argument unused +// RUN: %clang -### -fprofile-arcs -ftest-coverage %s 2>&1 | FileCheck -check-prefix=CHECK-u %s +// RUN: %clang -### --coverage %s 2>&1 | FileCheck -check-prefix=CHECK-u %s +// CHECK-u-NOT: "-u{{.*}}" + // RUN: %clang -### -S -fprofile-generate %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE-LLVM %s // RUN: %clang -### -S -fprofile-instr-generate %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE %s // RUN: %clang -### -S -fprofile-generate=/some/dir %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE-DIR %s -- 2.7.4