Skip to content

Commit 4a87761

Browse files
committed
Add 'diagnoseUnsupportedSanitizers' function.
Refactor logic of processing unsupported sanitizers per language toolchain to a common 'diagnoseUnsupportedSanitizers' function.
1 parent 0a976f4 commit 4a87761

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,12 +1106,8 @@ bool AMDGPUToolChain::shouldSkipSanitizeOption(
11061106

11071107
// For simplicity, we only allow -fsanitize=address
11081108
SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
1109-
if (K != SanitizerKind::Address) {
1110-
// Diagnose unsupported sanitizer options only once.
1111-
Diags.Report(clang::diag::warn_drv_unsupported_option_for_target)
1112-
<< A->getAsString(DriverArgs) << getTriple().str();
1109+
if (K != SanitizerKind::Address)
11131110
return true;
1114-
}
11151111

11161112
llvm::StringMap<bool> FeatureMap;
11171113
auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);

clang/lib/Driver/ToolChains/AMDGPU.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,24 @@ class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain {
146146
getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
147147
const std::string &GPUArch,
148148
bool isOpenMP = false) const;
149+
149150
SanitizerMask getSupportedSanitizers() const override {
150151
return SanitizerKind::Address;
151152
}
153+
154+
void diagnoseUnsupportedSanitizers(const llvm::opt::ArgList &Args) const {
155+
if (!Args.hasFlag(options::OPT_fgpu_sanitize, options::OPT_fno_gpu_sanitize,
156+
true))
157+
return;
158+
auto &Diags = getDriver().getDiags();
159+
for (auto *A : Args.filtered(options::OPT_fsanitize_EQ)) {
160+
SanitizerMask K =
161+
parseSanitizerValue(A->getValue(), /*Allow Groups*/ false);
162+
if (K != SanitizerKind::Address)
163+
Diags.Report(clang::diag::warn_drv_unsupported_option_for_target)
164+
<< A->getAsString(Args) << getTriple().str();
165+
}
166+
}
152167
};
153168

154169
} // end namespace toolchains

clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ AMDGPUOpenMPToolChain::AMDGPUOpenMPToolChain(const Driver &D,
3737
// Lookup binaries into the driver directory, this is used to
3838
// discover the 'amdgpu-arch' executable.
3939
getProgramPaths().push_back(getDriver().Dir);
40+
// Diagnose unsupported sanitizer options only once.
41+
diagnoseUnsupportedSanitizers(Args);
4042
}
4143

4244
void AMDGPUOpenMPToolChain::addClangTargetOptions(

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ HIPAMDToolChain::HIPAMDToolChain(const Driver &D, const llvm::Triple &Triple,
216216
// Lookup binaries into the driver directory, this is used to
217217
// discover the clang-offload-bundler executable.
218218
getProgramPaths().push_back(getDriver().Dir);
219+
// Diagnose unsupported sanitizer options only once.
220+
diagnoseUnsupportedSanitizers(Args);
219221
}
220222

221223
void HIPAMDToolChain::addClangTargetOptions(

0 commit comments

Comments
 (0)