clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name InterpState.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 -mframe-pointer=none -relaxed-aliasing -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/build-llvm/tools/clang/lib/AST -resource-dir /usr/lib/llvm-14/lib/clang/14.0.0 -D CLANG_ROUND_TRIP_CC1_ARGS=ON -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/build-llvm/tools/clang/lib/AST -I /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST -I /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include -I /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/build-llvm/include -I /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/llvm/include -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 -O2 -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 -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/build-llvm/tools/clang/lib/AST -fdebug-prefix-map=/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0=. -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -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-08-28-193554-24367-1 -x c++ /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/Interp/InterpState.cpp
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | #include "InterpState.h" |
10 | #include <limits> |
11 | #include "Function.h" |
12 | #include "InterpFrame.h" |
13 | #include "InterpStack.h" |
14 | #include "Opcode.h" |
15 | #include "PrimType.h" |
16 | #include "Program.h" |
17 | #include "State.h" |
18 | |
19 | using namespace clang; |
20 | using namespace clang::interp; |
21 | |
22 | using APSInt = llvm::APSInt; |
23 | |
24 | InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk, |
25 | Context &Ctx, SourceMapper *M) |
26 | : Parent(Parent), M(M), P(P), Stk(Stk), Ctx(Ctx), Current(nullptr), |
27 | CallStackDepth(Parent.getCallStackDepth() + 1) {} |
28 | |
29 | InterpState::~InterpState() { |
30 | while (Current) { |
31 | InterpFrame *Next = Current->Caller; |
32 | delete Current; |
33 | Current = Next; |
34 | } |
35 | |
36 | while (DeadBlocks) { |
37 | DeadBlock *Next = DeadBlocks->Next; |
38 | free(DeadBlocks); |
39 | DeadBlocks = Next; |
40 | } |
41 | } |
42 | |
43 | Frame *InterpState::getCurrentFrame() { |
44 | if (Current && Current->Caller) { |
45 | return Current; |
46 | } else { |
47 | return Parent.getCurrentFrame(); |
48 | } |
49 | } |
50 | |
51 | bool InterpState::reportOverflow(const Expr *E, const llvm::APSInt &Value) { |
52 | QualType Type = E->getType(); |
53 | CCEDiag(E, diag::note_constexpr_overflow) << Value << Type; |
54 | return noteUndefinedBehavior(); |
55 | } |
56 | |
57 | void InterpState::deallocate(Block *B) { |
58 | Descriptor *Desc = B->getDescriptor(); |
59 | if (B->hasPointers()) { |
| 1 | Assuming the condition is true | |
|
| |
60 | size_t Size = B->getSize(); |
61 | |
62 | |
63 | char *Memory = reinterpret_cast<char *>(malloc(sizeof(DeadBlock) + Size)); |
| |
64 | auto *D = new (Memory) DeadBlock(DeadBlocks, B); |
65 | |
66 | |
67 | if (Desc->MoveFn) |
| |
68 | Desc->MoveFn(B, B->data(), D->data(), Desc); |
69 | } else { |
70 | |
71 | if (Desc->DtorFn) |
72 | Desc->DtorFn(B, B->data(), Desc); |
73 | } |
74 | } |
| 5 | | Potential leak of memory pointed to by 'D' |
|