diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp index f27cb813012f2..098fe1f5c8248 100644 --- a/clang/lib/Driver/SanitizerArgs.cpp +++ b/clang/lib/Driver/SanitizerArgs.cpp @@ -1034,10 +1034,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, @@ -1099,7 +1095,6 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, } } else { - AsanUseAfterScope = false; // -fsanitize=pointer-compare/pointer-subtract requires -fsanitize=address. SanitizerMask DetectInvalidPointerPairs = SanitizerKind::PointerCompare | SanitizerKind::PointerSubtract; @@ -1113,6 +1108,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 \