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 InterpState.cpp -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 -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/source/build-llvm -resource-dir /usr/lib/llvm-17/lib/clang/17 -D _DEBUG -D _GLIBCXX_ASSERTIONS -D _GNU_SOURCE -D _LIBCPP_ENABLE_ASSERTIONS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I tools/clang/lib/AST -I /build/source/clang/lib/AST -I /build/source/clang/include -I tools/clang/include -I include -I /build/source/llvm/include -D _FORTIFY_SOURCE=2 -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-17/lib/clang/17/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 -fmacro-prefix-map=/build/source/build-llvm=build-llvm -fmacro-prefix-map=/build/source/= -fcoverage-prefix-map=/build/source/build-llvm=build-llvm -fcoverage-prefix-map=/build/source/= -source-date-epoch 1679443490 -O3 -Wno-unused-command-line-argument -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-misleading-indentation -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/build/source/build-llvm -fdebug-prefix-map=/build/source/build-llvm=build-llvm -fdebug-prefix-map=/build/source/= -fdebug-prefix-map=/build/source/build-llvm=build-llvm -fdebug-prefix-map=/build/source/= -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -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-2023-03-22-005342-16304-1 -x c++ /build/source/clang/lib/AST/Interp/InterpState.cpp
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | #include "InterpState.h" |
10 | #include "InterpFrame.h" |
11 | #include "InterpStack.h" |
12 | #include "Program.h" |
13 | #include "State.h" |
14 | |
15 | using namespace clang; |
16 | using namespace clang::interp; |
17 | |
18 | InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk, |
19 | Context &Ctx, SourceMapper *M) |
20 | : Parent(Parent), M(M), P(P), Stk(Stk), Ctx(Ctx), Current(nullptr), |
21 | CallStackDepth(Parent.getCallStackDepth() + 1) {} |
22 | |
23 | InterpState::~InterpState() { |
24 | while (Current) { |
25 | InterpFrame *Next = Current->Caller; |
26 | delete Current; |
27 | Current = Next; |
28 | } |
29 | |
30 | while (DeadBlocks) { |
31 | DeadBlock *Next = DeadBlocks->Next; |
32 | free(DeadBlocks); |
33 | DeadBlocks = Next; |
34 | } |
35 | } |
36 | |
37 | Frame *InterpState::getCurrentFrame() { |
38 | if (Current && Current->Caller) |
39 | return Current; |
40 | return Parent.getCurrentFrame(); |
41 | } |
42 | |
43 | bool InterpState::reportOverflow(const Expr *E, const llvm::APSInt &Value) { |
44 | QualType Type = E->getType(); |
45 | CCEDiag(E, diag::note_constexpr_overflow) << Value << Type; |
46 | return noteUndefinedBehavior(); |
47 | } |
48 | |
49 | void InterpState::deallocate(Block *B) { |
50 | Descriptor *Desc = B->getDescriptor(); |
51 | if (B->hasPointers()) { |
| 1 | Assuming the condition is true | |
|
| |
52 | size_t Size = B->getSize(); |
53 | |
54 | |
55 | char *Memory = reinterpret_cast<char *>(malloc(sizeof(DeadBlock) + Size)); |
| |
56 | auto *D = new (Memory) DeadBlock(DeadBlocks, B); |
57 | |
58 | |
59 | if (Desc->MoveFn) |
| 4 | | Assuming field 'MoveFn' is null | |
|
| |
60 | Desc->MoveFn(B, B->data(), D->data(), Desc); |
61 | } else { |
62 | |
63 | if (Desc->DtorFn) |
64 | Desc->DtorFn(B, B->data(), Desc); |
65 | } |
66 | } |
| 6 | | Potential leak of memory pointed to by 'D' |
|