[clang] 1acac5c - [sanitizer] Fix empty string in unsupported argument error for -fsanitize-trap (#136549)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 15 11:12:46 PDT 2025
Author: Sinkevich Artem
Date: 2025-05-15T11:12:42-07:00
New Revision: 1acac5cd38210131c543e4635fcbfd4d597e15f5
URL: https://github.com/llvm/llvm-project/commit/1acac5cd38210131c543e4635fcbfd4d597e15f5
DIFF: https://github.com/llvm/llvm-project/commit/1acac5cd38210131c543e4635fcbfd4d597e15f5.diff
LOG: [sanitizer] Fix empty string in unsupported argument error for -fsanitize-trap (#136549)
When using `-fsanitize-trap` with a sanitizer group that doesn't support
trapping, an empty argument is passed to
`err_drv_unsupported_option_argument`. Use new `toStringWithGroups` for
the diagnostic.
Added:
Modified:
clang/lib/Driver/SanitizerArgs.cpp
clang/test/Driver/fsanitize.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp
index 85c4a754f93c5..eb4718909c951 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -160,6 +160,10 @@ static std::string describeSanitizeArg(const llvm::opt::Arg *A,
/// Sanitizers set.
static std::string toString(const clang::SanitizerSet &Sanitizers);
+/// Produce a string containing comma-separated names of sanitizers and
+/// sanitizer groups in \p Sanitizers set.
+static std::string toStringWithGroups(const clang::SanitizerSet &Sanitizers);
+
/// Return true if an execute-only target disallows data access to code
/// sections.
static bool isExecuteOnlyTarget(const llvm::Triple &Triple,
@@ -289,7 +293,7 @@ parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList &Args,
SanitizerSet SetToDiagnose;
SetToDiagnose.Mask |= KindsToDiagnose;
D.Diag(diag::err_drv_unsupported_option_argument)
- << Arg->getSpelling() << toString(SetToDiagnose);
+ << Arg->getSpelling() << toStringWithGroups(SetToDiagnose);
DiagnosedAlwaysOutViolations |= KindsToDiagnose;
}
}
@@ -305,7 +309,7 @@ parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList &Args,
SanitizerSet SetToDiagnose;
SetToDiagnose.Mask |= KindsToDiagnose;
D.Diag(diag::err_drv_unsupported_option_argument)
- << Arg->getSpelling() << toString(SetToDiagnose);
+ << Arg->getSpelling() << toStringWithGroups(SetToDiagnose);
DiagnosedAlwaysInViolations |= KindsToDiagnose;
}
}
@@ -1200,6 +1204,19 @@ static std::string toString(const clang::SanitizerMaskCutoffs &Cutoffs) {
return llvm::join(Res, ",");
}
+static std::string toStringWithGroups(const clang::SanitizerSet &Sanitizers) {
+ std::string Res;
+#define SANITIZER(NAME, ID) \
+ if (Sanitizers.has(SanitizerKind::ID)) { \
+ if (!Res.empty()) \
+ Res += ","; \
+ Res += NAME; \
+ }
+#define SANITIZER_GROUP(NAME, ID, ALIAS) SANITIZER(NAME, ID##Group)
+#include "clang/Basic/Sanitizers.def"
+ return Res;
+}
+
static void addSpecialCaseListOpt(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs,
const char *SCLOptFlag,
diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index 24d64c94c0956..1f696aba8d088 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -317,6 +317,9 @@
// RUN: not %clang --target=aarch64-linux -fsanitize=memtag -I +mte %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANMT-NOMT-1
// CHECK-SANMT-NOMT-1: '-fsanitize=memtag-stack' requires hardware support (+memtag)
+// RUN: not %clang --target=aarch64-linux-android31 -fsanitize-trap=memtag -march=armv8-a+memtag -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANMT-TRAP
+// CHECK-SANMT-TRAP: error: unsupported argument 'memtag' to option '-fsanitize-trap='
+
// RUN: %clang --target=x86_64-linux-gnu -fsanitize=address -fsanitize-address-use-after-scope %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-SCOPE
// RUN: %clang_cl --target=x86_64-windows -fsanitize=address -fsanitize-address-use-after-scope -### -- %s 2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-SCOPE
// CHECK-USE-AFTER-SCOPE: -cc1{{.*}}-fsanitize-address-use-after-scope
More information about the cfe-commits
mailing list