Skip to content

[UBSan][Ignorelist] Expanding =sanitize to fun. #142074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

qinkunbao
Copy link
Member

@qinkunbao qinkunbao commented May 30, 2025

See #139128
If multiple entries match the source, than the latest entry takes the precedence.

qinkunbao added 2 commits May 30, 2025 01:21
Created using spr 1.3.6
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 30, 2025
@llvmbot
Copy link
Member

llvmbot commented May 30, 2025

@llvm/pr-subscribers-clang

Author: Qinkun Bao (qinkunbao)

Changes

See #139128
If multiple entries match the source, than the latest entry takes the precedence.


Full diff: https://github.com/llvm/llvm-project/pull/142074.diff

2 Files Affected:

  • (modified) clang/lib/Basic/NoSanitizeList.cpp (+1-1)
  • (added) clang/test/CodeGen/ubsan-function-ignorelist.test (+83)
diff --git a/clang/lib/Basic/NoSanitizeList.cpp b/clang/lib/Basic/NoSanitizeList.cpp
index a1ca31ea0e970..240a7f9693e21 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..ce8d37253e2fc
--- /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, than 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 @test
+void add(int A) {
+// IGNORE: %inc = add nsw
+// SANITIZE: @llvm.sadd.with.overflow.i32
+  ++A;
+}
+

@qinkunbao qinkunbao requested a review from Copilot May 30, 2025 01:22
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR expands the functionality of the sanitizer ignorelist to support =sanitize entries for functions, following the behavior described in issue #139128.

  • Updated test cases in ubsan-function-ignorelist.test to verify new precedence rules for matching ignorelist entries.
  • Modified the NoSanitizeList.cpp to use containsPrefix instead of the previous inSection call for function matching.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
clang/test/CodeGen/ubsan-function-ignorelist.test Added comprehensive test cases for multiple ignorelist orders to validate that the latest matching entry takes precedence.
clang/lib/Basic/NoSanitizeList.cpp Replaced inSection with containsPrefix to update the function matching logic in line with the PR's purpose.
Comments suppressed due to low confidence (1)

clang/lib/Basic/NoSanitizeList.cpp:57

  • Ensure that replacing inSection with containsPrefix maintains the intended matching behavior for ignorelist entries, as this change may affect how function name prefixes are interpreted.
return containsPrefix(Mask, "fun", FunctionName);

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@qinkunbao qinkunbao requested a review from Copilot May 30, 2025 01:23
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR expands the functionality of the ignorelist processing for UBSan by allowing entries with "=sanitize" to be applied to functions. It adds new tests in the ubsan-function-ignorelist test file to verify the multiple precedence ordering of ignorelist entries and updates the logic in NoSanitizeList.cpp to use prefix matching for function ignorelist entries.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
clang/test/CodeGen/ubsan-function-ignorelist.test Adds tests with various ignorelist ordering and patterns to validate =sanitize handling for functions.
clang/lib/Basic/NoSanitizeList.cpp Updates the logic to perform prefix matching for function ignorelist entries.
Comments suppressed due to low confidence (1)

clang/lib/Basic/NoSanitizeList.cpp:57

  • Please confirm that containsPrefix fully replicates the ignorelist matching semantics previously provided by inSection, ensuring consistency with the new test cases. Referencing additional tests might help verify that all expected patterns are correctly handled.
return containsPrefix(Mask, "fun", FunctionName);

Created using spr 1.3.6
@qinkunbao qinkunbao changed the base branch from users/qinkunbao/spr/main.ubsanignorelist-expanding-sanitize-to-fun to main May 30, 2025 09:27
@qinkunbao qinkunbao requested a review from vitalybuka May 30, 2025 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants