File: | lib/IR/Verifier.cpp |
Location: | line 989, column 7 |
Description: | Called C++ object pointer is null |
1 | //===-- Verifier.cpp - Implement the Module Verifier -----------------------==// | |||||
2 | // | |||||
3 | // The LLVM Compiler Infrastructure | |||||
4 | // | |||||
5 | // This file is distributed under the University of Illinois Open Source | |||||
6 | // License. See LICENSE.TXT for details. | |||||
7 | // | |||||
8 | //===----------------------------------------------------------------------===// | |||||
9 | // | |||||
10 | // This file defines the function verifier interface, that can be used for some | |||||
11 | // sanity checking of input to the system. | |||||
12 | // | |||||
13 | // Note that this does not provide full `Java style' security and verifications, | |||||
14 | // instead it just tries to ensure that code is well-formed. | |||||
15 | // | |||||
16 | // * Both of a binary operator's parameters are of the same type | |||||
17 | // * Verify that the indices of mem access instructions match other operands | |||||
18 | // * Verify that arithmetic and other things are only performed on first-class | |||||
19 | // types. Verify that shifts & logicals only happen on integrals f.e. | |||||
20 | // * All of the constants in a switch statement are of the correct type | |||||
21 | // * The code is in valid SSA form | |||||
22 | // * It should be illegal to put a label into any other type (like a structure) | |||||
23 | // or to return one. [except constant arrays!] | |||||
24 | // * Only phi nodes can be self referential: 'add i32 %0, %0 ; <int>:0' is bad | |||||
25 | // * PHI nodes must have an entry for each predecessor, with no extras. | |||||
26 | // * PHI nodes must be the first thing in a basic block, all grouped together | |||||
27 | // * PHI nodes must have at least one entry | |||||
28 | // * All basic blocks should only end with terminator insts, not contain them | |||||
29 | // * The entry node to a function must not have predecessors | |||||
30 | // * All Instructions must be embedded into a basic block | |||||
31 | // * Functions cannot take a void-typed parameter | |||||
32 | // * Verify that a function's argument list agrees with it's declared type. | |||||
33 | // * It is illegal to specify a name for a void value. | |||||
34 | // * It is illegal to have a internal global value with no initializer | |||||
35 | // * It is illegal to have a ret instruction that returns a value that does not | |||||
36 | // agree with the function return value type. | |||||
37 | // * Function call argument types match the function prototype | |||||
38 | // * A landing pad is defined by a landingpad instruction, and can be jumped to | |||||
39 | // only by the unwind edge of an invoke instruction. | |||||
40 | // * A landingpad instruction must be the first non-PHI instruction in the | |||||
41 | // block. | |||||
42 | // * All landingpad instructions must use the same personality function with | |||||
43 | // the same function. | |||||
44 | // * All other things that are tested by asserts spread about the code... | |||||
45 | // | |||||
46 | //===----------------------------------------------------------------------===// | |||||
47 | ||||||
48 | #include "llvm/IR/Verifier.h" | |||||
49 | #include "llvm/ADT/STLExtras.h" | |||||
50 | #include "llvm/ADT/SetVector.h" | |||||
51 | #include "llvm/ADT/SmallPtrSet.h" | |||||
52 | #include "llvm/ADT/SmallVector.h" | |||||
53 | #include "llvm/ADT/StringExtras.h" | |||||
54 | #include "llvm/IR/CFG.h" | |||||
55 | #include "llvm/IR/CallSite.h" | |||||
56 | #include "llvm/IR/CallingConv.h" | |||||
57 | #include "llvm/IR/ConstantRange.h" | |||||
58 | #include "llvm/IR/Constants.h" | |||||
59 | #include "llvm/IR/DataLayout.h" | |||||
60 | #include "llvm/IR/DebugInfo.h" | |||||
61 | #include "llvm/IR/DerivedTypes.h" | |||||
62 | #include "llvm/IR/Dominators.h" | |||||
63 | #include "llvm/IR/InlineAsm.h" | |||||
64 | #include "llvm/IR/InstIterator.h" | |||||
65 | #include "llvm/IR/InstVisitor.h" | |||||
66 | #include "llvm/IR/IntrinsicInst.h" | |||||
67 | #include "llvm/IR/LLVMContext.h" | |||||
68 | #include "llvm/IR/Metadata.h" | |||||
69 | #include "llvm/IR/Module.h" | |||||
70 | #include "llvm/IR/PassManager.h" | |||||
71 | #include "llvm/IR/Statepoint.h" | |||||
72 | #include "llvm/Pass.h" | |||||
73 | #include "llvm/Support/CommandLine.h" | |||||
74 | #include "llvm/Support/Debug.h" | |||||
75 | #include "llvm/Support/ErrorHandling.h" | |||||
76 | #include "llvm/Support/raw_ostream.h" | |||||
77 | #include <algorithm> | |||||
78 | #include <cstdarg> | |||||
79 | using namespace llvm; | |||||
80 | ||||||
81 | static cl::opt<bool> VerifyDebugInfo("verify-debug-info", cl::init(true)); | |||||
82 | ||||||
83 | namespace { | |||||
84 | struct VerifierSupport { | |||||
85 | raw_ostream &OS; | |||||
86 | const Module *M; | |||||
87 | ||||||
88 | /// \brief Track the brokenness of the module while recursively visiting. | |||||
89 | bool Broken; | |||||
90 | ||||||
91 | explicit VerifierSupport(raw_ostream &OS) | |||||
92 | : OS(OS), M(nullptr), Broken(false) {} | |||||
93 | ||||||
94 | private: | |||||
95 | void Write(const Value *V) { | |||||
96 | if (!V) | |||||
97 | return; | |||||
98 | if (isa<Instruction>(V)) { | |||||
99 | OS << *V << '\n'; | |||||
100 | } else { | |||||
101 | V->printAsOperand(OS, true, M); | |||||
102 | OS << '\n'; | |||||
103 | } | |||||
104 | } | |||||
105 | void Write(ImmutableCallSite CS) { | |||||
106 | Write(CS.getInstruction()); | |||||
107 | } | |||||
108 | ||||||
109 | void Write(const Metadata *MD) { | |||||
110 | if (!MD) | |||||
111 | return; | |||||
112 | MD->print(OS, M); | |||||
113 | OS << '\n'; | |||||
114 | } | |||||
115 | ||||||
116 | template <class T> void Write(const MDTupleTypedArrayWrapper<T> &MD) { | |||||
117 | Write(MD.get()); | |||||
118 | } | |||||
119 | ||||||
120 | void Write(const NamedMDNode *NMD) { | |||||
121 | if (!NMD) | |||||
122 | return; | |||||
123 | NMD->print(OS); | |||||
124 | OS << '\n'; | |||||
125 | } | |||||
126 | ||||||
127 | void Write(Type *T) { | |||||
128 | if (!T) | |||||
129 | return; | |||||
130 | OS << ' ' << *T; | |||||
131 | } | |||||
132 | ||||||
133 | void Write(const Comdat *C) { | |||||
134 | if (!C) | |||||
135 | return; | |||||
136 | OS << *C; | |||||
137 | } | |||||
138 | ||||||
139 | template <typename T1, typename... Ts> | |||||
140 | void WriteTs(const T1 &V1, const Ts &... Vs) { | |||||
141 | Write(V1); | |||||
142 | WriteTs(Vs...); | |||||
143 | } | |||||
144 | ||||||
145 | template <typename... Ts> void WriteTs() {} | |||||
146 | ||||||
147 | public: | |||||
148 | /// \brief A check failed, so printout out the condition and the message. | |||||
149 | /// | |||||
150 | /// This provides a nice place to put a breakpoint if you want to see why | |||||
151 | /// something is not correct. | |||||
152 | void CheckFailed(const Twine &Message) { | |||||
153 | OS << Message << '\n'; | |||||
154 | Broken = true; | |||||
155 | } | |||||
156 | ||||||
157 | /// \brief A check failed (with values to print). | |||||
158 | /// | |||||
159 | /// This calls the Message-only version so that the above is easier to set a | |||||
160 | /// breakpoint on. | |||||
161 | template <typename T1, typename... Ts> | |||||
162 | void CheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs) { | |||||
163 | CheckFailed(Message); | |||||
164 | WriteTs(V1, Vs...); | |||||
165 | } | |||||
166 | }; | |||||
167 | ||||||
168 | class Verifier : public InstVisitor<Verifier>, VerifierSupport { | |||||
169 | friend class InstVisitor<Verifier>; | |||||
170 | ||||||
171 | LLVMContext *Context; | |||||
172 | DominatorTree DT; | |||||
173 | ||||||
174 | /// \brief When verifying a basic block, keep track of all of the | |||||
175 | /// instructions we have seen so far. | |||||
176 | /// | |||||
177 | /// This allows us to do efficient dominance checks for the case when an | |||||
178 | /// instruction has an operand that is an instruction in the same block. | |||||
179 | SmallPtrSet<Instruction *, 16> InstsInThisBlock; | |||||
180 | ||||||
181 | /// \brief Keep track of the metadata nodes that have been checked already. | |||||
182 | SmallPtrSet<const Metadata *, 32> MDNodes; | |||||
183 | ||||||
184 | /// \brief Track unresolved string-based type references. | |||||
185 | SmallDenseMap<const MDString *, const MDNode *, 32> UnresolvedTypeRefs; | |||||
186 | ||||||
187 | /// \brief The result type for a landingpad. | |||||
188 | Type *LandingPadResultTy; | |||||
189 | ||||||
190 | /// \brief Whether we've seen a call to @llvm.localescape in this function | |||||
191 | /// already. | |||||
192 | bool SawFrameEscape; | |||||
193 | ||||||
194 | /// Stores the count of how many objects were passed to llvm.localescape for a | |||||
195 | /// given function and the largest index passed to llvm.localrecover. | |||||
196 | DenseMap<Function *, std::pair<unsigned, unsigned>> FrameEscapeInfo; | |||||
197 | ||||||
198 | public: | |||||
199 | explicit Verifier(raw_ostream &OS) | |||||
200 | : VerifierSupport(OS), Context(nullptr), LandingPadResultTy(nullptr), | |||||
201 | SawFrameEscape(false) {} | |||||
202 | ||||||
203 | bool verify(const Function &F) { | |||||
204 | M = F.getParent(); | |||||
205 | Context = &M->getContext(); | |||||
206 | ||||||
207 | // First ensure the function is well-enough formed to compute dominance | |||||
208 | // information. | |||||
209 | if (F.empty()) { | |||||
210 | OS << "Function '" << F.getName() | |||||
211 | << "' does not contain an entry block!\n"; | |||||
212 | return false; | |||||
213 | } | |||||
214 | for (Function::const_iterator I = F.begin(), E = F.end(); I != E; ++I) { | |||||
215 | if (I->empty() || !I->back().isTerminator()) { | |||||
216 | OS << "Basic Block in function '" << F.getName() | |||||
217 | << "' does not have terminator!\n"; | |||||
218 | I->printAsOperand(OS, true); | |||||
219 | OS << "\n"; | |||||
220 | return false; | |||||
221 | } | |||||
222 | } | |||||
223 | ||||||
224 | // Now directly compute a dominance tree. We don't rely on the pass | |||||
225 | // manager to provide this as it isolates us from a potentially | |||||
226 | // out-of-date dominator tree and makes it significantly more complex to | |||||
227 | // run this code outside of a pass manager. | |||||
228 | // FIXME: It's really gross that we have to cast away constness here. | |||||
229 | DT.recalculate(const_cast<Function &>(F)); | |||||
230 | ||||||
231 | Broken = false; | |||||
232 | // FIXME: We strip const here because the inst visitor strips const. | |||||
233 | visit(const_cast<Function &>(F)); | |||||
234 | InstsInThisBlock.clear(); | |||||
235 | LandingPadResultTy = nullptr; | |||||
236 | SawFrameEscape = false; | |||||
237 | ||||||
238 | return !Broken; | |||||
239 | } | |||||
240 | ||||||
241 | bool verify(const Module &M) { | |||||
242 | this->M = &M; | |||||
243 | Context = &M.getContext(); | |||||
244 | Broken = false; | |||||
245 | ||||||
246 | // Scan through, checking all of the external function's linkage now... | |||||
247 | for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) { | |||||
248 | visitGlobalValue(*I); | |||||
249 | ||||||
250 | // Check to make sure function prototypes are okay. | |||||
251 | if (I->isDeclaration()) | |||||
252 | visitFunction(*I); | |||||
253 | } | |||||
254 | ||||||
255 | // Now that we've visited every function, verify that we never asked to | |||||
256 | // recover a frame index that wasn't escaped. | |||||
257 | verifyFrameRecoverIndices(); | |||||
258 | ||||||
259 | for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); | |||||
260 | I != E; ++I) | |||||
261 | visitGlobalVariable(*I); | |||||
262 | ||||||
263 | for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end(); | |||||
264 | I != E; ++I) | |||||
265 | visitGlobalAlias(*I); | |||||
266 | ||||||
267 | for (Module::const_named_metadata_iterator I = M.named_metadata_begin(), | |||||
268 | E = M.named_metadata_end(); | |||||
269 | I != E; ++I) | |||||
270 | visitNamedMDNode(*I); | |||||
271 | ||||||
272 | for (const StringMapEntry<Comdat> &SMEC : M.getComdatSymbolTable()) | |||||
273 | visitComdat(SMEC.getValue()); | |||||
274 | ||||||
275 | visitModuleFlags(M); | |||||
276 | visitModuleIdents(M); | |||||
277 | ||||||
278 | // Verify type referneces last. | |||||
279 | verifyTypeRefs(); | |||||
280 | ||||||
281 | return !Broken; | |||||
282 | } | |||||
283 | ||||||
284 | private: | |||||
285 | // Verification methods... | |||||
286 | void visitGlobalValue(const GlobalValue &GV); | |||||
287 | void visitGlobalVariable(const GlobalVariable &GV); | |||||
288 | void visitGlobalAlias(const GlobalAlias &GA); | |||||
289 | void visitAliaseeSubExpr(const GlobalAlias &A, const Constant &C); | |||||
290 | void visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias *> &Visited, | |||||
291 | const GlobalAlias &A, const Constant &C); | |||||
292 | void visitNamedMDNode(const NamedMDNode &NMD); | |||||
293 | void visitMDNode(const MDNode &MD); | |||||
294 | void visitMetadataAsValue(const MetadataAsValue &MD, Function *F); | |||||
295 | void visitValueAsMetadata(const ValueAsMetadata &MD, Function *F); | |||||
296 | void visitComdat(const Comdat &C); | |||||
297 | void visitModuleIdents(const Module &M); | |||||
298 | void visitModuleFlags(const Module &M); | |||||
299 | void visitModuleFlag(const MDNode *Op, | |||||
300 | DenseMap<const MDString *, const MDNode *> &SeenIDs, | |||||
301 | SmallVectorImpl<const MDNode *> &Requirements); | |||||
302 | void visitFunction(const Function &F); | |||||
303 | void visitBasicBlock(BasicBlock &BB); | |||||
304 | void visitRangeMetadata(Instruction& I, MDNode* Range, Type* Ty); | |||||
305 | ||||||
306 | template <class Ty> bool isValidMetadataArray(const MDTuple &N); | |||||
307 | #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N); | |||||
308 | #include "llvm/IR/Metadata.def" | |||||
309 | void visitDIScope(const DIScope &N); | |||||
310 | void visitDIVariable(const DIVariable &N); | |||||
311 | void visitDILexicalBlockBase(const DILexicalBlockBase &N); | |||||
312 | void visitDITemplateParameter(const DITemplateParameter &N); | |||||
313 | ||||||
314 | void visitTemplateParams(const MDNode &N, const Metadata &RawParams); | |||||
315 | ||||||
316 | /// \brief Check for a valid string-based type reference. | |||||
317 | /// | |||||
318 | /// Checks if \c MD is a string-based type reference. If it is, keeps track | |||||
319 | /// of it (and its user, \c N) for error messages later. | |||||
320 | bool isValidUUID(const MDNode &N, const Metadata *MD); | |||||
321 | ||||||
322 | /// \brief Check for a valid type reference. | |||||
323 | /// | |||||
324 | /// Checks for subclasses of \a DIType, or \a isValidUUID(). | |||||
325 | bool isTypeRef(const MDNode &N, const Metadata *MD); | |||||
326 | ||||||
327 | /// \brief Check for a valid scope reference. | |||||
328 | /// | |||||
329 | /// Checks for subclasses of \a DIScope, or \a isValidUUID(). | |||||
330 | bool isScopeRef(const MDNode &N, const Metadata *MD); | |||||
331 | ||||||
332 | /// \brief Check for a valid debug info reference. | |||||
333 | /// | |||||
334 | /// Checks for subclasses of \a DINode, or \a isValidUUID(). | |||||
335 | bool isDIRef(const MDNode &N, const Metadata *MD); | |||||
336 | ||||||
337 | // InstVisitor overrides... | |||||
338 | using InstVisitor<Verifier>::visit; | |||||
339 | void visit(Instruction &I); | |||||
340 | ||||||
341 | void visitTruncInst(TruncInst &I); | |||||
342 | void visitZExtInst(ZExtInst &I); | |||||
343 | void visitSExtInst(SExtInst &I); | |||||
344 | void visitFPTruncInst(FPTruncInst &I); | |||||
345 | void visitFPExtInst(FPExtInst &I); | |||||
346 | void visitFPToUIInst(FPToUIInst &I); | |||||
347 | void visitFPToSIInst(FPToSIInst &I); | |||||
348 | void visitUIToFPInst(UIToFPInst &I); | |||||
349 | void visitSIToFPInst(SIToFPInst &I); | |||||
350 | void visitIntToPtrInst(IntToPtrInst &I); | |||||
351 | void visitPtrToIntInst(PtrToIntInst &I); | |||||
352 | void visitBitCastInst(BitCastInst &I); | |||||
353 | void visitAddrSpaceCastInst(AddrSpaceCastInst &I); | |||||
354 | void visitPHINode(PHINode &PN); | |||||
355 | void visitBinaryOperator(BinaryOperator &B); | |||||
356 | void visitICmpInst(ICmpInst &IC); | |||||
357 | void visitFCmpInst(FCmpInst &FC); | |||||
358 | void visitExtractElementInst(ExtractElementInst &EI); | |||||
359 | void visitInsertElementInst(InsertElementInst &EI); | |||||
360 | void visitShuffleVectorInst(ShuffleVectorInst &EI); | |||||
361 | void visitVAArgInst(VAArgInst &VAA) { visitInstruction(VAA); } | |||||
362 | void visitCallInst(CallInst &CI); | |||||
363 | void visitInvokeInst(InvokeInst &II); | |||||
364 | void visitGetElementPtrInst(GetElementPtrInst &GEP); | |||||
365 | void visitLoadInst(LoadInst &LI); | |||||
366 | void visitStoreInst(StoreInst &SI); | |||||
367 | void verifyDominatesUse(Instruction &I, unsigned i); | |||||
368 | void visitInstruction(Instruction &I); | |||||
369 | void visitTerminatorInst(TerminatorInst &I); | |||||
370 | void visitBranchInst(BranchInst &BI); | |||||
371 | void visitReturnInst(ReturnInst &RI); | |||||
372 | void visitSwitchInst(SwitchInst &SI); | |||||
373 | void visitIndirectBrInst(IndirectBrInst &BI); | |||||
374 | void visitSelectInst(SelectInst &SI); | |||||
375 | void visitUserOp1(Instruction &I); | |||||
376 | void visitUserOp2(Instruction &I) { visitUserOp1(I); } | |||||
377 | void visitIntrinsicCallSite(Intrinsic::ID ID, CallSite CS); | |||||
378 | template <class DbgIntrinsicTy> | |||||
379 | void visitDbgIntrinsic(StringRef Kind, DbgIntrinsicTy &DII); | |||||
380 | void visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI); | |||||
381 | void visitAtomicRMWInst(AtomicRMWInst &RMWI); | |||||
382 | void visitFenceInst(FenceInst &FI); | |||||
383 | void visitAllocaInst(AllocaInst &AI); | |||||
384 | void visitExtractValueInst(ExtractValueInst &EVI); | |||||
385 | void visitInsertValueInst(InsertValueInst &IVI); | |||||
386 | void visitEHPadPredecessors(Instruction &I); | |||||
387 | void visitLandingPadInst(LandingPadInst &LPI); | |||||
388 | void visitCatchPadInst(CatchPadInst &CPI); | |||||
389 | void visitCatchEndPadInst(CatchEndPadInst &CEPI); | |||||
390 | void visitCleanupPadInst(CleanupPadInst &CPI); | |||||
391 | void visitCleanupReturnInst(CleanupReturnInst &CRI); | |||||
392 | void visitTerminatePadInst(TerminatePadInst &TPI); | |||||
393 | ||||||
394 | void VerifyCallSite(CallSite CS); | |||||
395 | void verifyMustTailCall(CallInst &CI); | |||||
396 | bool PerformTypeCheck(Intrinsic::ID ID, Function *F, Type *Ty, int VT, | |||||
397 | unsigned ArgNo, std::string &Suffix); | |||||
398 | bool VerifyIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos, | |||||
399 | SmallVectorImpl<Type *> &ArgTys); | |||||
400 | bool VerifyIntrinsicIsVarArg(bool isVarArg, | |||||
401 | ArrayRef<Intrinsic::IITDescriptor> &Infos); | |||||
402 | bool VerifyAttributeCount(AttributeSet Attrs, unsigned Params); | |||||
403 | void VerifyAttributeTypes(AttributeSet Attrs, unsigned Idx, bool isFunction, | |||||
404 | const Value *V); | |||||
405 | void VerifyParameterAttrs(AttributeSet Attrs, unsigned Idx, Type *Ty, | |||||
406 | bool isReturnValue, const Value *V); | |||||
407 | void VerifyFunctionAttrs(FunctionType *FT, AttributeSet Attrs, | |||||
408 | const Value *V); | |||||
409 | void VerifyFunctionMetadata( | |||||
410 | const SmallVector<std::pair<unsigned, MDNode *>, 4> MDs); | |||||
411 | ||||||
412 | void VerifyConstantExprBitcastType(const ConstantExpr *CE); | |||||
413 | void VerifyStatepoint(ImmutableCallSite CS); | |||||
414 | void verifyFrameRecoverIndices(); | |||||
415 | ||||||
416 | // Module-level debug info verification... | |||||
417 | void verifyTypeRefs(); | |||||
418 | template <class MapTy> | |||||
419 | void verifyBitPieceExpression(const DbgInfoIntrinsic &I, | |||||
420 | const MapTy &TypeRefs); | |||||
421 | void visitUnresolvedTypeRef(const MDString *S, const MDNode *N); | |||||
422 | }; | |||||
423 | } // End anonymous namespace | |||||
424 | ||||||
425 | // Assert - We know that cond should be true, if not print an error message. | |||||
426 | #define Assert(C, ...)do { if (!(C)) { CheckFailed(...); return; } } while (0) \ | |||||
427 | do { if (!(C)) { CheckFailed(__VA_ARGS__); return; } } while (0) | |||||
428 | ||||||
429 | void Verifier::visit(Instruction &I) { | |||||
430 | for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) | |||||
431 | Assert(I.getOperand(i) != nullptr, "Operand is null", &I)do { if (!(I.getOperand(i) != nullptr)) { CheckFailed("Operand is null" , &I); return; } } while (0); | |||||
432 | InstVisitor<Verifier>::visit(I); | |||||
433 | } | |||||
434 | ||||||
435 | ||||||
436 | void Verifier::visitGlobalValue(const GlobalValue &GV) { | |||||
437 | Assert(!GV.isDeclaration() || GV.hasExternalLinkage() ||do { if (!(!GV.isDeclaration() || GV.hasExternalLinkage() || GV .hasExternalWeakLinkage())) { CheckFailed("Global is external, but doesn't have external or weak linkage!" , &GV); return; } } while (0) | |||||
438 | GV.hasExternalWeakLinkage(),do { if (!(!GV.isDeclaration() || GV.hasExternalLinkage() || GV .hasExternalWeakLinkage())) { CheckFailed("Global is external, but doesn't have external or weak linkage!" , &GV); return; } } while (0) | |||||
439 | "Global is external, but doesn't have external or weak linkage!", &GV)do { if (!(!GV.isDeclaration() || GV.hasExternalLinkage() || GV .hasExternalWeakLinkage())) { CheckFailed("Global is external, but doesn't have external or weak linkage!" , &GV); return; } } while (0); | |||||
440 | ||||||
441 | Assert(GV.getAlignment() <= Value::MaximumAlignment,do { if (!(GV.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &GV ); return; } } while (0) | |||||
442 | "huge alignment values are unsupported", &GV)do { if (!(GV.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &GV ); return; } } while (0); | |||||
443 | Assert(!GV.hasAppendingLinkage() || isa<GlobalVariable>(GV),do { if (!(!GV.hasAppendingLinkage() || isa<GlobalVariable >(GV))) { CheckFailed("Only global variables can have appending linkage!" , &GV); return; } } while (0) | |||||
444 | "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 (0); | |||||
445 | ||||||
446 | if (GV.hasAppendingLinkage()) { | |||||
447 | const GlobalVariable *GVar = dyn_cast<GlobalVariable>(&GV); | |||||
448 | Assert(GVar && GVar->getValueType()->isArrayTy(),do { if (!(GVar && GVar->getValueType()->isArrayTy ())) { CheckFailed("Only global arrays can have appending linkage!" , GVar); return; } } while (0) | |||||
449 | "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 (0); | |||||
450 | } | |||||
451 | ||||||
452 | if (GV.isDeclarationForLinker()) | |||||
453 | 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 (0); | |||||
454 | } | |||||
455 | ||||||
456 | void Verifier::visitGlobalVariable(const GlobalVariable &GV) { | |||||
457 | if (GV.hasInitializer()) { | |||||
458 | Assert(GV.getInitializer()->getType() == GV.getType()->getElementType(),do { if (!(GV.getInitializer()->getType() == GV.getType()-> getElementType())) { CheckFailed("Global variable initializer type does not match global " "variable type!", &GV); return; } } while (0) | |||||
459 | "Global variable initializer type does not match global "do { if (!(GV.getInitializer()->getType() == GV.getType()-> getElementType())) { CheckFailed("Global variable initializer type does not match global " "variable type!", &GV); return; } } while (0) | |||||
460 | "variable type!",do { if (!(GV.getInitializer()->getType() == GV.getType()-> getElementType())) { CheckFailed("Global variable initializer type does not match global " "variable type!", &GV); return; } } while (0) | |||||
461 | &GV)do { if (!(GV.getInitializer()->getType() == GV.getType()-> getElementType())) { CheckFailed("Global variable initializer type does not match global " "variable type!", &GV); return; } } while (0); | |||||
462 | ||||||
463 | // If the global has common linkage, it must have a zero initializer and | |||||
464 | // cannot be constant. | |||||
465 | if (GV.hasCommonLinkage()) { | |||||
466 | Assert(GV.getInitializer()->isNullValue(),do { if (!(GV.getInitializer()->isNullValue())) { CheckFailed ("'common' global must have a zero initializer!", &GV); return ; } } while (0) | |||||
467 | "'common' global must have a zero initializer!", &GV)do { if (!(GV.getInitializer()->isNullValue())) { CheckFailed ("'common' global must have a zero initializer!", &GV); return ; } } while (0); | |||||
468 | 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 (0) | |||||
469 | &GV)do { if (!(!GV.isConstant())) { CheckFailed("'common' global may not be marked constant!" , &GV); return; } } while (0); | |||||
470 | 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 (0); | |||||
471 | } | |||||
472 | } else { | |||||
473 | Assert(GV.hasExternalLinkage() || GV.hasExternalWeakLinkage(),do { if (!(GV.hasExternalLinkage() || GV.hasExternalWeakLinkage ())) { CheckFailed("invalid linkage type for global declaration" , &GV); return; } } while (0) | |||||
474 | "invalid linkage type for global declaration", &GV)do { if (!(GV.hasExternalLinkage() || GV.hasExternalWeakLinkage ())) { CheckFailed("invalid linkage type for global declaration" , &GV); return; } } while (0); | |||||
475 | } | |||||
476 | ||||||
477 | if (GV.hasName() && (GV.getName() == "llvm.global_ctors" || | |||||
478 | GV.getName() == "llvm.global_dtors")) { | |||||
479 | Assert(!GV.hasInitializer() || GV.hasAppendingLinkage(),do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage())) { CheckFailed("invalid linkage for intrinsic global variable" , &GV); return; } } while (0) | |||||
480 | "invalid linkage for intrinsic global variable", &GV)do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage())) { CheckFailed("invalid linkage for intrinsic global variable" , &GV); return; } } while (0); | |||||
481 | // Don't worry about emitting an error for it not being an array, | |||||
482 | // visitGlobalValue will complain on appending non-array. | |||||
483 | if (ArrayType *ATy = dyn_cast<ArrayType>(GV.getValueType())) { | |||||
484 | StructType *STy = dyn_cast<StructType>(ATy->getElementType()); | |||||
485 | PointerType *FuncPtrTy = | |||||
486 | FunctionType::get(Type::getVoidTy(*Context), false)->getPointerTo(); | |||||
487 | // FIXME: Reject the 2-field form in LLVM 4.0. | |||||
488 | 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 (0) | |||||
489 | (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 (0) | |||||
490 | 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 (0) | |||||
491 | 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 (0) | |||||
492 | "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 (0); | |||||
493 | if (STy->getNumElements() == 3) { | |||||
494 | Type *ETy = STy->getTypeAtIndex(2); | |||||
495 | Assert(ETy->isPointerTy() &&do { if (!(ETy->isPointerTy() && cast<PointerType >(ETy)->getElementType()->isIntegerTy(8))) { CheckFailed ("wrong type for intrinsic global variable", &GV); return ; } } while (0) | |||||
496 | 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 (0) | |||||
497 | "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 (0); | |||||
498 | } | |||||
499 | } | |||||
500 | } | |||||
501 | ||||||
502 | if (GV.hasName() && (GV.getName() == "llvm.used" || | |||||
503 | GV.getName() == "llvm.compiler.used")) { | |||||
504 | Assert(!GV.hasInitializer() || GV.hasAppendingLinkage(),do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage())) { CheckFailed("invalid linkage for intrinsic global variable" , &GV); return; } } while (0) | |||||
505 | "invalid linkage for intrinsic global variable", &GV)do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage())) { CheckFailed("invalid linkage for intrinsic global variable" , &GV); return; } } while (0); | |||||
506 | Type *GVType = GV.getValueType(); | |||||
507 | if (ArrayType *ATy = dyn_cast<ArrayType>(GVType)) { | |||||
508 | PointerType *PTy = dyn_cast<PointerType>(ATy->getElementType()); | |||||
509 | Assert(PTy, "wrong type for intrinsic global variable", &GV)do { if (!(PTy)) { CheckFailed("wrong type for intrinsic global variable" , &GV); return; } } while (0); | |||||
510 | if (GV.hasInitializer()) { | |||||
511 | const Constant *Init = GV.getInitializer(); | |||||
512 | const ConstantArray *InitArray = dyn_cast<ConstantArray>(Init); | |||||
513 | Assert(InitArray, "wrong initalizer for intrinsic global variable",do { if (!(InitArray)) { CheckFailed("wrong initalizer for intrinsic global variable" , Init); return; } } while (0) | |||||
514 | Init)do { if (!(InitArray)) { CheckFailed("wrong initalizer for intrinsic global variable" , Init); return; } } while (0); | |||||
515 | for (unsigned i = 0, e = InitArray->getNumOperands(); i != e; ++i) { | |||||
516 | Value *V = Init->getOperand(i)->stripPointerCastsNoFollowAliases(); | |||||
517 | 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 (0) | |||||
518 | isa<GlobalAlias>(V),do { if (!(isa<GlobalVariable>(V) || isa<Function> (V) || isa<GlobalAlias>(V))) { CheckFailed("invalid llvm.used member" , V); return; } } while (0) | |||||
519 | "invalid llvm.used member", V)do { if (!(isa<GlobalVariable>(V) || isa<Function> (V) || isa<GlobalAlias>(V))) { CheckFailed("invalid llvm.used member" , V); return; } } while (0); | |||||
520 | 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 (0); | |||||
521 | } | |||||
522 | } | |||||
523 | } | |||||
524 | } | |||||
525 | ||||||
526 | Assert(!GV.hasDLLImportStorageClass() ||do { if (!(!GV.hasDLLImportStorageClass() || (GV.isDeclaration () && GV.hasExternalLinkage()) || GV.hasAvailableExternallyLinkage ())) { CheckFailed("Global is marked as dllimport, but not external" , &GV); return; } } while (0) | |||||
527 | (GV.isDeclaration() && GV.hasExternalLinkage()) ||do { if (!(!GV.hasDLLImportStorageClass() || (GV.isDeclaration () && GV.hasExternalLinkage()) || GV.hasAvailableExternallyLinkage ())) { CheckFailed("Global is marked as dllimport, but not external" , &GV); return; } } while (0) | |||||
528 | GV.hasAvailableExternallyLinkage(),do { if (!(!GV.hasDLLImportStorageClass() || (GV.isDeclaration () && GV.hasExternalLinkage()) || GV.hasAvailableExternallyLinkage ())) { CheckFailed("Global is marked as dllimport, but not external" , &GV); return; } } while (0) | |||||
529 | "Global is marked as dllimport, but not external", &GV)do { if (!(!GV.hasDLLImportStorageClass() || (GV.isDeclaration () && GV.hasExternalLinkage()) || GV.hasAvailableExternallyLinkage ())) { CheckFailed("Global is marked as dllimport, but not external" , &GV); return; } } while (0); | |||||
530 | ||||||
531 | if (!GV.hasInitializer()) { | |||||
532 | visitGlobalValue(GV); | |||||
533 | return; | |||||
534 | } | |||||
535 | ||||||
536 | // Walk any aggregate initializers looking for bitcasts between address spaces | |||||
537 | SmallPtrSet<const Value *, 4> Visited; | |||||
538 | SmallVector<const Value *, 4> WorkStack; | |||||
539 | WorkStack.push_back(cast<Value>(GV.getInitializer())); | |||||
540 | ||||||
541 | while (!WorkStack.empty()) { | |||||
542 | const Value *V = WorkStack.pop_back_val(); | |||||
543 | if (!Visited.insert(V).second) | |||||
544 | continue; | |||||
545 | ||||||
546 | if (const User *U = dyn_cast<User>(V)) { | |||||
547 | WorkStack.append(U->op_begin(), U->op_end()); | |||||
548 | } | |||||
549 | ||||||
550 | if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) { | |||||
551 | VerifyConstantExprBitcastType(CE); | |||||
552 | if (Broken) | |||||
553 | return; | |||||
554 | } | |||||
555 | } | |||||
556 | ||||||
557 | visitGlobalValue(GV); | |||||
558 | } | |||||
559 | ||||||
560 | void Verifier::visitAliaseeSubExpr(const GlobalAlias &GA, const Constant &C) { | |||||
561 | SmallPtrSet<const GlobalAlias*, 4> Visited; | |||||
562 | Visited.insert(&GA); | |||||
563 | visitAliaseeSubExpr(Visited, GA, C); | |||||
564 | } | |||||
565 | ||||||
566 | void Verifier::visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias*> &Visited, | |||||
567 | const GlobalAlias &GA, const Constant &C) { | |||||
568 | if (const auto *GV = dyn_cast<GlobalValue>(&C)) { | |||||
569 | Assert(!GV->isDeclaration(), "Alias must point to a definition", &GA)do { if (!(!GV->isDeclaration())) { CheckFailed("Alias must point to a definition" , &GA); return; } } while (0); | |||||
570 | ||||||
571 | if (const auto *GA2 = dyn_cast<GlobalAlias>(GV)) { | |||||
572 | 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 (0); | |||||
573 | ||||||
574 | Assert(!GA2->mayBeOverridden(), "Alias cannot point to a weak alias",do { if (!(!GA2->mayBeOverridden())) { CheckFailed("Alias cannot point to a weak alias" , &GA); return; } } while (0) | |||||
575 | &GA)do { if (!(!GA2->mayBeOverridden())) { CheckFailed("Alias cannot point to a weak alias" , &GA); return; } } while (0); | |||||
576 | } else { | |||||
577 | // Only continue verifying subexpressions of GlobalAliases. | |||||
578 | // Do not recurse into global initializers. | |||||
579 | return; | |||||
580 | } | |||||
581 | } | |||||
582 | ||||||
583 | if (const auto *CE = dyn_cast<ConstantExpr>(&C)) | |||||
584 | VerifyConstantExprBitcastType(CE); | |||||
585 | ||||||
586 | for (const Use &U : C.operands()) { | |||||
587 | Value *V = &*U; | |||||
588 | if (const auto *GA2 = dyn_cast<GlobalAlias>(V)) | |||||
589 | visitAliaseeSubExpr(Visited, GA, *GA2->getAliasee()); | |||||
590 | else if (const auto *C2 = dyn_cast<Constant>(V)) | |||||
591 | visitAliaseeSubExpr(Visited, GA, *C2); | |||||
592 | } | |||||
593 | } | |||||
594 | ||||||
595 | void Verifier::visitGlobalAlias(const GlobalAlias &GA) { | |||||
596 | 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 (0) | |||||
597 | "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 (0) | |||||
598 | "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 (0) | |||||
599 | &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 (0); | |||||
600 | const Constant *Aliasee = GA.getAliasee(); | |||||
601 | Assert(Aliasee, "Aliasee cannot be NULL!", &GA)do { if (!(Aliasee)) { CheckFailed("Aliasee cannot be NULL!", &GA); return; } } while (0); | |||||
602 | Assert(GA.getType() == Aliasee->getType(),do { if (!(GA.getType() == Aliasee->getType())) { CheckFailed ("Alias and aliasee types should match!", &GA); return; } } while (0) | |||||
603 | "Alias and aliasee types should match!", &GA)do { if (!(GA.getType() == Aliasee->getType())) { CheckFailed ("Alias and aliasee types should match!", &GA); return; } } while (0); | |||||
604 | ||||||
605 | 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 (0) | |||||
606 | "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 (0); | |||||
607 | ||||||
608 | visitAliaseeSubExpr(GA, *Aliasee); | |||||
609 | ||||||
610 | visitGlobalValue(GA); | |||||
611 | } | |||||
612 | ||||||
613 | void Verifier::visitNamedMDNode(const NamedMDNode &NMD) { | |||||
614 | for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i) { | |||||
615 | MDNode *MD = NMD.getOperand(i); | |||||
616 | ||||||
617 | if (NMD.getName() == "llvm.dbg.cu") { | |||||
618 | Assert(MD && isa<DICompileUnit>(MD), "invalid compile unit", &NMD, MD)do { if (!(MD && isa<DICompileUnit>(MD))) { CheckFailed ("invalid compile unit", &NMD, MD); return; } } while (0); | |||||
619 | } | |||||
620 | ||||||
621 | if (!MD) | |||||
622 | continue; | |||||
623 | ||||||
624 | visitMDNode(*MD); | |||||
625 | } | |||||
626 | } | |||||
627 | ||||||
628 | void Verifier::visitMDNode(const MDNode &MD) { | |||||
629 | // Only visit each node once. Metadata can be mutually recursive, so this | |||||
630 | // avoids infinite recursion here, as well as being an optimization. | |||||
631 | if (!MDNodes.insert(&MD).second) | |||||
632 | return; | |||||
633 | ||||||
634 | switch (MD.getMetadataID()) { | |||||
635 | default: | |||||
636 | llvm_unreachable("Invalid MDNode subclass")::llvm::llvm_unreachable_internal("Invalid MDNode subclass", "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 636); | |||||
637 | case Metadata::MDTupleKind: | |||||
638 | break; | |||||
639 | #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \ | |||||
640 | case Metadata::CLASS##Kind: \ | |||||
641 | visit##CLASS(cast<CLASS>(MD)); \ | |||||
642 | break; | |||||
643 | #include "llvm/IR/Metadata.def" | |||||
644 | } | |||||
645 | ||||||
646 | for (unsigned i = 0, e = MD.getNumOperands(); i != e; ++i) { | |||||
647 | Metadata *Op = MD.getOperand(i); | |||||
648 | if (!Op) | |||||
649 | continue; | |||||
650 | Assert(!isa<LocalAsMetadata>(Op), "Invalid operand for global metadata!",do { if (!(!isa<LocalAsMetadata>(Op))) { CheckFailed("Invalid operand for global metadata!" , &MD, Op); return; } } while (0) | |||||
651 | &MD, Op)do { if (!(!isa<LocalAsMetadata>(Op))) { CheckFailed("Invalid operand for global metadata!" , &MD, Op); return; } } while (0); | |||||
652 | if (auto *N = dyn_cast<MDNode>(Op)) { | |||||
653 | visitMDNode(*N); | |||||
654 | continue; | |||||
655 | } | |||||
656 | if (auto *V = dyn_cast<ValueAsMetadata>(Op)) { | |||||
657 | visitValueAsMetadata(*V, nullptr); | |||||
658 | continue; | |||||
659 | } | |||||
660 | } | |||||
661 | ||||||
662 | // Check these last, so we diagnose problems in operands first. | |||||
663 | Assert(!MD.isTemporary(), "Expected no forward declarations!", &MD)do { if (!(!MD.isTemporary())) { CheckFailed("Expected no forward declarations!" , &MD); return; } } while (0); | |||||
664 | Assert(MD.isResolved(), "All nodes should be resolved!", &MD)do { if (!(MD.isResolved())) { CheckFailed("All nodes should be resolved!" , &MD); return; } } while (0); | |||||
665 | } | |||||
666 | ||||||
667 | void Verifier::visitValueAsMetadata(const ValueAsMetadata &MD, Function *F) { | |||||
668 | Assert(MD.getValue(), "Expected valid value", &MD)do { if (!(MD.getValue())) { CheckFailed("Expected valid value" , &MD); return; } } while (0); | |||||
669 | Assert(!MD.getValue()->getType()->isMetadataTy(),do { if (!(!MD.getValue()->getType()->isMetadataTy())) { CheckFailed("Unexpected metadata round-trip through values", &MD, MD.getValue()); return; } } while (0) | |||||
670 | "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 (0); | |||||
671 | ||||||
672 | auto *L = dyn_cast<LocalAsMetadata>(&MD); | |||||
673 | if (!L) | |||||
674 | return; | |||||
675 | ||||||
676 | Assert(F, "function-local metadata used outside a function", L)do { if (!(F)) { CheckFailed("function-local metadata used outside a function" , L); return; } } while (0); | |||||
677 | ||||||
678 | // If this was an instruction, bb, or argument, verify that it is in the | |||||
679 | // function that we expect. | |||||
680 | Function *ActualF = nullptr; | |||||
681 | if (Instruction *I = dyn_cast<Instruction>(L->getValue())) { | |||||
682 | 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 (0); | |||||
683 | ActualF = I->getParent()->getParent(); | |||||
684 | } else if (BasicBlock *BB = dyn_cast<BasicBlock>(L->getValue())) | |||||
685 | ActualF = BB->getParent(); | |||||
686 | else if (Argument *A = dyn_cast<Argument>(L->getValue())) | |||||
687 | ActualF = A->getParent(); | |||||
688 | 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!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 688, __PRETTY_FUNCTION__)); | |||||
689 | ||||||
690 | 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 (0); | |||||
691 | } | |||||
692 | ||||||
693 | void Verifier::visitMetadataAsValue(const MetadataAsValue &MDV, Function *F) { | |||||
694 | Metadata *MD = MDV.getMetadata(); | |||||
695 | if (auto *N = dyn_cast<MDNode>(MD)) { | |||||
696 | visitMDNode(*N); | |||||
697 | return; | |||||
698 | } | |||||
699 | ||||||
700 | // Only visit each node once. Metadata can be mutually recursive, so this | |||||
701 | // avoids infinite recursion here, as well as being an optimization. | |||||
702 | if (!MDNodes.insert(MD).second) | |||||
703 | return; | |||||
704 | ||||||
705 | if (auto *V = dyn_cast<ValueAsMetadata>(MD)) | |||||
706 | visitValueAsMetadata(*V, F); | |||||
707 | } | |||||
708 | ||||||
709 | bool Verifier::isValidUUID(const MDNode &N, const Metadata *MD) { | |||||
710 | auto *S = dyn_cast<MDString>(MD); | |||||
711 | if (!S) | |||||
712 | return false; | |||||
713 | if (S->getString().empty()) | |||||
714 | return false; | |||||
715 | ||||||
716 | // Keep track of names of types referenced via UUID so we can check that they | |||||
717 | // actually exist. | |||||
718 | UnresolvedTypeRefs.insert(std::make_pair(S, &N)); | |||||
719 | return true; | |||||
720 | } | |||||
721 | ||||||
722 | /// \brief Check if a value can be a reference to a type. | |||||
723 | bool Verifier::isTypeRef(const MDNode &N, const Metadata *MD) { | |||||
724 | return !MD || isValidUUID(N, MD) || isa<DIType>(MD); | |||||
725 | } | |||||
726 | ||||||
727 | /// \brief Check if a value can be a ScopeRef. | |||||
728 | bool Verifier::isScopeRef(const MDNode &N, const Metadata *MD) { | |||||
729 | return !MD || isValidUUID(N, MD) || isa<DIScope>(MD); | |||||
730 | } | |||||
731 | ||||||
732 | /// \brief Check if a value can be a debug info ref. | |||||
733 | bool Verifier::isDIRef(const MDNode &N, const Metadata *MD) { | |||||
734 | return !MD || isValidUUID(N, MD) || isa<DINode>(MD); | |||||
735 | } | |||||
736 | ||||||
737 | template <class Ty> | |||||
738 | bool isValidMetadataArrayImpl(const MDTuple &N, bool AllowNull) { | |||||
739 | for (Metadata *MD : N.operands()) { | |||||
740 | if (MD) { | |||||
741 | if (!isa<Ty>(MD)) | |||||
742 | return false; | |||||
743 | } else { | |||||
744 | if (!AllowNull) | |||||
745 | return false; | |||||
746 | } | |||||
747 | } | |||||
748 | return true; | |||||
749 | } | |||||
750 | ||||||
751 | template <class Ty> | |||||
752 | bool isValidMetadataArray(const MDTuple &N) { | |||||
753 | return isValidMetadataArrayImpl<Ty>(N, /* AllowNull */ false); | |||||
754 | } | |||||
755 | ||||||
756 | template <class Ty> | |||||
757 | bool isValidMetadataNullArray(const MDTuple &N) { | |||||
758 | return isValidMetadataArrayImpl<Ty>(N, /* AllowNull */ true); | |||||
759 | } | |||||
760 | ||||||
761 | void Verifier::visitDILocation(const DILocation &N) { | |||||
762 | Assert(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { CheckFailed("location requires a valid scope" , &N, N.getRawScope()); return; } } while (0) | |||||
763 | "location requires a valid scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { CheckFailed("location requires a valid scope" , &N, N.getRawScope()); return; } } while (0); | |||||
764 | if (auto *IA = N.getRawInlinedAt()) | |||||
765 | Assert(isa<DILocation>(IA), "inlined-at should be a location", &N, IA)do { if (!(isa<DILocation>(IA))) { CheckFailed("inlined-at should be a location" , &N, IA); return; } } while (0); | |||||
766 | } | |||||
767 | ||||||
768 | void Verifier::visitGenericDINode(const GenericDINode &N) { | |||||
769 | Assert(N.getTag(), "invalid tag", &N)do { if (!(N.getTag())) { CheckFailed("invalid tag", &N); return; } } while (0); | |||||
770 | } | |||||
771 | ||||||
772 | void Verifier::visitDIScope(const DIScope &N) { | |||||
773 | if (auto *F = N.getRawFile()) | |||||
774 | Assert(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { CheckFailed("invalid file" , &N, F); return; } } while (0); | |||||
775 | } | |||||
776 | ||||||
777 | void Verifier::visitDISubrange(const DISubrange &N) { | |||||
778 | Assert(N.getTag() == dwarf::DW_TAG_subrange_type, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_subrange_type)) { CheckFailed ("invalid tag", &N); return; } } while (0); | |||||
779 | Assert(N.getCount() >= -1, "invalid subrange count", &N)do { if (!(N.getCount() >= -1)) { CheckFailed("invalid subrange count" , &N); return; } } while (0); | |||||
780 | } | |||||
781 | ||||||
782 | void Verifier::visitDIEnumerator(const DIEnumerator &N) { | |||||
783 | Assert(N.getTag() == dwarf::DW_TAG_enumerator, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_enumerator)) { CheckFailed ("invalid tag", &N); return; } } while (0); | |||||
784 | } | |||||
785 | ||||||
786 | void Verifier::visitDIBasicType(const DIBasicType &N) { | |||||
787 | Assert(N.getTag() == dwarf::DW_TAG_base_type ||do { if (!(N.getTag() == dwarf::DW_TAG_base_type || N.getTag( ) == dwarf::DW_TAG_unspecified_type)) { CheckFailed("invalid tag" , &N); return; } } while (0) | |||||
788 | N.getTag() == dwarf::DW_TAG_unspecified_type,do { if (!(N.getTag() == dwarf::DW_TAG_base_type || N.getTag( ) == dwarf::DW_TAG_unspecified_type)) { CheckFailed("invalid tag" , &N); return; } } while (0) | |||||
789 | "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_base_type || N.getTag( ) == dwarf::DW_TAG_unspecified_type)) { CheckFailed("invalid tag" , &N); return; } } while (0); | |||||
790 | } | |||||
791 | ||||||
792 | void Verifier::visitDIDerivedType(const DIDerivedType &N) { | |||||
793 | // Common scope checks. | |||||
794 | visitDIScope(N); | |||||
795 | ||||||
796 | Assert(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_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf::DW_TAG_friend)) { CheckFailed("invalid tag" , &N); return; } } while (0) | |||||
797 | 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_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf::DW_TAG_friend)) { CheckFailed("invalid tag" , &N); return; } } while (0) | |||||
798 | 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_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf::DW_TAG_friend)) { CheckFailed("invalid tag" , &N); return; } } while (0) | |||||
799 | 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_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf::DW_TAG_friend)) { CheckFailed("invalid tag" , &N); return; } } while (0) | |||||
800 | 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_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf::DW_TAG_friend)) { CheckFailed("invalid tag" , &N); return; } } while (0) | |||||
801 | 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_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf::DW_TAG_friend)) { CheckFailed("invalid tag" , &N); return; } } while (0) | |||||
802 | 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_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf::DW_TAG_friend)) { CheckFailed("invalid tag" , &N); return; } } while (0) | |||||
803 | 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_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf::DW_TAG_friend)) { CheckFailed("invalid tag" , &N); return; } } while (0) | |||||
804 | 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_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf::DW_TAG_friend)) { CheckFailed("invalid tag" , &N); return; } } while (0) | |||||
805 | 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_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf::DW_TAG_friend)) { CheckFailed("invalid tag" , &N); return; } } while (0) | |||||
806 | 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_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf::DW_TAG_friend)) { CheckFailed("invalid tag" , &N); return; } } while (0) | |||||
807 | "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_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf::DW_TAG_friend)) { CheckFailed("invalid tag" , &N); return; } } while (0); | |||||
808 | if (N.getTag() == dwarf::DW_TAG_ptr_to_member_type) { | |||||
809 | Assert(isTypeRef(N, N.getExtraData()), "invalid pointer to member type", &N,do { if (!(isTypeRef(N, N.getExtraData()))) { CheckFailed("invalid pointer to member type" , &N, N.getExtraData()); return; } } while (0) | |||||
810 | N.getExtraData())do { if (!(isTypeRef(N, N.getExtraData()))) { CheckFailed("invalid pointer to member type" , &N, N.getExtraData()); return; } } while (0); | |||||
811 | } | |||||
812 | ||||||
813 | Assert(isScopeRef(N, N.getScope()), "invalid scope", &N, N.getScope())do { if (!(isScopeRef(N, N.getScope()))) { CheckFailed("invalid scope" , &N, N.getScope()); return; } } while (0); | |||||
814 | Assert(isTypeRef(N, N.getBaseType()), "invalid base type", &N,do { if (!(isTypeRef(N, N.getBaseType()))) { CheckFailed("invalid base type" , &N, N.getBaseType()); return; } } while (0) | |||||
815 | N.getBaseType())do { if (!(isTypeRef(N, N.getBaseType()))) { CheckFailed("invalid base type" , &N, N.getBaseType()); return; } } while (0); | |||||
816 | } | |||||
817 | ||||||
818 | static bool hasConflictingReferenceFlags(unsigned Flags) { | |||||
819 | return (Flags & DINode::FlagLValueReference) && | |||||
820 | (Flags & DINode::FlagRValueReference); | |||||
821 | } | |||||
822 | ||||||
823 | void Verifier::visitTemplateParams(const MDNode &N, const Metadata &RawParams) { | |||||
824 | auto *Params = dyn_cast<MDTuple>(&RawParams); | |||||
825 | Assert(Params, "invalid template params", &N, &RawParams)do { if (!(Params)) { CheckFailed("invalid template params", & N, &RawParams); return; } } while (0); | |||||
826 | for (Metadata *Op : Params->operands()) { | |||||
827 | Assert(Op && isa<DITemplateParameter>(Op), "invalid template parameter", &N,do { if (!(Op && isa<DITemplateParameter>(Op))) { CheckFailed("invalid template parameter", &N, Params, Op ); return; } } while (0) | |||||
828 | Params, Op)do { if (!(Op && isa<DITemplateParameter>(Op))) { CheckFailed("invalid template parameter", &N, Params, Op ); return; } } while (0); | |||||
829 | } | |||||
830 | } | |||||
831 | ||||||
832 | void Verifier::visitDICompositeType(const DICompositeType &N) { | |||||
833 | // Common scope checks. | |||||
834 | visitDIScope(N); | |||||
835 | ||||||
836 | Assert(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)) { CheckFailed("invalid tag", & N); return; } } while (0) | |||||
837 | 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)) { CheckFailed("invalid tag", & N); return; } } while (0) | |||||
838 | 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)) { CheckFailed("invalid tag", & N); return; } } while (0) | |||||
839 | 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)) { CheckFailed("invalid tag", & N); return; } } while (0) | |||||
840 | 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)) { CheckFailed("invalid tag", & N); return; } } while (0) | |||||
841 | "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)) { CheckFailed("invalid tag", & N); return; } } while (0); | |||||
842 | ||||||
843 | Assert(isScopeRef(N, N.getScope()), "invalid scope", &N, N.getScope())do { if (!(isScopeRef(N, N.getScope()))) { CheckFailed("invalid scope" , &N, N.getScope()); return; } } while (0); | |||||
844 | Assert(isTypeRef(N, N.getBaseType()), "invalid base type", &N,do { if (!(isTypeRef(N, N.getBaseType()))) { CheckFailed("invalid base type" , &N, N.getBaseType()); return; } } while (0) | |||||
845 | N.getBaseType())do { if (!(isTypeRef(N, N.getBaseType()))) { CheckFailed("invalid base type" , &N, N.getBaseType()); return; } } while (0); | |||||
846 | ||||||
847 | Assert(!N.getRawElements() || isa<MDTuple>(N.getRawElements()),do { if (!(!N.getRawElements() || isa<MDTuple>(N.getRawElements ()))) { CheckFailed("invalid composite elements", &N, N.getRawElements ()); return; } } while (0) | |||||
848 | "invalid composite elements", &N, N.getRawElements())do { if (!(!N.getRawElements() || isa<MDTuple>(N.getRawElements ()))) { CheckFailed("invalid composite elements", &N, N.getRawElements ()); return; } } while (0); | |||||
849 | Assert(isTypeRef(N, N.getRawVTableHolder()), "invalid vtable holder", &N,do { if (!(isTypeRef(N, N.getRawVTableHolder()))) { CheckFailed ("invalid vtable holder", &N, N.getRawVTableHolder()); return ; } } while (0) | |||||
850 | N.getRawVTableHolder())do { if (!(isTypeRef(N, N.getRawVTableHolder()))) { CheckFailed ("invalid vtable holder", &N, N.getRawVTableHolder()); return ; } } while (0); | |||||
851 | Assert(!N.getRawElements() || isa<MDTuple>(N.getRawElements()),do { if (!(!N.getRawElements() || isa<MDTuple>(N.getRawElements ()))) { CheckFailed("invalid composite elements", &N, N.getRawElements ()); return; } } while (0) | |||||
852 | "invalid composite elements", &N, N.getRawElements())do { if (!(!N.getRawElements() || isa<MDTuple>(N.getRawElements ()))) { CheckFailed("invalid composite elements", &N, N.getRawElements ()); return; } } while (0); | |||||
853 | Assert(!hasConflictingReferenceFlags(N.getFlags()), "invalid reference flags",do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { CheckFailed ("invalid reference flags", &N); return; } } while (0) | |||||
854 | &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { CheckFailed ("invalid reference flags", &N); return; } } while (0); | |||||
855 | if (auto *Params = N.getRawTemplateParams()) | |||||
856 | visitTemplateParams(N, *Params); | |||||
857 | ||||||
858 | if (N.getTag() == dwarf::DW_TAG_class_type || | |||||
859 | N.getTag() == dwarf::DW_TAG_union_type) { | |||||
860 | Assert(N.getFile() && !N.getFile()->getFilename().empty(),do { if (!(N.getFile() && !N.getFile()->getFilename ().empty())) { CheckFailed("class/union requires a filename", &N, N.getFile()); return; } } while (0) | |||||
861 | "class/union requires a filename", &N, N.getFile())do { if (!(N.getFile() && !N.getFile()->getFilename ().empty())) { CheckFailed("class/union requires a filename", &N, N.getFile()); return; } } while (0); | |||||
862 | } | |||||
863 | } | |||||
864 | ||||||
865 | void Verifier::visitDISubroutineType(const DISubroutineType &N) { | |||||
866 | Assert(N.getTag() == dwarf::DW_TAG_subroutine_type, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_subroutine_type)) { CheckFailed ("invalid tag", &N); return; } } while (0); | |||||
867 | if (auto *Types = N.getRawTypeArray()) { | |||||
868 | Assert(isa<MDTuple>(Types), "invalid composite elements", &N, Types)do { if (!(isa<MDTuple>(Types))) { CheckFailed("invalid composite elements" , &N, Types); return; } } while (0); | |||||
869 | for (Metadata *Ty : N.getTypeArray()->operands()) { | |||||
870 | Assert(isTypeRef(N, Ty), "invalid subroutine type ref", &N, Types, Ty)do { if (!(isTypeRef(N, Ty))) { CheckFailed("invalid subroutine type ref" , &N, Types, Ty); return; } } while (0); | |||||
871 | } | |||||
872 | } | |||||
873 | Assert(!hasConflictingReferenceFlags(N.getFlags()), "invalid reference flags",do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { CheckFailed ("invalid reference flags", &N); return; } } while (0) | |||||
874 | &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { CheckFailed ("invalid reference flags", &N); return; } } while (0); | |||||
875 | } | |||||
876 | ||||||
877 | void Verifier::visitDIFile(const DIFile &N) { | |||||
878 | Assert(N.getTag() == dwarf::DW_TAG_file_type, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_file_type)) { CheckFailed ("invalid tag", &N); return; } } while (0); | |||||
879 | } | |||||
880 | ||||||
881 | void Verifier::visitDICompileUnit(const DICompileUnit &N) { | |||||
882 | Assert(N.isDistinct(), "compile units must be distinct", &N)do { if (!(N.isDistinct())) { CheckFailed("compile units must be distinct" , &N); return; } } while (0); | |||||
883 | Assert(N.getTag() == dwarf::DW_TAG_compile_unit, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_compile_unit)) { CheckFailed ("invalid tag", &N); return; } } while (0); | |||||
884 | ||||||
885 | // Don't bother verifying the compilation directory or producer string | |||||
886 | // as those could be empty. | |||||
887 | Assert(N.getRawFile() && isa<DIFile>(N.getRawFile()), "invalid file", &N,do { if (!(N.getRawFile() && isa<DIFile>(N.getRawFile ()))) { CheckFailed("invalid file", &N, N.getRawFile()); return ; } } while (0) | |||||
888 | N.getRawFile())do { if (!(N.getRawFile() && isa<DIFile>(N.getRawFile ()))) { CheckFailed("invalid file", &N, N.getRawFile()); return ; } } while (0); | |||||
889 | Assert(!N.getFile()->getFilename().empty(), "invalid filename", &N,do { if (!(!N.getFile()->getFilename().empty())) { CheckFailed ("invalid filename", &N, N.getFile()); return; } } while ( 0) | |||||
890 | N.getFile())do { if (!(!N.getFile()->getFilename().empty())) { CheckFailed ("invalid filename", &N, N.getFile()); return; } } while ( 0); | |||||
891 | ||||||
892 | if (auto *Array = N.getRawEnumTypes()) { | |||||
893 | Assert(isa<MDTuple>(Array), "invalid enum list", &N, Array)do { if (!(isa<MDTuple>(Array))) { CheckFailed("invalid enum list" , &N, Array); return; } } while (0); | |||||
894 | for (Metadata *Op : N.getEnumTypes()->operands()) { | |||||
895 | auto *Enum = dyn_cast_or_null<DICompositeType>(Op); | |||||
896 | Assert(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type,do { if (!(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type )) { CheckFailed("invalid enum type", &N, N.getEnumTypes( ), Op); return; } } while (0) | |||||
897 | "invalid enum type", &N, N.getEnumTypes(), Op)do { if (!(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type )) { CheckFailed("invalid enum type", &N, N.getEnumTypes( ), Op); return; } } while (0); | |||||
898 | } | |||||
899 | } | |||||
900 | if (auto *Array = N.getRawRetainedTypes()) { | |||||
901 | Assert(isa<MDTuple>(Array), "invalid retained type list", &N, Array)do { if (!(isa<MDTuple>(Array))) { CheckFailed("invalid retained type list" , &N, Array); return; } } while (0); | |||||
902 | for (Metadata *Op : N.getRetainedTypes()->operands()) { | |||||
903 | Assert(Op && isa<DIType>(Op), "invalid retained type", &N, Op)do { if (!(Op && isa<DIType>(Op))) { CheckFailed ("invalid retained type", &N, Op); return; } } while (0); | |||||
904 | } | |||||
905 | } | |||||
906 | if (auto *Array = N.getRawSubprograms()) { | |||||
907 | Assert(isa<MDTuple>(Array), "invalid subprogram list", &N, Array)do { if (!(isa<MDTuple>(Array))) { CheckFailed("invalid subprogram list" , &N, Array); return; } } while (0); | |||||
908 | for (Metadata *Op : N.getSubprograms()->operands()) { | |||||
909 | Assert(Op && isa<DISubprogram>(Op), "invalid subprogram ref", &N, Op)do { if (!(Op && isa<DISubprogram>(Op))) { CheckFailed ("invalid subprogram ref", &N, Op); return; } } while (0); | |||||
910 | } | |||||
911 | } | |||||
912 | if (auto *Array = N.getRawGlobalVariables()) { | |||||
913 | Assert(isa<MDTuple>(Array), "invalid global variable list", &N, Array)do { if (!(isa<MDTuple>(Array))) { CheckFailed("invalid global variable list" , &N, Array); return; } } while (0); | |||||
914 | for (Metadata *Op : N.getGlobalVariables()->operands()) { | |||||
915 | Assert(Op && isa<DIGlobalVariable>(Op), "invalid global variable ref", &N,do { if (!(Op && isa<DIGlobalVariable>(Op))) { CheckFailed ("invalid global variable ref", &N, Op); return; } } while (0) | |||||
916 | Op)do { if (!(Op && isa<DIGlobalVariable>(Op))) { CheckFailed ("invalid global variable ref", &N, Op); return; } } while (0); | |||||
917 | } | |||||
918 | } | |||||
919 | if (auto *Array = N.getRawImportedEntities()) { | |||||
920 | Assert(isa<MDTuple>(Array), "invalid imported entity list", &N, Array)do { if (!(isa<MDTuple>(Array))) { CheckFailed("invalid imported entity list" , &N, Array); return; } } while (0); | |||||
921 | for (Metadata *Op : N.getImportedEntities()->operands()) { | |||||
922 | Assert(Op && isa<DIImportedEntity>(Op), "invalid imported entity ref", &N,do { if (!(Op && isa<DIImportedEntity>(Op))) { CheckFailed ("invalid imported entity ref", &N, Op); return; } } while (0) | |||||
923 | Op)do { if (!(Op && isa<DIImportedEntity>(Op))) { CheckFailed ("invalid imported entity ref", &N, Op); return; } } while (0); | |||||
924 | } | |||||
925 | } | |||||
926 | } | |||||
927 | ||||||
928 | void Verifier::visitDISubprogram(const DISubprogram &N) { | |||||
929 | Assert(N.getTag() == dwarf::DW_TAG_subprogram, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_subprogram)) { CheckFailed ("invalid tag", &N); return; } } while (0); | |||||
930 | Assert(isScopeRef(N, N.getRawScope()), "invalid scope", &N, N.getRawScope())do { if (!(isScopeRef(N, N.getRawScope()))) { CheckFailed("invalid scope" , &N, N.getRawScope()); return; } } while (0); | |||||
931 | if (auto *T = N.getRawType()) | |||||
| ||||||
932 | Assert(isa<DISubroutineType>(T), "invalid subroutine type", &N, T)do { if (!(isa<DISubroutineType>(T))) { CheckFailed("invalid subroutine type" , &N, T); return; } } while (0); | |||||
933 | Assert(isTypeRef(N, N.getRawContainingType()), "invalid containing type", &N,do { if (!(isTypeRef(N, N.getRawContainingType()))) { CheckFailed ("invalid containing type", &N, N.getRawContainingType()) ; return; } } while (0) | |||||
934 | N.getRawContainingType())do { if (!(isTypeRef(N, N.getRawContainingType()))) { CheckFailed ("invalid containing type", &N, N.getRawContainingType()) ; return; } } while (0); | |||||
935 | if (auto *RawF = N.getRawFunction()) { | |||||
936 | auto *FMD = dyn_cast<ConstantAsMetadata>(RawF); | |||||
937 | auto *F = FMD ? FMD->getValue() : nullptr; | |||||
938 | auto *FT = F ? dyn_cast<PointerType>(F->getType()) : nullptr; | |||||
939 | Assert(F && FT && isa<FunctionType>(FT->getElementType()),do { if (!(F && FT && isa<FunctionType> (FT->getElementType()))) { CheckFailed("invalid function", &N, F, FT); return; } } while (0) | |||||
940 | "invalid function", &N, F, FT)do { if (!(F && FT && isa<FunctionType> (FT->getElementType()))) { CheckFailed("invalid function", &N, F, FT); return; } } while (0); | |||||
941 | } | |||||
942 | if (auto *Params = N.getRawTemplateParams()) | |||||
943 | visitTemplateParams(N, *Params); | |||||
944 | if (auto *S = N.getRawDeclaration()) { | |||||
945 | Assert(isa<DISubprogram>(S) && !cast<DISubprogram>(S)->isDefinition(),do { if (!(isa<DISubprogram>(S) && !cast<DISubprogram >(S)->isDefinition())) { CheckFailed("invalid subprogram declaration" , &N, S); return; } } while (0) | |||||
946 | "invalid subprogram declaration", &N, S)do { if (!(isa<DISubprogram>(S) && !cast<DISubprogram >(S)->isDefinition())) { CheckFailed("invalid subprogram declaration" , &N, S); return; } } while (0); | |||||
947 | } | |||||
948 | if (auto *RawVars = N.getRawVariables()) { | |||||
949 | auto *Vars = dyn_cast<MDTuple>(RawVars); | |||||
950 | Assert(Vars, "invalid variable list", &N, RawVars)do { if (!(Vars)) { CheckFailed("invalid variable list", & N, RawVars); return; } } while (0); | |||||
951 | for (Metadata *Op : Vars->operands()) { | |||||
952 | Assert(Op && isa<DILocalVariable>(Op), "invalid local variable", &N, Vars,do { if (!(Op && isa<DILocalVariable>(Op))) { CheckFailed ("invalid local variable", &N, Vars, Op); return; } } while (0) | |||||
953 | Op)do { if (!(Op && isa<DILocalVariable>(Op))) { CheckFailed ("invalid local variable", &N, Vars, Op); return; } } while (0); | |||||
954 | } | |||||
955 | } | |||||
956 | Assert(!hasConflictingReferenceFlags(N.getFlags()), "invalid reference flags",do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { CheckFailed ("invalid reference flags", &N); return; } } while (0) | |||||
957 | &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { CheckFailed ("invalid reference flags", &N); return; } } while (0); | |||||
958 | ||||||
959 | auto *F = N.getFunction(); | |||||
960 | if (!F) | |||||
961 | return; | |||||
962 | ||||||
963 | // Check that all !dbg attachments lead to back to N (or, at least, another | |||||
964 | // subprogram that describes the same function). | |||||
965 | // | |||||
966 | // FIXME: Check this incrementally while visiting !dbg attachments. | |||||
967 | // FIXME: Only check when N is the canonical subprogram for F. | |||||
968 | SmallPtrSet<const MDNode *, 32> Seen; | |||||
969 | for (auto &BB : *F) | |||||
970 | for (auto &I : BB) { | |||||
971 | // Be careful about using DILocation here since we might be dealing with | |||||
972 | // broken code (this is the Verifier after all). | |||||
973 | DILocation *DL = | |||||
974 | dyn_cast_or_null<DILocation>(I.getDebugLoc().getAsMDNode()); | |||||
975 | if (!DL) | |||||
976 | continue; | |||||
977 | if (!Seen.insert(DL).second) | |||||
978 | continue; | |||||
979 | ||||||
980 | DILocalScope *Scope = DL->getInlinedAtScope(); | |||||
981 | if (Scope && !Seen.insert(Scope).second) | |||||
982 | continue; | |||||
983 | ||||||
984 | DISubprogram *SP = Scope ? Scope->getSubprogram() : nullptr; | |||||
985 | if (SP && !Seen.insert(SP).second) | |||||
986 | continue; | |||||
987 | ||||||
988 | // FIXME: Once N is canonical, check "SP == &N". | |||||
989 | Assert(SP->describes(F),do { if (!(SP->describes(F))) { CheckFailed("!dbg attachment points at wrong subprogram for function" , &N, F, &I, DL, Scope, SP); return; } } while (0) | |||||
| ||||||
990 | "!dbg attachment points at wrong subprogram for function", &N, F,do { if (!(SP->describes(F))) { CheckFailed("!dbg attachment points at wrong subprogram for function" , &N, F, &I, DL, Scope, SP); return; } } while (0) | |||||
991 | &I, DL, Scope, SP)do { if (!(SP->describes(F))) { CheckFailed("!dbg attachment points at wrong subprogram for function" , &N, F, &I, DL, Scope, SP); return; } } while (0); | |||||
992 | } | |||||
993 | } | |||||
994 | ||||||
995 | void Verifier::visitDILexicalBlockBase(const DILexicalBlockBase &N) { | |||||
996 | Assert(N.getTag() == dwarf::DW_TAG_lexical_block, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_lexical_block)) { CheckFailed ("invalid tag", &N); return; } } while (0); | |||||
997 | Assert(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { CheckFailed("invalid local scope", & N, N.getRawScope()); return; } } while (0) | |||||
998 | "invalid local scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { CheckFailed("invalid local scope", & N, N.getRawScope()); return; } } while (0); | |||||
999 | } | |||||
1000 | ||||||
1001 | void Verifier::visitDILexicalBlock(const DILexicalBlock &N) { | |||||
1002 | visitDILexicalBlockBase(N); | |||||
1003 | ||||||
1004 | Assert(N.getLine() || !N.getColumn(),do { if (!(N.getLine() || !N.getColumn())) { CheckFailed("cannot have column info without line info" , &N); return; } } while (0) | |||||
1005 | "cannot have column info without line info", &N)do { if (!(N.getLine() || !N.getColumn())) { CheckFailed("cannot have column info without line info" , &N); return; } } while (0); | |||||
1006 | } | |||||
1007 | ||||||
1008 | void Verifier::visitDILexicalBlockFile(const DILexicalBlockFile &N) { | |||||
1009 | visitDILexicalBlockBase(N); | |||||
1010 | } | |||||
1011 | ||||||
1012 | void Verifier::visitDINamespace(const DINamespace &N) { | |||||
1013 | Assert(N.getTag() == dwarf::DW_TAG_namespace, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_namespace)) { CheckFailed ("invalid tag", &N); return; } } while (0); | |||||
1014 | if (auto *S = N.getRawScope()) | |||||
1015 | Assert(isa<DIScope>(S), "invalid scope ref", &N, S)do { if (!(isa<DIScope>(S))) { CheckFailed("invalid scope ref" , &N, S); return; } } while (0); | |||||
1016 | } | |||||
1017 | ||||||
1018 | void Verifier::visitDIModule(const DIModule &N) { | |||||
1019 | Assert(N.getTag() == dwarf::DW_TAG_module, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_module)) { CheckFailed ("invalid tag", &N); return; } } while (0); | |||||
1020 | Assert(!N.getName().empty(), "anonymous module", &N)do { if (!(!N.getName().empty())) { CheckFailed("anonymous module" , &N); return; } } while (0); | |||||
1021 | } | |||||
1022 | ||||||
1023 | void Verifier::visitDITemplateParameter(const DITemplateParameter &N) { | |||||
1024 | Assert(isTypeRef(N, N.getType()), "invalid type ref", &N, N.getType())do { if (!(isTypeRef(N, N.getType()))) { CheckFailed("invalid type ref" , &N, N.getType()); return; } } while (0); | |||||
1025 | } | |||||
1026 | ||||||
1027 | void Verifier::visitDITemplateTypeParameter(const DITemplateTypeParameter &N) { | |||||
1028 | visitDITemplateParameter(N); | |||||
1029 | ||||||
1030 | Assert(N.getTag() == dwarf::DW_TAG_template_type_parameter, "invalid tag",do { if (!(N.getTag() == dwarf::DW_TAG_template_type_parameter )) { CheckFailed("invalid tag", &N); return; } } while (0 ) | |||||
1031 | &N)do { if (!(N.getTag() == dwarf::DW_TAG_template_type_parameter )) { CheckFailed("invalid tag", &N); return; } } while (0 ); | |||||
1032 | } | |||||
1033 | ||||||
1034 | void Verifier::visitDITemplateValueParameter( | |||||
1035 | const DITemplateValueParameter &N) { | |||||
1036 | visitDITemplateParameter(N); | |||||
1037 | ||||||
1038 | Assert(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)) { CheckFailed ("invalid tag", &N); return; } } while (0) | |||||
1039 | 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)) { CheckFailed ("invalid tag", &N); return; } } while (0) | |||||
1040 | 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)) { CheckFailed ("invalid tag", &N); return; } } while (0) | |||||
1041 | "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)) { CheckFailed ("invalid tag", &N); return; } } while (0); | |||||
1042 | } | |||||
1043 | ||||||
1044 | void Verifier::visitDIVariable(const DIVariable &N) { | |||||
1045 | if (auto *S = N.getRawScope()) | |||||
1046 | Assert(isa<DIScope>(S), "invalid scope", &N, S)do { if (!(isa<DIScope>(S))) { CheckFailed("invalid scope" , &N, S); return; } } while (0); | |||||
1047 | Assert(isTypeRef(N, N.getRawType()), "invalid type ref", &N, N.getRawType())do { if (!(isTypeRef(N, N.getRawType()))) { CheckFailed("invalid type ref" , &N, N.getRawType()); return; } } while (0); | |||||
1048 | if (auto *F = N.getRawFile()) | |||||
1049 | Assert(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { CheckFailed("invalid file" , &N, F); return; } } while (0); | |||||
1050 | } | |||||
1051 | ||||||
1052 | void Verifier::visitDIGlobalVariable(const DIGlobalVariable &N) { | |||||
1053 | // Checks common to all variables. | |||||
1054 | visitDIVariable(N); | |||||
1055 | ||||||
1056 | Assert(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_variable)) { CheckFailed ("invalid tag", &N); return; } } while (0); | |||||
1057 | Assert(!N.getName().empty(), "missing global variable name", &N)do { if (!(!N.getName().empty())) { CheckFailed("missing global variable name" , &N); return; } } while (0); | |||||
1058 | if (auto *V = N.getRawVariable()) { | |||||
1059 | Assert(isa<ConstantAsMetadata>(V) &&do { if (!(isa<ConstantAsMetadata>(V) && !isa< Function>(cast<ConstantAsMetadata>(V)->getValue() ))) { CheckFailed("invalid global varaible ref", &N, V); return ; } } while (0) | |||||
1060 | !isa<Function>(cast<ConstantAsMetadata>(V)->getValue()),do { if (!(isa<ConstantAsMetadata>(V) && !isa< Function>(cast<ConstantAsMetadata>(V)->getValue() ))) { CheckFailed("invalid global varaible ref", &N, V); return ; } } while (0) | |||||
1061 | "invalid global varaible ref", &N, V)do { if (!(isa<ConstantAsMetadata>(V) && !isa< Function>(cast<ConstantAsMetadata>(V)->getValue() ))) { CheckFailed("invalid global varaible ref", &N, V); return ; } } while (0); | |||||
1062 | } | |||||
1063 | if (auto *Member = N.getRawStaticDataMemberDeclaration()) { | |||||
1064 | Assert(isa<DIDerivedType>(Member), "invalid static data member declaration",do { if (!(isa<DIDerivedType>(Member))) { CheckFailed("invalid static data member declaration" , &N, Member); return; } } while (0) | |||||
1065 | &N, Member)do { if (!(isa<DIDerivedType>(Member))) { CheckFailed("invalid static data member declaration" , &N, Member); return; } } while (0); | |||||
1066 | } | |||||
1067 | } | |||||
1068 | ||||||
1069 | void Verifier::visitDILocalVariable(const DILocalVariable &N) { | |||||
1070 | // Checks common to all variables. | |||||
1071 | visitDIVariable(N); | |||||
1072 | ||||||
1073 | Assert(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_variable)) { CheckFailed ("invalid tag", &N); return; } } while (0); | |||||
1074 | Assert(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { CheckFailed("local variable requires a valid scope" , &N, N.getRawScope()); return; } } while (0) | |||||
1075 | "local variable requires a valid scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { CheckFailed("local variable requires a valid scope" , &N, N.getRawScope()); return; } } while (0); | |||||
1076 | } | |||||
1077 | ||||||
1078 | void Verifier::visitDIExpression(const DIExpression &N) { | |||||
1079 | Assert(N.isValid(), "invalid expression", &N)do { if (!(N.isValid())) { CheckFailed("invalid expression", & N); return; } } while (0); | |||||
1080 | } | |||||
1081 | ||||||
1082 | void Verifier::visitDIObjCProperty(const DIObjCProperty &N) { | |||||
1083 | Assert(N.getTag() == dwarf::DW_TAG_APPLE_property, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_APPLE_property)) { CheckFailed ("invalid tag", &N); return; } } while (0); | |||||
1084 | if (auto *T = N.getRawType()) | |||||
1085 | Assert(isTypeRef(N, T), "invalid type ref", &N, T)do { if (!(isTypeRef(N, T))) { CheckFailed("invalid type ref" , &N, T); return; } } while (0); | |||||
1086 | if (auto *F = N.getRawFile()) | |||||
1087 | Assert(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { CheckFailed("invalid file" , &N, F); return; } } while (0); | |||||
1088 | } | |||||
1089 | ||||||
1090 | void Verifier::visitDIImportedEntity(const DIImportedEntity &N) { | |||||
1091 | Assert(N.getTag() == dwarf::DW_TAG_imported_module ||do { if (!(N.getTag() == dwarf::DW_TAG_imported_module || N.getTag () == dwarf::DW_TAG_imported_declaration)) { CheckFailed("invalid tag" , &N); return; } } while (0) | |||||
1092 | N.getTag() == dwarf::DW_TAG_imported_declaration,do { if (!(N.getTag() == dwarf::DW_TAG_imported_module || N.getTag () == dwarf::DW_TAG_imported_declaration)) { CheckFailed("invalid tag" , &N); return; } } while (0) | |||||
1093 | "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_imported_module || N.getTag () == dwarf::DW_TAG_imported_declaration)) { CheckFailed("invalid tag" , &N); return; } } while (0); | |||||
1094 | if (auto *S = N.getRawScope()) | |||||
1095 | Assert(isa<DIScope>(S), "invalid scope for imported entity", &N, S)do { if (!(isa<DIScope>(S))) { CheckFailed("invalid scope for imported entity" , &N, S); return; } } while (0); | |||||
1096 | Assert(isDIRef(N, N.getEntity()), "invalid imported entity", &N,do { if (!(isDIRef(N, N.getEntity()))) { CheckFailed("invalid imported entity" , &N, N.getEntity()); return; } } while (0) | |||||
1097 | N.getEntity())do { if (!(isDIRef(N, N.getEntity()))) { CheckFailed("invalid imported entity" , &N, N.getEntity()); return; } } while (0); | |||||
1098 | } | |||||
1099 | ||||||
1100 | void Verifier::visitComdat(const Comdat &C) { | |||||
1101 | // The Module is invalid if the GlobalValue has private linkage. Entities | |||||
1102 | // with private linkage don't have entries in the symbol table. | |||||
1103 | if (const GlobalValue *GV = M->getNamedValue(C.getName())) | |||||
1104 | Assert(!GV->hasPrivateLinkage(), "comdat global value has private linkage",do { if (!(!GV->hasPrivateLinkage())) { CheckFailed("comdat global value has private linkage" , GV); return; } } while (0) | |||||
1105 | GV)do { if (!(!GV->hasPrivateLinkage())) { CheckFailed("comdat global value has private linkage" , GV); return; } } while (0); | |||||
1106 | } | |||||
1107 | ||||||
1108 | void Verifier::visitModuleIdents(const Module &M) { | |||||
1109 | const NamedMDNode *Idents = M.getNamedMetadata("llvm.ident"); | |||||
1110 | if (!Idents) | |||||
1111 | return; | |||||
1112 | ||||||
1113 | // llvm.ident takes a list of metadata entry. Each entry has only one string. | |||||
1114 | // Scan each llvm.ident entry and make sure that this requirement is met. | |||||
1115 | for (unsigned i = 0, e = Idents->getNumOperands(); i != e; ++i) { | |||||
1116 | const MDNode *N = Idents->getOperand(i); | |||||
1117 | Assert(N->getNumOperands() == 1,do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.ident metadata" , N); return; } } while (0) | |||||
1118 | "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 (0); | |||||
1119 | 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 (0) | |||||
1120 | ("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 (0) | |||||
1121 | "(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 (0) | |||||
1122 | 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 (0); | |||||
1123 | } | |||||
1124 | } | |||||
1125 | ||||||
1126 | void Verifier::visitModuleFlags(const Module &M) { | |||||
1127 | const NamedMDNode *Flags = M.getModuleFlagsMetadata(); | |||||
1128 | if (!Flags) return; | |||||
1129 | ||||||
1130 | // Scan each flag, and track the flags and requirements. | |||||
1131 | DenseMap<const MDString*, const MDNode*> SeenIDs; | |||||
1132 | SmallVector<const MDNode*, 16> Requirements; | |||||
1133 | for (unsigned I = 0, E = Flags->getNumOperands(); I != E; ++I) { | |||||
1134 | visitModuleFlag(Flags->getOperand(I), SeenIDs, Requirements); | |||||
1135 | } | |||||
1136 | ||||||
1137 | // Validate that the requirements in the module are valid. | |||||
1138 | for (unsigned I = 0, E = Requirements.size(); I != E; ++I) { | |||||
1139 | const MDNode *Requirement = Requirements[I]; | |||||
1140 | const MDString *Flag = cast<MDString>(Requirement->getOperand(0)); | |||||
1141 | const Metadata *ReqValue = Requirement->getOperand(1); | |||||
1142 | ||||||
1143 | const MDNode *Op = SeenIDs.lookup(Flag); | |||||
1144 | if (!Op) { | |||||
1145 | CheckFailed("invalid requirement on flag, flag is not present in module", | |||||
1146 | Flag); | |||||
1147 | continue; | |||||
1148 | } | |||||
1149 | ||||||
1150 | if (Op->getOperand(2) != ReqValue) { | |||||
1151 | CheckFailed(("invalid requirement on flag, " | |||||
1152 | "flag does not have the required value"), | |||||
1153 | Flag); | |||||
1154 | continue; | |||||
1155 | } | |||||
1156 | } | |||||
1157 | } | |||||
1158 | ||||||
1159 | void | |||||
1160 | Verifier::visitModuleFlag(const MDNode *Op, | |||||
1161 | DenseMap<const MDString *, const MDNode *> &SeenIDs, | |||||
1162 | SmallVectorImpl<const MDNode *> &Requirements) { | |||||
1163 | // Each module flag should have three arguments, the merge behavior (a | |||||
1164 | // constant int), the flag ID (an MDString), and the value. | |||||
1165 | Assert(Op->getNumOperands() == 3,do { if (!(Op->getNumOperands() == 3)) { CheckFailed("incorrect number of operands in module flag" , Op); return; } } while (0) | |||||
1166 | "incorrect number of operands in module flag", Op)do { if (!(Op->getNumOperands() == 3)) { CheckFailed("incorrect number of operands in module flag" , Op); return; } } while (0); | |||||
1167 | Module::ModFlagBehavior MFB; | |||||
1168 | if (!Module::isValidModFlagBehavior(Op->getOperand(0), MFB)) { | |||||
1169 | 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 (0) | |||||
1170 | 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 (0) | |||||
1171 | "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 (0) | |||||
1172 | 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 (0); | |||||
1173 | Assert(false,do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)" , Op->getOperand(0)); return; } } while (0) | |||||
1174 | "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 (0) | |||||
1175 | Op->getOperand(0))do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)" , Op->getOperand(0)); return; } } while (0); | |||||
1176 | } | |||||
1177 | MDString *ID = dyn_cast_or_null<MDString>(Op->getOperand(1)); | |||||
1178 | 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 (0) | |||||
1179 | Op->getOperand(1))do { if (!(ID)) { CheckFailed("invalid ID operand in module flag (expected metadata string)" , Op->getOperand(1)); return; } } while (0); | |||||
1180 | ||||||
1181 | // Sanity check the values for behaviors with additional requirements. | |||||
1182 | switch (MFB) { | |||||
1183 | case Module::Error: | |||||
1184 | case Module::Warning: | |||||
1185 | case Module::Override: | |||||
1186 | // These behavior types accept any value. | |||||
1187 | break; | |||||
1188 | ||||||
1189 | case Module::Require: { | |||||
1190 | // The value should itself be an MDNode with two operands, a flag ID (an | |||||
1191 | // MDString), and a value. | |||||
1192 | MDNode *Value = dyn_cast<MDNode>(Op->getOperand(2)); | |||||
1193 | 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 (0) | |||||
1194 | "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 (0) | |||||
1195 | Op->getOperand(2))do { if (!(Value && Value->getNumOperands() == 2)) { CheckFailed("invalid value for 'require' module flag (expected metadata pair)" , Op->getOperand(2)); return; } } while (0); | |||||
1196 | 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 (0) | |||||
1197 | ("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 (0) | |||||
1198 | "(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 (0) | |||||
1199 | 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 (0); | |||||
1200 | ||||||
1201 | // Append it to the list of requirements, to check once all module flags are | |||||
1202 | // scanned. | |||||
1203 | Requirements.push_back(Value); | |||||
1204 | break; | |||||
1205 | } | |||||
1206 | ||||||
1207 | case Module::Append: | |||||
1208 | case Module::AppendUnique: { | |||||
1209 | // These behavior types require the operand be an MDNode. | |||||
1210 | 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 (0) | |||||
1211 | "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 (0) | |||||
1212 | "(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 (0) | |||||
1213 | 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 (0); | |||||
1214 | break; | |||||
1215 | } | |||||
1216 | } | |||||
1217 | ||||||
1218 | // Unless this is a "requires" flag, check the ID is unique. | |||||
1219 | if (MFB != Module::Require) { | |||||
1220 | bool Inserted = SeenIDs.insert(std::make_pair(ID, Op)).second; | |||||
1221 | Assert(Inserted,do { if (!(Inserted)) { CheckFailed("module flag identifiers must be unique (or of 'require' type)" , ID); return; } } while (0) | |||||
1222 | "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 (0); | |||||
1223 | } | |||||
1224 | } | |||||
1225 | ||||||
1226 | void Verifier::VerifyAttributeTypes(AttributeSet Attrs, unsigned Idx, | |||||
1227 | bool isFunction, const Value *V) { | |||||
1228 | unsigned Slot = ~0U; | |||||
1229 | for (unsigned I = 0, E = Attrs.getNumSlots(); I != E; ++I) | |||||
1230 | if (Attrs.getSlotIndex(I) == Idx) { | |||||
1231 | Slot = I; | |||||
1232 | break; | |||||
1233 | } | |||||
1234 | ||||||
1235 | assert(Slot != ~0U && "Attribute set inconsistency!")((Slot != ~0U && "Attribute set inconsistency!") ? static_cast <void> (0) : __assert_fail ("Slot != ~0U && \"Attribute set inconsistency!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 1235, __PRETTY_FUNCTION__)); | |||||
1236 | ||||||
1237 | for (AttributeSet::iterator I = Attrs.begin(Slot), E = Attrs.end(Slot); | |||||
1238 | I != E; ++I) { | |||||
1239 | if (I->isStringAttribute()) | |||||
1240 | continue; | |||||
1241 | ||||||
1242 | if (I->getKindAsEnum() == Attribute::NoReturn || | |||||
1243 | I->getKindAsEnum() == Attribute::NoUnwind || | |||||
1244 | I->getKindAsEnum() == Attribute::NoInline || | |||||
1245 | I->getKindAsEnum() == Attribute::AlwaysInline || | |||||
1246 | I->getKindAsEnum() == Attribute::OptimizeForSize || | |||||
1247 | I->getKindAsEnum() == Attribute::StackProtect || | |||||
1248 | I->getKindAsEnum() == Attribute::StackProtectReq || | |||||
1249 | I->getKindAsEnum() == Attribute::StackProtectStrong || | |||||
1250 | I->getKindAsEnum() == Attribute::SafeStack || | |||||
1251 | I->getKindAsEnum() == Attribute::NoRedZone || | |||||
1252 | I->getKindAsEnum() == Attribute::NoImplicitFloat || | |||||
1253 | I->getKindAsEnum() == Attribute::Naked || | |||||
1254 | I->getKindAsEnum() == Attribute::InlineHint || | |||||
1255 | I->getKindAsEnum() == Attribute::StackAlignment || | |||||
1256 | I->getKindAsEnum() == Attribute::UWTable || | |||||
1257 | I->getKindAsEnum() == Attribute::NonLazyBind || | |||||
1258 | I->getKindAsEnum() == Attribute::ReturnsTwice || | |||||
1259 | I->getKindAsEnum() == Attribute::SanitizeAddress || | |||||
1260 | I->getKindAsEnum() == Attribute::SanitizeThread || | |||||
1261 | I->getKindAsEnum() == Attribute::SanitizeMemory || | |||||
1262 | I->getKindAsEnum() == Attribute::MinSize || | |||||
1263 | I->getKindAsEnum() == Attribute::NoDuplicate || | |||||
1264 | I->getKindAsEnum() == Attribute::Builtin || | |||||
1265 | I->getKindAsEnum() == Attribute::NoBuiltin || | |||||
1266 | I->getKindAsEnum() == Attribute::Cold || | |||||
1267 | I->getKindAsEnum() == Attribute::OptimizeNone || | |||||
1268 | I->getKindAsEnum() == Attribute::JumpTable || | |||||
1269 | I->getKindAsEnum() == Attribute::Convergent || | |||||
1270 | I->getKindAsEnum() == Attribute::ArgMemOnly) { | |||||
1271 | if (!isFunction) { | |||||
1272 | CheckFailed("Attribute '" + I->getAsString() + | |||||
1273 | "' only applies to functions!", V); | |||||
1274 | return; | |||||
1275 | } | |||||
1276 | } else if (I->getKindAsEnum() == Attribute::ReadOnly || | |||||
1277 | I->getKindAsEnum() == Attribute::ReadNone) { | |||||
1278 | if (Idx == 0) { | |||||
1279 | CheckFailed("Attribute '" + I->getAsString() + | |||||
1280 | "' does not apply to function returns"); | |||||
1281 | return; | |||||
1282 | } | |||||
1283 | } else if (isFunction) { | |||||
1284 | CheckFailed("Attribute '" + I->getAsString() + | |||||
1285 | "' does not apply to functions!", V); | |||||
1286 | return; | |||||
1287 | } | |||||
1288 | } | |||||
1289 | } | |||||
1290 | ||||||
1291 | // VerifyParameterAttrs - Check the given attributes for an argument or return | |||||
1292 | // value of the specified type. The value V is printed in error messages. | |||||
1293 | void Verifier::VerifyParameterAttrs(AttributeSet Attrs, unsigned Idx, Type *Ty, | |||||
1294 | bool isReturnValue, const Value *V) { | |||||
1295 | if (!Attrs.hasAttributes(Idx)) | |||||
1296 | return; | |||||
1297 | ||||||
1298 | VerifyAttributeTypes(Attrs, Idx, false, V); | |||||
1299 | ||||||
1300 | if (isReturnValue) | |||||
1301 | Assert(!Attrs.hasAttribute(Idx, Attribute::ByVal) &&do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal) && !Attrs.hasAttribute(Idx, Attribute::Nest) && !Attrs. hasAttribute(Idx, Attribute::StructRet) && !Attrs.hasAttribute (Idx, Attribute::NoCapture) && !Attrs.hasAttribute(Idx , Attribute::Returned) && !Attrs.hasAttribute(Idx, Attribute ::InAlloca))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', and " "'returned' do not apply to return values!", V); return; } } while (0) | |||||
1302 | !Attrs.hasAttribute(Idx, Attribute::Nest) &&do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal) && !Attrs.hasAttribute(Idx, Attribute::Nest) && !Attrs. hasAttribute(Idx, Attribute::StructRet) && !Attrs.hasAttribute (Idx, Attribute::NoCapture) && !Attrs.hasAttribute(Idx , Attribute::Returned) && !Attrs.hasAttribute(Idx, Attribute ::InAlloca))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', and " "'returned' do not apply to return values!", V); return; } } while (0) | |||||
1303 | !Attrs.hasAttribute(Idx, Attribute::StructRet) &&do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal) && !Attrs.hasAttribute(Idx, Attribute::Nest) && !Attrs. hasAttribute(Idx, Attribute::StructRet) && !Attrs.hasAttribute (Idx, Attribute::NoCapture) && !Attrs.hasAttribute(Idx , Attribute::Returned) && !Attrs.hasAttribute(Idx, Attribute ::InAlloca))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', and " "'returned' do not apply to return values!", V); return; } } while (0) | |||||
1304 | !Attrs.hasAttribute(Idx, Attribute::NoCapture) &&do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal) && !Attrs.hasAttribute(Idx, Attribute::Nest) && !Attrs. hasAttribute(Idx, Attribute::StructRet) && !Attrs.hasAttribute (Idx, Attribute::NoCapture) && !Attrs.hasAttribute(Idx , Attribute::Returned) && !Attrs.hasAttribute(Idx, Attribute ::InAlloca))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', and " "'returned' do not apply to return values!", V); return; } } while (0) | |||||
1305 | !Attrs.hasAttribute(Idx, Attribute::Returned) &&do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal) && !Attrs.hasAttribute(Idx, Attribute::Nest) && !Attrs. hasAttribute(Idx, Attribute::StructRet) && !Attrs.hasAttribute (Idx, Attribute::NoCapture) && !Attrs.hasAttribute(Idx , Attribute::Returned) && !Attrs.hasAttribute(Idx, Attribute ::InAlloca))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', and " "'returned' do not apply to return values!", V); return; } } while (0) | |||||
1306 | !Attrs.hasAttribute(Idx, Attribute::InAlloca),do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal) && !Attrs.hasAttribute(Idx, Attribute::Nest) && !Attrs. hasAttribute(Idx, Attribute::StructRet) && !Attrs.hasAttribute (Idx, Attribute::NoCapture) && !Attrs.hasAttribute(Idx , Attribute::Returned) && !Attrs.hasAttribute(Idx, Attribute ::InAlloca))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', and " "'returned' do not apply to return values!", V); return; } } while (0) | |||||
1307 | "Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', and "do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal) && !Attrs.hasAttribute(Idx, Attribute::Nest) && !Attrs. hasAttribute(Idx, Attribute::StructRet) && !Attrs.hasAttribute (Idx, Attribute::NoCapture) && !Attrs.hasAttribute(Idx , Attribute::Returned) && !Attrs.hasAttribute(Idx, Attribute ::InAlloca))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', and " "'returned' do not apply to return values!", V); return; } } while (0) | |||||
1308 | "'returned' do not apply to return values!",do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal) && !Attrs.hasAttribute(Idx, Attribute::Nest) && !Attrs. hasAttribute(Idx, Attribute::StructRet) && !Attrs.hasAttribute (Idx, Attribute::NoCapture) && !Attrs.hasAttribute(Idx , Attribute::Returned) && !Attrs.hasAttribute(Idx, Attribute ::InAlloca))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', and " "'returned' do not apply to return values!", V); return; } } while (0) | |||||
1309 | V)do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal) && !Attrs.hasAttribute(Idx, Attribute::Nest) && !Attrs. hasAttribute(Idx, Attribute::StructRet) && !Attrs.hasAttribute (Idx, Attribute::NoCapture) && !Attrs.hasAttribute(Idx , Attribute::Returned) && !Attrs.hasAttribute(Idx, Attribute ::InAlloca))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', and " "'returned' do not apply to return values!", V); return; } } while (0); | |||||
1310 | ||||||
1311 | // Check for mutually incompatible attributes. Only inreg is compatible with | |||||
1312 | // sret. | |||||
1313 | unsigned AttrCount = 0; | |||||
1314 | AttrCount += Attrs.hasAttribute(Idx, Attribute::ByVal); | |||||
1315 | AttrCount += Attrs.hasAttribute(Idx, Attribute::InAlloca); | |||||
1316 | AttrCount += Attrs.hasAttribute(Idx, Attribute::StructRet) || | |||||
1317 | Attrs.hasAttribute(Idx, Attribute::InReg); | |||||
1318 | AttrCount += Attrs.hasAttribute(Idx, Attribute::Nest); | |||||
1319 | 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 (0) | |||||
1320 | "and 'sret' are incompatible!",do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'inreg', 'nest', " "and 'sret' are incompatible!", V); return; } } while (0) | |||||
1321 | V)do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'inreg', 'nest', " "and 'sret' are incompatible!", V); return; } } while (0); | |||||
1322 | ||||||
1323 | Assert(!(Attrs.hasAttribute(Idx, Attribute::InAlloca) &&do { if (!(!(Attrs.hasAttribute(Idx, Attribute::InAlloca) && Attrs.hasAttribute(Idx, Attribute::ReadOnly)))) { CheckFailed ("Attributes " "'inalloca and readonly' are incompatible!", V ); return; } } while (0) | |||||
1324 | Attrs.hasAttribute(Idx, Attribute::ReadOnly)),do { if (!(!(Attrs.hasAttribute(Idx, Attribute::InAlloca) && Attrs.hasAttribute(Idx, Attribute::ReadOnly)))) { CheckFailed ("Attributes " "'inalloca and readonly' are incompatible!", V ); return; } } while (0) | |||||
1325 | "Attributes "do { if (!(!(Attrs.hasAttribute(Idx, Attribute::InAlloca) && Attrs.hasAttribute(Idx, Attribute::ReadOnly)))) { CheckFailed ("Attributes " "'inalloca and readonly' are incompatible!", V ); return; } } while (0) | |||||
1326 | "'inalloca and readonly' are incompatible!",do { if (!(!(Attrs.hasAttribute(Idx, Attribute::InAlloca) && Attrs.hasAttribute(Idx, Attribute::ReadOnly)))) { CheckFailed ("Attributes " "'inalloca and readonly' are incompatible!", V ); return; } } while (0) | |||||
1327 | V)do { if (!(!(Attrs.hasAttribute(Idx, Attribute::InAlloca) && Attrs.hasAttribute(Idx, Attribute::ReadOnly)))) { CheckFailed ("Attributes " "'inalloca and readonly' are incompatible!", V ); return; } } while (0); | |||||
1328 | ||||||
1329 | Assert(!(Attrs.hasAttribute(Idx, Attribute::StructRet) &&do { if (!(!(Attrs.hasAttribute(Idx, Attribute::StructRet) && Attrs.hasAttribute(Idx, Attribute::Returned)))) { CheckFailed ("Attributes " "'sret and returned' are incompatible!", V); return ; } } while (0) | |||||
1330 | Attrs.hasAttribute(Idx, Attribute::Returned)),do { if (!(!(Attrs.hasAttribute(Idx, Attribute::StructRet) && Attrs.hasAttribute(Idx, Attribute::Returned)))) { CheckFailed ("Attributes " "'sret and returned' are incompatible!", V); return ; } } while (0) | |||||
1331 | "Attributes "do { if (!(!(Attrs.hasAttribute(Idx, Attribute::StructRet) && Attrs.hasAttribute(Idx, Attribute::Returned)))) { CheckFailed ("Attributes " "'sret and returned' are incompatible!", V); return ; } } while (0) | |||||
1332 | "'sret and returned' are incompatible!",do { if (!(!(Attrs.hasAttribute(Idx, Attribute::StructRet) && Attrs.hasAttribute(Idx, Attribute::Returned)))) { CheckFailed ("Attributes " "'sret and returned' are incompatible!", V); return ; } } while (0) | |||||
1333 | V)do { if (!(!(Attrs.hasAttribute(Idx, Attribute::StructRet) && Attrs.hasAttribute(Idx, Attribute::Returned)))) { CheckFailed ("Attributes " "'sret and returned' are incompatible!", V); return ; } } while (0); | |||||
1334 | ||||||
1335 | Assert(!(Attrs.hasAttribute(Idx, Attribute::ZExt) &&do { if (!(!(Attrs.hasAttribute(Idx, Attribute::ZExt) && Attrs.hasAttribute(Idx, Attribute::SExt)))) { CheckFailed("Attributes " "'zeroext and signext' are incompatible!", V); return; } } while (0) | |||||
1336 | Attrs.hasAttribute(Idx, Attribute::SExt)),do { if (!(!(Attrs.hasAttribute(Idx, Attribute::ZExt) && Attrs.hasAttribute(Idx, Attribute::SExt)))) { CheckFailed("Attributes " "'zeroext and signext' are incompatible!", V); return; } } while (0) | |||||
1337 | "Attributes "do { if (!(!(Attrs.hasAttribute(Idx, Attribute::ZExt) && Attrs.hasAttribute(Idx, Attribute::SExt)))) { CheckFailed("Attributes " "'zeroext and signext' are incompatible!", V); return; } } while (0) | |||||
1338 | "'zeroext and signext' are incompatible!",do { if (!(!(Attrs.hasAttribute(Idx, Attribute::ZExt) && Attrs.hasAttribute(Idx, Attribute::SExt)))) { CheckFailed("Attributes " "'zeroext and signext' are incompatible!", V); return; } } while (0) | |||||
1339 | V)do { if (!(!(Attrs.hasAttribute(Idx, Attribute::ZExt) && Attrs.hasAttribute(Idx, Attribute::SExt)))) { CheckFailed("Attributes " "'zeroext and signext' are incompatible!", V); return; } } while (0); | |||||
1340 | ||||||
1341 | Assert(!(Attrs.hasAttribute(Idx, Attribute::ReadNone) &&do { if (!(!(Attrs.hasAttribute(Idx, Attribute::ReadNone) && Attrs.hasAttribute(Idx, Attribute::ReadOnly)))) { CheckFailed ("Attributes " "'readnone and readonly' are incompatible!", V ); return; } } while (0) | |||||
1342 | Attrs.hasAttribute(Idx, Attribute::ReadOnly)),do { if (!(!(Attrs.hasAttribute(Idx, Attribute::ReadNone) && Attrs.hasAttribute(Idx, Attribute::ReadOnly)))) { CheckFailed ("Attributes " "'readnone and readonly' are incompatible!", V ); return; } } while (0) | |||||
1343 | "Attributes "do { if (!(!(Attrs.hasAttribute(Idx, Attribute::ReadNone) && Attrs.hasAttribute(Idx, Attribute::ReadOnly)))) { CheckFailed ("Attributes " "'readnone and readonly' are incompatible!", V ); return; } } while (0) | |||||
1344 | "'readnone and readonly' are incompatible!",do { if (!(!(Attrs.hasAttribute(Idx, Attribute::ReadNone) && Attrs.hasAttribute(Idx, Attribute::ReadOnly)))) { CheckFailed ("Attributes " "'readnone and readonly' are incompatible!", V ); return; } } while (0) | |||||
1345 | V)do { if (!(!(Attrs.hasAttribute(Idx, Attribute::ReadNone) && Attrs.hasAttribute(Idx, Attribute::ReadOnly)))) { CheckFailed ("Attributes " "'readnone and readonly' are incompatible!", V ); return; } } while (0); | |||||
1346 | ||||||
1347 | Assert(!(Attrs.hasAttribute(Idx, Attribute::NoInline) &&do { if (!(!(Attrs.hasAttribute(Idx, Attribute::NoInline) && Attrs.hasAttribute(Idx, Attribute::AlwaysInline)))) { CheckFailed ("Attributes " "'noinline and alwaysinline' are incompatible!" , V); return; } } while (0) | |||||
1348 | Attrs.hasAttribute(Idx, Attribute::AlwaysInline)),do { if (!(!(Attrs.hasAttribute(Idx, Attribute::NoInline) && Attrs.hasAttribute(Idx, Attribute::AlwaysInline)))) { CheckFailed ("Attributes " "'noinline and alwaysinline' are incompatible!" , V); return; } } while (0) | |||||
1349 | "Attributes "do { if (!(!(Attrs.hasAttribute(Idx, Attribute::NoInline) && Attrs.hasAttribute(Idx, Attribute::AlwaysInline)))) { CheckFailed ("Attributes " "'noinline and alwaysinline' are incompatible!" , V); return; } } while (0) | |||||
1350 | "'noinline and alwaysinline' are incompatible!",do { if (!(!(Attrs.hasAttribute(Idx, Attribute::NoInline) && Attrs.hasAttribute(Idx, Attribute::AlwaysInline)))) { CheckFailed ("Attributes " "'noinline and alwaysinline' are incompatible!" , V); return; } } while (0) | |||||
1351 | V)do { if (!(!(Attrs.hasAttribute(Idx, Attribute::NoInline) && Attrs.hasAttribute(Idx, Attribute::AlwaysInline)))) { CheckFailed ("Attributes " "'noinline and alwaysinline' are incompatible!" , V); return; } } while (0); | |||||
1352 | ||||||
1353 | Assert(!AttrBuilder(Attrs, Idx)do { if (!(!AttrBuilder(Attrs, Idx) .overlaps(AttributeFuncs:: typeIncompatible(Ty)))) { CheckFailed("Wrong types for attribute: " + AttributeSet::get(*Context, Idx, AttributeFuncs::typeIncompatible (Ty)).getAsString(Idx), V); return; } } while (0) | |||||
1354 | .overlaps(AttributeFuncs::typeIncompatible(Ty)),do { if (!(!AttrBuilder(Attrs, Idx) .overlaps(AttributeFuncs:: typeIncompatible(Ty)))) { CheckFailed("Wrong types for attribute: " + AttributeSet::get(*Context, Idx, AttributeFuncs::typeIncompatible (Ty)).getAsString(Idx), V); return; } } while (0) | |||||
1355 | "Wrong types for attribute: " +do { if (!(!AttrBuilder(Attrs, Idx) .overlaps(AttributeFuncs:: typeIncompatible(Ty)))) { CheckFailed("Wrong types for attribute: " + AttributeSet::get(*Context, Idx, AttributeFuncs::typeIncompatible (Ty)).getAsString(Idx), V); return; } } while (0) | |||||
1356 | AttributeSet::get(*Context, Idx,do { if (!(!AttrBuilder(Attrs, Idx) .overlaps(AttributeFuncs:: typeIncompatible(Ty)))) { CheckFailed("Wrong types for attribute: " + AttributeSet::get(*Context, Idx, AttributeFuncs::typeIncompatible (Ty)).getAsString(Idx), V); return; } } while (0) | |||||
1357 | AttributeFuncs::typeIncompatible(Ty)).getAsString(Idx),do { if (!(!AttrBuilder(Attrs, Idx) .overlaps(AttributeFuncs:: typeIncompatible(Ty)))) { CheckFailed("Wrong types for attribute: " + AttributeSet::get(*Context, Idx, AttributeFuncs::typeIncompatible (Ty)).getAsString(Idx), V); return; } } while (0) | |||||
1358 | V)do { if (!(!AttrBuilder(Attrs, Idx) .overlaps(AttributeFuncs:: typeIncompatible(Ty)))) { CheckFailed("Wrong types for attribute: " + AttributeSet::get(*Context, Idx, AttributeFuncs::typeIncompatible (Ty)).getAsString(Idx), V); return; } } while (0); | |||||
1359 | ||||||
1360 | if (PointerType *PTy = dyn_cast<PointerType>(Ty)) { | |||||
1361 | SmallPtrSet<Type*, 4> Visited; | |||||
1362 | if (!PTy->getElementType()->isSized(&Visited)) { | |||||
1363 | Assert(!Attrs.hasAttribute(Idx, Attribute::ByVal) &&do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal) && !Attrs.hasAttribute(Idx, Attribute::InAlloca))) { CheckFailed ("Attributes 'byval' and 'inalloca' do not support unsized types!" , V); return; } } while (0) | |||||
1364 | !Attrs.hasAttribute(Idx, Attribute::InAlloca),do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal) && !Attrs.hasAttribute(Idx, Attribute::InAlloca))) { CheckFailed ("Attributes 'byval' and 'inalloca' do not support unsized types!" , V); return; } } while (0) | |||||
1365 | "Attributes 'byval' and 'inalloca' do not support unsized types!",do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal) && !Attrs.hasAttribute(Idx, Attribute::InAlloca))) { CheckFailed ("Attributes 'byval' and 'inalloca' do not support unsized types!" , V); return; } } while (0) | |||||
1366 | V)do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal) && !Attrs.hasAttribute(Idx, Attribute::InAlloca))) { CheckFailed ("Attributes 'byval' and 'inalloca' do not support unsized types!" , V); return; } } while (0); | |||||
1367 | } | |||||
1368 | } else { | |||||
1369 | Assert(!Attrs.hasAttribute(Idx, Attribute::ByVal),do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal))) { CheckFailed ("Attribute 'byval' only applies to parameters with pointer type!" , V); return; } } while (0) | |||||
1370 | "Attribute 'byval' only applies to parameters with pointer type!",do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal))) { CheckFailed ("Attribute 'byval' only applies to parameters with pointer type!" , V); return; } } while (0) | |||||
1371 | V)do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal))) { CheckFailed ("Attribute 'byval' only applies to parameters with pointer type!" , V); return; } } while (0); | |||||
1372 | } | |||||
1373 | } | |||||
1374 | ||||||
1375 | // VerifyFunctionAttrs - Check parameter attributes against a function type. | |||||
1376 | // The value V is printed in error messages. | |||||
1377 | void Verifier::VerifyFunctionAttrs(FunctionType *FT, AttributeSet Attrs, | |||||
1378 | const Value *V) { | |||||
1379 | if (Attrs.isEmpty()) | |||||
1380 | return; | |||||
1381 | ||||||
1382 | bool SawNest = false; | |||||
1383 | bool SawReturned = false; | |||||
1384 | bool SawSRet = false; | |||||
1385 | ||||||
1386 | for (unsigned i = 0, e = Attrs.getNumSlots(); i != e; ++i) { | |||||
1387 | unsigned Idx = Attrs.getSlotIndex(i); | |||||
1388 | ||||||
1389 | Type *Ty; | |||||
1390 | if (Idx == 0) | |||||
1391 | Ty = FT->getReturnType(); | |||||
1392 | else if (Idx-1 < FT->getNumParams()) | |||||
1393 | Ty = FT->getParamType(Idx-1); | |||||
1394 | else | |||||
1395 | break; // VarArgs attributes, verified elsewhere. | |||||
1396 | ||||||
1397 | VerifyParameterAttrs(Attrs, Idx, Ty, Idx == 0, V); | |||||
1398 | ||||||
1399 | if (Idx == 0) | |||||
1400 | continue; | |||||
1401 | ||||||
1402 | if (Attrs.hasAttribute(Idx, Attribute::Nest)) { | |||||
1403 | Assert(!SawNest, "More than one parameter has attribute nest!", V)do { if (!(!SawNest)) { CheckFailed("More than one parameter has attribute nest!" , V); return; } } while (0); | |||||
1404 | SawNest = true; | |||||
1405 | } | |||||
1406 | ||||||
1407 | if (Attrs.hasAttribute(Idx, Attribute::Returned)) { | |||||
1408 | Assert(!SawReturned, "More than one parameter has attribute returned!",do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!" , V); return; } } while (0) | |||||
1409 | V)do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!" , V); return; } } while (0); | |||||
1410 | Assert(Ty->canLosslesslyBitCastTo(FT->getReturnType()),do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType ()))) { CheckFailed("Incompatible " "argument and return types for 'returned' attribute" , V); return; } } while (0) | |||||
1411 | "Incompatible "do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType ()))) { CheckFailed("Incompatible " "argument and return types for 'returned' attribute" , V); return; } } while (0) | |||||
1412 | "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 (0) | |||||
1413 | V)do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType ()))) { CheckFailed("Incompatible " "argument and return types for 'returned' attribute" , V); return; } } while (0); | |||||
1414 | SawReturned = true; | |||||
1415 | } | |||||
1416 | ||||||
1417 | if (Attrs.hasAttribute(Idx, Attribute::StructRet)) { | |||||
1418 | Assert(!SawSRet, "Cannot have multiple 'sret' parameters!", V)do { if (!(!SawSRet)) { CheckFailed("Cannot have multiple 'sret' parameters!" , V); return; } } while (0); | |||||
1419 | Assert(Idx == 1 || Idx == 2,do { if (!(Idx == 1 || Idx == 2)) { CheckFailed("Attribute 'sret' is not on first or second parameter!" , V); return; } } while (0) | |||||
1420 | "Attribute 'sret' is not on first or second parameter!", V)do { if (!(Idx == 1 || Idx == 2)) { CheckFailed("Attribute 'sret' is not on first or second parameter!" , V); return; } } while (0); | |||||
1421 | SawSRet = true; | |||||
1422 | } | |||||
1423 | ||||||
1424 | if (Attrs.hasAttribute(Idx, Attribute::InAlloca)) { | |||||
1425 | Assert(Idx == FT->getNumParams(), "inalloca isn't on the last parameter!",do { if (!(Idx == FT->getNumParams())) { CheckFailed("inalloca isn't on the last parameter!" , V); return; } } while (0) | |||||
1426 | V)do { if (!(Idx == FT->getNumParams())) { CheckFailed("inalloca isn't on the last parameter!" , V); return; } } while (0); | |||||
1427 | } | |||||
1428 | } | |||||
1429 | ||||||
1430 | if (!Attrs.hasAttributes(AttributeSet::FunctionIndex)) | |||||
1431 | return; | |||||
1432 | ||||||
1433 | VerifyAttributeTypes(Attrs, AttributeSet::FunctionIndex, true, V); | |||||
1434 | ||||||
1435 | Assert(do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::ReadNone) && Attrs.hasAttribute(AttributeSet::FunctionIndex , Attribute::ReadOnly)))) { CheckFailed("Attributes 'readnone and readonly' are incompatible!" , V); return; } } while (0) | |||||
1436 | !(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone) &&do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::ReadNone) && Attrs.hasAttribute(AttributeSet::FunctionIndex , Attribute::ReadOnly)))) { CheckFailed("Attributes 'readnone and readonly' are incompatible!" , V); return; } } while (0) | |||||
1437 | Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly)),do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::ReadNone) && Attrs.hasAttribute(AttributeSet::FunctionIndex , Attribute::ReadOnly)))) { CheckFailed("Attributes 'readnone and readonly' are incompatible!" , V); return; } } while (0) | |||||
1438 | "Attributes 'readnone and readonly' are incompatible!", V)do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::ReadNone) && Attrs.hasAttribute(AttributeSet::FunctionIndex , Attribute::ReadOnly)))) { CheckFailed("Attributes 'readnone and readonly' are incompatible!" , V); return; } } while (0); | |||||
1439 | ||||||
1440 | Assert(do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::NoInline) && Attrs.hasAttribute(AttributeSet::FunctionIndex , Attribute::AlwaysInline)))) { CheckFailed("Attributes 'noinline and alwaysinline' are incompatible!" , V); return; } } while (0) | |||||
1441 | !(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute::NoInline) &&do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::NoInline) && Attrs.hasAttribute(AttributeSet::FunctionIndex , Attribute::AlwaysInline)))) { CheckFailed("Attributes 'noinline and alwaysinline' are incompatible!" , V); return; } } while (0) | |||||
1442 | Attrs.hasAttribute(AttributeSet::FunctionIndex,do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::NoInline) && Attrs.hasAttribute(AttributeSet::FunctionIndex , Attribute::AlwaysInline)))) { CheckFailed("Attributes 'noinline and alwaysinline' are incompatible!" , V); return; } } while (0) | |||||
1443 | Attribute::AlwaysInline)),do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::NoInline) && Attrs.hasAttribute(AttributeSet::FunctionIndex , Attribute::AlwaysInline)))) { CheckFailed("Attributes 'noinline and alwaysinline' are incompatible!" , V); return; } } while (0) | |||||
1444 | "Attributes 'noinline and alwaysinline' are incompatible!", V)do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::NoInline) && Attrs.hasAttribute(AttributeSet::FunctionIndex , Attribute::AlwaysInline)))) { CheckFailed("Attributes 'noinline and alwaysinline' are incompatible!" , V); return; } } while (0); | |||||
1445 | ||||||
1446 | if (Attrs.hasAttribute(AttributeSet::FunctionIndex, | |||||
1447 | Attribute::OptimizeNone)) { | |||||
1448 | Assert(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute::NoInline),do { if (!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::NoInline))) { CheckFailed("Attribute 'optnone' requires 'noinline'!" , V); return; } } while (0) | |||||
1449 | "Attribute 'optnone' requires 'noinline'!", V)do { if (!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::NoInline))) { CheckFailed("Attribute 'optnone' requires 'noinline'!" , V); return; } } while (0); | |||||
1450 | ||||||
1451 | Assert(!Attrs.hasAttribute(AttributeSet::FunctionIndex,do { if (!(!Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::OptimizeForSize))) { CheckFailed("Attributes 'optsize and optnone' are incompatible!" , V); return; } } while (0) | |||||
1452 | Attribute::OptimizeForSize),do { if (!(!Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::OptimizeForSize))) { CheckFailed("Attributes 'optsize and optnone' are incompatible!" , V); return; } } while (0) | |||||
1453 | "Attributes 'optsize and optnone' are incompatible!", V)do { if (!(!Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::OptimizeForSize))) { CheckFailed("Attributes 'optsize and optnone' are incompatible!" , V); return; } } while (0); | |||||
1454 | ||||||
1455 | Assert(!Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute::MinSize),do { if (!(!Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::MinSize))) { CheckFailed("Attributes 'minsize and optnone' are incompatible!" , V); return; } } while (0) | |||||
1456 | "Attributes 'minsize and optnone' are incompatible!", V)do { if (!(!Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::MinSize))) { CheckFailed("Attributes 'minsize and optnone' are incompatible!" , V); return; } } while (0); | |||||
1457 | } | |||||
1458 | ||||||
1459 | if (Attrs.hasAttribute(AttributeSet::FunctionIndex, | |||||
1460 | Attribute::JumpTable)) { | |||||
1461 | const GlobalValue *GV = cast<GlobalValue>(V); | |||||
1462 | Assert(GV->hasUnnamedAddr(),do { if (!(GV->hasUnnamedAddr())) { CheckFailed("Attribute 'jumptable' requires 'unnamed_addr'" , V); return; } } while (0) | |||||
1463 | "Attribute 'jumptable' requires 'unnamed_addr'", V)do { if (!(GV->hasUnnamedAddr())) { CheckFailed("Attribute 'jumptable' requires 'unnamed_addr'" , V); return; } } while (0); | |||||
1464 | } | |||||
1465 | } | |||||
1466 | ||||||
1467 | void Verifier::VerifyFunctionMetadata( | |||||
1468 | const SmallVector<std::pair<unsigned, MDNode *>, 4> MDs) { | |||||
1469 | if (MDs.empty()) | |||||
1470 | return; | |||||
1471 | ||||||
1472 | for (unsigned i = 0; i < MDs.size(); i++) { | |||||
1473 | if (MDs[i].first == LLVMContext::MD_prof) { | |||||
1474 | MDNode *MD = MDs[i].second; | |||||
1475 | Assert(MD->getNumOperands() == 2,do { if (!(MD->getNumOperands() == 2)) { CheckFailed("!prof annotations should have exactly 2 operands" , MD); return; } } while (0) | |||||
1476 | "!prof annotations should have exactly 2 operands", MD)do { if (!(MD->getNumOperands() == 2)) { CheckFailed("!prof annotations should have exactly 2 operands" , MD); return; } } while (0); | |||||
1477 | ||||||
1478 | // Check first operand. | |||||
1479 | 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 (0) | |||||
1480 | MD)do { if (!(MD->getOperand(0) != nullptr)) { CheckFailed("first operand should not be null" , MD); return; } } while (0); | |||||
1481 | 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 (0) | |||||
1482 | "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 (0); | |||||
1483 | MDString *MDS = cast<MDString>(MD->getOperand(0)); | |||||
1484 | StringRef ProfName = MDS->getString(); | |||||
1485 | Assert(ProfName.equals("function_entry_count"),do { if (!(ProfName.equals("function_entry_count"))) { CheckFailed ("first operand should be 'function_entry_count'", MD); return ; } } while (0) | |||||
1486 | "first operand should be 'function_entry_count'", MD)do { if (!(ProfName.equals("function_entry_count"))) { CheckFailed ("first operand should be 'function_entry_count'", MD); return ; } } while (0); | |||||
1487 | ||||||
1488 | // Check second operand. | |||||
1489 | 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 (0) | |||||
1490 | MD)do { if (!(MD->getOperand(1) != nullptr)) { CheckFailed("second operand should not be null" , MD); return; } } while (0); | |||||
1491 | Assert(isa<ConstantAsMetadata>(MD->getOperand(1)),do { if (!(isa<ConstantAsMetadata>(MD->getOperand(1) ))) { CheckFailed("expected integer argument to function_entry_count" , MD); return; } } while (0) | |||||
1492 | "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 (0); | |||||
1493 | } | |||||
1494 | } | |||||
1495 | } | |||||
1496 | ||||||
1497 | void Verifier::VerifyConstantExprBitcastType(const ConstantExpr *CE) { | |||||
1498 | if (CE->getOpcode() != Instruction::BitCast) | |||||
1499 | return; | |||||
1500 | ||||||
1501 | 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 (0) | |||||
1502 | CE->getType()),do { if (!(CastInst::castIsValid(Instruction::BitCast, CE-> getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast" , CE); return; } } while (0) | |||||
1503 | "Invalid bitcast", CE)do { if (!(CastInst::castIsValid(Instruction::BitCast, CE-> getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast" , CE); return; } } while (0); | |||||
1504 | } | |||||
1505 | ||||||
1506 | bool Verifier::VerifyAttributeCount(AttributeSet Attrs, unsigned Params) { | |||||
1507 | if (Attrs.getNumSlots() == 0) | |||||
1508 | return true; | |||||
1509 | ||||||
1510 | unsigned LastSlot = Attrs.getNumSlots() - 1; | |||||
1511 | unsigned LastIndex = Attrs.getSlotIndex(LastSlot); | |||||
1512 | if (LastIndex <= Params | |||||
1513 | || (LastIndex == AttributeSet::FunctionIndex | |||||
1514 | && (LastSlot == 0 || Attrs.getSlotIndex(LastSlot - 1) <= Params))) | |||||
1515 | return true; | |||||
1516 | ||||||
1517 | return false; | |||||
1518 | } | |||||
1519 | ||||||
1520 | /// \brief Verify that statepoint intrinsic is well formed. | |||||
1521 | void Verifier::VerifyStatepoint(ImmutableCallSite CS) { | |||||
1522 | assert(CS.getCalledFunction() &&((CS.getCalledFunction() && CS.getCalledFunction()-> getIntrinsicID() == Intrinsic::experimental_gc_statepoint) ? static_cast <void> (0) : __assert_fail ("CS.getCalledFunction() && CS.getCalledFunction()->getIntrinsicID() == Intrinsic::experimental_gc_statepoint" , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 1524, __PRETTY_FUNCTION__)) | |||||
1523 | CS.getCalledFunction()->getIntrinsicID() ==((CS.getCalledFunction() && CS.getCalledFunction()-> getIntrinsicID() == Intrinsic::experimental_gc_statepoint) ? static_cast <void> (0) : __assert_fail ("CS.getCalledFunction() && CS.getCalledFunction()->getIntrinsicID() == Intrinsic::experimental_gc_statepoint" , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 1524, __PRETTY_FUNCTION__)) | |||||
1524 | Intrinsic::experimental_gc_statepoint)((CS.getCalledFunction() && CS.getCalledFunction()-> getIntrinsicID() == Intrinsic::experimental_gc_statepoint) ? static_cast <void> (0) : __assert_fail ("CS.getCalledFunction() && CS.getCalledFunction()->getIntrinsicID() == Intrinsic::experimental_gc_statepoint" , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 1524, __PRETTY_FUNCTION__)); | |||||
1525 | ||||||
1526 | const Instruction &CI = *CS.getInstruction(); | |||||
1527 | ||||||
1528 | Assert(!CS.doesNotAccessMemory() && !CS.onlyReadsMemory() &&do { if (!(!CS.doesNotAccessMemory() && !CS.onlyReadsMemory () && !CS.onlyAccessesArgMemory())) { CheckFailed("gc.statepoint must read and write all memory to preserve " "reordering restrictions required by safepoint semantics", & CI); return; } } while (0) | |||||
1529 | !CS.onlyAccessesArgMemory(),do { if (!(!CS.doesNotAccessMemory() && !CS.onlyReadsMemory () && !CS.onlyAccessesArgMemory())) { CheckFailed("gc.statepoint must read and write all memory to preserve " "reordering restrictions required by safepoint semantics", & CI); return; } } while (0) | |||||
1530 | "gc.statepoint must read and write all memory to preserve "do { if (!(!CS.doesNotAccessMemory() && !CS.onlyReadsMemory () && !CS.onlyAccessesArgMemory())) { CheckFailed("gc.statepoint must read and write all memory to preserve " "reordering restrictions required by safepoint semantics", & CI); return; } } while (0) | |||||
1531 | "reordering restrictions required by safepoint semantics",do { if (!(!CS.doesNotAccessMemory() && !CS.onlyReadsMemory () && !CS.onlyAccessesArgMemory())) { CheckFailed("gc.statepoint must read and write all memory to preserve " "reordering restrictions required by safepoint semantics", & CI); return; } } while (0) | |||||
1532 | &CI)do { if (!(!CS.doesNotAccessMemory() && !CS.onlyReadsMemory () && !CS.onlyAccessesArgMemory())) { CheckFailed("gc.statepoint must read and write all memory to preserve " "reordering restrictions required by safepoint semantics", & CI); return; } } while (0); | |||||
1533 | ||||||
1534 | const Value *IDV = CS.getArgument(0); | |||||
1535 | Assert(isa<ConstantInt>(IDV), "gc.statepoint ID must be a constant integer",do { if (!(isa<ConstantInt>(IDV))) { CheckFailed("gc.statepoint ID must be a constant integer" , &CI); return; } } while (0) | |||||
1536 | &CI)do { if (!(isa<ConstantInt>(IDV))) { CheckFailed("gc.statepoint ID must be a constant integer" , &CI); return; } } while (0); | |||||
1537 | ||||||
1538 | const Value *NumPatchBytesV = CS.getArgument(1); | |||||
1539 | Assert(isa<ConstantInt>(NumPatchBytesV),do { if (!(isa<ConstantInt>(NumPatchBytesV))) { CheckFailed ("gc.statepoint number of patchable bytes must be a constant integer" , &CI); return; } } while (0) | |||||
1540 | "gc.statepoint number of patchable bytes must be a constant integer",do { if (!(isa<ConstantInt>(NumPatchBytesV))) { CheckFailed ("gc.statepoint number of patchable bytes must be a constant integer" , &CI); return; } } while (0) | |||||
1541 | &CI)do { if (!(isa<ConstantInt>(NumPatchBytesV))) { CheckFailed ("gc.statepoint number of patchable bytes must be a constant integer" , &CI); return; } } while (0); | |||||
1542 | const int64_t NumPatchBytes = | |||||
1543 | cast<ConstantInt>(NumPatchBytesV)->getSExtValue(); | |||||
1544 | 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!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 1544, __PRETTY_FUNCTION__)); | |||||
1545 | Assert(NumPatchBytes >= 0, "gc.statepoint number of patchable bytes must be "do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be " "positive", &CI); return; } } while (0) | |||||
1546 | "positive",do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be " "positive", &CI); return; } } while (0) | |||||
1547 | &CI)do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be " "positive", &CI); return; } } while (0); | |||||
1548 | ||||||
1549 | const Value *Target = CS.getArgument(2); | |||||
1550 | auto *PT = dyn_cast<PointerType>(Target->getType()); | |||||
1551 | Assert(PT && PT->getElementType()->isFunctionTy(),do { if (!(PT && PT->getElementType()->isFunctionTy ())) { CheckFailed("gc.statepoint callee must be of function pointer type" , &CI, Target); return; } } while (0) | |||||
1552 | "gc.statepoint callee must be of function pointer type", &CI, Target)do { if (!(PT && PT->getElementType()->isFunctionTy ())) { CheckFailed("gc.statepoint callee must be of function pointer type" , &CI, Target); return; } } while (0); | |||||
1553 | FunctionType *TargetFuncType = cast<FunctionType>(PT->getElementType()); | |||||
1554 | ||||||
1555 | const Value *NumCallArgsV = CS.getArgument(3); | |||||
1556 | Assert(isa<ConstantInt>(NumCallArgsV),do { if (!(isa<ConstantInt>(NumCallArgsV))) { CheckFailed ("gc.statepoint number of arguments to underlying call " "must be constant integer" , &CI); return; } } while (0) | |||||
1557 | "gc.statepoint number of arguments to underlying call "do { if (!(isa<ConstantInt>(NumCallArgsV))) { CheckFailed ("gc.statepoint number of arguments to underlying call " "must be constant integer" , &CI); return; } } while (0) | |||||
1558 | "must be constant integer",do { if (!(isa<ConstantInt>(NumCallArgsV))) { CheckFailed ("gc.statepoint number of arguments to underlying call " "must be constant integer" , &CI); return; } } while (0) | |||||
1559 | &CI)do { if (!(isa<ConstantInt>(NumCallArgsV))) { CheckFailed ("gc.statepoint number of arguments to underlying call " "must be constant integer" , &CI); return; } } while (0); | |||||
1560 | const int NumCallArgs = cast<ConstantInt>(NumCallArgsV)->getZExtValue(); | |||||
1561 | Assert(NumCallArgs >= 0,do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call " "must be positive", &CI); return; } } while (0) | |||||
1562 | "gc.statepoint number of arguments to underlying call "do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call " "must be positive", &CI); return; } } while (0) | |||||
1563 | "must be positive",do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call " "must be positive", &CI); return; } } while (0) | |||||
1564 | &CI)do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call " "must be positive", &CI); return; } } while (0); | |||||
1565 | const int NumParams = (int)TargetFuncType->getNumParams(); | |||||
1566 | if (TargetFuncType->isVarArg()) { | |||||
1567 | Assert(NumCallArgs >= NumParams,do { if (!(NumCallArgs >= NumParams)) { CheckFailed("gc.statepoint mismatch in number of vararg call args" , &CI); return; } } while (0) | |||||
1568 | "gc.statepoint mismatch in number of vararg call args", &CI)do { if (!(NumCallArgs >= NumParams)) { CheckFailed("gc.statepoint mismatch in number of vararg call args" , &CI); return; } } while (0); | |||||
1569 | ||||||
1570 | // TODO: Remove this limitation | |||||
1571 | Assert(TargetFuncType->getReturnType()->isVoidTy(),do { if (!(TargetFuncType->getReturnType()->isVoidTy()) ) { CheckFailed("gc.statepoint doesn't support wrapping non-void " "vararg functions yet", &CI); return; } } while (0) | |||||
1572 | "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", &CI); return; } } while (0) | |||||
1573 | "vararg functions yet",do { if (!(TargetFuncType->getReturnType()->isVoidTy()) ) { CheckFailed("gc.statepoint doesn't support wrapping non-void " "vararg functions yet", &CI); return; } } while (0) | |||||
1574 | &CI)do { if (!(TargetFuncType->getReturnType()->isVoidTy()) ) { CheckFailed("gc.statepoint doesn't support wrapping non-void " "vararg functions yet", &CI); return; } } while (0); | |||||
1575 | } else | |||||
1576 | Assert(NumCallArgs == NumParams,do { if (!(NumCallArgs == NumParams)) { CheckFailed("gc.statepoint mismatch in number of call args" , &CI); return; } } while (0) | |||||
1577 | "gc.statepoint mismatch in number of call args", &CI)do { if (!(NumCallArgs == NumParams)) { CheckFailed("gc.statepoint mismatch in number of call args" , &CI); return; } } while (0); | |||||
1578 | ||||||
1579 | const Value *FlagsV = CS.getArgument(4); | |||||
1580 | Assert(isa<ConstantInt>(FlagsV),do { if (!(isa<ConstantInt>(FlagsV))) { CheckFailed("gc.statepoint flags must be constant integer" , &CI); return; } } while (0) | |||||
1581 | "gc.statepoint flags must be constant integer", &CI)do { if (!(isa<ConstantInt>(FlagsV))) { CheckFailed("gc.statepoint flags must be constant integer" , &CI); return; } } while (0); | |||||
1582 | const uint64_t Flags = cast<ConstantInt>(FlagsV)->getZExtValue(); | |||||
1583 | Assert((Flags & ~(uint64_t)StatepointFlags::MaskAll) == 0,do { if (!((Flags & ~(uint64_t)StatepointFlags::MaskAll) == 0)) { CheckFailed("unknown flag used in gc.statepoint flags argument" , &CI); return; } } while (0) | |||||
1584 | "unknown flag used in gc.statepoint flags argument", &CI)do { if (!((Flags & ~(uint64_t)StatepointFlags::MaskAll) == 0)) { CheckFailed("unknown flag used in gc.statepoint flags argument" , &CI); return; } } while (0); | |||||
1585 | ||||||
1586 | // Verify that the types of the call parameter arguments match | |||||
1587 | // the type of the wrapped callee. | |||||
1588 | for (int i = 0; i < NumParams; i++) { | |||||
1589 | Type *ParamType = TargetFuncType->getParamType(i); | |||||
1590 | Type *ArgType = CS.getArgument(5 + i)->getType(); | |||||
1591 | Assert(ArgType == ParamType,do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped " "function type", &CI); return; } } while (0) | |||||
1592 | "gc.statepoint call argument does not match wrapped "do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped " "function type", &CI); return; } } while (0) | |||||
1593 | "function type",do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped " "function type", &CI); return; } } while (0) | |||||
1594 | &CI)do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped " "function type", &CI); return; } } while (0); | |||||
1595 | } | |||||
1596 | ||||||
1597 | const int EndCallArgsInx = 4 + NumCallArgs; | |||||
1598 | ||||||
1599 | const Value *NumTransitionArgsV = CS.getArgument(EndCallArgsInx+1); | |||||
1600 | Assert(isa<ConstantInt>(NumTransitionArgsV),do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed ("gc.statepoint number of transition arguments " "must be constant integer" , &CI); return; } } while (0) | |||||
1601 | "gc.statepoint number of transition arguments "do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed ("gc.statepoint number of transition arguments " "must be constant integer" , &CI); return; } } while (0) | |||||
1602 | "must be constant integer",do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed ("gc.statepoint number of transition arguments " "must be constant integer" , &CI); return; } } while (0) | |||||
1603 | &CI)do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed ("gc.statepoint number of transition arguments " "must be constant integer" , &CI); return; } } while (0); | |||||
1604 | const int NumTransitionArgs = | |||||
1605 | cast<ConstantInt>(NumTransitionArgsV)->getZExtValue(); | |||||
1606 | Assert(NumTransitionArgs >= 0,do { if (!(NumTransitionArgs >= 0)) { CheckFailed("gc.statepoint number of transition arguments must be positive" , &CI); return; } } while (0) | |||||
1607 | "gc.statepoint number of transition arguments must be positive", &CI)do { if (!(NumTransitionArgs >= 0)) { CheckFailed("gc.statepoint number of transition arguments must be positive" , &CI); return; } } while (0); | |||||
1608 | const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs; | |||||
1609 | ||||||
1610 | const Value *NumDeoptArgsV = CS.getArgument(EndTransitionArgsInx+1); | |||||
1611 | Assert(isa<ConstantInt>(NumDeoptArgsV),do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed ("gc.statepoint number of deoptimization arguments " "must be constant integer" , &CI); return; } } while (0) | |||||
1612 | "gc.statepoint number of deoptimization arguments "do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed ("gc.statepoint number of deoptimization arguments " "must be constant integer" , &CI); return; } } while (0) | |||||
1613 | "must be constant integer",do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed ("gc.statepoint number of deoptimization arguments " "must be constant integer" , &CI); return; } } while (0) | |||||
1614 | &CI)do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed ("gc.statepoint number of deoptimization arguments " "must be constant integer" , &CI); return; } } while (0); | |||||
1615 | const int NumDeoptArgs = cast<ConstantInt>(NumDeoptArgsV)->getZExtValue(); | |||||
1616 | Assert(NumDeoptArgs >= 0, "gc.statepoint number of deoptimization arguments "do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments " "must be positive", &CI); return; } } while (0) | |||||
1617 | "must be positive",do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments " "must be positive", &CI); return; } } while (0) | |||||
1618 | &CI)do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments " "must be positive", &CI); return; } } while (0); | |||||
1619 | ||||||
1620 | const int ExpectedNumArgs = | |||||
1621 | 7 + NumCallArgs + NumTransitionArgs + NumDeoptArgs; | |||||
1622 | Assert(ExpectedNumArgs <= (int)CS.arg_size(),do { if (!(ExpectedNumArgs <= (int)CS.arg_size())) { CheckFailed ("gc.statepoint too few arguments according to length fields" , &CI); return; } } while (0) | |||||
1623 | "gc.statepoint too few arguments according to length fields", &CI)do { if (!(ExpectedNumArgs <= (int)CS.arg_size())) { CheckFailed ("gc.statepoint too few arguments according to length fields" , &CI); return; } } while (0); | |||||
1624 | ||||||
1625 | // Check that the only uses of this gc.statepoint are gc.result or | |||||
1626 | // gc.relocate calls which are tied to this statepoint and thus part | |||||
1627 | // of the same statepoint sequence | |||||
1628 | for (const User *U : CI.users()) { | |||||
1629 | const CallInst *Call = dyn_cast<const CallInst>(U); | |||||
1630 | Assert(Call, "illegal use of statepoint token", &CI, U)do { if (!(Call)) { CheckFailed("illegal use of statepoint token" , &CI, U); return; } } while (0); | |||||
1631 | if (!Call) continue; | |||||
1632 | Assert(isGCRelocate(Call) || isGCResult(Call),do { if (!(isGCRelocate(Call) || isGCResult(Call))) { CheckFailed ("gc.result or gc.relocate are the only value uses" "of a gc.statepoint" , &CI, U); return; } } while (0) | |||||
1633 | "gc.result or gc.relocate are the only value uses"do { if (!(isGCRelocate(Call) || isGCResult(Call))) { CheckFailed ("gc.result or gc.relocate are the only value uses" "of a gc.statepoint" , &CI, U); return; } } while (0) | |||||
1634 | "of a gc.statepoint",do { if (!(isGCRelocate(Call) || isGCResult(Call))) { CheckFailed ("gc.result or gc.relocate are the only value uses" "of a gc.statepoint" , &CI, U); return; } } while (0) | |||||
1635 | &CI, U)do { if (!(isGCRelocate(Call) || isGCResult(Call))) { CheckFailed ("gc.result or gc.relocate are the only value uses" "of a gc.statepoint" , &CI, U); return; } } while (0); | |||||
1636 | if (isGCResult(Call)) { | |||||
1637 | Assert(Call->getArgOperand(0) == &CI,do { if (!(Call->getArgOperand(0) == &CI)) { CheckFailed ("gc.result connected to wrong gc.statepoint", &CI, Call) ; return; } } while (0) | |||||
1638 | "gc.result connected to wrong gc.statepoint", &CI, Call)do { if (!(Call->getArgOperand(0) == &CI)) { CheckFailed ("gc.result connected to wrong gc.statepoint", &CI, Call) ; return; } } while (0); | |||||
1639 | } else if (isGCRelocate(Call)) { | |||||
1640 | Assert(Call->getArgOperand(0) == &CI,do { if (!(Call->getArgOperand(0) == &CI)) { CheckFailed ("gc.relocate connected to wrong gc.statepoint", &CI, Call ); return; } } while (0) | |||||
1641 | "gc.relocate connected to wrong gc.statepoint", &CI, Call)do { if (!(Call->getArgOperand(0) == &CI)) { CheckFailed ("gc.relocate connected to wrong gc.statepoint", &CI, Call ); return; } } while (0); | |||||
1642 | } | |||||
1643 | } | |||||
1644 | ||||||
1645 | // Note: It is legal for a single derived pointer to be listed multiple | |||||
1646 | // times. It's non-optimal, but it is legal. It can also happen after | |||||
1647 | // insertion if we strip a bitcast away. | |||||
1648 | // Note: It is really tempting to check that each base is relocated and | |||||
1649 | // that a derived pointer is never reused as a base pointer. This turns | |||||
1650 | // out to be problematic since optimizations run after safepoint insertion | |||||
1651 | // can recognize equality properties that the insertion logic doesn't know | |||||
1652 | // about. See example statepoint.ll in the verifier subdirectory | |||||
1653 | } | |||||
1654 | ||||||
1655 | void Verifier::verifyFrameRecoverIndices() { | |||||
1656 | for (auto &Counts : FrameEscapeInfo) { | |||||
1657 | Function *F = Counts.first; | |||||
1658 | unsigned EscapedObjectCount = Counts.second.first; | |||||
1659 | unsigned MaxRecoveredIndex = Counts.second.second; | |||||
1660 | Assert(MaxRecoveredIndex <= EscapedObjectCount,do { if (!(MaxRecoveredIndex <= EscapedObjectCount)) { CheckFailed ("all indices passed to llvm.localrecover must be less than the " "number of arguments passed ot llvm.localescape in the parent " "function", F); return; } } while (0) | |||||
1661 | "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 ot llvm.localescape in the parent " "function", F); return; } } while (0) | |||||
1662 | "number of arguments passed ot 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 ot llvm.localescape in the parent " "function", F); return; } } while (0) | |||||
1663 | "function",do { if (!(MaxRecoveredIndex <= EscapedObjectCount)) { CheckFailed ("all indices passed to llvm.localrecover must be less than the " "number of arguments passed ot llvm.localescape in the parent " "function", F); return; } } while (0) | |||||
1664 | F)do { if (!(MaxRecoveredIndex <= EscapedObjectCount)) { CheckFailed ("all indices passed to llvm.localrecover must be less than the " "number of arguments passed ot llvm.localescape in the parent " "function", F); return; } } while (0); | |||||
1665 | } | |||||
1666 | } | |||||
1667 | ||||||
1668 | // visitFunction - Verify that a function is ok. | |||||
1669 | // | |||||
1670 | void Verifier::visitFunction(const Function &F) { | |||||
1671 | // Check function arguments. | |||||
1672 | FunctionType *FT = F.getFunctionType(); | |||||
1673 | unsigned NumArgs = F.arg_size(); | |||||
1674 | ||||||
1675 | Assert(Context == &F.getContext(),do { if (!(Context == &F.getContext())) { CheckFailed("Function context does not match Module context!" , &F); return; } } while (0) | |||||
1676 | "Function context does not match Module context!", &F)do { if (!(Context == &F.getContext())) { CheckFailed("Function context does not match Module context!" , &F); return; } } while (0); | |||||
1677 | ||||||
1678 | Assert(!F.hasCommonLinkage(), "Functions may not have common linkage", &F)do { if (!(!F.hasCommonLinkage())) { CheckFailed("Functions may not have common linkage" , &F); return; } } while (0); | |||||
1679 | Assert(FT->getNumParams() == NumArgs,do { if (!(FT->getNumParams() == NumArgs)) { CheckFailed("# formal arguments must match # of arguments for function type!" , &F, FT); return; } } while (0) | |||||
1680 | "# 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 (0) | |||||
1681 | FT)do { if (!(FT->getNumParams() == NumArgs)) { CheckFailed("# formal arguments must match # of arguments for function type!" , &F, FT); return; } } while (0); | |||||
1682 | Assert(F.getReturnType()->isFirstClassType() ||do { if (!(F.getReturnType()->isFirstClassType() || F.getReturnType ()->isVoidTy() || F.getReturnType()->isStructTy())) { CheckFailed ("Functions cannot return aggregate values!", &F); return ; } } while (0) | |||||
1683 | 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 (0) | |||||
1684 | "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 (0); | |||||
1685 | ||||||
1686 | Assert(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy(),do { if (!(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy ())) { CheckFailed("Invalid struct return type!", &F); return ; } } while (0) | |||||
1687 | "Invalid struct return type!", &F)do { if (!(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy ())) { CheckFailed("Invalid struct return type!", &F); return ; } } while (0); | |||||
1688 | ||||||
1689 | AttributeSet Attrs = F.getAttributes(); | |||||
1690 | ||||||
1691 | Assert(VerifyAttributeCount(Attrs, FT->getNumParams()),do { if (!(VerifyAttributeCount(Attrs, FT->getNumParams()) )) { CheckFailed("Attribute after last parameter!", &F); return ; } } while (0) | |||||
1692 | "Attribute after last parameter!", &F)do { if (!(VerifyAttributeCount(Attrs, FT->getNumParams()) )) { CheckFailed("Attribute after last parameter!", &F); return ; } } while (0); | |||||
1693 | ||||||
1694 | // Check function attributes. | |||||
1695 | VerifyFunctionAttrs(FT, Attrs, &F); | |||||
1696 | ||||||
1697 | // On function declarations/definitions, we do not support the builtin | |||||
1698 | // attribute. We do not check this in VerifyFunctionAttrs since that is | |||||
1699 | // checking for Attributes that can/can not ever be on functions. | |||||
1700 | Assert(!Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute::Builtin),do { if (!(!Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::Builtin))) { CheckFailed("Attribute 'builtin' can only be applied to a callsite." , &F); return; } } while (0) | |||||
1701 | "Attribute 'builtin' can only be applied to a callsite.", &F)do { if (!(!Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute ::Builtin))) { CheckFailed("Attribute 'builtin' can only be applied to a callsite." , &F); return; } } while (0); | |||||
1702 | ||||||
1703 | // Check that this function meets the restrictions on this calling convention. | |||||
1704 | // Sometimes varargs is used for perfectly forwarding thunks, so some of these | |||||
1705 | // restrictions can be lifted. | |||||
1706 | switch (F.getCallingConv()) { | |||||
1707 | default: | |||||
1708 | case CallingConv::C: | |||||
1709 | break; | |||||
1710 | case CallingConv::Fast: | |||||
1711 | case CallingConv::Cold: | |||||
1712 | case CallingConv::Intel_OCL_BI: | |||||
1713 | case CallingConv::PTX_Kernel: | |||||
1714 | case CallingConv::PTX_Device: | |||||
1715 | 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 (0) | |||||
1716 | "perfect forwarding!",do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or " "perfect forwarding!", &F); return; } } while (0) | |||||
1717 | &F)do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or " "perfect forwarding!", &F); return; } } while (0); | |||||
1718 | break; | |||||
1719 | } | |||||
1720 | ||||||
1721 | bool isLLVMdotName = F.getName().size() >= 5 && | |||||
1722 | F.getName().substr(0, 5) == "llvm."; | |||||
1723 | ||||||
1724 | // Check that the argument values match the function type for this function... | |||||
1725 | unsigned i = 0; | |||||
1726 | for (Function::const_arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; | |||||
1727 | ++I, ++i) { | |||||
1728 | Assert(I->getType() == FT->getParamType(i),do { if (!(I->getType() == FT->getParamType(i))) { CheckFailed ("Argument value does not match function argument type!", I, FT ->getParamType(i)); return; } } while (0) | |||||
1729 | "Argument value does not match function argument type!", I,do { if (!(I->getType() == FT->getParamType(i))) { CheckFailed ("Argument value does not match function argument type!", I, FT ->getParamType(i)); return; } } while (0) | |||||
1730 | FT->getParamType(i))do { if (!(I->getType() == FT->getParamType(i))) { CheckFailed ("Argument value does not match function argument type!", I, FT ->getParamType(i)); return; } } while (0); | |||||
1731 | Assert(I->getType()->isFirstClassType(),do { if (!(I->getType()->isFirstClassType())) { CheckFailed ("Function arguments must have first-class types!", I); return ; } } while (0) | |||||
1732 | "Function arguments must have first-class types!", I)do { if (!(I->getType()->isFirstClassType())) { CheckFailed ("Function arguments must have first-class types!", I); return ; } } while (0); | |||||
1733 | if (!isLLVMdotName) { | |||||
1734 | Assert(!I->getType()->isMetadataTy(),do { if (!(!I->getType()->isMetadataTy())) { CheckFailed ("Function takes metadata but isn't an intrinsic", I, &F) ; return; } } while (0) | |||||
1735 | "Function takes metadata but isn't an intrinsic", I, &F)do { if (!(!I->getType()->isMetadataTy())) { CheckFailed ("Function takes metadata but isn't an intrinsic", I, &F) ; return; } } while (0); | |||||
1736 | Assert(!I->getType()->isTokenTy(),do { if (!(!I->getType()->isTokenTy())) { CheckFailed("Function takes token but isn't an intrinsic" , I, &F); return; } } while (0) | |||||
1737 | "Function takes token but isn't an intrinsic", I, &F)do { if (!(!I->getType()->isTokenTy())) { CheckFailed("Function takes token but isn't an intrinsic" , I, &F); return; } } while (0); | |||||
1738 | } | |||||
1739 | } | |||||
1740 | ||||||
1741 | if (!isLLVMdotName) | |||||
1742 | Assert(!F.getReturnType()->isTokenTy(),do { if (!(!F.getReturnType()->isTokenTy())) { CheckFailed ("Functions returns a token but isn't an intrinsic", &F); return; } } while (0) | |||||
1743 | "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 (0); | |||||
1744 | ||||||
1745 | // Get the function metadata attachments. | |||||
1746 | SmallVector<std::pair<unsigned, MDNode *>, 4> MDs; | |||||
1747 | F.getAllMetadata(MDs); | |||||
1748 | 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\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 1748, __PRETTY_FUNCTION__)); | |||||
1749 | VerifyFunctionMetadata(MDs); | |||||
1750 | ||||||
1751 | if (F.isMaterializable()) { | |||||
1752 | // Function has a body somewhere we can't see. | |||||
1753 | 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 (0) | |||||
1754 | 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 (0); | |||||
1755 | } else if (F.isDeclaration()) { | |||||
1756 | Assert(F.hasExternalLinkage() || F.hasExternalWeakLinkage(),do { if (!(F.hasExternalLinkage() || F.hasExternalWeakLinkage ())) { CheckFailed("invalid linkage type for function declaration" , &F); return; } } while (0) | |||||
1757 | "invalid linkage type for function declaration", &F)do { if (!(F.hasExternalLinkage() || F.hasExternalWeakLinkage ())) { CheckFailed("invalid linkage type for function declaration" , &F); return; } } while (0); | |||||
1758 | Assert(MDs.empty(), "function without a body cannot have metadata", &F,do { if (!(MDs.empty())) { CheckFailed("function without a body cannot have metadata" , &F, MDs.empty() ? nullptr : MDs.front().second); return ; } } while (0) | |||||
1759 | MDs.empty() ? nullptr : MDs.front().second)do { if (!(MDs.empty())) { CheckFailed("function without a body cannot have metadata" , &F, MDs.empty() ? nullptr : MDs.front().second); return ; } } while (0); | |||||
1760 | Assert(!F.hasPersonalityFn(),do { if (!(!F.hasPersonalityFn())) { CheckFailed("Function declaration shouldn't have a personality routine" , &F); return; } } while (0) | |||||
1761 | "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 (0); | |||||
1762 | } else { | |||||
1763 | // Verify that this function (which has a body) is not named "llvm.*". It | |||||
1764 | // is not legal to define intrinsics. | |||||
1765 | Assert(!isLLVMdotName, "llvm intrinsics cannot be defined!", &F)do { if (!(!isLLVMdotName)) { CheckFailed("llvm intrinsics cannot be defined!" , &F); return; } } while (0); | |||||
1766 | ||||||
1767 | // Check the entry node | |||||
1768 | const BasicBlock *Entry = &F.getEntryBlock(); | |||||
1769 | Assert(pred_empty(Entry),do { if (!(pred_empty(Entry))) { CheckFailed("Entry block to function must not have predecessors!" , Entry); return; } } while (0) | |||||
1770 | "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 (0); | |||||
1771 | ||||||
1772 | // The address of the entry block cannot be taken, unless it is dead. | |||||
1773 | if (Entry->hasAddressTaken()) { | |||||
1774 | Assert(!BlockAddress::lookup(Entry)->isConstantUsed(),do { if (!(!BlockAddress::lookup(Entry)->isConstantUsed()) ) { CheckFailed("blockaddress may not be used with the entry block!" , Entry); return; } } while (0) | |||||
1775 | "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 (0); | |||||
1776 | } | |||||
1777 | ||||||
1778 | // Visit metadata attachments. | |||||
1779 | for (const auto &I : MDs) | |||||
1780 | visitMDNode(*I.second); | |||||
1781 | } | |||||
1782 | ||||||
1783 | // If this function is actually an intrinsic, verify that it is only used in | |||||
1784 | // direct call/invokes, never having its "address taken". | |||||
1785 | if (F.getIntrinsicID()) { | |||||
1786 | const User *U; | |||||
1787 | if (F.hasAddressTaken(&U)) | |||||
1788 | Assert(0, "Invalid user of intrinsic instruction!", U)do { if (!(0)) { CheckFailed("Invalid user of intrinsic instruction!" , U); return; } } while (0); | |||||
1789 | } | |||||
1790 | ||||||
1791 | Assert(!F.hasDLLImportStorageClass() ||do { if (!(!F.hasDLLImportStorageClass() || (F.isDeclaration( ) && F.hasExternalLinkage()) || F.hasAvailableExternallyLinkage ())) { CheckFailed("Function is marked as dllimport, but not external." , &F); return; } } while (0) | |||||
1792 | (F.isDeclaration() && F.hasExternalLinkage()) ||do { if (!(!F.hasDLLImportStorageClass() || (F.isDeclaration( ) && F.hasExternalLinkage()) || F.hasAvailableExternallyLinkage ())) { CheckFailed("Function is marked as dllimport, but not external." , &F); return; } } while (0) | |||||
1793 | F.hasAvailableExternallyLinkage(),do { if (!(!F.hasDLLImportStorageClass() || (F.isDeclaration( ) && F.hasExternalLinkage()) || F.hasAvailableExternallyLinkage ())) { CheckFailed("Function is marked as dllimport, but not external." , &F); return; } } while (0) | |||||
1794 | "Function is marked as dllimport, but not external.", &F)do { if (!(!F.hasDLLImportStorageClass() || (F.isDeclaration( ) && F.hasExternalLinkage()) || F.hasAvailableExternallyLinkage ())) { CheckFailed("Function is marked as dllimport, but not external." , &F); return; } } while (0); | |||||
1795 | } | |||||
1796 | ||||||
1797 | // verifyBasicBlock - Verify that a basic block is well formed... | |||||
1798 | // | |||||
1799 | void Verifier::visitBasicBlock(BasicBlock &BB) { | |||||
1800 | InstsInThisBlock.clear(); | |||||
1801 | ||||||
1802 | // Ensure that basic blocks have terminators! | |||||
1803 | Assert(BB.getTerminator(), "Basic Block does not have terminator!", &BB)do { if (!(BB.getTerminator())) { CheckFailed("Basic Block does not have terminator!" , &BB); return; } } while (0); | |||||
1804 | ||||||
1805 | // Check constraints that this basic block imposes on all of the PHI nodes in | |||||
1806 | // it. | |||||
1807 | if (isa<PHINode>(BB.front())) { | |||||
1808 | SmallVector<BasicBlock*, 8> Preds(pred_begin(&BB), pred_end(&BB)); | |||||
1809 | SmallVector<std::pair<BasicBlock*, Value*>, 8> Values; | |||||
1810 | std::sort(Preds.begin(), Preds.end()); | |||||
1811 | PHINode *PN; | |||||
1812 | for (BasicBlock::iterator I = BB.begin(); (PN = dyn_cast<PHINode>(I));++I) { | |||||
1813 | // Ensure that PHI nodes have at least one entry! | |||||
1814 | 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 (0) | |||||
1815 | "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 (0) | |||||
1816 | "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 (0) | |||||
1817 | 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 (0); | |||||
1818 | 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 (0) | |||||
1819 | "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 (0) | |||||
1820 | "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 (0) | |||||
1821 | PN)do { if (!(PN->getNumIncomingValues() == Preds.size())) { CheckFailed ("PHINode should have one entry for each predecessor of its " "parent basic block!", PN); return; } } while (0); | |||||
1822 | ||||||
1823 | // Get and sort all incoming values in the PHI node... | |||||
1824 | Values.clear(); | |||||
1825 | Values.reserve(PN->getNumIncomingValues()); | |||||
1826 | for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) | |||||
1827 | Values.push_back(std::make_pair(PN->getIncomingBlock(i), | |||||
1828 | PN->getIncomingValue(i))); | |||||
1829 | std::sort(Values.begin(), Values.end()); | |||||
1830 | ||||||
1831 | for (unsigned i = 0, e = Values.size(); i != e; ++i) { | |||||
1832 | // Check to make sure that if there is more than one entry for a | |||||
1833 | // particular basic block in this PHI node, that the incoming values are | |||||
1834 | // all identical. | |||||
1835 | // | |||||
1836 | 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 (0) | |||||
1837 | 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 (0) | |||||
1838 | "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 (0) | |||||
1839 | "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 (0) | |||||
1840 | 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 (0); | |||||
1841 | ||||||
1842 | // Check to make sure that the predecessors and PHI node entries are | |||||
1843 | // matched up. | |||||
1844 | 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 (0) | |||||
1845 | "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 (0) | |||||
1846 | 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 (0); | |||||
1847 | } | |||||
1848 | } | |||||
1849 | } | |||||
1850 | ||||||
1851 | // Check that all instructions have their parent pointers set up correctly. | |||||
1852 | for (auto &I : BB) | |||||
1853 | { | |||||
1854 | Assert(I.getParent() == &BB, "Instruction has bogus parent pointer!")do { if (!(I.getParent() == &BB)) { CheckFailed("Instruction has bogus parent pointer!" ); return; } } while (0); | |||||
1855 | } | |||||
1856 | } | |||||
1857 | ||||||
1858 | void Verifier::visitTerminatorInst(TerminatorInst &I) { | |||||
1859 | // Ensure that terminators only exist at the end of the basic block. | |||||
1860 | 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 (0) | |||||
1861 | "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 (0); | |||||
1862 | visitInstruction(I); | |||||
1863 | } | |||||
1864 | ||||||
1865 | void Verifier::visitBranchInst(BranchInst &BI) { | |||||
1866 | if (BI.isConditional()) { | |||||
1867 | 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 (0) | |||||
1868 | "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 (0); | |||||
1869 | } | |||||
1870 | visitTerminatorInst(BI); | |||||
1871 | } | |||||
1872 | ||||||
1873 | void Verifier::visitReturnInst(ReturnInst &RI) { | |||||
1874 | Function *F = RI.getParent()->getParent(); | |||||
1875 | unsigned N = RI.getNumOperands(); | |||||
1876 | if (F->getReturnType()->isVoidTy()) | |||||
1877 | 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 (0) | |||||
1878 | "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 (0) | |||||
1879 | "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 (0) | |||||
1880 | &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 (0); | |||||
1881 | else | |||||
1882 | 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 (0) | |||||
1883 | "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 (0) | |||||
1884 | "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 (0) | |||||
1885 | &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 (0); | |||||
1886 | ||||||
1887 | // Check to make sure that the return value has necessary properties for | |||||
1888 | // terminators... | |||||
1889 | visitTerminatorInst(RI); | |||||
1890 | } | |||||
1891 | ||||||
1892 | void Verifier::visitSwitchInst(SwitchInst &SI) { | |||||
1893 | // Check to make sure that all of the constants in the switch instruction | |||||
1894 | // have the same type as the switched-on value. | |||||
1895 | Type *SwitchTy = SI.getCondition()->getType(); | |||||
1896 | SmallPtrSet<ConstantInt*, 32> Constants; | |||||
1897 | for (SwitchInst::CaseIt i = SI.case_begin(), e = SI.case_end(); i != e; ++i) { | |||||
1898 | Assert(i.getCaseValue()->getType() == SwitchTy,do { if (!(i.getCaseValue()->getType() == SwitchTy)) { CheckFailed ("Switch constants must all be same type as switch value!", & SI); return; } } while (0) | |||||
1899 | "Switch constants must all be same type as switch value!", &SI)do { if (!(i.getCaseValue()->getType() == SwitchTy)) { CheckFailed ("Switch constants must all be same type as switch value!", & SI); return; } } while (0); | |||||
1900 | Assert(Constants.insert(i.getCaseValue()).second,do { if (!(Constants.insert(i.getCaseValue()).second)) { CheckFailed ("Duplicate integer as switch case", &SI, i.getCaseValue( )); return; } } while (0) | |||||
1901 | "Duplicate integer as switch case", &SI, i.getCaseValue())do { if (!(Constants.insert(i.getCaseValue()).second)) { CheckFailed ("Duplicate integer as switch case", &SI, i.getCaseValue( )); return; } } while (0); | |||||
1902 | } | |||||
1903 | ||||||
1904 | visitTerminatorInst(SI); | |||||
1905 | } | |||||
1906 | ||||||
1907 | void Verifier::visitIndirectBrInst(IndirectBrInst &BI) { | |||||
1908 | Assert(BI.getAddress()->getType()->isPointerTy(),do { if (!(BI.getAddress()->getType()->isPointerTy())) { CheckFailed("Indirectbr operand must have pointer type!", & BI); return; } } while (0) | |||||
1909 | "Indirectbr operand must have pointer type!", &BI)do { if (!(BI.getAddress()->getType()->isPointerTy())) { CheckFailed("Indirectbr operand must have pointer type!", & BI); return; } } while (0); | |||||
1910 | for (unsigned i = 0, e = BI.getNumDestinations(); i != e; ++i) | |||||
1911 | Assert(BI.getDestination(i)->getType()->isLabelTy(),do { if (!(BI.getDestination(i)->getType()->isLabelTy() )) { CheckFailed("Indirectbr destinations must all have pointer type!" , &BI); return; } } while (0) | |||||
1912 | "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 (0); | |||||
1913 | ||||||
1914 | visitTerminatorInst(BI); | |||||
1915 | } | |||||
1916 | ||||||
1917 | void Verifier::visitSelectInst(SelectInst &SI) { | |||||
1918 | 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 (0) | |||||
1919 | 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 (0) | |||||
1920 | "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 (0); | |||||
1921 | ||||||
1922 | 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 (0) | |||||
1923 | "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 (0); | |||||
1924 | visitInstruction(SI); | |||||
1925 | } | |||||
1926 | ||||||
1927 | /// visitUserOp1 - User defined operators shouldn't live beyond the lifetime of | |||||
1928 | /// a pass, if any exist, it's an error. | |||||
1929 | /// | |||||
1930 | void Verifier::visitUserOp1(Instruction &I) { | |||||
1931 | Assert(0, "User-defined operators should not live outside of a pass!", &I)do { if (!(0)) { CheckFailed("User-defined operators should not live outside of a pass!" , &I); return; } } while (0); | |||||
1932 | } | |||||
1933 | ||||||
1934 | void Verifier::visitTruncInst(TruncInst &I) { | |||||
1935 | // Get the source and destination types | |||||
1936 | Type *SrcTy = I.getOperand(0)->getType(); | |||||
1937 | Type *DestTy = I.getType(); | |||||
1938 | ||||||
1939 | // Get the size of the types in bits, we'll need this later | |||||
1940 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | |||||
1941 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | |||||
1942 | ||||||
1943 | Assert(SrcTy->isIntOrIntVectorTy(), "Trunc only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("Trunc only operates on integer" , &I); return; } } while (0); | |||||
1944 | Assert(DestTy->isIntOrIntVectorTy(), "Trunc only produces integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("Trunc only produces integer" , &I); return; } } while (0); | |||||
1945 | 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 (0) | |||||
1946 | "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 (0); | |||||
1947 | Assert(SrcBitSize > DestBitSize, "DestTy too big for Trunc", &I)do { if (!(SrcBitSize > DestBitSize)) { CheckFailed("DestTy too big for Trunc" , &I); return; } } while (0); | |||||
1948 | ||||||
1949 | visitInstruction(I); | |||||
1950 | } | |||||
1951 | ||||||
1952 | void Verifier::visitZExtInst(ZExtInst &I) { | |||||
1953 | // Get the source and destination types | |||||
1954 | Type *SrcTy = I.getOperand(0)->getType(); | |||||
1955 | Type *DestTy = I.getType(); | |||||
1956 | ||||||
1957 | // Get the size of the types in bits, we'll need this later | |||||
1958 | Assert(SrcTy->isIntOrIntVectorTy(), "ZExt only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("ZExt only operates on integer" , &I); return; } } while (0); | |||||
1959 | Assert(DestTy->isIntOrIntVectorTy(), "ZExt only produces an integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("ZExt only produces an integer" , &I); return; } } while (0); | |||||
1960 | 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 (0) | |||||
1961 | "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 (0); | |||||
1962 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | |||||
1963 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | |||||
1964 | ||||||
1965 | Assert(SrcBitSize < DestBitSize, "Type too small for ZExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("Type too small for ZExt" , &I); return; } } while (0); | |||||
1966 | ||||||
1967 | visitInstruction(I); | |||||
1968 | } | |||||
1969 | ||||||
1970 | void Verifier::visitSExtInst(SExtInst &I) { | |||||
1971 | // Get the source and destination types | |||||
1972 | Type *SrcTy = I.getOperand(0)->getType(); | |||||
1973 | Type *DestTy = I.getType(); | |||||
1974 | ||||||
1975 | // Get the size of the types in bits, we'll need this later | |||||
1976 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | |||||
1977 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | |||||
1978 | ||||||
1979 | Assert(SrcTy->isIntOrIntVectorTy(), "SExt only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("SExt only operates on integer" , &I); return; } } while (0); | |||||
1980 | Assert(DestTy->isIntOrIntVectorTy(), "SExt only produces an integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("SExt only produces an integer" , &I); return; } } while (0); | |||||
1981 | 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 (0) | |||||
1982 | "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 (0); | |||||
1983 | Assert(SrcBitSize < DestBitSize, "Type too small for SExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("Type too small for SExt" , &I); return; } } while (0); | |||||
1984 | ||||||
1985 | visitInstruction(I); | |||||
1986 | } | |||||
1987 | ||||||
1988 | void Verifier::visitFPTruncInst(FPTruncInst &I) { | |||||
1989 | // Get the source and destination types | |||||
1990 | Type *SrcTy = I.getOperand(0)->getType(); | |||||
1991 | Type *DestTy = I.getType(); | |||||
1992 | // Get the size of the types in bits, we'll need this later | |||||
1993 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | |||||
1994 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | |||||
1995 | ||||||
1996 | Assert(SrcTy->isFPOrFPVectorTy(), "FPTrunc only operates on FP", &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPTrunc only operates on FP" , &I); return; } } while (0); | |||||
1997 | Assert(DestTy->isFPOrFPVectorTy(), "FPTrunc only produces an FP", &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("FPTrunc only produces an FP" , &I); return; } } while (0); | |||||
1998 | 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 (0) | |||||
1999 | "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 (0); | |||||
2000 | Assert(SrcBitSize > DestBitSize, "DestTy too big for FPTrunc", &I)do { if (!(SrcBitSize > DestBitSize)) { CheckFailed("DestTy too big for FPTrunc" , &I); return; } } while (0); | |||||
2001 | ||||||
2002 | visitInstruction(I); | |||||
2003 | } | |||||
2004 | ||||||
2005 | void Verifier::visitFPExtInst(FPExtInst &I) { | |||||
2006 | // Get the source and destination types | |||||
2007 | Type *SrcTy = I.getOperand(0)->getType(); | |||||
2008 | Type *DestTy = I.getType(); | |||||
2009 | ||||||
2010 | // Get the size of the types in bits, we'll need this later | |||||
2011 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | |||||
2012 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | |||||
2013 | ||||||
2014 | Assert(SrcTy->isFPOrFPVectorTy(), "FPExt only operates on FP", &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPExt only operates on FP" , &I); return; } } while (0); | |||||
2015 | Assert(DestTy->isFPOrFPVectorTy(), "FPExt only produces an FP", &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("FPExt only produces an FP" , &I); return; } } while (0); | |||||
2016 | 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 (0) | |||||
2017 | "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 (0); | |||||
2018 | Assert(SrcBitSize < DestBitSize, "DestTy too small for FPExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("DestTy too small for FPExt" , &I); return; } } while (0); | |||||
2019 | ||||||
2020 | visitInstruction(I); | |||||
2021 | } | |||||
2022 | ||||||
2023 | void Verifier::visitUIToFPInst(UIToFPInst &I) { | |||||
2024 | // Get the source and destination types | |||||
2025 | Type *SrcTy = I.getOperand(0)->getType(); | |||||
2026 | Type *DestTy = I.getType(); | |||||
2027 | ||||||
2028 | bool SrcVec = SrcTy->isVectorTy(); | |||||
2029 | bool DstVec = DestTy->isVectorTy(); | |||||
2030 | ||||||
2031 | Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("UIToFP source and dest must both be vector or scalar" , &I); return; } } while (0) | |||||
2032 | "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 (0); | |||||
2033 | Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("UIToFP source must be integer or integer vector" , &I); return; } } while (0) | |||||
2034 | "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 (0); | |||||
2035 | 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 (0) | |||||
2036 | &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("UIToFP result must be FP or FP vector" , &I); return; } } while (0); | |||||
2037 | ||||||
2038 | if (SrcVec && DstVec) | |||||
2039 | 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 (0) | |||||
2040 | 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 (0) | |||||
2041 | "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 (0); | |||||
2042 | ||||||
2043 | visitInstruction(I); | |||||
2044 | } | |||||
2045 | ||||||
2046 | void Verifier::visitSIToFPInst(SIToFPInst &I) { | |||||
2047 | // Get the source and destination types | |||||
2048 | Type *SrcTy = I.getOperand(0)->getType(); | |||||
2049 | Type *DestTy = I.getType(); | |||||
2050 | ||||||
2051 | bool SrcVec = SrcTy->isVectorTy(); | |||||
2052 | bool DstVec = DestTy->isVectorTy(); | |||||
2053 | ||||||
2054 | Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("SIToFP source and dest must both be vector or scalar" , &I); return; } } while (0) | |||||
2055 | "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 (0); | |||||
2056 | Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("SIToFP source must be integer or integer vector" , &I); return; } } while (0) | |||||
2057 | "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 (0); | |||||
2058 | 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 (0) | |||||
2059 | &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("SIToFP result must be FP or FP vector" , &I); return; } } while (0); | |||||
2060 | ||||||
2061 | if (SrcVec && DstVec) | |||||
2062 | 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 (0) | |||||
2063 | 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 (0) | |||||
2064 | "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 (0); | |||||
2065 | ||||||
2066 | visitInstruction(I); | |||||
2067 | } | |||||
2068 | ||||||
2069 | void Verifier::visitFPToUIInst(FPToUIInst &I) { | |||||
2070 | // Get the source and destination types | |||||
2071 | Type *SrcTy = I.getOperand(0)->getType(); | |||||
2072 | Type *DestTy = I.getType(); | |||||
2073 | ||||||
2074 | bool SrcVec = SrcTy->isVectorTy(); | |||||
2075 | bool DstVec = DestTy->isVectorTy(); | |||||
2076 | ||||||
2077 | Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("FPToUI source and dest must both be vector or scalar" , &I); return; } } while (0) | |||||
2078 | "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 (0); | |||||
2079 | 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 (0) | |||||
2080 | &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToUI source must be FP or FP vector" , &I); return; } } while (0); | |||||
2081 | Assert(DestTy->isIntOrIntVectorTy(),do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToUI result must be integer or integer vector" , &I); return; } } while (0) | |||||
2082 | "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 (0); | |||||
2083 | ||||||
2084 | if (SrcVec && DstVec) | |||||
2085 | 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 (0) | |||||
2086 | 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 (0) | |||||
2087 | "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 (0); | |||||
2088 | ||||||
2089 | visitInstruction(I); | |||||
2090 | } | |||||
2091 | ||||||
2092 | void Verifier::visitFPToSIInst(FPToSIInst &I) { | |||||
2093 | // Get the source and destination types | |||||
2094 | Type *SrcTy = I.getOperand(0)->getType(); | |||||
2095 | Type *DestTy = I.getType(); | |||||
2096 | ||||||
2097 | bool SrcVec = SrcTy->isVectorTy(); | |||||
2098 | bool DstVec = DestTy->isVectorTy(); | |||||
2099 | ||||||
2100 | Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("FPToSI source and dest must both be vector or scalar" , &I); return; } } while (0) | |||||
2101 | "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 (0); | |||||
2102 | 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 (0) | |||||
2103 | &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToSI source must be FP or FP vector" , &I); return; } } while (0); | |||||
2104 | Assert(DestTy->isIntOrIntVectorTy(),do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToSI result must be integer or integer vector" , &I); return; } } while (0) | |||||
2105 | "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 (0); | |||||
2106 | ||||||
2107 | if (SrcVec && DstVec) | |||||
2108 | 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 (0) | |||||
2109 | 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 (0) | |||||
2110 | "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 (0); | |||||
2111 | ||||||
2112 | visitInstruction(I); | |||||
2113 | } | |||||
2114 | ||||||
2115 | void Verifier::visitPtrToIntInst(PtrToIntInst &I) { | |||||
2116 | // Get the source and destination types | |||||
2117 | Type *SrcTy = I.getOperand(0)->getType(); | |||||
2118 | Type *DestTy = I.getType(); | |||||
2119 | ||||||
2120 | Assert(SrcTy->getScalarType()->isPointerTy(),do { if (!(SrcTy->getScalarType()->isPointerTy())) { CheckFailed ("PtrToInt source must be pointer", &I); return; } } while (0) | |||||
2121 | "PtrToInt source must be pointer", &I)do { if (!(SrcTy->getScalarType()->isPointerTy())) { CheckFailed ("PtrToInt source must be pointer", &I); return; } } while (0); | |||||
2122 | Assert(DestTy->getScalarType()->isIntegerTy(),do { if (!(DestTy->getScalarType()->isIntegerTy())) { CheckFailed ("PtrToInt result must be integral", &I); return; } } while (0) | |||||
2123 | "PtrToInt result must be integral", &I)do { if (!(DestTy->getScalarType()->isIntegerTy())) { CheckFailed ("PtrToInt result must be integral", &I); return; } } while (0); | |||||
2124 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(), "PtrToInt type mismatch",do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("PtrToInt type mismatch", &I); return; } } while (0) | |||||
2125 | &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("PtrToInt type mismatch", &I); return; } } while (0); | |||||
2126 | ||||||
2127 | if (SrcTy->isVectorTy()) { | |||||
2128 | VectorType *VSrc = dyn_cast<VectorType>(SrcTy); | |||||
2129 | VectorType *VDest = dyn_cast<VectorType>(DestTy); | |||||
2130 | Assert(VSrc->getNumElements() == VDest->getNumElements(),do { if (!(VSrc->getNumElements() == VDest->getNumElements ())) { CheckFailed("PtrToInt Vector width mismatch", &I); return; } } while (0) | |||||
2131 | "PtrToInt Vector width mismatch", &I)do { if (!(VSrc->getNumElements() == VDest->getNumElements ())) { CheckFailed("PtrToInt Vector width mismatch", &I); return; } } while (0); | |||||
2132 | } | |||||
2133 | ||||||
2134 | visitInstruction(I); | |||||
2135 | } | |||||
2136 | ||||||
2137 | void Verifier::visitIntToPtrInst(IntToPtrInst &I) { | |||||
2138 | // Get the source and destination types | |||||
2139 | Type *SrcTy = I.getOperand(0)->getType(); | |||||
2140 | Type *DestTy = I.getType(); | |||||
2141 | ||||||
2142 | Assert(SrcTy->getScalarType()->isIntegerTy(),do { if (!(SrcTy->getScalarType()->isIntegerTy())) { CheckFailed ("IntToPtr source must be an integral", &I); return; } } while (0) | |||||
2143 | "IntToPtr source must be an integral", &I)do { if (!(SrcTy->getScalarType()->isIntegerTy())) { CheckFailed ("IntToPtr source must be an integral", &I); return; } } while (0); | |||||
2144 | Assert(DestTy->getScalarType()->isPointerTy(),do { if (!(DestTy->getScalarType()->isPointerTy())) { CheckFailed ("IntToPtr result must be a pointer", &I); return; } } while (0) | |||||
2145 | "IntToPtr result must be a pointer", &I)do { if (!(DestTy->getScalarType()->isPointerTy())) { CheckFailed ("IntToPtr result must be a pointer", &I); return; } } while (0); | |||||
2146 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(), "IntToPtr type mismatch",do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("IntToPtr type mismatch", &I); return; } } while (0) | |||||
2147 | &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("IntToPtr type mismatch", &I); return; } } while (0); | |||||
2148 | if (SrcTy->isVectorTy()) { | |||||
2149 | VectorType *VSrc = dyn_cast<VectorType>(SrcTy); | |||||
2150 | VectorType *VDest = dyn_cast<VectorType>(DestTy); | |||||
2151 | Assert(VSrc->getNumElements() == VDest->getNumElements(),do { if (!(VSrc->getNumElements() == VDest->getNumElements ())) { CheckFailed("IntToPtr Vector width mismatch", &I); return; } } while (0) | |||||
2152 | "IntToPtr Vector width mismatch", &I)do { if (!(VSrc->getNumElements() == VDest->getNumElements ())) { CheckFailed("IntToPtr Vector width mismatch", &I); return; } } while (0); | |||||
2153 | } | |||||
2154 | visitInstruction(I); | |||||
2155 | } | |||||
2156 | ||||||
2157 | void Verifier::visitBitCastInst(BitCastInst &I) { | |||||
2158 | Assert(do { if (!(CastInst::castIsValid(Instruction::BitCast, I.getOperand (0), I.getType()))) { CheckFailed("Invalid bitcast", &I); return; } } while (0) | |||||
2159 | 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 (0) | |||||
2160 | "Invalid bitcast", &I)do { if (!(CastInst::castIsValid(Instruction::BitCast, I.getOperand (0), I.getType()))) { CheckFailed("Invalid bitcast", &I); return; } } while (0); | |||||
2161 | visitInstruction(I); | |||||
2162 | } | |||||
2163 | ||||||
2164 | void Verifier::visitAddrSpaceCastInst(AddrSpaceCastInst &I) { | |||||
2165 | Type *SrcTy = I.getOperand(0)->getType(); | |||||
2166 | Type *DestTy = I.getType(); | |||||
2167 | ||||||
2168 | Assert(SrcTy->isPtrOrPtrVectorTy(), "AddrSpaceCast source must be a pointer",do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast source must be a pointer" , &I); return; } } while (0) | |||||
2169 | &I)do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast source must be a pointer" , &I); return; } } while (0); | |||||
2170 | Assert(DestTy->isPtrOrPtrVectorTy(), "AddrSpaceCast result must be a pointer",do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast result must be a pointer" , &I); return; } } while (0) | |||||
2171 | &I)do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast result must be a pointer" , &I); return; } } while (0); | |||||
2172 | Assert(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace(),do { if (!(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace ())) { CheckFailed("AddrSpaceCast must be between different address spaces" , &I); return; } } while (0) | |||||
2173 | "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 (0); | |||||
2174 | if (SrcTy->isVectorTy()) | |||||
2175 | Assert(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements(),do { if (!(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements ())) { CheckFailed("AddrSpaceCast vector pointer number of elements mismatch" , &I); return; } } while (0) | |||||
2176 | "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 (0); | |||||
2177 | visitInstruction(I); | |||||
2178 | } | |||||
2179 | ||||||
2180 | /// visitPHINode - Ensure that a PHI node is well formed. | |||||
2181 | /// | |||||
2182 | void Verifier::visitPHINode(PHINode &PN) { | |||||
2183 | // Ensure that the PHI nodes are all grouped together at the top of the block. | |||||
2184 | // This can be tested by checking whether the instruction before this is | |||||
2185 | // either nonexistent (because this is begin()) or is a PHI node. If not, | |||||
2186 | // then there is some other instruction before a PHI. | |||||
2187 | 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 (0) | |||||
2188 | 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 (0) | |||||
2189 | "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 (0); | |||||
2190 | ||||||
2191 | // Check that a PHI doesn't yield a Token. | |||||
2192 | Assert(!PN.getType()->isTokenTy(), "PHI nodes cannot have token type!")do { if (!(!PN.getType()->isTokenTy())) { CheckFailed("PHI nodes cannot have token type!" ); return; } } while (0); | |||||
2193 | ||||||
2194 | // Check that all of the values of the PHI node have the same type as the | |||||
2195 | // result, and that the incoming blocks are really basic blocks. | |||||
2196 | for (Value *IncValue : PN.incoming_values()) { | |||||
2197 | 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 (0) | |||||
2198 | "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 (0); | |||||
2199 | } | |||||
2200 | ||||||
2201 | // All other PHI node constraints are checked in the visitBasicBlock method. | |||||
2202 | ||||||
2203 | visitInstruction(PN); | |||||
2204 | } | |||||
2205 | ||||||
2206 | void Verifier::VerifyCallSite(CallSite CS) { | |||||
2207 | Instruction *I = CS.getInstruction(); | |||||
2208 | ||||||
2209 | Assert(CS.getCalledValue()->getType()->isPointerTy(),do { if (!(CS.getCalledValue()->getType()->isPointerTy( ))) { CheckFailed("Called function must be a pointer!", I); return ; } } while (0) | |||||
2210 | "Called function must be a pointer!", I)do { if (!(CS.getCalledValue()->getType()->isPointerTy( ))) { CheckFailed("Called function must be a pointer!", I); return ; } } while (0); | |||||
2211 | PointerType *FPTy = cast<PointerType>(CS.getCalledValue()->getType()); | |||||
2212 | ||||||
2213 | Assert(FPTy->getElementType()->isFunctionTy(),do { if (!(FPTy->getElementType()->isFunctionTy())) { CheckFailed ("Called function is not pointer to function type!", I); return ; } } while (0) | |||||
2214 | "Called function is not pointer to function type!", I)do { if (!(FPTy->getElementType()->isFunctionTy())) { CheckFailed ("Called function is not pointer to function type!", I); return ; } } while (0); | |||||
2215 | ||||||
2216 | Assert(FPTy->getElementType() == CS.getFunctionType(),do { if (!(FPTy->getElementType() == CS.getFunctionType()) ) { CheckFailed("Called function is not the same type as the call!" , I); return; } } while (0) | |||||
2217 | "Called function is not the same type as the call!", I)do { if (!(FPTy->getElementType() == CS.getFunctionType()) ) { CheckFailed("Called function is not the same type as the call!" , I); return; } } while (0); | |||||
2218 | ||||||
2219 | FunctionType *FTy = CS.getFunctionType(); | |||||
2220 | ||||||
2221 | // Verify that the correct number of arguments are being passed | |||||
2222 | if (FTy->isVarArg()) | |||||
2223 | Assert(CS.arg_size() >= FTy->getNumParams(),do { if (!(CS.arg_size() >= FTy->getNumParams())) { CheckFailed ("Called function requires more parameters than were provided!" , I); return; } } while (0) | |||||
2224 | "Called function requires more parameters than were provided!", I)do { if (!(CS.arg_size() >= FTy->getNumParams())) { CheckFailed ("Called function requires more parameters than were provided!" , I); return; } } while (0); | |||||
2225 | else | |||||
2226 | Assert(CS.arg_size() == FTy->getNumParams(),do { if (!(CS.arg_size() == FTy->getNumParams())) { CheckFailed ("Incorrect number of arguments passed to called function!", I ); return; } } while (0) | |||||
2227 | "Incorrect number of arguments passed to called function!", I)do { if (!(CS.arg_size() == FTy->getNumParams())) { CheckFailed ("Incorrect number of arguments passed to called function!", I ); return; } } while (0); | |||||
2228 | ||||||
2229 | // Verify that all arguments to the call match the function type. | |||||
2230 | for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) | |||||
2231 | Assert(CS.getArgument(i)->getType() == FTy->getParamType(i),do { if (!(CS.getArgument(i)->getType() == FTy->getParamType (i))) { CheckFailed("Call parameter type does not match function signature!" , CS.getArgument(i), FTy->getParamType(i), I); return; } } while (0) | |||||
2232 | "Call parameter type does not match function signature!",do { if (!(CS.getArgument(i)->getType() == FTy->getParamType (i))) { CheckFailed("Call parameter type does not match function signature!" , CS.getArgument(i), FTy->getParamType(i), I); return; } } while (0) | |||||
2233 | CS.getArgument(i), FTy->getParamType(i), I)do { if (!(CS.getArgument(i)->getType() == FTy->getParamType (i))) { CheckFailed("Call parameter type does not match function signature!" , CS.getArgument(i), FTy->getParamType(i), I); return; } } while (0); | |||||
2234 | ||||||
2235 | AttributeSet Attrs = CS.getAttributes(); | |||||
2236 | ||||||
2237 | Assert(VerifyAttributeCount(Attrs, CS.arg_size()),do { if (!(VerifyAttributeCount(Attrs, CS.arg_size()))) { CheckFailed ("Attribute after last parameter!", I); return; } } while (0) | |||||
2238 | "Attribute after last parameter!", I)do { if (!(VerifyAttributeCount(Attrs, CS.arg_size()))) { CheckFailed ("Attribute after last parameter!", I); return; } } while (0); | |||||
2239 | ||||||
2240 | // Verify call attributes. | |||||
2241 | VerifyFunctionAttrs(FTy, Attrs, I); | |||||
2242 | ||||||
2243 | // Conservatively check the inalloca argument. | |||||
2244 | // We have a bug if we can find that there is an underlying alloca without | |||||
2245 | // inalloca. | |||||
2246 | if (CS.hasInAllocaArgument()) { | |||||
2247 | Value *InAllocaArg = CS.getArgument(FTy->getNumParams() - 1); | |||||
2248 | if (auto AI = dyn_cast<AllocaInst>(InAllocaArg->stripInBoundsOffsets())) | |||||
2249 | Assert(AI->isUsedWithInAlloca(),do { if (!(AI->isUsedWithInAlloca())) { CheckFailed("inalloca argument for call has mismatched alloca" , AI, I); return; } } while (0) | |||||
2250 | "inalloca argument for call has mismatched alloca", AI, I)do { if (!(AI->isUsedWithInAlloca())) { CheckFailed("inalloca argument for call has mismatched alloca" , AI, I); return; } } while (0); | |||||
2251 | } | |||||
2252 | ||||||
2253 | if (FTy->isVarArg()) { | |||||
2254 | // FIXME? is 'nest' even legal here? | |||||
2255 | bool SawNest = false; | |||||
2256 | bool SawReturned = false; | |||||
2257 | ||||||
2258 | for (unsigned Idx = 1; Idx < 1 + FTy->getNumParams(); ++Idx) { | |||||
2259 | if (Attrs.hasAttribute(Idx, Attribute::Nest)) | |||||
2260 | SawNest = true; | |||||
2261 | if (Attrs.hasAttribute(Idx, Attribute::Returned)) | |||||
2262 | SawReturned = true; | |||||
2263 | } | |||||
2264 | ||||||
2265 | // Check attributes on the varargs part. | |||||
2266 | for (unsigned Idx = 1 + FTy->getNumParams(); Idx <= CS.arg_size(); ++Idx) { | |||||
2267 | Type *Ty = CS.getArgument(Idx-1)->getType(); | |||||
2268 | VerifyParameterAttrs(Attrs, Idx, Ty, false, I); | |||||
2269 | ||||||
2270 | if (Attrs.hasAttribute(Idx, Attribute::Nest)) { | |||||
2271 | Assert(!SawNest, "More than one parameter has attribute nest!", I)do { if (!(!SawNest)) { CheckFailed("More than one parameter has attribute nest!" , I); return; } } while (0); | |||||
2272 | SawNest = true; | |||||
2273 | } | |||||
2274 | ||||||
2275 | if (Attrs.hasAttribute(Idx, Attribute::Returned)) { | |||||
2276 | Assert(!SawReturned, "More than one parameter has attribute returned!",do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!" , I); return; } } while (0) | |||||
2277 | I)do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!" , I); return; } } while (0); | |||||
2278 | Assert(Ty->canLosslesslyBitCastTo(FTy->getReturnType()),do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' " "attribute", I); return; } } while (0) | |||||
2279 | "Incompatible argument and return types for 'returned' "do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' " "attribute", I); return; } } while (0) | |||||
2280 | "attribute",do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' " "attribute", I); return; } } while (0) | |||||
2281 | I)do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' " "attribute", I); return; } } while (0); | |||||
2282 | SawReturned = true; | |||||
2283 | } | |||||
2284 | ||||||
2285 | Assert(!Attrs.hasAttribute(Idx, Attribute::StructRet),do { if (!(!Attrs.hasAttribute(Idx, Attribute::StructRet))) { CheckFailed("Attribute 'sret' cannot be used for vararg call arguments!" , I); return; } } while (0) | |||||
2286 | "Attribute 'sret' cannot be used for vararg call arguments!", I)do { if (!(!Attrs.hasAttribute(Idx, Attribute::StructRet))) { CheckFailed("Attribute 'sret' cannot be used for vararg call arguments!" , I); return; } } while (0); | |||||
2287 | ||||||
2288 | if (Attrs.hasAttribute(Idx, Attribute::InAlloca)) | |||||
2289 | Assert(Idx == CS.arg_size(), "inalloca isn't on the last argument!", I)do { if (!(Idx == CS.arg_size())) { CheckFailed("inalloca isn't on the last argument!" , I); return; } } while (0); | |||||
2290 | } | |||||
2291 | } | |||||
2292 | ||||||
2293 | // Verify that there's no metadata unless it's a direct call to an intrinsic. | |||||
2294 | if (CS.getCalledFunction() == nullptr || | |||||
2295 | !CS.getCalledFunction()->getName().startswith("llvm.")) { | |||||
2296 | for (Type *ParamTy : FTy->params()) { | |||||
2297 | Assert(!ParamTy->isMetadataTy(),do { if (!(!ParamTy->isMetadataTy())) { CheckFailed("Function has metadata parameter but isn't an intrinsic" , I); return; } } while (0) | |||||
2298 | "Function has metadata parameter but isn't an intrinsic", I)do { if (!(!ParamTy->isMetadataTy())) { CheckFailed("Function has metadata parameter but isn't an intrinsic" , I); return; } } while (0); | |||||
2299 | Assert(!ParamTy->isTokenTy(),do { if (!(!ParamTy->isTokenTy())) { CheckFailed("Function has token parameter but isn't an intrinsic" , I); return; } } while (0) | |||||
2300 | "Function has token parameter but isn't an intrinsic", I)do { if (!(!ParamTy->isTokenTy())) { CheckFailed("Function has token parameter but isn't an intrinsic" , I); return; } } while (0); | |||||
2301 | } | |||||
2302 | } | |||||
2303 | ||||||
2304 | // Verify that indirect calls don't return tokens. | |||||
2305 | if (CS.getCalledFunction() == nullptr) | |||||
2306 | Assert(!FTy->getReturnType()->isTokenTy(),do { if (!(!FTy->getReturnType()->isTokenTy())) { CheckFailed ("Return type cannot be token for indirect call!"); return; } } while (0) | |||||
2307 | "Return type cannot be token for indirect call!")do { if (!(!FTy->getReturnType()->isTokenTy())) { CheckFailed ("Return type cannot be token for indirect call!"); return; } } while (0); | |||||
2308 | ||||||
2309 | if (Function *F = CS.getCalledFunction()) | |||||
2310 | if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) | |||||
2311 | visitIntrinsicCallSite(ID, CS); | |||||
2312 | ||||||
2313 | visitInstruction(*I); | |||||
2314 | } | |||||
2315 | ||||||
2316 | /// Two types are "congruent" if they are identical, or if they are both pointer | |||||
2317 | /// types with different pointee types and the same address space. | |||||
2318 | static bool isTypeCongruent(Type *L, Type *R) { | |||||
2319 | if (L == R) | |||||
2320 | return true; | |||||
2321 | PointerType *PL = dyn_cast<PointerType>(L); | |||||
2322 | PointerType *PR = dyn_cast<PointerType>(R); | |||||
2323 | if (!PL || !PR) | |||||
2324 | return false; | |||||
2325 | return PL->getAddressSpace() == PR->getAddressSpace(); | |||||
2326 | } | |||||
2327 | ||||||
2328 | static AttrBuilder getParameterABIAttributes(int I, AttributeSet Attrs) { | |||||
2329 | static const Attribute::AttrKind ABIAttrs[] = { | |||||
2330 | Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca, | |||||
2331 | Attribute::InReg, Attribute::Returned}; | |||||
2332 | AttrBuilder Copy; | |||||
2333 | for (auto AK : ABIAttrs) { | |||||
2334 | if (Attrs.hasAttribute(I + 1, AK)) | |||||
2335 | Copy.addAttribute(AK); | |||||
2336 | } | |||||
2337 | if (Attrs.hasAttribute(I + 1, Attribute::Alignment)) | |||||
2338 | Copy.addAlignmentAttr(Attrs.getParamAlignment(I + 1)); | |||||
2339 | return Copy; | |||||
2340 | } | |||||
2341 | ||||||
2342 | void Verifier::verifyMustTailCall(CallInst &CI) { | |||||
2343 | 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 (0); | |||||
2344 | ||||||
2345 | // - The caller and callee prototypes must match. Pointer types of | |||||
2346 | // parameters or return types may differ in pointee type, but not | |||||
2347 | // address space. | |||||
2348 | Function *F = CI.getParent()->getParent(); | |||||
2349 | FunctionType *CallerTy = F->getFunctionType(); | |||||
2350 | FunctionType *CalleeTy = CI.getFunctionType(); | |||||
2351 | Assert(CallerTy->getNumParams() == CalleeTy->getNumParams(),do { if (!(CallerTy->getNumParams() == CalleeTy->getNumParams ())) { CheckFailed("cannot guarantee tail call due to mismatched parameter counts" , &CI); return; } } while (0) | |||||
2352 | "cannot guarantee tail call due to mismatched parameter counts", &CI)do { if (!(CallerTy->getNumParams() == CalleeTy->getNumParams ())) { CheckFailed("cannot guarantee tail call due to mismatched parameter counts" , &CI); return; } } while (0); | |||||
2353 | Assert(CallerTy->isVarArg() == CalleeTy->isVarArg(),do { if (!(CallerTy->isVarArg() == CalleeTy->isVarArg() )) { CheckFailed("cannot guarantee tail call due to mismatched varargs" , &CI); return; } } while (0) | |||||
2354 | "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 (0); | |||||
2355 | 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 (0) | |||||
2356 | "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 (0); | |||||
2357 | for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) { | |||||
2358 | Assert(do { if (!(isTypeCongruent(CallerTy->getParamType(I), CalleeTy ->getParamType(I)))) { CheckFailed("cannot guarantee tail call due to mismatched parameter types" , &CI); return; } } while (0) | |||||
2359 | 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 (0) | |||||
2360 | "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 (0); | |||||
2361 | } | |||||
2362 | ||||||
2363 | // - The calling conventions of the caller and callee must match. | |||||
2364 | Assert(F->getCallingConv() == CI.getCallingConv(),do { if (!(F->getCallingConv() == CI.getCallingConv())) { CheckFailed ("cannot guarantee tail call due to mismatched calling conv", &CI); return; } } while (0) | |||||
2365 | "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 (0); | |||||
2366 | ||||||
2367 | // - All ABI-impacting function attributes, such as sret, byval, inreg, | |||||
2368 | // returned, and inalloca, must match. | |||||
2369 | AttributeSet CallerAttrs = F->getAttributes(); | |||||
2370 | AttributeSet CalleeAttrs = CI.getAttributes(); | |||||
2371 | for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) { | |||||
2372 | AttrBuilder CallerABIAttrs = getParameterABIAttributes(I, CallerAttrs); | |||||
2373 | AttrBuilder CalleeABIAttrs = getParameterABIAttributes(I, CalleeAttrs); | |||||
2374 | 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 (0) | |||||
2375 | "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 (0) | |||||
2376 | "function attributes",do { if (!(CallerABIAttrs == CalleeABIAttrs)) { CheckFailed("cannot guarantee tail call due to mismatched ABI impacting " "function attributes", &CI, CI.getOperand(I)); return; } } while (0) | |||||
2377 | &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 (0); | |||||
2378 | } | |||||
2379 | ||||||
2380 | // - The call must immediately precede a :ref:`ret <i_ret>` instruction, | |||||
2381 | // or a pointer bitcast followed by a ret instruction. | |||||
2382 | // - The ret instruction must return the (possibly bitcasted) value | |||||
2383 | // produced by the call or void. | |||||
2384 | Value *RetVal = &CI; | |||||
2385 | Instruction *Next = CI.getNextNode(); | |||||
2386 | ||||||
2387 | // Handle the optional bitcast. | |||||
2388 | if (BitCastInst *BI = dyn_cast_or_null<BitCastInst>(Next)) { | |||||
2389 | Assert(BI->getOperand(0) == RetVal,do { if (!(BI->getOperand(0) == RetVal)) { CheckFailed("bitcast following musttail call must use the call" , BI); return; } } while (0) | |||||
2390 | "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 (0); | |||||
2391 | RetVal = BI; | |||||
2392 | Next = BI->getNextNode(); | |||||
2393 | } | |||||
2394 | ||||||
2395 | // Check the return. | |||||
2396 | ReturnInst *Ret = dyn_cast_or_null<ReturnInst>(Next); | |||||
2397 | Assert(Ret, "musttail call must be precede a ret with an optional bitcast",do { if (!(Ret)) { CheckFailed("musttail call must be precede a ret with an optional bitcast" , &CI); return; } } while (0) | |||||
2398 | &CI)do { if (!(Ret)) { CheckFailed("musttail call must be precede a ret with an optional bitcast" , &CI); return; } } while (0); | |||||
2399 | Assert(!Ret->getReturnValue() || Ret->getReturnValue() == RetVal,do { if (!(!Ret->getReturnValue() || Ret->getReturnValue () == RetVal)) { CheckFailed("musttail call result must be returned" , Ret); return; } } while (0) | |||||
2400 | "musttail call result must be returned", Ret)do { if (!(!Ret->getReturnValue() || Ret->getReturnValue () == RetVal)) { CheckFailed("musttail call result must be returned" , Ret); return; } } while (0); | |||||
2401 | } | |||||
2402 | ||||||
2403 | void Verifier::visitCallInst(CallInst &CI) { | |||||
2404 | VerifyCallSite(&CI); | |||||
2405 | ||||||
2406 | if (CI.isMustTailCall()) | |||||
2407 | verifyMustTailCall(CI); | |||||
2408 | } | |||||
2409 | ||||||
2410 | void Verifier::visitInvokeInst(InvokeInst &II) { | |||||
2411 | VerifyCallSite(&II); | |||||
2412 | ||||||
2413 | // Verify that the first non-PHI instruction of the unwind destination is an | |||||
2414 | // exception handling instruction. | |||||
2415 | Assert(do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!" , &II); return; } } while (0) | |||||
2416 | II.getUnwindDest()->isEHPad(),do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!" , &II); return; } } while (0) | |||||
2417 | "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 (0) | |||||
2418 | &II)do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!" , &II); return; } } while (0); | |||||
2419 | ||||||
2420 | visitTerminatorInst(II); | |||||
2421 | } | |||||
2422 | ||||||
2423 | /// visitBinaryOperator - Check that both arguments to the binary operator are | |||||
2424 | /// of the same type! | |||||
2425 | /// | |||||
2426 | void Verifier::visitBinaryOperator(BinaryOperator &B) { | |||||
2427 | 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 (0) | |||||
2428 | "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 (0); | |||||
2429 | ||||||
2430 | switch (B.getOpcode()) { | |||||
2431 | // Check that integer arithmetic operators are only used with | |||||
2432 | // integral operands. | |||||
2433 | case Instruction::Add: | |||||
2434 | case Instruction::Sub: | |||||
2435 | case Instruction::Mul: | |||||
2436 | case Instruction::SDiv: | |||||
2437 | case Instruction::UDiv: | |||||
2438 | case Instruction::SRem: | |||||
2439 | case Instruction::URem: | |||||
2440 | Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Integer arithmetic operators only work with integral types!" , &B); return; } } while (0) | |||||
2441 | "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 (0); | |||||
2442 | 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 (0) | |||||
2443 | "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 (0) | |||||
2444 | "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 (0) | |||||
2445 | &B)do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Integer arithmetic operators must have same type " "for operands and result!" , &B); return; } } while (0); | |||||
2446 | break; | |||||
2447 | // Check that floating-point arithmetic operators are only used with | |||||
2448 | // floating-point operands. | |||||
2449 | case Instruction::FAdd: | |||||
2450 | case Instruction::FSub: | |||||
2451 | case Instruction::FMul: | |||||
2452 | case Instruction::FDiv: | |||||
2453 | case Instruction::FRem: | |||||
2454 | Assert(B.getType()->isFPOrFPVectorTy(),do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed ("Floating-point arithmetic operators only work with " "floating-point types!" , &B); return; } } while (0) | |||||
2455 | "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 (0) | |||||
2456 | "floating-point types!",do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed ("Floating-point arithmetic operators only work with " "floating-point types!" , &B); return; } } while (0) | |||||
2457 | &B)do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed ("Floating-point arithmetic operators only work with " "floating-point types!" , &B); return; } } while (0); | |||||
2458 | 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 (0) | |||||
2459 | "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 (0) | |||||
2460 | "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 (0) | |||||
2461 | &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 (0); | |||||
2462 | break; | |||||
2463 | // Check that logical operators are only used with integral operands. | |||||
2464 | case Instruction::And: | |||||
2465 | case Instruction::Or: | |||||
2466 | case Instruction::Xor: | |||||
2467 | Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Logical operators only work with integral types!", &B); return; } } while (0) | |||||
2468 | "Logical operators only work with integral types!", &B)do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Logical operators only work with integral types!", &B); return; } } while (0); | |||||
2469 | 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 (0) | |||||
2470 | "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 (0) | |||||
2471 | &B)do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Logical operators must have same type for operands and result!" , &B); return; } } while (0); | |||||
2472 | break; | |||||
2473 | case Instruction::Shl: | |||||
2474 | case Instruction::LShr: | |||||
2475 | case Instruction::AShr: | |||||
2476 | Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Shifts only work with integral types!", &B); return; } } while (0) | |||||
2477 | "Shifts only work with integral types!", &B)do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Shifts only work with integral types!", &B); return; } } while (0); | |||||
2478 | 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 (0) | |||||
2479 | "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 (0); | |||||
2480 | break; | |||||
2481 | default: | |||||
2482 | llvm_unreachable("Unknown BinaryOperator opcode!")::llvm::llvm_unreachable_internal("Unknown BinaryOperator opcode!" , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 2482); | |||||
2483 | } | |||||
2484 | ||||||
2485 | visitInstruction(B); | |||||
2486 | } | |||||
2487 | ||||||
2488 | void Verifier::visitICmpInst(ICmpInst &IC) { | |||||
2489 | // Check that the operands are the same type | |||||
2490 | Type *Op0Ty = IC.getOperand(0)->getType(); | |||||
2491 | Type *Op1Ty = IC.getOperand(1)->getType(); | |||||
2492 | Assert(Op0Ty == Op1Ty,do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to ICmp instruction are not of the same type!" , &IC); return; } } while (0) | |||||
2493 | "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 (0); | |||||
2494 | // Check that the operands are the right type | |||||
2495 | Assert(Op0Ty->isIntOrIntVectorTy() || Op0Ty->getScalarType()->isPointerTy(),do { if (!(Op0Ty->isIntOrIntVectorTy() || Op0Ty->getScalarType ()->isPointerTy())) { CheckFailed("Invalid operand types for ICmp instruction" , &IC); return; } } while (0) | |||||
2496 | "Invalid operand types for ICmp instruction", &IC)do { if (!(Op0Ty->isIntOrIntVectorTy() || Op0Ty->getScalarType ()->isPointerTy())) { CheckFailed("Invalid operand types for ICmp instruction" , &IC); return; } } while (0); | |||||
2497 | // Check that the predicate is valid. | |||||
2498 | Assert(IC.getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE &&do { if (!(IC.getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE && IC.getPredicate() <= CmpInst::LAST_ICMP_PREDICATE )) { CheckFailed("Invalid predicate in ICmp instruction!", & IC); return; } } while (0) | |||||
2499 | IC.getPredicate() <= CmpInst::LAST_ICMP_PREDICATE,do { if (!(IC.getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE && IC.getPredicate() <= CmpInst::LAST_ICMP_PREDICATE )) { CheckFailed("Invalid predicate in ICmp instruction!", & IC); return; } } while (0) | |||||
2500 | "Invalid predicate in ICmp instruction!", &IC)do { if (!(IC.getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE && IC.getPredicate() <= CmpInst::LAST_ICMP_PREDICATE )) { CheckFailed("Invalid predicate in ICmp instruction!", & IC); return; } } while (0); | |||||
2501 | ||||||
2502 | visitInstruction(IC); | |||||
2503 | } | |||||
2504 | ||||||
2505 | void Verifier::visitFCmpInst(FCmpInst &FC) { | |||||
2506 | // Check that the operands are the same type | |||||
2507 | Type *Op0Ty = FC.getOperand(0)->getType(); | |||||
2508 | Type *Op1Ty = FC.getOperand(1)->getType(); | |||||
2509 | Assert(Op0Ty == Op1Ty,do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to FCmp instruction are not of the same type!" , &FC); return; } } while (0) | |||||
2510 | "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 (0); | |||||
2511 | // Check that the operands are the right type | |||||
2512 | Assert(Op0Ty->isFPOrFPVectorTy(),do { if (!(Op0Ty->isFPOrFPVectorTy())) { CheckFailed("Invalid operand types for FCmp instruction" , &FC); return; } } while (0) | |||||
2513 | "Invalid operand types for FCmp instruction", &FC)do { if (!(Op0Ty->isFPOrFPVectorTy())) { CheckFailed("Invalid operand types for FCmp instruction" , &FC); return; } } while (0); | |||||
2514 | // Check that the predicate is valid. | |||||
2515 | Assert(FC.getPredicate() >= CmpInst::FIRST_FCMP_PREDICATE &&do { if (!(FC.getPredicate() >= CmpInst::FIRST_FCMP_PREDICATE && FC.getPredicate() <= CmpInst::LAST_FCMP_PREDICATE )) { CheckFailed("Invalid predicate in FCmp instruction!", & FC); return; } } while (0) | |||||
2516 | FC.getPredicate() <= CmpInst::LAST_FCMP_PREDICATE,do { if (!(FC.getPredicate() >= CmpInst::FIRST_FCMP_PREDICATE && FC.getPredicate() <= CmpInst::LAST_FCMP_PREDICATE )) { CheckFailed("Invalid predicate in FCmp instruction!", & FC); return; } } while (0) | |||||
2517 | "Invalid predicate in FCmp instruction!", &FC)do { if (!(FC.getPredicate() >= CmpInst::FIRST_FCMP_PREDICATE && FC.getPredicate() <= CmpInst::LAST_FCMP_PREDICATE )) { CheckFailed("Invalid predicate in FCmp instruction!", & FC); return; } } while (0); | |||||
2518 | ||||||
2519 | visitInstruction(FC); | |||||
2520 | } | |||||
2521 | ||||||
2522 | void Verifier::visitExtractElementInst(ExtractElementInst &EI) { | |||||
2523 | Assert(do { if (!(ExtractElementInst::isValidOperands(EI.getOperand( 0), EI.getOperand(1)))) { CheckFailed("Invalid extractelement operands!" , &EI); return; } } while (0) | |||||
2524 | 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 (0) | |||||
2525 | "Invalid extractelement operands!", &EI)do { if (!(ExtractElementInst::isValidOperands(EI.getOperand( 0), EI.getOperand(1)))) { CheckFailed("Invalid extractelement operands!" , &EI); return; } } while (0); | |||||
2526 | visitInstruction(EI); | |||||
2527 | } | |||||
2528 | ||||||
2529 | void Verifier::visitInsertElementInst(InsertElementInst &IE) { | |||||
2530 | 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 (0) | |||||
2531 | IE.getOperand(2)),do { if (!(InsertElementInst::isValidOperands(IE.getOperand(0 ), IE.getOperand(1), IE.getOperand(2)))) { CheckFailed("Invalid insertelement operands!" , &IE); return; } } while (0) | |||||
2532 | "Invalid insertelement operands!", &IE)do { if (!(InsertElementInst::isValidOperands(IE.getOperand(0 ), IE.getOperand(1), IE.getOperand(2)))) { CheckFailed("Invalid insertelement operands!" , &IE); return; } } while (0); | |||||
2533 | visitInstruction(IE); | |||||
2534 | } | |||||
2535 | ||||||
2536 | void Verifier::visitShuffleVectorInst(ShuffleVectorInst &SV) { | |||||
2537 | 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 (0) | |||||
2538 | SV.getOperand(2)),do { if (!(ShuffleVectorInst::isValidOperands(SV.getOperand(0 ), SV.getOperand(1), SV.getOperand(2)))) { CheckFailed("Invalid shufflevector operands!" , &SV); return; } } while (0) | |||||
2539 | "Invalid shufflevector operands!", &SV)do { if (!(ShuffleVectorInst::isValidOperands(SV.getOperand(0 ), SV.getOperand(1), SV.getOperand(2)))) { CheckFailed("Invalid shufflevector operands!" , &SV); return; } } while (0); | |||||
2540 | visitInstruction(SV); | |||||
2541 | } | |||||
2542 | ||||||
2543 | void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) { | |||||
2544 | Type *TargetTy = GEP.getPointerOperandType()->getScalarType(); | |||||
2545 | ||||||
2546 | 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 (0) | |||||
2547 | "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 (0); | |||||
2548 | Assert(GEP.getSourceElementType()->isSized(), "GEP into unsized type!", &GEP)do { if (!(GEP.getSourceElementType()->isSized())) { CheckFailed ("GEP into unsized type!", &GEP); return; } } while (0); | |||||
2549 | SmallVector<Value*, 16> Idxs(GEP.idx_begin(), GEP.idx_end()); | |||||
2550 | Type *ElTy = | |||||
2551 | GetElementPtrInst::getIndexedType(GEP.getSourceElementType(), Idxs); | |||||
2552 | Assert(ElTy, "Invalid indices for GEP pointer type!", &GEP)do { if (!(ElTy)) { CheckFailed("Invalid indices for GEP pointer type!" , &GEP); return; } } while (0); | |||||
2553 | ||||||
2554 | Assert(GEP.getType()->getScalarType()->isPointerTy() &&do { if (!(GEP.getType()->getScalarType()->isPointerTy( ) && GEP.getResultElementType() == ElTy)) { CheckFailed ("GEP is not of right type for indices!", &GEP, ElTy); return ; } } while (0) | |||||
2555 | GEP.getResultElementType() == ElTy,do { if (!(GEP.getType()->getScalarType()->isPointerTy( ) && GEP.getResultElementType() == ElTy)) { CheckFailed ("GEP is not of right type for indices!", &GEP, ElTy); return ; } } while (0) | |||||
2556 | "GEP is not of right type for indices!", &GEP, ElTy)do { if (!(GEP.getType()->getScalarType()->isPointerTy( ) && GEP.getResultElementType() == ElTy)) { CheckFailed ("GEP is not of right type for indices!", &GEP, ElTy); return ; } } while (0); | |||||
2557 | ||||||
2558 | if (GEP.getType()->isVectorTy()) { | |||||
2559 | // Additional checks for vector GEPs. | |||||
2560 | unsigned GEPWidth = GEP.getType()->getVectorNumElements(); | |||||
2561 | if (GEP.getPointerOperandType()->isVectorTy()) | |||||
2562 | Assert(GEPWidth == GEP.getPointerOperandType()->getVectorNumElements(),do { if (!(GEPWidth == GEP.getPointerOperandType()->getVectorNumElements ())) { CheckFailed("Vector GEP result width doesn't match operand's" , &GEP); return; } } while (0) | |||||
2563 | "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 (0); | |||||
2564 | for (unsigned i = 0, e = Idxs.size(); i != e; ++i) { | |||||
2565 | Type *IndexTy = Idxs[i]->getType(); | |||||
2566 | if (IndexTy->isVectorTy()) { | |||||
2567 | unsigned IndexWidth = IndexTy->getVectorNumElements(); | |||||
2568 | Assert(IndexWidth == GEPWidth, "Invalid GEP index vector width", &GEP)do { if (!(IndexWidth == GEPWidth)) { CheckFailed("Invalid GEP index vector width" , &GEP); return; } } while (0); | |||||
2569 | } | |||||
2570 | Assert(IndexTy->getScalarType()->isIntegerTy(),do { if (!(IndexTy->getScalarType()->isIntegerTy())) { CheckFailed ("All GEP indices should be of integer type"); return; } } while (0) | |||||
2571 | "All GEP indices should be of integer type")do { if (!(IndexTy->getScalarType()->isIntegerTy())) { CheckFailed ("All GEP indices should be of integer type"); return; } } while (0); | |||||
2572 | } | |||||
2573 | } | |||||
2574 | visitInstruction(GEP); | |||||
2575 | } | |||||
2576 | ||||||
2577 | static bool isContiguous(const ConstantRange &A, const ConstantRange &B) { | |||||
2578 | return A.getUpper() == B.getLower() || A.getLower() == B.getUpper(); | |||||
2579 | } | |||||
2580 | ||||||
2581 | void Verifier::visitRangeMetadata(Instruction& I, | |||||
2582 | MDNode* Range, Type* Ty) { | |||||
2583 | assert(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\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 2585, __PRETTY_FUNCTION__)) | |||||
2584 | 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\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 2585, __PRETTY_FUNCTION__)) | |||||
2585 | "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\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 2585, __PRETTY_FUNCTION__)); | |||||
2586 | ||||||
2587 | unsigned NumOperands = Range->getNumOperands(); | |||||
2588 | Assert(NumOperands % 2 == 0, "Unfinished range!", Range)do { if (!(NumOperands % 2 == 0)) { CheckFailed("Unfinished range!" , Range); return; } } while (0); | |||||
2589 | unsigned NumRanges = NumOperands / 2; | |||||
2590 | 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 (0); | |||||
2591 | ||||||
2592 | ConstantRange LastRange(1); // Dummy initial value | |||||
2593 | for (unsigned i = 0; i < NumRanges; ++i) { | |||||
2594 | ConstantInt *Low = | |||||
2595 | mdconst::dyn_extract<ConstantInt>(Range->getOperand(2 * i)); | |||||
2596 | Assert(Low, "The lower limit must be an integer!", Low)do { if (!(Low)) { CheckFailed("The lower limit must be an integer!" , Low); return; } } while (0); | |||||
2597 | ConstantInt *High = | |||||
2598 | mdconst::dyn_extract<ConstantInt>(Range->getOperand(2 * i + 1)); | |||||
2599 | Assert(High, "The upper limit must be an integer!", High)do { if (!(High)) { CheckFailed("The upper limit must be an integer!" , High); return; } } while (0); | |||||
2600 | 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 (0) | |||||
2601 | "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 (0); | |||||
2602 | ||||||
2603 | APInt HighV = High->getValue(); | |||||
2604 | APInt LowV = Low->getValue(); | |||||
2605 | ConstantRange CurRange(LowV, HighV); | |||||
2606 | Assert(!CurRange.isEmptySet() && !CurRange.isFullSet(),do { if (!(!CurRange.isEmptySet() && !CurRange.isFullSet ())) { CheckFailed("Range must not be empty!", Range); return ; } } while (0) | |||||
2607 | "Range must not be empty!", Range)do { if (!(!CurRange.isEmptySet() && !CurRange.isFullSet ())) { CheckFailed("Range must not be empty!", Range); return ; } } while (0); | |||||
2608 | if (i != 0) { | |||||
2609 | Assert(CurRange.intersectWith(LastRange).isEmptySet(),do { if (!(CurRange.intersectWith(LastRange).isEmptySet())) { CheckFailed("Intervals are overlapping", Range); return; } } while (0) | |||||
2610 | "Intervals are overlapping", Range)do { if (!(CurRange.intersectWith(LastRange).isEmptySet())) { CheckFailed("Intervals are overlapping", Range); return; } } while (0); | |||||
2611 | 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 (0) | |||||
2612 | Range)do { if (!(LowV.sgt(LastRange.getLower()))) { CheckFailed("Intervals are not in order" , Range); return; } } while (0); | |||||
2613 | Assert(!isContiguous(CurRange, LastRange), "Intervals are contiguous",do { if (!(!isContiguous(CurRange, LastRange))) { CheckFailed ("Intervals are contiguous", Range); return; } } while (0) | |||||
2614 | Range)do { if (!(!isContiguous(CurRange, LastRange))) { CheckFailed ("Intervals are contiguous", Range); return; } } while (0); | |||||
2615 | } | |||||
2616 | LastRange = ConstantRange(LowV, HighV); | |||||
2617 | } | |||||
2618 | if (NumRanges > 2) { | |||||
2619 | APInt FirstLow = | |||||
2620 | mdconst::dyn_extract<ConstantInt>(Range->getOperand(0))->getValue(); | |||||
2621 | APInt FirstHigh = | |||||
2622 | mdconst::dyn_extract<ConstantInt>(Range->getOperand(1))->getValue(); | |||||
2623 | ConstantRange FirstRange(FirstLow, FirstHigh); | |||||
2624 | Assert(FirstRange.intersectWith(LastRange).isEmptySet(),do { if (!(FirstRange.intersectWith(LastRange).isEmptySet())) { CheckFailed("Intervals are overlapping", Range); return; } } while (0) | |||||
2625 | "Intervals are overlapping", Range)do { if (!(FirstRange.intersectWith(LastRange).isEmptySet())) { CheckFailed("Intervals are overlapping", Range); return; } } while (0); | |||||
2626 | Assert(!isContiguous(FirstRange, LastRange), "Intervals are contiguous",do { if (!(!isContiguous(FirstRange, LastRange))) { CheckFailed ("Intervals are contiguous", Range); return; } } while (0) | |||||
2627 | Range)do { if (!(!isContiguous(FirstRange, LastRange))) { CheckFailed ("Intervals are contiguous", Range); return; } } while (0); | |||||
2628 | } | |||||
2629 | } | |||||
2630 | ||||||
2631 | void Verifier::visitLoadInst(LoadInst &LI) { | |||||
2632 | PointerType *PTy = dyn_cast<PointerType>(LI.getOperand(0)->getType()); | |||||
2633 | Assert(PTy, "Load operand must be a pointer.", &LI)do { if (!(PTy)) { CheckFailed("Load operand must be a pointer." , &LI); return; } } while (0); | |||||
2634 | Type *ElTy = LI.getType(); | |||||
2635 | Assert(LI.getAlignment() <= Value::MaximumAlignment,do { if (!(LI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &LI ); return; } } while (0) | |||||
2636 | "huge alignment values are unsupported", &LI)do { if (!(LI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &LI ); return; } } while (0); | |||||
2637 | if (LI.isAtomic()) { | |||||
2638 | Assert(LI.getOrdering() != Release && LI.getOrdering() != AcquireRelease,do { if (!(LI.getOrdering() != Release && LI.getOrdering () != AcquireRelease)) { CheckFailed("Load cannot have Release ordering" , &LI); return; } } while (0) | |||||
2639 | "Load cannot have Release ordering", &LI)do { if (!(LI.getOrdering() != Release && LI.getOrdering () != AcquireRelease)) { CheckFailed("Load cannot have Release ordering" , &LI); return; } } while (0); | |||||
2640 | Assert(LI.getAlignment() != 0,do { if (!(LI.getAlignment() != 0)) { CheckFailed("Atomic load must specify explicit alignment" , &LI); return; } } while (0) | |||||
2641 | "Atomic load must specify explicit alignment", &LI)do { if (!(LI.getAlignment() != 0)) { CheckFailed("Atomic load must specify explicit alignment" , &LI); return; } } while (0); | |||||
2642 | if (!ElTy->isPointerTy()) { | |||||
2643 | Assert(ElTy->isIntegerTy(), "atomic load operand must have integer type!",do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomic load operand must have integer type!" , &LI, ElTy); return; } } while (0) | |||||
2644 | &LI, ElTy)do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomic load operand must have integer type!" , &LI, ElTy); return; } } while (0); | |||||
2645 | unsigned Size = ElTy->getPrimitiveSizeInBits(); | |||||
2646 | Assert(Size >= 8 && !(Size & (Size - 1)),do { if (!(Size >= 8 && !(Size & (Size - 1)))) { CheckFailed("atomic load operand must be power-of-two byte-sized integer" , &LI, ElTy); return; } } while (0) | |||||
2647 | "atomic load operand must be power-of-two byte-sized integer", &LI,do { if (!(Size >= 8 && !(Size & (Size - 1)))) { CheckFailed("atomic load operand must be power-of-two byte-sized integer" , &LI, ElTy); return; } } while (0) | |||||
2648 | ElTy)do { if (!(Size >= 8 && !(Size & (Size - 1)))) { CheckFailed("atomic load operand must be power-of-two byte-sized integer" , &LI, ElTy); return; } } while (0); | |||||
2649 | } | |||||
2650 | } else { | |||||
2651 | Assert(LI.getSynchScope() == CrossThread,do { if (!(LI.getSynchScope() == CrossThread)) { CheckFailed( "Non-atomic load cannot have SynchronizationScope specified", &LI); return; } } while (0) | |||||
2652 | "Non-atomic load cannot have SynchronizationScope specified", &LI)do { if (!(LI.getSynchScope() == CrossThread)) { CheckFailed( "Non-atomic load cannot have SynchronizationScope specified", &LI); return; } } while (0); | |||||
2653 | } | |||||
2654 | ||||||
2655 | visitInstruction(LI); | |||||
2656 | } | |||||
2657 | ||||||
2658 | void Verifier::visitStoreInst(StoreInst &SI) { | |||||
2659 | PointerType *PTy = dyn_cast<PointerType>(SI.getOperand(1)->getType()); | |||||
2660 | Assert(PTy, "Store operand must be a pointer.", &SI)do { if (!(PTy)) { CheckFailed("Store operand must be a pointer." , &SI); return; } } while (0); | |||||
2661 | Type *ElTy = PTy->getElementType(); | |||||
2662 | 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 (0) | |||||
2663 | "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 (0); | |||||
2664 | Assert(SI.getAlignment() <= Value::MaximumAlignment,do { if (!(SI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &SI ); return; } } while (0) | |||||
2665 | "huge alignment values are unsupported", &SI)do { if (!(SI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &SI ); return; } } while (0); | |||||
2666 | if (SI.isAtomic()) { | |||||
2667 | Assert(SI.getOrdering() != Acquire && SI.getOrdering() != AcquireRelease,do { if (!(SI.getOrdering() != Acquire && SI.getOrdering () != AcquireRelease)) { CheckFailed("Store cannot have Acquire ordering" , &SI); return; } } while (0) | |||||
2668 | "Store cannot have Acquire ordering", &SI)do { if (!(SI.getOrdering() != Acquire && SI.getOrdering () != AcquireRelease)) { CheckFailed("Store cannot have Acquire ordering" , &SI); return; } } while (0); | |||||
2669 | Assert(SI.getAlignment() != 0,do { if (!(SI.getAlignment() != 0)) { CheckFailed("Atomic store must specify explicit alignment" , &SI); return; } } while (0) | |||||
2670 | "Atomic store must specify explicit alignment", &SI)do { if (!(SI.getAlignment() != 0)) { CheckFailed("Atomic store must specify explicit alignment" , &SI); return; } } while (0); | |||||
2671 | if (!ElTy->isPointerTy()) { | |||||
2672 | Assert(ElTy->isIntegerTy(),do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomic store operand must have integer type!" , &SI, ElTy); return; } } while (0) | |||||
2673 | "atomic store operand must have integer type!", &SI, ElTy)do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomic store operand must have integer type!" , &SI, ElTy); return; } } while (0); | |||||
2674 | unsigned Size = ElTy->getPrimitiveSizeInBits(); | |||||
2675 | Assert(Size >= 8 && !(Size & (Size - 1)),do { if (!(Size >= 8 && !(Size & (Size - 1)))) { CheckFailed("atomic store operand must be power-of-two byte-sized integer" , &SI, ElTy); return; } } while (0) | |||||
2676 | "atomic store operand must be power-of-two byte-sized integer",do { if (!(Size >= 8 && !(Size & (Size - 1)))) { CheckFailed("atomic store operand must be power-of-two byte-sized integer" , &SI, ElTy); return; } } while (0) | |||||
2677 | &SI, ElTy)do { if (!(Size >= 8 && !(Size & (Size - 1)))) { CheckFailed("atomic store operand must be power-of-two byte-sized integer" , &SI, ElTy); return; } } while (0); | |||||
2678 | } | |||||
2679 | } else { | |||||
2680 | Assert(SI.getSynchScope() == CrossThread,do { if (!(SI.getSynchScope() == CrossThread)) { CheckFailed( "Non-atomic store cannot have SynchronizationScope specified" , &SI); return; } } while (0) | |||||
2681 | "Non-atomic store cannot have SynchronizationScope specified", &SI)do { if (!(SI.getSynchScope() == CrossThread)) { CheckFailed( "Non-atomic store cannot have SynchronizationScope specified" , &SI); return; } } while (0); | |||||
2682 | } | |||||
2683 | visitInstruction(SI); | |||||
2684 | } | |||||
2685 | ||||||
2686 | void Verifier::visitAllocaInst(AllocaInst &AI) { | |||||
2687 | SmallPtrSet<Type*, 4> Visited; | |||||
2688 | PointerType *PTy = AI.getType(); | |||||
2689 | Assert(PTy->getAddressSpace() == 0,do { if (!(PTy->getAddressSpace() == 0)) { CheckFailed("Allocation instruction pointer not in the generic address space!" , &AI); return; } } while (0) | |||||
2690 | "Allocation instruction pointer not in the generic address space!",do { if (!(PTy->getAddressSpace() == 0)) { CheckFailed("Allocation instruction pointer not in the generic address space!" , &AI); return; } } while (0) | |||||
2691 | &AI)do { if (!(PTy->getAddressSpace() == 0)) { CheckFailed("Allocation instruction pointer not in the generic address space!" , &AI); return; } } while (0); | |||||
2692 | Assert(AI.getAllocatedType()->isSized(&Visited),do { if (!(AI.getAllocatedType()->isSized(&Visited))) { CheckFailed("Cannot allocate unsized type", &AI); return ; } } while (0) | |||||
2693 | "Cannot allocate unsized type", &AI)do { if (!(AI.getAllocatedType()->isSized(&Visited))) { CheckFailed("Cannot allocate unsized type", &AI); return ; } } while (0); | |||||
2694 | Assert(AI.getArraySize()->getType()->isIntegerTy(),do { if (!(AI.getArraySize()->getType()->isIntegerTy()) ) { CheckFailed("Alloca array size must have integer type", & AI); return; } } while (0) | |||||
2695 | "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 (0); | |||||
2696 | Assert(AI.getAlignment() <= Value::MaximumAlignment,do { if (!(AI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &AI ); return; } } while (0) | |||||
2697 | "huge alignment values are unsupported", &AI)do { if (!(AI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &AI ); return; } } while (0); | |||||
2698 | ||||||
2699 | visitInstruction(AI); | |||||
2700 | } | |||||
2701 | ||||||
2702 | void Verifier::visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI) { | |||||
2703 | ||||||
2704 | // FIXME: more conditions??? | |||||
2705 | Assert(CXI.getSuccessOrdering() != NotAtomic,do { if (!(CXI.getSuccessOrdering() != NotAtomic)) { CheckFailed ("cmpxchg instructions must be atomic.", &CXI); return; } } while (0) | |||||
2706 | "cmpxchg instructions must be atomic.", &CXI)do { if (!(CXI.getSuccessOrdering() != NotAtomic)) { CheckFailed ("cmpxchg instructions must be atomic.", &CXI); return; } } while (0); | |||||
2707 | Assert(CXI.getFailureOrdering() != NotAtomic,do { if (!(CXI.getFailureOrdering() != NotAtomic)) { CheckFailed ("cmpxchg instructions must be atomic.", &CXI); return; } } while (0) | |||||
2708 | "cmpxchg instructions must be atomic.", &CXI)do { if (!(CXI.getFailureOrdering() != NotAtomic)) { CheckFailed ("cmpxchg instructions must be atomic.", &CXI); return; } } while (0); | |||||
2709 | Assert(CXI.getSuccessOrdering() != Unordered,do { if (!(CXI.getSuccessOrdering() != Unordered)) { CheckFailed ("cmpxchg instructions cannot be unordered.", &CXI); return ; } } while (0) | |||||
2710 | "cmpxchg instructions cannot be unordered.", &CXI)do { if (!(CXI.getSuccessOrdering() != Unordered)) { CheckFailed ("cmpxchg instructions cannot be unordered.", &CXI); return ; } } while (0); | |||||
2711 | Assert(CXI.getFailureOrdering() != Unordered,do { if (!(CXI.getFailureOrdering() != Unordered)) { CheckFailed ("cmpxchg instructions cannot be unordered.", &CXI); return ; } } while (0) | |||||
2712 | "cmpxchg instructions cannot be unordered.", &CXI)do { if (!(CXI.getFailureOrdering() != Unordered)) { CheckFailed ("cmpxchg instructions cannot be unordered.", &CXI); return ; } } while (0); | |||||
2713 | Assert(CXI.getSuccessOrdering() >= CXI.getFailureOrdering(),do { if (!(CXI.getSuccessOrdering() >= CXI.getFailureOrdering ())) { CheckFailed("cmpxchg instructions be at least as constrained on success as fail" , &CXI); return; } } while (0) | |||||
2714 | "cmpxchg instructions be at least as constrained on success as fail",do { if (!(CXI.getSuccessOrdering() >= CXI.getFailureOrdering ())) { CheckFailed("cmpxchg instructions be at least as constrained on success as fail" , &CXI); return; } } while (0) | |||||
2715 | &CXI)do { if (!(CXI.getSuccessOrdering() >= CXI.getFailureOrdering ())) { CheckFailed("cmpxchg instructions be at least as constrained on success as fail" , &CXI); return; } } while (0); | |||||
2716 | Assert(CXI.getFailureOrdering() != Release &&do { if (!(CXI.getFailureOrdering() != Release && CXI .getFailureOrdering() != AcquireRelease)) { CheckFailed("cmpxchg failure ordering cannot include release semantics" , &CXI); return; } } while (0) | |||||
2717 | CXI.getFailureOrdering() != AcquireRelease,do { if (!(CXI.getFailureOrdering() != Release && CXI .getFailureOrdering() != AcquireRelease)) { CheckFailed("cmpxchg failure ordering cannot include release semantics" , &CXI); return; } } while (0) | |||||
2718 | "cmpxchg failure ordering cannot include release semantics", &CXI)do { if (!(CXI.getFailureOrdering() != Release && CXI .getFailureOrdering() != AcquireRelease)) { CheckFailed("cmpxchg failure ordering cannot include release semantics" , &CXI); return; } } while (0); | |||||
2719 | ||||||
2720 | PointerType *PTy = dyn_cast<PointerType>(CXI.getOperand(0)->getType()); | |||||
2721 | Assert(PTy, "First cmpxchg operand must be a pointer.", &CXI)do { if (!(PTy)) { CheckFailed("First cmpxchg operand must be a pointer." , &CXI); return; } } while (0); | |||||
2722 | Type *ElTy = PTy->getElementType(); | |||||
2723 | Assert(ElTy->isIntegerTy(), "cmpxchg operand must have integer type!", &CXI,do { if (!(ElTy->isIntegerTy())) { CheckFailed("cmpxchg operand must have integer type!" , &CXI, ElTy); return; } } while (0) | |||||
2724 | ElTy)do { if (!(ElTy->isIntegerTy())) { CheckFailed("cmpxchg operand must have integer type!" , &CXI, ElTy); return; } } while (0); | |||||
2725 | unsigned Size = ElTy->getPrimitiveSizeInBits(); | |||||
2726 | Assert(Size >= 8 && !(Size & (Size - 1)),do { if (!(Size >= 8 && !(Size & (Size - 1)))) { CheckFailed("cmpxchg operand must be power-of-two byte-sized integer" , &CXI, ElTy); return; } } while (0) | |||||
2727 | "cmpxchg operand must be power-of-two byte-sized integer", &CXI, ElTy)do { if (!(Size >= 8 && !(Size & (Size - 1)))) { CheckFailed("cmpxchg operand must be power-of-two byte-sized integer" , &CXI, ElTy); return; } } while (0); | |||||
2728 | 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 (0) | |||||
2729 | "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 (0) | |||||
2730 | ElTy)do { if (!(ElTy == CXI.getOperand(1)->getType())) { CheckFailed ("Expected value type does not match pointer operand type!", & CXI, ElTy); return; } } while (0); | |||||
2731 | 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 (0) | |||||
2732 | "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 (0); | |||||
2733 | visitInstruction(CXI); | |||||
2734 | } | |||||
2735 | ||||||
2736 | void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) { | |||||
2737 | Assert(RMWI.getOrdering() != NotAtomic,do { if (!(RMWI.getOrdering() != NotAtomic)) { CheckFailed("atomicrmw instructions must be atomic." , &RMWI); return; } } while (0) | |||||
2738 | "atomicrmw instructions must be atomic.", &RMWI)do { if (!(RMWI.getOrdering() != NotAtomic)) { CheckFailed("atomicrmw instructions must be atomic." , &RMWI); return; } } while (0); | |||||
2739 | Assert(RMWI.getOrdering() != Unordered,do { if (!(RMWI.getOrdering() != Unordered)) { CheckFailed("atomicrmw instructions cannot be unordered." , &RMWI); return; } } while (0) | |||||
2740 | "atomicrmw instructions cannot be unordered.", &RMWI)do { if (!(RMWI.getOrdering() != Unordered)) { CheckFailed("atomicrmw instructions cannot be unordered." , &RMWI); return; } } while (0); | |||||
2741 | PointerType *PTy = dyn_cast<PointerType>(RMWI.getOperand(0)->getType()); | |||||
2742 | Assert(PTy, "First atomicrmw operand must be a pointer.", &RMWI)do { if (!(PTy)) { CheckFailed("First atomicrmw operand must be a pointer." , &RMWI); return; } } while (0); | |||||
2743 | Type *ElTy = PTy->getElementType(); | |||||
2744 | Assert(ElTy->isIntegerTy(), "atomicrmw operand must have integer type!",do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw operand must have integer type!" , &RMWI, ElTy); return; } } while (0) | |||||
2745 | &RMWI, ElTy)do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw operand must have integer type!" , &RMWI, ElTy); return; } } while (0); | |||||
2746 | unsigned Size = ElTy->getPrimitiveSizeInBits(); | |||||
2747 | Assert(Size >= 8 && !(Size & (Size - 1)),do { if (!(Size >= 8 && !(Size & (Size - 1)))) { CheckFailed("atomicrmw operand must be power-of-two byte-sized integer" , &RMWI, ElTy); return; } } while (0) | |||||
2748 | "atomicrmw operand must be power-of-two byte-sized integer", &RMWI,do { if (!(Size >= 8 && !(Size & (Size - 1)))) { CheckFailed("atomicrmw operand must be power-of-two byte-sized integer" , &RMWI, ElTy); return; } } while (0) | |||||
2749 | ElTy)do { if (!(Size >= 8 && !(Size & (Size - 1)))) { CheckFailed("atomicrmw operand must be power-of-two byte-sized integer" , &RMWI, ElTy); return; } } while (0); | |||||
2750 | 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 (0) | |||||
2751 | "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 (0) | |||||
2752 | ElTy)do { if (!(ElTy == RMWI.getOperand(1)->getType())) { CheckFailed ("Argument value type does not match pointer operand type!", & RMWI, ElTy); return; } } while (0); | |||||
2753 | Assert(AtomicRMWInst::FIRST_BINOP <= RMWI.getOperation() &&do { if (!(AtomicRMWInst::FIRST_BINOP <= RMWI.getOperation () && RMWI.getOperation() <= AtomicRMWInst::LAST_BINOP )) { CheckFailed("Invalid binary operation!", &RMWI); return ; } } while (0) | |||||
2754 | RMWI.getOperation() <= AtomicRMWInst::LAST_BINOP,do { if (!(AtomicRMWInst::FIRST_BINOP <= RMWI.getOperation () && RMWI.getOperation() <= AtomicRMWInst::LAST_BINOP )) { CheckFailed("Invalid binary operation!", &RMWI); return ; } } while (0) | |||||
2755 | "Invalid binary operation!", &RMWI)do { if (!(AtomicRMWInst::FIRST_BINOP <= RMWI.getOperation () && RMWI.getOperation() <= AtomicRMWInst::LAST_BINOP )) { CheckFailed("Invalid binary operation!", &RMWI); return ; } } while (0); | |||||
2756 | visitInstruction(RMWI); | |||||
2757 | } | |||||
2758 | ||||||
2759 | void Verifier::visitFenceInst(FenceInst &FI) { | |||||
2760 | const AtomicOrdering Ordering = FI.getOrdering(); | |||||
2761 | Assert(Ordering == Acquire || Ordering == Release ||do { if (!(Ordering == Acquire || Ordering == Release || Ordering == AcquireRelease || Ordering == SequentiallyConsistent)) { CheckFailed ("fence instructions may only have " "acquire, release, acq_rel, or seq_cst ordering." , &FI); return; } } while (0) | |||||
2762 | Ordering == AcquireRelease || Ordering == SequentiallyConsistent,do { if (!(Ordering == Acquire || Ordering == Release || Ordering == AcquireRelease || Ordering == SequentiallyConsistent)) { CheckFailed ("fence instructions may only have " "acquire, release, acq_rel, or seq_cst ordering." , &FI); return; } } while (0) | |||||
2763 | "fence instructions may only have "do { if (!(Ordering == Acquire || Ordering == Release || Ordering == AcquireRelease || Ordering == SequentiallyConsistent)) { CheckFailed ("fence instructions may only have " "acquire, release, acq_rel, or seq_cst ordering." , &FI); return; } } while (0) | |||||
2764 | "acquire, release, acq_rel, or seq_cst ordering.",do { if (!(Ordering == Acquire || Ordering == Release || Ordering == AcquireRelease || Ordering == SequentiallyConsistent)) { CheckFailed ("fence instructions may only have " "acquire, release, acq_rel, or seq_cst ordering." , &FI); return; } } while (0) | |||||
2765 | &FI)do { if (!(Ordering == Acquire || Ordering == Release || Ordering == AcquireRelease || Ordering == SequentiallyConsistent)) { CheckFailed ("fence instructions may only have " "acquire, release, acq_rel, or seq_cst ordering." , &FI); return; } } while (0); | |||||
2766 | visitInstruction(FI); | |||||
2767 | } | |||||
2768 | ||||||
2769 | void Verifier::visitExtractValueInst(ExtractValueInst &EVI) { | |||||
2770 | Assert(ExtractValueInst::getIndexedType(EVI.getAggregateOperand()->getType(),do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand ()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed ("Invalid ExtractValueInst operands!", &EVI); return; } } while (0) | |||||
2771 | EVI.getIndices()) == EVI.getType(),do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand ()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed ("Invalid ExtractValueInst operands!", &EVI); return; } } while (0) | |||||
2772 | "Invalid ExtractValueInst operands!", &EVI)do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand ()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed ("Invalid ExtractValueInst operands!", &EVI); return; } } while (0); | |||||
2773 | ||||||
2774 | visitInstruction(EVI); | |||||
2775 | } | |||||
2776 | ||||||
2777 | void Verifier::visitInsertValueInst(InsertValueInst &IVI) { | |||||
2778 | 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 (0) | |||||
2779 | IVI.getIndices()) ==do { if (!(ExtractValueInst::getIndexedType(IVI.getAggregateOperand ()->getType(), IVI.getIndices()) == IVI.getOperand(1)-> getType())) { CheckFailed("Invalid InsertValueInst operands!" , &IVI); return; } } while (0) | |||||
2780 | IVI.getOperand(1)->getType(),do { if (!(ExtractValueInst::getIndexedType(IVI.getAggregateOperand ()->getType(), IVI.getIndices()) == IVI.getOperand(1)-> getType())) { CheckFailed("Invalid InsertValueInst operands!" , &IVI); return; } } while (0) | |||||
2781 | "Invalid InsertValueInst operands!", &IVI)do { if (!(ExtractValueInst::getIndexedType(IVI.getAggregateOperand ()->getType(), IVI.getIndices()) == IVI.getOperand(1)-> getType())) { CheckFailed("Invalid InsertValueInst operands!" , &IVI); return; } } while (0); | |||||
2782 | ||||||
2783 | visitInstruction(IVI); | |||||
2784 | } | |||||
2785 | ||||||
2786 | void Verifier::visitEHPadPredecessors(Instruction &I) { | |||||
2787 | assert(I.isEHPad())((I.isEHPad()) ? static_cast<void> (0) : __assert_fail ( "I.isEHPad()", "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 2787, __PRETTY_FUNCTION__)); | |||||
2788 | ||||||
2789 | BasicBlock *BB = I.getParent(); | |||||
2790 | Function *F = BB->getParent(); | |||||
2791 | ||||||
2792 | 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 (0); | |||||
2793 | ||||||
2794 | if (auto *LPI = dyn_cast<LandingPadInst>(&I)) { | |||||
2795 | // The landingpad instruction defines its parent as a landing pad block. The | |||||
2796 | // landing pad block may be branched to only by the unwind edge of an | |||||
2797 | // invoke. | |||||
2798 | for (BasicBlock *PredBB : predecessors(BB)) { | |||||
2799 | const auto *II = dyn_cast<InvokeInst>(PredBB->getTerminator()); | |||||
2800 | 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 (0) | |||||
2801 | "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 (0) | |||||
2802 | "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 (0) | |||||
2803 | 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 (0); | |||||
2804 | } | |||||
2805 | return; | |||||
2806 | } | |||||
2807 | ||||||
2808 | for (BasicBlock *PredBB : predecessors(BB)) { | |||||
2809 | TerminatorInst *TI = PredBB->getTerminator(); | |||||
2810 | if (auto *II = dyn_cast<InvokeInst>(TI)) | |||||
2811 | 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" , &I, II); return; } } while (0) | |||||
2812 | "EH pad must be jumped to via an unwind edge", &I, II)do { if (!(II->getUnwindDest() == BB && II->getNormalDest () != BB)) { CheckFailed("EH pad must be jumped to via an unwind edge" , &I, II); return; } } while (0); | |||||
2813 | else if (auto *CPI = dyn_cast<CatchPadInst>(TI)) | |||||
2814 | Assert(CPI->getUnwindDest() == BB && CPI->getNormalDest() != BB,do { if (!(CPI->getUnwindDest() == BB && CPI->getNormalDest () != BB)) { CheckFailed("EH pad must be jumped to via an unwind edge" , &I, CPI); return; } } while (0) | |||||
2815 | "EH pad must be jumped to via an unwind edge", &I, CPI)do { if (!(CPI->getUnwindDest() == BB && CPI->getNormalDest () != BB)) { CheckFailed("EH pad must be jumped to via an unwind edge" , &I, CPI); return; } } while (0); | |||||
2816 | else if (isa<CatchEndPadInst>(TI)) | |||||
2817 | ; | |||||
2818 | else if (isa<CleanupReturnInst>(TI)) | |||||
2819 | ; | |||||
2820 | else if (isa<TerminatePadInst>(TI)) | |||||
2821 | ; | |||||
2822 | else | |||||
2823 | Assert(false, "EH pad must be jumped to via an unwind edge", &I, TI)do { if (!(false)) { CheckFailed("EH pad must be jumped to via an unwind edge" , &I, TI); return; } } while (0); | |||||
2824 | } | |||||
2825 | } | |||||
2826 | ||||||
2827 | void Verifier::visitLandingPadInst(LandingPadInst &LPI) { | |||||
2828 | // The landingpad instruction is ill-formed if it doesn't have any clauses and | |||||
2829 | // isn't a cleanup. | |||||
2830 | 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 (0) | |||||
2831 | "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 (0); | |||||
2832 | ||||||
2833 | visitEHPadPredecessors(LPI); | |||||
2834 | ||||||
2835 | if (!LandingPadResultTy) | |||||
2836 | LandingPadResultTy = LPI.getType(); | |||||
2837 | else | |||||
2838 | 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 (0) | |||||
2839 | "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 (0) | |||||
2840 | "inside a function.",do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed ("The landingpad instruction should have a consistent result type " "inside a function.", &LPI); return; } } while (0) | |||||
2841 | &LPI)do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed ("The landingpad instruction should have a consistent result type " "inside a function.", &LPI); return; } } while (0); | |||||
2842 | ||||||
2843 | Function *F = LPI.getParent()->getParent(); | |||||
2844 | Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("LandingPadInst needs to be in a function with a personality." , &LPI); return; } } while (0) | |||||
2845 | "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 (0); | |||||
2846 | ||||||
2847 | // The landingpad instruction must be the first non-PHI instruction in the | |||||
2848 | // block. | |||||
2849 | 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 (0) | |||||
2850 | "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 (0) | |||||
2851 | &LPI)do { if (!(LPI.getParent()->getLandingPadInst() == &LPI )) { CheckFailed("LandingPadInst not the first non-PHI instruction in the block." , &LPI); return; } } while (0); | |||||
2852 | ||||||
2853 | for (unsigned i = 0, e = LPI.getNumClauses(); i < e; ++i) { | |||||
2854 | Constant *Clause = LPI.getClause(i); | |||||
2855 | if (LPI.isCatch(i)) { | |||||
2856 | Assert(isa<PointerType>(Clause->getType()),do { if (!(isa<PointerType>(Clause->getType()))) { CheckFailed ("Catch operand does not have pointer type!", &LPI); return ; } } while (0) | |||||
2857 | "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 (0); | |||||
2858 | } else { | |||||
2859 | 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 (0); | |||||
2860 | 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 (0) | |||||
2861 | "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 (0); | |||||
2862 | } | |||||
2863 | } | |||||
2864 | ||||||
2865 | visitInstruction(LPI); | |||||
2866 | } | |||||
2867 | ||||||
2868 | void Verifier::visitCatchPadInst(CatchPadInst &CPI) { | |||||
2869 | visitEHPadPredecessors(CPI); | |||||
2870 | ||||||
2871 | BasicBlock *BB = CPI.getParent(); | |||||
2872 | Function *F = BB->getParent(); | |||||
2873 | Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchPadInst needs to be in a function with a personality." , &CPI); return; } } while (0) | |||||
2874 | "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 (0); | |||||
2875 | ||||||
2876 | // The catchpad instruction must be the first non-PHI instruction in the | |||||
2877 | // block. | |||||
2878 | Assert(BB->getFirstNonPHI() == &CPI,do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CatchPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (0) | |||||
2879 | "CatchPadInst not the first non-PHI instruction in the block.",do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CatchPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (0) | |||||
2880 | &CPI)do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CatchPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (0); | |||||
2881 | ||||||
2882 | if (!BB->getSinglePredecessor()) | |||||
2883 | for (BasicBlock *PredBB : predecessors(BB)) { | |||||
2884 | Assert(!isa<CatchPadInst>(PredBB->getTerminator()),do { if (!(!isa<CatchPadInst>(PredBB->getTerminator( )))) { CheckFailed("CatchPadInst with CatchPadInst predecessor cannot have any other " "predecessors.", &CPI); return; } } while (0) | |||||
2885 | "CatchPadInst with CatchPadInst predecessor cannot have any other "do { if (!(!isa<CatchPadInst>(PredBB->getTerminator( )))) { CheckFailed("CatchPadInst with CatchPadInst predecessor cannot have any other " "predecessors.", &CPI); return; } } while (0) | |||||
2886 | "predecessors.",do { if (!(!isa<CatchPadInst>(PredBB->getTerminator( )))) { CheckFailed("CatchPadInst with CatchPadInst predecessor cannot have any other " "predecessors.", &CPI); return; } } while (0) | |||||
2887 | &CPI)do { if (!(!isa<CatchPadInst>(PredBB->getTerminator( )))) { CheckFailed("CatchPadInst with CatchPadInst predecessor cannot have any other " "predecessors.", &CPI); return; } } while (0); | |||||
2888 | } | |||||
2889 | ||||||
2890 | BasicBlock *UnwindDest = CPI.getUnwindDest(); | |||||
2891 | Instruction *I = UnwindDest->getFirstNonPHI(); | |||||
2892 | Assert(do { if (!(isa<CatchPadInst>(I) || isa<CatchEndPadInst >(I))) { CheckFailed("CatchPadInst must unwind to a CatchPadInst or a CatchEndPadInst." , &CPI); return; } } while (0) | |||||
2893 | isa<CatchPadInst>(I) || isa<CatchEndPadInst>(I),do { if (!(isa<CatchPadInst>(I) || isa<CatchEndPadInst >(I))) { CheckFailed("CatchPadInst must unwind to a CatchPadInst or a CatchEndPadInst." , &CPI); return; } } while (0) | |||||
2894 | "CatchPadInst must unwind to a CatchPadInst or a CatchEndPadInst.",do { if (!(isa<CatchPadInst>(I) || isa<CatchEndPadInst >(I))) { CheckFailed("CatchPadInst must unwind to a CatchPadInst or a CatchEndPadInst." , &CPI); return; } } while (0) | |||||
2895 | &CPI)do { if (!(isa<CatchPadInst>(I) || isa<CatchEndPadInst >(I))) { CheckFailed("CatchPadInst must unwind to a CatchPadInst or a CatchEndPadInst." , &CPI); return; } } while (0); | |||||
2896 | ||||||
2897 | visitTerminatorInst(CPI); | |||||
2898 | } | |||||
2899 | ||||||
2900 | void Verifier::visitCatchEndPadInst(CatchEndPadInst &CEPI) { | |||||
2901 | visitEHPadPredecessors(CEPI); | |||||
2902 | ||||||
2903 | BasicBlock *BB = CEPI.getParent(); | |||||
2904 | Function *F = BB->getParent(); | |||||
2905 | Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchEndPadInst needs to be in a function with a personality." , &CEPI); return; } } while (0) | |||||
2906 | "CatchEndPadInst needs to be in a function with a personality.",do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchEndPadInst needs to be in a function with a personality." , &CEPI); return; } } while (0) | |||||
2907 | &CEPI)do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchEndPadInst needs to be in a function with a personality." , &CEPI); return; } } while (0); | |||||
2908 | ||||||
2909 | // The catchendpad instruction must be the first non-PHI instruction in the | |||||
2910 | // block. | |||||
2911 | Assert(BB->getFirstNonPHI() == &CEPI,do { if (!(BB->getFirstNonPHI() == &CEPI)) { CheckFailed ("CatchEndPadInst not the first non-PHI instruction in the block." , &CEPI); return; } } while (0) | |||||
2912 | "CatchEndPadInst not the first non-PHI instruction in the block.",do { if (!(BB->getFirstNonPHI() == &CEPI)) { CheckFailed ("CatchEndPadInst not the first non-PHI instruction in the block." , &CEPI); return; } } while (0) | |||||
2913 | &CEPI)do { if (!(BB->getFirstNonPHI() == &CEPI)) { CheckFailed ("CatchEndPadInst not the first non-PHI instruction in the block." , &CEPI); return; } } while (0); | |||||
2914 | ||||||
2915 | unsigned CatchPadsSeen = 0; | |||||
2916 | for (BasicBlock *PredBB : predecessors(BB)) | |||||
2917 | if (isa<CatchPadInst>(PredBB->getTerminator())) | |||||
2918 | ++CatchPadsSeen; | |||||
2919 | ||||||
2920 | Assert(CatchPadsSeen <= 1, "CatchEndPadInst must have no more than one "do { if (!(CatchPadsSeen <= 1)) { CheckFailed("CatchEndPadInst must have no more than one " "CatchPadInst predecessor.", &CEPI); return; } } while ( 0) | |||||
2921 | "CatchPadInst predecessor.",do { if (!(CatchPadsSeen <= 1)) { CheckFailed("CatchEndPadInst must have no more than one " "CatchPadInst predecessor.", &CEPI); return; } } while ( 0) | |||||
2922 | &CEPI)do { if (!(CatchPadsSeen <= 1)) { CheckFailed("CatchEndPadInst must have no more than one " "CatchPadInst predecessor.", &CEPI); return; } } while ( 0); | |||||
2923 | ||||||
2924 | if (BasicBlock *UnwindDest = CEPI.getUnwindDest()) { | |||||
2925 | Instruction *I = UnwindDest->getFirstNonPHI(); | |||||
2926 | Assert(do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("CatchEndPad must unwind to an EH block which is not a landingpad." , &CEPI); return; } } while (0) | |||||
2927 | I->isEHPad() && !isa<LandingPadInst>(I),do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("CatchEndPad must unwind to an EH block which is not a landingpad." , &CEPI); return; } } while (0) | |||||
2928 | "CatchEndPad must unwind to an EH block which is not a landingpad.",do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("CatchEndPad must unwind to an EH block which is not a landingpad." , &CEPI); return; } } while (0) | |||||
2929 | &CEPI)do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("CatchEndPad must unwind to an EH block which is not a landingpad." , &CEPI); return; } } while (0); | |||||
2930 | } | |||||
2931 | ||||||
2932 | visitTerminatorInst(CEPI); | |||||
2933 | } | |||||
2934 | ||||||
2935 | void Verifier::visitCleanupPadInst(CleanupPadInst &CPI) { | |||||
2936 | visitEHPadPredecessors(CPI); | |||||
2937 | ||||||
2938 | BasicBlock *BB = CPI.getParent(); | |||||
2939 | ||||||
2940 | Function *F = BB->getParent(); | |||||
2941 | Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CleanupPadInst needs to be in a function with a personality." , &CPI); return; } } while (0) | |||||
2942 | "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 (0); | |||||
2943 | ||||||
2944 | // The cleanuppad instruction must be the first non-PHI instruction in the | |||||
2945 | // block. | |||||
2946 | Assert(BB->getFirstNonPHI() == &CPI,do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CleanupPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (0) | |||||
2947 | "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 (0) | |||||
2948 | &CPI)do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CleanupPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (0); | |||||
2949 | ||||||
2950 | CleanupReturnInst *FirstCRI = nullptr; | |||||
2951 | for (User *U : CPI.users()) | |||||
2952 | if (CleanupReturnInst *CRI = dyn_cast<CleanupReturnInst>(U)) { | |||||
2953 | if (!FirstCRI) | |||||
2954 | FirstCRI = CRI; | |||||
2955 | else | |||||
2956 | Assert(CRI->getUnwindDest() == FirstCRI->getUnwindDest(),do { if (!(CRI->getUnwindDest() == FirstCRI->getUnwindDest ())) { CheckFailed("Cleanuprets from same cleanuppad have different exceptional " "successors.", FirstCRI, CRI); return; } } while (0) | |||||
2957 | "Cleanuprets from same cleanuppad have different exceptional "do { if (!(CRI->getUnwindDest() == FirstCRI->getUnwindDest ())) { CheckFailed("Cleanuprets from same cleanuppad have different exceptional " "successors.", FirstCRI, CRI); return; } } while (0) | |||||
2958 | "successors.",do { if (!(CRI->getUnwindDest() == FirstCRI->getUnwindDest ())) { CheckFailed("Cleanuprets from same cleanuppad have different exceptional " "successors.", FirstCRI, CRI); return; } } while (0) | |||||
2959 | FirstCRI, CRI)do { if (!(CRI->getUnwindDest() == FirstCRI->getUnwindDest ())) { CheckFailed("Cleanuprets from same cleanuppad have different exceptional " "successors.", FirstCRI, CRI); return; } } while (0); | |||||
2960 | } | |||||
2961 | ||||||
2962 | visitInstruction(CPI); | |||||
2963 | } | |||||
2964 | ||||||
2965 | void Verifier::visitCleanupReturnInst(CleanupReturnInst &CRI) { | |||||
2966 | if (BasicBlock *UnwindDest = CRI.getUnwindDest()) { | |||||
2967 | Instruction *I = UnwindDest->getFirstNonPHI(); | |||||
2968 | 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 (0) | |||||
2969 | "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 (0) | |||||
2970 | "landingpad.",do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("CleanupReturnInst must unwind to an EH block which is not a " "landingpad.", &CRI); return; } } while (0) | |||||
2971 | &CRI)do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("CleanupReturnInst must unwind to an EH block which is not a " "landingpad.", &CRI); return; } } while (0); | |||||
2972 | } | |||||
2973 | ||||||
2974 | visitTerminatorInst(CRI); | |||||
2975 | } | |||||
2976 | ||||||
2977 | void Verifier::visitTerminatePadInst(TerminatePadInst &TPI) { | |||||
2978 | visitEHPadPredecessors(TPI); | |||||
2979 | ||||||
2980 | BasicBlock *BB = TPI.getParent(); | |||||
2981 | Function *F = BB->getParent(); | |||||
2982 | Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("TerminatePadInst needs to be in a function with a personality." , &TPI); return; } } while (0) | |||||
2983 | "TerminatePadInst needs to be in a function with a personality.",do { if (!(F->hasPersonalityFn())) { CheckFailed("TerminatePadInst needs to be in a function with a personality." , &TPI); return; } } while (0) | |||||
2984 | &TPI)do { if (!(F->hasPersonalityFn())) { CheckFailed("TerminatePadInst needs to be in a function with a personality." , &TPI); return; } } while (0); | |||||
2985 | ||||||
2986 | // The terminatepad instruction must be the first non-PHI instruction in the | |||||
2987 | // block. | |||||
2988 | Assert(BB->getFirstNonPHI() == &TPI,do { if (!(BB->getFirstNonPHI() == &TPI)) { CheckFailed ("TerminatePadInst not the first non-PHI instruction in the block." , &TPI); return; } } while (0) | |||||
2989 | "TerminatePadInst not the first non-PHI instruction in the block.",do { if (!(BB->getFirstNonPHI() == &TPI)) { CheckFailed ("TerminatePadInst not the first non-PHI instruction in the block." , &TPI); return; } } while (0) | |||||
2990 | &TPI)do { if (!(BB->getFirstNonPHI() == &TPI)) { CheckFailed ("TerminatePadInst not the first non-PHI instruction in the block." , &TPI); return; } } while (0); | |||||
2991 | ||||||
2992 | if (BasicBlock *UnwindDest = TPI.getUnwindDest()) { | |||||
2993 | Instruction *I = UnwindDest->getFirstNonPHI(); | |||||
2994 | Assert(I->isEHPad() && !isa<LandingPadInst>(I),do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("TerminatePadInst must unwind to an EH block which is not a " "landingpad.", &TPI); return; } } while (0) | |||||
2995 | "TerminatePadInst must unwind to an EH block which is not a "do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("TerminatePadInst must unwind to an EH block which is not a " "landingpad.", &TPI); return; } } while (0) | |||||
2996 | "landingpad.",do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("TerminatePadInst must unwind to an EH block which is not a " "landingpad.", &TPI); return; } } while (0) | |||||
2997 | &TPI)do { if (!(I->isEHPad() && !isa<LandingPadInst> (I))) { CheckFailed("TerminatePadInst must unwind to an EH block which is not a " "landingpad.", &TPI); return; } } while (0); | |||||
2998 | } | |||||
2999 | ||||||
3000 | visitTerminatorInst(TPI); | |||||
3001 | } | |||||
3002 | ||||||
3003 | void Verifier::verifyDominatesUse(Instruction &I, unsigned i) { | |||||
3004 | Instruction *Op = cast<Instruction>(I.getOperand(i)); | |||||
3005 | // If the we have an invalid invoke, don't try to compute the dominance. | |||||
3006 | // We already reject it in the invoke specific checks and the dominance | |||||
3007 | // computation doesn't handle multiple edges. | |||||
3008 | if (InvokeInst *II = dyn_cast<InvokeInst>(Op)) { | |||||
3009 | if (II->getNormalDest() == II->getUnwindDest()) | |||||
3010 | return; | |||||
3011 | } | |||||
3012 | ||||||
3013 | const Use &U = I.getOperandUse(i); | |||||
3014 | Assert(InstsInThisBlock.count(Op) || DT.dominates(Op, U),do { if (!(InstsInThisBlock.count(Op) || DT.dominates(Op, U)) ) { CheckFailed("Instruction does not dominate all uses!", Op , &I); return; } } while (0) | |||||
3015 | "Instruction does not dominate all uses!", Op, &I)do { if (!(InstsInThisBlock.count(Op) || DT.dominates(Op, U)) ) { CheckFailed("Instruction does not dominate all uses!", Op , &I); return; } } while (0); | |||||
3016 | } | |||||
3017 | ||||||
3018 | /// verifyInstruction - Verify that an instruction is well formed. | |||||
3019 | /// | |||||
3020 | void Verifier::visitInstruction(Instruction &I) { | |||||
3021 | BasicBlock *BB = I.getParent(); | |||||
3022 | Assert(BB, "Instruction not embedded in basic block!", &I)do { if (!(BB)) { CheckFailed("Instruction not embedded in basic block!" , &I); return; } } while (0); | |||||
3023 | ||||||
3024 | if (!isa<PHINode>(I)) { // Check that non-phi nodes are not self referential | |||||
3025 | for (User *U : I.users()) { | |||||
3026 | 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 (0) | |||||
3027 | "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 (0); | |||||
3028 | } | |||||
3029 | } | |||||
3030 | ||||||
3031 | // Check that void typed values don't have names | |||||
3032 | 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 (0) | |||||
3033 | "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 (0); | |||||
3034 | ||||||
3035 | // Check that the return value of the instruction is either void or a legal | |||||
3036 | // value type. | |||||
3037 | 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 (0) | |||||
3038 | "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 (0); | |||||
3039 | ||||||
3040 | // Check that the instruction doesn't produce metadata. Calls are already | |||||
3041 | // checked against the callee type. | |||||
3042 | 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 (0) | |||||
3043 | "Invalid use of metadata!", &I)do { if (!(!I.getType()->isMetadataTy() || isa<CallInst >(I) || isa<InvokeInst>(I))) { CheckFailed("Invalid use of metadata!" , &I); return; } } while (0); | |||||
3044 | ||||||
3045 | // Check that all uses of the instruction, if they are instructions | |||||
3046 | // themselves, actually have parent basic blocks. If the use is not an | |||||
3047 | // instruction, it is an error! | |||||
3048 | for (Use &U : I.uses()) { | |||||
3049 | if (Instruction *Used = dyn_cast<Instruction>(U.getUser())) | |||||
3050 | Assert(Used->getParent() != nullptr,do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing" " instruction not embedded in a basic block!", &I, Used) ; return; } } while (0) | |||||
3051 | "Instruction referencing"do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing" " instruction not embedded in a basic block!", &I, Used) ; return; } } while (0) | |||||
3052 | " 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 (0) | |||||
3053 | &I, Used)do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing" " instruction not embedded in a basic block!", &I, Used) ; return; } } while (0); | |||||
3054 | else { | |||||
3055 | CheckFailed("Use of instruction is not an instruction!", U); | |||||
3056 | return; | |||||
3057 | } | |||||
3058 | } | |||||
3059 | ||||||
3060 | for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) { | |||||
3061 | Assert(I.getOperand(i) != nullptr, "Instruction has null operand!", &I)do { if (!(I.getOperand(i) != nullptr)) { CheckFailed("Instruction has null operand!" , &I); return; } } while (0); | |||||
3062 | ||||||
3063 | // Check to make sure that only first-class-values are operands to | |||||
3064 | // instructions. | |||||
3065 | if (!I.getOperand(i)->getType()->isFirstClassType()) { | |||||
3066 | Assert(0, "Instruction operands must be first-class values!", &I)do { if (!(0)) { CheckFailed("Instruction operands must be first-class values!" , &I); return; } } while (0); | |||||
3067 | } | |||||
3068 | ||||||
3069 | if (Function *F = dyn_cast<Function>(I.getOperand(i))) { | |||||
3070 | // Check to make sure that the "address of" an intrinsic function is never | |||||
3071 | // taken. | |||||
3072 | Assert(do { if (!(!F->isIntrinsic() || i == (isa<CallInst>( I) ? e - 1 : isa<InvokeInst>(I) ? e - 3 : 0))) { CheckFailed ("Cannot take the address of an intrinsic!", &I); return; } } while (0) | |||||
3073 | !F->isIntrinsic() ||do { if (!(!F->isIntrinsic() || i == (isa<CallInst>( I) ? e - 1 : isa<InvokeInst>(I) ? e - 3 : 0))) { CheckFailed ("Cannot take the address of an intrinsic!", &I); return; } } while (0) | |||||
3074 | i == (isa<CallInst>(I) ? e - 1 : isa<InvokeInst>(I) ? e - 3 : 0),do { if (!(!F->isIntrinsic() || i == (isa<CallInst>( I) ? e - 1 : isa<InvokeInst>(I) ? e - 3 : 0))) { CheckFailed ("Cannot take the address of an intrinsic!", &I); return; } } while (0) | |||||
3075 | "Cannot take the address of an intrinsic!", &I)do { if (!(!F->isIntrinsic() || i == (isa<CallInst>( I) ? e - 1 : isa<InvokeInst>(I) ? e - 3 : 0))) { CheckFailed ("Cannot take the address of an intrinsic!", &I); return; } } while (0); | |||||
3076 | Assert(do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID () == Intrinsic::experimental_gc_statepoint)) { CheckFailed("Cannot invoke an intrinsinc other than" " donothing or patchpoint", &I); return; } } while (0) | |||||
3077 | !F->isIntrinsic() || isa<CallInst>(I) ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID () == Intrinsic::experimental_gc_statepoint)) { CheckFailed("Cannot invoke an intrinsinc other than" " donothing or patchpoint", &I); return; } } while (0) | |||||
3078 | F->getIntrinsicID() == Intrinsic::donothing ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID () == Intrinsic::experimental_gc_statepoint)) { CheckFailed("Cannot invoke an intrinsinc other than" " donothing or patchpoint", &I); return; } } while (0) | |||||
3079 | F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID () == Intrinsic::experimental_gc_statepoint)) { CheckFailed("Cannot invoke an intrinsinc other than" " donothing or patchpoint", &I); return; } } while (0) | |||||
3080 | F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID () == Intrinsic::experimental_gc_statepoint)) { CheckFailed("Cannot invoke an intrinsinc other than" " donothing or patchpoint", &I); return; } } while (0) | |||||
3081 | F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint,do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID () == Intrinsic::experimental_gc_statepoint)) { CheckFailed("Cannot invoke an intrinsinc other than" " donothing or patchpoint", &I); return; } } while (0) | |||||
3082 | "Cannot invoke an intrinsinc other than"do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID () == Intrinsic::experimental_gc_statepoint)) { CheckFailed("Cannot invoke an intrinsinc other than" " donothing or patchpoint", &I); return; } } while (0) | |||||
3083 | " donothing or patchpoint",do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID () == Intrinsic::experimental_gc_statepoint)) { CheckFailed("Cannot invoke an intrinsinc other than" " donothing or patchpoint", &I); return; } } while (0) | |||||
3084 | &I)do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F ->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_void || F->getIntrinsicID () == Intrinsic::experimental_patchpoint_i64 || F->getIntrinsicID () == Intrinsic::experimental_gc_statepoint)) { CheckFailed("Cannot invoke an intrinsinc other than" " donothing or patchpoint", &I); return; } } while (0); | |||||
3085 | Assert(F->getParent() == M, "Referencing function in another module!",do { if (!(F->getParent() == M)) { CheckFailed("Referencing function in another module!" , &I); return; } } while (0) | |||||
3086 | &I)do { if (!(F->getParent() == M)) { CheckFailed("Referencing function in another module!" , &I); return; } } while (0); | |||||
3087 | } else if (BasicBlock *OpBB = dyn_cast<BasicBlock>(I.getOperand(i))) { | |||||
3088 | Assert(OpBB->getParent() == BB->getParent(),do { if (!(OpBB->getParent() == BB->getParent())) { CheckFailed ("Referring to a basic block in another function!", &I); return ; } } while (0) | |||||
3089 | "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 (0); | |||||
3090 | } else if (Argument *OpArg = dyn_cast<Argument>(I.getOperand(i))) { | |||||
3091 | Assert(OpArg->getParent() == BB->getParent(),do { if (!(OpArg->getParent() == BB->getParent())) { CheckFailed ("Referring to an argument in another function!", &I); return ; } } while (0) | |||||
3092 | "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 (0); | |||||
3093 | } else if (GlobalValue *GV = dyn_cast<GlobalValue>(I.getOperand(i))) { | |||||
3094 | Assert(GV->getParent() == M, "Referencing global in another module!", &I)do { if (!(GV->getParent() == M)) { CheckFailed("Referencing global in another module!" , &I); return; } } while (0); | |||||
3095 | } else if (isa<Instruction>(I.getOperand(i))) { | |||||
3096 | verifyDominatesUse(I, i); | |||||
3097 | } else if (isa<InlineAsm>(I.getOperand(i))) { | |||||
3098 | Assert((i + 1 == e && isa<CallInst>(I)) ||do { if (!((i + 1 == e && isa<CallInst>(I)) || ( i + 3 == e && isa<InvokeInst>(I)))) { CheckFailed ("Cannot take the address of an inline asm!", &I); return ; } } while (0) | |||||
3099 | (i + 3 == e && isa<InvokeInst>(I)),do { if (!((i + 1 == e && isa<CallInst>(I)) || ( i + 3 == e && isa<InvokeInst>(I)))) { CheckFailed ("Cannot take the address of an inline asm!", &I); return ; } } while (0) | |||||
3100 | "Cannot take the address of an inline asm!", &I)do { if (!((i + 1 == e && isa<CallInst>(I)) || ( i + 3 == e && isa<InvokeInst>(I)))) { CheckFailed ("Cannot take the address of an inline asm!", &I); return ; } } while (0); | |||||
3101 | } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(I.getOperand(i))) { | |||||
3102 | if (CE->getType()->isPtrOrPtrVectorTy()) { | |||||
3103 | // If we have a ConstantExpr pointer, we need to see if it came from an | |||||
3104 | // illegal bitcast (inttoptr <constant int> ) | |||||
3105 | SmallVector<const ConstantExpr *, 4> Stack; | |||||
3106 | SmallPtrSet<const ConstantExpr *, 4> Visited; | |||||
3107 | Stack.push_back(CE); | |||||
3108 | ||||||
3109 | while (!Stack.empty()) { | |||||
3110 | const ConstantExpr *V = Stack.pop_back_val(); | |||||
3111 | if (!Visited.insert(V).second) | |||||
3112 | continue; | |||||
3113 | ||||||
3114 | VerifyConstantExprBitcastType(V); | |||||
3115 | ||||||
3116 | for (unsigned I = 0, N = V->getNumOperands(); I != N; ++I) { | |||||
3117 | if (ConstantExpr *Op = dyn_cast<ConstantExpr>(V->getOperand(I))) | |||||
3118 | Stack.push_back(Op); | |||||
3119 | } | |||||
3120 | } | |||||
3121 | } | |||||
3122 | } | |||||
3123 | } | |||||
3124 | ||||||
3125 | if (MDNode *MD = I.getMetadata(LLVMContext::MD_fpmath)) { | |||||
3126 | Assert(I.getType()->isFPOrFPVectorTy(),do { if (!(I.getType()->isFPOrFPVectorTy())) { CheckFailed ("fpmath requires a floating point result!", &I); return; } } while (0) | |||||
3127 | "fpmath requires a floating point result!", &I)do { if (!(I.getType()->isFPOrFPVectorTy())) { CheckFailed ("fpmath requires a floating point result!", &I); return; } } while (0); | |||||
3128 | Assert(MD->getNumOperands() == 1, "fpmath takes one operand!", &I)do { if (!(MD->getNumOperands() == 1)) { CheckFailed("fpmath takes one operand!" , &I); return; } } while (0); | |||||
3129 | if (ConstantFP *CFP0 = | |||||
3130 | mdconst::dyn_extract_or_null<ConstantFP>(MD->getOperand(0))) { | |||||
3131 | APFloat Accuracy = CFP0->getValueAPF(); | |||||
3132 | Assert(Accuracy.isFiniteNonZero() && !Accuracy.isNegative(),do { if (!(Accuracy.isFiniteNonZero() && !Accuracy.isNegative ())) { CheckFailed("fpmath accuracy not a positive number!", & I); return; } } while (0) | |||||
3133 | "fpmath accuracy not a positive number!", &I)do { if (!(Accuracy.isFiniteNonZero() && !Accuracy.isNegative ())) { CheckFailed("fpmath accuracy not a positive number!", & I); return; } } while (0); | |||||
3134 | } else { | |||||
3135 | Assert(false, "invalid fpmath accuracy!", &I)do { if (!(false)) { CheckFailed("invalid fpmath accuracy!", & I); return; } } while (0); | |||||
3136 | } | |||||
3137 | } | |||||
3138 | ||||||
3139 | if (MDNode *Range = I.getMetadata(LLVMContext::MD_range)) { | |||||
3140 | 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 (0) | |||||
3141 | "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 (0); | |||||
3142 | visitRangeMetadata(I, Range, I.getType()); | |||||
3143 | } | |||||
3144 | ||||||
3145 | if (I.getMetadata(LLVMContext::MD_nonnull)) { | |||||
3146 | 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 (0) | |||||
3147 | &I)do { if (!(I.getType()->isPointerTy())) { CheckFailed("nonnull applies only to pointer types" , &I); return; } } while (0); | |||||
3148 | 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 (0) | |||||
3149 | "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 (0) | |||||
3150 | " 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 (0) | |||||
3151 | &I)do { if (!(isa<LoadInst>(I))) { CheckFailed("nonnull applies only to load instructions, use attributes" " for calls or invokes", &I); return; } } while (0); | |||||
3152 | } | |||||
3153 | ||||||
3154 | if (MDNode *N = I.getDebugLoc().getAsMDNode()) { | |||||
3155 | Assert(isa<DILocation>(N), "invalid !dbg metadata attachment", &I, N)do { if (!(isa<DILocation>(N))) { CheckFailed("invalid !dbg metadata attachment" , &I, N); return; } } while (0); | |||||
3156 | visitMDNode(*N); | |||||
3157 | } | |||||
3158 | ||||||
3159 | InstsInThisBlock.insert(&I); | |||||
3160 | } | |||||
3161 | ||||||
3162 | /// VerifyIntrinsicType - Verify that the specified type (which comes from an | |||||
3163 | /// intrinsic argument or return value) matches the type constraints specified | |||||
3164 | /// by the .td file (e.g. an "any integer" argument really is an integer). | |||||
3165 | /// | |||||
3166 | /// This return true on error but does not print a message. | |||||
3167 | bool Verifier::VerifyIntrinsicType(Type *Ty, | |||||
3168 | ArrayRef<Intrinsic::IITDescriptor> &Infos, | |||||
3169 | SmallVectorImpl<Type*> &ArgTys) { | |||||
3170 | using namespace Intrinsic; | |||||
3171 | ||||||
3172 | // If we ran out of descriptors, there are too many arguments. | |||||
3173 | if (Infos.empty()) return true; | |||||
3174 | IITDescriptor D = Infos.front(); | |||||
3175 | Infos = Infos.slice(1); | |||||
3176 | ||||||
3177 | switch (D.Kind) { | |||||
3178 | case IITDescriptor::Void: return !Ty->isVoidTy(); | |||||
3179 | case IITDescriptor::VarArg: return true; | |||||
3180 | case IITDescriptor::MMX: return !Ty->isX86_MMXTy(); | |||||
3181 | case IITDescriptor::Metadata: return !Ty->isMetadataTy(); | |||||
3182 | case IITDescriptor::Half: return !Ty->isHalfTy(); | |||||
3183 | case IITDescriptor::Float: return !Ty->isFloatTy(); | |||||
3184 | case IITDescriptor::Double: return !Ty->isDoubleTy(); | |||||
3185 | case IITDescriptor::Integer: return !Ty->isIntegerTy(D.Integer_Width); | |||||
3186 | case IITDescriptor::Vector: { | |||||
3187 | VectorType *VT = dyn_cast<VectorType>(Ty); | |||||
3188 | return !VT || VT->getNumElements() != D.Vector_Width || | |||||
3189 | VerifyIntrinsicType(VT->getElementType(), Infos, ArgTys); | |||||
3190 | } | |||||
3191 | case IITDescriptor::Pointer: { | |||||
3192 | PointerType *PT = dyn_cast<PointerType>(Ty); | |||||
3193 | return !PT || PT->getAddressSpace() != D.Pointer_AddressSpace || | |||||
3194 | VerifyIntrinsicType(PT->getElementType(), Infos, ArgTys); | |||||
3195 | } | |||||
3196 | ||||||
3197 | case IITDescriptor::Struct: { | |||||
3198 | StructType *ST = dyn_cast<StructType>(Ty); | |||||
3199 | if (!ST || ST->getNumElements() != D.Struct_NumElements) | |||||
3200 | return true; | |||||
3201 | ||||||
3202 | for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i) | |||||
3203 | if (VerifyIntrinsicType(ST->getElementType(i), Infos, ArgTys)) | |||||
3204 | return true; | |||||
3205 | return false; | |||||
3206 | } | |||||
3207 | ||||||
3208 | case IITDescriptor::Argument: | |||||
3209 | // Two cases here - If this is the second occurrence of an argument, verify | |||||
3210 | // that the later instance matches the previous instance. | |||||
3211 | if (D.getArgumentNumber() < ArgTys.size()) | |||||
3212 | return Ty != ArgTys[D.getArgumentNumber()]; | |||||
3213 | ||||||
3214 | // Otherwise, if this is the first instance of an argument, record it and | |||||
3215 | // verify the "Any" kind. | |||||
3216 | assert(D.getArgumentNumber() == ArgTys.size() && "Table consistency error")((D.getArgumentNumber() == ArgTys.size() && "Table consistency error" ) ? static_cast<void> (0) : __assert_fail ("D.getArgumentNumber() == ArgTys.size() && \"Table consistency error\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 3216, __PRETTY_FUNCTION__)); | |||||
3217 | ArgTys.push_back(Ty); | |||||
3218 | ||||||
3219 | switch (D.getArgumentKind()) { | |||||
3220 | case IITDescriptor::AK_Any: return false; // Success | |||||
3221 | case IITDescriptor::AK_AnyInteger: return !Ty->isIntOrIntVectorTy(); | |||||
3222 | case IITDescriptor::AK_AnyFloat: return !Ty->isFPOrFPVectorTy(); | |||||
3223 | case IITDescriptor::AK_AnyVector: return !isa<VectorType>(Ty); | |||||
3224 | case IITDescriptor::AK_AnyPointer: return !isa<PointerType>(Ty); | |||||
3225 | } | |||||
3226 | llvm_unreachable("all argument kinds not covered")::llvm::llvm_unreachable_internal("all argument kinds not covered" , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 3226); | |||||
3227 | ||||||
3228 | case IITDescriptor::ExtendArgument: { | |||||
3229 | // This may only be used when referring to a previous vector argument. | |||||
3230 | if (D.getArgumentNumber() >= ArgTys.size()) | |||||
3231 | return true; | |||||
3232 | ||||||
3233 | Type *NewTy = ArgTys[D.getArgumentNumber()]; | |||||
3234 | if (VectorType *VTy = dyn_cast<VectorType>(NewTy)) | |||||
3235 | NewTy = VectorType::getExtendedElementVectorType(VTy); | |||||
3236 | else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy)) | |||||
3237 | NewTy = IntegerType::get(ITy->getContext(), 2 * ITy->getBitWidth()); | |||||
3238 | else | |||||
3239 | return true; | |||||
3240 | ||||||
3241 | return Ty != NewTy; | |||||
3242 | } | |||||
3243 | case IITDescriptor::TruncArgument: { | |||||
3244 | // This may only be used when referring to a previous vector argument. | |||||
3245 | if (D.getArgumentNumber() >= ArgTys.size()) | |||||
3246 | return true; | |||||
3247 | ||||||
3248 | Type *NewTy = ArgTys[D.getArgumentNumber()]; | |||||
3249 | if (VectorType *VTy = dyn_cast<VectorType>(NewTy)) | |||||
3250 | NewTy = VectorType::getTruncatedElementVectorType(VTy); | |||||
3251 | else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy)) | |||||
3252 | NewTy = IntegerType::get(ITy->getContext(), ITy->getBitWidth() / 2); | |||||
3253 | else | |||||
3254 | return true; | |||||
3255 | ||||||
3256 | return Ty != NewTy; | |||||
3257 | } | |||||
3258 | case IITDescriptor::HalfVecArgument: | |||||
3259 | // This may only be used when referring to a previous vector argument. | |||||
3260 | return D.getArgumentNumber() >= ArgTys.size() || | |||||
3261 | !isa<VectorType>(ArgTys[D.getArgumentNumber()]) || | |||||
3262 | VectorType::getHalfElementsVectorType( | |||||
3263 | cast<VectorType>(ArgTys[D.getArgumentNumber()])) != Ty; | |||||
3264 | case IITDescriptor::SameVecWidthArgument: { | |||||
3265 | if (D.getArgumentNumber() >= ArgTys.size()) | |||||
3266 | return true; | |||||
3267 | VectorType * ReferenceType = | |||||
3268 | dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]); | |||||
3269 | VectorType *ThisArgType = dyn_cast<VectorType>(Ty); | |||||
3270 | if (!ThisArgType || !ReferenceType || | |||||
3271 | (ReferenceType->getVectorNumElements() != | |||||
3272 | ThisArgType->getVectorNumElements())) | |||||
3273 | return true; | |||||
3274 | return VerifyIntrinsicType(ThisArgType->getVectorElementType(), | |||||
3275 | Infos, ArgTys); | |||||
3276 | } | |||||
3277 | case IITDescriptor::PtrToArgument: { | |||||
3278 | if (D.getArgumentNumber() >= ArgTys.size()) | |||||
3279 | return true; | |||||
3280 | Type * ReferenceType = ArgTys[D.getArgumentNumber()]; | |||||
3281 | PointerType *ThisArgType = dyn_cast<PointerType>(Ty); | |||||
3282 | return (!ThisArgType || ThisArgType->getElementType() != ReferenceType); | |||||
3283 | } | |||||
3284 | case IITDescriptor::VecOfPtrsToElt: { | |||||
3285 | if (D.getArgumentNumber() >= ArgTys.size()) | |||||
3286 | return true; | |||||
3287 | VectorType * ReferenceType = | |||||
3288 | dyn_cast<VectorType> (ArgTys[D.getArgumentNumber()]); | |||||
3289 | VectorType *ThisArgVecTy = dyn_cast<VectorType>(Ty); | |||||
3290 | if (!ThisArgVecTy || !ReferenceType || | |||||
3291 | (ReferenceType->getVectorNumElements() != | |||||
3292 | ThisArgVecTy->getVectorNumElements())) | |||||
3293 | return true; | |||||
3294 | PointerType *ThisArgEltTy = | |||||
3295 | dyn_cast<PointerType>(ThisArgVecTy->getVectorElementType()); | |||||
3296 | if (!ThisArgEltTy) | |||||
3297 | return true; | |||||
3298 | return ThisArgEltTy->getElementType() != | |||||
3299 | ReferenceType->getVectorElementType(); | |||||
3300 | } | |||||
3301 | } | |||||
3302 | llvm_unreachable("unhandled")::llvm::llvm_unreachable_internal("unhandled", "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 3302); | |||||
3303 | } | |||||
3304 | ||||||
3305 | /// \brief Verify if the intrinsic has variable arguments. | |||||
3306 | /// This method is intended to be called after all the fixed arguments have been | |||||
3307 | /// verified first. | |||||
3308 | /// | |||||
3309 | /// This method returns true on error and does not print an error message. | |||||
3310 | bool | |||||
3311 | Verifier::VerifyIntrinsicIsVarArg(bool isVarArg, | |||||
3312 | ArrayRef<Intrinsic::IITDescriptor> &Infos) { | |||||
3313 | using namespace Intrinsic; | |||||
3314 | ||||||
3315 | // If there are no descriptors left, then it can't be a vararg. | |||||
3316 | if (Infos.empty()) | |||||
3317 | return isVarArg; | |||||
3318 | ||||||
3319 | // There should be only one descriptor remaining at this point. | |||||
3320 | if (Infos.size() != 1) | |||||
3321 | return true; | |||||
3322 | ||||||
3323 | // Check and verify the descriptor. | |||||
3324 | IITDescriptor D = Infos.front(); | |||||
3325 | Infos = Infos.slice(1); | |||||
3326 | if (D.Kind == IITDescriptor::VarArg) | |||||
3327 | return !isVarArg; | |||||
3328 | ||||||
3329 | return true; | |||||
3330 | } | |||||
3331 | ||||||
3332 | /// Allow intrinsics to be verified in different ways. | |||||
3333 | void Verifier::visitIntrinsicCallSite(Intrinsic::ID ID, CallSite CS) { | |||||
3334 | Function *IF = CS.getCalledFunction(); | |||||
3335 | Assert(IF->isDeclaration(), "Intrinsic functions should never be defined!",do { if (!(IF->isDeclaration())) { CheckFailed("Intrinsic functions should never be defined!" , IF); return; } } while (0) | |||||
3336 | IF)do { if (!(IF->isDeclaration())) { CheckFailed("Intrinsic functions should never be defined!" , IF); return; } } while (0); | |||||
3337 | ||||||
3338 | // Verify that the intrinsic prototype lines up with what the .td files | |||||
3339 | // describe. | |||||
3340 | FunctionType *IFTy = IF->getFunctionType(); | |||||
3341 | bool IsVarArg = IFTy->isVarArg(); | |||||
3342 | ||||||
3343 | SmallVector<Intrinsic::IITDescriptor, 8> Table; | |||||
3344 | getIntrinsicInfoTableEntries(ID, Table); | |||||
3345 | ArrayRef<Intrinsic::IITDescriptor> TableRef = Table; | |||||
3346 | ||||||
3347 | SmallVector<Type *, 4> ArgTys; | |||||
3348 | Assert(!VerifyIntrinsicType(IFTy->getReturnType(), TableRef, ArgTys),do { if (!(!VerifyIntrinsicType(IFTy->getReturnType(), TableRef , ArgTys))) { CheckFailed("Intrinsic has incorrect return type!" , IF); return; } } while (0) | |||||
3349 | "Intrinsic has incorrect return type!", IF)do { if (!(!VerifyIntrinsicType(IFTy->getReturnType(), TableRef , ArgTys))) { CheckFailed("Intrinsic has incorrect return type!" , IF); return; } } while (0); | |||||
3350 | for (unsigned i = 0, e = IFTy->getNumParams(); i != e; ++i) | |||||
3351 | Assert(!VerifyIntrinsicType(IFTy->getParamType(i), TableRef, ArgTys),do { if (!(!VerifyIntrinsicType(IFTy->getParamType(i), TableRef , ArgTys))) { CheckFailed("Intrinsic has incorrect argument type!" , IF); return; } } while (0) | |||||
3352 | "Intrinsic has incorrect argument type!", IF)do { if (!(!VerifyIntrinsicType(IFTy->getParamType(i), TableRef , ArgTys))) { CheckFailed("Intrinsic has incorrect argument type!" , IF); return; } } while (0); | |||||
3353 | ||||||
3354 | // Verify if the intrinsic call matches the vararg property. | |||||
3355 | if (IsVarArg) | |||||
3356 | Assert(!VerifyIntrinsicIsVarArg(IsVarArg, TableRef),do { if (!(!VerifyIntrinsicIsVarArg(IsVarArg, TableRef))) { CheckFailed ("Intrinsic was not defined with variable arguments!", IF); return ; } } while (0) | |||||
3357 | "Intrinsic was not defined with variable arguments!", IF)do { if (!(!VerifyIntrinsicIsVarArg(IsVarArg, TableRef))) { CheckFailed ("Intrinsic was not defined with variable arguments!", IF); return ; } } while (0); | |||||
3358 | else | |||||
3359 | Assert(!VerifyIntrinsicIsVarArg(IsVarArg, TableRef),do { if (!(!VerifyIntrinsicIsVarArg(IsVarArg, TableRef))) { CheckFailed ("Callsite was not defined with variable arguments!", IF); return ; } } while (0) | |||||
3360 | "Callsite was not defined with variable arguments!", IF)do { if (!(!VerifyIntrinsicIsVarArg(IsVarArg, TableRef))) { CheckFailed ("Callsite was not defined with variable arguments!", IF); return ; } } while (0); | |||||
3361 | ||||||
3362 | // All descriptors should be absorbed by now. | |||||
3363 | Assert(TableRef.empty(), "Intrinsic has too few arguments!", IF)do { if (!(TableRef.empty())) { CheckFailed("Intrinsic has too few arguments!" , IF); return; } } while (0); | |||||
3364 | ||||||
3365 | // Now that we have the intrinsic ID and the actual argument types (and we | |||||
3366 | // know they are legal for the intrinsic!) get the intrinsic name through the | |||||
3367 | // usual means. This allows us to verify the mangling of argument types into | |||||
3368 | // the name. | |||||
3369 | const std::string ExpectedName = Intrinsic::getName(ID, ArgTys); | |||||
3370 | Assert(ExpectedName == IF->getName(),do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! " "Should be: " + ExpectedName, IF); return; } } while (0) | |||||
3371 | "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 (0) | |||||
3372 | "Should be: " +do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! " "Should be: " + ExpectedName, IF); return; } } while (0) | |||||
3373 | ExpectedName,do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! " "Should be: " + ExpectedName, IF); return; } } while (0) | |||||
3374 | IF)do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! " "Should be: " + ExpectedName, IF); return; } } while (0); | |||||
3375 | ||||||
3376 | // If the intrinsic takes MDNode arguments, verify that they are either global | |||||
3377 | // or are local to *this* function. | |||||
3378 | for (Value *V : CS.args()) | |||||
3379 | if (auto *MD = dyn_cast<MetadataAsValue>(V)) | |||||
3380 | visitMetadataAsValue(*MD, CS.getCaller()); | |||||
3381 | ||||||
3382 | switch (ID) { | |||||
3383 | default: | |||||
3384 | break; | |||||
3385 | case Intrinsic::ctlz: // llvm.ctlz | |||||
3386 | case Intrinsic::cttz: // llvm.cttz | |||||
3387 | Assert(isa<ConstantInt>(CS.getArgOperand(1)),do { if (!(isa<ConstantInt>(CS.getArgOperand(1)))) { CheckFailed ("is_zero_undef argument of bit counting intrinsics must be a " "constant int", CS); return; } } while (0) | |||||
3388 | "is_zero_undef argument of bit counting intrinsics must be a "do { if (!(isa<ConstantInt>(CS.getArgOperand(1)))) { CheckFailed ("is_zero_undef argument of bit counting intrinsics must be a " "constant int", CS); return; } } while (0) | |||||
3389 | "constant int",do { if (!(isa<ConstantInt>(CS.getArgOperand(1)))) { CheckFailed ("is_zero_undef argument of bit counting intrinsics must be a " "constant int", CS); return; } } while (0) | |||||
3390 | CS)do { if (!(isa<ConstantInt>(CS.getArgOperand(1)))) { CheckFailed ("is_zero_undef argument of bit counting intrinsics must be a " "constant int", CS); return; } } while (0); | |||||
3391 | break; | |||||
3392 | case Intrinsic::dbg_declare: // llvm.dbg.declare | |||||
3393 | Assert(isa<MetadataAsValue>(CS.getArgOperand(0)),do { if (!(isa<MetadataAsValue>(CS.getArgOperand(0)))) { CheckFailed("invalid llvm.dbg.declare intrinsic call 1", CS) ; return; } } while (0) | |||||
3394 | "invalid llvm.dbg.declare intrinsic call 1", CS)do { if (!(isa<MetadataAsValue>(CS.getArgOperand(0)))) { CheckFailed("invalid llvm.dbg.declare intrinsic call 1", CS) ; return; } } while (0); | |||||
3395 | visitDbgIntrinsic("declare", cast<DbgDeclareInst>(*CS.getInstruction())); | |||||
3396 | break; | |||||
3397 | case Intrinsic::dbg_value: // llvm.dbg.value | |||||
3398 | visitDbgIntrinsic("value", cast<DbgValueInst>(*CS.getInstruction())); | |||||
3399 | break; | |||||
3400 | case Intrinsic::memcpy: | |||||
3401 | case Intrinsic::memmove: | |||||
3402 | case Intrinsic::memset: { | |||||
3403 | ConstantInt *AlignCI = dyn_cast<ConstantInt>(CS.getArgOperand(3)); | |||||
3404 | Assert(AlignCI,do { if (!(AlignCI)) { CheckFailed("alignment argument of memory intrinsics must be a constant int" , CS); return; } } while (0) | |||||
3405 | "alignment argument of memory intrinsics must be a constant int",do { if (!(AlignCI)) { CheckFailed("alignment argument of memory intrinsics must be a constant int" , CS); return; } } while (0) | |||||
3406 | CS)do { if (!(AlignCI)) { CheckFailed("alignment argument of memory intrinsics must be a constant int" , CS); return; } } while (0); | |||||
3407 | const APInt &AlignVal = AlignCI->getValue(); | |||||
3408 | Assert(AlignCI->isZero() || AlignVal.isPowerOf2(),do { if (!(AlignCI->isZero() || AlignVal.isPowerOf2())) { CheckFailed ("alignment argument of memory intrinsics must be a power of 2" , CS); return; } } while (0) | |||||
3409 | "alignment argument of memory intrinsics must be a power of 2", CS)do { if (!(AlignCI->isZero() || AlignVal.isPowerOf2())) { CheckFailed ("alignment argument of memory intrinsics must be a power of 2" , CS); return; } } while (0); | |||||
3410 | Assert(isa<ConstantInt>(CS.getArgOperand(4)),do { if (!(isa<ConstantInt>(CS.getArgOperand(4)))) { CheckFailed ("isvolatile argument of memory intrinsics must be a constant int" , CS); return; } } while (0) | |||||
3411 | "isvolatile argument of memory intrinsics must be a constant int",do { if (!(isa<ConstantInt>(CS.getArgOperand(4)))) { CheckFailed ("isvolatile argument of memory intrinsics must be a constant int" , CS); return; } } while (0) | |||||
3412 | CS)do { if (!(isa<ConstantInt>(CS.getArgOperand(4)))) { CheckFailed ("isvolatile argument of memory intrinsics must be a constant int" , CS); return; } } while (0); | |||||
3413 | break; | |||||
3414 | } | |||||
3415 | case Intrinsic::gcroot: | |||||
3416 | case Intrinsic::gcwrite: | |||||
3417 | case Intrinsic::gcread: | |||||
3418 | if (ID == Intrinsic::gcroot) { | |||||
3419 | AllocaInst *AI = | |||||
3420 | dyn_cast<AllocaInst>(CS.getArgOperand(0)->stripPointerCasts()); | |||||
3421 | Assert(AI, "llvm.gcroot parameter #1 must be an alloca.", CS)do { if (!(AI)) { CheckFailed("llvm.gcroot parameter #1 must be an alloca." , CS); return; } } while (0); | |||||
3422 | Assert(isa<Constant>(CS.getArgOperand(1)),do { if (!(isa<Constant>(CS.getArgOperand(1)))) { CheckFailed ("llvm.gcroot parameter #2 must be a constant.", CS); return; } } while (0) | |||||
3423 | "llvm.gcroot parameter #2 must be a constant.", CS)do { if (!(isa<Constant>(CS.getArgOperand(1)))) { CheckFailed ("llvm.gcroot parameter #2 must be a constant.", CS); return; } } while (0); | |||||
3424 | if (!AI->getAllocatedType()->isPointerTy()) { | |||||
3425 | Assert(!isa<ConstantPointerNull>(CS.getArgOperand(1)),do { if (!(!isa<ConstantPointerNull>(CS.getArgOperand(1 )))) { CheckFailed("llvm.gcroot parameter #1 must either be a pointer alloca, " "or argument #2 must be a non-null constant.", CS); return; } } while (0) | |||||
3426 | "llvm.gcroot parameter #1 must either be a pointer alloca, "do { if (!(!isa<ConstantPointerNull>(CS.getArgOperand(1 )))) { CheckFailed("llvm.gcroot parameter #1 must either be a pointer alloca, " "or argument #2 must be a non-null constant.", CS); return; } } while (0) | |||||
3427 | "or argument #2 must be a non-null constant.",do { if (!(!isa<ConstantPointerNull>(CS.getArgOperand(1 )))) { CheckFailed("llvm.gcroot parameter #1 must either be a pointer alloca, " "or argument #2 must be a non-null constant.", CS); return; } } while (0) | |||||
3428 | CS)do { if (!(!isa<ConstantPointerNull>(CS.getArgOperand(1 )))) { CheckFailed("llvm.gcroot parameter #1 must either be a pointer alloca, " "or argument #2 must be a non-null constant.", CS); return; } } while (0); | |||||
3429 | } | |||||
3430 | } | |||||
3431 | ||||||
3432 | Assert(CS.getParent()->getParent()->hasGC(),do { if (!(CS.getParent()->getParent()->hasGC())) { CheckFailed ("Enclosing function does not use GC.", CS); return; } } while (0) | |||||
3433 | "Enclosing function does not use GC.", CS)do { if (!(CS.getParent()->getParent()->hasGC())) { CheckFailed ("Enclosing function does not use GC.", CS); return; } } while (0); | |||||
3434 | break; | |||||
3435 | case Intrinsic::init_trampoline: | |||||
3436 | Assert(isa<Function>(CS.getArgOperand(1)->stripPointerCasts()),do { if (!(isa<Function>(CS.getArgOperand(1)->stripPointerCasts ()))) { CheckFailed("llvm.init_trampoline parameter #2 must resolve to a function." , CS); return; } } while (0) | |||||
3437 | "llvm.init_trampoline parameter #2 must resolve to a function.",do { if (!(isa<Function>(CS.getArgOperand(1)->stripPointerCasts ()))) { CheckFailed("llvm.init_trampoline parameter #2 must resolve to a function." , CS); return; } } while (0) | |||||
3438 | CS)do { if (!(isa<Function>(CS.getArgOperand(1)->stripPointerCasts ()))) { CheckFailed("llvm.init_trampoline parameter #2 must resolve to a function." , CS); return; } } while (0); | |||||
3439 | break; | |||||
3440 | case Intrinsic::prefetch: | |||||
3441 | Assert(isa<ConstantInt>(CS.getArgOperand(1)) &&do { if (!(isa<ConstantInt>(CS.getArgOperand(1)) && isa<ConstantInt>(CS.getArgOperand(2)) && cast< ConstantInt>(CS.getArgOperand(1))->getZExtValue() < 2 && cast<ConstantInt>(CS.getArgOperand(2))-> getZExtValue() < 4)) { CheckFailed("invalid arguments to llvm.prefetch" , CS); return; } } while (0) | |||||
3442 | isa<ConstantInt>(CS.getArgOperand(2)) &&do { if (!(isa<ConstantInt>(CS.getArgOperand(1)) && isa<ConstantInt>(CS.getArgOperand(2)) && cast< ConstantInt>(CS.getArgOperand(1))->getZExtValue() < 2 && cast<ConstantInt>(CS.getArgOperand(2))-> getZExtValue() < 4)) { CheckFailed("invalid arguments to llvm.prefetch" , CS); return; } } while (0) | |||||
3443 | cast<ConstantInt>(CS.getArgOperand(1))->getZExtValue() < 2 &&do { if (!(isa<ConstantInt>(CS.getArgOperand(1)) && isa<ConstantInt>(CS.getArgOperand(2)) && cast< ConstantInt>(CS.getArgOperand(1))->getZExtValue() < 2 && cast<ConstantInt>(CS.getArgOperand(2))-> getZExtValue() < 4)) { CheckFailed("invalid arguments to llvm.prefetch" , CS); return; } } while (0) | |||||
3444 | cast<ConstantInt>(CS.getArgOperand(2))->getZExtValue() < 4,do { if (!(isa<ConstantInt>(CS.getArgOperand(1)) && isa<ConstantInt>(CS.getArgOperand(2)) && cast< ConstantInt>(CS.getArgOperand(1))->getZExtValue() < 2 && cast<ConstantInt>(CS.getArgOperand(2))-> getZExtValue() < 4)) { CheckFailed("invalid arguments to llvm.prefetch" , CS); return; } } while (0) | |||||
3445 | "invalid arguments to llvm.prefetch", CS)do { if (!(isa<ConstantInt>(CS.getArgOperand(1)) && isa<ConstantInt>(CS.getArgOperand(2)) && cast< ConstantInt>(CS.getArgOperand(1))->getZExtValue() < 2 && cast<ConstantInt>(CS.getArgOperand(2))-> getZExtValue() < 4)) { CheckFailed("invalid arguments to llvm.prefetch" , CS); return; } } while (0); | |||||
3446 | break; | |||||
3447 | case Intrinsic::stackprotector: | |||||
3448 | Assert(isa<AllocaInst>(CS.getArgOperand(1)->stripPointerCasts()),do { if (!(isa<AllocaInst>(CS.getArgOperand(1)->stripPointerCasts ()))) { CheckFailed("llvm.stackprotector parameter #2 must resolve to an alloca." , CS); return; } } while (0) | |||||
3449 | "llvm.stackprotector parameter #2 must resolve to an alloca.", CS)do { if (!(isa<AllocaInst>(CS.getArgOperand(1)->stripPointerCasts ()))) { CheckFailed("llvm.stackprotector parameter #2 must resolve to an alloca." , CS); return; } } while (0); | |||||
3450 | break; | |||||
3451 | case Intrinsic::lifetime_start: | |||||
3452 | case Intrinsic::lifetime_end: | |||||
3453 | case Intrinsic::invariant_start: | |||||
3454 | Assert(isa<ConstantInt>(CS.getArgOperand(0)),do { if (!(isa<ConstantInt>(CS.getArgOperand(0)))) { CheckFailed ("size argument of memory use markers must be a constant integer" , CS); return; } } while (0) | |||||
3455 | "size argument of memory use markers must be a constant integer",do { if (!(isa<ConstantInt>(CS.getArgOperand(0)))) { CheckFailed ("size argument of memory use markers must be a constant integer" , CS); return; } } while (0) | |||||
3456 | CS)do { if (!(isa<ConstantInt>(CS.getArgOperand(0)))) { CheckFailed ("size argument of memory use markers must be a constant integer" , CS); return; } } while (0); | |||||
3457 | break; | |||||
3458 | case Intrinsic::invariant_end: | |||||
3459 | Assert(isa<ConstantInt>(CS.getArgOperand(1)),do { if (!(isa<ConstantInt>(CS.getArgOperand(1)))) { CheckFailed ("llvm.invariant.end parameter #2 must be a constant integer" , CS); return; } } while (0) | |||||
3460 | "llvm.invariant.end parameter #2 must be a constant integer", CS)do { if (!(isa<ConstantInt>(CS.getArgOperand(1)))) { CheckFailed ("llvm.invariant.end parameter #2 must be a constant integer" , CS); return; } } while (0); | |||||
3461 | break; | |||||
3462 | ||||||
3463 | case Intrinsic::localescape: { | |||||
3464 | BasicBlock *BB = CS.getParent(); | |||||
3465 | Assert(BB == &BB->getParent()->front(),do { if (!(BB == &BB->getParent()->front())) { CheckFailed ("llvm.localescape used outside of entry block", CS); return; } } while (0) | |||||
3466 | "llvm.localescape used outside of entry block", CS)do { if (!(BB == &BB->getParent()->front())) { CheckFailed ("llvm.localescape used outside of entry block", CS); return; } } while (0); | |||||
3467 | Assert(!SawFrameEscape,do { if (!(!SawFrameEscape)) { CheckFailed("multiple calls to llvm.localescape in one function" , CS); return; } } while (0) | |||||
3468 | "multiple calls to llvm.localescape in one function", CS)do { if (!(!SawFrameEscape)) { CheckFailed("multiple calls to llvm.localescape in one function" , CS); return; } } while (0); | |||||
3469 | for (Value *Arg : CS.args()) { | |||||
3470 | if (isa<ConstantPointerNull>(Arg)) | |||||
3471 | continue; // Null values are allowed as placeholders. | |||||
3472 | auto *AI = dyn_cast<AllocaInst>(Arg->stripPointerCasts()); | |||||
3473 | Assert(AI && AI->isStaticAlloca(),do { if (!(AI && AI->isStaticAlloca())) { CheckFailed ("llvm.localescape only accepts static allocas", CS); return; } } while (0) | |||||
3474 | "llvm.localescape only accepts static allocas", CS)do { if (!(AI && AI->isStaticAlloca())) { CheckFailed ("llvm.localescape only accepts static allocas", CS); return; } } while (0); | |||||
3475 | } | |||||
3476 | FrameEscapeInfo[BB->getParent()].first = CS.getNumArgOperands(); | |||||
3477 | SawFrameEscape = true; | |||||
3478 | break; | |||||
3479 | } | |||||
3480 | case Intrinsic::localrecover: { | |||||
3481 | Value *FnArg = CS.getArgOperand(0)->stripPointerCasts(); | |||||
3482 | Function *Fn = dyn_cast<Function>(FnArg); | |||||
3483 | Assert(Fn && !Fn->isDeclaration(),do { if (!(Fn && !Fn->isDeclaration())) { CheckFailed ("llvm.localrecover first " "argument must be function defined in this module" , CS); return; } } while (0) | |||||
3484 | "llvm.localrecover first "do { if (!(Fn && !Fn->isDeclaration())) { CheckFailed ("llvm.localrecover first " "argument must be function defined in this module" , CS); return; } } while (0) | |||||
3485 | "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" , CS); return; } } while (0) | |||||
3486 | CS)do { if (!(Fn && !Fn->isDeclaration())) { CheckFailed ("llvm.localrecover first " "argument must be function defined in this module" , CS); return; } } while (0); | |||||
3487 | auto *IdxArg = dyn_cast<ConstantInt>(CS.getArgOperand(2)); | |||||
3488 | Assert(IdxArg, "idx argument of llvm.localrecover must be a constant int",do { if (!(IdxArg)) { CheckFailed("idx argument of llvm.localrecover must be a constant int" , CS); return; } } while (0) | |||||
3489 | CS)do { if (!(IdxArg)) { CheckFailed("idx argument of llvm.localrecover must be a constant int" , CS); return; } } while (0); | |||||
3490 | auto &Entry = FrameEscapeInfo[Fn]; | |||||
3491 | Entry.second = unsigned( | |||||
3492 | std::max(uint64_t(Entry.second), IdxArg->getLimitedValue(~0U) + 1)); | |||||
3493 | break; | |||||
3494 | } | |||||
3495 | ||||||
3496 | case Intrinsic::experimental_gc_statepoint: | |||||
3497 | Assert(!CS.isInlineAsm(),do { if (!(!CS.isInlineAsm())) { CheckFailed("gc.statepoint support for inline assembly unimplemented" , CS); return; } } while (0) | |||||
3498 | "gc.statepoint support for inline assembly unimplemented", CS)do { if (!(!CS.isInlineAsm())) { CheckFailed("gc.statepoint support for inline assembly unimplemented" , CS); return; } } while (0); | |||||
3499 | Assert(CS.getParent()->getParent()->hasGC(),do { if (!(CS.getParent()->getParent()->hasGC())) { CheckFailed ("Enclosing function does not use GC.", CS); return; } } while (0) | |||||
3500 | "Enclosing function does not use GC.", CS)do { if (!(CS.getParent()->getParent()->hasGC())) { CheckFailed ("Enclosing function does not use GC.", CS); return; } } while (0); | |||||
3501 | ||||||
3502 | VerifyStatepoint(CS); | |||||
3503 | break; | |||||
3504 | case Intrinsic::experimental_gc_result_int: | |||||
3505 | case Intrinsic::experimental_gc_result_float: | |||||
3506 | case Intrinsic::experimental_gc_result_ptr: | |||||
3507 | case Intrinsic::experimental_gc_result: { | |||||
3508 | Assert(CS.getParent()->getParent()->hasGC(),do { if (!(CS.getParent()->getParent()->hasGC())) { CheckFailed ("Enclosing function does not use GC.", CS); return; } } while (0) | |||||
3509 | "Enclosing function does not use GC.", CS)do { if (!(CS.getParent()->getParent()->hasGC())) { CheckFailed ("Enclosing function does not use GC.", CS); return; } } while (0); | |||||
3510 | // Are we tied to a statepoint properly? | |||||
3511 | CallSite StatepointCS(CS.getArgOperand(0)); | |||||
3512 | const Function *StatepointFn = | |||||
3513 | StatepointCS.getInstruction() ? StatepointCS.getCalledFunction() : nullptr; | |||||
3514 | 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" , CS, CS.getArgOperand(0)); return; } } while (0) | |||||
3515 | StatepointFn->getIntrinsicID() ==do { if (!(StatepointFn && StatepointFn->isDeclaration () && StatepointFn->getIntrinsicID() == Intrinsic:: experimental_gc_statepoint)) { CheckFailed("gc.result operand #1 must be from a statepoint" , CS, CS.getArgOperand(0)); return; } } while (0) | |||||
3516 | 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" , CS, CS.getArgOperand(0)); return; } } while (0) | |||||
3517 | "gc.result operand #1 must be from a statepoint", CS,do { if (!(StatepointFn && StatepointFn->isDeclaration () && StatepointFn->getIntrinsicID() == Intrinsic:: experimental_gc_statepoint)) { CheckFailed("gc.result operand #1 must be from a statepoint" , CS, CS.getArgOperand(0)); return; } } while (0) | |||||
3518 | CS.getArgOperand(0))do { if (!(StatepointFn && StatepointFn->isDeclaration () && StatepointFn->getIntrinsicID() == Intrinsic:: experimental_gc_statepoint)) { CheckFailed("gc.result operand #1 must be from a statepoint" , CS, CS.getArgOperand(0)); return; } } while (0); | |||||
3519 | ||||||
3520 | // Assert that result type matches wrapped callee. | |||||
3521 | const Value *Target = StatepointCS.getArgument(2); | |||||
3522 | auto *PT = cast<PointerType>(Target->getType()); | |||||
3523 | auto *TargetFuncType = cast<FunctionType>(PT->getElementType()); | |||||
3524 | Assert(CS.getType() == TargetFuncType->getReturnType(),do { if (!(CS.getType() == TargetFuncType->getReturnType() )) { CheckFailed("gc.result result type does not match wrapped callee" , CS); return; } } while (0) | |||||
3525 | "gc.result result type does not match wrapped callee", CS)do { if (!(CS.getType() == TargetFuncType->getReturnType() )) { CheckFailed("gc.result result type does not match wrapped callee" , CS); return; } } while (0); | |||||
3526 | break; | |||||
3527 | } | |||||
3528 | case Intrinsic::experimental_gc_relocate: { | |||||
3529 | Assert(CS.getNumArgOperands() == 3, "wrong number of arguments", CS)do { if (!(CS.getNumArgOperands() == 3)) { CheckFailed("wrong number of arguments" , CS); return; } } while (0); | |||||
3530 | ||||||
3531 | // Check that this relocate is correctly tied to the statepoint | |||||
3532 | ||||||
3533 | // This is case for relocate on the unwinding path of an invoke statepoint | |||||
3534 | if (ExtractValueInst *ExtractValue = | |||||
3535 | dyn_cast<ExtractValueInst>(CS.getArgOperand(0))) { | |||||
3536 | Assert(isa<LandingPadInst>(ExtractValue->getAggregateOperand()),do { if (!(isa<LandingPadInst>(ExtractValue->getAggregateOperand ()))) { CheckFailed("gc relocate on unwind path incorrectly linked to the statepoint" , CS); return; } } while (0) | |||||
3537 | "gc relocate on unwind path incorrectly linked to the statepoint",do { if (!(isa<LandingPadInst>(ExtractValue->getAggregateOperand ()))) { CheckFailed("gc relocate on unwind path incorrectly linked to the statepoint" , CS); return; } } while (0) | |||||
3538 | CS)do { if (!(isa<LandingPadInst>(ExtractValue->getAggregateOperand ()))) { CheckFailed("gc relocate on unwind path incorrectly linked to the statepoint" , CS); return; } } while (0); | |||||
3539 | ||||||
3540 | const BasicBlock *InvokeBB = | |||||
3541 | ExtractValue->getParent()->getUniquePredecessor(); | |||||
3542 | ||||||
3543 | // Landingpad relocates should have only one predecessor with invoke | |||||
3544 | // statepoint terminator | |||||
3545 | Assert(InvokeBB, "safepoints should have unique landingpads",do { if (!(InvokeBB)) { CheckFailed("safepoints should have unique landingpads" , ExtractValue->getParent()); return; } } while (0) | |||||
3546 | ExtractValue->getParent())do { if (!(InvokeBB)) { CheckFailed("safepoints should have unique landingpads" , ExtractValue->getParent()); return; } } while (0); | |||||
3547 | Assert(InvokeBB->getTerminator(), "safepoint block should be well formed",do { if (!(InvokeBB->getTerminator())) { CheckFailed("safepoint block should be well formed" , InvokeBB); return; } } while (0) | |||||
3548 | InvokeBB)do { if (!(InvokeBB->getTerminator())) { CheckFailed("safepoint block should be well formed" , InvokeBB); return; } } while (0); | |||||
3549 | Assert(isStatepoint(InvokeBB->getTerminator()),do { if (!(isStatepoint(InvokeBB->getTerminator()))) { CheckFailed ("gc relocate should be linked to a statepoint", InvokeBB); return ; } } while (0) | |||||
3550 | "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 (0); | |||||
3551 | } | |||||
3552 | else { | |||||
3553 | // In all other cases relocate should be tied to the statepoint directly. | |||||
3554 | // This covers relocates on a normal return path of invoke statepoint and | |||||
3555 | // relocates of a call statepoint | |||||
3556 | auto Token = CS.getArgOperand(0); | |||||
3557 | 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" , CS, Token); return; } } while (0) | |||||
3558 | "gc relocate is incorrectly tied to the statepoint", CS, Token)do { if (!(isa<Instruction>(Token) && isStatepoint (cast<Instruction>(Token)))) { CheckFailed("gc relocate is incorrectly tied to the statepoint" , CS, Token); return; } } while (0); | |||||
3559 | } | |||||
3560 | ||||||
3561 | // Verify rest of the relocate arguments | |||||
3562 | ||||||
3563 | GCRelocateOperands Ops(CS); | |||||
3564 | ImmutableCallSite StatepointCS(Ops.getStatepoint()); | |||||
3565 | ||||||
3566 | // Both the base and derived must be piped through the safepoint | |||||
3567 | Value* Base = CS.getArgOperand(1); | |||||
3568 | Assert(isa<ConstantInt>(Base),do { if (!(isa<ConstantInt>(Base))) { CheckFailed("gc.relocate operand #2 must be integer offset" , CS); return; } } while (0) | |||||
3569 | "gc.relocate operand #2 must be integer offset", CS)do { if (!(isa<ConstantInt>(Base))) { CheckFailed("gc.relocate operand #2 must be integer offset" , CS); return; } } while (0); | |||||
3570 | ||||||
3571 | Value* Derived = CS.getArgOperand(2); | |||||
3572 | Assert(isa<ConstantInt>(Derived),do { if (!(isa<ConstantInt>(Derived))) { CheckFailed("gc.relocate operand #3 must be integer offset" , CS); return; } } while (0) | |||||
3573 | "gc.relocate operand #3 must be integer offset", CS)do { if (!(isa<ConstantInt>(Derived))) { CheckFailed("gc.relocate operand #3 must be integer offset" , CS); return; } } while (0); | |||||
3574 | ||||||
3575 | const int BaseIndex = cast<ConstantInt>(Base)->getZExtValue(); | |||||
3576 | const int DerivedIndex = cast<ConstantInt>(Derived)->getZExtValue(); | |||||
3577 | // Check the bounds | |||||
3578 | Assert(0 <= BaseIndex && BaseIndex < (int)StatepointCS.arg_size(),do { if (!(0 <= BaseIndex && BaseIndex < (int)StatepointCS .arg_size())) { CheckFailed("gc.relocate: statepoint base index out of bounds" , CS); return; } } while (0) | |||||
3579 | "gc.relocate: statepoint base index out of bounds", CS)do { if (!(0 <= BaseIndex && BaseIndex < (int)StatepointCS .arg_size())) { CheckFailed("gc.relocate: statepoint base index out of bounds" , CS); return; } } while (0); | |||||
3580 | Assert(0 <= DerivedIndex && DerivedIndex < (int)StatepointCS.arg_size(),do { if (!(0 <= DerivedIndex && DerivedIndex < ( int)StatepointCS.arg_size())) { CheckFailed("gc.relocate: statepoint derived index out of bounds" , CS); return; } } while (0) | |||||
3581 | "gc.relocate: statepoint derived index out of bounds", CS)do { if (!(0 <= DerivedIndex && DerivedIndex < ( int)StatepointCS.arg_size())) { CheckFailed("gc.relocate: statepoint derived index out of bounds" , CS); return; } } while (0); | |||||
3582 | ||||||
3583 | // Check that BaseIndex and DerivedIndex fall within the 'gc parameters' | |||||
3584 | // section of the statepoint's argument | |||||
3585 | Assert(StatepointCS.arg_size() > 0,do { if (!(StatepointCS.arg_size() > 0)) { CheckFailed("gc.statepoint: insufficient arguments" ); return; } } while (0) | |||||
3586 | "gc.statepoint: insufficient arguments")do { if (!(StatepointCS.arg_size() > 0)) { CheckFailed("gc.statepoint: insufficient arguments" ); return; } } while (0); | |||||
3587 | Assert(isa<ConstantInt>(StatepointCS.getArgument(3)),do { if (!(isa<ConstantInt>(StatepointCS.getArgument(3) ))) { CheckFailed("gc.statement: number of call arguments must be constant integer" ); return; } } while (0) | |||||
3588 | "gc.statement: number of call arguments must be constant integer")do { if (!(isa<ConstantInt>(StatepointCS.getArgument(3) ))) { CheckFailed("gc.statement: number of call arguments must be constant integer" ); return; } } while (0); | |||||
3589 | const unsigned NumCallArgs = | |||||
3590 | cast<ConstantInt>(StatepointCS.getArgument(3))->getZExtValue(); | |||||
3591 | Assert(StatepointCS.arg_size() > NumCallArgs + 5,do { if (!(StatepointCS.arg_size() > NumCallArgs + 5)) { CheckFailed ("gc.statepoint: mismatch in number of call arguments"); return ; } } while (0) | |||||
3592 | "gc.statepoint: mismatch in number of call arguments")do { if (!(StatepointCS.arg_size() > NumCallArgs + 5)) { CheckFailed ("gc.statepoint: mismatch in number of call arguments"); return ; } } while (0); | |||||
3593 | Assert(isa<ConstantInt>(StatepointCS.getArgument(NumCallArgs + 5)),do { if (!(isa<ConstantInt>(StatepointCS.getArgument(NumCallArgs + 5)))) { CheckFailed("gc.statepoint: number of transition arguments must be " "a constant integer"); return; } } while (0) | |||||
3594 | "gc.statepoint: number of transition arguments must be "do { if (!(isa<ConstantInt>(StatepointCS.getArgument(NumCallArgs + 5)))) { CheckFailed("gc.statepoint: number of transition arguments must be " "a constant integer"); return; } } while (0) | |||||
3595 | "a constant integer")do { if (!(isa<ConstantInt>(StatepointCS.getArgument(NumCallArgs + 5)))) { CheckFailed("gc.statepoint: number of transition arguments must be " "a constant integer"); return; } } while (0); | |||||
3596 | const int NumTransitionArgs = | |||||
3597 | cast<ConstantInt>(StatepointCS.getArgument(NumCallArgs + 5)) | |||||
3598 | ->getZExtValue(); | |||||
3599 | const int DeoptArgsStart = 4 + NumCallArgs + 1 + NumTransitionArgs + 1; | |||||
3600 | Assert(isa<ConstantInt>(StatepointCS.getArgument(DeoptArgsStart)),do { if (!(isa<ConstantInt>(StatepointCS.getArgument(DeoptArgsStart )))) { CheckFailed("gc.statepoint: number of deoptimization arguments must be " "a constant integer"); return; } } while (0) | |||||
3601 | "gc.statepoint: number of deoptimization arguments must be "do { if (!(isa<ConstantInt>(StatepointCS.getArgument(DeoptArgsStart )))) { CheckFailed("gc.statepoint: number of deoptimization arguments must be " "a constant integer"); return; } } while (0) | |||||
3602 | "a constant integer")do { if (!(isa<ConstantInt>(StatepointCS.getArgument(DeoptArgsStart )))) { CheckFailed("gc.statepoint: number of deoptimization arguments must be " "a constant integer"); return; } } while (0); | |||||
3603 | const int NumDeoptArgs = | |||||
3604 | cast<ConstantInt>(StatepointCS.getArgument(DeoptArgsStart))->getZExtValue(); | |||||
3605 | const int GCParamArgsStart = DeoptArgsStart + 1 + NumDeoptArgs; | |||||
3606 | const int GCParamArgsEnd = StatepointCS.arg_size(); | |||||
3607 | 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", CS); return ; } } while (0) | |||||
3608 | "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", CS); return ; } } while (0) | |||||
3609 | "'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", CS); return ; } } while (0) | |||||
3610 | CS)do { if (!(GCParamArgsStart <= BaseIndex && BaseIndex < GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint base index doesn't fall within the " "'gc parameters' section of the statepoint call", CS); return ; } } while (0); | |||||
3611 | 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", CS); return ; } } while (0) | |||||
3612 | "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", CS); return ; } } while (0) | |||||
3613 | "'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", CS); return ; } } while (0) | |||||
3614 | CS)do { if (!(GCParamArgsStart <= DerivedIndex && DerivedIndex < GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint derived index doesn't fall within the " "'gc parameters' section of the statepoint call", CS); return ; } } while (0); | |||||
3615 | ||||||
3616 | // Relocated value must be a pointer type, but gc_relocate does not need to return the | |||||
3617 | // same pointer type as the relocated pointer. It can be casted to the correct type later | |||||
3618 | // if it's desired. However, they must have the same address space. | |||||
3619 | GCRelocateOperands Operands(CS); | |||||
3620 | Assert(Operands.getDerivedPtr()->getType()->isPointerTy(),do { if (!(Operands.getDerivedPtr()->getType()->isPointerTy ())) { CheckFailed("gc.relocate: relocated value must be a gc pointer" , CS); return; } } while (0) | |||||
3621 | "gc.relocate: relocated value must be a gc pointer", CS)do { if (!(Operands.getDerivedPtr()->getType()->isPointerTy ())) { CheckFailed("gc.relocate: relocated value must be a gc pointer" , CS); return; } } while (0); | |||||
3622 | ||||||
3623 | // gc_relocate return type must be a pointer type, and is verified earlier in | |||||
3624 | // VerifyIntrinsicType(). | |||||
3625 | Assert(cast<PointerType>(CS.getType())->getAddressSpace() ==do { if (!(cast<PointerType>(CS.getType())->getAddressSpace () == cast<PointerType>(Operands.getDerivedPtr()->getType ())->getAddressSpace())) { CheckFailed("gc.relocate: relocating a pointer shouldn't change its address space" , CS); return; } } while (0) | |||||
3626 | cast<PointerType>(Operands.getDerivedPtr()->getType())->getAddressSpace(),do { if (!(cast<PointerType>(CS.getType())->getAddressSpace () == cast<PointerType>(Operands.getDerivedPtr()->getType ())->getAddressSpace())) { CheckFailed("gc.relocate: relocating a pointer shouldn't change its address space" , CS); return; } } while (0) | |||||
3627 | "gc.relocate: relocating a pointer shouldn't change its address space", CS)do { if (!(cast<PointerType>(CS.getType())->getAddressSpace () == cast<PointerType>(Operands.getDerivedPtr()->getType ())->getAddressSpace())) { CheckFailed("gc.relocate: relocating a pointer shouldn't change its address space" , CS); return; } } while (0); | |||||
3628 | break; | |||||
3629 | } | |||||
3630 | }; | |||||
3631 | } | |||||
3632 | ||||||
3633 | /// \brief Carefully grab the subprogram from a local scope. | |||||
3634 | /// | |||||
3635 | /// This carefully grabs the subprogram from a local scope, avoiding the | |||||
3636 | /// built-in assertions that would typically fire. | |||||
3637 | static DISubprogram *getSubprogram(Metadata *LocalScope) { | |||||
3638 | if (!LocalScope) | |||||
3639 | return nullptr; | |||||
3640 | ||||||
3641 | if (auto *SP = dyn_cast<DISubprogram>(LocalScope)) | |||||
3642 | return SP; | |||||
3643 | ||||||
3644 | if (auto *LB = dyn_cast<DILexicalBlockBase>(LocalScope)) | |||||
3645 | return getSubprogram(LB->getRawScope()); | |||||
3646 | ||||||
3647 | // Just return null; broken scope chains are checked elsewhere. | |||||
3648 | 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\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 3648, __PRETTY_FUNCTION__)); | |||||
3649 | return nullptr; | |||||
3650 | } | |||||
3651 | ||||||
3652 | template <class DbgIntrinsicTy> | |||||
3653 | void Verifier::visitDbgIntrinsic(StringRef Kind, DbgIntrinsicTy &DII) { | |||||
3654 | auto *MD = cast<MetadataAsValue>(DII.getArgOperand(0))->getMetadata(); | |||||
3655 | Assert(isa<ValueAsMetadata>(MD) ||do { if (!(isa<ValueAsMetadata>(MD) || (isa<MDNode> (MD) && !cast<MDNode>(MD)->getNumOperands()) )) { CheckFailed("invalid llvm.dbg." + Kind + " intrinsic address/value" , &DII, MD); return; } } while (0) | |||||
3656 | (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands()),do { if (!(isa<ValueAsMetadata>(MD) || (isa<MDNode> (MD) && !cast<MDNode>(MD)->getNumOperands()) )) { CheckFailed("invalid llvm.dbg." + Kind + " intrinsic address/value" , &DII, MD); return; } } while (0) | |||||
3657 | "invalid llvm.dbg." + Kind + " intrinsic address/value", &DII, MD)do { if (!(isa<ValueAsMetadata>(MD) || (isa<MDNode> (MD) && !cast<MDNode>(MD)->getNumOperands()) )) { CheckFailed("invalid llvm.dbg." + Kind + " intrinsic address/value" , &DII, MD); return; } } while (0); | |||||
3658 | Assert(isa<DILocalVariable>(DII.getRawVariable()),do { if (!(isa<DILocalVariable>(DII.getRawVariable()))) { CheckFailed("invalid llvm.dbg." + Kind + " intrinsic variable" , &DII, DII.getRawVariable()); return; } } while (0) | |||||
3659 | "invalid llvm.dbg." + Kind + " intrinsic variable", &DII,do { if (!(isa<DILocalVariable>(DII.getRawVariable()))) { CheckFailed("invalid llvm.dbg." + Kind + " intrinsic variable" , &DII, DII.getRawVariable()); return; } } while (0) | |||||
3660 | DII.getRawVariable())do { if (!(isa<DILocalVariable>(DII.getRawVariable()))) { CheckFailed("invalid llvm.dbg." + Kind + " intrinsic variable" , &DII, DII.getRawVariable()); return; } } while (0); | |||||
3661 | Assert(isa<DIExpression>(DII.getRawExpression()),do { if (!(isa<DIExpression>(DII.getRawExpression()))) { CheckFailed("invalid llvm.dbg." + Kind + " intrinsic expression" , &DII, DII.getRawExpression()); return; } } while (0) | |||||
3662 | "invalid llvm.dbg." + Kind + " intrinsic expression", &DII,do { if (!(isa<DIExpression>(DII.getRawExpression()))) { CheckFailed("invalid llvm.dbg." + Kind + " intrinsic expression" , &DII, DII.getRawExpression()); return; } } while (0) | |||||
3663 | DII.getRawExpression())do { if (!(isa<DIExpression>(DII.getRawExpression()))) { CheckFailed("invalid llvm.dbg." + Kind + " intrinsic expression" , &DII, DII.getRawExpression()); return; } } while (0); | |||||
3664 | ||||||
3665 | // Ignore broken !dbg attachments; they're checked elsewhere. | |||||
3666 | if (MDNode *N = DII.getDebugLoc().getAsMDNode()) | |||||
3667 | if (!isa<DILocation>(N)) | |||||
3668 | return; | |||||
3669 | ||||||
3670 | BasicBlock *BB = DII.getParent(); | |||||
3671 | Function *F = BB ? BB->getParent() : nullptr; | |||||
3672 | ||||||
3673 | // The scopes for variables and !dbg attachments must agree. | |||||
3674 | DILocalVariable *Var = DII.getVariable(); | |||||
3675 | DILocation *Loc = DII.getDebugLoc(); | |||||
3676 | Assert(Loc, "llvm.dbg." + Kind + " intrinsic requires a !dbg attachment",do { if (!(Loc)) { CheckFailed("llvm.dbg." + Kind + " intrinsic requires a !dbg attachment" , &DII, BB, F); return; } } while (0) | |||||
3677 | &DII, BB, F)do { if (!(Loc)) { CheckFailed("llvm.dbg." + Kind + " intrinsic requires a !dbg attachment" , &DII, BB, F); return; } } while (0); | |||||
3678 | ||||||
3679 | DISubprogram *VarSP = getSubprogram(Var->getRawScope()); | |||||
3680 | DISubprogram *LocSP = getSubprogram(Loc->getRawScope()); | |||||
3681 | if (!VarSP || !LocSP) | |||||
3682 | return; // Broken scope chains are checked elsewhere. | |||||
3683 | ||||||
3684 | Assert(VarSP == LocSP, "mismatched subprogram between llvm.dbg." + Kind +do { if (!(VarSP == LocSP)) { CheckFailed("mismatched subprogram between llvm.dbg." + Kind + " variable and !dbg attachment", &DII, BB, F, Var , Var->getScope()->getSubprogram(), Loc, Loc->getScope ()->getSubprogram()); return; } } while (0) | |||||
3685 | " variable and !dbg attachment",do { if (!(VarSP == LocSP)) { CheckFailed("mismatched subprogram between llvm.dbg." + Kind + " variable and !dbg attachment", &DII, BB, F, Var , Var->getScope()->getSubprogram(), Loc, Loc->getScope ()->getSubprogram()); return; } } while (0) | |||||
3686 | &DII, BB, F, Var, Var->getScope()->getSubprogram(), Loc,do { if (!(VarSP == LocSP)) { CheckFailed("mismatched subprogram between llvm.dbg." + Kind + " variable and !dbg attachment", &DII, BB, F, Var , Var->getScope()->getSubprogram(), Loc, Loc->getScope ()->getSubprogram()); return; } } while (0) | |||||
3687 | Loc->getScope()->getSubprogram())do { if (!(VarSP == LocSP)) { CheckFailed("mismatched subprogram between llvm.dbg." + Kind + " variable and !dbg attachment", &DII, BB, F, Var , Var->getScope()->getSubprogram(), Loc, Loc->getScope ()->getSubprogram()); return; } } while (0); | |||||
3688 | } | |||||
3689 | ||||||
3690 | template <class MapTy> | |||||
3691 | static uint64_t getVariableSize(const DILocalVariable &V, const MapTy &Map) { | |||||
3692 | // Be careful of broken types (checked elsewhere). | |||||
3693 | const Metadata *RawType = V.getRawType(); | |||||
3694 | while (RawType) { | |||||
3695 | // Try to get the size directly. | |||||
3696 | if (auto *T = dyn_cast<DIType>(RawType)) | |||||
3697 | if (uint64_t Size = T->getSizeInBits()) | |||||
3698 | return Size; | |||||
3699 | ||||||
3700 | if (auto *DT = dyn_cast<DIDerivedType>(RawType)) { | |||||
3701 | // Look at the base type. | |||||
3702 | RawType = DT->getRawBaseType(); | |||||
3703 | continue; | |||||
3704 | } | |||||
3705 | ||||||
3706 | if (auto *S = dyn_cast<MDString>(RawType)) { | |||||
3707 | // Don't error on missing types (checked elsewhere). | |||||
3708 | RawType = Map.lookup(S); | |||||
3709 | continue; | |||||
3710 | } | |||||
3711 | ||||||
3712 | // Missing type or size. | |||||
3713 | break; | |||||
3714 | } | |||||
3715 | ||||||
3716 | // Fail gracefully. | |||||
3717 | return 0; | |||||
3718 | } | |||||
3719 | ||||||
3720 | template <class MapTy> | |||||
3721 | void Verifier::verifyBitPieceExpression(const DbgInfoIntrinsic &I, | |||||
3722 | const MapTy &TypeRefs) { | |||||
3723 | DILocalVariable *V; | |||||
3724 | DIExpression *E; | |||||
3725 | if (auto *DVI = dyn_cast<DbgValueInst>(&I)) { | |||||
3726 | V = dyn_cast_or_null<DILocalVariable>(DVI->getRawVariable()); | |||||
3727 | E = dyn_cast_or_null<DIExpression>(DVI->getRawExpression()); | |||||
3728 | } else { | |||||
3729 | auto *DDI = cast<DbgDeclareInst>(&I); | |||||
3730 | V = dyn_cast_or_null<DILocalVariable>(DDI->getRawVariable()); | |||||
3731 | E = dyn_cast_or_null<DIExpression>(DDI->getRawExpression()); | |||||
3732 | } | |||||
3733 | ||||||
3734 | // We don't know whether this intrinsic verified correctly. | |||||
3735 | if (!V || !E || !E->isValid()) | |||||
3736 | return; | |||||
3737 | ||||||
3738 | // Nothing to do if this isn't a bit piece expression. | |||||
3739 | if (!E->isBitPiece()) | |||||
3740 | return; | |||||
3741 | ||||||
3742 | // The frontend helps out GDB by emitting the members of local anonymous | |||||
3743 | // unions as artificial local variables with shared storage. When SROA splits | |||||
3744 | // the storage for artificial local variables that are smaller than the entire | |||||
3745 | // union, the overhang piece will be outside of the allotted space for the | |||||
3746 | // variable and this check fails. | |||||
3747 | // FIXME: Remove this check as soon as clang stops doing this; it hides bugs. | |||||
3748 | if (V->isArtificial()) | |||||
3749 | return; | |||||
3750 | ||||||
3751 | // If there's no size, the type is broken, but that should be checked | |||||
3752 | // elsewhere. | |||||
3753 | uint64_t VarSize = getVariableSize(*V, TypeRefs); | |||||
3754 | if (!VarSize) | |||||
3755 | return; | |||||
3756 | ||||||
3757 | unsigned PieceSize = E->getBitPieceSize(); | |||||
3758 | unsigned PieceOffset = E->getBitPieceOffset(); | |||||
3759 | Assert(PieceSize + PieceOffset <= VarSize,do { if (!(PieceSize + PieceOffset <= VarSize)) { CheckFailed ("piece is larger than or outside of variable", &I, V, E) ; return; } } while (0) | |||||
3760 | "piece is larger than or outside of variable", &I, V, E)do { if (!(PieceSize + PieceOffset <= VarSize)) { CheckFailed ("piece is larger than or outside of variable", &I, V, E) ; return; } } while (0); | |||||
3761 | Assert(PieceSize != VarSize, "piece covers entire variable", &I, V, E)do { if (!(PieceSize != VarSize)) { CheckFailed("piece covers entire variable" , &I, V, E); return; } } while (0); | |||||
3762 | } | |||||
3763 | ||||||
3764 | void Verifier::visitUnresolvedTypeRef(const MDString *S, const MDNode *N) { | |||||
3765 | // This is in its own function so we get an error for each bad type ref (not | |||||
3766 | // just the first). | |||||
3767 | Assert(false, "unresolved type ref", S, N)do { if (!(false)) { CheckFailed("unresolved type ref", S, N) ; return; } } while (0); | |||||
3768 | } | |||||
3769 | ||||||
3770 | void Verifier::verifyTypeRefs() { | |||||
3771 | auto *CUs = M->getNamedMetadata("llvm.dbg.cu"); | |||||
3772 | if (!CUs) | |||||
3773 | return; | |||||
3774 | ||||||
3775 | // Visit all the compile units again to map the type references. | |||||
3776 | SmallDenseMap<const MDString *, const DIType *, 32> TypeRefs; | |||||
3777 | for (auto *CU : CUs->operands()) | |||||
3778 | if (auto Ts = cast<DICompileUnit>(CU)->getRetainedTypes()) | |||||
3779 | for (DIType *Op : Ts) | |||||
3780 | if (auto *T = dyn_cast_or_null<DICompositeType>(Op)) | |||||
3781 | if (auto *S = T->getRawIdentifier()) { | |||||
3782 | UnresolvedTypeRefs.erase(S); | |||||
3783 | TypeRefs.insert(std::make_pair(S, T)); | |||||
3784 | } | |||||
3785 | ||||||
3786 | // Verify debug info intrinsic bit piece expressions. This needs a second | |||||
3787 | // pass through the intructions, since we haven't built TypeRefs yet when | |||||
3788 | // verifying functions, and simply queuing the DbgInfoIntrinsics to evaluate | |||||
3789 | // later/now would queue up some that could be later deleted. | |||||
3790 | for (const Function &F : *M) | |||||
3791 | for (const BasicBlock &BB : F) | |||||
3792 | for (const Instruction &I : BB) | |||||
3793 | if (auto *DII = dyn_cast<DbgInfoIntrinsic>(&I)) | |||||
3794 | verifyBitPieceExpression(*DII, TypeRefs); | |||||
3795 | ||||||
3796 | // Return early if all typerefs were resolved. | |||||
3797 | if (UnresolvedTypeRefs.empty()) | |||||
3798 | return; | |||||
3799 | ||||||
3800 | // Sort the unresolved references by name so the output is deterministic. | |||||
3801 | typedef std::pair<const MDString *, const MDNode *> TypeRef; | |||||
3802 | SmallVector<TypeRef, 32> Unresolved(UnresolvedTypeRefs.begin(), | |||||
3803 | UnresolvedTypeRefs.end()); | |||||
3804 | std::sort(Unresolved.begin(), Unresolved.end(), | |||||
3805 | [](const TypeRef &LHS, const TypeRef &RHS) { | |||||
3806 | return LHS.first->getString() < RHS.first->getString(); | |||||
3807 | }); | |||||
3808 | ||||||
3809 | // Visit the unresolved refs (printing out the errors). | |||||
3810 | for (const TypeRef &TR : Unresolved) | |||||
3811 | visitUnresolvedTypeRef(TR.first, TR.second); | |||||
3812 | } | |||||
3813 | ||||||
3814 | //===----------------------------------------------------------------------===// | |||||
3815 | // Implement the public interfaces to this file... | |||||
3816 | //===----------------------------------------------------------------------===// | |||||
3817 | ||||||
3818 | bool llvm::verifyFunction(const Function &f, raw_ostream *OS) { | |||||
3819 | Function &F = const_cast<Function &>(f); | |||||
3820 | assert(!F.isDeclaration() && "Cannot verify external functions")((!F.isDeclaration() && "Cannot verify external functions" ) ? static_cast<void> (0) : __assert_fail ("!F.isDeclaration() && \"Cannot verify external functions\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn246288/lib/IR/Verifier.cpp" , 3820, __PRETTY_FUNCTION__)); | |||||
3821 | ||||||
3822 | raw_null_ostream NullStr; | |||||
3823 | Verifier V(OS ? *OS : NullStr); | |||||
3824 | ||||||
3825 | // Note that this function's return value is inverted from what you would | |||||
3826 | // expect of a function called "verify". | |||||
3827 | return !V.verify(F); | |||||
3828 | } | |||||
3829 | ||||||
3830 | bool llvm::verifyModule(const Module &M, raw_ostream *OS) { | |||||
3831 | raw_null_ostream NullStr; | |||||
3832 | Verifier V(OS ? *OS : NullStr); | |||||
3833 | ||||||
3834 | bool Broken = false; | |||||
3835 | for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) | |||||
3836 | if (!I->isDeclaration() && !I->isMaterializable()) | |||||
3837 | Broken |= !V.verify(*I); | |||||
3838 | ||||||
3839 | // Note that this function's return value is inverted from what you would | |||||
3840 | // expect of a function called "verify". | |||||
3841 | return !V.verify(M) || Broken; | |||||
3842 | } | |||||
3843 | ||||||
3844 | namespace { | |||||
3845 | struct VerifierLegacyPass : public FunctionPass { | |||||
3846 | static char ID; | |||||
3847 | ||||||
3848 | Verifier V; | |||||
3849 | bool FatalErrors; | |||||
3850 | ||||||
3851 | VerifierLegacyPass() : FunctionPass(ID), V(dbgs()), FatalErrors(true) { | |||||
3852 | initializeVerifierLegacyPassPass(*PassRegistry::getPassRegistry()); | |||||
3853 | } | |||||
3854 | explicit VerifierLegacyPass(bool FatalErrors) | |||||
3855 | : FunctionPass(ID), V(dbgs()), FatalErrors(FatalErrors) { | |||||
3856 | initializeVerifierLegacyPassPass(*PassRegistry::getPassRegistry()); | |||||
3857 | } | |||||
3858 | ||||||
3859 | bool runOnFunction(Function &F) override { | |||||
3860 | if (!V.verify(F) && FatalErrors) | |||||
3861 | report_fatal_error("Broken function found, compilation aborted!"); | |||||
3862 | ||||||
3863 | return false; | |||||
3864 | } | |||||
3865 | ||||||
3866 | bool doFinalization(Module &M) override { | |||||
3867 | if (!V.verify(M) && FatalErrors) | |||||
3868 | report_fatal_error("Broken module found, compilation aborted!"); | |||||
3869 | ||||||
3870 | return false; | |||||
3871 | } | |||||
3872 | ||||||
3873 | void getAnalysisUsage(AnalysisUsage &AU) const override { | |||||
3874 | AU.setPreservesAll(); | |||||
3875 | } | |||||
3876 | }; | |||||
3877 | } | |||||
3878 | ||||||
3879 | char VerifierLegacyPass::ID = 0; | |||||
3880 | 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; } void llvm::initializeVerifierLegacyPassPass (PassRegistry &Registry) { static volatile sys::cas_flag initialized = 0; sys::cas_flag old_val = sys::CompareAndSwap(&initialized , 1, 0); if (old_val == 0) { initializeVerifierLegacyPassPassOnce (Registry); sys::MemoryFence(); ; ; initialized = 2; ; } else { sys::cas_flag tmp = initialized; sys::MemoryFence(); while (tmp != 2) { tmp = initialized; sys::MemoryFence(); } } ; } | |||||
3881 | ||||||
3882 | FunctionPass *llvm::createVerifierPass(bool FatalErrors) { | |||||
3883 | return new VerifierLegacyPass(FatalErrors); | |||||
3884 | } | |||||
3885 | ||||||
3886 | PreservedAnalyses VerifierPass::run(Module &M) { | |||||
3887 | if (verifyModule(M, &dbgs()) && FatalErrors) | |||||
3888 | report_fatal_error("Broken module found, compilation aborted!"); | |||||
3889 | ||||||
3890 | return PreservedAnalyses::all(); | |||||
3891 | } | |||||
3892 | ||||||
3893 | PreservedAnalyses VerifierPass::run(Function &F) { | |||||
3894 | if (verifyFunction(F, &dbgs()) && FatalErrors) | |||||
3895 | report_fatal_error("Broken function found, compilation aborted!"); | |||||
3896 | ||||||
3897 | return PreservedAnalyses::all(); | |||||
3898 | } |