clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name Operator.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 pic -pic-level 1 -fhalf-no-semantic-interposition -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/libLLVM/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Analysis -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ASMParser -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/BinaryFormat -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Bitcode -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Bitcode -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Bitstream -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /include/llvm/CodeGen -I /include/llvm/CodeGen/PBQP -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/IR -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/IR -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Coroutines -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ProfileData/Coverage -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/CodeView -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/DWARF -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/MSF -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/PDB -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Demangle -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ExecutionEngine -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ExecutionEngine/JITLink -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ExecutionEngine/Orc -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend/OpenACC -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend/OpenMP -I /include/llvm/CodeGen/GlobalISel -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/IRReader -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/InstCombine -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/Transforms/InstCombine -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/LTO -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Linker -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/MC -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/MC/MCParser -I /include/llvm/CodeGen/MIRParser -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Object -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Option -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Passes -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ProfileData -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Scalar -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ADT -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Support -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/Symbolize -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Target -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Utils -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Vectorize -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/IPO -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/libLLVM/../include -I /usr/src/gnu/usr.bin/clang/libLLVM/obj -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -D PIC -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/libLLVM/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -D_RET_PROTECTOR -ret-protector -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/libLLVM/../../../llvm/llvm/lib/IR/Operator.cpp
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #include "llvm/IR/Operator.h" |
14 | #include "llvm/IR/DataLayout.h" |
15 | #include "llvm/IR/GetElementPtrTypeIterator.h" |
16 | #include "llvm/IR/Instructions.h" |
17 | #include "llvm/IR/Type.h" |
18 | |
19 | #include "ConstantsContext.h" |
20 | |
21 | namespace llvm { |
22 | Type *GEPOperator::getSourceElementType() const { |
23 | if (auto *I = dyn_cast<GetElementPtrInst>(this)) |
24 | return I->getSourceElementType(); |
25 | return cast<GetElementPtrConstantExpr>(this)->getSourceElementType(); |
26 | } |
27 | |
28 | Type *GEPOperator::getResultElementType() const { |
29 | if (auto *I = dyn_cast<GetElementPtrInst>(this)) |
30 | return I->getResultElementType(); |
31 | return cast<GetElementPtrConstantExpr>(this)->getResultElementType(); |
32 | } |
33 | |
34 | Align GEPOperator::getMaxPreservedAlignment(const DataLayout &DL) const { |
35 | |
36 | |
37 | |
38 | Align Result = Align(llvm::Value::MaximumAlignment); |
39 | for (gep_type_iterator GTI = gep_type_begin(this), GTE = gep_type_end(this); |
| 1 | Loop condition is true. Entering loop body | |
|
40 | GTI != GTE; ++GTI) { |
41 | int64_t Offset = 1; |
42 | ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand()); |
| 2 | | Assuming the object is not a 'ConstantInt' | |
|
| 3 | | 'OpC' initialized to a null pointer value | |
|
43 | |
44 | if (StructType *STy = GTI.getStructTypeOrNull()) { |
| 4 | | Assuming 'STy' is non-null | |
|
| |
45 | const StructLayout *SL = DL.getStructLayout(STy); |
46 | Offset = SL->getElementOffset(OpC->getZExtValue()); |
| 6 | | Called C++ object pointer is null |
|
47 | } else { |
48 | assert(GTI.isSequential() && "should be sequencial"); |
49 | |
50 | |
51 | int64_t ElemCount = 1; |
52 | if (OpC) |
53 | ElemCount = OpC->getZExtValue(); |
54 | Offset = DL.getTypeAllocSize(GTI.getIndexedType()) * ElemCount; |
55 | } |
56 | Result = Align(MinAlign(Offset, Result.value())); |
57 | } |
58 | return Result; |
59 | } |
60 | |
61 | bool GEPOperator::accumulateConstantOffset( |
62 | const DataLayout &DL, APInt &Offset, |
63 | function_ref<bool(Value &, APInt &)> ExternalAnalysis) const { |
64 | assert(Offset.getBitWidth() == |
65 | DL.getIndexSizeInBits(getPointerAddressSpace()) && |
66 | "The offset bit width does not match DL specification."); |
67 | SmallVector<const Value *> Index(value_op_begin() + 1, value_op_end()); |
68 | return GEPOperator::accumulateConstantOffset(getSourceElementType(), Index, |
69 | DL, Offset, ExternalAnalysis); |
70 | } |
71 | |
72 | bool GEPOperator::accumulateConstantOffset( |
73 | Type *SourceType, ArrayRef<const Value *> Index, const DataLayout &DL, |
74 | APInt &Offset, function_ref<bool(Value &, APInt &)> ExternalAnalysis) { |
75 | bool UsedExternalAnalysis = false; |
76 | auto AccumulateOffset = [&](APInt Index, uint64_t Size) -> bool { |
77 | Index = Index.sextOrTrunc(Offset.getBitWidth()); |
78 | APInt IndexedSize = APInt(Offset.getBitWidth(), Size); |
79 | |
80 | if (!UsedExternalAnalysis) { |
81 | Offset += Index * IndexedSize; |
82 | } else { |
83 | |
84 | |
85 | bool Overflow = false; |
86 | APInt OffsetPlus = Index.smul_ov(IndexedSize, Overflow); |
87 | if (Overflow) |
88 | return false; |
89 | Offset = Offset.sadd_ov(OffsetPlus, Overflow); |
90 | if (Overflow) |
91 | return false; |
92 | } |
93 | return true; |
94 | }; |
95 | auto begin = generic_gep_type_iterator<decltype(Index.begin())>::begin( |
96 | SourceType, Index.begin()); |
97 | auto end = generic_gep_type_iterator<decltype(Index.end())>::end(Index.end()); |
98 | for (auto GTI = begin, GTE = end; GTI != GTE; ++GTI) { |
99 | |
100 | bool ScalableType = false; |
101 | if (isa<ScalableVectorType>(GTI.getIndexedType())) |
102 | ScalableType = true; |
103 | |
104 | Value *V = GTI.getOperand(); |
105 | StructType *STy = GTI.getStructTypeOrNull(); |
106 | |
107 | if (auto ConstOffset = dyn_cast<ConstantInt>(V)) { |
108 | if (ConstOffset->isZero()) |
109 | continue; |
110 | |
111 | |
112 | if (ScalableType) |
113 | return false; |
114 | |
115 | if (STy) { |
116 | unsigned ElementIdx = ConstOffset->getZExtValue(); |
117 | const StructLayout *SL = DL.getStructLayout(STy); |
118 | |
119 | if (!AccumulateOffset( |
120 | APInt(Offset.getBitWidth(), SL->getElementOffset(ElementIdx)), |
121 | 1)) |
122 | return false; |
123 | continue; |
124 | } |
125 | if (!AccumulateOffset(ConstOffset->getValue(), |
126 | DL.getTypeAllocSize(GTI.getIndexedType()))) |
127 | return false; |
128 | continue; |
129 | } |
130 | |
131 | |
132 | |
133 | if (!ExternalAnalysis || STy || ScalableType) |
134 | return false; |
135 | APInt AnalysisIndex; |
136 | if (!ExternalAnalysis(*V, AnalysisIndex)) |
137 | return false; |
138 | UsedExternalAnalysis = true; |
139 | if (!AccumulateOffset(AnalysisIndex, |
140 | DL.getTypeAllocSize(GTI.getIndexedType()))) |
141 | return false; |
142 | } |
143 | return true; |
144 | } |
145 | |
146 | bool GEPOperator::collectOffset( |
147 | const DataLayout &DL, unsigned BitWidth, |
148 | MapVector<Value *, APInt> &VariableOffsets, |
149 | APInt &ConstantOffset) const { |
150 | assert(BitWidth == DL.getIndexSizeInBits(getPointerAddressSpace()) && |
151 | "The offset bit width does not match DL specification."); |
152 | |
153 | auto CollectConstantOffset = [&](APInt Index, uint64_t Size) { |
154 | Index = Index.sextOrTrunc(BitWidth); |
155 | APInt IndexedSize = APInt(BitWidth, Size); |
156 | ConstantOffset += Index * IndexedSize; |
157 | }; |
158 | |
159 | for (gep_type_iterator GTI = gep_type_begin(this), GTE = gep_type_end(this); |
160 | GTI != GTE; ++GTI) { |
161 | |
162 | bool ScalableType = isa<ScalableVectorType>(GTI.getIndexedType()); |
163 | |
164 | Value *V = GTI.getOperand(); |
165 | StructType *STy = GTI.getStructTypeOrNull(); |
166 | |
167 | if (auto ConstOffset = dyn_cast<ConstantInt>(V)) { |
168 | if (ConstOffset->isZero()) |
169 | continue; |
170 | |
171 | |
172 | |
173 | |
174 | |
175 | if (ScalableType) |
176 | return false; |
177 | |
178 | if (STy) { |
179 | unsigned ElementIdx = ConstOffset->getZExtValue(); |
180 | const StructLayout *SL = DL.getStructLayout(STy); |
181 | |
182 | CollectConstantOffset(APInt(BitWidth, SL->getElementOffset(ElementIdx)), |
183 | 1); |
184 | continue; |
185 | } |
186 | CollectConstantOffset(ConstOffset->getValue(), |
187 | DL.getTypeAllocSize(GTI.getIndexedType())); |
188 | continue; |
189 | } |
190 | |
191 | if (STy || ScalableType) |
192 | return false; |
193 | |
194 | |
195 | VariableOffsets.insert({V, APInt(BitWidth, 0)}); |
196 | APInt IndexedSize = |
197 | APInt(BitWidth, DL.getTypeAllocSize(GTI.getIndexedType())); |
198 | VariableOffsets[V] += IndexedSize; |
199 | } |
200 | return true; |
201 | } |
202 | } |