[clang] efd46bc - [sanitizer] Allow use-after-scope front-end argument to take effect with -fsanitize=kernel-address (#137015)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 28 11:54:46 PDT 2025
Author: Douglas
Date: 2025-04-28T11:54:43-07:00
New Revision: efd46bc1efb18180366798134164dc9f87a6c79d
URL: https://github.com/llvm/llvm-project/commit/efd46bc1efb18180366798134164dc9f87a6c79d
DIFF: https://github.com/llvm/llvm-project/commit/efd46bc1efb18180366798134164dc9f87a6c79d.diff
LOG: [sanitizer] Allow use-after-scope front-end argument to take effect with -fsanitize=kernel-address (#137015)
Allow `-f[no]-sanitize-address-use-after-scope` to take effect under
kernel-address sanitizer (`-fsanitize=kernel-address`). `use-after-scope` is
now enabled by default under kernel-address sanitizer.
Previously, users may have enabled `use-after-scope` checks for kernel-address
sanitizer via `-mllvm -asan-use-after-scope=true`. While this may have worked
for optimization levels > O0, the required lifetime intrinsics to allow for
`use-after-scope` detection were not emitted under O0. This commit ensures
the required lifetime intrinsics are emitted under O0 with kernel-address
sanitizer.
Added:
Modified:
clang/lib/Driver/SanitizerArgs.cpp
clang/test/CodeGen/lifetime-sanitizer.c
clang/test/CodeGenCXX/lifetime-sanitizer.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp
index 2edb200688418..ff08bffdbde1f 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -1028,10 +1028,6 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
StableABI = Args.hasFlag(options::OPT_fsanitize_stable_abi,
options::OPT_fno_sanitize_stable_abi, false);
- AsanUseAfterScope = Args.hasFlag(
- options::OPT_fsanitize_address_use_after_scope,
- options::OPT_fno_sanitize_address_use_after_scope, AsanUseAfterScope);
-
AsanPoisonCustomArrayCookie = Args.hasFlag(
options::OPT_fsanitize_address_poison_custom_array_cookie,
options::OPT_fno_sanitize_address_poison_custom_array_cookie,
@@ -1093,7 +1089,6 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
}
} else {
- AsanUseAfterScope = false;
// -fsanitize=pointer-compare/pointer-subtract requires -fsanitize=address.
SanitizerMask DetectInvalidPointerPairs =
SanitizerKind::PointerCompare | SanitizerKind::PointerSubtract;
@@ -1107,6 +1102,14 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
}
}
+ if (AllAddedKinds & (SanitizerKind::Address | SanitizerKind::KernelAddress)) {
+ AsanUseAfterScope = Args.hasFlag(
+ options::OPT_fsanitize_address_use_after_scope,
+ options::OPT_fno_sanitize_address_use_after_scope, AsanUseAfterScope);
+ } else {
+ AsanUseAfterScope = false;
+ }
+
if (AllAddedKinds & SanitizerKind::HWAddress) {
if (Arg *HwasanAbiArg =
Args.getLastArg(options::OPT_fsanitize_hwaddress_abi_EQ)) {
diff --git a/clang/test/CodeGen/lifetime-sanitizer.c b/clang/test/CodeGen/lifetime-sanitizer.c
index b15d692b79e36..68879fda1e1a5 100644
--- a/clang/test/CodeGen/lifetime-sanitizer.c
+++ b/clang/test/CodeGen/lifetime-sanitizer.c
@@ -4,6 +4,9 @@
// RUN: -fsanitize=address -fsanitize-address-use-after-scope \
// RUN: -Xclang -disable-llvm-passes %s | FileCheck %s -check-prefix=LIFETIME
// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
+// RUN: -fsanitize=kernel-address -fsanitize-address-use-after-scope \
+// RUN: -Xclang -disable-llvm-passes %s | FileCheck %s -check-prefix=LIFETIME
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
// RUN: -fsanitize=memory -Xclang -disable-llvm-passes %s | \
// RUN: FileCheck %s -check-prefix=LIFETIME
// RUN: %clang -target aarch64-linux-gnu -S -emit-llvm -o - -O0 \
diff --git a/clang/test/CodeGenCXX/lifetime-sanitizer.cpp b/clang/test/CodeGenCXX/lifetime-sanitizer.cpp
index 33a8566092519..225d5e28921b8 100644
--- a/clang/test/CodeGenCXX/lifetime-sanitizer.cpp
+++ b/clang/test/CodeGenCXX/lifetime-sanitizer.cpp
@@ -5,6 +5,9 @@
// RUN: -fsanitize=address -fsanitize-address-use-after-scope \
// RUN: -Xclang -disable-llvm-passes %s | FileCheck %s -check-prefixes=CHECK,LIFETIME
// RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
+// RUN: -fsanitize=kernel-address -fsanitize-address-use-after-scope \
+// RUN: -Xclang -disable-llvm-passes %s | FileCheck %s -check-prefixes=CHECK,LIFETIME
+// RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
// RUN: -fsanitize=memory -Xclang -disable-llvm-passes %s | \
// RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME
// RUN: %clang -w -target aarch64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
More information about the cfe-commits
mailing list