Skip to content

[sanitizer] Fix empty string in unsupported argument error for -fsanitize-trap #136549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ArtSin
Copy link
Contributor

@ArtSin ArtSin commented Apr 21, 2025

When using -fsanitize-trap with a sanitizer group that doesn't support trapping, an empty argument is passed to err_drv_unsupported_option_argument. Expand groups for the diagnostic.

…tize-trap

When using `-fsanitize-trap` with a sanitizer group that doesn't support
trapping, an empty argument is passed to `err_drv_unsupported_option_argument`.
Expand groups for the diagnostic.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Apr 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 21, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Sinkevich Artem (ArtSin)

Changes

When using -fsanitize-trap with a sanitizer group that doesn't support trapping, an empty argument is passed to err_drv_unsupported_option_argument. Expand groups for the diagnostic.


Full diff: https://github.com/llvm/llvm-project/pull/136549.diff

2 Files Affected:

  • (modified) clang/lib/Driver/SanitizerArgs.cpp (+2-2)
  • (modified) clang/test/Driver/fsanitize.c (+3)
diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp
index f27cb813012f2..05ca2656c6522 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -286,7 +286,7 @@ parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList &Args,
               Add & AlwaysOut & ~DiagnosedAlwaysOutViolations) {
         if (DiagnoseErrors) {
           SanitizerSet SetToDiagnose;
-          SetToDiagnose.Mask |= KindsToDiagnose;
+          SetToDiagnose.Mask |= expandSanitizerGroups(KindsToDiagnose);
           D.Diag(diag::err_drv_unsupported_option_argument)
               << Arg->getSpelling() << toString(SetToDiagnose);
           DiagnosedAlwaysOutViolations |= KindsToDiagnose;
@@ -302,7 +302,7 @@ parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList &Args,
               Remove & AlwaysIn & ~DiagnosedAlwaysInViolations) {
         if (DiagnoseErrors) {
           SanitizerSet SetToDiagnose;
-          SetToDiagnose.Mask |= KindsToDiagnose;
+          SetToDiagnose.Mask |= expandSanitizerGroups(KindsToDiagnose);
           D.Diag(diag::err_drv_unsupported_option_argument)
               << Arg->getSpelling() << toString(SetToDiagnose);
           DiagnosedAlwaysInViolations |= KindsToDiagnose;
diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index c154e339941f2..434e6fd8c4a15 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -259,6 +259,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-stack,memtag-heap,memtag-globals' 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

@ArtSin
Copy link
Contributor Author

ArtSin commented Apr 21, 2025

PTAL @vitalybuka

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants