Skip to content

Commit 24684bb

Browse files
authored
[sanitizer] Delay sanitizer args parsing (#107280)
Delay sanitizer arg parsing until after -Xclang flags are forwarded to the clang command line. This allows the check in hasTargetFeatureMTE to pick up manually specified target feature, and enables the following: -march=armv8-a -Xclang -target-feature -Xclang +mte -fsanitize=memtag-stack
1 parent 247d3ea commit 24684bb

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6786,8 +6786,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
67866786
CmdArgs.push_back("--offload-new-driver");
67876787
}
67886788

6789-
SanitizeArgs.addArgs(TC, Args, CmdArgs, InputType);
6790-
67916789
const XRayArgs &XRay = TC.getXRayArgs();
67926790
XRay.addArgs(TC, Args, CmdArgs, InputType);
67936791

@@ -7677,6 +7675,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
76777675
}
76787676
}
76797677

7678+
// This needs to run after -Xclang argument forwarding to pick up the target
7679+
// features enabled through -Xclang -target-feature flags.
7680+
SanitizeArgs.addArgs(TC, Args, CmdArgs, InputType);
7681+
76807682
// With -save-temps, we want to save the unoptimized bitcode output from the
76817683
// CompileJobAction, use -disable-llvm-passes to get pristine IR generated
76827684
// by the frontend.

clang/test/Driver/fsanitize.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@
197197
// CHECK-SANMT-MT: "-target-feature" "+mte"
198198
// CHECK-SANMT-MT-SAME: "-fsanitize=memtag-stack,memtag-heap,memtag-globals"
199199

200+
// RUN: not %clang --target=aarch64-linux -fsanitize=memtag -Xclang -target-feature -Xclang +mte %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANMT-MT
201+
200202
// RUN: not %clang --target=aarch64-linux -fsanitize=memtag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANMT-NOMT-0
201203
// CHECK-SANMT-NOMT-0: '-fsanitize=memtag-stack' requires hardware support (+memtag)
202204

@@ -726,8 +728,8 @@
726728
// NO-SP-NOT: stack-protector
727729
// NO-SP: "-fsanitize=safe-stack"
728730
// SP-ASAN: error: invalid argument '-fsanitize=safe-stack' not allowed with '-fsanitize=address'
729-
// SP: "-fsanitize=safe-stack"
730731
// SP: -stack-protector
732+
// SP: "-fsanitize=safe-stack"
731733
// NO-SP-NOT: stack-protector
732734

733735
// RUN: %clang --target=powerpc64-unknown-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SANM

clang/test/Driver/fuchsia.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
// CHECK: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
3131
// CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
3232
// CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|\\\\}}include"
33+
// CHECK: "-stack-protector" "2"
3334
// CHECK-AARCH64: "-fsanitize=shadow-call-stack"
3435
// CHECK-RISCV64: "-fsanitize=shadow-call-stack"
3536
// CHECK-X86_64: "-fsanitize=safe-stack"
36-
// CHECK: "-stack-protector" "2"
3737
// CHECK-AARCH64: "-target-feature" "+outline-atomics"
3838
// CHECK-NOT: "-fcommon"
3939
// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "start-stop-visibility=hidden" "-z" "rodynamic" "-z" "separate-loadable-segments" "-z" "rel" "--pack-dyn-relocs=relr"

0 commit comments

Comments
 (0)