Skip to content

Commit 3ad28ed

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.6
2 parents 9ca41b6 + 3b8af2c commit 3ad28ed

File tree

4 files changed

+55
-27
lines changed

4 files changed

+55
-27
lines changed

clang/include/clang/Basic/NoSanitizeList.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class SanitizerSpecialCaseList;
2929
class NoSanitizeList {
3030
std::unique_ptr<SanitizerSpecialCaseList> SSCL;
3131
SourceManager &SM;
32-
32+
bool containsPrefix(SanitizerMask Mask,StringRef Prefix, StringRef Name,
33+
StringRef Category = StringRef()) const;
3334
public:
3435
NoSanitizeList(const std::vector<std::string> &NoSanitizeListPaths,
3536
SourceManager &SM);

clang/lib/AST/ASTContext.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,7 @@ ASTContext::insertCanonicalTemplateTemplateParmDeclInternal(
875875
bool ASTContext::isTypeIgnoredBySanitizer(const SanitizerMask &Mask,
876876
const QualType &Ty) const {
877877
std::string TyName = Ty.getUnqualifiedType().getAsString(getPrintingPolicy());
878-
return NoSanitizeL->containsType(Mask, TyName) &&
879-
!NoSanitizeL->containsType(Mask, TyName, "sanitize");
878+
return NoSanitizeL->containsType(Mask, TyName);
880879
}
881880

882881
TargetCXXABI::Kind ASTContext::getCXXABIKind() const {

clang/lib/Basic/NoSanitizeList.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,23 @@ NoSanitizeList::NoSanitizeList(const std::vector<std::string> &NoSanitizePaths,
2727

2828
NoSanitizeList::~NoSanitizeList() = default;
2929

30+
bool NoSanitizeList::containsPrefix(SanitizerMask Mask, StringRef Prefix,
31+
StringRef Name, StringRef Category) const {
32+
auto NoSan = SSCL->inSectionBlame(Mask, Prefix, Name, Category);
33+
if (NoSan == llvm::SpecialCaseList::NotFound)
34+
return false;
35+
auto San = SSCL->inSectionBlame(Mask, Prefix, Name, "sanitize");
36+
return San == llvm::SpecialCaseList::NotFound || NoSan > San;
37+
}
38+
3039
bool NoSanitizeList::containsGlobal(SanitizerMask Mask, StringRef GlobalName,
3140
StringRef Category) const {
3241
return SSCL->inSection(Mask, "global", GlobalName, Category);
3342
}
3443

3544
bool NoSanitizeList::containsType(SanitizerMask Mask, StringRef MangledTypeName,
3645
StringRef Category) const {
37-
return SSCL->inSection(Mask, "type", MangledTypeName, Category);
46+
return containsPrefix(Mask, "type", MangledTypeName, Category);
3847
}
3948

4049
bool NoSanitizeList::containsFunction(SanitizerMask Mask,
@@ -44,11 +53,7 @@ bool NoSanitizeList::containsFunction(SanitizerMask Mask,
4453

4554
bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName,
4655
StringRef Category) const {
47-
auto NoSan = SSCL->inSectionBlame(Mask, "src", FileName, Category);
48-
if (NoSan == llvm::SpecialCaseList::NotFound)
49-
return false;
50-
auto San = SSCL->inSectionBlame(Mask, "src", FileName, "sanitize");
51-
return San == llvm::SpecialCaseList::NotFound || NoSan > San;
56+
return containsPrefix(Mask, "src", FileName, Category);
5257
}
5358

5459
bool NoSanitizeList::containsMainFile(SanitizerMask Mask, StringRef FileName,

clang/test/CodeGen/ubsan-type-ignorelist-category-2.test

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
// RUN: rm -rf %t
22
// RUN: split-file %s %t
33

4-
// 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
5-
// 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
6-
// 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
7-
// 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
8-
// 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
9-
// 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
10-
// 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
11-
// 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
12-
13-
// The same type can appear multiple times within an ignorelist. This is a test
14-
// to make sure "=sanitize" has priority regardless of the order in which
15-
// duplicate type entries appear. This is a precautionary measure; we would
16-
// much rather eagerly sanitize than silently forgo sanitization.
4+
// 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
5+
// 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
6+
// 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
7+
// 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
8+
// 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
9+
// 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
10+
// 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
11+
// 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
12+
// 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
13+
14+
15+
// The same type can appear multiple times within an ignorelist. Any ``=sanitize`` type
16+
// entries enable sanitizer instrumentation, even if it was ignored by entries before.
17+
// If multiple entries match the source, than the latest entry takes the
18+
// precedence.
19+
1720

1821
//--- order-0.ignorelist
1922
type:int
@@ -40,19 +43,39 @@ type:int=sanitize
4043
type:in*
4144

4245
//--- order-6.ignorelist
46+
type:int
4347
type:int=sanitize
44-
type:in*
4548

4649
//--- order-7.ignorelist
47-
type:int
50+
[{unsigned-integer-overflow,signed-integer-overflow}]
51+
type:*
4852
type:int=sanitize
53+
type:i*t
54+
type:*nt=sanitize
55+
[{unsigned-integer-overflow,signed-integer-overflow}]
56+
type:*
57+
type:int
58+
type:i*t=sanitize
59+
type:*nt
4960

50-
61+
//--- order-8.ignorelist
62+
[{unsigned-integer-overflow,signed-integer-overflow}]
63+
type:*
64+
type:int
65+
type:i*t=sanitize
66+
type:*nt
67+
[{unsigned-integer-overflow,signed-integer-overflow}]
68+
type:*
69+
type:int=sanitize
70+
type:i*t
71+
type:*nt=sanitize
5172

5273

5374
//--- test.c
54-
// CHECK-LABEL: @test
75+
// CHECK-LABEL: define dso_local void @test
5576
void test(int A) {
56-
// CHECK: @llvm.sadd.with.overflow.i32
77+
// IGNORE: %inc = add nsw
78+
// SANITIZE: @llvm.sadd.with.overflow.i32
5779
++A;
5880
}
81+

0 commit comments

Comments
 (0)