https://github.com/qinkunbao updated 
https://github.com/llvm/llvm-project/pull/142472

>From dd04cac8d0e4db4d6a073f142bfcefa5f2671785 Mon Sep 17 00:00:00 2001
From: Qinkun Bao <qin...@google.com>
Date: Mon, 2 Jun 2025 20:03:07 +0000
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20change?=
 =?UTF-8?q?s=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.6

[skip ci]
---
 clang/lib/Basic/NoSanitizeList.cpp            |  4 +-
 .../test/CodeGen/asan-global-ignorelist.test  | 37 +++++++++
 .../CodeGen/ubsan-function-ignorelist.test    | 83 +++++++++++++++++++
 3 files changed, 122 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/asan-global-ignorelist.test
 create mode 100644 clang/test/CodeGen/ubsan-function-ignorelist.test

diff --git a/clang/lib/Basic/NoSanitizeList.cpp 
b/clang/lib/Basic/NoSanitizeList.cpp
index a1ca31ea0e970..24d2276f50ddf 100644
--- a/clang/lib/Basic/NoSanitizeList.cpp
+++ b/clang/lib/Basic/NoSanitizeList.cpp
@@ -44,7 +44,7 @@ bool NoSanitizeList::containsPrefix(SanitizerMask Mask, 
StringRef Prefix,
 
 bool NoSanitizeList::containsGlobal(SanitizerMask Mask, StringRef GlobalName,
                                     StringRef Category) const {
-  return SSCL->inSection(Mask, "global", GlobalName, Category);
+  return containsPrefix(Mask, "global", GlobalName, Category);
 }
 
 bool NoSanitizeList::containsType(SanitizerMask Mask, StringRef 
MangledTypeName,
@@ -54,7 +54,7 @@ bool NoSanitizeList::containsType(SanitizerMask Mask, 
StringRef MangledTypeName,
 
 bool NoSanitizeList::containsFunction(SanitizerMask Mask,
                                       StringRef FunctionName) const {
-  return SSCL->inSection(Mask, "fun", FunctionName);
+  return containsPrefix(Mask, "fun", FunctionName, {});
 }
 
 bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName,
diff --git a/clang/test/CodeGen/asan-global-ignorelist.test 
b/clang/test/CodeGen/asan-global-ignorelist.test
new file mode 100644
index 0000000000000..2bb37c100c067
--- /dev/null
+++ b/clang/test/CodeGen/asan-global-ignorelist.test
@@ -0,0 +1,37 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -S -emit-llvm 
-fsanitize=address %t/test.c -o - | FileCheck %s --check-prefixes=SANITIZE
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -S -emit-llvm 
-fsanitize=address -fsanitize-ignorelist=%t/order-0.ignorelist %t/test.c -o - | 
FileCheck %s --check-prefixes=IGNORE
+// RUN: %clang -target x86_64-unknown-linux-gnu -S -emit-llvm 
-fsanitize=address -fsanitize-ignorelist=%t/order-1.ignorelist %t/test.c -o - | 
FileCheck %s --check-prefixes=SANITIZE
+// RUN: %clang -target x86_64-unknown-linux-gnu -S -emit-llvm 
-fsanitize=address -fsanitize-ignorelist=%t/order-2.ignorelist %t/test.c -o - | 
FileCheck %s --check-prefixes=IGNORE
+// RUN: %clang -target x86_64-unknown-linux-gnu -S -emit-llvm 
-fsanitize=address -fsanitize-ignorelist=%t/order-3.ignorelist %t/test.c -o - | 
FileCheck %s --check-prefixes=SANITIZE
+
+// The same type can appear multiple times within an ignorelist. Any 
``=sanitize`` type
+// entries enable sanitizer instrumentation, even if it was ignored by entries 
before.
+// If multiple entries match the source, then the latest entry takes the
+// precedence.
+
+//--- order-0.ignorelist
+global:global_array
+
+//--- order-1.ignorelist
+global:global_array
+global:global_array=sanitize
+
+//--- order-2.ignorelist
+global:*
+global:global_array=sanitize
+global:global_array
+
+//--- order-3.ignorelist
+global:*
+global:global_array=sanitize
+global:global*
+global:*array=sanitize
+
+//--- test.c
+// SANITIZE: @global_array ={{.*}} global {{.*}}, comdat, align {{.*}} 
+// IGNORE: @global_array ={{.*}} global {{.*}}, no_sanitize_address, align 
{{.*}}
+unsigned global_array[100] = {-1};
diff --git a/clang/test/CodeGen/ubsan-function-ignorelist.test 
b/clang/test/CodeGen/ubsan-function-ignorelist.test
new file mode 100644
index 0000000000000..311b2ffd7f737
--- /dev/null
+++ b/clang/test/CodeGen/ubsan-function-ignorelist.test
@@ -0,0 +1,83 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -triple x86_64-linux-gnu 
-fsanitize=signed-integer-overflow,unsigned-integer-overflow 
-fsanitize-ignorelist=%t/order-0.ignorelist -emit-llvm %t/test.c -o - | 
FileCheck %s --check-prefixes=CHECK,SANITIZE
+// RUN: %clang_cc1 -triple x86_64-linux-gnu 
-fsanitize=signed-integer-overflow,unsigned-integer-overflow 
-fsanitize-ignorelist=%t/order-1.ignorelist -emit-llvm %t/test.c -o - | 
FileCheck %s --check-prefixes=CHECK,IGNORE
+// RUN: %clang_cc1 -triple x86_64-linux-gnu 
-fsanitize=signed-integer-overflow,unsigned-integer-overflow 
-fsanitize-ignorelist=%t/order-2.ignorelist -emit-llvm %t/test.c -o - | 
FileCheck %s --check-prefixes=CHECK,SANITIZE
+// RUN: %clang_cc1 -triple x86_64-linux-gnu 
-fsanitize=signed-integer-overflow,unsigned-integer-overflow 
-fsanitize-ignorelist=%t/order-3.ignorelist -emit-llvm %t/test.c -o - | 
FileCheck %s --check-prefixes=CHECK,IGNORE
+// RUN: %clang_cc1 -triple x86_64-linux-gnu 
-fsanitize=signed-integer-overflow,unsigned-integer-overflow 
-fsanitize-ignorelist=%t/order-4.ignorelist -emit-llvm %t/test.c -o - | 
FileCheck %s --check-prefixes=CHECK,SANITIZE
+// RUN: %clang_cc1 -triple x86_64-linux-gnu 
-fsanitize=signed-integer-overflow,unsigned-integer-overflow 
-fsanitize-ignorelist=%t/order-5.ignorelist -emit-llvm %t/test.c -o - | 
FileCheck %s --check-prefixes=CHECK,IGNORE
+// RUN: %clang_cc1 -triple x86_64-linux-gnu 
-fsanitize=signed-integer-overflow,unsigned-integer-overflow 
-fsanitize-ignorelist=%t/order-6.ignorelist -emit-llvm %t/test.c -o - | 
FileCheck %s --check-prefixes=CHECK,SANITIZE
+// RUN: %clang_cc1 -triple x86_64-linux-gnu 
-fsanitize=signed-integer-overflow,unsigned-integer-overflow 
-fsanitize-ignorelist=%t/order-7.ignorelist -emit-llvm %t/test.c -o - | 
FileCheck %s --check-prefixes=CHECK,IGNORE
+// RUN: %clang_cc1 -triple x86_64-linux-gnu 
-fsanitize=signed-integer-overflow,unsigned-integer-overflow 
-fsanitize-ignorelist=%t/order-8.ignorelist -emit-llvm %t/test.c -o - | 
FileCheck %s --check-prefixes=CHECK,SANITIZE
+
+
+// The same type can appear multiple times within an ignorelist. Any 
``=sanitize`` type
+// entries enable sanitizer instrumentation, even if it was ignored by entries 
before.
+// If multiple entries match the source, then the latest entry takes the
+// precedence.
+
+
+//--- order-0.ignorelist
+fun:add
+fun:add=sanitize
+
+//--- order-1.ignorelist
+fun:add=sanitize
+fun:add
+
+//--- order-2.ignorelist
+fun:ad*
+fun:add=sanitize
+
+//--- order-3.ignorelist
+fun:ad*=sanitize
+fun:add
+
+//--- order-4.ignorelist
+fun:add
+fun:ad*=sanitize
+
+//--- order-5.ignorelist
+fun:add=sanitize
+fun:ad*
+
+//--- order-6.ignorelist
+fun:add
+fun:add=sanitize
+fun:a*d
+fun:*dd=sanitize
+
+//--- order-7.ignorelist
+[{unsigned-integer-overflow,signed-integer-overflow}]
+fun:*
+fun:add=sanitize
+fun:a*d
+fun:*dd=sanitize
+[{unsigned-integer-overflow,signed-integer-overflow}]
+fun:*
+fun:add
+fun:a*d=sanitize
+fun:*d
+
+//--- order-8.ignorelist
+[{unsigned-integer-overflow,signed-integer-overflow}]
+fun:*
+fun:add
+fun:a*d=sanitize
+fun:*dd
+[{unsigned-integer-overflow,signed-integer-overflow}]
+fun:*
+fun:add=sanitize
+fun:a*d
+fun:*dd=sanitize
+
+
+//--- test.c
+// CHECK-LABEL: define dso_local void @add
+void add(int A) {
+// IGNORE: %inc = add nsw
+// SANITIZE: @llvm.sadd.with.overflow.i32
+  ++A;
+}
+

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to