File: | lib/IR/Verifier.cpp |
Warning: | line 2332, column 7 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 | const DataLayout &DL; | |||
123 | LLVMContext &Context; | |||
124 | ||||
125 | /// Track the brokenness of the module while recursively visiting. | |||
126 | bool Broken = false; | |||
127 | /// Broken debug info can be "recovered" from by stripping the debug info. | |||
128 | bool BrokenDebugInfo = false; | |||
129 | /// Whether to treat broken debug info as an error. | |||
130 | bool TreatBrokenDebugInfoAsError = true; | |||
131 | ||||
132 | explicit VerifierSupport(raw_ostream *OS, const Module &M) | |||
133 | : OS(OS), M(M), MST(&M), DL(M.getDataLayout()), Context(M.getContext()) {} | |||
134 | ||||
135 | private: | |||
136 | void Write(const Module *M) { | |||
137 | *OS << "; ModuleID = '" << M->getModuleIdentifier() << "'\n"; | |||
138 | } | |||
139 | ||||
140 | void Write(const Value *V) { | |||
141 | if (V) | |||
142 | Write(*V); | |||
143 | } | |||
144 | ||||
145 | void Write(const Value &V) { | |||
146 | if (isa<Instruction>(V)) { | |||
147 | V.print(*OS, MST); | |||
148 | *OS << '\n'; | |||
149 | } else { | |||
150 | V.printAsOperand(*OS, true, MST); | |||
151 | *OS << '\n'; | |||
152 | } | |||
153 | } | |||
154 | ||||
155 | void Write(const Metadata *MD) { | |||
156 | if (!MD) | |||
157 | return; | |||
158 | MD->print(*OS, MST, &M); | |||
159 | *OS << '\n'; | |||
160 | } | |||
161 | ||||
162 | template <class T> void Write(const MDTupleTypedArrayWrapper<T> &MD) { | |||
163 | Write(MD.get()); | |||
164 | } | |||
165 | ||||
166 | void Write(const NamedMDNode *NMD) { | |||
167 | if (!NMD) | |||
168 | return; | |||
169 | NMD->print(*OS, MST); | |||
170 | *OS << '\n'; | |||
171 | } | |||
172 | ||||
173 | void Write(Type *T) { | |||
174 | if (!T) | |||
175 | return; | |||
176 | *OS << ' ' << *T; | |||
177 | } | |||
178 | ||||
179 | void Write(const Comdat *C) { | |||
180 | if (!C) | |||
181 | return; | |||
182 | *OS << *C; | |||
183 | } | |||
184 | ||||
185 | void Write(const APInt *AI) { | |||
186 | if (!AI) | |||
187 | return; | |||
188 | *OS << *AI << '\n'; | |||
189 | } | |||
190 | ||||
191 | void Write(const unsigned i) { *OS << i << '\n'; } | |||
192 | ||||
193 | template <typename T> void Write(ArrayRef<T> Vs) { | |||
194 | for (const T &V : Vs) | |||
195 | Write(V); | |||
196 | } | |||
197 | ||||
198 | template <typename T1, typename... Ts> | |||
199 | void WriteTs(const T1 &V1, const Ts &... Vs) { | |||
200 | Write(V1); | |||
201 | WriteTs(Vs...); | |||
202 | } | |||
203 | ||||
204 | template <typename... Ts> void WriteTs() {} | |||
205 | ||||
206 | public: | |||
207 | /// A check failed, so printout out the condition and the message. | |||
208 | /// | |||
209 | /// This provides a nice place to put a breakpoint if you want to see why | |||
210 | /// something is not correct. | |||
211 | void CheckFailed(const Twine &Message) { | |||
212 | if (OS) | |||
213 | *OS << Message << '\n'; | |||
214 | Broken = true; | |||
215 | } | |||
216 | ||||
217 | /// A check failed (with values to print). | |||
218 | /// | |||
219 | /// This calls the Message-only version so that the above is easier to set a | |||
220 | /// breakpoint on. | |||
221 | template <typename T1, typename... Ts> | |||
222 | void CheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs) { | |||
223 | CheckFailed(Message); | |||
224 | if (OS) | |||
225 | WriteTs(V1, Vs...); | |||
226 | } | |||
227 | ||||
228 | /// A debug info check failed. | |||
229 | void DebugInfoCheckFailed(const Twine &Message) { | |||
230 | if (OS) | |||
231 | *OS << Message << '\n'; | |||
232 | Broken |= TreatBrokenDebugInfoAsError; | |||
233 | BrokenDebugInfo = true; | |||
234 | } | |||
235 | ||||
236 | /// A debug info check failed (with values to print). | |||
237 | template <typename T1, typename... Ts> | |||
238 | void DebugInfoCheckFailed(const Twine &Message, const T1 &V1, | |||
239 | const Ts &... Vs) { | |||
240 | DebugInfoCheckFailed(Message); | |||
241 | if (OS) | |||
242 | WriteTs(V1, Vs...); | |||
243 | } | |||
244 | }; | |||
245 | ||||
246 | } // namespace llvm | |||
247 | ||||
248 | namespace { | |||
249 | ||||
250 | class Verifier : public InstVisitor<Verifier>, VerifierSupport { | |||
251 | friend class InstVisitor<Verifier>; | |||
252 | ||||
253 | DominatorTree DT; | |||
254 | ||||
255 | /// When verifying a basic block, keep track of all of the | |||
256 | /// instructions we have seen so far. | |||
257 | /// | |||
258 | /// This allows us to do efficient dominance checks for the case when an | |||
259 | /// instruction has an operand that is an instruction in the same block. | |||
260 | SmallPtrSet<Instruction *, 16> InstsInThisBlock; | |||
261 | ||||
262 | /// Keep track of the metadata nodes that have been checked already. | |||
263 | SmallPtrSet<const Metadata *, 32> MDNodes; | |||
264 | ||||
265 | /// Keep track which DISubprogram is attached to which function. | |||
266 | DenseMap<const DISubprogram *, const Function *> DISubprogramAttachments; | |||
267 | ||||
268 | /// Track all DICompileUnits visited. | |||
269 | SmallPtrSet<const Metadata *, 2> CUVisited; | |||
270 | ||||
271 | /// The result type for a landingpad. | |||
272 | Type *LandingPadResultTy; | |||
273 | ||||
274 | /// Whether we've seen a call to @llvm.localescape in this function | |||
275 | /// already. | |||
276 | bool SawFrameEscape; | |||
277 | ||||
278 | /// Whether the current function has a DISubprogram attached to it. | |||
279 | bool HasDebugInfo = false; | |||
280 | ||||
281 | /// Whether source was present on the first DIFile encountered in each CU. | |||
282 | DenseMap<const DICompileUnit *, bool> HasSourceDebugInfo; | |||
283 | ||||
284 | /// Stores the count of how many objects were passed to llvm.localescape for a | |||
285 | /// given function and the largest index passed to llvm.localrecover. | |||
286 | DenseMap<Function *, std::pair<unsigned, unsigned>> FrameEscapeInfo; | |||
287 | ||||
288 | // Maps catchswitches and cleanuppads that unwind to siblings to the | |||
289 | // terminators that indicate the unwind, used to detect cycles therein. | |||
290 | MapVector<Instruction *, Instruction *> SiblingFuncletInfo; | |||
291 | ||||
292 | /// Cache of constants visited in search of ConstantExprs. | |||
293 | SmallPtrSet<const Constant *, 32> ConstantExprVisited; | |||
294 | ||||
295 | /// Cache of declarations of the llvm.experimental.deoptimize.<ty> intrinsic. | |||
296 | SmallVector<const Function *, 4> DeoptimizeDeclarations; | |||
297 | ||||
298 | // Verify that this GlobalValue is only used in this module. | |||
299 | // This map is used to avoid visiting uses twice. We can arrive at a user | |||
300 | // twice, if they have multiple operands. In particular for very large | |||
301 | // constant expressions, we can arrive at a particular user many times. | |||
302 | SmallPtrSet<const Value *, 32> GlobalValueVisited; | |||
303 | ||||
304 | // Keeps track of duplicate function argument debug info. | |||
305 | SmallVector<const DILocalVariable *, 16> DebugFnArgs; | |||
306 | ||||
307 | TBAAVerifier TBAAVerifyHelper; | |||
308 | ||||
309 | void checkAtomicMemAccessSize(Type *Ty, const Instruction *I); | |||
310 | ||||
311 | public: | |||
312 | explicit Verifier(raw_ostream *OS, bool ShouldTreatBrokenDebugInfoAsError, | |||
313 | const Module &M) | |||
314 | : VerifierSupport(OS, M), LandingPadResultTy(nullptr), | |||
315 | SawFrameEscape(false), TBAAVerifyHelper(this) { | |||
316 | TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError; | |||
317 | } | |||
318 | ||||
319 | bool hasBrokenDebugInfo() const { return BrokenDebugInfo; } | |||
320 | ||||
321 | bool verify(const Function &F) { | |||
322 | 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-9~svn360410/lib/IR/Verifier.cpp" , 323, __PRETTY_FUNCTION__)) | |||
323 | "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-9~svn360410/lib/IR/Verifier.cpp" , 323, __PRETTY_FUNCTION__)); | |||
324 | ||||
325 | // First ensure the function is well-enough formed to compute dominance | |||
326 | // information, and directly compute a dominance tree. We don't rely on the | |||
327 | // pass manager to provide this as it isolates us from a potentially | |||
328 | // out-of-date dominator tree and makes it significantly more complex to run | |||
329 | // this code outside of a pass manager. | |||
330 | // FIXME: It's really gross that we have to cast away constness here. | |||
331 | if (!F.empty()) | |||
332 | DT.recalculate(const_cast<Function &>(F)); | |||
333 | ||||
334 | for (const BasicBlock &BB : F) { | |||
335 | if (!BB.empty() && BB.back().isTerminator()) | |||
336 | continue; | |||
337 | ||||
338 | if (OS) { | |||
339 | *OS << "Basic Block in function '" << F.getName() | |||
340 | << "' does not have terminator!\n"; | |||
341 | BB.printAsOperand(*OS, true, MST); | |||
342 | *OS << "\n"; | |||
343 | } | |||
344 | return false; | |||
345 | } | |||
346 | ||||
347 | Broken = false; | |||
348 | // FIXME: We strip const here because the inst visitor strips const. | |||
349 | visit(const_cast<Function &>(F)); | |||
350 | verifySiblingFuncletUnwinds(); | |||
351 | InstsInThisBlock.clear(); | |||
352 | DebugFnArgs.clear(); | |||
353 | LandingPadResultTy = nullptr; | |||
354 | SawFrameEscape = false; | |||
355 | SiblingFuncletInfo.clear(); | |||
356 | ||||
357 | return !Broken; | |||
358 | } | |||
359 | ||||
360 | /// Verify the module that this instance of \c Verifier was initialized with. | |||
361 | bool verify() { | |||
362 | Broken = false; | |||
363 | ||||
364 | // Collect all declarations of the llvm.experimental.deoptimize intrinsic. | |||
365 | for (const Function &F : M) | |||
366 | if (F.getIntrinsicID() == Intrinsic::experimental_deoptimize) | |||
367 | DeoptimizeDeclarations.push_back(&F); | |||
368 | ||||
369 | // Now that we've visited every function, verify that we never asked to | |||
370 | // recover a frame index that wasn't escaped. | |||
371 | verifyFrameRecoverIndices(); | |||
372 | for (const GlobalVariable &GV : M.globals()) | |||
373 | visitGlobalVariable(GV); | |||
374 | ||||
375 | for (const GlobalAlias &GA : M.aliases()) | |||
376 | visitGlobalAlias(GA); | |||
377 | ||||
378 | for (const NamedMDNode &NMD : M.named_metadata()) | |||
379 | visitNamedMDNode(NMD); | |||
380 | ||||
381 | for (const StringMapEntry<Comdat> &SMEC : M.getComdatSymbolTable()) | |||
382 | visitComdat(SMEC.getValue()); | |||
383 | ||||
384 | visitModuleFlags(M); | |||
385 | visitModuleIdents(M); | |||
386 | visitModuleCommandLines(M); | |||
387 | ||||
388 | verifyCompileUnits(); | |||
389 | ||||
390 | verifyDeoptimizeCallingConvs(); | |||
391 | DISubprogramAttachments.clear(); | |||
392 | return !Broken; | |||
393 | } | |||
394 | ||||
395 | private: | |||
396 | // Verification methods... | |||
397 | void visitGlobalValue(const GlobalValue &GV); | |||
398 | void visitGlobalVariable(const GlobalVariable &GV); | |||
399 | void visitGlobalAlias(const GlobalAlias &GA); | |||
400 | void visitAliaseeSubExpr(const GlobalAlias &A, const Constant &C); | |||
401 | void visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias *> &Visited, | |||
402 | const GlobalAlias &A, const Constant &C); | |||
403 | void visitNamedMDNode(const NamedMDNode &NMD); | |||
404 | void visitMDNode(const MDNode &MD); | |||
405 | void visitMetadataAsValue(const MetadataAsValue &MD, Function *F); | |||
406 | void visitValueAsMetadata(const ValueAsMetadata &MD, Function *F); | |||
407 | void visitComdat(const Comdat &C); | |||
408 | void visitModuleIdents(const Module &M); | |||
409 | void visitModuleCommandLines(const Module &M); | |||
410 | void visitModuleFlags(const Module &M); | |||
411 | void visitModuleFlag(const MDNode *Op, | |||
412 | DenseMap<const MDString *, const MDNode *> &SeenIDs, | |||
413 | SmallVectorImpl<const MDNode *> &Requirements); | |||
414 | void visitModuleFlagCGProfileEntry(const MDOperand &MDO); | |||
415 | void visitFunction(const Function &F); | |||
416 | void visitBasicBlock(BasicBlock &BB); | |||
417 | void visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty); | |||
418 | void visitDereferenceableMetadata(Instruction &I, MDNode *MD); | |||
419 | ||||
420 | template <class Ty> bool isValidMetadataArray(const MDTuple &N); | |||
421 | #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N); | |||
422 | #include "llvm/IR/Metadata.def" | |||
423 | void visitDIScope(const DIScope &N); | |||
424 | void visitDIVariable(const DIVariable &N); | |||
425 | void visitDILexicalBlockBase(const DILexicalBlockBase &N); | |||
426 | void visitDITemplateParameter(const DITemplateParameter &N); | |||
427 | ||||
428 | void visitTemplateParams(const MDNode &N, const Metadata &RawParams); | |||
429 | ||||
430 | // InstVisitor overrides... | |||
431 | using InstVisitor<Verifier>::visit; | |||
432 | void visit(Instruction &I); | |||
433 | ||||
434 | void visitTruncInst(TruncInst &I); | |||
435 | void visitZExtInst(ZExtInst &I); | |||
436 | void visitSExtInst(SExtInst &I); | |||
437 | void visitFPTruncInst(FPTruncInst &I); | |||
438 | void visitFPExtInst(FPExtInst &I); | |||
439 | void visitFPToUIInst(FPToUIInst &I); | |||
440 | void visitFPToSIInst(FPToSIInst &I); | |||
441 | void visitUIToFPInst(UIToFPInst &I); | |||
442 | void visitSIToFPInst(SIToFPInst &I); | |||
443 | void visitIntToPtrInst(IntToPtrInst &I); | |||
444 | void visitPtrToIntInst(PtrToIntInst &I); | |||
445 | void visitBitCastInst(BitCastInst &I); | |||
446 | void visitAddrSpaceCastInst(AddrSpaceCastInst &I); | |||
447 | void visitPHINode(PHINode &PN); | |||
448 | void visitCallBase(CallBase &Call); | |||
449 | void visitUnaryOperator(UnaryOperator &U); | |||
450 | void visitBinaryOperator(BinaryOperator &B); | |||
451 | void visitICmpInst(ICmpInst &IC); | |||
452 | void visitFCmpInst(FCmpInst &FC); | |||
453 | void visitExtractElementInst(ExtractElementInst &EI); | |||
454 | void visitInsertElementInst(InsertElementInst &EI); | |||
455 | void visitShuffleVectorInst(ShuffleVectorInst &EI); | |||
456 | void visitVAArgInst(VAArgInst &VAA) { visitInstruction(VAA); } | |||
457 | void visitCallInst(CallInst &CI); | |||
458 | void visitInvokeInst(InvokeInst &II); | |||
459 | void visitGetElementPtrInst(GetElementPtrInst &GEP); | |||
460 | void visitLoadInst(LoadInst &LI); | |||
461 | void visitStoreInst(StoreInst &SI); | |||
462 | void verifyDominatesUse(Instruction &I, unsigned i); | |||
463 | void visitInstruction(Instruction &I); | |||
464 | void visitTerminator(Instruction &I); | |||
465 | void visitBranchInst(BranchInst &BI); | |||
466 | void visitReturnInst(ReturnInst &RI); | |||
467 | void visitSwitchInst(SwitchInst &SI); | |||
468 | void visitIndirectBrInst(IndirectBrInst &BI); | |||
469 | void visitCallBrInst(CallBrInst &CBI); | |||
470 | void visitSelectInst(SelectInst &SI); | |||
471 | void visitUserOp1(Instruction &I); | |||
472 | void visitUserOp2(Instruction &I) { visitUserOp1(I); } | |||
473 | void visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call); | |||
474 | void visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI); | |||
475 | void visitDbgIntrinsic(StringRef Kind, DbgVariableIntrinsic &DII); | |||
476 | void visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI); | |||
477 | void visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI); | |||
478 | void visitAtomicRMWInst(AtomicRMWInst &RMWI); | |||
479 | void visitFenceInst(FenceInst &FI); | |||
480 | void visitAllocaInst(AllocaInst &AI); | |||
481 | void visitExtractValueInst(ExtractValueInst &EVI); | |||
482 | void visitInsertValueInst(InsertValueInst &IVI); | |||
483 | void visitEHPadPredecessors(Instruction &I); | |||
484 | void visitLandingPadInst(LandingPadInst &LPI); | |||
485 | void visitResumeInst(ResumeInst &RI); | |||
486 | void visitCatchPadInst(CatchPadInst &CPI); | |||
487 | void visitCatchReturnInst(CatchReturnInst &CatchReturn); | |||
488 | void visitCleanupPadInst(CleanupPadInst &CPI); | |||
489 | void visitFuncletPadInst(FuncletPadInst &FPI); | |||
490 | void visitCatchSwitchInst(CatchSwitchInst &CatchSwitch); | |||
491 | void visitCleanupReturnInst(CleanupReturnInst &CRI); | |||
492 | ||||
493 | void verifySwiftErrorCall(CallBase &Call, const Value *SwiftErrorVal); | |||
494 | void verifySwiftErrorValue(const Value *SwiftErrorVal); | |||
495 | void verifyMustTailCall(CallInst &CI); | |||
496 | bool performTypeCheck(Intrinsic::ID ID, Function *F, Type *Ty, int VT, | |||
497 | unsigned ArgNo, std::string &Suffix); | |||
498 | bool verifyAttributeCount(AttributeList Attrs, unsigned Params); | |||
499 | void verifyAttributeTypes(AttributeSet Attrs, bool IsFunction, | |||
500 | const Value *V); | |||
501 | void verifyParameterAttrs(AttributeSet Attrs, Type *Ty, const Value *V); | |||
502 | void verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs, | |||
503 | const Value *V, bool IsIntrinsic); | |||
504 | void verifyFunctionMetadata(ArrayRef<std::pair<unsigned, MDNode *>> MDs); | |||
505 | ||||
506 | void visitConstantExprsRecursively(const Constant *EntryC); | |||
507 | void visitConstantExpr(const ConstantExpr *CE); | |||
508 | void verifyStatepoint(const CallBase &Call); | |||
509 | void verifyFrameRecoverIndices(); | |||
510 | void verifySiblingFuncletUnwinds(); | |||
511 | ||||
512 | void verifyFragmentExpression(const DbgVariableIntrinsic &I); | |||
513 | template <typename ValueOrMetadata> | |||
514 | void verifyFragmentExpression(const DIVariable &V, | |||
515 | DIExpression::FragmentInfo Fragment, | |||
516 | ValueOrMetadata *Desc); | |||
517 | void verifyFnArgs(const DbgVariableIntrinsic &I); | |||
518 | ||||
519 | /// Module-level debug info verification... | |||
520 | void verifyCompileUnits(); | |||
521 | ||||
522 | /// Module-level verification that all @llvm.experimental.deoptimize | |||
523 | /// declarations share the same calling convention. | |||
524 | void verifyDeoptimizeCallingConvs(); | |||
525 | ||||
526 | /// Verify all-or-nothing property of DIFile source attribute within a CU. | |||
527 | void verifySourceDebugInfo(const DICompileUnit &U, const DIFile &F); | |||
528 | }; | |||
529 | ||||
530 | } // end anonymous namespace | |||
531 | ||||
532 | /// We know that cond should be true, if not print an error message. | |||
533 | #define Assert(C, ...)do { if (!(C)) { CheckFailed(...); return; } } while (false) \ | |||
534 | do { if (!(C)) { CheckFailed(__VA_ARGS__); return; } } while (false) | |||
535 | ||||
536 | /// We know that a debug info condition should be true, if not print | |||
537 | /// an error message. | |||
538 | #define AssertDI(C, ...)do { if (!(C)) { DebugInfoCheckFailed(...); return; } } while (false) \ | |||
539 | do { if (!(C)) { DebugInfoCheckFailed(__VA_ARGS__); return; } } while (false) | |||
540 | ||||
541 | void Verifier::visit(Instruction &I) { | |||
542 | for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) | |||
543 | Assert(I.getOperand(i) != nullptr, "Operand is null", &I)do { if (!(I.getOperand(i) != nullptr)) { CheckFailed("Operand is null" , &I); return; } } while (false); | |||
544 | InstVisitor<Verifier>::visit(I); | |||
545 | } | |||
546 | ||||
547 | // Helper to recursively iterate over indirect users. By | |||
548 | // returning false, the callback can ask to stop recursing | |||
549 | // further. | |||
550 | static void forEachUser(const Value *User, | |||
551 | SmallPtrSet<const Value *, 32> &Visited, | |||
552 | llvm::function_ref<bool(const Value *)> Callback) { | |||
553 | if (!Visited.insert(User).second) | |||
554 | return; | |||
555 | for (const Value *TheNextUser : User->materialized_users()) | |||
556 | if (Callback(TheNextUser)) | |||
557 | forEachUser(TheNextUser, Visited, Callback); | |||
558 | } | |||
559 | ||||
560 | void Verifier::visitGlobalValue(const GlobalValue &GV) { | |||
561 | 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) | |||
562 | "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); | |||
563 | ||||
564 | Assert(GV.getAlignment() <= Value::MaximumAlignment,do { if (!(GV.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &GV ); return; } } while (false) | |||
565 | "huge alignment values are unsupported", &GV)do { if (!(GV.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &GV ); return; } } while (false); | |||
566 | 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) | |||
567 | "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); | |||
568 | ||||
569 | if (GV.hasAppendingLinkage()) { | |||
570 | const GlobalVariable *GVar = dyn_cast<GlobalVariable>(&GV); | |||
571 | Assert(GVar && GVar->getValueType()->isArrayTy(),do { if (!(GVar && GVar->getValueType()->isArrayTy ())) { CheckFailed("Only global arrays can have appending linkage!" , GVar); return; } } while (false) | |||
572 | "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); | |||
573 | } | |||
574 | ||||
575 | if (GV.isDeclarationForLinker()) | |||
576 | 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); | |||
577 | ||||
578 | if (GV.hasDLLImportStorageClass()) { | |||
579 | Assert(!GV.isDSOLocal(),do { if (!(!GV.isDSOLocal())) { CheckFailed("GlobalValue with DLLImport Storage is dso_local!" , &GV); return; } } while (false) | |||
580 | "GlobalValue with DLLImport Storage is dso_local!", &GV)do { if (!(!GV.isDSOLocal())) { CheckFailed("GlobalValue with DLLImport Storage is dso_local!" , &GV); return; } } while (false); | |||
581 | ||||
582 | 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) | |||
583 | GV.hasAvailableExternallyLinkage(),do { if (!((GV.isDeclaration() && GV.hasExternalLinkage ()) || GV.hasAvailableExternallyLinkage())) { CheckFailed("Global is marked as dllimport, but not external" , &GV); return; } } while (false) | |||
584 | "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); | |||
585 | } | |||
586 | ||||
587 | if (GV.hasLocalLinkage()) | |||
588 | Assert(GV.isDSOLocal(),do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with private or internal linkage must be dso_local!" , &GV); return; } } while (false) | |||
589 | "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) | |||
590 | &GV)do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with private or internal linkage must be dso_local!" , &GV); return; } } while (false); | |||
591 | ||||
592 | if (!GV.hasDefaultVisibility() && !GV.hasExternalWeakLinkage()) | |||
593 | Assert(GV.isDSOLocal(),do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with non default visibility must be dso_local!" , &GV); return; } } while (false) | |||
594 | "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); | |||
595 | ||||
596 | forEachUser(&GV, GlobalValueVisited, [&](const Value *V) -> bool { | |||
597 | if (const Instruction *I = dyn_cast<Instruction>(V)) { | |||
598 | if (!I->getParent() || !I->getParent()->getParent()) | |||
599 | CheckFailed("Global is referenced by parentless instruction!", &GV, &M, | |||
600 | I); | |||
601 | else if (I->getParent()->getParent()->getParent() != &M) | |||
602 | CheckFailed("Global is referenced in a different module!", &GV, &M, I, | |||
603 | I->getParent()->getParent(), | |||
604 | I->getParent()->getParent()->getParent()); | |||
605 | return false; | |||
606 | } else if (const Function *F = dyn_cast<Function>(V)) { | |||
607 | if (F->getParent() != &M) | |||
608 | CheckFailed("Global is used by function in a different module", &GV, &M, | |||
609 | F, F->getParent()); | |||
610 | return false; | |||
611 | } | |||
612 | return true; | |||
613 | }); | |||
614 | } | |||
615 | ||||
616 | void Verifier::visitGlobalVariable(const GlobalVariable &GV) { | |||
617 | if (GV.hasInitializer()) { | |||
618 | 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) | |||
619 | "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) | |||
620 | "variable type!",do { if (!(GV.getInitializer()->getType() == GV.getValueType ())) { CheckFailed("Global variable initializer type does not match global " "variable type!", &GV); return; } } while (false) | |||
621 | &GV)do { if (!(GV.getInitializer()->getType() == GV.getValueType ())) { CheckFailed("Global variable initializer type does not match global " "variable type!", &GV); return; } } while (false); | |||
622 | // If the global has common linkage, it must have a zero initializer and | |||
623 | // cannot be constant. | |||
624 | if (GV.hasCommonLinkage()) { | |||
625 | Assert(GV.getInitializer()->isNullValue(),do { if (!(GV.getInitializer()->isNullValue())) { CheckFailed ("'common' global must have a zero initializer!", &GV); return ; } } while (false) | |||
626 | "'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); | |||
627 | 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) | |||
628 | &GV)do { if (!(!GV.isConstant())) { CheckFailed("'common' global may not be marked constant!" , &GV); return; } } while (false); | |||
629 | 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); | |||
630 | } | |||
631 | } | |||
632 | ||||
633 | if (GV.hasName() && (GV.getName() == "llvm.global_ctors" || | |||
634 | GV.getName() == "llvm.global_dtors")) { | |||
635 | Assert(!GV.hasInitializer() || GV.hasAppendingLinkage(),do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage())) { CheckFailed("invalid linkage for intrinsic global variable" , &GV); return; } } while (false) | |||
636 | "invalid linkage for intrinsic global variable", &GV)do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage())) { CheckFailed("invalid linkage for intrinsic global variable" , &GV); return; } } while (false); | |||
637 | // Don't worry about emitting an error for it not being an array, | |||
638 | // visitGlobalValue will complain on appending non-array. | |||
639 | if (ArrayType *ATy = dyn_cast<ArrayType>(GV.getValueType())) { | |||
640 | StructType *STy = dyn_cast<StructType>(ATy->getElementType()); | |||
641 | PointerType *FuncPtrTy = | |||
642 | FunctionType::get(Type::getVoidTy(Context), false)-> | |||
643 | getPointerTo(DL.getProgramAddressSpace()); | |||
644 | // FIXME: Reject the 2-field form in LLVM 4.0. | |||
645 | 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) | |||
646 | (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) | |||
647 | 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) | |||
648 | 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) | |||
649 | "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); | |||
650 | if (STy->getNumElements() == 3) { | |||
651 | Type *ETy = STy->getTypeAtIndex(2); | |||
652 | Assert(ETy->isPointerTy() &&do { if (!(ETy->isPointerTy() && cast<PointerType >(ETy)->getElementType()->isIntegerTy(8))) { CheckFailed ("wrong type for intrinsic global variable", &GV); return ; } } while (false) | |||
653 | 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) | |||
654 | "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); | |||
655 | } | |||
656 | } | |||
657 | } | |||
658 | ||||
659 | if (GV.hasName() && (GV.getName() == "llvm.used" || | |||
660 | GV.getName() == "llvm.compiler.used")) { | |||
661 | Assert(!GV.hasInitializer() || GV.hasAppendingLinkage(),do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage())) { CheckFailed("invalid linkage for intrinsic global variable" , &GV); return; } } while (false) | |||
662 | "invalid linkage for intrinsic global variable", &GV)do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage())) { CheckFailed("invalid linkage for intrinsic global variable" , &GV); return; } } while (false); | |||
663 | Type *GVType = GV.getValueType(); | |||
664 | if (ArrayType *ATy = dyn_cast<ArrayType>(GVType)) { | |||
665 | PointerType *PTy = dyn_cast<PointerType>(ATy->getElementType()); | |||
666 | Assert(PTy, "wrong type for intrinsic global variable", &GV)do { if (!(PTy)) { CheckFailed("wrong type for intrinsic global variable" , &GV); return; } } while (false); | |||
667 | if (GV.hasInitializer()) { | |||
668 | const Constant *Init = GV.getInitializer(); | |||
669 | const ConstantArray *InitArray = dyn_cast<ConstantArray>(Init); | |||
670 | Assert(InitArray, "wrong initalizer for intrinsic global variable",do { if (!(InitArray)) { CheckFailed("wrong initalizer for intrinsic global variable" , Init); return; } } while (false) | |||
671 | Init)do { if (!(InitArray)) { CheckFailed("wrong initalizer for intrinsic global variable" , Init); return; } } while (false); | |||
672 | for (Value *Op : InitArray->operands()) { | |||
673 | Value *V = Op->stripPointerCastsNoFollowAliases(); | |||
674 | 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) | |||
675 | isa<GlobalAlias>(V),do { if (!(isa<GlobalVariable>(V) || isa<Function> (V) || isa<GlobalAlias>(V))) { CheckFailed("invalid llvm.used member" , V); return; } } while (false) | |||
676 | "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); | |||
677 | 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); | |||
678 | } | |||
679 | } | |||
680 | } | |||
681 | } | |||
682 | ||||
683 | // Visit any debug info attachments. | |||
684 | SmallVector<MDNode *, 1> MDs; | |||
685 | GV.getMetadata(LLVMContext::MD_dbg, MDs); | |||
686 | for (auto *MD : MDs) { | |||
687 | if (auto *GVE = dyn_cast<DIGlobalVariableExpression>(MD)) | |||
688 | visitDIGlobalVariableExpression(*GVE); | |||
689 | else | |||
690 | 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) | |||
691 | "DIGlobalVariableExpression")do { if (!(false)) { DebugInfoCheckFailed("!dbg attachment of global variable must be a " "DIGlobalVariableExpression"); return; } } while (false); | |||
692 | } | |||
693 | ||||
694 | if (!GV.hasInitializer()) { | |||
695 | visitGlobalValue(GV); | |||
696 | return; | |||
697 | } | |||
698 | ||||
699 | // Walk any aggregate initializers looking for bitcasts between address spaces | |||
700 | visitConstantExprsRecursively(GV.getInitializer()); | |||
701 | ||||
702 | visitGlobalValue(GV); | |||
703 | } | |||
704 | ||||
705 | void Verifier::visitAliaseeSubExpr(const GlobalAlias &GA, const Constant &C) { | |||
706 | SmallPtrSet<const GlobalAlias*, 4> Visited; | |||
707 | Visited.insert(&GA); | |||
708 | visitAliaseeSubExpr(Visited, GA, C); | |||
709 | } | |||
710 | ||||
711 | void Verifier::visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias*> &Visited, | |||
712 | const GlobalAlias &GA, const Constant &C) { | |||
713 | if (const auto *GV = dyn_cast<GlobalValue>(&C)) { | |||
714 | Assert(!GV->isDeclarationForLinker(), "Alias must point to a definition",do { if (!(!GV->isDeclarationForLinker())) { CheckFailed("Alias must point to a definition" , &GA); return; } } while (false) | |||
715 | &GA)do { if (!(!GV->isDeclarationForLinker())) { CheckFailed("Alias must point to a definition" , &GA); return; } } while (false); | |||
716 | ||||
717 | if (const auto *GA2 = dyn_cast<GlobalAlias>(GV)) { | |||
718 | 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); | |||
719 | ||||
720 | 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) | |||
721 | &GA)do { if (!(!GA2->isInterposable())) { CheckFailed("Alias cannot point to an interposable alias" , &GA); return; } } while (false); | |||
722 | } else { | |||
723 | // Only continue verifying subexpressions of GlobalAliases. | |||
724 | // Do not recurse into global initializers. | |||
725 | return; | |||
726 | } | |||
727 | } | |||
728 | ||||
729 | if (const auto *CE = dyn_cast<ConstantExpr>(&C)) | |||
730 | visitConstantExprsRecursively(CE); | |||
731 | ||||
732 | for (const Use &U : C.operands()) { | |||
733 | Value *V = &*U; | |||
734 | if (const auto *GA2 = dyn_cast<GlobalAlias>(V)) | |||
735 | visitAliaseeSubExpr(Visited, GA, *GA2->getAliasee()); | |||
736 | else if (const auto *C2 = dyn_cast<Constant>(V)) | |||
737 | visitAliaseeSubExpr(Visited, GA, *C2); | |||
738 | } | |||
739 | } | |||
740 | ||||
741 | void Verifier::visitGlobalAlias(const GlobalAlias &GA) { | |||
742 | 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) | |||
743 | "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) | |||
744 | "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) | |||
745 | &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); | |||
746 | const Constant *Aliasee = GA.getAliasee(); | |||
747 | Assert(Aliasee, "Aliasee cannot be NULL!", &GA)do { if (!(Aliasee)) { CheckFailed("Aliasee cannot be NULL!", &GA); return; } } while (false); | |||
748 | Assert(GA.getType() == Aliasee->getType(),do { if (!(GA.getType() == Aliasee->getType())) { CheckFailed ("Alias and aliasee types should match!", &GA); return; } } while (false) | |||
749 | "Alias and aliasee types should match!", &GA)do { if (!(GA.getType() == Aliasee->getType())) { CheckFailed ("Alias and aliasee types should match!", &GA); return; } } while (false); | |||
750 | ||||
751 | 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) | |||
752 | "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); | |||
753 | ||||
754 | visitAliaseeSubExpr(GA, *Aliasee); | |||
755 | ||||
756 | visitGlobalValue(GA); | |||
757 | } | |||
758 | ||||
759 | void Verifier::visitNamedMDNode(const NamedMDNode &NMD) { | |||
760 | // There used to be various other llvm.dbg.* nodes, but we don't support | |||
761 | // upgrading them and we want to reserve the namespace for future uses. | |||
762 | if (NMD.getName().startswith("llvm.dbg.")) | |||
763 | 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) | |||
764 | "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) | |||
765 | &NMD)do { if (!(NMD.getName() == "llvm.dbg.cu")) { DebugInfoCheckFailed ("unrecognized named metadata node in the llvm.dbg namespace" , &NMD); return; } } while (false); | |||
766 | for (const MDNode *MD : NMD.operands()) { | |||
767 | if (NMD.getName() == "llvm.dbg.cu") | |||
768 | 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 ); | |||
769 | ||||
770 | if (!MD) | |||
771 | continue; | |||
772 | ||||
773 | visitMDNode(*MD); | |||
774 | } | |||
775 | } | |||
776 | ||||
777 | void Verifier::visitMDNode(const MDNode &MD) { | |||
778 | // Only visit each node once. Metadata can be mutually recursive, so this | |||
779 | // avoids infinite recursion here, as well as being an optimization. | |||
780 | if (!MDNodes.insert(&MD).second) | |||
781 | return; | |||
782 | ||||
783 | switch (MD.getMetadataID()) { | |||
784 | default: | |||
785 | llvm_unreachable("Invalid MDNode subclass")::llvm::llvm_unreachable_internal("Invalid MDNode subclass", "/build/llvm-toolchain-snapshot-9~svn360410/lib/IR/Verifier.cpp" , 785); | |||
786 | case Metadata::MDTupleKind: | |||
787 | break; | |||
788 | #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \ | |||
789 | case Metadata::CLASS##Kind: \ | |||
790 | visit##CLASS(cast<CLASS>(MD)); \ | |||
791 | break; | |||
792 | #include "llvm/IR/Metadata.def" | |||
793 | } | |||
794 | ||||
795 | for (const Metadata *Op : MD.operands()) { | |||
796 | if (!Op) | |||
797 | continue; | |||
798 | 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) | |||
799 | &MD, Op)do { if (!(!isa<LocalAsMetadata>(Op))) { CheckFailed("Invalid operand for global metadata!" , &MD, Op); return; } } while (false); | |||
800 | if (auto *N = dyn_cast<MDNode>(Op)) { | |||
801 | visitMDNode(*N); | |||
802 | continue; | |||
803 | } | |||
804 | if (auto *V = dyn_cast<ValueAsMetadata>(Op)) { | |||
805 | visitValueAsMetadata(*V, nullptr); | |||
806 | continue; | |||
807 | } | |||
808 | } | |||
809 | ||||
810 | // Check these last, so we diagnose problems in operands first. | |||
811 | Assert(!MD.isTemporary(), "Expected no forward declarations!", &MD)do { if (!(!MD.isTemporary())) { CheckFailed("Expected no forward declarations!" , &MD); return; } } while (false); | |||
812 | Assert(MD.isResolved(), "All nodes should be resolved!", &MD)do { if (!(MD.isResolved())) { CheckFailed("All nodes should be resolved!" , &MD); return; } } while (false); | |||
813 | } | |||
814 | ||||
815 | void Verifier::visitValueAsMetadata(const ValueAsMetadata &MD, Function *F) { | |||
816 | Assert(MD.getValue(), "Expected valid value", &MD)do { if (!(MD.getValue())) { CheckFailed("Expected valid value" , &MD); return; } } while (false); | |||
817 | Assert(!MD.getValue()->getType()->isMetadataTy(),do { if (!(!MD.getValue()->getType()->isMetadataTy())) { CheckFailed("Unexpected metadata round-trip through values", &MD, MD.getValue()); return; } } while (false) | |||
818 | "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); | |||
819 | ||||
820 | auto *L = dyn_cast<LocalAsMetadata>(&MD); | |||
821 | if (!L) | |||
822 | return; | |||
823 | ||||
824 | 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); | |||
825 | ||||
826 | // If this was an instruction, bb, or argument, verify that it is in the | |||
827 | // function that we expect. | |||
828 | Function *ActualF = nullptr; | |||
829 | if (Instruction *I = dyn_cast<Instruction>(L->getValue())) { | |||
830 | 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); | |||
831 | ActualF = I->getParent()->getParent(); | |||
832 | } else if (BasicBlock *BB = dyn_cast<BasicBlock>(L->getValue())) | |||
833 | ActualF = BB->getParent(); | |||
834 | else if (Argument *A = dyn_cast<Argument>(L->getValue())) | |||
835 | ActualF = A->getParent(); | |||
836 | 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-9~svn360410/lib/IR/Verifier.cpp" , 836, __PRETTY_FUNCTION__)); | |||
837 | ||||
838 | 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); | |||
839 | } | |||
840 | ||||
841 | void Verifier::visitMetadataAsValue(const MetadataAsValue &MDV, Function *F) { | |||
842 | Metadata *MD = MDV.getMetadata(); | |||
843 | if (auto *N = dyn_cast<MDNode>(MD)) { | |||
844 | visitMDNode(*N); | |||
845 | return; | |||
846 | } | |||
847 | ||||
848 | // Only visit each node once. Metadata can be mutually recursive, so this | |||
849 | // avoids infinite recursion here, as well as being an optimization. | |||
850 | if (!MDNodes.insert(MD).second) | |||
851 | return; | |||
852 | ||||
853 | if (auto *V = dyn_cast<ValueAsMetadata>(MD)) | |||
854 | visitValueAsMetadata(*V, F); | |||
855 | } | |||
856 | ||||
857 | static bool isType(const Metadata *MD) { return !MD || isa<DIType>(MD); } | |||
858 | static bool isScope(const Metadata *MD) { return !MD || isa<DIScope>(MD); } | |||
859 | static bool isDINode(const Metadata *MD) { return !MD || isa<DINode>(MD); } | |||
860 | ||||
861 | void Verifier::visitDILocation(const DILocation &N) { | |||
862 | 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) | |||
863 | "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); | |||
864 | if (auto *IA = N.getRawInlinedAt()) | |||
865 | 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); | |||
866 | if (auto *SP = dyn_cast<DISubprogram>(N.getRawScope())) | |||
867 | 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); | |||
868 | } | |||
869 | ||||
870 | void Verifier::visitGenericDINode(const GenericDINode &N) { | |||
871 | AssertDI(N.getTag(), "invalid tag", &N)do { if (!(N.getTag())) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false); | |||
872 | } | |||
873 | ||||
874 | void Verifier::visitDIScope(const DIScope &N) { | |||
875 | if (auto *F = N.getRawFile()) | |||
876 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | |||
877 | } | |||
878 | ||||
879 | void Verifier::visitDISubrange(const DISubrange &N) { | |||
880 | 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); | |||
881 | auto Count = N.getCount(); | |||
882 | 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) | |||
883 | &N)do { if (!(Count)) { DebugInfoCheckFailed("Count must either be a signed constant or a DIVariable" , &N); return; } } while (false); | |||
884 | AssertDI(!Count.is<ConstantInt*>() ||do { if (!(!Count.is<ConstantInt*>() || Count.get<ConstantInt *>()->getSExtValue() >= -1)) { DebugInfoCheckFailed( "invalid subrange count", &N); return; } } while (false) | |||
885 | Count.get<ConstantInt*>()->getSExtValue() >= -1,do { if (!(!Count.is<ConstantInt*>() || Count.get<ConstantInt *>()->getSExtValue() >= -1)) { DebugInfoCheckFailed( "invalid subrange count", &N); return; } } while (false) | |||
886 | "invalid subrange count", &N)do { if (!(!Count.is<ConstantInt*>() || Count.get<ConstantInt *>()->getSExtValue() >= -1)) { DebugInfoCheckFailed( "invalid subrange count", &N); return; } } while (false); | |||
887 | } | |||
888 | ||||
889 | void Verifier::visitDIEnumerator(const DIEnumerator &N) { | |||
890 | 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); | |||
891 | } | |||
892 | ||||
893 | void Verifier::visitDIBasicType(const DIBasicType &N) { | |||
894 | 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) | |||
895 | 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) | |||
896 | "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); | |||
897 | AssertDI(!(N.isBigEndian() && N.isLittleEndian()) ,do { if (!(!(N.isBigEndian() && N.isLittleEndian()))) { DebugInfoCheckFailed("has conflicting flags", &N); return ; } } while (false) | |||
898 | "has conflicting flags", &N)do { if (!(!(N.isBigEndian() && N.isLittleEndian()))) { DebugInfoCheckFailed("has conflicting flags", &N); return ; } } while (false); | |||
899 | } | |||
900 | ||||
901 | void Verifier::visitDIDerivedType(const DIDerivedType &N) { | |||
902 | // Common scope checks. | |||
903 | visitDIScope(N); | |||
904 | ||||
905 | 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) | |||
906 | 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) | |||
907 | 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) | |||
908 | 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) | |||
909 | 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) | |||
910 | 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) | |||
911 | 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) | |||
912 | 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) | |||
913 | 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) | |||
914 | 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) | |||
915 | 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) | |||
916 | 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) | |||
917 | "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); | |||
918 | if (N.getTag() == dwarf::DW_TAG_ptr_to_member_type) { | |||
919 | 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) | |||
920 | N.getRawExtraData())do { if (!(isType(N.getRawExtraData()))) { DebugInfoCheckFailed ("invalid pointer to member type", &N, N.getRawExtraData( )); return; } } while (false); | |||
921 | } | |||
922 | ||||
923 | AssertDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope())do { if (!(isScope(N.getRawScope()))) { DebugInfoCheckFailed( "invalid scope", &N, N.getRawScope()); return; } } while ( false); | |||
924 | AssertDI(isType(N.getRawBaseType()), "invalid base type", &N,do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed ("invalid base type", &N, N.getRawBaseType()); return; } } while (false) | |||
925 | N.getRawBaseType())do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed ("invalid base type", &N, N.getRawBaseType()); return; } } while (false); | |||
926 | ||||
927 | if (N.getDWARFAddressSpace()) { | |||
928 | 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) | |||
929 | 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) | |||
930 | 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) | |||
931 | "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) | |||
932 | &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); | |||
933 | } | |||
934 | } | |||
935 | ||||
936 | /// Detect mutually exclusive flags. | |||
937 | static bool hasConflictingReferenceFlags(unsigned Flags) { | |||
938 | return ((Flags & DINode::FlagLValueReference) && | |||
939 | (Flags & DINode::FlagRValueReference)) || | |||
940 | ((Flags & DINode::FlagTypePassByValue) && | |||
941 | (Flags & DINode::FlagTypePassByReference)); | |||
942 | } | |||
943 | ||||
944 | void Verifier::visitTemplateParams(const MDNode &N, const Metadata &RawParams) { | |||
945 | auto *Params = dyn_cast<MDTuple>(&RawParams); | |||
946 | AssertDI(Params, "invalid template params", &N, &RawParams)do { if (!(Params)) { DebugInfoCheckFailed("invalid template params" , &N, &RawParams); return; } } while (false); | |||
947 | for (Metadata *Op : Params->operands()) { | |||
948 | AssertDI(Op && isa<DITemplateParameter>(Op), "invalid template parameter",do { if (!(Op && isa<DITemplateParameter>(Op))) { DebugInfoCheckFailed("invalid template parameter", &N, Params, Op); return; } } while (false) | |||
949 | &N, Params, Op)do { if (!(Op && isa<DITemplateParameter>(Op))) { DebugInfoCheckFailed("invalid template parameter", &N, Params, Op); return; } } while (false); | |||
950 | } | |||
951 | } | |||
952 | ||||
953 | void Verifier::visitDICompositeType(const DICompositeType &N) { | |||
954 | // Common scope checks. | |||
955 | visitDIScope(N); | |||
956 | ||||
957 | 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) | |||
958 | 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) | |||
959 | 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) | |||
960 | 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) | |||
961 | 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) | |||
962 | 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) | |||
963 | "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); | |||
964 | ||||
965 | AssertDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope())do { if (!(isScope(N.getRawScope()))) { DebugInfoCheckFailed( "invalid scope", &N, N.getRawScope()); return; } } while ( false); | |||
966 | AssertDI(isType(N.getRawBaseType()), "invalid base type", &N,do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed ("invalid base type", &N, N.getRawBaseType()); return; } } while (false) | |||
967 | N.getRawBaseType())do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed ("invalid base type", &N, N.getRawBaseType()); return; } } while (false); | |||
968 | ||||
969 | 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) | |||
970 | "invalid composite elements", &N, N.getRawElements())do { if (!(!N.getRawElements() || isa<MDTuple>(N.getRawElements ()))) { DebugInfoCheckFailed("invalid composite elements", & N, N.getRawElements()); return; } } while (false); | |||
971 | AssertDI(isType(N.getRawVTableHolder()), "invalid vtable holder", &N,do { if (!(isType(N.getRawVTableHolder()))) { DebugInfoCheckFailed ("invalid vtable holder", &N, N.getRawVTableHolder()); return ; } } while (false) | |||
972 | N.getRawVTableHolder())do { if (!(isType(N.getRawVTableHolder()))) { DebugInfoCheckFailed ("invalid vtable holder", &N, N.getRawVTableHolder()); return ; } } while (false); | |||
973 | AssertDI(!hasConflictingReferenceFlags(N.getFlags()),do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ) | |||
974 | "invalid reference flags", &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ); | |||
975 | ||||
976 | if (N.isVector()) { | |||
977 | const DINodeArray Elements = N.getElements(); | |||
978 | 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) | |||
979 | 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) | |||
980 | "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); | |||
981 | } | |||
982 | ||||
983 | if (auto *Params = N.getRawTemplateParams()) | |||
984 | visitTemplateParams(N, *Params); | |||
985 | ||||
986 | if (N.getTag() == dwarf::DW_TAG_class_type || | |||
987 | N.getTag() == dwarf::DW_TAG_union_type) { | |||
988 | 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) | |||
989 | "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); | |||
990 | } | |||
991 | ||||
992 | if (auto *D = N.getRawDiscriminator()) { | |||
993 | 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) | |||
994 | "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); | |||
995 | } | |||
996 | } | |||
997 | ||||
998 | void Verifier::visitDISubroutineType(const DISubroutineType &N) { | |||
999 | 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); | |||
1000 | if (auto *Types = N.getRawTypeArray()) { | |||
1001 | AssertDI(isa<MDTuple>(Types), "invalid composite elements", &N, Types)do { if (!(isa<MDTuple>(Types))) { DebugInfoCheckFailed ("invalid composite elements", &N, Types); return; } } while (false); | |||
1002 | for (Metadata *Ty : N.getTypeArray()->operands()) { | |||
1003 | 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); | |||
1004 | } | |||
1005 | } | |||
1006 | AssertDI(!hasConflictingReferenceFlags(N.getFlags()),do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ) | |||
1007 | "invalid reference flags", &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ); | |||
1008 | } | |||
1009 | ||||
1010 | void Verifier::visitDIFile(const DIFile &N) { | |||
1011 | 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); | |||
1012 | Optional<DIFile::ChecksumInfo<StringRef>> Checksum = N.getChecksum(); | |||
1013 | if (Checksum) { | |||
1014 | AssertDI(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last,do { if (!(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last )) { DebugInfoCheckFailed("invalid checksum kind", &N); return ; } } while (false) | |||
1015 | "invalid checksum kind", &N)do { if (!(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last )) { DebugInfoCheckFailed("invalid checksum kind", &N); return ; } } while (false); | |||
1016 | size_t Size; | |||
1017 | switch (Checksum->Kind) { | |||
1018 | case DIFile::CSK_MD5: | |||
1019 | Size = 32; | |||
1020 | break; | |||
1021 | case DIFile::CSK_SHA1: | |||
1022 | Size = 40; | |||
1023 | break; | |||
1024 | } | |||
1025 | AssertDI(Checksum->Value.size() == Size, "invalid checksum length", &N)do { if (!(Checksum->Value.size() == Size)) { DebugInfoCheckFailed ("invalid checksum length", &N); return; } } while (false ); | |||
1026 | 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) | |||
1027 | "invalid checksum", &N)do { if (!(Checksum->Value.find_if_not(llvm::isHexDigit) == StringRef::npos)) { DebugInfoCheckFailed("invalid checksum", &N); return; } } while (false); | |||
1028 | } | |||
1029 | } | |||
1030 | ||||
1031 | void Verifier::visitDICompileUnit(const DICompileUnit &N) { | |||
1032 | AssertDI(N.isDistinct(), "compile units must be distinct", &N)do { if (!(N.isDistinct())) { DebugInfoCheckFailed("compile units must be distinct" , &N); return; } } while (false); | |||
1033 | 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); | |||
1034 | ||||
1035 | // Don't bother verifying the compilation directory or producer string | |||
1036 | // as those could be empty. | |||
1037 | 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) | |||
1038 | N.getRawFile())do { if (!(N.getRawFile() && isa<DIFile>(N.getRawFile ()))) { DebugInfoCheckFailed("invalid file", &N, N.getRawFile ()); return; } } while (false); | |||
1039 | AssertDI(!N.getFile()->getFilename().empty(), "invalid filename", &N,do { if (!(!N.getFile()->getFilename().empty())) { DebugInfoCheckFailed ("invalid filename", &N, N.getFile()); return; } } while ( false) | |||
1040 | N.getFile())do { if (!(!N.getFile()->getFilename().empty())) { DebugInfoCheckFailed ("invalid filename", &N, N.getFile()); return; } } while ( false); | |||
1041 | ||||
1042 | verifySourceDebugInfo(N, *N.getFile()); | |||
1043 | ||||
1044 | AssertDI((N.getEmissionKind() <= DICompileUnit::LastEmissionKind),do { if (!((N.getEmissionKind() <= DICompileUnit::LastEmissionKind ))) { DebugInfoCheckFailed("invalid emission kind", &N); return ; } } while (false) | |||
1045 | "invalid emission kind", &N)do { if (!((N.getEmissionKind() <= DICompileUnit::LastEmissionKind ))) { DebugInfoCheckFailed("invalid emission kind", &N); return ; } } while (false); | |||
1046 | ||||
1047 | if (auto *Array = N.getRawEnumTypes()) { | |||
1048 | AssertDI(isa<MDTuple>(Array), "invalid enum list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed ("invalid enum list", &N, Array); return; } } while (false ); | |||
1049 | for (Metadata *Op : N.getEnumTypes()->operands()) { | |||
1050 | auto *Enum = dyn_cast_or_null<DICompositeType>(Op); | |||
1051 | 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) | |||
1052 | "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); | |||
1053 | } | |||
1054 | } | |||
1055 | if (auto *Array = N.getRawRetainedTypes()) { | |||
1056 | 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); | |||
1057 | for (Metadata *Op : N.getRetainedTypes()->operands()) { | |||
1058 | 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) | |||
1059 | (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) | |||
1060 | !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) | |||
1061 | "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); | |||
1062 | } | |||
1063 | } | |||
1064 | if (auto *Array = N.getRawGlobalVariables()) { | |||
1065 | 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); | |||
1066 | for (Metadata *Op : N.getGlobalVariables()->operands()) { | |||
1067 | AssertDI(Op && (isa<DIGlobalVariableExpression>(Op)),do { if (!(Op && (isa<DIGlobalVariableExpression> (Op)))) { DebugInfoCheckFailed("invalid global variable ref", &N, Op); return; } } while (false) | |||
1068 | "invalid global variable ref", &N, Op)do { if (!(Op && (isa<DIGlobalVariableExpression> (Op)))) { DebugInfoCheckFailed("invalid global variable ref", &N, Op); return; } } while (false); | |||
1069 | } | |||
1070 | } | |||
1071 | if (auto *Array = N.getRawImportedEntities()) { | |||
1072 | 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); | |||
1073 | for (Metadata *Op : N.getImportedEntities()->operands()) { | |||
1074 | 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) | |||
1075 | &N, Op)do { if (!(Op && isa<DIImportedEntity>(Op))) { DebugInfoCheckFailed ("invalid imported entity ref", &N, Op); return; } } while (false); | |||
1076 | } | |||
1077 | } | |||
1078 | if (auto *Array = N.getRawMacros()) { | |||
1079 | AssertDI(isa<MDTuple>(Array), "invalid macro list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed ("invalid macro list", &N, Array); return; } } while (false ); | |||
1080 | for (Metadata *Op : N.getMacros()->operands()) { | |||
1081 | 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); | |||
1082 | } | |||
1083 | } | |||
1084 | CUVisited.insert(&N); | |||
1085 | } | |||
1086 | ||||
1087 | void Verifier::visitDISubprogram(const DISubprogram &N) { | |||
1088 | 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); | |||
1089 | AssertDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope())do { if (!(isScope(N.getRawScope()))) { DebugInfoCheckFailed( "invalid scope", &N, N.getRawScope()); return; } } while ( false); | |||
1090 | if (auto *F = N.getRawFile()) | |||
1091 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | |||
1092 | else | |||
1093 | 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); | |||
1094 | if (auto *T = N.getRawType()) | |||
1095 | AssertDI(isa<DISubroutineType>(T), "invalid subroutine type", &N, T)do { if (!(isa<DISubroutineType>(T))) { DebugInfoCheckFailed ("invalid subroutine type", &N, T); return; } } while (false ); | |||
1096 | AssertDI(isType(N.getRawContainingType()), "invalid containing type", &N,do { if (!(isType(N.getRawContainingType()))) { DebugInfoCheckFailed ("invalid containing type", &N, N.getRawContainingType()) ; return; } } while (false) | |||
1097 | N.getRawContainingType())do { if (!(isType(N.getRawContainingType()))) { DebugInfoCheckFailed ("invalid containing type", &N, N.getRawContainingType()) ; return; } } while (false); | |||
1098 | if (auto *Params = N.getRawTemplateParams()) | |||
1099 | visitTemplateParams(N, *Params); | |||
1100 | if (auto *S = N.getRawDeclaration()) | |||
1101 | 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) | |||
1102 | "invalid subprogram declaration", &N, S)do { if (!(isa<DISubprogram>(S) && !cast<DISubprogram >(S)->isDefinition())) { DebugInfoCheckFailed("invalid subprogram declaration" , &N, S); return; } } while (false); | |||
1103 | if (auto *RawNode = N.getRawRetainedNodes()) { | |||
1104 | auto *Node = dyn_cast<MDTuple>(RawNode); | |||
1105 | AssertDI(Node, "invalid retained nodes list", &N, RawNode)do { if (!(Node)) { DebugInfoCheckFailed("invalid retained nodes list" , &N, RawNode); return; } } while (false); | |||
1106 | for (Metadata *Op : Node->operands()) { | |||
1107 | 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) | |||
1108 | "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) | |||
1109 | &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); | |||
1110 | } | |||
1111 | } | |||
1112 | AssertDI(!hasConflictingReferenceFlags(N.getFlags()),do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ) | |||
1113 | "invalid reference flags", &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ); | |||
1114 | ||||
1115 | auto *Unit = N.getRawUnit(); | |||
1116 | if (N.isDefinition()) { | |||
1117 | // Subprogram definitions (not part of the type hierarchy). | |||
1118 | AssertDI(N.isDistinct(), "subprogram definitions must be distinct", &N)do { if (!(N.isDistinct())) { DebugInfoCheckFailed("subprogram definitions must be distinct" , &N); return; } } while (false); | |||
1119 | 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); | |||
1120 | AssertDI(isa<DICompileUnit>(Unit), "invalid unit type", &N, Unit)do { if (!(isa<DICompileUnit>(Unit))) { DebugInfoCheckFailed ("invalid unit type", &N, Unit); return; } } while (false ); | |||
1121 | if (N.getFile()) | |||
1122 | verifySourceDebugInfo(*N.getUnit(), *N.getFile()); | |||
1123 | } else { | |||
1124 | // Subprogram declarations (part of the type hierarchy). | |||
1125 | 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); | |||
1126 | } | |||
1127 | ||||
1128 | if (auto *RawThrownTypes = N.getRawThrownTypes()) { | |||
1129 | auto *ThrownTypes = dyn_cast<MDTuple>(RawThrownTypes); | |||
1130 | AssertDI(ThrownTypes, "invalid thrown types list", &N, RawThrownTypes)do { if (!(ThrownTypes)) { DebugInfoCheckFailed("invalid thrown types list" , &N, RawThrownTypes); return; } } while (false); | |||
1131 | for (Metadata *Op : ThrownTypes->operands()) | |||
1132 | 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) | |||
1133 | Op)do { if (!(Op && isa<DIType>(Op))) { DebugInfoCheckFailed ("invalid thrown type", &N, ThrownTypes, Op); return; } } while (false); | |||
1134 | } | |||
1135 | ||||
1136 | if (N.areAllCallsDescribed()) | |||
1137 | AssertDI(N.isDefinition(),do { if (!(N.isDefinition())) { DebugInfoCheckFailed("DIFlagAllCallsDescribed must be attached to a definition" ); return; } } while (false) | |||
1138 | "DIFlagAllCallsDescribed must be attached to a definition")do { if (!(N.isDefinition())) { DebugInfoCheckFailed("DIFlagAllCallsDescribed must be attached to a definition" ); return; } } while (false); | |||
1139 | } | |||
1140 | ||||
1141 | void Verifier::visitDILexicalBlockBase(const DILexicalBlockBase &N) { | |||
1142 | 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); | |||
1143 | 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) | |||
1144 | "invalid local scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { DebugInfoCheckFailed("invalid local scope" , &N, N.getRawScope()); return; } } while (false); | |||
1145 | if (auto *SP = dyn_cast<DISubprogram>(N.getRawScope())) | |||
1146 | 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); | |||
1147 | } | |||
1148 | ||||
1149 | void Verifier::visitDILexicalBlock(const DILexicalBlock &N) { | |||
1150 | visitDILexicalBlockBase(N); | |||
1151 | ||||
1152 | AssertDI(N.getLine() || !N.getColumn(),do { if (!(N.getLine() || !N.getColumn())) { DebugInfoCheckFailed ("cannot have column info without line info", &N); return ; } } while (false) | |||
1153 | "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); | |||
1154 | } | |||
1155 | ||||
1156 | void Verifier::visitDILexicalBlockFile(const DILexicalBlockFile &N) { | |||
1157 | visitDILexicalBlockBase(N); | |||
1158 | } | |||
1159 | ||||
1160 | void Verifier::visitDICommonBlock(const DICommonBlock &N) { | |||
1161 | 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); | |||
1162 | if (auto *S = N.getRawScope()) | |||
1163 | AssertDI(isa<DIScope>(S), "invalid scope ref", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope ref" , &N, S); return; } } while (false); | |||
1164 | if (auto *S = N.getRawDecl()) | |||
1165 | AssertDI(isa<DIGlobalVariable>(S), "invalid declaration", &N, S)do { if (!(isa<DIGlobalVariable>(S))) { DebugInfoCheckFailed ("invalid declaration", &N, S); return; } } while (false); | |||
1166 | } | |||
1167 | ||||
1168 | void Verifier::visitDINamespace(const DINamespace &N) { | |||
1169 | 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); | |||
1170 | if (auto *S = N.getRawScope()) | |||
1171 | AssertDI(isa<DIScope>(S), "invalid scope ref", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope ref" , &N, S); return; } } while (false); | |||
1172 | } | |||
1173 | ||||
1174 | void Verifier::visitDIMacro(const DIMacro &N) { | |||
1175 | 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) | |||
1176 | 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) | |||
1177 | "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); | |||
1178 | AssertDI(!N.getName().empty(), "anonymous macro", &N)do { if (!(!N.getName().empty())) { DebugInfoCheckFailed("anonymous macro" , &N); return; } } while (false); | |||
1179 | if (!N.getValue().empty()) { | |||
1180 | 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-9~svn360410/lib/IR/Verifier.cpp" , 1180, __PRETTY_FUNCTION__)); | |||
1181 | } | |||
1182 | } | |||
1183 | ||||
1184 | void Verifier::visitDIMacroFile(const DIMacroFile &N) { | |||
1185 | 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) | |||
1186 | "invalid macinfo type", &N)do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_start_file )) { DebugInfoCheckFailed("invalid macinfo type", &N); return ; } } while (false); | |||
1187 | if (auto *F = N.getRawFile()) | |||
1188 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | |||
1189 | ||||
1190 | if (auto *Array = N.getRawElements()) { | |||
1191 | AssertDI(isa<MDTuple>(Array), "invalid macro list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed ("invalid macro list", &N, Array); return; } } while (false ); | |||
1192 | for (Metadata *Op : N.getElements()->operands()) { | |||
1193 | 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); | |||
1194 | } | |||
1195 | } | |||
1196 | } | |||
1197 | ||||
1198 | void Verifier::visitDIModule(const DIModule &N) { | |||
1199 | 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); | |||
1200 | AssertDI(!N.getName().empty(), "anonymous module", &N)do { if (!(!N.getName().empty())) { DebugInfoCheckFailed("anonymous module" , &N); return; } } while (false); | |||
1201 | } | |||
1202 | ||||
1203 | void Verifier::visitDITemplateParameter(const DITemplateParameter &N) { | |||
1204 | 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); | |||
1205 | } | |||
1206 | ||||
1207 | void Verifier::visitDITemplateTypeParameter(const DITemplateTypeParameter &N) { | |||
1208 | visitDITemplateParameter(N); | |||
1209 | ||||
1210 | 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) | |||
1211 | &N)do { if (!(N.getTag() == dwarf::DW_TAG_template_type_parameter )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false); | |||
1212 | } | |||
1213 | ||||
1214 | void Verifier::visitDITemplateValueParameter( | |||
1215 | const DITemplateValueParameter &N) { | |||
1216 | visitDITemplateParameter(N); | |||
1217 | ||||
1218 | 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) | |||
1219 | 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) | |||
1220 | 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) | |||
1221 | "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); | |||
1222 | } | |||
1223 | ||||
1224 | void Verifier::visitDIVariable(const DIVariable &N) { | |||
1225 | if (auto *S = N.getRawScope()) | |||
1226 | AssertDI(isa<DIScope>(S), "invalid scope", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope" , &N, S); return; } } while (false); | |||
1227 | if (auto *F = N.getRawFile()) | |||
1228 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | |||
1229 | } | |||
1230 | ||||
1231 | void Verifier::visitDIGlobalVariable(const DIGlobalVariable &N) { | |||
1232 | // Checks common to all variables. | |||
1233 | visitDIVariable(N); | |||
1234 | ||||
1235 | 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); | |||
1236 | 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); | |||
1237 | AssertDI(N.getType(), "missing global variable type", &N)do { if (!(N.getType())) { DebugInfoCheckFailed("missing global variable type" , &N); return; } } while (false); | |||
1238 | if (auto *Member = N.getRawStaticDataMemberDeclaration()) { | |||
1239 | AssertDI(isa<DIDerivedType>(Member),do { if (!(isa<DIDerivedType>(Member))) { DebugInfoCheckFailed ("invalid static data member declaration", &N, Member); return ; } } while (false) | |||
1240 | "invalid static data member declaration", &N, Member)do { if (!(isa<DIDerivedType>(Member))) { DebugInfoCheckFailed ("invalid static data member declaration", &N, Member); return ; } } while (false); | |||
1241 | } | |||
1242 | } | |||
1243 | ||||
1244 | void Verifier::visitDILocalVariable(const DILocalVariable &N) { | |||
1245 | // Checks common to all variables. | |||
1246 | visitDIVariable(N); | |||
1247 | ||||
1248 | 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); | |||
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(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) | |||
1251 | "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); | |||
1252 | if (auto Ty = N.getType()) | |||
1253 | AssertDI(!isa<DISubroutineType>(Ty), "invalid type", &N, N.getType())do { if (!(!isa<DISubroutineType>(Ty))) { DebugInfoCheckFailed ("invalid type", &N, N.getType()); return; } } while (false ); | |||
1254 | } | |||
1255 | ||||
1256 | void Verifier::visitDILabel(const DILabel &N) { | |||
1257 | if (auto *S = N.getRawScope()) | |||
1258 | AssertDI(isa<DIScope>(S), "invalid scope", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope" , &N, S); return; } } while (false); | |||
1259 | if (auto *F = N.getRawFile()) | |||
1260 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | |||
1261 | ||||
1262 | 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); | |||
1263 | 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) | |||
1264 | "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); | |||
1265 | } | |||
1266 | ||||
1267 | void Verifier::visitDIExpression(const DIExpression &N) { | |||
1268 | AssertDI(N.isValid(), "invalid expression", &N)do { if (!(N.isValid())) { DebugInfoCheckFailed("invalid expression" , &N); return; } } while (false); | |||
1269 | } | |||
1270 | ||||
1271 | void Verifier::visitDIGlobalVariableExpression( | |||
1272 | const DIGlobalVariableExpression &GVE) { | |||
1273 | AssertDI(GVE.getVariable(), "missing variable")do { if (!(GVE.getVariable())) { DebugInfoCheckFailed("missing variable" ); return; } } while (false); | |||
1274 | if (auto *Var = GVE.getVariable()) | |||
1275 | visitDIGlobalVariable(*Var); | |||
1276 | if (auto *Expr = GVE.getExpression()) { | |||
1277 | visitDIExpression(*Expr); | |||
1278 | if (auto Fragment = Expr->getFragmentInfo()) | |||
1279 | verifyFragmentExpression(*GVE.getVariable(), *Fragment, &GVE); | |||
1280 | } | |||
1281 | } | |||
1282 | ||||
1283 | void Verifier::visitDIObjCProperty(const DIObjCProperty &N) { | |||
1284 | 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); | |||
1285 | if (auto *T = N.getRawType()) | |||
1286 | AssertDI(isType(T), "invalid type ref", &N, T)do { if (!(isType(T))) { DebugInfoCheckFailed("invalid type ref" , &N, T); return; } } while (false); | |||
1287 | if (auto *F = N.getRawFile()) | |||
1288 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | |||
1289 | } | |||
1290 | ||||
1291 | void Verifier::visitDIImportedEntity(const DIImportedEntity &N) { | |||
1292 | 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) | |||
1293 | 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) | |||
1294 | "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); | |||
1295 | if (auto *S = N.getRawScope()) | |||
1296 | 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); | |||
1297 | AssertDI(isDINode(N.getRawEntity()), "invalid imported entity", &N,do { if (!(isDINode(N.getRawEntity()))) { DebugInfoCheckFailed ("invalid imported entity", &N, N.getRawEntity()); return ; } } while (false) | |||
1298 | N.getRawEntity())do { if (!(isDINode(N.getRawEntity()))) { DebugInfoCheckFailed ("invalid imported entity", &N, N.getRawEntity()); return ; } } while (false); | |||
1299 | } | |||
1300 | ||||
1301 | void Verifier::visitComdat(const Comdat &C) { | |||
1302 | // The Module is invalid if the GlobalValue has private linkage. Entities | |||
1303 | // with private linkage don't have entries in the symbol table. | |||
1304 | if (const GlobalValue *GV = M.getNamedValue(C.getName())) | |||
1305 | Assert(!GV->hasPrivateLinkage(), "comdat global value has private linkage",do { if (!(!GV->hasPrivateLinkage())) { CheckFailed("comdat global value has private linkage" , GV); return; } } while (false) | |||
1306 | GV)do { if (!(!GV->hasPrivateLinkage())) { CheckFailed("comdat global value has private linkage" , GV); return; } } while (false); | |||
1307 | } | |||
1308 | ||||
1309 | void Verifier::visitModuleIdents(const Module &M) { | |||
1310 | const NamedMDNode *Idents = M.getNamedMetadata("llvm.ident"); | |||
1311 | if (!Idents) | |||
1312 | return; | |||
1313 | ||||
1314 | // llvm.ident takes a list of metadata entry. Each entry has only one string. | |||
1315 | // Scan each llvm.ident entry and make sure that this requirement is met. | |||
1316 | for (const MDNode *N : Idents->operands()) { | |||
1317 | Assert(N->getNumOperands() == 1,do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.ident metadata" , N); return; } } while (false) | |||
1318 | "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); | |||
1319 | 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) | |||
1320 | ("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) | |||
1321 | "(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) | |||
1322 | 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); | |||
1323 | } | |||
1324 | } | |||
1325 | ||||
1326 | void Verifier::visitModuleCommandLines(const Module &M) { | |||
1327 | const NamedMDNode *CommandLines = M.getNamedMetadata("llvm.commandline"); | |||
1328 | if (!CommandLines) | |||
1329 | return; | |||
1330 | ||||
1331 | // llvm.commandline takes a list of metadata entry. Each entry has only one | |||
1332 | // string. Scan each llvm.commandline entry and make sure that this | |||
1333 | // requirement is met. | |||
1334 | for (const MDNode *N : CommandLines->operands()) { | |||
1335 | Assert(N->getNumOperands() == 1,do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.commandline metadata" , N); return; } } while (false) | |||
1336 | "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); | |||
1337 | 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) | |||
1338 | ("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) | |||
1339 | "(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) | |||
1340 | 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); | |||
1341 | } | |||
1342 | } | |||
1343 | ||||
1344 | void Verifier::visitModuleFlags(const Module &M) { | |||
1345 | const NamedMDNode *Flags = M.getModuleFlagsMetadata(); | |||
1346 | if (!Flags) return; | |||
1347 | ||||
1348 | // Scan each flag, and track the flags and requirements. | |||
1349 | DenseMap<const MDString*, const MDNode*> SeenIDs; | |||
1350 | SmallVector<const MDNode*, 16> Requirements; | |||
1351 | for (const MDNode *MDN : Flags->operands()) | |||
1352 | visitModuleFlag(MDN, SeenIDs, Requirements); | |||
1353 | ||||
1354 | // Validate that the requirements in the module are valid. | |||
1355 | for (const MDNode *Requirement : Requirements) { | |||
1356 | const MDString *Flag = cast<MDString>(Requirement->getOperand(0)); | |||
1357 | const Metadata *ReqValue = Requirement->getOperand(1); | |||
1358 | ||||
1359 | const MDNode *Op = SeenIDs.lookup(Flag); | |||
1360 | if (!Op) { | |||
1361 | CheckFailed("invalid requirement on flag, flag is not present in module", | |||
1362 | Flag); | |||
1363 | continue; | |||
1364 | } | |||
1365 | ||||
1366 | if (Op->getOperand(2) != ReqValue) { | |||
1367 | CheckFailed(("invalid requirement on flag, " | |||
1368 | "flag does not have the required value"), | |||
1369 | Flag); | |||
1370 | continue; | |||
1371 | } | |||
1372 | } | |||
1373 | } | |||
1374 | ||||
1375 | void | |||
1376 | Verifier::visitModuleFlag(const MDNode *Op, | |||
1377 | DenseMap<const MDString *, const MDNode *> &SeenIDs, | |||
1378 | SmallVectorImpl<const MDNode *> &Requirements) { | |||
1379 | // Each module flag should have three arguments, the merge behavior (a | |||
1380 | // constant int), the flag ID (an MDString), and the value. | |||
1381 | Assert(Op->getNumOperands() == 3,do { if (!(Op->getNumOperands() == 3)) { CheckFailed("incorrect number of operands in module flag" , Op); return; } } while (false) | |||
1382 | "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); | |||
1383 | Module::ModFlagBehavior MFB; | |||
1384 | if (!Module::isValidModFlagBehavior(Op->getOperand(0), MFB)) { | |||
1385 | 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) | |||
1386 | 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) | |||
1387 | "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) | |||
1388 | 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); | |||
1389 | Assert(false,do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)" , Op->getOperand(0)); return; } } while (false) | |||
1390 | "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) | |||
1391 | Op->getOperand(0))do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)" , Op->getOperand(0)); return; } } while (false); | |||
1392 | } | |||
1393 | MDString *ID = dyn_cast_or_null<MDString>(Op->getOperand(1)); | |||
1394 | 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) | |||
1395 | Op->getOperand(1))do { if (!(ID)) { CheckFailed("invalid ID operand in module flag (expected metadata string)" , Op->getOperand(1)); return; } } while (false); | |||
1396 | ||||
1397 | // Sanity check the values for behaviors with additional requirements. | |||
1398 | switch (MFB) { | |||
1399 | case Module::Error: | |||
1400 | case Module::Warning: | |||
1401 | case Module::Override: | |||
1402 | // These behavior types accept any value. | |||
1403 | break; | |||
1404 | ||||
1405 | case Module::Max: { | |||
1406 | 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) | |||
1407 | "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) | |||
1408 | 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); | |||
1409 | break; | |||
1410 | } | |||
1411 | ||||
1412 | case Module::Require: { | |||
1413 | // The value should itself be an MDNode with two operands, a flag ID (an | |||
1414 | // MDString), and a value. | |||
1415 | MDNode *Value = dyn_cast<MDNode>(Op->getOperand(2)); | |||
1416 | 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) | |||
1417 | "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) | |||
1418 | 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); | |||
1419 | 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) | |||
1420 | ("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) | |||
1421 | "(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) | |||
1422 | 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); | |||
1423 | ||||
1424 | // Append it to the list of requirements, to check once all module flags are | |||
1425 | // scanned. | |||
1426 | Requirements.push_back(Value); | |||
1427 | break; | |||
1428 | } | |||
1429 | ||||
1430 | case Module::Append: | |||
1431 | case Module::AppendUnique: { | |||
1432 | // These behavior types require the operand be an MDNode. | |||
1433 | 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) | |||
1434 | "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) | |||
1435 | "(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) | |||
1436 | 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); | |||
1437 | break; | |||
1438 | } | |||
1439 | } | |||
1440 | ||||
1441 | // Unless this is a "requires" flag, check the ID is unique. | |||
1442 | if (MFB != Module::Require) { | |||
1443 | bool Inserted = SeenIDs.insert(std::make_pair(ID, Op)).second; | |||
1444 | Assert(Inserted,do { if (!(Inserted)) { CheckFailed("module flag identifiers must be unique (or of 'require' type)" , ID); return; } } while (false) | |||
1445 | "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); | |||
1446 | } | |||
1447 | ||||
1448 | if (ID->getString() == "wchar_size") { | |||
1449 | ConstantInt *Value | |||
1450 | = mdconst::dyn_extract_or_null<ConstantInt>(Op->getOperand(2)); | |||
1451 | Assert(Value, "wchar_size metadata requires constant integer argument")do { if (!(Value)) { CheckFailed("wchar_size metadata requires constant integer argument" ); return; } } while (false); | |||
1452 | } | |||
1453 | ||||
1454 | if (ID->getString() == "Linker Options") { | |||
1455 | // If the llvm.linker.options named metadata exists, we assume that the | |||
1456 | // bitcode reader has upgraded the module flag. Otherwise the flag might | |||
1457 | // have been created by a client directly. | |||
1458 | Assert(M.getNamedMetadata("llvm.linker.options"),do { if (!(M.getNamedMetadata("llvm.linker.options"))) { CheckFailed ("'Linker Options' named metadata no longer supported"); return ; } } while (false) | |||
1459 | "'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); | |||
1460 | } | |||
1461 | ||||
1462 | if (ID->getString() == "CG Profile") { | |||
1463 | for (const MDOperand &MDO : cast<MDNode>(Op->getOperand(2))->operands()) | |||
1464 | visitModuleFlagCGProfileEntry(MDO); | |||
1465 | } | |||
1466 | } | |||
1467 | ||||
1468 | void Verifier::visitModuleFlagCGProfileEntry(const MDOperand &MDO) { | |||
1469 | auto CheckFunction = [&](const MDOperand &FuncMDO) { | |||
1470 | if (!FuncMDO) | |||
1471 | return; | |||
1472 | auto F = dyn_cast<ValueAsMetadata>(FuncMDO); | |||
1473 | 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) | |||
1474 | FuncMDO)do { if (!(F && isa<Function>(F->getValue()) )) { CheckFailed("expected a Function or null", FuncMDO); return ; } } while (false); | |||
1475 | }; | |||
1476 | auto Node = dyn_cast_or_null<MDNode>(MDO); | |||
1477 | 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); | |||
1478 | CheckFunction(Node->getOperand(0)); | |||
1479 | CheckFunction(Node->getOperand(1)); | |||
1480 | auto Count = dyn_cast_or_null<ConstantAsMetadata>(Node->getOperand(2)); | |||
1481 | Assert(Count && Count->getType()->isIntegerTy(),do { if (!(Count && Count->getType()->isIntegerTy ())) { CheckFailed("expected an integer constant", Node->getOperand (2)); return; } } while (false) | |||
1482 | "expected an integer constant", Node->getOperand(2))do { if (!(Count && Count->getType()->isIntegerTy ())) { CheckFailed("expected an integer constant", Node->getOperand (2)); return; } } while (false); | |||
1483 | } | |||
1484 | ||||
1485 | /// Return true if this attribute kind only applies to functions. | |||
1486 | static bool isFuncOnlyAttr(Attribute::AttrKind Kind) { | |||
1487 | switch (Kind) { | |||
1488 | case Attribute::NoReturn: | |||
1489 | case Attribute::NoCfCheck: | |||
1490 | case Attribute::NoUnwind: | |||
1491 | case Attribute::NoInline: | |||
1492 | case Attribute::AlwaysInline: | |||
1493 | case Attribute::OptimizeForSize: | |||
1494 | case Attribute::StackProtect: | |||
1495 | case Attribute::StackProtectReq: | |||
1496 | case Attribute::StackProtectStrong: | |||
1497 | case Attribute::SafeStack: | |||
1498 | case Attribute::ShadowCallStack: | |||
1499 | case Attribute::NoRedZone: | |||
1500 | case Attribute::NoImplicitFloat: | |||
1501 | case Attribute::Naked: | |||
1502 | case Attribute::InlineHint: | |||
1503 | case Attribute::StackAlignment: | |||
1504 | case Attribute::UWTable: | |||
1505 | case Attribute::NonLazyBind: | |||
1506 | case Attribute::ReturnsTwice: | |||
1507 | case Attribute::SanitizeAddress: | |||
1508 | case Attribute::SanitizeHWAddress: | |||
1509 | case Attribute::SanitizeThread: | |||
1510 | case Attribute::SanitizeMemory: | |||
1511 | case Attribute::MinSize: | |||
1512 | case Attribute::NoDuplicate: | |||
1513 | case Attribute::Builtin: | |||
1514 | case Attribute::NoBuiltin: | |||
1515 | case Attribute::Cold: | |||
1516 | case Attribute::OptForFuzzing: | |||
1517 | case Attribute::OptimizeNone: | |||
1518 | case Attribute::JumpTable: | |||
1519 | case Attribute::Convergent: | |||
1520 | case Attribute::ArgMemOnly: | |||
1521 | case Attribute::NoRecurse: | |||
1522 | case Attribute::InaccessibleMemOnly: | |||
1523 | case Attribute::InaccessibleMemOrArgMemOnly: | |||
1524 | case Attribute::AllocSize: | |||
1525 | case Attribute::SpeculativeLoadHardening: | |||
1526 | case Attribute::Speculatable: | |||
1527 | case Attribute::StrictFP: | |||
1528 | return true; | |||
1529 | default: | |||
1530 | break; | |||
1531 | } | |||
1532 | return false; | |||
1533 | } | |||
1534 | ||||
1535 | /// Return true if this is a function attribute that can also appear on | |||
1536 | /// arguments. | |||
1537 | static bool isFuncOrArgAttr(Attribute::AttrKind Kind) { | |||
1538 | return Kind == Attribute::ReadOnly || Kind == Attribute::WriteOnly || | |||
1539 | Kind == Attribute::ReadNone; | |||
1540 | } | |||
1541 | ||||
1542 | void Verifier::verifyAttributeTypes(AttributeSet Attrs, bool IsFunction, | |||
1543 | const Value *V) { | |||
1544 | for (Attribute A : Attrs) { | |||
1545 | if (A.isStringAttribute()) | |||
1546 | continue; | |||
1547 | ||||
1548 | if (isFuncOnlyAttr(A.getKindAsEnum())) { | |||
1549 | if (!IsFunction) { | |||
1550 | CheckFailed("Attribute '" + A.getAsString() + | |||
1551 | "' only applies to functions!", | |||
1552 | V); | |||
1553 | return; | |||
1554 | } | |||
1555 | } else if (IsFunction && !isFuncOrArgAttr(A.getKindAsEnum())) { | |||
1556 | CheckFailed("Attribute '" + A.getAsString() + | |||
1557 | "' does not apply to functions!", | |||
1558 | V); | |||
1559 | return; | |||
1560 | } | |||
1561 | } | |||
1562 | } | |||
1563 | ||||
1564 | // VerifyParameterAttrs - Check the given attributes for an argument or return | |||
1565 | // value of the specified type. The value V is printed in error messages. | |||
1566 | void Verifier::verifyParameterAttrs(AttributeSet Attrs, Type *Ty, | |||
1567 | const Value *V) { | |||
1568 | if (!Attrs.hasAttributes()) | |||
1569 | return; | |||
1570 | ||||
1571 | verifyAttributeTypes(Attrs, /*IsFunction=*/false, V); | |||
1572 | ||||
1573 | if (Attrs.hasAttribute(Attribute::ImmArg)) { | |||
1574 | Assert(Attrs.getNumAttributes() == 1,do { if (!(Attrs.getNumAttributes() == 1)) { CheckFailed("Attribute 'immarg' is incompatible with other attributes" , V); return; } } while (false) | |||
1575 | "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); | |||
1576 | } | |||
1577 | ||||
1578 | // Check for mutually incompatible attributes. Only inreg is compatible with | |||
1579 | // sret. | |||
1580 | unsigned AttrCount = 0; | |||
1581 | AttrCount += Attrs.hasAttribute(Attribute::ByVal); | |||
1582 | AttrCount += Attrs.hasAttribute(Attribute::InAlloca); | |||
1583 | AttrCount += Attrs.hasAttribute(Attribute::StructRet) || | |||
1584 | Attrs.hasAttribute(Attribute::InReg); | |||
1585 | AttrCount += Attrs.hasAttribute(Attribute::Nest); | |||
1586 | 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 ) | |||
1587 | "and 'sret' are incompatible!",do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'inreg', 'nest', " "and 'sret' are incompatible!", V); return; } } while (false ) | |||
1588 | V)do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'inreg', 'nest', " "and 'sret' are incompatible!", V); return; } } while (false ); | |||
1589 | ||||
1590 | 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) | |||
1591 | 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) | |||
1592 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'inalloca and readonly' are incompatible!", V); return; } } while (false) | |||
1593 | "'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) | |||
1594 | V)do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'inalloca and readonly' are incompatible!", V); return; } } while (false); | |||
1595 | ||||
1596 | 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) | |||
1597 | 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) | |||
1598 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) && Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes " "'sret and returned' are incompatible!", V); return; } } while (false) | |||
1599 | "'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) | |||
1600 | V)do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) && Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes " "'sret and returned' are incompatible!", V); return; } } while (false); | |||
1601 | ||||
1602 | 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) | |||
1603 | 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) | |||
1604 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs .hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes " "'zeroext and signext' are incompatible!", V); return; } } while (false) | |||
1605 | "'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) | |||
1606 | V)do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs .hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes " "'zeroext and signext' are incompatible!", V); return; } } while (false); | |||
1607 | ||||
1608 | 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) | |||
1609 | 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) | |||
1610 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'readnone and readonly' are incompatible!", V); return; } } while (false) | |||
1611 | "'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) | |||
1612 | V)do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'readnone and readonly' are incompatible!", V); return; } } while (false); | |||
1613 | ||||
1614 | 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) | |||
1615 | 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) | |||
1616 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readnone and writeonly' are incompatible!", V); return; } } while (false) | |||
1617 | "'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) | |||
1618 | V)do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readnone and writeonly' are incompatible!", V); return; } } while (false); | |||
1619 | ||||
1620 | 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) | |||
1621 | 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) | |||
1622 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readonly and writeonly' are incompatible!", V); return; } } while (false) | |||
1623 | "'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) | |||
1624 | V)do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readonly and writeonly' are incompatible!", V); return; } } while (false); | |||
1625 | ||||
1626 | 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) | |||
1627 | 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) | |||
1628 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) && Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed ("Attributes " "'noinline and alwaysinline' are incompatible!" , V); return; } } while (false) | |||
1629 | "'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) | |||
1630 | V)do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) && Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed ("Attributes " "'noinline and alwaysinline' are incompatible!" , V); return; } } while (false); | |||
1631 | ||||
1632 | AttrBuilder IncompatibleAttrs = AttributeFuncs::typeIncompatible(Ty); | |||
1633 | 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) | |||
1634 | "Wrong types for attribute: " +do { if (!(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs))) { CheckFailed("Wrong types for attribute: " + AttributeSet::get (Context, IncompatibleAttrs).getAsString(), V); return; } } while (false) | |||
1635 | 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) | |||
1636 | V)do { if (!(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs))) { CheckFailed("Wrong types for attribute: " + AttributeSet::get (Context, IncompatibleAttrs).getAsString(), V); return; } } while (false); | |||
1637 | ||||
1638 | if (PointerType *PTy = dyn_cast<PointerType>(Ty)) { | |||
1639 | SmallPtrSet<Type*, 4> Visited; | |||
1640 | if (!PTy->getElementType()->isSized(&Visited)) { | |||
1641 | 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) | |||
1642 | !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) | |||
1643 | "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) | |||
1644 | 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); | |||
1645 | } | |||
1646 | if (!isa<PointerType>(PTy->getElementType())) | |||
1647 | 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) | |||
1648 | "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) | |||
1649 | "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) | |||
1650 | V)do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer to pointer type!" , V); return; } } while (false); | |||
1651 | } else { | |||
1652 | 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) | |||
1653 | "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) | |||
1654 | V)do { if (!(!Attrs.hasAttribute(Attribute::ByVal))) { CheckFailed ("Attribute 'byval' only applies to parameters with pointer type!" , V); return; } } while (false); | |||
1655 | 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) | |||
1656 | "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) | |||
1657 | "with pointer type!",do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer type!" , V); return; } } while (false) | |||
1658 | V)do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer type!" , V); return; } } while (false); | |||
1659 | } | |||
1660 | } | |||
1661 | ||||
1662 | // Check parameter attributes against a function type. | |||
1663 | // The value V is printed in error messages. | |||
1664 | void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs, | |||
1665 | const Value *V, bool IsIntrinsic) { | |||
1666 | if (Attrs.isEmpty()) | |||
1667 | return; | |||
1668 | ||||
1669 | bool SawNest = false; | |||
1670 | bool SawReturned = false; | |||
1671 | bool SawSRet = false; | |||
1672 | bool SawSwiftSelf = false; | |||
1673 | bool SawSwiftError = false; | |||
1674 | ||||
1675 | // Verify return value attributes. | |||
1676 | AttributeSet RetAttrs = Attrs.getRetAttributes(); | |||
1677 | 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 ::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca ) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed ("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1678 | !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 ::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca ) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed ("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1679 | !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 ::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca ) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed ("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1680 | !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 ::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca ) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed ("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1681 | !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 ::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca ) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed ("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1682 | !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 ::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca ) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed ("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1683 | !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 ::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca ) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed ("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1684 | !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 ::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca ) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed ("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1685 | "Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', "do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca ) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed ("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1686 | "'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 ::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca ) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed ("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1687 | "values!",do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca ) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed ("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | |||
1688 | V)do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca ) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed ("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false); | |||
1689 | 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) | |||
1690 | !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) | |||
1691 | !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) | |||
1692 | "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) | |||
1693 | "' 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) | |||
1694 | 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); | |||
1695 | verifyParameterAttrs(RetAttrs, FT->getReturnType(), V); | |||
1696 | ||||
1697 | // Verify parameter attributes. | |||
1698 | for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) { | |||
1699 | Type *Ty = FT->getParamType(i); | |||
1700 | AttributeSet ArgAttrs = Attrs.getParamAttributes(i); | |||
1701 | ||||
1702 | if (!IsIntrinsic) { | |||
1703 | Assert(!ArgAttrs.hasAttribute(Attribute::ImmArg),do { if (!(!ArgAttrs.hasAttribute(Attribute::ImmArg))) { CheckFailed ("immarg attribute only applies to intrinsics",V); return; } } while (false) | |||
1704 | "immarg attribute only applies to intrinsics",V)do { if (!(!ArgAttrs.hasAttribute(Attribute::ImmArg))) { CheckFailed ("immarg attribute only applies to intrinsics",V); return; } } while (false); | |||
1705 | } | |||
1706 | ||||
1707 | verifyParameterAttrs(ArgAttrs, Ty, V); | |||
1708 | ||||
1709 | if (ArgAttrs.hasAttribute(Attribute::Nest)) { | |||
1710 | 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); | |||
1711 | SawNest = true; | |||
1712 | } | |||
1713 | ||||
1714 | if (ArgAttrs.hasAttribute(Attribute::Returned)) { | |||
1715 | Assert(!SawReturned, "More than one parameter has attribute returned!",do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!" , V); return; } } while (false) | |||
1716 | V)do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!" , V); return; } } while (false); | |||
1717 | Assert(Ty->canLosslesslyBitCastTo(FT->getReturnType()),do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' attribute" , V); return; } } while (false) | |||
1718 | "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) | |||
1719 | V)do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' attribute" , V); return; } } while (false); | |||
1720 | SawReturned = true; | |||
1721 | } | |||
1722 | ||||
1723 | if (ArgAttrs.hasAttribute(Attribute::StructRet)) { | |||
1724 | Assert(!SawSRet, "Cannot have multiple 'sret' parameters!", V)do { if (!(!SawSRet)) { CheckFailed("Cannot have multiple 'sret' parameters!" , V); return; } } while (false); | |||
1725 | 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) | |||
1726 | "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); | |||
1727 | SawSRet = true; | |||
1728 | } | |||
1729 | ||||
1730 | if (ArgAttrs.hasAttribute(Attribute::SwiftSelf)) { | |||
1731 | Assert(!SawSwiftSelf, "Cannot have multiple 'swiftself' parameters!", V)do { if (!(!SawSwiftSelf)) { CheckFailed("Cannot have multiple 'swiftself' parameters!" , V); return; } } while (false); | |||
1732 | SawSwiftSelf = true; | |||
1733 | } | |||
1734 | ||||
1735 | if (ArgAttrs.hasAttribute(Attribute::SwiftError)) { | |||
1736 | Assert(!SawSwiftError, "Cannot have multiple 'swifterror' parameters!",do { if (!(!SawSwiftError)) { CheckFailed("Cannot have multiple 'swifterror' parameters!" , V); return; } } while (false) | |||
1737 | V)do { if (!(!SawSwiftError)) { CheckFailed("Cannot have multiple 'swifterror' parameters!" , V); return; } } while (false); | |||
1738 | SawSwiftError = true; | |||
1739 | } | |||
1740 | ||||
1741 | if (ArgAttrs.hasAttribute(Attribute::InAlloca)) { | |||
1742 | Assert(i == FT->getNumParams() - 1,do { if (!(i == FT->getNumParams() - 1)) { CheckFailed("inalloca isn't on the last parameter!" , V); return; } } while (false) | |||
1743 | "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); | |||
1744 | } | |||
1745 | } | |||
1746 | ||||
1747 | if (!Attrs.hasAttributes(AttributeList::FunctionIndex)) | |||
1748 | return; | |||
1749 | ||||
1750 | verifyAttributeTypes(Attrs.getFnAttributes(), /*IsFunction=*/true, V); | |||
1751 | ||||
1752 | 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) | |||
1753 | 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) | |||
1754 | "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); | |||
1755 | ||||
1756 | 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) | |||
1757 | 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) | |||
1758 | "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); | |||
1759 | ||||
1760 | 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) | |||
1761 | 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) | |||
1762 | "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); | |||
1763 | ||||
1764 | 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) | |||
1765 | 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) | |||
1766 | "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) | |||
1767 | "incompatible!",do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly) ))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are " "incompatible!", V); return; } } while (false) | |||
1768 | V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly) ))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are " "incompatible!", V); return; } } while (false); | |||
1769 | ||||
1770 | 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) | |||
1771 | 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) | |||
1772 | "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); | |||
1773 | ||||
1774 | 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) | |||
1775 | 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) | |||
1776 | "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); | |||
1777 | ||||
1778 | if (Attrs.hasFnAttribute(Attribute::OptimizeNone)) { | |||
1779 | Assert(Attrs.hasFnAttribute(Attribute::NoInline),do { if (!(Attrs.hasFnAttribute(Attribute::NoInline))) { CheckFailed ("Attribute 'optnone' requires 'noinline'!", V); return; } } while (false) | |||
1780 | "Attribute 'optnone' requires 'noinline'!", V)do { if (!(Attrs.hasFnAttribute(Attribute::NoInline))) { CheckFailed ("Attribute 'optnone' requires 'noinline'!", V); return; } } while (false); | |||
1781 | ||||
1782 | Assert(!Attrs.hasFnAttribute(Attribute::OptimizeForSize),do { if (!(!Attrs.hasFnAttribute(Attribute::OptimizeForSize)) ) { CheckFailed("Attributes 'optsize and optnone' are incompatible!" , V); return; } } while (false) | |||
1783 | "Attributes 'optsize and optnone' are incompatible!", V)do { if (!(!Attrs.hasFnAttribute(Attribute::OptimizeForSize)) ) { CheckFailed("Attributes 'optsize and optnone' are incompatible!" , V); return; } } while (false); | |||
1784 | ||||
1785 | Assert(!Attrs.hasFnAttribute(Attribute::MinSize),do { if (!(!Attrs.hasFnAttribute(Attribute::MinSize))) { CheckFailed ("Attributes 'minsize and optnone' are incompatible!", V); return ; } } while (false) | |||
1786 | "Attributes 'minsize and optnone' are incompatible!", V)do { if (!(!Attrs.hasFnAttribute(Attribute::MinSize))) { CheckFailed ("Attributes 'minsize and optnone' are incompatible!", V); return ; } } while (false); | |||
1787 | } | |||
1788 | ||||
1789 | if (Attrs.hasFnAttribute(Attribute::JumpTable)) { | |||
1790 | const GlobalValue *GV = cast<GlobalValue>(V); | |||
1791 | Assert(GV->hasGlobalUnnamedAddr(),do { if (!(GV->hasGlobalUnnamedAddr())) { CheckFailed("Attribute 'jumptable' requires 'unnamed_addr'" , V); return; } } while (false) | |||
1792 | "Attribute 'jumptable' requires 'unnamed_addr'", V)do { if (!(GV->hasGlobalUnnamedAddr())) { CheckFailed("Attribute 'jumptable' requires 'unnamed_addr'" , V); return; } } while (false); | |||
1793 | } | |||
1794 | ||||
1795 | if (Attrs.hasFnAttribute(Attribute::AllocSize)) { | |||
1796 | std::pair<unsigned, Optional<unsigned>> Args = | |||
1797 | Attrs.getAllocSizeArgs(AttributeList::FunctionIndex); | |||
1798 | ||||
1799 | auto CheckParam = [&](StringRef Name, unsigned ParamNo) { | |||
1800 | if (ParamNo >= FT->getNumParams()) { | |||
1801 | CheckFailed("'allocsize' " + Name + " argument is out of bounds", V); | |||
1802 | return false; | |||
1803 | } | |||
1804 | ||||
1805 | if (!FT->getParamType(ParamNo)->isIntegerTy()) { | |||
1806 | CheckFailed("'allocsize' " + Name + | |||
1807 | " argument must refer to an integer parameter", | |||
1808 | V); | |||
1809 | return false; | |||
1810 | } | |||
1811 | ||||
1812 | return true; | |||
1813 | }; | |||
1814 | ||||
1815 | if (!CheckParam("element size", Args.first)) | |||
1816 | return; | |||
1817 | ||||
1818 | if (Args.second && !CheckParam("number of elements", *Args.second)) | |||
1819 | return; | |||
1820 | } | |||
1821 | } | |||
1822 | ||||
1823 | void Verifier::verifyFunctionMetadata( | |||
1824 | ArrayRef<std::pair<unsigned, MDNode *>> MDs) { | |||
1825 | for (const auto &Pair : MDs) { | |||
1826 | if (Pair.first == LLVMContext::MD_prof) { | |||
1827 | MDNode *MD = Pair.second; | |||
1828 | Assert(MD->getNumOperands() >= 2,do { if (!(MD->getNumOperands() >= 2)) { CheckFailed("!prof annotations should have no less than 2 operands" , MD); return; } } while (false) | |||
1829 | "!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); | |||
1830 | ||||
1831 | // Check first operand. | |||
1832 | 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) | |||
1833 | MD)do { if (!(MD->getOperand(0) != nullptr)) { CheckFailed("first operand should not be null" , MD); return; } } while (false); | |||
1834 | 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) | |||
1835 | "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); | |||
1836 | MDString *MDS = cast<MDString>(MD->getOperand(0)); | |||
1837 | StringRef ProfName = MDS->getString(); | |||
1838 | 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) | |||
1839 | 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) | |||
1840 | "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) | |||
1841 | " 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) | |||
1842 | 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); | |||
1843 | ||||
1844 | // Check second operand. | |||
1845 | 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) | |||
1846 | MD)do { if (!(MD->getOperand(1) != nullptr)) { CheckFailed("second operand should not be null" , MD); return; } } while (false); | |||
1847 | 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) | |||
1848 | "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); | |||
1849 | } | |||
1850 | } | |||
1851 | } | |||
1852 | ||||
1853 | void Verifier::visitConstantExprsRecursively(const Constant *EntryC) { | |||
1854 | if (!ConstantExprVisited.insert(EntryC).second) | |||
1855 | return; | |||
1856 | ||||
1857 | SmallVector<const Constant *, 16> Stack; | |||
1858 | Stack.push_back(EntryC); | |||
1859 | ||||
1860 | while (!Stack.empty()) { | |||
1861 | const Constant *C = Stack.pop_back_val(); | |||
1862 | ||||
1863 | // Check this constant expression. | |||
1864 | if (const auto *CE = dyn_cast<ConstantExpr>(C)) | |||
1865 | visitConstantExpr(CE); | |||
1866 | ||||
1867 | if (const auto *GV = dyn_cast<GlobalValue>(C)) { | |||
1868 | // Global Values get visited separately, but we do need to make sure | |||
1869 | // that the global value is in the correct module | |||
1870 | 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) | |||
1871 | EntryC, &M, GV, GV->getParent())do { if (!(GV->getParent() == &M)) { CheckFailed("Referencing global in another module!" , EntryC, &M, GV, GV->getParent()); return; } } while ( false); | |||
1872 | continue; | |||
1873 | } | |||
1874 | ||||
1875 | // Visit all sub-expressions. | |||
1876 | for (const Use &U : C->operands()) { | |||
1877 | const auto *OpC = dyn_cast<Constant>(U); | |||
1878 | if (!OpC) | |||
1879 | continue; | |||
1880 | if (!ConstantExprVisited.insert(OpC).second) | |||
1881 | continue; | |||
1882 | Stack.push_back(OpC); | |||
1883 | } | |||
1884 | } | |||
1885 | } | |||
1886 | ||||
1887 | void Verifier::visitConstantExpr(const ConstantExpr *CE) { | |||
1888 | if (CE->getOpcode() == Instruction::BitCast) | |||
1889 | 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) | |||
1890 | CE->getType()),do { if (!(CastInst::castIsValid(Instruction::BitCast, CE-> getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast" , CE); return; } } while (false) | |||
1891 | "Invalid bitcast", CE)do { if (!(CastInst::castIsValid(Instruction::BitCast, CE-> getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast" , CE); return; } } while (false); | |||
1892 | ||||
1893 | if (CE->getOpcode() == Instruction::IntToPtr || | |||
1894 | CE->getOpcode() == Instruction::PtrToInt) { | |||
1895 | auto *PtrTy = CE->getOpcode() == Instruction::IntToPtr | |||
1896 | ? CE->getType() | |||
1897 | : CE->getOperand(0)->getType(); | |||
1898 | StringRef Msg = CE->getOpcode() == Instruction::IntToPtr | |||
1899 | ? "inttoptr not supported for non-integral pointers" | |||
1900 | : "ptrtoint not supported for non-integral pointers"; | |||
1901 | Assert(do { if (!(!DL.isNonIntegralPointerType(cast<PointerType> (PtrTy->getScalarType())))) { CheckFailed(Msg); return; } } while (false) | |||
1902 | !DL.isNonIntegralPointerType(cast<PointerType>(PtrTy->getScalarType())),do { if (!(!DL.isNonIntegralPointerType(cast<PointerType> (PtrTy->getScalarType())))) { CheckFailed(Msg); return; } } while (false) | |||
1903 | Msg)do { if (!(!DL.isNonIntegralPointerType(cast<PointerType> (PtrTy->getScalarType())))) { CheckFailed(Msg); return; } } while (false); | |||
1904 | } | |||
1905 | } | |||
1906 | ||||
1907 | bool Verifier::verifyAttributeCount(AttributeList Attrs, unsigned Params) { | |||
1908 | // There shouldn't be more attribute sets than there are parameters plus the | |||
1909 | // function and return value. | |||
1910 | return Attrs.getNumAttrSets() <= Params + 2; | |||
1911 | } | |||
1912 | ||||
1913 | /// Verify that statepoint intrinsic is well formed. | |||
1914 | void Verifier::verifyStatepoint(const CallBase &Call) { | |||
1915 | 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-9~svn360410/lib/IR/Verifier.cpp" , 1917, __PRETTY_FUNCTION__)) | |||
1916 | 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-9~svn360410/lib/IR/Verifier.cpp" , 1917, __PRETTY_FUNCTION__)) | |||
1917 | 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-9~svn360410/lib/IR/Verifier.cpp" , 1917, __PRETTY_FUNCTION__)); | |||
1918 | ||||
1919 | 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) | |||
1920 | !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) | |||
1921 | "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) | |||
1922 | "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) | |||
1923 | 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); | |||
1924 | ||||
1925 | const int64_t NumPatchBytes = | |||
1926 | cast<ConstantInt>(Call.getArgOperand(1))->getSExtValue(); | |||
1927 | 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-9~svn360410/lib/IR/Verifier.cpp" , 1927, __PRETTY_FUNCTION__)); | |||
1928 | Assert(NumPatchBytes >= 0,do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be " "positive", Call); return; } } while (false) | |||
1929 | "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) | |||
1930 | "positive",do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be " "positive", Call); return; } } while (false) | |||
1931 | Call)do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be " "positive", Call); return; } } while (false); | |||
1932 | ||||
1933 | const Value *Target = Call.getArgOperand(2); | |||
1934 | auto *PT = dyn_cast<PointerType>(Target->getType()); | |||
1935 | 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) | |||
1936 | "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); | |||
1937 | FunctionType *TargetFuncType = cast<FunctionType>(PT->getElementType()); | |||
1938 | ||||
1939 | const int NumCallArgs = cast<ConstantInt>(Call.getArgOperand(3))->getZExtValue(); | |||
1940 | Assert(NumCallArgs >= 0,do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call " "must be positive", Call); return; } } while (false) | |||
1941 | "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) | |||
1942 | "must be positive",do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call " "must be positive", Call); return; } } while (false) | |||
1943 | Call)do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call " "must be positive", Call); return; } } while (false); | |||
1944 | const int NumParams = (int)TargetFuncType->getNumParams(); | |||
1945 | if (TargetFuncType->isVarArg()) { | |||
1946 | Assert(NumCallArgs >= NumParams,do { if (!(NumCallArgs >= NumParams)) { CheckFailed("gc.statepoint mismatch in number of vararg call args" , Call); return; } } while (false) | |||
1947 | "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); | |||
1948 | ||||
1949 | // TODO: Remove this limitation | |||
1950 | 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) | |||
1951 | "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) | |||
1952 | "vararg functions yet",do { if (!(TargetFuncType->getReturnType()->isVoidTy()) ) { CheckFailed("gc.statepoint doesn't support wrapping non-void " "vararg functions yet", Call); return; } } while (false) | |||
1953 | Call)do { if (!(TargetFuncType->getReturnType()->isVoidTy()) ) { CheckFailed("gc.statepoint doesn't support wrapping non-void " "vararg functions yet", Call); return; } } while (false); | |||
1954 | } else | |||
1955 | Assert(NumCallArgs == NumParams,do { if (!(NumCallArgs == NumParams)) { CheckFailed("gc.statepoint mismatch in number of call args" , Call); return; } } while (false) | |||
1956 | "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); | |||
1957 | ||||
1958 | const uint64_t Flags | |||
1959 | = cast<ConstantInt>(Call.getArgOperand(4))->getZExtValue(); | |||
1960 | 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) | |||
1961 | "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); | |||
1962 | ||||
1963 | // Verify that the types of the call parameter arguments match | |||
1964 | // the type of the wrapped callee. | |||
1965 | AttributeList Attrs = Call.getAttributes(); | |||
1966 | for (int i = 0; i < NumParams; i++) { | |||
1967 | Type *ParamType = TargetFuncType->getParamType(i); | |||
1968 | Type *ArgType = Call.getArgOperand(5 + i)->getType(); | |||
1969 | Assert(ArgType == ParamType,do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped " "function type", Call); return; } } while (false) | |||
1970 | "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) | |||
1971 | "function type",do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped " "function type", Call); return; } } while (false) | |||
1972 | Call)do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped " "function type", Call); return; } } while (false); | |||
1973 | ||||
1974 | if (TargetFuncType->isVarArg()) { | |||
1975 | AttributeSet ArgAttrs = Attrs.getParamAttributes(5 + i); | |||
1976 | 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) | |||
1977 | "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) | |||
1978 | Call)do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed ("Attribute 'sret' cannot be used for vararg call arguments!" , Call); return; } } while (false); | |||
1979 | } | |||
1980 | } | |||
1981 | ||||
1982 | const int EndCallArgsInx = 4 + NumCallArgs; | |||
1983 | ||||
1984 | const Value *NumTransitionArgsV = Call.getArgOperand(EndCallArgsInx + 1); | |||
1985 | Assert(isa<ConstantInt>(NumTransitionArgsV),do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed ("gc.statepoint number of transition arguments " "must be constant integer" , Call); return; } } while (false) | |||
1986 | "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) | |||
1987 | "must be constant integer",do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed ("gc.statepoint number of transition arguments " "must be constant integer" , Call); return; } } while (false) | |||
1988 | Call)do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed ("gc.statepoint number of transition arguments " "must be constant integer" , Call); return; } } while (false); | |||
1989 | const int NumTransitionArgs = | |||
1990 | cast<ConstantInt>(NumTransitionArgsV)->getZExtValue(); | |||
1991 | Assert(NumTransitionArgs >= 0,do { if (!(NumTransitionArgs >= 0)) { CheckFailed("gc.statepoint number of transition arguments must be positive" , Call); return; } } while (false) | |||
1992 | "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); | |||
1993 | const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs; | |||
1994 | ||||
1995 | const Value *NumDeoptArgsV = Call.getArgOperand(EndTransitionArgsInx + 1); | |||
1996 | Assert(isa<ConstantInt>(NumDeoptArgsV),do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed ("gc.statepoint number of deoptimization arguments " "must be constant integer" , Call); return; } } while (false) | |||
1997 | "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) | |||
1998 | "must be constant integer",do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed ("gc.statepoint number of deoptimization arguments " "must be constant integer" , Call); return; } } while (false) | |||
1999 | Call)do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed ("gc.statepoint number of deoptimization arguments " "must be constant integer" , Call); return; } } while (false); | |||
2000 | const int NumDeoptArgs = cast<ConstantInt>(NumDeoptArgsV)->getZExtValue(); | |||
2001 | Assert(NumDeoptArgs >= 0,do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments " "must be positive", Call); return; } } while (false) | |||
2002 | "gc.statepoint number of deoptimization arguments "do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments " "must be positive", Call); return; } } while (false) | |||
2003 | "must be positive",do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments " "must be positive", Call); return; } } while (false) | |||
2004 | Call)do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments " "must be positive", Call); return; } } while (false); | |||
2005 | ||||
2006 | const int ExpectedNumArgs = | |||
2007 | 7 + NumCallArgs + NumTransitionArgs + NumDeoptArgs; | |||
2008 | 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) | |||
2009 | "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); | |||
2010 | ||||
2011 | // Check that the only uses of this gc.statepoint are gc.result or | |||
2012 | // gc.relocate calls which are tied to this statepoint and thus part | |||
2013 | // of the same statepoint sequence | |||
2014 | for (const User *U : Call.users()) { | |||
2015 | const CallInst *UserCall = dyn_cast<const CallInst>(U); | |||
2016 | Assert(UserCall, "illegal use of statepoint token", Call, U)do { if (!(UserCall)) { CheckFailed("illegal use of statepoint token" , Call, U); return; } } while (false); | |||
2017 | if (!UserCall) | |||
2018 | continue; | |||
2019 | 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) | |||
2020 | "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) | |||
2021 | "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) | |||
2022 | 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); | |||
2023 | if (isa<GCResultInst>(UserCall)) { | |||
2024 | Assert(UserCall->getArgOperand(0) == &Call,do { if (!(UserCall->getArgOperand(0) == &Call)) { CheckFailed ("gc.result connected to wrong gc.statepoint", Call, UserCall ); return; } } while (false) | |||
2025 | "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); | |||
2026 | } else if (isa<GCRelocateInst>(Call)) { | |||
2027 | Assert(UserCall->getArgOperand(0) == &Call,do { if (!(UserCall->getArgOperand(0) == &Call)) { CheckFailed ("gc.relocate connected to wrong gc.statepoint", Call, UserCall ); return; } } while (false) | |||
2028 | "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); | |||
2029 | } | |||
2030 | } | |||
2031 | ||||
2032 | // Note: It is legal for a single derived pointer to be listed multiple | |||
2033 | // times. It's non-optimal, but it is legal. It can also happen after | |||
2034 | // insertion if we strip a bitcast away. | |||
2035 | // Note: It is really tempting to check that each base is relocated and | |||
2036 | // that a derived pointer is never reused as a base pointer. This turns | |||
2037 | // out to be problematic since optimizations run after safepoint insertion | |||
2038 | // can recognize equality properties that the insertion logic doesn't know | |||
2039 | // about. See example statepoint.ll in the verifier subdirectory | |||
2040 | } | |||
2041 | ||||
2042 | void Verifier::verifyFrameRecoverIndices() { | |||
2043 | for (auto &Counts : FrameEscapeInfo) { | |||
2044 | Function *F = Counts.first; | |||
2045 | unsigned EscapedObjectCount = Counts.second.first; | |||
2046 | unsigned MaxRecoveredIndex = Counts.second.second; | |||
2047 | 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) | |||
2048 | "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) | |||
2049 | "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) | |||
2050 | "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) | |||
2051 | 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); | |||
2052 | } | |||
2053 | } | |||
2054 | ||||
2055 | static Instruction *getSuccPad(Instruction *Terminator) { | |||
2056 | BasicBlock *UnwindDest; | |||
2057 | if (auto *II = dyn_cast<InvokeInst>(Terminator)) | |||
2058 | UnwindDest = II->getUnwindDest(); | |||
2059 | else if (auto *CSI = dyn_cast<CatchSwitchInst>(Terminator)) | |||
2060 | UnwindDest = CSI->getUnwindDest(); | |||
2061 | else | |||
2062 | UnwindDest = cast<CleanupReturnInst>(Terminator)->getUnwindDest(); | |||
2063 | return UnwindDest->getFirstNonPHI(); | |||
2064 | } | |||
2065 | ||||
2066 | void Verifier::verifySiblingFuncletUnwinds() { | |||
2067 | SmallPtrSet<Instruction *, 8> Visited; | |||
2068 | SmallPtrSet<Instruction *, 8> Active; | |||
2069 | for (const auto &Pair : SiblingFuncletInfo) { | |||
2070 | Instruction *PredPad = Pair.first; | |||
2071 | if (Visited.count(PredPad)) | |||
2072 | continue; | |||
2073 | Active.insert(PredPad); | |||
2074 | Instruction *Terminator = Pair.second; | |||
2075 | do { | |||
2076 | Instruction *SuccPad = getSuccPad(Terminator); | |||
2077 | if (Active.count(SuccPad)) { | |||
2078 | // Found a cycle; report error | |||
2079 | Instruction *CyclePad = SuccPad; | |||
2080 | SmallVector<Instruction *, 8> CycleNodes; | |||
2081 | do { | |||
2082 | CycleNodes.push_back(CyclePad); | |||
2083 | Instruction *CycleTerminator = SiblingFuncletInfo[CyclePad]; | |||
2084 | if (CycleTerminator != CyclePad) | |||
2085 | CycleNodes.push_back(CycleTerminator); | |||
2086 | CyclePad = getSuccPad(CycleTerminator); | |||
2087 | } while (CyclePad != SuccPad); | |||
2088 | 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) | |||
2089 | ArrayRef<Instruction *>(CycleNodes))do { if (!(false)) { CheckFailed("EH pads can't handle each other's exceptions" , ArrayRef<Instruction *>(CycleNodes)); return; } } while (false); | |||
2090 | } | |||
2091 | // Don't re-walk a node we've already checked | |||
2092 | if (!Visited.insert(SuccPad).second) | |||
2093 | break; | |||
2094 | // Walk to this successor if it has a map entry. | |||
2095 | PredPad = SuccPad; | |||
2096 | auto TermI = SiblingFuncletInfo.find(PredPad); | |||
2097 | if (TermI == SiblingFuncletInfo.end()) | |||
2098 | break; | |||
2099 | Terminator = TermI->second; | |||
2100 | Active.insert(PredPad); | |||
2101 | } while (true); | |||
2102 | // Each node only has one successor, so we've walked all the active | |||
2103 | // nodes' successors. | |||
2104 | Active.clear(); | |||
2105 | } | |||
2106 | } | |||
2107 | ||||
2108 | // visitFunction - Verify that a function is ok. | |||
2109 | // | |||
2110 | void Verifier::visitFunction(const Function &F) { | |||
2111 | visitGlobalValue(F); | |||
2112 | ||||
2113 | // Check function arguments. | |||
2114 | FunctionType *FT = F.getFunctionType(); | |||
2115 | unsigned NumArgs = F.arg_size(); | |||
2116 | ||||
2117 | Assert(&Context == &F.getContext(),do { if (!(&Context == &F.getContext())) { CheckFailed ("Function context does not match Module context!", &F); return ; } } while (false) | |||
| ||||
2118 | "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); | |||
2119 | ||||
2120 | 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); | |||
2121 | Assert(FT->getNumParams() == NumArgs,do { if (!(FT->getNumParams() == NumArgs)) { CheckFailed("# formal arguments must match # of arguments for function type!" , &F, FT); return; } } while (false) | |||
2122 | "# 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) | |||
2123 | FT)do { if (!(FT->getNumParams() == NumArgs)) { CheckFailed("# formal arguments must match # of arguments for function type!" , &F, FT); return; } } while (false); | |||
2124 | 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) | |||
2125 | 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) | |||
2126 | "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); | |||
2127 | ||||
2128 | Assert(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy(),do { if (!(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy ())) { CheckFailed("Invalid struct return type!", &F); return ; } } while (false) | |||
2129 | "Invalid struct return type!", &F)do { if (!(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy ())) { CheckFailed("Invalid struct return type!", &F); return ; } } while (false); | |||
2130 | ||||
2131 | AttributeList Attrs = F.getAttributes(); | |||
2132 | ||||
2133 | Assert(verifyAttributeCount(Attrs, FT->getNumParams()),do { if (!(verifyAttributeCount(Attrs, FT->getNumParams()) )) { CheckFailed("Attribute after last parameter!", &F); return ; } } while (false) | |||
2134 | "Attribute after last parameter!", &F)do { if (!(verifyAttributeCount(Attrs, FT->getNumParams()) )) { CheckFailed("Attribute after last parameter!", &F); return ; } } while (false); | |||
2135 | ||||
2136 | bool isLLVMdotName = F.getName().size() >= 5 && | |||
2137 | F.getName().substr(0, 5) == "llvm."; | |||
2138 | ||||
2139 | // Check function attributes. | |||
2140 | verifyFunctionAttrs(FT, Attrs, &F, isLLVMdotName); | |||
2141 | ||||
2142 | // On function declarations/definitions, we do not support the builtin | |||
2143 | // attribute. We do not check this in VerifyFunctionAttrs since that is | |||
2144 | // checking for Attributes that can/can not ever be on functions. | |||
2145 | 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) | |||
2146 | "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); | |||
2147 | ||||
2148 | // Check that this function meets the restrictions on this calling convention. | |||
2149 | // Sometimes varargs is used for perfectly forwarding thunks, so some of these | |||
2150 | // restrictions can be lifted. | |||
2151 | switch (F.getCallingConv()) { | |||
2152 | default: | |||
2153 | case CallingConv::C: | |||
2154 | break; | |||
2155 | case CallingConv::AMDGPU_KERNEL: | |||
2156 | case CallingConv::SPIR_KERNEL: | |||
2157 | Assert(F.getReturnType()->isVoidTy(),do { if (!(F.getReturnType()->isVoidTy())) { CheckFailed("Calling convention requires void return type" , &F); return; } } while (false) | |||
2158 | "Calling convention requires void return type", &F)do { if (!(F.getReturnType()->isVoidTy())) { CheckFailed("Calling convention requires void return type" , &F); return; } } while (false); | |||
2159 | LLVM_FALLTHROUGH[[clang::fallthrough]]; | |||
2160 | case CallingConv::AMDGPU_VS: | |||
2161 | case CallingConv::AMDGPU_HS: | |||
2162 | case CallingConv::AMDGPU_GS: | |||
2163 | case CallingConv::AMDGPU_PS: | |||
2164 | case CallingConv::AMDGPU_CS: | |||
2165 | Assert(!F.hasStructRetAttr(),do { if (!(!F.hasStructRetAttr())) { CheckFailed("Calling convention does not allow sret" , &F); return; } } while (false) | |||
2166 | "Calling convention does not allow sret", &F)do { if (!(!F.hasStructRetAttr())) { CheckFailed("Calling convention does not allow sret" , &F); return; } } while (false); | |||
2167 | LLVM_FALLTHROUGH[[clang::fallthrough]]; | |||
2168 | case CallingConv::Fast: | |||
2169 | case CallingConv::Cold: | |||
2170 | case CallingConv::Intel_OCL_BI: | |||
2171 | case CallingConv::PTX_Kernel: | |||
2172 | case CallingConv::PTX_Device: | |||
2173 | 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) | |||
2174 | "perfect forwarding!",do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or " "perfect forwarding!", &F); return; } } while (false) | |||
2175 | &F)do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or " "perfect forwarding!", &F); return; } } while (false); | |||
2176 | break; | |||
2177 | } | |||
2178 | ||||
2179 | // Check that the argument values match the function type for this function... | |||
2180 | unsigned i = 0; | |||
2181 | for (const Argument &Arg : F.args()) { | |||
2182 | 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) | |||
2183 | "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) | |||
2184 | 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); | |||
2185 | Assert(Arg.getType()->isFirstClassType(),do { if (!(Arg.getType()->isFirstClassType())) { CheckFailed ("Function arguments must have first-class types!", &Arg) ; return; } } while (false) | |||
2186 | "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); | |||
2187 | if (!isLLVMdotName) { | |||
2188 | Assert(!Arg.getType()->isMetadataTy(),do { if (!(!Arg.getType()->isMetadataTy())) { CheckFailed( "Function takes metadata but isn't an intrinsic", &Arg, & F); return; } } while (false) | |||
2189 | "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); | |||
2190 | Assert(!Arg.getType()->isTokenTy(),do { if (!(!Arg.getType()->isTokenTy())) { CheckFailed("Function takes token but isn't an intrinsic" , &Arg, &F); return; } } while (false) | |||
2191 | "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); | |||
2192 | } | |||
2193 | ||||
2194 | // Check that swifterror argument is only used by loads and stores. | |||
2195 | if (Attrs.hasParamAttribute(i, Attribute::SwiftError)) { | |||
2196 | verifySwiftErrorValue(&Arg); | |||
2197 | } | |||
2198 | ++i; | |||
2199 | } | |||
2200 | ||||
2201 | if (!isLLVMdotName) | |||
2202 | Assert(!F.getReturnType()->isTokenTy(),do { if (!(!F.getReturnType()->isTokenTy())) { CheckFailed ("Functions returns a token but isn't an intrinsic", &F); return; } } while (false) | |||
2203 | "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); | |||
2204 | ||||
2205 | // Get the function metadata attachments. | |||
2206 | SmallVector<std::pair<unsigned, MDNode *>, 4> MDs; | |||
2207 | F.getAllMetadata(MDs); | |||
2208 | 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-9~svn360410/lib/IR/Verifier.cpp" , 2208, __PRETTY_FUNCTION__)); | |||
2209 | verifyFunctionMetadata(MDs); | |||
2210 | ||||
2211 | // Check validity of the personality function | |||
2212 | if (F.hasPersonalityFn()) { | |||
2213 | auto *Per = dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts()); | |||
2214 | if (Per) | |||
2215 | 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) | |||
2216 | "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) | |||
2217 | &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); | |||
2218 | } | |||
2219 | ||||
2220 | if (F.isMaterializable()) { | |||
2221 | // Function has a body somewhere we can't see. | |||
2222 | 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) | |||
2223 | 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); | |||
2224 | } else if (F.isDeclaration()) { | |||
2225 | for (const auto &I : MDs) { | |||
2226 | AssertDI(I.first != LLVMContext::MD_dbg,do { if (!(I.first != LLVMContext::MD_dbg)) { DebugInfoCheckFailed ("function declaration may not have a !dbg attachment", & F); return; } } while (false) | |||
2227 | "function declaration may not have a !dbg attachment", &F)do { if (!(I.first != LLVMContext::MD_dbg)) { DebugInfoCheckFailed ("function declaration may not have a !dbg attachment", & F); return; } } while (false); | |||
2228 | 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) | |||
2229 | "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); | |||
2230 | ||||
2231 | // Verify the metadata itself. | |||
2232 | visitMDNode(*I.second); | |||
2233 | } | |||
2234 | Assert(!F.hasPersonalityFn(),do { if (!(!F.hasPersonalityFn())) { CheckFailed("Function declaration shouldn't have a personality routine" , &F); return; } } while (false) | |||
2235 | "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); | |||
2236 | } else { | |||
2237 | // Verify that this function (which has a body) is not named "llvm.*". It | |||
2238 | // is not legal to define intrinsics. | |||
2239 | Assert(!isLLVMdotName, "llvm intrinsics cannot be defined!", &F)do { if (!(!isLLVMdotName)) { CheckFailed("llvm intrinsics cannot be defined!" , &F); return; } } while (false); | |||
2240 | ||||
2241 | // Check the entry node | |||
2242 | const BasicBlock *Entry = &F.getEntryBlock(); | |||
2243 | Assert(pred_empty(Entry),do { if (!(pred_empty(Entry))) { CheckFailed("Entry block to function must not have predecessors!" , Entry); return; } } while (false) | |||
2244 | "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); | |||
2245 | ||||
2246 | // The address of the entry block cannot be taken, unless it is dead. | |||
2247 | if (Entry->hasAddressTaken()) { | |||
2248 | 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) | |||
2249 | "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); | |||
2250 | } | |||
2251 | ||||
2252 | unsigned NumDebugAttachments = 0, NumProfAttachments = 0; | |||
2253 | // Visit metadata attachments. | |||
2254 | for (const auto &I : MDs) { | |||
2255 | // Verify that the attachment is legal. | |||
2256 | switch (I.first) { | |||
2257 | default: | |||
2258 | break; | |||
2259 | case LLVMContext::MD_dbg: { | |||
2260 | ++NumDebugAttachments; | |||
2261 | AssertDI(NumDebugAttachments == 1,do { if (!(NumDebugAttachments == 1)) { DebugInfoCheckFailed( "function must have a single !dbg attachment", &F, I.second ); return; } } while (false) | |||
2262 | "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); | |||
2263 | 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) | |||
2264 | "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); | |||
2265 | auto *SP = cast<DISubprogram>(I.second); | |||
2266 | const Function *&AttachedTo = DISubprogramAttachments[SP]; | |||
2267 | AssertDI(!AttachedTo || AttachedTo == &F,do { if (!(!AttachedTo || AttachedTo == &F)) { DebugInfoCheckFailed ("DISubprogram attached to more than one function", SP, & F); return; } } while (false) | |||
2268 | "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); | |||
2269 | AttachedTo = &F; | |||
2270 | break; | |||
2271 | } | |||
2272 | case LLVMContext::MD_prof: | |||
2273 | ++NumProfAttachments; | |||
2274 | Assert(NumProfAttachments == 1,do { if (!(NumProfAttachments == 1)) { CheckFailed("function must have a single !prof attachment" , &F, I.second); return; } } while (false) | |||
2275 | "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); | |||
2276 | break; | |||
2277 | } | |||
2278 | ||||
2279 | // Verify the metadata itself. | |||
2280 | visitMDNode(*I.second); | |||
2281 | } | |||
2282 | } | |||
2283 | ||||
2284 | // If this function is actually an intrinsic, verify that it is only used in | |||
2285 | // direct call/invokes, never having its "address taken". | |||
2286 | // Only do this if the module is materialized, otherwise we don't have all the | |||
2287 | // uses. | |||
2288 | if (F.getIntrinsicID() && F.getParent()->isMaterialized()) { | |||
2289 | const User *U; | |||
2290 | if (F.hasAddressTaken(&U)) | |||
2291 | Assert(false, "Invalid user of intrinsic instruction!", U)do { if (!(false)) { CheckFailed("Invalid user of intrinsic instruction!" , U); return; } } while (false); | |||
2292 | } | |||
2293 | ||||
2294 | auto *N = F.getSubprogram(); | |||
2295 | HasDebugInfo = (N != nullptr); | |||
2296 | if (!HasDebugInfo) | |||
2297 | return; | |||
2298 | ||||
2299 | // Check that all !dbg attachments lead to back to N (or, at least, another | |||
2300 | // subprogram that describes the same function). | |||
2301 | // | |||
2302 | // FIXME: Check this incrementally while visiting !dbg attachments. | |||
2303 | // FIXME: Only check when N is the canonical subprogram for F. | |||
2304 | SmallPtrSet<const MDNode *, 32> Seen; | |||
2305 | for (auto &BB : F) | |||
2306 | for (auto &I : BB) { | |||
2307 | // Be careful about using DILocation here since we might be dealing with | |||
2308 | // broken code (this is the Verifier after all). | |||
2309 | DILocation *DL = | |||
2310 | dyn_cast_or_null<DILocation>(I.getDebugLoc().getAsMDNode()); | |||
2311 | if (!DL) | |||
2312 | continue; | |||
2313 | if (!Seen.insert(DL).second) | |||
2314 | continue; | |||
2315 | ||||
2316 | Metadata *Parent = DL->getRawScope(); | |||
2317 | 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) | |||
2318 | "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) | |||
2319 | Parent)do { if (!(Parent && isa<DILocalScope>(Parent)) ) { DebugInfoCheckFailed("DILocation's scope must be a DILocalScope" , N, &F, &I, DL, Parent); return; } } while (false); | |||
2320 | DILocalScope *Scope = DL->getInlinedAtScope(); | |||
2321 | if (Scope && !Seen.insert(Scope).second) | |||
2322 | continue; | |||
2323 | ||||
2324 | DISubprogram *SP = Scope ? Scope->getSubprogram() : nullptr; | |||
2325 | ||||
2326 | // Scope and SP could be the same MDNode and we don't want to skip | |||
2327 | // validation in that case | |||
2328 | if (SP && ((Scope != SP) && !Seen.insert(SP).second)) | |||
2329 | continue; | |||
2330 | ||||
2331 | // FIXME: Once N is canonical, check "SP == &N". | |||
2332 | 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) | |||
| ||||
2333 | "!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) | |||
2334 | &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); | |||
2335 | } | |||
2336 | } | |||
2337 | ||||
2338 | // verifyBasicBlock - Verify that a basic block is well formed... | |||
2339 | // | |||
2340 | void Verifier::visitBasicBlock(BasicBlock &BB) { | |||
2341 | InstsInThisBlock.clear(); | |||
2342 | ||||
2343 | // Ensure that basic blocks have terminators! | |||
2344 | 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); | |||
2345 | ||||
2346 | // Check constraints that this basic block imposes on all of the PHI nodes in | |||
2347 | // it. | |||
2348 | if (isa<PHINode>(BB.front())) { | |||
2349 | SmallVector<BasicBlock*, 8> Preds(pred_begin(&BB), pred_end(&BB)); | |||
2350 | SmallVector<std::pair<BasicBlock*, Value*>, 8> Values; | |||
2351 | llvm::sort(Preds); | |||
2352 | for (const PHINode &PN : BB.phis()) { | |||
2353 | // Ensure that PHI nodes have at least one entry! | |||
2354 | 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 ) | |||
2355 | "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 ) | |||
2356 | "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 ) | |||
2357 | &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 ); | |||
2358 | 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) | |||
2359 | "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) | |||
2360 | "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) | |||
2361 | &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); | |||
2362 | ||||
2363 | // Get and sort all incoming values in the PHI node... | |||
2364 | Values.clear(); | |||
2365 | Values.reserve(PN.getNumIncomingValues()); | |||
2366 | for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) | |||
2367 | Values.push_back( | |||
2368 | std::make_pair(PN.getIncomingBlock(i), PN.getIncomingValue(i))); | |||
2369 | llvm::sort(Values); | |||
2370 | ||||
2371 | for (unsigned i = 0, e = Values.size(); i != e; ++i) { | |||
2372 | // Check to make sure that if there is more than one entry for a | |||
2373 | // particular basic block in this PHI node, that the incoming values are | |||
2374 | // all identical. | |||
2375 | // | |||
2376 | 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) | |||
2377 | 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) | |||
2378 | "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) | |||
2379 | "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) | |||
2380 | &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); | |||
2381 | ||||
2382 | // Check to make sure that the predecessors and PHI node entries are | |||
2383 | // matched up. | |||
2384 | 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 ) | |||
2385 | "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 ) | |||
2386 | 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 ); | |||
2387 | } | |||
2388 | } | |||
2389 | } | |||
2390 | ||||
2391 | // Check that all instructions have their parent pointers set up correctly. | |||
2392 | for (auto &I : BB) | |||
2393 | { | |||
2394 | Assert(I.getParent() == &BB, "Instruction has bogus parent pointer!")do { if (!(I.getParent() == &BB)) { CheckFailed("Instruction has bogus parent pointer!" ); return; } } while (false); | |||
2395 | } | |||
2396 | } | |||
2397 | ||||
2398 | void Verifier::visitTerminator(Instruction &I) { | |||
2399 | // Ensure that terminators only exist at the end of the basic block. | |||
2400 | 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) | |||
2401 | "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); | |||
2402 | visitInstruction(I); | |||
2403 | } | |||
2404 | ||||
2405 | void Verifier::visitBranchInst(BranchInst &BI) { | |||
2406 | if (BI.isConditional()) { | |||
2407 | 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) | |||
2408 | "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); | |||
2409 | } | |||
2410 | visitTerminator(BI); | |||
2411 | } | |||
2412 | ||||
2413 | void Verifier::visitReturnInst(ReturnInst &RI) { | |||
2414 | Function *F = RI.getParent()->getParent(); | |||
2415 | unsigned N = RI.getNumOperands(); | |||
2416 | if (F->getReturnType()->isVoidTy()) | |||
2417 | 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) | |||
2418 | "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) | |||
2419 | "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) | |||
2420 | &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); | |||
2421 | else | |||
2422 | 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) | |||
2423 | "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) | |||
2424 | "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) | |||
2425 | &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); | |||
2426 | ||||
2427 | // Check to make sure that the return value has necessary properties for | |||
2428 | // terminators... | |||
2429 | visitTerminator(RI); | |||
2430 | } | |||
2431 | ||||
2432 | void Verifier::visitSwitchInst(SwitchInst &SI) { | |||
2433 | // Check to make sure that all of the constants in the switch instruction | |||
2434 | // have the same type as the switched-on value. | |||
2435 | Type *SwitchTy = SI.getCondition()->getType(); | |||
2436 | SmallPtrSet<ConstantInt*, 32> Constants; | |||
2437 | for (auto &Case : SI.cases()) { | |||
2438 | 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) | |||
2439 | "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); | |||
2440 | 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) | |||
2441 | "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); | |||
2442 | } | |||
2443 | ||||
2444 | visitTerminator(SI); | |||
2445 | } | |||
2446 | ||||
2447 | void Verifier::visitIndirectBrInst(IndirectBrInst &BI) { | |||
2448 | Assert(BI.getAddress()->getType()->isPointerTy(),do { if (!(BI.getAddress()->getType()->isPointerTy())) { CheckFailed("Indirectbr operand must have pointer type!", & BI); return; } } while (false) | |||
2449 | "Indirectbr operand must have pointer type!", &BI)do { if (!(BI.getAddress()->getType()->isPointerTy())) { CheckFailed("Indirectbr operand must have pointer type!", & BI); return; } } while (false); | |||
2450 | for (unsigned i = 0, e = BI.getNumDestinations(); i != e; ++i) | |||
2451 | 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) | |||
2452 | "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); | |||
2453 | ||||
2454 | visitTerminator(BI); | |||
2455 | } | |||
2456 | ||||
2457 | void Verifier::visitCallBrInst(CallBrInst &CBI) { | |||
2458 | 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) | |||
2459 | &CBI)do { if (!(CBI.isInlineAsm())) { CheckFailed("Callbr is currently only used for asm-goto!" , &CBI); return; } } while (false); | |||
2460 | 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) | |||
2461 | &CBI)do { if (!(CBI.getType()->isVoidTy())) { CheckFailed("Callbr return value is not supported!" , &CBI); return; } } while (false); | |||
2462 | for (unsigned i = 0, e = CBI.getNumSuccessors(); i != e; ++i) | |||
2463 | 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) | |||
2464 | "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); | |||
2465 | for (unsigned i = 0, e = CBI.getNumOperands(); i != e; ++i) { | |||
2466 | 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) | |||
2467 | "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); | |||
2468 | if (isa<BasicBlock>(CBI.getOperand(i))) | |||
2469 | for (unsigned j = i + 1; j != e; ++j) | |||
2470 | Assert(CBI.getOperand(i) != CBI.getOperand(j),do { if (!(CBI.getOperand(i) != CBI.getOperand(j))) { CheckFailed ("Duplicate callbr destination!", &CBI); return; } } while (false) | |||
2471 | "Duplicate callbr destination!", &CBI)do { if (!(CBI.getOperand(i) != CBI.getOperand(j))) { CheckFailed ("Duplicate callbr destination!", &CBI); return; } } while (false); | |||
2472 | } | |||
2473 | ||||
2474 | visitTerminator(CBI); | |||
2475 | } | |||
2476 | ||||
2477 | void Verifier::visitSelectInst(SelectInst &SI) { | |||
2478 | 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) | |||
2479 | 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) | |||
2480 | "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); | |||
2481 | ||||
2482 | 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) | |||
2483 | "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); | |||
2484 | visitInstruction(SI); | |||
2485 | } | |||
2486 | ||||
2487 | /// visitUserOp1 - User defined operators shouldn't live beyond the lifetime of | |||
2488 | /// a pass, if any exist, it's an error. | |||
2489 | /// | |||
2490 | void Verifier::visitUserOp1(Instruction &I) { | |||
2491 | 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); | |||
2492 | } | |||
2493 | ||||
2494 | void Verifier::visitTruncInst(TruncInst &I) { | |||
2495 | // Get the source and destination types | |||
2496 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2497 | Type *DestTy = I.getType(); | |||
2498 | ||||
2499 | // Get the size of the types in bits, we'll need this later | |||
2500 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | |||
2501 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | |||
2502 | ||||
2503 | Assert(SrcTy->isIntOrIntVectorTy(), "Trunc only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("Trunc only operates on integer" , &I); return; } } while (false); | |||
2504 | Assert(DestTy->isIntOrIntVectorTy(), "Trunc only produces integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("Trunc only produces integer" , &I); return; } } while (false); | |||
2505 | 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) | |||
2506 | "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); | |||
2507 | Assert(SrcBitSize > DestBitSize, "DestTy too big for Trunc", &I)do { if (!(SrcBitSize > DestBitSize)) { CheckFailed("DestTy too big for Trunc" , &I); return; } } while (false); | |||
2508 | ||||
2509 | visitInstruction(I); | |||
2510 | } | |||
2511 | ||||
2512 | void Verifier::visitZExtInst(ZExtInst &I) { | |||
2513 | // Get the source and destination types | |||
2514 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2515 | Type *DestTy = I.getType(); | |||
2516 | ||||
2517 | // Get the size of the types in bits, we'll need this later | |||
2518 | Assert(SrcTy->isIntOrIntVectorTy(), "ZExt only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("ZExt only operates on integer" , &I); return; } } while (false); | |||
2519 | Assert(DestTy->isIntOrIntVectorTy(), "ZExt only produces an integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("ZExt only produces an integer" , &I); return; } } while (false); | |||
2520 | 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) | |||
2521 | "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); | |||
2522 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | |||
2523 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | |||
2524 | ||||
2525 | Assert(SrcBitSize < DestBitSize, "Type too small for ZExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("Type too small for ZExt" , &I); return; } } while (false); | |||
2526 | ||||
2527 | visitInstruction(I); | |||
2528 | } | |||
2529 | ||||
2530 | void Verifier::visitSExtInst(SExtInst &I) { | |||
2531 | // Get the source and destination types | |||
2532 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2533 | Type *DestTy = I.getType(); | |||
2534 | ||||
2535 | // Get the size of the types in bits, we'll need this later | |||
2536 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | |||
2537 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | |||
2538 | ||||
2539 | Assert(SrcTy->isIntOrIntVectorTy(), "SExt only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("SExt only operates on integer" , &I); return; } } while (false); | |||
2540 | Assert(DestTy->isIntOrIntVectorTy(), "SExt only produces an integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("SExt only produces an integer" , &I); return; } } while (false); | |||
2541 | 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) | |||
2542 | "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); | |||
2543 | Assert(SrcBitSize < DestBitSize, "Type too small for SExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("Type too small for SExt" , &I); return; } } while (false); | |||
2544 | ||||
2545 | visitInstruction(I); | |||
2546 | } | |||
2547 | ||||
2548 | void Verifier::visitFPTruncInst(FPTruncInst &I) { | |||
2549 | // Get the source and destination types | |||
2550 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2551 | Type *DestTy = I.getType(); | |||
2552 | // Get the size of the types in bits, we'll need this later | |||
2553 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | |||
2554 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | |||
2555 | ||||
2556 | Assert(SrcTy->isFPOrFPVectorTy(), "FPTrunc only operates on FP", &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPTrunc only operates on FP" , &I); return; } } while (false); | |||
2557 | Assert(DestTy->isFPOrFPVectorTy(), "FPTrunc only produces an FP", &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("FPTrunc only produces an FP" , &I); return; } } while (false); | |||
2558 | 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) | |||
2559 | "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); | |||
2560 | Assert(SrcBitSize > DestBitSize, "DestTy too big for FPTrunc", &I)do { if (!(SrcBitSize > DestBitSize)) { CheckFailed("DestTy too big for FPTrunc" , &I); return; } } while (false); | |||
2561 | ||||
2562 | visitInstruction(I); | |||
2563 | } | |||
2564 | ||||
2565 | void Verifier::visitFPExtInst(FPExtInst &I) { | |||
2566 | // Get the source and destination types | |||
2567 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2568 | Type *DestTy = I.getType(); | |||
2569 | ||||
2570 | // Get the size of the types in bits, we'll need this later | |||
2571 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | |||
2572 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | |||
2573 | ||||
2574 | Assert(SrcTy->isFPOrFPVectorTy(), "FPExt only operates on FP", &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPExt only operates on FP" , &I); return; } } while (false); | |||
2575 | Assert(DestTy->isFPOrFPVectorTy(), "FPExt only produces an FP", &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("FPExt only produces an FP" , &I); return; } } while (false); | |||
2576 | 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) | |||
2577 | "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); | |||
2578 | Assert(SrcBitSize < DestBitSize, "DestTy too small for FPExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("DestTy too small for FPExt" , &I); return; } } while (false); | |||
2579 | ||||
2580 | visitInstruction(I); | |||
2581 | } | |||
2582 | ||||
2583 | void Verifier::visitUIToFPInst(UIToFPInst &I) { | |||
2584 | // Get the source and destination types | |||
2585 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2586 | Type *DestTy = I.getType(); | |||
2587 | ||||
2588 | bool SrcVec = SrcTy->isVectorTy(); | |||
2589 | bool DstVec = DestTy->isVectorTy(); | |||
2590 | ||||
2591 | Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("UIToFP source and dest must both be vector or scalar" , &I); return; } } while (false) | |||
2592 | "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); | |||
2593 | Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("UIToFP source must be integer or integer vector" , &I); return; } } while (false) | |||
2594 | "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); | |||
2595 | 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) | |||
2596 | &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("UIToFP result must be FP or FP vector" , &I); return; } } while (false); | |||
2597 | ||||
2598 | if (SrcVec && DstVec) | |||
2599 | 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) | |||
2600 | 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) | |||
2601 | "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); | |||
2602 | ||||
2603 | visitInstruction(I); | |||
2604 | } | |||
2605 | ||||
2606 | void Verifier::visitSIToFPInst(SIToFPInst &I) { | |||
2607 | // Get the source and destination types | |||
2608 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2609 | Type *DestTy = I.getType(); | |||
2610 | ||||
2611 | bool SrcVec = SrcTy->isVectorTy(); | |||
2612 | bool DstVec = DestTy->isVectorTy(); | |||
2613 | ||||
2614 | Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("SIToFP source and dest must both be vector or scalar" , &I); return; } } while (false) | |||
2615 | "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); | |||
2616 | Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("SIToFP source must be integer or integer vector" , &I); return; } } while (false) | |||
2617 | "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); | |||
2618 | 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) | |||
2619 | &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("SIToFP result must be FP or FP vector" , &I); return; } } while (false); | |||
2620 | ||||
2621 | if (SrcVec && DstVec) | |||
2622 | 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) | |||
2623 | 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) | |||
2624 | "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); | |||
2625 | ||||
2626 | visitInstruction(I); | |||
2627 | } | |||
2628 | ||||
2629 | void Verifier::visitFPToUIInst(FPToUIInst &I) { | |||
2630 | // Get the source and destination types | |||
2631 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2632 | Type *DestTy = I.getType(); | |||
2633 | ||||
2634 | bool SrcVec = SrcTy->isVectorTy(); | |||
2635 | bool DstVec = DestTy->isVectorTy(); | |||
2636 | ||||
2637 | Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("FPToUI source and dest must both be vector or scalar" , &I); return; } } while (false) | |||
2638 | "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); | |||
2639 | 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) | |||
2640 | &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToUI source must be FP or FP vector" , &I); return; } } while (false); | |||
2641 | Assert(DestTy->isIntOrIntVectorTy(),do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToUI result must be integer or integer vector" , &I); return; } } while (false) | |||
2642 | "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); | |||
2643 | ||||
2644 | if (SrcVec && DstVec) | |||
2645 | 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) | |||
2646 | 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) | |||
2647 | "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); | |||
2648 | ||||
2649 | visitInstruction(I); | |||
2650 | } | |||
2651 | ||||
2652 | void Verifier::visitFPToSIInst(FPToSIInst &I) { | |||
2653 | // Get the source and destination types | |||
2654 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2655 | Type *DestTy = I.getType(); | |||
2656 | ||||
2657 | bool SrcVec = SrcTy->isVectorTy(); | |||
2658 | bool DstVec = DestTy->isVectorTy(); | |||
2659 | ||||
2660 | Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("FPToSI source and dest must both be vector or scalar" , &I); return; } } while (false) | |||
2661 | "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); | |||
2662 | 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) | |||
2663 | &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToSI source must be FP or FP vector" , &I); return; } } while (false); | |||
2664 | Assert(DestTy->isIntOrIntVectorTy(),do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToSI result must be integer or integer vector" , &I); return; } } while (false) | |||
2665 | "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); | |||
2666 | ||||
2667 | if (SrcVec && DstVec) | |||
2668 | 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) | |||
2669 | 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) | |||
2670 | "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); | |||
2671 | ||||
2672 | visitInstruction(I); | |||
2673 | } | |||
2674 | ||||
2675 | void Verifier::visitPtrToIntInst(PtrToIntInst &I) { | |||
2676 | // Get the source and destination types | |||
2677 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2678 | Type *DestTy = I.getType(); | |||
2679 | ||||
2680 | Assert(SrcTy->isPtrOrPtrVectorTy(), "PtrToInt source must be pointer", &I)do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("PtrToInt source must be pointer" , &I); return; } } while (false); | |||
2681 | ||||
2682 | if (auto *PTy = dyn_cast<PointerType>(SrcTy->getScalarType())) | |||
2683 | Assert(!DL.isNonIntegralPointerType(PTy),do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed( "ptrtoint not supported for non-integral pointers"); return; } } while (false) | |||
2684 | "ptrtoint not supported for non-integral pointers")do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed( "ptrtoint not supported for non-integral pointers"); return; } } while (false); | |||
2685 | ||||
2686 | Assert(DestTy->isIntOrIntVectorTy(), "PtrToInt result must be integral", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("PtrToInt result must be integral" , &I); return; } } while (false); | |||
2687 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(), "PtrToInt type mismatch",do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("PtrToInt type mismatch", &I); return; } } while (false) | |||
2688 | &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("PtrToInt type mismatch", &I); return; } } while (false); | |||
2689 | ||||
2690 | if (SrcTy->isVectorTy()) { | |||
2691 | VectorType *VSrc = dyn_cast<VectorType>(SrcTy); | |||
2692 | VectorType *VDest = dyn_cast<VectorType>(DestTy); | |||
2693 | Assert(VSrc->getNumElements() == VDest->getNumElements(),do { if (!(VSrc->getNumElements() == VDest->getNumElements ())) { CheckFailed("PtrToInt Vector width mismatch", &I); return; } } while (false) | |||
2694 | "PtrToInt Vector width mismatch", &I)do { if (!(VSrc->getNumElements() == VDest->getNumElements ())) { CheckFailed("PtrToInt Vector width mismatch", &I); return; } } while (false); | |||
2695 | } | |||
2696 | ||||
2697 | visitInstruction(I); | |||
2698 | } | |||
2699 | ||||
2700 | void Verifier::visitIntToPtrInst(IntToPtrInst &I) { | |||
2701 | // Get the source and destination types | |||
2702 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2703 | Type *DestTy = I.getType(); | |||
2704 | ||||
2705 | Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("IntToPtr source must be an integral" , &I); return; } } while (false) | |||
2706 | "IntToPtr source must be an integral", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("IntToPtr source must be an integral" , &I); return; } } while (false); | |||
2707 | 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); | |||
2708 | ||||
2709 | if (auto *PTy = dyn_cast<PointerType>(DestTy->getScalarType())) | |||
2710 | Assert(!DL.isNonIntegralPointerType(PTy),do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed( "inttoptr not supported for non-integral pointers"); return; } } while (false) | |||
2711 | "inttoptr not supported for non-integral pointers")do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed( "inttoptr not supported for non-integral pointers"); return; } } while (false); | |||
2712 | ||||
2713 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(), "IntToPtr type mismatch",do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("IntToPtr type mismatch", &I); return; } } while (false) | |||
2714 | &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("IntToPtr type mismatch", &I); return; } } while (false); | |||
2715 | if (SrcTy->isVectorTy()) { | |||
2716 | VectorType *VSrc = dyn_cast<VectorType>(SrcTy); | |||
2717 | VectorType *VDest = dyn_cast<VectorType>(DestTy); | |||
2718 | Assert(VSrc->getNumElements() == VDest->getNumElements(),do { if (!(VSrc->getNumElements() == VDest->getNumElements ())) { CheckFailed("IntToPtr Vector width mismatch", &I); return; } } while (false) | |||
2719 | "IntToPtr Vector width mismatch", &I)do { if (!(VSrc->getNumElements() == VDest->getNumElements ())) { CheckFailed("IntToPtr Vector width mismatch", &I); return; } } while (false); | |||
2720 | } | |||
2721 | visitInstruction(I); | |||
2722 | } | |||
2723 | ||||
2724 | void Verifier::visitBitCastInst(BitCastInst &I) { | |||
2725 | Assert(do { if (!(CastInst::castIsValid(Instruction::BitCast, I.getOperand (0), I.getType()))) { CheckFailed("Invalid bitcast", &I); return; } } while (false) | |||
2726 | 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) | |||
2727 | "Invalid bitcast", &I)do { if (!(CastInst::castIsValid(Instruction::BitCast, I.getOperand (0), I.getType()))) { CheckFailed("Invalid bitcast", &I); return; } } while (false); | |||
2728 | visitInstruction(I); | |||
2729 | } | |||
2730 | ||||
2731 | void Verifier::visitAddrSpaceCastInst(AddrSpaceCastInst &I) { | |||
2732 | Type *SrcTy = I.getOperand(0)->getType(); | |||
2733 | Type *DestTy = I.getType(); | |||
2734 | ||||
2735 | Assert(SrcTy->isPtrOrPtrVectorTy(), "AddrSpaceCast source must be a pointer",do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast source must be a pointer" , &I); return; } } while (false) | |||
2736 | &I)do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast source must be a pointer" , &I); return; } } while (false); | |||
2737 | Assert(DestTy->isPtrOrPtrVectorTy(), "AddrSpaceCast result must be a pointer",do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast result must be a pointer" , &I); return; } } while (false) | |||
2738 | &I)do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast result must be a pointer" , &I); return; } } while (false); | |||
2739 | Assert(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace(),do { if (!(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace ())) { CheckFailed("AddrSpaceCast must be between different address spaces" , &I); return; } } while (false) | |||
2740 | "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); | |||
2741 | if (SrcTy->isVectorTy()) | |||
2742 | Assert(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements(),do { if (!(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements ())) { CheckFailed("AddrSpaceCast vector pointer number of elements mismatch" , &I); return; } } while (false) | |||
2743 | "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); | |||
2744 | visitInstruction(I); | |||
2745 | } | |||
2746 | ||||
2747 | /// visitPHINode - Ensure that a PHI node is well formed. | |||
2748 | /// | |||
2749 | void Verifier::visitPHINode(PHINode &PN) { | |||
2750 | // Ensure that the PHI nodes are all grouped together at the top of the block. | |||
2751 | // This can be tested by checking whether the instruction before this is | |||
2752 | // either nonexistent (because this is begin()) or is a PHI node. If not, | |||
2753 | // then there is some other instruction before a PHI. | |||
2754 | 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) | |||
2755 | 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) | |||
2756 | "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); | |||
2757 | ||||
2758 | // Check that a PHI doesn't yield a Token. | |||
2759 | 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); | |||
2760 | ||||
2761 | // Check that all of the values of the PHI node have the same type as the | |||
2762 | // result, and that the incoming blocks are really basic blocks. | |||
2763 | for (Value *IncValue : PN.incoming_values()) { | |||
2764 | 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) | |||
2765 | "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); | |||
2766 | } | |||
2767 | ||||
2768 | // All other PHI node constraints are checked in the visitBasicBlock method. | |||
2769 | ||||
2770 | visitInstruction(PN); | |||
2771 | } | |||
2772 | ||||
2773 | void Verifier::visitCallBase(CallBase &Call) { | |||
2774 | Assert(Call.getCalledValue()->getType()->isPointerTy(),do { if (!(Call.getCalledValue()->getType()->isPointerTy ())) { CheckFailed("Called function must be a pointer!", Call ); return; } } while (false) | |||
2775 | "Called function must be a pointer!", Call)do { if (!(Call.getCalledValue()->getType()->isPointerTy ())) { CheckFailed("Called function must be a pointer!", Call ); return; } } while (false); | |||
2776 | PointerType *FPTy = cast<PointerType>(Call.getCalledValue()->getType()); | |||
2777 | ||||
2778 | Assert(FPTy->getElementType()->isFunctionTy(),do { if (!(FPTy->getElementType()->isFunctionTy())) { CheckFailed ("Called function is not pointer to function type!", Call); return ; } } while (false) | |||
2779 | "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); | |||
2780 | ||||
2781 | 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) | |||
2782 | "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); | |||
2783 | ||||
2784 | FunctionType *FTy = Call.getFunctionType(); | |||
2785 | ||||
2786 | // Verify that the correct number of arguments are being passed | |||
2787 | if (FTy->isVarArg()) | |||
2788 | 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) | |||
2789 | "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) | |||
2790 | Call)do { if (!(Call.arg_size() >= FTy->getNumParams())) { CheckFailed ("Called function requires more parameters than were provided!" , Call); return; } } while (false); | |||
2791 | else | |||
2792 | 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) | |||
2793 | "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); | |||
2794 | ||||
2795 | // Verify that all arguments to the call match the function type. | |||
2796 | for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) | |||
2797 | 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) | |||
2798 | "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) | |||
2799 | 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); | |||
2800 | ||||
2801 | AttributeList Attrs = Call.getAttributes(); | |||
2802 | ||||
2803 | Assert(verifyAttributeCount(Attrs, Call.arg_size()),do { if (!(verifyAttributeCount(Attrs, Call.arg_size()))) { CheckFailed ("Attribute after last parameter!", Call); return; } } while ( false) | |||
2804 | "Attribute after last parameter!", Call)do { if (!(verifyAttributeCount(Attrs, Call.arg_size()))) { CheckFailed ("Attribute after last parameter!", Call); return; } } while ( false); | |||
2805 | ||||
2806 | bool IsIntrinsic = Call.getCalledFunction() && | |||
2807 | Call.getCalledFunction()->getName().startswith("llvm."); | |||
2808 | ||||
2809 | Function *Callee | |||
2810 | = dyn_cast<Function>(Call.getCalledValue()->stripPointerCasts()); | |||
2811 | ||||
2812 | if (Attrs.hasAttribute(AttributeList::FunctionIndex, Attribute::Speculatable)) { | |||
2813 | // Don't allow speculatable on call sites, unless the underlying function | |||
2814 | // declaration is also speculatable. | |||
2815 | Assert(Callee && Callee->isSpeculatable(),do { if (!(Callee && Callee->isSpeculatable())) { CheckFailed ("speculatable attribute may not apply to call sites", Call); return; } } while (false) | |||
2816 | "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); | |||
2817 | } | |||
2818 | ||||
2819 | // Verify call attributes. | |||
2820 | verifyFunctionAttrs(FTy, Attrs, &Call, IsIntrinsic); | |||
2821 | ||||
2822 | // Conservatively check the inalloca argument. | |||
2823 | // We have a bug if we can find that there is an underlying alloca without | |||
2824 | // inalloca. | |||
2825 | if (Call.hasInAllocaArgument()) { | |||
2826 | Value *InAllocaArg = Call.getArgOperand(FTy->getNumParams() - 1); | |||
2827 | if (auto AI = dyn_cast<AllocaInst>(InAllocaArg->stripInBoundsOffsets())) | |||
2828 | Assert(AI->isUsedWithInAlloca(),do { if (!(AI->isUsedWithInAlloca())) { CheckFailed("inalloca argument for call has mismatched alloca" , AI, Call); return; } } while (false) | |||
2829 | "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); | |||
2830 | } | |||
2831 | ||||
2832 | // For each argument of the callsite, if it has the swifterror argument, | |||
2833 | // make sure the underlying alloca/parameter it comes from has a swifterror as | |||
2834 | // well. | |||
2835 | for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) { | |||
2836 | if (Call.paramHasAttr(i, Attribute::SwiftError)) { | |||
2837 | Value *SwiftErrorArg = Call.getArgOperand(i); | |||
2838 | if (auto AI = dyn_cast<AllocaInst>(SwiftErrorArg->stripInBoundsOffsets())) { | |||
2839 | Assert(AI->isSwiftError(),do { if (!(AI->isSwiftError())) { CheckFailed("swifterror argument for call has mismatched alloca" , AI, Call); return; } } while (false) | |||
2840 | "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); | |||
2841 | continue; | |||
2842 | } | |||
2843 | auto ArgI = dyn_cast<Argument>(SwiftErrorArg); | |||
2844 | Assert(ArgI,do { if (!(ArgI)) { CheckFailed("swifterror argument should come from an alloca or parameter" , SwiftErrorArg, Call); return; } } while (false) | |||
2845 | "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) | |||
2846 | SwiftErrorArg, Call)do { if (!(ArgI)) { CheckFailed("swifterror argument should come from an alloca or parameter" , SwiftErrorArg, Call); return; } } while (false); | |||
2847 | Assert(ArgI->hasSwiftErrorAttr(),do { if (!(ArgI->hasSwiftErrorAttr())) { CheckFailed("swifterror argument for call has mismatched parameter" , ArgI, Call); return; } } while (false) | |||
2848 | "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) | |||
2849 | Call)do { if (!(ArgI->hasSwiftErrorAttr())) { CheckFailed("swifterror argument for call has mismatched parameter" , ArgI, Call); return; } } while (false); | |||
2850 | } | |||
2851 | ||||
2852 | if (Attrs.hasParamAttribute(i, Attribute::ImmArg)) { | |||
2853 | // Don't allow immarg on call sites, unless the underlying declaration | |||
2854 | // also has the matching immarg. | |||
2855 | 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) | |||
2856 | "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) | |||
2857 | 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); | |||
2858 | } | |||
2859 | ||||
2860 | if (Call.paramHasAttr(i, Attribute::ImmArg)) { | |||
2861 | Value *ArgVal = Call.getArgOperand(i); | |||
2862 | 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) | |||
2863 | "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); | |||
2864 | } | |||
2865 | } | |||
2866 | ||||
2867 | if (FTy->isVarArg()) { | |||
2868 | // FIXME? is 'nest' even legal here? | |||
2869 | bool SawNest = false; | |||
2870 | bool SawReturned = false; | |||
2871 | ||||
2872 | for (unsigned Idx = 0; Idx < FTy->getNumParams(); ++Idx) { | |||
2873 | if (Attrs.hasParamAttribute(Idx, Attribute::Nest)) | |||
2874 | SawNest = true; | |||
2875 | if (Attrs.hasParamAttribute(Idx, Attribute::Returned)) | |||
2876 | SawReturned = true; | |||
2877 | } | |||
2878 | ||||
2879 | // Check attributes on the varargs part. | |||
2880 | for (unsigned Idx = FTy->getNumParams(); Idx < Call.arg_size(); ++Idx) { | |||
2881 | Type *Ty = Call.getArgOperand(Idx)->getType(); | |||
2882 | AttributeSet ArgAttrs = Attrs.getParamAttributes(Idx); | |||
2883 | verifyParameterAttrs(ArgAttrs, Ty, &Call); | |||
2884 | ||||
2885 | if (ArgAttrs.hasAttribute(Attribute::Nest)) { | |||
2886 | 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); | |||
2887 | SawNest = true; | |||
2888 | } | |||
2889 | ||||
2890 | if (ArgAttrs.hasAttribute(Attribute::Returned)) { | |||
2891 | Assert(!SawReturned, "More than one parameter has attribute returned!",do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!" , Call); return; } } while (false) | |||
2892 | Call)do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!" , Call); return; } } while (false); | |||
2893 | Assert(Ty->canLosslesslyBitCastTo(FTy->getReturnType()),do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' " "attribute", Call); return; } } while (false) | |||
2894 | "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) | |||
2895 | "attribute",do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' " "attribute", Call); return; } } while (false) | |||
2896 | Call)do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' " "attribute", Call); return; } } while (false); | |||
2897 | SawReturned = true; | |||
2898 | } | |||
2899 | ||||
2900 | // Statepoint intrinsic is vararg but the wrapped function may be not. | |||
2901 | // Allow sret here and check the wrapped function in verifyStatepoint. | |||
2902 | if (!Call.getCalledFunction() || | |||
2903 | Call.getCalledFunction()->getIntrinsicID() != | |||
2904 | Intrinsic::experimental_gc_statepoint) | |||
2905 | 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) | |||
2906 | "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) | |||
2907 | Call)do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed ("Attribute 'sret' cannot be used for vararg call arguments!" , Call); return; } } while (false); | |||
2908 | ||||
2909 | if (ArgAttrs.hasAttribute(Attribute::InAlloca)) | |||
2910 | 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) | |||
2911 | "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); | |||
2912 | } | |||
2913 | } | |||
2914 | ||||
2915 | // Verify that there's no metadata unless it's a direct call to an intrinsic. | |||
2916 | if (!IsIntrinsic) { | |||
2917 | for (Type *ParamTy : FTy->params()) { | |||
2918 | Assert(!ParamTy->isMetadataTy(),do { if (!(!ParamTy->isMetadataTy())) { CheckFailed("Function has metadata parameter but isn't an intrinsic" , Call); return; } } while (false) | |||
2919 | "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); | |||
2920 | Assert(!ParamTy->isTokenTy(),do { if (!(!ParamTy->isTokenTy())) { CheckFailed("Function has token parameter but isn't an intrinsic" , Call); return; } } while (false) | |||
2921 | "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); | |||
2922 | } | |||
2923 | } | |||
2924 | ||||
2925 | // Verify that indirect calls don't return tokens. | |||
2926 | if (!Call.getCalledFunction()) | |||
2927 | Assert(!FTy->getReturnType()->isTokenTy(),do { if (!(!FTy->getReturnType()->isTokenTy())) { CheckFailed ("Return type cannot be token for indirect call!"); return; } } while (false) | |||
2928 | "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); | |||
2929 | ||||
2930 | if (Function *F = Call.getCalledFunction()) | |||
2931 | if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) | |||
2932 | visitIntrinsicCall(ID, Call); | |||
2933 | ||||
2934 | // Verify that a callsite has at most one "deopt", at most one "funclet" and | |||
2935 | // at most one "gc-transition" operand bundle. | |||
2936 | bool FoundDeoptBundle = false, FoundFuncletBundle = false, | |||
2937 | FoundGCTransitionBundle = false; | |||
2938 | for (unsigned i = 0, e = Call.getNumOperandBundles(); i < e; ++i) { | |||
2939 | OperandBundleUse BU = Call.getOperandBundleAt(i); | |||
2940 | uint32_t Tag = BU.getTagID(); | |||
2941 | if (Tag == LLVMContext::OB_deopt) { | |||
2942 | Assert(!FoundDeoptBundle, "Multiple deopt operand bundles", Call)do { if (!(!FoundDeoptBundle)) { CheckFailed("Multiple deopt operand bundles" , Call); return; } } while (false); | |||
2943 | FoundDeoptBundle = true; | |||
2944 | } else if (Tag == LLVMContext::OB_gc_transition) { | |||
2945 | Assert(!FoundGCTransitionBundle, "Multiple gc-transition operand bundles",do { if (!(!FoundGCTransitionBundle)) { CheckFailed("Multiple gc-transition operand bundles" , Call); return; } } while (false) | |||
2946 | Call)do { if (!(!FoundGCTransitionBundle)) { CheckFailed("Multiple gc-transition operand bundles" , Call); return; } } while (false); | |||
2947 | FoundGCTransitionBundle = true; | |||
2948 | } else if (Tag == LLVMContext::OB_funclet) { | |||
2949 | Assert(!FoundFuncletBundle, "Multiple funclet operand bundles", Call)do { if (!(!FoundFuncletBundle)) { CheckFailed("Multiple funclet operand bundles" , Call); return; } } while (false); | |||
2950 | FoundFuncletBundle = true; | |||
2951 | Assert(BU.Inputs.size() == 1,do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one funclet bundle operand" , Call); return; } } while (false) | |||
2952 | "Expected exactly one funclet bundle operand", Call)do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one funclet bundle operand" , Call); return; } } while (false); | |||
2953 | 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) | |||
2954 | "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) | |||
2955 | Call)do { if (!(isa<FuncletPadInst>(BU.Inputs.front()))) { CheckFailed ("Funclet bundle operands should correspond to a FuncletPadInst" , Call); return; } } while (false); | |||
2956 | } | |||
2957 | } | |||
2958 | ||||
2959 | // Verify that each inlinable callsite of a debug-info-bearing function in a | |||
2960 | // debug-info-bearing function has a debug location attached to it. Failure to | |||
2961 | // do so causes assertion failures when the inliner sets up inline scope info. | |||
2962 | if (Call.getFunction()->getSubprogram() && Call.getCalledFunction() && | |||
2963 | Call.getCalledFunction()->getSubprogram()) | |||
2964 | 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) | |||
2965 | "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) | |||
2966 | "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) | |||
2967 | Call)do { if (!(Call.getDebugLoc())) { DebugInfoCheckFailed("inlinable function call in a function with " "debug info must have a !dbg location", Call); return; } } while (false); | |||
2968 | ||||
2969 | visitInstruction(Call); | |||
2970 | } | |||
2971 | ||||
2972 | /// Two types are "congruent" if they are identical, or if they are both pointer | |||
2973 | /// types with different pointee types and the same address space. | |||
2974 | static bool isTypeCongruent(Type *L, Type *R) { | |||
2975 | if (L == R) | |||
2976 | return true; | |||
2977 | PointerType *PL = dyn_cast<PointerType>(L); | |||
2978 | PointerType *PR = dyn_cast<PointerType>(R); | |||
2979 | if (!PL || !PR) | |||
2980 | return false; | |||
2981 | return PL->getAddressSpace() == PR->getAddressSpace(); | |||
2982 | } | |||
2983 | ||||
2984 | static AttrBuilder getParameterABIAttributes(int I, AttributeList Attrs) { | |||
2985 | static const Attribute::AttrKind ABIAttrs[] = { | |||
2986 | Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca, | |||
2987 | Attribute::InReg, Attribute::Returned, Attribute::SwiftSelf, | |||
2988 | Attribute::SwiftError}; | |||
2989 | AttrBuilder Copy; | |||
2990 | for (auto AK : ABIAttrs) { | |||
2991 | if (Attrs.hasParamAttribute(I, AK)) | |||
2992 | Copy.addAttribute(AK); | |||
2993 | } | |||
2994 | if (Attrs.hasParamAttribute(I, Attribute::Alignment)) | |||
2995 | Copy.addAlignmentAttr(Attrs.getParamAlignment(I)); | |||
2996 | return Copy; | |||
2997 | } | |||
2998 | ||||
2999 | void Verifier::verifyMustTailCall(CallInst &CI) { | |||
3000 | 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); | |||
3001 | ||||
3002 | // - The caller and callee prototypes must match. Pointer types of | |||
3003 | // parameters or return types may differ in pointee type, but not | |||
3004 | // address space. | |||
3005 | Function *F = CI.getParent()->getParent(); | |||
3006 | FunctionType *CallerTy = F->getFunctionType(); | |||
3007 | FunctionType *CalleeTy = CI.getFunctionType(); | |||
3008 | if (!CI.getCalledFunction() || !CI.getCalledFunction()->isIntrinsic()) { | |||
3009 | 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) | |||
3010 | "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) | |||
3011 | &CI)do { if (!(CallerTy->getNumParams() == CalleeTy->getNumParams ())) { CheckFailed("cannot guarantee tail call due to mismatched parameter counts" , &CI); return; } } while (false); | |||
3012 | for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) { | |||
3013 | Assert(do { if (!(isTypeCongruent(CallerTy->getParamType(I), CalleeTy ->getParamType(I)))) { CheckFailed("cannot guarantee tail call due to mismatched parameter types" , &CI); return; } } while (false) | |||
3014 | 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) | |||
3015 | "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); | |||
3016 | } | |||
3017 | } | |||
3018 | Assert(CallerTy->isVarArg() == CalleeTy->isVarArg(),do { if (!(CallerTy->isVarArg() == CalleeTy->isVarArg() )) { CheckFailed("cannot guarantee tail call due to mismatched varargs" , &CI); return; } } while (false) | |||
3019 | "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); | |||
3020 | 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) | |||
3021 | "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); | |||
3022 | ||||
3023 | // - The calling conventions of the caller and callee must match. | |||
3024 | 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) | |||
3025 | "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); | |||
3026 | ||||
3027 | // - All ABI-impacting function attributes, such as sret, byval, inreg, | |||
3028 | // returned, and inalloca, must match. | |||
3029 | AttributeList CallerAttrs = F->getAttributes(); | |||
3030 | AttributeList CalleeAttrs = CI.getAttributes(); | |||
3031 | for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) { | |||
3032 | AttrBuilder CallerABIAttrs = getParameterABIAttributes(I, CallerAttrs); | |||
3033 | AttrBuilder CalleeABIAttrs = getParameterABIAttributes(I, CalleeAttrs); | |||
3034 | 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) | |||
3035 | "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) | |||
3036 | "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) | |||
3037 | &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); | |||
3038 | } | |||
3039 | ||||
3040 | // - The call must immediately precede a :ref:`ret <i_ret>` instruction, | |||
3041 | // or a pointer bitcast followed by a ret instruction. | |||
3042 | // - The ret instruction must return the (possibly bitcasted) value | |||
3043 | // produced by the call or void. | |||
3044 | Value *RetVal = &CI; | |||
3045 | Instruction *Next = CI.getNextNode(); | |||
3046 | ||||
3047 | // Handle the optional bitcast. | |||
3048 | if (BitCastInst *BI = dyn_cast_or_null<BitCastInst>(Next)) { | |||
3049 | Assert(BI->getOperand(0) == RetVal,do { if (!(BI->getOperand(0) == RetVal)) { CheckFailed("bitcast following musttail call must use the call" , BI); return; } } while (false) | |||
3050 | "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); | |||
3051 | RetVal = BI; | |||
3052 | Next = BI->getNextNode(); | |||
3053 | } | |||
3054 | ||||
3055 | // Check the return. | |||
3056 | ReturnInst *Ret = dyn_cast_or_null<ReturnInst>(Next); | |||
3057 | 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) | |||
3058 | &CI)do { if (!(Ret)) { CheckFailed("musttail call must precede a ret with an optional bitcast" , &CI); return; } } while (false); | |||
3059 | Assert(!Ret->getReturnValue() || Ret->getReturnValue() == RetVal,do { if (!(!Ret->getReturnValue() || Ret->getReturnValue () == RetVal)) { CheckFailed("musttail call result must be returned" , Ret); return; } } while (false) | |||
3060 | "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); | |||
3061 | } | |||
3062 | ||||
3063 | void Verifier::visitCallInst(CallInst &CI) { | |||
3064 | visitCallBase(CI); | |||
3065 | ||||
3066 | if (CI.isMustTailCall()) | |||
3067 | verifyMustTailCall(CI); | |||
3068 | } | |||
3069 | ||||
3070 | void Verifier::visitInvokeInst(InvokeInst &II) { | |||
3071 | visitCallBase(II); | |||
3072 | ||||
3073 | // Verify that the first non-PHI instruction of the unwind destination is an | |||
3074 | // exception handling instruction. | |||
3075 | Assert(do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!" , &II); return; } } while (false) | |||
3076 | II.getUnwindDest()->isEHPad(),do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!" , &II); return; } } while (false) | |||
3077 | "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) | |||
3078 | &II)do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!" , &II); return; } } while (false); | |||
3079 | ||||
3080 | visitTerminator(II); | |||
3081 | } | |||
3082 | ||||
3083 | /// visitUnaryOperator - Check the argument to the unary operator. | |||
3084 | /// | |||
3085 | void Verifier::visitUnaryOperator(UnaryOperator &U) { | |||
3086 | 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) | |||
3087 | "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) | |||
3088 | "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) | |||
3089 | &U)do { if (!(U.getType() == U.getOperand(0)->getType())) { CheckFailed ("Unary operators must have same type for" "operands and result!" , &U); return; } } while (false); | |||
3090 | ||||
3091 | switch (U.getOpcode()) { | |||
3092 | // Check that floating-point arithmetic operators are only used with | |||
3093 | // floating-point operands. | |||
3094 | case Instruction::FNeg: | |||
3095 | Assert(U.getType()->isFPOrFPVectorTy(),do { if (!(U.getType()->isFPOrFPVectorTy())) { CheckFailed ("FNeg operator only works with float types!", &U); return ; } } while (false) | |||
3096 | "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); | |||
3097 | break; | |||
3098 | default: | |||
3099 | llvm_unreachable("Unknown UnaryOperator opcode!")::llvm::llvm_unreachable_internal("Unknown UnaryOperator opcode!" , "/build/llvm-toolchain-snapshot-9~svn360410/lib/IR/Verifier.cpp" , 3099); | |||
3100 | } | |||
3101 | ||||
3102 | visitInstruction(U); | |||
3103 | } | |||
3104 | ||||
3105 | /// visitBinaryOperator - Check that both arguments to the binary operator are | |||
3106 | /// of the same type! | |||
3107 | /// | |||
3108 | void Verifier::visitBinaryOperator(BinaryOperator &B) { | |||
3109 | 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) | |||
3110 | "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); | |||
3111 | ||||
3112 | switch (B.getOpcode()) { | |||
3113 | // Check that integer arithmetic operators are only used with | |||
3114 | // integral operands. | |||
3115 | case Instruction::Add: | |||
3116 | case Instruction::Sub: | |||
3117 | case Instruction::Mul: | |||
3118 | case Instruction::SDiv: | |||
3119 | case Instruction::UDiv: | |||
3120 | case Instruction::SRem: | |||
3121 | case Instruction::URem: | |||
3122 | Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Integer arithmetic operators only work with integral types!" , &B); return; } } while (false) | |||
3123 | "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); | |||
3124 | 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) | |||
3125 | "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) | |||
3126 | "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) | |||
3127 | &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); | |||
3128 | break; | |||
3129 | // Check that floating-point arithmetic operators are only used with | |||
3130 | // floating-point operands. | |||
3131 | case Instruction::FAdd: | |||
3132 | case Instruction::FSub: | |||
3133 | case Instruction::FMul: | |||
3134 | case Instruction::FDiv: | |||
3135 | case Instruction::FRem: | |||
3136 | Assert(B.getType()->isFPOrFPVectorTy(),do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed ("Floating-point arithmetic operators only work with " "floating-point types!" , &B); return; } } while (false) | |||
3137 | "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) | |||
3138 | "floating-point types!",do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed ("Floating-point arithmetic operators only work with " "floating-point types!" , &B); return; } } while (false) | |||
3139 | &B)do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed ("Floating-point arithmetic operators only work with " "floating-point types!" , &B); return; } } while (false); | |||
3140 | 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) | |||
3141 | "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) | |||
3142 | "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) | |||
3143 | &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); | |||
3144 | break; | |||
3145 | // Check that logical operators are only used with integral operands. | |||
3146 | case Instruction::And: | |||
3147 | case Instruction::Or: | |||
3148 | case Instruction::Xor: | |||
3149 | Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Logical operators only work with integral types!", &B); return; } } while (false) | |||
3150 | "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); | |||
3151 | 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) | |||
3152 | "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) | |||
3153 | &B)do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Logical operators must have same type for operands and result!" , &B); return; } } while (false); | |||
3154 | break; | |||
3155 | case Instruction::Shl: | |||
3156 | case Instruction::LShr: | |||
3157 | case Instruction::AShr: | |||
3158 | Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Shifts only work with integral types!", &B); return; } } while (false) | |||
3159 | "Shifts only work with integral types!", &B)do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Shifts only work with integral types!", &B); return; } } while (false); | |||
3160 | 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) | |||
3161 | "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); | |||
3162 | break; | |||
3163 | default: | |||
3164 | llvm_unreachable("Unknown BinaryOperator opcode!")::llvm::llvm_unreachable_internal("Unknown BinaryOperator opcode!" , "/build/llvm-toolchain-snapshot-9~svn360410/lib/IR/Verifier.cpp" , 3164); | |||
3165 | } | |||
3166 | ||||
3167 | visitInstruction(B); | |||
3168 | } | |||
3169 | ||||
3170 | void Verifier::visitICmpInst(ICmpInst &IC) { | |||
3171 | // Check that the operands are the same type | |||
3172 | Type *Op0Ty = IC.getOperand(0)->getType(); | |||
3173 | Type *Op1Ty = IC.getOperand(1)->getType(); | |||
3174 | Assert(Op0Ty == Op1Ty,do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to ICmp instruction are not of the same type!" , &IC); return; } } while (false) | |||
3175 | "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); | |||
3176 | // Check that the operands are the right type | |||
3177 | Assert(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy(),do { if (!(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy ())) { CheckFailed("Invalid operand types for ICmp instruction" , &IC); return; } } while (false) | |||
3178 | "Invalid operand types for ICmp instruction", &IC)do { if (!(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy ())) { CheckFailed("Invalid operand types for ICmp instruction" , &IC); return; } } while (false); | |||
3179 | // Check that the predicate is valid. | |||
3180 | Assert(IC.isIntPredicate(),do { if (!(IC.isIntPredicate())) { CheckFailed("Invalid predicate in ICmp instruction!" , &IC); return; } } while (false) | |||
3181 | "Invalid predicate in ICmp instruction!", &IC)do { if (!(IC.isIntPredicate())) { CheckFailed("Invalid predicate in ICmp instruction!" , &IC); return; } } while (false); | |||
3182 | ||||
3183 | visitInstruction(IC); | |||
3184 | } | |||
3185 | ||||
3186 | void Verifier::visitFCmpInst(FCmpInst &FC) { | |||
3187 | // Check that the operands are the same type | |||
3188 | Type *Op0Ty = FC.getOperand(0)->getType(); | |||
3189 | Type *Op1Ty = FC.getOperand(1)->getType(); | |||
3190 | Assert(Op0Ty == Op1Ty,do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to FCmp instruction are not of the same type!" , &FC); return; } } while (false) | |||
3191 | "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); | |||
3192 | // Check that the operands are the right type | |||
3193 | Assert(Op0Ty->isFPOrFPVectorTy(),do { if (!(Op0Ty->isFPOrFPVectorTy())) { CheckFailed("Invalid operand types for FCmp instruction" , &FC); return; } } while (false) | |||
3194 | "Invalid operand types for FCmp instruction", &FC)do { if (!(Op0Ty->isFPOrFPVectorTy())) { CheckFailed("Invalid operand types for FCmp instruction" , &FC); return; } } while (false); | |||
3195 | // Check that the predicate is valid. | |||
3196 | Assert(FC.isFPPredicate(),do { if (!(FC.isFPPredicate())) { CheckFailed("Invalid predicate in FCmp instruction!" , &FC); return; } } while (false) | |||
3197 | "Invalid predicate in FCmp instruction!", &FC)do { if (!(FC.isFPPredicate())) { CheckFailed("Invalid predicate in FCmp instruction!" , &FC); return; } } while (false); | |||
3198 | ||||
3199 | visitInstruction(FC); | |||
3200 | } | |||
3201 | ||||
3202 | void Verifier::visitExtractElementInst(ExtractElementInst &EI) { | |||
3203 | Assert(do { if (!(ExtractElementInst::isValidOperands(EI.getOperand( 0), EI.getOperand(1)))) { CheckFailed("Invalid extractelement operands!" , &EI); return; } } while (false) | |||
3204 | 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) | |||
3205 | "Invalid extractelement operands!", &EI)do { if (!(ExtractElementInst::isValidOperands(EI.getOperand( 0), EI.getOperand(1)))) { CheckFailed("Invalid extractelement operands!" , &EI); return; } } while (false); | |||
3206 | visitInstruction(EI); | |||
3207 | } | |||
3208 | ||||
3209 | void Verifier::visitInsertElementInst(InsertElementInst &IE) { | |||
3210 | 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) | |||
3211 | IE.getOperand(2)),do { if (!(InsertElementInst::isValidOperands(IE.getOperand(0 ), IE.getOperand(1), IE.getOperand(2)))) { CheckFailed("Invalid insertelement operands!" , &IE); return; } } while (false) | |||
3212 | "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); | |||
3213 | visitInstruction(IE); | |||
3214 | } | |||
3215 | ||||
3216 | void Verifier::visitShuffleVectorInst(ShuffleVectorInst &SV) { | |||
3217 | 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) | |||
3218 | SV.getOperand(2)),do { if (!(ShuffleVectorInst::isValidOperands(SV.getOperand(0 ), SV.getOperand(1), SV.getOperand(2)))) { CheckFailed("Invalid shufflevector operands!" , &SV); return; } } while (false) | |||
3219 | "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); | |||
3220 | visitInstruction(SV); | |||
3221 | } | |||
3222 | ||||
3223 | void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) { | |||
3224 | Type *TargetTy = GEP.getPointerOperandType()->getScalarType(); | |||
3225 | ||||
3226 | 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) | |||
3227 | "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); | |||
3228 | Assert(GEP.getSourceElementType()->isSized(), "GEP into unsized type!", &GEP)do { if (!(GEP.getSourceElementType()->isSized())) { CheckFailed ("GEP into unsized type!", &GEP); return; } } while (false ); | |||
3229 | ||||
3230 | SmallVector<Value*, 16> Idxs(GEP.idx_begin(), GEP.idx_end()); | |||
3231 | Assert(all_of(do { if (!(all_of( Idxs, [](Value* V) { return V->getType( )->isIntOrIntVectorTy(); }))) { CheckFailed("GEP indexes must be integers" , &GEP); return; } } while (false) | |||
3232 | 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) | |||
3233 | "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); | |||
3234 | Type *ElTy = | |||
3235 | GetElementPtrInst::getIndexedType(GEP.getSourceElementType(), Idxs); | |||
3236 | Assert(ElTy, "Invalid indices for GEP pointer type!", &GEP)do { if (!(ElTy)) { CheckFailed("Invalid indices for GEP pointer type!" , &GEP); return; } } while (false); | |||
3237 | ||||
3238 | 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) | |||
3239 | 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) | |||
3240 | "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); | |||
3241 | ||||
3242 | if (GEP.getType()->isVectorTy()) { | |||
3243 | // Additional checks for vector GEPs. | |||
3244 | unsigned GEPWidth = GEP.getType()->getVectorNumElements(); | |||
3245 | if (GEP.getPointerOperandType()->isVectorTy()) | |||
3246 | 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) | |||
3247 | "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); | |||
3248 | for (Value *Idx : Idxs) { | |||
3249 | Type *IndexTy = Idx->getType(); | |||
3250 | if (IndexTy->isVectorTy()) { | |||
3251 | unsigned IndexWidth = IndexTy->getVectorNumElements(); | |||
3252 | Assert(IndexWidth == GEPWidth, "Invalid GEP index vector width", &GEP)do { if (!(IndexWidth == GEPWidth)) { CheckFailed("Invalid GEP index vector width" , &GEP); return; } } while (false); | |||
3253 | } | |||
3254 | Assert(IndexTy->isIntOrIntVectorTy(),do { if (!(IndexTy->isIntOrIntVectorTy())) { CheckFailed("All GEP indices should be of integer type" ); return; } } while (false) | |||
3255 | "All GEP indices should be of integer type")do { if (!(IndexTy->isIntOrIntVectorTy())) { CheckFailed("All GEP indices should be of integer type" ); return; } } while (false); | |||
3256 | } | |||
3257 | } | |||
3258 | ||||
3259 | if (auto *PTy = dyn_cast<PointerType>(GEP.getType())) { | |||
3260 | Assert(GEP.getAddressSpace() == PTy->getAddressSpace(),do { if (!(GEP.getAddressSpace() == PTy->getAddressSpace() )) { CheckFailed("GEP address space doesn't match type", & GEP); return; } } while (false) | |||
3261 | "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); | |||
3262 | } | |||
3263 | ||||
3264 | visitInstruction(GEP); | |||
3265 | } | |||
3266 | ||||
3267 | static bool isContiguous(const ConstantRange &A, const ConstantRange &B) { | |||
3268 | return A.getUpper() == B.getLower() || A.getLower() == B.getUpper(); | |||
3269 | } | |||
3270 | ||||
3271 | void Verifier::visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty) { | |||
3272 | 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-9~svn360410/lib/IR/Verifier.cpp" , 3273, __PRETTY_FUNCTION__)) | |||
3273 | "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-9~svn360410/lib/IR/Verifier.cpp" , 3273, __PRETTY_FUNCTION__)); | |||
3274 | ||||
3275 | unsigned NumOperands = Range->getNumOperands(); | |||
3276 | Assert(NumOperands % 2 == 0, "Unfinished range!", Range)do { if (!(NumOperands % 2 == 0)) { CheckFailed("Unfinished range!" , Range); return; } } while (false); | |||
3277 | unsigned NumRanges = NumOperands / 2; | |||
3278 | 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); | |||
3279 | ||||
3280 | ConstantRange LastRange(1, true); // Dummy initial value | |||
3281 | for (unsigned i = 0; i < NumRanges; ++i) { | |||
3282 | ConstantInt *Low = | |||
3283 | mdconst::dyn_extract<ConstantInt>(Range->getOperand(2 * i)); | |||
3284 | 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); | |||
3285 | ConstantInt *High = | |||
3286 | mdconst::dyn_extract<ConstantInt>(Range->getOperand(2 * i + 1)); | |||
3287 | 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); | |||
3288 | 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) | |||
3289 | "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); | |||
3290 | ||||
3291 | APInt HighV = High->getValue(); | |||
3292 | APInt LowV = Low->getValue(); | |||
3293 | ConstantRange CurRange(LowV, HighV); | |||
3294 | Assert(!CurRange.isEmptySet() && !CurRange.isFullSet(),do { if (!(!CurRange.isEmptySet() && !CurRange.isFullSet ())) { CheckFailed("Range must not be empty!", Range); return ; } } while (false) | |||
3295 | "Range must not be empty!", Range)do { if (!(!CurRange.isEmptySet() && !CurRange.isFullSet ())) { CheckFailed("Range must not be empty!", Range); return ; } } while (false); | |||
3296 | if (i != 0) { | |||
3297 | Assert(CurRange.intersectWith(LastRange).isEmptySet(),do { if (!(CurRange.intersectWith(LastRange).isEmptySet())) { CheckFailed("Intervals are overlapping", Range); return; } } while (false) | |||
3298 | "Intervals are overlapping", Range)do { if (!(CurRange.intersectWith(LastRange).isEmptySet())) { CheckFailed("Intervals are overlapping", Range); return; } } while (false); | |||
3299 | 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) | |||
3300 | Range)do { if (!(LowV.sgt(LastRange.getLower()))) { CheckFailed("Intervals are not in order" , Range); return; } } while (false); | |||
3301 | Assert(!isContiguous(CurRange, LastRange), "Intervals are contiguous",do { if (!(!isContiguous(CurRange, LastRange))) { CheckFailed ("Intervals are contiguous", Range); return; } } while (false ) | |||
3302 | Range)do { if (!(!isContiguous(CurRange, LastRange))) { CheckFailed ("Intervals are contiguous", Range); return; } } while (false ); | |||
3303 | } | |||
3304 | LastRange = ConstantRange(LowV, HighV); | |||
3305 | } | |||
3306 | if (NumRanges > 2) { | |||
3307 | APInt FirstLow = | |||
3308 | mdconst::dyn_extract<ConstantInt>(Range->getOperand(0))->getValue(); | |||
3309 | APInt FirstHigh = | |||
3310 | mdconst::dyn_extract<ConstantInt>(Range->getOperand(1))->getValue(); | |||
3311 | ConstantRange FirstRange(FirstLow, FirstHigh); | |||
3312 | Assert(FirstRange.intersectWith(LastRange).isEmptySet(),do { if (!(FirstRange.intersectWith(LastRange).isEmptySet())) { CheckFailed("Intervals are overlapping", Range); return; } } while (false) | |||
3313 | "Intervals are overlapping", Range)do { if (!(FirstRange.intersectWith(LastRange).isEmptySet())) { CheckFailed("Intervals are overlapping", Range); return; } } while (false); | |||
3314 | Assert(!isContiguous(FirstRange, LastRange), "Intervals are contiguous",do { if (!(!isContiguous(FirstRange, LastRange))) { CheckFailed ("Intervals are contiguous", Range); return; } } while (false ) | |||
3315 | Range)do { if (!(!isContiguous(FirstRange, LastRange))) { CheckFailed ("Intervals are contiguous", Range); return; } } while (false ); | |||
3316 | } | |||
3317 | } | |||
3318 | ||||
3319 | void Verifier::checkAtomicMemAccessSize(Type *Ty, const Instruction *I) { | |||
3320 | unsigned Size = DL.getTypeSizeInBits(Ty); | |||
3321 | 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); | |||
3322 | 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) | |||
3323 | "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); | |||
3324 | } | |||
3325 | ||||
3326 | void Verifier::visitLoadInst(LoadInst &LI) { | |||
3327 | PointerType *PTy = dyn_cast<PointerType>(LI.getOperand(0)->getType()); | |||
3328 | Assert(PTy, "Load operand must be a pointer.", &LI)do { if (!(PTy)) { CheckFailed("Load operand must be a pointer." , &LI); return; } } while (false); | |||
3329 | Type *ElTy = LI.getType(); | |||
3330 | Assert(LI.getAlignment() <= Value::MaximumAlignment,do { if (!(LI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &LI ); return; } } while (false) | |||
3331 | "huge alignment values are unsupported", &LI)do { if (!(LI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &LI ); return; } } while (false); | |||
3332 | 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); | |||
3333 | if (LI.isAtomic()) { | |||
3334 | 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) | |||
3335 | LI.getOrdering() != AtomicOrdering::AcquireRelease,do { if (!(LI.getOrdering() != AtomicOrdering::Release && LI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed ("Load cannot have Release ordering", &LI); return; } } while (false) | |||
3336 | "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); | |||
3337 | Assert(LI.getAlignment() != 0,do { if (!(LI.getAlignment() != 0)) { CheckFailed("Atomic load must specify explicit alignment" , &LI); return; } } while (false) | |||
3338 | "Atomic load must specify explicit alignment", &LI)do { if (!(LI.getAlignment() != 0)) { CheckFailed("Atomic load must specify explicit alignment" , &LI); return; } } while (false); | |||
3339 | 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) | |||
3340 | "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) | |||
3341 | "type!",do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomic load operand must have integer, pointer, or floating point " "type!", ElTy, &LI); return; } } while (false) | |||
3342 | 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); | |||
3343 | checkAtomicMemAccessSize(ElTy, &LI); | |||
3344 | } else { | |||
3345 | Assert(LI.getSyncScopeID() == SyncScope::System,do { if (!(LI.getSyncScopeID() == SyncScope::System)) { CheckFailed ("Non-atomic load cannot have SynchronizationScope specified" , &LI); return; } } while (false) | |||
3346 | "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); | |||
3347 | } | |||
3348 | ||||
3349 | visitInstruction(LI); | |||
3350 | } | |||
3351 | ||||
3352 | void Verifier::visitStoreInst(StoreInst &SI) { | |||
3353 | PointerType *PTy = dyn_cast<PointerType>(SI.getOperand(1)->getType()); | |||
3354 | Assert(PTy, "Store operand must be a pointer.", &SI)do { if (!(PTy)) { CheckFailed("Store operand must be a pointer." , &SI); return; } } while (false); | |||
3355 | Type *ElTy = PTy->getElementType(); | |||
3356 | 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) | |||
3357 | "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); | |||
3358 | Assert(SI.getAlignment() <= Value::MaximumAlignment,do { if (!(SI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &SI ); return; } } while (false) | |||
3359 | "huge alignment values are unsupported", &SI)do { if (!(SI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &SI ); return; } } while (false); | |||
3360 | 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); | |||
3361 | if (SI.isAtomic()) { | |||
3362 | 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) | |||
3363 | SI.getOrdering() != AtomicOrdering::AcquireRelease,do { if (!(SI.getOrdering() != AtomicOrdering::Acquire && SI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed ("Store cannot have Acquire ordering", &SI); return; } } while (false) | |||
3364 | "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); | |||
3365 | Assert(SI.getAlignment() != 0,do { if (!(SI.getAlignment() != 0)) { CheckFailed("Atomic store must specify explicit alignment" , &SI); return; } } while (false) | |||
3366 | "Atomic store must specify explicit alignment", &SI)do { if (!(SI.getAlignment() != 0)) { CheckFailed("Atomic store must specify explicit alignment" , &SI); return; } } while (false); | |||
3367 | 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) | |||
3368 | "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) | |||
3369 | "type!",do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomic store operand must have integer, pointer, or floating point " "type!", ElTy, &SI); return; } } while (false) | |||
3370 | 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); | |||
3371 | checkAtomicMemAccessSize(ElTy, &SI); | |||
3372 | } else { | |||
3373 | Assert(SI.getSyncScopeID() == SyncScope::System,do { if (!(SI.getSyncScopeID() == SyncScope::System)) { CheckFailed ("Non-atomic store cannot have SynchronizationScope specified" , &SI); return; } } while (false) | |||
3374 | "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); | |||
3375 | } | |||
3376 | visitInstruction(SI); | |||
3377 | } | |||
3378 | ||||
3379 | /// Check that SwiftErrorVal is used as a swifterror argument in CS. | |||
3380 | void Verifier::verifySwiftErrorCall(CallBase &Call, | |||
3381 | const Value *SwiftErrorVal) { | |||
3382 | unsigned Idx = 0; | |||
3383 | for (auto I = Call.arg_begin(), E = Call.arg_end(); I != E; ++I, ++Idx) { | |||
3384 | if (*I == SwiftErrorVal) { | |||
3385 | 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) | |||
3386 | "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) | |||
3387 | "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) | |||
3388 | 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); | |||
3389 | } | |||
3390 | } | |||
3391 | } | |||
3392 | ||||
3393 | void Verifier::verifySwiftErrorValue(const Value *SwiftErrorVal) { | |||
3394 | // Check that swifterror value is only used by loads, stores, or as | |||
3395 | // a swifterror argument. | |||
3396 | for (const User *U : SwiftErrorVal->users()) { | |||
3397 | 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) | |||
3398 | 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) | |||
3399 | "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) | |||
3400 | "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) | |||
3401 | 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); | |||
3402 | // If it is used by a store, check it is the second operand. | |||
3403 | if (auto StoreI = dyn_cast<StoreInst>(U)) | |||
3404 | 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) | |||
3405 | "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) | |||
3406 | "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); | |||
3407 | if (auto *Call = dyn_cast<CallBase>(U)) | |||
3408 | verifySwiftErrorCall(*const_cast<CallBase *>(Call), SwiftErrorVal); | |||
3409 | } | |||
3410 | } | |||
3411 | ||||
3412 | void Verifier::visitAllocaInst(AllocaInst &AI) { | |||
3413 | SmallPtrSet<Type*, 4> Visited; | |||
3414 | PointerType *PTy = AI.getType(); | |||
3415 | // TODO: Relax this restriction? | |||
3416 | 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) | |||
3417 | "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) | |||
3418 | &AI)do { if (!(PTy->getAddressSpace() == DL.getAllocaAddrSpace ())) { CheckFailed("Allocation instruction pointer not in the stack address space!" , &AI); return; } } while (false); | |||
3419 | Assert(AI.getAllocatedType()->isSized(&Visited),do { if (!(AI.getAllocatedType()->isSized(&Visited))) { CheckFailed("Cannot allocate unsized type", &AI); return ; } } while (false) | |||
3420 | "Cannot allocate unsized type", &AI)do { if (!(AI.getAllocatedType()->isSized(&Visited))) { CheckFailed("Cannot allocate unsized type", &AI); return ; } } while (false); | |||
3421 | Assert(AI.getArraySize()->getType()->isIntegerTy(),do { if (!(AI.getArraySize()->getType()->isIntegerTy()) ) { CheckFailed("Alloca array size must have integer type", & AI); return; } } while (false) | |||
3422 | "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); | |||
3423 | Assert(AI.getAlignment() <= Value::MaximumAlignment,do { if (!(AI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &AI ); return; } } while (false) | |||
3424 | "huge alignment values are unsupported", &AI)do { if (!(AI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &AI ); return; } } while (false); | |||
3425 | ||||
3426 | if (AI.isSwiftError()) { | |||
3427 | verifySwiftErrorValue(&AI); | |||
3428 | } | |||
3429 | ||||
3430 | visitInstruction(AI); | |||
3431 | } | |||
3432 | ||||
3433 | void Verifier::visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI) { | |||
3434 | ||||
3435 | // FIXME: more conditions??? | |||
3436 | Assert(CXI.getSuccessOrdering() != AtomicOrdering::NotAtomic,do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::NotAtomic )) { CheckFailed("cmpxchg instructions must be atomic.", & CXI); return; } } while (false) | |||
3437 | "cmpxchg instructions must be atomic.", &CXI)do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::NotAtomic )) { CheckFailed("cmpxchg instructions must be atomic.", & CXI); return; } } while (false); | |||
3438 | Assert(CXI.getFailureOrdering() != AtomicOrdering::NotAtomic,do { if (!(CXI.getFailureOrdering() != AtomicOrdering::NotAtomic )) { CheckFailed("cmpxchg instructions must be atomic.", & CXI); return; } } while (false) | |||
3439 | "cmpxchg instructions must be atomic.", &CXI)do { if (!(CXI.getFailureOrdering() != AtomicOrdering::NotAtomic )) { CheckFailed("cmpxchg instructions must be atomic.", & CXI); return; } } while (false); | |||
3440 | Assert(CXI.getSuccessOrdering() != AtomicOrdering::Unordered,do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::Unordered )) { CheckFailed("cmpxchg instructions cannot be unordered.", &CXI); return; } } while (false) | |||
3441 | "cmpxchg instructions cannot be unordered.", &CXI)do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::Unordered )) { CheckFailed("cmpxchg instructions cannot be unordered.", &CXI); return; } } while (false); | |||
3442 | Assert(CXI.getFailureOrdering() != AtomicOrdering::Unordered,do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Unordered )) { CheckFailed("cmpxchg instructions cannot be unordered.", &CXI); return; } } while (false) | |||
3443 | "cmpxchg instructions cannot be unordered.", &CXI)do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Unordered )) { CheckFailed("cmpxchg instructions cannot be unordered.", &CXI); return; } } while (false); | |||
3444 | 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) | |||
3445 | "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) | |||
3446 | "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) | |||
3447 | &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); | |||
3448 | 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) | |||
3449 | 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) | |||
3450 | "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); | |||
3451 | ||||
3452 | PointerType *PTy = dyn_cast<PointerType>(CXI.getOperand(0)->getType()); | |||
3453 | 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); | |||
3454 | Type *ElTy = PTy->getElementType(); | |||
3455 | Assert(ElTy->isIntOrPtrTy(),do { if (!(ElTy->isIntOrPtrTy())) { CheckFailed("cmpxchg operand must have integer or pointer type" , ElTy, &CXI); return; } } while (false) | |||
3456 | "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); | |||
3457 | checkAtomicMemAccessSize(ElTy, &CXI); | |||
3458 | 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) | |||
3459 | "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) | |||
3460 | ElTy)do { if (!(ElTy == CXI.getOperand(1)->getType())) { CheckFailed ("Expected value type does not match pointer operand type!", & CXI, ElTy); return; } } while (false); | |||
3461 | 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) | |||
3462 | "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); | |||
3463 | visitInstruction(CXI); | |||
3464 | } | |||
3465 | ||||
3466 | void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) { | |||
3467 | Assert(RMWI.getOrdering() != AtomicOrdering::NotAtomic,do { if (!(RMWI.getOrdering() != AtomicOrdering::NotAtomic)) { CheckFailed("atomicrmw instructions must be atomic.", &RMWI ); return; } } while (false) | |||
3468 | "atomicrmw instructions must be atomic.", &RMWI)do { if (!(RMWI.getOrdering() != AtomicOrdering::NotAtomic)) { CheckFailed("atomicrmw instructions must be atomic.", &RMWI ); return; } } while (false); | |||
3469 | Assert(RMWI.getOrdering() != AtomicOrdering::Unordered,do { if (!(RMWI.getOrdering() != AtomicOrdering::Unordered)) { CheckFailed("atomicrmw instructions cannot be unordered.", & RMWI); return; } } while (false) | |||
3470 | "atomicrmw instructions cannot be unordered.", &RMWI)do { if (!(RMWI.getOrdering() != AtomicOrdering::Unordered)) { CheckFailed("atomicrmw instructions cannot be unordered.", & RMWI); return; } } while (false); | |||
3471 | auto Op = RMWI.getOperation(); | |||
3472 | PointerType *PTy = dyn_cast<PointerType>(RMWI.getOperand(0)->getType()); | |||
3473 | 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); | |||
3474 | Type *ElTy = PTy->getElementType(); | |||
3475 | if (Op == AtomicRMWInst::Xchg) { | |||
3476 | 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) | |||
3477 | 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) | |||
3478 | " 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) | |||
3479 | &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); | |||
3480 | } else if (AtomicRMWInst::isFPOperation(Op)) { | |||
3481 | Assert(ElTy->isFloatingPointTy(), "atomicrmw " +do { if (!(ElTy->isFloatingPointTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have floating point type!" , &RMWI, ElTy); return; } } while (false) | |||
3482 | AtomicRMWInst::getOperationName(Op) +do { if (!(ElTy->isFloatingPointTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have floating point type!" , &RMWI, ElTy); return; } } while (false) | |||
3483 | " 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) | |||
3484 | &RMWI, ElTy)do { if (!(ElTy->isFloatingPointTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have floating point type!" , &RMWI, ElTy); return; } } while (false); | |||
3485 | } else { | |||
3486 | Assert(ElTy->isIntegerTy(), "atomicrmw " +do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have integer type!" , &RMWI, ElTy); return; } } while (false) | |||
3487 | AtomicRMWInst::getOperationName(Op) +do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have integer type!" , &RMWI, ElTy); return; } } while (false) | |||
3488 | " operand must have integer type!",do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have integer type!" , &RMWI, ElTy); return; } } while (false) | |||
3489 | &RMWI, ElTy)do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have integer type!" , &RMWI, ElTy); return; } } while (false); | |||
3490 | } | |||
3491 | checkAtomicMemAccessSize(ElTy, &RMWI); | |||
3492 | 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) | |||
3493 | "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) | |||
3494 | ElTy)do { if (!(ElTy == RMWI.getOperand(1)->getType())) { CheckFailed ("Argument value type does not match pointer operand type!", & RMWI, ElTy); return; } } while (false); | |||
3495 | 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) | |||
3496 | "Invalid binary operation!", &RMWI)do { if (!(AtomicRMWInst::FIRST_BINOP <= Op && Op <= AtomicRMWInst::LAST_BINOP)) { CheckFailed("Invalid binary operation!" , &RMWI); return; } } while (false); | |||
3497 | visitInstruction(RMWI); | |||
3498 | } | |||
3499 | ||||
3500 | void Verifier::visitFenceInst(FenceInst &FI) { | |||
3501 | const AtomicOrdering Ordering = FI.getOrdering(); | |||
3502 | 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) | |||
3503 | 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) | |||
3504 | 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) | |||
3505 | 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) | |||
3506 | "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) | |||
3507 | "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) | |||
3508 | &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); | |||
3509 | visitInstruction(FI); | |||
3510 | } | |||
3511 | ||||
3512 | void Verifier::visitExtractValueInst(ExtractValueInst &EVI) { | |||
3513 | 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) | |||
3514 | EVI.getIndices()) == EVI.getType(),do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand ()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed ("Invalid ExtractValueInst operands!", &EVI); return; } } while (false) | |||
3515 | "Invalid ExtractValueInst operands!", &EVI)do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand ()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed ("Invalid ExtractValueInst operands!", &EVI); return; } } while (false); | |||
3516 | ||||
3517 | visitInstruction(EVI); | |||
3518 | } | |||
3519 | ||||
3520 | void Verifier::visitInsertValueInst(InsertValueInst &IVI) { | |||
3521 | 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) | |||
3522 | IVI.getIndices()) ==do { if (!(ExtractValueInst::getIndexedType(IVI.getAggregateOperand ()->getType(), IVI.getIndices()) == IVI.getOperand(1)-> getType())) { CheckFailed("Invalid InsertValueInst operands!" , &IVI); return; } } while (false) | |||
3523 | 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) | |||
3524 | "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); | |||
3525 | ||||
3526 | visitInstruction(IVI); | |||
3527 | } | |||
3528 | ||||
3529 | static Value *getParentPad(Value *EHPad) { | |||
3530 | if (auto *FPI = dyn_cast<FuncletPadInst>(EHPad)) | |||
3531 | return FPI->getParentPad(); | |||
3532 | ||||
3533 | return cast<CatchSwitchInst>(EHPad)->getParentPad(); | |||
3534 | } | |||
3535 | ||||
3536 | void Verifier::visitEHPadPredecessors(Instruction &I) { | |||
3537 | assert(I.isEHPad())((I.isEHPad()) ? static_cast<void> (0) : __assert_fail ( "I.isEHPad()", "/build/llvm-toolchain-snapshot-9~svn360410/lib/IR/Verifier.cpp" , 3537, __PRETTY_FUNCTION__)); | |||
3538 | ||||
3539 | BasicBlock *BB = I.getParent(); | |||
3540 | Function *F = BB->getParent(); | |||
3541 | ||||
3542 | 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); | |||
3543 | ||||
3544 | if (auto *LPI = dyn_cast<LandingPadInst>(&I)) { | |||
3545 | // The landingpad instruction defines its parent as a landing pad block. The | |||
3546 | // landing pad block may be branched to only by the unwind edge of an | |||
3547 | // invoke. | |||
3548 | for (BasicBlock *PredBB : predecessors(BB)) { | |||
3549 | const auto *II = dyn_cast<InvokeInst>(PredBB->getTerminator()); | |||
3550 | 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) | |||
3551 | "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) | |||
3552 | "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) | |||
3553 | 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); | |||
3554 | } | |||
3555 | return; | |||
3556 | } | |||
3557 | if (auto *CPI = dyn_cast<CatchPadInst>(&I)) { | |||
3558 | if (!pred_empty(BB)) | |||
3559 | 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) | |||
3560 | "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) | |||
3561 | "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) | |||
3562 | CPI)do { if (!(BB->getUniquePredecessor() == CPI->getCatchSwitch ()->getParent())) { CheckFailed("Block containg CatchPadInst must be jumped to " "only by its catchswitch.", CPI); return; } } while (false); | |||
3563 | 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) | |||
3564 | "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) | |||
3565 | CPI->getCatchSwitch(), CPI)do { if (!(BB != CPI->getCatchSwitch()->getUnwindDest() )) { CheckFailed("Catchswitch cannot unwind to one of its catchpads" , CPI->getCatchSwitch(), CPI); return; } } while (false); | |||
3566 | return; | |||
3567 | } | |||
3568 | ||||
3569 | // Verify that each pred has a legal terminator with a legal to/from EH | |||
3570 | // pad relationship. | |||
3571 | Instruction *ToPad = &I; | |||
3572 | Value *ToPadParent = getParentPad(ToPad); | |||
3573 | for (BasicBlock *PredBB : predecessors(BB)) { | |||
3574 | Instruction *TI = PredBB->getTerminator(); | |||
3575 | Value *FromPad; | |||
3576 | if (auto *II = dyn_cast<InvokeInst>(TI)) { | |||
3577 | 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) | |||
3578 | "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); | |||
3579 | if (auto Bundle = II->getOperandBundle(LLVMContext::OB_funclet)) | |||
3580 | FromPad = Bundle->Inputs[0]; | |||
3581 | else | |||
3582 | FromPad = ConstantTokenNone::get(II->getContext()); | |||
3583 | } else if (auto *CRI = dyn_cast<CleanupReturnInst>(TI)) { | |||
3584 | FromPad = CRI->getOperand(0); | |||
3585 | 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); | |||
3586 | } else if (auto *CSI = dyn_cast<CatchSwitchInst>(TI)) { | |||
3587 | FromPad = CSI; | |||
3588 | } else { | |||
3589 | 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); | |||
3590 | } | |||
3591 | ||||
3592 | // The edge may exit from zero or more nested pads. | |||
3593 | SmallSet<Value *, 8> Seen; | |||
3594 | for (;; FromPad = getParentPad(FromPad)) { | |||
3595 | Assert(FromPad != ToPad,do { if (!(FromPad != ToPad)) { CheckFailed("EH pad cannot handle exceptions raised within it" , FromPad, TI); return; } } while (false) | |||
3596 | "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); | |||
3597 | if (FromPad == ToPadParent) { | |||
3598 | // This is a legal unwind edge. | |||
3599 | break; | |||
3600 | } | |||
3601 | Assert(!isa<ConstantTokenNone>(FromPad),do { if (!(!isa<ConstantTokenNone>(FromPad))) { CheckFailed ("A single unwind edge may only enter one EH pad", TI); return ; } } while (false) | |||
3602 | "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); | |||
3603 | Assert(Seen.insert(FromPad).second,do { if (!(Seen.insert(FromPad).second)) { CheckFailed("EH pad jumps through a cycle of pads" , FromPad); return; } } while (false) | |||
3604 | "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); | |||
3605 | } | |||
3606 | } | |||
3607 | } | |||
3608 | ||||
3609 | void Verifier::visitLandingPadInst(LandingPadInst &LPI) { | |||
3610 | // The landingpad instruction is ill-formed if it doesn't have any clauses and | |||
3611 | // isn't a cleanup. | |||
3612 | 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) | |||
3613 | "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); | |||
3614 | ||||
3615 | visitEHPadPredecessors(LPI); | |||
3616 | ||||
3617 | if (!LandingPadResultTy) | |||
3618 | LandingPadResultTy = LPI.getType(); | |||
3619 | else | |||
3620 | 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) | |||
3621 | "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) | |||
3622 | "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) | |||
3623 | &LPI)do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed ("The landingpad instruction should have a consistent result type " "inside a function.", &LPI); return; } } while (false); | |||
3624 | ||||
3625 | Function *F = LPI.getParent()->getParent(); | |||
3626 | Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("LandingPadInst needs to be in a function with a personality." , &LPI); return; } } while (false) | |||
3627 | "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); | |||
3628 | ||||
3629 | // The landingpad instruction must be the first non-PHI instruction in the | |||
3630 | // block. | |||
3631 | 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) | |||
3632 | "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) | |||
3633 | &LPI)do { if (!(LPI.getParent()->getLandingPadInst() == &LPI )) { CheckFailed("LandingPadInst not the first non-PHI instruction in the block." , &LPI); return; } } while (false); | |||
3634 | ||||
3635 | for (unsigned i = 0, e = LPI.getNumClauses(); i < e; ++i) { | |||
3636 | Constant *Clause = LPI.getClause(i); | |||
3637 | if (LPI.isCatch(i)) { | |||
3638 | Assert(isa<PointerType>(Clause->getType()),do { if (!(isa<PointerType>(Clause->getType()))) { CheckFailed ("Catch operand does not have pointer type!", &LPI); return ; } } while (false) | |||
3639 | "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); | |||
3640 | } else { | |||
3641 | 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); | |||
3642 | 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) | |||
3643 | "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); | |||
3644 | } | |||
3645 | } | |||
3646 | ||||
3647 | visitInstruction(LPI); | |||
3648 | } | |||
3649 | ||||
3650 | void Verifier::visitResumeInst(ResumeInst &RI) { | |||
3651 | Assert(RI.getFunction()->hasPersonalityFn(),do { if (!(RI.getFunction()->hasPersonalityFn())) { CheckFailed ("ResumeInst needs to be in a function with a personality.", & RI); return; } } while (false) | |||
3652 | "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); | |||
3653 | ||||
3654 | if (!LandingPadResultTy) | |||
3655 | LandingPadResultTy = RI.getValue()->getType(); | |||
3656 | else | |||
3657 | 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) | |||
3658 | "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) | |||
3659 | "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) | |||
3660 | &RI)do { if (!(LandingPadResultTy == RI.getValue()->getType()) ) { CheckFailed("The resume instruction should have a consistent result type " "inside a function.", &RI); return; } } while (false); | |||
3661 | ||||
3662 | visitTerminator(RI); | |||
3663 | } | |||
3664 | ||||
3665 | void Verifier::visitCatchPadInst(CatchPadInst &CPI) { | |||
3666 | BasicBlock *BB = CPI.getParent(); | |||
3667 | ||||
3668 | Function *F = BB->getParent(); | |||
3669 | Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchPadInst needs to be in a function with a personality." , &CPI); return; } } while (false) | |||
3670 | "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); | |||
3671 | ||||
3672 | 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) | |||
3673 | "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) | |||
3674 | CPI.getParentPad())do { if (!(isa<CatchSwitchInst>(CPI.getParentPad()))) { CheckFailed("CatchPadInst needs to be directly nested in a CatchSwitchInst." , CPI.getParentPad()); return; } } while (false); | |||
3675 | ||||
3676 | // The catchpad instruction must be the first non-PHI instruction in the | |||
3677 | // block. | |||
3678 | Assert(BB->getFirstNonPHI() == &CPI,do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CatchPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (false) | |||
3679 | "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); | |||
3680 | ||||
3681 | visitEHPadPredecessors(CPI); | |||
3682 | visitFuncletPadInst(CPI); | |||
3683 | } | |||
3684 | ||||
3685 | void Verifier::visitCatchReturnInst(CatchReturnInst &CatchReturn) { | |||
3686 | 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) | |||
3687 | "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) | |||
3688 | 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); | |||
3689 | ||||
3690 | visitTerminator(CatchReturn); | |||
3691 | } | |||
3692 | ||||
3693 | void Verifier::visitCleanupPadInst(CleanupPadInst &CPI) { | |||
3694 | BasicBlock *BB = CPI.getParent(); | |||
3695 | ||||
3696 | Function *F = BB->getParent(); | |||
3697 | Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CleanupPadInst needs to be in a function with a personality." , &CPI); return; } } while (false) | |||
3698 | "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); | |||
3699 | ||||
3700 | // The cleanuppad instruction must be the first non-PHI instruction in the | |||
3701 | // block. | |||
3702 | Assert(BB->getFirstNonPHI() == &CPI,do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CleanupPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (false) | |||
3703 | "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) | |||
3704 | &CPI)do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CleanupPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (false); | |||
3705 | ||||
3706 | auto *ParentPad = CPI.getParentPad(); | |||
3707 | 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) | |||
3708 | "CleanupPadInst has an invalid parent.", &CPI)do { if (!(isa<ConstantTokenNone>(ParentPad) || isa< FuncletPadInst>(ParentPad))) { CheckFailed("CleanupPadInst has an invalid parent." , &CPI); return; } } while (false); | |||
3709 | ||||
3710 | visitEHPadPredecessors(CPI); | |||
3711 | visitFuncletPadInst(CPI); | |||
3712 | } | |||
3713 | ||||
3714 | void Verifier::visitFuncletPadInst(FuncletPadInst &FPI) { | |||
3715 | User *FirstUser = nullptr; | |||
3716 | Value *FirstUnwindPad = nullptr; | |||
3717 | SmallVector<FuncletPadInst *, 8> Worklist({&FPI}); | |||
3718 | SmallSet<FuncletPadInst *, 8> Seen; | |||
3719 | ||||
3720 | while (!Worklist.empty()) { | |||
3721 | FuncletPadInst *CurrentPad = Worklist.pop_back_val(); | |||
3722 | Assert(Seen.insert(CurrentPad).second,do { if (!(Seen.insert(CurrentPad).second)) { CheckFailed("FuncletPadInst must not be nested within itself" , CurrentPad); return; } } while (false) | |||
3723 | "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); | |||
3724 | Value *UnresolvedAncestorPad = nullptr; | |||
3725 | for (User *U : CurrentPad->users()) { | |||
3726 | BasicBlock *UnwindDest; | |||
3727 | if (auto *CRI = dyn_cast<CleanupReturnInst>(U)) { | |||
3728 | UnwindDest = CRI->getUnwindDest(); | |||
3729 | } else if (auto *CSI = dyn_cast<CatchSwitchInst>(U)) { | |||
3730 | // We allow catchswitch unwind to caller to nest | |||
3731 | // within an outer pad that unwinds somewhere else, | |||
3732 | // because catchswitch doesn't have a nounwind variant. | |||
3733 | // See e.g. SimplifyCFGOpt::SimplifyUnreachable. | |||
3734 | if (CSI->unwindsToCaller()) | |||
3735 | continue; | |||
3736 | UnwindDest = CSI->getUnwindDest(); | |||
3737 | } else if (auto *II = dyn_cast<InvokeInst>(U)) { | |||
3738 | UnwindDest = II->getUnwindDest(); | |||
3739 | } else if (isa<CallInst>(U)) { | |||
3740 | // Calls which don't unwind may be found inside funclet | |||
3741 | // pads that unwind somewhere else. We don't *require* | |||
3742 | // such calls to be annotated nounwind. | |||
3743 | continue; | |||
3744 | } else if (auto *CPI = dyn_cast<CleanupPadInst>(U)) { | |||
3745 | // The unwind dest for a cleanup can only be found by | |||
3746 | // recursive search. Add it to the worklist, and we'll | |||
3747 | // search for its first use that determines where it unwinds. | |||
3748 | Worklist.push_back(CPI); | |||
3749 | continue; | |||
3750 | } else { | |||
3751 | Assert(isa<CatchReturnInst>(U), "Bogus funclet pad use", U)do { if (!(isa<CatchReturnInst>(U))) { CheckFailed("Bogus funclet pad use" , U); return; } } while (false); | |||
3752 | continue; | |||
3753 | } | |||
3754 | ||||
3755 | Value *UnwindPad; | |||
3756 | bool ExitsFPI; | |||
3757 | if (UnwindDest) { | |||
3758 | UnwindPad = UnwindDest->getFirstNonPHI(); | |||
3759 | if (!cast<Instruction>(UnwindPad)->isEHPad()) | |||
3760 | continue; | |||
3761 | Value *UnwindParent = getParentPad(UnwindPad); | |||
3762 | // Ignore unwind edges that don't exit CurrentPad. | |||
3763 | if (UnwindParent == CurrentPad) | |||
3764 | continue; | |||
3765 | // Determine whether the original funclet pad is exited, | |||
3766 | // and if we are scanning nested pads determine how many | |||
3767 | // of them are exited so we can stop searching their | |||
3768 | // children. | |||
3769 | Value *ExitedPad = CurrentPad; | |||
3770 | ExitsFPI = false; | |||
3771 | do { | |||
3772 | if (ExitedPad == &FPI) { | |||
3773 | ExitsFPI = true; | |||
3774 | // Now we can resolve any ancestors of CurrentPad up to | |||
3775 | // FPI, but not including FPI since we need to make sure | |||
3776 | // to check all direct users of FPI for consistency. | |||
3777 | UnresolvedAncestorPad = &FPI; | |||
3778 | break; | |||
3779 | } | |||
3780 | Value *ExitedParent = getParentPad(ExitedPad); | |||
3781 | if (ExitedParent == UnwindParent) { | |||
3782 | // ExitedPad is the ancestor-most pad which this unwind | |||
3783 | // edge exits, so we can resolve up to it, meaning that | |||
3784 | // ExitedParent is the first ancestor still unresolved. | |||
3785 | UnresolvedAncestorPad = ExitedParent; | |||
3786 | break; | |||
3787 | } | |||
3788 | ExitedPad = ExitedParent; | |||
3789 | } while (!isa<ConstantTokenNone>(ExitedPad)); | |||
3790 | } else { | |||
3791 | // Unwinding to caller exits all pads. | |||
3792 | UnwindPad = ConstantTokenNone::get(FPI.getContext()); | |||
3793 | ExitsFPI = true; | |||
3794 | UnresolvedAncestorPad = &FPI; | |||
3795 | } | |||
3796 | ||||
3797 | if (ExitsFPI) { | |||
3798 | // This unwind edge exits FPI. Make sure it agrees with other | |||
3799 | // such edges. | |||
3800 | if (FirstUser) { | |||
3801 | 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) | |||
3802 | "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) | |||
3803 | "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) | |||
3804 | &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); | |||
3805 | } else { | |||
3806 | FirstUser = U; | |||
3807 | FirstUnwindPad = UnwindPad; | |||
3808 | // Record cleanup sibling unwinds for verifySiblingFuncletUnwinds | |||
3809 | if (isa<CleanupPadInst>(&FPI) && !isa<ConstantTokenNone>(UnwindPad) && | |||
3810 | getParentPad(UnwindPad) == getParentPad(&FPI)) | |||
3811 | SiblingFuncletInfo[&FPI] = cast<Instruction>(U); | |||
3812 | } | |||
3813 | } | |||
3814 | // Make sure we visit all uses of FPI, but for nested pads stop as | |||
3815 | // soon as we know where they unwind to. | |||
3816 | if (CurrentPad != &FPI) | |||
3817 | break; | |||
3818 | } | |||
3819 | if (UnresolvedAncestorPad) { | |||
3820 | if (CurrentPad == UnresolvedAncestorPad) { | |||
3821 | // When CurrentPad is FPI itself, we don't mark it as resolved even if | |||
3822 | // we've found an unwind edge that exits it, because we need to verify | |||
3823 | // all direct uses of FPI. | |||
3824 | assert(CurrentPad == &FPI)((CurrentPad == &FPI) ? static_cast<void> (0) : __assert_fail ("CurrentPad == &FPI", "/build/llvm-toolchain-snapshot-9~svn360410/lib/IR/Verifier.cpp" , 3824, __PRETTY_FUNCTION__)); | |||
3825 | continue; | |||
3826 | } | |||
3827 | // Pop off the worklist any nested pads that we've found an unwind | |||
3828 | // destination for. The pads on the worklist are the uncles, | |||
3829 | // great-uncles, etc. of CurrentPad. We've found an unwind destination | |||
3830 | // for all ancestors of CurrentPad up to but not including | |||
3831 | // UnresolvedAncestorPad. | |||
3832 | Value *ResolvedPad = CurrentPad; | |||
3833 | while (!Worklist.empty()) { | |||
3834 | Value *UnclePad = Worklist.back(); | |||
3835 | Value *AncestorPad = getParentPad(UnclePad); | |||
3836 | // Walk ResolvedPad up the ancestor list until we either find the | |||
3837 | // uncle's parent or the last resolved ancestor. | |||
3838 | while (ResolvedPad != AncestorPad) { | |||
3839 | Value *ResolvedParent = getParentPad(ResolvedPad); | |||
3840 | if (ResolvedParent == UnresolvedAncestorPad) { | |||
3841 | break; | |||
3842 | } | |||
3843 | ResolvedPad = ResolvedParent; | |||
3844 | } | |||
3845 | // If the resolved ancestor search didn't find the uncle's parent, | |||
3846 | // then the uncle is not yet resolved. | |||
3847 | if (ResolvedPad != AncestorPad) | |||
3848 | break; | |||
3849 | // This uncle is resolved, so pop it from the worklist. | |||
3850 | Worklist.pop_back(); | |||
3851 | } | |||
3852 | } | |||
3853 | } | |||
3854 | ||||
3855 | if (FirstUnwindPad) { | |||
3856 | if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(FPI.getParentPad())) { | |||
3857 | BasicBlock *SwitchUnwindDest = CatchSwitch->getUnwindDest(); | |||
3858 | Value *SwitchUnwindPad; | |||
3859 | if (SwitchUnwindDest) | |||
3860 | SwitchUnwindPad = SwitchUnwindDest->getFirstNonPHI(); | |||
3861 | else | |||
3862 | SwitchUnwindPad = ConstantTokenNone::get(FPI.getContext()); | |||
3863 | 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) | |||
3864 | "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) | |||
3865 | "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) | |||
3866 | &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); | |||
3867 | } | |||
3868 | } | |||
3869 | ||||
3870 | visitInstruction(FPI); | |||
3871 | } | |||
3872 | ||||
3873 | void Verifier::visitCatchSwitchInst(CatchSwitchInst &CatchSwitch) { | |||
3874 | BasicBlock *BB = CatchSwitch.getParent(); | |||
3875 | ||||
3876 | Function *F = BB->getParent(); | |||
3877 | Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchSwitchInst needs to be in a function with a personality." , &CatchSwitch); return; } } while (false) | |||
3878 | "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) | |||
3879 | &CatchSwitch)do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchSwitchInst needs to be in a function with a personality." , &CatchSwitch); return; } } while (false); | |||
3880 | ||||
3881 | // The catchswitch instruction must be the first non-PHI instruction in the | |||
3882 | // block. | |||
3883 | Assert(BB->getFirstNonPHI() == &CatchSwitch,do { if (!(BB->getFirstNonPHI() == &CatchSwitch)) { CheckFailed ("CatchSwitchInst not the first non-PHI instruction in the block." , &CatchSwitch); return; } } while (false) | |||
3884 | "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) | |||
3885 | &CatchSwitch)do { if (!(BB->getFirstNonPHI() == &CatchSwitch)) { CheckFailed ("CatchSwitchInst not the first non-PHI instruction in the block." , &CatchSwitch); return; } } while (false); | |||
3886 | ||||
3887 | auto *ParentPad = CatchSwitch.getParentPad(); | |||
3888 | 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) | |||
3889 | "CatchSwitchInst has an invalid parent.", ParentPad)do { if (!(isa<ConstantTokenNone>(ParentPad) || isa< FuncletPadInst>(ParentPad))) { CheckFailed("CatchSwitchInst has an invalid parent." , ParentPad); return; } } while (false); | |||
3890 | ||||
3891 | if (BasicBlock *UnwindDest = CatchSwitch.getUnwindDest()) { | |||
3892 | Instruction *I = UnwindDest->getFirstNonPHI(); | |||
3893 | 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) | |||
3894 | "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) | |||
3895 | "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) | |||
3896 | &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); | |||
3897 | ||||
3898 | // Record catchswitch sibling unwinds for verifySiblingFuncletUnwinds | |||
3899 | if (getParentPad(I) == ParentPad) | |||
3900 | SiblingFuncletInfo[&CatchSwitch] = &CatchSwitch; | |||
3901 | } | |||
3902 | ||||
3903 | Assert(CatchSwitch.getNumHandlers() != 0,do { if (!(CatchSwitch.getNumHandlers() != 0)) { CheckFailed( "CatchSwitchInst cannot have empty handler list", &CatchSwitch ); return; } } while (false) | |||
3904 | "CatchSwitchInst cannot have empty handler list", &CatchSwitch)do { if (!(CatchSwitch.getNumHandlers() != 0)) { CheckFailed( "CatchSwitchInst cannot have empty handler list", &CatchSwitch ); return; } } while (false); | |||
3905 | ||||
3906 | for (BasicBlock *Handler : CatchSwitch.handlers()) { | |||
3907 | Assert(isa<CatchPadInst>(Handler->getFirstNonPHI()),do { if (!(isa<CatchPadInst>(Handler->getFirstNonPHI ()))) { CheckFailed("CatchSwitchInst handlers must be catchpads" , &CatchSwitch, Handler); return; } } while (false) | |||
3908 | "CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler)do { if (!(isa<CatchPadInst>(Handler->getFirstNonPHI ()))) { CheckFailed("CatchSwitchInst handlers must be catchpads" , &CatchSwitch, Handler); return; } } while (false); | |||
3909 | } | |||
3910 | ||||
3911 | visitEHPadPredecessors(CatchSwitch); | |||
3912 | visitTerminator(CatchSwitch); | |||
3913 | } | |||
3914 | ||||
3915 | void Verifier::visitCleanupReturnInst(CleanupReturnInst &CRI) { | |||
3916 | 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) | |||
3917 | "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) | |||
3918 | 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); | |||
3919 | ||||
3920 | if (BasicBlock *UnwindDest = CRI.getUnwindDest()) { | |||
3921 | Instruction *I = UnwindDest->getFirstNonPHI(); | |||
3922 | 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) | |||
3923 | "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) | |||
3924 | "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) | |||
3925 | &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); | |||
3926 | } | |||
3927 | ||||
3928 | visitTerminator(CRI); | |||
3929 | } | |||
3930 | ||||
3931 | void Verifier::verifyDominatesUse(Instruction &I, unsigned i) { | |||
3932 | Instruction *Op = cast<Instruction>(I.getOperand(i)); | |||
3933 | // If the we have an invalid invoke, don't try to compute the dominance. | |||
3934 | // We already reject it in the invoke specific checks and the dominance | |||
3935 | // computation doesn't handle multiple edges. | |||
3936 | if (InvokeInst *II = dyn_cast<InvokeInst>(Op)) { | |||
3937 | if (II->getNormalDest() == II->getUnwindDest()) | |||
3938 | return; | |||
3939 | } | |||
3940 | ||||
3941 | // Quick check whether the def has already been encountered in the same block. | |||
3942 | // PHI nodes are not checked to prevent accepting preceding PHIs, because PHI | |||
3943 | // uses are defined to happen on the incoming edge, not at the instruction. | |||
3944 | // | |||
3945 | // FIXME: If this operand is a MetadataAsValue (wrapping a LocalAsMetadata) | |||
3946 | // wrapping an SSA value, assert that we've already encountered it. See | |||
3947 | // related FIXME in Mapper::mapLocalAsMetadata in ValueMapper.cpp. | |||
3948 | if (!isa<PHINode>(I) && InstsInThisBlock.count(Op)) | |||
3949 | return; | |||
3950 | ||||
3951 | const Use &U = I.getOperandUse(i); | |||
3952 | Assert(DT.dominates(Op, U),do { if (!(DT.dominates(Op, U))) { CheckFailed("Instruction does not dominate all uses!" , Op, &I); return; } } while (false) | |||
3953 | "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); | |||
3954 | } | |||
3955 | ||||
3956 | void Verifier::visitDereferenceableMetadata(Instruction& I, MDNode* MD) { | |||
3957 | 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 ) | |||
3958 | "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 ); | |||
3959 | Assert(isa<LoadInst>(I),do { if (!(isa<LoadInst>(I))) { CheckFailed("dereferenceable, dereferenceable_or_null apply only to load" " instructions, use attributes for calls or invokes", &I ); return; } } while (false) | |||
3960 | "dereferenceable, dereferenceable_or_null apply only to load"do { if (!(isa<LoadInst>(I))) { CheckFailed("dereferenceable, dereferenceable_or_null apply only to load" " instructions, use attributes for calls or invokes", &I ); return; } } while (false) | |||
3961 | " instructions, use attributes for calls or invokes", &I)do { if (!(isa<LoadInst>(I))) { CheckFailed("dereferenceable, dereferenceable_or_null apply only to load" " instructions, use attributes for calls or invokes", &I ); return; } } while (false); | |||
3962 | 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) | |||
3963 | "take one operand!", &I)do { if (!(MD->getNumOperands() == 1)) { CheckFailed("dereferenceable, dereferenceable_or_null " "take one operand!", &I); return; } } while (false); | |||
3964 | ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(MD->getOperand(0)); | |||
3965 | 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) | |||
3966 | "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); | |||
3967 | } | |||
3968 | ||||
3969 | /// verifyInstruction - Verify that an instruction is well formed. | |||
3970 | /// | |||
3971 | void Verifier::visitInstruction(Instruction &I) { | |||
3972 | BasicBlock *BB = I.getParent(); | |||
3973 | Assert(BB, "Instruction not embedded in basic block!", &I)do { if (!(BB)) { CheckFailed("Instruction not embedded in basic block!" , &I); return; } } while (false); | |||
3974 | ||||
3975 | if (!isa<PHINode>(I)) { // Check that non-phi nodes are not self referential | |||
3976 | for (User *U : I.users()) { | |||
3977 | 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) | |||
3978 | "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); | |||
3979 | } | |||
3980 | } | |||
3981 | ||||
3982 | // Check that void typed values don't have names | |||
3983 | 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) | |||
3984 | "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); | |||
3985 | ||||
3986 | // Check that the return value of the instruction is either void or a legal | |||
3987 | // value type. | |||
3988 | 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) | |||
3989 | "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); | |||
3990 | ||||
3991 | // Check that the instruction doesn't produce metadata. Calls are already | |||
3992 | // checked against the callee type. | |||
3993 | 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) | |||
3994 | "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); | |||
3995 | ||||
3996 | // Check that all uses of the instruction, if they are instructions | |||
3997 | // themselves, actually have parent basic blocks. If the use is not an | |||
3998 | // instruction, it is an error! | |||
3999 | for (Use &U : I.uses()) { | |||
4000 | if (Instruction *Used = dyn_cast<Instruction>(U.getUser())) | |||
4001 | Assert(Used->getParent() != nullptr,do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing" " instruction not embedded in a basic block!", &I, Used) ; return; } } while (false) | |||
4002 | "Instruction referencing"do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing" " instruction not embedded in a basic block!", &I, Used) ; return; } } while (false) | |||
4003 | " 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) | |||
4004 | &I, Used)do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing" " instruction not embedded in a basic block!", &I, Used) ; return; } } while (false); | |||
4005 | else { | |||
4006 | CheckFailed("Use of instruction is not an instruction!", U); | |||
4007 | return; | |||
4008 | } | |||
4009 | } | |||
4010 | ||||
4011 | // Get a pointer to the call base of the instruction if it is some form of | |||
4012 | // call. | |||
4013 | const CallBase *CBI = dyn_cast<CallBase>(&I); | |||
4014 | ||||
4015 | for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) { | |||
4016 | 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); | |||
4017 | ||||
4018 | // Check to make sure that only first-class-values are operands to | |||
4019 | // instructions. | |||
4020 | if (!I.getOperand(i)->getType()->isFirstClassType()) { | |||
4021 | 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); | |||
4022 | } | |||
4023 | ||||
4024 | if (Function *F = dyn_cast<Function>(I.getOperand(i))) { | |||
4025 | // Check to make sure that the "address of" an intrinsic function is never | |||
4026 | // taken. | |||
4027 | 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) | |||
4028 | (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) | |||
4029 | "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); | |||
4030 | 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) | |||
4031 | !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) | |||
4032 | 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) | |||
4033 | 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) | |||
4034 | 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) | |||
4035 | 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) | |||
4036 | 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) | |||
4037 | 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) | |||
4038 | 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) | |||
4039 | "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) | |||
4040 | "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) | |||
4041 | &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); | |||
4042 | 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 ) | |||
4043 | &I, &M, F, F->getParent())do { if (!(F->getParent() == &M)) { CheckFailed("Referencing function in another module!" , &I, &M, F, F->getParent()); return; } } while (false ); | |||
4044 | } else if (BasicBlock *OpBB = dyn_cast<BasicBlock>(I.getOperand(i))) { | |||
4045 | Assert(OpBB->getParent() == BB->getParent(),do { if (!(OpBB->getParent() == BB->getParent())) { CheckFailed ("Referring to a basic block in another function!", &I); return ; } } while (false) | |||
4046 | "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); | |||
4047 | } else if (Argument *OpArg = dyn_cast<Argument>(I.getOperand(i))) { | |||
4048 | Assert(OpArg->getParent() == BB->getParent(),do { if (!(OpArg->getParent() == BB->getParent())) { CheckFailed ("Referring to an argument in another function!", &I); return ; } } while (false) | |||
4049 | "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); | |||
4050 | } else if (GlobalValue *GV = dyn_cast<GlobalValue>(I.getOperand(i))) { | |||
4051 | 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) | |||
4052 | &M, GV, GV->getParent())do { if (!(GV->getParent() == &M)) { CheckFailed("Referencing global in another module!" , &I, &M, GV, GV->getParent()); return; } } while ( false); | |||
4053 | } else if (isa<Instruction>(I.getOperand(i))) { | |||
4054 | verifyDominatesUse(I, i); | |||
4055 | } else if (isa<InlineAsm>(I.getOperand(i))) { | |||
4056 | 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) | |||
4057 | "Cannot take the address of an inline asm!", &I)do { if (!(CBI && &CBI->getCalledOperandUse() == &I.getOperandUse(i))) { CheckFailed("Cannot take the address of an inline asm!" , &I); return; } } while (false); | |||
4058 | } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(I.getOperand(i))) { | |||
4059 | if (CE->getType()->isPtrOrPtrVectorTy() || | |||
4060 | !DL.getNonIntegralAddressSpaces().empty()) { | |||
4061 | // If we have a ConstantExpr pointer, we need to see if it came from an | |||
4062 | // illegal bitcast. If the datalayout string specifies non-integral | |||
4063 | // address spaces then we also need to check for illegal ptrtoint and | |||
4064 | // inttoptr expressions. | |||
4065 | visitConstantExprsRecursively(CE); | |||
4066 | } | |||
4067 | } | |||
4068 | } | |||
4069 | ||||
4070 | if (MDNode *MD = I.getMetadata(LLVMContext::MD_fpmath)) { | |||
4071 | Assert(I.getType()->isFPOrFPVectorTy(),do { if (!(I.getType()->isFPOrFPVectorTy())) { CheckFailed ("fpmath requires a floating point result!", &I); return; } } while (false) | |||
4072 | "fpmath requires a floating point result!", &I)do { if (!(I.getType()->isFPOrFPVectorTy())) { CheckFailed ("fpmath requires a floating point result!", &I); return; } } while (false); | |||
4073 | Assert(MD->getNumOperands() == 1, "fpmath takes one operand!", &I)do { if (!(MD->getNumOperands() == 1)) { CheckFailed("fpmath takes one operand!" , &I); return; } } while (false); | |||
4074 | if (ConstantFP *CFP0 = | |||
4075 | mdconst::dyn_extract_or_null<ConstantFP>(MD->getOperand(0))) { | |||
4076 | const APFloat &Accuracy = CFP0->getValueAPF(); | |||
4077 | Assert(&Accuracy.getSemantics() == &APFloat::IEEEsingle(),do { if (!(&Accuracy.getSemantics() == &APFloat::IEEEsingle ())) { CheckFailed("fpmath accuracy must have float type", & I); return; } } while (false) | |||
4078 | "fpmath accuracy must have float type", &I)do { if (!(&Accuracy.getSemantics() == &APFloat::IEEEsingle ())) { CheckFailed("fpmath accuracy must have float type", & I); return; } } while (false); | |||
4079 | Assert(Accuracy.isFiniteNonZero() && !Accuracy.isNegative(),do { if (!(Accuracy.isFiniteNonZero() && !Accuracy.isNegative ())) { CheckFailed("fpmath accuracy not a positive number!", & I); return; } } while (false) | |||
4080 | "fpmath accuracy not a positive number!", &I)do { if (!(Accuracy.isFiniteNonZero() && !Accuracy.isNegative ())) { CheckFailed("fpmath accuracy not a positive number!", & I); return; } } while (false); | |||
4081 | } else { | |||
4082 | Assert(false, "invalid fpmath accuracy!", &I)do { if (!(false)) { CheckFailed("invalid fpmath accuracy!", & I); return; } } while (false); | |||
4083 | } | |||
4084 | } | |||
4085 | ||||
4086 | if (MDNode *Range = I.getMetadata(LLVMContext::MD_range)) { | |||
4087 | Assert(isa<LoadInst>(I) || isa<CallInst>(I) || isa<InvokeInst>(I),do { if (!(isa<LoadInst>(I) || isa<CallInst>(I) || isa<InvokeInst>(I))) { CheckFailed("Ranges are only for loads, calls and invokes!" , &I); return; } } while (false) | |||
4088 | "Ranges are only for loads, calls and invokes!", &I)do { if (!(isa<LoadInst>(I) || isa<CallInst>(I) || isa<InvokeInst>(I))) { CheckFailed("Ranges are only for loads, calls and invokes!" , &I); return; } } while (false); | |||
4089 | visitRangeMetadata(I, Range, I.getType()); | |||
4090 | } | |||
4091 | ||||
4092 | if (I.getMetadata(LLVMContext::MD_nonnull)) { | |||
4093 | Assert(I.getType()->isPointerTy(), "nonnull applies only to pointer types",do { if (!(I.getType()->isPointerTy())) { CheckFailed("nonnull applies only to pointer types" , &I); return; } } while (false) | |||
4094 | &I)do { if (!(I.getType()->isPointerTy())) { CheckFailed("nonnull applies only to pointer types" , &I); return; } } while (false); | |||
4095 | Assert(isa<LoadInst>(I),do { if (!(isa<LoadInst>(I))) { CheckFailed("nonnull applies only to load instructions, use attributes" " for calls or invokes", &I); return; } } while (false) | |||
4096 | "nonnull applies only to load instructions, use attributes"do { if (!(isa<LoadInst>(I))) { CheckFailed("nonnull applies only to load instructions, use attributes" " for calls or invokes", &I); return; } } while (false) | |||
4097 | " for calls or invokes",do { if (!(isa<LoadInst>(I))) { CheckFailed("nonnull applies only to load instructions, use attributes" " for calls or invokes", &I); return; } } while (false) | |||
4098 | &I)do { if (!(isa<LoadInst>(I))) { CheckFailed("nonnull applies only to load instructions, use attributes" " for calls or invokes", &I); return; } } while (false); | |||
4099 | } | |||
4100 | ||||
4101 | if (MDNode *MD = I.getMetadata(LLVMContext::MD_dereferenceable)) | |||
4102 | visitDereferenceableMetadata(I, MD); | |||
4103 | ||||
4104 | if (MDNode *MD = I.getMetadata(LLVMContext::MD_dereferenceable_or_null)) | |||
4105 | visitDereferenceableMetadata(I, MD); | |||
4106 | ||||
4107 | if (MDNode *TBAA = I.getMetadata(LLVMContext::MD_tbaa)) | |||
4108 | TBAAVerifyHelper.visitTBAAMetadata(I, TBAA); | |||
4109 | ||||
4110 | if (MDNode *AlignMD = I.getMetadata(LLVMContext::MD_align)) { | |||
4111 | Assert(I.getType()->isPointerTy(), "align applies only to pointer types",do { if (!(I.getType()->isPointerTy())) { CheckFailed("align applies only to pointer types" , &I); return; } } while (false) | |||
4112 | &I)do { if (!(I.getType()->isPointerTy())) { CheckFailed("align applies only to pointer types" , &I); return; } } while (false); | |||
4113 | Assert(isa<LoadInst>(I), "align applies only to load instructions, "do { if (!(isa<LoadInst>(I))) { CheckFailed("align applies only to load instructions, " "use attributes for calls or invokes", &I); return; } } while (false) | |||
4114 | "use attributes for calls or invokes", &I)do { if (!(isa<LoadInst>(I))) { CheckFailed("align applies only to load instructions, " "use attributes for calls or invokes", &I); return; } } while (false); | |||
4115 | Assert(AlignMD->getNumOperands() == 1, "align takes one operand!", &I)do { if (!(AlignMD->getNumOperands() == 1)) { CheckFailed( "align takes one operand!", &I); return; } } while (false ); | |||
4116 | ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(AlignMD->getOperand(0)); | |||
4117 | Assert(CI && CI->getType()->isIntegerTy(64),do { if (!(CI && CI->getType()->isIntegerTy(64) )) { CheckFailed("align metadata value must be an i64!", & I); return; } } while (false) | |||
4118 | "align metadata value must be an i64!", &I)do { if (!(CI && CI->getType()->isIntegerTy(64) )) { CheckFailed("align metadata value must be an i64!", & I); return; } } while (false); | |||
4119 | uint64_t Align = CI->getZExtValue(); | |||
4120 | Assert(isPowerOf2_64(Align),do { if (!(isPowerOf2_64(Align))) { CheckFailed("align metadata value must be a power of 2!" , &I); return; } } while (false) | |||
4121 | "align metadata value must be a power of 2!", &I)do { if (!(isPowerOf2_64(Align))) { CheckFailed("align metadata value must be a power of 2!" , &I); return; } } while (false); | |||
4122 | Assert(Align <= Value::MaximumAlignment,do { if (!(Align <= Value::MaximumAlignment)) { CheckFailed ("alignment is larger that implementation defined limit", & I); return; } } while (false) | |||
4123 | "alignment is larger that implementation defined limit", &I)do { if (!(Align <= Value::MaximumAlignment)) { CheckFailed ("alignment is larger that implementation defined limit", & I); return; } } while (false); | |||
4124 | } | |||
4125 | ||||
4126 | if (MDNode *N = I.getDebugLoc().getAsMDNode()) { | |||
4127 | AssertDI(isa<DILocation>(N), "invalid !dbg metadata attachment", &I, N)do { if (!(isa<DILocation>(N))) { DebugInfoCheckFailed( "invalid !dbg metadata attachment", &I, N); return; } } while (false); | |||
4128 | visitMDNode(*N); | |||
4129 | } | |||
4130 | ||||
4131 | if (auto *DII = dyn_cast<DbgVariableIntrinsic>(&I)) | |||
4132 | verifyFragmentExpression(*DII); | |||
4133 | ||||
4134 | InstsInThisBlock.insert(&I); | |||
4135 | } | |||
4136 | ||||
4137 | /// Allow intrinsics to be verified in different ways. | |||
4138 | void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) { | |||
4139 | Function *IF = Call.getCalledFunction(); | |||
4140 | Assert(IF->isDeclaration(), "Intrinsic functions should never be defined!",do { if (!(IF->isDeclaration())) { CheckFailed("Intrinsic functions should never be defined!" , IF); return; } } while (false) | |||
4141 | IF)do { if (!(IF->isDeclaration())) { CheckFailed("Intrinsic functions should never be defined!" , IF); return; } } while (false); | |||
4142 | ||||
4143 | // Verify that the intrinsic prototype lines up with what the .td files | |||
4144 | // describe. | |||
4145 | FunctionType *IFTy = IF->getFunctionType(); | |||
4146 | bool IsVarArg = IFTy->isVarArg(); | |||
4147 | ||||
4148 | SmallVector<Intrinsic::IITDescriptor, 8> Table; | |||
4149 | getIntrinsicInfoTableEntries(ID, Table); | |||
4150 | ArrayRef<Intrinsic::IITDescriptor> TableRef = Table; | |||
4151 | ||||
4152 | SmallVector<Type *, 4> ArgTys; | |||
4153 | Assert(!Intrinsic::matchIntrinsicType(IFTy->getReturnType(),do { if (!(!Intrinsic::matchIntrinsicType(IFTy->getReturnType (), TableRef, ArgTys))) { CheckFailed("Intrinsic has incorrect return type!" , IF); return; } } while (false) | |||
4154 | TableRef, ArgTys),do { if (!(!Intrinsic::matchIntrinsicType(IFTy->getReturnType (), TableRef, ArgTys))) { CheckFailed("Intrinsic has incorrect return type!" , IF); return; } } while (false) | |||
4155 | "Intrinsic has incorrect return type!", IF)do { if (!(!Intrinsic::matchIntrinsicType(IFTy->getReturnType (), TableRef, ArgTys))) { CheckFailed("Intrinsic has incorrect return type!" , IF); return; } } while (false); | |||
4156 | for (unsigned i = 0, e = IFTy->getNumParams(); i != e; ++i) | |||
4157 | Assert(!Intrinsic::matchIntrinsicType(IFTy->getParamType(i),do { if (!(!Intrinsic::matchIntrinsicType(IFTy->getParamType (i), TableRef, ArgTys))) { CheckFailed("Intrinsic has incorrect argument type!" , IF); return; } } while (false) | |||
4158 | TableRef, ArgTys),do { if (!(!Intrinsic::matchIntrinsicType(IFTy->getParamType (i), TableRef, ArgTys))) { CheckFailed("Intrinsic has incorrect argument type!" , IF); return; } } while (false) | |||
4159 | "Intrinsic has incorrect argument type!", IF)do { if (!(!Intrinsic::matchIntrinsicType(IFTy->getParamType (i), TableRef, ArgTys))) { CheckFailed("Intrinsic has incorrect argument type!" , IF); return; } } while (false); | |||
4160 | ||||
4161 | // Verify if the intrinsic call matches the vararg property. | |||
4162 | if (IsVarArg) | |||
4163 | Assert(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef),do { if (!(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef ))) { CheckFailed("Intrinsic was not defined with variable arguments!" , IF); return; } } while (false) | |||
4164 | "Intrinsic was not defined with variable arguments!", IF)do { if (!(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef ))) { CheckFailed("Intrinsic was not defined with variable arguments!" , IF); return; } } while (false); | |||
4165 | else | |||
4166 | Assert(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef),do { if (!(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef ))) { CheckFailed("Callsite was not defined with variable arguments!" , IF); return; } } while (false) | |||
4167 | "Callsite was not defined with variable arguments!", IF)do { if (!(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef ))) { CheckFailed("Callsite was not defined with variable arguments!" , IF); return; } } while (false); | |||
4168 | ||||
4169 | // All descriptors should be absorbed by now. | |||
4170 | Assert(TableRef.empty(), "Intrinsic has too few arguments!", IF)do { if (!(TableRef.empty())) { CheckFailed("Intrinsic has too few arguments!" , IF); return; } } while (false); | |||
4171 | ||||
4172 | // Now that we have the intrinsic ID and the actual argument types (and we | |||
4173 | // know they are legal for the intrinsic!) get the intrinsic name through the | |||
4174 | // usual means. This allows us to verify the mangling of argument types into | |||
4175 | // the name. | |||
4176 | const std::string ExpectedName = Intrinsic::getName(ID, ArgTys); | |||
4177 | Assert(ExpectedName == IF->getName(),do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! " "Should be: " + ExpectedName, IF); return; } } while (false) | |||
4178 | "Intrinsic name not mangled correctly for type arguments! "do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! " "Should be: " + ExpectedName, IF); return; } } while (false) | |||
4179 | "Should be: " +do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! " "Should be: " + ExpectedName, IF); return; } } while (false) | |||
4180 | ExpectedName,do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! " "Should be: " + ExpectedName, IF); return; } } while (false) | |||
4181 | IF)do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! " "Should be: " + ExpectedName, IF); return; } } while (false); | |||
4182 | ||||
4183 | // If the intrinsic takes MDNode arguments, verify that they are either global | |||
4184 | // or are local to *this* function. | |||
4185 | for (Value *V : Call.args()) | |||
4186 | if (auto *MD = dyn_cast<MetadataAsValue>(V)) | |||
4187 | visitMetadataAsValue(*MD, Call.getCaller()); | |||
4188 | ||||
4189 | switch (ID) { | |||
4190 | default: | |||
4191 | break; | |||
4192 | case Intrinsic::coro_id: { | |||
4193 | auto *InfoArg = Call.getArgOperand(3)->stripPointerCasts(); | |||
4194 | if (isa<ConstantPointerNull>(InfoArg)) | |||
4195 | break; | |||
4196 | auto *GV = dyn_cast<GlobalVariable>(InfoArg); | |||
4197 | Assert(GV && GV->isConstant() && GV->hasDefinitiveInitializer(),do { if (!(GV && GV->isConstant() && GV-> hasDefinitiveInitializer())) { CheckFailed("info argument of llvm.coro.begin must refer to an initialized " "constant"); return; } } while (false) | |||
4198 | "info argument of llvm.coro.begin must refer to an initialized "do { if (!(GV && GV->isConstant() && GV-> hasDefinitiveInitializer())) { CheckFailed("info argument of llvm.coro.begin must refer to an initialized " "constant"); return; } } while (false) | |||
4199 | "constant")do { if (!(GV && GV->isConstant() && GV-> hasDefinitiveInitializer())) { CheckFailed("info argument of llvm.coro.begin must refer to an initialized " "constant"); return; } } while (false); | |||
4200 | Constant *Init = GV->getInitializer(); | |||
4201 | Assert(isa<ConstantStruct>(Init) || isa<ConstantArray>(Init),do { if (!(isa<ConstantStruct>(Init) || isa<ConstantArray >(Init))) { CheckFailed("info argument of llvm.coro.begin must refer to either a struct or " "an array"); return; } } while (false) | |||
4202 | "info argument of llvm.coro.begin must refer to either a struct or "do { if (!(isa<ConstantStruct>(Init) || isa<ConstantArray >(Init))) { CheckFailed("info argument of llvm.coro.begin must refer to either a struct or " "an array"); return; } } while (false) | |||
4203 | "an array")do { if (!(isa<ConstantStruct>(Init) || isa<ConstantArray >(Init))) { CheckFailed("info argument of llvm.coro.begin must refer to either a struct or " "an array"); return; } } while (false); | |||
4204 | break; | |||
4205 | } | |||
4206 | case Intrinsic::experimental_constrained_fadd: | |||
4207 | case Intrinsic::experimental_constrained_fsub: | |||
4208 | case Intrinsic::experimental_constrained_fmul: | |||
4209 | case Intrinsic::experimental_constrained_fdiv: | |||
4210 | case Intrinsic::experimental_constrained_frem: | |||
4211 | case Intrinsic::experimental_constrained_fma: | |||
4212 | case Intrinsic::experimental_constrained_sqrt: | |||
4213 | case Intrinsic::experimental_constrained_pow: | |||
4214 | case Intrinsic::experimental_constrained_powi: | |||
4215 | case Intrinsic::experimental_constrained_sin: | |||
4216 | case Intrinsic::experimental_constrained_cos: | |||
4217 | case Intrinsic::experimental_constrained_exp: | |||
4218 | case Intrinsic::experimental_constrained_exp2: | |||
4219 | case Intrinsic::experimental_constrained_log: | |||
4220 | case Intrinsic::experimental_constrained_log10: | |||
4221 | case Intrinsic::experimental_constrained_log2: | |||
4222 | case Intrinsic::experimental_constrained_rint: | |||
4223 | case Intrinsic::experimental_constrained_nearbyint: | |||
4224 | case Intrinsic::experimental_constrained_maxnum: | |||
4225 | case Intrinsic::experimental_constrained_minnum: | |||
4226 | case Intrinsic::experimental_constrained_ceil: | |||
4227 | case Intrinsic::experimental_constrained_floor: | |||
4228 | case Intrinsic::experimental_constrained_round: | |||
4229 | case Intrinsic::experimental_constrained_trunc: | |||
4230 | visitConstrainedFPIntrinsic(cast<ConstrainedFPIntrinsic>(Call)); | |||
4231 | break; | |||
4232 | case Intrinsic::dbg_declare: // llvm.dbg.declare | |||
4233 | Assert(isa<MetadataAsValue>(Call.getArgOperand(0)),do { if (!(isa<MetadataAsValue>(Call.getArgOperand(0))) ) { CheckFailed("invalid llvm.dbg.declare intrinsic call 1", Call ); return; } } while (false) | |||
4234 | "invalid llvm.dbg.declare intrinsic call 1", Call)do { if (!(isa<MetadataAsValue>(Call.getArgOperand(0))) ) { CheckFailed("invalid llvm.dbg.declare intrinsic call 1", Call ); return; } } while (false); | |||
4235 | visitDbgIntrinsic("declare", cast<DbgVariableIntrinsic>(Call)); | |||
4236 | break; | |||
4237 | case Intrinsic::dbg_addr: // llvm.dbg.addr | |||
4238 | visitDbgIntrinsic("addr", cast<DbgVariableIntrinsic>(Call)); | |||
4239 | break; | |||
4240 | case Intrinsic::dbg_value: // llvm.dbg.value | |||
4241 | visitDbgIntrinsic("value", cast<DbgVariableIntrinsic>(Call)); | |||
4242 | break; | |||
4243 | case Intrinsic::dbg_label: // llvm.dbg.label | |||
4244 | visitDbgLabelIntrinsic("label", cast<DbgLabelInst>(Call)); | |||
4245 | break; | |||
4246 | case Intrinsic::memcpy: | |||
4247 | case Intrinsic::memmove: | |||
4248 | case Intrinsic::memset: { | |||
4249 | const auto *MI = cast<MemIntrinsic>(&Call); | |||
4250 | auto IsValidAlignment = [&](unsigned Alignment) -> bool { | |||
4251 | return Alignment == 0 || isPowerOf2_32(Alignment); | |||
4252 | }; | |||
4253 | Assert(IsValidAlignment(MI->getDestAlignment()),do { if (!(IsValidAlignment(MI->getDestAlignment()))) { CheckFailed ("alignment of arg 0 of memory intrinsic must be 0 or a power of 2" , Call); return; } } while (false) | |||
4254 | "alignment of arg 0 of memory intrinsic must be 0 or a power of 2",do { if (!(IsValidAlignment(MI->getDestAlignment()))) { CheckFailed ("alignment of arg 0 of memory intrinsic must be 0 or a power of 2" , Call); return; } } while (false) | |||
4255 | Call)do { if (!(IsValidAlignment(MI->getDestAlignment()))) { CheckFailed ("alignment of arg 0 of memory intrinsic must be 0 or a power of 2" , Call); return; } } while (false); | |||
4256 | if (const auto *MTI = dyn_cast<MemTransferInst>(MI)) { | |||
4257 | Assert(IsValidAlignment(MTI->getSourceAlignment()),do { if (!(IsValidAlignment(MTI->getSourceAlignment()))) { CheckFailed("alignment of arg 1 of memory intrinsic must be 0 or a power of 2" , Call); return; } } while (false) | |||
4258 | "alignment of arg 1 of memory intrinsic must be 0 or a power of 2",do { if (!(IsValidAlignment(MTI->getSourceAlignment()))) { CheckFailed("alignment of arg 1 of memory intrinsic must be 0 or a power of 2" , Call); return; } } while (false) | |||
4259 | Call)do { if (!(IsValidAlignment(MTI->getSourceAlignment()))) { CheckFailed("alignment of arg 1 of memory intrinsic must be 0 or a power of 2" , Call); return; } } while (false); | |||
4260 | } | |||
4261 | ||||
4262 | break; | |||
4263 | } | |||
4264 | case Intrinsic::memcpy_element_unordered_atomic: | |||
4265 | case Intrinsic::memmove_element_unordered_atomic: | |||
4266 | case Intrinsic::memset_element_unordered_atomic: { | |||
4267 | const auto *AMI = cast<AtomicMemIntrinsic>(&Call); | |||
4268 | ||||
4269 | ConstantInt *ElementSizeCI = | |||
4270 | cast<ConstantInt>(AMI->getRawElementSizeInBytes()); | |||
4271 | const APInt &ElementSizeVal = ElementSizeCI->getValue(); | |||
4272 | Assert(ElementSizeVal.isPowerOf2(),do { if (!(ElementSizeVal.isPowerOf2())) { CheckFailed("element size of the element-wise atomic memory intrinsic " "must be a power of 2", Call); return; } } while (false) | |||
4273 | "element size of the element-wise atomic memory intrinsic "do { if (!(ElementSizeVal.isPowerOf2())) { CheckFailed("element size of the element-wise atomic memory intrinsic " "must be a power of 2", Call); return; } } while (false) | |||
4274 | "must be a power of 2",do { if (!(ElementSizeVal.isPowerOf2())) { CheckFailed("element size of the element-wise atomic memory intrinsic " "must be a power of 2", Call); return; } } while (false) | |||
4275 | Call)do { if (!(ElementSizeVal.isPowerOf2())) { CheckFailed("element size of the element-wise atomic memory intrinsic " "must be a power of 2", Call); return; } } while (false); | |||
4276 | ||||
4277 | if (auto *LengthCI = dyn_cast<ConstantInt>(AMI->getLength())) { | |||
4278 | uint64_t Length = LengthCI->getZExtValue(); | |||
4279 | uint64_t ElementSize = AMI->getElementSizeInBytes(); | |||
4280 | Assert((Length % ElementSize) == 0,do { if (!((Length % ElementSize) == 0)) { CheckFailed("constant length must be a multiple of the element size in the " "element-wise atomic memory intrinsic", Call); return; } } while (false) | |||
4281 | "constant length must be a multiple of the element size in the "do { if (!((Length % ElementSize) == 0)) { CheckFailed("constant length must be a multiple of the element size in the " "element-wise atomic memory intrinsic", Call); return; } } while (false) | |||
4282 | "element-wise atomic memory intrinsic",do { if (!((Length % ElementSize) == 0)) { CheckFailed("constant length must be a multiple of the element size in the " "element-wise atomic memory intrinsic", Call); return; } } while (false) | |||
4283 | Call)do { if (!((Length % ElementSize) == 0)) { CheckFailed("constant length must be a multiple of the element size in the " "element-wise atomic memory intrinsic", Call); return; } } while (false); | |||
4284 | } | |||
4285 | ||||
4286 | auto IsValidAlignment = [&](uint64_t Alignment) { | |||
4287 | return isPowerOf2_64(Alignment) && ElementSizeVal.ule(Alignment); | |||
4288 | }; | |||
4289 | uint64_t DstAlignment = AMI->getDestAlignment(); | |||
4290 | Assert(IsValidAlignment(DstAlignment),do { if (!(IsValidAlignment(DstAlignment))) { CheckFailed("incorrect alignment of the destination argument" , Call); return; } } while (false) | |||
4291 | "incorrect alignment of the destination argument", Call)do { if (!(IsValidAlignment(DstAlignment))) { CheckFailed("incorrect alignment of the destination argument" , Call); return; } } while (false); | |||
4292 | if (const auto *AMT = dyn_cast<AtomicMemTransferInst>(AMI)) { | |||
4293 | uint64_t SrcAlignment = AMT->getSourceAlignment(); | |||
4294 | Assert(IsValidAlignment(SrcAlignment),do { if (!(IsValidAlignment(SrcAlignment))) { CheckFailed("incorrect alignment of the source argument" , Call); return; } } while (false) | |||
4295 | "incorrect alignment of the source argument", Call)do { if (!(IsValidAlignment(SrcAlignment))) { CheckFailed("incorrect alignment of the source argument" , Call); return; } } while (false); | |||
4296 | } | |||
4297 | break; | |||
4298 | } | |||
4299 | case Intrinsic::gcroot: | |||
4300 | case Intrinsic::gcwrite: | |||
4301 | case Intrinsic::gcread: | |||
4302 | if (ID == Intrinsic::gcroot) { | |||
4303 | AllocaInst *AI = | |||
4304 | dyn_cast<AllocaInst>(Call.getArgOperand(0)->stripPointerCasts()); | |||
4305 | Assert(AI, "llvm.gcroot parameter #1 must be an alloca.", Call)do { if (!(AI)) { CheckFailed("llvm.gcroot parameter #1 must be an alloca." , Call); return; } } while (false); | |||
4306 | Assert(isa<Constant>(Call.getArgOperand(1)),do { if (!(isa<Constant>(Call.getArgOperand(1)))) { CheckFailed ("llvm.gcroot parameter #2 must be a constant.", Call); return ; } } while (false) | |||
4307 | "llvm.gcroot parameter #2 must be a constant.", Call)do { if (!(isa<Constant>(Call.getArgOperand(1)))) { CheckFailed ("llvm.gcroot parameter #2 must be a constant.", Call); return ; } } while (false); | |||
4308 | if (!AI->getAllocatedType()->isPointerTy()) { | |||
4309 | Assert(!isa<ConstantPointerNull>(Call.getArgOperand(1)),do { if (!(!isa<ConstantPointerNull>(Call.getArgOperand (1)))) { CheckFailed("llvm.gcroot parameter #1 must either be a pointer alloca, " "or argument #2 must be a non-null constant.", Call); return ; } } while (false) | |||
4310 | "llvm.gcroot parameter #1 must either be a pointer alloca, "do { if (!(!isa<ConstantPointerNull>(Call.getArgOperand (1)))) { CheckFailed("llvm.gcroot parameter #1 must either be a pointer alloca, " "or argument #2 must be a non-null constant.", Call); return ; } } while (false) | |||
4311 | "or argument #2 must be a non-null constant.",do { if (!(!isa<ConstantPointerNull>(Call.getArgOperand (1)))) { CheckFailed("llvm.gcroot parameter #1 must either be a pointer alloca, " "or argument #2 must be a non-null constant.", Call); return ; } } while (false) | |||
4312 | Call)do { if (!(!isa<ConstantPointerNull>(Call.getArgOperand (1)))) { CheckFailed("llvm.gcroot parameter #1 must either be a pointer alloca, " "or argument #2 must be a non-null constant.", Call); return ; } } while (false); | |||
4313 | } | |||
4314 | } | |||
4315 | ||||
4316 | Assert(Call.getParent()->getParent()->hasGC(),do { if (!(Call.getParent()->getParent()->hasGC())) { CheckFailed ("Enclosing function does not use GC.", Call); return; } } while (false) | |||
4317 | "Enclosing function does not use GC.", Call)do { if (!(Call.getParent()->getParent()->hasGC())) { CheckFailed ("Enclosing function does not use GC.", Call); return; } } while (false); | |||
4318 | break; | |||
4319 | case Intrinsic::init_trampoline: | |||
4320 | Assert(isa<Function>(Call.getArgOperand(1)->stripPointerCasts()),do { if (!(isa<Function>(Call.getArgOperand(1)->stripPointerCasts ()))) { CheckFailed("llvm.init_trampoline parameter #2 must resolve to a function." , Call); return; } } while (false) | |||
4321 | "llvm.init_trampoline parameter #2 must resolve to a function.",do { if (!(isa<Function>(Call.getArgOperand(1)->stripPointerCasts ()))) { CheckFailed("llvm.init_trampoline parameter #2 must resolve to a function." , Call); return; } } while (false) | |||
4322 | Call)do { if (!(isa<Function>(Call.getArgOperand(1)->stripPointerCasts ()))) { CheckFailed("llvm.init_trampoline parameter #2 must resolve to a function." , Call); return; } } while (false); | |||
4323 | break; | |||
4324 | case Intrinsic::prefetch: | |||
4325 | Assert(cast<ConstantInt>(Call.getArgOperand(1))->getZExtValue() < 2 &&do { if (!(cast<ConstantInt>(Call.getArgOperand(1))-> getZExtValue() < 2 && cast<ConstantInt>(Call .getArgOperand(2))->getZExtValue() < 4)) { CheckFailed( "invalid arguments to llvm.prefetch", Call); return; } } while (false) | |||
4326 | cast<ConstantInt>(Call.getArgOperand(2))->getZExtValue() < 4,do { if (!(cast<ConstantInt>(Call.getArgOperand(1))-> getZExtValue() < 2 && cast<ConstantInt>(Call .getArgOperand(2))->getZExtValue() < 4)) { CheckFailed( "invalid arguments to llvm.prefetch", Call); return; } } while (false) | |||
4327 | "invalid arguments to llvm.prefetch", Call)do { if (!(cast<ConstantInt>(Call.getArgOperand(1))-> getZExtValue() < 2 && cast<ConstantInt>(Call .getArgOperand(2))->getZExtValue() < 4)) { CheckFailed( "invalid arguments to llvm.prefetch", Call); return; } } while (false); | |||
4328 | break; | |||
4329 | case Intrinsic::stackprotector: | |||
4330 | Assert(isa<AllocaInst>(Call.getArgOperand(1)->stripPointerCasts()),do { if (!(isa<AllocaInst>(Call.getArgOperand(1)->stripPointerCasts ()))) { CheckFailed("llvm.stackprotector parameter #2 must resolve to an alloca." , Call); return; } } while (false) | |||
4331 | "llvm.stackprotector parameter #2 must resolve to an alloca.", Call)do { if (!(isa<AllocaInst>(Call.getArgOperand(1)->stripPointerCasts ()))) { CheckFailed("llvm.stackprotector parameter #2 must resolve to an alloca." , Call); return; } } while (false); | |||
4332 | break; | |||
4333 | case Intrinsic::localescape: { | |||
4334 | BasicBlock *BB = Call.getParent(); | |||
4335 | Assert(BB == &BB->getParent()->front(),do { if (!(BB == &BB->getParent()->front())) { CheckFailed ("llvm.localescape used outside of entry block", Call); return ; } } while (false) | |||
4336 | "llvm.localescape used outside of entry block", Call)do { if (!(BB == &BB->getParent()->front())) { CheckFailed ("llvm.localescape used outside of entry block", Call); return ; } } while (false); | |||
4337 | Assert(!SawFrameEscape,do { if (!(!SawFrameEscape)) { CheckFailed("multiple calls to llvm.localescape in one function" , Call); return; } } while (false) | |||
4338 | "multiple calls to llvm.localescape in one function", Call)do { if (!(!SawFrameEscape)) { CheckFailed("multiple calls to llvm.localescape in one function" , Call); return; } } while (false); | |||
4339 | for (Value *Arg : Call.args()) { | |||
4340 | if (isa<ConstantPointerNull>(Arg)) | |||
4341 | continue; // Null values are allowed as placeholders. | |||
4342 | auto *AI = dyn_cast<AllocaInst>(Arg->stripPointerCasts()); | |||
4343 | Assert(AI && AI->isStaticAlloca(),do { if (!(AI && AI->isStaticAlloca())) { CheckFailed ("llvm.localescape only accepts static allocas", Call); return ; } } while (false) | |||
4344 | "llvm.localescape only accepts static allocas", Call)do { if (!(AI && AI->isStaticAlloca())) { CheckFailed ("llvm.localescape only accepts static allocas", Call); return ; } } while (false); | |||
4345 | } | |||
4346 | FrameEscapeInfo[BB->getParent()].first = Call.getNumArgOperands(); | |||
4347 | SawFrameEscape = true; | |||
4348 | break; | |||
4349 | } | |||
4350 | case Intrinsic::localrecover: { | |||
4351 | Value *FnArg = Call.getArgOperand(0)->stripPointerCasts(); | |||
4352 | Function *Fn = dyn_cast<Function>(FnArg); | |||
4353 | Assert(Fn && !Fn->isDeclaration(),do { if (!(Fn && !Fn->isDeclaration())) { CheckFailed ("llvm.localrecover first " "argument must be function defined in this module" , Call); return; } } while (false) | |||
4354 | "llvm.localrecover first "do { if (!(Fn && !Fn->isDeclaration())) { CheckFailed ("llvm.localrecover first " "argument must be function defined in this module" , Call); return; } } while (false) | |||
4355 | "argument must be function defined in this module",do { if (!(Fn && !Fn->isDeclaration())) { CheckFailed ("llvm.localrecover first " "argument must be function defined in this module" , Call); return; } } while (false) | |||
4356 | Call)do { if (!(Fn && !Fn->isDeclaration())) { CheckFailed ("llvm.localrecover first " "argument must be function defined in this module" , Call); return; } } while (false); | |||
4357 | auto *IdxArg = cast<ConstantInt>(Call.getArgOperand(2)); | |||
4358 | auto &Entry = FrameEscapeInfo[Fn]; | |||
4359 | Entry.second = unsigned( | |||
4360 | std::max(uint64_t(Entry.second), IdxArg->getLimitedValue(~0U) + 1)); | |||
4361 | break; | |||
4362 | } | |||
4363 | ||||
4364 | case Intrinsic::experimental_gc_statepoint: | |||
4365 | if (auto *CI = dyn_cast<CallInst>(&Call)) | |||
4366 | Assert(!CI->isInlineAsm(),do { if (!(!CI->isInlineAsm())) { CheckFailed("gc.statepoint support for inline assembly unimplemented" , CI); return; } } while (false) | |||
4367 | "gc.statepoint support for inline assembly unimplemented", CI)do { if (!(!CI->isInlineAsm())) { CheckFailed("gc.statepoint support for inline assembly unimplemented" , CI); return; } } while (false); | |||
4368 | Assert(Call.getParent()->getParent()->hasGC(),do { if (!(Call.getParent()->getParent()->hasGC())) { CheckFailed ("Enclosing function does not use GC.", Call); return; } } while (false) | |||
4369 | "Enclosing function does not use GC.", Call)do { if (!(Call.getParent()->getParent()->hasGC())) { CheckFailed ("Enclosing function does not use GC.", Call); return; } } while (false); | |||
4370 | ||||
4371 | verifyStatepoint(Call); | |||
4372 | break; | |||
4373 | case Intrinsic::experimental_gc_result: { | |||
4374 | Assert(Call.getParent()->getParent()->hasGC(),do { if (!(Call.getParent()->getParent()->hasGC())) { CheckFailed ("Enclosing function does not use GC.", Call); return; } } while (false) | |||
4375 | "Enclosing function does not use GC.", Call)do { if (!(Call.getParent()->getParent()->hasGC())) { CheckFailed ("Enclosing function does not use GC.", Call); return; } } while (false); | |||
4376 | // Are we tied to a statepoint properly? | |||
4377 | const auto *StatepointCall = dyn_cast<CallBase>(Call.getArgOperand(0)); | |||
4378 | const Function *StatepointFn = | |||
4379 | StatepointCall ? StatepointCall->getCalledFunction() : nullptr; | |||
4380 | Assert(StatepointFn && StatepointFn->isDeclaration() &&do { if (!(StatepointFn && StatepointFn->isDeclaration () && StatepointFn->getIntrinsicID() == Intrinsic:: experimental_gc_statepoint)) { CheckFailed("gc.result operand #1 must be from a statepoint" , Call, Call.getArgOperand(0)); return; } } while (false) | |||
4381 | StatepointFn->getIntrinsicID() ==do { if (!(StatepointFn && StatepointFn->isDeclaration () && StatepointFn->getIntrinsicID() == Intrinsic:: experimental_gc_statepoint)) { CheckFailed("gc.result operand #1 must be from a statepoint" , Call, Call.getArgOperand(0)); return; } } while (false) | |||
4382 | Intrinsic::experimental_gc_statepoint,do { if (!(StatepointFn && StatepointFn->isDeclaration () && StatepointFn->getIntrinsicID() == Intrinsic:: experimental_gc_statepoint)) { CheckFailed("gc.result operand #1 must be from a statepoint" , Call, Call.getArgOperand(0)); return; } } while (false) | |||
4383 | "gc.result operand #1 must be from a statepoint", Call,do { if (!(StatepointFn && StatepointFn->isDeclaration () && StatepointFn->getIntrinsicID() == Intrinsic:: experimental_gc_statepoint)) { CheckFailed("gc.result operand #1 must be from a statepoint" , Call, Call.getArgOperand(0)); return; } } while (false) | |||
4384 | Call.getArgOperand(0))do { if (!(StatepointFn && StatepointFn->isDeclaration () && StatepointFn->getIntrinsicID() == Intrinsic:: experimental_gc_statepoint)) { CheckFailed("gc.result operand #1 must be from a statepoint" , Call, Call.getArgOperand(0)); return; } } while (false); | |||
4385 | ||||
4386 | // Assert that result type matches wrapped callee. | |||
4387 | const Value *Target = StatepointCall->getArgOperand(2); | |||
4388 | auto *PT = cast<PointerType>(Target->getType()); | |||
4389 | auto *TargetFuncType = cast<FunctionType>(PT->getElementType()); | |||
4390 | Assert(Call.getType() == TargetFuncType->getReturnType(),do { if (!(Call.getType() == TargetFuncType->getReturnType ())) { CheckFailed("gc.result result type does not match wrapped callee" , Call); return; } } while (false) | |||
4391 | "gc.result result type does not match wrapped callee", Call)do { if (!(Call.getType() == TargetFuncType->getReturnType ())) { CheckFailed("gc.result result type does not match wrapped callee" , Call); return; } } while (false); | |||
4392 | break; | |||
4393 | } | |||
4394 | case Intrinsic::experimental_gc_relocate: { | |||
4395 | Assert(Call.getNumArgOperands() == 3, "wrong number of arguments", Call)do { if (!(Call.getNumArgOperands() == 3)) { CheckFailed("wrong number of arguments" , Call); return; } } while (false); | |||
4396 | ||||
4397 | Assert(isa<PointerType>(Call.getType()->getScalarType()),do { if (!(isa<PointerType>(Call.getType()->getScalarType ()))) { CheckFailed("gc.relocate must return a pointer or a vector of pointers" , Call); return; } } while (false) | |||
4398 | "gc.relocate must return a pointer or a vector of pointers", Call)do { if (!(isa<PointerType>(Call.getType()->getScalarType ()))) { CheckFailed("gc.relocate must return a pointer or a vector of pointers" , Call); return; } } while (false); | |||
4399 | ||||
4400 | // Check that this relocate is correctly tied to the statepoint | |||
4401 | ||||
4402 | // This is case for relocate on the unwinding path of an invoke statepoint | |||
4403 | if (LandingPadInst *LandingPad = | |||
4404 | dyn_cast<LandingPadInst>(Call.getArgOperand(0))) { | |||
4405 | ||||
4406 | const BasicBlock *InvokeBB = | |||
4407 | LandingPad->getParent()->getUniquePredecessor(); | |||
4408 | ||||
4409 | // Landingpad relocates should have only one predecessor with invoke | |||
4410 | // statepoint terminator | |||
4411 | Assert(InvokeBB, "safepoints should have unique landingpads",do { if (!(InvokeBB)) { CheckFailed("safepoints should have unique landingpads" , LandingPad->getParent()); return; } } while (false) | |||
4412 | LandingPad->getParent())do { if (!(InvokeBB)) { CheckFailed("safepoints should have unique landingpads" , LandingPad->getParent()); return; } } while (false); | |||
4413 | Assert(InvokeBB->getTerminator(), "safepoint block should be well formed",do { if (!(InvokeBB->getTerminator())) { CheckFailed("safepoint block should be well formed" , InvokeBB); return; } } while (false) | |||
4414 | InvokeBB)do { if (!(InvokeBB->getTerminator())) { CheckFailed("safepoint block should be well formed" , InvokeBB); return; } } while (false); | |||
4415 | Assert(isStatepoint(InvokeBB->getTerminator()),do { if (!(isStatepoint(InvokeBB->getTerminator()))) { CheckFailed ("gc relocate should be linked to a statepoint", InvokeBB); return ; } } while (false) | |||
4416 | "gc relocate should be linked to a statepoint", InvokeBB)do { if (!(isStatepoint(InvokeBB->getTerminator()))) { CheckFailed ("gc relocate should be linked to a statepoint", InvokeBB); return ; } } while (false); | |||
4417 | } else { | |||
4418 | // In all other cases relocate should be tied to the statepoint directly. | |||
4419 | // This covers relocates on a normal return path of invoke statepoint and | |||
4420 | // relocates of a call statepoint. | |||
4421 | auto Token = Call.getArgOperand(0); | |||
4422 | Assert(isa<Instruction>(Token) && isStatepoint(cast<Instruction>(Token)),do { if (!(isa<Instruction>(Token) && isStatepoint (cast<Instruction>(Token)))) { CheckFailed("gc relocate is incorrectly tied to the statepoint" , Call, Token); return; } } while (false) | |||
4423 | "gc relocate is incorrectly tied to the statepoint", Call, Token)do { if (!(isa<Instruction>(Token) && isStatepoint (cast<Instruction>(Token)))) { CheckFailed("gc relocate is incorrectly tied to the statepoint" , Call, Token); return; } } while (false); | |||
4424 | } | |||
4425 | ||||
4426 | // Verify rest of the relocate arguments. | |||
4427 | const CallBase &StatepointCall = | |||
4428 | *cast<CallBase>(cast<GCRelocateInst>(Call).getStatepoint()); | |||
4429 | ||||
4430 | // Both the base and derived must be piped through the safepoint. | |||
4431 | Value *Base = Call.getArgOperand(1); | |||
4432 | Assert(isa<ConstantInt>(Base),do { if (!(isa<ConstantInt>(Base))) { CheckFailed("gc.relocate operand #2 must be integer offset" , Call); return; } } while (false) | |||
4433 | "gc.relocate operand #2 must be integer offset", Call)do { if (!(isa<ConstantInt>(Base))) { CheckFailed("gc.relocate operand #2 must be integer offset" , Call); return; } } while (false); | |||
4434 | ||||
4435 | Value *Derived = Call.getArgOperand(2); | |||
4436 | Assert(isa<ConstantInt>(Derived),do { if (!(isa<ConstantInt>(Derived))) { CheckFailed("gc.relocate operand #3 must be integer offset" , Call); return; } } while (false) | |||
4437 | "gc.relocate operand #3 must be integer offset", Call)do { if (!(isa<ConstantInt>(Derived))) { CheckFailed("gc.relocate operand #3 must be integer offset" , Call); return; } } while (false); | |||
4438 | ||||
4439 | const int BaseIndex = cast<ConstantInt>(Base)->getZExtValue(); | |||
4440 | const int DerivedIndex = cast<ConstantInt>(Derived)->getZExtValue(); | |||
4441 | // Check the bounds | |||
4442 | Assert(0 <= BaseIndex && BaseIndex < (int)StatepointCall.arg_size(),do { if (!(0 <= BaseIndex && BaseIndex < (int)StatepointCall .arg_size())) { CheckFailed("gc.relocate: statepoint base index out of bounds" , Call); return; } } while (false) | |||
4443 | "gc.relocate: statepoint base index out of bounds", Call)do { if (!(0 <= BaseIndex && BaseIndex < (int)StatepointCall .arg_size())) { CheckFailed("gc.relocate: statepoint base index out of bounds" , Call); return; } } while (false); | |||
4444 | Assert(0 <= DerivedIndex && DerivedIndex < (int)StatepointCall.arg_size(),do { if (!(0 <= DerivedIndex && DerivedIndex < ( int)StatepointCall.arg_size())) { CheckFailed("gc.relocate: statepoint derived index out of bounds" , Call); return; } } while (false) | |||
4445 | "gc.relocate: statepoint derived index out of bounds", Call)do { if (!(0 <= DerivedIndex && DerivedIndex < ( int)StatepointCall.arg_size())) { CheckFailed("gc.relocate: statepoint derived index out of bounds" , Call); return; } } while (false); | |||
4446 | ||||
4447 | // Check that BaseIndex and DerivedIndex fall within the 'gc parameters' | |||
4448 | // section of the statepoint's argument. | |||
4449 | Assert(StatepointCall.arg_size() > 0,do { if (!(StatepointCall.arg_size() > 0)) { CheckFailed("gc.statepoint: insufficient arguments" ); return; } } while (false) | |||
4450 | "gc.statepoint: insufficient arguments")do { if (!(StatepointCall.arg_size() > 0)) { CheckFailed("gc.statepoint: insufficient arguments" ); return; } } while (false); | |||
4451 | Assert(isa<ConstantInt>(StatepointCall.getArgOperand(3)),do { if (!(isa<ConstantInt>(StatepointCall.getArgOperand (3)))) { CheckFailed("gc.statement: number of call arguments must be constant integer" ); return; } } while (false) | |||
4452 | "gc.statement: number of call arguments must be constant integer")do { if (!(isa<ConstantInt>(StatepointCall.getArgOperand (3)))) { CheckFailed("gc.statement: number of call arguments must be constant integer" ); return; } } while (false); | |||
4453 | const unsigned NumCallArgs = | |||
4454 | cast<ConstantInt>(StatepointCall.getArgOperand(3))->getZExtValue(); | |||
4455 | Assert(StatepointCall.arg_size() > NumCallArgs + 5,do { if (!(StatepointCall.arg_size() > NumCallArgs + 5)) { CheckFailed("gc.statepoint: mismatch in number of call arguments" ); return; } } while (false) | |||
4456 | "gc.statepoint: mismatch in number of call arguments")do { if (!(StatepointCall.arg_size() > NumCallArgs + 5)) { CheckFailed("gc.statepoint: mismatch in number of call arguments" ); return; } } while (false); | |||
4457 | Assert(isa<ConstantInt>(StatepointCall.getArgOperand(NumCallArgs + 5)),do { if (!(isa<ConstantInt>(StatepointCall.getArgOperand (NumCallArgs + 5)))) { CheckFailed("gc.statepoint: number of transition arguments must be " "a constant integer"); return; } } while (false) | |||
4458 | "gc.statepoint: number of transition arguments must be "do { if (!(isa<ConstantInt>(StatepointCall.getArgOperand (NumCallArgs + 5)))) { CheckFailed("gc.statepoint: number of transition arguments must be " "a constant integer"); return; } } while (false) | |||
4459 | "a constant integer")do { if (!(isa<ConstantInt>(StatepointCall.getArgOperand (NumCallArgs + 5)))) { CheckFailed("gc.statepoint: number of transition arguments must be " "a constant integer"); return; } } while (false); | |||
4460 | const int NumTransitionArgs = | |||
4461 | cast<ConstantInt>(StatepointCall.getArgOperand(NumCallArgs + 5)) | |||
4462 | ->getZExtValue(); | |||
4463 | const int DeoptArgsStart = 4 + NumCallArgs + 1 + NumTransitionArgs + 1; | |||
4464 | Assert(isa<ConstantInt>(StatepointCall.getArgOperand(DeoptArgsStart)),do { if (!(isa<ConstantInt>(StatepointCall.getArgOperand (DeoptArgsStart)))) { CheckFailed("gc.statepoint: number of deoptimization arguments must be " "a constant integer"); return; } } while (false) | |||
4465 | "gc.statepoint: number of deoptimization arguments must be "do { if (!(isa<ConstantInt>(StatepointCall.getArgOperand (DeoptArgsStart)))) { CheckFailed("gc.statepoint: number of deoptimization arguments must be " "a constant integer"); return; } } while (false) | |||
4466 | "a constant integer")do { if (!(isa<ConstantInt>(StatepointCall.getArgOperand (DeoptArgsStart)))) { CheckFailed("gc.statepoint: number of deoptimization arguments must be " "a constant integer"); return; } } while (false); | |||
4467 | const int NumDeoptArgs = | |||
4468 | cast<ConstantInt>(StatepointCall.getArgOperand(DeoptArgsStart)) | |||
4469 | ->getZExtValue(); | |||
4470 | const int GCParamArgsStart = DeoptArgsStart + 1 + NumDeoptArgs; | |||
4471 | const int GCParamArgsEnd = StatepointCall.arg_size(); | |||
4472 | Assert(GCParamArgsStart <= BaseIndex && BaseIndex < GCParamArgsEnd,do { if (!(GCParamArgsStart <= BaseIndex && BaseIndex < GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint base index doesn't fall within the " "'gc parameters' section of the statepoint call", Call); return ; } } while (false) | |||
4473 | "gc.relocate: statepoint base index doesn't fall within the "do { if (!(GCParamArgsStart <= BaseIndex && BaseIndex < GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint base index doesn't fall within the " "'gc parameters' section of the statepoint call", Call); return ; } } while (false) | |||
4474 | "'gc parameters' section of the statepoint call",do { if (!(GCParamArgsStart <= BaseIndex && BaseIndex < GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint base index doesn't fall within the " "'gc parameters' section of the statepoint call", Call); return ; } } while (false) | |||
4475 | Call)do { if (!(GCParamArgsStart <= BaseIndex && BaseIndex < GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint base index doesn't fall within the " "'gc parameters' section of the statepoint call", Call); return ; } } while (false); | |||
4476 | Assert(GCParamArgsStart <= DerivedIndex && DerivedIndex < GCParamArgsEnd,do { if (!(GCParamArgsStart <= DerivedIndex && DerivedIndex < GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint derived index doesn't fall within the " "'gc parameters' section of the statepoint call", Call); return ; } } while (false) | |||
4477 | "gc.relocate: statepoint derived index doesn't fall within the "do { if (!(GCParamArgsStart <= DerivedIndex && DerivedIndex < GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint derived index doesn't fall within the " "'gc parameters' section of the statepoint call", Call); return ; } } while (false) | |||
4478 | "'gc parameters' section of the statepoint call",do { if (!(GCParamArgsStart <= DerivedIndex && DerivedIndex < GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint derived index doesn't fall within the " "'gc parameters' section of the statepoint call", Call); return ; } } while (false) | |||
4479 | Call)do { if (!(GCParamArgsStart <= DerivedIndex && DerivedIndex < GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint derived index doesn't fall within the " "'gc parameters' section of the statepoint call", Call); return ; } } while (false); | |||
4480 | ||||
4481 | // Relocated value must be either a pointer type or vector-of-pointer type, | |||
4482 | // but gc_relocate does not need to return the same pointer type as the | |||
4483 | // relocated pointer. It can be casted to the correct type later if it's | |||
4484 | // desired. However, they must have the same address space and 'vectorness' | |||
4485 | GCRelocateInst &Relocate = cast<GCRelocateInst>(Call); | |||
4486 | Assert(Relocate.getDerivedPtr()->getType()->isPtrOrPtrVectorTy(),do { if (!(Relocate.getDerivedPtr()->getType()->isPtrOrPtrVectorTy ())) { CheckFailed("gc.relocate: relocated value must be a gc pointer" , Call); return; } } while (false) | |||
4487 | "gc.relocate: relocated value must be a gc pointer", Call)do { if (!(Relocate.getDerivedPtr()->getType()->isPtrOrPtrVectorTy ())) { CheckFailed("gc.relocate: relocated value must be a gc pointer" , Call); return; } } while (false); | |||
4488 | ||||
4489 | auto ResultType = Call.getType(); | |||
4490 | auto DerivedType = Relocate.getDerivedPtr()->getType(); | |||
4491 | Assert(ResultType->isVectorTy() == DerivedType->isVectorTy(),do { if (!(ResultType->isVectorTy() == DerivedType->isVectorTy ())) { CheckFailed("gc.relocate: vector relocates to vector and pointer to pointer" , Call); return; } } while (false) | |||
4492 | "gc.relocate: vector relocates to vector and pointer to pointer",do { if (!(ResultType->isVectorTy() == DerivedType->isVectorTy ())) { CheckFailed("gc.relocate: vector relocates to vector and pointer to pointer" , Call); return; } } while (false) | |||
4493 | Call)do { if (!(ResultType->isVectorTy() == DerivedType->isVectorTy ())) { CheckFailed("gc.relocate: vector relocates to vector and pointer to pointer" , Call); return; } } while (false); | |||
4494 | Assert(do { if (!(ResultType->getPointerAddressSpace() == DerivedType ->getPointerAddressSpace())) { CheckFailed("gc.relocate: relocating a pointer shouldn't change its address space" , Call); return; } } while (false) | |||
4495 | ResultType->getPointerAddressSpace() ==do { if (!(ResultType->getPointerAddressSpace() == DerivedType ->getPointerAddressSpace())) { CheckFailed("gc.relocate: relocating a pointer shouldn't change its address space" , Call); return; } } while (false) | |||
4496 | DerivedType->getPointerAddressSpace(),do { if (!(ResultType->getPointerAddressSpace() == DerivedType ->getPointerAddressSpace())) { CheckFailed("gc.relocate: relocating a pointer shouldn't change its address space" , Call); return; } } while (false) | |||
4497 | "gc.relocate: relocating a pointer shouldn't change its address space",do { if (!(ResultType->getPointerAddressSpace() == DerivedType ->getPointerAddressSpace())) { CheckFailed("gc.relocate: relocating a pointer shouldn't change its address space" , Call); return; } } while (false) | |||
4498 | Call)do { if (!(ResultType->getPointerAddressSpace() == DerivedType ->getPointerAddressSpace())) { CheckFailed("gc.relocate: relocating a pointer shouldn't change its address space" , Call); return; } } while (false); | |||
4499 | break; | |||
4500 | } | |||
4501 | case Intrinsic::eh_exceptioncode: | |||
4502 | case Intrinsic::eh_exceptionpointer: { | |||
4503 | Assert(isa<CatchPadInst>(Call.getArgOperand(0)),do { if (!(isa<CatchPadInst>(Call.getArgOperand(0)))) { CheckFailed("eh.exceptionpointer argument must be a catchpad" , Call); return; } } while (false) | |||
4504 | "eh.exceptionpointer argument must be a catchpad", Call)do { if (!(isa<CatchPadInst>(Call.getArgOperand(0)))) { CheckFailed("eh.exceptionpointer argument must be a catchpad" , Call); return; } } while (false); | |||
4505 | break; | |||
4506 | } | |||
4507 | case Intrinsic::masked_load: { | |||
4508 | Assert(Call.getType()->isVectorTy(), "masked_load: must return a vector",do { if (!(Call.getType()->isVectorTy())) { CheckFailed("masked_load: must return a vector" , Call); return; } } while (false) | |||
4509 | Call)do { if (!(Call.getType()->isVectorTy())) { CheckFailed("masked_load: must return a vector" , Call); return; } } while (false); | |||
4510 | ||||
4511 | Value *Ptr = Call.getArgOperand(0); | |||
4512 | ConstantInt *Alignment = cast<ConstantInt>(Call.getArgOperand(1)); | |||
4513 | Value *Mask = Call.getArgOperand(2); | |||
4514 | Value *PassThru = Call.getArgOperand(3); | |||
4515 | Assert(Mask->getType()->isVectorTy(), "masked_load: mask must be vector",do { if (!(Mask->getType()->isVectorTy())) { CheckFailed ("masked_load: mask must be vector", Call); return; } } while (false) | |||
4516 | Call)do { if (!(Mask->getType()->isVectorTy())) { CheckFailed ("masked_load: mask must be vector", Call); return; } } while (false); | |||
4517 | Assert(Alignment->getValue().isPowerOf2(),do { if (!(Alignment->getValue().isPowerOf2())) { CheckFailed ("masked_load: alignment must be a power of 2", Call); return ; } } while (false) | |||
4518 | "masked_load: alignment must be a power of 2", Call)do { if (!(Alignment->getValue().isPowerOf2())) { CheckFailed ("masked_load: alignment must be a power of 2", Call); return ; } } while (false); | |||
4519 | ||||
4520 | // DataTy is the overloaded type | |||
4521 | Type *DataTy = cast<PointerType>(Ptr->getType())->getElementType(); | |||
4522 | Assert(DataTy == Call.getType(),do { if (!(DataTy == Call.getType())) { CheckFailed("masked_load: return must match pointer type" , Call); return; } } while (false) | |||
4523 | "masked_load: return must match pointer type", Call)do { if (!(DataTy == Call.getType())) { CheckFailed("masked_load: return must match pointer type" , Call); return; } } while (false); | |||
4524 | Assert(PassThru->getType() == DataTy,do { if (!(PassThru->getType() == DataTy)) { CheckFailed("masked_load: pass through and data type must match" , Call); return; } } while (false) | |||
4525 | "masked_load: pass through and data type must match", Call)do { if (!(PassThru->getType() == DataTy)) { CheckFailed("masked_load: pass through and data type must match" , Call); return; } } while (false); | |||
4526 | Assert(Mask->getType()->getVectorNumElements() ==do { if (!(Mask->getType()->getVectorNumElements() == DataTy ->getVectorNumElements())) { CheckFailed("masked_load: vector mask must be same length as data" , Call); return; } } while (false) | |||
4527 | DataTy->getVectorNumElements(),do { if (!(Mask->getType()->getVectorNumElements() == DataTy ->getVectorNumElements())) { CheckFailed("masked_load: vector mask must be same length as data" , Call); return; } } while (false) | |||
4528 | "masked_load: vector mask must be same length as data", Call)do { if (!(Mask->getType()->getVectorNumElements() == DataTy ->getVectorNumElements())) { CheckFailed("masked_load: vector mask must be same length as data" , Call); return; } } while (false); | |||
4529 | break; | |||
4530 | } | |||
4531 | case Intrinsic::masked_store: { | |||
4532 | Value *Val = Call.getArgOperand(0); | |||
4533 | Value *Ptr = Call.getArgOperand(1); | |||
4534 | ConstantInt *Alignment = cast<ConstantInt>(Call.getArgOperand(2)); | |||
4535 | Value *Mask = Call.getArgOperand(3); | |||
4536 | Assert(Mask->getType()->isVectorTy(), "masked_store: mask must be vector",do { if (!(Mask->getType()->isVectorTy())) { CheckFailed ("masked_store: mask must be vector", Call); return; } } while (false) | |||
4537 | Call)do { if (!(Mask->getType()->isVectorTy())) { CheckFailed ("masked_store: mask must be vector", Call); return; } } while (false); | |||
4538 | Assert(Alignment->getValue().isPowerOf2(),do { if (!(Alignment->getValue().isPowerOf2())) { CheckFailed ("masked_store: alignment must be a power of 2", Call); return ; } } while (false) | |||
4539 | "masked_store: alignment must be a power of 2", Call)do { if (!(Alignment->getValue().isPowerOf2())) { CheckFailed ("masked_store: alignment must be a power of 2", Call); return ; } } while (false); | |||
4540 | ||||
4541 | // DataTy is the overloaded type | |||
4542 | Type *DataTy = cast<PointerType>(Ptr->getType())->getElementType(); | |||
4543 | Assert(DataTy == Val->getType(),do { if (!(DataTy == Val->getType())) { CheckFailed("masked_store: storee must match pointer type" , Call); return; } } while (false) | |||
4544 | "masked_store: storee must match pointer type", Call)do { if (!(DataTy == Val->getType())) { CheckFailed("masked_store: storee must match pointer type" , Call); return; } } while (false); | |||
4545 | Assert(Mask->getType()->getVectorNumElements() ==do { if (!(Mask->getType()->getVectorNumElements() == DataTy ->getVectorNumElements())) { CheckFailed("masked_store: vector mask must be same length as data" , Call); return; } } while (false) | |||
4546 | DataTy->getVectorNumElements(),do { if (!(Mask->getType()->getVectorNumElements() == DataTy ->getVectorNumElements())) { CheckFailed("masked_store: vector mask must be same length as data" , Call); return; } } while (false) | |||
4547 | "masked_store: vector mask must be same length as data", Call)do { if (!(Mask->getType()->getVectorNumElements() == DataTy ->getVectorNumElements())) { CheckFailed("masked_store: vector mask must be same length as data" , Call); return; } } while (false); | |||
4548 | break; | |||
4549 | } | |||
4550 | ||||
4551 | case Intrinsic::experimental_guard: { | |||
4552 | Assert(isa<CallInst>(Call), "experimental_guard cannot be invoked", Call)do { if (!(isa<CallInst>(Call))) { CheckFailed("experimental_guard cannot be invoked" , Call); return; } } while (false); | |||
4553 | Assert(Call.countOperandBundlesOfType(LLVMContext::OB_deopt) == 1,do { if (!(Call.countOperandBundlesOfType(LLVMContext::OB_deopt ) == 1)) { CheckFailed("experimental_guard must have exactly one " "\"deopt\" operand bundle"); return; } } while (false) | |||
4554 | "experimental_guard must have exactly one "do { if (!(Call.countOperandBundlesOfType(LLVMContext::OB_deopt ) == 1)) { CheckFailed("experimental_guard must have exactly one " "\"deopt\" operand bundle"); return; } } while (false) | |||
4555 | "\"deopt\" operand bundle")do { if (!(Call.countOperandBundlesOfType(LLVMContext::OB_deopt ) == 1)) { CheckFailed("experimental_guard must have exactly one " "\"deopt\" operand bundle"); return; } } while (false); | |||
4556 | break; | |||
4557 | } | |||
4558 | ||||
4559 | case Intrinsic::experimental_deoptimize: { | |||
4560 | Assert(isa<CallInst>(Call), "experimental_deoptimize cannot be invoked",do { if (!(isa<CallInst>(Call))) { CheckFailed("experimental_deoptimize cannot be invoked" , Call); return; } } while (false) | |||
4561 | Call)do { if (!(isa<CallInst>(Call))) { CheckFailed("experimental_deoptimize cannot be invoked" , Call); return; } } while (false); | |||
4562 | Assert(Call.countOperandBundlesOfType(LLVMContext::OB_deopt) == 1,do { if (!(Call.countOperandBundlesOfType(LLVMContext::OB_deopt ) == 1)) { CheckFailed("experimental_deoptimize must have exactly one " "\"deopt\" operand bundle"); return; } } while (false) | |||
4563 | "experimental_deoptimize must have exactly one "do { if (!(Call.countOperandBundlesOfType(LLVMContext::OB_deopt ) == 1)) { CheckFailed("experimental_deoptimize must have exactly one " "\"deopt\" operand bundle"); return; } } while (false) | |||
4564 | "\"deopt\" operand bundle")do { if (!(Call.countOperandBundlesOfType(LLVMContext::OB_deopt ) == 1)) { CheckFailed("experimental_deoptimize must have exactly one " "\"deopt\" operand bundle"); return; } } while (false); | |||
4565 | Assert(Call.getType() == Call.getFunction()->getReturnType(),do { if (!(Call.getType() == Call.getFunction()->getReturnType ())) { CheckFailed("experimental_deoptimize return type must match caller return type" ); return; } } while (false) | |||
4566 | "experimental_deoptimize return type must match caller return type")do { if (!(Call.getType() == Call.getFunction()->getReturnType ())) { CheckFailed("experimental_deoptimize return type must match caller return type" ); return; } } while (false); | |||
4567 | ||||
4568 | if (isa<CallInst>(Call)) { | |||
4569 | auto *RI = dyn_cast<ReturnInst>(Call.getNextNode()); | |||
4570 | Assert(RI,do { if (!(RI)) { CheckFailed("calls to experimental_deoptimize must be followed by a return" ); return; } } while (false) | |||
4571 | "calls to experimental_deoptimize must be followed by a return")do { if (!(RI)) { CheckFailed("calls to experimental_deoptimize must be followed by a return" ); return; } } while (false); | |||
4572 | ||||
4573 | if (!Call.getType()->isVoidTy() && RI) | |||
4574 | Assert(RI->getReturnValue() == &Call,do { if (!(RI->getReturnValue() == &Call)) { CheckFailed ("calls to experimental_deoptimize must be followed by a return " "of the value computed by experimental_deoptimize"); return; } } while (false) | |||
4575 | "calls to experimental_deoptimize must be followed by a return "do { if (!(RI->getReturnValue() == &Call)) { CheckFailed ("calls to experimental_deoptimize must be followed by a return " "of the value computed by experimental_deoptimize"); return; } } while (false) | |||
4576 | "of the value computed by experimental_deoptimize")do { if (!(RI->getReturnValue() == &Call)) { CheckFailed ("calls to experimental_deoptimize must be followed by a return " "of the value computed by experimental_deoptimize"); return; } } while (false); | |||
4577 | } | |||
4578 | ||||
4579 | break; | |||
4580 | } | |||
4581 | case Intrinsic::sadd_sat: | |||
4582 | case Intrinsic::uadd_sat: | |||
4583 | case Intrinsic::ssub_sat: | |||
4584 | case Intrinsic::usub_sat: { | |||
4585 | Value *Op1 = Call.getArgOperand(0); | |||
4586 | Value *Op2 = Call.getArgOperand(1); | |||
4587 | Assert(Op1->getType()->isIntOrIntVectorTy(),do { if (!(Op1->getType()->isIntOrIntVectorTy())) { CheckFailed ("first operand of [us][add|sub]_sat must be an int type or vector " "of ints"); return; } } while (false) | |||
4588 | "first operand of [us][add|sub]_sat must be an int type or vector "do { if (!(Op1->getType()->isIntOrIntVectorTy())) { CheckFailed ("first operand of [us][add|sub]_sat must be an int type or vector " "of ints"); return; } } while (false) | |||
4589 | "of ints")do { if (!(Op1->getType()->isIntOrIntVectorTy())) { CheckFailed ("first operand of [us][add|sub]_sat must be an int type or vector " "of ints"); return; } } while (false); | |||
4590 | Assert(Op2->getType()->isIntOrIntVectorTy(),do { if (!(Op2->getType()->isIntOrIntVectorTy())) { CheckFailed ("second operand of [us][add|sub]_sat must be an int type or vector " "of ints"); return; } } while (false) | |||
4591 | "second operand of [us][add|sub]_sat must be an int type or vector "do { if (!(Op2->getType()->isIntOrIntVectorTy())) { CheckFailed ("second operand of [us][add|sub]_sat must be an int type or vector " "of ints"); return; } } while (false) | |||
4592 | "of ints")do { if (!(Op2->getType()->isIntOrIntVectorTy())) { CheckFailed ("second operand of [us][add|sub]_sat must be an int type or vector " "of ints"); return; } } while (false); | |||
4593 | break; | |||
4594 | } | |||
4595 | case Intrinsic::smul_fix: | |||
4596 | case Intrinsic::umul_fix: { | |||
4597 | Value *Op1 = Call.getArgOperand(0); | |||
4598 | Value *Op2 = Call.getArgOperand(1); | |||
4599 | Assert(Op1->getType()->isIntOrIntVectorTy(),do { if (!(Op1->getType()->isIntOrIntVectorTy())) { CheckFailed ("first operand of [us]mul_fix must be an int type or vector " "of ints"); return; } } while (false) | |||
4600 | "first operand of [us]mul_fix must be an int type or vector "do { if (!(Op1->getType()->isIntOrIntVectorTy())) { CheckFailed ("first operand of [us]mul_fix must be an int type or vector " "of ints"); return; } } while (false) | |||
4601 | "of ints")do { if (!(Op1->getType()->isIntOrIntVectorTy())) { CheckFailed ("first operand of [us]mul_fix must be an int type or vector " "of ints"); return; } } while (false); | |||
4602 | Assert(Op2->getType()->isIntOrIntVectorTy(),do { if (!(Op2->getType()->isIntOrIntVectorTy())) { CheckFailed ("second operand of [us]mul_fix must be an int type or vector " "of ints"); return; } } while (false) | |||
4603 | "second operand of [us]mul_fix must be an int type or vector "do { if (!(Op2->getType()->isIntOrIntVectorTy())) { CheckFailed ("second operand of [us]mul_fix must be an int type or vector " "of ints"); return; } } while (false) | |||
4604 | "of ints")do { if (!(Op2->getType()->isIntOrIntVectorTy())) { CheckFailed ("second operand of [us]mul_fix must be an int type or vector " "of ints"); return; } } while (false); | |||
4605 | ||||
4606 | auto *Op3 = cast<ConstantInt>(Call.getArgOperand(2)); | |||
4607 | Assert(Op3->getType()->getBitWidth() <= 32,do { if (!(Op3->getType()->getBitWidth() <= 32)) { CheckFailed ("third argument of [us]mul_fix must fit within 32 bits"); return ; } } while (false) | |||
4608 | "third argument of [us]mul_fix must fit within 32 bits")do { if (!(Op3->getType()->getBitWidth() <= 32)) { CheckFailed ("third argument of [us]mul_fix must fit within 32 bits"); return ; } } while (false); | |||
4609 | ||||
4610 | if (ID == Intrinsic::smul_fix) { | |||
4611 | Assert(do { if (!(Op3->getZExtValue() < Op1->getType()-> getScalarSizeInBits())) { CheckFailed("the scale of smul_fix must be less than the width of the operands" ); return; } } while (false) | |||
4612 | Op3->getZExtValue() < Op1->getType()->getScalarSizeInBits(),do { if (!(Op3->getZExtValue() < Op1->getType()-> getScalarSizeInBits())) { CheckFailed("the scale of smul_fix must be less than the width of the operands" ); return; } } while (false) | |||
4613 | "the scale of smul_fix must be less than the width of the operands")do { if (!(Op3->getZExtValue() < Op1->getType()-> getScalarSizeInBits())) { CheckFailed("the scale of smul_fix must be less than the width of the operands" ); return; } } while (false); | |||
4614 | } else { | |||
4615 | Assert(Op3->getZExtValue() <= Op1->getType()->getScalarSizeInBits(),do { if (!(Op3->getZExtValue() <= Op1->getType()-> getScalarSizeInBits())) { CheckFailed("the scale of umul_fix must be less than or equal to the width of " "the operands"); return; } } while (false) | |||
4616 | "the scale of umul_fix must be less than or equal to the width of "do { if (!(Op3->getZExtValue() <= Op1->getType()-> getScalarSizeInBits())) { CheckFailed("the scale of umul_fix must be less than or equal to the width of " "the operands"); return; } } while (false) | |||
4617 | "the operands")do { if (!(Op3->getZExtValue() <= Op1->getType()-> getScalarSizeInBits())) { CheckFailed("the scale of umul_fix must be less than or equal to the width of " "the operands"); return; } } while (false); | |||
4618 | } | |||
4619 | break; | |||
4620 | } | |||
4621 | }; | |||
4622 | } | |||
4623 | ||||
4624 | /// Carefully grab the subprogram from a local scope. | |||
4625 | /// | |||
4626 | /// This carefully grabs the subprogram from a local scope, avoiding the | |||
4627 | /// built-in assertions that would typically fire. | |||
4628 | static DISubprogram *getSubprogram(Metadata *LocalScope) { | |||
4629 | if (!LocalScope) | |||
4630 | return nullptr; | |||
4631 | ||||
4632 | if (auto *SP = dyn_cast<DISubprogram>(LocalScope)) | |||
4633 | return SP; | |||
4634 | ||||
4635 | if (auto *LB = dyn_cast<DILexicalBlockBase>(LocalScope)) | |||
4636 | return getSubprogram(LB->getRawScope()); | |||
4637 | ||||
4638 | // Just return null; broken scope chains are checked elsewhere. | |||
4639 | assert(!isa<DILocalScope>(LocalScope) && "Unknown type of local scope")((!isa<DILocalScope>(LocalScope) && "Unknown type of local scope" ) ? static_cast<void> (0) : __assert_fail ("!isa<DILocalScope>(LocalScope) && \"Unknown type of local scope\"" , "/build/llvm-toolchain-snapshot-9~svn360410/lib/IR/Verifier.cpp" , 4639, __PRETTY_FUNCTION__)); | |||
4640 | return nullptr; | |||
4641 | } | |||
4642 | ||||
4643 | void Verifier::visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI) { | |||
4644 | unsigned NumOperands = FPI.getNumArgOperands(); | |||
4645 | bool HasExceptionMD = false; | |||
4646 | bool HasRoundingMD = false; | |||
4647 | switch (FPI.getIntrinsicID()) { | |||
4648 | case Intrinsic::experimental_constrained_sqrt: | |||
4649 | case Intrinsic::experimental_constrained_sin: | |||
4650 | case Intrinsic::experimental_constrained_cos: | |||
4651 | case Intrinsic::experimental_constrained_exp: | |||
4652 | case Intrinsic::experimental_constrained_exp2: | |||
4653 | case Intrinsic::experimental_constrained_log: | |||
4654 | case Intrinsic::experimental_constrained_log10: | |||
4655 | case Intrinsic::experimental_constrained_log2: | |||
4656 | case Intrinsic::experimental_constrained_rint: | |||
4657 | case Intrinsic::experimental_constrained_nearbyint: | |||
4658 | case Intrinsic::experimental_constrained_ceil: | |||
4659 | case Intrinsic::experimental_constrained_floor: | |||
4660 | case Intrinsic::experimental_constrained_round: | |||
4661 | case Intrinsic::experimental_constrained_trunc: | |||
4662 | Assert((NumOperands == 3), "invalid arguments for constrained FP intrinsic",do { if (!((NumOperands == 3))) { CheckFailed("invalid arguments for constrained FP intrinsic" , &FPI); return; } } while (false) | |||
4663 | &FPI)do { if (!((NumOperands == 3))) { CheckFailed("invalid arguments for constrained FP intrinsic" , &FPI); return; } } while (false); | |||
4664 | HasExceptionMD = true; | |||
4665 | HasRoundingMD = true; | |||
4666 | break; | |||
4667 | ||||
4668 | case Intrinsic::experimental_constrained_fma: | |||
4669 | Assert((NumOperands == 5), "invalid arguments for constrained FP intrinsic",do { if (!((NumOperands == 5))) { CheckFailed("invalid arguments for constrained FP intrinsic" , &FPI); return; } } while (false) | |||
4670 | &FPI)do { if (!((NumOperands == 5))) { CheckFailed("invalid arguments for constrained FP intrinsic" , &FPI); return; } } while (false); | |||
4671 | HasExceptionMD = true; | |||
4672 | HasRoundingMD = true; | |||
4673 | break; | |||
4674 | ||||
4675 | case Intrinsic::experimental_constrained_fadd: | |||
4676 | case Intrinsic::experimental_constrained_fsub: | |||
4677 | case Intrinsic::experimental_constrained_fmul: | |||
4678 | case Intrinsic::experimental_constrained_fdiv: | |||
4679 | case Intrinsic::experimental_constrained_frem: | |||
4680 | case Intrinsic::experimental_constrained_pow: | |||
4681 | case Intrinsic::experimental_constrained_powi: | |||
4682 | case Intrinsic::experimental_constrained_maxnum: | |||
4683 | case Intrinsic::experimental_constrained_minnum: | |||
4684 | Assert((NumOperands == 4), "invalid arguments for constrained FP intrinsic",do { if (!((NumOperands == 4))) { CheckFailed("invalid arguments for constrained FP intrinsic" , &FPI); return; } } while (false) | |||
4685 | &FPI)do { if (!((NumOperands == 4))) { CheckFailed("invalid arguments for constrained FP intrinsic" , &FPI); return; } } while (false); | |||
4686 | HasExceptionMD = true; | |||
4687 | HasRoundingMD = true; | |||
4688 | break; | |||
4689 | ||||
4690 | default: | |||
4691 | llvm_unreachable("Invalid constrained FP intrinsic!")::llvm::llvm_unreachable_internal("Invalid constrained FP intrinsic!" , "/build/llvm-toolchain-snapshot-9~svn360410/lib/IR/Verifier.cpp" , 4691); | |||
4692 | } | |||
4693 | ||||
4694 | // If a non-metadata argument is passed in a metadata slot then the | |||
4695 | // error will be caught earlier when the incorrect argument doesn't | |||
4696 | // match the specification in the intrinsic call table. Thus, no | |||
4697 | // argument type check is needed here. | |||
4698 | ||||
4699 | if (HasExceptionMD) { | |||
4700 | Assert(FPI.getExceptionBehavior() != ConstrainedFPIntrinsic::ebInvalid,do { if (!(FPI.getExceptionBehavior() != ConstrainedFPIntrinsic ::ebInvalid)) { CheckFailed("invalid exception behavior argument" , &FPI); return; } } while (false) | |||
4701 | "invalid exception behavior argument", &FPI)do { if (!(FPI.getExceptionBehavior() != ConstrainedFPIntrinsic ::ebInvalid)) { CheckFailed("invalid exception behavior argument" , &FPI); return; } } while (false); | |||
4702 | } | |||
4703 | if (HasRoundingMD) { | |||
4704 | Assert(FPI.getRoundingMode() != ConstrainedFPIntrinsic::rmInvalid,do { if (!(FPI.getRoundingMode() != ConstrainedFPIntrinsic::rmInvalid )) { CheckFailed("invalid rounding mode argument", &FPI); return; } } while (false) | |||
4705 | "invalid rounding mode argument", &FPI)do { if (!(FPI.getRoundingMode() != ConstrainedFPIntrinsic::rmInvalid )) { CheckFailed("invalid rounding mode argument", &FPI); return; } } while (false); | |||
4706 | } | |||
4707 | } | |||
4708 | ||||
4709 | void Verifier::visitDbgIntrinsic(StringRef Kind, DbgVariableIntrinsic &DII) { | |||
4710 | auto *MD = cast<MetadataAsValue>(DII.getArgOperand(0))->getMetadata(); | |||
4711 | AssertDI(isa<ValueAsMetadata>(MD) ||do { if (!(isa<ValueAsMetadata>(MD) || (isa<MDNode> (MD) && !cast<MDNode>(MD)->getNumOperands()) )) { DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic address/value" , &DII, MD); return; } } while (false) | |||
4712 | (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands()),do { if (!(isa<ValueAsMetadata>(MD) || (isa<MDNode> (MD) && !cast<MDNode>(MD)->getNumOperands()) )) { DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic address/value" , &DII, MD); return; } } while (false) | |||
4713 | "invalid llvm.dbg." + Kind + " intrinsic address/value", &DII, MD)do { if (!(isa<ValueAsMetadata>(MD) || (isa<MDNode> (MD) && !cast<MDNode>(MD)->getNumOperands()) )) { DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic address/value" , &DII, MD); return; } } while (false); | |||
4714 | AssertDI(isa<DILocalVariable>(DII.getRawVariable()),do { if (!(isa<DILocalVariable>(DII.getRawVariable()))) { DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic variable" , &DII, DII.getRawVariable()); return; } } while (false) | |||
4715 | "invalid llvm.dbg." + Kind + " intrinsic variable", &DII,do { if (!(isa<DILocalVariable>(DII.getRawVariable()))) { DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic variable" , &DII, DII.getRawVariable()); return; } } while (false) | |||
4716 | DII.getRawVariable())do { if (!(isa<DILocalVariable>(DII.getRawVariable()))) { DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic variable" , &DII, DII.getRawVariable()); return; } } while (false); | |||
4717 | AssertDI(isa<DIExpression>(DII.getRawExpression()),do { if (!(isa<DIExpression>(DII.getRawExpression()))) { DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic expression" , &DII, DII.getRawExpression()); return; } } while (false ) | |||
4718 | "invalid llvm.dbg." + Kind + " intrinsic expression", &DII,do { if (!(isa<DIExpression>(DII.getRawExpression()))) { DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic expression" , &DII, DII.getRawExpression()); return; } } while (false ) | |||
4719 | DII.getRawExpression())do { if (!(isa<DIExpression>(DII.getRawExpression()))) { DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic expression" , &DII, DII.getRawExpression()); return; } } while (false ); | |||
4720 | ||||
4721 | // Ignore broken !dbg attachments; they're checked elsewhere. | |||
4722 | if (MDNode *N = DII.getDebugLoc().getAsMDNode()) | |||
4723 | if (!isa<DILocation>(N)) | |||
4724 | return; | |||
4725 | ||||
4726 | BasicBlock *BB = DII.getParent(); | |||
4727 | Function *F = BB ? BB->getParent() : nullptr; | |||
4728 | ||||
4729 | // The scopes for variables and !dbg attachments must agree. | |||
4730 | DILocalVariable *Var = DII.getVariable(); | |||
4731 | DILocation *Loc = DII.getDebugLoc(); | |||
4732 | AssertDI(Loc, "llvm.dbg." + Kind + " intrinsic requires a !dbg attachment",do { if (!(Loc)) { DebugInfoCheckFailed("llvm.dbg." + Kind + " intrinsic requires a !dbg attachment" , &DII, BB, F); return; } } while (false) | |||
4733 | &DII, BB, F)do { if (!(Loc)) { DebugInfoCheckFailed("llvm.dbg." + Kind + " intrinsic requires a !dbg attachment" , &DII, BB, F); return; } } while (false); | |||
4734 | ||||
4735 | DISubprogram *VarSP = getSubprogram(Var->getRawScope()); | |||
4736 | DISubprogram *LocSP = getSubprogram(Loc->getRawScope()); | |||
4737 | if (!VarSP || !LocSP) | |||
4738 | return; // Broken scope chains are checked elsewhere. | |||
4739 | ||||
4740 | AssertDI(VarSP == LocSP, "mismatched subprogram between llvm.dbg." + Kind +do { if (!(VarSP == LocSP)) { DebugInfoCheckFailed("mismatched subprogram between llvm.dbg." + Kind + " variable and !dbg attachment", &DII, BB, F, Var , Var->getScope()->getSubprogram(), Loc, Loc->getScope ()->getSubprogram()); return; } } while (false) | |||
4741 | " variable and !dbg attachment",do { if (!(VarSP == LocSP)) { DebugInfoCheckFailed("mismatched subprogram between llvm.dbg." + Kind + " variable and !dbg attachment", &DII, BB, F, Var , Var->getScope()->getSubprogram(), Loc, Loc->getScope ()->getSubprogram()); return; } } while (false) | |||
4742 | &DII, BB, F, Var, Var->getScope()->getSubprogram(), Loc,do { if (!(VarSP == LocSP)) { DebugInfoCheckFailed("mismatched subprogram between llvm.dbg." + Kind + " variable and !dbg attachment", &DII, BB, F, Var , Var->getScope()->getSubprogram(), Loc, Loc->getScope ()->getSubprogram()); return; } } while (false) | |||
4743 | Loc->getScope()->getSubprogram())do { if (!(VarSP == LocSP)) { DebugInfoCheckFailed("mismatched subprogram between llvm.dbg." + Kind + " variable and !dbg attachment", &DII, BB, F, Var , Var->getScope()->getSubprogram(), Loc, Loc->getScope ()->getSubprogram()); return; } } while (false); | |||
4744 | ||||
4745 | // This check is redundant with one in visitLocalVariable(). | |||
4746 | AssertDI(isType(Var->getRawType()), "invalid type ref", Var,do { if (!(isType(Var->getRawType()))) { DebugInfoCheckFailed ("invalid type ref", Var, Var->getRawType()); return; } } while (false) | |||
4747 | Var->getRawType())do { if (!(isType(Var->getRawType()))) { DebugInfoCheckFailed ("invalid type ref", Var, Var->getRawType()); return; } } while (false); | |||
4748 | if (auto *Type = dyn_cast_or_null<DIType>(Var->getRawType())) | |||
4749 | if (Type->isBlockByrefStruct()) | |||
4750 | AssertDI(DII.getExpression() && DII.getExpression()->getNumElements(),do { if (!(DII.getExpression() && DII.getExpression() ->getNumElements())) { DebugInfoCheckFailed("BlockByRef variable without complex expression" , Var, &DII); return; } } while (false) | |||
4751 | "BlockByRef variable without complex expression", Var, &DII)do { if (!(DII.getExpression() && DII.getExpression() ->getNumElements())) { DebugInfoCheckFailed("BlockByRef variable without complex expression" , Var, &DII); return; } } while (false); | |||
4752 | ||||
4753 | verifyFnArgs(DII); | |||
4754 | } | |||
4755 | ||||
4756 | void Verifier::visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI) { | |||
4757 | AssertDI(isa<DILabel>(DLI.getRawLabel()),do { if (!(isa<DILabel>(DLI.getRawLabel()))) { DebugInfoCheckFailed ("invalid llvm.dbg." + Kind + " intrinsic variable", &DLI , DLI.getRawLabel()); return; } } while (false) | |||
4758 | "invalid llvm.dbg." + Kind + " intrinsic variable", &DLI,do { if (!(isa<DILabel>(DLI.getRawLabel()))) { DebugInfoCheckFailed ("invalid llvm.dbg." + Kind + " intrinsic variable", &DLI , DLI.getRawLabel()); return; } } while (false) | |||
4759 | DLI.getRawLabel())do { if (!(isa<DILabel>(DLI.getRawLabel()))) { DebugInfoCheckFailed ("invalid llvm.dbg." + Kind + " intrinsic variable", &DLI , DLI.getRawLabel()); return; } } while (false); | |||
4760 | ||||
4761 | // Ignore broken !dbg attachments; they're checked elsewhere. | |||
4762 | if (MDNode *N = DLI.getDebugLoc().getAsMDNode()) | |||
4763 | if (!isa<DILocation>(N)) | |||
4764 | return; | |||
4765 | ||||
4766 | BasicBlock *BB = DLI.getParent(); | |||
4767 | Function *F = BB ? BB->getParent() : nullptr; | |||
4768 | ||||
4769 | // The scopes for variables and !dbg attachments must agree. | |||
4770 | DILabel *Label = DLI.getLabel(); | |||
4771 | DILocation *Loc = DLI.getDebugLoc(); | |||
4772 | Assert(Loc, "llvm.dbg." + Kind + " intrinsic requires a !dbg attachment",do { if (!(Loc)) { CheckFailed("llvm.dbg." + Kind + " intrinsic requires a !dbg attachment" , &DLI, BB, F); return; } } while (false) | |||
4773 | &DLI, BB, F)do { if (!(Loc)) { CheckFailed("llvm.dbg." + Kind + " intrinsic requires a !dbg attachment" , &DLI, BB, F); return; } } while (false); | |||
4774 | ||||
4775 | DISubprogram *LabelSP = getSubprogram(Label->getRawScope()); | |||
4776 | DISubprogram *LocSP = getSubprogram(Loc->getRawScope()); | |||
4777 | if (!LabelSP || !LocSP) | |||
4778 | return; | |||
4779 | ||||
4780 | AssertDI(LabelSP == LocSP, "mismatched subprogram between llvm.dbg." + Kind +do { if (!(LabelSP == LocSP)) { DebugInfoCheckFailed("mismatched subprogram between llvm.dbg." + Kind + " label and !dbg attachment", &DLI, BB, F, Label , Label->getScope()->getSubprogram(), Loc, Loc->getScope ()->getSubprogram()); return; } } while (false) | |||
4781 | " label and !dbg attachment",do { if (!(LabelSP == LocSP)) { DebugInfoCheckFailed("mismatched subprogram between llvm.dbg." + Kind + " label and !dbg attachment", &DLI, BB, F, Label , Label->getScope()->getSubprogram(), Loc, Loc->getScope ()->getSubprogram()); return; } } while (false) | |||
4782 | &DLI, BB, F, Label, Label->getScope()->getSubprogram(), Loc,do { if (!(LabelSP == LocSP)) { DebugInfoCheckFailed("mismatched subprogram between llvm.dbg." + Kind + " label and !dbg attachment", &DLI, BB, F, Label , Label->getScope()->getSubprogram(), Loc, Loc->getScope ()->getSubprogram()); return; } } while (false) | |||
4783 | Loc->getScope()->getSubprogram())do { if (!(LabelSP == LocSP)) { DebugInfoCheckFailed("mismatched subprogram between llvm.dbg." + Kind + " label and !dbg attachment", &DLI, BB, F, Label , Label->getScope()->getSubprogram(), Loc, Loc->getScope ()->getSubprogram()); return; } } while (false); | |||
4784 | } | |||
4785 | ||||
4786 | void Verifier::verifyFragmentExpression(const DbgVariableIntrinsic &I) { | |||
4787 | DILocalVariable *V = dyn_cast_or_null<DILocalVariable>(I.getRawVariable()); | |||
4788 | DIExpression *E = dyn_cast_or_null<DIExpression>(I.getRawExpression()); | |||
4789 | ||||
4790 | // We don't know whether this intrinsic verified correctly. | |||
4791 | if (!V || !E || !E->isValid()) | |||
4792 | return; | |||
4793 | ||||
4794 | // Nothing to do if this isn't a DW_OP_LLVM_fragment expression. | |||
4795 | auto Fragment = E->getFragmentInfo(); | |||
4796 | if (!Fragment) | |||
4797 | return; | |||
4798 | ||||
4799 | // The frontend helps out GDB by emitting the members of local anonymous | |||
4800 | // unions as artificial local variables with shared storage. When SROA splits | |||
4801 | // the storage for artificial local variables that are smaller than the entire | |||
4802 | // union, the overhang piece will be outside of the allotted space for the | |||
4803 | // variable and this check fails. | |||
4804 | // FIXME: Remove this check as soon as clang stops doing this; it hides bugs. | |||
4805 | if (V->isArtificial()) | |||
4806 | return; | |||
4807 | ||||
4808 | verifyFragmentExpression(*V, *Fragment, &I); | |||
4809 | } | |||
4810 | ||||
4811 | template <typename ValueOrMetadata> | |||
4812 | void Verifier::verifyFragmentExpression(const DIVariable &V, | |||
4813 | DIExpression::FragmentInfo Fragment, | |||
4814 | ValueOrMetadata *Desc) { | |||
4815 | // If there's no size, the type is broken, but that should be checked | |||
4816 | // elsewhere. | |||
4817 | auto VarSize = V.getSizeInBits(); | |||
4818 | if (!VarSize) | |||
4819 | return; | |||
4820 | ||||
4821 | unsigned FragSize = Fragment.SizeInBits; | |||
4822 | unsigned FragOffset = Fragment.OffsetInBits; | |||
4823 | AssertDI(FragSize + FragOffset <= *VarSize,do { if (!(FragSize + FragOffset <= *VarSize)) { DebugInfoCheckFailed ("fragment is larger than or outside of variable", Desc, & V); return; } } while (false) | |||
4824 | "fragment is larger than or outside of variable", Desc, &V)do { if (!(FragSize + FragOffset <= *VarSize)) { DebugInfoCheckFailed ("fragment is larger than or outside of variable", Desc, & V); return; } } while (false); | |||
4825 | AssertDI(FragSize != *VarSize, "fragment covers entire variable", Desc, &V)do { if (!(FragSize != *VarSize)) { DebugInfoCheckFailed("fragment covers entire variable" , Desc, &V); return; } } while (false); | |||
4826 | } | |||
4827 | ||||
4828 | void Verifier::verifyFnArgs(const DbgVariableIntrinsic &I) { | |||
4829 | // This function does not take the scope of noninlined function arguments into | |||
4830 | // account. Don't run it if current function is nodebug, because it may | |||
4831 | // contain inlined debug intrinsics. | |||
4832 | if (!HasDebugInfo) | |||
4833 | return; | |||
4834 | ||||
4835 | // For performance reasons only check non-inlined ones. | |||
4836 | if (I.getDebugLoc()->getInlinedAt()) | |||
4837 | return; | |||
4838 | ||||
4839 | DILocalVariable *Var = I.getVariable(); | |||
4840 | AssertDI(Var, "dbg intrinsic without variable")do { if (!(Var)) { DebugInfoCheckFailed("dbg intrinsic without variable" ); return; } } while (false); | |||
4841 | ||||
4842 | unsigned ArgNo = Var->getArg(); | |||
4843 | if (!ArgNo) | |||
4844 | return; | |||
4845 | ||||
4846 | // Verify there are no duplicate function argument debug info entries. | |||
4847 | // These will cause hard-to-debug assertions in the DWARF backend. | |||
4848 | if (DebugFnArgs.size() < ArgNo) | |||
4849 | DebugFnArgs.resize(ArgNo, nullptr); | |||
4850 | ||||
4851 | auto *Prev = DebugFnArgs[ArgNo - 1]; | |||
4852 | DebugFnArgs[ArgNo - 1] = Var; | |||
4853 | AssertDI(!Prev || (Prev == Var), "conflicting debug info for argument", &I,do { if (!(!Prev || (Prev == Var))) { DebugInfoCheckFailed("conflicting debug info for argument" , &I, Prev, Var); return; } } while (false) | |||
4854 | Prev, Var)do { if (!(!Prev || (Prev == Var))) { DebugInfoCheckFailed("conflicting debug info for argument" , &I, Prev, Var); return; } } while (false); | |||
4855 | } | |||
4856 | ||||
4857 | void Verifier::verifyCompileUnits() { | |||
4858 | // When more than one Module is imported into the same context, such as during | |||
4859 | // an LTO build before linking the modules, ODR type uniquing may cause types | |||
4860 | // to point to a different CU. This check does not make sense in this case. | |||
4861 | if (M.getContext().isODRUniquingDebugTypes()) | |||
4862 | return; | |||
4863 | auto *CUs = M.getNamedMetadata("llvm.dbg.cu"); | |||
4864 | SmallPtrSet<const Metadata *, 2> Listed; | |||
4865 | if (CUs) | |||
4866 | Listed.insert(CUs->op_begin(), CUs->op_end()); | |||
4867 | for (auto *CU : CUVisited) | |||
4868 | AssertDI(Listed.count(CU), "DICompileUnit not listed in llvm.dbg.cu", CU)do { if (!(Listed.count(CU))) { DebugInfoCheckFailed("DICompileUnit not listed in llvm.dbg.cu" , CU); return; } } while (false); | |||
4869 | CUVisited.clear(); | |||
4870 | } | |||
4871 | ||||
4872 | void Verifier::verifyDeoptimizeCallingConvs() { | |||
4873 | if (DeoptimizeDeclarations.empty()) | |||
4874 | return; | |||
4875 | ||||
4876 | const Function *First = DeoptimizeDeclarations[0]; | |||
4877 | for (auto *F : makeArrayRef(DeoptimizeDeclarations).slice(1)) { | |||
4878 | Assert(First->getCallingConv() == F->getCallingConv(),do { if (!(First->getCallingConv() == F->getCallingConv ())) { CheckFailed("All llvm.experimental.deoptimize declarations must have the same " "calling convention", First, F); return; } } while (false) | |||
4879 | "All llvm.experimental.deoptimize declarations must have the same "do { if (!(First->getCallingConv() == F->getCallingConv ())) { CheckFailed("All llvm.experimental.deoptimize declarations must have the same " "calling convention", First, F); return; } } while (false) | |||
4880 | "calling convention",do { if (!(First->getCallingConv() == F->getCallingConv ())) { CheckFailed("All llvm.experimental.deoptimize declarations must have the same " "calling convention", First, F); return; } } while (false) | |||
4881 | First, F)do { if (!(First->getCallingConv() == F->getCallingConv ())) { CheckFailed("All llvm.experimental.deoptimize declarations must have the same " "calling convention", First, F); return; } } while (false); | |||
4882 | } | |||
4883 | } | |||
4884 | ||||
4885 | void Verifier::verifySourceDebugInfo(const DICompileUnit &U, const DIFile &F) { | |||
4886 | bool HasSource = F.getSource().hasValue(); | |||
4887 | if (!HasSourceDebugInfo.count(&U)) | |||
4888 | HasSourceDebugInfo[&U] = HasSource; | |||
4889 | AssertDI(HasSource == HasSourceDebugInfo[&U],do { if (!(HasSource == HasSourceDebugInfo[&U])) { DebugInfoCheckFailed ("inconsistent use of embedded source"); return; } } while (false ) | |||
4890 | "inconsistent use of embedded source")do { if (!(HasSource == HasSourceDebugInfo[&U])) { DebugInfoCheckFailed ("inconsistent use of embedded source"); return; } } while (false ); | |||
4891 | } | |||
4892 | ||||
4893 | //===----------------------------------------------------------------------===// | |||
4894 | // Implement the public interfaces to this file... | |||
4895 | //===----------------------------------------------------------------------===// | |||
4896 | ||||
4897 | bool llvm::verifyFunction(const Function &f, raw_ostream *OS) { | |||
4898 | Function &F = const_cast<Function &>(f); | |||
4899 | ||||
4900 | // Don't use a raw_null_ostream. Printing IR is expensive. | |||
4901 | Verifier V(OS, /*ShouldTreatBrokenDebugInfoAsError=*/true, *f.getParent()); | |||
4902 | ||||
4903 | // Note that this function's return value is inverted from what you would | |||
4904 | // expect of a function called "verify". | |||
4905 | return !V.verify(F); | |||
4906 | } | |||
4907 | ||||
4908 | bool llvm::verifyModule(const Module &M, raw_ostream *OS, | |||
4909 | bool *BrokenDebugInfo) { | |||
4910 | // Don't use a raw_null_ostream. Printing IR is expensive. | |||
4911 | Verifier V(OS, /*ShouldTreatBrokenDebugInfoAsError=*/!BrokenDebugInfo, M); | |||
4912 | ||||
4913 | bool Broken = false; | |||
4914 | for (const Function &F : M) | |||
4915 | Broken |= !V.verify(F); | |||
4916 | ||||
4917 | Broken |= !V.verify(); | |||
4918 | if (BrokenDebugInfo) | |||
4919 | *BrokenDebugInfo = V.hasBrokenDebugInfo(); | |||
4920 | // Note that this function's return value is inverted from what you would | |||
4921 | // expect of a function called "verify". | |||
4922 | return Broken; | |||
4923 | } | |||
4924 | ||||
4925 | namespace { | |||
4926 | ||||
4927 | struct VerifierLegacyPass : public FunctionPass { | |||
4928 | static char ID; | |||
4929 | ||||
4930 | std::unique_ptr<Verifier> V; | |||
4931 | bool FatalErrors = true; | |||
4932 | ||||
4933 | VerifierLegacyPass() : FunctionPass(ID) { | |||
4934 | initializeVerifierLegacyPassPass(*PassRegistry::getPassRegistry()); | |||
4935 | } | |||
4936 | explicit VerifierLegacyPass(bool FatalErrors) | |||
4937 | : FunctionPass(ID), | |||
4938 | FatalErrors(FatalErrors) { | |||
4939 | initializeVerifierLegacyPassPass(*PassRegistry::getPassRegistry()); | |||
4940 | } | |||
4941 | ||||
4942 | bool doInitialization(Module &M) override { | |||
4943 | V = llvm::make_unique<Verifier>( | |||
4944 | &dbgs(), /*ShouldTreatBrokenDebugInfoAsError=*/false, M); | |||
4945 | return false; | |||
4946 | } | |||
4947 | ||||
4948 | bool runOnFunction(Function &F) override { | |||
4949 | if (!V->verify(F) && FatalErrors) { | |||
4950 | errs() << "in function " << F.getName() << '\n'; | |||
4951 | report_fatal_error("Broken function found, compilation aborted!"); | |||
4952 | } | |||
4953 | return false; | |||
4954 | } | |||
4955 | ||||
4956 | bool doFinalization(Module &M) override { | |||
4957 | bool HasErrors = false; | |||
4958 | for (Function &F : M) | |||
4959 | if (F.isDeclaration()) | |||
4960 | HasErrors |= !V->verify(F); | |||
4961 | ||||
4962 | HasErrors |= !V->verify(); | |||
4963 | if (FatalErrors && (HasErrors || V->hasBrokenDebugInfo())) | |||
4964 | report_fatal_error("Broken module found, compilation aborted!"); | |||
4965 | return false; | |||
4966 | } | |||
4967 | ||||
4968 | void getAnalysisUsage(AnalysisUsage &AU) const override { | |||
4969 | AU.setPreservesAll(); | |||
4970 | } | |||
4971 | }; | |||
4972 | ||||
4973 | } // end anonymous namespace | |||
4974 | ||||
4975 | /// Helper to issue failure from the TBAA verification | |||
4976 | template <typename... Tys> void TBAAVerifier::CheckFailed(Tys &&... Args) { | |||
4977 | if (Diagnostic) | |||
4978 | return Diagnostic->CheckFailed(Args...); | |||
4979 | } | |||
4980 | ||||
4981 | #define AssertTBAA(C, ...)do { if (!(C)) { CheckFailed(...); return false; } } while (false ) \ | |||
4982 | do { \ | |||
4983 | if (!(C)) { \ | |||
4984 | CheckFailed(__VA_ARGS__); \ | |||
4985 | return false; \ | |||
4986 | } \ | |||
4987 | } while (false) | |||
4988 | ||||
4989 | /// Verify that \p BaseNode can be used as the "base type" in the struct-path | |||
4990 | /// TBAA scheme. This means \p BaseNode is either a scalar node, or a | |||
4991 | /// struct-type node describing an aggregate data structure (like a struct). | |||
4992 | TBAAVerifier::TBAABaseNodeSummary | |||
4993 | TBAAVerifier::verifyTBAABaseNode(Instruction &I, const MDNode *BaseNode, | |||
4994 | bool IsNewFormat) { | |||
4995 | if (BaseNode->getNumOperands() < 2) { | |||
4996 | CheckFailed("Base nodes must have at least two operands", &I, BaseNode); | |||
4997 | return {true, ~0u}; | |||
4998 | } | |||
4999 | ||||
5000 | auto Itr = TBAABaseNodes.find(BaseNode); | |||
5001 | if (Itr != TBAABaseNodes.end()) | |||
5002 | return Itr->second; | |||
5003 | ||||
5004 | auto Result = verifyTBAABaseNodeImpl(I, BaseNode, IsNewFormat); | |||
5005 | auto InsertResult = TBAABaseNodes.insert({BaseNode, Result}); | |||
5006 | (void)InsertResult; | |||
5007 | assert(InsertResult.second && "We just checked!")((InsertResult.second && "We just checked!") ? static_cast <void> (0) : __assert_fail ("InsertResult.second && \"We just checked!\"" , "/build/llvm-toolchain-snapshot-9~svn360410/lib/IR/Verifier.cpp" , 5007, __PRETTY_FUNCTION__)); | |||
5008 | return Result; | |||
5009 | } | |||
5010 | ||||
5011 | TBAAVerifier::TBAABaseNodeSummary | |||
5012 | TBAAVerifier::verifyTBAABaseNodeImpl(Instruction &I, const MDNode *BaseNode, | |||
5013 | bool IsNewFormat) { | |||
5014 | const TBAAVerifier::TBAABaseNodeSummary InvalidNode = {true, ~0u}; | |||
5015 | ||||
5016 | if (BaseNode->getNumOperands() == 2) { | |||
5017 | // Scalar nodes can only be accessed at offset 0. | |||
5018 | return isValidScalarTBAANode(BaseNode) | |||
5019 | ? TBAAVerifier::TBAABaseNodeSummary({false, 0}) | |||
5020 | : InvalidNode; | |||
5021 | } | |||
5022 | ||||
5023 | if (IsNewFormat) { | |||
5024 | if (BaseNode->getNumOperands() % 3 != 0) { | |||
5025 | CheckFailed("Access tag nodes must have the number of operands that is a " | |||
5026 | "multiple of 3!", BaseNode); | |||
5027 | return InvalidNode; | |||
5028 | } | |||
5029 | } else { | |||
5030 | if (BaseNode->getNumOperands() % 2 != 1) { | |||
5031 | CheckFailed("Struct tag nodes must have an odd number of operands!", | |||
5032 | BaseNode); | |||
5033 | return InvalidNode; | |||
5034 | } | |||
5035 | } | |||
5036 | ||||
5037 | // Check the type size field. | |||
5038 | if (IsNewFormat) { | |||
5039 | auto *TypeSizeNode = mdconst::dyn_extract_or_null<ConstantInt>( | |||
5040 | BaseNode->getOperand(1)); | |||
5041 | if (!TypeSizeNode) { | |||
5042 | CheckFailed("Type size nodes must be constants!", &I, BaseNode); | |||
5043 | return InvalidNode; | |||
5044 | } | |||
5045 | } | |||
5046 | ||||
5047 | // Check the type name field. In the new format it can be anything. | |||
5048 | if (!IsNewFormat && !isa<MDString>(BaseNode->getOperand(0))) { | |||
5049 | CheckFailed("Struct tag nodes have a string as their first operand", | |||
5050 | BaseNode); | |||
5051 | return InvalidNode; | |||
5052 | } | |||
5053 | ||||
5054 | bool Failed = false; | |||
5055 | ||||
5056 | Optional<APInt> PrevOffset; | |||
5057 | unsigned BitWidth = ~0u; | |||
5058 | ||||
5059 | // We've already checked that BaseNode is not a degenerate root node with one | |||
5060 | // operand in \c verifyTBAABaseNode, so this loop should run at least once. | |||
5061 | unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1; | |||
5062 | unsigned NumOpsPerField = IsNewFormat ? 3 : 2; | |||
5063 | for (unsigned Idx = FirstFieldOpNo; Idx < BaseNode->getNumOperands(); | |||
5064 | Idx += NumOpsPerField) { | |||
5065 | const MDOperand &FieldTy = BaseNode->getOperand(Idx); | |||
5066 | const MDOperand &FieldOffset = BaseNode->getOperand(Idx + 1); | |||
5067 | if (!isa<MDNode>(FieldTy)) { | |||
5068 | CheckFailed("Incorrect field entry in struct type node!", &I, BaseNode); | |||
5069 | Failed = true; | |||
5070 | continue; | |||
5071 | } | |||
5072 | ||||
5073 | auto *OffsetEntryCI = | |||
5074 | mdconst::dyn_extract_or_null<ConstantInt>(FieldOffset); | |||
5075 | if (!OffsetEntryCI) { | |||
5076 | CheckFailed("Offset entries must be constants!", &I, BaseNode); | |||
5077 | Failed = true; | |||
5078 | continue; | |||
5079 | } | |||
5080 | ||||
5081 | if (BitWidth == ~0u) | |||
5082 | BitWidth = OffsetEntryCI->getBitWidth(); | |||
5083 | ||||
5084 | if (OffsetEntryCI->getBitWidth() != BitWidth) { | |||
5085 | CheckFailed( | |||
5086 | "Bitwidth between the offsets and struct type entries must match", &I, | |||
5087 | BaseNode); | |||
5088 | Failed = true; | |||
5089 | continue; | |||
5090 | } | |||
5091 | ||||
5092 | // NB! As far as I can tell, we generate a non-strictly increasing offset | |||
5093 | // sequence only from structs that have zero size bit fields. When | |||
5094 | // recursing into a contained struct in \c getFieldNodeFromTBAABaseNode we | |||
5095 | // pick the field lexically the latest in struct type metadata node. This | |||
5096 | // mirrors the actual behavior of the alias analysis implementation. | |||
5097 | bool IsAscending = | |||
5098 | !PrevOffset || PrevOffset->ule(OffsetEntryCI->getValue()); | |||
5099 | ||||
5100 | if (!IsAscending) { | |||
5101 | CheckFailed("Offsets must be increasing!", &I, BaseNode); | |||
5102 | Failed = true; | |||
5103 | } | |||
5104 | ||||
5105 | PrevOffset = OffsetEntryCI->getValue(); | |||
5106 | ||||
5107 | if (IsNewFormat) { | |||
5108 | auto *MemberSizeNode = mdconst::dyn_extract_or_null<ConstantInt>( | |||
5109 | BaseNode->getOperand(Idx + 2)); | |||
5110 | if (!MemberSizeNode) { | |||
5111 | CheckFailed("Member size entries must be constants!", &I, BaseNode); | |||
5112 | Failed = true; | |||
5113 | continue; | |||
5114 | } | |||
5115 | } | |||
5116 | } | |||
5117 | ||||
5118 | return Failed ? InvalidNode | |||
5119 | : TBAAVerifier::TBAABaseNodeSummary(false, BitWidth); | |||
5120 | } | |||
5121 | ||||
5122 | static bool IsRootTBAANode(const MDNode *MD) { | |||
5123 | return MD->getNumOperands() < 2; | |||
5124 | } | |||
5125 | ||||
5126 | static bool IsScalarTBAANodeImpl(const MDNode *MD, | |||
5127 | SmallPtrSetImpl<const MDNode *> &Visited) { | |||
5128 | if (MD->getNumOperands() != 2 && MD->getNumOperands() != 3) | |||
5129 | return false; | |||
5130 | ||||
5131 | if (!isa<MDString>(MD->getOperand(0))) | |||
5132 | return false; | |||
5133 | ||||
5134 | if (MD->getNumOperands() == 3) { | |||
5135 | auto *Offset = mdconst::dyn_extract<ConstantInt>(MD->getOperand(2)); | |||
5136 | if (!(Offset && Offset->isZero() && isa<MDString>(MD->getOperand(0)))) | |||
5137 | return false; | |||
5138 | } | |||
5139 | ||||
5140 | auto *Parent = dyn_cast_or_null<MDNode>(MD->getOperand(1)); | |||
5141 | return Parent && Visited.insert(Parent).second && | |||
5142 | (IsRootTBAANode(Parent) || IsScalarTBAANodeImpl(Parent, Visited)); | |||
5143 | } | |||
5144 | ||||
5145 | bool TBAAVerifier::isValidScalarTBAANode(const MDNode *MD) { | |||
5146 | auto ResultIt = TBAAScalarNodes.find(MD); | |||
5147 | if (ResultIt != TBAAScalarNodes.end()) | |||
5148 | return ResultIt->second; | |||
5149 | ||||
5150 | SmallPtrSet<const MDNode *, 4> Visited; | |||
5151 | bool Result = IsScalarTBAANodeImpl(MD, Visited); | |||
5152 | auto InsertResult = TBAAScalarNodes.insert({MD, Result}); | |||
5153 | (void)InsertResult; | |||
5154 | assert(InsertResult.second && "Just checked!")((InsertResult.second && "Just checked!") ? static_cast <void> (0) : __assert_fail ("InsertResult.second && \"Just checked!\"" , "/build/llvm-toolchain-snapshot-9~svn360410/lib/IR/Verifier.cpp" , 5154, __PRETTY_FUNCTION__)); | |||
5155 | ||||
5156 | return Result; | |||
5157 | } | |||
5158 | ||||
5159 | /// Returns the field node at the offset \p Offset in \p BaseNode. Update \p | |||
5160 | /// Offset in place to be the offset within the field node returned. | |||
5161 | /// | |||
5162 | /// We assume we've okayed \p BaseNode via \c verifyTBAABaseNode. | |||
5163 | MDNode *TBAAVerifier::getFieldNodeFromTBAABaseNode(Instruction &I, | |||
5164 | const MDNode *BaseNode, | |||
5165 | APInt &Offset, | |||
5166 | bool IsNewFormat) { | |||
5167 | assert(BaseNode->getNumOperands() >= 2 && "Invalid base node!")((BaseNode->getNumOperands() >= 2 && "Invalid base node!" ) ? static_cast<void> (0) : __assert_fail ("BaseNode->getNumOperands() >= 2 && \"Invalid base node!\"" , "/build/llvm-toolchain-snapshot-9~svn360410/lib/IR/Verifier.cpp" , 5167, __PRETTY_FUNCTION__)); | |||
5168 | ||||
5169 | // Scalar nodes have only one possible "field" -- their parent in the access | |||
5170 | // hierarchy. Offset must be zero at this point, but our caller is supposed | |||
5171 | // to Assert that. | |||
5172 | if (BaseNode->getNumOperands() == 2) | |||
5173 | return cast<MDNode>(BaseNode->getOperand(1)); | |||
5174 | ||||
5175 | unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1; | |||
5176 | unsigned NumOpsPerField = IsNewFormat ? 3 : 2; | |||
5177 | for (unsigned Idx = FirstFieldOpNo; Idx < BaseNode->getNumOperands(); | |||
5178 | Idx += NumOpsPerField) { | |||
5179 | auto *OffsetEntryCI = | |||
5180 | mdconst::extract<ConstantInt>(BaseNode->getOperand(Idx + 1)); | |||
5181 | if (OffsetEntryCI->getValue().ugt(Offset)) { | |||
5182 | if (Idx == FirstFieldOpNo) { | |||
5183 | CheckFailed("Could not find TBAA parent in struct type node", &I, | |||
5184 | BaseNode, &Offset); | |||
5185 | return nullptr; | |||
5186 | } | |||
5187 | ||||
5188 | unsigned PrevIdx = Idx - NumOpsPerField; | |||
5189 | auto *PrevOffsetEntryCI = | |||
5190 | mdconst::extract<ConstantInt>(BaseNode->getOperand(PrevIdx + 1)); | |||
5191 | Offset -= PrevOffsetEntryCI->getValue(); | |||
5192 | return cast<MDNode>(BaseNode->getOperand(PrevIdx)); | |||
5193 | } | |||
5194 | } | |||
5195 | ||||
5196 | unsigned LastIdx = BaseNode->getNumOperands() - NumOpsPerField; | |||
5197 | auto *LastOffsetEntryCI = mdconst::extract<ConstantInt>( | |||
5198 | BaseNode->getOperand(LastIdx + 1)); | |||
5199 | Offset -= LastOffsetEntryCI->getValue(); | |||
5200 | return cast<MDNode>(BaseNode->getOperand(LastIdx)); | |||
5201 | } | |||
5202 | ||||
5203 | static bool isNewFormatTBAATypeNode(llvm::MDNode *Type) { | |||
5204 | if (!Type || Type->getNumOperands() < 3) | |||
5205 | return false; | |||
5206 | ||||
5207 | // In the new format type nodes shall have a reference to the parent type as | |||
5208 | // its first operand. | |||
5209 | MDNode *Parent = dyn_cast_or_null<MDNode>(Type->getOperand(0)); | |||
5210 | if (!Parent) | |||
5211 | return false; | |||
5212 | ||||
5213 | return true; | |||
5214 | } | |||
5215 | ||||
5216 | bool TBAAVerifier::visitTBAAMetadata(Instruction &I, const MDNode *MD) { | |||
5217 | AssertTBAA(isa<LoadInst>(I) || isa<StoreInst>(I) || isa<CallInst>(I) ||do { if (!(isa<LoadInst>(I) || isa<StoreInst>(I) || isa<CallInst>(I) || isa<VAArgInst>(I) || isa< AtomicRMWInst>(I) || isa<AtomicCmpXchgInst>(I))) { CheckFailed ("This instruction shall not have a TBAA access tag!", &I ); return false; } } while (false) | |||
5218 | isa<VAArgInst>(I) || isa<AtomicRMWInst>(I) ||do { if (!(isa<LoadInst>(I) || isa<StoreInst>(I) || isa<CallInst>(I) || isa<VAArgInst>(I) || isa< AtomicRMWInst>(I) || isa<AtomicCmpXchgInst>(I))) { CheckFailed ("This instruction shall not have a TBAA access tag!", &I ); return false; } } while (false) | |||
5219 | isa<AtomicCmpXchgInst>(I),do { if (!(isa<LoadInst>(I) || isa<StoreInst>(I) || isa<CallInst>(I) || isa<VAArgInst>(I) || isa< AtomicRMWInst>(I) || isa<AtomicCmpXchgInst>(I))) { CheckFailed ("This instruction shall not have a TBAA access tag!", &I ); return false; } } while (false) | |||
5220 | "This instruction shall not have a TBAA access tag!", &I)do { if (!(isa<LoadInst>(I) || isa<StoreInst>(I) || isa<CallInst>(I) || isa<VAArgInst>(I) || isa< AtomicRMWInst>(I) || isa<AtomicCmpXchgInst>(I))) { CheckFailed ("This instruction shall not have a TBAA access tag!", &I ); return false; } } while (false); | |||
5221 | ||||
5222 | bool IsStructPathTBAA = | |||
5223 | isa<MDNode>(MD->getOperand(0)) && MD->getNumOperands() >= 3; | |||
5224 | ||||
5225 | AssertTBAA(do { if (!(IsStructPathTBAA)) { CheckFailed("Old-style TBAA is no longer allowed, use struct-path TBAA instead" , &I); return false; } } while (false) | |||
5226 | IsStructPathTBAA,do { if (!(IsStructPathTBAA)) { CheckFailed("Old-style TBAA is no longer allowed, use struct-path TBAA instead" , &I); return false; } } while (false) | |||
5227 | "Old-style TBAA is no longer allowed, use struct-path TBAA instead", &I)do { if (!(IsStructPathTBAA)) { CheckFailed("Old-style TBAA is no longer allowed, use struct-path TBAA instead" , &I); return false; } } while (false); | |||
5228 | ||||
5229 | MDNode *BaseNode = dyn_cast_or_null<MDNode>(MD->getOperand(0)); | |||
5230 | MDNode *AccessType = dyn_cast_or_null<MDNode>(MD->getOperand(1)); | |||
5231 | ||||
5232 | bool IsNewFormat = isNewFormatTBAATypeNode(AccessType); | |||
5233 | ||||
5234 | if (IsNewFormat) { | |||
5235 | AssertTBAA(MD->getNumOperands() == 4 || MD->getNumOperands() == 5,do { if (!(MD->getNumOperands() == 4 || MD->getNumOperands () == 5)) { CheckFailed("Access tag metadata must have either 4 or 5 operands" , &I, MD); return false; } } while (false) | |||
5236 | "Access tag metadata must have either 4 or 5 operands", &I, MD)do { if (!(MD->getNumOperands() == 4 || MD->getNumOperands () == 5)) { CheckFailed("Access tag metadata must have either 4 or 5 operands" , &I, MD); return false; } } while (false); | |||
5237 | } else { | |||
5238 | AssertTBAA(MD->getNumOperands() < 5,do { if (!(MD->getNumOperands() < 5)) { CheckFailed("Struct tag metadata must have either 3 or 4 operands" , &I, MD); return false; } } while (false) | |||
5239 | "Struct tag metadata must have either 3 or 4 operands", &I, MD)do { if (!(MD->getNumOperands() < 5)) { CheckFailed("Struct tag metadata must have either 3 or 4 operands" , &I, MD); return false; } } while (false); | |||
5240 | } | |||
5241 | ||||
5242 | // Check the access size field. | |||
5243 | if (IsNewFormat) { | |||
5244 | auto *AccessSizeNode = mdconst::dyn_extract_or_null<ConstantInt>( | |||
5245 | MD->getOperand(3)); | |||
5246 | AssertTBAA(AccessSizeNode, "Access size field must be a constant", &I, MD)do { if (!(AccessSizeNode)) { CheckFailed("Access size field must be a constant" , &I, MD); return false; } } while (false); | |||
5247 | } | |||
5248 | ||||
5249 | // Check the immutability flag. | |||
5250 | unsigned ImmutabilityFlagOpNo = IsNewFormat ? 4 : 3; | |||
5251 | if (MD->getNumOperands() == ImmutabilityFlagOpNo + 1) { | |||
5252 | auto *IsImmutableCI = mdconst::dyn_extract_or_null<ConstantInt>( | |||
5253 | MD->getOperand(ImmutabilityFlagOpNo)); | |||
5254 | AssertTBAA(IsImmutableCI,do { if (!(IsImmutableCI)) { CheckFailed("Immutability tag on struct tag metadata must be a constant" , &I, MD); return false; } } while (false) | |||
5255 | "Immutability tag on struct tag metadata must be a constant",do { if (!(IsImmutableCI)) { CheckFailed("Immutability tag on struct tag metadata must be a constant" , &I, MD); return false; } } while (false) | |||
5256 | &I, MD)do { if (!(IsImmutableCI)) { CheckFailed("Immutability tag on struct tag metadata must be a constant" , &I, MD); return false; } } while (false); | |||
5257 | AssertTBAA(do { if (!(IsImmutableCI->isZero() || IsImmutableCI->isOne ())) { CheckFailed("Immutability part of the struct tag metadata must be either 0 or 1" , &I, MD); return false; } } while (false) | |||
5258 | IsImmutableCI->isZero() || IsImmutableCI->isOne(),do { if (!(IsImmutableCI->isZero() || IsImmutableCI->isOne ())) { CheckFailed("Immutability part of the struct tag metadata must be either 0 or 1" , &I, MD); return false; } } while (false) | |||
5259 | "Immutability part of the struct tag metadata must be either 0 or 1",do { if (!(IsImmutableCI->isZero() || IsImmutableCI->isOne ())) { CheckFailed("Immutability part of the struct tag metadata must be either 0 or 1" , &I, MD); return false; } } while (false) | |||
5260 | &I, MD)do { if (!(IsImmutableCI->isZero() || IsImmutableCI->isOne ())) { CheckFailed("Immutability part of the struct tag metadata must be either 0 or 1" , &I, MD); return false; } } while (false); | |||
5261 | } | |||
5262 | ||||
5263 | AssertTBAA(BaseNode && AccessType,do { if (!(BaseNode && AccessType)) { CheckFailed("Malformed struct tag metadata: base and access-type " "should be non-null and point to Metadata nodes", &I, MD , BaseNode, AccessType); return false; } } while (false) | |||
5264 | "Malformed struct tag metadata: base and access-type "do { if (!(BaseNode && AccessType)) { CheckFailed("Malformed struct tag metadata: base and access-type " "should be non-null and point to Metadata nodes", &I, MD , BaseNode, AccessType); return false; } } while (false) | |||
5265 | "should be non-null and point to Metadata nodes",do { if (!(BaseNode && AccessType)) { CheckFailed("Malformed struct tag metadata: base and access-type " "should be non-null and point to Metadata nodes", &I, MD , BaseNode, AccessType); return false; } } while (false) | |||
5266 | &I, MD, BaseNode, AccessType)do { if (!(BaseNode && AccessType)) { CheckFailed("Malformed struct tag metadata: base and access-type " "should be non-null and point to Metadata nodes", &I, MD , BaseNode, AccessType); return false; } } while (false); | |||
5267 | ||||
5268 | if (!IsNewFormat) { | |||
5269 | AssertTBAA(isValidScalarTBAANode(AccessType),do { if (!(isValidScalarTBAANode(AccessType))) { CheckFailed( "Access type node must be a valid scalar type", &I, MD, AccessType ); return false; } } while (false) | |||
5270 | "Access type node must be a valid scalar type", &I, MD,do { if (!(isValidScalarTBAANode(AccessType))) { CheckFailed( "Access type node must be a valid scalar type", &I, MD, AccessType ); return false; } } while (false) | |||
5271 | AccessType)do { if (!(isValidScalarTBAANode(AccessType))) { CheckFailed( "Access type node must be a valid scalar type", &I, MD, AccessType ); return false; } } while (false); | |||
5272 | } | |||
5273 | ||||
5274 | auto *OffsetCI = mdconst::dyn_extract_or_null<ConstantInt>(MD->getOperand(2)); | |||
5275 | AssertTBAA(OffsetCI, "Offset must be constant integer", &I, MD)do { if (!(OffsetCI)) { CheckFailed("Offset must be constant integer" , &I, MD); return false; } } while (false); | |||
5276 | ||||
5277 | APInt Offset = OffsetCI->getValue(); | |||
5278 | bool SeenAccessTypeInPath = false; | |||
5279 | ||||
5280 | SmallPtrSet<MDNode *, 4> StructPath; | |||
5281 | ||||
5282 | for (/* empty */; BaseNode && !IsRootTBAANode(BaseNode); | |||
5283 | BaseNode = getFieldNodeFromTBAABaseNode(I, BaseNode, Offset, | |||
5284 | IsNewFormat)) { | |||
5285 | if (!StructPath.insert(BaseNode).second) { | |||
5286 | CheckFailed("Cycle detected in struct path", &I, MD); | |||
5287 | return false; | |||
5288 | } | |||
5289 | ||||
5290 | bool Invalid; | |||
5291 | unsigned BaseNodeBitWidth; | |||
5292 | std::tie(Invalid, BaseNodeBitWidth) = verifyTBAABaseNode(I, BaseNode, | |||
5293 | IsNewFormat); | |||
5294 | ||||
5295 | // If the base node is invalid in itself, then we've already printed all the | |||
5296 | // errors we wanted to print. | |||
5297 | if (Invalid) | |||
5298 | return false; | |||
5299 | ||||
5300 | SeenAccessTypeInPath |= BaseNode == AccessType; | |||
5301 | ||||
5302 | if (isValidScalarTBAANode(BaseNode) || BaseNode == AccessType) | |||
5303 | AssertTBAA(Offset == 0, "Offset not zero at the point of scalar access",do { if (!(Offset == 0)) { CheckFailed("Offset not zero at the point of scalar access" , &I, MD, &Offset); return false; } } while (false) | |||
5304 | &I, MD, &Offset)do { if (!(Offset == 0)) { CheckFailed("Offset not zero at the point of scalar access" , &I, MD, &Offset); return false; } } while (false); | |||
5305 | ||||
5306 | AssertTBAA(BaseNodeBitWidth == Offset.getBitWidth() ||do { if (!(BaseNodeBitWidth == Offset.getBitWidth() || (BaseNodeBitWidth == 0 && Offset == 0) || (IsNewFormat && BaseNodeBitWidth == ~0u))) { CheckFailed("Access bit-width not the same as description bit-width" , &I, MD, BaseNodeBitWidth, Offset.getBitWidth()); return false; } } while (false) | |||
5307 | (BaseNodeBitWidth == 0 && Offset == 0) ||do { if (!(BaseNodeBitWidth == Offset.getBitWidth() || (BaseNodeBitWidth == 0 && Offset == 0) || (IsNewFormat && BaseNodeBitWidth == ~0u))) { CheckFailed("Access bit-width not the same as description bit-width" , &I, MD, BaseNodeBitWidth, Offset.getBitWidth()); return false; } } while (false) | |||
5308 | (IsNewFormat && BaseNodeBitWidth == ~0u),do { if (!(BaseNodeBitWidth == Offset.getBitWidth() || (BaseNodeBitWidth == 0 && Offset == 0) || (IsNewFormat && BaseNodeBitWidth == ~0u))) { CheckFailed("Access bit-width not the same as description bit-width" , &I, MD, BaseNodeBitWidth, Offset.getBitWidth()); return false; } } while (false) | |||
5309 | "Access bit-width not the same as description bit-width", &I, MD,do { if (!(BaseNodeBitWidth == Offset.getBitWidth() || (BaseNodeBitWidth == 0 && Offset == 0) || (IsNewFormat && BaseNodeBitWidth == ~0u))) { CheckFailed("Access bit-width not the same as description bit-width" , &I, MD, BaseNodeBitWidth, Offset.getBitWidth()); return false; } } while (false) | |||
5310 | BaseNodeBitWidth, Offset.getBitWidth())do { if (!(BaseNodeBitWidth == Offset.getBitWidth() || (BaseNodeBitWidth == 0 && Offset == 0) || (IsNewFormat && BaseNodeBitWidth == ~0u))) { CheckFailed("Access bit-width not the same as description bit-width" , &I, MD, BaseNodeBitWidth, Offset.getBitWidth()); return false; } } while (false); | |||
5311 | ||||
5312 | if (IsNewFormat && SeenAccessTypeInPath) | |||
5313 | break; | |||
5314 | } | |||
5315 | ||||
5316 | AssertTBAA(SeenAccessTypeInPath, "Did not see access type in access path!",do { if (!(SeenAccessTypeInPath)) { CheckFailed("Did not see access type in access path!" , &I, MD); return false; } } while (false) | |||
5317 | &I, MD)do { if (!(SeenAccessTypeInPath)) { CheckFailed("Did not see access type in access path!" , &I, MD); return false; } } while (false); | |||
5318 | return true; | |||
5319 | } | |||
5320 | ||||
5321 | char VerifierLegacyPass::ID = 0; | |||
5322 | INITIALIZE_PASS(VerifierLegacyPass, "verify", "Module Verifier", false, false)static void *initializeVerifierLegacyPassPassOnce(PassRegistry &Registry) { PassInfo *PI = new PassInfo( "Module Verifier" , "verify", &VerifierLegacyPass::ID, PassInfo::NormalCtor_t (callDefaultCtor<VerifierLegacyPass>), false, false); Registry .registerPass(*PI, true); return PI; } static llvm::once_flag InitializeVerifierLegacyPassPassFlag; void llvm::initializeVerifierLegacyPassPass (PassRegistry &Registry) { llvm::call_once(InitializeVerifierLegacyPassPassFlag , initializeVerifierLegacyPassPassOnce, std::ref(Registry)); } | |||
5323 | ||||
5324 | FunctionPass *llvm::createVerifierPass(bool FatalErrors) { | |||
5325 | return new VerifierLegacyPass(FatalErrors); | |||
5326 | } | |||
5327 | ||||
5328 | AnalysisKey VerifierAnalysis::Key; | |||
5329 | VerifierAnalysis::Result VerifierAnalysis::run(Module &M, | |||
5330 | ModuleAnalysisManager &) { | |||
5331 | Result Res; | |||
5332 | Res.IRBroken = llvm::verifyModule(M, &dbgs(), &Res.DebugInfoBroken); | |||
5333 | return Res; | |||
5334 | } | |||
5335 | ||||
5336 | VerifierAnalysis::Result VerifierAnalysis::run(Function &F, | |||
5337 | FunctionAnalysisManager &) { | |||
5338 | return { llvm::verifyFunction(F, &dbgs()), false }; | |||
5339 | } | |||
5340 | ||||
5341 | PreservedAnalyses VerifierPass::run(Module &M, ModuleAnalysisManager &AM) { | |||
5342 | auto Res = AM.getResult<VerifierAnalysis>(M); | |||
5343 | if (FatalErrors && (Res.IRBroken || Res.DebugInfoBroken)) | |||
5344 | report_fatal_error("Broken module found, compilation aborted!"); | |||
5345 | ||||
5346 | return PreservedAnalyses::all(); | |||
5347 | } | |||
5348 | ||||
5349 | PreservedAnalyses VerifierPass::run(Function &F, FunctionAnalysisManager &AM) { | |||
5350 | auto res = AM.getResult<VerifierAnalysis>(F); | |||
5351 | if (res.IRBroken && FatalErrors) | |||
5352 | report_fatal_error("Broken function found, compilation aborted!"); | |||
5353 | ||||
5354 | return PreservedAnalyses::all(); | |||
5355 | } |