Index: clang/lib/CodeGen/CodeGenFunction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenFunction.cpp +++ clang/lib/CodeGen/CodeGenFunction.cpp @@ -846,8 +846,12 @@ if (D) { // Apply the no_sanitize* attributes to SanOpts. - for (auto Attr : D->specific_attrs()) - SanOpts.Mask &= ~Attr->getMask(); + for (auto Attr : D->specific_attrs()) { + SanitizerMask mask = Attr->getMask(); + SanOpts.Mask &= ~mask; + if (mask & SanitizerKind::Address) + SanOpts.set(SanitizerKind::KernelAddress, false); + } } // Apply sanitizer attributes to the function. Index: clang/test/CodeGen/address-safety-attr-kasan-hwasan.cpp =================================================================== --- clang/test/CodeGen/address-safety-attr-kasan-hwasan.cpp +++ clang/test/CodeGen/address-safety-attr-kasan-hwasan.cpp @@ -1,5 +1,5 @@ // Make sure the sanitize_address attribute is emitted when using both ASan and KASan. -// Also document that __attribute__((no_sanitize_address)) doesn't disable KASan instrumentation. +// Also document that __attribute__((no_sanitize_address)) disables KASan instrumentation. /// RUN: %clang_cc1 -triple i386-unknown-linux -disable-O0-optnone -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-NOASAN %s /// RUN: %clang_cc1 -triple i386-unknown-linux -fsanitize=address -disable-O0-optnone -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-ASAN %s @@ -20,7 +20,7 @@ } // CHECK-NOASAN: {{Function Attrs: noinline nounwind$}} // CHECK-ASAN: {{Function Attrs: noinline nounwind$}} -// CHECK-KASAN: {{Function Attrs: noinline nounwind sanitize_address$}} +// CHECK-KASAN: {{Function Attrs: noinline nounwind$}} // CHECK-HWASAN: {{Function Attrs: noinline nounwind sanitize_hwaddress$}} __attribute__((no_sanitize_address)) @@ -29,14 +29,13 @@ } // CHECK-NOASAN: {{Function Attrs: noinline nounwind$}} // CHECK-ASAN: {{Function Attrs: noinline nounwind$}} -// CHECK-KASAN: {{Function Attrs: noinline nounwind sanitize_address$}} +// CHECK-KASAN: {{Function Attrs: noinline nounwind$}} // CHECK-HWASAN: {{Function Attrs: noinline nounwind sanitize_hwaddress$}} __attribute__((no_sanitize("kernel-address"))) int NoSanitizeKernelAddress() { return 0; } - // CHECK-NOASAN: {{Function Attrs: noinline nounwind$}} // CHECK-ASAN: {{Function Attrs: noinline nounwind sanitize_address$}} // CHECK-KASAN: {{Function Attrs: noinline nounwind$}} @@ -46,7 +45,6 @@ int NoSanitizeHWAddress() { return 0; } - // CHECK-NOASAN: {{Function Attrs: noinline nounwind$}} // CHECK-ASAN: {{Function Attrs: noinline nounwind sanitize_address$}} // CHECK-KASAN: {{Function Attrs: noinline nounwind sanitize_address$}} Index: clang/test/CodeGen/address-safety-attr-kasan.cpp =================================================================== --- clang/test/CodeGen/address-safety-attr-kasan.cpp +++ clang/test/CodeGen/address-safety-attr-kasan.cpp @@ -1,5 +1,5 @@ // Make sure the sanitize_address attribute is emitted when using both ASan and KASan. -// Also document that __attribute__((no_sanitize_address)) doesn't disable KASan instrumentation. +// Also document that __attribute__((no_sanitize_address)) disables KASan instrumentation. /// RUN: %clang_cc1 -triple i386-unknown-linux -disable-O0-optnone -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-NOASAN %s /// RUN: %clang_cc1 -triple i386-unknown-linux -fsanitize=address -disable-O0-optnone -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-ASAN %s @@ -18,7 +18,7 @@ } // CHECK-NOASAN: {{Function Attrs: noinline nounwind$}} // CHECK-ASAN: {{Function Attrs: noinline nounwind$}} -// CHECK-KASAN: {{Function Attrs: noinline nounwind sanitize_address$}} +// CHECK-KASAN: {{Function Attrs: noinline nounwind$}} __attribute__((no_sanitize_address)) int NoSanitizeAddress() { @@ -26,13 +26,12 @@ } // CHECK-NOASAN: {{Function Attrs: noinline nounwind$}} // CHECK-ASAN: {{Function Attrs: noinline nounwind$}} -// CHECK-KASAN: {{Function Attrs: noinline nounwind sanitize_address$}} +// CHECK-KASAN: {{Function Attrs: noinline nounwind$}} __attribute__((no_sanitize("kernel-address"))) int NoSanitizeKernelAddress() { return 0; } - // CHECK-NOASAN: {{Function Attrs: noinline nounwind$}} // CHECK-ASAN: {{Function Attrs: noinline nounwind sanitize_address$}} // CHECK-KASAN: {{Function Attrs: noinline nounwind$}}