Skip to content

Commit 94c933e

Browse files
committed
[Clang] Improve error for -fsanitize=function/kcfi -mexecute-only incompatibility
The current error message when using the `-fsanitize=function -mexecute-only` flags together points to the target triple as the reason that `-fsanitize=function` is not allowed to be used, even when the function sanitizer is otherwise supported on the target when not using `-mexecute-only`. The error message is improved to give `-mexecute-only` as the reason for disallowing `-fsanitize=function` if it was passed to the driver.
1 parent ffb1c21 commit 94c933e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,14 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
418418
Add & NotAllowedWithExecuteOnly & ~DiagnosedKinds) {
419419
if (DiagnoseErrors) {
420420
std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
421-
D.Diag(diag::err_drv_argument_not_allowed_with)
422-
<< Desc << Triple.str();
421+
llvm::opt::Arg *A = Args.getLastArgNoClaim(
422+
options::OPT_mexecute_only, options::OPT_mno_execute_only);
423+
if (A && A->getOption().matches(options::OPT_mexecute_only))
424+
D.Diag(diag::err_drv_argument_not_allowed_with)
425+
<< Desc << A->getAsString(Args);
426+
else
427+
D.Diag(diag::err_drv_argument_not_allowed_with)
428+
<< Desc << Triple.str();
423429
}
424430
DiagnosedKinds |= KindsToDiagnose;
425431
}

clang/test/Driver/fsanitize.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,8 +1000,8 @@
10001000
// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI
10011001
// RUN: %clang --target=armv6t2-eabi -mexecute-only -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED-VPTR
10021002

1003-
// CHECK-UBSAN-KCFI-DAG: error: invalid argument '-fsanitize=kcfi' not allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}}
1004-
// CHECK-UBSAN-FUNCTION-DAG: error: invalid argument '-fsanitize=function' not allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}}
1003+
// CHECK-UBSAN-KCFI-DAG: error: invalid argument '-fsanitize=kcfi' not allowed with {{('x86_64-sie-ps5'|'-mexecute-only')}}
1004+
// CHECK-UBSAN-FUNCTION-DAG: error: invalid argument '-fsanitize=function' not allowed with {{('x86_64-sie-ps5'|'-mexecute-only')}}
10051005
// CHECK-UBSAN-UNDEFINED-VPTR: "-fsanitize={{((alignment|array-bounds|bool|builtin|enum|float-cast-overflow|integer-divide-by-zero|nonnull-attribute|null|pointer-overflow|return|returns-nonnull-attribute|shift-base|shift-exponent|signed-integer-overflow|unreachable|vla-bound|vptr),?){18}"}}
10061006

10071007
// * Test BareMetal toolchain sanitizer support *

0 commit comments

Comments
 (0)