File: | llvm/lib/IR/Verifier.cpp |
Warning: | line 2357, column 5 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===-- Verifier.cpp - Implement the Module Verifier -----------------------==// | |||
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 | // This file defines the function verifier interface, that can be used for some | |||
10 | // sanity checking of input to the system. | |||
11 | // | |||
12 | // Note that this does not provide full `Java style' security and verifications, | |||
13 | // instead it just tries to ensure that code is well-formed. | |||
14 | // | |||
15 | // * Both of a binary operator's parameters are of the same type | |||
16 | // * Verify that the indices of mem access instructions match other operands | |||
17 | // * Verify that arithmetic and other things are only performed on first-class | |||
18 | // types. Verify that shifts & logicals only happen on integrals f.e. | |||
19 | // * All of the constants in a switch statement are of the correct type | |||
20 | // * The code is in valid SSA form | |||
21 | // * It should be illegal to put a label into any other type (like a structure) | |||
22 | // or to return one. [except constant arrays!] | |||
23 | // * Only phi nodes can be self referential: 'add i32 %0, %0 ; <int>:0' is bad | |||
24 | // * PHI nodes must have an entry for each predecessor, with no extras. | |||
25 | // * PHI nodes must be the first thing in a basic block, all grouped together | |||
26 | // * PHI nodes must have at least one entry | |||
27 | // * All basic blocks should only end with terminator insts, not contain them | |||
28 | // * The entry node to a function must not have predecessors | |||
29 | // * All Instructions must be embedded into a basic block | |||
30 | // * Functions cannot take a void-typed parameter | |||
31 | // * Verify that a function's argument list agrees with it's declared type. | |||
32 | // * It is illegal to specify a name for a void value. | |||
33 | // * It is illegal to have a internal global value with no initializer | |||
34 | // * It is illegal to have a ret instruction that returns a value that does not | |||
35 | // agree with the function return value type. | |||
36 | // * Function call argument types match the function prototype | |||
37 | // * A landing pad is defined by a landingpad instruction, and can be jumped to | |||
38 | // only by the unwind edge of an invoke instruction. | |||
39 | // * A landingpad instruction must be the first non-PHI instruction in the | |||
40 | // block. | |||
41 | // * Landingpad instructions must be in a function with a personality function. | |||
42 | // * All other things that are tested by asserts spread about the code... | |||
43 | // | |||
44 | //===----------------------------------------------------------------------===// | |||
45 | ||||
46 | #include "llvm/IR/Verifier.h" | |||
47 | #include "llvm/ADT/APFloat.h" | |||
48 | #include "llvm/ADT/APInt.h" | |||
49 | #include "llvm/ADT/ArrayRef.h" | |||
50 | #include "llvm/ADT/DenseMap.h" | |||
51 | #include "llvm/ADT/MapVector.h" | |||
52 | #include "llvm/ADT/Optional.h" | |||
53 | #include "llvm/ADT/STLExtras.h" | |||
54 | #include "llvm/ADT/SmallPtrSet.h" | |||
55 | #include "llvm/ADT/SmallSet.h" | |||
56 | #include "llvm/ADT/SmallVector.h" | |||
57 | #include "llvm/ADT/StringExtras.h" | |||
58 | #include "llvm/ADT/StringMap.h" | |||
59 | #include "llvm/ADT/StringRef.h" | |||
60 | #include "llvm/ADT/Twine.h" | |||
61 | #include "llvm/ADT/ilist.h" | |||
62 | #include "llvm/BinaryFormat/Dwarf.h" | |||
63 | #include "llvm/IR/Argument.h" | |||
64 | #include "llvm/IR/Attributes.h" | |||
65 | #include "llvm/IR/BasicBlock.h" | |||
66 | #include "llvm/IR/CFG.h" | |||
67 | #include "llvm/IR/CallingConv.h" | |||
68 | #include "llvm/IR/Comdat.h" | |||
69 | #include "llvm/IR/Constant.h" | |||
70 | #include "llvm/IR/ConstantRange.h" | |||
71 | #include "llvm/IR/Constants.h" | |||
72 | #include "llvm/IR/DataLayout.h" | |||
73 | #include "llvm/IR/DebugInfo.h" | |||
74 | #include "llvm/IR/DebugInfoMetadata.h" | |||
75 | #include "llvm/IR/DebugLoc.h" | |||
76 | #include "llvm/IR/DerivedTypes.h" | |||
77 | #include "llvm/IR/Dominators.h" | |||
78 | #include "llvm/IR/Function.h" | |||
79 | #include "llvm/IR/GlobalAlias.h" | |||
80 | #include "llvm/IR/GlobalValue.h" | |||
81 | #include "llvm/IR/GlobalVariable.h" | |||
82 | #include "llvm/IR/InlineAsm.h" | |||
83 | #include "llvm/IR/InstVisitor.h" | |||
84 | #include "llvm/IR/InstrTypes.h" | |||
85 | #include "llvm/IR/Instruction.h" | |||
86 | #include "llvm/IR/Instructions.h" | |||
87 | #include "llvm/IR/IntrinsicInst.h" | |||
88 | #include "llvm/IR/Intrinsics.h" | |||
89 | #include "llvm/IR/LLVMContext.h" | |||
90 | #include "llvm/IR/Metadata.h" | |||
91 | #include "llvm/IR/Module.h" | |||
92 | #include "llvm/IR/ModuleSlotTracker.h" | |||
93 | #include "llvm/IR/PassManager.h" | |||
94 | #include "llvm/IR/Statepoint.h" | |||
95 | #include "llvm/IR/Type.h" | |||
96 | #include "llvm/IR/Use.h" | |||
97 | #include "llvm/IR/User.h" | |||
98 | #include "llvm/IR/Value.h" | |||
99 | #include "llvm/Pass.h" | |||
100 | #include "llvm/Support/AtomicOrdering.h" | |||
101 | #include "llvm/Support/Casting.h" | |||
102 | #include "llvm/Support/CommandLine.h" | |||
103 | #include "llvm/Support/Debug.h" | |||
104 | #include "llvm/Support/ErrorHandling.h" | |||
105 | #include "llvm/Support/MathExtras.h" | |||
106 | #include "llvm/Support/raw_ostream.h" | |||
107 | #include <algorithm> | |||
108 | #include <cassert> | |||
109 | #include <cstdint> | |||
110 | #include <memory> | |||
111 | #include <string> | |||
112 | #include <utility> | |||
113 | ||||
114 | using namespace llvm; | |||
115 | ||||
116 | namespace llvm { | |||
117 | ||||
118 | struct VerifierSupport { | |||
119 | raw_ostream *OS; | |||
120 | const Module &M; | |||
121 | ModuleSlotTracker MST; | |||
122 | Triple TT; | |||
123 | const DataLayout &DL; | |||
124 | LLVMContext &Context; | |||
125 | ||||
126 | /// Track the brokenness of the module while recursively visiting. | |||
127 | bool Broken = false; | |||
128 | /// Broken debug info can be "recovered" from by stripping the debug info. | |||
129 | bool BrokenDebugInfo = false; | |||
130 | /// Whether to treat broken debug info as an error. | |||
131 | bool TreatBrokenDebugInfoAsError = true; | |||
132 | ||||
133 | explicit VerifierSupport(raw_ostream *OS, const Module &M) | |||
134 | : OS(OS), M(M), MST(&M), TT(M.getTargetTriple()), DL(M.getDataLayout()), | |||
135 | Context(M.getContext()) {} | |||
136 | ||||
137 | private: | |||
138 | void Write(const Module *M) { | |||
139 | *OS << "; ModuleID = '" << M->getModuleIdentifier() << "'\n"; | |||
140 | } | |||
141 | ||||
142 | void Write(const Value *V) { | |||
143 | if (V) | |||
144 | Write(*V); | |||
145 | } | |||
146 | ||||
147 | void Write(const Value &V) { | |||
148 | if (isa<Instruction>(V)) { | |||
149 | V.print(*OS, MST); | |||
150 | *OS << '\n'; | |||
151 | } else { | |||
152 | V.printAsOperand(*OS, true, MST); | |||
153 | *OS << '\n'; | |||
154 | } | |||
155 | } | |||
156 | ||||
157 | void Write(const Metadata *MD) { | |||
158 | if (!MD) | |||
159 | return; | |||
160 | MD->print(*OS, MST, &M); | |||
161 | *OS << '\n'; | |||
162 | } | |||
163 | ||||
164 | template <class T> void Write(const MDTupleTypedArrayWrapper<T> &MD) { | |||
165 | Write(MD.get()); | |||
166 | } | |||
167 | ||||
168 | void Write(const NamedMDNode *NMD) { | |||
169 | if (!NMD) | |||
170 | return; | |||
171 | NMD->print(*OS, MST); | |||
172 | *OS << '\n'; | |||
173 | } | |||
174 | ||||
175 | void Write(Type *T) { | |||
176 | if (!T) | |||
177 | return; | |||
178 | *OS << ' ' << *T; | |||
179 | } | |||
180 | ||||
181 | void Write(const Comdat *C) { | |||
182 | if (!C) | |||
183 | return; | |||
184 | *OS << *C; | |||
185 | } | |||
186 | ||||
187 | void Write(const APInt *AI) { | |||
188 | if (!AI) | |||
189 | return; | |||
190 | *OS << *AI << '\n'; | |||
191 | } | |||
192 | ||||
193 | void Write(const unsigned i) { *OS << i << '\n'; } | |||
194 | ||||
195 | template <typename T> void Write(ArrayRef<T> Vs) { | |||
196 | for (const T &V : Vs) | |||
197 | Write(V); | |||
198 | } | |||
199 | ||||
200 | template <typename T1, typename... Ts> | |||
201 | void WriteTs(const T1 &V1, const Ts &... Vs) { | |||
202 | Write(V1); | |||
203 | WriteTs(Vs...); | |||
204 | } | |||
205 | ||||
206 | template <typename... Ts> void WriteTs() {} | |||
207 | ||||
208 | public: | |||
209 | /// A check failed, so printout out the condition and the message. | |||
210 | /// | |||
211 | /// This provides a nice place to put a breakpoint if you want to see why | |||
212 | /// something is not correct. | |||
213 | void CheckFailed(const Twine &Message) { | |||
214 | if (OS) | |||
215 | *OS << Message << '\n'; | |||
216 | Broken = true; | |||
217 | } | |||
218 | ||||
219 | /// A check failed (with values to print). | |||
220 | /// | |||
221 | /// This calls the Message-only version so that the above is easier to set a | |||
222 | /// breakpoint on. | |||
223 | template <typename T1, typename... Ts> | |||
224 | void CheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs) { | |||
225 | CheckFailed(Message); | |||
226 | if (OS) | |||
227 | WriteTs(V1, Vs...); | |||
228 | } | |||
229 | ||||
230 | /// A debug info check failed. | |||
231 | void DebugInfoCheckFailed(const Twine &Message) { | |||
232 | if (OS) | |||
233 | *OS << Message << '\n'; | |||
234 | Broken |= TreatBrokenDebugInfoAsError; | |||
235 | BrokenDebugInfo = true; | |||
236 | } | |||
237 | ||||
238 | /// A debug info check failed (with values to print). | |||
239 | template <typename T1, typename... Ts> | |||
240 | void DebugInfoCheckFailed(const Twine &Message, const T1 &V1, | |||
241 | const Ts &... Vs) { | |||
242 | DebugInfoCheckFailed(Message); | |||
243 | if (OS) | |||
244 | WriteTs(V1, Vs...); | |||
245 | } | |||
246 | }; | |||
247 | ||||
248 | } // namespace llvm | |||
249 | ||||
250 | namespace { | |||
251 | ||||
252 | class Verifier : public InstVisitor<Verifier>, VerifierSupport { | |||
253 | friend class InstVisitor<Verifier>; | |||
254 | ||||
255 | DominatorTree DT; | |||
256 | ||||
257 | /// When verifying a basic block, keep track of all of the | |||
258 | /// instructions we have seen so far. | |||
259 | /// | |||
260 | /// This allows us to do efficient dominance checks for the case when an | |||
261 | /// instruction has an operand that is an instruction in the same block. | |||
262 | SmallPtrSet<Instruction *, 16> InstsInThisBlock; | |||
263 | ||||
264 | /// Keep track of the metadata nodes that have been checked already. | |||
265 | SmallPtrSet<const Metadata *, 32> MDNodes; | |||
266 | ||||
267 | /// Keep track which DISubprogram is attached to which function. | |||
268 | DenseMap<const DISubprogram *, const Function *> DISubprogramAttachments; | |||
269 | ||||
270 | /// Track all DICompileUnits visited. | |||
271 | SmallPtrSet<const Metadata *, 2> CUVisited; | |||
272 | ||||
273 | /// The result type for a landingpad. | |||
274 | Type *LandingPadResultTy; | |||
275 | ||||
276 | /// Whether we've seen a call to @llvm.localescape in this function | |||
277 | /// already. | |||
278 | bool SawFrameEscape; | |||
279 | ||||
280 | /// Whether the current function has a DISubprogram attached to it. | |||
281 | bool HasDebugInfo = false; | |||
282 | ||||
283 | /// Whether source was present on the first DIFile encountered in each CU. | |||
284 | DenseMap<const DICompileUnit *, bool> HasSourceDebugInfo; | |||
285 | ||||
286 | /// Stores the count of how many objects were passed to llvm.localescape for a | |||
287 | /// given function and the largest index passed to llvm.localrecover. | |||
288 | DenseMap<Function *, std::pair<unsigned, unsigned>> FrameEscapeInfo; | |||
289 | ||||
290 | // Maps catchswitches and cleanuppads that unwind to siblings to the | |||
291 | // terminators that indicate the unwind, used to detect cycles therein. | |||
292 | MapVector<Instruction *, Instruction *> SiblingFuncletInfo; | |||
293 | ||||
294 | /// Cache of constants visited in search of ConstantExprs. | |||
295 | SmallPtrSet<const Constant *, 32> ConstantExprVisited; | |||
296 | ||||
297 | /// Cache of declarations of the llvm.experimental.deoptimize.<ty> intrinsic. | |||
298 | SmallVector<const Function *, 4> DeoptimizeDeclarations; | |||
299 | ||||
300 | // Verify that this GlobalValue is only used in this module. | |||
301 | // This map is used to avoid visiting uses twice. We can arrive at a user | |||
302 | // twice, if they have multiple operands. In particular for very large | |||
303 | // constant expressions, we can arrive at a particular user many times. | |||
304 | SmallPtrSet<const Value *, 32> GlobalValueVisited; | |||
305 | ||||
306 | // Keeps track of duplicate function argument debug info. | |||
307 | SmallVector<const DILocalVariable *, 16> DebugFnArgs; | |||
308 | ||||
309 | TBAAVerifier TBAAVerifyHelper; | |||
310 | ||||
311 | void checkAtomicMemAccessSize(Type *Ty, const Instruction *I); | |||
312 | ||||
313 | public: | |||
314 | explicit Verifier(raw_ostream *OS, bool ShouldTreatBrokenDebugInfoAsError, | |||
315 | const Module &M) | |||
316 | : VerifierSupport(OS, M), LandingPadResultTy(nullptr), | |||
317 | SawFrameEscape(false), TBAAVerifyHelper(this) { | |||
318 | TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError; | |||
319 | } | |||
320 | ||||
321 | bool hasBrokenDebugInfo() const { return BrokenDebugInfo; } | |||
322 | ||||
323 | bool verify(const Function &F) { | |||
324 | assert(F.getParent() == &M &&((F.getParent() == &M && "An instance of this class only works with a specific module!" ) ? static_cast<void> (0) : __assert_fail ("F.getParent() == &M && \"An instance of this class only works with a specific module!\"" , "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/IR/Verifier.cpp" , 325, __PRETTY_FUNCTION__)) | |||
325 | "An instance of this class only works with a specific module!")((F.getParent() == &M && "An instance of this class only works with a specific module!" ) ? static_cast<void> (0) : __assert_fail ("F.getParent() == &M && \"An instance of this class only works with a specific module!\"" , "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/IR/Verifier.cpp" , 325, __PRETTY_FUNCTION__)); | |||
326 | ||||
327 | // First ensure the function is well-enough formed to compute dominance | |||
328 | // information, and directly compute a dominance tree. We don't rely on the | |||
329 | // pass manager to provide this as it isolates us from a potentially | |||
330 | // out-of-date dominator tree and makes it significantly more complex to run | |||
331 | // this code outside of a pass manager. | |||
332 | // FIXME: It's really gross that we have to cast away constness here. | |||
333 | if (!F.empty()) | |||
334 | DT.recalculate(const_cast<Function &>(F)); | |||
335 | ||||
336 | for (const BasicBlock &BB : F) { | |||
337 | if (!BB.empty() && BB.back().isTerminator()) | |||
338 | continue; | |||
339 | ||||
340 | if (OS) { | |||
341 | *OS << "Basic Block in function '" << F.getName() | |||
342 | << "' does not have terminator!\n"; | |||
343 | BB.printAsOperand(*OS, true, MST); | |||
344 | *OS << "\n"; | |||
345 | } | |||
346 | return false; | |||
347 | } | |||
348 | ||||
349 | Broken = false; | |||
350 | // FIXME: We strip const here because the inst visitor strips const. | |||
351 | visit(const_cast<Function &>(F)); | |||
352 | verifySiblingFuncletUnwinds(); | |||
353 | InstsInThisBlock.clear(); | |||
354 | DebugFnArgs.clear(); | |||
355 | LandingPadResultTy = nullptr; | |||
356 | SawFrameEscape = false; | |||
357 | SiblingFuncletInfo.clear(); | |||
358 | ||||
359 | return !Broken; | |||
360 | } | |||
361 | ||||
362 | /// Verify the module that this instance of \c Verifier was initialized with. | |||
363 | bool verify() { | |||
364 | Broken = false; | |||
365 | ||||
366 | // Collect all declarations of the llvm.experimental.deoptimize intrinsic. | |||
367 | for (const Function &F : M) | |||
368 | if (F.getIntrinsicID() == Intrinsic::experimental_deoptimize) | |||
369 | DeoptimizeDeclarations.push_back(&F); | |||
370 | ||||
371 | // Now that we've visited every function, verify that we never asked to | |||
372 | // recover a frame index that wasn't escaped. | |||
373 | verifyFrameRecoverIndices(); | |||
374 | for (const GlobalVariable &GV : M.globals()) | |||
375 | visitGlobalVariable(GV); | |||
376 | ||||
377 | for (const GlobalAlias &GA : M.aliases()) | |||
378 | visitGlobalAlias(GA); | |||
379 | ||||
380 | for (const NamedMDNode &NMD : M.named_metadata()) | |||
381 | visitNamedMDNode(NMD); | |||
382 | ||||
383 | for (const StringMapEntry<Comdat> &SMEC : M.getComdatSymbolTable()) | |||
384 | visitComdat(SMEC.getValue()); | |||
385 | ||||
386 | visitModuleFlags(M); | |||
387 | visitModuleIdents(M); | |||
388 | visitModuleCommandLines(M); | |||
389 | ||||
390 | verifyCompileUnits(); | |||
391 | ||||
392 | verifyDeoptimizeCallingConvs(); | |||
393 | DISubprogramAttachments.clear(); | |||
394 | return !Broken; | |||
395 | } | |||
396 | ||||
397 | private: | |||
398 | // Verification methods... | |||
399 | void visitGlobalValue(const GlobalValue &GV); | |||
400 | void visitGlobalVariable(const GlobalVariable &GV); | |||
401 | void visitGlobalAlias(const GlobalAlias &GA); | |||
402 | void visitAliaseeSubExpr(const GlobalAlias &A, const Constant &C); | |||
403 | void visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias *> &Visited, | |||
404 | const GlobalAlias &A, const Constant &C); | |||
405 | void visitNamedMDNode(const NamedMDNode &NMD); | |||
406 | void visitMDNode(const MDNode &MD); | |||
407 | void visitMetadataAsValue(const MetadataAsValue &MD, Function *F); | |||
408 | void visitValueAsMetadata(const ValueAsMetadata &MD, Function *F); | |||
409 | void visitComdat(const Comdat &C); | |||
410 | void visitModuleIdents(const Module &M); | |||
411 | void visitModuleCommandLines(const Module &M); | |||
412 | void visitModuleFlags(const Module &M); | |||
413 | void visitModuleFlag(const MDNode *Op, | |||
414 | DenseMap<const MDString *, const MDNode *> &SeenIDs, | |||
415 | SmallVectorImpl<const MDNode *> &Requirements); | |||
416 | void visitModuleFlagCGProfileEntry(const MDOperand &MDO); | |||
417 | void visitFunction(const Function &F); | |||
418 | void visitBasicBlock(BasicBlock &BB); | |||
419 | void visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty); | |||
420 | void visitDereferenceableMetadata(Instruction &I, MDNode *MD); | |||
421 | void visitProfMetadata(Instruction &I, MDNode *MD); | |||
422 | ||||
423 | template <class Ty> bool isValidMetadataArray(const MDTuple &N); | |||
424 | #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N); | |||
425 | #include "llvm/IR/Metadata.def" | |||
426 | void visitDIScope(const DIScope &N); | |||
427 | void visitDIVariable(const DIVariable &N); | |||
428 | void visitDILexicalBlockBase(const DILexicalBlockBase &N); | |||
429 | void visitDITemplateParameter(const DITemplateParameter &N); | |||
430 | ||||
431 | void visitTemplateParams(const MDNode &N, const Metadata &RawParams); | |||
432 | ||||
433 | // InstVisitor overrides... | |||
434 | using InstVisitor<Verifier>::visit; | |||
435 | void visit(Instruction &I); | |||
436 | ||||
437 | void visitTruncInst(TruncInst &I); | |||
438 | void visitZExtInst(ZExtInst &I); | |||
439 | void visitSExtInst(SExtInst &I); | |||
440 | void visitFPTruncInst(FPTruncInst &I); | |||
441 | void visitFPExtInst(FPExtInst &I); | |||
442 | void visitFPToUIInst(FPToUIInst &I); | |||
443 | void visitFPToSIInst(FPToSIInst &I); | |||
444 | void visitUIToFPInst(UIToFPInst &I); | |||
445 | void visitSIToFPInst(SIToFPInst &I); | |||
446 | void visitIntToPtrInst(IntToPtrInst &I); | |||
447 | void visitPtrToIntInst(PtrToIntInst &I); | |||
448 | void visitBitCastInst(BitCastInst &I); | |||
449 | void visitAddrSpaceCastInst(AddrSpaceCastInst &I); | |||
450 | void visitPHINode(PHINode &PN); | |||
451 | void visitCallBase(CallBase &Call); | |||
452 | void visitUnaryOperator(UnaryOperator &U); | |||
453 | void visitBinaryOperator(BinaryOperator &B); | |||
454 | void visitICmpInst(ICmpInst &IC); | |||
455 | void visitFCmpInst(FCmpInst &FC); | |||
456 | void visitExtractElementInst(ExtractElementInst &EI); | |||
457 | void visitInsertElementInst(InsertElementInst &EI); | |||
458 | void visitShuffleVectorInst(ShuffleVectorInst &EI); | |||
459 | void visitVAArgInst(VAArgInst &VAA) { visitInstruction(VAA); } | |||
460 | void visitCallInst(CallInst &CI); | |||
461 | void visitInvokeInst(InvokeInst &II); | |||
462 | void visitGetElementPtrInst(GetElementPtrInst &GEP); | |||
463 | void visitLoadInst(LoadInst &LI); | |||
464 | void visitStoreInst(StoreInst &SI); | |||
465 | void verifyDominatesUse(Instruction &I, unsigned i); | |||
466 | void visitInstruction(Instruction &I); | |||
467 | void visitTerminator(Instruction &I); | |||
468 | void visitBranchInst(BranchInst &BI); | |||
469 | void visitReturnInst(ReturnInst &RI); | |||
470 | void visitSwitchInst(SwitchInst &SI); | |||
471 | void visitIndirectBrInst(IndirectBrInst &BI); | |||
472 | void visitCallBrInst(CallBrInst &CBI); | |||
473 | void visitSelectInst(SelectInst &SI); | |||
474 | void visitUserOp1(Instruction &I); | |||
475 | void visitUserOp2(Instruction &I) { visitUserOp1(I); } | |||
476 | void visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call); | |||
477 | void visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI); | |||
478 | void visitDbgIntrinsic(StringRef Kind, DbgVariableIntrinsic &DII); | |||
479 | void visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI); | |||
480 | void visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI); | |||
481 | void visitAtomicRMWInst(AtomicRMWInst &RMWI); | |||
482 | void visitFenceInst(FenceInst &FI); | |||
483 | void visitAllocaInst(AllocaInst &AI); | |||
484 | void visitExtractValueInst(ExtractValueInst &EVI); | |||
485 | void visitInsertValueInst(InsertValueInst &IVI); | |||
486 | void visitEHPadPredecessors(Instruction &I); | |||
487 | void visitLandingPadInst(LandingPadInst &LPI); | |||
488 | void visitResumeInst(ResumeInst &RI); | |||
489 | void visitCatchPadInst(CatchPadInst &CPI); | |||
490 | void visitCatchReturnInst(CatchReturnInst &CatchReturn); | |||
491 | void visitCleanupPadInst(CleanupPadInst &CPI); | |||
492 | void visitFuncletPadInst(FuncletPadInst &FPI); | |||
493 | void visitCatchSwitchInst(CatchSwitchInst &CatchSwitch); | |||
494 | void visitCleanupReturnInst(CleanupReturnInst &CRI); | |||
495 | ||||
496 | void verifySwiftErrorCall(CallBase &Call, const Value *SwiftErrorVal); | |||
497 | void verifySwiftErrorValue(const Value *SwiftErrorVal); | |||
498 | void verifyMustTailCall(CallInst &CI); | |||
499 | bool performTypeCheck(Intrinsic::ID ID, Function *F, Type *Ty, int VT, | |||
500 | unsigned ArgNo, std::string &Suffix); | |||
501 | bool verifyAttributeCount(AttributeList Attrs, unsigned Params); | |||
502 | void verifyAttributeTypes(AttributeSet Attrs, bool IsFunction, | |||
503 | const Value *V); | |||
504 | void verifyParameterAttrs(AttributeSet Attrs, Type *Ty, const Value *V); | |||
505 | void verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs, | |||
506 | const Value *V, bool IsIntrinsic); | |||
507 | void verifyFunctionMetadata(ArrayRef<std::pair<unsigned, MDNode *>> MDs); | |||
508 | ||||
509 | void visitConstantExprsRecursively(const Constant *EntryC); | |||
510 | void visitConstantExpr(const ConstantExpr *CE); | |||
511 | void verifyStatepoint(const CallBase &Call); | |||
512 | void verifyFrameRecoverIndices(); | |||
513 | void verifySiblingFuncletUnwinds(); | |||
514 | ||||
515 | void verifyFragmentExpression(const DbgVariableIntrinsic &I); | |||
516 | template <typename ValueOrMetadata> | |||
517 | void verifyFragmentExpression(const DIVariable &V, | |||
518 | DIExpression::FragmentInfo Fragment, | |||
519 | ValueOrMetadata *Desc); | |||
520 | void verifyFnArgs(const DbgVariableIntrinsic &I); | |||
521 | void verifyNotEntryValue(const DbgVariableIntrinsic &I); | |||
522 | ||||
523 | /// Module-level debug info verification... | |||
524 | void verifyCompileUnits(); | |||
525 | ||||
526 | /// Module-level verification that all @llvm.experimental.deoptimize | |||
527 | /// declarations share the same calling convention. | |||
528 | void verifyDeoptimizeCallingConvs(); | |||
529 | ||||
530 | /// Verify all-or-nothing property of DIFile source attribute within a CU. | |||
531 | void verifySourceDebugInfo(const DICompileUnit &U, const DIFile &F); | |||
532 | }; | |||
533 | ||||
534 | } // end anonymous namespace | |||
535 | ||||
536 | /// We know that cond should be true, if not print an error message. | |||
537 | #define Assert(C, ...)do { if (!(C)) { CheckFailed(...); return; } } while (false) \ | |||
538 | do { if (!(C)) { CheckFailed(__VA_ARGS__); return; } } while (false) | |||
539 | ||||
540 | /// We know that a debug info condition should be true, if not print | |||
541 | /// an error message. | |||
542 | #define AssertDI(C, ...)do { if (!(C)) { DebugInfoCheckFailed(...); return; } } while (false) \ | |||
543 | do { if (!(C)) { DebugInfoCheckFailed(__VA_ARGS__); return; } } while (false) | |||
544 | ||||
545 | void Verifier::visit(Instruction &I) { | |||
546 | for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) | |||
547 | Assert(I.getOperand(i) != nullptr, "Operand is null", &I)do { if (!(I.getOperand(i) != nullptr)) { CheckFailed("Operand is null" , &I); return; } } while (false); | |||
548 | InstVisitor<Verifier>::visit(I); | |||
549 | } | |||
550 | ||||
551 | // Helper to recursively iterate over indirect users. By | |||
552 | // returning false, the callback can ask to stop recursing | |||
553 | // further. | |||
554 | static void forEachUser(const Value *User, | |||
555 | SmallPtrSet<const Value *, 32> &Visited, | |||
556 | llvm::function_ref<bool(const Value *)> Callback) { | |||
557 | if (!Visited.insert(User).second) | |||
558 | return; | |||
559 | for (const Value *TheNextUser : User->materialized_users()) | |||
560 | if (Callback(TheNextUser)) | |||
561 | forEachUser(TheNextUser, Visited, Callback); | |||
562 | } | |||
563 | ||||
564 | void Verifier::visitGlobalValue(const GlobalValue &GV) { | |||
565 | Assert(!GV.isDeclaration() || GV.hasValidDeclarationLinkage(),do { if (!(!GV.isDeclaration() || GV.hasValidDeclarationLinkage ())) { CheckFailed("Global is external, but doesn't have external or weak linkage!" , &GV); return; } } while (false) | |||
566 | "Global is external, but doesn't have external or weak linkage!", &GV)do { if (!(!GV.isDeclaration() || GV.hasValidDeclarationLinkage ())) { CheckFailed("Global is external, but doesn't have external or weak linkage!" , &GV); return; } } while (false); | |||
567 | ||||
568 | Assert(GV.getAlignment() <= Value::MaximumAlignment,do { if (!(GV.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &GV ); return; } } while (false) | |||
569 | "huge alignment values are unsupported", &GV)do { if (!(GV.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &GV ); return; } } while (false); | |||
570 | Assert(!GV.hasAppendingLinkage() || isa<GlobalVariable>(GV),do { if (!(!GV.hasAppendingLinkage() || isa<GlobalVariable >(GV))) { CheckFailed("Only global variables can have appending linkage!" , &GV); return; } } while (false) | |||
571 | "Only global variables can have appending linkage!", &GV)do { if (!(!GV.hasAppendingLinkage() || isa<GlobalVariable >(GV))) { CheckFailed("Only global variables can have appending linkage!" , &GV); return; } } while (false); | |||
572 | ||||
573 | if (GV.hasAppendingLinkage()) { | |||
574 | const GlobalVariable *GVar = dyn_cast<GlobalVariable>(&GV); | |||
575 | Assert(GVar && GVar->getValueType()->isArrayTy(),do { if (!(GVar && GVar->getValueType()->isArrayTy ())) { CheckFailed("Only global arrays can have appending linkage!" , GVar); return; } } while (false) | |||
576 | "Only global arrays can have appending linkage!", GVar)do { if (!(GVar && GVar->getValueType()->isArrayTy ())) { CheckFailed("Only global arrays can have appending linkage!" , GVar); return; } } while (false); | |||
577 | } | |||
578 | ||||
579 | if (GV.isDeclarationForLinker()) | |||
580 | Assert(!GV.hasComdat(), "Declaration may not be in a Comdat!", &GV)do { if (!(!GV.hasComdat())) { CheckFailed("Declaration may not be in a Comdat!" , &GV); return; } } while (false); | |||
581 | ||||
582 | if (GV.hasDLLImportStorageClass()) { | |||
583 | Assert(!GV.isDSOLocal(),do { if (!(!GV.isDSOLocal())) { CheckFailed("GlobalValue with DLLImport Storage is dso_local!" , &GV); return; } } while (false) | |||
584 | "GlobalValue with DLLImport Storage is dso_local!", &GV)do { if (!(!GV.isDSOLocal())) { CheckFailed("GlobalValue with DLLImport Storage is dso_local!" , &GV); return; } } while (false); | |||
585 | ||||
586 | Assert((GV.isDeclaration() && GV.hasExternalLinkage()) ||do { if (!((GV.isDeclaration() && GV.hasExternalLinkage ()) || GV.hasAvailableExternallyLinkage())) { CheckFailed("Global is marked as dllimport, but not external" , &GV); return; } } while (false) | |||
587 | GV.hasAvailableExternallyLinkage(),do { if (!((GV.isDeclaration() && GV.hasExternalLinkage ()) || GV.hasAvailableExternallyLinkage())) { CheckFailed("Global is marked as dllimport, but not external" , &GV); return; } } while (false) | |||
588 | "Global is marked as dllimport, but not external", &GV)do { if (!((GV.isDeclaration() && GV.hasExternalLinkage ()) || GV.hasAvailableExternallyLinkage())) { CheckFailed("Global is marked as dllimport, but not external" , &GV); return; } } while (false); | |||
589 | } | |||
590 | ||||
591 | if (GV.hasLocalLinkage()) | |||
592 | Assert(GV.isDSOLocal(),do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with private or internal linkage must be dso_local!" , &GV); return; } } while (false) | |||
593 | "GlobalValue with private or internal linkage must be dso_local!",do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with private or internal linkage must be dso_local!" , &GV); return; } } while (false) | |||
594 | &GV)do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with private or internal linkage must be dso_local!" , &GV); return; } } while (false); | |||
595 | ||||
596 | if (!GV.hasDefaultVisibility() && !GV.hasExternalWeakLinkage()) | |||
597 | Assert(GV.isDSOLocal(),do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with non default visibility must be dso_local!" , &GV); return; } } while (false) | |||
598 | "GlobalValue with non default visibility must be dso_local!", &GV)do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with non default visibility must be dso_local!" , &GV); return; } } while (false); | |||
599 | ||||
600 | forEachUser(&GV, GlobalValueVisited, [&](const Value *V) -> bool { | |||
601 | if (const Instruction *I = dyn_cast<Instruction>(V)) { | |||
602 | if (!I->getParent() || !I->getParent()->getParent()) | |||
603 | CheckFailed("Global is referenced by parentless instruction!", &GV, &M, | |||
604 | I); | |||
605 | else if (I->getParent()->getParent()->getParent() != &M) | |||
606 | CheckFailed("Global is referenced in a different module!", &GV, &M, I, | |||
607 | I->getParent()->getParent(), | |||
608 | I->getParent()->getParent()->getParent()); | |||
609 | return false; | |||
610 | } else if (const Function *F = dyn_cast<Function>(V)) { | |||
611 | if (F->getParent() != &M) | |||
612 | CheckFailed("Global is used by function in a different module", &GV, &M, | |||
613 | F, F->getParent()); | |||
614 | return false; | |||
615 | } | |||
616 | return true; | |||
617 | }); | |||
618 | } | |||
619 | ||||
620 | void Verifier::visitGlobalVariable(const GlobalVariable &GV) { | |||
621 | if (GV.hasInitializer()) { | |||
622 | Assert(GV.getInitializer()->getType() == GV.getValueType(),do { if (!(GV.getInitializer()->getType() == GV.getValueType ())) { CheckFailed("Global variable initializer type does not match global " "variable type!", &GV); return; } } while (false) | |||
623 | "Global variable initializer type does not match global "do { if (!(GV.getInitializer()->getType() == GV.getValueType ())) { CheckFailed("Global variable initializer type does not match global " "variable type!", &GV); return; } } while (false) | |||
624 | "variable type!",do { if (!(GV.getInitializer()->getType() == GV.getValueType ())) { CheckFailed("Global variable initializer type does not match global " "variable type!", &GV); return; } } while (false) | |||
625 | &GV)do { if (!(GV.getInitializer()->getType() == GV.getValueType ())) { CheckFailed("Global variable initializer type does not match global " "variable type!", &GV); return; } } while (false); | |||
626 | // If the global has common linkage, it must have a zero initializer and | |||
627 | // cannot be constant. | |||
628 | if (GV.hasCommonLinkage()) { | |||
629 | Assert(GV.getInitializer()->isNullValue(),do { if (!(GV.getInitializer()->isNullValue())) { CheckFailed ("'common' global must have a zero initializer!", &GV); return ; } } while (false) | |||
630 | "'common' global must have a zero initializer!", &GV)do { if (!(GV.getInitializer()->isNullValue())) { CheckFailed ("'common' global must have a zero initializer!", &GV); return ; } } while (false); | |||
631 | Assert(!GV.isConstant(), "'common' global may not be marked constant!",do { if (!(!GV.isConstant())) { CheckFailed("'common' global may not be marked constant!" , &GV); return; } } while (false) | |||
632 | &GV)do { if (!(!GV.isConstant())) { CheckFailed("'common' global may not be marked constant!" , &GV); return; } } while (false); | |||
633 | Assert(!GV.hasComdat(), "'common' global may not be in a Comdat!", &GV)do { if (!(!GV.hasComdat())) { CheckFailed("'common' global may not be in a Comdat!" , &GV); return; } } while (false); | |||
634 | } | |||
635 | } | |||
636 | ||||
637 | if (GV.hasName() && (GV.getName() == "llvm.global_ctors" || | |||
638 | GV.getName() == "llvm.global_dtors")) { | |||
639 | Assert(!GV.hasInitializer() || GV.hasAppendingLinkage(),do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage())) { CheckFailed("invalid linkage for intrinsic global variable" , &GV); return; } } while (false) | |||
640 | "invalid linkage for intrinsic global variable", &GV)do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage())) { CheckFailed("invalid linkage for intrinsic global variable" , &GV); return; } } while (false); | |||
641 | // Don't worry about emitting an error for it not being an array, | |||
642 | // visitGlobalValue will complain on appending non-array. | |||
643 | if (ArrayType *ATy = dyn_cast<ArrayType>(GV.getValueType())) { | |||
644 | StructType *STy = dyn_cast<StructType>(ATy->getElementType()); | |||
645 | PointerType *FuncPtrTy = | |||
646 | FunctionType::get(Type::getVoidTy(Context), false)-> | |||
647 | getPointerTo(DL.getProgramAddressSpace()); | |||
648 | Assert(STy &&do { if (!(STy && (STy->getNumElements() == 2 || STy ->getNumElements() == 3) && STy->getTypeAtIndex (0u)->isIntegerTy(32) && STy->getTypeAtIndex(1) == FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable" , &GV); return; } } while (false) | |||
649 | (STy->getNumElements() == 2 || STy->getNumElements() == 3) &&do { if (!(STy && (STy->getNumElements() == 2 || STy ->getNumElements() == 3) && STy->getTypeAtIndex (0u)->isIntegerTy(32) && STy->getTypeAtIndex(1) == FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable" , &GV); return; } } while (false) | |||
650 | STy->getTypeAtIndex(0u)->isIntegerTy(32) &&do { if (!(STy && (STy->getNumElements() == 2 || STy ->getNumElements() == 3) && STy->getTypeAtIndex (0u)->isIntegerTy(32) && STy->getTypeAtIndex(1) == FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable" , &GV); return; } } while (false) | |||
651 | STy->getTypeAtIndex(1) == FuncPtrTy,do { if (!(STy && (STy->getNumElements() == 2 || STy ->getNumElements() == 3) && STy->getTypeAtIndex (0u)->isIntegerTy(32) && STy->getTypeAtIndex(1) == FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable" , &GV); return; } } while (false) | |||
652 | "wrong type for intrinsic global variable", &GV)do { if (!(STy && (STy->getNumElements() == 2 || STy ->getNumElements() == 3) && STy->getTypeAtIndex (0u)->isIntegerTy(32) && STy->getTypeAtIndex(1) == FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable" , &GV); return; } } while (false); | |||
653 | Assert(STy->getNumElements() == 3,do { if (!(STy->getNumElements() == 3)) { CheckFailed("the third field of the element type is mandatory, " "specify i8* null to migrate from the obsoleted 2-field form" ); return; } } while (false) | |||
654 | "the third field of the element type is mandatory, "do { if (!(STy->getNumElements() == 3)) { CheckFailed("the third field of the element type is mandatory, " "specify i8* null to migrate from the obsoleted 2-field form" ); return; } } while (false) | |||
655 | "specify i8* null to migrate from the obsoleted 2-field form")do { if (!(STy->getNumElements() == 3)) { CheckFailed("the third field of the element type is mandatory, " "specify i8* null to migrate from the obsoleted 2-field form" ); return; } } while (false); | |||
656 | Type *ETy = STy->getTypeAtIndex(2); | |||
657 | Assert(ETy->isPointerTy() &&do { if (!(ETy->isPointerTy() && cast<PointerType >(ETy)->getElementType()->isIntegerTy(8))) { CheckFailed ("wrong type for intrinsic global variable", &GV); return ; } } while (false) | |||
658 | cast<PointerType>(ETy)->getElementType()->isIntegerTy(8),do { if (!(ETy->isPointerTy() && cast<PointerType >(ETy)->getElementType()->isIntegerTy(8))) { CheckFailed ("wrong type for intrinsic global variable", &GV); return ; } } while (false) | |||
659 | "wrong type for intrinsic global variable", &GV)do { if (!(ETy->isPointerTy() && cast<PointerType >(ETy)->getElementType()->isIntegerTy(8))) { CheckFailed ("wrong type for intrinsic global variable", &GV); return ; } } while (false); | |||
660 | } | |||
661 | } | |||
662 | ||||
663 | if (GV.hasName() && (GV.getName() == "llvm.used" || | |||
664 | GV.getName() == "llvm.compiler.used")) { | |||
665 | Assert(!GV.hasInitializer() || GV.hasAppendingLinkage(),do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage())) { CheckFailed("invalid linkage for intrinsic global variable" , &GV); return; } } while (false) | |||
666 | "invalid linkage for intrinsic global variable", &GV)do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage())) { CheckFailed("invalid linkage for intrinsic global variable" , &GV); return; } } while (false); | |||
667 | Type *GVType = GV.getValueType(); | |||
668 | if (ArrayType *ATy = dyn_cast<ArrayType>(GVType)) { | |||
669 | PointerType *PTy = dyn_cast<PointerType>(ATy->getElementType()); | |||
670 | Assert(PTy, "wrong type for intrinsic global variable", &GV)do { if (!(PTy)) { CheckFailed("wrong type for intrinsic global variable" , &GV); return; } } while (false); | |||
671 | if (GV.hasInitializer()) { | |||
672 | const Constant *Init = GV.getInitializer(); | |||
673 | const ConstantArray *InitArray = dyn_cast<ConstantArray>(Init); | |||
674 | Assert(InitArray, "wrong initalizer for intrinsic global variable",do { if (!(InitArray)) { CheckFailed("wrong initalizer for intrinsic global variable" , Init); return; } } while (false) | |||
675 | Init)do { if (!(InitArray)) { CheckFailed("wrong initalizer for intrinsic global variable" , Init); return; } } while (false); | |||
676 | for (Value *Op : InitArray->operands()) { | |||
677 | Value *V = Op->stripPointerCasts(); | |||
678 | Assert(isa<GlobalVariable>(V) || isa<Function>(V) ||do { if (!(isa<GlobalVariable>(V) || isa<Function> (V) || isa<GlobalAlias>(V))) { CheckFailed("invalid llvm.used member" , V); return; } } while (false) | |||
679 | isa<GlobalAlias>(V),do { if (!(isa<GlobalVariable>(V) || isa<Function> (V) || isa<GlobalAlias>(V))) { CheckFailed("invalid llvm.used member" , V); return; } } while (false) | |||
680 | "invalid llvm.used member", V)do { if (!(isa<GlobalVariable>(V) || isa<Function> (V) || isa<GlobalAlias>(V))) { CheckFailed("invalid llvm.used member" , V); return; } } while (false); | |||
681 | Assert(V->hasName(), "members of llvm.used must be named", V)do { if (!(V->hasName())) { CheckFailed("members of llvm.used must be named" , V); return; } } while (false); | |||
682 | } | |||
683 | } | |||
684 | } | |||
685 | } | |||
686 | ||||
687 | // Visit any debug info attachments. | |||
688 | SmallVector<MDNode *, 1> MDs; | |||
689 | GV.getMetadata(LLVMContext::MD_dbg, MDs); | |||
690 | for (auto *MD : MDs) { | |||
691 | if (auto *GVE = dyn_cast<DIGlobalVariableExpression>(MD)) | |||
692 | visitDIGlobalVariableExpression(*GVE); | |||
693 | else | |||
694 | AssertDI(false, "!dbg attachment of global variable must be a "do { if (!(false)) { DebugInfoCheckFailed("!dbg attachment of global variable must be a " "DIGlobalVariableExpression"); return; } } while (false) | |||
695 | "DIGlobalVariableExpression")do { if (!(false)) { DebugInfoCheckFailed("!dbg attachment of global variable must be a " "DIGlobalVariableExpression"); return; } } while (false); | |||
696 | } | |||
697 | ||||
698 | // Scalable vectors cannot be global variables, since we don't know | |||
699 | // the runtime size. If the global is a struct or an array containing | |||
700 | // scalable vectors, that will be caught by the isValidElementType methods | |||
701 | // in StructType or ArrayType instead. | |||
702 | if (auto *VTy = dyn_cast<VectorType>(GV.getValueType())) | |||
703 | Assert(!VTy->isScalable(), "Globals cannot contain scalable vectors", &GV)do { if (!(!VTy->isScalable())) { CheckFailed("Globals cannot contain scalable vectors" , &GV); return; } } while (false); | |||
704 | ||||
705 | if (!GV.hasInitializer()) { | |||
706 | visitGlobalValue(GV); | |||
707 | return; | |||
708 | } | |||
709 | ||||
710 | // Walk any aggregate initializers looking for bitcasts between address spaces | |||
711 | visitConstantExprsRecursively(GV.getInitializer()); | |||
712 | ||||
713 | visitGlobalValue(GV); | |||
714 | } | |||
715 | ||||
716 | void Verifier::visitAliaseeSubExpr(const GlobalAlias &GA, const Constant &C) { | |||
717 | SmallPtrSet<const GlobalAlias*, 4> Visited; | |||
718 | Visited.insert(&GA); | |||
719 | visitAliaseeSubExpr(Visited, GA, C); | |||
720 | } | |||
721 | ||||
722 | void Verifier::visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias*> &Visited, | |||
723 | const GlobalAlias &GA, const Constant &C) { | |||
724 | if (const auto *GV = dyn_cast<GlobalValue>(&C)) { | |||
725 | Assert(!GV->isDeclarationForLinker(), "Alias must point to a definition",do { if (!(!GV->isDeclarationForLinker())) { CheckFailed("Alias must point to a definition" , &GA); return; } } while (false) | |||
726 | &GA)do { if (!(!GV->isDeclarationForLinker())) { CheckFailed("Alias must point to a definition" , &GA); return; } } while (false); | |||
727 | ||||
728 | if (const auto *GA2 = dyn_cast<GlobalAlias>(GV)) { | |||
729 | Assert(Visited.insert(GA2).second, "Aliases cannot form a cycle", &GA)do { if (!(Visited.insert(GA2).second)) { CheckFailed("Aliases cannot form a cycle" , &GA); return; } } while (false); | |||
730 | ||||
731 | Assert(!GA2->isInterposable(), "Alias cannot point to an interposable alias",do { if (!(!GA2->isInterposable())) { CheckFailed("Alias cannot point to an interposable alias" , &GA); return; } } while (false) | |||
732 | &GA)do { if (!(!GA2->isInterposable())) { CheckFailed("Alias cannot point to an interposable alias" , &GA); return; } } while (false); | |||
733 | } else { | |||
734 | // Only continue verifying subexpressions of GlobalAliases. | |||
735 | // Do not recurse into global initializers. | |||
736 | return; | |||
737 | } | |||
738 | } | |||
739 | ||||
740 | if (const auto *CE = dyn_cast<ConstantExpr>(&C)) | |||
741 | visitConstantExprsRecursively(CE); | |||
742 | ||||
743 | for (const Use &U : C.operands()) { | |||
744 | Value *V = &*U; | |||
745 | if (const auto *GA2 = dyn_cast<GlobalAlias>(V)) | |||
746 | visitAliaseeSubExpr(Visited, GA, *GA2->getAliasee()); | |||
747 | else if (const auto *C2 = dyn_cast<Constant>(V)) | |||
748 | visitAliaseeSubExpr(Visited, GA, *C2); | |||
749 | } | |||
750 | } | |||
751 | ||||
752 | void Verifier::visitGlobalAlias(const GlobalAlias &GA) { | |||
753 | Assert(GlobalAlias::isValidLinkage(GA.getLinkage()),do { if (!(GlobalAlias::isValidLinkage(GA.getLinkage()))) { CheckFailed ("Alias should have private, internal, linkonce, weak, linkonce_odr, " "weak_odr, or external linkage!", &GA); return; } } while (false) | |||
754 | "Alias should have private, internal, linkonce, weak, linkonce_odr, "do { if (!(GlobalAlias::isValidLinkage(GA.getLinkage()))) { CheckFailed ("Alias should have private, internal, linkonce, weak, linkonce_odr, " "weak_odr, or external linkage!", &GA); return; } } while (false) | |||
755 | "weak_odr, or external linkage!",do { if (!(GlobalAlias::isValidLinkage(GA.getLinkage()))) { CheckFailed ("Alias should have private, internal, linkonce, weak, linkonce_odr, " "weak_odr, or external linkage!", &GA); return; } } while (false) | |||
756 | &GA)do { if (!(GlobalAlias::isValidLinkage(GA.getLinkage()))) { CheckFailed ("Alias should have private, internal, linkonce, weak, linkonce_odr, " "weak_odr, or external linkage!", &GA); return; } } while (false); | |||
757 | const Constant *Aliasee = GA.getAliasee(); | |||
758 | Assert(Aliasee, "Aliasee cannot be NULL!", &GA)do { if (!(Aliasee)) { CheckFailed("Aliasee cannot be NULL!", &GA); return; } } while (false); | |||
759 | Assert(GA.getType() == Aliasee->getType(),do { if (!(GA.getType() == Aliasee->getType())) { CheckFailed ("Alias and aliasee types should match!", &GA); return; } } while (false) | |||
760 | "Alias and aliasee types should match!", &GA)do { if (!(GA.getType() == Aliasee->getType())) { CheckFailed ("Alias and aliasee types should match!", &GA); return; } } while (false); | |||
761 | ||||
762 | Assert(isa<GlobalValue>(Aliasee) || isa<ConstantExpr>(Aliasee),do { if (!(isa<GlobalValue>(Aliasee) || isa<ConstantExpr >(Aliasee))) { CheckFailed("Aliasee should be either GlobalValue or ConstantExpr" , &GA); return; } } while (false) | |||
763 | "Aliasee should be either GlobalValue or ConstantExpr", &GA)do { if (!(isa<GlobalValue>(Aliasee) || isa<ConstantExpr >(Aliasee))) { CheckFailed("Aliasee should be either GlobalValue or ConstantExpr" , &GA); return; } } while (false); | |||
764 | ||||
765 | visitAliaseeSubExpr(GA, *Aliasee); | |||
766 | ||||
767 | visitGlobalValue(GA); | |||
768 | } | |||
769 | ||||
770 | void Verifier::visitNamedMDNode(const NamedMDNode &NMD) { | |||
771 | // There used to be various other llvm.dbg.* nodes, but we don't support | |||
772 | // upgrading them and we want to reserve the namespace for future uses. | |||
773 | if (NMD.getName().startswith("llvm.dbg.")) | |||
774 | AssertDI(NMD.getName() == "llvm.dbg.cu",do { if (!(NMD.getName() == "llvm.dbg.cu")) { DebugInfoCheckFailed ("unrecognized named metadata node in the llvm.dbg namespace" , &NMD); return; } } while (false) | |||
775 | "unrecognized named metadata node in the llvm.dbg namespace",do { if (!(NMD.getName() == "llvm.dbg.cu")) { DebugInfoCheckFailed ("unrecognized named metadata node in the llvm.dbg namespace" , &NMD); return; } } while (false) | |||
776 | &NMD)do { if (!(NMD.getName() == "llvm.dbg.cu")) { DebugInfoCheckFailed ("unrecognized named metadata node in the llvm.dbg namespace" , &NMD); return; } } while (false); | |||
777 | for (const MDNode *MD : NMD.operands()) { | |||
778 | if (NMD.getName() == "llvm.dbg.cu") | |||
779 | AssertDI(MD && isa<DICompileUnit>(MD), "invalid compile unit", &NMD, MD)do { if (!(MD && isa<DICompileUnit>(MD))) { DebugInfoCheckFailed ("invalid compile unit", &NMD, MD); return; } } while (false ); | |||
780 | ||||
781 | if (!MD) | |||
782 | continue; | |||
783 | ||||
784 | visitMDNode(*MD); | |||
785 | } | |||
786 | } | |||
787 | ||||
788 | void Verifier::visitMDNode(const MDNode &MD) { | |||
789 | // Only visit each node once. Metadata can be mutually recursive, so this | |||
790 | // avoids infinite recursion here, as well as being an optimization. | |||
791 | if (!MDNodes.insert(&MD).second) | |||
792 | return; | |||
793 | ||||
794 | switch (MD.getMetadataID()) { | |||
795 | default: | |||
796 | llvm_unreachable("Invalid MDNode subclass")::llvm::llvm_unreachable_internal("Invalid MDNode subclass", "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/IR/Verifier.cpp" , 796); | |||
797 | case Metadata::MDTupleKind: | |||
798 | break; | |||
799 | #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \ | |||
800 | case Metadata::CLASS##Kind: \ | |||
801 | visit##CLASS(cast<CLASS>(MD)); \ | |||
802 | break; | |||
803 | #include "llvm/IR/Metadata.def" | |||
804 | } | |||
805 | ||||
806 | for (const Metadata *Op : MD.operands()) { | |||
807 | if (!Op) | |||
808 | continue; | |||
809 | Assert(!isa<LocalAsMetadata>(Op), "Invalid operand for global metadata!",do { if (!(!isa<LocalAsMetadata>(Op))) { CheckFailed("Invalid operand for global metadata!" , &MD, Op); return; } } while (false) | |||
810 | &MD, Op)do { if (!(!isa<LocalAsMetadata>(Op))) { CheckFailed("Invalid operand for global metadata!" , &MD, Op); return; } } while (false); | |||
811 | if (auto *N = dyn_cast<MDNode>(Op)) { | |||
812 | visitMDNode(*N); | |||
813 | continue; | |||
814 | } | |||
815 | if (auto *V = dyn_cast<ValueAsMetadata>(Op)) { | |||
816 | visitValueAsMetadata(*V, nullptr); | |||
817 | continue; | |||
818 | } | |||
819 | } | |||
820 | ||||
821 | // Check these last, so we diagnose problems in operands first. | |||
822 | Assert(!MD.isTemporary(), "Expected no forward declarations!", &MD)do { if (!(!MD.isTemporary())) { CheckFailed("Expected no forward declarations!" , &MD); return; } } while (false); | |||
823 | Assert(MD.isResolved(), "All nodes should be resolved!", &MD)do { if (!(MD.isResolved())) { CheckFailed("All nodes should be resolved!" , &MD); return; } } while (false); | |||
824 | } | |||
825 | ||||
826 | void Verifier::visitValueAsMetadata(const ValueAsMetadata &MD, Function *F) { | |||
827 | Assert(MD.getValue(), "Expected valid value", &MD)do { if (!(MD.getValue())) { CheckFailed("Expected valid value" , &MD); return; } } while (false); | |||
828 | Assert(!MD.getValue()->getType()->isMetadataTy(),do { if (!(!MD.getValue()->getType()->isMetadataTy())) { CheckFailed("Unexpected metadata round-trip through values", &MD, MD.getValue()); return; } } while (false) | |||
829 | "Unexpected metadata round-trip through values", &MD, MD.getValue())do { if (!(!MD.getValue()->getType()->isMetadataTy())) { CheckFailed("Unexpected metadata round-trip through values", &MD, MD.getValue()); return; } } while (false); | |||
830 | ||||
831 | auto *L = dyn_cast<LocalAsMetadata>(&MD); | |||
832 | if (!L) | |||
833 | return; | |||
834 | ||||
835 | Assert(F, "function-local metadata used outside a function", L)do { if (!(F)) { CheckFailed("function-local metadata used outside a function" , L); return; } } while (false); | |||
836 | ||||
837 | // If this was an instruction, bb, or argument, verify that it is in the | |||
838 | // function that we expect. | |||
839 | Function *ActualF = nullptr; | |||
840 | if (Instruction *I = dyn_cast<Instruction>(L->getValue())) { | |||
841 | Assert(I->getParent(), "function-local metadata not in basic block", L, I)do { if (!(I->getParent())) { CheckFailed("function-local metadata not in basic block" , L, I); return; } } while (false); | |||
842 | ActualF = I->getParent()->getParent(); | |||
843 | } else if (BasicBlock *BB = dyn_cast<BasicBlock>(L->getValue())) | |||
844 | ActualF = BB->getParent(); | |||
845 | else if (Argument *A = dyn_cast<Argument>(L->getValue())) | |||
846 | ActualF = A->getParent(); | |||
847 | assert(ActualF && "Unimplemented function local metadata case!")((ActualF && "Unimplemented function local metadata case!" ) ? static_cast<void> (0) : __assert_fail ("ActualF && \"Unimplemented function local metadata case!\"" , "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/IR/Verifier.cpp" , 847, __PRETTY_FUNCTION__)); | |||
848 | ||||
849 | Assert(ActualF == F, "function-local metadata used in wrong function", L)do { if (!(ActualF == F)) { CheckFailed("function-local metadata used in wrong function" , L); return; } } while (false); | |||
850 | } | |||
851 | ||||
852 | void Verifier::visitMetadataAsValue(const MetadataAsValue &MDV, Function *F) { | |||
853 | Metadata *MD = MDV.getMetadata(); | |||
854 | if (auto *N = dyn_cast<MDNode>(MD)) { | |||
855 | visitMDNode(*N); | |||
856 | return; | |||
857 | } | |||
858 | ||||
859 | // Only visit each node once. Metadata can be mutually recursive, so this | |||
860 | // avoids infinite recursion here, as well as being an optimization. | |||
861 | if (!MDNodes.insert(MD).second) | |||
862 | return; | |||
863 | ||||
864 | if (auto *V = dyn_cast<ValueAsMetadata>(MD)) | |||
865 | visitValueAsMetadata(*V, F); | |||
866 | } | |||
867 | ||||
868 | static bool isType(const Metadata *MD) { return !MD || isa<DIType>(MD); } | |||
869 | static bool isScope(const Metadata *MD) { return !MD || isa<DIScope>(MD); } | |||
870 | static bool isDINode(const Metadata *MD) { return !MD || isa<DINode>(MD); } | |||
871 | ||||
872 | void Verifier::visitDILocation(const DILocation &N) { | |||
873 | AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { DebugInfoCheckFailed("location requires a valid scope" , &N, N.getRawScope()); return; } } while (false) | |||
874 | "location requires a valid scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { DebugInfoCheckFailed("location requires a valid scope" , &N, N.getRawScope()); return; } } while (false); | |||
875 | if (auto *IA = N.getRawInlinedAt()) | |||
876 | AssertDI(isa<DILocation>(IA), "inlined-at should be a location", &N, IA)do { if (!(isa<DILocation>(IA))) { DebugInfoCheckFailed ("inlined-at should be a location", &N, IA); return; } } while (false); | |||
877 | if (auto *SP = dyn_cast<DISubprogram>(N.getRawScope())) | |||
878 | AssertDI(SP->isDefinition(), "scope points into the type hierarchy", &N)do { if (!(SP->isDefinition())) { DebugInfoCheckFailed("scope points into the type hierarchy" , &N); return; } } while (false); | |||
879 | } | |||
880 | ||||
881 | void Verifier::visitGenericDINode(const GenericDINode &N) { | |||
882 | AssertDI(N.getTag(), "invalid tag", &N)do { if (!(N.getTag())) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false); | |||
883 | } | |||
884 | ||||
885 | void Verifier::visitDIScope(const DIScope &N) { | |||
886 | if (auto *F = N.getRawFile()) | |||
887 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | |||
888 | } | |||
889 | ||||
890 | void Verifier::visitDISubrange(const DISubrange &N) { | |||
891 | AssertDI(N.getTag() == dwarf::DW_TAG_subrange_type, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_subrange_type)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | |||
892 | auto Count = N.getCount(); | |||
893 | AssertDI(Count, "Count must either be a signed constant or a DIVariable",do { if (!(Count)) { DebugInfoCheckFailed("Count must either be a signed constant or a DIVariable" , &N); return; } } while (false) | |||
894 | &N)do { if (!(Count)) { DebugInfoCheckFailed("Count must either be a signed constant or a DIVariable" , &N); return; } } while (false); | |||
895 | AssertDI(!Count.is<ConstantInt*>() ||do { if (!(!Count.is<ConstantInt*>() || Count.get<ConstantInt *>()->getSExtValue() >= -1)) { DebugInfoCheckFailed( "invalid subrange count", &N); return; } } while (false) | |||
896 | Count.get<ConstantInt*>()->getSExtValue() >= -1,do { if (!(!Count.is<ConstantInt*>() || Count.get<ConstantInt *>()->getSExtValue() >= -1)) { DebugInfoCheckFailed( "invalid subrange count", &N); return; } } while (false) | |||
897 | "invalid subrange count", &N)do { if (!(!Count.is<ConstantInt*>() || Count.get<ConstantInt *>()->getSExtValue() >= -1)) { DebugInfoCheckFailed( "invalid subrange count", &N); return; } } while (false); | |||
898 | } | |||
899 | ||||
900 | void Verifier::visitDIEnumerator(const DIEnumerator &N) { | |||
901 | AssertDI(N.getTag() == dwarf::DW_TAG_enumerator, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_enumerator)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | |||
902 | } | |||
903 | ||||
904 | void Verifier::visitDIBasicType(const DIBasicType &N) { | |||
905 | AssertDI(N.getTag() == dwarf::DW_TAG_base_type ||do { if (!(N.getTag() == dwarf::DW_TAG_base_type || N.getTag( ) == dwarf::DW_TAG_unspecified_type)) { DebugInfoCheckFailed( "invalid tag", &N); return; } } while (false) | |||
906 | N.getTag() == dwarf::DW_TAG_unspecified_type,do { if (!(N.getTag() == dwarf::DW_TAG_base_type || N.getTag( ) == dwarf::DW_TAG_unspecified_type)) { DebugInfoCheckFailed( "invalid tag", &N); return; } } while (false) | |||
907 | "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_base_type || N.getTag( ) == dwarf::DW_TAG_unspecified_type)) { DebugInfoCheckFailed( "invalid tag", &N); return; } } while (false); | |||
908 | AssertDI(!(N.isBigEndian() && N.isLittleEndian()) ,do { if (!(!(N.isBigEndian() && N.isLittleEndian()))) { DebugInfoCheckFailed("has conflicting flags", &N); return ; } } while (false) | |||
909 | "has conflicting flags", &N)do { if (!(!(N.isBigEndian() && N.isLittleEndian()))) { DebugInfoCheckFailed("has conflicting flags", &N); return ; } } while (false); | |||
910 | } | |||
911 | ||||
912 | void Verifier::visitDIDerivedType(const DIDerivedType &N) { | |||
913 | // Common scope checks. | |||
914 | visitDIScope(N); | |||
915 | ||||
916 | AssertDI(N.getTag() == dwarf::DW_TAG_typedef ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | |||
917 | N.getTag() == dwarf::DW_TAG_pointer_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | |||
918 | N.getTag() == dwarf::DW_TAG_ptr_to_member_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | |||
919 | N.getTag() == dwarf::DW_TAG_reference_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | |||
920 | N.getTag() == dwarf::DW_TAG_rvalue_reference_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | |||
921 | N.getTag() == dwarf::DW_TAG_const_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | |||
922 | N.getTag() == dwarf::DW_TAG_volatile_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | |||
923 | N.getTag() == dwarf::DW_TAG_restrict_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | |||
924 | N.getTag() == dwarf::DW_TAG_atomic_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | |||
925 | N.getTag() == dwarf::DW_TAG_member ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | |||
926 | N.getTag() == dwarf::DW_TAG_inheritance ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | |||
927 | N.getTag() == dwarf::DW_TAG_friend,do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | |||
928 | "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false); | |||
929 | if (N.getTag() == dwarf::DW_TAG_ptr_to_member_type) { | |||
930 | AssertDI(isType(N.getRawExtraData()), "invalid pointer to member type", &N,do { if (!(isType(N.getRawExtraData()))) { DebugInfoCheckFailed ("invalid pointer to member type", &N, N.getRawExtraData( )); return; } } while (false) | |||
931 | N.getRawExtraData())do { if (!(isType(N.getRawExtraData()))) { DebugInfoCheckFailed ("invalid pointer to member type", &N, N.getRawExtraData( )); return; } } while (false); | |||
932 | } | |||
933 | ||||
934 | AssertDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope())do { if (!(isScope(N.getRawScope()))) { DebugInfoCheckFailed( "invalid scope", &N, N.getRawScope()); return; } } while ( false); | |||
935 | AssertDI(isType(N.getRawBaseType()), "invalid base type", &N,do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed ("invalid base type", &N, N.getRawBaseType()); return; } } while (false) | |||
936 | N.getRawBaseType())do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed ("invalid base type", &N, N.getRawBaseType()); return; } } while (false); | |||
937 | ||||
938 | if (N.getDWARFAddressSpace()) { | |||
939 | AssertDI(N.getTag() == dwarf::DW_TAG_pointer_type ||do { if (!(N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag () == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type )) { DebugInfoCheckFailed("DWARF address space only applies to pointer or reference types" , &N); return; } } while (false) | |||
940 | N.getTag() == dwarf::DW_TAG_reference_type ||do { if (!(N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag () == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type )) { DebugInfoCheckFailed("DWARF address space only applies to pointer or reference types" , &N); return; } } while (false) | |||
941 | N.getTag() == dwarf::DW_TAG_rvalue_reference_type,do { if (!(N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag () == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type )) { DebugInfoCheckFailed("DWARF address space only applies to pointer or reference types" , &N); return; } } while (false) | |||
942 | "DWARF address space only applies to pointer or reference types",do { if (!(N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag () == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type )) { DebugInfoCheckFailed("DWARF address space only applies to pointer or reference types" , &N); return; } } while (false) | |||
943 | &N)do { if (!(N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag () == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type )) { DebugInfoCheckFailed("DWARF address space only applies to pointer or reference types" , &N); return; } } while (false); | |||
944 | } | |||
945 | } | |||
946 | ||||
947 | /// Detect mutually exclusive flags. | |||
948 | static bool hasConflictingReferenceFlags(unsigned Flags) { | |||
949 | return ((Flags & DINode::FlagLValueReference) && | |||
950 | (Flags & DINode::FlagRValueReference)) || | |||
951 | ((Flags & DINode::FlagTypePassByValue) && | |||
952 | (Flags & DINode::FlagTypePassByReference)); | |||
953 | } | |||
954 | ||||
955 | void Verifier::visitTemplateParams(const MDNode &N, const Metadata &RawParams) { | |||
956 | auto *Params = dyn_cast<MDTuple>(&RawParams); | |||
957 | AssertDI(Params, "invalid template params", &N, &RawParams)do { if (!(Params)) { DebugInfoCheckFailed("invalid template params" , &N, &RawParams); return; } } while (false); | |||
958 | for (Metadata *Op : Params->operands()) { | |||
959 | AssertDI(Op && isa<DITemplateParameter>(Op), "invalid template parameter",do { if (!(Op && isa<DITemplateParameter>(Op))) { DebugInfoCheckFailed("invalid template parameter", &N, Params, Op); return; } } while (false) | |||
960 | &N, Params, Op)do { if (!(Op && isa<DITemplateParameter>(Op))) { DebugInfoCheckFailed("invalid template parameter", &N, Params, Op); return; } } while (false); | |||
961 | } | |||
962 | } | |||
963 | ||||
964 | void Verifier::visitDICompositeType(const DICompositeType &N) { | |||
965 | // Common scope checks. | |||
966 | visitDIScope(N); | |||
967 | ||||
968 | AssertDI(N.getTag() == dwarf::DW_TAG_array_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag () == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type || N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag( ) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false) | |||
969 | N.getTag() == dwarf::DW_TAG_structure_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag () == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type || N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag( ) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false) | |||
970 | N.getTag() == dwarf::DW_TAG_union_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag () == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type || N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag( ) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false) | |||
971 | N.getTag() == dwarf::DW_TAG_enumeration_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag () == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type || N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag( ) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false) | |||
972 | N.getTag() == dwarf::DW_TAG_class_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag () == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type || N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag( ) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false) | |||
973 | N.getTag() == dwarf::DW_TAG_variant_part,do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag () == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type || N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag( ) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false) | |||
974 | "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag () == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type || N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag( ) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false); | |||
975 | ||||
976 | AssertDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope())do { if (!(isScope(N.getRawScope()))) { DebugInfoCheckFailed( "invalid scope", &N, N.getRawScope()); return; } } while ( false); | |||
977 | AssertDI(isType(N.getRawBaseType()), "invalid base type", &N,do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed ("invalid base type", &N, N.getRawBaseType()); return; } } while (false) | |||
978 | N.getRawBaseType())do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed ("invalid base type", &N, N.getRawBaseType()); return; } } while (false); | |||
979 | ||||
980 | AssertDI(!N.getRawElements() || isa<MDTuple>(N.getRawElements()),do { if (!(!N.getRawElements() || isa<MDTuple>(N.getRawElements ()))) { DebugInfoCheckFailed("invalid composite elements", & N, N.getRawElements()); return; } } while (false) | |||
981 | "invalid composite elements", &N, N.getRawElements())do { if (!(!N.getRawElements() || isa<MDTuple>(N.getRawElements ()))) { DebugInfoCheckFailed("invalid composite elements", & N, N.getRawElements()); return; } } while (false); | |||
982 | AssertDI(isType(N.getRawVTableHolder()), "invalid vtable holder", &N,do { if (!(isType(N.getRawVTableHolder()))) { DebugInfoCheckFailed ("invalid vtable holder", &N, N.getRawVTableHolder()); return ; } } while (false) | |||
983 | N.getRawVTableHolder())do { if (!(isType(N.getRawVTableHolder()))) { DebugInfoCheckFailed ("invalid vtable holder", &N, N.getRawVTableHolder()); return ; } } while (false); | |||
984 | AssertDI(!hasConflictingReferenceFlags(N.getFlags()),do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ) | |||
985 | "invalid reference flags", &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ); | |||
986 | unsigned DIBlockByRefStruct = 1 << 4; | |||
987 | AssertDI((N.getFlags() & DIBlockByRefStruct) == 0,do { if (!((N.getFlags() & DIBlockByRefStruct) == 0)) { DebugInfoCheckFailed ("DIBlockByRefStruct on DICompositeType is no longer supported" , &N); return; } } while (false) | |||
988 | "DIBlockByRefStruct on DICompositeType is no longer supported", &N)do { if (!((N.getFlags() & DIBlockByRefStruct) == 0)) { DebugInfoCheckFailed ("DIBlockByRefStruct on DICompositeType is no longer supported" , &N); return; } } while (false); | |||
989 | ||||
990 | if (N.isVector()) { | |||
991 | const DINodeArray Elements = N.getElements(); | |||
992 | AssertDI(Elements.size() == 1 &&do { if (!(Elements.size() == 1 && Elements[0]->getTag () == dwarf::DW_TAG_subrange_type)) { DebugInfoCheckFailed("invalid vector, expected one element of type subrange" , &N); return; } } while (false) | |||
993 | Elements[0]->getTag() == dwarf::DW_TAG_subrange_type,do { if (!(Elements.size() == 1 && Elements[0]->getTag () == dwarf::DW_TAG_subrange_type)) { DebugInfoCheckFailed("invalid vector, expected one element of type subrange" , &N); return; } } while (false) | |||
994 | "invalid vector, expected one element of type subrange", &N)do { if (!(Elements.size() == 1 && Elements[0]->getTag () == dwarf::DW_TAG_subrange_type)) { DebugInfoCheckFailed("invalid vector, expected one element of type subrange" , &N); return; } } while (false); | |||
995 | } | |||
996 | ||||
997 | if (auto *Params = N.getRawTemplateParams()) | |||
998 | visitTemplateParams(N, *Params); | |||
999 | ||||
1000 | if (N.getTag() == dwarf::DW_TAG_class_type || | |||
1001 | N.getTag() == dwarf::DW_TAG_union_type) { | |||
1002 | AssertDI(N.getFile() && !N.getFile()->getFilename().empty(),do { if (!(N.getFile() && !N.getFile()->getFilename ().empty())) { DebugInfoCheckFailed("class/union requires a filename" , &N, N.getFile()); return; } } while (false) | |||
1003 | "class/union requires a filename", &N, N.getFile())do { if (!(N.getFile() && !N.getFile()->getFilename ().empty())) { DebugInfoCheckFailed("class/union requires a filename" , &N, N.getFile()); return; } } while (false); | |||
1004 | } | |||
1005 | ||||
1006 | if (auto *D = N.getRawDiscriminator()) { | |||
1007 | AssertDI(isa<DIDerivedType>(D) && N.getTag() == dwarf::DW_TAG_variant_part,do { if (!(isa<DIDerivedType>(D) && N.getTag() == dwarf::DW_TAG_variant_part)) { DebugInfoCheckFailed("discriminator can only appear on variant part" ); return; } } while (false) | |||
1008 | "discriminator can only appear on variant part")do { if (!(isa<DIDerivedType>(D) && N.getTag() == dwarf::DW_TAG_variant_part)) { DebugInfoCheckFailed("discriminator can only appear on variant part" ); return; } } while (false); | |||
1009 | } | |||
1010 | } | |||
1011 | ||||
1012 | void Verifier::visitDISubroutineType(const DISubroutineType &N) { | |||
1013 | AssertDI(N.getTag() == dwarf::DW_TAG_subroutine_type, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_subroutine_type)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | |||
1014 | if (auto *Types = N.getRawTypeArray()) { | |||
1015 | AssertDI(isa<MDTuple>(Types), "invalid composite elements", &N, Types)do { if (!(isa<MDTuple>(Types))) { DebugInfoCheckFailed ("invalid composite elements", &N, Types); return; } } while (false); | |||
1016 | for (Metadata *Ty : N.getTypeArray()->operands()) { | |||
1017 | AssertDI(isType(Ty), "invalid subroutine type ref", &N, Types, Ty)do { if (!(isType(Ty))) { DebugInfoCheckFailed("invalid subroutine type ref" , &N, Types, Ty); return; } } while (false); | |||
1018 | } | |||
1019 | } | |||
1020 | AssertDI(!hasConflictingReferenceFlags(N.getFlags()),do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ) | |||
1021 | "invalid reference flags", &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ); | |||
1022 | } | |||
1023 | ||||
1024 | void Verifier::visitDIFile(const DIFile &N) { | |||
1025 | AssertDI(N.getTag() == dwarf::DW_TAG_file_type, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_file_type)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | |||
1026 | Optional<DIFile::ChecksumInfo<StringRef>> Checksum = N.getChecksum(); | |||
1027 | if (Checksum) { | |||
1028 | AssertDI(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last,do { if (!(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last )) { DebugInfoCheckFailed("invalid checksum kind", &N); return ; } } while (false) | |||
1029 | "invalid checksum kind", &N)do { if (!(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last )) { DebugInfoCheckFailed("invalid checksum kind", &N); return ; } } while (false); | |||
1030 | size_t Size; | |||
1031 | switch (Checksum->Kind) { | |||
1032 | case DIFile::CSK_MD5: | |||
1033 | Size = 32; | |||
1034 | break; | |||
1035 | case DIFile::CSK_SHA1: | |||
1036 | Size = 40; | |||
1037 | break; | |||
1038 | } | |||
1039 | AssertDI(Checksum->Value.size() == Size, "invalid checksum length", &N)do { if (!(Checksum->Value.size() == Size)) { DebugInfoCheckFailed ("invalid checksum length", &N); return; } } while (false ); | |||
1040 | AssertDI(Checksum->Value.find_if_not(llvm::isHexDigit) == StringRef::npos,do { if (!(Checksum->Value.find_if_not(llvm::isHexDigit) == StringRef::npos)) { DebugInfoCheckFailed("invalid checksum", &N); return; } } while (false) | |||
1041 | "invalid checksum", &N)do { if (!(Checksum->Value.find_if_not(llvm::isHexDigit) == StringRef::npos)) { DebugInfoCheckFailed("invalid checksum", &N); return; } } while (false); | |||
1042 | } | |||
1043 | } | |||
1044 | ||||
1045 | void Verifier::visitDICompileUnit(const DICompileUnit &N) { | |||
1046 | AssertDI(N.isDistinct(), "compile units must be distinct", &N)do { if (!(N.isDistinct())) { DebugInfoCheckFailed("compile units must be distinct" , &N); return; } } while (false); | |||
1047 | AssertDI(N.getTag() == dwarf::DW_TAG_compile_unit, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_compile_unit)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | |||
1048 | ||||
1049 | // Don't bother verifying the compilation directory or producer string | |||
1050 | // as those could be empty. | |||
1051 | AssertDI(N.getRawFile() && isa<DIFile>(N.getRawFile()), "invalid file", &N,do { if (!(N.getRawFile() && isa<DIFile>(N.getRawFile ()))) { DebugInfoCheckFailed("invalid file", &N, N.getRawFile ()); return; } } while (false) | |||
1052 | N.getRawFile())do { if (!(N.getRawFile() && isa<DIFile>(N.getRawFile ()))) { DebugInfoCheckFailed("invalid file", &N, N.getRawFile ()); return; } } while (false); | |||
1053 | AssertDI(!N.getFile()->getFilename().empty(), "invalid filename", &N,do { if (!(!N.getFile()->getFilename().empty())) { DebugInfoCheckFailed ("invalid filename", &N, N.getFile()); return; } } while ( false) | |||
1054 | N.getFile())do { if (!(!N.getFile()->getFilename().empty())) { DebugInfoCheckFailed ("invalid filename", &N, N.getFile()); return; } } while ( false); | |||
1055 | ||||
1056 | verifySourceDebugInfo(N, *N.getFile()); | |||
1057 | ||||
1058 | AssertDI((N.getEmissionKind() <= DICompileUnit::LastEmissionKind),do { if (!((N.getEmissionKind() <= DICompileUnit::LastEmissionKind ))) { DebugInfoCheckFailed("invalid emission kind", &N); return ; } } while (false) | |||
1059 | "invalid emission kind", &N)do { if (!((N.getEmissionKind() <= DICompileUnit::LastEmissionKind ))) { DebugInfoCheckFailed("invalid emission kind", &N); return ; } } while (false); | |||
1060 | ||||
1061 | if (auto *Array = N.getRawEnumTypes()) { | |||
1062 | AssertDI(isa<MDTuple>(Array), "invalid enum list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed ("invalid enum list", &N, Array); return; } } while (false ); | |||
1063 | for (Metadata *Op : N.getEnumTypes()->operands()) { | |||
1064 | auto *Enum = dyn_cast_or_null<DICompositeType>(Op); | |||
1065 | AssertDI(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type,do { if (!(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type )) { DebugInfoCheckFailed("invalid enum type", &N, N.getEnumTypes (), Op); return; } } while (false) | |||
1066 | "invalid enum type", &N, N.getEnumTypes(), Op)do { if (!(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type )) { DebugInfoCheckFailed("invalid enum type", &N, N.getEnumTypes (), Op); return; } } while (false); | |||
1067 | } | |||
1068 | } | |||
1069 | if (auto *Array = N.getRawRetainedTypes()) { | |||
1070 | AssertDI(isa<MDTuple>(Array), "invalid retained type list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed ("invalid retained type list", &N, Array); return; } } while (false); | |||
1071 | for (Metadata *Op : N.getRetainedTypes()->operands()) { | |||
1072 | AssertDI(Op && (isa<DIType>(Op) ||do { if (!(Op && (isa<DIType>(Op) || (isa<DISubprogram >(Op) && !cast<DISubprogram>(Op)->isDefinition ())))) { DebugInfoCheckFailed("invalid retained type", &N , Op); return; } } while (false) | |||
1073 | (isa<DISubprogram>(Op) &&do { if (!(Op && (isa<DIType>(Op) || (isa<DISubprogram >(Op) && !cast<DISubprogram>(Op)->isDefinition ())))) { DebugInfoCheckFailed("invalid retained type", &N , Op); return; } } while (false) | |||
1074 | !cast<DISubprogram>(Op)->isDefinition())),do { if (!(Op && (isa<DIType>(Op) || (isa<DISubprogram >(Op) && !cast<DISubprogram>(Op)->isDefinition ())))) { DebugInfoCheckFailed("invalid retained type", &N , Op); return; } } while (false) | |||
1075 | "invalid retained type", &N, Op)do { if (!(Op && (isa<DIType>(Op) || (isa<DISubprogram >(Op) && !cast<DISubprogram>(Op)->isDefinition ())))) { DebugInfoCheckFailed("invalid retained type", &N , Op); return; } } while (false); | |||
1076 | } | |||
1077 | } | |||
1078 | if (auto *Array = N.getRawGlobalVariables()) { | |||
1079 | AssertDI(isa<MDTuple>(Array), "invalid global variable list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed ("invalid global variable list", &N, Array); return; } } while (false); | |||
1080 | for (Metadata *Op : N.getGlobalVariables()->operands()) { | |||
1081 | AssertDI(Op && (isa<DIGlobalVariableExpression>(Op)),do { if (!(Op && (isa<DIGlobalVariableExpression> (Op)))) { DebugInfoCheckFailed("invalid global variable ref", &N, Op); return; } } while (false) | |||
1082 | "invalid global variable ref", &N, Op)do { if (!(Op && (isa<DIGlobalVariableExpression> (Op)))) { DebugInfoCheckFailed("invalid global variable ref", &N, Op); return; } } while (false); | |||
1083 | } | |||
1084 | } | |||
1085 | if (auto *Array = N.getRawImportedEntities()) { | |||
1086 | AssertDI(isa<MDTuple>(Array), "invalid imported entity list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed ("invalid imported entity list", &N, Array); return; } } while (false); | |||
1087 | for (Metadata *Op : N.getImportedEntities()->operands()) { | |||
1088 | AssertDI(Op && isa<DIImportedEntity>(Op), "invalid imported entity ref",do { if (!(Op && isa<DIImportedEntity>(Op))) { DebugInfoCheckFailed ("invalid imported entity ref", &N, Op); return; } } while (false) | |||
1089 | &N, Op)do { if (!(Op && isa<DIImportedEntity>(Op))) { DebugInfoCheckFailed ("invalid imported entity ref", &N, Op); return; } } while (false); | |||
1090 | } | |||
1091 | } | |||
1092 | if (auto *Array = N.getRawMacros()) { | |||
1093 | AssertDI(isa<MDTuple>(Array), "invalid macro list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed ("invalid macro list", &N, Array); return; } } while (false ); | |||
1094 | for (Metadata *Op : N.getMacros()->operands()) { | |||
1095 | AssertDI(Op && isa<DIMacroNode>(Op), "invalid macro ref", &N, Op)do { if (!(Op && isa<DIMacroNode>(Op))) { DebugInfoCheckFailed ("invalid macro ref", &N, Op); return; } } while (false); | |||
1096 | } | |||
1097 | } | |||
1098 | CUVisited.insert(&N); | |||
1099 | } | |||
1100 | ||||
1101 | void Verifier::visitDISubprogram(const DISubprogram &N) { | |||
1102 | AssertDI(N.getTag() == dwarf::DW_TAG_subprogram, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_subprogram)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | |||
1103 | AssertDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope())do { if (!(isScope(N.getRawScope()))) { DebugInfoCheckFailed( "invalid scope", &N, N.getRawScope()); return; } } while ( false); | |||
1104 | if (auto *F = N.getRawFile()) | |||
1105 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | |||
1106 | else | |||
1107 | AssertDI(N.getLine() == 0, "line specified with no file", &N, N.getLine())do { if (!(N.getLine() == 0)) { DebugInfoCheckFailed("line specified with no file" , &N, N.getLine()); return; } } while (false); | |||
1108 | if (auto *T = N.getRawType()) | |||
1109 | AssertDI(isa<DISubroutineType>(T), "invalid subroutine type", &N, T)do { if (!(isa<DISubroutineType>(T))) { DebugInfoCheckFailed ("invalid subroutine type", &N, T); return; } } while (false ); | |||
1110 | AssertDI(isType(N.getRawContainingType()), "invalid containing type", &N,do { if (!(isType(N.getRawContainingType()))) { DebugInfoCheckFailed ("invalid containing type", &N, N.getRawContainingType()) ; return; } } while (false) | |||
1111 | N.getRawContainingType())do { if (!(isType(N.getRawContainingType()))) { DebugInfoCheckFailed ("invalid containing type", &N, N.getRawContainingType()) ; return; } } while (false); | |||
1112 | if (auto *Params = N.getRawTemplateParams()) | |||
1113 | visitTemplateParams(N, *Params); | |||
1114 | if (auto *S = N.getRawDeclaration()) | |||
1115 | AssertDI(isa<DISubprogram>(S) && !cast<DISubprogram>(S)->isDefinition(),do { if (!(isa<DISubprogram>(S) && !cast<DISubprogram >(S)->isDefinition())) { DebugInfoCheckFailed("invalid subprogram declaration" , &N, S); return; } } while (false) | |||
1116 | "invalid subprogram declaration", &N, S)do { if (!(isa<DISubprogram>(S) && !cast<DISubprogram >(S)->isDefinition())) { DebugInfoCheckFailed("invalid subprogram declaration" , &N, S); return; } } while (false); | |||
1117 | if (auto *RawNode = N.getRawRetainedNodes()) { | |||
1118 | auto *Node = dyn_cast<MDTuple>(RawNode); | |||
1119 | AssertDI(Node, "invalid retained nodes list", &N, RawNode)do { if (!(Node)) { DebugInfoCheckFailed("invalid retained nodes list" , &N, RawNode); return; } } while (false); | |||
1120 | for (Metadata *Op : Node->operands()) { | |||
1121 | AssertDI(Op && (isa<DILocalVariable>(Op) || isa<DILabel>(Op)),do { if (!(Op && (isa<DILocalVariable>(Op) || isa <DILabel>(Op)))) { DebugInfoCheckFailed("invalid retained nodes, expected DILocalVariable or DILabel" , &N, Node, Op); return; } } while (false) | |||
1122 | "invalid retained nodes, expected DILocalVariable or DILabel",do { if (!(Op && (isa<DILocalVariable>(Op) || isa <DILabel>(Op)))) { DebugInfoCheckFailed("invalid retained nodes, expected DILocalVariable or DILabel" , &N, Node, Op); return; } } while (false) | |||
1123 | &N, Node, Op)do { if (!(Op && (isa<DILocalVariable>(Op) || isa <DILabel>(Op)))) { DebugInfoCheckFailed("invalid retained nodes, expected DILocalVariable or DILabel" , &N, Node, Op); return; } } while (false); | |||
1124 | } | |||
1125 | } | |||
1126 | AssertDI(!hasConflictingReferenceFlags(N.getFlags()),do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ) | |||
1127 | "invalid reference flags", &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ); | |||
1128 | ||||
1129 | auto *Unit = N.getRawUnit(); | |||
1130 | if (N.isDefinition()) { | |||
1131 | // Subprogram definitions (not part of the type hierarchy). | |||
1132 | AssertDI(N.isDistinct(), "subprogram definitions must be distinct", &N)do { if (!(N.isDistinct())) { DebugInfoCheckFailed("subprogram definitions must be distinct" , &N); return; } } while (false); | |||
1133 | AssertDI(Unit, "subprogram definitions must have a compile unit", &N)do { if (!(Unit)) { DebugInfoCheckFailed("subprogram definitions must have a compile unit" , &N); return; } } while (false); | |||
1134 | AssertDI(isa<DICompileUnit>(Unit), "invalid unit type", &N, Unit)do { if (!(isa<DICompileUnit>(Unit))) { DebugInfoCheckFailed ("invalid unit type", &N, Unit); return; } } while (false ); | |||
1135 | if (N.getFile()) | |||
1136 | verifySourceDebugInfo(*N.getUnit(), *N.getFile()); | |||
1137 | } else { | |||
1138 | // Subprogram declarations (part of the type hierarchy). | |||
1139 | AssertDI(!Unit, "subprogram declarations must not have a compile unit", &N)do { if (!(!Unit)) { DebugInfoCheckFailed("subprogram declarations must not have a compile unit" , &N); return; } } while (false); | |||
1140 | } | |||
1141 | ||||
1142 | if (auto *RawThrownTypes = N.getRawThrownTypes()) { | |||
1143 | auto *ThrownTypes = dyn_cast<MDTuple>(RawThrownTypes); | |||
1144 | AssertDI(ThrownTypes, "invalid thrown types list", &N, RawThrownTypes)do { if (!(ThrownTypes)) { DebugInfoCheckFailed("invalid thrown types list" , &N, RawThrownTypes); return; } } while (false); | |||
1145 | for (Metadata *Op : ThrownTypes->operands()) | |||
1146 | AssertDI(Op && isa<DIType>(Op), "invalid thrown type", &N, ThrownTypes,do { if (!(Op && isa<DIType>(Op))) { DebugInfoCheckFailed ("invalid thrown type", &N, ThrownTypes, Op); return; } } while (false) | |||
1147 | Op)do { if (!(Op && isa<DIType>(Op))) { DebugInfoCheckFailed ("invalid thrown type", &N, ThrownTypes, Op); return; } } while (false); | |||
1148 | } | |||
1149 | ||||
1150 | if (N.areAllCallsDescribed()) | |||
1151 | AssertDI(N.isDefinition(),do { if (!(N.isDefinition())) { DebugInfoCheckFailed("DIFlagAllCallsDescribed must be attached to a definition" ); return; } } while (false) | |||
1152 | "DIFlagAllCallsDescribed must be attached to a definition")do { if (!(N.isDefinition())) { DebugInfoCheckFailed("DIFlagAllCallsDescribed must be attached to a definition" ); return; } } while (false); | |||
1153 | } | |||
1154 | ||||
1155 | void Verifier::visitDILexicalBlockBase(const DILexicalBlockBase &N) { | |||
1156 | AssertDI(N.getTag() == dwarf::DW_TAG_lexical_block, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_lexical_block)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | |||
1157 | AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { DebugInfoCheckFailed("invalid local scope" , &N, N.getRawScope()); return; } } while (false) | |||
1158 | "invalid local scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { DebugInfoCheckFailed("invalid local scope" , &N, N.getRawScope()); return; } } while (false); | |||
1159 | if (auto *SP = dyn_cast<DISubprogram>(N.getRawScope())) | |||
1160 | AssertDI(SP->isDefinition(), "scope points into the type hierarchy", &N)do { if (!(SP->isDefinition())) { DebugInfoCheckFailed("scope points into the type hierarchy" , &N); return; } } while (false); | |||
1161 | } | |||
1162 | ||||
1163 | void Verifier::visitDILexicalBlock(const DILexicalBlock &N) { | |||
1164 | visitDILexicalBlockBase(N); | |||
1165 | ||||
1166 | AssertDI(N.getLine() || !N.getColumn(),do { if (!(N.getLine() || !N.getColumn())) { DebugInfoCheckFailed ("cannot have column info without line info", &N); return ; } } while (false) | |||
1167 | "cannot have column info without line info", &N)do { if (!(N.getLine() || !N.getColumn())) { DebugInfoCheckFailed ("cannot have column info without line info", &N); return ; } } while (false); | |||
1168 | } | |||
1169 | ||||
1170 | void Verifier::visitDILexicalBlockFile(const DILexicalBlockFile &N) { | |||
1171 | visitDILexicalBlockBase(N); | |||
1172 | } | |||
1173 | ||||
1174 | void Verifier::visitDICommonBlock(const DICommonBlock &N) { | |||
1175 | AssertDI(N.getTag() == dwarf::DW_TAG_common_block, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_common_block)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | |||
1176 | if (auto *S = N.getRawScope()) | |||
1177 | AssertDI(isa<DIScope>(S), "invalid scope ref", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope ref" , &N, S); return; } } while (false); | |||
1178 | if (auto *S = N.getRawDecl()) | |||
1179 | AssertDI(isa<DIGlobalVariable>(S), "invalid declaration", &N, S)do { if (!(isa<DIGlobalVariable>(S))) { DebugInfoCheckFailed ("invalid declaration", &N, S); return; } } while (false); | |||
1180 | } | |||
1181 | ||||
1182 | void Verifier::visitDINamespace(const DINamespace &N) { | |||
1183 | AssertDI(N.getTag() == dwarf::DW_TAG_namespace, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_namespace)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | |||
1184 | if (auto *S = N.getRawScope()) | |||
1185 | AssertDI(isa<DIScope>(S), "invalid scope ref", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope ref" , &N, S); return; } } while (false); | |||
1186 | } | |||
1187 | ||||
1188 | void Verifier::visitDIMacro(const DIMacro &N) { | |||
1189 | AssertDI(N.getMacinfoType() == dwarf::DW_MACINFO_define ||do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_define || N .getMacinfoType() == dwarf::DW_MACINFO_undef)) { DebugInfoCheckFailed ("invalid macinfo type", &N); return; } } while (false) | |||
1190 | N.getMacinfoType() == dwarf::DW_MACINFO_undef,do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_define || N .getMacinfoType() == dwarf::DW_MACINFO_undef)) { DebugInfoCheckFailed ("invalid macinfo type", &N); return; } } while (false) | |||
1191 | "invalid macinfo type", &N)do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_define || N .getMacinfoType() == dwarf::DW_MACINFO_undef)) { DebugInfoCheckFailed ("invalid macinfo type", &N); return; } } while (false); | |||
1192 | AssertDI(!N.getName().empty(), "anonymous macro", &N)do { if (!(!N.getName().empty())) { DebugInfoCheckFailed("anonymous macro" , &N); return; } } while (false); | |||
1193 | if (!N.getValue().empty()) { | |||
1194 | assert(N.getValue().data()[0] != ' ' && "Macro value has a space prefix")((N.getValue().data()[0] != ' ' && "Macro value has a space prefix" ) ? static_cast<void> (0) : __assert_fail ("N.getValue().data()[0] != ' ' && \"Macro value has a space prefix\"" , "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/IR/Verifier.cpp" , 1194, __PRETTY_FUNCTION__)); | |||
1195 | } | |||
1196 | } | |||
1197 | ||||
1198 | void Verifier::visitDIMacroFile(const DIMacroFile &N) { | |||
1199 | AssertDI(N.getMacinfoType() == dwarf::DW_MACINFO_start_file,do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_start_file )) { DebugInfoCheckFailed("invalid macinfo type", &N); return ; } } while (false) | |||
1200 | "invalid macinfo type", &N)do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_start_file )) { DebugInfoCheckFailed("invalid macinfo type", &N); return ; } } while (false); | |||
1201 | if (auto *F = N.getRawFile()) | |||
1202 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | |||
1203 | ||||
1204 | if (auto *Array = N.getRawElements()) { | |||
1205 | AssertDI(isa<MDTuple>(Array), "invalid macro list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed ("invalid macro list", &N, Array); return; } } while (false ); | |||
1206 | for (Metadata *Op : N.getElements()->operands()) { | |||
1207 | AssertDI(Op && isa<DIMacroNode>(Op), "invalid macro ref", &N, Op)do { if (!(Op && isa<DIMacroNode>(Op))) { DebugInfoCheckFailed ("invalid macro ref", &N, Op); return; } } while (false); | |||
1208 | } | |||
1209 | } | |||
1210 | } | |||
1211 | ||||
1212 | void Verifier::visitDIModule(const DIModule &N) { | |||
1213 | AssertDI(N.getTag() == dwarf::DW_TAG_module, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_module)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | |||
1214 | AssertDI(!N.getName().empty(), "anonymous module", &N)do { if (!(!N.getName().empty())) { DebugInfoCheckFailed("anonymous module" , &N); return; } } while (false); | |||
1215 | } | |||
1216 | ||||
1217 | void Verifier::visitDITemplateParameter(const DITemplateParameter &N) { | |||
1218 | AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType())do { if (!(isType(N.getRawType()))) { DebugInfoCheckFailed("invalid type ref" , &N, N.getRawType()); return; } } while (false); | |||
1219 | } | |||
1220 | ||||
1221 | void Verifier::visitDITemplateTypeParameter(const DITemplateTypeParameter &N) { | |||
1222 | visitDITemplateParameter(N); | |||
1223 | ||||
1224 | AssertDI(N.getTag() == dwarf::DW_TAG_template_type_parameter, "invalid tag",do { if (!(N.getTag() == dwarf::DW_TAG_template_type_parameter )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false) | |||
1225 | &N)do { if (!(N.getTag() == dwarf::DW_TAG_template_type_parameter )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false); | |||
1226 | } | |||
1227 | ||||
1228 | void Verifier::visitDITemplateValueParameter( | |||
1229 | const DITemplateValueParameter &N) { | |||
1230 | visitDITemplateParameter(N); | |||
1231 | ||||
1232 | AssertDI(N.getTag() == dwarf::DW_TAG_template_value_parameter ||do { if (!(N.getTag() == dwarf::DW_TAG_template_value_parameter || N.getTag() == dwarf::DW_TAG_GNU_template_template_param || N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false) | |||
1233 | N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||do { if (!(N.getTag() == dwarf::DW_TAG_template_value_parameter || N.getTag() == dwarf::DW_TAG_GNU_template_template_param || N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false) | |||
1234 | N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack,do { if (!(N.getTag() == dwarf::DW_TAG_template_value_parameter || N.getTag() == dwarf::DW_TAG_GNU_template_template_param || N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false) | |||
1235 | "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_template_value_parameter || N.getTag() == dwarf::DW_TAG_GNU_template_template_param || N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | |||
1236 | } | |||
1237 | ||||
1238 | void Verifier::visitDIVariable(const DIVariable &N) { | |||
1239 | if (auto *S = N.getRawScope()) | |||
1240 | AssertDI(isa<DIScope>(S), "invalid scope", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope" , &N, S); return; } } while (false); | |||
1241 | if (auto *F = N.getRawFile()) | |||
1242 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | |||
1243 | } | |||
1244 | ||||
1245 | void Verifier::visitDIGlobalVariable(const DIGlobalVariable &N) { | |||
1246 | // Checks common to all variables. | |||
1247 | visitDIVariable(N); | |||
1248 | ||||
1249 | AssertDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_variable)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | |||
1250 | AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType())do { if (!(isType(N.getRawType()))) { DebugInfoCheckFailed("invalid type ref" , &N, N.getRawType()); return; } } while (false); | |||
1251 | AssertDI(N.getType(), "missing global variable type", &N)do { if (!(N.getType())) { DebugInfoCheckFailed("missing global variable type" , &N); return; } } while (false); | |||
1252 | if (auto *Member = N.getRawStaticDataMemberDeclaration()) { | |||
1253 | AssertDI(isa<DIDerivedType>(Member),do { if (!(isa<DIDerivedType>(Member))) { DebugInfoCheckFailed ("invalid static data member declaration", &N, Member); return ; } } while (false) | |||
1254 | "invalid static data member declaration", &N, Member)do { if (!(isa<DIDerivedType>(Member))) { DebugInfoCheckFailed ("invalid static data member declaration", &N, Member); return ; } } while (false); | |||
1255 | } | |||
1256 | } | |||
1257 | ||||
1258 | void Verifier::visitDILocalVariable(const DILocalVariable &N) { | |||
1259 | // Checks common to all variables. | |||
1260 | visitDIVariable(N); | |||
1261 | ||||
1262 | AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType())do { if (!(isType(N.getRawType()))) { DebugInfoCheckFailed("invalid type ref" , &N, N.getRawType()); return; } } while (false); | |||
1263 | AssertDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_variable)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | |||
1264 | AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { DebugInfoCheckFailed("local variable requires a valid scope" , &N, N.getRawScope()); return; } } while (false) | |||
1265 | "local variable requires a valid scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { DebugInfoCheckFailed("local variable requires a valid scope" , &N, N.getRawScope()); return; } } while (false); | |||
1266 | if (auto Ty = N.getType()) | |||
1267 | AssertDI(!isa<DISubroutineType>(Ty), "invalid type", &N, N.getType())do { if (!(!isa<DISubroutineType>(Ty))) { DebugInfoCheckFailed ("invalid type", &N, N.getType()); return; } } while (false ); | |||
1268 | } | |||
1269 | ||||
1270 | void Verifier::visitDILabel(const DILabel &N) { | |||
1271 | if (auto *S = N.getRawScope()) | |||
1272 | AssertDI(isa<DIScope>(S), "invalid scope", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope" , &N, S); return; } } while (false); | |||
1273 | if (auto *F = N.getRawFile()) | |||
1274 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | |||
1275 | ||||
1276 | AssertDI(N.getTag() == dwarf::DW_TAG_label, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_label)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | |||
1277 | AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { DebugInfoCheckFailed("label requires a valid scope" , &N, N.getRawScope()); return; } } while (false) | |||
1278 | "label requires a valid scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { DebugInfoCheckFailed("label requires a valid scope" , &N, N.getRawScope()); return; } } while (false); | |||
1279 | } | |||
1280 | ||||
1281 | void Verifier::visitDIExpression(const DIExpression &N) { | |||
1282 | AssertDI(N.isValid(), "invalid expression", &N)do { if (!(N.isValid())) { DebugInfoCheckFailed("invalid expression" , &N); return; } } while (false); | |||
1283 | } | |||
1284 | ||||
1285 | void Verifier::visitDIGlobalVariableExpression( | |||
1286 | const DIGlobalVariableExpression &GVE) { | |||
1287 | AssertDI(GVE.getVariable(), "missing variable")do { if (!(GVE.getVariable())) { DebugInfoCheckFailed("missing variable" ); return; } } while (false); | |||
1288 | if (auto *Var = GVE.getVariable()) | |||
1289 | visitDIGlobalVariable(*Var); | |||
1290 | if (auto *Expr = GVE.getExpression()) { | |||
1291 | visitDIExpression(*Expr); | |||
1292 | if (auto Fragment = Expr->getFragmentInfo()) | |||
1293 | verifyFragmentExpression(*GVE.getVariable(), *Fragment, &GVE); | |||
1294 | } | |||
1295 | } | |||
1296 | ||||
1297 | void Verifier::visitDIObjCProperty(const DIObjCProperty &N) { | |||
1298 | AssertDI(N.getTag() == dwarf::DW_TAG_APPLE_property, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_APPLE_property)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | |||
1299 | if (auto *T = N.getRawType()) | |||
1300 | AssertDI(isType(T), "invalid type ref", &N, T)do { if (!(isType(T))) { DebugInfoCheckFailed("invalid type ref" , &N, T); return; } } while (false); | |||
1301 | if (auto *F = N.getRawFile()) | |||
1302 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | |||
1303 | } | |||
1304 | ||||
1305 | void Verifier::visitDIImportedEntity(const DIImportedEntity &N) { | |||
1306 | AssertDI(N.getTag() == dwarf::DW_TAG_imported_module ||do { if (!(N.getTag() == dwarf::DW_TAG_imported_module || N.getTag () == dwarf::DW_TAG_imported_declaration)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false) | |||
1307 | N.getTag() == dwarf::DW_TAG_imported_declaration,do { if (!(N.getTag() == dwarf::DW_TAG_imported_module || N.getTag () == dwarf::DW_TAG_imported_declaration)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false) | |||
1308 | "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_imported_module || N.getTag () == dwarf::DW_TAG_imported_declaration)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | |||
1309 | if (auto *S = N.getRawScope()) | |||
1310 | AssertDI(isa<DIScope>(S), "invalid scope for imported entity", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope for imported entity" , &N, S); return; } } while (false); | |||
1311 | AssertDI(isDINode(N.getRawEntity()), "invalid imported entity", &N,do { if (!(isDINode(N.getRawEntity()))) { DebugInfoCheckFailed ("invalid imported entity", &N, N.getRawEntity()); return ; } } while (false) | |||
1312 | N.getRawEntity())do { if (!(isDINode(N.getRawEntity()))) { DebugInfoCheckFailed ("invalid imported entity", &N, N.getRawEntity()); return ; } } while (false); | |||
1313 | } | |||
1314 | ||||
1315 | void Verifier::visitComdat(const Comdat &C) { | |||
1316 | // In COFF the Module is invalid if the GlobalValue has private linkage. | |||
1317 | // Entities with private linkage don't have entries in the symbol table. | |||
1318 | if (TT.isOSBinFormatCOFF()) | |||
1319 | if (const GlobalValue *GV = M.getNamedValue(C.getName())) | |||
1320 | Assert(!GV->hasPrivateLinkage(),do { if (!(!GV->hasPrivateLinkage())) { CheckFailed("comdat global value has private linkage" , GV); return; } } while (false) | |||
1321 | "comdat global value has private linkage", GV)do { if (!(!GV->hasPrivateLinkage())) { CheckFailed("comdat global value has private linkage" , GV); return; } } while (false); | |||
1322 | } | |||
1323 | ||||
1324 | void Verifier::visitModuleIdents(const Module &M) { | |||
1325 | const NamedMDNode *Idents = M.getNamedMetadata("llvm.ident"); | |||
1326 | if (!Idents) | |||
1327 | return; | |||
1328 | ||||
1329 | // llvm.ident takes a list of metadata entry. Each entry has only one string. | |||
1330 | // Scan each llvm.ident entry and make sure that this requirement is met. | |||
1331 | for (const MDNode *N : Idents->operands()) { | |||
1332 | Assert(N->getNumOperands() == 1,do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.ident metadata" , N); return; } } while (false) | |||
1333 | "incorrect number of operands in llvm.ident metadata", N)do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.ident metadata" , N); return; } } while (false); | |||
1334 | Assert(dyn_cast_or_null<MDString>(N->getOperand(0)),do { if (!(dyn_cast_or_null<MDString>(N->getOperand( 0)))) { CheckFailed(("invalid value for llvm.ident metadata entry operand" "(the operand should be a string)"), N->getOperand(0)); return ; } } while (false) | |||
1335 | ("invalid value for llvm.ident metadata entry operand"do { if (!(dyn_cast_or_null<MDString>(N->getOperand( 0)))) { CheckFailed(("invalid value for llvm.ident metadata entry operand" "(the operand should be a string)"), N->getOperand(0)); return ; } } while (false) | |||
1336 | "(the operand should be a string)"),do { if (!(dyn_cast_or_null<MDString>(N->getOperand( 0)))) { CheckFailed(("invalid value for llvm.ident metadata entry operand" "(the operand should be a string)"), N->getOperand(0)); return ; } } while (false) | |||
1337 | N->getOperand(0))do { if (!(dyn_cast_or_null<MDString>(N->getOperand( 0)))) { CheckFailed(("invalid value for llvm.ident metadata entry operand" "(the operand should be a string)"), N->getOperand(0)); return ; } } while (false); | |||
1338 | } | |||
1339 | } | |||
1340 | ||||
1341 | void Verifier::visitModuleCommandLines(const Module &M) { | |||
1342 | const NamedMDNode *CommandLines = M.getNamedMetadata("llvm.commandline"); | |||
1343 | if (!CommandLines) | |||
1344 | return; | |||
1345 | ||||
1346 | // llvm.commandline takes a list of metadata entry. Each entry has only one | |||
1347 | // string. Scan each llvm.commandline entry and make sure that this | |||
1348 | // requirement is met. | |||
1349 | for (const MDNode *N : CommandLines->operands()) { | |||
1350 | Assert(N->getNumOperands() == 1,do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.commandline metadata" , N); return; } } while (false) | |||
1351 | "incorrect number of operands in llvm.commandline metadata", N)do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.commandline metadata" , N); return; } } while (false); | |||
1352 | Assert(dyn_cast_or_null<MDString>(N->getOperand(0)),do { if (!(dyn_cast_or_null<MDString>(N->getOperand( 0)))) { CheckFailed(("invalid value for llvm.commandline metadata entry operand" "(the operand should be a string)"), N->getOperand(0)); return ; } } while (false) | |||
1353 | ("invalid value for llvm.commandline metadata entry operand"do { if (!(dyn_cast_or_null<MDString>(N->getOperand( 0)))) { CheckFailed(("invalid value for llvm.commandline metadata entry operand" "(the operand should be a string)"), N->getOperand(0)); return ; } } while (false) | |||
1354 | "(the operand should be a string)"),do { if (!(dyn_cast_or_null<MDString>(N->getOperand( 0)))) { CheckFailed(("invalid value for llvm.commandline metadata entry operand" "(the operand should be a string)"), N->getOperand(0)); return ; } } while (false) | |||
1355 | N->getOperand(0))do { if (!(dyn_cast_or_null<MDString>(N->getOperand( 0)))) { CheckFailed(("invalid value for llvm.commandline metadata entry operand" "(the operand should be a string)"), N->getOperand(0)); return ; } } while (false); | |||
1356 | } | |||
1357 | } | |||
1358 | ||||
1359 | void Verifier::visitModuleFlags(const Module &M) { | |||
1360 | const NamedMDNode *Flags = M.getModuleFlagsMetadata(); | |||
1361 | if (!Flags) return; | |||
1362 | ||||
1363 | // Scan each flag, and track the flags and requirements. | |||
1364 | DenseMap<const MDString*, const MDNode*> SeenIDs; | |||
1365 | SmallVector<const MDNode*, 16> Requirements; | |||
1366 | for (const MDNode *MDN : Flags->operands()) | |||
1367 | visitModuleFlag(MDN, SeenIDs, Requirements); | |||
1368 | ||||
1369 | // Validate that the requirements in the module are valid. | |||
1370 | for (const MDNode *Requirement : Requirements) { | |||
1371 | const MDString *Flag = cast<MDString>(Requirement->getOperand(0)); | |||
1372 | const Metadata *ReqValue = Requirement->getOperand(1); | |||
1373 | ||||
1374 | const MDNode *Op = SeenIDs.lookup(Flag); | |||
1375 | if (!Op) { | |||
1376 | CheckFailed("invalid requirement on flag, flag is not present in module", | |||
1377 | Flag); | |||
1378 | continue; | |||
1379 | } | |||
1380 | ||||
1381 | if (Op->getOperand(2) != ReqValue) { | |||
1382 | CheckFailed(("invalid requirement on flag, " | |||
1383 | "flag does not have the required value"), | |||
1384 | Flag); | |||
1385 | continue; | |||
1386 | } | |||
1387 | } | |||
1388 | } | |||
1389 | ||||
1390 | void | |||
1391 | Verifier::visitModuleFlag(const MDNode *Op, | |||
1392 | DenseMap<const MDString *, const MDNode *> &SeenIDs, | |||
1393 | SmallVectorImpl<const MDNode *> &Requirements) { | |||
1394 | // Each module flag should have three arguments, the merge behavior (a | |||
1395 | // constant int), the flag ID (an MDString), and the value. | |||
1396 | Assert(Op->getNumOperands() == 3,do { if (!(Op->getNumOperands() == 3)) { CheckFailed("incorrect number of operands in module flag" , Op); return; } } while (false) | |||
1397 | "incorrect number of operands in module flag", Op)do { if (!(Op->getNumOperands() == 3)) { CheckFailed("incorrect number of operands in module flag" , Op); return; } } while (false); | |||
1398 | Module::ModFlagBehavior MFB; | |||
1399 | if (!Module::isValidModFlagBehavior(Op->getOperand(0), MFB)) { | |||
1400 | Assert(do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op ->getOperand(0)))) { CheckFailed("invalid behavior operand in module flag (expected constant integer)" , Op->getOperand(0)); return; } } while (false) | |||
1401 | mdconst::dyn_extract_or_null<ConstantInt>(Op->getOperand(0)),do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op ->getOperand(0)))) { CheckFailed("invalid behavior operand in module flag (expected constant integer)" , Op->getOperand(0)); return; } } while (false) | |||
1402 | "invalid behavior operand in module flag (expected constant integer)",do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op ->getOperand(0)))) { CheckFailed("invalid behavior operand in module flag (expected constant integer)" , Op->getOperand(0)); return; } } while (false) | |||
1403 | Op->getOperand(0))do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op ->getOperand(0)))) { CheckFailed("invalid behavior operand in module flag (expected constant integer)" , Op->getOperand(0)); return; } } while (false); | |||
1404 | Assert(false,do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)" , Op->getOperand(0)); return; } } while (false) | |||
1405 | "invalid behavior operand in module flag (unexpected constant)",do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)" , Op->getOperand(0)); return; } } while (false) | |||
1406 | Op->getOperand(0))do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)" , Op->getOperand(0)); return; } } while (false); | |||
1407 | } | |||
1408 | MDString *ID = dyn_cast_or_null<MDString>(Op->getOperand(1)); | |||
1409 | Assert(ID, "invalid ID operand in module flag (expected metadata string)",do { if (!(ID)) { CheckFailed("invalid ID operand in module flag (expected metadata string)" , Op->getOperand(1)); return; } } while (false) | |||
1410 | Op->getOperand(1))do { if (!(ID)) { CheckFailed("invalid ID operand in module flag (expected metadata string)" , Op->getOperand(1)); return; } } while (false); | |||
1411 | ||||
1412 | // Sanity check the values for behaviors with additional requirements. | |||
1413 | switch (MFB) { | |||
1414 | case Module::Error: | |||
1415 | case Module::Warning: | |||
1416 | case Module::Override: | |||
1417 | // These behavior types accept any value. | |||
1418 | break; | |||
1419 | ||||
1420 | case Module::Max: { | |||
1421 | Assert(mdconst::dyn_extract_or_null<ConstantInt>(Op->getOperand(2)),do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op ->getOperand(2)))) { CheckFailed("invalid value for 'max' module flag (expected constant integer)" , Op->getOperand(2)); return; } } while (false) | |||
1422 | "invalid value for 'max' module flag (expected constant integer)",do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op ->getOperand(2)))) { CheckFailed("invalid value for 'max' module flag (expected constant integer)" , Op->getOperand(2)); return; } } while (false) | |||
1423 | Op->getOperand(2))do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op ->getOperand(2)))) { CheckFailed("invalid value for 'max' module flag (expected constant integer)" , Op->getOperand(2)); return; } } while (false); | |||
1424 | break; | |||
1425 | } | |||
1426 | ||||
1427 | case Module::Require: { | |||
1428 | // The value should itself be an MDNode with two operands, a flag ID (an | |||
1429 | // MDString), and a value. | |||
1430 | MDNode *Value = dyn_cast<MDNode>(Op->getOperand(2)); | |||
1431 | Assert(Value && Value->getNumOperands() == 2,do { if (!(Value && Value->getNumOperands() == 2)) { CheckFailed("invalid value for 'require' module flag (expected metadata pair)" , Op->getOperand(2)); return; } } while (false) | |||
1432 | "invalid value for 'require' module flag (expected metadata pair)",do { if (!(Value && Value->getNumOperands() == 2)) { CheckFailed("invalid value for 'require' module flag (expected metadata pair)" , Op->getOperand(2)); return; } } while (false) | |||
1433 | Op->getOperand(2))do { if (!(Value && Value->getNumOperands() == 2)) { CheckFailed("invalid value for 'require' module flag (expected metadata pair)" , Op->getOperand(2)); return; } } while (false); | |||
1434 | Assert(isa<MDString>(Value->getOperand(0)),do { if (!(isa<MDString>(Value->getOperand(0)))) { CheckFailed (("invalid value for 'require' module flag " "(first value operand should be a string)" ), Value->getOperand(0)); return; } } while (false) | |||
1435 | ("invalid value for 'require' module flag "do { if (!(isa<MDString>(Value->getOperand(0)))) { CheckFailed (("invalid value for 'require' module flag " "(first value operand should be a string)" ), Value->getOperand(0)); return; } } while (false) | |||
1436 | "(first value operand should be a string)"),do { if (!(isa<MDString>(Value->getOperand(0)))) { CheckFailed (("invalid value for 'require' module flag " "(first value operand should be a string)" ), Value->getOperand(0)); return; } } while (false) | |||
1437 | Value->getOperand(0))do { if (!(isa<MDString>(Value->getOperand(0)))) { CheckFailed (("invalid value for 'require' module flag " "(first value operand should be a string)" ), Value->getOperand(0)); return; } } while (false); | |||
1438 | ||||
1439 | // Append it to the list of requirements, to check once all module flags are | |||
1440 | // scanned. | |||
1441 | Requirements.push_back(Value); | |||
1442 | break; | |||
1443 | } | |||
1444 | ||||
1445 | case Module::Append: | |||
1446 | case Module::AppendUnique: { | |||
1447 | // These behavior types require the operand be an MDNode. | |||
1448 | Assert(isa<MDNode>(Op->getOperand(2)),do { if (!(isa<MDNode>(Op->getOperand(2)))) { CheckFailed ("invalid value for 'append'-type module flag " "(expected a metadata node)" , Op->getOperand(2)); return; } } while (false) | |||
1449 | "invalid value for 'append'-type module flag "do { if (!(isa<MDNode>(Op->getOperand(2)))) { CheckFailed ("invalid value for 'append'-type module flag " "(expected a metadata node)" , Op->getOperand(2)); return; } } while (false) | |||
1450 | "(expected a metadata node)",do { if (!(isa<MDNode>(Op->getOperand(2)))) { CheckFailed ("invalid value for 'append'-type module flag " "(expected a metadata node)" , Op->getOperand(2)); return; } } while (false) | |||
1451 | Op->getOperand(2))do { if (!(isa<MDNode>(Op->getOperand(2)))) { CheckFailed ("invalid value for 'append'-type module flag " "(expected a metadata node)" , Op->getOperand(2)); return; } } while (false); | |||
1452 | break; | |||
1453 | } | |||
1454 | } | |||
1455 | ||||
1456 | // Unless this is a "requires" flag, check the ID is unique. | |||
1457 | if (MFB != Module::Require) { | |||
1458 | bool Inserted = SeenIDs.insert(std::make_pair(ID, Op)).second; | |||
1459 | Assert(Inserted,do { if (!(Inserted)) { CheckFailed("module flag identifiers must be unique (or of 'require' type)" , ID); return; } } while (false) | |||
1460 | "module flag identifiers must be unique (or of 'require' type)", ID)do { if (!(Inserted)) { CheckFailed("module flag identifiers must be unique (or of 'require' type)" , ID); return; } } while (false); | |||
1461 | } | |||
1462 | ||||
1463 | if (ID->getString() == "wchar_size") { | |||
1464 | ConstantInt *Value | |||
1465 | = mdconst::dyn_extract_or_null<ConstantInt>(Op->getOperand(2)); | |||
1466 | Assert(Value, "wchar_size metadata requires constant integer argument")do { if (!(Value)) { CheckFailed("wchar_size metadata requires constant integer argument" ); return; } } while (false); | |||
1467 | } | |||
1468 | ||||
1469 | if (ID->getString() == "Linker Options") { | |||
1470 | // If the llvm.linker.options named metadata exists, we assume that the | |||
1471 | // bitcode reader has upgraded the module flag. Otherwise the flag might | |||
1472 | // have been created by a client directly. | |||
1473 | Assert(M.getNamedMetadata("llvm.linker.options"),do { if (!(M.getNamedMetadata("llvm.linker.options"))) { CheckFailed ("'Linker Options' named metadata no longer supported"); return ; } } while (false) | |||
1474 | "'Linker Options' named metadata no longer supported")do { if (!(M.getNamedMetadata("llvm.linker.options"))) { CheckFailed ("'Linker Options' named metadata no longer supported"); return ; } } while (false); | |||
1475 | } | |||
1476 | ||||
1477 | if (ID->getString() == "CG Profile") { | |||
1478 | for (const MDOperand &MDO : cast<MDNode>(Op->getOperand(2))->operands()) | |||
1479 | visitModuleFlagCGProfileEntry(MDO); | |||
1480 | } | |||
1481 | } | |||
1482 | ||||
1483 | void Verifier::visitModuleFlagCGProfileEntry(const MDOperand &MDO) { | |||
1484 | auto CheckFunction = [&](const MDOperand &FuncMDO) { | |||
1485 | if (!FuncMDO) | |||
1486 | return; | |||
1487 | auto F = dyn_cast<ValueAsMetadata>(FuncMDO); | |||
1488 | Assert(F && isa<Function>(F->getValue()), "expected a Function or null",do { if (!(F && isa<Function>(F->getValue()) )) { CheckFailed("expected a Function or null", FuncMDO); return ; } } while (false) | |||
1489 | FuncMDO)do { if (!(F && isa<Function>(F->getValue()) )) { CheckFailed("expected a Function or null", FuncMDO); return ; } } while (false); | |||
1490 | }; | |||
1491 | auto Node = dyn_cast_or_null<MDNode>(MDO); | |||
1492 | Assert(Node && Node->getNumOperands() == 3, "expected a MDNode triple", MDO)do { if (!(Node && Node->getNumOperands() == 3)) { CheckFailed("expected a MDNode triple", MDO); return; } } while (false); | |||
1493 | CheckFunction(Node->getOperand(0)); | |||
1494 | CheckFunction(Node->getOperand(1)); | |||
1495 | auto Count = dyn_cast_or_null<ConstantAsMetadata>(Node->getOperand(2)); | |||
1496 | Assert(Count && Count->getType()->isIntegerTy(),do { if (!(Count && Count->getType()->isIntegerTy ())) { CheckFailed("expected an integer constant", Node->getOperand (2)); return; } } while (false) | |||
1497 | "expected an integer constant", Node->getOperand(2))do { if (!(Count && Count->getType()->isIntegerTy ())) { CheckFailed("expected an integer constant", Node->getOperand (2)); return; } } while (false); | |||
1498 | } | |||
1499 | ||||
1500 | /// Return true if this attribute kind only applies to functions. | |||
1501 | static bool isFuncOnlyAttr(Attribute::AttrKind Kind) { | |||
1502 | switch (Kind) { | |||
1503 | case Attribute::NoReturn: | |||
1504 | case Attribute::NoSync: | |||
1505 | case Attribute::WillReturn: | |||
1506 | case Attribute::NoCfCheck: | |||
1507 | case Attribute::NoUnwind: | |||
1508 | case Attribute::NoInline: | |||
1509 | case Attribute::AlwaysInline: | |||
1510 | case Attribute::OptimizeForSize: | |||
1511 | case Attribute::StackProtect: | |||
1512 | case Attribute::StackProtectReq: | |||
1513 | case Attribute::StackProtectStrong: | |||
1514 | case Attribute::SafeStack: | |||
1515 | case Attribute::ShadowCallStack: | |||
1516 | case Attribute::NoRedZone: | |||
1517 | case Attribute::NoImplicitFloat: | |||
1518 | case Attribute::Naked: | |||
1519 | case Attribute::InlineHint: | |||
1520 | case Attribute::StackAlignment: | |||
1521 | case Attribute::UWTable: | |||
1522 | case Attribute::NonLazyBind: | |||
1523 | case Attribute::ReturnsTwice: | |||
1524 | case Attribute::SanitizeAddress: | |||
1525 | case Attribute::SanitizeHWAddress: | |||
1526 | case Attribute::SanitizeMemTag: | |||
1527 | case Attribute::SanitizeThread: | |||
1528 | case Attribute::SanitizeMemory: | |||
1529 | case Attribute::MinSize: | |||
1530 | case Attribute::NoDuplicate: | |||
1531 | case Attribute::Builtin: | |||
1532 | case Attribute::NoBuiltin: | |||
1533 | case Attribute::Cold: | |||
1534 | case Attribute::OptForFuzzing: | |||
1535 | case Attribute::OptimizeNone: | |||
1536 | case Attribute::JumpTable: | |||
1537 | case Attribute::Convergent: | |||
1538 | case Attribute::ArgMemOnly: | |||
1539 | case Attribute::NoRecurse: | |||
1540 | case Attribute::InaccessibleMemOnly: | |||
1541 | case Attribute::InaccessibleMemOrArgMemOnly: | |||
1542 | case Attribute::AllocSize: | |||
1543 | case Attribute::SpeculativeLoadHardening: | |||
1544 | case Attribute::Speculatable: | |||
1545 | case Attribute::StrictFP: | |||
1546 | return true; | |||
1547 | default: | |||
1548 | break; | |||
1549 | } | |||
1550 | return false; | |||
1551 | } | |||
1552 | ||||
1553 | /// Return true if this is a function attribute that can also appear on | |||
1554 | /// arguments. | |||
1555 | static bool isFuncOrArgAttr(Attribute::AttrKind Kind) { | |||
1556 | return Kind == Attribute::ReadOnly || Kind == Attribute::WriteOnly || | |||
1557 | Kind == Attribute::ReadNone || Kind == Attribute::NoFree; | |||
1558 | } | |||
1559 | ||||
1560 | void Verifier::verifyAttributeTypes(AttributeSet Attrs, bool IsFunction, | |||
1561 | const Value *V) { | |||
1562 | for (Attribute A : Attrs) { | |||
1563 | if (A.isStringAttribute()) | |||
1564 | continue; | |||
1565 | ||||
1566 | if (isFuncOnlyAttr(A.getKindAsEnum())) { | |||
1567 | if (!IsFunction) { | |||
1568 | CheckFailed("Attribute '" + A.getAsString() + | |||
1569 | "' only applies to functions!", | |||
1570 | V); | |||
1571 | return; | |||
1572 | } | |||
1573 | } else if (IsFunction && !isFuncOrArgAttr(A.getKindAsEnum())) { | |||
1574 | CheckFailed("Attribute '" + A.getAsString() + | |||
1575 | "' does not apply to functions!", | |||
1576 | V); | |||
1577 | return; | |||
1578 | } | |||
1579 | } | |||
1580 | } | |||
1581 | ||||
1582 | // VerifyParameterAttrs - Check the given attributes for an argument or return | |||
1583 | // value of the specified type. The value V is printed in error messages. | |||
1584 | void Verifier::verifyParameterAttrs(AttributeSet Attrs, Type *Ty, | |||
1585 | const Value *V) { | |||
1586 | if (!Attrs.hasAttributes()) | |||
1587 | return; | |||
1588 | ||||
1589 | verifyAttributeTypes(Attrs, /*IsFunction=*/false, V); | |||
1590 | ||||
1591 | if (Attrs.hasAttribute(Attribute::ImmArg)) { | |||
1592 | Assert(Attrs.getNumAttributes() == 1,do { if (!(Attrs.getNumAttributes() == 1)) { CheckFailed("Attribute 'immarg' is incompatible with other attributes" , V); return; } } while (false) | |||
1593 | "Attribute 'immarg' is incompatible with other attributes", V)do { if (!(Attrs.getNumAttributes() == 1)) { CheckFailed("Attribute 'immarg' is incompatible with other attributes" , V); return; } } while (false); | |||
1594 | } | |||
1595 | ||||
1596 | // Check for mutually incompatible attributes. Only inreg is compatible with | |||
1597 | // sret. | |||
1598 | unsigned AttrCount = 0; | |||
1599 | AttrCount += Attrs.hasAttribute(Attribute::ByVal); | |||
1600 | AttrCount += Attrs.hasAttribute(Attribute::InAlloca); | |||
1601 | AttrCount += Attrs.hasAttribute(Attribute::StructRet) || | |||
1602 | Attrs.hasAttribute(Attribute::InReg); | |||
1603 | AttrCount += Attrs.hasAttribute(Attribute::Nest); | |||
1604 | Assert(AttrCount <= 1, "Attributes 'byval', 'inalloca', 'inreg', 'nest', "do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'inreg', 'nest', " "and 'sret' are incompatible!", V); return; } } while (false ) | |||
1605 | "and 'sret' are incompatible!",do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'inreg', 'nest', " "and 'sret' are incompatible!", V); return; } } while (false ) | |||
1606 | V)do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'inreg', 'nest', " "and 'sret' are incompatible!", V); return; } } while (false ); | |||
1607 | ||||
1608 | Assert(!(Attrs.hasAttribute(Attribute::InAlloca) &&do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'inalloca and readonly' are incompatible!", V); return; } } while (false) | |||
1609 | Attrs.hasAttribute(Attribute::ReadOnly)),do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'inalloca and readonly' are incompatible!", V); return; } } while (false) | |||
1610 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'inalloca and readonly' are incompatible!", V); return; } } while (false) | |||
1611 | "'inalloca and readonly' are incompatible!",do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'inalloca and readonly' are incompatible!", V); return; } } while (false) | |||
1612 | V)do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'inalloca and readonly' are incompatible!", V); return; } } while (false); | |||
1613 | ||||
1614 | Assert(!(Attrs.hasAttribute(Attribute::StructRet) &&do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) && Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes " "'sret and returned' are incompatible!", V); return; } } while (false) | |||
1615 | Attrs.hasAttribute(Attribute::Returned)),do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) && Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes " "'sret and returned' are incompatible!", V); return; } } while (false) | |||
1616 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) && Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes " "'sret and returned' are incompatible!", V); return; } } while (false) | |||
1617 | "'sret and returned' are incompatible!",do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) && Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes " "'sret and returned' are incompatible!", V); return; } } while (false) | |||
1618 | V)do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) && Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes " "'sret and returned' are incompatible!", V); return; } } while (false); | |||
1619 | ||||
1620 | Assert(!(Attrs.hasAttribute(Attribute::ZExt) &&do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs .hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes " "'zeroext and signext' are incompatible!", V); return; } } while (false) | |||
1621 | Attrs.hasAttribute(Attribute::SExt)),do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs .hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes " "'zeroext and signext' are incompatible!", V); return; } } while (false) | |||
1622 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs .hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes " "'zeroext and signext' are incompatible!", V); return; } } while (false) | |||
1623 | "'zeroext and signext' are incompatible!",do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs .hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes " "'zeroext and signext' are incompatible!", V); return; } } while (false) | |||
1624 | V)do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs .hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes " "'zeroext and signext' are incompatible!", V); return; } } while (false); | |||
1625 | ||||
1626 | Assert(!(Attrs.hasAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'readnone and readonly' are incompatible!", V); return; } } while (false) | |||
1627 | Attrs.hasAttribute(Attribute::ReadOnly)),do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'readnone and readonly' are incompatible!", V); return; } } while (false) | |||
1628 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'readnone and readonly' are incompatible!", V); return; } } while (false) | |||
1629 | "'readnone and readonly' are incompatible!",do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'readnone and readonly' are incompatible!", V); return; } } while (false) | |||
1630 | V)do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'readnone and readonly' are incompatible!", V); return; } } while (false); | |||
1631 | ||||
1632 | Assert(!(Attrs.hasAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readnone and writeonly' are incompatible!", V); return; } } while (false) | |||
1633 | Attrs.hasAttribute(Attribute::WriteOnly)),do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readnone and writeonly' are incompatible!", V); return; } } while (false) | |||
1634 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readnone and writeonly' are incompatible!", V); return; } } while (false) | |||
1635 | "'readnone and writeonly' are incompatible!",do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readnone and writeonly' are incompatible!", V); return; } } while (false) | |||
1636 | V)do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readnone and writeonly' are incompatible!", V); return; } } while (false); | |||
1637 | ||||
1638 | Assert(!(Attrs.hasAttribute(Attribute::ReadOnly) &&do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readonly and writeonly' are incompatible!", V); return; } } while (false) | |||
1639 | Attrs.hasAttribute(Attribute::WriteOnly)),do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readonly and writeonly' are incompatible!", V); return; } } while (false) | |||
1640 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readonly and writeonly' are incompatible!", V); return; } } while (false) | |||
1641 | "'readonly and writeonly' are incompatible!",do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readonly and writeonly' are incompatible!", V); return; } } while (false) | |||
1642 | V)do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readonly and writeonly' are incompatible!", V); return; } } while (false); | |||
1643 | ||||
1644 | Assert(!(Attrs.hasAttribute(Attribute::NoInline) &&do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) && Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed ("Attributes " "'noinline and alwaysinline' are incompatible!" , V); return; } } while (false) | |||
1645 | Attrs.hasAttribute(Attribute::AlwaysInline)),do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) && Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed ("Attributes " "'noinline and alwaysinline' are incompatible!" , V); return; } } while (false) | |||
1646 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) && Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed ("Attributes " "'noinline and alwaysinline' are incompatible!" , V); return; } } while (false) | |||
1647 | "'noinline and alwaysinline' are incompatible!",do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) && Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed ("Attributes " "'noinline and alwaysinline' are incompatible!" , V); return; } } while (false) | |||
1648 | V)do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) && Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed ("Attributes " "'noinline and alwaysinline' are incompatible!" , V); return; } } while (false); | |||
1649 | ||||
1650 | if (Attrs.hasAttribute(Attribute::ByVal) && Attrs.getByValType()) { | |||
1651 | Assert(Attrs.getByValType() == cast<PointerType>(Ty)->getElementType(),do { if (!(Attrs.getByValType() == cast<PointerType>(Ty )->getElementType())) { CheckFailed("Attribute 'byval' type does not match parameter!" , V); return; } } while (false) | |||
1652 | "Attribute 'byval' type does not match parameter!", V)do { if (!(Attrs.getByValType() == cast<PointerType>(Ty )->getElementType())) { CheckFailed("Attribute 'byval' type does not match parameter!" , V); return; } } while (false); | |||
1653 | } | |||
1654 | ||||
1655 | AttrBuilder IncompatibleAttrs = AttributeFuncs::typeIncompatible(Ty); | |||
1656 | Assert(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs),do { if (!(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs))) { CheckFailed("Wrong types for attribute: " + AttributeSet::get (Context, IncompatibleAttrs).getAsString(), V); return; } } while (false) | |||
1657 | "Wrong types for attribute: " +do { if (!(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs))) { CheckFailed("Wrong types for attribute: " + AttributeSet::get (Context, IncompatibleAttrs).getAsString(), V); return; } } while (false) | |||
1658 | AttributeSet::get(Context, IncompatibleAttrs).getAsString(),do { if (!(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs))) { CheckFailed("Wrong types for attribute: " + AttributeSet::get (Context, IncompatibleAttrs).getAsString(), V); return; } } while (false) | |||
1659 | V)do { if (!(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs))) { CheckFailed("Wrong types for attribute: " + AttributeSet::get (Context, IncompatibleAttrs).getAsString(), V); return; } } while (false); | |||
1660 | ||||
1661 | if (PointerType *PTy = dyn_cast<PointerType>(Ty)) { | |||
1662 | SmallPtrSet<Type*, 4> Visited; | |||
1663 | if (!PTy->getElementType()->isSized(&Visited)) { | |||
1664 | Assert(!Attrs.hasAttribute(Attribute::ByVal) &&do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && ! Attrs.hasAttribute(Attribute::InAlloca))) { CheckFailed("Attributes 'byval' and 'inalloca' do not support unsized types!" , V); return; } } while (false) | |||
1665 | !Attrs.hasAttribute(Attribute::InAlloca),do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && ! Attrs.hasAttribute(Attribute::InAlloca))) { CheckFailed("Attributes 'byval' and 'inalloca' do not support unsized types!" , V); return; } } while (false) | |||
1666 | "Attributes 'byval' and 'inalloca' do not support unsized types!",do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && ! Attrs.hasAttribute(Attribute::InAlloca))) { CheckFailed("Attributes 'byval' and 'inalloca' do not support unsized types!" , V); return; } } while (false) | |||
1667 | V)do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && ! Attrs.hasAttribute(Attribute::InAlloca))) { CheckFailed("Attributes 'byval' and 'inalloca' do not support unsized types!" , V); return; } } while (false); | |||
1668 | } | |||
1669 | if (!isa<PointerType>(PTy->getElementType())) | |||
1670 | Assert(!Attrs.hasAttribute(Attribute::SwiftError),do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer to pointer type!" , V); return; } } while (false) | |||
1671 | "Attribute 'swifterror' only applies to parameters "do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer to pointer type!" , V); return; } } while (false) | |||
1672 | "with pointer to pointer type!",do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer to pointer type!" , V); return; } } while (false) | |||
1673 | V)do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer to pointer type!" , V); return; } } while (false); | |||
1674 | } else { | |||
1675 | Assert(!Attrs.hasAttribute(Attribute::ByVal),do { if (!(!Attrs.hasAttribute(Attribute::ByVal))) { CheckFailed ("Attribute 'byval' only applies to parameters with pointer type!" , V); return; } } while (false) | |||
1676 | "Attribute 'byval' only applies to parameters with pointer type!",do { if (!(!Attrs.hasAttribute(Attribute::ByVal))) { CheckFailed ("Attribute 'byval' only applies to parameters with pointer type!" , V); return; } } while (false) | |||
1677 | V)do { if (!(!Attrs.hasAttribute(Attribute::ByVal))) { CheckFailed ("Attribute 'byval' only applies to parameters with pointer type!" , V); return; } } while (false); | |||
1678 | Assert(!Attrs.hasAttribute(Attribute::SwiftError),do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer type!" , V); return; } } while (false) | |||
1679 | "Attribute 'swifterror' only applies to parameters "do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer type!" , V); return; } } while (false) | |||
1680 | "with pointer type!",do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer type!" , V); return; } } while (false) | |||
1681 | V)do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer type!" , V); return; } } while (false); | |||
1682 | } | |||
1683 | } | |||
1684 | ||||
1685 | // Check parameter attributes against a function type. | |||
1686 | // The value V is printed in error messages. | |||
1687 | void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs, | |||
1688 | const Value *V, bool IsIntrinsic) { | |||
1689 | if (Attrs.isEmpty()) | |||
1690 | return; | |||
1691 | ||||
1692 | bool SawNest = false; | |||
1693 | bool SawReturned = false; | |||
1694 | bool SawSRet = false; | |||
1695 | bool SawSwiftSelf = false; | |||
1696 | bool SawSwiftError = false; | |||
1697 | ||||
1698 | // Verify return value attributes. | |||
1699 | AttributeSet RetAttrs = Attrs.getRetAttributes(); | |||
1700 | Assert((!RetAttrs.hasAttribute(Attribute::ByVal) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs .hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'" "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1701 | !RetAttrs.hasAttribute(Attribute::Nest) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs .hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'" "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1702 | !RetAttrs.hasAttribute(Attribute::StructRet) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs .hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'" "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1703 | !RetAttrs.hasAttribute(Attribute::NoCapture) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs .hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'" "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1704 | !RetAttrs.hasAttribute(Attribute::NoFree) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs .hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'" "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1705 | !RetAttrs.hasAttribute(Attribute::Returned) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs .hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'" "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1706 | !RetAttrs.hasAttribute(Attribute::InAlloca) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs .hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'" "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1707 | !RetAttrs.hasAttribute(Attribute::SwiftSelf) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs .hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'" "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1708 | !RetAttrs.hasAttribute(Attribute::SwiftError)),do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs .hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'" "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1709 | "Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'"do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs .hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'" "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1710 | "'returned', 'swiftself', and 'swifterror' do not apply to return "do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs .hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'" "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1711 | "values!",do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs .hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'" "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1712 | V)do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs .hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'" "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false); | |||
1713 | Assert((!RetAttrs.hasAttribute(Attribute::ReadOnly) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) && !RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs .hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '" + RetAttrs.getAsString() + "' does not apply to function returns" , V); return; } } while (false) | |||
1714 | !RetAttrs.hasAttribute(Attribute::WriteOnly) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) && !RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs .hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '" + RetAttrs.getAsString() + "' does not apply to function returns" , V); return; } } while (false) | |||
1715 | !RetAttrs.hasAttribute(Attribute::ReadNone)),do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) && !RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs .hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '" + RetAttrs.getAsString() + "' does not apply to function returns" , V); return; } } while (false) | |||
1716 | "Attribute '" + RetAttrs.getAsString() +do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) && !RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs .hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '" + RetAttrs.getAsString() + "' does not apply to function returns" , V); return; } } while (false) | |||
1717 | "' does not apply to function returns",do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) && !RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs .hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '" + RetAttrs.getAsString() + "' does not apply to function returns" , V); return; } } while (false) | |||
1718 | V)do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) && !RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs .hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '" + RetAttrs.getAsString() + "' does not apply to function returns" , V); return; } } while (false); | |||
1719 | verifyParameterAttrs(RetAttrs, FT->getReturnType(), V); | |||
1720 | ||||
1721 | // Verify parameter attributes. | |||
1722 | for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) { | |||
1723 | Type *Ty = FT->getParamType(i); | |||
1724 | AttributeSet ArgAttrs = Attrs.getParamAttributes(i); | |||
1725 | ||||
1726 | if (!IsIntrinsic) { | |||
1727 | Assert(!ArgAttrs.hasAttribute(Attribute::ImmArg),do { if (!(!ArgAttrs.hasAttribute(Attribute::ImmArg))) { CheckFailed ("immarg attribute only applies to intrinsics",V); return; } } while (false) | |||
1728 | "immarg attribute only applies to intrinsics",V)do { if (!(!ArgAttrs.hasAttribute(Attribute::ImmArg))) { CheckFailed ("immarg attribute only applies to intrinsics",V); return; } } while (false); | |||
1729 | } | |||
1730 | ||||
1731 | verifyParameterAttrs(ArgAttrs, Ty, V); | |||
1732 | ||||
1733 | if (ArgAttrs.hasAttribute(Attribute::Nest)) { | |||
1734 | Assert(!SawNest, "More than one parameter has attribute nest!", V)do { if (!(!SawNest)) { CheckFailed("More than one parameter has attribute nest!" , V); return; } } while (false); | |||
1735 | SawNest = true; | |||
1736 | } | |||
1737 | ||||
1738 | if (ArgAttrs.hasAttribute(Attribute::Returned)) { | |||
1739 | Assert(!SawReturned, "More than one parameter has attribute returned!",do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!" , V); return; } } while (false) | |||
1740 | V)do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!" , V); return; } } while (false); | |||
1741 | Assert(Ty->canLosslesslyBitCastTo(FT->getReturnType()),do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' attribute" , V); return; } } while (false) | |||
1742 | "Incompatible argument and return types for 'returned' attribute",do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' attribute" , V); return; } } while (false) | |||
1743 | V)do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' attribute" , V); return; } } while (false); | |||
1744 | SawReturned = true; | |||
1745 | } | |||
1746 | ||||
1747 | if (ArgAttrs.hasAttribute(Attribute::StructRet)) { | |||
1748 | Assert(!SawSRet, "Cannot have multiple 'sret' parameters!", V)do { if (!(!SawSRet)) { CheckFailed("Cannot have multiple 'sret' parameters!" , V); return; } } while (false); | |||
1749 | Assert(i == 0 || i == 1,do { if (!(i == 0 || i == 1)) { CheckFailed("Attribute 'sret' is not on first or second parameter!" , V); return; } } while (false) | |||
1750 | "Attribute 'sret' is not on first or second parameter!", V)do { if (!(i == 0 || i == 1)) { CheckFailed("Attribute 'sret' is not on first or second parameter!" , V); return; } } while (false); | |||
1751 | SawSRet = true; | |||
1752 | } | |||
1753 | ||||
1754 | if (ArgAttrs.hasAttribute(Attribute::SwiftSelf)) { | |||
1755 | Assert(!SawSwiftSelf, "Cannot have multiple 'swiftself' parameters!", V)do { if (!(!SawSwiftSelf)) { CheckFailed("Cannot have multiple 'swiftself' parameters!" , V); return; } } while (false); | |||
1756 | SawSwiftSelf = true; | |||
1757 | } | |||
1758 | ||||
1759 | if (ArgAttrs.hasAttribute(Attribute::SwiftError)) { | |||
1760 | Assert(!SawSwiftError, "Cannot have multiple 'swifterror' parameters!",do { if (!(!SawSwiftError)) { CheckFailed("Cannot have multiple 'swifterror' parameters!" , V); return; } } while (false) | |||
1761 | V)do { if (!(!SawSwiftError)) { CheckFailed("Cannot have multiple 'swifterror' parameters!" , V); return; } } while (false); | |||
1762 | SawSwiftError = true; | |||
1763 | } | |||
1764 | ||||
1765 | if (ArgAttrs.hasAttribute(Attribute::InAlloca)) { | |||
1766 | Assert(i == FT->getNumParams() - 1,do { if (!(i == FT->getNumParams() - 1)) { CheckFailed("inalloca isn't on the last parameter!" , V); return; } } while (false) | |||
1767 | "inalloca isn't on the last parameter!", V)do { if (!(i == FT->getNumParams() - 1)) { CheckFailed("inalloca isn't on the last parameter!" , V); return; } } while (false); | |||
1768 | } | |||
1769 | } | |||
1770 | ||||
1771 | if (!Attrs.hasAttributes(AttributeList::FunctionIndex)) | |||
1772 | return; | |||
1773 | ||||
1774 | verifyAttributeTypes(Attrs.getFnAttributes(), /*IsFunction=*/true, V); | |||
1775 | ||||
1776 | Assert(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes 'readnone and readonly' are incompatible!" , V); return; } } while (false) | |||
1777 | Attrs.hasFnAttribute(Attribute::ReadOnly)),do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes 'readnone and readonly' are incompatible!" , V); return; } } while (false) | |||
1778 | "Attributes 'readnone and readonly' are incompatible!", V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes 'readnone and readonly' are incompatible!" , V); return; } } while (false); | |||
1779 | ||||
1780 | Assert(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed( "Attributes 'readnone and writeonly' are incompatible!", V); return ; } } while (false) | |||
1781 | Attrs.hasFnAttribute(Attribute::WriteOnly)),do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed( "Attributes 'readnone and writeonly' are incompatible!", V); return ; } } while (false) | |||
1782 | "Attributes 'readnone and writeonly' are incompatible!", V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed( "Attributes 'readnone and writeonly' are incompatible!", V); return ; } } while (false); | |||
1783 | ||||
1784 | Assert(!(Attrs.hasFnAttribute(Attribute::ReadOnly) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadOnly) && Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed( "Attributes 'readonly and writeonly' are incompatible!", V); return ; } } while (false) | |||
1785 | Attrs.hasFnAttribute(Attribute::WriteOnly)),do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadOnly) && Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed( "Attributes 'readonly and writeonly' are incompatible!", V); return ; } } while (false) | |||
1786 | "Attributes 'readonly and writeonly' are incompatible!", V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadOnly) && Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed( "Attributes 'readonly and writeonly' are incompatible!", V); return ; } } while (false); | |||
1787 | ||||
1788 | Assert(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly) ))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are " "incompatible!", V); return; } } while (false) | |||
1789 | Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly)),do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly) ))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are " "incompatible!", V); return; } } while (false) | |||
1790 | "Attributes 'readnone and inaccessiblemem_or_argmemonly' are "do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly) ))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are " "incompatible!", V); return; } } while (false) | |||
1791 | "incompatible!",do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly) ))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are " "incompatible!", V); return; } } while (false) | |||
1792 | V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly) ))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are " "incompatible!", V); return; } } while (false); | |||
1793 | ||||
1794 | Assert(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOnly)))) { CheckFailed ("Attributes 'readnone and inaccessiblememonly' are incompatible!" , V); return; } } while (false) | |||
1795 | Attrs.hasFnAttribute(Attribute::InaccessibleMemOnly)),do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOnly)))) { CheckFailed ("Attributes 'readnone and inaccessiblememonly' are incompatible!" , V); return; } } while (false) | |||
1796 | "Attributes 'readnone and inaccessiblememonly' are incompatible!", V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOnly)))) { CheckFailed ("Attributes 'readnone and inaccessiblememonly' are incompatible!" , V); return; } } while (false); | |||
1797 | ||||
1798 | Assert(!(Attrs.hasFnAttribute(Attribute::NoInline) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::NoInline) && Attrs.hasFnAttribute(Attribute::AlwaysInline)))) { CheckFailed ("Attributes 'noinline and alwaysinline' are incompatible!", V ); return; } } while (false) | |||
1799 | Attrs.hasFnAttribute(Attribute::AlwaysInline)),do { if (!(!(Attrs.hasFnAttribute(Attribute::NoInline) && Attrs.hasFnAttribute(Attribute::AlwaysInline)))) { CheckFailed ("Attributes 'noinline and alwaysinline' are incompatible!", V ); return; } } while (false) | |||
1800 | "Attributes 'noinline and alwaysinline' are incompatible!", V)do { if (!(!(Attrs.hasFnAttribute(Attribute::NoInline) && Attrs.hasFnAttribute(Attribute::AlwaysInline)))) { CheckFailed ("Attributes 'noinline and alwaysinline' are incompatible!", V ); return; } } while (false); | |||
1801 | ||||
1802 | if (Attrs.hasFnAttribute(Attribute::OptimizeNone)) { | |||
1803 | Assert(Attrs.hasFnAttribute(Attribute::NoInline),do { if (!(Attrs.hasFnAttribute(Attribute::NoInline))) { CheckFailed ("Attribute 'optnone' requires 'noinline'!", V); return; } } while (false) | |||
1804 | "Attribute 'optnone' requires 'noinline'!", V)do { if (!(Attrs.hasFnAttribute(Attribute::NoInline))) { CheckFailed ("Attribute 'optnone' requires 'noinline'!", V); return; } } while (false); | |||
1805 | ||||
1806 | Assert(!Attrs.hasFnAttribute(Attribute::OptimizeForSize),do { if (!(!Attrs.hasFnAttribute(Attribute::OptimizeForSize)) ) { CheckFailed("Attributes 'optsize and optnone' are incompatible!" , V); return; } } while (false) | |||
1807 | "Attributes 'optsize and optnone' are incompatible!", V)do { if (!(!Attrs.hasFnAttribute(Attribute::OptimizeForSize)) ) { CheckFailed("Attributes 'optsize and optnone' are incompatible!" , V); return; } } while (false); | |||
1808 | ||||
1809 | Assert(!Attrs.hasFnAttribute(Attribute::MinSize),do { if (!(!Attrs.hasFnAttribute(Attribute::MinSize))) { CheckFailed ("Attributes 'minsize and optnone' are incompatible!", V); return ; } } while (false) | |||
1810 | "Attributes 'minsize and optnone' are incompatible!", V)do { if (!(!Attrs.hasFnAttribute(Attribute::MinSize))) { CheckFailed ("Attributes 'minsize and optnone' are incompatible!", V); return ; } } while (false); | |||
1811 | } | |||
1812 | ||||
1813 | if (Attrs.hasFnAttribute(Attribute::JumpTable)) { | |||
1814 | const GlobalValue *GV = cast<GlobalValue>(V); | |||
1815 | Assert(GV->hasGlobalUnnamedAddr(),do { if (!(GV->hasGlobalUnnamedAddr())) { CheckFailed("Attribute 'jumptable' requires 'unnamed_addr'" , V); return; } } while (false) | |||
1816 | "Attribute 'jumptable' requires 'unnamed_addr'", V)do { if (!(GV->hasGlobalUnnamedAddr())) { CheckFailed("Attribute 'jumptable' requires 'unnamed_addr'" , V); return; } } while (false); | |||
1817 | } | |||
1818 | ||||
1819 | if (Attrs.hasFnAttribute(Attribute::AllocSize)) { | |||
1820 | std::pair<unsigned, Optional<unsigned>> Args = | |||
1821 | Attrs.getAllocSizeArgs(AttributeList::FunctionIndex); | |||
1822 | ||||
1823 | auto CheckParam = [&](StringRef Name, unsigned ParamNo) { | |||
1824 | if (ParamNo >= FT->getNumParams()) { | |||
1825 | CheckFailed("'allocsize' " + Name + " argument is out of bounds", V); | |||
1826 | return false; | |||
1827 | } | |||
1828 | ||||
1829 | if (!FT->getParamType(ParamNo)->isIntegerTy()) { | |||
1830 | CheckFailed("'allocsize' " + Name + | |||
1831 | " argument must refer to an integer parameter", | |||
1832 | V); | |||
1833 | return false; | |||
1834 | } | |||
1835 | ||||
1836 | return true; | |||
1837 | }; | |||
1838 | ||||
1839 | if (!CheckParam("element size", Args.first)) | |||
1840 | return; | |||
1841 | ||||
1842 | if (Args.second && !CheckParam("number of elements", *Args.second)) | |||
1843 | return; | |||
1844 | } | |||
1845 | } | |||
1846 | ||||
1847 | void Verifier::verifyFunctionMetadata( | |||
1848 | ArrayRef<std::pair<unsigned, MDNode *>> MDs) { | |||
1849 | for (const auto &Pair : MDs) { | |||
1850 | if (Pair.first == LLVMContext::MD_prof) { | |||
1851 | MDNode *MD = Pair.second; | |||
1852 | Assert(MD->getNumOperands() >= 2,do { if (!(MD->getNumOperands() >= 2)) { CheckFailed("!prof annotations should have no less than 2 operands" , MD); return; } } while (false) | |||
1853 | "!prof annotations should have no less than 2 operands", MD)do { if (!(MD->getNumOperands() >= 2)) { CheckFailed("!prof annotations should have no less than 2 operands" , MD); return; } } while (false); | |||
1854 | ||||
1855 | // Check first operand. | |||
1856 | Assert(MD->getOperand(0) != nullptr, "first operand should not be null",do { if (!(MD->getOperand(0) != nullptr)) { CheckFailed("first operand should not be null" , MD); return; } } while (false) | |||
1857 | MD)do { if (!(MD->getOperand(0) != nullptr)) { CheckFailed("first operand should not be null" , MD); return; } } while (false); | |||
1858 | Assert(isa<MDString>(MD->getOperand(0)),do { if (!(isa<MDString>(MD->getOperand(0)))) { CheckFailed ("expected string with name of the !prof annotation", MD); return ; } } while (false) | |||
1859 | "expected string with name of the !prof annotation", MD)do { if (!(isa<MDString>(MD->getOperand(0)))) { CheckFailed ("expected string with name of the !prof annotation", MD); return ; } } while (false); | |||
1860 | MDString *MDS = cast<MDString>(MD->getOperand(0)); | |||
1861 | StringRef ProfName = MDS->getString(); | |||
1862 | Assert(ProfName.equals("function_entry_count") ||do { if (!(ProfName.equals("function_entry_count") || ProfName .equals("synthetic_function_entry_count"))) { CheckFailed("first operand should be 'function_entry_count'" " or 'synthetic_function_entry_count'", MD); return; } } while (false) | |||
1863 | ProfName.equals("synthetic_function_entry_count"),do { if (!(ProfName.equals("function_entry_count") || ProfName .equals("synthetic_function_entry_count"))) { CheckFailed("first operand should be 'function_entry_count'" " or 'synthetic_function_entry_count'", MD); return; } } while (false) | |||
1864 | "first operand should be 'function_entry_count'"do { if (!(ProfName.equals("function_entry_count") || ProfName .equals("synthetic_function_entry_count"))) { CheckFailed("first operand should be 'function_entry_count'" " or 'synthetic_function_entry_count'", MD); return; } } while (false) | |||
1865 | " or 'synthetic_function_entry_count'",do { if (!(ProfName.equals("function_entry_count") || ProfName .equals("synthetic_function_entry_count"))) { CheckFailed("first operand should be 'function_entry_count'" " or 'synthetic_function_entry_count'", MD); return; } } while (false) | |||
1866 | MD)do { if (!(ProfName.equals("function_entry_count") || ProfName .equals("synthetic_function_entry_count"))) { CheckFailed("first operand should be 'function_entry_count'" " or 'synthetic_function_entry_count'", MD); return; } } while (false); | |||
1867 | ||||
1868 | // Check second operand. | |||
1869 | Assert(MD->getOperand(1) != nullptr, "second operand should not be null",do { if (!(MD->getOperand(1) != nullptr)) { CheckFailed("second operand should not be null" , MD); return; } } while (false) | |||
1870 | MD)do { if (!(MD->getOperand(1) != nullptr)) { CheckFailed("second operand should not be null" , MD); return; } } while (false); | |||
1871 | Assert(isa<ConstantAsMetadata>(MD->getOperand(1)),do { if (!(isa<ConstantAsMetadata>(MD->getOperand(1) ))) { CheckFailed("expected integer argument to function_entry_count" , MD); return; } } while (false) | |||
1872 | "expected integer argument to function_entry_count", MD)do { if (!(isa<ConstantAsMetadata>(MD->getOperand(1) ))) { CheckFailed("expected integer argument to function_entry_count" , MD); return; } } while (false); | |||
1873 | } | |||
1874 | } | |||
1875 | } | |||
1876 | ||||
1877 | void Verifier::visitConstantExprsRecursively(const Constant *EntryC) { | |||
1878 | if (!ConstantExprVisited.insert(EntryC).second) | |||
1879 | return; | |||
1880 | ||||
1881 | SmallVector<const Constant *, 16> Stack; | |||
1882 | Stack.push_back(EntryC); | |||
1883 | ||||
1884 | while (!Stack.empty()) { | |||
1885 | const Constant *C = Stack.pop_back_val(); | |||
1886 | ||||
1887 | // Check this constant expression. | |||
1888 | if (const auto *CE = dyn_cast<ConstantExpr>(C)) | |||
1889 | visitConstantExpr(CE); | |||
1890 | ||||
1891 | if (const auto *GV = dyn_cast<GlobalValue>(C)) { | |||
1892 | // Global Values get visited separately, but we do need to make sure | |||
1893 | // that the global value is in the correct module | |||
1894 | Assert(GV->getParent() == &M, "Referencing global in another module!",do { if (!(GV->getParent() == &M)) { CheckFailed("Referencing global in another module!" , EntryC, &M, GV, GV->getParent()); return; } } while ( false) | |||
1895 | EntryC, &M, GV, GV->getParent())do { if (!(GV->getParent() == &M)) { CheckFailed("Referencing global in another module!" , EntryC, &M, GV, GV->getParent()); return; } } while ( false); | |||
1896 | continue; | |||
1897 | } | |||
1898 | ||||
1899 | // Visit all sub-expressions. | |||
1900 | for (const Use &U : C->operands()) { | |||
1901 | const auto *OpC = dyn_cast<Constant>(U); | |||
1902 | if (!OpC) | |||
1903 | continue; | |||
1904 | if (!ConstantExprVisited.insert(OpC).second) | |||
1905 | continue; | |||
1906 | Stack.push_back(OpC); | |||
1907 | } | |||
1908 | } | |||
1909 | } | |||
1910 | ||||
1911 | void Verifier::visitConstantExpr(const ConstantExpr *CE) { | |||
1912 | if (CE->getOpcode() == Instruction::BitCast) | |||
1913 | Assert(CastInst::castIsValid(Instruction::BitCast, CE->getOperand(0),do { if (!(CastInst::castIsValid(Instruction::BitCast, CE-> getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast" , CE); return; } } while (false) | |||
1914 | CE->getType()),do { if (!(CastInst::castIsValid(Instruction::BitCast, CE-> getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast" , CE); return; } } while (false) | |||
1915 | "Invalid bitcast", CE)do { if (!(CastInst::castIsValid(Instruction::BitCast, CE-> getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast" , CE); return; } } while (false); | |||
1916 | ||||
1917 | if (CE->getOpcode() == Instruction::IntToPtr || | |||
1918 | CE->getOpcode() == Instruction::PtrToInt) { | |||
1919 | auto *PtrTy = CE->getOpcode() == Instruction::IntToPtr | |||
1920 | ? CE->getType() | |||
1921 | : CE->getOperand(0)->getType(); | |||
1922 | StringRef Msg = CE->getOpcode() == Instruction::IntToPtr | |||
1923 | ? "inttoptr not supported for non-integral pointers" | |||
1924 | : "ptrtoint not supported for non-integral pointers"; | |||
1925 | Assert(do { if (!(!DL.isNonIntegralPointerType(cast<PointerType> (PtrTy->getScalarType())))) { CheckFailed(Msg); return; } } while (false) | |||
1926 | !DL.isNonIntegralPointerType(cast<PointerType>(PtrTy->getScalarType())),do { if (!(!DL.isNonIntegralPointerType(cast<PointerType> (PtrTy->getScalarType())))) { CheckFailed(Msg); return; } } while (false) | |||
1927 | Msg)do { if (!(!DL.isNonIntegralPointerType(cast<PointerType> (PtrTy->getScalarType())))) { CheckFailed(Msg); return; } } while (false); | |||
1928 | } | |||
1929 | } | |||
1930 | ||||
1931 | bool Verifier::verifyAttributeCount(AttributeList Attrs, unsigned Params) { | |||
1932 | // There shouldn't be more attribute sets than there are parameters plus the | |||
1933 | // function and return value. | |||
1934 | return Attrs.getNumAttrSets() <= Params + 2; | |||
1935 | } | |||
1936 | ||||
1937 | /// Verify that statepoint intrinsic is well formed. | |||
1938 | void Verifier::verifyStatepoint(const CallBase &Call) { | |||
1939 | assert(Call.getCalledFunction() &&((Call.getCalledFunction() && Call.getCalledFunction( )->getIntrinsicID() == Intrinsic::experimental_gc_statepoint ) ? static_cast<void> (0) : __assert_fail ("Call.getCalledFunction() && Call.getCalledFunction()->getIntrinsicID() == Intrinsic::experimental_gc_statepoint" , "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/IR/Verifier.cpp" , 1941, __PRETTY_FUNCTION__)) | |||
1940 | Call.getCalledFunction()->getIntrinsicID() ==((Call.getCalledFunction() && Call.getCalledFunction( )->getIntrinsicID() == Intrinsic::experimental_gc_statepoint ) ? static_cast<void> (0) : __assert_fail ("Call.getCalledFunction() && Call.getCalledFunction()->getIntrinsicID() == Intrinsic::experimental_gc_statepoint" , "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/IR/Verifier.cpp" , 1941, __PRETTY_FUNCTION__)) | |||
1941 | Intrinsic::experimental_gc_statepoint)((Call.getCalledFunction() && Call.getCalledFunction( )->getIntrinsicID() == Intrinsic::experimental_gc_statepoint ) ? static_cast<void> (0) : __assert_fail ("Call.getCalledFunction() && Call.getCalledFunction()->getIntrinsicID() == Intrinsic::experimental_gc_statepoint" , "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/IR/Verifier.cpp" , 1941, __PRETTY_FUNCTION__)); | |||
1942 | ||||
1943 | Assert(!Call.doesNotAccessMemory() && !Call.onlyReadsMemory() &&do { if (!(!Call.doesNotAccessMemory() && !Call.onlyReadsMemory () && !Call.onlyAccessesArgMemory())) { CheckFailed("gc.statepoint must read and write all memory to preserve " "reordering restrictions required by safepoint semantics", Call ); return; } } while (false) | |||
1944 | !Call.onlyAccessesArgMemory(),do { if (!(!Call.doesNotAccessMemory() && !Call.onlyReadsMemory () && !Call.onlyAccessesArgMemory())) { CheckFailed("gc.statepoint must read and write all memory to preserve " "reordering restrictions required by safepoint semantics", Call ); return; } } while (false) | |||
1945 | "gc.statepoint must read and write all memory to preserve "do { if (!(!Call.doesNotAccessMemory() && !Call.onlyReadsMemory () && !Call.onlyAccessesArgMemory())) { CheckFailed("gc.statepoint must read and write all memory to preserve " "reordering restrictions required by safepoint semantics", Call ); return; } } while (false) | |||
1946 | "reordering restrictions required by safepoint semantics",do { if (!(!Call.doesNotAccessMemory() && !Call.onlyReadsMemory () && !Call.onlyAccessesArgMemory())) { CheckFailed("gc.statepoint must read and write all memory to preserve " "reordering restrictions required by safepoint semantics", Call ); return; } } while (false) | |||
1947 | Call)do { if (!(!Call.doesNotAccessMemory() && !Call.onlyReadsMemory () && !Call.onlyAccessesArgMemory())) { CheckFailed("gc.statepoint must read and write all memory to preserve " "reordering restrictions required by safepoint semantics", Call ); return; } } while (false); | |||
1948 | ||||
1949 | const int64_t NumPatchBytes = | |||
1950 | cast<ConstantInt>(Call.getArgOperand(1))->getSExtValue(); | |||
1951 | assert(isInt<32>(NumPatchBytes) && "NumPatchBytesV is an i32!")((isInt<32>(NumPatchBytes) && "NumPatchBytesV is an i32!" ) ? static_cast<void> (0) : __assert_fail ("isInt<32>(NumPatchBytes) && \"NumPatchBytesV is an i32!\"" , "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/IR/Verifier.cpp" , 1951, __PRETTY_FUNCTION__)); | |||
1952 | Assert(NumPatchBytes >= 0,do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be " "positive", Call); return; } } while (false) | |||
1953 | "gc.statepoint number of patchable bytes must be "do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be " "positive", Call); return; } } while (false) | |||
1954 | "positive",do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be " "positive", Call); return; } } while (false) | |||
1955 | Call)do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be " "positive", Call); return; } } while (false); | |||
1956 | ||||
1957 | const Value *Target = Call.getArgOperand(2); | |||
1958 | auto *PT = dyn_cast<PointerType>(Target->getType()); | |||
1959 | Assert(PT && PT->getElementType()->isFunctionTy(),do { if (!(PT && PT->getElementType()->isFunctionTy ())) { CheckFailed("gc.statepoint callee must be of function pointer type" , Call, Target); return; } } while (false) | |||
1960 | "gc.statepoint callee must be of function pointer type", Call, Target)do { if (!(PT && PT->getElementType()->isFunctionTy ())) { CheckFailed("gc.statepoint callee must be of function pointer type" , Call, Target); return; } } while (false); | |||
1961 | FunctionType *TargetFuncType = cast<FunctionType>(PT->getElementType()); | |||
1962 | ||||
1963 | const int NumCallArgs = cast<ConstantInt>(Call.getArgOperand(3))->getZExtValue(); | |||
1964 | Assert(NumCallArgs >= 0,do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call " "must be positive", Call); return; } } while (false) | |||
1965 | "gc.statepoint number of arguments to underlying call "do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call " "must be positive", Call); return; } } while (false) | |||
1966 | "must be positive",do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call " "must be positive", Call); return; } } while (false) | |||
1967 | Call)do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call " "must be positive", Call); return; } } while (false); | |||
1968 | const int NumParams = (int)TargetFuncType->getNumParams(); | |||
1969 | if (TargetFuncType->isVarArg()) { | |||
1970 | Assert(NumCallArgs >= NumParams,do { if (!(NumCallArgs >= NumParams)) { CheckFailed("gc.statepoint mismatch in number of vararg call args" , Call); return; } } while (false) | |||
1971 | "gc.statepoint mismatch in number of vararg call args", Call)do { if (!(NumCallArgs >= NumParams)) { CheckFailed("gc.statepoint mismatch in number of vararg call args" , Call); return; } } while (false); | |||
1972 | ||||
1973 | // TODO: Remove this limitation | |||
1974 | Assert(TargetFuncType->getReturnType()->isVoidTy(),do { if (!(TargetFuncType->getReturnType()->isVoidTy()) ) { CheckFailed("gc.statepoint doesn't support wrapping non-void " "vararg functions yet", Call); return; } } while (false) | |||
1975 | "gc.statepoint doesn't support wrapping non-void "do { if (!(TargetFuncType->getReturnType()->isVoidTy()) ) { CheckFailed("gc.statepoint doesn't support wrapping non-void " "vararg functions yet", Call); return; } } while (false) | |||
1976 | "vararg functions yet",do { if (!(TargetFuncType->getReturnType()->isVoidTy()) ) { CheckFailed("gc.statepoint doesn't support wrapping non-void " "vararg functions yet", Call); return; } } while (false) | |||
1977 | Call)do { if (!(TargetFuncType->getReturnType()->isVoidTy()) ) { CheckFailed("gc.statepoint doesn't support wrapping non-void " "vararg functions yet", Call); return; } } while (false); | |||
1978 | } else | |||
1979 | Assert(NumCallArgs == NumParams,do { if (!(NumCallArgs == NumParams)) { CheckFailed("gc.statepoint mismatch in number of call args" , Call); return; } } while (false) | |||
1980 | "gc.statepoint mismatch in number of call args", Call)do { if (!(NumCallArgs == NumParams)) { CheckFailed("gc.statepoint mismatch in number of call args" , Call); return; } } while (false); | |||
1981 | ||||
1982 | const uint64_t Flags | |||
1983 | = cast<ConstantInt>(Call.getArgOperand(4))->getZExtValue(); | |||
1984 | Assert((Flags & ~(uint64_t)StatepointFlags::MaskAll) == 0,do { if (!((Flags & ~(uint64_t)StatepointFlags::MaskAll) == 0)) { CheckFailed("unknown flag used in gc.statepoint flags argument" , Call); return; } } while (false) | |||
1985 | "unknown flag used in gc.statepoint flags argument", Call)do { if (!((Flags & ~(uint64_t)StatepointFlags::MaskAll) == 0)) { CheckFailed("unknown flag used in gc.statepoint flags argument" , Call); return; } } while (false); | |||
1986 | ||||
1987 | // Verify that the types of the call parameter arguments match | |||
1988 | // the type of the wrapped callee. | |||
1989 | AttributeList Attrs = Call.getAttributes(); | |||
1990 | for (int i = 0; i < NumParams; i++) { | |||
1991 | Type *ParamType = TargetFuncType->getParamType(i); | |||
1992 | Type *ArgType = Call.getArgOperand(5 + i)->getType(); | |||
1993 | Assert(ArgType == ParamType,do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped " "function type", Call); return; } } while (false) | |||
1994 | "gc.statepoint call argument does not match wrapped "do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped " "function type", Call); return; } } while (false) | |||
1995 | "function type",do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped " "function type", Call); return; } } while (false) | |||
1996 | Call)do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped " "function type", Call); return; } } while (false); | |||
1997 | ||||
1998 | if (TargetFuncType->isVarArg()) { | |||
1999 | AttributeSet ArgAttrs = Attrs.getParamAttributes(5 + i); | |||
2000 | Assert(!ArgAttrs.hasAttribute(Attribute::StructRet),do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed ("Attribute 'sret' cannot be used for vararg call arguments!" , Call); return; } } while (false) | |||
2001 | "Attribute 'sret' cannot be used for vararg call arguments!",do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed ("Attribute 'sret' cannot be used for vararg call arguments!" , Call); return; } } while (false) | |||
2002 | Call)do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed ("Attribute 'sret' cannot be used for vararg call arguments!" , Call); return; } } while (false); | |||
2003 | } | |||
2004 | } | |||
2005 | ||||
2006 | const int EndCallArgsInx = 4 + NumCallArgs; | |||
2007 | ||||
2008 | const Value *NumTransitionArgsV = Call.getArgOperand(EndCallArgsInx + 1); | |||
2009 | Assert(isa<ConstantInt>(NumTransitionArgsV),do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed ("gc.statepoint number of transition arguments " "must be constant integer" , Call); return; } } while (false) | |||
2010 | "gc.statepoint number of transition arguments "do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed ("gc.statepoint number of transition arguments " "must be constant integer" , Call); return; } } while (false) | |||
2011 | "must be constant integer",do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed ("gc.statepoint number of transition arguments " "must be constant integer" , Call); return; } } while (false) | |||
2012 | Call)do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed ("gc.statepoint number of transition arguments " "must be constant integer" , Call); return; } } while (false); | |||
2013 | const int NumTransitionArgs = | |||
2014 | cast<ConstantInt>(NumTransitionArgsV)->getZExtValue(); | |||
2015 | Assert(NumTransitionArgs >= 0,do { if (!(NumTransitionArgs >= 0)) { CheckFailed("gc.statepoint number of transition arguments must be positive" , Call); return; } } while (false) | |||
2016 | "gc.statepoint number of transition arguments must be positive", Call)do { if (!(NumTransitionArgs >= 0)) { CheckFailed("gc.statepoint number of transition arguments must be positive" , Call); return; } } while (false); | |||
2017 | const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs; | |||
2018 | ||||
2019 | const Value *NumDeoptArgsV = Call.getArgOperand(EndTransitionArgsInx + 1); | |||
2020 | Assert(isa<ConstantInt>(NumDeoptArgsV),do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed ("gc.statepoint number of deoptimization arguments " "must be constant integer" , Call); return; } } while (false) | |||
2021 | "gc.statepoint number of deoptimization arguments "do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed ("gc.statepoint number of deoptimization arguments " "must be constant integer" , Call); return; } } while (false) | |||
2022 | "must be constant integer",do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed ("gc.statepoint number of deoptimization arguments " "must be constant integer" , Call); return; } } while (false) | |||
2023 | Call)do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed ("gc.statepoint number of deoptimization arguments " "must be constant integer" , Call); return; } } while (false); | |||
2024 | const int NumDeoptArgs = cast<ConstantInt>(NumDeoptArgsV)->getZExtValue(); | |||
2025 | Assert(NumDeoptArgs >= 0,do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments " "must be positive", Call); return; } } while (false) | |||
2026 | "gc.statepoint number of deoptimization arguments "do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments " "must be positive", Call); return; } } while (false) | |||
2027 | "must be positive",do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments " "must be positive", Call); return; } } while (false) | |||
2028 | Call)do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments " "must be positive", Call); return; } } while (false); | |||
2029 | ||||
2030 | const int ExpectedNumArgs = | |||
2031 | 7 + NumCallArgs + NumTransitionArgs + NumDeoptArgs; | |||
2032 | Assert(ExpectedNumArgs <= (int)Call.arg_size(),do { if (!(ExpectedNumArgs <= (int)Call.arg_size())) { CheckFailed ("gc.statepoint too few arguments according to length fields" , Call); return; } } while (false) | |||
2033 | "gc.statepoint too few arguments according to length fields", Call)do { if (!(ExpectedNumArgs <= (int)Call.arg_size())) { CheckFailed ("gc.statepoint too few arguments according to length fields" , Call); return; } } while (false); | |||
2034 | ||||
2035 | // Check that the only uses of this gc.statepoint are gc.result or | |||
2036 | // gc.relocate calls which are tied to this statepoint and thus part | |||
2037 | // of the same statepoint sequence | |||
2038 | for (const User *U : Call.users()) { | |||
2039 | const CallInst *UserCall = dyn_cast<const CallInst>(U); | |||
2040 | Assert(UserCall, "illegal use of statepoint token", Call, U)do { if (!(UserCall)) { CheckFailed("illegal use of statepoint token" , Call, U); return; } } while (false); | |||
2041 | if (!UserCall) | |||
2042 | continue; | |||
2043 | Assert(isa<GCRelocateInst>(UserCall) || isa<GCResultInst>(UserCall),do { if (!(isa<GCRelocateInst>(UserCall) || isa<GCResultInst >(UserCall))) { CheckFailed("gc.result or gc.relocate are the only value uses " "of a gc.statepoint", Call, U); return; } } while (false) | |||
2044 | "gc.result or gc.relocate are the only value uses "do { if (!(isa<GCRelocateInst>(UserCall) || isa<GCResultInst >(UserCall))) { CheckFailed("gc.result or gc.relocate are the only value uses " "of a gc.statepoint", Call, U); return; } } while (false) | |||
2045 | "of a gc.statepoint",do { if (!(isa<GCRelocateInst>(UserCall) || isa<GCResultInst >(UserCall))) { CheckFailed("gc.result or gc.relocate are the only value uses " "of a gc.statepoint", Call, U); return; } } while (false) | |||
2046 | Call, U)do { if (!(isa<GCRelocateInst>(UserCall) || isa<GCResultInst >(UserCall))) { CheckFailed("gc.result or gc.relocate are the only value uses " "of a gc.statepoint", Call, U); return; } } while (false); | |||
2047 | if (isa<GCResultInst>(UserCall)) { | |||
2048 | Assert(UserCall->getArgOperand(0) == &Call,do { if (!(UserCall->getArgOperand(0) == &Call)) { CheckFailed ("gc.result connected to wrong gc.statepoint", Call, UserCall ); return; } } while (false) | |||
2049 | "gc.result connected to wrong gc.statepoint", Call, UserCall)do { if (!(UserCall->getArgOperand(0) == &Call)) { CheckFailed ("gc.result connected to wrong gc.statepoint", Call, UserCall ); return; } } while (false); | |||
2050 | } else if (isa<GCRelocateInst>(Call)) { | |||
2051 | Assert(UserCall->getArgOperand(0) == &Call,do { if (!(UserCall->getArgOperand(0) == &Call)) { CheckFailed ("gc.relocate connected to wrong gc.statepoint", Call, UserCall ); return; } } while (false) | |||
2052 | "gc.relocate connected to wrong gc.statepoint", Call, UserCall)do { if (!(UserCall->getArgOperand(0) == &Call)) { CheckFailed ("gc.relocate connected to wrong gc.statepoint", Call, UserCall ); return; } } while (false); | |||
2053 | } | |||
2054 | } | |||
2055 | ||||
2056 | // Note: It is legal for a single derived pointer to be listed multiple | |||
2057 | // times. It's non-optimal, but it is legal. It can also happen after | |||
2058 | // insertion if we strip a bitcast away. | |||
2059 | // Note: It is really tempting to check that each base is relocated and | |||
2060 | // that a derived pointer is never reused as a base pointer. This turns | |||
2061 | // out to be problematic since optimizations run after safepoint insertion | |||
2062 | // can recognize equality properties that the insertion logic doesn't know | |||
2063 | // about. See example statepoint.ll in the verifier subdirectory | |||
2064 | } | |||
2065 | ||||
2066 | void Verifier::verifyFrameRecoverIndices() { | |||
2067 | for (auto &Counts : FrameEscapeInfo) { | |||
2068 | Function *F = Counts.first; | |||
2069 | unsigned EscapedObjectCount = Counts.second.first; | |||
2070 | unsigned MaxRecoveredIndex = Counts.second.second; | |||
2071 | Assert(MaxRecoveredIndex <= EscapedObjectCount,do { if (!(MaxRecoveredIndex <= EscapedObjectCount)) { CheckFailed ("all indices passed to llvm.localrecover must be less than the " "number of arguments passed to llvm.localescape in the parent " "function", F); return; } } while (false) | |||
2072 | "all indices passed to llvm.localrecover must be less than the "do { if (!(MaxRecoveredIndex <= EscapedObjectCount)) { CheckFailed ("all indices passed to llvm.localrecover must be less than the " "number of arguments passed to llvm.localescape in the parent " "function", F); return; } } while (false) | |||
2073 | "number of arguments passed to llvm.localescape in the parent "do { if (!(MaxRecoveredIndex <= EscapedObjectCount)) { CheckFailed ("all indices passed to llvm.localrecover must be less than the " "number of arguments passed to llvm.localescape in the parent " "function", F); return; } } while (false) | |||
2074 | "function",do { if (!(MaxRecoveredIndex <= EscapedObjectCount)) { CheckFailed ("all indices passed to llvm.localrecover must be less than the " "number of arguments passed to llvm.localescape in the parent " "function", F); return; } } while (false) | |||
2075 | F)do { if (!(MaxRecoveredIndex <= EscapedObjectCount)) { CheckFailed ("all indices passed to llvm.localrecover must be less than the " "number of arguments passed to llvm.localescape in the parent " "function", F); return; } } while (false); | |||
2076 | } | |||
2077 | } | |||
2078 | ||||
2079 | static Instruction *getSuccPad(Instruction *Terminator) { | |||
2080 | BasicBlock *UnwindDest; | |||
2081 | if (auto *II = dyn_cast<InvokeInst>(Terminator)) | |||
2082 | UnwindDest = II->getUnwindDest(); | |||
2083 | else if (auto *CSI = dyn_cast<CatchSwitchInst>(Terminator)) | |||
2084 | UnwindDest = CSI->getUnwindDest(); | |||
2085 | else | |||
2086 | UnwindDest = cast<CleanupReturnInst>(Terminator)->getUnwindDest(); | |||
2087 | return UnwindDest->getFirstNonPHI(); | |||
2088 | } | |||
2089 | ||||
2090 | void Verifier::verifySiblingFuncletUnwinds() { | |||
2091 | SmallPtrSet<Instruction *, 8> Visited; | |||
2092 | SmallPtrSet<Instruction *, 8> Active; | |||
2093 | for (const auto &Pair : SiblingFuncletInfo) { | |||
2094 | Instruction *PredPad = Pair.first; | |||
2095 | if (Visited.count(PredPad)) | |||
2096 | continue; | |||
2097 | Active.insert(PredPad); | |||
2098 | Instruction *Terminator = Pair.second; | |||
2099 | do { | |||
2100 | Instruction *SuccPad = getSuccPad(Terminator); | |||
2101 | if (Active.count(SuccPad)) { | |||
2102 | // Found a cycle; report error | |||
2103 | Instruction *CyclePad = SuccPad; | |||
2104 | SmallVector<Instruction *, 8> CycleNodes; | |||
2105 | do { | |||
2106 | CycleNodes.push_back(CyclePad); | |||
2107 | Instruction *CycleTerminator = SiblingFuncletInfo[CyclePad]; | |||
2108 | if (CycleTerminator != CyclePad) | |||
2109 | CycleNodes.push_back(CycleTerminator); | |||
2110 | CyclePad = getSuccPad(CycleTerminator); | |||
2111 | } while (CyclePad != SuccPad); | |||
2112 | Assert(false, "EH pads can't handle each other's exceptions",do { if (!(false)) { CheckFailed("EH pads can't handle each other's exceptions" , ArrayRef<Instruction *>(CycleNodes)); return; } } while (false) | |||
2113 | ArrayRef<Instruction *>(CycleNodes))do { if (!(false)) { CheckFailed("EH pads can't handle each other's exceptions" , ArrayRef<Instruction *>(CycleNodes)); return; } } while (false); | |||
2114 | } | |||
2115 | // Don't re-walk a node we've already checked | |||
2116 | if (!Visited.insert(SuccPad).second) | |||
2117 | break; | |||
2118 | // Walk to this successor if it has a map entry. | |||
2119 | PredPad = SuccPad; | |||
2120 | auto TermI = SiblingFuncletInfo.find(PredPad); | |||
2121 | if (TermI == SiblingFuncletInfo.end()) | |||
2122 | break; | |||
2123 | Terminator = TermI->second; | |||
2124 | Active.insert(PredPad); | |||
2125 | } while (true); | |||
2126 | // Each node only has one successor, so we've walked all the active | |||
2127 | // nodes' successors. | |||
2128 | Active.clear(); | |||
2129 | } | |||
2130 | } | |||
2131 | ||||
2132 | // visitFunction - Verify that a function is ok. | |||
2133 | // | |||
2134 | void Verifier::visitFunction(const Function &F) { | |||
2135 | visitGlobalValue(F); | |||
2136 | ||||
2137 | // Check function arguments. | |||
2138 | FunctionType *FT = F.getFunctionType(); | |||
2139 | unsigned NumArgs = F.arg_size(); | |||
2140 | ||||
2141 | Assert(&Context == &F.getContext(),do { if (!(&Context == &F.getContext())) { CheckFailed ("Function context does not match Module context!", &F); return ; } } while (false) | |||
| ||||
2142 | "Function context does not match Module context!", &F)do { if (!(&Context == &F.getContext())) { CheckFailed ("Function context does not match Module context!", &F); return ; } } while (false); | |||
2143 | ||||
2144 | Assert(!F.hasCommonLinkage(), "Functions may not have common linkage", &F)do { if (!(!F.hasCommonLinkage())) { CheckFailed("Functions may not have common linkage" , &F); return; } } while (false); | |||
2145 | Assert(FT->getNumParams() == NumArgs,do { if (!(FT->getNumParams() == NumArgs)) { CheckFailed("# formal arguments must match # of arguments for function type!" , &F, FT); return; } } while (false) | |||
2146 | "# formal arguments must match # of arguments for function type!", &F,do { if (!(FT->getNumParams() == NumArgs)) { CheckFailed("# formal arguments must match # of arguments for function type!" , &F, FT); return; } } while (false) | |||
2147 | FT)do { if (!(FT->getNumParams() == NumArgs)) { CheckFailed("# formal arguments must match # of arguments for function type!" , &F, FT); return; } } while (false); | |||
2148 | Assert(F.getReturnType()->isFirstClassType() ||do { if (!(F.getReturnType()->isFirstClassType() || F.getReturnType ()->isVoidTy() || F.getReturnType()->isStructTy())) { CheckFailed ("Functions cannot return aggregate values!", &F); return ; } } while (false) | |||
2149 | F.getReturnType()->isVoidTy() || F.getReturnType()->isStructTy(),do { if (!(F.getReturnType()->isFirstClassType() || F.getReturnType ()->isVoidTy() || F.getReturnType()->isStructTy())) { CheckFailed ("Functions cannot return aggregate values!", &F); return ; } } while (false) | |||
2150 | "Functions cannot return aggregate values!", &F)do { if (!(F.getReturnType()->isFirstClassType() || F.getReturnType ()->isVoidTy() || F.getReturnType()->isStructTy())) { CheckFailed ("Functions cannot return aggregate values!", &F); return ; } } while (false); | |||
2151 | ||||
2152 | Assert(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy(),do { if (!(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy ())) { CheckFailed("Invalid struct return type!", &F); return ; } } while (false) | |||
2153 | "Invalid struct return type!", &F)do { if (!(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy ())) { CheckFailed("Invalid struct return type!", &F); return ; } } while (false); | |||
2154 | ||||
2155 | AttributeList Attrs = F.getAttributes(); | |||
2156 | ||||
2157 | Assert(verifyAttributeCount(Attrs, FT->getNumParams()),do { if (!(verifyAttributeCount(Attrs, FT->getNumParams()) )) { CheckFailed("Attribute after last parameter!", &F); return ; } } while (false) | |||
2158 | "Attribute after last parameter!", &F)do { if (!(verifyAttributeCount(Attrs, FT->getNumParams()) )) { CheckFailed("Attribute after last parameter!", &F); return ; } } while (false); | |||
2159 | ||||
2160 | bool isLLVMdotName = F.getName().size() >= 5 && | |||
2161 | F.getName().substr(0, 5) == "llvm."; | |||
2162 | ||||
2163 | // Check function attributes. | |||
2164 | verifyFunctionAttrs(FT, Attrs, &F, isLLVMdotName); | |||
2165 | ||||
2166 | // On function declarations/definitions, we do not support the builtin | |||
2167 | // attribute. We do not check this in VerifyFunctionAttrs since that is | |||
2168 | // checking for Attributes that can/can not ever be on functions. | |||
2169 | Assert(!Attrs.hasFnAttribute(Attribute::Builtin),do { if (!(!Attrs.hasFnAttribute(Attribute::Builtin))) { CheckFailed ("Attribute 'builtin' can only be applied to a callsite.", & F); return; } } while (false) | |||
2170 | "Attribute 'builtin' can only be applied to a callsite.", &F)do { if (!(!Attrs.hasFnAttribute(Attribute::Builtin))) { CheckFailed ("Attribute 'builtin' can only be applied to a callsite.", & F); return; } } while (false); | |||
2171 | ||||
2172 | // Check that this function meets the restrictions on this calling convention. | |||
2173 | // Sometimes varargs is used for perfectly forwarding thunks, so some of these | |||
2174 | // restrictions can be lifted. | |||
2175 | switch (F.getCallingConv()) { | |||
2176 | default: | |||
2177 | case CallingConv::C: | |||
2178 | break; | |||
2179 | case CallingConv::AMDGPU_KERNEL: | |||
2180 | case CallingConv::SPIR_KERNEL: | |||
2181 | Assert(F.getReturnType()->isVoidTy(),do { if (!(F.getReturnType()->isVoidTy())) { CheckFailed("Calling convention requires void return type" , &F); return; } } while (false) | |||
2182 | "Calling convention requires void return type", &F)do { if (!(F.getReturnType()->isVoidTy())) { CheckFailed("Calling convention requires void return type" , &F); return; } } while (false); | |||
2183 | LLVM_FALLTHROUGH[[gnu::fallthrough]]; | |||
2184 | case CallingConv::AMDGPU_VS: | |||
2185 | case CallingConv::AMDGPU_HS: | |||
2186 | case CallingConv::AMDGPU_GS: | |||
2187 | case CallingConv::AMDGPU_PS: | |||
2188 | case CallingConv::AMDGPU_CS: | |||
2189 | Assert(!F.hasStructRetAttr(),do { if (!(!F.hasStructRetAttr())) { CheckFailed("Calling convention does not allow sret" , &F); return; } } while (false) | |||
2190 | "Calling convention does not allow sret", &F)do { if (!(!F.hasStructRetAttr())) { CheckFailed("Calling convention does not allow sret" , &F); return; } } while (false); | |||
2191 | LLVM_FALLTHROUGH[[gnu::fallthrough]]; | |||
2192 | case CallingConv::Fast: | |||
2193 | case CallingConv::Cold: | |||
2194 | case CallingConv::Intel_OCL_BI: | |||
2195 | case CallingConv::PTX_Kernel: | |||
2196 | case CallingConv::PTX_Device: | |||
2197 | Assert(!F.isVarArg(), "Calling convention does not support varargs or "do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or " "perfect forwarding!", &F); return; } } while (false) | |||
2198 | "perfect forwarding!",do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or " "perfect forwarding!", &F); return; } } while (false) | |||
2199 | &F)do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or " "perfect forwarding!", &F); return; } } while (false); | |||
2200 | break; | |||
2201 | } | |||
2202 | ||||
2203 | // Check that the argument values match the function type for this function... | |||
2204 | unsigned i = 0; | |||
2205 | for (const Argument &Arg : F.args()) { | |||
2206 | Assert(Arg.getType() == FT->getParamType(i),do { if (!(Arg.getType() == FT->getParamType(i))) { CheckFailed ("Argument value does not match function argument type!", & Arg, FT->getParamType(i)); return; } } while (false) | |||
2207 | "Argument value does not match function argument type!", &Arg,do { if (!(Arg.getType() == FT->getParamType(i))) { CheckFailed ("Argument value does not match function argument type!", & Arg, FT->getParamType(i)); return; } } while (false) | |||
2208 | FT->getParamType(i))do { if (!(Arg.getType() == FT->getParamType(i))) { CheckFailed ("Argument value does not match function argument type!", & Arg, FT->getParamType(i)); return; } } while (false); | |||
2209 | Assert(Arg.getType()->isFirstClassType(),do { if (!(Arg.getType()->isFirstClassType())) { CheckFailed ("Function arguments must have first-class types!", &Arg) ; return; } } while (false) | |||
2210 | "Function arguments must have first-class types!", &Arg)do { if (!(Arg.getType()->isFirstClassType())) { CheckFailed ("Function arguments must have first-class types!", &Arg) ; return; } } while (false); | |||
2211 | if (!isLLVMdotName) { | |||
2212 | Assert(!Arg.getType()->isMetadataTy(),do { if (!(!Arg.getType()->isMetadataTy())) { CheckFailed( "Function takes metadata but isn't an intrinsic", &Arg, & F); return; } } while (false) | |||
2213 | "Function takes metadata but isn't an intrinsic", &Arg, &F)do { if (!(!Arg.getType()->isMetadataTy())) { CheckFailed( "Function takes metadata but isn't an intrinsic", &Arg, & F); return; } } while (false); | |||
2214 | Assert(!Arg.getType()->isTokenTy(),do { if (!(!Arg.getType()->isTokenTy())) { CheckFailed("Function takes token but isn't an intrinsic" , &Arg, &F); return; } } while (false) | |||
2215 | "Function takes token but isn't an intrinsic", &Arg, &F)do { if (!(!Arg.getType()->isTokenTy())) { CheckFailed("Function takes token but isn't an intrinsic" , &Arg, &F); return; } } while (false); | |||
2216 | } | |||
2217 | ||||
2218 | // Check that swifterror argument is only used by loads and stores. | |||
2219 | if (Attrs.hasParamAttribute(i, Attribute::SwiftError)) { | |||
2220 | verifySwiftErrorValue(&Arg); | |||
2221 | } | |||
2222 | ++i; | |||
2223 | } | |||
2224 | ||||
2225 | if (!isLLVMdotName
| |||
2226 | Assert(!F.getReturnType()->isTokenTy(),do { if (!(!F.getReturnType()->isTokenTy())) { CheckFailed ("Functions returns a token but isn't an intrinsic", &F); return; } } while (false) | |||
2227 | "Functions returns a token but isn't an intrinsic", &F)do { if (!(!F.getReturnType()->isTokenTy())) { CheckFailed ("Functions returns a token but isn't an intrinsic", &F); return; } } while (false); | |||
2228 | ||||
2229 | // Get the function metadata attachments. | |||
2230 | SmallVector<std::pair<unsigned, MDNode *>, 4> MDs; | |||
2231 | F.getAllMetadata(MDs); | |||
2232 | assert(F.hasMetadata() != MDs.empty() && "Bit out-of-sync")((F.hasMetadata() != MDs.empty() && "Bit out-of-sync" ) ? static_cast<void> (0) : __assert_fail ("F.hasMetadata() != MDs.empty() && \"Bit out-of-sync\"" , "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/IR/Verifier.cpp" , 2232, __PRETTY_FUNCTION__)); | |||
2233 | verifyFunctionMetadata(MDs); | |||
2234 | ||||
2235 | // Check validity of the personality function | |||
2236 | if (F.hasPersonalityFn()) { | |||
2237 | auto *Per = dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts()); | |||
2238 | if (Per) | |||
2239 | Assert(Per->getParent() == F.getParent(),do { if (!(Per->getParent() == F.getParent())) { CheckFailed ("Referencing personality function in another module!", & F, F.getParent(), Per, Per->getParent()); return; } } while (false) | |||
2240 | "Referencing personality function in another module!",do { if (!(Per->getParent() == F.getParent())) { CheckFailed ("Referencing personality function in another module!", & F, F.getParent(), Per, Per->getParent()); return; } } while (false) | |||
2241 | &F, F.getParent(), Per, Per->getParent())do { if (!(Per->getParent() == F.getParent())) { CheckFailed ("Referencing personality function in another module!", & F, F.getParent(), Per, Per->getParent()); return; } } while (false); | |||
2242 | } | |||
2243 | ||||
2244 | if (F.isMaterializable()) { | |||
2245 | // Function has a body somewhere we can't see. | |||
2246 | Assert(MDs.empty(), "unmaterialized function cannot have metadata", &F,do { if (!(MDs.empty())) { CheckFailed("unmaterialized function cannot have metadata" , &F, MDs.empty() ? nullptr : MDs.front().second); return ; } } while (false) | |||
2247 | MDs.empty() ? nullptr : MDs.front().second)do { if (!(MDs.empty())) { CheckFailed("unmaterialized function cannot have metadata" , &F, MDs.empty() ? nullptr : MDs.front().second); return ; } } while (false); | |||
2248 | } else if (F.isDeclaration()) { | |||
2249 | for (const auto &I : MDs) { | |||
2250 | // This is used for call site debug information. | |||
2251 | AssertDI(I.first != LLVMContext::MD_dbg ||do { if (!(I.first != LLVMContext::MD_dbg || !cast<DISubprogram >(I.second)->isDistinct())) { DebugInfoCheckFailed("function declaration may only have a unique !dbg attachment" , &F); return; } } while (false) | |||
2252 | !cast<DISubprogram>(I.second)->isDistinct(),do { if (!(I.first != LLVMContext::MD_dbg || !cast<DISubprogram >(I.second)->isDistinct())) { DebugInfoCheckFailed("function declaration may only have a unique !dbg attachment" , &F); return; } } while (false) | |||
2253 | "function declaration may only have a unique !dbg attachment",do { if (!(I.first != LLVMContext::MD_dbg || !cast<DISubprogram >(I.second)->isDistinct())) { DebugInfoCheckFailed("function declaration may only have a unique !dbg attachment" , &F); return; } } while (false) | |||
2254 | &F)do { if (!(I.first != LLVMContext::MD_dbg || !cast<DISubprogram >(I.second)->isDistinct())) { DebugInfoCheckFailed("function declaration may only have a unique !dbg attachment" , &F); return; } } while (false); | |||
2255 | Assert(I.first != LLVMContext::MD_prof,do { if (!(I.first != LLVMContext::MD_prof)) { CheckFailed("function declaration may not have a !prof attachment" , &F); return; } } while (false) | |||
2256 | "function declaration may not have a !prof attachment", &F)do { if (!(I.first != LLVMContext::MD_prof)) { CheckFailed("function declaration may not have a !prof attachment" , &F); return; } } while (false); | |||
2257 | ||||
2258 | // Verify the metadata itself. | |||
2259 | visitMDNode(*I.second); | |||
2260 | } | |||
2261 | Assert(!F.hasPersonalityFn(),do { if (!(!F.hasPersonalityFn())) { CheckFailed("Function declaration shouldn't have a personality routine" , &F); return; } } while (false) | |||
2262 | "Function declaration shouldn't have a personality routine", &F)do { if (!(!F.hasPersonalityFn())) { CheckFailed("Function declaration shouldn't have a personality routine" , &F); return; } } while (false); | |||
2263 | } else { | |||
2264 | // Verify that this function (which has a body) is not named "llvm.*". It | |||
2265 | // is not legal to define intrinsics. | |||
2266 | Assert
, &F); return; } } while (false); | |||
2267 | ||||
2268 | // Check the entry node | |||
2269 | const BasicBlock *Entry = &F.getEntryBlock(); | |||
2270 | Assert(pred_empty(Entry),do { if (!(pred_empty(Entry))) { CheckFailed("Entry block to function must not have predecessors!" , Entry); return; } } while (false) | |||
2271 | "Entry block to function must not have predecessors!", Entry)do { if (!(pred_empty(Entry))) { CheckFailed("Entry block to function must not have predecessors!" , Entry); return; } } while (false); | |||
2272 | ||||
2273 | // The address of the entry block cannot be taken, unless it is dead. | |||
2274 | if (Entry->hasAddressTaken()) { | |||
2275 | Assert(!BlockAddress::lookup(Entry)->isConstantUsed(),do { if (!(!BlockAddress::lookup(Entry)->isConstantUsed()) ) { CheckFailed("blockaddress may not be used with the entry block!" , Entry); return; } } while (false) | |||
2276 | "blockaddress may not be used with the entry block!", Entry)do { if (!(!BlockAddress::lookup(Entry)->isConstantUsed()) ) { CheckFailed("blockaddress may not be used with the entry block!" , Entry); return; } } while (false); | |||
2277 | } | |||
2278 | ||||
2279 | unsigned NumDebugAttachments = 0, NumProfAttachments = 0; | |||
2280 | // Visit metadata attachments. | |||
2281 | for (const auto &I : MDs) { | |||
2282 | // Verify that the attachment is legal. | |||
2283 | switch (I.first) { | |||
2284 | default: | |||
2285 | break; | |||
2286 | case LLVMContext::MD_dbg: { | |||
2287 | ++NumDebugAttachments; | |||
2288 | AssertDI(NumDebugAttachments == 1,do { if (!(NumDebugAttachments == 1)) { DebugInfoCheckFailed( "function must have a single !dbg attachment", &F, I.second ); return; } } while (false) | |||
2289 | "function must have a single !dbg attachment", &F, I.second)do { if (!(NumDebugAttachments == 1)) { DebugInfoCheckFailed( "function must have a single !dbg attachment", &F, I.second ); return; } } while (false); | |||
2290 | AssertDI(isa<DISubprogram>(I.second),do { if (!(isa<DISubprogram>(I.second))) { DebugInfoCheckFailed ("function !dbg attachment must be a subprogram", &F, I.second ); return; } } while (false) | |||
2291 | "function !dbg attachment must be a subprogram", &F, I.second)do { if (!(isa<DISubprogram>(I.second))) { DebugInfoCheckFailed ("function !dbg attachment must be a subprogram", &F, I.second ); return; } } while (false); | |||
2292 | auto *SP = cast<DISubprogram>(I.second); | |||
2293 | const Function *&AttachedTo = DISubprogramAttachments[SP]; | |||
2294 | AssertDI(!AttachedTo || AttachedTo == &F,do { if (!(!AttachedTo || AttachedTo == &F)) { DebugInfoCheckFailed ("DISubprogram attached to more than one function", SP, & F); return; } } while (false) | |||
2295 | "DISubprogram attached to more than one function", SP, &F)do { if (!(!AttachedTo || AttachedTo == &F)) { DebugInfoCheckFailed ("DISubprogram attached to more than one function", SP, & F); return; } } while (false); | |||
2296 | AttachedTo = &F; | |||
2297 | break; | |||
2298 | } | |||
2299 | case LLVMContext::MD_prof: | |||
2300 | ++NumProfAttachments; | |||
2301 | Assert(NumProfAttachments == 1,do { if (!(NumProfAttachments == 1)) { CheckFailed("function must have a single !prof attachment" , &F, I.second); return; } } while (false) | |||
2302 | "function must have a single !prof attachment", &F, I.second)do { if (!(NumProfAttachments == 1)) { CheckFailed("function must have a single !prof attachment" , &F, I.second); return; } } while (false); | |||
2303 | break; | |||
2304 | } | |||
2305 | ||||
2306 | // Verify the metadata itself. | |||
2307 | visitMDNode(*I.second); | |||
2308 | } | |||
2309 | } | |||
2310 | ||||
2311 | // If this function is actually an intrinsic, verify that it is only used in | |||
2312 | // direct call/invokes, never having its "address taken". | |||
2313 | // Only do this if the module is materialized, otherwise we don't have all the | |||
2314 | // uses. | |||
2315 | if (F.getIntrinsicID() && F.getParent()->isMaterialized()) { | |||
2316 | const User *U; | |||
2317 | if (F.hasAddressTaken(&U)) | |||
2318 | Assert(false, "Invalid user of intrinsic instruction!", U)do { if (!(false)) { CheckFailed("Invalid user of intrinsic instruction!" , U); return; } } while (false); | |||
2319 | } | |||
2320 | ||||
2321 | auto *N = F.getSubprogram(); | |||
2322 | HasDebugInfo = (N != nullptr); | |||
2323 | if (!HasDebugInfo
| |||
2324 | return; | |||
2325 | ||||
2326 | // Check that all !dbg attachments lead to back to N (or, at least, another | |||
2327 | // subprogram that describes the same function). | |||
2328 | // | |||
2329 | // FIXME: Check this incrementally while visiting !dbg attachments. | |||
2330 | // FIXME: Only check when N is the canonical subprogram for F. | |||
2331 | SmallPtrSet<const MDNode *, 32> Seen; | |||
2332 | auto VisitDebugLoc = [&](const Instruction &I, const MDNode *Node) { | |||
2333 | // Be careful about using DILocation here since we might be dealing with | |||
2334 | // broken code (this is the Verifier after all). | |||
2335 | const DILocation *DL = dyn_cast_or_null<DILocation>(Node); | |||
2336 | if (!DL
| |||
2337 | return; | |||
2338 | if (!Seen.insert(DL).second) | |||
2339 | return; | |||
2340 | ||||
2341 | Metadata *Parent = DL->getRawScope(); | |||
2342 | AssertDI(Parent && isa<DILocalScope>(Parent),do { if (!(Parent && isa<DILocalScope>(Parent)) ) { DebugInfoCheckFailed("DILocation's scope must be a DILocalScope" , N, &F, &I, DL, Parent); return; } } while (false) | |||
2343 | "DILocation's scope must be a DILocalScope", N, &F, &I, DL,do { if (!(Parent && isa<DILocalScope>(Parent)) ) { DebugInfoCheckFailed("DILocation's scope must be a DILocalScope" , N, &F, &I, DL, Parent); return; } } while (false) | |||
2344 | Parent)do { if (!(Parent && isa<DILocalScope>(Parent)) ) { DebugInfoCheckFailed("DILocation's scope must be a DILocalScope" , N, &F, &I, DL, Parent); return; } } while (false); | |||
2345 | DILocalScope *Scope = DL->getInlinedAtScope(); | |||
2346 | if (Scope
| |||
2347 | return; | |||
2348 | ||||
2349 | DISubprogram *SP = Scope
| |||
2350 | ||||
2351 | // Scope and SP could be the same MDNode and we don't want to skip | |||
2352 | // validation in that case | |||
2353 | if (SP && ((Scope != SP) && !Seen.insert(SP).second)) | |||
2354 | return; | |||
2355 | ||||
2356 | // FIXME: Once N is canonical, check "SP == &N". | |||
2357 | AssertDI(SP->describes(&F),do { if (!(SP->describes(&F))) { DebugInfoCheckFailed( "!dbg attachment points at wrong subprogram for function", N, &F, &I, DL, Scope, SP); return; } } while (false) | |||
| ||||
2358 | "!dbg attachment points at wrong subprogram for function", N, &F,do { if (!(SP->describes(&F))) { DebugInfoCheckFailed( "!dbg attachment points at wrong subprogram for function", N, &F, &I, DL, Scope, SP); return; } } while (false) | |||
2359 | &I, DL, Scope, SP)do { if (!(SP->describes(&F))) { DebugInfoCheckFailed( "!dbg attachment points at wrong subprogram for function", N, &F, &I, DL, Scope, SP); return; } } while (false); | |||
2360 | }; | |||
2361 | for (auto &BB : F) | |||
2362 | for (auto &I : BB) { | |||
2363 | VisitDebugLoc(I, I.getDebugLoc().getAsMDNode()); | |||
2364 | // The llvm.loop annotations also contain two DILocations. | |||
2365 | if (auto MD = I.getMetadata(LLVMContext::MD_loop)) | |||
2366 | for (unsigned i = 1; i < MD->getNumOperands(); ++i) | |||
2367 | VisitDebugLoc(I, dyn_cast_or_null<MDNode>(MD->getOperand(i))); | |||
2368 | if (BrokenDebugInfo) | |||
2369 | return; | |||
2370 | } | |||
2371 | } | |||
2372 | ||||
2373 | // verifyBasicBlock - Verify that a basic block is well formed... | |||
2374 | // | |||
2375 | void Verifier::visitBasicBlock(BasicBlock &BB) { | |||
2376 | InstsInThisBlock.clear(); | |||
2377 | ||||
2378 | // Ensure that basic blocks have terminators! | |||
2379 | Assert(BB.getTerminator(), "Basic Block does not have terminator!", &BB)do { if (!(BB.getTerminator())) { CheckFailed("Basic Block does not have terminator!" , &BB); return; } } while (false); | |||
2380 | ||||
2381 | // Check constraints that this basic block imposes on all of the PHI nodes in | |||
2382 | // it. | |||
2383 | if (isa<PHINode>(BB.front())) { | |||
2384 | SmallVector<BasicBlock*, 8> Preds(pred_begin(&BB), pred_end(&BB)); | |||
2385 | SmallVector<std::pair<BasicBlock*, Value*>, 8> Values; | |||
2386 | llvm::sort(Preds); | |||
2387 | for (const PHINode &PN : BB.phis()) { | |||
2388 | // Ensure that PHI nodes have at least one entry! | |||
2389 | Assert(PN.getNumIncomingValues() != 0,do { if (!(PN.getNumIncomingValues() != 0)) { CheckFailed("PHI nodes must have at least one entry. If the block is dead, " "the PHI should be removed!", &PN); return; } } while (false ) | |||
2390 | "PHI nodes must have at least one entry. If the block is dead, "do { if (!(PN.getNumIncomingValues() != 0)) { CheckFailed("PHI nodes must have at least one entry. If the block is dead, " "the PHI should be removed!", &PN); return; } } while (false ) | |||
2391 | "the PHI should be removed!",do { if (!(PN.getNumIncomingValues() != 0)) { CheckFailed("PHI nodes must have at least one entry. If the block is dead, " "the PHI should be removed!", &PN); return; } } while (false ) | |||
2392 | &PN)do { if (!(PN.getNumIncomingValues() != 0)) { CheckFailed("PHI nodes must have at least one entry. If the block is dead, " "the PHI should be removed!", &PN); return; } } while (false ); | |||
2393 | Assert(PN.getNumIncomingValues() == Preds.size(),do { if (!(PN.getNumIncomingValues() == Preds.size())) { CheckFailed ("PHINode should have one entry for each predecessor of its " "parent basic block!", &PN); return; } } while (false) | |||
2394 | "PHINode should have one entry for each predecessor of its "do { if (!(PN.getNumIncomingValues() == Preds.size())) { CheckFailed ("PHINode should have one entry for each predecessor of its " "parent basic block!", &PN); return; } } while (false) | |||
2395 | "parent basic block!",do { if (!(PN.getNumIncomingValues() == Preds.size())) { CheckFailed ("PHINode should have one entry for each predecessor of its " "parent basic block!", &PN); return; } } while (false) | |||
2396 | &PN)do { if (!(PN.getNumIncomingValues() == Preds.size())) { CheckFailed ("PHINode should have one entry for each predecessor of its " "parent basic block!", &PN); return; } } while (false); | |||
2397 | ||||
2398 | // Get and sort all incoming values in the PHI node... | |||
2399 | Values.clear(); | |||
2400 | Values.reserve(PN.getNumIncomingValues()); | |||
2401 | for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) | |||
2402 | Values.push_back( | |||
2403 | std::make_pair(PN.getIncomingBlock(i), PN.getIncomingValue(i))); | |||
2404 | llvm::sort(Values); | |||
2405 | ||||
2406 | for (unsigned i = 0, e = Values.size(); i != e; ++i) { | |||
2407 | // Check to make sure that if there is more than one entry for a | |||
2408 | // particular basic block in this PHI node, that the incoming values are | |||
2409 | // all identical. | |||
2410 | // | |||
2411 | Assert(i == 0 || Values[i].first != Values[i - 1].first ||do { if (!(i == 0 || Values[i].first != Values[i - 1].first || Values[i].second == Values[i - 1].second)) { CheckFailed("PHI node has multiple entries for the same basic block with " "different incoming values!", &PN, Values[i].first, Values [i].second, Values[i - 1].second); return; } } while (false) | |||
2412 | Values[i].second == Values[i - 1].second,do { if (!(i == 0 || Values[i].first != Values[i - 1].first || Values[i].second == Values[i - 1].second)) { CheckFailed("PHI node has multiple entries for the same basic block with " "different incoming values!", &PN, Values[i].first, Values [i].second, Values[i - 1].second); return; } } while (false) | |||
2413 | "PHI node has multiple entries for the same basic block with "do { if (!(i == 0 || Values[i].first != Values[i - 1].first || Values[i].second == Values[i - 1].second)) { CheckFailed("PHI node has multiple entries for the same basic block with " "different incoming values!", &PN, Values[i].first, Values [i].second, Values[i - 1].second); return; } } while (false) | |||
2414 | "different incoming values!",do { if (!(i == 0 || Values[i].first != Values[i - 1].first || Values[i].second == Values[i - 1].second)) { CheckFailed("PHI node has multiple entries for the same basic block with " "different incoming values!", &PN, Values[i].first, Values [i].second, Values[i - 1].second); return; } } while (false) | |||
2415 | &PN, Values[i].first, Values[i].second, Values[i - 1].second)do { if (!(i == 0 || Values[i].first != Values[i - 1].first || Values[i].second == Values[i - 1].second)) { CheckFailed("PHI node has multiple entries for the same basic block with " "different incoming values!", &PN, Values[i].first, Values [i].second, Values[i - 1].second); return; } } while (false); | |||
2416 | ||||
2417 | // Check to make sure that the predecessors and PHI node entries are | |||
2418 | // matched up. | |||
2419 | Assert(Values[i].first == Preds[i],do { if (!(Values[i].first == Preds[i])) { CheckFailed("PHI node entries do not match predecessors!" , &PN, Values[i].first, Preds[i]); return; } } while (false ) | |||
2420 | "PHI node entries do not match predecessors!", &PN,do { if (!(Values[i].first == Preds[i])) { CheckFailed("PHI node entries do not match predecessors!" , &PN, Values[i].first, Preds[i]); return; } } while (false ) | |||
2421 | Values[i].first, Preds[i])do { if (!(Values[i].first == Preds[i])) { CheckFailed("PHI node entries do not match predecessors!" , &PN, Values[i].first, Preds[i]); return; } } while (false ); | |||
2422 | } | |||
2423 | } | |||
2424 | } | |||
2425 | ||||
2426 | // Check that all instructions have their parent pointers set up correctly. | |||
2427 | for (auto &I : BB) | |||
2428 | { | |||
2429 | Assert(I.getParent() == &BB, "Instruction has bogus parent pointer!")do { if (!(I.getParent() == &BB)) { CheckFailed("Instruction has bogus parent pointer!" ); return; } } while (false); | |||
2430 | } | |||
2431 | } | |||
2432 | ||||
2433 | void Verifier::visitTerminator(Instruction &I) { | |||
2434 | // Ensure that terminators only exist at the end of the basic block. | |||
2435 | Assert(&I == I.getParent()->getTerminator(),do { if (!(&I == I.getParent()->getTerminator())) { CheckFailed ("Terminator found in the middle of a basic block!", I.getParent ()); return; } } while (false) | |||
2436 | "Terminator found in the middle of a basic block!", I.getParent())do { if (!(&I == I.getParent()->getTerminator())) { CheckFailed ("Terminator found in the middle of a basic block!", I.getParent ()); return; } } while (false); | |||
2437 | visitInstruction(I); | |||
2438 | } | |||
2439 | ||||
2440 | void Verifier::visitBranchInst(BranchInst &BI) { | |||
2441 | if (BI.isConditional()) { | |||
2442 | Assert(BI.getCondition()->getType()->isIntegerTy(1),do { if (!(BI.getCondition()->getType()->isIntegerTy(1) )) { CheckFailed("Branch condition is not 'i1' type!", &BI , BI.getCondition()); return; } } while (false) | |||
2443 | "Branch condition is not 'i1' type!", &BI, BI.getCondition())do { if (!(BI.getCondition()->getType()->isIntegerTy(1) )) { CheckFailed("Branch condition is not 'i1' type!", &BI , BI.getCondition()); return; } } while (false); | |||
2444 | } | |||
2445 | visitTerminator(BI); | |||
2446 | } | |||
2447 | ||||
2448 | void Verifier::visitReturnInst(ReturnInst &RI) { | |||
2449 | Function *F = RI.getParent()->getParent(); | |||
2450 | unsigned N = RI.getNumOperands(); | |||
2451 | if (F->getReturnType()->isVoidTy()) | |||
2452 | Assert(N == 0,do { if (!(N == 0)) { CheckFailed("Found return instr that returns non-void in Function of void " "return type!", &RI, F->getReturnType()); return; } } while (false) | |||
2453 | "Found return instr that returns non-void in Function of void "do { if (!(N == 0)) { CheckFailed("Found return instr that returns non-void in Function of void " "return type!", &RI, F->getReturnType()); return; } } while (false) | |||
2454 | "return type!",do { if (!(N == 0)) { CheckFailed("Found return instr that returns non-void in Function of void " "return type!", &RI, F->getReturnType()); return; } } while (false) | |||
2455 | &RI, F->getReturnType())do { if (!(N == 0)) { CheckFailed("Found return instr that returns non-void in Function of void " "return type!", &RI, F->getReturnType()); return; } } while (false); | |||
2456 | else | |||
2457 | Assert(N == 1 && F->getReturnType() == RI.getOperand(0)->getType(),do { if (!(N == 1 && F->getReturnType() == RI.getOperand (0)->getType())) { CheckFailed("Function return type does not match operand " "type of return inst!", &RI, F->getReturnType()); return ; } } while (false) | |||
2458 | "Function return type does not match operand "do { if (!(N == 1 && F->getReturnType() == RI.getOperand (0)->getType())) { CheckFailed("Function return type does not match operand " "type of return inst!", &RI, F->getReturnType()); return ; } } while (false) | |||
2459 | "type of return inst!",do { if (!(N == 1 && F->getReturnType() == RI.getOperand (0)->getType())) { CheckFailed("Function return type does not match operand " "type of return inst!", &RI, F->getReturnType()); return ; } } while (false) | |||
2460 | &RI, F->getReturnType())do { if (!(N == 1 && F->getReturnType() == RI.getOperand (0)->getType())) { CheckFailed("Function return type does not match operand " "type of return inst!", &RI, F->getReturnType()); return ; } } while (false); | |||
2461 | ||||
2462 | // Check to make sure that the return value has necessary properties for | |||
2463 | // terminators... | |||
2464 | visitTerminator(RI); | |||
2465 | } | |||
2466 | ||||
2467 | void Verifier::visitSwitchInst(SwitchInst &SI) { | |||
2468 | // Check to make sure that all of the constants in the switch instruction | |||
2469 | // have the same type as the switched-on value. | |||
2470 | Type *SwitchTy = SI.getCondition()->getType(); | |||
2471 | SmallPtrSet<ConstantInt*, 32> Constants; | |||
2472 | for (auto &Case : SI.cases()) { | |||
2473 | Assert(Case.getCaseValue()->getType() == SwitchTy,do { if (!(Case.getCaseValue()->getType() == SwitchTy)) { CheckFailed ("Switch constants must all be same type as switch value!", & SI); return; } } while (false) | |||
2474 | "Switch constants must all be same type as switch value!", &SI)do { if (!(Case.getCaseValue()->getType() == SwitchTy)) { CheckFailed ("Switch constants must all be same type as switch value!", & SI); return; } } while (false); | |||
2475 | Assert(Constants.insert(Case.getCaseValue()).second,do { if (!(Constants.insert(Case.getCaseValue()).second)) { CheckFailed ("Duplicate integer as switch case", &SI, Case.getCaseValue ()); return; } } while (false) | |||
2476 | "Duplicate integer as switch case", &SI, Case.getCaseValue())do { if (!(Constants.insert(Case.getCaseValue()).second)) { CheckFailed ("Duplicate integer as switch case", &SI, Case.getCaseValue ()); return; } } while (false); | |||
2477 | } | |||
2478 | ||||
2479 | visitTerminator(SI); | |||
2480 | } | |||
2481 | ||||
2482 | void Verifier::visitIndirectBrInst(IndirectBrInst &BI) { | |||
2483 | Assert(BI.getAddress()->getType()->isPointerTy(),do { if (!(BI.getAddress()->getType()->isPointerTy())) { CheckFailed("Indirectbr operand must have pointer type!", & BI); return; } } while (false) | |||
2484 | "Indirectbr operand must have pointer type!", &BI)do { if (!(BI.getAddress()->getType()->isPointerTy())) { CheckFailed("Indirectbr operand must have pointer type!", & BI); return; } } while (false); | |||
2485 | for (unsigned i = 0, e = BI.getNumDestinations(); i != e; ++i) | |||
2486 | Assert(BI.getDestination(i)->getType()->isLabelTy(),do { if (!(BI.getDestination(i)->getType()->isLabelTy() )) { CheckFailed("Indirectbr destinations must all have pointer type!" , &BI); return; } } while (false) | |||
2487 | "Indirectbr destinations must all have pointer type!", &BI)do { if (!(BI.getDestination(i)->getType()->isLabelTy() )) { CheckFailed("Indirectbr destinations must all have pointer type!" , &BI); return; } } while (false); | |||
2488 | ||||
2489 | visitTerminator(BI); | |||
2490 | } | |||
2491 | ||||
2492 | void Verifier::visitCallBrInst(CallBrInst &CBI) { | |||
2493 | Assert(CBI.isInlineAsm(), "Callbr is currently only used for asm-goto!",do { if (!(CBI.isInlineAsm())) { CheckFailed("Callbr is currently only used for asm-goto!" , &CBI); return; } } while (false) | |||
2494 | &CBI)do { if (!(CBI.isInlineAsm())) { CheckFailed("Callbr is currently only used for asm-goto!" , &CBI); return; } } while (false); | |||
2495 | Assert(CBI.getType()->isVoidTy(), "Callbr return value is not supported!",do { if (!(CBI.getType()->isVoidTy())) { CheckFailed("Callbr return value is not supported!" , &CBI); return; } } while (false) | |||
2496 | &CBI)do { if (!(CBI.getType()->isVoidTy())) { CheckFailed("Callbr return value is not supported!" , &CBI); return; } } while (false); | |||
2497 | for (unsigned i = 0, e = CBI.getNumSuccessors(); i != e; ++i) | |||
2498 | Assert(CBI.getSuccessor(i)->getType()->isLabelTy(),do { if (!(CBI.getSuccessor(i)->getType()->isLabelTy()) ) { CheckFailed("Callbr successors must all have pointer type!" , &CBI); return; } } while (false) | |||
2499 | "Callbr successors must all have pointer type!", &CBI)do { if (!(CBI.getSuccessor(i)->getType()->isLabelTy()) ) { CheckFailed("Callbr successors must all have pointer type!" , &CBI); return; } } while (false); | |||
2500 | for (unsigned i = 0, e = CBI.getNumOperands(); i != e; ++i) { | |||
2501 | Assert(i >= CBI.getNumArgOperands() || !isa<BasicBlock>(CBI.getOperand(i)),do { if (!(i >= CBI.getNumArgOperands() || !isa<BasicBlock >(CBI.getOperand(i)))) { CheckFailed("Using an unescaped label as a callbr argument!" , &CBI); return; } } while (false) | |||
2502 | "Using an unescaped label as a callbr argument!", &CBI)do { if (!(i >= CBI.getNumArgOperands() || !isa<BasicBlock >(CBI.getOperand(i)))) { CheckFailed("Using an unescaped label as a callbr argument!" , &CBI); return; } } while (false); | |||
2503 | if (isa<BasicBlock>(CBI.getOperand(i))) | |||
2504 | for (unsigned j = i + 1; j != e; ++j) | |||
2505 | Assert(CBI.getOperand(i) != CBI.getOperand(j),do { if (!(CBI.getOperand(i) != CBI.getOperand(j))) { CheckFailed ("Duplicate callbr destination!", &CBI); return; } } while (false) | |||
2506 | "Duplicate callbr destination!", &CBI)do { if (!(CBI.getOperand(i) != CBI.getOperand(j))) { CheckFailed ("Duplicate callbr destination!", &CBI); return; } } while (false); | |||
2507 | } | |||
2508 | { | |||
2509 | SmallPtrSet<BasicBlock *, 4> ArgBBs; | |||
2510 | for (Value *V : CBI.args()) | |||
2511 | if (auto *BA = dyn_cast<BlockAddress>(V)) | |||
2512 | ArgBBs.insert(BA->getBasicBlock()); | |||
2513 | for (BasicBlock *BB : CBI.getIndirectDests()) | |||
2514 | Assert(ArgBBs.find(BB) != ArgBBs.end(),do { if (!(ArgBBs.find(BB) != ArgBBs.end())) { CheckFailed("Indirect label missing from arglist." , &CBI); return; } } while (false) | |||
2515 | "Indirect label missing from arglist.", &CBI)do { if (!(ArgBBs.find(BB) != ArgBBs.end())) { CheckFailed("Indirect label missing from arglist." , &CBI); return; } } while (false); | |||
2516 | } | |||
2517 | ||||
2518 | visitTerminator(CBI); | |||
2519 | } | |||
2520 | ||||
2521 | void Verifier::visitSelectInst(SelectInst &SI) { | |||
2522 | Assert(!SelectInst::areInvalidOperands(SI.getOperand(0), SI.getOperand(1),do { if (!(!SelectInst::areInvalidOperands(SI.getOperand(0), SI .getOperand(1), SI.getOperand(2)))) { CheckFailed("Invalid operands for select instruction!" , &SI); return; } } while (false) | |||
2523 | SI.getOperand(2)),do { if (!(!SelectInst::areInvalidOperands(SI.getOperand(0), SI .getOperand(1), SI.getOperand(2)))) { CheckFailed("Invalid operands for select instruction!" , &SI); return; } } while (false) | |||
2524 | "Invalid operands for select instruction!", &SI)do { if (!(!SelectInst::areInvalidOperands(SI.getOperand(0), SI .getOperand(1), SI.getOperand(2)))) { CheckFailed("Invalid operands for select instruction!" , &SI); return; } } while (false); | |||
2525 | ||||
2526 | Assert(SI.getTrueValue()->getType() == SI.getType(),do { if (!(SI.getTrueValue()->getType() == SI.getType())) { CheckFailed("Select values must have same type as select instruction!" , &SI); return; } } while (false) | |||
2527 | "Select values must have same type as select instruction!", &SI)do { if (!(SI.getTrueValue()->getType() == SI.getType())) { CheckFailed("Select values must have same type as select instruction!" , &SI); return; } } while (false); | |||
2528 | visitInstruction(SI); | |||
2529 | } | |||
2530 | ||||
2531 | /// visitUserOp1 - User defined operators shouldn't live beyond the lifetime of | |||
2532 | /// a pass, if any exist, it's an error. | |||
2533 | /// | |||
2534 | void Verifier::visitUserOp1(Instruction &I) { | |||
2535 | Assert(false, "User-defined operators should not live outside of a pass!", &I)do { if (!(false)) { CheckFailed("User-defined operators should not live outside of a pass!" , &I); return; } } while (false); | |||
2536 | } | |||
2537 | ||||
2538 | void Verifier::visitTruncInst(TruncInst &I) { | |||
2539 | // Get the source and destination types | |||
2540 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2541 | Type *DestTy = I.getType(); | |||
2542 | ||||
2543 | // Get the size of the types in bits, we'll need this later | |||
2544 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | |||
2545 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | |||
2546 | ||||
2547 | Assert(SrcTy->isIntOrIntVectorTy(), "Trunc only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("Trunc only operates on integer" , &I); return; } } while (false); | |||
2548 | Assert(DestTy->isIntOrIntVectorTy(), "Trunc only produces integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("Trunc only produces integer" , &I); return; } } while (false); | |||
2549 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(),do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("trunc source and destination must both be a vector or neither" , &I); return; } } while (false) | |||
2550 | "trunc source and destination must both be a vector or neither", &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("trunc source and destination must both be a vector or neither" , &I); return; } } while (false); | |||
2551 | Assert(SrcBitSize > DestBitSize, "DestTy too big for Trunc", &I)do { if (!(SrcBitSize > DestBitSize)) { CheckFailed("DestTy too big for Trunc" , &I); return; } } while (false); | |||
2552 | ||||
2553 | visitInstruction(I); | |||
2554 | } | |||
2555 | ||||
2556 | void Verifier::visitZExtInst(ZExtInst &I) { | |||
2557 | // Get the source and destination types | |||
2558 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2559 | Type *DestTy = I.getType(); | |||
2560 | ||||
2561 | // Get the size of the types in bits, we'll need this later | |||
2562 | Assert(SrcTy->isIntOrIntVectorTy(), "ZExt only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("ZExt only operates on integer" , &I); return; } } while (false); | |||
2563 | Assert(DestTy->isIntOrIntVectorTy(), "ZExt only produces an integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("ZExt only produces an integer" , &I); return; } } while (false); | |||
2564 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(),do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("zext source and destination must both be a vector or neither" , &I); return; } } while (false) | |||
2565 | "zext source and destination must both be a vector or neither", &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("zext source and destination must both be a vector or neither" , &I); return; } } while (false); | |||
2566 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | |||
2567 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | |||
2568 | ||||
2569 | Assert(SrcBitSize < DestBitSize, "Type too small for ZExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("Type too small for ZExt" , &I); return; } } while (false); | |||
2570 | ||||
2571 | visitInstruction(I); | |||
2572 | } | |||
2573 | ||||
2574 | void Verifier::visitSExtInst(SExtInst &I) { | |||
2575 | // Get the source and destination types | |||
2576 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2577 | Type *DestTy = I.getType(); | |||
2578 | ||||
2579 | // Get the size of the types in bits, we'll need this later | |||
2580 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | |||
2581 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | |||
2582 | ||||
2583 | Assert(SrcTy->isIntOrIntVectorTy(), "SExt only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("SExt only operates on integer" , &I); return; } } while (false); | |||
2584 | Assert(DestTy->isIntOrIntVectorTy(), "SExt only produces an integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("SExt only produces an integer" , &I); return; } } while (false); | |||
2585 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(),do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("sext source and destination must both be a vector or neither" , &I); return; } } while (false) | |||
2586 | "sext source and destination must both be a vector or neither", &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("sext source and destination must both be a vector or neither" , &I); return; } } while (false); | |||
2587 | Assert(SrcBitSize < DestBitSize, "Type too small for SExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("Type too small for SExt" , &I); return; } } while (false); | |||
2588 | ||||
2589 | visitInstruction(I); | |||
2590 | } | |||
2591 | ||||
2592 | void Verifier::visitFPTruncInst(FPTruncInst &I) { | |||
2593 | // Get the source and destination types | |||
2594 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2595 | Type *DestTy = I.getType(); | |||
2596 | // Get the size of the types in bits, we'll need this later | |||
2597 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | |||
2598 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | |||
2599 | ||||
2600 | Assert(SrcTy->isFPOrFPVectorTy(), "FPTrunc only operates on FP", &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPTrunc only operates on FP" , &I); return; } } while (false); | |||
2601 | Assert(DestTy->isFPOrFPVectorTy(), "FPTrunc only produces an FP", &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("FPTrunc only produces an FP" , &I); return; } } while (false); | |||
2602 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(),do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("fptrunc source and destination must both be a vector or neither" , &I); return; } } while (false) | |||
2603 | "fptrunc source and destination must both be a vector or neither", &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("fptrunc source and destination must both be a vector or neither" , &I); return; } } while (false); | |||
2604 | Assert(SrcBitSize > DestBitSize, "DestTy too big for FPTrunc", &I)do { if (!(SrcBitSize > DestBitSize)) { CheckFailed("DestTy too big for FPTrunc" , &I); return; } } while (false); | |||
2605 | ||||
2606 | visitInstruction(I); | |||
2607 | } | |||
2608 | ||||
2609 | void Verifier::visitFPExtInst(FPExtInst &I) { | |||
2610 | // Get the source and destination types | |||
2611 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2612 | Type *DestTy = I.getType(); | |||
2613 | ||||
2614 | // Get the size of the types in bits, we'll need this later | |||
2615 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | |||
2616 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | |||
2617 | ||||
2618 | Assert(SrcTy->isFPOrFPVectorTy(), "FPExt only operates on FP", &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPExt only operates on FP" , &I); return; } } while (false); | |||
2619 | Assert(DestTy->isFPOrFPVectorTy(), "FPExt only produces an FP", &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("FPExt only produces an FP" , &I); return; } } while (false); | |||
2620 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(),do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("fpext source and destination must both be a vector or neither" , &I); return; } } while (false) | |||
2621 | "fpext source and destination must both be a vector or neither", &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("fpext source and destination must both be a vector or neither" , &I); return; } } while (false); | |||
2622 | Assert(SrcBitSize < DestBitSize, "DestTy too small for FPExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("DestTy too small for FPExt" , &I); return; } } while (false); | |||
2623 | ||||
2624 | visitInstruction(I); | |||
2625 | } | |||
2626 | ||||
2627 | void Verifier::visitUIToFPInst(UIToFPInst &I) { | |||
2628 | // Get the source and destination types | |||
2629 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2630 | Type *DestTy = I.getType(); | |||
2631 | ||||
2632 | bool SrcVec = SrcTy->isVectorTy(); | |||
2633 | bool DstVec = DestTy->isVectorTy(); | |||
2634 | ||||
2635 | Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("UIToFP source and dest must both be vector or scalar" , &I); return; } } while (false) | |||
2636 | "UIToFP source and dest must both be vector or scalar", &I)do { if (!(SrcVec == DstVec)) { CheckFailed("UIToFP source and dest must both be vector or scalar" , &I); return; } } while (false); | |||
2637 | Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("UIToFP source must be integer or integer vector" , &I); return; } } while (false) | |||
2638 | "UIToFP source must be integer or integer vector", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("UIToFP source must be integer or integer vector" , &I); return; } } while (false); | |||
2639 | Assert(DestTy->isFPOrFPVectorTy(), "UIToFP result must be FP or FP vector",do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("UIToFP result must be FP or FP vector" , &I); return; } } while (false) | |||
2640 | &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("UIToFP result must be FP or FP vector" , &I); return; } } while (false); | |||
2641 | ||||
2642 | if (SrcVec && DstVec) | |||
2643 | Assert(cast<VectorType>(SrcTy)->getNumElements() ==do { if (!(cast<VectorType>(SrcTy)->getNumElements() == cast<VectorType>(DestTy)->getNumElements())) { CheckFailed ("UIToFP source and dest vector length mismatch", &I); return ; } } while (false) | |||
2644 | cast<VectorType>(DestTy)->getNumElements(),do { if (!(cast<VectorType>(SrcTy)->getNumElements() == cast<VectorType>(DestTy)->getNumElements())) { CheckFailed ("UIToFP source and dest vector length mismatch", &I); return ; } } while (false) | |||
2645 | "UIToFP source and dest vector length mismatch", &I)do { if (!(cast<VectorType>(SrcTy)->getNumElements() == cast<VectorType>(DestTy)->getNumElements())) { CheckFailed ("UIToFP source and dest vector length mismatch", &I); return ; } } while (false); | |||
2646 | ||||
2647 | visitInstruction(I); | |||
2648 | } | |||
2649 | ||||
2650 | void Verifier::visitSIToFPInst(SIToFPInst &I) { | |||
2651 | // Get the source and destination types | |||
2652 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2653 | Type *DestTy = I.getType(); | |||
2654 | ||||
2655 | bool SrcVec = SrcTy->isVectorTy(); | |||
2656 | bool DstVec = DestTy->isVectorTy(); | |||
2657 | ||||
2658 | Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("SIToFP source and dest must both be vector or scalar" , &I); return; } } while (false) | |||
2659 | "SIToFP source and dest must both be vector or scalar", &I)do { if (!(SrcVec == DstVec)) { CheckFailed("SIToFP source and dest must both be vector or scalar" , &I); return; } } while (false); | |||
2660 | Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("SIToFP source must be integer or integer vector" , &I); return; } } while (false) | |||
2661 | "SIToFP source must be integer or integer vector", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("SIToFP source must be integer or integer vector" , &I); return; } } while (false); | |||
2662 | Assert(DestTy->isFPOrFPVectorTy(), "SIToFP result must be FP or FP vector",do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("SIToFP result must be FP or FP vector" , &I); return; } } while (false) | |||
2663 | &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("SIToFP result must be FP or FP vector" , &I); return; } } while (false); | |||
2664 | ||||
2665 | if (SrcVec && DstVec) | |||
2666 | Assert(cast<VectorType>(SrcTy)->getNumElements() ==do { if (!(cast<VectorType>(SrcTy)->getNumElements() == cast<VectorType>(DestTy)->getNumElements())) { CheckFailed ("SIToFP source and dest vector length mismatch", &I); return ; } } while (false) | |||
2667 | cast<VectorType>(DestTy)->getNumElements(),do { if (!(cast<VectorType>(SrcTy)->getNumElements() == cast<VectorType>(DestTy)->getNumElements())) { CheckFailed ("SIToFP source and dest vector length mismatch", &I); return ; } } while (false) | |||
2668 | "SIToFP source and dest vector length mismatch", &I)do { if (!(cast<VectorType>(SrcTy)->getNumElements() == cast<VectorType>(DestTy)->getNumElements())) { CheckFailed ("SIToFP source and dest vector length mismatch", &I); return ; } } while (false); | |||
2669 | ||||
2670 | visitInstruction(I); | |||
2671 | } | |||
2672 | ||||
2673 | void Verifier::visitFPToUIInst(FPToUIInst &I) { | |||
2674 | // Get the source and destination types | |||
2675 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2676 | Type *DestTy = I.getType(); | |||
2677 | ||||
2678 | bool SrcVec = SrcTy->isVectorTy(); | |||
2679 | bool DstVec = DestTy->isVectorTy(); | |||
2680 | ||||
2681 | Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("FPToUI source and dest must both be vector or scalar" , &I); return; } } while (false) | |||
2682 | "FPToUI source and dest must both be vector or scalar", &I)do { if (!(SrcVec == DstVec)) { CheckFailed("FPToUI source and dest must both be vector or scalar" , &I); return; } } while (false); | |||
2683 | Assert(SrcTy->isFPOrFPVectorTy(), "FPToUI source must be FP or FP vector",do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToUI source must be FP or FP vector" , &I); return; } } while (false) | |||
2684 | &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToUI source must be FP or FP vector" , &I); return; } } while (false); | |||
2685 | Assert(DestTy->isIntOrIntVectorTy(),do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToUI result must be integer or integer vector" , &I); return; } } while (false) | |||
2686 | "FPToUI result must be integer or integer vector", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToUI result must be integer or integer vector" , &I); return; } } while (false); | |||
2687 | ||||
2688 | if (SrcVec && DstVec) | |||
2689 | Assert(cast<VectorType>(SrcTy)->getNumElements() ==do { if (!(cast<VectorType>(SrcTy)->getNumElements() == cast<VectorType>(DestTy)->getNumElements())) { CheckFailed ("FPToUI source and dest vector length mismatch", &I); return ; } } while (false) | |||
2690 | cast<VectorType>(DestTy)->getNumElements(),do { if (!(cast<VectorType>(SrcTy)->getNumElements() == cast<VectorType>(DestTy)->getNumElements())) { CheckFailed ("FPToUI source and dest vector length mismatch", &I); return ; } } while (false) | |||
2691 | "FPToUI source and dest vector length mismatch", &I)do { if (!(cast<VectorType>(SrcTy)->getNumElements() == cast<VectorType>(DestTy)->getNumElements())) { CheckFailed ("FPToUI source and dest vector length mismatch", &I); return ; } } while (false); | |||
2692 | ||||
2693 | visitInstruction(I); | |||
2694 | } | |||
2695 | ||||
2696 | void Verifier::visitFPToSIInst(FPToSIInst &I) { | |||
2697 | // Get the source and destination types | |||
2698 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2699 | Type *DestTy = I.getType(); | |||
2700 | ||||
2701 | bool SrcVec = SrcTy->isVectorTy(); | |||
2702 | bool DstVec = DestTy->isVectorTy(); | |||
2703 | ||||
2704 | Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("FPToSI source and dest must both be vector or scalar" , &I); return; } } while (false) | |||
2705 | "FPToSI source and dest must both be vector or scalar", &I)do { if (!(SrcVec == DstVec)) { CheckFailed("FPToSI source and dest must both be vector or scalar" , &I); return; } } while (false); | |||
2706 | Assert(SrcTy->isFPOrFPVectorTy(), "FPToSI source must be FP or FP vector",do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToSI source must be FP or FP vector" , &I); return; } } while (false) | |||
2707 | &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToSI source must be FP or FP vector" , &I); return; } } while (false); | |||
2708 | Assert(DestTy->isIntOrIntVectorTy(),do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToSI result must be integer or integer vector" , &I); return; } } while (false) | |||
2709 | "FPToSI result must be integer or integer vector", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToSI result must be integer or integer vector" , &I); return; } } while (false); | |||
2710 | ||||
2711 | if (SrcVec && DstVec) | |||
2712 | Assert(cast<VectorType>(SrcTy)->getNumElements() ==do { if (!(cast<VectorType>(SrcTy)->getNumElements() == cast<VectorType>(DestTy)->getNumElements())) { CheckFailed ("FPToSI source and dest vector length mismatch", &I); return ; } } while (false) | |||
2713 | cast<VectorType>(DestTy)->getNumElements(),do { if (!(cast<VectorType>(SrcTy)->getNumElements() == cast<VectorType>(DestTy)->getNumElements())) { CheckFailed ("FPToSI source and dest vector length mismatch", &I); return ; } } while (false) | |||
2714 | "FPToSI source and dest vector length mismatch", &I)do { if (!(cast<VectorType>(SrcTy)->getNumElements() == cast<VectorType>(DestTy)->getNumElements())) { CheckFailed ("FPToSI source and dest vector length mismatch", &I); return ; } } while (false); | |||
2715 | ||||
2716 | visitInstruction(I); | |||
2717 | } | |||
2718 | ||||
2719 | void Verifier::visitPtrToIntInst(PtrToIntInst &I) { | |||
2720 | // Get the source and destination types | |||
2721 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2722 | Type *DestTy = I.getType(); | |||
2723 | ||||
2724 | Assert(SrcTy->isPtrOrPtrVectorTy(), "PtrToInt source must be pointer", &I)do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("PtrToInt source must be pointer" , &I); return; } } while (false); | |||
2725 | ||||
2726 | if (auto *PTy = dyn_cast<PointerType>(SrcTy->getScalarType())) | |||
2727 | Assert(!DL.isNonIntegralPointerType(PTy),do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed( "ptrtoint not supported for non-integral pointers"); return; } } while (false) | |||
2728 | "ptrtoint not supported for non-integral pointers")do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed( "ptrtoint not supported for non-integral pointers"); return; } } while (false); | |||
2729 | ||||
2730 | Assert(DestTy->isIntOrIntVectorTy(), "PtrToInt result must be integral", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("PtrToInt result must be integral" , &I); return; } } while (false); | |||
2731 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(), "PtrToInt type mismatch",do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("PtrToInt type mismatch", &I); return; } } while (false) | |||
2732 | &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("PtrToInt type mismatch", &I); return; } } while (false); | |||
2733 | ||||
2734 | if (SrcTy->isVectorTy()) { | |||
2735 | VectorType *VSrc = cast<VectorType>(SrcTy); | |||
2736 | VectorType *VDest = cast<VectorType>(DestTy); | |||
2737 | Assert(VSrc->getNumElements() == VDest->getNumElements(),do { if (!(VSrc->getNumElements() == VDest->getNumElements ())) { CheckFailed("PtrToInt Vector width mismatch", &I); return; } } while (false) | |||
2738 | "PtrToInt Vector width mismatch", &I)do { if (!(VSrc->getNumElements() == VDest->getNumElements ())) { CheckFailed("PtrToInt Vector width mismatch", &I); return; } } while (false); | |||
2739 | } | |||
2740 | ||||
2741 | visitInstruction(I); | |||
2742 | } | |||
2743 | ||||
2744 | void Verifier::visitIntToPtrInst(IntToPtrInst &I) { | |||
2745 | // Get the source and destination types | |||
2746 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2747 | Type *DestTy = I.getType(); | |||
2748 | ||||
2749 | Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("IntToPtr source must be an integral" , &I); return; } } while (false) | |||
2750 | "IntToPtr source must be an integral", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("IntToPtr source must be an integral" , &I); return; } } while (false); | |||
2751 | Assert(DestTy->isPtrOrPtrVectorTy(), "IntToPtr result must be a pointer", &I)do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("IntToPtr result must be a pointer" , &I); return; } } while (false); | |||
2752 | ||||
2753 | if (auto *PTy = dyn_cast<PointerType>(DestTy->getScalarType())) | |||
2754 | Assert(!DL.isNonIntegralPointerType(PTy),do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed( "inttoptr not supported for non-integral pointers"); return; } } while (false) | |||
2755 | "inttoptr not supported for non-integral pointers")do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed( "inttoptr not supported for non-integral pointers"); return; } } while (false); | |||
2756 | ||||
2757 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(), "IntToPtr type mismatch",do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("IntToPtr type mismatch", &I); return; } } while (false) | |||
2758 | &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("IntToPtr type mismatch", &I); return; } } while (false); | |||
2759 | if (SrcTy->isVectorTy()) { | |||
2760 | VectorType *VSrc = cast<VectorType>(SrcTy); | |||
2761 | VectorType *VDest = cast<VectorType>(DestTy); | |||
2762 | Assert(VSrc->getNumElements() == VDest->getNumElements(),do { if (!(VSrc->getNumElements() == VDest->getNumElements ())) { CheckFailed("IntToPtr Vector width mismatch", &I); return; } } while (false) | |||
2763 | "IntToPtr Vector width mismatch", &I)do { if (!(VSrc->getNumElements() == VDest->getNumElements ())) { CheckFailed("IntToPtr Vector width mismatch", &I); return; } } while (false); | |||
2764 | } | |||
2765 | visitInstruction(I); | |||
2766 | } | |||
2767 | ||||
2768 | void Verifier::visitBitCastInst(BitCastInst &I) { | |||
2769 | Assert(do { if (!(CastInst::castIsValid(Instruction::BitCast, I.getOperand (0), I.getType()))) { CheckFailed("Invalid bitcast", &I); return; } } while (false) | |||
2770 | CastInst::castIsValid(Instruction::BitCast, I.getOperand(0), I.getType()),do { if (!(CastInst::castIsValid(Instruction::BitCast, I.getOperand (0), I.getType()))) { CheckFailed("Invalid bitcast", &I); return; } } while (false) | |||
2771 | "Invalid bitcast", &I)do { if (!(CastInst::castIsValid(Instruction::BitCast, I.getOperand (0), I.getType()))) { CheckFailed("Invalid bitcast", &I); return; } } while (false); | |||
2772 | visitInstruction(I); | |||
2773 | } | |||
2774 | ||||
2775 | void Verifier::visitAddrSpaceCastInst(AddrSpaceCastInst &I) { | |||
2776 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2777 | Type *DestTy = I.getType(); | |||
2778 | ||||
2779 | Assert(SrcTy->isPtrOrPtrVectorTy(), "AddrSpaceCast source must be a pointer",do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast source must be a pointer" , &I); return; } } while (false) | |||
2780 | &I)do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast source must be a pointer" , &I); return; } } while (false); | |||
2781 | Assert(DestTy->isPtrOrPtrVectorTy(), "AddrSpaceCast result must be a pointer",do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast result must be a pointer" , &I); return; } } while (false) | |||
2782 | &I)do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast result must be a pointer" , &I); return; } } while (false); | |||
2783 | Assert(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace(),do { if (!(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace ())) { CheckFailed("AddrSpaceCast must be between different address spaces" , &I); return; } } while (false) | |||
2784 | "AddrSpaceCast must be between different address spaces", &I)do { if (!(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace ())) { CheckFailed("AddrSpaceCast must be between different address spaces" , &I); return; } } while (false); | |||
2785 | if (SrcTy->isVectorTy()) | |||
2786 | Assert(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements(),do { if (!(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements ())) { CheckFailed("AddrSpaceCast vector pointer number of elements mismatch" , &I); return; } } while (false) | |||
2787 | "AddrSpaceCast vector pointer number of elements mismatch", &I)do { if (!(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements ())) { CheckFailed("AddrSpaceCast vector pointer number of elements mismatch" , &I); return; } } while (false); | |||
2788 | visitInstruction(I); | |||
2789 | } | |||
2790 | ||||
2791 | /// visitPHINode - Ensure that a PHI node is well formed. | |||
2792 | /// | |||
2793 | void Verifier::visitPHINode(PHINode &PN) { | |||
2794 | // Ensure that the PHI nodes are all grouped together at the top of the block. | |||
2795 | // This can be tested by checking whether the instruction before this is | |||
2796 | // either nonexistent (because this is begin()) or is a PHI node. If not, | |||
2797 | // then there is some other instruction before a PHI. | |||
2798 | Assert(&PN == &PN.getParent()->front() ||do { if (!(&PN == &PN.getParent()->front() || isa< PHINode>(--BasicBlock::iterator(&PN)))) { CheckFailed( "PHI nodes not grouped at top of basic block!", &PN, PN.getParent ()); return; } } while (false) | |||
2799 | isa<PHINode>(--BasicBlock::iterator(&PN)),do { if (!(&PN == &PN.getParent()->front() || isa< PHINode>(--BasicBlock::iterator(&PN)))) { CheckFailed( "PHI nodes not grouped at top of basic block!", &PN, PN.getParent ()); return; } } while (false) | |||
2800 | "PHI nodes not grouped at top of basic block!", &PN, PN.getParent())do { if (!(&PN == &PN.getParent()->front() || isa< PHINode>(--BasicBlock::iterator(&PN)))) { CheckFailed( "PHI nodes not grouped at top of basic block!", &PN, PN.getParent ()); return; } } while (false); | |||
2801 | ||||
2802 | // Check that a PHI doesn't yield a Token. | |||
2803 | Assert(!PN.getType()->isTokenTy(), "PHI nodes cannot have token type!")do { if (!(!PN.getType()->isTokenTy())) { CheckFailed("PHI nodes cannot have token type!" ); return; } } while (false); | |||
2804 | ||||
2805 | // Check that all of the values of the PHI node have the same type as the | |||
2806 | // result, and that the incoming blocks are really basic blocks. | |||
2807 | for (Value *IncValue : PN.incoming_values()) { | |||
2808 | Assert(PN.getType() == IncValue->getType(),do { if (!(PN.getType() == IncValue->getType())) { CheckFailed ("PHI node operands are not the same type as the result!", & PN); return; } } while (false) | |||
2809 | "PHI node operands are not the same type as the result!", &PN)do { if (!(PN.getType() == IncValue->getType())) { CheckFailed ("PHI node operands are not the same type as the result!", & PN); return; } } while (false); | |||
2810 | } | |||
2811 | ||||
2812 | // All other PHI node constraints are checked in the visitBasicBlock method. | |||
2813 | ||||
2814 | visitInstruction(PN); | |||
2815 | } | |||
2816 | ||||
2817 | void Verifier::visitCallBase(CallBase &Call) { | |||
2818 | Assert(Call.getCalledValue()->getType()->isPointerTy(),do { if (!(Call.getCalledValue()->getType()->isPointerTy ())) { CheckFailed("Called function must be a pointer!", Call ); return; } } while (false) | |||
2819 | "Called function must be a pointer!", Call)do { if (!(Call.getCalledValue()->getType()->isPointerTy ())) { CheckFailed("Called function must be a pointer!", Call ); return; } } while (false); | |||
2820 | PointerType *FPTy = cast<PointerType>(Call.getCalledValue()->getType()); | |||
2821 | ||||
2822 | Assert(FPTy->getElementType()->isFunctionTy(),do { if (!(FPTy->getElementType()->isFunctionTy())) { CheckFailed ("Called function is not pointer to function type!", Call); return ; } } while (false) | |||
2823 | "Called function is not pointer to function type!", Call)do { if (!(FPTy->getElementType()->isFunctionTy())) { CheckFailed ("Called function is not pointer to function type!", Call); return ; } } while (false); | |||
2824 | ||||
2825 | Assert(FPTy->getElementType() == Call.getFunctionType(),do { if (!(FPTy->getElementType() == Call.getFunctionType( ))) { CheckFailed("Called function is not the same type as the call!" , Call); return; } } while (false) | |||
2826 | "Called function is not the same type as the call!", Call)do { if (!(FPTy->getElementType() == Call.getFunctionType( ))) { CheckFailed("Called function is not the same type as the call!" , Call); return; } } while (false); | |||
2827 | ||||
2828 | FunctionType *FTy = Call.getFunctionType(); | |||
2829 | ||||
2830 | // Verify that the correct number of arguments are being passed | |||
2831 | if (FTy->isVarArg()) | |||
2832 | Assert(Call.arg_size() >= FTy->getNumParams(),do { if (!(Call.arg_size() >= FTy->getNumParams())) { CheckFailed ("Called function requires more parameters than were provided!" , Call); return; } } while (false) | |||
2833 | "Called function requires more parameters than were provided!",do { if (!(Call.arg_size() >= FTy->getNumParams())) { CheckFailed ("Called function requires more parameters than were provided!" , Call); return; } } while (false) | |||
2834 | Call)do { if (!(Call.arg_size() >= FTy->getNumParams())) { CheckFailed ("Called function requires more parameters than were provided!" , Call); return; } } while (false); | |||
2835 | else | |||
2836 | Assert(Call.arg_size() == FTy->getNumParams(),do { if (!(Call.arg_size() == FTy->getNumParams())) { CheckFailed ("Incorrect number of arguments passed to called function!", Call ); return; } } while (false) | |||
2837 | "Incorrect number of arguments passed to called function!", Call)do { if (!(Call.arg_size() == FTy->getNumParams())) { CheckFailed ("Incorrect number of arguments passed to called function!", Call ); return; } } while (false); | |||
2838 | ||||
2839 | // Verify that all arguments to the call match the function type. | |||
2840 | for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) | |||
2841 | Assert(Call.getArgOperand(i)->getType() == FTy->getParamType(i),do { if (!(Call.getArgOperand(i)->getType() == FTy->getParamType (i))) { CheckFailed("Call parameter type does not match function signature!" , Call.getArgOperand(i), FTy->getParamType(i), Call); return ; } } while (false) | |||
2842 | "Call parameter type does not match function signature!",do { if (!(Call.getArgOperand(i)->getType() == FTy->getParamType (i))) { CheckFailed("Call parameter type does not match function signature!" , Call.getArgOperand(i), FTy->getParamType(i), Call); return ; } } while (false) | |||
2843 | Call.getArgOperand(i), FTy->getParamType(i), Call)do { if (!(Call.getArgOperand(i)->getType() == FTy->getParamType (i))) { CheckFailed("Call parameter type does not match function signature!" , Call.getArgOperand(i), FTy->getParamType(i), Call); return ; } } while (false); | |||
2844 | ||||
2845 | AttributeList Attrs = Call.getAttributes(); | |||
2846 | ||||
2847 | Assert(verifyAttributeCount(Attrs, Call.arg_size()),do { if (!(verifyAttributeCount(Attrs, Call.arg_size()))) { CheckFailed ("Attribute after last parameter!", Call); return; } } while ( false) | |||
2848 | "Attribute after last parameter!", Call)do { if (!(verifyAttributeCount(Attrs, Call.arg_size()))) { CheckFailed ("Attribute after last parameter!", Call); return; } } while ( false); | |||
2849 | ||||
2850 | bool IsIntrinsic = Call.getCalledFunction() && | |||
2851 | Call.getCalledFunction()->getName().startswith("llvm."); | |||
2852 | ||||
2853 | Function *Callee | |||
2854 | = dyn_cast<Function>(Call.getCalledValue()->stripPointerCasts()); | |||
2855 | ||||
2856 | if (Attrs.hasAttribute(AttributeList::FunctionIndex, Attribute::Speculatable)) { | |||
2857 | // Don't allow speculatable on call sites, unless the underlying function | |||
2858 | // declaration is also speculatable. | |||
2859 | Assert(Callee && Callee->isSpeculatable(),do { if (!(Callee && Callee->isSpeculatable())) { CheckFailed ("speculatable attribute may not apply to call sites", Call); return; } } while (false) | |||
2860 | "speculatable attribute may not apply to call sites", Call)do { if (!(Callee && Callee->isSpeculatable())) { CheckFailed ("speculatable attribute may not apply to call sites", Call); return; } } while (false); | |||
2861 | } | |||
2862 | ||||
2863 | // Verify call attributes. | |||
2864 | verifyFunctionAttrs(FTy, Attrs, &Call, IsIntrinsic); | |||
2865 | ||||
2866 | // Conservatively check the inalloca argument. | |||
2867 | // We have a bug if we can find that there is an underlying alloca without | |||
2868 | // inalloca. | |||
2869 | if (Call.hasInAllocaArgument()) { | |||
2870 | Value *InAllocaArg = Call.getArgOperand(FTy->getNumParams() - 1); | |||
2871 | if (auto AI = dyn_cast<AllocaInst>(InAllocaArg->stripInBoundsOffsets())) | |||
2872 | Assert(AI->isUsedWithInAlloca(),do { if (!(AI->isUsedWithInAlloca())) { CheckFailed("inalloca argument for call has mismatched alloca" , AI, Call); return; } } while (false) | |||
2873 | "inalloca argument for call has mismatched alloca", AI, Call)do { if (!(AI->isUsedWithInAlloca())) { CheckFailed("inalloca argument for call has mismatched alloca" , AI, Call); return; } } while (false); | |||
2874 | } | |||
2875 | ||||
2876 | // For each argument of the callsite, if it has the swifterror argument, | |||
2877 | // make sure the underlying alloca/parameter it comes from has a swifterror as | |||
2878 | // well. | |||
2879 | for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) { | |||
2880 | if (Call.paramHasAttr(i, Attribute::SwiftError)) { | |||
2881 | Value *SwiftErrorArg = Call.getArgOperand(i); | |||
2882 | if (auto AI = dyn_cast<AllocaInst>(SwiftErrorArg->stripInBoundsOffsets())) { | |||
2883 | Assert(AI->isSwiftError(),do { if (!(AI->isSwiftError())) { CheckFailed("swifterror argument for call has mismatched alloca" , AI, Call); return; } } while (false) | |||
2884 | "swifterror argument for call has mismatched alloca", AI, Call)do { if (!(AI->isSwiftError())) { CheckFailed("swifterror argument for call has mismatched alloca" , AI, Call); return; } } while (false); | |||
2885 | continue; | |||
2886 | } | |||
2887 | auto ArgI = dyn_cast<Argument>(SwiftErrorArg); | |||
2888 | Assert(ArgI,do { if (!(ArgI)) { CheckFailed("swifterror argument should come from an alloca or parameter" , SwiftErrorArg, Call); return; } } while (false) | |||
2889 | "swifterror argument should come from an alloca or parameter",do { if (!(ArgI)) { CheckFailed("swifterror argument should come from an alloca or parameter" , SwiftErrorArg, Call); return; } } while (false) | |||
2890 | SwiftErrorArg, Call)do { if (!(ArgI)) { CheckFailed("swifterror argument should come from an alloca or parameter" , SwiftErrorArg, Call); return; } } while (false); | |||
2891 | Assert(ArgI->hasSwiftErrorAttr(),do { if (!(ArgI->hasSwiftErrorAttr())) { CheckFailed("swifterror argument for call has mismatched parameter" , ArgI, Call); return; } } while (false) | |||
2892 | "swifterror argument for call has mismatched parameter", ArgI,do { if (!(ArgI->hasSwiftErrorAttr())) { CheckFailed("swifterror argument for call has mismatched parameter" , ArgI, Call); return; } } while (false) | |||
2893 | Call)do { if (!(ArgI->hasSwiftErrorAttr())) { CheckFailed("swifterror argument for call has mismatched parameter" , ArgI, Call); return; } } while (false); | |||
2894 | } | |||
2895 | ||||
2896 | if (Attrs.hasParamAttribute(i, Attribute::ImmArg)) { | |||
2897 | // Don't allow immarg on call sites, unless the underlying declaration | |||
2898 | // also has the matching immarg. | |||
2899 | Assert(Callee && Callee->hasParamAttribute(i, Attribute::ImmArg),do { if (!(Callee && Callee->hasParamAttribute(i, Attribute ::ImmArg))) { CheckFailed("immarg may not apply only to call sites" , Call.getArgOperand(i), Call); return; } } while (false) | |||
2900 | "immarg may not apply only to call sites",do { if (!(Callee && Callee->hasParamAttribute(i, Attribute ::ImmArg))) { CheckFailed("immarg may not apply only to call sites" , Call.getArgOperand(i), Call); return; } } while (false) | |||
2901 | Call.getArgOperand(i), Call)do { if (!(Callee && Callee->hasParamAttribute(i, Attribute ::ImmArg))) { CheckFailed("immarg may not apply only to call sites" , Call.getArgOperand(i), Call); return; } } while (false); | |||
2902 | } | |||
2903 | ||||
2904 | if (Call.paramHasAttr(i, Attribute::ImmArg)) { | |||
2905 | Value *ArgVal = Call.getArgOperand(i); | |||
2906 | Assert(isa<ConstantInt>(ArgVal) || isa<ConstantFP>(ArgVal),do { if (!(isa<ConstantInt>(ArgVal) || isa<ConstantFP >(ArgVal))) { CheckFailed("immarg operand has non-immediate parameter" , ArgVal, Call); return; } } while (false) | |||
2907 | "immarg operand has non-immediate parameter", ArgVal, Call)do { if (!(isa<ConstantInt>(ArgVal) || isa<ConstantFP >(ArgVal))) { CheckFailed("immarg operand has non-immediate parameter" , ArgVal, Call); return; } } while (false); | |||
2908 | } | |||
2909 | } | |||
2910 | ||||
2911 | if (FTy->isVarArg()) { | |||
2912 | // FIXME? is 'nest' even legal here? | |||
2913 | bool SawNest = false; | |||
2914 | bool SawReturned = false; | |||
2915 | ||||
2916 | for (unsigned Idx = 0; Idx < FTy->getNumParams(); ++Idx) { | |||
2917 | if (Attrs.hasParamAttribute(Idx, Attribute::Nest)) | |||
2918 | SawNest = true; | |||
2919 | if (Attrs.hasParamAttribute(Idx, Attribute::Returned)) | |||
2920 | SawReturned = true; | |||
2921 | } | |||
2922 | ||||
2923 | // Check attributes on the varargs part. | |||
2924 | for (unsigned Idx = FTy->getNumParams(); Idx < Call.arg_size(); ++Idx) { | |||
2925 | Type *Ty = Call.getArgOperand(Idx)->getType(); | |||
2926 | AttributeSet ArgAttrs = Attrs.getParamAttributes(Idx); | |||
2927 | verifyParameterAttrs(ArgAttrs, Ty, &Call); | |||
2928 | ||||
2929 | if (ArgAttrs.hasAttribute(Attribute::Nest)) { | |||
2930 | Assert(!SawNest, "More than one parameter has attribute nest!", Call)do { if (!(!SawNest)) { CheckFailed("More than one parameter has attribute nest!" , Call); return; } } while (false); | |||
2931 | SawNest = true; | |||
2932 | } | |||
2933 | ||||
2934 | if (ArgAttrs.hasAttribute(Attribute::Returned)) { | |||
2935 | Assert(!SawReturned, "More than one parameter has attribute returned!",do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!" , Call); return; } } while (false) | |||
2936 | Call)do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!" , Call); return; } } while (false); | |||
2937 | Assert(Ty->canLosslesslyBitCastTo(FTy->getReturnType()),do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' " "attribute", Call); return; } } while (false) | |||
2938 | "Incompatible argument and return types for 'returned' "do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' " "attribute", Call); return; } } while (false) | |||
2939 | "attribute",do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' " "attribute", Call); return; } } while (false) | |||
2940 | Call)do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' " "attribute", Call); return; } } while (false); | |||
2941 | SawReturned = true; | |||
2942 | } | |||
2943 | ||||
2944 | // Statepoint intrinsic is vararg but the wrapped function may be not. | |||
2945 | // Allow sret here and check the wrapped function in verifyStatepoint. | |||
2946 | if (!Call.getCalledFunction() || | |||
2947 | Call.getCalledFunction()->getIntrinsicID() != | |||
2948 | Intrinsic::experimental_gc_statepoint) | |||
2949 | Assert(!ArgAttrs.hasAttribute(Attribute::StructRet),do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed ("Attribute 'sret' cannot be used for vararg call arguments!" , Call); return; } } while (false) | |||
2950 | "Attribute 'sret' cannot be used for vararg call arguments!",do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed ("Attribute 'sret' cannot be used for vararg call arguments!" , Call); return; } } while (false) | |||
2951 | Call)do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed ("Attribute 'sret' cannot be used for vararg call arguments!" , Call); return; } } while (false); | |||
2952 | ||||
2953 | if (ArgAttrs.hasAttribute(Attribute::InAlloca)) | |||
2954 | Assert(Idx == Call.arg_size() - 1,do { if (!(Idx == Call.arg_size() - 1)) { CheckFailed("inalloca isn't on the last argument!" , Call); return; } } while (false) | |||
2955 | "inalloca isn't on the last argument!", Call)do { if (!(Idx == Call.arg_size() - 1)) { CheckFailed("inalloca isn't on the last argument!" , Call); return; } } while (false); | |||
2956 | } | |||
2957 | } | |||
2958 | ||||
2959 | // Verify that there's no metadata unless it's a direct call to an intrinsic. | |||
2960 | if (!IsIntrinsic) { | |||
2961 | for (Type *ParamTy : FTy->params()) { | |||
2962 | Assert(!ParamTy->isMetadataTy(),do { if (!(!ParamTy->isMetadataTy())) { CheckFailed("Function has metadata parameter but isn't an intrinsic" , Call); return; } } while (false) | |||
2963 | "Function has metadata parameter but isn't an intrinsic", Call)do { if (!(!ParamTy->isMetadataTy())) { CheckFailed("Function has metadata parameter but isn't an intrinsic" , Call); return; } } while (false); | |||
2964 | Assert(!ParamTy->isTokenTy(),do { if (!(!ParamTy->isTokenTy())) { CheckFailed("Function has token parameter but isn't an intrinsic" , Call); return; } } while (false) | |||
2965 | "Function has token parameter but isn't an intrinsic", Call)do { if (!(!ParamTy->isTokenTy())) { CheckFailed("Function has token parameter but isn't an intrinsic" , Call); return; } } while (false); | |||
2966 | } | |||
2967 | } | |||
2968 | ||||
2969 | // Verify that indirect calls don't return tokens. | |||
2970 | if (!Call.getCalledFunction()) | |||
2971 | Assert(!FTy->getReturnType()->isTokenTy(),do { if (!(!FTy->getReturnType()->isTokenTy())) { CheckFailed ("Return type cannot be token for indirect call!"); return; } } while (false) | |||
2972 | "Return type cannot be token for indirect call!")do { if (!(!FTy->getReturnType()->isTokenTy())) { CheckFailed ("Return type cannot be token for indirect call!"); return; } } while (false); | |||
2973 | ||||
2974 | if (Function *F = Call.getCalledFunction()) | |||
2975 | if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) | |||
2976 | visitIntrinsicCall(ID, Call); | |||
2977 | ||||
2978 | // Verify that a callsite has at most one "deopt", at most one "funclet", at | |||
2979 | // most one "gc-transition", and at most one "cfguardtarget" operand bundle. | |||
2980 | bool FoundDeoptBundle = false, FoundFuncletBundle = false, | |||
2981 | FoundGCTransitionBundle = false, FoundCFGuardTargetBundle = false; | |||
2982 | for (unsigned i = 0, e = Call.getNumOperandBundles(); i < e; ++i) { | |||
2983 | OperandBundleUse BU = Call.getOperandBundleAt(i); | |||
2984 | uint32_t Tag = BU.getTagID(); | |||
2985 | if (Tag == LLVMContext::OB_deopt) { | |||
2986 | Assert(!FoundDeoptBundle, "Multiple deopt operand bundles", Call)do { if (!(!FoundDeoptBundle)) { CheckFailed("Multiple deopt operand bundles" , Call); return; } } while (false); | |||
2987 | FoundDeoptBundle = true; | |||
2988 | } else if (Tag == LLVMContext::OB_gc_transition) { | |||
2989 | Assert(!FoundGCTransitionBundle, "Multiple gc-transition operand bundles",do { if (!(!FoundGCTransitionBundle)) { CheckFailed("Multiple gc-transition operand bundles" , Call); return; } } while (false) | |||
2990 | Call)do { if (!(!FoundGCTransitionBundle)) { CheckFailed("Multiple gc-transition operand bundles" , Call); return; } } while (false); | |||
2991 | FoundGCTransitionBundle = true; | |||
2992 | } else if (Tag == LLVMContext::OB_funclet) { | |||
2993 | Assert(!FoundFuncletBundle, "Multiple funclet operand bundles", Call)do { if (!(!FoundFuncletBundle)) { CheckFailed("Multiple funclet operand bundles" , Call); return; } } while (false); | |||
2994 | FoundFuncletBundle = true; | |||
2995 | Assert(BU.Inputs.size() == 1,do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one funclet bundle operand" , Call); return; } } while (false) | |||
2996 | "Expected exactly one funclet bundle operand", Call)do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one funclet bundle operand" , Call); return; } } while (false); | |||
2997 | Assert(isa<FuncletPadInst>(BU.Inputs.front()),do { if (!(isa<FuncletPadInst>(BU.Inputs.front()))) { CheckFailed ("Funclet bundle operands should correspond to a FuncletPadInst" , Call); return; } } while (false) | |||
2998 | "Funclet bundle operands should correspond to a FuncletPadInst",do { if (!(isa<FuncletPadInst>(BU.Inputs.front()))) { CheckFailed ("Funclet bundle operands should correspond to a FuncletPadInst" , Call); return; } } while (false) | |||
2999 | Call)do { if (!(isa<FuncletPadInst>(BU.Inputs.front()))) { CheckFailed ("Funclet bundle operands should correspond to a FuncletPadInst" , Call); return; } } while (false); | |||
3000 | } else if (Tag == LLVMContext::OB_cfguardtarget) { | |||
3001 | Assert(!FoundCFGuardTargetBundle,do { if (!(!FoundCFGuardTargetBundle)) { CheckFailed("Multiple CFGuardTarget operand bundles" , Call); return; } } while (false) | |||
3002 | "Multiple CFGuardTarget operand bundles", Call)do { if (!(!FoundCFGuardTargetBundle)) { CheckFailed("Multiple CFGuardTarget operand bundles" , Call); return; } } while (false); | |||
3003 | FoundCFGuardTargetBundle = true; | |||
3004 | Assert(BU.Inputs.size() == 1,do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one cfguardtarget bundle operand" , Call); return; } } while (false) | |||
3005 | "Expected exactly one cfguardtarget bundle operand", Call)do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one cfguardtarget bundle operand" , Call); return; } } while (false); | |||
3006 | } | |||
3007 | } | |||
3008 | ||||
3009 | // Verify that each inlinable callsite of a debug-info-bearing function in a | |||
3010 | // debug-info-bearing function has a debug location attached to it. Failure to | |||
3011 | // do so causes assertion failures when the inliner sets up inline scope info. | |||
3012 | if (Call.getFunction()->getSubprogram() && Call.getCalledFunction() && | |||
3013 | Call.getCalledFunction()->getSubprogram()) | |||
3014 | AssertDI(Call.getDebugLoc(),do { if (!(Call.getDebugLoc())) { DebugInfoCheckFailed("inlinable function call in a function with " "debug info must have a !dbg location", Call); return; } } while (false) | |||
3015 | "inlinable function call in a function with "do { if (!(Call.getDebugLoc())) { DebugInfoCheckFailed("inlinable function call in a function with " "debug info must have a !dbg location", Call); return; } } while (false) | |||
3016 | "debug info must have a !dbg location",do { if (!(Call.getDebugLoc())) { DebugInfoCheckFailed("inlinable function call in a function with " "debug info must have a !dbg location", Call); return; } } while (false) | |||
3017 | Call)do { if (!(Call.getDebugLoc())) { DebugInfoCheckFailed("inlinable function call in a function with " "debug info must have a !dbg location", Call); return; } } while (false); | |||
3018 | ||||
3019 | visitInstruction(Call); | |||
3020 | } | |||
3021 | ||||
3022 | /// Two types are "congruent" if they are identical, or if they are both pointer | |||
3023 | /// types with different pointee types and the same address space. | |||
3024 | static bool isTypeCongruent(Type *L, Type *R) { | |||
3025 | if (L == R) | |||
3026 | return true; | |||
3027 | PointerType *PL = dyn_cast<PointerType>(L); | |||
3028 | PointerType *PR = dyn_cast<PointerType>(R); | |||
3029 | if (!PL || !PR) | |||
3030 | return false; | |||
3031 | return PL->getAddressSpace() == PR->getAddressSpace(); | |||
3032 | } | |||
3033 | ||||
3034 | static AttrBuilder getParameterABIAttributes(int I, AttributeList Attrs) { | |||
3035 | static const Attribute::AttrKind ABIAttrs[] = { | |||
3036 | Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca, | |||
3037 | Attribute::InReg, Attribute::Returned, Attribute::SwiftSelf, | |||
3038 | Attribute::SwiftError}; | |||
3039 | AttrBuilder Copy; | |||
3040 | for (auto AK : ABIAttrs) { | |||
3041 | if (Attrs.hasParamAttribute(I, AK)) | |||
3042 | Copy.addAttribute(AK); | |||
3043 | } | |||
3044 | if (Attrs.hasParamAttribute(I, Attribute::Alignment)) | |||
3045 | Copy.addAlignmentAttr(Attrs.getParamAlignment(I)); | |||
3046 | return Copy; | |||
3047 | } | |||
3048 | ||||
3049 | void Verifier::verifyMustTailCall(CallInst &CI) { | |||
3050 | Assert(!CI.isInlineAsm(), "cannot use musttail call with inline asm", &CI)do { if (!(!CI.isInlineAsm())) { CheckFailed("cannot use musttail call with inline asm" , &CI); return; } } while (false); | |||
3051 | ||||
3052 | // - The caller and callee prototypes must match. Pointer types of | |||
3053 | // parameters or return types may differ in pointee type, but not | |||
3054 | // address space. | |||
3055 | Function *F = CI.getParent()->getParent(); | |||
3056 | FunctionType *CallerTy = F->getFunctionType(); | |||
3057 | FunctionType *CalleeTy = CI.getFunctionType(); | |||
3058 | if (!CI.getCalledFunction() || !CI.getCalledFunction()->isIntrinsic()) { | |||
3059 | Assert(CallerTy->getNumParams() == CalleeTy->getNumParams(),do { if (!(CallerTy->getNumParams() == CalleeTy->getNumParams ())) { CheckFailed("cannot guarantee tail call due to mismatched parameter counts" , &CI); return; } } while (false) | |||
3060 | "cannot guarantee tail call due to mismatched parameter counts",do { if (!(CallerTy->getNumParams() == CalleeTy->getNumParams ())) { CheckFailed("cannot guarantee tail call due to mismatched parameter counts" , &CI); return; } } while (false) | |||
3061 | &CI)do { if (!(CallerTy->getNumParams() == CalleeTy->getNumParams ())) { CheckFailed("cannot guarantee tail call due to mismatched parameter counts" , &CI); return; } } while (false); | |||
3062 | for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) { | |||
3063 | Assert(do { if (!(isTypeCongruent(CallerTy->getParamType(I), CalleeTy ->getParamType(I)))) { CheckFailed("cannot guarantee tail call due to mismatched parameter types" , &CI); return; } } while (false) | |||
3064 | isTypeCongruent(CallerTy->getParamType(I), CalleeTy->getParamType(I)),do { if (!(isTypeCongruent(CallerTy->getParamType(I), CalleeTy ->getParamType(I)))) { CheckFailed("cannot guarantee tail call due to mismatched parameter types" , &CI); return; } } while (false) | |||
3065 | "cannot guarantee tail call due to mismatched parameter types", &CI)do { if (!(isTypeCongruent(CallerTy->getParamType(I), CalleeTy ->getParamType(I)))) { CheckFailed("cannot guarantee tail call due to mismatched parameter types" , &CI); return; } } while (false); | |||
3066 | } | |||
3067 | } | |||
3068 | Assert(CallerTy->isVarArg() == CalleeTy->isVarArg(),do { if (!(CallerTy->isVarArg() == CalleeTy->isVarArg() )) { CheckFailed("cannot guarantee tail call due to mismatched varargs" , &CI); return; } } while (false) | |||
3069 | "cannot guarantee tail call due to mismatched varargs", &CI)do { if (!(CallerTy->isVarArg() == CalleeTy->isVarArg() )) { CheckFailed("cannot guarantee tail call due to mismatched varargs" , &CI); return; } } while (false); | |||
3070 | Assert(isTypeCongruent(CallerTy->getReturnType(), CalleeTy->getReturnType()),do { if (!(isTypeCongruent(CallerTy->getReturnType(), CalleeTy ->getReturnType()))) { CheckFailed("cannot guarantee tail call due to mismatched return types" , &CI); return; } } while (false) | |||
3071 | "cannot guarantee tail call due to mismatched return types", &CI)do { if (!(isTypeCongruent(CallerTy->getReturnType(), CalleeTy ->getReturnType()))) { CheckFailed("cannot guarantee tail call due to mismatched return types" , &CI); return; } } while (false); | |||
3072 | ||||
3073 | // - The calling conventions of the caller and callee must match. | |||
3074 | Assert(F->getCallingConv() == CI.getCallingConv(),do { if (!(F->getCallingConv() == CI.getCallingConv())) { CheckFailed ("cannot guarantee tail call due to mismatched calling conv", &CI); return; } } while (false) | |||
3075 | "cannot guarantee tail call due to mismatched calling conv", &CI)do { if (!(F->getCallingConv() == CI.getCallingConv())) { CheckFailed ("cannot guarantee tail call due to mismatched calling conv", &CI); return; } } while (false); | |||
3076 | ||||
3077 | // - All ABI-impacting function attributes, such as sret, byval, inreg, | |||
3078 | // returned, and inalloca, must match. | |||
3079 | AttributeList CallerAttrs = F->getAttributes(); | |||
3080 | AttributeList CalleeAttrs = CI.getAttributes(); | |||
3081 | for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) { | |||
3082 | AttrBuilder CallerABIAttrs = getParameterABIAttributes(I, CallerAttrs); | |||
3083 | AttrBuilder CalleeABIAttrs = getParameterABIAttributes(I, CalleeAttrs); | |||
3084 | Assert(CallerABIAttrs == CalleeABIAttrs,do { if (!(CallerABIAttrs == CalleeABIAttrs)) { CheckFailed("cannot guarantee tail call due to mismatched ABI impacting " "function attributes", &CI, CI.getOperand(I)); return; } } while (false) | |||
3085 | "cannot guarantee tail call due to mismatched ABI impacting "do { if (!(CallerABIAttrs == CalleeABIAttrs)) { CheckFailed("cannot guarantee tail call due to mismatched ABI impacting " "function attributes", &CI, CI.getOperand(I)); return; } } while (false) | |||
3086 | "function attributes",do { if (!(CallerABIAttrs == CalleeABIAttrs)) { CheckFailed("cannot guarantee tail call due to mismatched ABI impacting " "function attributes", &CI, CI.getOperand(I)); return; } } while (false) | |||
3087 | &CI, CI.getOperand(I))do { if (!(CallerABIAttrs == CalleeABIAttrs)) { CheckFailed("cannot guarantee tail call due to mismatched ABI impacting " "function attributes", &CI, CI.getOperand(I)); return; } } while (false); | |||
3088 | } | |||
3089 | ||||
3090 | // - The call must immediately precede a :ref:`ret <i_ret>` instruction, | |||
3091 | // or a pointer bitcast followed by a ret instruction. | |||
3092 | // - The ret instruction must return the (possibly bitcasted) value | |||
3093 | // produced by the call or void. | |||
3094 | Value *RetVal = &CI; | |||
3095 | Instruction *Next = CI.getNextNode(); | |||
3096 | ||||
3097 | // Handle the optional bitcast. | |||
3098 | if (BitCastInst *BI = dyn_cast_or_null<BitCastInst>(Next)) { | |||
3099 | Assert(BI->getOperand(0) == RetVal,do { if (!(BI->getOperand(0) == RetVal)) { CheckFailed("bitcast following musttail call must use the call" , BI); return; } } while (false) | |||
3100 | "bitcast following musttail call must use the call", BI)do { if (!(BI->getOperand(0) == RetVal)) { CheckFailed("bitcast following musttail call must use the call" , BI); return; } } while (false); | |||
3101 | RetVal = BI; | |||
3102 | Next = BI->getNextNode(); | |||
3103 | } | |||
3104 | ||||
3105 | // Check the return. | |||
3106 | ReturnInst *Ret = dyn_cast_or_null<ReturnInst>(Next); | |||
3107 | Assert(Ret, "musttail call must precede a ret with an optional bitcast",do { if (!(Ret)) { CheckFailed("musttail call must precede a ret with an optional bitcast" , &CI); return; } } while (false) | |||
3108 | &CI)do { if (!(Ret)) { CheckFailed("musttail call must precede a ret with an optional bitcast" , &CI); return; } } while (false); | |||
3109 | Assert(!Ret->getReturnValue() || Ret->getReturnValue() == RetVal,do { if (!(!Ret->getReturnValue() || Ret->getReturnValue () == RetVal)) { CheckFailed("musttail call result must be returned" , Ret); return; } } while (false) | |||
3110 | "musttail call result must be returned", Ret)do { if (!(!Ret->getReturnValue() || Ret->getReturnValue () == RetVal)) { CheckFailed("musttail call result must be returned" , Ret); return; } } while (false); | |||
3111 | } | |||
3112 | ||||
3113 | void Verifier::visitCallInst(CallInst &CI) { | |||
3114 | visitCallBase(CI); | |||
3115 | ||||
3116 | if (CI.isMustTailCall()) | |||
3117 | verifyMustTailCall(CI); | |||
3118 | } | |||
3119 | ||||
3120 | void Verifier::visitInvokeInst(InvokeInst &II) { | |||
3121 | visitCallBase(II); | |||
3122 | ||||
3123 | // Verify that the first non-PHI instruction of the unwind destination is an | |||
3124 | // exception handling instruction. | |||
3125 | Assert(do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!" , &II); return; } } while (false) | |||
3126 | II.getUnwindDest()->isEHPad(),do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!" , &II); return; } } while (false) | |||
3127 | "The unwind destination does not have an exception handling instruction!",do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!" , &II); return; } } while (false) | |||
3128 | &II)do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!" , &II); return; } } while (false); | |||
3129 | ||||
3130 | visitTerminator(II); | |||
3131 | } | |||
3132 | ||||
3133 | /// visitUnaryOperator - Check the argument to the unary operator. | |||
3134 | /// | |||
3135 | void Verifier::visitUnaryOperator(UnaryOperator &U) { | |||
3136 | Assert(U.getType() == U.getOperand(0)->getType(),do { if (!(U.getType() == U.getOperand(0)->getType())) { CheckFailed ("Unary operators must have same type for" "operands and result!" , &U); return; } } while (false) | |||
3137 | "Unary operators must have same type for"do { if (!(U.getType() == U.getOperand(0)->getType())) { CheckFailed ("Unary operators must have same type for" "operands and result!" , &U); return; } } while (false) | |||
3138 | "operands and result!",do { if (!(U.getType() == U.getOperand(0)->getType())) { CheckFailed ("Unary operators must have same type for" "operands and result!" , &U); return; } } while (false) | |||
3139 | &U)do { if (!(U.getType() == U.getOperand(0)->getType())) { CheckFailed ("Unary operators must have same type for" "operands and result!" , &U); return; } } while (false); | |||
3140 | ||||
3141 | switch (U.getOpcode()) { | |||
3142 | // Check that floating-point arithmetic operators are only used with | |||
3143 | // floating-point operands. | |||
3144 | case Instruction::FNeg: | |||
3145 | Assert(U.getType()->isFPOrFPVectorTy(),do { if (!(U.getType()->isFPOrFPVectorTy())) { CheckFailed ("FNeg operator only works with float types!", &U); return ; } } while (false) | |||
3146 | "FNeg operator only works with float types!", &U)do { if (!(U.getType()->isFPOrFPVectorTy())) { CheckFailed ("FNeg operator only works with float types!", &U); return ; } } while (false); | |||
3147 | break; | |||
3148 | case Instruction::Freeze: | |||
3149 | // Freeze can take all kinds of types. | |||
3150 | break; | |||
3151 | default: | |||
3152 | llvm_unreachable("Unknown UnaryOperator opcode!")::llvm::llvm_unreachable_internal("Unknown UnaryOperator opcode!" , "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/IR/Verifier.cpp" , 3152); | |||
3153 | } | |||
3154 | ||||
3155 | visitInstruction(U); | |||
3156 | } | |||
3157 | ||||
3158 | /// visitBinaryOperator - Check that both arguments to the binary operator are | |||
3159 | /// of the same type! | |||
3160 | /// | |||
3161 | void Verifier::visitBinaryOperator(BinaryOperator &B) { | |||
3162 | Assert(B.getOperand(0)->getType() == B.getOperand(1)->getType(),do { if (!(B.getOperand(0)->getType() == B.getOperand(1)-> getType())) { CheckFailed("Both operands to a binary operator are not of the same type!" , &B); return; } } while (false) | |||
3163 | "Both operands to a binary operator are not of the same type!", &B)do { if (!(B.getOperand(0)->getType() == B.getOperand(1)-> getType())) { CheckFailed("Both operands to a binary operator are not of the same type!" , &B); return; } } while (false); | |||
3164 | ||||
3165 | switch (B.getOpcode()) { | |||
3166 | // Check that integer arithmetic operators are only used with | |||
3167 | // integral operands. | |||
3168 | case Instruction::Add: | |||
3169 | case Instruction::Sub: | |||
3170 | case Instruction::Mul: | |||
3171 | case Instruction::SDiv: | |||
3172 | case Instruction::UDiv: | |||
3173 | case Instruction::SRem: | |||
3174 | case Instruction::URem: | |||
3175 | Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Integer arithmetic operators only work with integral types!" , &B); return; } } while (false) | |||
3176 | "Integer arithmetic operators only work with integral types!", &B)do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Integer arithmetic operators only work with integral types!" , &B); return; } } while (false); | |||
3177 | Assert(B.getType() == B.getOperand(0)->getType(),do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Integer arithmetic operators must have same type " "for operands and result!" , &B); return; } } while (false) | |||
3178 | "Integer arithmetic operators must have same type "do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Integer arithmetic operators must have same type " "for operands and result!" , &B); return; } } while (false) | |||
3179 | "for operands and result!",do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Integer arithmetic operators must have same type " "for operands and result!" , &B); return; } } while (false) | |||
3180 | &B)do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Integer arithmetic operators must have same type " "for operands and result!" , &B); return; } } while (false); | |||
3181 | break; | |||
3182 | // Check that floating-point arithmetic operators are only used with | |||
3183 | // floating-point operands. | |||
3184 | case Instruction::FAdd: | |||
3185 | case Instruction::FSub: | |||
3186 | case Instruction::FMul: | |||
3187 | case Instruction::FDiv: | |||
3188 | case Instruction::FRem: | |||
3189 | Assert(B.getType()->isFPOrFPVectorTy(),do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed ("Floating-point arithmetic operators only work with " "floating-point types!" , &B); return; } } while (false) | |||
3190 | "Floating-point arithmetic operators only work with "do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed ("Floating-point arithmetic operators only work with " "floating-point types!" , &B); return; } } while (false) | |||
3191 | "floating-point types!",do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed ("Floating-point arithmetic operators only work with " "floating-point types!" , &B); return; } } while (false) | |||
3192 | &B)do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed ("Floating-point arithmetic operators only work with " "floating-point types!" , &B); return; } } while (false); | |||
3193 | Assert(B.getType() == B.getOperand(0)->getType(),do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Floating-point arithmetic operators must have same type " "for operands and result!" , &B); return; } } while (false) | |||
3194 | "Floating-point arithmetic operators must have same type "do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Floating-point arithmetic operators must have same type " "for operands and result!" , &B); return; } } while (false) | |||
3195 | "for operands and result!",do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Floating-point arithmetic operators must have same type " "for operands and result!" , &B); return; } } while (false) | |||
3196 | &B)do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Floating-point arithmetic operators must have same type " "for operands and result!" , &B); return; } } while (false); | |||
3197 | break; | |||
3198 | // Check that logical operators are only used with integral operands. | |||
3199 | case Instruction::And: | |||
3200 | case Instruction::Or: | |||
3201 | case Instruction::Xor: | |||
3202 | Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Logical operators only work with integral types!", &B); return; } } while (false) | |||
3203 | "Logical operators only work with integral types!", &B)do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Logical operators only work with integral types!", &B); return; } } while (false); | |||
3204 | Assert(B.getType() == B.getOperand(0)->getType(),do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Logical operators must have same type for operands and result!" , &B); return; } } while (false) | |||
3205 | "Logical operators must have same type for operands and result!",do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Logical operators must have same type for operands and result!" , &B); return; } } while (false) | |||
3206 | &B)do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Logical operators must have same type for operands and result!" , &B); return; } } while (false); | |||
3207 | break; | |||
3208 | case Instruction::Shl: | |||
3209 | case Instruction::LShr: | |||
3210 | case Instruction::AShr: | |||
3211 | Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Shifts only work with integral types!", &B); return; } } while (false) | |||
3212 | "Shifts only work with integral types!", &B)do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Shifts only work with integral types!", &B); return; } } while (false); | |||
3213 | Assert(B.getType() == B.getOperand(0)->getType(),do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Shift return type must be same as operands!", &B); return ; } } while (false) | |||
3214 | "Shift return type must be same as operands!", &B)do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Shift return type must be same as operands!", &B); return ; } } while (false); | |||
3215 | break; | |||
3216 | default: | |||
3217 | llvm_unreachable("Unknown BinaryOperator opcode!")::llvm::llvm_unreachable_internal("Unknown BinaryOperator opcode!" , "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/IR/Verifier.cpp" , 3217); | |||
3218 | } | |||
3219 | ||||
3220 | visitInstruction(B); | |||
3221 | } | |||
3222 | ||||
3223 | void Verifier::visitICmpInst(ICmpInst &IC) { | |||
3224 | // Check that the operands are the same type | |||
3225 | Type *Op0Ty = IC.getOperand(0)->getType(); | |||
3226 | Type *Op1Ty = IC.getOperand(1)->getType(); | |||
3227 | Assert(Op0Ty == Op1Ty,do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to ICmp instruction are not of the same type!" , &IC); return; } } while (false) | |||
3228 | "Both operands to ICmp instruction are not of the same type!", &IC)do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to ICmp instruction are not of the same type!" , &IC); return; } } while (false); | |||
3229 | // Check that the operands are the right type | |||
3230 | Assert(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy(),do { if (!(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy ())) { CheckFailed("Invalid operand types for ICmp instruction" , &IC); return; } } while (false) | |||
3231 | "Invalid operand types for ICmp instruction", &IC)do { if (!(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy ())) { CheckFailed("Invalid operand types for ICmp instruction" , &IC); return; } } while (false); | |||
3232 | // Check that the predicate is valid. | |||
3233 | Assert(IC.isIntPredicate(),do { if (!(IC.isIntPredicate())) { CheckFailed("Invalid predicate in ICmp instruction!" , &IC); return; } } while (false) | |||
3234 | "Invalid predicate in ICmp instruction!", &IC)do { if (!(IC.isIntPredicate())) { CheckFailed("Invalid predicate in ICmp instruction!" , &IC); return; } } while (false); | |||
3235 | ||||
3236 | visitInstruction(IC); | |||
3237 | } | |||
3238 | ||||
3239 | void Verifier::visitFCmpInst(FCmpInst &FC) { | |||
3240 | // Check that the operands are the same type | |||
3241 | Type *Op0Ty = FC.getOperand(0)->getType(); | |||
3242 | Type *Op1Ty = FC.getOperand(1)->getType(); | |||
3243 | Assert(Op0Ty == Op1Ty,do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to FCmp instruction are not of the same type!" , &FC); return; } } while (false) | |||
3244 | "Both operands to FCmp instruction are not of the same type!", &FC)do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to FCmp instruction are not of the same type!" , &FC); return; } } while (false); | |||
3245 | // Check that the operands are the right type | |||
3246 | Assert(Op0Ty->isFPOrFPVectorTy(),do { if (!(Op0Ty->isFPOrFPVectorTy())) { CheckFailed("Invalid operand types for FCmp instruction" , &FC); return; } } while (false) | |||
3247 | "Invalid operand types for FCmp instruction", &FC)do { if (!(Op0Ty->isFPOrFPVectorTy())) { CheckFailed("Invalid operand types for FCmp instruction" , &FC); return; } } while (false); | |||
3248 | // Check that the predicate is valid. | |||
3249 | Assert(FC.isFPPredicate(),do { if (!(FC.isFPPredicate())) { CheckFailed("Invalid predicate in FCmp instruction!" , &FC); return; } } while (false) | |||
3250 | "Invalid predicate in FCmp instruction!", &FC)do { if (!(FC.isFPPredicate())) { CheckFailed("Invalid predicate in FCmp instruction!" , &FC); return; } } while (false); | |||
3251 | ||||
3252 | visitInstruction(FC); | |||
3253 | } | |||
3254 | ||||
3255 | void Verifier::visitExtractElementInst(ExtractElementInst &EI) { | |||
3256 | Assert(do { if (!(ExtractElementInst::isValidOperands(EI.getOperand( 0), EI.getOperand(1)))) { CheckFailed("Invalid extractelement operands!" , &EI); return; } } while (false) | |||
3257 | ExtractElementInst::isValidOperands(EI.getOperand(0), EI.getOperand(1)),do { if (!(ExtractElementInst::isValidOperands(EI.getOperand( 0), EI.getOperand(1)))) { CheckFailed("Invalid extractelement operands!" , &EI); return; } } while (false) | |||
3258 | "Invalid extractelement operands!", &EI)do { if (!(ExtractElementInst::isValidOperands(EI.getOperand( 0), EI.getOperand(1)))) { CheckFailed("Invalid extractelement operands!" , &EI); return; } } while (false); | |||
3259 | visitInstruction(EI); | |||
3260 | } | |||
3261 | ||||
3262 | void Verifier::visitInsertElementInst(InsertElementInst &IE) { | |||
3263 | Assert(InsertElementInst::isValidOperands(IE.getOperand(0), IE.getOperand(1),do { if (!(InsertElementInst::isValidOperands(IE.getOperand(0 ), IE.getOperand(1), IE.getOperand(2)))) { CheckFailed("Invalid insertelement operands!" , &IE); return; } } while (false) | |||
3264 | IE.getOperand(2)),do { if (!(InsertElementInst::isValidOperands(IE.getOperand(0 ), IE.getOperand(1), IE.getOperand(2)))) { CheckFailed("Invalid insertelement operands!" , &IE); return; } } while (false) | |||
3265 | "Invalid insertelement operands!", &IE)do { if (!(InsertElementInst::isValidOperands(IE.getOperand(0 ), IE.getOperand(1), IE.getOperand(2)))) { CheckFailed("Invalid insertelement operands!" , &IE); return; } } while (false); | |||
3266 | visitInstruction(IE); | |||
3267 | } | |||
3268 | ||||
3269 | void Verifier::visitShuffleVectorInst(ShuffleVectorInst &SV) { | |||
3270 | Assert(ShuffleVectorInst::isValidOperands(SV.getOperand(0), SV.getOperand(1),do { if (!(ShuffleVectorInst::isValidOperands(SV.getOperand(0 ), SV.getOperand(1), SV.getOperand(2)))) { CheckFailed("Invalid shufflevector operands!" , &SV); return; } } while (false) | |||
3271 | SV.getOperand(2)),do { if (!(ShuffleVectorInst::isValidOperands(SV.getOperand(0 ), SV.getOperand(1), SV.getOperand(2)))) { CheckFailed("Invalid shufflevector operands!" , &SV); return; } } while (false) | |||
3272 | "Invalid shufflevector operands!", &SV)do { if (!(ShuffleVectorInst::isValidOperands(SV.getOperand(0 ), SV.getOperand(1), SV.getOperand(2)))) { CheckFailed("Invalid shufflevector operands!" , &SV); return; } } while (false); | |||
3273 | visitInstruction(SV); | |||
3274 | } | |||
3275 | ||||
3276 | void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) { | |||
3277 | Type *TargetTy = GEP.getPointerOperandType()->getScalarType(); | |||
3278 | ||||
3279 | Assert(isa<PointerType>(TargetTy),do { if (!(isa<PointerType>(TargetTy))) { CheckFailed("GEP base pointer is not a vector or a vector of pointers" , &GEP); return; } } while (false) | |||
3280 | "GEP base pointer is not a vector or a vector of pointers", &GEP)do { if (!(isa<PointerType>(TargetTy))) { CheckFailed("GEP base pointer is not a vector or a vector of pointers" , &GEP); return; } } while (false); | |||
3281 | Assert(GEP.getSourceElementType()->isSized(), "GEP into unsized type!", &GEP)do { if (!(GEP.getSourceElementType()->isSized())) { CheckFailed ("GEP into unsized type!", &GEP); return; } } while (false ); | |||
3282 | ||||
3283 | SmallVector<Value*, 16> Idxs(GEP.idx_begin(), GEP.idx_end()); | |||
3284 | Assert(all_of(do { if (!(all_of( Idxs, [](Value* V) { return V->getType( )->isIntOrIntVectorTy(); }))) { CheckFailed("GEP indexes must be integers" , &GEP); return; } } while (false) | |||
3285 | Idxs, [](Value* V) { return V->getType()->isIntOrIntVectorTy(); }),do { if (!(all_of( Idxs, [](Value* V) { return V->getType( )->isIntOrIntVectorTy(); }))) { CheckFailed("GEP indexes must be integers" , &GEP); return; } } while (false) | |||
3286 | "GEP indexes must be integers", &GEP)do { if (!(all_of( Idxs, [](Value* V) { return V->getType( )->isIntOrIntVectorTy(); }))) { CheckFailed("GEP indexes must be integers" , &GEP); return; } } while (false); | |||
3287 | Type *ElTy = | |||
3288 | GetElementPtrInst::getIndexedType(GEP.getSourceElementType(), Idxs); | |||
3289 | Assert(ElTy, "Invalid indices for GEP pointer type!", &GEP)do { if (!(ElTy)) { CheckFailed("Invalid indices for GEP pointer type!" , &GEP); return; } } while (false); | |||
3290 | ||||
3291 | Assert(GEP.getType()->isPtrOrPtrVectorTy() &&do { if (!(GEP.getType()->isPtrOrPtrVectorTy() && GEP .getResultElementType() == ElTy)) { CheckFailed("GEP is not of right type for indices!" , &GEP, ElTy); return; } } while (false) | |||
3292 | GEP.getResultElementType() == ElTy,do { if (!(GEP.getType()->isPtrOrPtrVectorTy() && GEP .getResultElementType() == ElTy)) { CheckFailed("GEP is not of right type for indices!" , &GEP, ElTy); return; } } while (false) | |||
3293 | "GEP is not of right type for indices!", &GEP, ElTy)do { if (!(GEP.getType()->isPtrOrPtrVectorTy() && GEP .getResultElementType() == ElTy)) { CheckFailed("GEP is not of right type for indices!" , &GEP, ElTy); return; } } while (false); | |||
3294 | ||||
3295 | if (GEP.getType()->isVectorTy()) { | |||
3296 | // Additional checks for vector GEPs. | |||
3297 | unsigned GEPWidth = GEP.getType()->getVectorNumElements(); | |||
3298 | if (GEP.getPointerOperandType()->isVectorTy()) | |||
3299 | Assert(GEPWidth == GEP.getPointerOperandType()->getVectorNumElements(),do { if (!(GEPWidth == GEP.getPointerOperandType()->getVectorNumElements ())) { CheckFailed("Vector GEP result width doesn't match operand's" , &GEP); return; } } while (false) | |||
3300 | "Vector GEP result width doesn't match operand's", &GEP)do { if (!(GEPWidth == GEP.getPointerOperandType()->getVectorNumElements ())) { CheckFailed("Vector GEP result width doesn't match operand's" , &GEP); return; } } while (false); | |||
3301 | for (Value *Idx : Idxs) { | |||
3302 | Type *IndexTy = Idx->getType(); | |||
3303 | if (IndexTy->isVectorTy()) { | |||
3304 | unsigned IndexWidth = IndexTy->getVectorNumElements(); | |||
3305 | Assert(IndexWidth == GEPWidth, "Invalid GEP index vector width", &GEP)do { if (!(IndexWidth == GEPWidth)) { CheckFailed("Invalid GEP index vector width" , &GEP); return; } } while (false); | |||
3306 | } | |||
3307 | Assert(IndexTy->isIntOrIntVectorTy(),do { if (!(IndexTy->isIntOrIntVectorTy())) { CheckFailed("All GEP indices should be of integer type" ); return; } } while (false) | |||
3308 | "All GEP indices should be of integer type")do { if (!(IndexTy->isIntOrIntVectorTy())) { CheckFailed("All GEP indices should be of integer type" ); return; } } while (false); | |||
3309 | } | |||
3310 | } | |||
3311 | ||||
3312 | if (auto *PTy = dyn_cast<PointerType>(GEP.getType())) { | |||
3313 | Assert(GEP.getAddressSpace() == PTy->getAddressSpace(),do { if (!(GEP.getAddressSpace() == PTy->getAddressSpace() )) { CheckFailed("GEP address space doesn't match type", & GEP); return; } } while (false) | |||
3314 | "GEP address space doesn't match type", &GEP)do { if (!(GEP.getAddressSpace() == PTy->getAddressSpace() )) { CheckFailed("GEP address space doesn't match type", & GEP); return; } } while (false); | |||
3315 | } | |||
3316 | ||||
3317 | visitInstruction(GEP); | |||
3318 | } | |||
3319 | ||||
3320 | static bool isContiguous(const ConstantRange &A, const ConstantRange &B) { | |||
3321 | return A.getUpper() == B.getLower() || A.getLower() == B.getUpper(); | |||
3322 | } | |||
3323 | ||||
3324 | void Verifier::visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty) { | |||
3325 | assert(Range && Range == I.getMetadata(LLVMContext::MD_range) &&((Range && Range == I.getMetadata(LLVMContext::MD_range ) && "precondition violation") ? static_cast<void> (0) : __assert_fail ("Range && Range == I.getMetadata(LLVMContext::MD_range) && \"precondition violation\"" , "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/IR/Verifier.cpp" , 3326, __PRETTY_FUNCTION__)) | |||
3326 | "precondition violation")((Range && Range == I.getMetadata(LLVMContext::MD_range ) && "precondition violation") ? static_cast<void> (0) : __assert_fail ("Range && Range == I.getMetadata(LLVMContext::MD_range) && \"precondition violation\"" , "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/IR/Verifier.cpp" , 3326, __PRETTY_FUNCTION__)); | |||
3327 | ||||
3328 | unsigned NumOperands = Range->getNumOperands(); | |||
3329 | Assert(NumOperands % 2 == 0, "Unfinished range!", Range)do { if (!(NumOperands % 2 == 0)) { CheckFailed("Unfinished range!" , Range); return; } } while (false); | |||
3330 | unsigned NumRanges = NumOperands / 2; | |||
3331 | Assert(NumRanges >= 1, "It should have at least one range!", Range)do { if (!(NumRanges >= 1)) { CheckFailed("It should have at least one range!" , Range); return; } } while (false); | |||
3332 | ||||
3333 | ConstantRange LastRange(1, true); // Dummy initial value | |||
3334 | for (unsigned i = 0; i < NumRanges; ++i) { | |||
3335 | ConstantInt *Low = | |||
3336 | mdconst::dyn_extract<ConstantInt>(Range->getOperand(2 * i)); | |||
3337 | Assert(Low, "The lower limit must be an integer!", Low)do { if (!(Low)) { CheckFailed("The lower limit must be an integer!" , Low); return; } } while (false); | |||
3338 | ConstantInt *High = | |||
3339 | mdconst::dyn_extract<ConstantInt>(Range->getOperand(2 * i + 1)); | |||
3340 | Assert(High, "The upper limit must be an integer!", High)do { if (!(High)) { CheckFailed("The upper limit must be an integer!" , High); return; } } while (false); | |||
3341 | Assert(High->getType() == Low->getType() && High->getType() == Ty,do { if (!(High->getType() == Low->getType() && High->getType() == Ty)) { CheckFailed("Range types must match instruction type!" , &I); return; } } while (false) | |||
3342 | "Range types must match instruction type!", &I)do { if (!(High->getType() == Low->getType() && High->getType() == Ty)) { CheckFailed("Range types must match instruction type!" , &I); return; } } while (false); | |||
3343 | ||||
3344 | APInt HighV = High->getValue(); | |||
3345 | APInt LowV = Low->getValue(); | |||
3346 | ConstantRange CurRange(LowV, HighV); | |||
3347 | Assert(!CurRange.isEmptySet() && !CurRange.isFullSet(),do { if (!(!CurRange.isEmptySet() && !CurRange.isFullSet ())) { CheckFailed("Range must not be empty!", Range); return ; } } while (false) | |||
3348 | "Range must not be empty!", Range)do { if (!(!CurRange.isEmptySet() && !CurRange.isFullSet ())) { CheckFailed("Range must not be empty!", Range); return ; } } while (false); | |||
3349 | if (i != 0) { | |||
3350 | Assert(CurRange.intersectWith(LastRange).isEmptySet(),do { if (!(CurRange.intersectWith(LastRange).isEmptySet())) { CheckFailed("Intervals are overlapping", Range); return; } } while (false) | |||
3351 | "Intervals are overlapping", Range)do { if (!(CurRange.intersectWith(LastRange).isEmptySet())) { CheckFailed("Intervals are overlapping", Range); return; } } while (false); | |||
3352 | Assert(LowV.sgt(LastRange.getLower()), "Intervals are not in order",do { if (!(LowV.sgt(LastRange.getLower()))) { CheckFailed("Intervals are not in order" , Range); return; } } while (false) | |||
3353 | Range)do { if (!(LowV.sgt(LastRange.getLower()))) { CheckFailed("Intervals are not in order" , Range); return; } } while (false); | |||
3354 | Assert(!isContiguous(CurRange, LastRange), "Intervals are contiguous",do { if (!(!isContiguous(CurRange, LastRange))) { CheckFailed ("Intervals are contiguous", Range); return; } } while (false ) | |||
3355 | Range)do { if (!(!isContiguous(CurRange, LastRange))) { CheckFailed ("Intervals are contiguous", Range); return; } } while (false ); | |||
3356 | } | |||
3357 | LastRange = ConstantRange(LowV, HighV); | |||
3358 | } | |||
3359 | if (NumRanges > 2) { | |||
3360 | APInt FirstLow = | |||
3361 | mdconst::dyn_extract<ConstantInt>(Range->getOperand(0))->getValue(); | |||
3362 | APInt FirstHigh = | |||
3363 | mdconst::dyn_extract<ConstantInt>(Range->getOperand(1))->getValue(); | |||
3364 | ConstantRange FirstRange(FirstLow, FirstHigh); | |||
3365 | Assert(FirstRange.intersectWith(LastRange).isEmptySet(),do { if (!(FirstRange.intersectWith(LastRange).isEmptySet())) { CheckFailed("Intervals are overlapping", Range); return; } } while (false) | |||
3366 | "Intervals are overlapping", Range)do { if (!(FirstRange.intersectWith(LastRange).isEmptySet())) { CheckFailed("Intervals are overlapping", Range); return; } } while (false); | |||
3367 | Assert(!isContiguous(FirstRange, LastRange), "Intervals are contiguous",do { if (!(!isContiguous(FirstRange, LastRange))) { CheckFailed ("Intervals are contiguous", Range); return; } } while (false ) | |||
3368 | Range)do { if (!(!isContiguous(FirstRange, LastRange))) { CheckFailed ("Intervals are contiguous", Range); return; } } while (false ); | |||
3369 | } | |||
3370 | } | |||
3371 | ||||
3372 | void Verifier::checkAtomicMemAccessSize(Type *Ty, const Instruction *I) { | |||
3373 | unsigned Size = DL.getTypeSizeInBits(Ty); | |||
3374 | Assert(Size >= 8, "atomic memory access' size must be byte-sized", Ty, I)do { if (!(Size >= 8)) { CheckFailed("atomic memory access' size must be byte-sized" , Ty, I); return; } } while (false); | |||
3375 | Assert(!(Size & (Size - 1)),do { if (!(!(Size & (Size - 1)))) { CheckFailed("atomic memory access' operand must have a power-of-two size" , Ty, I); return; } } while (false) | |||
3376 | "atomic memory access' operand must have a power-of-two size", Ty, I)do { if (!(!(Size & (Size - 1)))) { CheckFailed("atomic memory access' operand must have a power-of-two size" , Ty, I); return; } } while (false); | |||
3377 | } | |||
3378 | ||||
3379 | void Verifier::visitLoadInst(LoadInst &LI) { | |||
3380 | PointerType *PTy = dyn_cast<PointerType>(LI.getOperand(0)->getType()); | |||
3381 | Assert(PTy, "Load operand must be a pointer.", &LI)do { if (!(PTy)) { CheckFailed("Load operand must be a pointer." , &LI); return; } } while (false); | |||
3382 | Type *ElTy = LI.getType(); | |||
3383 | Assert(LI.getAlignment() <= Value::MaximumAlignment,do { if (!(LI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &LI ); return; } } while (false) | |||
3384 | "huge alignment values are unsupported", &LI)do { if (!(LI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &LI ); return; } } while (false); | |||
3385 | Assert(ElTy->isSized(), "loading unsized types is not allowed", &LI)do { if (!(ElTy->isSized())) { CheckFailed("loading unsized types is not allowed" , &LI); return; } } while (false); | |||
3386 | if (LI.isAtomic()) { | |||
3387 | Assert(LI.getOrdering() != AtomicOrdering::Release &&do { if (!(LI.getOrdering() != AtomicOrdering::Release && LI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed ("Load cannot have Release ordering", &LI); return; } } while (false) | |||
3388 | LI.getOrdering() != AtomicOrdering::AcquireRelease,do { if (!(LI.getOrdering() != AtomicOrdering::Release && LI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed ("Load cannot have Release ordering", &LI); return; } } while (false) | |||
3389 | "Load cannot have Release ordering", &LI)do { if (!(LI.getOrdering() != AtomicOrdering::Release && LI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed ("Load cannot have Release ordering", &LI); return; } } while (false); | |||
3390 | Assert(LI.getAlignment() != 0,do { if (!(LI.getAlignment() != 0)) { CheckFailed("Atomic load must specify explicit alignment" , &LI); return; } } while (false) | |||
3391 | "Atomic load must specify explicit alignment", &LI)do { if (!(LI.getAlignment() != 0)) { CheckFailed("Atomic load must specify explicit alignment" , &LI); return; } } while (false); | |||
3392 | Assert(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy(),do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomic load operand must have integer, pointer, or floating point " "type!", ElTy, &LI); return; } } while (false) | |||
3393 | "atomic load operand must have integer, pointer, or floating point "do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomic load operand must have integer, pointer, or floating point " "type!", ElTy, &LI); return; } } while (false) | |||
3394 | "type!",do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomic load operand must have integer, pointer, or floating point " "type!", ElTy, &LI); return; } } while (false) | |||
3395 | ElTy, &LI)do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomic load operand must have integer, pointer, or floating point " "type!", ElTy, &LI); return; } } while (false); | |||
3396 | checkAtomicMemAccessSize(ElTy, &LI); | |||
3397 | } else { | |||
3398 | Assert(LI.getSyncScopeID() == SyncScope::System,do { if (!(LI.getSyncScopeID() == SyncScope::System)) { CheckFailed ("Non-atomic load cannot have SynchronizationScope specified" , &LI); return; } } while (false) | |||
3399 | "Non-atomic load cannot have SynchronizationScope specified", &LI)do { if (!(LI.getSyncScopeID() == SyncScope::System)) { CheckFailed ("Non-atomic load cannot have SynchronizationScope specified" , &LI); return; } } while (false); | |||
3400 | } | |||
3401 | ||||
3402 | visitInstruction(LI); | |||
3403 | } | |||
3404 | ||||
3405 | void Verifier::visitStoreInst(StoreInst &SI) { | |||
3406 | PointerType *PTy = dyn_cast<PointerType>(SI.getOperand(1)->getType()); | |||
3407 | Assert(PTy, "Store operand must be a pointer.", &SI)do { if (!(PTy)) { CheckFailed("Store operand must be a pointer." , &SI); return; } } while (false); | |||
3408 | Type *ElTy = PTy->getElementType(); | |||
3409 | Assert(ElTy == SI.getOperand(0)->getType(),do { if (!(ElTy == SI.getOperand(0)->getType())) { CheckFailed ("Stored value type does not match pointer operand type!", & SI, ElTy); return; } } while (false) | |||
3410 | "Stored value type does not match pointer operand type!", &SI, ElTy)do { if (!(ElTy == SI.getOperand(0)->getType())) { CheckFailed ("Stored value type does not match pointer operand type!", & SI, ElTy); return; } } while (false); | |||
3411 | Assert(SI.getAlignment() <= Value::MaximumAlignment,do { if (!(SI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &SI ); return; } } while (false) | |||
3412 | "huge alignment values are unsupported", &SI)do { if (!(SI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &SI ); return; } } while (false); | |||
3413 | Assert(ElTy->isSized(), "storing unsized types is not allowed", &SI)do { if (!(ElTy->isSized())) { CheckFailed("storing unsized types is not allowed" , &SI); return; } } while (false); | |||
3414 | if (SI.isAtomic()) { | |||
3415 | Assert(SI.getOrdering() != AtomicOrdering::Acquire &&do { if (!(SI.getOrdering() != AtomicOrdering::Acquire && SI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed ("Store cannot have Acquire ordering", &SI); return; } } while (false) | |||
3416 | SI.getOrdering() != AtomicOrdering::AcquireRelease,do { if (!(SI.getOrdering() != AtomicOrdering::Acquire && SI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed ("Store cannot have Acquire ordering", &SI); return; } } while (false) | |||
3417 | "Store cannot have Acquire ordering", &SI)do { if (!(SI.getOrdering() != AtomicOrdering::Acquire && SI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed ("Store cannot have Acquire ordering", &SI); return; } } while (false); | |||
3418 | Assert(SI.getAlignment() != 0,do { if (!(SI.getAlignment() != 0)) { CheckFailed("Atomic store must specify explicit alignment" , &SI); return; } } while (false) | |||
3419 | "Atomic store must specify explicit alignment", &SI)do { if (!(SI.getAlignment() != 0)) { CheckFailed("Atomic store must specify explicit alignment" , &SI); return; } } while (false); | |||
3420 | Assert(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy(),do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomic store operand must have integer, pointer, or floating point " "type!", ElTy, &SI); return; } } while (false) | |||
3421 | "atomic store operand must have integer, pointer, or floating point "do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomic store operand must have integer, pointer, or floating point " "type!", ElTy, &SI); return; } } while (false) | |||
3422 | "type!",do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomic store operand must have integer, pointer, or floating point " "type!", ElTy, &SI); return; } } while (false) | |||
3423 | ElTy, &SI)do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomic store operand must have integer, pointer, or floating point " "type!", ElTy, &SI); return; } } while (false); | |||
3424 | checkAtomicMemAccessSize(ElTy, &SI); | |||
3425 | } else { | |||
3426 | Assert(SI.getSyncScopeID() == SyncScope::System,do { if (!(SI.getSyncScopeID() == SyncScope::System)) { CheckFailed ("Non-atomic store cannot have SynchronizationScope specified" , &SI); return; } } while (false) | |||
3427 | "Non-atomic store cannot have SynchronizationScope specified", &SI)do { if (!(SI.getSyncScopeID() == SyncScope::System)) { CheckFailed ("Non-atomic store cannot have SynchronizationScope specified" , &SI); return; } } while (false); | |||
3428 | } | |||
3429 | visitInstruction(SI); | |||
3430 | } | |||
3431 | ||||
3432 | /// Check that SwiftErrorVal is used as a swifterror argument in CS. | |||
3433 | void Verifier::verifySwiftErrorCall(CallBase &Call, | |||
3434 | const Value *SwiftErrorVal) { | |||
3435 | unsigned Idx = 0; | |||
3436 | for (auto I = Call.arg_begin(), E = Call.arg_end(); I != E; ++I, ++Idx) { | |||
3437 | if (*I == SwiftErrorVal) { | |||
3438 | Assert(Call.paramHasAttr(Idx, Attribute::SwiftError),do { if (!(Call.paramHasAttr(Idx, Attribute::SwiftError))) { CheckFailed ("swifterror value when used in a callsite should be marked " "with swifterror attribute", SwiftErrorVal, Call); return; } } while (false) | |||
3439 | "swifterror value when used in a callsite should be marked "do { if (!(Call.paramHasAttr(Idx, Attribute::SwiftError))) { CheckFailed ("swifterror value when used in a callsite should be marked " "with swifterror attribute", SwiftErrorVal, Call); return; } } while (false) | |||
3440 | "with swifterror attribute",do { if (!(Call.paramHasAttr(Idx, Attribute::SwiftError))) { CheckFailed ("swifterror value when used in a callsite should be marked " "with swifterror attribute", SwiftErrorVal, Call); return; } } while (false) | |||
3441 | SwiftErrorVal, Call)do { if (!(Call.paramHasAttr(Idx, Attribute::SwiftError))) { CheckFailed ("swifterror value when used in a callsite should be marked " "with swifterror attribute", SwiftErrorVal, Call); return; } } while (false); | |||
3442 | } | |||
3443 | } | |||
3444 | } | |||
3445 | ||||
3446 | void Verifier::verifySwiftErrorValue(const Value *SwiftErrorVal) { | |||
3447 | // Check that swifterror value is only used by loads, stores, or as | |||
3448 | // a swifterror argument. | |||
3449 | for (const User *U : SwiftErrorVal->users()) { | |||
3450 | Assert(isa<LoadInst>(U) || isa<StoreInst>(U) || isa<CallInst>(U) ||do { if (!(isa<LoadInst>(U) || isa<StoreInst>(U) || isa<CallInst>(U) || isa<InvokeInst>(U))) { CheckFailed ("swifterror value can only be loaded and stored from, or " "as a swifterror argument!" , SwiftErrorVal, U); return; } } while (false) | |||
3451 | isa<InvokeInst>(U),do { if (!(isa<LoadInst>(U) || isa<StoreInst>(U) || isa<CallInst>(U) || isa<InvokeInst>(U))) { CheckFailed ("swifterror value can only be loaded and stored from, or " "as a swifterror argument!" , SwiftErrorVal, U); return; } } while (false) | |||
3452 | "swifterror value can only be loaded and stored from, or "do { if (!(isa<LoadInst>(U) || isa<StoreInst>(U) || isa<CallInst>(U) || isa<InvokeInst>(U))) { CheckFailed ("swifterror value can only be loaded and stored from, or " "as a swifterror argument!" , SwiftErrorVal, U); return; } } while (false) | |||
3453 | "as a swifterror argument!",do { if (!(isa<LoadInst>(U) || isa<StoreInst>(U) || isa<CallInst>(U) || isa<InvokeInst>(U))) { CheckFailed ("swifterror value can only be loaded and stored from, or " "as a swifterror argument!" , SwiftErrorVal, U); return; } } while (false) | |||
3454 | SwiftErrorVal, U)do { if (!(isa<LoadInst>(U) || isa<StoreInst>(U) || isa<CallInst>(U) || isa<InvokeInst>(U))) { CheckFailed ("swifterror value can only be loaded and stored from, or " "as a swifterror argument!" , SwiftErrorVal, U); return; } } while (false); | |||
3455 | // If it is used by a store, check it is the second operand. | |||
3456 | if (auto StoreI = dyn_cast<StoreInst>(U)) | |||
3457 | Assert(StoreI->getOperand(1) == SwiftErrorVal,do { if (!(StoreI->getOperand(1) == SwiftErrorVal)) { CheckFailed ("swifterror value should be the second operand when used " "by stores" , SwiftErrorVal, U); return; } } while (false) | |||
3458 | "swifterror value should be the second operand when used "do { if (!(StoreI->getOperand(1) == SwiftErrorVal)) { CheckFailed ("swifterror value should be the second operand when used " "by stores" , SwiftErrorVal, U); return; } } while (false) | |||
3459 | "by stores", SwiftErrorVal, U)do { if (!(StoreI->getOperand(1) == SwiftErrorVal)) { CheckFailed ("swifterror value should be the second operand when used " "by stores" , SwiftErrorVal, U); return; } } while (false); | |||
3460 | if (auto *Call = dyn_cast<CallBase>(U)) | |||
3461 | verifySwiftErrorCall(*const_cast<CallBase *>(Call), SwiftErrorVal); | |||
3462 | } | |||
3463 | } | |||
3464 | ||||
3465 | void Verifier::visitAllocaInst(AllocaInst &AI) { | |||
3466 | SmallPtrSet<Type*, 4> Visited; | |||
3467 | PointerType *PTy = AI.getType(); | |||
3468 | // TODO: Relax this restriction? | |||
3469 | Assert(PTy->getAddressSpace() == DL.getAllocaAddrSpace(),do { if (!(PTy->getAddressSpace() == DL.getAllocaAddrSpace ())) { CheckFailed("Allocation instruction pointer not in the stack address space!" , &AI); return; } } while (false) | |||
3470 | "Allocation instruction pointer not in the stack address space!",do { if (!(PTy->getAddressSpace() == DL.getAllocaAddrSpace ())) { CheckFailed("Allocation instruction pointer not in the stack address space!" , &AI); return; } } while (false) | |||
3471 | &AI)do { if (!(PTy->getAddressSpace() == DL.getAllocaAddrSpace ())) { CheckFailed("Allocation instruction pointer not in the stack address space!" , &AI); return; } } while (false); | |||
3472 | Assert(AI.getAllocatedType()->isSized(&Visited),do { if (!(AI.getAllocatedType()->isSized(&Visited))) { CheckFailed("Cannot allocate unsized type", &AI); return ; } } while (false) | |||
3473 | "Cannot allocate unsized type", &AI)do { if (!(AI.getAllocatedType()->isSized(&Visited))) { CheckFailed("Cannot allocate unsized type", &AI); return ; } } while (false); | |||
3474 | Assert(AI.getArraySize()->getType()->isIntegerTy(),do { if (!(AI.getArraySize()->getType()->isIntegerTy()) ) { CheckFailed("Alloca array size must have integer type", & AI); return; } } while (false) | |||
3475 | "Alloca array size must have integer type", &AI)do { if (!(AI.getArraySize()->getType()->isIntegerTy()) ) { CheckFailed("Alloca array size must have integer type", & AI); return; } } while (false); | |||
3476 | Assert(AI.getAlignment() <= Value::MaximumAlignment,do { if (!(AI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &AI ); return; } } while (false) | |||
3477 | "huge alignment values are unsupported", &AI)do { if (!(AI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &AI ); return; } } while (false); | |||
3478 | ||||
3479 | if (AI.isSwiftError()) { | |||
3480 | verifySwiftErrorValue(&AI); | |||
3481 | } | |||
3482 | ||||
3483 | visitInstruction(AI); | |||
3484 | } | |||
3485 | ||||
3486 | void Verifier::visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI) { | |||
3487 | ||||
3488 | // FIXME: more conditions??? | |||
3489 | Assert(CXI.getSuccessOrdering() != AtomicOrdering::NotAtomic,do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::NotAtomic )) { CheckFailed("cmpxchg instructions must be atomic.", & CXI); return; } } while (false) | |||
3490 | "cmpxchg instructions must be atomic.", &CXI)do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::NotAtomic )) { CheckFailed("cmpxchg instructions must be atomic.", & CXI); return; } } while (false); | |||
3491 | Assert(CXI.getFailureOrdering() != AtomicOrdering::NotAtomic,do { if (!(CXI.getFailureOrdering() != AtomicOrdering::NotAtomic )) { CheckFailed("cmpxchg instructions must be atomic.", & CXI); return; } } while (false) | |||
3492 | "cmpxchg instructions must be atomic.", &CXI)do { if (!(CXI.getFailureOrdering() != AtomicOrdering::NotAtomic )) { CheckFailed("cmpxchg instructions must be atomic.", & CXI); return; } } while (false); | |||
3493 | Assert(CXI.getSuccessOrdering() != AtomicOrdering::Unordered,do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::Unordered )) { CheckFailed("cmpxchg instructions cannot be unordered.", &CXI); return; } } while (false) | |||
3494 | "cmpxchg instructions cannot be unordered.", &CXI)do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::Unordered )) { CheckFailed("cmpxchg instructions cannot be unordered.", &CXI); return; } } while (false); | |||
3495 | Assert(CXI.getFailureOrdering() != AtomicOrdering::Unordered,do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Unordered )) { CheckFailed("cmpxchg instructions cannot be unordered.", &CXI); return; } } while (false) | |||
3496 | "cmpxchg instructions cannot be unordered.", &CXI)do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Unordered )) { CheckFailed("cmpxchg instructions cannot be unordered.", &CXI); return; } } while (false); | |||
3497 | Assert(!isStrongerThan(CXI.getFailureOrdering(), CXI.getSuccessOrdering()),do { if (!(!isStrongerThan(CXI.getFailureOrdering(), CXI.getSuccessOrdering ()))) { CheckFailed("cmpxchg instructions failure argument shall be no stronger than the " "success argument", &CXI); return; } } while (false) | |||
3498 | "cmpxchg instructions failure argument shall be no stronger than the "do { if (!(!isStrongerThan(CXI.getFailureOrdering(), CXI.getSuccessOrdering ()))) { CheckFailed("cmpxchg instructions failure argument shall be no stronger than the " "success argument", &CXI); return; } } while (false) | |||
3499 | "success argument",do { if (!(!isStrongerThan(CXI.getFailureOrdering(), CXI.getSuccessOrdering ()))) { CheckFailed("cmpxchg instructions failure argument shall be no stronger than the " "success argument", &CXI); return; } } while (false) | |||
3500 | &CXI)do { if (!(!isStrongerThan(CXI.getFailureOrdering(), CXI.getSuccessOrdering ()))) { CheckFailed("cmpxchg instructions failure argument shall be no stronger than the " "success argument", &CXI); return; } } while (false); | |||
3501 | Assert(CXI.getFailureOrdering() != AtomicOrdering::Release &&do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Release && CXI.getFailureOrdering() != AtomicOrdering::AcquireRelease )) { CheckFailed("cmpxchg failure ordering cannot include release semantics" , &CXI); return; } } while (false) | |||
3502 | CXI.getFailureOrdering() != AtomicOrdering::AcquireRelease,do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Release && CXI.getFailureOrdering() != AtomicOrdering::AcquireRelease )) { CheckFailed("cmpxchg failure ordering cannot include release semantics" , &CXI); return; } } while (false) | |||
3503 | "cmpxchg failure ordering cannot include release semantics", &CXI)do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Release && CXI.getFailureOrdering() != AtomicOrdering::AcquireRelease )) { CheckFailed("cmpxchg failure ordering cannot include release semantics" , &CXI); return; } } while (false); | |||
3504 | ||||
3505 | PointerType *PTy = dyn_cast<PointerType>(CXI.getOperand(0)->getType()); | |||
3506 | Assert(PTy, "First cmpxchg operand must be a pointer.", &CXI)do { if (!(PTy)) { CheckFailed("First cmpxchg operand must be a pointer." , &CXI); return; } } while (false); | |||
3507 | Type *ElTy = PTy->getElementType(); | |||
3508 | Assert(ElTy->isIntOrPtrTy(),do { if (!(ElTy->isIntOrPtrTy())) { CheckFailed("cmpxchg operand must have integer or pointer type" , ElTy, &CXI); return; } } while (false) | |||
3509 | "cmpxchg operand must have integer or pointer type", ElTy, &CXI)do { if (!(ElTy->isIntOrPtrTy())) { CheckFailed("cmpxchg operand must have integer or pointer type" , ElTy, &CXI); return; } } while (false); | |||
3510 | checkAtomicMemAccessSize(ElTy, &CXI); | |||
3511 | Assert(ElTy == CXI.getOperand(1)->getType(),do { if (!(ElTy == CXI.getOperand(1)->getType())) { CheckFailed ("Expected value type does not match pointer operand type!", & CXI, ElTy); return; } } while (false) | |||
3512 | "Expected value type does not match pointer operand type!", &CXI,do { if (!(ElTy == CXI.getOperand(1)->getType())) { CheckFailed ("Expected value type does not match pointer operand type!", & CXI, ElTy); return; } } while (false) | |||
3513 | ElTy)do { if (!(ElTy == CXI.getOperand(1)->getType())) { CheckFailed ("Expected value type does not match pointer operand type!", & CXI, ElTy); return; } } while (false); | |||
3514 | Assert(ElTy == CXI.getOperand(2)->getType(),do { if (!(ElTy == CXI.getOperand(2)->getType())) { CheckFailed ("Stored value type does not match pointer operand type!", & CXI, ElTy); return; } } while (false) | |||
3515 | "Stored value type does not match pointer operand type!", &CXI, ElTy)do { if (!(ElTy == CXI.getOperand(2)->getType())) { CheckFailed ("Stored value type does not match pointer operand type!", & CXI, ElTy); return; } } while (false); | |||
3516 | visitInstruction(CXI); | |||
3517 | } | |||
3518 | ||||
3519 | void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) { | |||
3520 | Assert(RMWI.getOrdering() != AtomicOrdering::NotAtomic,do { if (!(RMWI.getOrdering() != AtomicOrdering::NotAtomic)) { CheckFailed("atomicrmw instructions must be atomic.", &RMWI ); return; } } while (false) | |||
3521 | "atomicrmw instructions must be atomic.", &RMWI)do { if (!(RMWI.getOrdering() != AtomicOrdering::NotAtomic)) { CheckFailed("atomicrmw instructions must be atomic.", &RMWI ); return; } } while (false); | |||
3522 | Assert(RMWI.getOrdering() != AtomicOrdering::Unordered,do { if (!(RMWI.getOrdering() != AtomicOrdering::Unordered)) { CheckFailed("atomicrmw instructions cannot be unordered.", & RMWI); return; } } while (false) | |||
3523 | "atomicrmw instructions cannot be unordered.", &RMWI)do { if (!(RMWI.getOrdering() != AtomicOrdering::Unordered)) { CheckFailed("atomicrmw instructions cannot be unordered.", & RMWI); return; } } while (false); | |||
3524 | auto Op = RMWI.getOperation(); | |||
3525 | PointerType *PTy = dyn_cast<PointerType>(RMWI.getOperand(0)->getType()); | |||
3526 | Assert(PTy, "First atomicrmw operand must be a pointer.", &RMWI)do { if (!(PTy)) { CheckFailed("First atomicrmw operand must be a pointer." , &RMWI); return; } } while (false); | |||
3527 | Type *ElTy = PTy->getElementType(); | |||
3528 | if (Op == AtomicRMWInst::Xchg) { | |||
3529 | Assert(ElTy->isIntegerTy() || ElTy->isFloatingPointTy(), "atomicrmw " +do { if (!(ElTy->isIntegerTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName (Op) + " operand must have integer or floating point type!", & RMWI, ElTy); return; } } while (false) | |||
3530 | AtomicRMWInst::getOperationName(Op) +do { if (!(ElTy->isIntegerTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName (Op) + " operand must have integer or floating point type!", & RMWI, ElTy); return; } } while (false) | |||
3531 | " operand must have integer or floating point type!",do { if (!(ElTy->isIntegerTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName (Op) + " operand must have integer or floating point type!", & RMWI, ElTy); return; } } while (false) | |||
3532 | &RMWI, ElTy)do { if (!(ElTy->isIntegerTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName (Op) + " operand must have integer or floating point type!", & RMWI, ElTy); return; } } while (false); | |||
3533 | } else if (AtomicRMWInst::isFPOperation(Op)) { | |||
3534 | Assert(ElTy->isFloatingPointTy(), "atomicrmw " +do { if (!(ElTy->isFloatingPointTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have floating point type!" , &RMWI, ElTy); return; } } while (false) | |||
3535 | AtomicRMWInst::getOperationName(Op) +do { if (!(ElTy->isFloatingPointTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have floating point type!" , &RMWI, ElTy); return; } } while (false) | |||
3536 | " operand must have floating point type!",do { if (!(ElTy->isFloatingPointTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have floating point type!" , &RMWI, ElTy); return; } } while (false) | |||
3537 | &RMWI, ElTy)do { if (!(ElTy->isFloatingPointTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have floating point type!" , &RMWI, ElTy); return; } } while (false); | |||
3538 | } else { | |||
3539 | Assert(ElTy->isIntegerTy(), "atomicrmw " +do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have integer type!" , &RMWI, ElTy); return; } } while (false) | |||
3540 | AtomicRMWInst::getOperationName(Op) +do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have integer type!" , &RMWI, ElTy); return; } } while (false) | |||
3541 | " operand must have integer type!",do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have integer type!" , &RMWI, ElTy); return; } } while (false) | |||
3542 | &RMWI, ElTy)do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have integer type!" , &RMWI, ElTy); return; } } while (false); | |||
3543 | } | |||
3544 | checkAtomicMemAccessSize(ElTy, &RMWI); | |||
3545 | Assert(ElTy == RMWI.getOperand(1)->getType(),do { if (!(ElTy == RMWI.getOperand(1)->getType())) { CheckFailed ("Argument value type does not match pointer operand type!", & RMWI, ElTy); return; } } while (false) | |||
3546 | "Argument value type does not match pointer operand type!", &RMWI,do { if (!(ElTy == RMWI.getOperand(1)->getType())) { CheckFailed ("Argument value type does not match pointer operand type!", & RMWI, ElTy); return; } } while (false) | |||
3547 | ElTy)do { if (!(ElTy == RMWI.getOperand(1)->getType())) { CheckFailed ("Argument value type does not match pointer operand type!", & RMWI, ElTy); return; } } while (false); | |||
3548 | Assert(AtomicRMWInst::FIRST_BINOP <= Op && Op <= AtomicRMWInst::LAST_BINOP,do { if (!(AtomicRMWInst::FIRST_BINOP <= Op && Op <= AtomicRMWInst::LAST_BINOP)) { CheckFailed("Invalid binary operation!" , &RMWI); return; } } while (false) | |||
3549 | "Invalid binary operation!", &RMWI)do { if (!(AtomicRMWInst::FIRST_BINOP <= Op && Op <= AtomicRMWInst::LAST_BINOP)) { CheckFailed("Invalid binary operation!" , &RMWI); return; } } while (false); | |||
3550 | visitInstruction(RMWI); | |||
3551 | } | |||
3552 | ||||
3553 | void Verifier::visitFenceInst(FenceInst &FI) { | |||
3554 | const AtomicOrdering Ordering = FI.getOrdering(); | |||
3555 | Assert(Ordering == AtomicOrdering::Acquire ||do { if (!(Ordering == AtomicOrdering::Acquire || Ordering == AtomicOrdering::Release || Ordering == AtomicOrdering::AcquireRelease || Ordering == AtomicOrdering::SequentiallyConsistent)) { CheckFailed ("fence instructions may only have acquire, release, acq_rel, or " "seq_cst ordering.", &FI); return; } } while (false) | |||
3556 | Ordering == AtomicOrdering::Release ||do { if (!(Ordering == AtomicOrdering::Acquire || Ordering == AtomicOrdering::Release || Ordering == AtomicOrdering::AcquireRelease || Ordering == AtomicOrdering::SequentiallyConsistent)) { CheckFailed ("fence instructions may only have acquire, release, acq_rel, or " "seq_cst ordering.", &FI); return; } } while (false) | |||
3557 | Ordering == AtomicOrdering::AcquireRelease ||do { if (!(Ordering == AtomicOrdering::Acquire || Ordering == AtomicOrdering::Release || Ordering == AtomicOrdering::AcquireRelease || Ordering == AtomicOrdering::SequentiallyConsistent)) { CheckFailed ("fence instructions may only have acquire, release, acq_rel, or " "seq_cst ordering.", &FI); return; } } while (false) | |||
3558 | Ordering == AtomicOrdering::SequentiallyConsistent,do { if (!(Ordering == AtomicOrdering::Acquire || Ordering == AtomicOrdering::Release || Ordering == AtomicOrdering::AcquireRelease || Ordering == AtomicOrdering::SequentiallyConsistent)) { CheckFailed ("fence instructions may only have acquire, release, acq_rel, or " "seq_cst ordering.", &FI); return; } } while (false) | |||
3559 | "fence instructions may only have acquire, release, acq_rel, or "do { if (!(Ordering == AtomicOrdering::Acquire || Ordering == AtomicOrdering::Release || Ordering == AtomicOrdering::AcquireRelease || Ordering == AtomicOrdering::SequentiallyConsistent)) { CheckFailed ("fence instructions may only have acquire, release, acq_rel, or " "seq_cst ordering.", &FI); return; } } while (false) | |||
3560 | "seq_cst ordering.",do { if (!(Ordering == AtomicOrdering::Acquire || Ordering == AtomicOrdering::Release || Ordering == AtomicOrdering::AcquireRelease || Ordering == AtomicOrdering::SequentiallyConsistent)) { CheckFailed ("fence instructions may only have acquire, release, acq_rel, or " "seq_cst ordering.", &FI); return; } } while (false) | |||
3561 | &FI)do { if (!(Ordering == AtomicOrdering::Acquire || Ordering == AtomicOrdering::Release || Ordering == AtomicOrdering::AcquireRelease || Ordering == AtomicOrdering::SequentiallyConsistent)) { CheckFailed ("fence instructions may only have acquire, release, acq_rel, or " "seq_cst ordering.", &FI); return; } } while (false); | |||
3562 | visitInstruction(FI); | |||
3563 | } | |||
3564 | ||||
3565 | void Verifier::visitExtractValueInst(ExtractValueInst &EVI) { | |||
3566 | Assert(ExtractValueInst::getIndexedType(EVI.getAggregateOperand()->getType(),do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand ()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed ("Invalid ExtractValueInst operands!", &EVI); return; } } while (false) | |||
3567 | EVI.getIndices()) == EVI.getType(),do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand ()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed ("Invalid ExtractValueInst operands!", &EVI); return; } } while (false) | |||
3568 | "Invalid ExtractValueInst operands!", &EVI)do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand ()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed ("Invalid ExtractValueInst operands!", &EVI); return; } } while (false); | |||
3569 | ||||
3570 | visitInstruction(EVI); | |||
3571 | } | |||
3572 | ||||
3573 | void Verifier::visitInsertValueInst(InsertValueInst &IVI) { | |||
3574 | Assert(ExtractValueInst::getIndexedType(IVI.getAggregateOperand()->getType(),do { if (!(ExtractValueInst::getIndexedType(IVI.getAggregateOperand ()->getType(), IVI.getIndices()) == IVI.getOperand(1)-> getType())) { CheckFailed("Invalid InsertValueInst operands!" , &IVI); return; } } while (false) | |||
3575 | IVI.getIndices()) ==do { if (!(ExtractValueInst::getIndexedType(IVI.getAggregateOperand ()->getType(), IVI.getIndices()) == IVI.getOperand(1)-> getType())) { CheckFailed("Invalid InsertValueInst operands!" , &IVI); return; } } while (false) | |||
3576 | IVI.getOperand(1)->getType(),do { if (!(ExtractValueInst::getIndexedType(IVI.getAggregateOperand ()->getType(), IVI.getIndices()) == IVI.getOperand(1)-> getType())) { CheckFailed("Invalid InsertValueInst operands!" , &IVI); return; } } while (false) | |||
3577 | "Invalid InsertValueInst operands!", &IVI)do { if (!(ExtractValueInst::getIndexedType(IVI.getAggregateOperand ()->getType(), IVI.getIndices()) == IVI.getOperand(1)-> getType())) { CheckFailed("Invalid InsertValueInst operands!" , &IVI); return; } } while (false); | |||
3578 | ||||
3579 | visitInstruction(IVI); | |||
3580 | } | |||
3581 | ||||
3582 | static Value *getParentPad(Value *EHPad) { | |||
3583 | if (auto *FPI = dyn_cast<FuncletPadInst>(EHPad)) | |||
3584 | return FPI->getParentPad(); | |||
3585 | ||||
3586 | return cast<CatchSwitchInst>(EHPad)->getParentPad(); | |||
3587 | } | |||
3588 | ||||
3589 | void Verifier::visitEHPadPredecessors(Instruction &I) { | |||
3590 | assert(I.isEHPad())((I.isEHPad()) ? static_cast<void> (0) : __assert_fail ( "I.isEHPad()", "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/IR/Verifier.cpp" , 3590, __PRETTY_FUNCTION__)); | |||
3591 | ||||
3592 | BasicBlock *BB = I.getParent(); | |||
3593 | Function *F = BB->getParent(); | |||
3594 | ||||
3595 | Assert(BB != &F->getEntryBlock(), "EH pad cannot be in entry block.", &I)do { if (!(BB != &F->getEntryBlock())) { CheckFailed("EH pad cannot be in entry block." , &I); return; } } while (false); | |||
3596 | ||||
3597 | if (auto *LPI = dyn_cast<LandingPadInst>(&I)) { | |||
3598 | // The landingpad instruction defines its parent as a landing pad block. The | |||
3599 | // landing pad block may be branched to only by the unwind edge of an | |||
3600 | // invoke. | |||
3601 | for (BasicBlock *PredBB : predecessors(BB)) { | |||
3602 | const auto *II = dyn_cast<InvokeInst>(PredBB->getTerminator()); | |||
3603 | Assert(II && II->getUnwindDest() == BB && II->getNormalDest() != BB,do { if (!(II && II->getUnwindDest() == BB && II->getNormalDest() != BB)) { CheckFailed("Block containing LandingPadInst must be jumped to " "only by the unwind edge of an invoke.", LPI); return; } } while (false) | |||
3604 | "Block containing LandingPadInst must be jumped to "do { if (!(II && II->getUnwindDest() == BB && II->getNormalDest() != BB)) { CheckFailed("Block containing LandingPadInst must be jumped to " "only by the unwind edge of an invoke.", LPI); return; } } while (false) | |||
3605 | "only by the unwind edge of an invoke.",do { if (!(II && II->getUnwindDest() == BB && II->getNormalDest() != BB)) { CheckFailed("Block containing LandingPadInst must be jumped to " "only by the unwind edge of an invoke.", LPI); return; } } while (false) | |||
3606 | LPI)do { if (!(II && II->getUnwindDest() == BB && II->getNormalDest() != BB)) { CheckFailed("Block containing LandingPadInst must be jumped to " "only by the unwind edge of an invoke.", LPI); return; } } while (false); | |||
3607 | } | |||
3608 | return; | |||
3609 | } | |||
3610 | if (auto *CPI = dyn_cast<CatchPadInst>(&I)) { | |||
3611 | if (!pred_empty(BB)) | |||
3612 | Assert(BB->getUniquePredecessor() == CPI->getCatchSwitch()->getParent(),do { if (!(BB->getUniquePredecessor() == CPI->getCatchSwitch ()->getParent())) { CheckFailed("Block containg CatchPadInst must be jumped to " "only by its catchswitch.", CPI); return; } } while (false) | |||
3613 | "Block containg CatchPadInst must be jumped to "do { if (!(BB->getUniquePredecessor() == CPI->getCatchSwitch ()->getParent())) { CheckFailed("Block containg CatchPadInst must be jumped to " "only by its catchswitch.", CPI); return; } } while (false) | |||
3614 | "only by its catchswitch.",do { if (!(BB->getUniquePredecessor() == CPI->getCatchSwitch ()->getParent())) { CheckFailed("Block containg CatchPadInst must be jumped to " "only by its catchswitch.", CPI); return; } } while (false) | |||
3615 | CPI)do { if (!(BB->getUniquePredecessor() == CPI->getCatchSwitch ()->getParent())) { CheckFailed("Block containg CatchPadInst must be jumped to " "only by its catchswitch.", CPI); return; } } while (false); | |||
3616 | Assert(BB != CPI->getCatchSwitch()->getUnwindDest(),do { if (!(BB != CPI->getCatchSwitch()->getUnwindDest() )) { CheckFailed("Catchswitch cannot unwind to one of its catchpads" , CPI->getCatchSwitch(), CPI); return; } } while (false) | |||
3617 | "Catchswitch cannot unwind to one of its catchpads",do { if (!(BB != CPI->getCatchSwitch()->getUnwindDest() )) { CheckFailed("Catchswitch cannot unwind to one of its catchpads" , CPI->getCatchSwitch(), CPI); return; } } while (false) | |||
3618 | CPI->getCatchSwitch(), CPI)do { if (!(BB != CPI->getCatchSwitch()->getUnwindDest() )) { CheckFailed("Catchswitch cannot unwind to one of its catchpads" , CPI->getCatchSwitch(), CPI); return; } } while (false); | |||
3619 | return; | |||
3620 | } | |||
3621 | ||||
3622 | // Verify that each pred has a legal terminator with a legal to/from EH | |||
3623 | // pad relationship. | |||
3624 | Instruction *ToPad = &I; | |||
3625 | Value *ToPadParent = getParentPad(ToPad); | |||
3626 | for (BasicBlock *PredBB : predecessors(BB)) { | |||
3627 | Instruction *TI = PredBB->getTerminator(); | |||
3628 | Value *FromPad; | |||
3629 | if (auto *II = dyn_cast<InvokeInst>(TI)) { | |||
3630 | Assert(II->getUnwindDest() == BB && II->getNormalDest() != BB,do { if (!(II->getUnwindDest() == BB && II->getNormalDest () != BB)) { CheckFailed("EH pad must be jumped to via an unwind edge" , ToPad, II); return; } } while (false) | |||
3631 | "EH pad must be jumped to via an unwind edge", ToPad, II)do { if (!(II->getUnwindDest() == BB && II->getNormalDest () != BB)) { CheckFailed("EH pad must be jumped to via an unwind edge" , ToPad, II); return; } } while (false); | |||
3632 | if (auto Bundle = II->getOperandBundle(LLVMContext::OB_funclet)) | |||
3633 | FromPad = Bundle->Inputs[0]; | |||
3634 | else | |||
3635 | FromPad = ConstantTokenNone::get(II->getContext()); | |||
3636 | } else if (auto *CRI = dyn_cast<CleanupReturnInst>(TI)) { | |||
3637 | FromPad = CRI->getOperand(0); | |||
3638 | Assert(FromPad != ToPadParent, "A cleanupret must exit its cleanup", CRI)do { if (!(FromPad != ToPadParent)) { CheckFailed("A cleanupret must exit its cleanup" , CRI); return; } } while (false); | |||
3639 | } else if (auto *CSI = dyn_cast<CatchSwitchInst>(TI)) { | |||
3640 | FromPad = CSI; | |||
3641 | } else { | |||
3642 | Assert(false, "EH pad must be jumped to via an unwind edge", ToPad, TI)do { if (!(false)) { CheckFailed("EH pad must be jumped to via an unwind edge" , ToPad, TI); return; } } while (false); | |||
3643 | } | |||
3644 | ||||
3645 | // The edge may exit from zero or more nested pads. | |||
3646 | SmallSet<Value *, 8> Seen; | |||
3647 | for (;; FromPad = getParentPad(FromPad)) { | |||
3648 | Assert(FromPad != ToPad,do { if (!(FromPad != ToPad)) { CheckFailed("EH pad cannot handle exceptions raised within it" , FromPad, TI); return; } } while (false) | |||
3649 | "EH pad cannot handle exceptions raised within it", FromPad, TI)do { if (!(FromPad != ToPad)) { CheckFailed("EH pad cannot handle exceptions raised within it" , FromPad, TI); return; } } while (false); | |||
3650 | if (FromPad == ToPadParent) { | |||
3651 | // This is a legal unwind edge. | |||
3652 | break; | |||
3653 | } | |||
3654 | Assert(!isa<ConstantTokenNone>(FromPad),do { if (!(!isa<ConstantTokenNone>(FromPad))) { CheckFailed ("A single unwind edge may only enter one EH pad", TI); return ; } } while (false) | |||
3655 | "A single unwind edge may only enter one EH pad", TI)do { if (!(!isa<ConstantTokenNone>(FromPad))) { CheckFailed ("A single unwind edge may only enter one EH pad", TI); return ; } } while (false); | |||
3656 | Assert(Seen.insert(FromPad).second,do { if (!(Seen.insert(FromPad).second)) { CheckFailed("EH pad jumps through a cycle of pads" , FromPad); return; } } while (false) | |||
3657 | "EH pad jumps through a cycle of pads", FromPad)do { if (!(Seen.insert(FromPad).second)) { CheckFailed("EH pad jumps through a cycle of pads" , FromPad); return; } } while (false); | |||
3658 | } | |||
3659 | } | |||
3660 | } | |||
3661 | ||||
3662 | void Verifier::visitLandingPadInst(LandingPadInst &LPI) { | |||
3663 | // The landingpad instruction is ill-formed if it doesn't have any clauses and | |||
3664 | // isn't a cleanup. | |||
3665 | Assert(LPI.getNumClauses() > 0 || LPI.isCleanup(),do { if (!(LPI.getNumClauses() > 0 || LPI.isCleanup())) { CheckFailed ("LandingPadInst needs at least one clause or to be a cleanup." , &LPI); return; } } while (false) | |||
3666 | "LandingPadInst needs at least one clause or to be a cleanup.", &LPI)do { if (!(LPI.getNumClauses() > 0 || LPI.isCleanup())) { CheckFailed ("LandingPadInst needs at least one clause or to be a cleanup." , &LPI); return; } } while (false); | |||
3667 | ||||
3668 | visitEHPadPredecessors(LPI); | |||
3669 | ||||
3670 | if (!LandingPadResultTy) | |||
3671 | LandingPadResultTy = LPI.getType(); | |||
3672 | else | |||
3673 | Assert(LandingPadResultTy == LPI.getType(),do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed ("The landingpad instruction should have a consistent result type " "inside a function.", &LPI); return; } } while (false) | |||
3674 | "The landingpad instruction should have a consistent result type "do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed ("The landingpad instruction should have a consistent result type " "inside a function.", &LPI); return; } } while (false) | |||
3675 | "inside a function.",do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed ("The landingpad instruction should have a consistent result type " "inside a function.", &LPI); return; } } while (false) | |||
3676 | &LPI)do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed ("The landingpad instruction should have a consistent result type " "inside a function.", &LPI); return; } } while (false); | |||
3677 | ||||
3678 | Function *F = LPI.getParent()->getParent(); | |||
3679 | Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("LandingPadInst needs to be in a function with a personality." , &LPI); return; } } while (false) | |||
3680 | "LandingPadInst needs to be in a function with a personality.", &LPI)do { if (!(F->hasPersonalityFn())) { CheckFailed("LandingPadInst needs to be in a function with a personality." , &LPI); return; } } while (false); | |||
3681 | ||||
3682 | // The landingpad instruction must be the first non-PHI instruction in the | |||
3683 | // block. | |||
3684 | Assert(LPI.getParent()->getLandingPadInst() == &LPI,do { if (!(LPI.getParent()->getLandingPadInst() == &LPI )) { CheckFailed("LandingPadInst not the first non-PHI instruction in the block." , &LPI); return; } } while (false) | |||
3685 | "LandingPadInst not the first non-PHI instruction in the block.",do { if (!(LPI.getParent()->getLandingPadInst() == &LPI )) { CheckFailed("LandingPadInst not the first non-PHI instruction in the block." , &LPI); return; } } while (false) | |||
3686 | &LPI)do { if (!(LPI.getParent()->getLandingPadInst() == &LPI )) { CheckFailed("LandingPadInst not the first non-PHI instruction in the block." , &LPI); return; } } while (false); | |||
3687 | ||||
3688 | for (unsigned i = 0, e = LPI.getNumClauses(); i < e; ++i) { | |||
3689 | Constant *Clause = LPI.getClause(i); | |||
3690 | if (LPI.isCatch(i)) { | |||
3691 | Assert(isa<PointerType>(Clause->getType()),do { if (!(isa<PointerType>(Clause->getType()))) { CheckFailed ("Catch operand does not have pointer type!", &LPI); return ; } } while (false) | |||
3692 | "Catch operand does not have pointer type!", &LPI)do { if (!(isa<PointerType>(Clause->getType()))) { CheckFailed ("Catch operand does not have pointer type!", &LPI); return ; } } while (false); | |||
3693 | } else { | |||
3694 | Assert(LPI.isFilter(i), "Clause is neither catch nor filter!", &LPI)do { if (!(LPI.isFilter(i))) { CheckFailed("Clause is neither catch nor filter!" , &LPI); return; } } while (false); | |||
3695 | Assert(isa<ConstantArray>(Clause) || isa<ConstantAggregateZero>(Clause),do { if (!(isa<ConstantArray>(Clause) || isa<ConstantAggregateZero >(Clause))) { CheckFailed("Filter operand is not an array of constants!" , &LPI); return; } } while (false) | |||
3696 | "Filter operand is not an array of constants!", &LPI)do { if (!(isa<ConstantArray>(Clause) || isa<ConstantAggregateZero >(Clause))) { CheckFailed("Filter operand is not an array of constants!" , &LPI); return; } } while (false); | |||
3697 | } | |||
3698 | } | |||
3699 | ||||
3700 | visitInstruction(LPI); | |||
3701 | } | |||
3702 | ||||
3703 | void Verifier::visitResumeInst(ResumeInst &RI) { | |||
3704 | Assert(RI.getFunction()->hasPersonalityFn(),do { if (!(RI.getFunction()->hasPersonalityFn())) { CheckFailed ("ResumeInst needs to be in a function with a personality.", & RI); return; } } while (false) | |||
3705 | "ResumeInst needs to be in a function with a personality.", &RI)do { if (!(RI.getFunction()->hasPersonalityFn())) { CheckFailed ("ResumeInst needs to be in a function with a personality.", & RI); return; } } while (false); | |||
3706 | ||||
3707 | if (!LandingPadResultTy) | |||
3708 | LandingPadResultTy = RI.getValue()->getType(); | |||
3709 | else | |||
3710 | Assert(LandingPadResultTy == RI.getValue()->getType(),do { if (!(LandingPadResultTy == RI.getValue()->getType()) ) { CheckFailed("The resume instruction should have a consistent result type " "inside a function.", &RI); return; } } while (false) | |||
3711 | "The resume instruction should have a consistent result type "do { if (!(LandingPadResultTy == RI.getValue()->getType()) ) { CheckFailed("The resume instruction should have a consistent result type " "inside a function.", &RI); return; } } while (false) | |||
3712 | "inside a function.",do { if (!(LandingPadResultTy == RI.getValue()->getType()) ) { CheckFailed("The resume instruction should have a consistent result type " "inside a function.", &RI); return; } } while (false) | |||
3713 | &RI)do { if (!(LandingPadResultTy == RI.getValue()->getType()) ) { CheckFailed("The resume instruction should have a consistent result type " "inside a function.", &RI); return; } } while (false); | |||
3714 | ||||
3715 | visitTerminator(RI); | |||
3716 | } | |||
3717 | ||||
3718 | void Verifier::visitCatchPadInst(CatchPadInst &CPI) { | |||
3719 | BasicBlock *BB = CPI.getParent(); | |||
3720 | ||||
3721 | Function *F = BB->getParent(); | |||
3722 | Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchPadInst needs to be in a function with a personality." , &CPI); return; } } while (false) | |||
3723 | "CatchPadInst needs to be in a function with a personality.", &CPI)do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchPadInst needs to be in a function with a personality." , &CPI); return; } } while (false); | |||
3724 | ||||
3725 | Assert(isa<CatchSwitchInst>(CPI.getParentPad()),do { if (!(isa<CatchSwitchInst>(CPI.getParentPad()))) { CheckFailed("CatchPadInst needs to be directly nested in a CatchSwitchInst." , CPI.getParentPad()); return; } } while (false) | |||
3726 | "CatchPadInst needs to be directly nested in a CatchSwitchInst.",do { if (!(isa<CatchSwitchInst>(CPI.getParentPad()))) { CheckFailed("CatchPadInst needs to be directly nested in a CatchSwitchInst." , CPI.getParentPad()); return; } } while (false) | |||
3727 | CPI.getParentPad())do { if (!(isa<CatchSwitchInst>(CPI.getParentPad()))) { CheckFailed("CatchPadInst needs to be directly nested in a CatchSwitchInst." , CPI.getParentPad()); return; } } while (false); | |||
3728 | ||||
3729 | // The catchpad instruction must be the first non-PHI instruction in the | |||
3730 | // block. | |||
3731 | Assert(BB->getFirstNonPHI() == &CPI,do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CatchPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (false) | |||
3732 | "CatchPadInst not the first non-PHI instruction in the block.", &CPI)do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CatchPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (false); | |||
3733 | ||||
3734 | visitEHPadPredecessors(CPI); | |||
3735 | visitFuncletPadInst(CPI); | |||
3736 | } | |||
3737 | ||||
3738 | void Verifier::visitCatchReturnInst(CatchReturnInst &CatchReturn) { | |||
3739 | Assert(isa<CatchPadInst>(CatchReturn.getOperand(0)),do { if (!(isa<CatchPadInst>(CatchReturn.getOperand(0)) )) { CheckFailed("CatchReturnInst needs to be provided a CatchPad" , &CatchReturn, CatchReturn.getOperand(0)); return; } } while (false) | |||
3740 | "CatchReturnInst needs to be provided a CatchPad", &CatchReturn,do { if (!(isa<CatchPadInst>(CatchReturn.getOperand(0)) )) { CheckFailed("CatchReturnInst needs to be provided a CatchPad" , &CatchReturn, CatchReturn.getOperand(0)); return; } } while (false) | |||
3741 | CatchReturn.getOperand(0))do { if (!(isa<CatchPadInst>(CatchReturn.getOperand(0)) )) { CheckFailed("CatchReturnInst needs to be provided a CatchPad" , &CatchReturn, CatchReturn.getOperand(0)); return; } } while (false); | |||
3742 | ||||
3743 | visitTerminator(CatchReturn); | |||
3744 | } | |||
3745 | ||||
3746 | void Verifier::visitCleanupPadInst(CleanupPadInst &CPI) { | |||
3747 | BasicBlock *BB = CPI.getParent(); | |||
3748 | ||||
3749 | Function *F = BB->getParent(); | |||
3750 | Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CleanupPadInst needs to be in a function with a personality." , &CPI); return; } } while (false) | |||
3751 | "CleanupPadInst needs to be in a function with a personality.", &CPI)do { if (!(F->hasPersonalityFn())) { CheckFailed("CleanupPadInst needs to be in a function with a personality." , &CPI); return; } } while (false); | |||
3752 | ||||
3753 | // The cleanuppad instruction must be the first non-PHI instruction in the | |||
3754 | // block. | |||
3755 | Assert(BB->getFirstNonPHI() == &CPI,do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CleanupPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (false) | |||
3756 | "CleanupPadInst not the first non-PHI instruction in the block.",do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CleanupPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (false) | |||
3757 | &CPI)do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CleanupPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (false); | |||
3758 | ||||
3759 | auto *ParentPad = CPI.getParentPad(); | |||
3760 | Assert(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),do { if (!(isa<ConstantTokenNone>(ParentPad) || isa< FuncletPadInst>(ParentPad))) { CheckFailed("CleanupPadInst has an invalid parent." , &CPI); return; } } while (false) | |||
3761 | "CleanupPadInst has an invalid parent.", &CPI)do { if (!(isa<ConstantTokenNone>(ParentPad) || isa< FuncletPadInst>(ParentPad))) { CheckFailed("CleanupPadInst has an invalid parent." , &CPI); return; } } while (false); | |||
3762 | ||||
3763 | visitEHPadPredecessors(CPI); | |||
3764 | visitFuncletPadInst(CPI); | |||
3765 | } | |||
3766 | ||||
3767 | void Verifier::visitFuncletPadInst(FuncletPadInst &FPI) { | |||
3768 | User *FirstUser = nullptr; | |||
3769 | Value *FirstUnwindPad = nullptr; | |||
3770 | SmallVector<FuncletPadInst *, 8> Worklist({&FPI}); | |||
3771 | SmallSet<FuncletPadInst *, 8> Seen; | |||
3772 | ||||
3773 | while (!Worklist.empty()) { | |||
3774 | FuncletPadInst *CurrentPad = Worklist.pop_back_val(); | |||
3775 | Assert(Seen.insert(CurrentPad).second,do { if (!(Seen.insert(CurrentPad).second)) { CheckFailed("FuncletPadInst must not be nested within itself" , CurrentPad); return; } } while (false) | |||
3776 | "FuncletPadInst must not be nested within itself", CurrentPad)do { if (!(Seen.insert(CurrentPad).second)) { CheckFailed("FuncletPadInst must not be nested within itself" , CurrentPad); return; } } while (false); | |||
3777 | Value *UnresolvedAncestorPad = nullptr; | |||
3778 | for (User *U : CurrentPad->users()) { | |||
3779 | BasicBlock *UnwindDest; | |||
3780 | if (auto *CRI = dyn_cast<CleanupReturnInst>(U)) { | |||
3781 | UnwindDest = CRI->getUnwindDest(); | |||
3782 | } else if (auto *CSI = dyn_cast<CatchSwitchInst>(U)) { | |||
3783 | // We allow catchswitch unwind to caller to nest | |||
3784 | // within an outer pad that unwinds somewhere else, | |||
3785 | // because catchswitch doesn't have a nounwind variant. | |||
3786 | // See e.g. SimplifyCFGOpt::SimplifyUnreachable. | |||
3787 | if (CSI->unwindsToCaller()) | |||
3788 | continue; | |||
3789 | UnwindDest = CSI->getUnwindDest(); | |||
3790 | } else if (auto *II = dyn_cast<InvokeInst>(U)) { | |||
3791 | UnwindDest = II->getUnwindDest(); | |||
3792 | } else if (isa<CallInst>(U)) { | |||
3793 | // Calls which don't unwind may be found inside funclet | |||
3794 | // pads that unwind somewhere else. We don't *require* | |||
3795 | // such calls to be annotated nounwind. | |||
3796 | continue; | |||
3797 | } else if (auto *CPI = dyn_cast<CleanupPadInst>(U)) { | |||
3798 | // The unwind dest for a cleanup can only be found by | |||
3799 | // recursive search. Add it to the worklist, and we'll | |||
3800 | // search for its first use that determines where it unwinds. | |||
3801 | Worklist.push_back(CPI); | |||
3802 | continue; | |||
3803 | } else { | |||
3804 | Assert(isa<CatchReturnInst>(U), "Bogus funclet pad use", U)do { if (!(isa<CatchReturnInst>(U))) { CheckFailed("Bogus funclet pad use" , U); return; } } while (false); | |||
3805 | continue; | |||
3806 | } | |||
3807 | ||||
3808 | Value *UnwindPad; | |||
3809 | bool ExitsFPI; | |||
3810 | if (UnwindDest) { | |||
3811 | UnwindPad = UnwindDest->getFirstNonPHI(); | |||
3812 | if (!cast<Instruction>(UnwindPad)->isEHPad()) | |||
3813 | continue; | |||
3814 | Value *UnwindParent = getParentPad(UnwindPad); | |||
3815 | // Ignore unwind edges that don't exit CurrentPad. | |||
3816 | if (UnwindParent == CurrentPad) | |||
3817 | continue; | |||
3818 | // Determine whether the original funclet pad is exited, | |||
3819 | // and if we are scanning nested pads determine how many | |||
3820 | // of them are exited so we can stop searching their | |||
3821 | // children. | |||
3822 | Value *ExitedPad = CurrentPad; | |||
3823 | ExitsFPI = false; | |||
3824 | do { | |||
3825 | if (ExitedPad == &FPI) { | |||
3826 | ExitsFPI = true; | |||
3827 | // Now we can resolve any ancestors of CurrentPad up to | |||
3828 | // FPI, but not including FPI since we need to make sure | |||
3829 | // to check all direct users of FPI for consistency. | |||
3830 | UnresolvedAncestorPad = &FPI; | |||
3831 | break; | |||
3832 | } | |||
3833 | Value *ExitedParent = getParentPad(ExitedPad); | |||
3834 | if (ExitedParent == UnwindParent) { | |||
3835 | // ExitedPad is the ancestor-most pad which this unwind | |||
3836 | // edge exits, so we can resolve up to it, meaning that | |||
3837 | // ExitedParent is the first ancestor still unresolved. | |||
3838 | UnresolvedAncestorPad = ExitedParent; | |||
3839 | break; | |||
3840 | } | |||
3841 | ExitedPad = ExitedParent; | |||
3842 | } while (!isa<ConstantTokenNone>(ExitedPad)); | |||
3843 | } else { | |||
3844 | // Unwinding to caller exits all pads. | |||
3845 | UnwindPad = ConstantTokenNone::get(FPI.getContext()); | |||
3846 | ExitsFPI = true; | |||
3847 | UnresolvedAncestorPad = &FPI; | |||
3848 | } | |||
3849 | ||||
3850 | if (ExitsFPI) { | |||
3851 | // This unwind edge exits FPI. Make sure it agrees with other | |||
3852 | // such edges. | |||
3853 | if (FirstUser) { | |||
3854 | Assert(UnwindPad == FirstUnwindPad, "Unwind edges out of a funclet "do { if (!(UnwindPad == FirstUnwindPad)) { CheckFailed("Unwind edges out of a funclet " "pad must have the same unwind " "dest", &FPI, U, FirstUser ); return; } } while (false) | |||
3855 | "pad must have the same unwind "do { if (!(UnwindPad == FirstUnwindPad)) { CheckFailed("Unwind edges out of a funclet " "pad must have the same unwind " "dest", &FPI, U, FirstUser ); return; } } while (false) | |||
3856 | "dest",do { if (!(UnwindPad == FirstUnwindPad)) { CheckFailed("Unwind edges out of a funclet " "pad must have the same unwind " "dest", &FPI, U, FirstUser ); return; } } while (false) | |||
3857 | &FPI, U, FirstUser)do { if (!(UnwindPad == FirstUnwindPad)) { CheckFailed("Unwind edges out of a funclet " "pad must have the same unwind " "dest", &FPI, U, FirstUser ); return; } } while (false); | |||
3858 | } else { | |||
3859 | FirstUser = U; | |||
3860 | FirstUnwindPad = UnwindPad; | |||
3861 | // Record cleanup sibling unwinds for verifySiblingFuncletUnwinds | |||
3862 | if (isa<CleanupPadInst>(&FPI) && !isa<ConstantTokenNone>(UnwindPad) && | |||
3863 | getParentPad(UnwindPad) == getParentPad(&FPI)) | |||
3864 | SiblingFuncletInfo[&FPI] = cast<Instruction>(U); | |||
3865 | } | |||
3866 | } | |||
3867 | // Make sure we visit all uses of FPI, but for nested pads stop as | |||
3868 | // soon as we know where they unwind to. | |||
3869 | if (CurrentPad != &FPI) | |||
3870 | break; | |||
3871 | } | |||
3872 | if (UnresolvedAncestorPad) { | |||
3873 | if (CurrentPad == UnresolvedAncestorPad) { | |||
3874 | // When CurrentPad is FPI itself, we don't mark it as resolved even if | |||
3875 | // we've found an unwind edge that exits it, because we need to verify | |||
3876 | // all direct uses of FPI. | |||
3877 | assert(CurrentPad == &FPI)((CurrentPad == &FPI) ? static_cast<void> (0) : __assert_fail ("CurrentPad == &FPI", "/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/lib/IR/Verifier.cpp" , 3877, __PRETTY_FUNCTION__)); | |||
3878 | continue; | |||
3879 | } | |||
3880 | // Pop off the worklist any nested pads that we've found an unwind | |||
3881 | // destination for. The pads on the worklist are the uncles, | |||
3882 | // great-uncles, etc. of CurrentPad. We've found an unwind destination | |||
3883 | // for all ancestors of CurrentPad up to but not including | |||
3884 | // UnresolvedAncestorPad. | |||
3885 | Value *ResolvedPad = CurrentPad; | |||
3886 | while (!Worklist.empty()) { | |||
3887 | Value *UnclePad = Worklist.back(); | |||
3888 | Value *AncestorPad = getParentPad(UnclePad); | |||
3889 | // Walk ResolvedPad up the ancestor list until we either find the | |||
3890 | // uncle's parent or the last resolved ancestor. | |||
3891 | while (ResolvedPad != AncestorPad) { | |||
3892 | Value *ResolvedParent = getParentPad(ResolvedPad); | |||
3893 | if (ResolvedParent == UnresolvedAncestorPad) { | |||
3894 | break; | |||
3895 | } | |||
3896 | ResolvedPad = ResolvedParent; | |||
3897 | } | |||
3898 | // If the resolved ancestor search didn't find the uncle's parent, | |||
3899 | // then the uncle is not yet resolved. | |||
3900 | if (ResolvedPad != AncestorPad) | |||
3901 | break; | |||
3902 | // This uncle is resolved, so pop it from the worklist. | |||
3903 | Worklist.pop_back(); | |||
3904 | } | |||
3905 | } | |||
3906 | } | |||
3907 | ||||
3908 | if (FirstUnwindPad) { | |||
3909 | if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(FPI.getParentPad())) { | |||
3910 | BasicBlock *SwitchUnwindDest = CatchSwitch->getUnwindDest(); | |||
3911 | Value *SwitchUnwindPad; | |||
3912 | if (SwitchUnwindDest) | |||
3913 | SwitchUnwindPad = SwitchUnwindDest->getFirstNonPHI(); | |||
3914 | else | |||
3915 | SwitchUnwindPad = ConstantTokenNone::get(FPI.getContext()); | |||
3916 | Assert(SwitchUnwindPad == FirstUnwindPad,do { if (!(SwitchUnwindPad == FirstUnwindPad)) { CheckFailed( "Unwind edges out of a catch must have the same unwind dest as " "the parent catchswitch", &FPI, FirstUser, CatchSwitch); return; } } while (false) | |||
3917 | "Unwind edges out of a catch must have the same unwind dest as "do { if (!(SwitchUnwindPad == FirstUnwindPad)) { CheckFailed( "Unwind edges out of a catch must have the same unwind dest as " "the parent catchswitch", &FPI, FirstUser, CatchSwitch); return; } } while (false) | |||
3918 | "the parent catchswitch",do { if (!(SwitchUnwindPad == FirstUnwindPad)) { CheckFailed( "Unwind edges out of a catch must have the same unwind dest as " "the parent catchswitch", &FPI, FirstUser, CatchSwitch); return; } } while (false) | |||
3919 | &FPI, FirstUser, CatchSwitch)do { if (!(SwitchUnwindPad == FirstUnwindPad)) { CheckFailed( "Unwind edges out of a catch must have the same unwind dest as " "the parent catchswitch", &FPI, FirstUser, CatchSwitch); return; } } while (false); | |||
3920 | } | |||
3921 | } | |||
3922 | ||||
3923 | visitInstruction(FPI); | |||
3924 | } | |||
3925 | ||||
3926 | void Verifier::visitCatchSwitchInst(CatchSwitchInst &CatchSwitch) { | |||
3927 | BasicBlock *BB = CatchSwitch.getParent(); | |||
3928 | ||||
3929 | Function *F = BB->getParent(); | |||
3930 | Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchSwitchInst needs to be in a function with a personality." , &CatchSwitch); return; } } while (false) | |||
3931 | "CatchSwitchInst needs to be in a function with a personality.",do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchSwitchInst needs to be in a function with a personality." , &CatchSwitch); return; } } while (false) | |||
3932 | &CatchSwitch)do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchSwitchInst needs to be in a function with a personality." , &CatchSwitch); return; } } while (false); | |||
3933 | ||||
3934 | // The catchswitch instruction must be the first non-PHI instruction in the | |||
3935 | // block. | |||
3936 | Assert(BB->getFirstNonPHI() == &CatchSwitch,do { if (!(BB->getFirstNonPHI() == &CatchSwitch)) { CheckFailed ("CatchSwitchInst not the first non-PHI instruction in the block." , &CatchSwitch); return; } } while (false) | |||
3937 | "CatchSwitchInst not the first non-PHI instruction in the block.",do { if (!(BB->getFirstNonPHI() == &CatchSwitch)) { CheckFailed ("CatchSwitchInst not the first non-PHI instruction in the block." , &CatchSwitch); return; } } while (false) | |||
3938 | &CatchSwitch)do { if (!(BB->getFirstNonPHI() == &CatchSwitch)) { CheckFailed ("CatchSwitchInst not the first non-PHI instruction in the block." , &CatchSwitch); return; } } while (false); | |||
3939 | ||||
3940 | auto *ParentPad = CatchSwitch.getParentPad(); | |||
3941 | Assert(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),do { if (!(isa<ConstantTokenNone>(ParentPad) || isa< FuncletPadInst>(ParentPad))) { CheckFailed("CatchSwitchInst has an invalid parent." , ParentPad); return; } } while (false) | |||
3942 | "CatchSwitchInst has an invalid parent.", ParentPad)do { if (!(isa<ConstantTokenNone>(ParentPad) || isa< FuncletPadInst>(ParentPad))) { CheckFailed("CatchSwitchInst has an invalid parent." , ParentPad); return; } } while (false); | |||
3943 | ||||
3944 | if (BasicBlock *UnwindDest = CatchSwitch.getUnwindDest()) { | |||
3945 | Instruction *I = UnwindDest->getFirstNonPHI(); | |||
3946 | Assert(I->isEHPad() && !isa<LandingPadInst>(I),do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("CatchSwitchInst must unwind to an EH block which is not a " "landingpad.", &CatchSwitch); return; } } while (false) | |||
3947 | "CatchSwitchInst must unwind to an EH block which is not a "do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("CatchSwitchInst must unwind to an EH block which is not a " "landingpad.", &CatchSwitch); return; } } while (false) | |||
3948 | "landingpad.",do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("CatchSwitchInst must unwind to an EH block which is not a " "landingpad.", &CatchSwitch); return; } } while (false) | |||
3949 | &CatchSwitch)do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("CatchSwitchInst must unwind to an EH block which is not a " "landingpad.", &CatchSwitch); return; } } while (false); | |||
3950 | ||||
3951 | // Record catchswitch sibling unwinds for verifySiblingFuncletUnwinds | |||
3952 | if (getParentPad(I) == ParentPad) | |||
3953 | SiblingFuncletInfo[&CatchSwitch] = &CatchSwitch; | |||
3954 | } | |||
3955 | ||||
3956 | Assert(CatchSwitch.getNumHandlers() != 0,do { if (!(CatchSwitch.getNumHandlers() != 0)) { CheckFailed( "CatchSwitchInst cannot have empty handler list", &CatchSwitch ); return; } } while (false) | |||
3957 | "CatchSwitchInst cannot have empty handler list", &CatchSwitch)do { if (!(CatchSwitch.getNumHandlers() != 0)) { CheckFailed( "CatchSwitchInst cannot have empty handler list", &CatchSwitch ); return; } } while (false); | |||
3958 | ||||
3959 | for (BasicBlock *Handler : CatchSwitch.handlers()) { | |||
3960 | Assert(isa<CatchPadInst>(Handler->getFirstNonPHI()),do { if (!(isa<CatchPadInst>(Handler->getFirstNonPHI ()))) { CheckFailed("CatchSwitchInst handlers must be catchpads" , &CatchSwitch, Handler); return; } } while (false) | |||
3961 | "CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler)do { if (!(isa<CatchPadInst>(Handler->getFirstNonPHI ()))) { CheckFailed("CatchSwitchInst handlers must be catchpads" , &CatchSwitch, Handler); return; } } while (false); | |||
3962 | } | |||
3963 | ||||
3964 | visitEHPadPredecessors(CatchSwitch); | |||
3965 | visitTerminator(CatchSwitch); | |||
3966 | } | |||
3967 | ||||
3968 | void Verifier::visitCleanupReturnInst(CleanupReturnInst &CRI) { | |||
3969 | Assert(isa<CleanupPadInst>(CRI.getOperand(0)),do { if (!(isa<CleanupPadInst>(CRI.getOperand(0)))) { CheckFailed ("CleanupReturnInst needs to be provided a CleanupPad", & CRI, CRI.getOperand(0)); return; } } while (false) | |||
3970 | "CleanupReturnInst needs to be provided a CleanupPad", &CRI,do { if (!(isa<CleanupPadInst>(CRI.getOperand(0)))) { CheckFailed ("CleanupReturnInst needs to be provided a CleanupPad", & CRI, CRI.getOperand(0)); return; } } while (false) | |||
3971 | CRI.getOperand(0))do { if (!(isa<CleanupPadInst>(CRI.getOperand(0)))) { CheckFailed ("CleanupReturnInst needs to be provided a CleanupPad", & CRI, CRI.getOperand(0)); return; } } while (false); | |||
3972 | ||||
3973 | if (BasicBlock *UnwindDest = CRI.getUnwindDest()) { | |||
3974 | Instruction *I = UnwindDest->getFirstNonPHI(); | |||
3975 | Assert(I->isEHPad() && !isa<LandingPadInst>(I),do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("CleanupReturnInst must unwind to an EH block which is not a " "landingpad.", &CRI); return; } } while (false) | |||
3976 | "CleanupReturnInst must unwind to an EH block which is not a "do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("CleanupReturnInst must unwind to an EH block which is not a " "landingpad.", &CRI); return; } } while (false) | |||
3977 | "landingpad.",do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("CleanupReturnInst must unwind to an EH block which is not a " "landingpad.", &CRI); return; } } while (false) | |||
3978 | &CRI)do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("CleanupReturnInst must unwind to an EH block which is not a " "landingpad.", &CRI); return; } } while (false); | |||
3979 | } | |||
3980 | ||||
3981 | visitTerminator(CRI); | |||
3982 | } | |||
3983 | ||||
3984 | void Verifier::verifyDominatesUse(Instruction &I, unsigned i) { | |||
3985 | Instruction *Op = cast<Instruction>(I.getOperand(i)); | |||
3986 | // If the we have an invalid invoke, don't try to compute the dominance. | |||
3987 | // We already reject it in the invoke specific checks and the dominance | |||
3988 | // computation doesn't handle multiple edges. | |||
3989 | if (InvokeInst *II = dyn_cast<InvokeInst>(Op)) { | |||
3990 | if (II->getNormalDest() == II->getUnwindDest()) | |||
3991 | return; | |||
3992 | } | |||
3993 | ||||
3994 | // Quick check whether the def has already been encountered in the same block. | |||
3995 | // PHI nodes are not checked to prevent accepting preceding PHIs, because PHI | |||
3996 | // uses are defined to happen on the incoming edge, not at the instruction. | |||
3997 | // | |||
3998 | // FIXME: If this operand is a MetadataAsValue (wrapping a LocalAsMetadata) | |||
3999 | // wrapping an SSA value, assert that we've already encountered it. See | |||
4000 | // related FIXME in Mapper::mapLocalAsMetadata in ValueMapper.cpp. | |||
4001 | if (!isa<PHINode>(I) && InstsInThisBlock.count(Op)) | |||
4002 | return; | |||
4003 | ||||
4004 | const Use &U = I.getOperandUse(i); | |||
4005 | Assert(DT.dominates(Op, U),do { if (!(DT.dominates(Op, U))) { CheckFailed("Instruction does not dominate all uses!" , Op, &I); return; } } while (false) | |||
4006 | "Instruction does not dominate all uses!", Op, &I)do { if (!(DT.dominates(Op, U))) { CheckFailed("Instruction does not dominate all uses!" , Op, &I); return; } } while (false); | |||
4007 | } | |||
4008 | ||||
4009 | void Verifier::visitDereferenceableMetadata(Instruction& I, MDNode* MD) { | |||
4010 | Assert(I.getType()->isPointerTy(), "dereferenceable, dereferenceable_or_null "do { if (!(I.getType()->isPointerTy())) { CheckFailed("dereferenceable, dereferenceable_or_null " "apply only to pointer types", &I); return; } } while (false ) | |||
4011 | "apply only to pointer types", &I)do { if (!(I.getType()->isPointerTy())) { CheckFailed("dereferenceable, dereferenceable_or_null " "apply only to pointer types", &I); return; } } while (false ); | |||
4012 | Assert((isa<LoadInst>(I) || isa<IntToPtrInst>(I)),do { if (!((isa<LoadInst>(I) || isa<IntToPtrInst> (I)))) { CheckFailed("dereferenceable, dereferenceable_or_null apply only to load" " and inttoptr instructions, use attributes for calls or invokes" , &I); return; } } while (false) | |||
4013 | "dereferenceable, dereferenceable_or_null apply only to load"do { if (!((isa<LoadInst>(I) || isa<IntToPtrInst> (I)))) { CheckFailed("dereferenceable, dereferenceable_or_null apply only to load" " and inttoptr instructions, use attributes for calls or invokes" , &I); return; } } while (false) | |||
4014 | " and inttoptr instructions, use attributes for calls or invokes", &I)do { if (!((isa<LoadInst>(I) || isa<IntToPtrInst> (I)))) { CheckFailed("dereferenceable, dereferenceable_or_null apply only to load" " and inttoptr instructions, use attributes for calls or invokes" , &I); return; } } while (false); | |||
4015 | Assert(MD->getNumOperands() == 1, "dereferenceable, dereferenceable_or_null "do { if (!(MD->getNumOperands() == 1)) { CheckFailed("dereferenceable, dereferenceable_or_null " "take one operand!", &I); return; } } while (false) | |||
4016 | "take one operand!", &I)do { if (!(MD->getNumOperands() == 1)) { CheckFailed("dereferenceable, dereferenceable_or_null " "take one operand!", &I); return; } } while (false); | |||
4017 | ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(MD->getOperand(0)); | |||
4018 | Assert(CI && CI->getType()->isIntegerTy(64), "dereferenceable, "do { if (!(CI && CI->getType()->isIntegerTy(64) )) { CheckFailed("dereferenceable, " "dereferenceable_or_null metadata value must be an i64!" , &I); return; } } while (false) | |||
4019 | "dereferenceable_or_null metadata value must be an i64!", &I)do { if (!(CI && CI->getType()->isIntegerTy(64) )) { CheckFailed("dereferenceable, " "dereferenceable_or_null metadata value must be an i64!" , &I); return; } } while (false); | |||
4020 | } | |||
4021 | ||||
4022 | void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) { | |||
4023 | Assert(MD->getNumOperands() >= 2,do { if (!(MD->getNumOperands() >= 2)) { CheckFailed("!prof annotations should have no less than 2 operands" , MD); return; } } while (false) | |||
4024 | "!prof annotations should have no less than 2 operands", MD)do { if (!(MD->getNumOperands() >= 2)) { CheckFailed("!prof annotations should have no less than 2 operands" , MD); return; } } while (false); | |||
4025 | ||||
4026 | // Check first operand. | |||
4027 | Assert(MD->getOperand(0) != nullptr, "first operand should not be null", MD)do { if (!(MD->getOperand(0) != nullptr)) { CheckFailed("first operand should not be null" , MD); return; } } while (false); | |||
4028 | Assert(isa<MDString>(MD->getOperand(0)),do { if (!(isa<MDString>(MD->getOperand(0)))) { CheckFailed ("expected string with name of the !prof annotation", MD); return ; } } while (false) | |||
4029 | "expected string with name of the !prof annotation", MD)do { if (!(isa<MDString>(MD->getOperand(0)))) { CheckFailed ("expected string with name of the !prof annotation", MD); return ; } } while (false); | |||
4030 | MDString *MDS = cast<MDString>(MD->getOperand(0)); | |||
4031 | StringRef ProfName = MDS->getString(); | |||
4032 | ||||
4033 | // Check consistency of !prof branch_weights metadata. | |||
4034 | if (ProfName.equals("branch_weights")) { | |||
4035 | unsigned ExpectedNumOperands = 0; | |||
4036 | if (BranchInst *BI = dyn_cast<BranchInst>(&I)) | |||
4037 | ExpectedNumOperands = BI->getNumSuccessors(); | |||
4038 | else if (SwitchInst *SI = dyn_cast<SwitchInst>(&I)) | |||
4039 | ExpectedNumOperands = SI->getNumSuccessors(); | |||
4040 | else if (isa<CallInst>(&I) || isa<InvokeInst>(&I)) | |||
4041 | ExpectedNumOperands = 1; | |||
4042 | else if (IndirectBrInst *IBI = dyn_cast<IndirectBrInst>(&I)) | |||
4043 | ExpectedNumOperands = IBI->getNumDestinations(); | |||
4044 | else if (isa<SelectInst>(&I)) | |||
4045 | ExpectedNumOperands = 2; | |||
4046 | else | |||
4047 | CheckFailed("!prof branch_weights are not allowed for this instruction", | |||
4048 | MD); | |||
4049 | ||||
4050 | Assert(MD->getNumOperands() == 1 + ExpectedNumOperands,do { if (!(MD->getNumOperands() == 1 + ExpectedNumOperands )) { CheckFailed("Wrong number of operands", MD); return; } } while (false) | |||
4051 | "Wrong number of operands", MD)do { if (!(MD->getNumOperands() == 1 + ExpectedNumOperands )) { CheckFailed("Wrong number of operands", MD); return; } } while (false); | |||
4052 | for (unsigned i = 1; i < MD->getNumOperands(); ++i) { | |||
4053 | auto &MDO = MD->getOperand(i); | |||
4054 | Assert(MDO, "second operand should not be null", MD)do { if (!(MDO)) { CheckFailed("second operand should not be null" , MD); return; } } while (false); | |||
4055 | Assert(mdconst::dyn_extract<ConstantInt>(MDO),do { if (!(mdconst::dyn_extract<ConstantInt>(MDO))) { CheckFailed ("!prof brunch_weights operand is not a const int"); return; } } while (false) | |||
4056 | "!prof brunch_weights operand is not a const int")do { if (!(mdconst::dyn_extract<ConstantInt>(MDO))) { CheckFailed ("!prof brunch_weights operand is not a const int"); return; } } while (false); | |||
4057 | } | |||
4058 | } | |||
4059 | } | |||
4060 | ||||
4061 | /// verifyInstruction - Verify that an instruction is well formed. | |||
4062 | /// | |||
4063 | void Verifier::visitInstruction(Instruction &I) { | |||
4064 | BasicBlock *BB = I.getParent(); | |||
4065 | Assert(BB, "Instruction not embedded in basic block!", &I)do { if (!(BB)) { CheckFailed("Instruction not embedded in basic block!" , &I); return; } } while (false); | |||
4066 | ||||
4067 | if (!isa<PHINode>(I)) { // Check that non-phi nodes are not self referential | |||
4068 | for (User *U : I.users()) { | |||
4069 | Assert(U != (User *)&I || !DT.isReachableFromEntry(BB),do { if (!(U != (User *)&I || !DT.isReachableFromEntry(BB ))) { CheckFailed("Only PHI nodes may reference their own value!" , &I); return; } } while (false) | |||
4070 | "Only PHI nodes may reference their own value!", &I)do { if (!(U != (User *)&I || !DT.isReachableFromEntry(BB ))) { CheckFailed("Only PHI nodes may reference their own value!" , &I); return; } } while (false); | |||
4071 | } | |||
4072 | } | |||
4073 | ||||
4074 | // Check that void typed values don't have names | |||
4075 | Assert(!I.getType()->isVoidTy() || !I.hasName(),do { if (!(!I.getType()->isVoidTy() || !I.hasName())) { CheckFailed ("Instruction has a name, but provides a void value!", &I ); return; } } while (false) | |||
4076 | "Instruction has a name, but provides a void value!", &I)do { if (!(!I.getType()->isVoidTy() || !I.hasName())) { CheckFailed ("Instruction has a name, but provides a void value!", &I ); return; } } while (false); | |||
4077 | ||||
4078 | // Check that the return value of the instruction is either void or a legal | |||
4079 | // value type. | |||
4080 | Assert(I.getType()->isVoidTy() || I.getType()->isFirstClassType(),do { if (!(I.getType()->isVoidTy() || I.getType()->isFirstClassType ())) { CheckFailed("Instruction returns a non-scalar type!", & I); return; } } while (false) | |||
4081 | "Instruction returns a non-scalar type!", &I)do { if (!(I.getType()->isVoidTy() || I.getType()->isFirstClassType ())) { CheckFailed("Instruction returns a non-scalar type!", & I); return; } } while (false); | |||
4082 | ||||
4083 | // Check that the instruction doesn't produce metadata. Calls are already | |||
4084 | // checked against the callee type. | |||
4085 | Assert(!I.getType()->isMetadataTy() || isa<CallInst>(I) || isa<InvokeInst>(I),do { if (!(!I.getType()->isMetadataTy() || isa<CallInst >(I) || isa<InvokeInst>(I))) { CheckFailed("Invalid use of metadata!" , &I); return; } } while (false) | |||
4086 | "Invalid use of metadata!", &I)do { if (!(!I.getType()->isMetadataTy() || isa<CallInst >(I) || isa<InvokeInst>(I))) { CheckFailed("Invalid use of metadata!" , &I); return; } } while (false); | |||
4087 | ||||
4088 | // Check that all uses of the instruction, if they are instructions | |||
4089 | // themselves, actually have parent basic blocks. If the use is not an | |||
4090 | // instruction, it is an error! | |||
4091 | for (Use &U : I.uses()) { | |||
4092 | if (Instruction *Used = dyn_cast<Instruction>(U.getUser())) | |||
4093 | Assert(Used->getParent() != nullptr,do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing" " instruction not embedded in a basic block!", &I, Used) ; return; } } while (false) | |||
4094 | "Instruction referencing"do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing" " instruction not embedded in a basic block!", &I, Used) ; return; } } while (false) | |||
4095 | " instruction not embedded in a basic block!",do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing" " instruction not embedded in a basic block!", &I, Used) ; return; } } while (false) | |||
4096 | &I, Used)do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing" " instruction not embedded in a basic block!", &I, Used) ; return; } } while (false); | |||
4097 | else { | |||
4098 | CheckFailed("Use of instruction is not an instruction!", U); | |||
4099 | return; | |||
4100 | } | |||
4101 | } | |||
4102 | ||||
4103 | // Get a pointer to the call base of the instruction if it is some form of | |||
4104 | // call. | |||
4105 | const CallBase *CBI = dyn_cast<CallBase>(&I); | |||
4106 | ||||
4107 | for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) { | |||
4108 | Assert(I.getOperand(i) != nullptr, "Instruction has null operand!", &I)do { if (!(I.getOperand(i) != nullptr)) { CheckFailed("Instruction has null operand!" , &I); return; } } while (false); | |||
4109 | ||||
4110 | // Check to make sure that only first-class-values are operands to | |||
4111 | // instructions. | |||
4112 | if (!I.getOperand(i)->getType()->isFirstClassType()) { | |||
4113 | Assert(false, "Instruction operands must be first-class values!", &I)do { if (!(false)) { CheckFailed("Instruction operands must be first-class values!" , &I); return; } } while (false); | |||
4114 | } | |||
4115 | ||||
4116 | if (Function *F = dyn_cast<Function>(I.getOperand(i))) { | |||
4117 | // Check to make sure that the "address of" an intrinsic function is never | |||
4118 | // taken. | |||
4119 | Assert(!F->isIntrinsic() ||do { if (!(!F->isIntrinsic() || (CBI && &CBI-> getCalledOperandUse() == &I.getOperandUse(i)))) { CheckFailed ("Cannot take the address of an intrinsic!", &I); return; } } while (false) | |||
4120 | (CBI && &CBI->getCalledOperandUse() == &I.getOperandUse(i)),do { if (!(!F->isIntrinsic() || (CBI && &CBI-> getCalledOperandUse() == &I.getOperandUse(i)))) { CheckFailed ("Cannot take the address of an intrinsic!", &I); return; } } while (false) | |||
4121 | "Cannot take the address of an intrinsic!", &I)do { if (!(!F->isIntrinsic() || (CBI && &CBI-> getCalledOperandUse() == &I.getOperandUse(i)))) { CheckFailed ("Cannot take the address of an intrinsic!", &I); return; } } while (false); | |||
4122 | Assert(do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic ::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint || F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch )) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, " "statepoint, coro_resume or coro_destroy", &I); return; } } while (false) | |||
4123 | !F->isIntrinsic() || isa<CallInst>(I) ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic ::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint || F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch )) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, " "statepoint, coro_resume or coro_destroy", &I); return; } } while (false) | |||
4124 | F->getIntrinsicID() == Intrinsic::donothing ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic ::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint || F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch )) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, " "statepoint, coro_resume or coro_destroy", &I); return; } } while (false) | |||
4125 | F->getIntrinsicID() == Intrinsic::coro_resume ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic ::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint || F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch )) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, " "statepoint, coro_resume or coro_destroy", &I); return; } } while (false) | |||
4126 | F->getIntrinsicID() == Intrinsic::coro_destroy ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic ::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint || F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch )) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, " "statepoint, coro_resume or coro_destroy", &I); return; } } while (false) | |||
4127 | F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic ::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint || F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch )) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, " "statepoint, coro_resume or coro_destroy", &I); return; } } while (false) | |||
4128 | F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic ::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint || F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch )) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, " "statepoint, coro_resume or coro_destroy", &I); return; } } while (false) | |||
4129 | F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic ::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint || F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch )) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, " "statepoint, coro_resume or coro_destroy", &I); return; } } while (false) | |||
4130 | F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch,do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic ::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint || F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch )) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, " "statepoint, coro_resume or coro_destroy", &I); return; } } while (false) | |||
4131 | "Cannot invoke an intrinsic other than donothing, patchpoint, "do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic ::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint || F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch )) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, " "statepoint, coro_resume or coro_destroy", &I); return; } } while (false) | |||
4132 | "statepoint, coro_resume or coro_destroy",do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic ::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint || F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch )) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, " "statepoint, coro_resume or coro_destroy", &I); return; } } while (false) | |||
4133 | &I)do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic ::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint || F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch )) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, " "statepoint, coro_resume or coro_destroy", &I); return; } } while (false); | |||
4134 | Assert(F->getParent() == &M, "Referencing function in another module!",do { if (!(F->getParent() == &M)) { CheckFailed("Referencing function in another module!" , &I, &M, F, F->getParent()); return; } } while (false ) | |||
4135 | &I, &M, F, F->getParent())do { if (!(F->getParent() == &M)) { CheckFailed("Referencing function in another module!" , &I, &M, F, F->getParent()); return; } } while (false ); | |||
4136 | } else if (BasicBlock *OpBB = dyn_cast<BasicBlock>(I.getOperand(i))) { | |||
4137 | Assert(OpBB->getParent() == BB->getParent(),do { if (!(OpBB->getParent() == BB->getParent())) { CheckFailed ("Referring to a basic block in another function!", &I); return ; } } while (false) | |||
4138 | "Referring to a basic block in another function!", &I)do { if (!(OpBB->getParent() == BB->getParent())) { CheckFailed ("Referring to a basic block in another function!", &I); return ; } } while (false); | |||
4139 | } else if (Argument *OpArg = dyn_cast<Argument>(I.getOperand(i))) { | |||
4140 | Assert(OpArg->getParent() == BB->getParent(),do { if (!(OpArg->getParent() == BB->getParent())) { CheckFailed ("Referring to an argument in another function!", &I); return ; } } while (false) | |||
4141 | "Referring to an argument in another function!", &I)do { if (!(OpArg->getParent() == BB->getParent())) { CheckFailed ("Referring to an argument in another function!", &I); return ; } } while (false); | |||
4142 | } else if (GlobalValue *GV = dyn_cast<GlobalValue>(I.getOperand(i))) { | |||
4143 | Assert(GV->getParent() == &M, "Referencing global in another module!", &I,do { if (!(GV->getParent() == &M)) { CheckFailed("Referencing global in another module!" , &I, &M, GV, GV->getParent()); return; } } while ( false) | |||
4144 | &M, GV, GV->getParent())do { if (!(GV->getParent() == &M)) { CheckFailed("Referencing global in another module!" , &I, &M, GV, GV->getParent()); return; } } while ( false); | |||
4145 | } else if (isa<Instruction>(I.getOperand(i))) { | |||
4146 | verifyDominatesUse(I, i); | |||
4147 | } else if (isa<InlineAsm>(I.getOperand(i))) { | |||
4148 | Assert(CBI && &CBI->getCalledOperandUse() == &I.getOperandUse(i),do { if (!(CBI && &CBI->getCalledOperandUse() == &I.getOperandUse(i))) { CheckFailed("Cannot take the address of an inline asm!" , &I); return; } } while (false) | |||
4149 | "Cannot take the address of an inline asm!", &I)do { if (!(CBI && &CBI->getCalledOperandUse() == &I.getOperandUse(i))) { CheckFailed("Cannot take the |