Skip to content

Commit ecd4781

Browse files
authored
[sanitizer] Skip /include/c++/ from summary (#78534)
std:: usually is not a cause of the bug. We now display ``` SUMMARY: AddressSanitizer: allocation-size-too-big path/to/allocator_returns_null.cpp:92:7 in main ``` instead of ``` SUMMARY: AddressSanitizer: allocation-size-too-big /usr/lib/../include/c++/13/bits/new_allocator.h:147:27 in std::__new_allocator<char>::allocate(unsigned long, void const*) ``` `/include/c++/` matches both libc++ and libstdc++ include paths.
1 parent c82b7fd commit ecd4781

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ static bool FrameIsInternal(const SymbolizedStack *frame) {
3434
return true;
3535
const char *file = frame->info.file;
3636
const char *module = frame->info.module;
37-
if (file && (internal_strstr(file, "/compiler-rt/lib/")))
37+
if (file && (internal_strstr(file, "/compiler-rt/lib/") ||
38+
internal_strstr(file, "/include/c++/")))
3839
return true;
3940
if (module && (internal_strstr(module, "libclang_rt.")))
4041
return true;

compiler-rt/test/sanitizer_common/TestCases/allocator_returns_null.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,20 @@
3434
// RUN: | FileCheck %s --check-prefix=CHECK-nnCRASH
3535
// RUN: %env_tool_opts=allocator_may_return_null=1 %run %t new-nothrow 2>&1 \
3636
// RUN: | FileCheck %s --check-prefix=CHECK-NULL
37+
// RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t vector 2>&1 \
38+
// RUN: | FileCheck %s --check-prefix=CHECK-vCRASH
3739

3840
// TODO(alekseyshl): win32 is disabled due to failing errno tests, fix it there.
3941
// UNSUPPORTED: ubsan, target={{.*windows-msvc.*}}
4042

4143
#include <assert.h>
4244
#include <errno.h>
45+
#include <limits>
46+
#include <new>
4347
#include <stdio.h>
4448
#include <stdlib.h>
4549
#include <string.h>
46-
#include <limits>
47-
#include <new>
50+
#include <vector>
4851

4952
int main(int argc, char **argv) {
5053
assert(argc == 2);
@@ -60,6 +63,8 @@ int main(int argc, char **argv) {
6063
(3UL << 30) + 1;
6164
#endif
6265

66+
std::vector<char> v;
67+
6368
void *x = nullptr;
6469
if (!strcmp(action, "malloc")) {
6570
x = malloc(kMaxAllowedMallocSizePlusOne);
@@ -82,6 +87,14 @@ int main(int argc, char **argv) {
8287
x = operator new(kMaxAllowedMallocSizePlusOne);
8388
} else if (!strcmp(action, "new-nothrow")) {
8489
x = operator new(kMaxAllowedMallocSizePlusOne, std::nothrow);
90+
} else if (!strcmp(action, "vector")) {
91+
#if __LP64__ || defined(_WIN64)
92+
v.resize(kMaxAllowedMallocSizePlusOne);
93+
x = v.data();
94+
#else
95+
// Fake it: 32bit fails early in std.
96+
x = malloc(kMaxAllowedMallocSizePlusOne);
97+
#endif
8598
} else {
8699
assert(0);
87100
}
@@ -117,6 +130,8 @@ int main(int argc, char **argv) {
117130
// CHECK-nnCRASH: new-nothrow:
118131
// CHECK-nnCRASH: #{{[0-9]+.*}}allocator_returns_null.cpp
119132
// CHECK-nnCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.*allocator_returns_null.cpp.*}} in main
133+
// CHECK-vCRASH: #{{[0-9]+.*}}allocator_returns_null.cpp
134+
// CHECK-vCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.*allocator_returns_null.cpp.*}} in main
120135

121136
// CHECK-NULL: {{malloc|calloc|calloc-overflow|realloc|realloc-after-malloc|new-nothrow}}
122137
// CHECK-NULL: errno: 12, x: 0

0 commit comments

Comments
 (0)