-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[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
base: main
Are you sure you want to change the base?
[UBSan][Ignorelist] Expanding =sanitize to fun. #142074
Conversation
Created using spr 1.3.6 [skip ci]
Created using spr 1.3.6
@llvm/pr-subscribers-clang Author: Qinkun Bao (qinkunbao) ChangesSee #139128 Full diff: https://github.com/llvm/llvm-project/pull/142074.diff 2 Files Affected:
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;
+}
+
|
There was a problem hiding this 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>
There was a problem hiding this 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
…g-sanitize-to-fun
Created using spr 1.3.6
See #139128
If multiple entries match the source, than the latest entry takes the precedence.