clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name tsan_stack_trace.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -target-feature +sse4.2 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-14~++20211110111138+cffbfd01e37b/build-llvm -resource-dir /usr/lib/llvm-14/lib/clang/14.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I projects/compiler-rt/lib/tsan -I /build/llvm-toolchain-snapshot-14~++20211110111138+cffbfd01e37b/compiler-rt/lib/tsan -I include -I /build/llvm-toolchain-snapshot-14~++20211110111138+cffbfd01e37b/llvm/include -I /build/llvm-toolchain-snapshot-14~++20211110111138+cffbfd01e37b/compiler-rt/lib/tsan/.. -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-unused-command-line-argument -Wno-unknown-warning-option -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -Wno-unused-parameter -Wno-variadic-macros -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-14~++20211110111138+cffbfd01e37b/build-llvm -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -fno-builtin -fno-rtti -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2021-11-10-160236-22541-1 -x c++ /build/llvm-toolchain-snapshot-14~++20211110111138+cffbfd01e37b/compiler-rt/lib/tsan/rtl/tsan_stack_trace.cpp
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | #include "tsan_stack_trace.h" |
13 | #include "tsan_rtl.h" |
14 | #include "tsan_mman.h" |
15 | |
16 | namespace __tsan { |
17 | |
18 | VarSizeStackTrace::VarSizeStackTrace() |
19 | : StackTrace(nullptr, 0), trace_buffer(nullptr) {} |
20 | |
21 | VarSizeStackTrace::~VarSizeStackTrace() { |
22 | ResizeBuffer(0); |
23 | } |
24 | |
25 | void VarSizeStackTrace::ResizeBuffer(uptr new_size) { |
26 | Free(trace_buffer); |
| 3 | | Calling 'Free<unsigned long>' | |
|
| 7 | | Returning from 'Free<unsigned long>' | |
|
27 | trace_buffer = (new_size > 0) |
| 8 | | Assuming 'new_size' is <= 0 | |
|
| |
| 10 | | Null pointer value stored to field 'trace_buffer' | |
|
28 | ? (uptr *)Alloc(new_size * sizeof(trace_buffer[0])) |
29 | : nullptr; |
30 | trace = trace_buffer; |
31 | size = new_size; |
32 | } |
33 | |
34 | void VarSizeStackTrace::Init(const uptr *pcs, uptr cnt, uptr extra_top_pc) { |
35 | ResizeBuffer(cnt + !!extra_top_pc); |
| 1 | Assuming 'extra_top_pc' is not equal to 0 | |
|
| 2 | | Calling 'VarSizeStackTrace::ResizeBuffer' | |
|
| 11 | | Returning from 'VarSizeStackTrace::ResizeBuffer' | |
|
36 | internal_memcpy(trace_buffer, pcs, cnt * sizeof(trace_buffer[0])); |
37 | if (extra_top_pc) |
| |
38 | trace_buffer[cnt] = extra_top_pc; |
| 13 | | Array access (via field 'trace_buffer') results in a null pointer dereference |
|
39 | } |
40 | |
41 | void VarSizeStackTrace::ReverseOrder() { |
42 | for (u32 i = 0; i < (size >> 1); i++) |
43 | Swap(trace_buffer[i], trace_buffer[size - 1 - i]); |
44 | } |
45 | |
46 | } |
47 | |
48 | #if !SANITIZER_GO |
49 | void __sanitizer::BufferedStackTrace::UnwindImpl( |
50 | uptr pc, uptr bp, void *context, bool request_fast, u32 max_depth) { |
51 | uptr top = 0; |
52 | uptr bottom = 0; |
53 | GetThreadStackTopAndBottom(false, &top, &bottom); |
54 | bool fast = StackTrace::WillUseFastUnwind(request_fast); |
55 | Unwind(max_depth, pc, bp, context, top, bottom, fast); |
56 | } |
57 | #endif // SANITIZER_GO |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | #ifndef TSAN_MMAN_H |
13 | #define TSAN_MMAN_H |
14 | |
15 | #include "tsan_defs.h" |
16 | |
17 | namespace __tsan { |
18 | |
19 | const uptr kDefaultAlignment = 16; |
20 | |
21 | void InitializeAllocator(); |
22 | void InitializeAllocatorLate(); |
23 | void ReplaceSystemMalloc(); |
24 | void AllocatorProcStart(Processor *proc); |
25 | void AllocatorProcFinish(Processor *proc); |
26 | void AllocatorPrintStats(); |
27 | |
28 | |
29 | void *user_alloc_internal(ThreadState *thr, uptr pc, uptr sz, |
30 | uptr align = kDefaultAlignment, bool signal = true); |
31 | |
32 | void user_free(ThreadState *thr, uptr pc, void *p, bool signal = true); |
33 | |
34 | void *user_alloc(ThreadState *thr, uptr pc, uptr sz); |
35 | void *user_calloc(ThreadState *thr, uptr pc, uptr sz, uptr n); |
36 | void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz); |
37 | void *user_reallocarray(ThreadState *thr, uptr pc, void *p, uptr sz, uptr n); |
38 | void *user_memalign(ThreadState *thr, uptr pc, uptr align, uptr sz); |
39 | int user_posix_memalign(ThreadState *thr, uptr pc, void **memptr, uptr align, |
40 | uptr sz); |
41 | void *user_aligned_alloc(ThreadState *thr, uptr pc, uptr align, uptr sz); |
42 | void *user_valloc(ThreadState *thr, uptr pc, uptr sz); |
43 | void *user_pvalloc(ThreadState *thr, uptr pc, uptr sz); |
44 | uptr user_alloc_usable_size(const void *p); |
45 | |
46 | |
47 | void invoke_malloc_hook(void *ptr, uptr size); |
48 | void invoke_free_hook(void *ptr); |
49 | |
50 | |
51 | void *Alloc(uptr sz); |
52 | void FreeImpl(void *p); |
53 | |
54 | template <typename T, typename... Args> |
55 | T *New(Args &&...args) { |
56 | return new (Alloc(sizeof(T))) T(static_cast<Args &&>(args)...); |
57 | } |
58 | |
59 | template <typename T> |
60 | void Free(T *&p) { |
61 | if (p == nullptr) |
| 4 | | Assuming the condition is true | |
|
| |
62 | return; |
| 6 | | Returning without writing to 'p' | |
|
63 | FreeImpl(p); |
64 | p = nullptr; |
65 | } |
66 | |
67 | template <typename T> |
68 | void DestroyAndFree(T *&p) { |
69 | if (p == nullptr) |
70 | return; |
71 | p->~T(); |
72 | Free(p); |
73 | } |
74 | |
75 | } |
76 | #endif // TSAN_MMAN_H |