[PATCH] D24799: [XRay] Check in Clang whether XRay supports the target when -fxray-instrument is passed

Serge Rogatch via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 21 11:22:56 PDT 2016


rSerge updated this revision to Diff 75452.
rSerge added a comment.

I had to add the root directories `a` and `b` manually, as I couldn't find an `svn diff` argument for that.
The code file `Tools.cpp` was run via `clang-format`, then just my changes were copy-pasted.
2 tests have been added to enable both OS and CPU checking.
`const string` approach was leading to undefined behavior, because the lifetime of the string is shorter than the lifetime of the `const char *` array using its data. So I had to return to `const char* const`.


https://reviews.llvm.org/D24799

Files:
  lib/Driver/Tools.cpp
  test/Driver/XRay/lit.local.cfg
  test/Driver/XRay/xray-instrument-cpu.c
  test/Driver/XRay/xray-instrument-os.c


Index: test/Driver/XRay/xray-instrument-os.c
===================================================================
--- test/Driver/XRay/xray-instrument-os.c
+++ test/Driver/XRay/xray-instrument-os.c
@@ -0,0 +1,4 @@
+// RUN: not %clang -v -fxray-instrument -c %s
+// XFAIL: -linux-
+// REQUIRES-ANY: amd64, x86_64, x86_64h, arm
+typedef int a;
Index: test/Driver/XRay/xray-instrument-cpu.c
===================================================================
--- test/Driver/XRay/xray-instrument-cpu.c
+++ test/Driver/XRay/xray-instrument-cpu.c
@@ -0,0 +1,4 @@
+// RUN: not %clang -v -fxray-instrument -c %s
+// XFAIL: amd64-, x86_64-, x86_64h-, arm
+// REQUIRES: linux
+typedef int a;
Index: test/Driver/XRay/lit.local.cfg
===================================================================
--- test/Driver/XRay/lit.local.cfg
+++ test/Driver/XRay/lit.local.cfg
@@ -0,0 +1,2 @@
+target_triple_components = config.target_triple.split('-')
+config.available_features.update(target_triple_components)
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4804,7 +4804,16 @@
 
   if (Args.hasFlag(options::OPT_fxray_instrument,
                    options::OPT_fnoxray_instrument, false)) {
-    CmdArgs.push_back("-fxray-instrument");
+    const char *const XRayInstrumentOption = "-fxray-instrument";
+    if (Triple.getOS() == llvm::Triple::Linux &&
+        (Triple.getArch() == llvm::Triple::arm ||
+         Triple.getArch() == llvm::Triple::x86_64)) {
+      // Supported.
+    } else {
+      D.Diag(diag::err_drv_clang_unsupported)
+          << (std::string(XRayInstrumentOption) + " on " + Triple.str());
+    }
+    CmdArgs.push_back(XRayInstrumentOption);
     if (const Arg *A =
             Args.getLastArg(options::OPT_fxray_instruction_threshold_,
                             options::OPT_fxray_instruction_threshold_EQ)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24799.75452.patch
Type: text/x-patch
Size: 1957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161021/f86b631b/attachment-0001.bin>


More information about the cfe-commits mailing list