generated from bazel-contrib/rules-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
load(":defs.bzl", "cc_asan_test") | ||
|
||
cc_asan_test( | ||
name = "asan_test", | ||
srcs = ["asan_test.cpp"], | ||
env = { | ||
# Effectively invert the exit code so that the test passes if and only | ||
# if the expected ASAN error is detected. | ||
"ASAN_OPTIONS": "exitcode=0:abort_on_error=0", | ||
}, | ||
deps = [ | ||
":lib", | ||
], | ||
) | ||
|
||
cc_library( | ||
name = "lib", | ||
srcs = ["lib.cpp"], | ||
hdrs = ["lib.h"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "cc_asan_test/lib.h" | ||
|
||
#include <iostream> | ||
|
||
int main() { | ||
trigger_asan(); | ||
std::cerr << "Did not get expected AddressSanitizer error, is the test instrumented correctly?" << std::endl; | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
load("@with_cfg.bzl", "with_cfg") | ||
|
||
cc_asan_test, _cc_asan_test_internal = with_cfg( | ||
native.cc_test, | ||
).extend( | ||
"copt", | ||
select({ | ||
"@rules_cc//cc/compiler:msvc-cl": ["/fsanitize=address"], | ||
"//conditions:default": ["-fsanitize=address"], | ||
}), | ||
).extend( | ||
"linkopt", | ||
select({ | ||
"@rules_cc//cc/compiler:msvc-cl": [], | ||
"//conditions:default": ["-fsanitize=address"], | ||
}), | ||
).build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "cc_asan_test/lib.h" | ||
|
||
int trigger_asan() { | ||
int* array = new int[100] {}; | ||
delete[] array; | ||
// Triggers a heap-use-after-free error. | ||
return array[0]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma once | ||
|
||
int trigger_asan(); |