[clang] [Sanitizer][Ignorelist] Expanding =sanitize to global. (PR #142456)
Qinkun Bao via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 2 14:08:54 PDT 2025
https://github.com/qinkunbao updated https://github.com/llvm/llvm-project/pull/142456
>From 31a1f9e6fb1d7ed1c86ce47badf211c7e98cf98f Mon Sep 17 00:00:00 2001
From: Qinkun Bao <qinkun at google.com>
Date: Mon, 2 Jun 2025 18:58:50 +0000
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
=?UTF-8?q?anges=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 | 2 +-
.../CodeGen/ubsan-function-ignorelist.test | 83 +++++++++++++++++++
2 files changed, 84 insertions(+), 1 deletion(-)
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..ba36f78175422 100644
--- a/clang/lib/Basic/NoSanitizeList.cpp
+++ b/clang/lib/Basic/NoSanitizeList.cpp
@@ -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/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;
+}
+
>From c0d1cb94966a24e12525bb5c1d863e43cd13e3c2 Mon Sep 17 00:00:00 2001
From: Qinkun Bao <qinkun at google.com>
Date: Mon, 2 Jun 2025 19:10:16 +0000
Subject: [PATCH 2/3] Change the test.
Created using spr 1.3.6
---
...relist.test => asan-global-ignorelist.test} | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
rename clang/test/CodeGen/{ubsan-global-ignorelist.test => asan-global-ignorelist.test} (60%)
diff --git a/clang/test/CodeGen/ubsan-global-ignorelist.test b/clang/test/CodeGen/asan-global-ignorelist.test
similarity index 60%
rename from clang/test/CodeGen/ubsan-global-ignorelist.test
rename to clang/test/CodeGen/asan-global-ignorelist.test
index 8d7812217f331..3ec2847a8a4e9 100644
--- a/clang/test/CodeGen/ubsan-global-ignorelist.test
+++ b/clang/test/CodeGen/asan-global-ignorelist.test
@@ -1,11 +1,11 @@
// RUN: rm -rf %t
// RUN: split-file %s %t
-// RUN: %clang -target x86_64-unknown-linux-gnu -S -emit-llvm -fsanitize=bounds %t/test.c -o - | FileCheck %s --check-prefixes=CHECK,SANITIZE
-// RUN: %clang -target x86_64-unknown-linux-gnu -S -emit-llvm -fsanitize=bounds -fsanitize-ignorelist=%t/order-0.ignorelist %t/test.c -o - | FileCheck %s --check-prefixes=CHECK,IGNORE
-// RUN: %clang -target x86_64-unknown-linux-gnu -S -emit-llvm -fsanitize=bounds -fsanitize-ignorelist=%t/order-1.ignorelist %t/test.c -o - | FileCheck %s --check-prefixes=CHECK,SANITIZE
-// RUN: %clang -target x86_64-unknown-linux-gnu -S -emit-llvm -fsanitize=bounds -fsanitize-ignorelist=%t/order-2.ignorelist %t/test.c -o - | FileCheck %s --check-prefixes=CHECK,IGNORE
-// RUN: %clang -target x86_64-unknown-linux-gnu -S -emit-llvm -fsanitize=bounds -fsanitize-ignorelist=%t/order-3.ignorelist %t/test.c -o - | FileCheck %s --check-prefixes=CHECK,SANITIZE
+// RUN: %clang -target x86_64-unknown-linux-gnu -S -emit-llvm -fsanitize=address %t/test.c -o - | FileCheck %s --check-prefixes=CHECK,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=CHECK,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=CHECK,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=CHECK,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=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.
@@ -13,18 +13,22 @@
// precedence.
//--- order-0.ignorelist
+[address]
global:global_array
//--- order-1.ignorelist
+[address]
global:global_array
global:global_array=sanitize
//--- order-2.ignorelist
+[address]
global:*
global:global_array=sanitize
global:global_array
//--- order-3.ignorelist
+[address]
global:*
global:global_array=sanitize
global:global*
@@ -34,6 +38,6 @@ global:*array=sanitize
unsigned global_array[100] = {-1};
// CHECK-LABEL: define dso_local i32 @test
-// IGNORE-NOT: call void @__ubsan_handle_out_of_bounds
-// SANITIZE: call void @__ubsan_handle_out_of_bounds
+// IGNORE-NOT: call void @__asan_report_load4
+// SANITIZE: call void @__asan_report_load4
int test(int i) { return global_array[i]; }
>From 0ae18c201b4a78aef9ed3df0528026bf7e6f2a67 Mon Sep 17 00:00:00 2001
From: Qinkun Bao <qinkun at google.com>
Date: Mon, 2 Jun 2025 19:45:30 +0000
Subject: [PATCH 3/3] Add implementation
Created using spr 1.3.6
---
clang/lib/Basic/NoSanitizeList.cpp | 2 +-
.../test/CodeGen/asan-global-ignorelist.test | 22 +++++++------------
2 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/clang/lib/Basic/NoSanitizeList.cpp b/clang/lib/Basic/NoSanitizeList.cpp
index ba36f78175422..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,
diff --git a/clang/test/CodeGen/asan-global-ignorelist.test b/clang/test/CodeGen/asan-global-ignorelist.test
index 3ec2847a8a4e9..2bb37c100c067 100644
--- a/clang/test/CodeGen/asan-global-ignorelist.test
+++ b/clang/test/CodeGen/asan-global-ignorelist.test
@@ -1,11 +1,12 @@
// 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=CHECK,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=CHECK,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=CHECK,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=CHECK,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=CHECK,SANITIZE
+// 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.
@@ -13,31 +14,24 @@
// precedence.
//--- order-0.ignorelist
-[address]
global:global_array
//--- order-1.ignorelist
-[address]
global:global_array
global:global_array=sanitize
//--- order-2.ignorelist
-[address]
global:*
global:global_array=sanitize
global:global_array
//--- order-3.ignorelist
-[address]
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};
-
-// CHECK-LABEL: define dso_local i32 @test
-// IGNORE-NOT: call void @__asan_report_load4
-// SANITIZE: call void @__asan_report_load4
-int test(int i) { return global_array[i]; }
More information about the cfe-commits
mailing list