Author: Qinkun Bao
Date: 2025-06-02T17:47:12-04:00
New Revision: 43c223424957a43a3cb778980b595a1cfd3ae1a6

URL: 
https://github.com/llvm/llvm-project/commit/43c223424957a43a3cb778980b595a1cfd3ae1a6
DIFF: 
https://github.com/llvm/llvm-project/commit/43c223424957a43a3cb778980b595a1cfd3ae1a6.diff

LOG: [Sanitizer][Ignorelist] Expanding =sanitize to global. (#142456)

See https://github.com/llvm/llvm-project/issues/139128
If multiple entries match the source, than the latest entry takes the
precedence.`

Added: 
    clang/test/CodeGen/asan-global-ignorelist.test

Modified: 
    clang/lib/Basic/NoSanitizeList.cpp

Removed: 
    


################################################################################
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
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};


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

Reply via email to