]> granicus.if.org Git - clang/commitdiff
[XRay][clang] Fix the -fxray-instruction-threshold flag processing
authorDean Michael Berris <dberris@google.com>
Thu, 30 Mar 2017 22:46:45 +0000 (22:46 +0000)
committerDean Michael Berris <dberris@google.com>
Thu, 30 Mar 2017 22:46:45 +0000 (22:46 +0000)
Summary:
The refactoring introduced a regression in the flag processing for
-fxray-instruction-threshold which causes it to not get passed properly.
This change should restore the previous behaviour.

Reviewers: rnk, pelikan

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D31491

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299126 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/XRayArgs.cpp
lib/Frontend/CompilerInvocation.cpp
test/CodeGen/xray-instruction-threshold.cpp [new file with mode: 0644]

index 0e0fe6ffa41c670476af71eeb7e3bf0278cb360b..8d68a8432d39d7b8db74eb86a88932a475a635b4 100644 (file)
@@ -16,8 +16,8 @@
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
-#include "llvm/Support/SpecialCaseList.h"
 #include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/SpecialCaseList.h"
 
 using namespace clang;
 using namespace clang::driver;
@@ -91,8 +91,8 @@ void XRayArgs::addArgs(const ToolChain &TC, const ArgList &Args,
     return;
 
   CmdArgs.push_back(XRayInstrumentOption);
-  CmdArgs.push_back(Args.MakeArgString(XRayInstructionThresholdOption +
-                                       llvm::to_string(InstructionThreshold)));
+  CmdArgs.push_back(Args.MakeArgString(Twine(XRayInstructionThresholdOption) +
+                                       Twine(InstructionThreshold)));
 
   for (const auto &Always : AlwaysInstrumentFiles) {
     SmallString<64> AlwaysInstrumentOpt(XRayAlwaysInstrumentOption);
index bea29e2de7c395b9922bcbf03a954517b2b1cc1a..a9d805b7db203ee57789002b9e0fde0dfa9709b9 100644 (file)
@@ -721,7 +721,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
   Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions);
   Opts.XRayInstrumentFunctions = Args.hasArg(OPT_fxray_instrument);
   Opts.XRayInstructionThreshold =
-      getLastArgIntValue(Args, OPT_fxray_instruction_threshold_, 200, Diags);
+      getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
   Opts.InstrumentForProfiling = Args.hasArg(OPT_pg);
   Opts.CallFEntry = Args.hasArg(OPT_mfentry);
   Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info);
@@ -2308,9 +2308,11 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
       getLastArgIntValue(Args, OPT_fsanitize_address_field_padding, 0, Diags);
   Opts.SanitizerBlacklistFiles = Args.getAllArgValues(OPT_fsanitize_blacklist);
 
-  // -fxray-{always,never}-instrument= filenames.
+  // -fxray-instrument
   Opts.XRayInstrument =
       Args.hasFlag(OPT_fxray_instrument, OPT_fnoxray_instrument, false);
+
+  // -fxray-{always,never}-instrument= filenames.
   Opts.XRayAlwaysInstrumentFiles =
       Args.getAllArgValues(OPT_fxray_always_instrument);
   Opts.XRayNeverInstrumentFiles =
diff --git a/test/CodeGen/xray-instruction-threshold.cpp b/test/CodeGen/xray-instruction-threshold.cpp
new file mode 100644 (file)
index 0000000..ad8801a
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fxray-instrument -fxray-instruction-threshold=1 -x c++ -std=c++11 -emit-llvm -o - %s -triple x86_64-unknown-linux-gnu | FileCheck %s
+
+int foo() {
+  return 1;
+}
+
+[[clang::xray_never_instrument]] int bar() {
+  return 2;
+}
+
+// CHECK-DAG: define i32 @_Z3foov() #[[THRESHOLD:[0-9]+]] {
+// CHECK-DAG: define i32 @_Z3barv() #[[NEVERATTR:[0-9]+]] {
+// CHECK-DAG: attributes #[[THRESHOLD]] = {{.*}} "xray-instruction-threshold"="1" {{.*}}
+// CHECK-DAG: attributes #[[NEVERATTR]] = {{.*}} "function-instrument"="xray-never" {{.*}}