clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -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 -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangAST/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/libclangAST/obj/../include/clang/AST -I /usr/src/gnu/usr.bin/clang/libclangAST/../../../llvm/clang/include -I /usr/src/gnu/usr.bin/clang/libclangAST/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/libclangAST/../include -I /usr/src/gnu/usr.bin/clang/libclangAST/obj -I /usr/src/gnu/usr.bin/clang/libclangAST/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangAST/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -stack-protector 2 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c++ /usr/src/gnu/usr.bin/clang/libclangAST/../../../llvm/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' |
|