[clang] e105141 - [Driver] Allow XRay for more architectures on ELF systems

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 20 20:41:59 PDT 2023


Author: Fangrui Song
Date: 2023-06-20T20:41:54-07:00
New Revision: e1051414a16e970c2e36c2ab7dfe2b17353c4751

URL: https://github.com/llvm/llvm-project/commit/e1051414a16e970c2e36c2ab7dfe2b17353c4751
DIFF: https://github.com/llvm/llvm-project/commit/e1051414a16e970c2e36c2ab7dfe2b17353c4751.diff

LOG: [Driver] Allow XRay for more architectures on ELF systems

Codegen OS-agnostic for ELF and the runtime is mostly OS-agnostic. It
seems unnecessary to make restriction.

While here, rewrite test/Driver/XRay/xray-instrument*.c to be more conventional:
specify --target= explicitly instead of relying on the configured default target
(which needs `REQUIRES:`).

I am not sure enumerating every supported architecture is useful, so we just test a few.

Added: 
    clang/test/Driver/XRay/xray-instrument.c

Modified: 
    clang/lib/Driver/XRayArgs.cpp

Removed: 
    clang/test/Driver/XRay/xray-instrument-cpu.c
    clang/test/Driver/XRay/xray-instrument-macos.c
    clang/test/Driver/XRay/xray-instrument-os.c


################################################################################
diff  --git a/clang/lib/Driver/XRayArgs.cpp b/clang/lib/Driver/XRayArgs.cpp
index 9a4b28576a9b9..427c4ced3cd46 100644
--- a/clang/lib/Driver/XRayArgs.cpp
+++ b/clang/lib/Driver/XRayArgs.cpp
@@ -31,7 +31,12 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
                     options::OPT_fno_xray_instrument, false))
     return;
   XRayInstrument = Args.getLastArg(options::OPT_fxray_instrument);
-  if (Triple.getOS() == llvm::Triple::Linux) {
+  if (Triple.isMacOSX()) {
+    if (Triple.getArch() != llvm::Triple::x86_64) {
+      D.Diag(diag::err_drv_unsupported_opt_for_target)
+          << XRayInstrument->getSpelling() << Triple.str();
+    }
+  } else if (Triple.isOSBinFormatELF()) {
     switch (Triple.getArch()) {
     case llvm::Triple::x86_64:
     case llvm::Triple::arm:
@@ -47,21 +52,6 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
       D.Diag(diag::err_drv_unsupported_opt_for_target)
           << XRayInstrument->getSpelling() << Triple.str();
     }
-  } else if (Triple.isOSFreeBSD() || Triple.isOSOpenBSD() ||
-             Triple.isOSNetBSD() || Triple.isMacOSX()) {
-    if (Triple.getArch() != llvm::Triple::x86_64) {
-      D.Diag(diag::err_drv_unsupported_opt_for_target)
-          << XRayInstrument->getSpelling() << Triple.str();
-    }
-  } else if (Triple.getOS() == llvm::Triple::Fuchsia) {
-    switch (Triple.getArch()) {
-    case llvm::Triple::x86_64:
-    case llvm::Triple::aarch64:
-      break;
-    default:
-      D.Diag(diag::err_drv_unsupported_opt_for_target)
-          << XRayInstrument->getSpelling() << Triple.str();
-    }
   } else {
     D.Diag(diag::err_drv_unsupported_opt_for_target)
         << XRayInstrument->getSpelling() << Triple.str();

diff  --git a/clang/test/Driver/XRay/xray-instrument-cpu.c b/clang/test/Driver/XRay/xray-instrument-cpu.c
deleted file mode 100644
index a8bc2a6431335..0000000000000
--- a/clang/test/Driver/XRay/xray-instrument-cpu.c
+++ /dev/null
@@ -1,5 +0,0 @@
-// RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: target={{(amd64|x86_64|x86_64h|powerpc64le)-.*}}
-// XFAIL: target={{(arm|aarch64|arm64|mips|mipsel|mips64|mips64el)-.*}}
-// REQUIRES: linux
-typedef int a;

diff  --git a/clang/test/Driver/XRay/xray-instrument-macos.c b/clang/test/Driver/XRay/xray-instrument-macos.c
deleted file mode 100644
index ce68345ed019f..0000000000000
--- a/clang/test/Driver/XRay/xray-instrument-macos.c
+++ /dev/null
@@ -1,4 +0,0 @@
-// RUN: %clang -o /dev/null -v -fxray-instrument -target x86_64-apple-macos10.11 -c %s
-// RUN: %clang -o /dev/null -v -fxray-instrument -target x86_64-apple-darwin15 -c %s
-// REQUIRES: x86_64 || x86_64h
-typedef int a;

diff  --git a/clang/test/Driver/XRay/xray-instrument-os.c b/clang/test/Driver/XRay/xray-instrument-os.c
deleted file mode 100644
index 7a4f1c13cb0b1..0000000000000
--- a/clang/test/Driver/XRay/xray-instrument-os.c
+++ /dev/null
@@ -1,4 +0,0 @@
-// RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: target={{.*-(linux|freebsd).*}}, target=x86_64-apple-{{(darwin|macos).*}}
-// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64)-.*}}
-typedef int a;

diff  --git a/clang/test/Driver/XRay/xray-instrument.c b/clang/test/Driver/XRay/xray-instrument.c
new file mode 100644
index 0000000000000..430418446366c
--- /dev/null
+++ b/clang/test/Driver/XRay/xray-instrument.c
@@ -0,0 +1,8 @@
+// RUN: %clang -### --target=aarch64-pc-freebsd -fxray-instrument -c %s -o /dev/null 2>&1 | FileCheck %s
+// RUN: %clang -### --target=x86_64-apple-darwin -fxray-instrument -c %s -o /dev/null 2>&1 | FileCheck %s
+// RUN: %clang -### --target=x86_64-pc-windows -fxray-instrument -c %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR
+
+// CHECK: "-cc1" {{.*}}"-fxray-instrument"
+// ERR:   error: unsupported option '-fxray-instrument' for target
+
+typedef int a;


        


More information about the cfe-commits mailing list