https://github.com/melver updated 
https://github.com/llvm/llvm-project/pull/172030

>From d4f149dbb21fd7f5e706560b1aa3b8f0b9fa5ae9 Mon Sep 17 00:00:00 2001
From: Marco Elver <[email protected]>
Date: Fri, 12 Dec 2025 17:18:15 +0100
Subject: [PATCH 1/2] tweak test

Created using spr 1.3.8-beta.1
---
 clang/test/CodeGen/builtin-allow-sanitize-check-lower.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/CodeGen/builtin-allow-sanitize-check-lower.c 
b/clang/test/CodeGen/builtin-allow-sanitize-check-lower.c
index 05a0295799f55..5e52f77f55573 100644
--- a/clang/test/CodeGen/builtin-allow-sanitize-check-lower.c
+++ b/clang/test/CodeGen/builtin-allow-sanitize-check-lower.c
@@ -9,9 +9,9 @@ _Bool check() {
   return __builtin_allow_sanitize_check("address");
 }
 
-// CHECK-LABEL: @test
+// CHECK-LABEL: @test_sanitize
 // CHECK: ret i1 true
-_Bool test() {
+_Bool test_sanitize() {
   return check();
 }
 

>From f4c6cfded128616e2c8d119e19174bbed1298781 Mon Sep 17 00:00:00 2001
From: Marco Elver <[email protected]>
Date: Wed, 17 Dec 2025 20:47:40 +0100
Subject: [PATCH 2/2] fixes

Created using spr 1.3.8-beta.1
---
 clang/lib/CodeGen/CGBuiltin.cpp               | 37 ++++++++++---------
 .../test/Sema/builtin-allow-sanitize-check.c  |  6 +--
 2 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 98d80620b44a5..9de085379882c 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3551,25 +3551,28 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
   }
   case Builtin::BI__builtin_allow_sanitize_check: {
     Intrinsic::ID IntrID = Intrinsic::not_intrinsic;
-    StringRef SanitizerName =
+    StringRef Name =
         cast<StringLiteral>(E->getArg(0)->IgnoreParenCasts())->getString();
 
-    if (SanitizerName == "address" || SanitizerName == "kernel-address") {
-      if (CGM.getLangOpts().Sanitize.hasOneOf(SanitizerKind::Address |
-                                              SanitizerKind::KernelAddress))
-        IntrID = Intrinsic::allow_sanitize_address;
-    } else if (SanitizerName == "thread") {
-      if (CGM.getLangOpts().Sanitize.has(SanitizerKind::Thread))
-        IntrID = Intrinsic::allow_sanitize_thread;
-    } else if (SanitizerName == "memory" || SanitizerName == "kernel-memory") {
-      if (CGM.getLangOpts().Sanitize.hasOneOf(SanitizerKind::Memory |
-                                              SanitizerKind::KernelMemory))
-        IntrID = Intrinsic::allow_sanitize_memory;
-    } else if (SanitizerName == "hwaddress" ||
-               SanitizerName == "kernel-hwaddress") {
-      if (CGM.getLangOpts().Sanitize.hasOneOf(SanitizerKind::HWAddress |
-                                              SanitizerKind::KernelHWAddress))
-        IntrID = Intrinsic::allow_sanitize_hwaddress;
+    // We deliberately allow the use of kernel- and non-kernel names
+    // interchangably, even when one or the other is enabled. This is 
consistent
+    // with the no_sanitize-attribute, which allows either kernel- or 
non-kernel
+    // name to disable instrumentation (see CodeGenFunction::StartFunction).
+    if (getLangOpts().Sanitize.hasOneOf(SanitizerKind::Address |
+                                        SanitizerKind::KernelAddress) &&
+        (Name == "address" || Name == "kernel-address")) {
+      IntrID = Intrinsic::allow_sanitize_address;
+    } else if (getLangOpts().Sanitize.has(SanitizerKind::Thread) &&
+               Name == "thread") {
+      IntrID = Intrinsic::allow_sanitize_thread;
+    } else if (getLangOpts().Sanitize.hasOneOf(SanitizerKind::Memory |
+                                               SanitizerKind::KernelMemory) &&
+               (Name == "memory" || Name == "kernel-memory")) {
+      IntrID = Intrinsic::allow_sanitize_memory;
+    } else if (getLangOpts().Sanitize.hasOneOf(
+                   SanitizerKind::HWAddress | SanitizerKind::KernelHWAddress) 
&&
+               (Name == "hwaddress" || Name == "kernel-hwaddress")) {
+      IntrID = Intrinsic::allow_sanitize_hwaddress;
     }
 
     if (IntrID != Intrinsic::not_intrinsic) {
diff --git a/clang/test/Sema/builtin-allow-sanitize-check.c 
b/clang/test/Sema/builtin-allow-sanitize-check.c
index 94deb16dd89f9..6e0e21a869461 100644
--- a/clang/test/Sema/builtin-allow-sanitize-check.c
+++ b/clang/test/Sema/builtin-allow-sanitize-check.c
@@ -1,15 +1,15 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
 void test_builtin_allow_sanitize_check() {
-  // Test with non-string literal argument
+  // Test with non-string literal argument.
   char str[] = "address";
   (void)__builtin_allow_sanitize_check(str); // expected-error {{expression is 
not a string literal}}
   (void)__builtin_allow_sanitize_check(123); // expected-error {{expression is 
not a string literal}}
 
-  // Test with unsupported sanitizer name
+  // Test with unsupported sanitizer name.
   (void)__builtin_allow_sanitize_check("unsupported"); // expected-error 
{{invalid argument 'unsupported' to __builtin_allow_sanitize_check}}
 
-  // Test with supported sanitizer names
+  // Test with supported sanitizer names.
   (void)__builtin_allow_sanitize_check("address");
   (void)__builtin_allow_sanitize_check("thread");
   (void)__builtin_allow_sanitize_check("memory");

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to