[llvm-branch-commits] [clang] clang: Refactor handling of offload sanitizer arguments (PR #196737)

2026-05-23 Thread Matt Arsenault via llvm-branch-commits


@@ -540,15 +550,79 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
 DiagnosedKinds |= SanitizerKind::CFIMFCall;
   }
 
-  if (SanitizerMask KindsToDiagnose = Add & ~Supported & ~DiagnosedKinds) {
-if (DiagnoseErrors) {
-  std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
+  // Check for sanitizers that are supported by the toolchain but not for
+  // this specific arch (e.g., AMDGPU requires specific subtarget features
+  // for address sanitizer.)
+  if (SanitizerMask ArchSpecificUnsupported =

arsenm wrote:

This is not conceptually amdgpu specific and is already a virtual for the set 
of features 

https://github.com/llvm/llvm-project/pull/196737
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] clang: Refactor handling of offload sanitizer arguments (PR #196737)

2026-05-21 Thread Joseph Huber via llvm-branch-commits


@@ -540,15 +550,79 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
 DiagnosedKinds |= SanitizerKind::CFIMFCall;
   }
 
-  if (SanitizerMask KindsToDiagnose = Add & ~Supported & ~DiagnosedKinds) {
-if (DiagnoseErrors) {
-  std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
+  // Check for sanitizers that are supported by the toolchain but not for
+  // this specific arch (e.g., AMDGPU requires specific subtarget features
+  // for address sanitizer.)
+  if (SanitizerMask ArchSpecificUnsupported =

jhuber6 wrote:

I'm a little hesitant to put this in the core SanitizerArgs because it seems to 
be purely AMDGPU specific. Would it be possible to have a virtual function in 
the ToolChain or something?  I'd expect us to be able to check `OPT_mcpu` 
instead of the bound architecture as well.

https://github.com/llvm/llvm-project/pull/196737
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] clang: Refactor handling of offload sanitizer arguments (PR #196737)

2026-05-21 Thread Matt Arsenault via llvm-branch-commits


@@ -540,15 +550,79 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
 DiagnosedKinds |= SanitizerKind::CFIMFCall;
   }
 
-  if (SanitizerMask KindsToDiagnose = Add & ~Supported & ~DiagnosedKinds) {
-if (DiagnoseErrors) {
-  std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
+  // Check for sanitizers that are supported by the toolchain but not for
+  // this specific arch (e.g., AMDGPU requires specific subtarget features
+  // for address sanitizer.)
+  if (SanitizerMask ArchSpecificUnsupported =

arsenm wrote:

This also should not consider -mcpu. This is only the behavior for offload with 
mixed architectures. Nonoffload will always error on unhandled sanitizers 

https://github.com/llvm/llvm-project/pull/196737
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] clang: Refactor handling of offload sanitizer arguments (PR #196737)

2026-05-11 Thread Joseph Huber via llvm-branch-commits

https://github.com/jhuber6 commented:

I *really* wish that we never added `-fgpu-sanitize`. This is something that 
should've been handled through `-Xarch_device`. Any chance we could alias this 
to `-Xarch_device -fsanitize=address` or something?

https://github.com/llvm/llvm-project/pull/196737
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] clang: Refactor handling of offload sanitizer arguments (PR #196737)

2026-05-11 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

> I _really_ wish that we never added `-fgpu-sanitize`. This is something that 
> should've been handled through `-Xarch_device`. Any chance we could alias 
> this to `-Xarch_device -fsanitize=address` or something?

I don't know how you would do that; I'm not trying to change behavior 

https://github.com/llvm/llvm-project/pull/196737
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] clang: Refactor handling of offload sanitizer arguments (PR #196737)

2026-05-10 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/196737

>From 2aec801befd3991f46879f01d014fd122f89c5cc Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Thu, 7 May 2026 20:57:02 +0100
Subject: [PATCH] clang: Refactor handling of offload sanitizer arguments

Previously the AMDGPU toolchains hackily handled -fsanitize arguments.
They would lie and report that all host side sanitizers are available,
then TranslateArgs would filter out the device side cases that do not
work, providing diagnostics for the skipped cases. Move that logic
into the base sanitizer argument parsing.

This makes the produced diagnostics more consistent. Previously we
would get repeated warnings when a sanitizer is fully unsupported
by amdgpu, which should now be once for the toolchain. These could
be further improved; we're printing the specific field of -fsanitize
in more cases where it could be skipped. In other cases we have the
opposite problem, where we aren't reporting the exact sanitizer
from the -f flag in the case that depends on a subtarget feature.

This will help fix other broken target specific flag forwarding bugs
in the future.

Co-authored-by: Claude Sonnet 4 
---
 clang/include/clang/Driver/SanitizerArgs.h|   5 +-
 clang/include/clang/Driver/ToolChain.h|  19 +++-
 clang/lib/Driver/SanitizerArgs.cpp|  94 ++--
 clang/lib/Driver/ToolChain.cpp|  11 +-
 clang/lib/Driver/ToolChains/AMDGPU.cpp| 101 ++
 clang/lib/Driver/ToolChains/AMDGPU.h  |  82 ++
 clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp  |  38 +++
 clang/lib/Driver/ToolChains/AMDGPUOpenMP.h|   5 +-
 clang/lib/Driver/ToolChains/Clang.cpp |   4 +-
 clang/lib/Driver/ToolChains/HIPAMD.cpp|  45 
 clang/lib/Driver/ToolChains/HIPAMD.h  |   5 +-
 .../Driver/amdgpu-openmp-sanitize-options.c   |   4 +-
 clang/test/Driver/amdgpu-validate-sanitize.cl |  23 
 clang/test/Driver/hip-sanitize-options.hip|  28 ++---
 14 files changed, 259 insertions(+), 205 deletions(-)
 create mode 100644 clang/test/Driver/amdgpu-validate-sanitize.cl

diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index ed2eb6852b124..d4ee17802fd8e 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -9,6 +9,7 @@
 #define LLVM_CLANG_DRIVER_SANITIZERARGS_H
 
 #include "clang/Basic/Sanitizers.h"
+#include "clang/Driver/Action.h"
 #include "clang/Driver/Types.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -85,7 +86,9 @@ class SanitizerArgs {
 public:
   /// Parses the sanitizer arguments from an argument list.
   SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
-bool DiagnoseErrors = true);
+bool DiagnoseErrors = true, bool DiagnoseBoundArchErrors = 
true,
+StringRef BoundArch = "",
+Action::OffloadKind DeviceOffloadKind = Action::OFK_None);
 
   bool needsSharedRt() const { return SharedRuntime; }
   bool needsStableAbi() const { return StableABI; }
diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 8676318d6f9d4..7df9565da8c2a 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -18,6 +18,7 @@
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FloatingPointMode.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Frontend/Debug/Options.h"
@@ -185,8 +186,13 @@ class ToolChain {
   Tool *getOffloadPackager() const;
   Tool *getLinkerWrapper() const;
 
+  /// Track if diagnostics have been emitted for sanitizer arguments already to
+  /// avoid duplicate diagnostics.
   mutable bool SanitizerArgsChecked = false;
 
+  /// Set of BoundArch values which have already had diagnostics emitted.
+  mutable llvm::SmallSet BoundArchSanitizerArgsChecked;
+
   /// The effective clang triple for the current Job.
   mutable llvm::Triple EffectiveTriple;
 
@@ -338,7 +344,18 @@ class ToolChain {
   /// -print-multi-flags-experimental argument.
   Multilib::flags_list getMultilibFlags(const llvm::opt::ArgList &) const;
 
-  SanitizerArgs getSanitizerArgs(const llvm::opt::ArgList &JobArgs) const;
+  SanitizerArgs getSanitizerArgs(
+  const llvm::opt::ArgList &JobArgs, StringRef BoundArch = "",
+  Action::OffloadKind DeviceOffloadKind = Action::OFK_None) const;
+
+  /// Returns the feature requirement for a sanitizer on a specific arch for
+  /// diagnostic purposes. Returns the required feature name (e.g., "xnack+") 
if
+  /// the sanitizer is generally supported but requires a specific feature for
+  /// the given BoundArch, or an empty StringRef otherwise.
+  virtual StringRef getSanitizerRequirement(SanitizerMask Kinds,
+

[llvm-branch-commits] [clang] clang: Refactor handling of offload sanitizer arguments (PR #196737)

2026-05-10 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/196737

>From 2aec801befd3991f46879f01d014fd122f89c5cc Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Thu, 7 May 2026 20:57:02 +0100
Subject: [PATCH] clang: Refactor handling of offload sanitizer arguments

Previously the AMDGPU toolchains hackily handled -fsanitize arguments.
They would lie and report that all host side sanitizers are available,
then TranslateArgs would filter out the device side cases that do not
work, providing diagnostics for the skipped cases. Move that logic
into the base sanitizer argument parsing.

This makes the produced diagnostics more consistent. Previously we
would get repeated warnings when a sanitizer is fully unsupported
by amdgpu, which should now be once for the toolchain. These could
be further improved; we're printing the specific field of -fsanitize
in more cases where it could be skipped. In other cases we have the
opposite problem, where we aren't reporting the exact sanitizer
from the -f flag in the case that depends on a subtarget feature.

This will help fix other broken target specific flag forwarding bugs
in the future.

Co-authored-by: Claude Sonnet 4 
---
 clang/include/clang/Driver/SanitizerArgs.h|   5 +-
 clang/include/clang/Driver/ToolChain.h|  19 +++-
 clang/lib/Driver/SanitizerArgs.cpp|  94 ++--
 clang/lib/Driver/ToolChain.cpp|  11 +-
 clang/lib/Driver/ToolChains/AMDGPU.cpp| 101 ++
 clang/lib/Driver/ToolChains/AMDGPU.h  |  82 ++
 clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp  |  38 +++
 clang/lib/Driver/ToolChains/AMDGPUOpenMP.h|   5 +-
 clang/lib/Driver/ToolChains/Clang.cpp |   4 +-
 clang/lib/Driver/ToolChains/HIPAMD.cpp|  45 
 clang/lib/Driver/ToolChains/HIPAMD.h  |   5 +-
 .../Driver/amdgpu-openmp-sanitize-options.c   |   4 +-
 clang/test/Driver/amdgpu-validate-sanitize.cl |  23 
 clang/test/Driver/hip-sanitize-options.hip|  28 ++---
 14 files changed, 259 insertions(+), 205 deletions(-)
 create mode 100644 clang/test/Driver/amdgpu-validate-sanitize.cl

diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index ed2eb6852b124..d4ee17802fd8e 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -9,6 +9,7 @@
 #define LLVM_CLANG_DRIVER_SANITIZERARGS_H
 
 #include "clang/Basic/Sanitizers.h"
+#include "clang/Driver/Action.h"
 #include "clang/Driver/Types.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -85,7 +86,9 @@ class SanitizerArgs {
 public:
   /// Parses the sanitizer arguments from an argument list.
   SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
-bool DiagnoseErrors = true);
+bool DiagnoseErrors = true, bool DiagnoseBoundArchErrors = 
true,
+StringRef BoundArch = "",
+Action::OffloadKind DeviceOffloadKind = Action::OFK_None);
 
   bool needsSharedRt() const { return SharedRuntime; }
   bool needsStableAbi() const { return StableABI; }
diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 8676318d6f9d4..7df9565da8c2a 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -18,6 +18,7 @@
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FloatingPointMode.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Frontend/Debug/Options.h"
@@ -185,8 +186,13 @@ class ToolChain {
   Tool *getOffloadPackager() const;
   Tool *getLinkerWrapper() const;
 
+  /// Track if diagnostics have been emitted for sanitizer arguments already to
+  /// avoid duplicate diagnostics.
   mutable bool SanitizerArgsChecked = false;
 
+  /// Set of BoundArch values which have already had diagnostics emitted.
+  mutable llvm::SmallSet BoundArchSanitizerArgsChecked;
+
   /// The effective clang triple for the current Job.
   mutable llvm::Triple EffectiveTriple;
 
@@ -338,7 +344,18 @@ class ToolChain {
   /// -print-multi-flags-experimental argument.
   Multilib::flags_list getMultilibFlags(const llvm::opt::ArgList &) const;
 
-  SanitizerArgs getSanitizerArgs(const llvm::opt::ArgList &JobArgs) const;
+  SanitizerArgs getSanitizerArgs(
+  const llvm::opt::ArgList &JobArgs, StringRef BoundArch = "",
+  Action::OffloadKind DeviceOffloadKind = Action::OFK_None) const;
+
+  /// Returns the feature requirement for a sanitizer on a specific arch for
+  /// diagnostic purposes. Returns the required feature name (e.g., "xnack+") 
if
+  /// the sanitizer is generally supported but requires a specific feature for
+  /// the given BoundArch, or an empty StringRef otherwise.
+  virtual StringRef getSanitizerRequirement(SanitizerMask Kinds,
+

[llvm-branch-commits] [clang] clang: Refactor handling of offload sanitizer arguments (PR #196737)

2026-05-10 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

Failure is test bug: #196745

https://github.com/llvm/llvm-project/pull/196737
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] clang: Refactor handling of offload sanitizer arguments (PR #196737)

2026-05-09 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/196737

>From 882122f1254331686f6e49b8d71e4c4a505d2b00 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Thu, 7 May 2026 20:57:02 +0100
Subject: [PATCH] clang: Refactor handling of offload sanitizer arguments

Previously the AMDGPU toolchains hackily handled -fsanitize arguments.
They would lie and report that all host side sanitizers are available,
then TranslateArgs would filter out the device side cases that do not
work, providing diagnostics for the skipped cases. Move that logic
into the base sanitizer argument parsing.

This makes the produced diagnostics more consistent. Previously we
would get repeated warnings when a sanitizer is fully unsupported
by amdgpu, which should now be once for the toolchain. These could
be further improved; we're printing the specific field of -fsanitize
in more cases where it could be skipped. In other cases we have the
opposite problem, where we aren't reporting the exact sanitizer
from the -f flag in the case that depends on a subtarget feature.

This will help fix other broken target specific flag forwarding bugs
in the future.

Co-authored-by: Claude Sonnet 4 
---
 clang/include/clang/Driver/SanitizerArgs.h|   5 +-
 clang/include/clang/Driver/ToolChain.h|  19 +++-
 clang/lib/Driver/SanitizerArgs.cpp|  94 ++--
 clang/lib/Driver/ToolChain.cpp|  11 +-
 clang/lib/Driver/ToolChains/AMDGPU.cpp| 101 ++
 clang/lib/Driver/ToolChains/AMDGPU.h  |  82 ++
 clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp  |  38 +++
 clang/lib/Driver/ToolChains/AMDGPUOpenMP.h|   5 +-
 clang/lib/Driver/ToolChains/Clang.cpp |   4 +-
 clang/lib/Driver/ToolChains/HIPAMD.cpp|  45 
 clang/lib/Driver/ToolChains/HIPAMD.h  |   5 +-
 .../Driver/amdgpu-openmp-sanitize-options.c   |   4 +-
 clang/test/Driver/amdgpu-validate-sanitize.cl |  23 
 clang/test/Driver/hip-sanitize-options.hip|  28 ++---
 14 files changed, 259 insertions(+), 205 deletions(-)
 create mode 100644 clang/test/Driver/amdgpu-validate-sanitize.cl

diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index ed2eb6852b124..d4ee17802fd8e 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -9,6 +9,7 @@
 #define LLVM_CLANG_DRIVER_SANITIZERARGS_H
 
 #include "clang/Basic/Sanitizers.h"
+#include "clang/Driver/Action.h"
 #include "clang/Driver/Types.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -85,7 +86,9 @@ class SanitizerArgs {
 public:
   /// Parses the sanitizer arguments from an argument list.
   SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
-bool DiagnoseErrors = true);
+bool DiagnoseErrors = true, bool DiagnoseBoundArchErrors = 
true,
+StringRef BoundArch = "",
+Action::OffloadKind DeviceOffloadKind = Action::OFK_None);
 
   bool needsSharedRt() const { return SharedRuntime; }
   bool needsStableAbi() const { return StableABI; }
diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 8676318d6f9d4..7df9565da8c2a 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -18,6 +18,7 @@
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FloatingPointMode.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Frontend/Debug/Options.h"
@@ -185,8 +186,13 @@ class ToolChain {
   Tool *getOffloadPackager() const;
   Tool *getLinkerWrapper() const;
 
+  /// Track if diagnostics have been emitted for sanitizer arguments already to
+  /// avoid duplicate diagnostics.
   mutable bool SanitizerArgsChecked = false;
 
+  /// Set of BoundArch values which have already had diagnostics emitted.
+  mutable llvm::SmallSet BoundArchSanitizerArgsChecked;
+
   /// The effective clang triple for the current Job.
   mutable llvm::Triple EffectiveTriple;
 
@@ -338,7 +344,18 @@ class ToolChain {
   /// -print-multi-flags-experimental argument.
   Multilib::flags_list getMultilibFlags(const llvm::opt::ArgList &) const;
 
-  SanitizerArgs getSanitizerArgs(const llvm::opt::ArgList &JobArgs) const;
+  SanitizerArgs getSanitizerArgs(
+  const llvm::opt::ArgList &JobArgs, StringRef BoundArch = "",
+  Action::OffloadKind DeviceOffloadKind = Action::OFK_None) const;
+
+  /// Returns the feature requirement for a sanitizer on a specific arch for
+  /// diagnostic purposes. Returns the required feature name (e.g., "xnack+") 
if
+  /// the sanitizer is generally supported but requires a specific feature for
+  /// the given BoundArch, or an empty StringRef otherwise.
+  virtual StringRef getSanitizerRequirement(SanitizerMask Kinds,
+

[llvm-branch-commits] [clang] clang: Refactor handling of offload sanitizer arguments (PR #196737)

2026-05-09 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

While working on this, Claude liked adding redundant and dead handling of the 
diagnostics. It also helpfully decided to "fix" some of the argument tests by 
breaking the check prefixes 

https://github.com/llvm/llvm-project/pull/196737
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] clang: Refactor handling of offload sanitizer arguments (PR #196737)

2026-05-09 Thread via llvm-branch-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-clang

Author: Matt Arsenault (arsenm)


Changes

Previously the AMDGPU toolchains hackily handled -fsanitize arguments.
They would lie and report that all host side sanitizers are available,
then TranslateArgs would filter out the device side cases that do not
work, providing diagnostics for the skipped cases. Move that logic
into the base sanitizer argument parsing.

This makes the produced diagnostics more consistent. Previously we
would get repeated warnings when a sanitizer is fully unsupported
by amdgpu, which should now be once for the toolchain. These could
be further improved; we're printing the specific field of -fsanitize
in more cases where it could be skipped. In other cases we have the
opposite problem, where we aren't reporting the exact sanitizer
from the -f flag in the case that depends on a subtarget feature.

This will help fix other broken target specific flag forwarding bugs
in the future.

Co-authored-by: Claude Sonnet 4 

---

Patch is 40.32 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/196737.diff


14 Files Affected:

- (modified) clang/include/clang/Driver/SanitizerArgs.h (+4-1) 
- (modified) clang/include/clang/Driver/ToolChain.h (+18-1) 
- (modified) clang/lib/Driver/SanitizerArgs.cpp (+84-10) 
- (modified) clang/lib/Driver/ToolChain.cpp (+9-2) 
- (modified) clang/lib/Driver/ToolChains/AMDGPU.cpp (+55-46) 
- (modified) clang/lib/Driver/ToolChains/AMDGPU.h (+7-75) 
- (modified) clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp (+17-21) 
- (modified) clang/lib/Driver/ToolChains/AMDGPUOpenMP.h (+1-4) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+3-1) 
- (modified) clang/lib/Driver/ToolChains/HIPAMD.cpp (+21-24) 
- (modified) clang/lib/Driver/ToolChains/HIPAMD.h (+1-4) 
- (modified) clang/test/Driver/amdgpu-openmp-sanitize-options.c (+2-2) 
- (added) clang/test/Driver/amdgpu-validate-sanitize.cl (+23) 
- (modified) clang/test/Driver/hip-sanitize-options.hip (+14-14) 


``diff
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index ed2eb6852b124..d4ee17802fd8e 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -9,6 +9,7 @@
 #define LLVM_CLANG_DRIVER_SANITIZERARGS_H
 
 #include "clang/Basic/Sanitizers.h"
+#include "clang/Driver/Action.h"
 #include "clang/Driver/Types.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -85,7 +86,9 @@ class SanitizerArgs {
 public:
   /// Parses the sanitizer arguments from an argument list.
   SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
-bool DiagnoseErrors = true);
+bool DiagnoseErrors = true, bool DiagnoseBoundArchErrors = 
true,
+StringRef BoundArch = "",
+Action::OffloadKind DeviceOffloadKind = Action::OFK_None);
 
   bool needsSharedRt() const { return SharedRuntime; }
   bool needsStableAbi() const { return StableABI; }
diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 8676318d6f9d4..cbdec7843876c 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -18,6 +18,7 @@
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FloatingPointMode.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Frontend/Debug/Options.h"
@@ -185,8 +186,13 @@ class ToolChain {
   Tool *getOffloadPackager() const;
   Tool *getLinkerWrapper() const;
 
+  /// Track if diagnostics have been emitted for sanitizer arguments already to
+  /// avoid duplicate diagnostics.
   mutable bool SanitizerArgsChecked = false;
 
+  /// Set of BoundArch values which have already had diagnostics emitted.
+  mutable llvm::SmallSet BoundArchSanitizerArgsChecked;
+
   /// The effective clang triple for the current Job.
   mutable llvm::Triple EffectiveTriple;
 
@@ -338,7 +344,18 @@ class ToolChain {
   /// -print-multi-flags-experimental argument.
   Multilib::flags_list getMultilibFlags(const llvm::opt::ArgList &) const;
 
-  SanitizerArgs getSanitizerArgs(const llvm::opt::ArgList &JobArgs) const;
+  virtual SanitizerArgs getSanitizerArgs(
+  const llvm::opt::ArgList &JobArgs, StringRef BoundArch = "",
+  Action::OffloadKind DeviceOffloadKind = Action::OFK_None) const;
+
+  /// Returns the feature requirement for a sanitizer on a specific arch for
+  /// diagnostic purposes. Returns the required feature name (e.g., "xnack+") 
if
+  /// the sanitizer is generally supported but requires a specific feature for
+  /// the given BoundArch, or an empty StringRef otherwise.
+  virtual StringRef getSanitizerRequirement(SanitizerMask Kinds,
+StringRef BoundArch) const {
+return {};
+  }
 
   const XRayArgs getXR

[llvm-branch-commits] [clang] clang: Refactor handling of offload sanitizer arguments (PR #196737)

2026-05-09 Thread via llvm-branch-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-clang-driver

Author: Matt Arsenault (arsenm)


Changes

Previously the AMDGPU toolchains hackily handled -fsanitize arguments.
They would lie and report that all host side sanitizers are available,
then TranslateArgs would filter out the device side cases that do not
work, providing diagnostics for the skipped cases. Move that logic
into the base sanitizer argument parsing.

This makes the produced diagnostics more consistent. Previously we
would get repeated warnings when a sanitizer is fully unsupported
by amdgpu, which should now be once for the toolchain. These could
be further improved; we're printing the specific field of -fsanitize
in more cases where it could be skipped. In other cases we have the
opposite problem, where we aren't reporting the exact sanitizer
from the -f flag in the case that depends on a subtarget feature.

This will help fix other broken target specific flag forwarding bugs
in the future.

Co-authored-by: Claude Sonnet 4 

---

Patch is 40.32 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/196737.diff


14 Files Affected:

- (modified) clang/include/clang/Driver/SanitizerArgs.h (+4-1) 
- (modified) clang/include/clang/Driver/ToolChain.h (+18-1) 
- (modified) clang/lib/Driver/SanitizerArgs.cpp (+84-10) 
- (modified) clang/lib/Driver/ToolChain.cpp (+9-2) 
- (modified) clang/lib/Driver/ToolChains/AMDGPU.cpp (+55-46) 
- (modified) clang/lib/Driver/ToolChains/AMDGPU.h (+7-75) 
- (modified) clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp (+17-21) 
- (modified) clang/lib/Driver/ToolChains/AMDGPUOpenMP.h (+1-4) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+3-1) 
- (modified) clang/lib/Driver/ToolChains/HIPAMD.cpp (+21-24) 
- (modified) clang/lib/Driver/ToolChains/HIPAMD.h (+1-4) 
- (modified) clang/test/Driver/amdgpu-openmp-sanitize-options.c (+2-2) 
- (added) clang/test/Driver/amdgpu-validate-sanitize.cl (+23) 
- (modified) clang/test/Driver/hip-sanitize-options.hip (+14-14) 


``diff
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index ed2eb6852b124..d4ee17802fd8e 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -9,6 +9,7 @@
 #define LLVM_CLANG_DRIVER_SANITIZERARGS_H
 
 #include "clang/Basic/Sanitizers.h"
+#include "clang/Driver/Action.h"
 #include "clang/Driver/Types.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -85,7 +86,9 @@ class SanitizerArgs {
 public:
   /// Parses the sanitizer arguments from an argument list.
   SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
-bool DiagnoseErrors = true);
+bool DiagnoseErrors = true, bool DiagnoseBoundArchErrors = 
true,
+StringRef BoundArch = "",
+Action::OffloadKind DeviceOffloadKind = Action::OFK_None);
 
   bool needsSharedRt() const { return SharedRuntime; }
   bool needsStableAbi() const { return StableABI; }
diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 8676318d6f9d4..cbdec7843876c 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -18,6 +18,7 @@
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FloatingPointMode.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Frontend/Debug/Options.h"
@@ -185,8 +186,13 @@ class ToolChain {
   Tool *getOffloadPackager() const;
   Tool *getLinkerWrapper() const;
 
+  /// Track if diagnostics have been emitted for sanitizer arguments already to
+  /// avoid duplicate diagnostics.
   mutable bool SanitizerArgsChecked = false;
 
+  /// Set of BoundArch values which have already had diagnostics emitted.
+  mutable llvm::SmallSet BoundArchSanitizerArgsChecked;
+
   /// The effective clang triple for the current Job.
   mutable llvm::Triple EffectiveTriple;
 
@@ -338,7 +344,18 @@ class ToolChain {
   /// -print-multi-flags-experimental argument.
   Multilib::flags_list getMultilibFlags(const llvm::opt::ArgList &) const;
 
-  SanitizerArgs getSanitizerArgs(const llvm::opt::ArgList &JobArgs) const;
+  virtual SanitizerArgs getSanitizerArgs(
+  const llvm::opt::ArgList &JobArgs, StringRef BoundArch = "",
+  Action::OffloadKind DeviceOffloadKind = Action::OFK_None) const;
+
+  /// Returns the feature requirement for a sanitizer on a specific arch for
+  /// diagnostic purposes. Returns the required feature name (e.g., "xnack+") 
if
+  /// the sanitizer is generally supported but requires a specific feature for
+  /// the given BoundArch, or an empty StringRef otherwise.
+  virtual StringRef getSanitizerRequirement(SanitizerMask Kinds,
+StringRef BoundArch) const {
+return {};
+  }
 
   const XRayArg

[llvm-branch-commits] [clang] clang: Refactor handling of offload sanitizer arguments (PR #196737)

2026-05-09 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm ready_for_review 
https://github.com/llvm/llvm-project/pull/196737
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] clang: Refactor handling of offload sanitizer arguments (PR #196737)

2026-05-09 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.com/github/pr/llvm/llvm-project/196737?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#196737** https://app.graphite.com/github/pr/llvm/llvm-project/196737?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.com/github/pr/llvm/llvm-project/196737?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#196503** https://app.graphite.com/github/pr/llvm/llvm-project/196503?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/196737
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] clang: Refactor handling of offload sanitizer arguments (PR #196737)

2026-05-09 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm created 
https://github.com/llvm/llvm-project/pull/196737

Previously the AMDGPU toolchains hackily handled -fsanitize arguments.
They would lie and report that all host side sanitizers are available,
then TranslateArgs would filter out the device side cases that do not
work, providing diagnostics for the skipped cases. Move that logic
into the base sanitizer argument parsing.

This makes the produced diagnostics more consistent. Previously we
would get repeated warnings when a sanitizer is fully unsupported
by amdgpu, which should now be once for the toolchain. These could
be further improved; we're printing the specific field of -fsanitize
in more cases where it could be skipped. In other cases we have the
opposite problem, where we aren't reporting the exact sanitizer
from the -f flag in the case that depends on a subtarget feature.

This will help fix other broken target specific flag forwarding bugs
in the future.

Co-authored-by: Claude Sonnet 4 

>From ed5b3ed6ce4ca65aa32286d36dd6a6582e0d1b53 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Thu, 7 May 2026 20:57:02 +0100
Subject: [PATCH] clang: Refactor handling of offload sanitizer arguments

Previously the AMDGPU toolchains hackily handled -fsanitize arguments.
They would lie and report that all host side sanitizers are available,
then TranslateArgs would filter out the device side cases that do not
work, providing diagnostics for the skipped cases. Move that logic
into the base sanitizer argument parsing.

This makes the produced diagnostics more consistent. Previously we
would get repeated warnings when a sanitizer is fully unsupported
by amdgpu, which should now be once for the toolchain. These could
be further improved; we're printing the specific field of -fsanitize
in more cases where it could be skipped. In other cases we have the
opposite problem, where we aren't reporting the exact sanitizer
from the -f flag in the case that depends on a subtarget feature.

This will help fix other broken target specific flag forwarding bugs
in the future.

Co-authored-by: Claude Sonnet 4 
---
 clang/include/clang/Driver/SanitizerArgs.h|   5 +-
 clang/include/clang/Driver/ToolChain.h|  19 +++-
 clang/lib/Driver/SanitizerArgs.cpp|  94 ++--
 clang/lib/Driver/ToolChain.cpp|  11 +-
 clang/lib/Driver/ToolChains/AMDGPU.cpp| 101 ++
 clang/lib/Driver/ToolChains/AMDGPU.h  |  82 ++
 clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp  |  38 +++
 clang/lib/Driver/ToolChains/AMDGPUOpenMP.h|   5 +-
 clang/lib/Driver/ToolChains/Clang.cpp |   4 +-
 clang/lib/Driver/ToolChains/HIPAMD.cpp|  45 
 clang/lib/Driver/ToolChains/HIPAMD.h  |   5 +-
 .../Driver/amdgpu-openmp-sanitize-options.c   |   4 +-
 clang/test/Driver/amdgpu-validate-sanitize.cl |  23 
 clang/test/Driver/hip-sanitize-options.hip|  28 ++---
 14 files changed, 259 insertions(+), 205 deletions(-)
 create mode 100644 clang/test/Driver/amdgpu-validate-sanitize.cl

diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index ed2eb6852b124..d4ee17802fd8e 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -9,6 +9,7 @@
 #define LLVM_CLANG_DRIVER_SANITIZERARGS_H
 
 #include "clang/Basic/Sanitizers.h"
+#include "clang/Driver/Action.h"
 #include "clang/Driver/Types.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -85,7 +86,9 @@ class SanitizerArgs {
 public:
   /// Parses the sanitizer arguments from an argument list.
   SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
-bool DiagnoseErrors = true);
+bool DiagnoseErrors = true, bool DiagnoseBoundArchErrors = 
true,
+StringRef BoundArch = "",
+Action::OffloadKind DeviceOffloadKind = Action::OFK_None);
 
   bool needsSharedRt() const { return SharedRuntime; }
   bool needsStableAbi() const { return StableABI; }
diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 8676318d6f9d4..cbdec7843876c 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -18,6 +18,7 @@
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FloatingPointMode.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Frontend/Debug/Options.h"
@@ -185,8 +186,13 @@ class ToolChain {
   Tool *getOffloadPackager() const;
   Tool *getLinkerWrapper() const;
 
+  /// Track if diagnostics have been emitted for sanitizer arguments already to
+  /// avoid duplicate diagnostics.
   mutable bool SanitizerArgsChecked = false;
 
+  /// Set of BoundArch values which have already had diagnostics emitted.
+  mutable llvm::SmallSet BoundArchSanitizerArgsChecked;
+
   /// Th