Bug Summary

File:build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/llvm/lib/Bitcode/Reader/ValueList.cpp
Warning:line 86, column 3
Potential leak of memory pointed to by field 'Val'

Annotated Source Code

Press '?' to see keyboard shortcuts

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 ValueList.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 -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/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/build-llvm -resource-dir /usr/lib/llvm-16/lib/clang/16.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I lib/Bitcode/Reader -I /build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/llvm/lib/Bitcode/Reader -I include -I /build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/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-16/lib/clang/16.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 -fmacro-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/build-llvm=build-llvm -fmacro-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/= -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/build-llvm=build-llvm -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/= -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/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/build-llvm -fdebug-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/build-llvm=build-llvm -fdebug-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/= -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-2022-10-03-140002-15933-1 -x c++ /build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/llvm/lib/Bitcode/Reader/ValueList.cpp
1//===- ValueList.cpp - Internal BitcodeReader implementation --------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "ValueList.h"
10#include "llvm/ADT/SmallVector.h"
11#include "llvm/IR/Argument.h"
12#include "llvm/IR/Constant.h"
13#include "llvm/IR/Constants.h"
14#include "llvm/IR/GlobalValue.h"
15#include "llvm/IR/Instruction.h"
16#include "llvm/IR/Type.h"
17#include "llvm/IR/User.h"
18#include "llvm/IR/Value.h"
19#include "llvm/Support/Casting.h"
20#include "llvm/Support/Error.h"
21#include "llvm/Support/ErrorHandling.h"
22#include <cstddef>
23
24using namespace llvm;
25
26Error BitcodeReaderValueList::assignValue(unsigned Idx, Value *V,
27 unsigned TypeID) {
28 if (Idx == size()) {
29 push_back(V, TypeID);
30 return Error::success();
31 }
32
33 if (Idx >= size())
34 resize(Idx + 1);
35
36 auto &Old = ValuePtrs[Idx];
37 if (!Old.first) {
38 Old.first = V;
39 Old.second = TypeID;
40 return Error::success();
41 }
42
43 assert(!isa<Constant>(&*Old.first) && "Shouldn't update constant")(static_cast <bool> (!isa<Constant>(&*Old.first
) && "Shouldn't update constant") ? void (0) : __assert_fail
("!isa<Constant>(&*Old.first) && \"Shouldn't update constant\""
, "llvm/lib/Bitcode/Reader/ValueList.cpp", 43, __extension__ __PRETTY_FUNCTION__
))
;
44 // If there was a forward reference to this value, replace it.
45 Value *PrevVal = Old.first;
46 if (PrevVal->getType() != V->getType())
47 return createStringError(
48 std::errc::illegal_byte_sequence,
49 "Assigned value does not match type of forward declaration");
50 Old.first->replaceAllUsesWith(V);
51 PrevVal->deleteValue();
52 return Error::success();
53}
54
55Value *BitcodeReaderValueList::getValueFwdRef(unsigned Idx, Type *Ty,
56 unsigned TyID,
57 BasicBlock *ConstExprInsertBB) {
58 // Bail out for a clearly invalid value.
59 if (Idx >= RefsUpperBound)
1
Assuming 'Idx' is < field 'RefsUpperBound'
2
Taking false branch
60 return nullptr;
61
62 if (Idx >= size())
3
Assuming the condition is false
4
Taking false branch
63 resize(Idx + 1);
64
65 if (Value *V = ValuePtrs[Idx].first) {
5
Assuming 'V' is null
6
Taking false branch
66 // If the types don't match, it's invalid.
67 if (Ty && Ty != V->getType())
68 return nullptr;
69
70 Expected<Value *> MaybeV = MaterializeValueFn(Idx, ConstExprInsertBB);
71 if (!MaybeV) {
72 // TODO: We might want to propagate the precise error message here.
73 consumeError(MaybeV.takeError());
74 return nullptr;
75 }
76 return MaybeV.get();
77 }
78
79 // No type specified, must be invalid reference.
80 if (!Ty)
7
Assuming 'Ty' is non-null
8
Taking false branch
81 return nullptr;
82
83 // Create and return a placeholder, which will later be RAUW'd.
84 Value *V = new Argument(Ty);
9
Memory is allocated
85 ValuePtrs[Idx] = {V, TyID};
86 return V;
10
Potential leak of memory pointed to by field 'Val'
87}