Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clang/lib/Basic/NoSanitizeList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -64,7 +64,7 @@ bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName,

bool NoSanitizeList::containsMainFile(SanitizerMask Mask, StringRef FileName,
StringRef Category) const {
return SSCL->inSection(Mask, "mainfile", FileName, Category);
return containsPrefix(Mask, "mainfile", FileName, Category);
}

bool NoSanitizeList::containsLocation(SanitizerMask Mask, SourceLocation Loc,
Expand Down
37 changes: 37 additions & 0 deletions clang/test/CodeGen/asan-global-ignorelist.test
Original file line number Diff line number Diff line change
@@ -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};
21 changes: 16 additions & 5 deletions clang/test/CodeGen/sanitize-ignorelist-mainfile.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/// Test mainfile in a sanitizer special case list.
// RUN: rm -rf %t && split-file %s %t
// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fsanitize=address,alignment %t/a.c -o - | FileCheck %s --check-prefixes=CHECK,DEFAULT
// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fsanitize=address,alignment %t/a.c -o - | FileCheck %s --check-prefixes=CHECK,SANITIZE
// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fsanitize=address,alignment -fsanitize-ignorelist=%t/a.list %t/a.c -o - | FileCheck %s --check-prefixes=CHECK,IGNORE
// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fsanitize=address,alignment -fsanitize-ignorelist=%t/b.list %t/a.c -o - | FileCheck %s --check-prefixes=CHECK,IGNORE
// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fsanitize=address,alignment -fsanitize-ignorelist=%t/c.list %t/a.c -o - | FileCheck %s --check-prefixes=CHECK,SANITIZE
// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fsanitize=address,alignment -fsanitize-ignorelist=%t/d.list %t/a.c -o - | FileCheck %s --check-prefixes=CHECK,IGNORE

//--- a.list
mainfile:*a.c
Expand All @@ -14,6 +16,15 @@ mainfile:*a.c
[alignment]
mainfile:*.c

//--- c.list
mainfile:*a.c
mainfile:*a.c=sanitize

//--- d.list
mainfile:*a.c
mainfile:*a.c=sanitize
mainfile:*a.c

//--- a.h
int global_h;

Expand All @@ -30,12 +41,12 @@ int foo(void *x) {
return load(x);
}

// DEFAULT: @___asan_gen_{{.*}} = {{.*}} c"global_h\00"
// DEFAULT: @___asan_gen_{{.*}} = {{.*}} c"global_c\00"
// SANITIZE: @___asan_gen_{{.*}} = {{.*}} c"global_h\00"
// SANITIZE: @___asan_gen_{{.*}} = {{.*}} c"global_c\00"
// IGNORE-NOT: @___asan_gen_

// CHECK-LABEL: define {{.*}}@load(
// DEFAULT: call void @__ubsan_handle_type_mismatch_v1_abort(
// DEFAULT: call void @__asan_report_load4(
// SANITIZE: call void @__ubsan_handle_type_mismatch_v1_abort(
// SANITIZE: call void @__asan_report_load4(
// IGNORE-NOT: call void @__ubsan_handle_type_mismatch_v1_abort(
// IGNORE-NOT: call void @__asan_report_load4(
83 changes: 83 additions & 0 deletions clang/test/CodeGen/ubsan-function-ignorelist.test
Original file line number Diff line number Diff line change
@@ -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;
}

Loading