Bug Summary

File:lib/IR/Verifier.cpp
Location:line 1883, column 7
Description:Called C++ object pointer is null

Annotated Source Code

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// * Landingpad instructions must be in a function with a personality function.
43// * All other things that are tested by asserts spread about the code...
44//
45//===----------------------------------------------------------------------===//
46
47#include "llvm/IR/Verifier.h"
48#include "llvm/ADT/STLExtras.h"
49#include "llvm/ADT/SetVector.h"
50#include "llvm/ADT/SmallPtrSet.h"
51#include "llvm/ADT/SmallVector.h"
52#include "llvm/ADT/StringExtras.h"
53#include "llvm/IR/CFG.h"
54#include "llvm/IR/CallSite.h"
55#include "llvm/IR/CallingConv.h"
56#include "llvm/IR/ConstantRange.h"
57#include "llvm/IR/Constants.h"
58#include "llvm/IR/DataLayout.h"
59#include "llvm/IR/DebugInfo.h"
60#include "llvm/IR/DerivedTypes.h"
61#include "llvm/IR/Dominators.h"
62#include "llvm/IR/InlineAsm.h"
63#include "llvm/IR/InstIterator.h"
64#include "llvm/IR/InstVisitor.h"
65#include "llvm/IR/IntrinsicInst.h"
66#include "llvm/IR/LLVMContext.h"
67#include "llvm/IR/Metadata.h"
68#include "llvm/IR/Module.h"
69#include "llvm/IR/PassManager.h"
70#include "llvm/IR/Statepoint.h"
71#include "llvm/Pass.h"
72#include "llvm/Support/CommandLine.h"
73#include "llvm/Support/Debug.h"
74#include "llvm/Support/ErrorHandling.h"
75#include "llvm/Support/raw_ostream.h"
76#include <algorithm>
77#include <cstdarg>
78using namespace llvm;
79
80static cl::opt<bool> VerifyDebugInfo("verify-debug-info", cl::init(true));
81
82namespace {
83struct VerifierSupport {
84 raw_ostream &OS;
85 const Module *M;
86
87 /// \brief Track the brokenness of the module while recursively visiting.
88 bool Broken;
89
90 explicit VerifierSupport(raw_ostream &OS)
91 : OS(OS), M(nullptr), Broken(false) {}
92
93private:
94 template <class NodeTy> void Write(const ilist_iterator<NodeTy> &I) {
95 Write(&*I);
96 }
97
98 void Write(const Module *M) {
99 if (!M)
100 return;
101 OS << "; ModuleID = '" << M->getModuleIdentifier() << "'\n";
102 }
103
104 void Write(const Value *V) {
105 if (!V)
106 return;
107 if (isa<Instruction>(V)) {
108 OS << *V << '\n';
109 } else {
110 V->printAsOperand(OS, true, M);
111 OS << '\n';
112 }
113 }
114 void Write(ImmutableCallSite CS) {
115 Write(CS.getInstruction());
116 }
117
118 void Write(const Metadata *MD) {
119 if (!MD)
120 return;
121 MD->print(OS, M);
122 OS << '\n';
123 }
124
125 template <class T> void Write(const MDTupleTypedArrayWrapper<T> &MD) {
126 Write(MD.get());
127 }
128
129 void Write(const NamedMDNode *NMD) {
130 if (!NMD)
131 return;
132 NMD->print(OS);
133 OS << '\n';
134 }
135
136 void Write(Type *T) {
137 if (!T)
138 return;
139 OS << ' ' << *T;
140 }
141
142 void Write(const Comdat *C) {
143 if (!C)
144 return;
145 OS << *C;
146 }
147
148 template <typename T1, typename... Ts>
149 void WriteTs(const T1 &V1, const Ts &... Vs) {
150 Write(V1);
151 WriteTs(Vs...);
152 }
153
154 template <typename... Ts> void WriteTs() {}
155
156public:
157 /// \brief A check failed, so printout out the condition and the message.
158 ///
159 /// This provides a nice place to put a breakpoint if you want to see why
160 /// something is not correct.
161 void CheckFailed(const Twine &Message) {
162 OS << Message << '\n';
163 Broken = true;
164 }
165
166 /// \brief A check failed (with values to print).
167 ///
168 /// This calls the Message-only version so that the above is easier to set a
169 /// breakpoint on.
170 template <typename T1, typename... Ts>
171 void CheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs) {
172 CheckFailed(Message);
173 WriteTs(V1, Vs...);
174 }
175};
176
177class Verifier : public InstVisitor<Verifier>, VerifierSupport {
178 friend class InstVisitor<Verifier>;
179
180 LLVMContext *Context;
181 DominatorTree DT;
182
183 /// \brief When verifying a basic block, keep track of all of the
184 /// instructions we have seen so far.
185 ///
186 /// This allows us to do efficient dominance checks for the case when an
187 /// instruction has an operand that is an instruction in the same block.
188 SmallPtrSet<Instruction *, 16> InstsInThisBlock;
189
190 /// \brief Keep track of the metadata nodes that have been checked already.
191 SmallPtrSet<const Metadata *, 32> MDNodes;
192
193 /// \brief Track unresolved string-based type references.
194 SmallDenseMap<const MDString *, const MDNode *, 32> UnresolvedTypeRefs;
195
196 /// \brief The result type for a landingpad.
197 Type *LandingPadResultTy;
198
199 /// \brief Whether we've seen a call to @llvm.localescape in this function
200 /// already.
201 bool SawFrameEscape;
202
203 /// Stores the count of how many objects were passed to llvm.localescape for a
204 /// given function and the largest index passed to llvm.localrecover.
205 DenseMap<Function *, std::pair<unsigned, unsigned>> FrameEscapeInfo;
206
207 /// Cache of constants visited in search of ConstantExprs.
208 SmallPtrSet<const Constant *, 32> ConstantExprVisited;
209
210 void checkAtomicMemAccessSize(const Module *M, Type *Ty,
211 const Instruction *I);
212public:
213 explicit Verifier(raw_ostream &OS)
214 : VerifierSupport(OS), Context(nullptr), LandingPadResultTy(nullptr),
215 SawFrameEscape(false) {}
216
217 bool verify(const Function &F) {
218 M = F.getParent();
219 Context = &M->getContext();
220
221 // First ensure the function is well-enough formed to compute dominance
222 // information.
223 if (F.empty()) {
224 OS << "Function '" << F.getName()
225 << "' does not contain an entry block!\n";
226 return false;
227 }
228 for (Function::const_iterator I = F.begin(), E = F.end(); I != E; ++I) {
229 if (I->empty() || !I->back().isTerminator()) {
230 OS << "Basic Block in function '" << F.getName()
231 << "' does not have terminator!\n";
232 I->printAsOperand(OS, true);
233 OS << "\n";
234 return false;
235 }
236 }
237
238 // Now directly compute a dominance tree. We don't rely on the pass
239 // manager to provide this as it isolates us from a potentially
240 // out-of-date dominator tree and makes it significantly more complex to
241 // run this code outside of a pass manager.
242 // FIXME: It's really gross that we have to cast away constness here.
243 DT.recalculate(const_cast<Function &>(F));
244
245 Broken = false;
246 // FIXME: We strip const here because the inst visitor strips const.
247 visit(const_cast<Function &>(F));
248 InstsInThisBlock.clear();
249 LandingPadResultTy = nullptr;
250 SawFrameEscape = false;
251
252 return !Broken;
253 }
254
255 bool verify(const Module &M) {
256 this->M = &M;
257 Context = &M.getContext();
258 Broken = false;
259
260 // Scan through, checking all of the external function's linkage now...
261 for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) {
262 visitGlobalValue(*I);
263
264 // Check to make sure function prototypes are okay.
265 if (I->isDeclaration())
266 visitFunction(*I);
267 }
268
269 // Now that we've visited every function, verify that we never asked to
270 // recover a frame index that wasn't escaped.
271 verifyFrameRecoverIndices();
272
273 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
274 I != E; ++I)
275 visitGlobalVariable(*I);
276
277 for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
278 I != E; ++I)
279 visitGlobalAlias(*I);
280
281 for (Module::const_named_metadata_iterator I = M.named_metadata_begin(),
282 E = M.named_metadata_end();
283 I != E; ++I)
284 visitNamedMDNode(*I);
285
286 for (const StringMapEntry<Comdat> &SMEC : M.getComdatSymbolTable())
287 visitComdat(SMEC.getValue());
288
289 visitModuleFlags(M);
290 visitModuleIdents(M);
291
292 // Verify type referneces last.
293 verifyTypeRefs();
294
295 return !Broken;
296 }
297
298private:
299 // Verification methods...
300 void visitGlobalValue(const GlobalValue &GV);
301 void visitGlobalVariable(const GlobalVariable &GV);
302 void visitGlobalAlias(const GlobalAlias &GA);
303 void visitAliaseeSubExpr(const GlobalAlias &A, const Constant &C);
304 void visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias *> &Visited,
305 const GlobalAlias &A, const Constant &C);
306 void visitNamedMDNode(const NamedMDNode &NMD);
307 void visitMDNode(const MDNode &MD);
308 void visitMetadataAsValue(const MetadataAsValue &MD, Function *F);
309 void visitValueAsMetadata(const ValueAsMetadata &MD, Function *F);
310 void visitComdat(const Comdat &C);
311 void visitModuleIdents(const Module &M);
312 void visitModuleFlags(const Module &M);
313 void visitModuleFlag(const MDNode *Op,
314 DenseMap<const MDString *, const MDNode *> &SeenIDs,
315 SmallVectorImpl<const MDNode *> &Requirements);
316 void visitFunction(const Function &F);
317 void visitBasicBlock(BasicBlock &BB);
318 void visitRangeMetadata(Instruction& I, MDNode* Range, Type* Ty);
319 void visitDereferenceableMetadata(Instruction& I, MDNode* MD);
320
321 template <class Ty> bool isValidMetadataArray(const MDTuple &N);
322#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N);
323#include "llvm/IR/Metadata.def"
324 void visitDIScope(const DIScope &N);
325 void visitDIVariable(const DIVariable &N);
326 void visitDILexicalBlockBase(const DILexicalBlockBase &N);
327 void visitDITemplateParameter(const DITemplateParameter &N);
328
329 void visitTemplateParams(const MDNode &N, const Metadata &RawParams);
330
331 /// \brief Check for a valid string-based type reference.
332 ///
333 /// Checks if \c MD is a string-based type reference. If it is, keeps track
334 /// of it (and its user, \c N) for error messages later.
335 bool isValidUUID(const MDNode &N, const Metadata *MD);
336
337 /// \brief Check for a valid type reference.
338 ///
339 /// Checks for subclasses of \a DIType, or \a isValidUUID().
340 bool isTypeRef(const MDNode &N, const Metadata *MD);
341
342 /// \brief Check for a valid scope reference.
343 ///
344 /// Checks for subclasses of \a DIScope, or \a isValidUUID().
345 bool isScopeRef(const MDNode &N, const Metadata *MD);
346
347 /// \brief Check for a valid debug info reference.
348 ///
349 /// Checks for subclasses of \a DINode, or \a isValidUUID().
350 bool isDIRef(const MDNode &N, const Metadata *MD);
351
352 // InstVisitor overrides...
353 using InstVisitor<Verifier>::visit;
354 void visit(Instruction &I);
355
356 void visitTruncInst(TruncInst &I);
357 void visitZExtInst(ZExtInst &I);
358 void visitSExtInst(SExtInst &I);
359 void visitFPTruncInst(FPTruncInst &I);
360 void visitFPExtInst(FPExtInst &I);
361 void visitFPToUIInst(FPToUIInst &I);
362 void visitFPToSIInst(FPToSIInst &I);
363 void visitUIToFPInst(UIToFPInst &I);
364 void visitSIToFPInst(SIToFPInst &I);
365 void visitIntToPtrInst(IntToPtrInst &I);
366 void visitPtrToIntInst(PtrToIntInst &I);
367 void visitBitCastInst(BitCastInst &I);
368 void visitAddrSpaceCastInst(AddrSpaceCastInst &I);
369 void visitPHINode(PHINode &PN);
370 void visitBinaryOperator(BinaryOperator &B);
371 void visitICmpInst(ICmpInst &IC);
372 void visitFCmpInst(FCmpInst &FC);
373 void visitExtractElementInst(ExtractElementInst &EI);
374 void visitInsertElementInst(InsertElementInst &EI);
375 void visitShuffleVectorInst(ShuffleVectorInst &EI);
376 void visitVAArgInst(VAArgInst &VAA) { visitInstruction(VAA); }
377 void visitCallInst(CallInst &CI);
378 void visitInvokeInst(InvokeInst &II);
379 void visitGetElementPtrInst(GetElementPtrInst &GEP);
380 void visitLoadInst(LoadInst &LI);
381 void visitStoreInst(StoreInst &SI);
382 void verifyDominatesUse(Instruction &I, unsigned i);
383 void visitInstruction(Instruction &I);
384 void visitTerminatorInst(TerminatorInst &I);
385 void visitBranchInst(BranchInst &BI);
386 void visitReturnInst(ReturnInst &RI);
387 void visitSwitchInst(SwitchInst &SI);
388 void visitIndirectBrInst(IndirectBrInst &BI);
389 void visitSelectInst(SelectInst &SI);
390 void visitUserOp1(Instruction &I);
391 void visitUserOp2(Instruction &I) { visitUserOp1(I); }
392 void visitIntrinsicCallSite(Intrinsic::ID ID, CallSite CS);
393 template <class DbgIntrinsicTy>
394 void visitDbgIntrinsic(StringRef Kind, DbgIntrinsicTy &DII);
395 void visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI);
396 void visitAtomicRMWInst(AtomicRMWInst &RMWI);
397 void visitFenceInst(FenceInst &FI);
398 void visitAllocaInst(AllocaInst &AI);
399 void visitExtractValueInst(ExtractValueInst &EVI);
400 void visitInsertValueInst(InsertValueInst &IVI);
401 void visitEHPadPredecessors(Instruction &I);
402 void visitLandingPadInst(LandingPadInst &LPI);
403 void visitCatchPadInst(CatchPadInst &CPI);
404 void visitCatchReturnInst(CatchReturnInst &CatchReturn);
405 void visitCleanupPadInst(CleanupPadInst &CPI);
406 void visitCatchSwitchInst(CatchSwitchInst &CatchSwitch);
407 void visitCleanupReturnInst(CleanupReturnInst &CRI);
408
409 void VerifyCallSite(CallSite CS);
410 void verifyMustTailCall(CallInst &CI);
411 bool PerformTypeCheck(Intrinsic::ID ID, Function *F, Type *Ty, int VT,
412 unsigned ArgNo, std::string &Suffix);
413 bool VerifyIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
414 SmallVectorImpl<Type *> &ArgTys);
415 bool VerifyIntrinsicIsVarArg(bool isVarArg,
416 ArrayRef<Intrinsic::IITDescriptor> &Infos);
417 bool VerifyAttributeCount(AttributeSet Attrs, unsigned Params);
418 void VerifyAttributeTypes(AttributeSet Attrs, unsigned Idx, bool isFunction,
419 const Value *V);
420 void VerifyParameterAttrs(AttributeSet Attrs, unsigned Idx, Type *Ty,
421 bool isReturnValue, const Value *V);
422 void VerifyFunctionAttrs(FunctionType *FT, AttributeSet Attrs,
423 const Value *V);
424 void VerifyFunctionMetadata(
425 const SmallVector<std::pair<unsigned, MDNode *>, 4> MDs);
426
427 void visitConstantExprsRecursively(const Constant *EntryC);
428 void visitConstantExpr(const ConstantExpr *CE);
429 void VerifyStatepoint(ImmutableCallSite CS);
430 void verifyFrameRecoverIndices();
431
432 // Module-level debug info verification...
433 void verifyTypeRefs();
434 template <class MapTy>
435 void verifyBitPieceExpression(const DbgInfoIntrinsic &I,
436 const MapTy &TypeRefs);
437 void visitUnresolvedTypeRef(const MDString *S, const MDNode *N);
438};
439} // End anonymous namespace
440
441// Assert - We know that cond should be true, if not print an error message.
442#define Assert(C, ...)do { if (!(C)) { CheckFailed(...); return; } } while (0) \
443 do { if (!(C)) { CheckFailed(__VA_ARGS__); return; } } while (0)
444
445void Verifier::visit(Instruction &I) {
446 for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i)
447 Assert(I.getOperand(i) != nullptr, "Operand is null", &I)do { if (!(I.getOperand(i) != nullptr)) { CheckFailed("Operand is null"
, &I); return; } } while (0)
;
448 InstVisitor<Verifier>::visit(I);
449}
450
451
452void Verifier::visitGlobalValue(const GlobalValue &GV) {
453 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)
454 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)
455 "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)
;
456
457 Assert(GV.getAlignment() <= Value::MaximumAlignment,do { if (!(GV.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &GV
); return; } } while (0)
458 "huge alignment values are unsupported", &GV)do { if (!(GV.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &GV
); return; } } while (0)
;
459 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)
460 "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)
;
461
462 if (GV.hasAppendingLinkage()) {
463 const GlobalVariable *GVar = dyn_cast<GlobalVariable>(&GV);
464 Assert(GVar && GVar->getValueType()->isArrayTy(),do { if (!(GVar && GVar->getValueType()->isArrayTy
())) { CheckFailed("Only global arrays can have appending linkage!"
, GVar); return; } } while (0)
465 "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)
;
466 }
467
468 if (GV.isDeclarationForLinker())
469 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)
;
470}
471
472void Verifier::visitGlobalVariable(const GlobalVariable &GV) {
473 if (GV.hasInitializer()) {
474 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)
475 "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)
476 "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)
477 &GV)do { if (!(GV.getInitializer()->getType() == GV.getType()->
getElementType())) { CheckFailed("Global variable initializer type does not match global "
"variable type!", &GV); return; } } while (0)
;
478
479 // If the global has common linkage, it must have a zero initializer and
480 // cannot be constant.
481 if (GV.hasCommonLinkage()) {
482 Assert(GV.getInitializer()->isNullValue(),do { if (!(GV.getInitializer()->isNullValue())) { CheckFailed
("'common' global must have a zero initializer!", &GV); return
; } } while (0)
483 "'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)
;
484 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)
485 &GV)do { if (!(!GV.isConstant())) { CheckFailed("'common' global may not be marked constant!"
, &GV); return; } } while (0)
;
486 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)
;
487 }
488 } else {
489 Assert(GV.hasExternalLinkage() || GV.hasExternalWeakLinkage(),do { if (!(GV.hasExternalLinkage() || GV.hasExternalWeakLinkage
())) { CheckFailed("invalid linkage type for global declaration"
, &GV); return; } } while (0)
490 "invalid linkage type for global declaration", &GV)do { if (!(GV.hasExternalLinkage() || GV.hasExternalWeakLinkage
())) { CheckFailed("invalid linkage type for global declaration"
, &GV); return; } } while (0)
;
491 }
492
493 if (GV.hasName() && (GV.getName() == "llvm.global_ctors" ||
494 GV.getName() == "llvm.global_dtors")) {
495 Assert(!GV.hasInitializer() || GV.hasAppendingLinkage(),do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage()))
{ CheckFailed("invalid linkage for intrinsic global variable"
, &GV); return; } } while (0)
496 "invalid linkage for intrinsic global variable", &GV)do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage()))
{ CheckFailed("invalid linkage for intrinsic global variable"
, &GV); return; } } while (0)
;
497 // Don't worry about emitting an error for it not being an array,
498 // visitGlobalValue will complain on appending non-array.
499 if (ArrayType *ATy = dyn_cast<ArrayType>(GV.getValueType())) {
500 StructType *STy = dyn_cast<StructType>(ATy->getElementType());
501 PointerType *FuncPtrTy =
502 FunctionType::get(Type::getVoidTy(*Context), false)->getPointerTo();
503 // FIXME: Reject the 2-field form in LLVM 4.0.
504 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)
505 (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)
506 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)
507 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)
508 "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)
;
509 if (STy->getNumElements() == 3) {
510 Type *ETy = STy->getTypeAtIndex(2);
511 Assert(ETy->isPointerTy() &&do { if (!(ETy->isPointerTy() && cast<PointerType
>(ETy)->getElementType()->isIntegerTy(8))) { CheckFailed
("wrong type for intrinsic global variable", &GV); return
; } } while (0)
512 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)
513 "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)
;
514 }
515 }
516 }
517
518 if (GV.hasName() && (GV.getName() == "llvm.used" ||
519 GV.getName() == "llvm.compiler.used")) {
520 Assert(!GV.hasInitializer() || GV.hasAppendingLinkage(),do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage()))
{ CheckFailed("invalid linkage for intrinsic global variable"
, &GV); return; } } while (0)
521 "invalid linkage for intrinsic global variable", &GV)do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage()))
{ CheckFailed("invalid linkage for intrinsic global variable"
, &GV); return; } } while (0)
;
522 Type *GVType = GV.getValueType();
523 if (ArrayType *ATy = dyn_cast<ArrayType>(GVType)) {
524 PointerType *PTy = dyn_cast<PointerType>(ATy->getElementType());
525 Assert(PTy, "wrong type for intrinsic global variable", &GV)do { if (!(PTy)) { CheckFailed("wrong type for intrinsic global variable"
, &GV); return; } } while (0)
;
526 if (GV.hasInitializer()) {
527 const Constant *Init = GV.getInitializer();
528 const ConstantArray *InitArray = dyn_cast<ConstantArray>(Init);
529 Assert(InitArray, "wrong initalizer for intrinsic global variable",do { if (!(InitArray)) { CheckFailed("wrong initalizer for intrinsic global variable"
, Init); return; } } while (0)
530 Init)do { if (!(InitArray)) { CheckFailed("wrong initalizer for intrinsic global variable"
, Init); return; } } while (0)
;
531 for (unsigned i = 0, e = InitArray->getNumOperands(); i != e; ++i) {
532 Value *V = Init->getOperand(i)->stripPointerCastsNoFollowAliases();
533 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)
534 isa<GlobalAlias>(V),do { if (!(isa<GlobalVariable>(V) || isa<Function>
(V) || isa<GlobalAlias>(V))) { CheckFailed("invalid llvm.used member"
, V); return; } } while (0)
535 "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)
;
536 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)
;
537 }
538 }
539 }
540 }
541
542 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)
543 (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)
544 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)
545 "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)
;
546
547 if (!GV.hasInitializer()) {
548 visitGlobalValue(GV);
549 return;
550 }
551
552 // Walk any aggregate initializers looking for bitcasts between address spaces
553 visitConstantExprsRecursively(GV.getInitializer());
554
555 visitGlobalValue(GV);
556}
557
558void Verifier::visitAliaseeSubExpr(const GlobalAlias &GA, const Constant &C) {
559 SmallPtrSet<const GlobalAlias*, 4> Visited;
560 Visited.insert(&GA);
561 visitAliaseeSubExpr(Visited, GA, C);
562}
563
564void Verifier::visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias*> &Visited,
565 const GlobalAlias &GA, const Constant &C) {
566 if (const auto *GV = dyn_cast<GlobalValue>(&C)) {
567 Assert(!GV->isDeclarationForLinker(), "Alias must point to a definition",do { if (!(!GV->isDeclarationForLinker())) { CheckFailed("Alias must point to a definition"
, &GA); return; } } while (0)
568 &GA)do { if (!(!GV->isDeclarationForLinker())) { CheckFailed("Alias must point to a definition"
, &GA); return; } } while (0)
;
569
570 if (const auto *GA2 = dyn_cast<GlobalAlias>(GV)) {
571 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)
;
572
573 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)
574 &GA)do { if (!(!GA2->mayBeOverridden())) { CheckFailed("Alias cannot point to a weak alias"
, &GA); return; } } while (0)
;
575 } else {
576 // Only continue verifying subexpressions of GlobalAliases.
577 // Do not recurse into global initializers.
578 return;
579 }
580 }
581
582 if (const auto *CE = dyn_cast<ConstantExpr>(&C))
583 visitConstantExprsRecursively(CE);
584
585 for (const Use &U : C.operands()) {
586 Value *V = &*U;
587 if (const auto *GA2 = dyn_cast<GlobalAlias>(V))
588 visitAliaseeSubExpr(Visited, GA, *GA2->getAliasee());
589 else if (const auto *C2 = dyn_cast<Constant>(V))
590 visitAliaseeSubExpr(Visited, GA, *C2);
591 }
592}
593
594void Verifier::visitGlobalAlias(const GlobalAlias &GA) {
595 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)
596 "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)
597 "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)
598 &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)
;
599 const Constant *Aliasee = GA.getAliasee();
600 Assert(Aliasee, "Aliasee cannot be NULL!", &GA)do { if (!(Aliasee)) { CheckFailed("Aliasee cannot be NULL!",
&GA); return; } } while (0)
;
601 Assert(GA.getType() == Aliasee->getType(),do { if (!(GA.getType() == Aliasee->getType())) { CheckFailed
("Alias and aliasee types should match!", &GA); return; }
} while (0)
602 "Alias and aliasee types should match!", &GA)do { if (!(GA.getType() == Aliasee->getType())) { CheckFailed
("Alias and aliasee types should match!", &GA); return; }
} while (0)
;
603
604 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)
605 "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)
;
606
607 visitAliaseeSubExpr(GA, *Aliasee);
608
609 visitGlobalValue(GA);
610}
611
612void Verifier::visitNamedMDNode(const NamedMDNode &NMD) {
613 for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i) {
614 MDNode *MD = NMD.getOperand(i);
615
616 if (NMD.getName() == "llvm.dbg.cu") {
617 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)
;
618 }
619
620 if (!MD)
621 continue;
622
623 visitMDNode(*MD);
624 }
625}
626
627void Verifier::visitMDNode(const MDNode &MD) {
628 // Only visit each node once. Metadata can be mutually recursive, so this
629 // avoids infinite recursion here, as well as being an optimization.
630 if (!MDNodes.insert(&MD).second)
631 return;
632
633 switch (MD.getMetadataID()) {
634 default:
635 llvm_unreachable("Invalid MDNode subclass")::llvm::llvm_unreachable_internal("Invalid MDNode subclass", "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/lib/IR/Verifier.cpp"
, 635)
;
636 case Metadata::MDTupleKind:
637 break;
638#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
639 case Metadata::CLASS##Kind: \
640 visit##CLASS(cast<CLASS>(MD)); \
641 break;
642#include "llvm/IR/Metadata.def"
643 }
644
645 for (unsigned i = 0, e = MD.getNumOperands(); i != e; ++i) {
646 Metadata *Op = MD.getOperand(i);
647 if (!Op)
648 continue;
649 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)
650 &MD, Op)do { if (!(!isa<LocalAsMetadata>(Op))) { CheckFailed("Invalid operand for global metadata!"
, &MD, Op); return; } } while (0)
;
651 if (auto *N = dyn_cast<MDNode>(Op)) {
652 visitMDNode(*N);
653 continue;
654 }
655 if (auto *V = dyn_cast<ValueAsMetadata>(Op)) {
656 visitValueAsMetadata(*V, nullptr);
657 continue;
658 }
659 }
660
661 // Check these last, so we diagnose problems in operands first.
662 Assert(!MD.isTemporary(), "Expected no forward declarations!", &MD)do { if (!(!MD.isTemporary())) { CheckFailed("Expected no forward declarations!"
, &MD); return; } } while (0)
;
663 Assert(MD.isResolved(), "All nodes should be resolved!", &MD)do { if (!(MD.isResolved())) { CheckFailed("All nodes should be resolved!"
, &MD); return; } } while (0)
;
664}
665
666void Verifier::visitValueAsMetadata(const ValueAsMetadata &MD, Function *F) {
667 Assert(MD.getValue(), "Expected valid value", &MD)do { if (!(MD.getValue())) { CheckFailed("Expected valid value"
, &MD); return; } } while (0)
;
668 Assert(!MD.getValue()->getType()->isMetadataTy(),do { if (!(!MD.getValue()->getType()->isMetadataTy())) {
CheckFailed("Unexpected metadata round-trip through values",
&MD, MD.getValue()); return; } } while (0)
669 "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)
;
670
671 auto *L = dyn_cast<LocalAsMetadata>(&MD);
672 if (!L)
673 return;
674
675 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)
;
676
677 // If this was an instruction, bb, or argument, verify that it is in the
678 // function that we expect.
679 Function *ActualF = nullptr;
680 if (Instruction *I = dyn_cast<Instruction>(L->getValue())) {
681 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)
;
682 ActualF = I->getParent()->getParent();
683 } else if (BasicBlock *BB = dyn_cast<BasicBlock>(L->getValue()))
684 ActualF = BB->getParent();
685 else if (Argument *A = dyn_cast<Argument>(L->getValue()))
686 ActualF = A->getParent();
687 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~svn257205/lib/IR/Verifier.cpp"
, 687, __PRETTY_FUNCTION__))
;
688
689 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)
;
690}
691
692void Verifier::visitMetadataAsValue(const MetadataAsValue &MDV, Function *F) {
693 Metadata *MD = MDV.getMetadata();
694 if (auto *N = dyn_cast<MDNode>(MD)) {
695 visitMDNode(*N);
696 return;
697 }
698
699 // Only visit each node once. Metadata can be mutually recursive, so this
700 // avoids infinite recursion here, as well as being an optimization.
701 if (!MDNodes.insert(MD).second)
702 return;
703
704 if (auto *V = dyn_cast<ValueAsMetadata>(MD))
705 visitValueAsMetadata(*V, F);
706}
707
708bool Verifier::isValidUUID(const MDNode &N, const Metadata *MD) {
709 auto *S = dyn_cast<MDString>(MD);
710 if (!S)
711 return false;
712 if (S->getString().empty())
713 return false;
714
715 // Keep track of names of types referenced via UUID so we can check that they
716 // actually exist.
717 UnresolvedTypeRefs.insert(std::make_pair(S, &N));
718 return true;
719}
720
721/// \brief Check if a value can be a reference to a type.
722bool Verifier::isTypeRef(const MDNode &N, const Metadata *MD) {
723 return !MD || isValidUUID(N, MD) || isa<DIType>(MD);
724}
725
726/// \brief Check if a value can be a ScopeRef.
727bool Verifier::isScopeRef(const MDNode &N, const Metadata *MD) {
728 return !MD || isValidUUID(N, MD) || isa<DIScope>(MD);
729}
730
731/// \brief Check if a value can be a debug info ref.
732bool Verifier::isDIRef(const MDNode &N, const Metadata *MD) {
733 return !MD || isValidUUID(N, MD) || isa<DINode>(MD);
734}
735
736template <class Ty>
737bool isValidMetadataArrayImpl(const MDTuple &N, bool AllowNull) {
738 for (Metadata *MD : N.operands()) {
739 if (MD) {
740 if (!isa<Ty>(MD))
741 return false;
742 } else {
743 if (!AllowNull)
744 return false;
745 }
746 }
747 return true;
748}
749
750template <class Ty>
751bool isValidMetadataArray(const MDTuple &N) {
752 return isValidMetadataArrayImpl<Ty>(N, /* AllowNull */ false);
753}
754
755template <class Ty>
756bool isValidMetadataNullArray(const MDTuple &N) {
757 return isValidMetadataArrayImpl<Ty>(N, /* AllowNull */ true);
758}
759
760void Verifier::visitDILocation(const DILocation &N) {
761 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)
762 "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)
;
763 if (auto *IA = N.getRawInlinedAt())
764 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)
;
765}
766
767void Verifier::visitGenericDINode(const GenericDINode &N) {
768 Assert(N.getTag(), "invalid tag", &N)do { if (!(N.getTag())) { CheckFailed("invalid tag", &N);
return; } } while (0)
;
769}
770
771void Verifier::visitDIScope(const DIScope &N) {
772 if (auto *F = N.getRawFile())
773 Assert(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { CheckFailed("invalid file"
, &N, F); return; } } while (0)
;
774}
775
776void Verifier::visitDISubrange(const DISubrange &N) {
777 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)
;
778 Assert(N.getCount() >= -1, "invalid subrange count", &N)do { if (!(N.getCount() >= -1)) { CheckFailed("invalid subrange count"
, &N); return; } } while (0)
;
779}
780
781void Verifier::visitDIEnumerator(const DIEnumerator &N) {
782 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)
;
783}
784
785void Verifier::visitDIBasicType(const DIBasicType &N) {
786 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)
787 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)
788 "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)
;
789}
790
791void Verifier::visitDIDerivedType(const DIDerivedType &N) {
792 // Common scope checks.
793 visitDIScope(N);
794
795 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)
796 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)
797 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)
798 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)
799 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)
800 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)
801 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)
802 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)
803 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)
804 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)
805 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)
806 "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)
;
807 if (N.getTag() == dwarf::DW_TAG_ptr_to_member_type) {
808 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)
809 N.getExtraData())do { if (!(isTypeRef(N, N.getExtraData()))) { CheckFailed("invalid pointer to member type"
, &N, N.getExtraData()); return; } } while (0)
;
810 }
811
812 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)
;
813 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)
814 N.getBaseType())do { if (!(isTypeRef(N, N.getBaseType()))) { CheckFailed("invalid base type"
, &N, N.getBaseType()); return; } } while (0)
;
815}
816
817static bool hasConflictingReferenceFlags(unsigned Flags) {
818 return (Flags & DINode::FlagLValueReference) &&
819 (Flags & DINode::FlagRValueReference);
820}
821
822void Verifier::visitTemplateParams(const MDNode &N, const Metadata &RawParams) {
823 auto *Params = dyn_cast<MDTuple>(&RawParams);
824 Assert(Params, "invalid template params", &N, &RawParams)do { if (!(Params)) { CheckFailed("invalid template params", &
N, &RawParams); return; } } while (0)
;
825 for (Metadata *Op : Params->operands()) {
826 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)
827 Params, Op)do { if (!(Op && isa<DITemplateParameter>(Op)))
{ CheckFailed("invalid template parameter", &N, Params, Op
); return; } } while (0)
;
828 }
829}
830
831void Verifier::visitDICompositeType(const DICompositeType &N) {
832 // Common scope checks.
833 visitDIScope(N);
834
835 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)
836 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)
837 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)
838 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)
839 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)
840 "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)
;
841
842 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)
;
843 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)
844 N.getBaseType())do { if (!(isTypeRef(N, N.getBaseType()))) { CheckFailed("invalid base type"
, &N, N.getBaseType()); return; } } while (0)
;
845
846 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)
847 "invalid composite elements", &N, N.getRawElements())do { if (!(!N.getRawElements() || isa<MDTuple>(N.getRawElements
()))) { CheckFailed("invalid composite elements", &N, N.getRawElements
()); return; } } while (0)
;
848 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)
849 N.getRawVTableHolder())do { if (!(isTypeRef(N, N.getRawVTableHolder()))) { CheckFailed
("invalid vtable holder", &N, N.getRawVTableHolder()); return
; } } while (0)
;
850 Assert(!hasConflictingReferenceFlags(N.getFlags()), "invalid reference flags",do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { CheckFailed
("invalid reference flags", &N); return; } } while (0)
851 &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { CheckFailed
("invalid reference flags", &N); return; } } while (0)
;
852 if (auto *Params = N.getRawTemplateParams())
853 visitTemplateParams(N, *Params);
854
855 if (N.getTag() == dwarf::DW_TAG_class_type ||
856 N.getTag() == dwarf::DW_TAG_union_type) {
857 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)
858 "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)
;
859 }
860}
861
862void Verifier::visitDISubroutineType(const DISubroutineType &N) {
863 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)
;
864 if (auto *Types = N.getRawTypeArray()) {
865 Assert(isa<MDTuple>(Types), "invalid composite elements", &N, Types)do { if (!(isa<MDTuple>(Types))) { CheckFailed("invalid composite elements"
, &N, Types); return; } } while (0)
;
866 for (Metadata *Ty : N.getTypeArray()->operands()) {
867 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)
;
868 }
869 }
870 Assert(!hasConflictingReferenceFlags(N.getFlags()), "invalid reference flags",do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { CheckFailed
("invalid reference flags", &N); return; } } while (0)
871 &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { CheckFailed
("invalid reference flags", &N); return; } } while (0)
;
872}
873
874void Verifier::visitDIFile(const DIFile &N) {
875 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)
;
876}
877
878void Verifier::visitDICompileUnit(const DICompileUnit &N) {
879 Assert(N.isDistinct(), "compile units must be distinct", &N)do { if (!(N.isDistinct())) { CheckFailed("compile units must be distinct"
, &N); return; } } while (0)
;
880 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)
;
881
882 // Don't bother verifying the compilation directory or producer string
883 // as those could be empty.
884 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)
885 N.getRawFile())do { if (!(N.getRawFile() && isa<DIFile>(N.getRawFile
()))) { CheckFailed("invalid file", &N, N.getRawFile()); return
; } } while (0)
;
886 Assert(!N.getFile()->getFilename().empty(), "invalid filename", &N,do { if (!(!N.getFile()->getFilename().empty())) { CheckFailed
("invalid filename", &N, N.getFile()); return; } } while (
0)
887 N.getFile())do { if (!(!N.getFile()->getFilename().empty())) { CheckFailed
("invalid filename", &N, N.getFile()); return; } } while (
0)
;
888
889 if (auto *Array = N.getRawEnumTypes()) {
890 Assert(isa<MDTuple>(Array), "invalid enum list", &N, Array)do { if (!(isa<MDTuple>(Array))) { CheckFailed("invalid enum list"
, &N, Array); return; } } while (0)
;
891 for (Metadata *Op : N.getEnumTypes()->operands()) {
892 auto *Enum = dyn_cast_or_null<DICompositeType>(Op);
893 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)
894 "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)
;
895 }
896 }
897 if (auto *Array = N.getRawRetainedTypes()) {
898 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)
;
899 for (Metadata *Op : N.getRetainedTypes()->operands()) {
900 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)
;
901 }
902 }
903 if (auto *Array = N.getRawSubprograms()) {
904 Assert(isa<MDTuple>(Array), "invalid subprogram list", &N, Array)do { if (!(isa<MDTuple>(Array))) { CheckFailed("invalid subprogram list"
, &N, Array); return; } } while (0)
;
905 for (Metadata *Op : N.getSubprograms()->operands()) {
906 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)
;
907 }
908 }
909 if (auto *Array = N.getRawGlobalVariables()) {
910 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)
;
911 for (Metadata *Op : N.getGlobalVariables()->operands()) {
912 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)
913 Op)do { if (!(Op && isa<DIGlobalVariable>(Op))) { CheckFailed
("invalid global variable ref", &N, Op); return; } } while
(0)
;
914 }
915 }
916 if (auto *Array = N.getRawImportedEntities()) {
917 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)
;
918 for (Metadata *Op : N.getImportedEntities()->operands()) {
919 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)
920 Op)do { if (!(Op && isa<DIImportedEntity>(Op))) { CheckFailed
("invalid imported entity ref", &N, Op); return; } } while
(0)
;
921 }
922 }
923 if (auto *Array = N.getRawMacros()) {
924 Assert(isa<MDTuple>(Array), "invalid macro list", &N, Array)do { if (!(isa<MDTuple>(Array))) { CheckFailed("invalid macro list"
, &N, Array); return; } } while (0)
;
925 for (Metadata *Op : N.getMacros()->operands()) {
926 Assert(Op && isa<DIMacroNode>(Op), "invalid macro ref", &N, Op)do { if (!(Op && isa<DIMacroNode>(Op))) { CheckFailed
("invalid macro ref", &N, Op); return; } } while (0)
;
927 }
928 }
929}
930
931void Verifier::visitDISubprogram(const DISubprogram &N) {
932 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)
;
933 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)
;
934 if (auto *T = N.getRawType())
935 Assert(isa<DISubroutineType>(T), "invalid subroutine type", &N, T)do { if (!(isa<DISubroutineType>(T))) { CheckFailed("invalid subroutine type"
, &N, T); return; } } while (0)
;
936 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)
937 N.getRawContainingType())do { if (!(isTypeRef(N, N.getRawContainingType()))) { CheckFailed
("invalid containing type", &N, N.getRawContainingType())
; return; } } while (0)
;
938 if (auto *Params = N.getRawTemplateParams())
939 visitTemplateParams(N, *Params);
940 if (auto *S = N.getRawDeclaration()) {
941 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)
942 "invalid subprogram declaration", &N, S)do { if (!(isa<DISubprogram>(S) && !cast<DISubprogram
>(S)->isDefinition())) { CheckFailed("invalid subprogram declaration"
, &N, S); return; } } while (0)
;
943 }
944 if (auto *RawVars = N.getRawVariables()) {
945 auto *Vars = dyn_cast<MDTuple>(RawVars);
946 Assert(Vars, "invalid variable list", &N, RawVars)do { if (!(Vars)) { CheckFailed("invalid variable list", &
N, RawVars); return; } } while (0)
;
947 for (Metadata *Op : Vars->operands()) {
948 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)
949 Op)do { if (!(Op && isa<DILocalVariable>(Op))) { CheckFailed
("invalid local variable", &N, Vars, Op); return; } } while
(0)
;
950 }
951 }
952 Assert(!hasConflictingReferenceFlags(N.getFlags()), "invalid reference flags",do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { CheckFailed
("invalid reference flags", &N); return; } } while (0)
953 &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { CheckFailed
("invalid reference flags", &N); return; } } while (0)
;
954
955 if (N.isDefinition())
956 Assert(N.isDistinct(), "subprogram definitions must be distinct", &N)do { if (!(N.isDistinct())) { CheckFailed("subprogram definitions must be distinct"
, &N); return; } } while (0)
;
957}
958
959void Verifier::visitDILexicalBlockBase(const DILexicalBlockBase &N) {
960 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)
;
961 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)
962 "invalid local scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { CheckFailed("invalid local scope", &
N, N.getRawScope()); return; } } while (0)
;
963}
964
965void Verifier::visitDILexicalBlock(const DILexicalBlock &N) {
966 visitDILexicalBlockBase(N);
967
968 Assert(N.getLine() || !N.getColumn(),do { if (!(N.getLine() || !N.getColumn())) { CheckFailed("cannot have column info without line info"
, &N); return; } } while (0)
969 "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)
;
970}
971
972void Verifier::visitDILexicalBlockFile(const DILexicalBlockFile &N) {
973 visitDILexicalBlockBase(N);
974}
975
976void Verifier::visitDINamespace(const DINamespace &N) {
977 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)
;
978 if (auto *S = N.getRawScope())
979 Assert(isa<DIScope>(S), "invalid scope ref", &N, S)do { if (!(isa<DIScope>(S))) { CheckFailed("invalid scope ref"
, &N, S); return; } } while (0)
;
980}
981
982void Verifier::visitDIMacro(const DIMacro &N) {
983 Assert(N.getMacinfoType() == dwarf::DW_MACINFO_define ||do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_define || N
.getMacinfoType() == dwarf::DW_MACINFO_undef)) { CheckFailed(
"invalid macinfo type", &N); return; } } while (0)
984 N.getMacinfoType() == dwarf::DW_MACINFO_undef,do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_define || N
.getMacinfoType() == dwarf::DW_MACINFO_undef)) { CheckFailed(
"invalid macinfo type", &N); return; } } while (0)
985 "invalid macinfo type", &N)do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_define || N
.getMacinfoType() == dwarf::DW_MACINFO_undef)) { CheckFailed(
"invalid macinfo type", &N); return; } } while (0)
;
986 Assert(!N.getName().empty(), "anonymous macro", &N)do { if (!(!N.getName().empty())) { CheckFailed("anonymous macro"
, &N); return; } } while (0)
;
987 if (!N.getValue().empty()) {
988 assert(N.getValue().data()[0] != ' ' && "Macro value has a space prefix")((N.getValue().data()[0] != ' ' && "Macro value has a space prefix"
) ? static_cast<void> (0) : __assert_fail ("N.getValue().data()[0] != ' ' && \"Macro value has a space prefix\""
, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/lib/IR/Verifier.cpp"
, 988, __PRETTY_FUNCTION__))
;
989 }
990}
991
992void Verifier::visitDIMacroFile(const DIMacroFile &N) {
993 Assert(N.getMacinfoType() == dwarf::DW_MACINFO_start_file,do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_start_file
)) { CheckFailed("invalid macinfo type", &N); return; } }
while (0)
994 "invalid macinfo type", &N)do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_start_file
)) { CheckFailed("invalid macinfo type", &N); return; } }
while (0)
;
995 if (auto *F = N.getRawFile())
996 Assert(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { CheckFailed("invalid file"
, &N, F); return; } } while (0)
;
997
998 if (auto *Array = N.getRawElements()) {
999 Assert(isa<MDTuple>(Array), "invalid macro list", &N, Array)do { if (!(isa<MDTuple>(Array))) { CheckFailed("invalid macro list"
, &N, Array); return; } } while (0)
;
1000 for (Metadata *Op : N.getElements()->operands()) {
1001 Assert(Op && isa<DIMacroNode>(Op), "invalid macro ref", &N, Op)do { if (!(Op && isa<DIMacroNode>(Op))) { CheckFailed
("invalid macro ref", &N, Op); return; } } while (0)
;
1002 }
1003 }
1004}
1005
1006void Verifier::visitDIModule(const DIModule &N) {
1007 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)
;
1008 Assert(!N.getName().empty(), "anonymous module", &N)do { if (!(!N.getName().empty())) { CheckFailed("anonymous module"
, &N); return; } } while (0)
;
1009}
1010
1011void Verifier::visitDITemplateParameter(const DITemplateParameter &N) {
1012 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)
;
1013}
1014
1015void Verifier::visitDITemplateTypeParameter(const DITemplateTypeParameter &N) {
1016 visitDITemplateParameter(N);
1017
1018 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
)
1019 &N)do { if (!(N.getTag() == dwarf::DW_TAG_template_type_parameter
)) { CheckFailed("invalid tag", &N); return; } } while (0
)
;
1020}
1021
1022void Verifier::visitDITemplateValueParameter(
1023 const DITemplateValueParameter &N) {
1024 visitDITemplateParameter(N);
1025
1026 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)
1027 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)
1028 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)
1029 "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)
;
1030}
1031
1032void Verifier::visitDIVariable(const DIVariable &N) {
1033 if (auto *S = N.getRawScope())
1034 Assert(isa<DIScope>(S), "invalid scope", &N, S)do { if (!(isa<DIScope>(S))) { CheckFailed("invalid scope"
, &N, S); return; } } while (0)
;
1035 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)
;
1036 if (auto *F = N.getRawFile())
1037 Assert(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { CheckFailed("invalid file"
, &N, F); return; } } while (0)
;
1038}
1039
1040void Verifier::visitDIGlobalVariable(const DIGlobalVariable &N) {
1041 // Checks common to all variables.
1042 visitDIVariable(N);
1043
1044 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)
;
1045 Assert(!N.getName().empty(), "missing global variable name", &N)do { if (!(!N.getName().empty())) { CheckFailed("missing global variable name"
, &N); return; } } while (0)
;
1046 if (auto *V = N.getRawVariable()) {
1047 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)
1048 !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)
1049 "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)
;
1050 }
1051 if (auto *Member = N.getRawStaticDataMemberDeclaration()) {
1052 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)
1053 &N, Member)do { if (!(isa<DIDerivedType>(Member))) { CheckFailed("invalid static data member declaration"
, &N, Member); return; } } while (0)
;
1054 }
1055}
1056
1057void Verifier::visitDILocalVariable(const DILocalVariable &N) {
1058 // Checks common to all variables.
1059 visitDIVariable(N);
1060
1061 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)
;
1062 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)
1063 "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)
;
1064}
1065
1066void Verifier::visitDIExpression(const DIExpression &N) {
1067 Assert(N.isValid(), "invalid expression", &N)do { if (!(N.isValid())) { CheckFailed("invalid expression", &
N); return; } } while (0)
;
1068}
1069
1070void Verifier::visitDIObjCProperty(const DIObjCProperty &N) {
1071 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)
;
1072 if (auto *T = N.getRawType())
1073 Assert(isTypeRef(N, T), "invalid type ref", &N, T)do { if (!(isTypeRef(N, T))) { CheckFailed("invalid type ref"
, &N, T); return; } } while (0)
;
1074 if (auto *F = N.getRawFile())
1075 Assert(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { CheckFailed("invalid file"
, &N, F); return; } } while (0)
;
1076}
1077
1078void Verifier::visitDIImportedEntity(const DIImportedEntity &N) {
1079 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)
1080 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)
1081 "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)
;
1082 if (auto *S = N.getRawScope())
1083 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)
;
1084 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)
1085 N.getEntity())do { if (!(isDIRef(N, N.getEntity()))) { CheckFailed("invalid imported entity"
, &N, N.getEntity()); return; } } while (0)
;
1086}
1087
1088void Verifier::visitComdat(const Comdat &C) {
1089 // The Module is invalid if the GlobalValue has private linkage. Entities
1090 // with private linkage don't have entries in the symbol table.
1091 if (const GlobalValue *GV = M->getNamedValue(C.getName()))
1092 Assert(!GV->hasPrivateLinkage(), "comdat global value has private linkage",do { if (!(!GV->hasPrivateLinkage())) { CheckFailed("comdat global value has private linkage"
, GV); return; } } while (0)
1093 GV)do { if (!(!GV->hasPrivateLinkage())) { CheckFailed("comdat global value has private linkage"
, GV); return; } } while (0)
;
1094}
1095
1096void Verifier::visitModuleIdents(const Module &M) {
1097 const NamedMDNode *Idents = M.getNamedMetadata("llvm.ident");
1098 if (!Idents)
1099 return;
1100
1101 // llvm.ident takes a list of metadata entry. Each entry has only one string.
1102 // Scan each llvm.ident entry and make sure that this requirement is met.
1103 for (unsigned i = 0, e = Idents->getNumOperands(); i != e; ++i) {
1104 const MDNode *N = Idents->getOperand(i);
1105 Assert(N->getNumOperands() == 1,do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.ident metadata"
, N); return; } } while (0)
1106 "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)
;
1107 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)
1108 ("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)
1109 "(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)
1110 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)
;
1111 }
1112}
1113
1114void Verifier::visitModuleFlags(const Module &M) {
1115 const NamedMDNode *Flags = M.getModuleFlagsMetadata();
1116 if (!Flags) return;
1117
1118 // Scan each flag, and track the flags and requirements.
1119 DenseMap<const MDString*, const MDNode*> SeenIDs;
1120 SmallVector<const MDNode*, 16> Requirements;
1121 for (unsigned I = 0, E = Flags->getNumOperands(); I != E; ++I) {
1122 visitModuleFlag(Flags->getOperand(I), SeenIDs, Requirements);
1123 }
1124
1125 // Validate that the requirements in the module are valid.
1126 for (unsigned I = 0, E = Requirements.size(); I != E; ++I) {
1127 const MDNode *Requirement = Requirements[I];
1128 const MDString *Flag = cast<MDString>(Requirement->getOperand(0));
1129 const Metadata *ReqValue = Requirement->getOperand(1);
1130
1131 const MDNode *Op = SeenIDs.lookup(Flag);
1132 if (!Op) {
1133 CheckFailed("invalid requirement on flag, flag is not present in module",
1134 Flag);
1135 continue;
1136 }
1137
1138 if (Op->getOperand(2) != ReqValue) {
1139 CheckFailed(("invalid requirement on flag, "
1140 "flag does not have the required value"),
1141 Flag);
1142 continue;
1143 }
1144 }
1145}
1146
1147void
1148Verifier::visitModuleFlag(const MDNode *Op,
1149 DenseMap<const MDString *, const MDNode *> &SeenIDs,
1150 SmallVectorImpl<const MDNode *> &Requirements) {
1151 // Each module flag should have three arguments, the merge behavior (a
1152 // constant int), the flag ID (an MDString), and the value.
1153 Assert(Op->getNumOperands() == 3,do { if (!(Op->getNumOperands() == 3)) { CheckFailed("incorrect number of operands in module flag"
, Op); return; } } while (0)
1154 "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)
;
1155 Module::ModFlagBehavior MFB;
1156 if (!Module::isValidModFlagBehavior(Op->getOperand(0), MFB)) {
1157 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)
1158 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)
1159 "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)
1160 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)
;
1161 Assert(false,do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)"
, Op->getOperand(0)); return; } } while (0)
1162 "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)
1163 Op->getOperand(0))do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)"
, Op->getOperand(0)); return; } } while (0)
;
1164 }
1165 MDString *ID = dyn_cast_or_null<MDString>(Op->getOperand(1));
1166 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)
1167 Op->getOperand(1))do { if (!(ID)) { CheckFailed("invalid ID operand in module flag (expected metadata string)"
, Op->getOperand(1)); return; } } while (0)
;
1168
1169 // Sanity check the values for behaviors with additional requirements.
1170 switch (MFB) {
1171 case Module::Error:
1172 case Module::Warning:
1173 case Module::Override:
1174 // These behavior types accept any value.
1175 break;
1176
1177 case Module::Require: {
1178 // The value should itself be an MDNode with two operands, a flag ID (an
1179 // MDString), and a value.
1180 MDNode *Value = dyn_cast<MDNode>(Op->getOperand(2));
1181 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)
1182 "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)
1183 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)
;
1184 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)
1185 ("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)
1186 "(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)
1187 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)
;
1188
1189 // Append it to the list of requirements, to check once all module flags are
1190 // scanned.
1191 Requirements.push_back(Value);
1192 break;
1193 }
1194
1195 case Module::Append:
1196 case Module::AppendUnique: {
1197 // These behavior types require the operand be an MDNode.
1198 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)
1199 "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)
1200 "(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)
1201 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)
;
1202 break;
1203 }
1204 }
1205
1206 // Unless this is a "requires" flag, check the ID is unique.
1207 if (MFB != Module::Require) {
1208 bool Inserted = SeenIDs.insert(std::make_pair(ID, Op)).second;
1209 Assert(Inserted,do { if (!(Inserted)) { CheckFailed("module flag identifiers must be unique (or of 'require' type)"
, ID); return; } } while (0)
1210 "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)
;
1211 }
1212}
1213
1214void Verifier::VerifyAttributeTypes(AttributeSet Attrs, unsigned Idx,
1215 bool isFunction, const Value *V) {
1216 unsigned Slot = ~0U;
1217 for (unsigned I = 0, E = Attrs.getNumSlots(); I != E; ++I)
1218 if (Attrs.getSlotIndex(I) == Idx) {
1219 Slot = I;
1220 break;
1221 }
1222
1223 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~svn257205/lib/IR/Verifier.cpp"
, 1223, __PRETTY_FUNCTION__))
;
1224
1225 for (AttributeSet::iterator I = Attrs.begin(Slot), E = Attrs.end(Slot);
1226 I != E; ++I) {
1227 if (I->isStringAttribute())
1228 continue;
1229
1230 if (I->getKindAsEnum() == Attribute::NoReturn ||
1231 I->getKindAsEnum() == Attribute::NoUnwind ||
1232 I->getKindAsEnum() == Attribute::NoInline ||
1233 I->getKindAsEnum() == Attribute::AlwaysInline ||
1234 I->getKindAsEnum() == Attribute::OptimizeForSize ||
1235 I->getKindAsEnum() == Attribute::StackProtect ||
1236 I->getKindAsEnum() == Attribute::StackProtectReq ||
1237 I->getKindAsEnum() == Attribute::StackProtectStrong ||
1238 I->getKindAsEnum() == Attribute::SafeStack ||
1239 I->getKindAsEnum() == Attribute::NoRedZone ||
1240 I->getKindAsEnum() == Attribute::NoImplicitFloat ||
1241 I->getKindAsEnum() == Attribute::Naked ||
1242 I->getKindAsEnum() == Attribute::InlineHint ||
1243 I->getKindAsEnum() == Attribute::StackAlignment ||
1244 I->getKindAsEnum() == Attribute::UWTable ||
1245 I->getKindAsEnum() == Attribute::NonLazyBind ||
1246 I->getKindAsEnum() == Attribute::ReturnsTwice ||
1247 I->getKindAsEnum() == Attribute::SanitizeAddress ||
1248 I->getKindAsEnum() == Attribute::SanitizeThread ||
1249 I->getKindAsEnum() == Attribute::SanitizeMemory ||
1250 I->getKindAsEnum() == Attribute::MinSize ||
1251 I->getKindAsEnum() == Attribute::NoDuplicate ||
1252 I->getKindAsEnum() == Attribute::Builtin ||
1253 I->getKindAsEnum() == Attribute::NoBuiltin ||
1254 I->getKindAsEnum() == Attribute::Cold ||
1255 I->getKindAsEnum() == Attribute::OptimizeNone ||
1256 I->getKindAsEnum() == Attribute::JumpTable ||
1257 I->getKindAsEnum() == Attribute::Convergent ||
1258 I->getKindAsEnum() == Attribute::ArgMemOnly ||
1259 I->getKindAsEnum() == Attribute::NoRecurse ||
1260 I->getKindAsEnum() == Attribute::InaccessibleMemOnly ||
1261 I->getKindAsEnum() == Attribute::InaccessibleMemOrArgMemOnly) {
1262 if (!isFunction) {
1263 CheckFailed("Attribute '" + I->getAsString() +
1264 "' only applies to functions!", V);
1265 return;
1266 }
1267 } else if (I->getKindAsEnum() == Attribute::ReadOnly ||
1268 I->getKindAsEnum() == Attribute::ReadNone) {
1269 if (Idx == 0) {
1270 CheckFailed("Attribute '" + I->getAsString() +
1271 "' does not apply to function returns");
1272 return;
1273 }
1274 } else if (isFunction) {
1275 CheckFailed("Attribute '" + I->getAsString() +
1276 "' does not apply to functions!", V);
1277 return;
1278 }
1279 }
1280}
1281
1282// VerifyParameterAttrs - Check the given attributes for an argument or return
1283// value of the specified type. The value V is printed in error messages.
1284void Verifier::VerifyParameterAttrs(AttributeSet Attrs, unsigned Idx, Type *Ty,
1285 bool isReturnValue, const Value *V) {
1286 if (!Attrs.hasAttributes(Idx))
1287 return;
1288
1289 VerifyAttributeTypes(Attrs, Idx, false, V);
1290
1291 if (isReturnValue)
1292 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)
1293 !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)
1294 !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)
1295 !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)
1296 !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)
1297 !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)
1298 "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)
1299 "'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)
1300 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)
;
1301
1302 // Check for mutually incompatible attributes. Only inreg is compatible with
1303 // sret.
1304 unsigned AttrCount = 0;
1305 AttrCount += Attrs.hasAttribute(Idx, Attribute::ByVal);
1306 AttrCount += Attrs.hasAttribute(Idx, Attribute::InAlloca);
1307 AttrCount += Attrs.hasAttribute(Idx, Attribute::StructRet) ||
1308 Attrs.hasAttribute(Idx, Attribute::InReg);
1309 AttrCount += Attrs.hasAttribute(Idx, Attribute::Nest);
1310 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)
1311 "and 'sret' are incompatible!",do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'inreg', 'nest', "
"and 'sret' are incompatible!", V); return; } } while (0)
1312 V)do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'inreg', 'nest', "
"and 'sret' are incompatible!", V); return; } } while (0)
;
1313
1314 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)
1315 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)
1316 "Attributes "do { if (!(!(Attrs.hasAttribute(Idx, Attribute::InAlloca) &&
Attrs.hasAttribute(Idx, Attribute::ReadOnly)))) { CheckFailed
("Attributes " "'inalloca and readonly' are incompatible!", V
); return; } } while (0)
1317 "'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)
1318 V)do { if (!(!(Attrs.hasAttribute(Idx, Attribute::InAlloca) &&
Attrs.hasAttribute(Idx, Attribute::ReadOnly)))) { CheckFailed
("Attributes " "'inalloca and readonly' are incompatible!", V
); return; } } while (0)
;
1319
1320 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)
1321 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)
1322 "Attributes "do { if (!(!(Attrs.hasAttribute(Idx, Attribute::StructRet) &&
Attrs.hasAttribute(Idx, Attribute::Returned)))) { CheckFailed
("Attributes " "'sret and returned' are incompatible!", V); return
; } } while (0)
1323 "'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)
1324 V)do { if (!(!(Attrs.hasAttribute(Idx, Attribute::StructRet) &&
Attrs.hasAttribute(Idx, Attribute::Returned)))) { CheckFailed
("Attributes " "'sret and returned' are incompatible!", V); return
; } } while (0)
;
1325
1326 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)
1327 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)
1328 "Attributes "do { if (!(!(Attrs.hasAttribute(Idx, Attribute::ZExt) &&
Attrs.hasAttribute(Idx, Attribute::SExt)))) { CheckFailed("Attributes "
"'zeroext and signext' are incompatible!", V); return; } } while
(0)
1329 "'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)
1330 V)do { if (!(!(Attrs.hasAttribute(Idx, Attribute::ZExt) &&
Attrs.hasAttribute(Idx, Attribute::SExt)))) { CheckFailed("Attributes "
"'zeroext and signext' are incompatible!", V); return; } } while
(0)
;
1331
1332 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)
1333 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)
1334 "Attributes "do { if (!(!(Attrs.hasAttribute(Idx, Attribute::ReadNone) &&
Attrs.hasAttribute(Idx, Attribute::ReadOnly)))) { CheckFailed
("Attributes " "'readnone and readonly' are incompatible!", V
); return; } } while (0)
1335 "'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)
1336 V)do { if (!(!(Attrs.hasAttribute(Idx, Attribute::ReadNone) &&
Attrs.hasAttribute(Idx, Attribute::ReadOnly)))) { CheckFailed
("Attributes " "'readnone and readonly' are incompatible!", V
); return; } } while (0)
;
1337
1338 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)
1339 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)
1340 "Attributes "do { if (!(!(Attrs.hasAttribute(Idx, Attribute::NoInline) &&
Attrs.hasAttribute(Idx, Attribute::AlwaysInline)))) { CheckFailed
("Attributes " "'noinline and alwaysinline' are incompatible!"
, V); return; } } while (0)
1341 "'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)
1342 V)do { if (!(!(Attrs.hasAttribute(Idx, Attribute::NoInline) &&
Attrs.hasAttribute(Idx, Attribute::AlwaysInline)))) { CheckFailed
("Attributes " "'noinline and alwaysinline' are incompatible!"
, V); return; } } while (0)
;
1343
1344 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)
1345 .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)
1346 "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)
1347 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)
1348 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)
1349 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)
;
1350
1351 if (PointerType *PTy = dyn_cast<PointerType>(Ty)) {
1352 SmallPtrSet<Type*, 4> Visited;
1353 if (!PTy->getElementType()->isSized(&Visited)) {
1354 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)
1355 !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)
1356 "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)
1357 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)
;
1358 }
1359 } else {
1360 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)
1361 "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)
1362 V)do { if (!(!Attrs.hasAttribute(Idx, Attribute::ByVal))) { CheckFailed
("Attribute 'byval' only applies to parameters with pointer type!"
, V); return; } } while (0)
;
1363 }
1364}
1365
1366// VerifyFunctionAttrs - Check parameter attributes against a function type.
1367// The value V is printed in error messages.
1368void Verifier::VerifyFunctionAttrs(FunctionType *FT, AttributeSet Attrs,
1369 const Value *V) {
1370 if (Attrs.isEmpty())
1371 return;
1372
1373 bool SawNest = false;
1374 bool SawReturned = false;
1375 bool SawSRet = false;
1376
1377 for (unsigned i = 0, e = Attrs.getNumSlots(); i != e; ++i) {
1378 unsigned Idx = Attrs.getSlotIndex(i);
1379
1380 Type *Ty;
1381 if (Idx == 0)
1382 Ty = FT->getReturnType();
1383 else if (Idx-1 < FT->getNumParams())
1384 Ty = FT->getParamType(Idx-1);
1385 else
1386 break; // VarArgs attributes, verified elsewhere.
1387
1388 VerifyParameterAttrs(Attrs, Idx, Ty, Idx == 0, V);
1389
1390 if (Idx == 0)
1391 continue;
1392
1393 if (Attrs.hasAttribute(Idx, Attribute::Nest)) {
1394 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)
;
1395 SawNest = true;
1396 }
1397
1398 if (Attrs.hasAttribute(Idx, Attribute::Returned)) {
1399 Assert(!SawReturned, "More than one parameter has attribute returned!",do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!"
, V); return; } } while (0)
1400 V)do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!"
, V); return; } } while (0)
;
1401 Assert(Ty->canLosslesslyBitCastTo(FT->getReturnType()),do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType
()))) { CheckFailed("Incompatible " "argument and return types for 'returned' attribute"
, V); return; } } while (0)
1402 "Incompatible "do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType
()))) { CheckFailed("Incompatible " "argument and return types for 'returned' attribute"
, V); return; } } while (0)
1403 "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)
1404 V)do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType
()))) { CheckFailed("Incompatible " "argument and return types for 'returned' attribute"
, V); return; } } while (0)
;
1405 SawReturned = true;
1406 }
1407
1408 if (Attrs.hasAttribute(Idx, Attribute::StructRet)) {
1409 Assert(!SawSRet, "Cannot have multiple 'sret' parameters!", V)do { if (!(!SawSRet)) { CheckFailed("Cannot have multiple 'sret' parameters!"
, V); return; } } while (0)
;
1410 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)
1411 "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)
;
1412 SawSRet = true;
1413 }
1414
1415 if (Attrs.hasAttribute(Idx, Attribute::InAlloca)) {
1416 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)
1417 V)do { if (!(Idx == FT->getNumParams())) { CheckFailed("inalloca isn't on the last parameter!"
, V); return; } } while (0)
;
1418 }
1419 }
1420
1421 if (!Attrs.hasAttributes(AttributeSet::FunctionIndex))
1422 return;
1423
1424 VerifyAttributeTypes(Attrs, AttributeSet::FunctionIndex, true, V);
1425
1426 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)
1427 !(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)
1428 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)
1429 "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)
;
1430
1431 Assert(do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute
::ReadNone) && Attrs.hasAttribute(AttributeSet::FunctionIndex
, Attribute::InaccessibleMemOrArgMemOnly)))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are incompatible!"
, V); return; } } while (0)
1432 !(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone) &&do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute
::ReadNone) && Attrs.hasAttribute(AttributeSet::FunctionIndex
, Attribute::InaccessibleMemOrArgMemOnly)))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are incompatible!"
, V); return; } } while (0)
1433 Attrs.hasAttribute(AttributeSet::FunctionIndex,do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute
::ReadNone) && Attrs.hasAttribute(AttributeSet::FunctionIndex
, Attribute::InaccessibleMemOrArgMemOnly)))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are incompatible!"
, V); return; } } while (0)
1434 Attribute::InaccessibleMemOrArgMemOnly)),do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute
::ReadNone) && Attrs.hasAttribute(AttributeSet::FunctionIndex
, Attribute::InaccessibleMemOrArgMemOnly)))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are incompatible!"
, V); return; } } while (0)
1435 "Attributes 'readnone and inaccessiblemem_or_argmemonly' are incompatible!", V)do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute
::ReadNone) && Attrs.hasAttribute(AttributeSet::FunctionIndex
, Attribute::InaccessibleMemOrArgMemOnly)))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are incompatible!"
, V); return; } } while (0)
;
1436
1437 Assert(do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute
::ReadNone) && Attrs.hasAttribute(AttributeSet::FunctionIndex
, Attribute::InaccessibleMemOnly)))) { CheckFailed("Attributes 'readnone and inaccessiblememonly' are incompatible!"
, V); return; } } while (0)
1438 !(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone) &&do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute
::ReadNone) && Attrs.hasAttribute(AttributeSet::FunctionIndex
, Attribute::InaccessibleMemOnly)))) { CheckFailed("Attributes 'readnone and inaccessiblememonly' are incompatible!"
, V); return; } } while (0)
1439 Attrs.hasAttribute(AttributeSet::FunctionIndex,do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute
::ReadNone) && Attrs.hasAttribute(AttributeSet::FunctionIndex
, Attribute::InaccessibleMemOnly)))) { CheckFailed("Attributes 'readnone and inaccessiblememonly' are incompatible!"
, V); return; } } while (0)
1440 Attribute::InaccessibleMemOnly)),do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute
::ReadNone) && Attrs.hasAttribute(AttributeSet::FunctionIndex
, Attribute::InaccessibleMemOnly)))) { CheckFailed("Attributes 'readnone and inaccessiblememonly' are incompatible!"
, V); return; } } while (0)
1441 "Attributes 'readnone and inaccessiblememonly' are incompatible!", V)do { if (!(!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute
::ReadNone) && Attrs.hasAttribute(AttributeSet::FunctionIndex
, Attribute::InaccessibleMemOnly)))) { CheckFailed("Attributes 'readnone and inaccessiblememonly' are incompatible!"
, V); return; } } while (0)
;
1442
1443 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)
1444 !(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)
1445 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)
1446 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)
1447 "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)
;
1448
1449 if (Attrs.hasAttribute(AttributeSet::FunctionIndex,
1450 Attribute::OptimizeNone)) {
1451 Assert(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute::NoInline),do { if (!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute
::NoInline))) { CheckFailed("Attribute 'optnone' requires 'noinline'!"
, V); return; } } while (0)
1452 "Attribute 'optnone' requires 'noinline'!", V)do { if (!(Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute
::NoInline))) { CheckFailed("Attribute 'optnone' requires 'noinline'!"
, V); return; } } while (0)
;
1453
1454 Assert(!Attrs.hasAttribute(AttributeSet::FunctionIndex,do { if (!(!Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute
::OptimizeForSize))) { CheckFailed("Attributes 'optsize and optnone' are incompatible!"
, V); return; } } while (0)
1455 Attribute::OptimizeForSize),do { if (!(!Attrs.hasAttribute(AttributeSet::FunctionIndex, Attribute
::OptimizeForSize))) { CheckFailed("Attributes 'optsize and optnone' are incompatible!"
, V); return; } } while (0)
1456 "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)
;
1457
1458 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)
1459 "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)
;
1460 }
1461
1462 if (Attrs.hasAttribute(AttributeSet::FunctionIndex,
1463 Attribute::JumpTable)) {
1464 const GlobalValue *GV = cast<GlobalValue>(V);
1465 Assert(GV->hasUnnamedAddr(),do { if (!(GV->hasUnnamedAddr())) { CheckFailed("Attribute 'jumptable' requires 'unnamed_addr'"
, V); return; } } while (0)
1466 "Attribute 'jumptable' requires 'unnamed_addr'", V)do { if (!(GV->hasUnnamedAddr())) { CheckFailed("Attribute 'jumptable' requires 'unnamed_addr'"
, V); return; } } while (0)
;
1467 }
1468}
1469
1470void Verifier::VerifyFunctionMetadata(
1471 const SmallVector<std::pair<unsigned, MDNode *>, 4> MDs) {
1472 if (MDs.empty())
1473 return;
1474
1475 for (unsigned i = 0; i < MDs.size(); i++) {
1476 if (MDs[i].first == LLVMContext::MD_prof) {
1477 MDNode *MD = MDs[i].second;
1478 Assert(MD->getNumOperands() == 2,do { if (!(MD->getNumOperands() == 2)) { CheckFailed("!prof annotations should have exactly 2 operands"
, MD); return; } } while (0)
1479 "!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)
;
1480
1481 // Check first operand.
1482 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)
1483 MD)do { if (!(MD->getOperand(0) != nullptr)) { CheckFailed("first operand should not be null"
, MD); return; } } while (0)
;
1484 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)
1485 "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)
;
1486 MDString *MDS = cast<MDString>(MD->getOperand(0));
1487 StringRef ProfName = MDS->getString();
1488 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)
1489 "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)
;
1490
1491 // Check second operand.
1492 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)
1493 MD)do { if (!(MD->getOperand(1) != nullptr)) { CheckFailed("second operand should not be null"
, MD); return; } } while (0)
;
1494 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)
1495 "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)
;
1496 }
1497 }
1498}
1499
1500void Verifier::visitConstantExprsRecursively(const Constant *EntryC) {
1501 if (!ConstantExprVisited.insert(EntryC).second)
1502 return;
1503
1504 SmallVector<const Constant *, 16> Stack;
1505 Stack.push_back(EntryC);
1506
1507 while (!Stack.empty()) {
1508 const Constant *C = Stack.pop_back_val();
1509
1510 // Check this constant expression.
1511 if (const auto *CE = dyn_cast<ConstantExpr>(C))
1512 visitConstantExpr(CE);
1513
1514 // Visit all sub-expressions.
1515 for (const Use &U : C->operands()) {
1516 const auto *OpC = dyn_cast<Constant>(U);
1517 if (!OpC)
1518 continue;
1519 if (isa<GlobalValue>(OpC))
1520 continue; // Global values get visited separately.
1521 if (!ConstantExprVisited.insert(OpC).second)
1522 continue;
1523 Stack.push_back(OpC);
1524 }
1525 }
1526}
1527
1528void Verifier::visitConstantExpr(const ConstantExpr *CE) {
1529 if (CE->getOpcode() != Instruction::BitCast)
1530 return;
1531
1532 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)
1533 CE->getType()),do { if (!(CastInst::castIsValid(Instruction::BitCast, CE->
getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast"
, CE); return; } } while (0)
1534 "Invalid bitcast", CE)do { if (!(CastInst::castIsValid(Instruction::BitCast, CE->
getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast"
, CE); return; } } while (0)
;
1535}
1536
1537bool Verifier::VerifyAttributeCount(AttributeSet Attrs, unsigned Params) {
1538 if (Attrs.getNumSlots() == 0)
1539 return true;
1540
1541 unsigned LastSlot = Attrs.getNumSlots() - 1;
1542 unsigned LastIndex = Attrs.getSlotIndex(LastSlot);
1543 if (LastIndex <= Params
1544 || (LastIndex == AttributeSet::FunctionIndex
1545 && (LastSlot == 0 || Attrs.getSlotIndex(LastSlot - 1) <= Params)))
1546 return true;
1547
1548 return false;
1549}
1550
1551/// \brief Verify that statepoint intrinsic is well formed.
1552void Verifier::VerifyStatepoint(ImmutableCallSite CS) {
1553 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~svn257205/lib/IR/Verifier.cpp"
, 1555, __PRETTY_FUNCTION__))
1554 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~svn257205/lib/IR/Verifier.cpp"
, 1555, __PRETTY_FUNCTION__))
1555 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~svn257205/lib/IR/Verifier.cpp"
, 1555, __PRETTY_FUNCTION__))
;
1556
1557 const Instruction &CI = *CS.getInstruction();
1558
1559 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)
1560 !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)
1561 "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)
1562 "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)
1563 &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)
;
1564
1565 const Value *IDV = CS.getArgument(0);
1566 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)
1567 &CI)do { if (!(isa<ConstantInt>(IDV))) { CheckFailed("gc.statepoint ID must be a constant integer"
, &CI); return; } } while (0)
;
1568
1569 const Value *NumPatchBytesV = CS.getArgument(1);
1570 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)
1571 "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)
1572 &CI)do { if (!(isa<ConstantInt>(NumPatchBytesV))) { CheckFailed
("gc.statepoint number of patchable bytes must be a constant integer"
, &CI); return; } } while (0)
;
1573 const int64_t NumPatchBytes =
1574 cast<ConstantInt>(NumPatchBytesV)->getSExtValue();
1575 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~svn257205/lib/IR/Verifier.cpp"
, 1575, __PRETTY_FUNCTION__))
;
1576 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)
1577 "positive",do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be "
"positive", &CI); return; } } while (0)
1578 &CI)do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be "
"positive", &CI); return; } } while (0)
;
1579
1580 const Value *Target = CS.getArgument(2);
1581 auto *PT = dyn_cast<PointerType>(Target->getType());
1582 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)
1583 "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)
;
1584 FunctionType *TargetFuncType = cast<FunctionType>(PT->getElementType());
1585
1586 const Value *NumCallArgsV = CS.getArgument(3);
1587 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)
1588 "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)
1589 "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)
1590 &CI)do { if (!(isa<ConstantInt>(NumCallArgsV))) { CheckFailed
("gc.statepoint number of arguments to underlying call " "must be constant integer"
, &CI); return; } } while (0)
;
1591 const int NumCallArgs = cast<ConstantInt>(NumCallArgsV)->getZExtValue();
1592 Assert(NumCallArgs >= 0,do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call "
"must be positive", &CI); return; } } while (0)
1593 "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)
1594 "must be positive",do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call "
"must be positive", &CI); return; } } while (0)
1595 &CI)do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call "
"must be positive", &CI); return; } } while (0)
;
1596 const int NumParams = (int)TargetFuncType->getNumParams();
1597 if (TargetFuncType->isVarArg()) {
1598 Assert(NumCallArgs >= NumParams,do { if (!(NumCallArgs >= NumParams)) { CheckFailed("gc.statepoint mismatch in number of vararg call args"
, &CI); return; } } while (0)
1599 "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)
;
1600
1601 // TODO: Remove this limitation
1602 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)
1603 "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)
1604 "vararg functions yet",do { if (!(TargetFuncType->getReturnType()->isVoidTy())
) { CheckFailed("gc.statepoint doesn't support wrapping non-void "
"vararg functions yet", &CI); return; } } while (0)
1605 &CI)do { if (!(TargetFuncType->getReturnType()->isVoidTy())
) { CheckFailed("gc.statepoint doesn't support wrapping non-void "
"vararg functions yet", &CI); return; } } while (0)
;
1606 } else
1607 Assert(NumCallArgs == NumParams,do { if (!(NumCallArgs == NumParams)) { CheckFailed("gc.statepoint mismatch in number of call args"
, &CI); return; } } while (0)
1608 "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)
;
1609
1610 const Value *FlagsV = CS.getArgument(4);
1611 Assert(isa<ConstantInt>(FlagsV),do { if (!(isa<ConstantInt>(FlagsV))) { CheckFailed("gc.statepoint flags must be constant integer"
, &CI); return; } } while (0)
1612 "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)
;
1613 const uint64_t Flags = cast<ConstantInt>(FlagsV)->getZExtValue();
1614 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)
1615 "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)
;
1616
1617 // Verify that the types of the call parameter arguments match
1618 // the type of the wrapped callee.
1619 for (int i = 0; i < NumParams; i++) {
1620 Type *ParamType = TargetFuncType->getParamType(i);
1621 Type *ArgType = CS.getArgument(5 + i)->getType();
1622 Assert(ArgType == ParamType,do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped "
"function type", &CI); return; } } while (0)
1623 "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)
1624 "function type",do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped "
"function type", &CI); return; } } while (0)
1625 &CI)do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped "
"function type", &CI); return; } } while (0)
;
1626 }
1627
1628 const int EndCallArgsInx = 4 + NumCallArgs;
1629
1630 const Value *NumTransitionArgsV = CS.getArgument(EndCallArgsInx+1);
1631 Assert(isa<ConstantInt>(NumTransitionArgsV),do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed
("gc.statepoint number of transition arguments " "must be constant integer"
, &CI); return; } } while (0)
1632 "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)
1633 "must be constant integer",do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed
("gc.statepoint number of transition arguments " "must be constant integer"
, &CI); return; } } while (0)
1634 &CI)do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed
("gc.statepoint number of transition arguments " "must be constant integer"
, &CI); return; } } while (0)
;
1635 const int NumTransitionArgs =
1636 cast<ConstantInt>(NumTransitionArgsV)->getZExtValue();
1637 Assert(NumTransitionArgs >= 0,do { if (!(NumTransitionArgs >= 0)) { CheckFailed("gc.statepoint number of transition arguments must be positive"
, &CI); return; } } while (0)
1638 "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)
;
1639 const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs;
1640
1641 const Value *NumDeoptArgsV = CS.getArgument(EndTransitionArgsInx+1);
1642 Assert(isa<ConstantInt>(NumDeoptArgsV),do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed
("gc.statepoint number of deoptimization arguments " "must be constant integer"
, &CI); return; } } while (0)
1643 "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)
1644 "must be constant integer",do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed
("gc.statepoint number of deoptimization arguments " "must be constant integer"
, &CI); return; } } while (0)
1645 &CI)do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed
("gc.statepoint number of deoptimization arguments " "must be constant integer"
, &CI); return; } } while (0)
;
1646 const int NumDeoptArgs = cast<ConstantInt>(NumDeoptArgsV)->getZExtValue();
1647 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)
1648 "must be positive",do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments "
"must be positive", &CI); return; } } while (0)
1649 &CI)do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments "
"must be positive", &CI); return; } } while (0)
;
1650
1651 const int ExpectedNumArgs =
1652 7 + NumCallArgs + NumTransitionArgs + NumDeoptArgs;
1653 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)
1654 "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)
;
1655
1656 // Check that the only uses of this gc.statepoint are gc.result or
1657 // gc.relocate calls which are tied to this statepoint and thus part
1658 // of the same statepoint sequence
1659 for (const User *U : CI.users()) {
1660 const CallInst *Call = dyn_cast<const CallInst>(U);
1661 Assert(Call, "illegal use of statepoint token", &CI, U)do { if (!(Call)) { CheckFailed("illegal use of statepoint token"
, &CI, U); return; } } while (0)
;
1662 if (!Call) continue;
1663 Assert(isa<GCRelocateInst>(Call) || isGCResult(Call),do { if (!(isa<GCRelocateInst>(Call) || isGCResult(Call
))) { CheckFailed("gc.result or gc.relocate are the only value uses"
"of a gc.statepoint", &CI, U); return; } } while (0)
1664 "gc.result or gc.relocate are the only value uses"do { if (!(isa<GCRelocateInst>(Call) || isGCResult(Call
))) { CheckFailed("gc.result or gc.relocate are the only value uses"
"of a gc.statepoint", &CI, U); return; } } while (0)
1665 "of a gc.statepoint",do { if (!(isa<GCRelocateInst>(Call) || isGCResult(Call
))) { CheckFailed("gc.result or gc.relocate are the only value uses"
"of a gc.statepoint", &CI, U); return; } } while (0)
1666 &CI, U)do { if (!(isa<GCRelocateInst>(Call) || isGCResult(Call
))) { CheckFailed("gc.result or gc.relocate are the only value uses"
"of a gc.statepoint", &CI, U); return; } } while (0)
;
1667 if (isGCResult(Call)) {
1668 Assert(Call->getArgOperand(0) == &CI,do { if (!(Call->getArgOperand(0) == &CI)) { CheckFailed
("gc.result connected to wrong gc.statepoint", &CI, Call)
; return; } } while (0)
1669 "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)
;
1670 } else if (isa<GCRelocateInst>(Call)) {
1671 Assert(Call->getArgOperand(0) == &CI,do { if (!(Call->getArgOperand(0) == &CI)) { CheckFailed
("gc.relocate connected to wrong gc.statepoint", &CI, Call
); return; } } while (0)
1672 "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)
;
1673 }
1674 }
1675
1676 // Note: It is legal for a single derived pointer to be listed multiple
1677 // times. It's non-optimal, but it is legal. It can also happen after
1678 // insertion if we strip a bitcast away.
1679 // Note: It is really tempting to check that each base is relocated and
1680 // that a derived pointer is never reused as a base pointer. This turns
1681 // out to be problematic since optimizations run after safepoint insertion
1682 // can recognize equality properties that the insertion logic doesn't know
1683 // about. See example statepoint.ll in the verifier subdirectory
1684}
1685
1686void Verifier::verifyFrameRecoverIndices() {
1687 for (auto &Counts : FrameEscapeInfo) {
1688 Function *F = Counts.first;
1689 unsigned EscapedObjectCount = Counts.second.first;
1690 unsigned MaxRecoveredIndex = Counts.second.second;
1691 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)
1692 "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)
1693 "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)
1694 "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)
1695 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)
;
1696 }
1697}
1698
1699// visitFunction - Verify that a function is ok.
1700//
1701void Verifier::visitFunction(const Function &F) {
1702 // Check function arguments.
1703 FunctionType *FT = F.getFunctionType();
1704 unsigned NumArgs = F.arg_size();
1705
1706 Assert(Context == &F.getContext(),do { if (!(Context == &F.getContext())) { CheckFailed("Function context does not match Module context!"
, &F); return; } } while (0)
1707 "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)
;
1708
1709 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)
;
1710 Assert(FT->getNumParams() == NumArgs,do { if (!(FT->getNumParams() == NumArgs)) { CheckFailed("# formal arguments must match # of arguments for function type!"
, &F, FT); return; } } while (0)
1711 "# 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)
1712 FT)do { if (!(FT->getNumParams() == NumArgs)) { CheckFailed("# formal arguments must match # of arguments for function type!"
, &F, FT); return; } } while (0)
;
1713 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)
1714 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)
1715 "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)
;
1716
1717 Assert(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy(),do { if (!(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy
())) { CheckFailed("Invalid struct return type!", &F); return
; } } while (0)
1718 "Invalid struct return type!", &F)do { if (!(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy
())) { CheckFailed("Invalid struct return type!", &F); return
; } } while (0)
;
1719
1720 AttributeSet Attrs = F.getAttributes();
1721
1722 Assert(VerifyAttributeCount(Attrs, FT->getNumParams()),do { if (!(VerifyAttributeCount(Attrs, FT->getNumParams())
)) { CheckFailed("Attribute after last parameter!", &F); return
; } } while (0)
1723 "Attribute after last parameter!", &F)do { if (!(VerifyAttributeCount(Attrs, FT->getNumParams())
)) { CheckFailed("Attribute after last parameter!", &F); return
; } } while (0)
;
1724
1725 // Check function attributes.
1726 VerifyFunctionAttrs(FT, Attrs, &F);
1727
1728 // On function declarations/definitions, we do not support the builtin
1729 // attribute. We do not check this in VerifyFunctionAttrs since that is
1730 // checking for Attributes that can/can not ever be on functions.
1731 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)
1732 "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)
;
1733
1734 // Check that this function meets the restrictions on this calling convention.
1735 // Sometimes varargs is used for perfectly forwarding thunks, so some of these
1736 // restrictions can be lifted.
1737 switch (F.getCallingConv()) {
1
Control jumps to the 'default' case at line 1738
1738 default:
1739 case CallingConv::C:
1740 break;
2
Execution continues on line 1752
1741 case CallingConv::Fast:
1742 case CallingConv::Cold:
1743 case CallingConv::Intel_OCL_BI:
1744 case CallingConv::PTX_Kernel:
1745 case CallingConv::PTX_Device:
1746 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)
1747 "perfect forwarding!",do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or "
"perfect forwarding!", &F); return; } } while (0)
1748 &F)do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or "
"perfect forwarding!", &F); return; } } while (0)
;
1749 break;
1750 }
1751
1752 bool isLLVMdotName = F.getName().size() >= 5 &&
1753 F.getName().substr(0, 5) == "llvm.";
1754
1755 // Check that the argument values match the function type for this function...
1756 unsigned i = 0;
1757 for (Function::const_arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E;
3
Loop condition is false. Execution continues on line 1772
1758 ++I, ++i) {
1759 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)
1760 "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)
1761 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)
;
1762 Assert(I->getType()->isFirstClassType(),do { if (!(I->getType()->isFirstClassType())) { CheckFailed
("Function arguments must have first-class types!", I); return
; } } while (0)
1763 "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)
;
1764 if (!isLLVMdotName) {
1765 Assert(!I->getType()->isMetadataTy(),do { if (!(!I->getType()->isMetadataTy())) { CheckFailed
("Function takes metadata but isn't an intrinsic", I, &F)
; return; } } while (0)
1766 "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)
;
1767 Assert(!I->getType()->isTokenTy(),do { if (!(!I->getType()->isTokenTy())) { CheckFailed("Function takes token but isn't an intrinsic"
, I, &F); return; } } while (0)
1768 "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)
;
1769 }
1770 }
1771
1772 if (!isLLVMdotName)
4
Taking true branch
1773 Assert(!F.getReturnType()->isTokenTy(),do { if (!(!F.getReturnType()->isTokenTy())) { CheckFailed
("Functions returns a token but isn't an intrinsic", &F);
return; } } while (0)
1774 "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)
;
1775
1776 // Get the function metadata attachments.
1777 SmallVector<std::pair<unsigned, MDNode *>, 4> MDs;
1778 F.getAllMetadata(MDs);
1779 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~svn257205/lib/IR/Verifier.cpp"
, 1779, __PRETTY_FUNCTION__))
;
1780 VerifyFunctionMetadata(MDs);
1781
1782 // Check validity of the personality function
1783 if (F.hasPersonalityFn()) {
5
Taking false branch
1784 auto *Per = dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts());
1785 if (Per)
1786 Assert(Per->getParent() == F.getParent(),do { if (!(Per->getParent() == F.getParent())) { CheckFailed
("Referencing personality function in another module!", &
F, F.getParent(), Per, Per->getParent()); return; } } while
(0)
1787 "Referencing personality function in another module!",do { if (!(Per->getParent() == F.getParent())) { CheckFailed
("Referencing personality function in another module!", &
F, F.getParent(), Per, Per->getParent()); return; } } while
(0)
1788 &F, F.getParent(), Per, Per->getParent())do { if (!(Per->getParent() == F.getParent())) { CheckFailed
("Referencing personality function in another module!", &
F, F.getParent(), Per, Per->getParent()); return; } } while
(0)
;
1789 }
1790
1791 if (F.isMaterializable()) {
6
Taking false branch
1792 // Function has a body somewhere we can't see.
1793 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)
1794 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)
;
1795 } else if (F.isDeclaration()) {
7
Taking false branch
1796 Assert(F.hasExternalLinkage() || F.hasExternalWeakLinkage(),do { if (!(F.hasExternalLinkage() || F.hasExternalWeakLinkage
())) { CheckFailed("invalid linkage type for function declaration"
, &F); return; } } while (0)
1797 "invalid linkage type for function declaration", &F)do { if (!(F.hasExternalLinkage() || F.hasExternalWeakLinkage
())) { CheckFailed("invalid linkage type for function declaration"
, &F); return; } } while (0)
;
1798 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)
1799 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)
;
1800 Assert(!F.hasPersonalityFn(),do { if (!(!F.hasPersonalityFn())) { CheckFailed("Function declaration shouldn't have a personality routine"
, &F); return; } } while (0)
1801 "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)
;
1802 } else {
1803 // Verify that this function (which has a body) is not named "llvm.*". It
1804 // is not legal to define intrinsics.
1805 Assert(!isLLVMdotName, "llvm intrinsics cannot be defined!", &F)do { if (!(!isLLVMdotName)) { CheckFailed("llvm intrinsics cannot be defined!"
, &F); return; } } while (0)
;
1806
1807 // Check the entry node
1808 const BasicBlock *Entry = &F.getEntryBlock();
1809 Assert(pred_empty(Entry),do { if (!(pred_empty(Entry))) { CheckFailed("Entry block to function must not have predecessors!"
, Entry); return; } } while (0)
1810 "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)
;
1811
1812 // The address of the entry block cannot be taken, unless it is dead.
1813 if (Entry->hasAddressTaken()) {
8
Taking false branch
1814 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)
1815 "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)
;
1816 }
1817
1818 // Visit metadata attachments.
1819 for (const auto &I : MDs) {
9
Assuming '__begin' is equal to '__end'
1820 // Verify that the attachment is legal.
1821 switch (I.first) {
1822 default:
1823 break;
1824 case LLVMContext::MD_dbg:
1825 Assert(isa<DISubprogram>(I.second),do { if (!(isa<DISubprogram>(I.second))) { CheckFailed(
"function !dbg attachment must be a subprogram", &F, I.second
); return; } } while (0)
1826 "function !dbg attachment must be a subprogram", &F, I.second)do { if (!(isa<DISubprogram>(I.second))) { CheckFailed(
"function !dbg attachment must be a subprogram", &F, I.second
); return; } } while (0)
;
1827 break;
1828 }
1829
1830 // Verify the metadata itself.
1831 visitMDNode(*I.second);
1832 }
1833 }
1834
1835 // If this function is actually an intrinsic, verify that it is only used in
1836 // direct call/invokes, never having its "address taken".
1837 // Only do this if the module is materialized, otherwise we don't have all the
1838 // uses.
1839 if (F.getIntrinsicID() && F.getParent()->isMaterialized()) {
1840 const User *U;
1841 if (F.hasAddressTaken(&U))
1842 Assert(0, "Invalid user of intrinsic instruction!", U)do { if (!(0)) { CheckFailed("Invalid user of intrinsic instruction!"
, U); return; } } while (0)
;
1843 }
1844
1845 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)
1846 (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)
1847 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)
1848 "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)
;
1849
1850 auto *N = F.getSubprogram();
1851 if (!N)
10
Assuming 'N' is non-null
11
Taking false branch
1852 return;
1853
1854 // Check that all !dbg attachments lead to back to N (or, at least, another
1855 // subprogram that describes the same function).
1856 //
1857 // FIXME: Check this incrementally while visiting !dbg attachments.
1858 // FIXME: Only check when N is the canonical subprogram for F.
1859 SmallPtrSet<const MDNode *, 32> Seen;
1860 for (auto &BB : F)
1861 for (auto &I : BB) {
1862 // Be careful about using DILocation here since we might be dealing with
1863 // broken code (this is the Verifier after all).
1864 DILocation *DL =
1865 dyn_cast_or_null<DILocation>(I.getDebugLoc().getAsMDNode());
1866 if (!DL)
12
Assuming 'DL' is non-null
13
Taking false branch
1867 continue;
1868 if (!Seen.insert(DL).second)
14
Taking false branch
1869 continue;
1870
1871 DILocalScope *Scope = DL->getInlinedAtScope();
1872 if (Scope && !Seen.insert(Scope).second)
1873 continue;
1874
1875 DISubprogram *SP = Scope ? Scope->getSubprogram() : nullptr;
15
'?' condition is false
16
'SP' initialized to a null pointer value
1876
1877 // Scope and SP could be the same MDNode and we don't want to skip
1878 // validation in that case
1879 if (SP && ((Scope != SP) && !Seen.insert(SP).second))
1880 continue;
1881
1882 // FIXME: Once N is canonical, check "SP == &N".
1883 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)
17
Within the expansion of the macro 'Assert':
a
Called C++ object pointer is null
1884 "!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)
1885 &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)
;
1886 }
1887}
1888
1889// verifyBasicBlock - Verify that a basic block is well formed...
1890//
1891void Verifier::visitBasicBlock(BasicBlock &BB) {
1892 InstsInThisBlock.clear();
1893
1894 // Ensure that basic blocks have terminators!
1895 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)
;
1896
1897 // Check constraints that this basic block imposes on all of the PHI nodes in
1898 // it.
1899 if (isa<PHINode>(BB.front())) {
1900 SmallVector<BasicBlock*, 8> Preds(pred_begin(&BB), pred_end(&BB));
1901 SmallVector<std::pair<BasicBlock*, Value*>, 8> Values;
1902 std::sort(Preds.begin(), Preds.end());
1903 PHINode *PN;
1904 for (BasicBlock::iterator I = BB.begin(); (PN = dyn_cast<PHINode>(I));++I) {
1905 // Ensure that PHI nodes have at least one entry!
1906 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)
1907 "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)
1908 "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)
1909 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)
;
1910 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)
1911 "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)
1912 "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)
1913 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)
;
1914
1915 // Get and sort all incoming values in the PHI node...
1916 Values.clear();
1917 Values.reserve(PN->getNumIncomingValues());
1918 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
1919 Values.push_back(std::make_pair(PN->getIncomingBlock(i),
1920 PN->getIncomingValue(i)));
1921 std::sort(Values.begin(), Values.end());
1922
1923 for (unsigned i = 0, e = Values.size(); i != e; ++i) {
1924 // Check to make sure that if there is more than one entry for a
1925 // particular basic block in this PHI node, that the incoming values are
1926 // all identical.
1927 //
1928 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)
1929 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)
1930 "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)
1931 "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)
1932 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)
;
1933
1934 // Check to make sure that the predecessors and PHI node entries are
1935 // matched up.
1936 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)
1937 "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)
1938 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)
;
1939 }
1940 }
1941 }
1942
1943 // Check that all instructions have their parent pointers set up correctly.
1944 for (auto &I : BB)
1945 {
1946 Assert(I.getParent() == &BB, "Instruction has bogus parent pointer!")do { if (!(I.getParent() == &BB)) { CheckFailed("Instruction has bogus parent pointer!"
); return; } } while (0)
;
1947 }
1948}
1949
1950void Verifier::visitTerminatorInst(TerminatorInst &I) {
1951 // Ensure that terminators only exist at the end of the basic block.
1952 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)
1953 "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)
;
1954 visitInstruction(I);
1955}
1956
1957void Verifier::visitBranchInst(BranchInst &BI) {
1958 if (BI.isConditional()) {
1959 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)
1960 "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)
;
1961 }
1962 visitTerminatorInst(BI);
1963}
1964
1965void Verifier::visitReturnInst(ReturnInst &RI) {
1966 Function *F = RI.getParent()->getParent();
1967 unsigned N = RI.getNumOperands();
1968 if (F->getReturnType()->isVoidTy())
1969 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)
1970 "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)
1971 "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)
1972 &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)
;
1973 else
1974 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)
1975 "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)
1976 "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)
1977 &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)
;
1978
1979 // Check to make sure that the return value has necessary properties for
1980 // terminators...
1981 visitTerminatorInst(RI);
1982}
1983
1984void Verifier::visitSwitchInst(SwitchInst &SI) {
1985 // Check to make sure that all of the constants in the switch instruction
1986 // have the same type as the switched-on value.
1987 Type *SwitchTy = SI.getCondition()->getType();
1988 SmallPtrSet<ConstantInt*, 32> Constants;
1989 for (SwitchInst::CaseIt i = SI.case_begin(), e = SI.case_end(); i != e; ++i) {
1990 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)
1991 "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)
;
1992 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)
1993 "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)
;
1994 }
1995
1996 visitTerminatorInst(SI);
1997}
1998
1999void Verifier::visitIndirectBrInst(IndirectBrInst &BI) {
2000 Assert(BI.getAddress()->getType()->isPointerTy(),do { if (!(BI.getAddress()->getType()->isPointerTy())) {
CheckFailed("Indirectbr operand must have pointer type!", &
BI); return; } } while (0)
2001 "Indirectbr operand must have pointer type!", &BI)do { if (!(BI.getAddress()->getType()->isPointerTy())) {
CheckFailed("Indirectbr operand must have pointer type!", &
BI); return; } } while (0)
;
2002 for (unsigned i = 0, e = BI.getNumDestinations(); i != e; ++i)
2003 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)
2004 "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)
;
2005
2006 visitTerminatorInst(BI);
2007}
2008
2009void Verifier::visitSelectInst(SelectInst &SI) {
2010 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)
2011 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)
2012 "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)
;
2013
2014 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)
2015 "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)
;
2016 visitInstruction(SI);
2017}
2018
2019/// visitUserOp1 - User defined operators shouldn't live beyond the lifetime of
2020/// a pass, if any exist, it's an error.
2021///
2022void Verifier::visitUserOp1(Instruction &I) {
2023 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)
;
2024}
2025
2026void Verifier::visitTruncInst(TruncInst &I) {
2027 // Get the source and destination types
2028 Type *SrcTy = I.getOperand(0)->getType();
2029 Type *DestTy = I.getType();
2030
2031 // Get the size of the types in bits, we'll need this later
2032 unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
2033 unsigned DestBitSize = DestTy->getScalarSizeInBits();
2034
2035 Assert(SrcTy->isIntOrIntVectorTy(), "Trunc only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("Trunc only operates on integer"
, &I); return; } } while (0)
;
2036 Assert(DestTy->isIntOrIntVectorTy(), "Trunc only produces integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("Trunc only produces integer"
, &I); return; } } while (0)
;
2037 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)
2038 "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)
;
2039 Assert(SrcBitSize > DestBitSize, "DestTy too big for Trunc", &I)do { if (!(SrcBitSize > DestBitSize)) { CheckFailed("DestTy too big for Trunc"
, &I); return; } } while (0)
;
2040
2041 visitInstruction(I);
2042}
2043
2044void Verifier::visitZExtInst(ZExtInst &I) {
2045 // Get the source and destination types
2046 Type *SrcTy = I.getOperand(0)->getType();
2047 Type *DestTy = I.getType();
2048
2049 // Get the size of the types in bits, we'll need this later
2050 Assert(SrcTy->isIntOrIntVectorTy(), "ZExt only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("ZExt only operates on integer"
, &I); return; } } while (0)
;
2051 Assert(DestTy->isIntOrIntVectorTy(), "ZExt only produces an integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("ZExt only produces an integer"
, &I); return; } } while (0)
;
2052 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)
2053 "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)
;
2054 unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
2055 unsigned DestBitSize = DestTy->getScalarSizeInBits();
2056
2057 Assert(SrcBitSize < DestBitSize, "Type too small for ZExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("Type too small for ZExt"
, &I); return; } } while (0)
;
2058
2059 visitInstruction(I);
2060}
2061
2062void Verifier::visitSExtInst(SExtInst &I) {
2063 // Get the source and destination types
2064 Type *SrcTy = I.getOperand(0)->getType();
2065 Type *DestTy = I.getType();
2066
2067 // Get the size of the types in bits, we'll need this later
2068 unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
2069 unsigned DestBitSize = DestTy->getScalarSizeInBits();
2070
2071 Assert(SrcTy->isIntOrIntVectorTy(), "SExt only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("SExt only operates on integer"
, &I); return; } } while (0)
;
2072 Assert(DestTy->isIntOrIntVectorTy(), "SExt only produces an integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("SExt only produces an integer"
, &I); return; } } while (0)
;
2073 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)
2074 "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)
;
2075 Assert(SrcBitSize < DestBitSize, "Type too small for SExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("Type too small for SExt"
, &I); return; } } while (0)
;
2076
2077 visitInstruction(I);
2078}
2079
2080void Verifier::visitFPTruncInst(FPTruncInst &I) {
2081 // Get the source and destination types
2082 Type *SrcTy = I.getOperand(0)->getType();
2083 Type *DestTy = I.getType();
2084 // Get the size of the types in bits, we'll need this later
2085 unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
2086 unsigned DestBitSize = DestTy->getScalarSizeInBits();
2087
2088 Assert(SrcTy->isFPOrFPVectorTy(), "FPTrunc only operates on FP", &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPTrunc only operates on FP"
, &I); return; } } while (0)
;
2089 Assert(DestTy->isFPOrFPVectorTy(), "FPTrunc only produces an FP", &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("FPTrunc only produces an FP"
, &I); return; } } while (0)
;
2090 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)
2091 "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)
;
2092 Assert(SrcBitSize > DestBitSize, "DestTy too big for FPTrunc", &I)do { if (!(SrcBitSize > DestBitSize)) { CheckFailed("DestTy too big for FPTrunc"
, &I); return; } } while (0)
;
2093
2094 visitInstruction(I);
2095}
2096
2097void Verifier::visitFPExtInst(FPExtInst &I) {
2098 // Get the source and destination types
2099 Type *SrcTy = I.getOperand(0)->getType();
2100 Type *DestTy = I.getType();
2101
2102 // Get the size of the types in bits, we'll need this later
2103 unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
2104 unsigned DestBitSize = DestTy->getScalarSizeInBits();
2105
2106 Assert(SrcTy->isFPOrFPVectorTy(), "FPExt only operates on FP", &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPExt only operates on FP"
, &I); return; } } while (0)
;
2107 Assert(DestTy->isFPOrFPVectorTy(), "FPExt only produces an FP", &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("FPExt only produces an FP"
, &I); return; } } while (0)
;
2108 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)
2109 "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)
;
2110 Assert(SrcBitSize < DestBitSize, "DestTy too small for FPExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("DestTy too small for FPExt"
, &I); return; } } while (0)
;
2111
2112 visitInstruction(I);
2113}
2114
2115void Verifier::visitUIToFPInst(UIToFPInst &I) {
2116 // Get the source and destination types
2117 Type *SrcTy = I.getOperand(0)->getType();
2118 Type *DestTy = I.getType();
2119
2120 bool SrcVec = SrcTy->isVectorTy();
2121 bool DstVec = DestTy->isVectorTy();
2122
2123 Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("UIToFP source and dest must both be vector or scalar"
, &I); return; } } while (0)
2124 "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)
;
2125 Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("UIToFP source must be integer or integer vector"
, &I); return; } } while (0)
2126 "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)
;
2127 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)
2128 &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("UIToFP result must be FP or FP vector"
, &I); return; } } while (0)
;
2129
2130 if (SrcVec && DstVec)
2131 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)
2132 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)
2133 "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)
;
2134
2135 visitInstruction(I);
2136}
2137
2138void Verifier::visitSIToFPInst(SIToFPInst &I) {
2139 // Get the source and destination types
2140 Type *SrcTy = I.getOperand(0)->getType();
2141 Type *DestTy = I.getType();
2142
2143 bool SrcVec = SrcTy->isVectorTy();
2144 bool DstVec = DestTy->isVectorTy();
2145
2146 Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("SIToFP source and dest must both be vector or scalar"
, &I); return; } } while (0)
2147 "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)
;
2148 Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("SIToFP source must be integer or integer vector"
, &I); return; } } while (0)
2149 "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)
;
2150 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)
2151 &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("SIToFP result must be FP or FP vector"
, &I); return; } } while (0)
;
2152
2153 if (SrcVec && DstVec)
2154 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)
2155 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)
2156 "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)
;
2157
2158 visitInstruction(I);
2159}
2160
2161void Verifier::visitFPToUIInst(FPToUIInst &I) {
2162 // Get the source and destination types
2163 Type *SrcTy = I.getOperand(0)->getType();
2164 Type *DestTy = I.getType();
2165
2166 bool SrcVec = SrcTy->isVectorTy();
2167 bool DstVec = DestTy->isVectorTy();
2168
2169 Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("FPToUI source and dest must both be vector or scalar"
, &I); return; } } while (0)
2170 "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)
;
2171 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)
2172 &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToUI source must be FP or FP vector"
, &I); return; } } while (0)
;
2173 Assert(DestTy->isIntOrIntVectorTy(),do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToUI result must be integer or integer vector"
, &I); return; } } while (0)
2174 "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)
;
2175
2176 if (SrcVec && DstVec)
2177 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)
2178 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)
2179 "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)
;
2180
2181 visitInstruction(I);
2182}
2183
2184void Verifier::visitFPToSIInst(FPToSIInst &I) {
2185 // Get the source and destination types
2186 Type *SrcTy = I.getOperand(0)->getType();
2187 Type *DestTy = I.getType();
2188
2189 bool SrcVec = SrcTy->isVectorTy();
2190 bool DstVec = DestTy->isVectorTy();
2191
2192 Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("FPToSI source and dest must both be vector or scalar"
, &I); return; } } while (0)
2193 "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)
;
2194 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)
2195 &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToSI source must be FP or FP vector"
, &I); return; } } while (0)
;
2196 Assert(DestTy->isIntOrIntVectorTy(),do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToSI result must be integer or integer vector"
, &I); return; } } while (0)
2197 "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)
;
2198
2199 if (SrcVec && DstVec)
2200 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)
2201 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)
2202 "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)
;
2203
2204 visitInstruction(I);
2205}
2206
2207void Verifier::visitPtrToIntInst(PtrToIntInst &I) {
2208 // Get the source and destination types
2209 Type *SrcTy = I.getOperand(0)->getType();
2210 Type *DestTy = I.getType();
2211
2212 Assert(SrcTy->getScalarType()->isPointerTy(),do { if (!(SrcTy->getScalarType()->isPointerTy())) { CheckFailed
("PtrToInt source must be pointer", &I); return; } } while
(0)
2213 "PtrToInt source must be pointer", &I)do { if (!(SrcTy->getScalarType()->isPointerTy())) { CheckFailed
("PtrToInt source must be pointer", &I); return; } } while
(0)
;
2214 Assert(DestTy->getScalarType()->isIntegerTy(),do { if (!(DestTy->getScalarType()->isIntegerTy())) { CheckFailed
("PtrToInt result must be integral", &I); return; } } while
(0)
2215 "PtrToInt result must be integral", &I)do { if (!(DestTy->getScalarType()->isIntegerTy())) { CheckFailed
("PtrToInt result must be integral", &I); return; } } while
(0)
;
2216 Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(), "PtrToInt type mismatch",do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("PtrToInt type mismatch", &I); return; } }
while (0)
2217 &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("PtrToInt type mismatch", &I); return; } }
while (0)
;
2218
2219 if (SrcTy->isVectorTy()) {
2220 VectorType *VSrc = dyn_cast<VectorType>(SrcTy);
2221 VectorType *VDest = dyn_cast<VectorType>(DestTy);
2222 Assert(VSrc->getNumElements() == VDest->getNumElements(),do { if (!(VSrc->getNumElements() == VDest->getNumElements
())) { CheckFailed("PtrToInt Vector width mismatch", &I);
return; } } while (0)
2223 "PtrToInt Vector width mismatch", &I)do { if (!(VSrc->getNumElements() == VDest->getNumElements
())) { CheckFailed("PtrToInt Vector width mismatch", &I);
return; } } while (0)
;
2224 }
2225
2226 visitInstruction(I);
2227}
2228
2229void Verifier::visitIntToPtrInst(IntToPtrInst &I) {
2230 // Get the source and destination types
2231 Type *SrcTy = I.getOperand(0)->getType();
2232 Type *DestTy = I.getType();
2233
2234 Assert(SrcTy->getScalarType()->isIntegerTy(),do { if (!(SrcTy->getScalarType()->isIntegerTy())) { CheckFailed
("IntToPtr source must be an integral", &I); return; } } while
(0)
2235 "IntToPtr source must be an integral", &I)do { if (!(SrcTy->getScalarType()->isIntegerTy())) { CheckFailed
("IntToPtr source must be an integral", &I); return; } } while
(0)
;
2236 Assert(DestTy->getScalarType()->isPointerTy(),do { if (!(DestTy->getScalarType()->isPointerTy())) { CheckFailed
("IntToPtr result must be a pointer", &I); return; } } while
(0)
2237 "IntToPtr result must be a pointer", &I)do { if (!(DestTy->getScalarType()->isPointerTy())) { CheckFailed
("IntToPtr result must be a pointer", &I); return; } } while
(0)
;
2238 Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(), "IntToPtr type mismatch",do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("IntToPtr type mismatch", &I); return; } }
while (0)
2239 &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("IntToPtr type mismatch", &I); return; } }
while (0)
;
2240 if (SrcTy->isVectorTy()) {
2241 VectorType *VSrc = dyn_cast<VectorType>(SrcTy);
2242 VectorType *VDest = dyn_cast<VectorType>(DestTy);
2243 Assert(VSrc->getNumElements() == VDest->getNumElements(),do { if (!(VSrc->getNumElements() == VDest->getNumElements
())) { CheckFailed("IntToPtr Vector width mismatch", &I);
return; } } while (0)
2244 "IntToPtr Vector width mismatch", &I)do { if (!(VSrc->getNumElements() == VDest->getNumElements
())) { CheckFailed("IntToPtr Vector width mismatch", &I);
return; } } while (0)
;
2245 }
2246 visitInstruction(I);
2247}
2248
2249void Verifier::visitBitCastInst(BitCastInst &I) {
2250 Assert(do { if (!(CastInst::castIsValid(Instruction::BitCast, I.getOperand
(0), I.getType()))) { CheckFailed("Invalid bitcast", &I);
return; } } while (0)
2251 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)
2252 "Invalid bitcast", &I)do { if (!(CastInst::castIsValid(Instruction::BitCast, I.getOperand
(0), I.getType()))) { CheckFailed("Invalid bitcast", &I);
return; } } while (0)
;
2253 visitInstruction(I);
2254}
2255
2256void Verifier::visitAddrSpaceCastInst(AddrSpaceCastInst &I) {
2257 Type *SrcTy = I.getOperand(0)->getType();
2258 Type *DestTy = I.getType();
2259
2260 Assert(SrcTy->isPtrOrPtrVectorTy(), "AddrSpaceCast source must be a pointer",do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast source must be a pointer"
, &I); return; } } while (0)
2261 &I)do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast source must be a pointer"
, &I); return; } } while (0)
;
2262 Assert(DestTy->isPtrOrPtrVectorTy(), "AddrSpaceCast result must be a pointer",do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast result must be a pointer"
, &I); return; } } while (0)
2263 &I)do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast result must be a pointer"
, &I); return; } } while (0)
;
2264 Assert(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace(),do { if (!(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace
())) { CheckFailed("AddrSpaceCast must be between different address spaces"
, &I); return; } } while (0)
2265 "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)
;
2266 if (SrcTy->isVectorTy())
2267 Assert(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements(),do { if (!(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements
())) { CheckFailed("AddrSpaceCast vector pointer number of elements mismatch"
, &I); return; } } while (0)
2268 "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)
;
2269 visitInstruction(I);
2270}
2271
2272/// visitPHINode - Ensure that a PHI node is well formed.
2273///
2274void Verifier::visitPHINode(PHINode &PN) {
2275 // Ensure that the PHI nodes are all grouped together at the top of the block.
2276 // This can be tested by checking whether the instruction before this is
2277 // either nonexistent (because this is begin()) or is a PHI node. If not,
2278 // then there is some other instruction before a PHI.
2279 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)
2280 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)
2281 "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)
;
2282
2283 // Check that a PHI doesn't yield a Token.
2284 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)
;
2285
2286 // Check that all of the values of the PHI node have the same type as the
2287 // result, and that the incoming blocks are really basic blocks.
2288 for (Value *IncValue : PN.incoming_values()) {
2289 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)
2290 "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)
;
2291 }
2292
2293 // All other PHI node constraints are checked in the visitBasicBlock method.
2294
2295 visitInstruction(PN);
2296}
2297
2298void Verifier::VerifyCallSite(CallSite CS) {
2299 Instruction *I = CS.getInstruction();
2300
2301 Assert(CS.getCalledValue()->getType()->isPointerTy(),do { if (!(CS.getCalledValue()->getType()->isPointerTy(
))) { CheckFailed("Called function must be a pointer!", I); return
; } } while (0)
2302 "Called function must be a pointer!", I)do { if (!(CS.getCalledValue()->getType()->isPointerTy(
))) { CheckFailed("Called function must be a pointer!", I); return
; } } while (0)
;
2303 PointerType *FPTy = cast<PointerType>(CS.getCalledValue()->getType());
2304
2305 Assert(FPTy->getElementType()->isFunctionTy(),do { if (!(FPTy->getElementType()->isFunctionTy())) { CheckFailed
("Called function is not pointer to function type!", I); return
; } } while (0)
2306 "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)
;
2307
2308 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)
2309 "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)
;
2310
2311 FunctionType *FTy = CS.getFunctionType();
2312
2313 // Verify that the correct number of arguments are being passed
2314 if (FTy->isVarArg())
2315 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)
2316 "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)
;
2317 else
2318 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)
2319 "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)
;
2320
2321 // Verify that all arguments to the call match the function type.
2322 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
2323 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)
2324 "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)
2325 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)
;
2326
2327 AttributeSet Attrs = CS.getAttributes();
2328
2329 Assert(VerifyAttributeCount(Attrs, CS.arg_size()),do { if (!(VerifyAttributeCount(Attrs, CS.arg_size()))) { CheckFailed
("Attribute after last parameter!", I); return; } } while (0)
2330 "Attribute after last parameter!", I)do { if (!(VerifyAttributeCount(Attrs, CS.arg_size()))) { CheckFailed
("Attribute after last parameter!", I); return; } } while (0)
;
2331
2332 // Verify call attributes.
2333 VerifyFunctionAttrs(FTy, Attrs, I);
2334
2335 // Conservatively check the inalloca argument.
2336 // We have a bug if we can find that there is an underlying alloca without
2337 // inalloca.
2338 if (CS.hasInAllocaArgument()) {
2339 Value *InAllocaArg = CS.getArgument(FTy->getNumParams() - 1);
2340 if (auto AI = dyn_cast<AllocaInst>(InAllocaArg->stripInBoundsOffsets()))
2341 Assert(AI->isUsedWithInAlloca(),do { if (!(AI->isUsedWithInAlloca())) { CheckFailed("inalloca argument for call has mismatched alloca"
, AI, I); return; } } while (0)
2342 "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)
;
2343 }
2344
2345 if (FTy->isVarArg()) {
2346 // FIXME? is 'nest' even legal here?
2347 bool SawNest = false;
2348 bool SawReturned = false;
2349
2350 for (unsigned Idx = 1; Idx < 1 + FTy->getNumParams(); ++Idx) {
2351 if (Attrs.hasAttribute(Idx, Attribute::Nest))
2352 SawNest = true;
2353 if (Attrs.hasAttribute(Idx, Attribute::Returned))
2354 SawReturned = true;
2355 }
2356
2357 // Check attributes on the varargs part.
2358 for (unsigned Idx = 1 + FTy->getNumParams(); Idx <= CS.arg_size(); ++Idx) {
2359 Type *Ty = CS.getArgument(Idx-1)->getType();
2360 VerifyParameterAttrs(Attrs, Idx, Ty, false, I);
2361
2362 if (Attrs.hasAttribute(Idx, Attribute::Nest)) {
2363 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)
;
2364 SawNest = true;
2365 }
2366
2367 if (Attrs.hasAttribute(Idx, Attribute::Returned)) {
2368 Assert(!SawReturned, "More than one parameter has attribute returned!",do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!"
, I); return; } } while (0)
2369 I)do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!"
, I); return; } } while (0)
;
2370 Assert(Ty->canLosslesslyBitCastTo(FTy->getReturnType()),do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType
()))) { CheckFailed("Incompatible argument and return types for 'returned' "
"attribute", I); return; } } while (0)
2371 "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)
2372 "attribute",do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType
()))) { CheckFailed("Incompatible argument and return types for 'returned' "
"attribute", I); return; } } while (0)
2373 I)do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType
()))) { CheckFailed("Incompatible argument and return types for 'returned' "
"attribute", I); return; } } while (0)
;
2374 SawReturned = true;
2375 }
2376
2377 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)
2378 "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)
;
2379
2380 if (Attrs.hasAttribute(Idx, Attribute::InAlloca))
2381 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)
;
2382 }
2383 }
2384
2385 // Verify that there's no metadata unless it's a direct call to an intrinsic.
2386 if (CS.getCalledFunction() == nullptr ||
2387 !CS.getCalledFunction()->getName().startswith("llvm.")) {
2388 for (Type *ParamTy : FTy->params()) {
2389 Assert(!ParamTy->isMetadataTy(),do { if (!(!ParamTy->isMetadataTy())) { CheckFailed("Function has metadata parameter but isn't an intrinsic"
, I); return; } } while (0)
2390 "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)
;
2391 Assert(!ParamTy->isTokenTy(),do { if (!(!ParamTy->isTokenTy())) { CheckFailed("Function has token parameter but isn't an intrinsic"
, I); return; } } while (0)
2392 "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)
;
2393 }
2394 }
2395
2396 // Verify that indirect calls don't return tokens.
2397 if (CS.getCalledFunction() == nullptr)
2398 Assert(!FTy->getReturnType()->isTokenTy(),do { if (!(!FTy->getReturnType()->isTokenTy())) { CheckFailed
("Return type cannot be token for indirect call!"); return; }
} while (0)
2399 "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)
;
2400
2401 if (Function *F = CS.getCalledFunction())
2402 if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID())
2403 visitIntrinsicCallSite(ID, CS);
2404
2405 // Verify that a callsite has at most one "deopt" and one "funclet" operand
2406 // bundle.
2407 bool FoundDeoptBundle = false, FoundFuncletBundle = false;
2408 for (unsigned i = 0, e = CS.getNumOperandBundles(); i < e; ++i) {
2409 OperandBundleUse BU = CS.getOperandBundleAt(i);
2410 uint32_t Tag = BU.getTagID();
2411 if (Tag == LLVMContext::OB_deopt) {
2412 Assert(!FoundDeoptBundle, "Multiple deopt operand bundles", I)do { if (!(!FoundDeoptBundle)) { CheckFailed("Multiple deopt operand bundles"
, I); return; } } while (0)
;
2413 FoundDeoptBundle = true;
2414 }
2415 if (Tag == LLVMContext::OB_funclet) {
2416 Assert(!FoundFuncletBundle, "Multiple funclet operand bundles", I)do { if (!(!FoundFuncletBundle)) { CheckFailed("Multiple funclet operand bundles"
, I); return; } } while (0)
;
2417 FoundFuncletBundle = true;
2418 Assert(BU.Inputs.size() == 1,do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one funclet bundle operand"
, I); return; } } while (0)
2419 "Expected exactly one funclet bundle operand", I)do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one funclet bundle operand"
, I); return; } } while (0)
;
2420 Assert(isa<FuncletPadInst>(BU.Inputs.front()),do { if (!(isa<FuncletPadInst>(BU.Inputs.front()))) { CheckFailed
("Funclet bundle operands should correspond to a FuncletPadInst"
, I); return; } } while (0)
2421 "Funclet bundle operands should correspond to a FuncletPadInst",do { if (!(isa<FuncletPadInst>(BU.Inputs.front()))) { CheckFailed
("Funclet bundle operands should correspond to a FuncletPadInst"
, I); return; } } while (0)
2422 I)do { if (!(isa<FuncletPadInst>(BU.Inputs.front()))) { CheckFailed
("Funclet bundle operands should correspond to a FuncletPadInst"
, I); return; } } while (0)
;
2423 }
2424 }
2425
2426 visitInstruction(*I);
2427}
2428
2429/// Two types are "congruent" if they are identical, or if they are both pointer
2430/// types with different pointee types and the same address space.
2431static bool isTypeCongruent(Type *L, Type *R) {
2432 if (L == R)
2433 return true;
2434 PointerType *PL = dyn_cast<PointerType>(L);
2435 PointerType *PR = dyn_cast<PointerType>(R);
2436 if (!PL || !PR)
2437 return false;
2438 return PL->getAddressSpace() == PR->getAddressSpace();
2439}
2440
2441static AttrBuilder getParameterABIAttributes(int I, AttributeSet Attrs) {
2442 static const Attribute::AttrKind ABIAttrs[] = {
2443 Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca,
2444 Attribute::InReg, Attribute::Returned};
2445 AttrBuilder Copy;
2446 for (auto AK : ABIAttrs) {
2447 if (Attrs.hasAttribute(I + 1, AK))
2448 Copy.addAttribute(AK);
2449 }
2450 if (Attrs.hasAttribute(I + 1, Attribute::Alignment))
2451 Copy.addAlignmentAttr(Attrs.getParamAlignment(I + 1));
2452 return Copy;
2453}
2454
2455void Verifier::verifyMustTailCall(CallInst &CI) {
2456 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)
;
2457
2458 // - The caller and callee prototypes must match. Pointer types of
2459 // parameters or return types may differ in pointee type, but not
2460 // address space.
2461 Function *F = CI.getParent()->getParent();
2462 FunctionType *CallerTy = F->getFunctionType();
2463 FunctionType *CalleeTy = CI.getFunctionType();
2464 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)
2465 "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)
;
2466 Assert(CallerTy->isVarArg() == CalleeTy->isVarArg(),do { if (!(CallerTy->isVarArg() == CalleeTy->isVarArg()
)) { CheckFailed("cannot guarantee tail call due to mismatched varargs"
, &CI); return; } } while (0)
2467 "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)
;
2468 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)
2469 "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)
;
2470 for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) {
2471 Assert(do { if (!(isTypeCongruent(CallerTy->getParamType(I), CalleeTy
->getParamType(I)))) { CheckFailed("cannot guarantee tail call due to mismatched parameter types"
, &CI); return; } } while (0)
2472 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)
2473 "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)
;
2474 }
2475
2476 // - The calling conventions of the caller and callee must match.
2477 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)
2478 "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)
;
2479
2480 // - All ABI-impacting function attributes, such as sret, byval, inreg,
2481 // returned, and inalloca, must match.
2482 AttributeSet CallerAttrs = F->getAttributes();
2483 AttributeSet CalleeAttrs = CI.getAttributes();
2484 for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) {
2485 AttrBuilder CallerABIAttrs = getParameterABIAttributes(I, CallerAttrs);
2486 AttrBuilder CalleeABIAttrs = getParameterABIAttributes(I, CalleeAttrs);
2487 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)
2488 "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)
2489 "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)
2490 &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)
;
2491 }
2492
2493 // - The call must immediately precede a :ref:`ret <i_ret>` instruction,
2494 // or a pointer bitcast followed by a ret instruction.
2495 // - The ret instruction must return the (possibly bitcasted) value
2496 // produced by the call or void.
2497 Value *RetVal = &CI;
2498 Instruction *Next = CI.getNextNode();
2499
2500 // Handle the optional bitcast.
2501 if (BitCastInst *BI = dyn_cast_or_null<BitCastInst>(Next)) {
2502 Assert(BI->getOperand(0) == RetVal,do { if (!(BI->getOperand(0) == RetVal)) { CheckFailed("bitcast following musttail call must use the call"
, BI); return; } } while (0)
2503 "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)
;
2504 RetVal = BI;
2505 Next = BI->getNextNode();
2506 }
2507
2508 // Check the return.
2509 ReturnInst *Ret = dyn_cast_or_null<ReturnInst>(Next);
2510 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)
2511 &CI)do { if (!(Ret)) { CheckFailed("musttail call must be precede a ret with an optional bitcast"
, &CI); return; } } while (0)
;
2512 Assert(!Ret->getReturnValue() || Ret->getReturnValue() == RetVal,do { if (!(!Ret->getReturnValue() || Ret->getReturnValue
() == RetVal)) { CheckFailed("musttail call result must be returned"
, Ret); return; } } while (0)
2513 "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)
;
2514}
2515
2516void Verifier::visitCallInst(CallInst &CI) {
2517 VerifyCallSite(&CI);
2518
2519 if (CI.isMustTailCall())
2520 verifyMustTailCall(CI);
2521}
2522
2523void Verifier::visitInvokeInst(InvokeInst &II) {
2524 VerifyCallSite(&II);
2525
2526 // Verify that the first non-PHI instruction of the unwind destination is an
2527 // exception handling instruction.
2528 Assert(do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!"
, &II); return; } } while (0)
2529 II.getUnwindDest()->isEHPad(),do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!"
, &II); return; } } while (0)
2530 "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)
2531 &II)do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!"
, &II); return; } } while (0)
;
2532
2533 visitTerminatorInst(II);
2534}
2535
2536/// visitBinaryOperator - Check that both arguments to the binary operator are
2537/// of the same type!
2538///
2539void Verifier::visitBinaryOperator(BinaryOperator &B) {
2540 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)
2541 "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)
;
2542
2543 switch (B.getOpcode()) {
2544 // Check that integer arithmetic operators are only used with
2545 // integral operands.
2546 case Instruction::Add:
2547 case Instruction::Sub:
2548 case Instruction::Mul:
2549 case Instruction::SDiv:
2550 case Instruction::UDiv:
2551 case Instruction::SRem:
2552 case Instruction::URem:
2553 Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed
("Integer arithmetic operators only work with integral types!"
, &B); return; } } while (0)
2554 "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)
;
2555 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)
2556 "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)
2557 "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)
2558 &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)
;
2559 break;
2560 // Check that floating-point arithmetic operators are only used with
2561 // floating-point operands.
2562 case Instruction::FAdd:
2563 case Instruction::FSub:
2564 case Instruction::FMul:
2565 case Instruction::FDiv:
2566 case Instruction::FRem:
2567 Assert(B.getType()->isFPOrFPVectorTy(),do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed
("Floating-point arithmetic operators only work with " "floating-point types!"
, &B); return; } } while (0)
2568 "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)
2569 "floating-point types!",do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed
("Floating-point arithmetic operators only work with " "floating-point types!"
, &B); return; } } while (0)
2570 &B)do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed
("Floating-point arithmetic operators only work with " "floating-point types!"
, &B); return; } } while (0)
;
2571 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)
2572 "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)
2573 "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)
2574 &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)
;
2575 break;
2576 // Check that logical operators are only used with integral operands.
2577 case Instruction::And:
2578 case Instruction::Or:
2579 case Instruction::Xor:
2580 Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed
("Logical operators only work with integral types!", &B);
return; } } while (0)
2581 "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)
;
2582 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)
2583 "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)
2584 &B)do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed
("Logical operators must have same type for operands and result!"
, &B); return; } } while (0)
;
2585 break;
2586 case Instruction::Shl:
2587 case Instruction::LShr:
2588 case Instruction::AShr:
2589 Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed
("Shifts only work with integral types!", &B); return; } }
while (0)
2590 "Shifts only work with integral types!", &B)do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed
("Shifts only work with integral types!", &B); return; } }
while (0)
;
2591 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)
2592 "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)
;
2593 break;
2594 default:
2595 llvm_unreachable("Unknown BinaryOperator opcode!")::llvm::llvm_unreachable_internal("Unknown BinaryOperator opcode!"
, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/lib/IR/Verifier.cpp"
, 2595)
;
2596 }
2597
2598 visitInstruction(B);
2599}
2600
2601void Verifier::visitICmpInst(ICmpInst &IC) {
2602 // Check that the operands are the same type
2603 Type *Op0Ty = IC.getOperand(0)->getType();
2604 Type *Op1Ty = IC.getOperand(1)->getType();
2605 Assert(Op0Ty == Op1Ty,do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to ICmp instruction are not of the same type!"
, &IC); return; } } while (0)
2606 "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)
;
2607 // Check that the operands are the right type
2608 Assert(Op0Ty->isIntOrIntVectorTy() || Op0Ty->getScalarType()->isPointerTy(),do { if (!(Op0Ty->isIntOrIntVectorTy() || Op0Ty->getScalarType
()->isPointerTy())) { CheckFailed("Invalid operand types for ICmp instruction"
, &IC); return; } } while (0)
2609 "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)
;
2610 // Check that the predicate is valid.
2611 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)
2612 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)
2613 "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)
;
2614
2615 visitInstruction(IC);
2616}
2617
2618void Verifier::visitFCmpInst(FCmpInst &FC) {
2619 // Check that the operands are the same type
2620 Type *Op0Ty = FC.getOperand(0)->getType();
2621 Type *Op1Ty = FC.getOperand(1)->getType();
2622 Assert(Op0Ty == Op1Ty,do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to FCmp instruction are not of the same type!"
, &FC); return; } } while (0)
2623 "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)
;
2624 // Check that the operands are the right type
2625 Assert(Op0Ty->isFPOrFPVectorTy(),do { if (!(Op0Ty->isFPOrFPVectorTy())) { CheckFailed("Invalid operand types for FCmp instruction"
, &FC); return; } } while (0)
2626 "Invalid operand types for FCmp instruction", &FC)do { if (!(Op0Ty->isFPOrFPVectorTy())) { CheckFailed("Invalid operand types for FCmp instruction"
, &FC); return; } } while (0)
;
2627 // Check that the predicate is valid.
2628 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)
2629 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)
2630 "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)
;
2631
2632 visitInstruction(FC);
2633}
2634
2635void Verifier::visitExtractElementInst(ExtractElementInst &EI) {
2636 Assert(do { if (!(ExtractElementInst::isValidOperands(EI.getOperand(
0), EI.getOperand(1)))) { CheckFailed("Invalid extractelement operands!"
, &EI); return; } } while (0)
2637 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)
2638 "Invalid extractelement operands!", &EI)do { if (!(ExtractElementInst::isValidOperands(EI.getOperand(
0), EI.getOperand(1)))) { CheckFailed("Invalid extractelement operands!"
, &EI); return; } } while (0)
;
2639 visitInstruction(EI);
2640}
2641
2642void Verifier::visitInsertElementInst(InsertElementInst &IE) {
2643 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)
2644 IE.getOperand(2)),do { if (!(InsertElementInst::isValidOperands(IE.getOperand(0
), IE.getOperand(1), IE.getOperand(2)))) { CheckFailed("Invalid insertelement operands!"
, &IE); return; } } while (0)
2645 "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)
;
2646 visitInstruction(IE);
2647}
2648
2649void Verifier::visitShuffleVectorInst(ShuffleVectorInst &SV) {
2650 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)
2651 SV.getOperand(2)),do { if (!(ShuffleVectorInst::isValidOperands(SV.getOperand(0
), SV.getOperand(1), SV.getOperand(2)))) { CheckFailed("Invalid shufflevector operands!"
, &SV); return; } } while (0)
2652 "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)
;
2653 visitInstruction(SV);
2654}
2655
2656void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
2657 Type *TargetTy = GEP.getPointerOperandType()->getScalarType();
2658
2659 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)
2660 "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)
;
2661 Assert(GEP.getSourceElementType()->isSized(), "GEP into unsized type!", &GEP)do { if (!(GEP.getSourceElementType()->isSized())) { CheckFailed
("GEP into unsized type!", &GEP); return; } } while (0)
;
2662 SmallVector<Value*, 16> Idxs(GEP.idx_begin(), GEP.idx_end());
2663 Type *ElTy =
2664 GetElementPtrInst::getIndexedType(GEP.getSourceElementType(), Idxs);
2665 Assert(ElTy, "Invalid indices for GEP pointer type!", &GEP)do { if (!(ElTy)) { CheckFailed("Invalid indices for GEP pointer type!"
, &GEP); return; } } while (0)
;
2666
2667 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)
2668 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)
2669 "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)
;
2670
2671 if (GEP.getType()->isVectorTy()) {
2672 // Additional checks for vector GEPs.
2673 unsigned GEPWidth = GEP.getType()->getVectorNumElements();
2674 if (GEP.getPointerOperandType()->isVectorTy())
2675 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)
2676 "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)
;
2677 for (unsigned i = 0, e = Idxs.size(); i != e; ++i) {
2678 Type *IndexTy = Idxs[i]->getType();
2679 if (IndexTy->isVectorTy()) {
2680 unsigned IndexWidth = IndexTy->getVectorNumElements();
2681 Assert(IndexWidth == GEPWidth, "Invalid GEP index vector width", &GEP)do { if (!(IndexWidth == GEPWidth)) { CheckFailed("Invalid GEP index vector width"
, &GEP); return; } } while (0)
;
2682 }
2683 Assert(IndexTy->getScalarType()->isIntegerTy(),do { if (!(IndexTy->getScalarType()->isIntegerTy())) { CheckFailed
("All GEP indices should be of integer type"); return; } } while
(0)
2684 "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)
;
2685 }
2686 }
2687 visitInstruction(GEP);
2688}
2689
2690static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {
2691 return A.getUpper() == B.getLower() || A.getLower() == B.getUpper();
2692}
2693
2694void Verifier::visitRangeMetadata(Instruction& I,
2695 MDNode* Range, Type* Ty) {
2696 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~svn257205/lib/IR/Verifier.cpp"
, 2698, __PRETTY_FUNCTION__))
2697 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~svn257205/lib/IR/Verifier.cpp"
, 2698, __PRETTY_FUNCTION__))
2698 "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~svn257205/lib/IR/Verifier.cpp"
, 2698, __PRETTY_FUNCTION__))
;
2699
2700 unsigned NumOperands = Range->getNumOperands();
2701 Assert(NumOperands % 2 == 0, "Unfinished range!", Range)do { if (!(NumOperands % 2 == 0)) { CheckFailed("Unfinished range!"
, Range); return; } } while (0)
;
2702 unsigned NumRanges = NumOperands / 2;
2703 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)
;
2704
2705 ConstantRange LastRange(1); // Dummy initial value
2706 for (unsigned i = 0; i < NumRanges; ++i) {
2707 ConstantInt *Low =
2708 mdconst::dyn_extract<ConstantInt>(Range->getOperand(2 * i));
2709 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)
;
2710 ConstantInt *High =
2711 mdconst::dyn_extract<ConstantInt>(Range->getOperand(2 * i + 1));
2712 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)
;
2713 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)
2714 "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)
;
2715
2716 APInt HighV = High->getValue();
2717 APInt LowV = Low->getValue();
2718 ConstantRange CurRange(LowV, HighV);
2719 Assert(!CurRange.isEmptySet() && !CurRange.isFullSet(),do { if (!(!CurRange.isEmptySet() && !CurRange.isFullSet
())) { CheckFailed("Range must not be empty!", Range); return
; } } while (0)
2720 "Range must not be empty!", Range)do { if (!(!CurRange.isEmptySet() && !CurRange.isFullSet
())) { CheckFailed("Range must not be empty!", Range); return
; } } while (0)
;
2721 if (i != 0) {
2722 Assert(CurRange.intersectWith(LastRange).isEmptySet(),do { if (!(CurRange.intersectWith(LastRange).isEmptySet())) {
CheckFailed("Intervals are overlapping", Range); return; } }
while (0)
2723 "Intervals are overlapping", Range)do { if (!(CurRange.intersectWith(LastRange).isEmptySet())) {
CheckFailed("Intervals are overlapping", Range); return; } }
while (0)
;
2724 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)
2725 Range)do { if (!(LowV.sgt(LastRange.getLower()))) { CheckFailed("Intervals are not in order"
, Range); return; } } while (0)
;
2726 Assert(!isContiguous(CurRange, LastRange), "Intervals are contiguous",do { if (!(!isContiguous(CurRange, LastRange))) { CheckFailed
("Intervals are contiguous", Range); return; } } while (0)
2727 Range)do { if (!(!isContiguous(CurRange, LastRange))) { CheckFailed
("Intervals are contiguous", Range); return; } } while (0)
;
2728 }
2729 LastRange = ConstantRange(LowV, HighV);
2730 }
2731 if (NumRanges > 2) {
2732 APInt FirstLow =
2733 mdconst::dyn_extract<ConstantInt>(Range->getOperand(0))->getValue();
2734 APInt FirstHigh =
2735 mdconst::dyn_extract<ConstantInt>(Range->getOperand(1))->getValue();
2736 ConstantRange FirstRange(FirstLow, FirstHigh);
2737 Assert(FirstRange.intersectWith(LastRange).isEmptySet(),do { if (!(FirstRange.intersectWith(LastRange).isEmptySet()))
{ CheckFailed("Intervals are overlapping", Range); return; }
} while (0)
2738 "Intervals are overlapping", Range)do { if (!(FirstRange.intersectWith(LastRange).isEmptySet()))
{ CheckFailed("Intervals are overlapping", Range); return; }
} while (0)
;
2739 Assert(!isContiguous(FirstRange, LastRange), "Intervals are contiguous",do { if (!(!isContiguous(FirstRange, LastRange))) { CheckFailed
("Intervals are contiguous", Range); return; } } while (0)
2740 Range)do { if (!(!isContiguous(FirstRange, LastRange))) { CheckFailed
("Intervals are contiguous", Range); return; } } while (0)
;
2741 }
2742}
2743
2744void Verifier::checkAtomicMemAccessSize(const Module *M, Type *Ty,
2745 const Instruction *I) {
2746 unsigned Size = M->getDataLayout().getTypeSizeInBits(Ty);
2747 Assert(Size >= 8, "atomic memory access' size must be byte-sized", Ty, I)do { if (!(Size >= 8)) { CheckFailed("atomic memory access' size must be byte-sized"
, Ty, I); return; } } while (0)
;
2748 Assert(!(Size & (Size - 1)),do { if (!(!(Size & (Size - 1)))) { CheckFailed("atomic memory access' operand must have a power-of-two size"
, Ty, I); return; } } while (0)
2749 "atomic memory access' operand must have a power-of-two size", Ty, I)do { if (!(!(Size & (Size - 1)))) { CheckFailed("atomic memory access' operand must have a power-of-two size"
, Ty, I); return; } } while (0)
;
2750}
2751
2752void Verifier::visitLoadInst(LoadInst &LI) {
2753 PointerType *PTy = dyn_cast<PointerType>(LI.getOperand(0)->getType());
2754 Assert(PTy, "Load operand must be a pointer.", &LI)do { if (!(PTy)) { CheckFailed("Load operand must be a pointer."
, &LI); return; } } while (0)
;
2755 Type *ElTy = LI.getType();
2756 Assert(LI.getAlignment() <= Value::MaximumAlignment,do { if (!(LI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &LI
); return; } } while (0)
2757 "huge alignment values are unsupported", &LI)do { if (!(LI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &LI
); return; } } while (0)
;
2758 if (LI.isAtomic()) {
2759 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)
2760 "Load cannot have Release ordering", &LI)do { if (!(LI.getOrdering() != Release && LI.getOrdering
() != AcquireRelease)) { CheckFailed("Load cannot have Release ordering"
, &LI); return; } } while (0)
;
2761 Assert(LI.getAlignment() != 0,do { if (!(LI.getAlignment() != 0)) { CheckFailed("Atomic load must specify explicit alignment"
, &LI); return; } } while (0)
2762 "Atomic load must specify explicit alignment", &LI)do { if (!(LI.getAlignment() != 0)) { CheckFailed("Atomic load must specify explicit alignment"
, &LI); return; } } while (0)
;
2763 Assert(ElTy->isIntegerTy() || ElTy->isPointerTy() ||do { if (!(ElTy->isIntegerTy() || ElTy->isPointerTy() ||
ElTy->isFloatingPointTy())) { CheckFailed("atomic load operand must have integer, pointer, or floating point "
"type!", ElTy, &LI); return; } } while (0)
2764 ElTy->isFloatingPointTy(),do { if (!(ElTy->isIntegerTy() || ElTy->isPointerTy() ||
ElTy->isFloatingPointTy())) { CheckFailed("atomic load operand must have integer, pointer, or floating point "
"type!", ElTy, &LI); return; } } while (0)
2765 "atomic load operand must have integer, pointer, or floating point "do { if (!(ElTy->isIntegerTy() || ElTy->isPointerTy() ||
ElTy->isFloatingPointTy())) { CheckFailed("atomic load operand must have integer, pointer, or floating point "
"type!", ElTy, &LI); return; } } while (0)
2766 "type!",do { if (!(ElTy->isIntegerTy() || ElTy->isPointerTy() ||
ElTy->isFloatingPointTy())) { CheckFailed("atomic load operand must have integer, pointer, or floating point "
"type!", ElTy, &LI); return; } } while (0)
2767 ElTy, &LI)do { if (!(ElTy->isIntegerTy() || ElTy->isPointerTy() ||
ElTy->isFloatingPointTy())) { CheckFailed("atomic load operand must have integer, pointer, or floating point "
"type!", ElTy, &LI); return; } } while (0)
;
2768 checkAtomicMemAccessSize(M, ElTy, &LI);
2769 } else {
2770 Assert(LI.getSynchScope() == CrossThread,do { if (!(LI.getSynchScope() == CrossThread)) { CheckFailed(
"Non-atomic load cannot have SynchronizationScope specified",
&LI); return; } } while (0)
2771 "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)
;
2772 }
2773
2774 visitInstruction(LI);
2775}
2776
2777void Verifier::visitStoreInst(StoreInst &SI) {
2778 PointerType *PTy = dyn_cast<PointerType>(SI.getOperand(1)->getType());
2779 Assert(PTy, "Store operand must be a pointer.", &SI)do { if (!(PTy)) { CheckFailed("Store operand must be a pointer."
, &SI); return; } } while (0)
;
2780 Type *ElTy = PTy->getElementType();
2781 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)
2782 "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)
;
2783 Assert(SI.getAlignment() <= Value::MaximumAlignment,do { if (!(SI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &SI
); return; } } while (0)
2784 "huge alignment values are unsupported", &SI)do { if (!(SI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &SI
); return; } } while (0)
;
2785 if (SI.isAtomic()) {
2786 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)
2787 "Store cannot have Acquire ordering", &SI)do { if (!(SI.getOrdering() != Acquire && SI.getOrdering
() != AcquireRelease)) { CheckFailed("Store cannot have Acquire ordering"
, &SI); return; } } while (0)
;
2788 Assert(SI.getAlignment() != 0,do { if (!(SI.getAlignment() != 0)) { CheckFailed("Atomic store must specify explicit alignment"
, &SI); return; } } while (0)
2789 "Atomic store must specify explicit alignment", &SI)do { if (!(SI.getAlignment() != 0)) { CheckFailed("Atomic store must specify explicit alignment"
, &SI); return; } } while (0)
;
2790 Assert(ElTy->isIntegerTy() || ElTy->isPointerTy() ||do { if (!(ElTy->isIntegerTy() || ElTy->isPointerTy() ||
ElTy->isFloatingPointTy())) { CheckFailed("atomic store operand must have integer, pointer, or floating point "
"type!", ElTy, &SI); return; } } while (0)
2791 ElTy->isFloatingPointTy(),do { if (!(ElTy->isIntegerTy() || ElTy->isPointerTy() ||
ElTy->isFloatingPointTy())) { CheckFailed("atomic store operand must have integer, pointer, or floating point "
"type!", ElTy, &SI); return; } } while (0)
2792 "atomic store operand must have integer, pointer, or floating point "do { if (!(ElTy->isIntegerTy() || ElTy->isPointerTy() ||
ElTy->isFloatingPointTy())) { CheckFailed("atomic store operand must have integer, pointer, or floating point "
"type!", ElTy, &SI); return; } } while (0)
2793 "type!",do { if (!(ElTy->isIntegerTy() || ElTy->isPointerTy() ||
ElTy->isFloatingPointTy())) { CheckFailed("atomic store operand must have integer, pointer, or floating point "
"type!", ElTy, &SI); return; } } while (0)
2794 ElTy, &SI)do { if (!(ElTy->isIntegerTy() || ElTy->isPointerTy() ||
ElTy->isFloatingPointTy())) { CheckFailed("atomic store operand must have integer, pointer, or floating point "
"type!", ElTy, &SI); return; } } while (0)
;
2795 checkAtomicMemAccessSize(M, ElTy, &SI);
2796 } else {
2797 Assert(SI.getSynchScope() == CrossThread,do { if (!(SI.getSynchScope() == CrossThread)) { CheckFailed(
"Non-atomic store cannot have SynchronizationScope specified"
, &SI); return; } } while (0)
2798 "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)
;
2799 }
2800 visitInstruction(SI);
2801}
2802
2803void Verifier::visitAllocaInst(AllocaInst &AI) {
2804 SmallPtrSet<Type*, 4> Visited;
2805 PointerType *PTy = AI.getType();
2806 Assert(PTy->getAddressSpace() == 0,do { if (!(PTy->getAddressSpace() == 0)) { CheckFailed("Allocation instruction pointer not in the generic address space!"
, &AI); return; } } while (0)
2807 "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)
2808 &AI)do { if (!(PTy->getAddressSpace() == 0)) { CheckFailed("Allocation instruction pointer not in the generic address space!"
, &AI); return; } } while (0)
;
2809 Assert(AI.getAllocatedType()->isSized(&Visited),do { if (!(AI.getAllocatedType()->isSized(&Visited))) {
CheckFailed("Cannot allocate unsized type", &AI); return
; } } while (0)
2810 "Cannot allocate unsized type", &AI)do { if (!(AI.getAllocatedType()->isSized(&Visited))) {
CheckFailed("Cannot allocate unsized type", &AI); return
; } } while (0)
;
2811 Assert(AI.getArraySize()->getType()->isIntegerTy(),do { if (!(AI.getArraySize()->getType()->isIntegerTy())
) { CheckFailed("Alloca array size must have integer type", &
AI); return; } } while (0)
2812 "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)
;
2813 Assert(AI.getAlignment() <= Value::MaximumAlignment,do { if (!(AI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &AI
); return; } } while (0)
2814 "huge alignment values are unsupported", &AI)do { if (!(AI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &AI
); return; } } while (0)
;
2815
2816 visitInstruction(AI);
2817}
2818
2819void Verifier::visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI) {
2820
2821 // FIXME: more conditions???
2822 Assert(CXI.getSuccessOrdering() != NotAtomic,do { if (!(CXI.getSuccessOrdering() != NotAtomic)) { CheckFailed
("cmpxchg instructions must be atomic.", &CXI); return; }
} while (0)
2823 "cmpxchg instructions must be atomic.", &CXI)do { if (!(CXI.getSuccessOrdering() != NotAtomic)) { CheckFailed
("cmpxchg instructions must be atomic.", &CXI); return; }
} while (0)
;
2824 Assert(CXI.getFailureOrdering() != NotAtomic,do { if (!(CXI.getFailureOrdering() != NotAtomic)) { CheckFailed
("cmpxchg instructions must be atomic.", &CXI); return; }
} while (0)
2825 "cmpxchg instructions must be atomic.", &CXI)do { if (!(CXI.getFailureOrdering() != NotAtomic)) { CheckFailed
("cmpxchg instructions must be atomic.", &CXI); return; }
} while (0)
;
2826 Assert(CXI.getSuccessOrdering() != Unordered,do { if (!(CXI.getSuccessOrdering() != Unordered)) { CheckFailed
("cmpxchg instructions cannot be unordered.", &CXI); return
; } } while (0)
2827 "cmpxchg instructions cannot be unordered.", &CXI)do { if (!(CXI.getSuccessOrdering() != Unordered)) { CheckFailed
("cmpxchg instructions cannot be unordered.", &CXI); return
; } } while (0)
;
2828 Assert(CXI.getFailureOrdering() != Unordered,do { if (!(CXI.getFailureOrdering() != Unordered)) { CheckFailed
("cmpxchg instructions cannot be unordered.", &CXI); return
; } } while (0)
2829 "cmpxchg instructions cannot be unordered.", &CXI)do { if (!(CXI.getFailureOrdering() != Unordered)) { CheckFailed
("cmpxchg instructions cannot be unordered.", &CXI); return
; } } while (0)
;
2830 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)
2831 "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)
2832 &CXI)do { if (!(CXI.getSuccessOrdering() >= CXI.getFailureOrdering
())) { CheckFailed("cmpxchg instructions be at least as constrained on success as fail"
, &CXI); return; } } while (0)
;
2833 Assert(CXI.getFailureOrdering() != Release &&do { if (!(CXI.getFailureOrdering() != Release && CXI
.getFailureOrdering() != AcquireRelease)) { CheckFailed("cmpxchg failure ordering cannot include release semantics"
, &CXI); return; } } while (0)
2834 CXI.getFailureOrdering() != AcquireRelease,do { if (!(CXI.getFailureOrdering() != Release && CXI
.getFailureOrdering() != AcquireRelease)) { CheckFailed("cmpxchg failure ordering cannot include release semantics"
, &CXI); return; } } while (0)
2835 "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)
;
2836
2837 PointerType *PTy = dyn_cast<PointerType>(CXI.getOperand(0)->getType());
2838 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)
;
2839 Type *ElTy = PTy->getElementType();
2840 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)
2841 ElTy)do { if (!(ElTy->isIntegerTy())) { CheckFailed("cmpxchg operand must have integer type!"
, &CXI, ElTy); return; } } while (0)
;
2842 checkAtomicMemAccessSize(M, ElTy, &CXI);
2843 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)
2844 "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)
2845 ElTy)do { if (!(ElTy == CXI.getOperand(1)->getType())) { CheckFailed
("Expected value type does not match pointer operand type!", &
CXI, ElTy); return; } } while (0)
;
2846 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)
2847 "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)
;
2848 visitInstruction(CXI);
2849}
2850
2851void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) {
2852 Assert(RMWI.getOrdering() != NotAtomic,do { if (!(RMWI.getOrdering() != NotAtomic)) { CheckFailed("atomicrmw instructions must be atomic."
, &RMWI); return; } } while (0)
2853 "atomicrmw instructions must be atomic.", &RMWI)do { if (!(RMWI.getOrdering() != NotAtomic)) { CheckFailed("atomicrmw instructions must be atomic."
, &RMWI); return; } } while (0)
;
2854 Assert(RMWI.getOrdering() != Unordered,do { if (!(RMWI.getOrdering() != Unordered)) { CheckFailed("atomicrmw instructions cannot be unordered."
, &RMWI); return; } } while (0)
2855 "atomicrmw instructions cannot be unordered.", &RMWI)do { if (!(RMWI.getOrdering() != Unordered)) { CheckFailed("atomicrmw instructions cannot be unordered."
, &RMWI); return; } } while (0)
;
2856 PointerType *PTy = dyn_cast<PointerType>(RMWI.getOperand(0)->getType());
2857 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)
;
2858 Type *ElTy = PTy->getElementType();
2859 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)
2860 &RMWI, ElTy)do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw operand must have integer type!"
, &RMWI, ElTy); return; } } while (0)
;
2861 checkAtomicMemAccessSize(M, ElTy, &RMWI);
2862 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)
2863 "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)
2864 ElTy)do { if (!(ElTy == RMWI.getOperand(1)->getType())) { CheckFailed
("Argument value type does not match pointer operand type!", &
RMWI, ElTy); return; } } while (0)
;
2865 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)
2866 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)
2867 "Invalid binary operation!", &RMWI)do { if (!(AtomicRMWInst::FIRST_BINOP <= RMWI.getOperation
() && RMWI.getOperation() <= AtomicRMWInst::LAST_BINOP
)) { CheckFailed("Invalid binary operation!", &RMWI); return
; } } while (0)
;
2868 visitInstruction(RMWI);
2869}
2870
2871void Verifier::visitFenceInst(FenceInst &FI) {
2872 const AtomicOrdering Ordering = FI.getOrdering();
2873 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)
2874 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)
2875 "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)
2876 "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)
2877 &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)
;
2878 visitInstruction(FI);
2879}
2880
2881void Verifier::visitExtractValueInst(ExtractValueInst &EVI) {
2882 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)
2883 EVI.getIndices()) == EVI.getType(),do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand
()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed
("Invalid ExtractValueInst operands!", &EVI); return; } }
while (0)
2884 "Invalid ExtractValueInst operands!", &EVI)do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand
()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed
("Invalid ExtractValueInst operands!", &EVI); return; } }
while (0)
;
2885
2886 visitInstruction(EVI);
2887}
2888
2889void Verifier::visitInsertValueInst(InsertValueInst &IVI) {
2890 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)
2891 IVI.getIndices()) ==do { if (!(ExtractValueInst::getIndexedType(IVI.getAggregateOperand
()->getType(), IVI.getIndices()) == IVI.getOperand(1)->
getType())) { CheckFailed("Invalid InsertValueInst operands!"
, &IVI); return; } } while (0)
2892 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)
2893 "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)
;
2894
2895 visitInstruction(IVI);
2896}
2897
2898void Verifier::visitEHPadPredecessors(Instruction &I) {
2899 assert(I.isEHPad())((I.isEHPad()) ? static_cast<void> (0) : __assert_fail (
"I.isEHPad()", "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/lib/IR/Verifier.cpp"
, 2899, __PRETTY_FUNCTION__))
;
2900
2901 BasicBlock *BB = I.getParent();
2902 Function *F = BB->getParent();
2903
2904 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)
;
2905
2906 if (auto *LPI = dyn_cast<LandingPadInst>(&I)) {
2907 // The landingpad instruction defines its parent as a landing pad block. The
2908 // landing pad block may be branched to only by the unwind edge of an
2909 // invoke.
2910 for (BasicBlock *PredBB : predecessors(BB)) {
2911 const auto *II = dyn_cast<InvokeInst>(PredBB->getTerminator());
2912 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)
2913 "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)
2914 "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)
2915 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)
;
2916 }
2917 return;
2918 }
2919 if (auto *CPI = dyn_cast<CatchPadInst>(&I)) {
2920 if (!pred_empty(BB))
2921 Assert(BB->getUniquePredecessor() == CPI->getCatchSwitch()->getParent(),do { if (!(BB->getUniquePredecessor() == CPI->getCatchSwitch
()->getParent())) { CheckFailed("Block containg CatchPadInst must be jumped to "
"only by its catchswitch.", CPI); return; } } while (0)
2922 "Block containg CatchPadInst must be jumped to "do { if (!(BB->getUniquePredecessor() == CPI->getCatchSwitch
()->getParent())) { CheckFailed("Block containg CatchPadInst must be jumped to "
"only by its catchswitch.", CPI); return; } } while (0)
2923 "only by its catchswitch.",do { if (!(BB->getUniquePredecessor() == CPI->getCatchSwitch
()->getParent())) { CheckFailed("Block containg CatchPadInst must be jumped to "
"only by its catchswitch.", CPI); return; } } while (0)
2924 CPI)do { if (!(BB->getUniquePredecessor() == CPI->getCatchSwitch
()->getParent())) { CheckFailed("Block containg CatchPadInst must be jumped to "
"only by its catchswitch.", CPI); return; } } while (0)
;
2925 return;
2926 }
2927
2928 for (BasicBlock *PredBB : predecessors(BB)) {
2929 TerminatorInst *TI = PredBB->getTerminator();
2930 if (auto *II = dyn_cast<InvokeInst>(TI)) {
2931 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)
2932 "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)
;
2933 } else if (!isa<CleanupReturnInst>(TI) && !isa<CatchSwitchInst>(TI)) {
2934 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)
;
2935 }
2936 }
2937}
2938
2939void Verifier::visitLandingPadInst(LandingPadInst &LPI) {
2940 // The landingpad instruction is ill-formed if it doesn't have any clauses and
2941 // isn't a cleanup.
2942 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)
2943 "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)
;
2944
2945 visitEHPadPredecessors(LPI);
2946
2947 if (!LandingPadResultTy)
2948 LandingPadResultTy = LPI.getType();
2949 else
2950 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)
2951 "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)
2952 "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)
2953 &LPI)do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed
("The landingpad instruction should have a consistent result type "
"inside a function.", &LPI); return; } } while (0)
;
2954
2955 Function *F = LPI.getParent()->getParent();
2956 Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("LandingPadInst needs to be in a function with a personality."
, &LPI); return; } } while (0)
2957 "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)
;
2958
2959 // The landingpad instruction must be the first non-PHI instruction in the
2960 // block.
2961 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)
2962 "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)
2963 &LPI)do { if (!(LPI.getParent()->getLandingPadInst() == &LPI
)) { CheckFailed("LandingPadInst not the first non-PHI instruction in the block."
, &LPI); return; } } while (0)
;
2964
2965 for (unsigned i = 0, e = LPI.getNumClauses(); i < e; ++i) {
2966 Constant *Clause = LPI.getClause(i);
2967 if (LPI.isCatch(i)) {
2968 Assert(isa<PointerType>(Clause->getType()),do { if (!(isa<PointerType>(Clause->getType()))) { CheckFailed
("Catch operand does not have pointer type!", &LPI); return
; } } while (0)
2969 "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)
;
2970 } else {
2971 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)
;
2972 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)
2973 "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)
;
2974 }
2975 }
2976
2977 visitInstruction(LPI);
2978}
2979
2980void Verifier::visitCatchPadInst(CatchPadInst &CPI) {
2981 visitEHPadPredecessors(CPI);
2982
2983 BasicBlock *BB = CPI.getParent();
2984
2985 Function *F = BB->getParent();
2986 Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchPadInst needs to be in a function with a personality."
, &CPI); return; } } while (0)
2987 "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)
;
2988
2989 Assert(isa<CatchSwitchInst>(CPI.getParentPad()),do { if (!(isa<CatchSwitchInst>(CPI.getParentPad()))) {
CheckFailed("CatchPadInst needs to be directly nested in a CatchSwitchInst."
, CPI.getParentPad()); return; } } while (0)
2990 "CatchPadInst needs to be directly nested in a CatchSwitchInst.",do { if (!(isa<CatchSwitchInst>(CPI.getParentPad()))) {
CheckFailed("CatchPadInst needs to be directly nested in a CatchSwitchInst."
, CPI.getParentPad()); return; } } while (0)
2991 CPI.getParentPad())do { if (!(isa<CatchSwitchInst>(CPI.getParentPad()))) {
CheckFailed("CatchPadInst needs to be directly nested in a CatchSwitchInst."
, CPI.getParentPad()); return; } } while (0)
;
2992
2993 // The catchpad instruction must be the first non-PHI instruction in the
2994 // block.
2995 Assert(BB->getFirstNonPHI() == &CPI,do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed
("CatchPadInst not the first non-PHI instruction in the block."
, &CPI); return; } } while (0)
2996 "CatchPadInst not the first non-PHI instruction in the block.", &CPI)do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed
("CatchPadInst not the first non-PHI instruction in the block."
, &CPI); return; } } while (0)
;
2997
2998 visitInstruction(CPI);
2999}
3000
3001void Verifier::visitCatchReturnInst(CatchReturnInst &CatchReturn) {
3002 Assert(isa<CatchPadInst>(CatchReturn.getOperand(0)),do { if (!(isa<CatchPadInst>(CatchReturn.getOperand(0))
)) { CheckFailed("CatchReturnInst needs to be provided a CatchPad"
, &CatchReturn, CatchReturn.getOperand(0)); return; } } while
(0)
3003 "CatchReturnInst needs to be provided a CatchPad", &CatchReturn,do { if (!(isa<CatchPadInst>(CatchReturn.getOperand(0))
)) { CheckFailed("CatchReturnInst needs to be provided a CatchPad"
, &CatchReturn, CatchReturn.getOperand(0)); return; } } while
(0)
3004 CatchReturn.getOperand(0))do { if (!(isa<CatchPadInst>(CatchReturn.getOperand(0))
)) { CheckFailed("CatchReturnInst needs to be provided a CatchPad"
, &CatchReturn, CatchReturn.getOperand(0)); return; } } while
(0)
;
3005
3006 visitTerminatorInst(CatchReturn);
3007}
3008
3009void Verifier::visitCleanupPadInst(CleanupPadInst &CPI) {
3010 visitEHPadPredecessors(CPI);
3011
3012 BasicBlock *BB = CPI.getParent();
3013
3014 Function *F = BB->getParent();
3015 Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CleanupPadInst needs to be in a function with a personality."
, &CPI); return; } } while (0)
3016 "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)
;
3017
3018 // The cleanuppad instruction must be the first non-PHI instruction in the
3019 // block.
3020 Assert(BB->getFirstNonPHI() == &CPI,do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed
("CleanupPadInst not the first non-PHI instruction in the block."
, &CPI); return; } } while (0)
3021 "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)
3022 &CPI)do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed
("CleanupPadInst not the first non-PHI instruction in the block."
, &CPI); return; } } while (0)
;
3023
3024 auto *ParentPad = CPI.getParentPad();
3025 Assert(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),do { if (!(isa<ConstantTokenNone>(ParentPad) || isa<
FuncletPadInst>(ParentPad))) { CheckFailed("CleanupPadInst has an invalid parent."
, &CPI); return; } } while (0)
3026 "CleanupPadInst has an invalid parent.", &CPI)do { if (!(isa<ConstantTokenNone>(ParentPad) || isa<
FuncletPadInst>(ParentPad))) { CheckFailed("CleanupPadInst has an invalid parent."
, &CPI); return; } } while (0)
;
3027
3028 User *FirstUser = nullptr;
3029 BasicBlock *FirstUnwindDest = nullptr;
3030 for (User *U : CPI.users()) {
3031 BasicBlock *UnwindDest;
3032 if (CleanupReturnInst *CRI = dyn_cast<CleanupReturnInst>(U)) {
3033 UnwindDest = CRI->getUnwindDest();
3034 } else if (isa<CleanupPadInst>(U) || isa<CatchSwitchInst>(U)) {
3035 continue;
3036 } else if (CallSite(U)) {
3037 continue;
3038 } else {
3039 Assert(false, "bogus cleanuppad use", &CPI)do { if (!(false)) { CheckFailed("bogus cleanuppad use", &
CPI); return; } } while (0)
;
3040 }
3041
3042 if (!FirstUser) {
3043 FirstUser = U;
3044 FirstUnwindDest = UnwindDest;
3045 } else {
3046 Assert(do { if (!(UnwindDest == FirstUnwindDest)) { CheckFailed("cleanupret instructions from the same cleanuppad must have the same "
"unwind destination", FirstUser, U); return; } } while (0)
3047 UnwindDest == FirstUnwindDest,do { if (!(UnwindDest == FirstUnwindDest)) { CheckFailed("cleanupret instructions from the same cleanuppad must have the same "
"unwind destination", FirstUser, U); return; } } while (0)
3048 "cleanupret instructions from the same cleanuppad must have the same "do { if (!(UnwindDest == FirstUnwindDest)) { CheckFailed("cleanupret instructions from the same cleanuppad must have the same "
"unwind destination", FirstUser, U); return; } } while (0)
3049 "unwind destination",do { if (!(UnwindDest == FirstUnwindDest)) { CheckFailed("cleanupret instructions from the same cleanuppad must have the same "
"unwind destination", FirstUser, U); return; } } while (0)
3050 FirstUser, U)do { if (!(UnwindDest == FirstUnwindDest)) { CheckFailed("cleanupret instructions from the same cleanuppad must have the same "
"unwind destination", FirstUser, U); return; } } while (0)
;
3051 }
3052 }
3053
3054 visitInstruction(CPI);
3055}
3056
3057void Verifier::visitCatchSwitchInst(CatchSwitchInst &CatchSwitch) {
3058 visitEHPadPredecessors(CatchSwitch);
3059
3060 BasicBlock *BB = CatchSwitch.getParent();
3061
3062 Function *F = BB->getParent();
3063 Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchSwitchInst needs to be in a function with a personality."
, &CatchSwitch); return; } } while (0)
3064 "CatchSwitchInst needs to be in a function with a personality.",do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchSwitchInst needs to be in a function with a personality."
, &CatchSwitch); return; } } while (0)
3065 &CatchSwitch)do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchSwitchInst needs to be in a function with a personality."
, &CatchSwitch); return; } } while (0)
;
3066
3067 // The catchswitch instruction must be the first non-PHI instruction in the
3068 // block.
3069 Assert(BB->getFirstNonPHI() == &CatchSwitch,do { if (!(BB->getFirstNonPHI() == &CatchSwitch)) { CheckFailed
("CatchSwitchInst not the first non-PHI instruction in the block."
, &CatchSwitch); return; } } while (0)
3070 "CatchSwitchInst not the first non-PHI instruction in the block.",do { if (!(BB->getFirstNonPHI() == &CatchSwitch)) { CheckFailed
("CatchSwitchInst not the first non-PHI instruction in the block."
, &CatchSwitch); return; } } while (0)
3071 &CatchSwitch)do { if (!(BB->getFirstNonPHI() == &CatchSwitch)) { CheckFailed
("CatchSwitchInst not the first non-PHI instruction in the block."
, &CatchSwitch); return; } } while (0)
;
3072
3073 if (BasicBlock *UnwindDest = CatchSwitch.getUnwindDest()) {
3074 Instruction *I = UnwindDest->getFirstNonPHI();
3075 Assert(I->isEHPad() && !isa<LandingPadInst>(I),do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CatchSwitchInst must unwind to an EH block which is not a "
"landingpad.", &CatchSwitch); return; } } while (0)
3076 "CatchSwitchInst must unwind to an EH block which is not a "do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CatchSwitchInst must unwind to an EH block which is not a "
"landingpad.", &CatchSwitch); return; } } while (0)
3077 "landingpad.",do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CatchSwitchInst must unwind to an EH block which is not a "
"landingpad.", &CatchSwitch); return; } } while (0)
3078 &CatchSwitch)do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CatchSwitchInst must unwind to an EH block which is not a "
"landingpad.", &CatchSwitch); return; } } while (0)
;
3079 }
3080
3081 auto *ParentPad = CatchSwitch.getParentPad();
3082 Assert(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),do { if (!(isa<ConstantTokenNone>(ParentPad) || isa<
FuncletPadInst>(ParentPad))) { CheckFailed("CatchSwitchInst has an invalid parent."
, ParentPad); return; } } while (0)
3083 "CatchSwitchInst has an invalid parent.", ParentPad)do { if (!(isa<ConstantTokenNone>(ParentPad) || isa<
FuncletPadInst>(ParentPad))) { CheckFailed("CatchSwitchInst has an invalid parent."
, ParentPad); return; } } while (0)
;
3084
3085 Assert(CatchSwitch.getNumHandlers() != 0,do { if (!(CatchSwitch.getNumHandlers() != 0)) { CheckFailed(
"CatchSwitchInst cannot have empty handler list", &CatchSwitch
); return; } } while (0)
3086 "CatchSwitchInst cannot have empty handler list", &CatchSwitch)do { if (!(CatchSwitch.getNumHandlers() != 0)) { CheckFailed(
"CatchSwitchInst cannot have empty handler list", &CatchSwitch
); return; } } while (0)
;
3087
3088 for (BasicBlock *Handler : CatchSwitch.handlers()) {
3089 Assert(isa<CatchPadInst>(Handler->getFirstNonPHI()),do { if (!(isa<CatchPadInst>(Handler->getFirstNonPHI
()))) { CheckFailed("CatchSwitchInst handlers must be catchpads"
, &CatchSwitch, Handler); return; } } while (0)
3090 "CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler)do { if (!(isa<CatchPadInst>(Handler->getFirstNonPHI
()))) { CheckFailed("CatchSwitchInst handlers must be catchpads"
, &CatchSwitch, Handler); return; } } while (0)
;
3091 }
3092
3093 visitTerminatorInst(CatchSwitch);
3094}
3095
3096void Verifier::visitCleanupReturnInst(CleanupReturnInst &CRI) {
3097 Assert(isa<CleanupPadInst>(CRI.getOperand(0)),do { if (!(isa<CleanupPadInst>(CRI.getOperand(0)))) { CheckFailed
("CleanupReturnInst needs to be provided a CleanupPad", &
CRI, CRI.getOperand(0)); return; } } while (0)
3098 "CleanupReturnInst needs to be provided a CleanupPad", &CRI,do { if (!(isa<CleanupPadInst>(CRI.getOperand(0)))) { CheckFailed
("CleanupReturnInst needs to be provided a CleanupPad", &
CRI, CRI.getOperand(0)); return; } } while (0)
3099 CRI.getOperand(0))do { if (!(isa<CleanupPadInst>(CRI.getOperand(0)))) { CheckFailed
("CleanupReturnInst needs to be provided a CleanupPad", &
CRI, CRI.getOperand(0)); return; } } while (0)
;
3100
3101 if (BasicBlock *UnwindDest = CRI.getUnwindDest()) {
3102 Instruction *I = UnwindDest->getFirstNonPHI();
3103 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)
3104 "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)
3105 "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)
3106 &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)
;
3107 }
3108
3109 visitTerminatorInst(CRI);
3110}
3111
3112void Verifier::verifyDominatesUse(Instruction &I, unsigned i) {
3113 Instruction *Op = cast<Instruction>(I.getOperand(i));
3114 // If the we have an invalid invoke, don't try to compute the dominance.
3115 // We already reject it in the invoke specific checks and the dominance
3116 // computation doesn't handle multiple edges.
3117 if (InvokeInst *II = dyn_cast<InvokeInst>(Op)) {
3118 if (II->getNormalDest() == II->getUnwindDest())
3119 return;
3120 }
3121
3122 const Use &U = I.getOperandUse(i);
3123 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)
3124 "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)
;
3125}
3126
3127void Verifier::visitDereferenceableMetadata(Instruction& I, MDNode* MD) {
3128 Assert(I.getType()->isPointerTy(), "dereferenceable, dereferenceable_or_null "do { if (!(I.getType()->isPointerTy())) { CheckFailed("dereferenceable, dereferenceable_or_null "
"apply only to pointer types", &I); return; } } while (0
)
3129 "apply only to pointer types", &I)do { if (!(I.getType()->isPointerTy())) { CheckFailed("dereferenceable, dereferenceable_or_null "
"apply only to pointer types", &I); return; } } while (0
)
;
3130 Assert(isa<LoadInst>(I),do { if (!(isa<LoadInst>(I))) { CheckFailed("dereferenceable, dereferenceable_or_null apply only to load"
" instructions, use attributes for calls or invokes", &I
); return; } } while (0)
3131 "dereferenceable, dereferenceable_or_null apply only to load"do { if (!(isa<LoadInst>(I))) { CheckFailed("dereferenceable, dereferenceable_or_null apply only to load"
" instructions, use attributes for calls or invokes", &I
); return; } } while (0)
3132 " instructions, use attributes for calls or invokes", &I)do { if (!(isa<LoadInst>(I))) { CheckFailed("dereferenceable, dereferenceable_or_null apply only to load"
" instructions, use attributes for calls or invokes", &I
); return; } } while (0)
;
3133 Assert(MD->getNumOperands() == 1, "dereferenceable, dereferenceable_or_null "do { if (!(MD->getNumOperands() == 1)) { CheckFailed("dereferenceable, dereferenceable_or_null "
"take one operand!", &I); return; } } while (0)
3134 "take one operand!", &I)do { if (!(MD->getNumOperands() == 1)) { CheckFailed("dereferenceable, dereferenceable_or_null "
"take one operand!", &I); return; } } while (0)
;
3135 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(MD->getOperand(0));
3136 Assert(CI && CI->getType()->isIntegerTy(64), "dereferenceable, "do { if (!(CI && CI->getType()->isIntegerTy(64)
)) { CheckFailed("dereferenceable, " "dereferenceable_or_null metadata value must be an i64!"
, &I); return; } } while (0)
3137 "dereferenceable_or_null metadata value must be an i64!", &I)do { if (!(CI && CI->getType()->isIntegerTy(64)
)) { CheckFailed("dereferenceable, " "dereferenceable_or_null metadata value must be an i64!"
, &I); return; } } while (0)
;
3138}
3139
3140/// verifyInstruction - Verify that an instruction is well formed.
3141///
3142void Verifier::visitInstruction(Instruction &I) {
3143 BasicBlock *BB = I.getParent();
3144 Assert(BB, "Instruction not embedded in basic block!", &I)do { if (!(BB)) { CheckFailed("Instruction not embedded in basic block!"
, &I); return; } } while (0)
;
3145
3146 if (!isa<PHINode>(I)) { // Check that non-phi nodes are not self referential
3147 for (User *U : I.users()) {
3148 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)
3149 "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)
;
3150 }
3151 }
3152
3153 // Check that void typed values don't have names
3154 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)
3155 "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)
;
3156
3157 // Check that the return value of the instruction is either void or a legal
3158 // value type.
3159 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)
3160 "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)
;
3161
3162 // Check that the instruction doesn't produce metadata. Calls are already
3163 // checked against the callee type.
3164 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)
3165 "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)
;
3166
3167 // Check that all uses of the instruction, if they are instructions
3168 // themselves, actually have parent basic blocks. If the use is not an
3169 // instruction, it is an error!
3170 for (Use &U : I.uses()) {
3171 if (Instruction *Used = dyn_cast<Instruction>(U.getUser()))
3172 Assert(Used->getParent() != nullptr,do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing"
" instruction not embedded in a basic block!", &I, Used)
; return; } } while (0)
3173 "Instruction referencing"do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing"
" instruction not embedded in a basic block!", &I, Used)
; return; } } while (0)
3174 " 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)
3175 &I, Used)do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing"
" instruction not embedded in a basic block!", &I, Used)
; return; } } while (0)
;
3176 else {
3177 CheckFailed("Use of instruction is not an instruction!", U);
3178 return;
3179 }
3180 }
3181
3182 for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) {
3183 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)
;
3184
3185 // Check to make sure that only first-class-values are operands to
3186 // instructions.
3187 if (!I.getOperand(i)->getType()->isFirstClassType()) {
3188 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)
;
3189 }
3190
3191 if (Function *F = dyn_cast<Function>(I.getOperand(i))) {
3192 // Check to make sure that the "address of" an intrinsic function is never
3193 // taken.
3194 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)
3195 !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)
3196 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)
3197 "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)
;
3198 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)
3199 !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)
3200 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)
3201 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)
3202 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)
3203 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)
3204 "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)
3205 " 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)
3206 &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)
;
3207 Assert(F->getParent() == M, "Referencing function in another module!",do { if (!(F->getParent() == M)) { CheckFailed("Referencing function in another module!"
, &I, M, F, F->getParent()); return; } } while (0)
3208 &I, M, F, F->getParent())do { if (!(F->getParent() == M)) { CheckFailed("Referencing function in another module!"
, &I, M, F, F->getParent()); return; } } while (0)
;
3209 } else if (BasicBlock *OpBB = dyn_cast<BasicBlock>(I.getOperand(i))) {
3210 Assert(OpBB->getParent() == BB->getParent(),do { if (!(OpBB->getParent() == BB->getParent())) { CheckFailed
("Referring to a basic block in another function!", &I); return
; } } while (0)
3211 "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)
;
3212 } else if (Argument *OpArg = dyn_cast<Argument>(I.getOperand(i))) {
3213 Assert(OpArg->getParent() == BB->getParent(),do { if (!(OpArg->getParent() == BB->getParent())) { CheckFailed
("Referring to an argument in another function!", &I); return
; } } while (0)
3214 "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)
;
3215 } else if (GlobalValue *GV = dyn_cast<GlobalValue>(I.getOperand(i))) {
3216 Assert(GV->getParent() == M, "Referencing global in another module!", &I, M, GV, GV->getParent())do { if (!(GV->getParent() == M)) { CheckFailed("Referencing global in another module!"
, &I, M, GV, GV->getParent()); return; } } while (0)
;
3217 } else if (isa<Instruction>(I.getOperand(i))) {
3218 verifyDominatesUse(I, i);
3219 } else if (isa<InlineAsm>(I.getOperand(i))) {
3220 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)
3221 (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)
3222 "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)
;
3223 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(I.getOperand(i))) {
3224 if (CE->getType()->isPtrOrPtrVectorTy()) {
3225 // If we have a ConstantExpr pointer, we need to see if it came from an
3226 // illegal bitcast (inttoptr <constant int> )
3227 visitConstantExprsRecursively(CE);
3228 }
3229 }
3230 }
3231
3232 if (MDNode *MD = I.getMetadata(LLVMContext::MD_fpmath)) {
3233 Assert(I.getType()->isFPOrFPVectorTy(),do { if (!(I.getType()->isFPOrFPVectorTy())) { CheckFailed
("fpmath requires a floating point result!", &I); return;
} } while (0)
3234 "fpmath requires a floating point result!", &I)do { if (!(I.getType()->isFPOrFPVectorTy())) { CheckFailed
("fpmath requires a floating point result!", &I); return;
} } while (0)
;
3235 Assert(MD->getNumOperands() == 1, "fpmath takes one operand!", &I)do { if (!(MD->getNumOperands() == 1)) { CheckFailed("fpmath takes one operand!"
, &I); return; } } while (0)
;
3236 if (ConstantFP *CFP0 =
3237 mdconst::dyn_extract_or_null<ConstantFP>(MD->getOperand(0))) {
3238 APFloat Accuracy = CFP0->getValueAPF();
3239 Assert(Accuracy.isFiniteNonZero() && !Accuracy.isNegative(),do { if (!(Accuracy.isFiniteNonZero() && !Accuracy.isNegative
())) { CheckFailed("fpmath accuracy not a positive number!", &
I); return; } } while (0)
3240 "fpmath accuracy not a positive number!", &I)do { if (!(Accuracy.isFiniteNonZero() && !Accuracy.isNegative
())) { CheckFailed("fpmath accuracy not a positive number!", &
I); return; } } while (0)
;
3241 } else {
3242 Assert(false, "invalid fpmath accuracy!", &I)do { if (!(false)) { CheckFailed("invalid fpmath accuracy!", &
I); return; } } while (0)
;
3243 }
3244 }
3245
3246 if (MDNode *Range = I.getMetadata(LLVMContext::MD_range)) {
3247 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)
3248 "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)
;
3249 visitRangeMetadata(I, Range, I.getType());
3250 }
3251
3252 if (I.getMetadata(LLVMContext::MD_nonnull)) {
3253 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)
3254 &I)do { if (!(I.getType()->isPointerTy())) { CheckFailed("nonnull applies only to pointer types"
, &I); return; } } while (0)
;
3255 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)
3256 "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)
3257 " 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)
3258 &I)do { if (!(isa<LoadInst>(I))) { CheckFailed("nonnull applies only to load instructions, use attributes"
" for calls or invokes", &I); return; } } while (0)
;
3259 }
3260
3261 if (MDNode *MD = I.getMetadata(LLVMContext::MD_dereferenceable))
3262 visitDereferenceableMetadata(I, MD);
3263
3264 if (MDNode *MD = I.getMetadata(LLVMContext::MD_dereferenceable_or_null))
3265 visitDereferenceableMetadata(I, MD);
3266
3267 if (MDNode *AlignMD = I.getMetadata(LLVMContext::MD_align)) {
3268 Assert(I.getType()->isPointerTy(), "align applies only to pointer types",do { if (!(I.getType()->isPointerTy())) { CheckFailed("align applies only to pointer types"
, &I); return; } } while (0)
3269 &I)do { if (!(I.getType()->isPointerTy())) { CheckFailed("align applies only to pointer types"
, &I); return; } } while (0)
;
3270 Assert(isa<LoadInst>(I), "align applies only to load instructions, "do { if (!(isa<LoadInst>(I))) { CheckFailed("align applies only to load instructions, "
"use attributes for calls or invokes", &I); return; } } while
(0)
3271 "use attributes for calls or invokes", &I)do { if (!(isa<LoadInst>(I))) { CheckFailed("align applies only to load instructions, "
"use attributes for calls or invokes", &I); return; } } while
(0)
;
3272 Assert(AlignMD->getNumOperands() == 1, "align takes one operand!", &I)do { if (!(AlignMD->getNumOperands() == 1)) { CheckFailed(
"align takes one operand!", &I); return; } } while (0)
;
3273 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(AlignMD->getOperand(0));
3274 Assert(CI && CI->getType()->isIntegerTy(64),do { if (!(CI && CI->getType()->isIntegerTy(64)
)) { CheckFailed("align metadata value must be an i64!", &
I); return; } } while (0)
3275 "align metadata value must be an i64!", &I)do { if (!(CI && CI->getType()->isIntegerTy(64)
)) { CheckFailed("align metadata value must be an i64!", &
I); return; } } while (0)
;
3276 uint64_t Align = CI->getZExtValue();
3277 Assert(isPowerOf2_64(Align),do { if (!(isPowerOf2_64(Align))) { CheckFailed("align metadata value must be a power of 2!"
, &I); return; } } while (0)
3278 "align metadata value must be a power of 2!", &I)do { if (!(isPowerOf2_64(Align))) { CheckFailed("align metadata value must be a power of 2!"
, &I); return; } } while (0)
;
3279 Assert(Align <= Value::MaximumAlignment,do { if (!(Align <= Value::MaximumAlignment)) { CheckFailed
("alignment is larger that implementation defined limit", &
I); return; } } while (0)
3280 "alignment is larger that implementation defined limit", &I)do { if (!(Align <= Value::MaximumAlignment)) { CheckFailed
("alignment is larger that implementation defined limit", &
I); return; } } while (0)
;
3281 }
3282
3283 if (MDNode *N = I.getDebugLoc().getAsMDNode()) {
3284 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)
;
3285 visitMDNode(*N);
3286 }
3287
3288 InstsInThisBlock.insert(&I);
3289}
3290
3291/// VerifyIntrinsicType - Verify that the specified type (which comes from an
3292/// intrinsic argument or return value) matches the type constraints specified
3293/// by the .td file (e.g. an "any integer" argument really is an integer).
3294///
3295/// This return true on error but does not print a message.
3296bool Verifier::VerifyIntrinsicType(Type *Ty,
3297 ArrayRef<Intrinsic::IITDescriptor> &Infos,
3298 SmallVectorImpl<Type*> &ArgTys) {
3299 using namespace Intrinsic;
3300
3301 // If we ran out of descriptors, there are too many arguments.
3302 if (Infos.empty()) return true;
3303 IITDescriptor D = Infos.front();
3304 Infos = Infos.slice(1);
3305
3306 switch (D.Kind) {
3307 case IITDescriptor::Void: return !Ty->isVoidTy();
3308 case IITDescriptor::VarArg: return true;
3309 case IITDescriptor::MMX: return !Ty->isX86_MMXTy();
3310 case IITDescriptor::Token: return !Ty->isTokenTy();
3311 case IITDescriptor::Metadata: return !Ty->isMetadataTy();
3312 case IITDescriptor::Half: return !Ty->isHalfTy();
3313 case IITDescriptor::Float: return !Ty->isFloatTy();
3314 case IITDescriptor::Double: return !Ty->isDoubleTy();
3315 case IITDescriptor::Integer: return !Ty->isIntegerTy(D.Integer_Width);
3316 case IITDescriptor::Vector: {
3317 VectorType *VT = dyn_cast<VectorType>(Ty);
3318 return !VT || VT->getNumElements() != D.Vector_Width ||
3319 VerifyIntrinsicType(VT->getElementType(), Infos, ArgTys);
3320 }
3321 case IITDescriptor::Pointer: {
3322 PointerType *PT = dyn_cast<PointerType>(Ty);
3323 return !PT || PT->getAddressSpace() != D.Pointer_AddressSpace ||
3324 VerifyIntrinsicType(PT->getElementType(), Infos, ArgTys);
3325 }
3326
3327 case IITDescriptor::Struct: {
3328 StructType *ST = dyn_cast<StructType>(Ty);
3329 if (!ST || ST->getNumElements() != D.Struct_NumElements)
3330 return true;
3331
3332 for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
3333 if (VerifyIntrinsicType(ST->getElementType(i), Infos, ArgTys))
3334 return true;
3335 return false;
3336 }
3337
3338 case IITDescriptor::Argument:
3339 // Two cases here - If this is the second occurrence of an argument, verify
3340 // that the later instance matches the previous instance.
3341 if (D.getArgumentNumber() < ArgTys.size())
3342 return Ty != ArgTys[D.getArgumentNumber()];
3343
3344 // Otherwise, if this is the first instance of an argument, record it and
3345 // verify the "Any" kind.
3346 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~svn257205/lib/IR/Verifier.cpp"
, 3346, __PRETTY_FUNCTION__))
;
3347 ArgTys.push_back(Ty);
3348
3349 switch (D.getArgumentKind()) {
3350 case IITDescriptor::AK_Any: return false; // Success
3351 case IITDescriptor::AK_AnyInteger: return !Ty->isIntOrIntVectorTy();
3352 case IITDescriptor::AK_AnyFloat: return !Ty->isFPOrFPVectorTy();
3353 case IITDescriptor::AK_AnyVector: return !isa<VectorType>(Ty);
3354 case IITDescriptor::AK_AnyPointer: return !isa<PointerType>(Ty);
3355 }
3356 llvm_unreachable("all argument kinds not covered")::llvm::llvm_unreachable_internal("all argument kinds not covered"
, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/lib/IR/Verifier.cpp"
, 3356)
;
3357
3358 case IITDescriptor::ExtendArgument: {
3359 // This may only be used when referring to a previous vector argument.
3360 if (D.getArgumentNumber() >= ArgTys.size())
3361 return true;
3362
3363 Type *NewTy = ArgTys[D.getArgumentNumber()];
3364 if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
3365 NewTy = VectorType::getExtendedElementVectorType(VTy);
3366 else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
3367 NewTy = IntegerType::get(ITy->getContext(), 2 * ITy->getBitWidth());
3368 else
3369 return true;
3370
3371 return Ty != NewTy;
3372 }
3373 case IITDescriptor::TruncArgument: {
3374 // This may only be used when referring to a previous vector argument.
3375 if (D.getArgumentNumber() >= ArgTys.size())
3376 return true;
3377
3378 Type *NewTy = ArgTys[D.getArgumentNumber()];
3379 if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
3380 NewTy = VectorType::getTruncatedElementVectorType(VTy);
3381 else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
3382 NewTy = IntegerType::get(ITy->getContext(), ITy->getBitWidth() / 2);
3383 else
3384 return true;
3385
3386 return Ty != NewTy;
3387 }
3388 case IITDescriptor::HalfVecArgument:
3389 // This may only be used when referring to a previous vector argument.
3390 return D.getArgumentNumber() >= ArgTys.size() ||
3391 !isa<VectorType>(ArgTys[D.getArgumentNumber()]) ||
3392 VectorType::getHalfElementsVectorType(
3393 cast<VectorType>(ArgTys[D.getArgumentNumber()])) != Ty;
3394 case IITDescriptor::SameVecWidthArgument: {
3395 if (D.getArgumentNumber() >= ArgTys.size())
3396 return true;
3397 VectorType * ReferenceType =
3398 dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]);
3399 VectorType *ThisArgType = dyn_cast<VectorType>(Ty);
3400 if (!ThisArgType || !ReferenceType ||
3401 (ReferenceType->getVectorNumElements() !=
3402 ThisArgType->getVectorNumElements()))
3403 return true;
3404 return VerifyIntrinsicType(ThisArgType->getVectorElementType(),
3405 Infos, ArgTys);
3406 }
3407 case IITDescriptor::PtrToArgument: {
3408 if (D.getArgumentNumber() >= ArgTys.size())
3409 return true;
3410 Type * ReferenceType = ArgTys[D.getArgumentNumber()];
3411 PointerType *ThisArgType = dyn_cast<PointerType>(Ty);
3412 return (!ThisArgType || ThisArgType->getElementType() != ReferenceType);
3413 }
3414 case IITDescriptor::VecOfPtrsToElt: {
3415 if (D.getArgumentNumber() >= ArgTys.size())
3416 return true;
3417 VectorType * ReferenceType =
3418 dyn_cast<VectorType> (ArgTys[D.getArgumentNumber()]);
3419 VectorType *ThisArgVecTy = dyn_cast<VectorType>(Ty);
3420 if (!ThisArgVecTy || !ReferenceType ||
3421 (ReferenceType->getVectorNumElements() !=
3422 ThisArgVecTy->getVectorNumElements()))
3423 return true;
3424 PointerType *ThisArgEltTy =
3425 dyn_cast<PointerType>(ThisArgVecTy->getVectorElementType());
3426 if (!ThisArgEltTy)
3427 return true;
3428 return ThisArgEltTy->getElementType() !=
3429 ReferenceType->getVectorElementType();
3430 }
3431 }
3432 llvm_unreachable("unhandled")::llvm::llvm_unreachable_internal("unhandled", "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/lib/IR/Verifier.cpp"
, 3432)
;
3433}
3434
3435/// \brief Verify if the intrinsic has variable arguments.
3436/// This method is intended to be called after all the fixed arguments have been
3437/// verified first.
3438///
3439/// This method returns true on error and does not print an error message.
3440bool
3441Verifier::VerifyIntrinsicIsVarArg(bool isVarArg,
3442 ArrayRef<Intrinsic::IITDescriptor> &Infos) {
3443 using namespace Intrinsic;
3444
3445 // If there are no descriptors left, then it can't be a vararg.
3446 if (Infos.empty())
3447 return isVarArg;
3448
3449 // There should be only one descriptor remaining at this point.
3450 if (Infos.size() != 1)
3451 return true;
3452
3453 // Check and verify the descriptor.
3454 IITDescriptor D = Infos.front();
3455 Infos = Infos.slice(1);
3456 if (D.Kind == IITDescriptor::VarArg)
3457 return !isVarArg;
3458
3459 return true;
3460}
3461
3462/// Allow intrinsics to be verified in different ways.
3463void Verifier::visitIntrinsicCallSite(Intrinsic::ID ID, CallSite CS) {
3464 Function *IF = CS.getCalledFunction();
3465 Assert(IF->isDeclaration(), "Intrinsic functions should never be defined!",do { if (!(IF->isDeclaration())) { CheckFailed("Intrinsic functions should never be defined!"
, IF); return; } } while (0)
3466 IF)do { if (!(IF->isDeclaration())) { CheckFailed("Intrinsic functions should never be defined!"
, IF); return; } } while (0)
;
3467
3468 // Verify that the intrinsic prototype lines up with what the .td files
3469 // describe.
3470 FunctionType *IFTy = IF->getFunctionType();
3471 bool IsVarArg = IFTy->isVarArg();
3472
3473 SmallVector<Intrinsic::IITDescriptor, 8> Table;
3474 getIntrinsicInfoTableEntries(ID, Table);
3475 ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
3476
3477 SmallVector<Type *, 4> ArgTys;
3478 Assert(!VerifyIntrinsicType(IFTy->getReturnType(), TableRef, ArgTys),do { if (!(!VerifyIntrinsicType(IFTy->getReturnType(), TableRef
, ArgTys))) { CheckFailed("Intrinsic has incorrect return type!"
, IF); return; } } while (0)
3479 "Intrinsic has incorrect return type!", IF)do { if (!(!VerifyIntrinsicType(IFTy->getReturnType(), TableRef
, ArgTys))) { CheckFailed("Intrinsic has incorrect return type!"
, IF); return; } } while (0)
;
3480 for (unsigned i = 0, e = IFTy->getNumParams(); i != e; ++i)
3481 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)
3482 "Intrinsic has incorrect argument type!", IF)do { if (!(!VerifyIntrinsicType(IFTy->getParamType(i), TableRef
, ArgTys))) { CheckFailed("Intrinsic has incorrect argument type!"
, IF); return; } } while (0)
;
3483
3484 // Verify if the intrinsic call matches the vararg property.
3485 if (IsVarArg)
3486 Assert(!VerifyIntrinsicIsVarArg(IsVarArg, TableRef),do { if (!(!VerifyIntrinsicIsVarArg(IsVarArg, TableRef))) { CheckFailed
("Intrinsic was not defined with variable arguments!", IF); return
; } } while (0)
3487 "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)
;
3488 else
3489 Assert(!VerifyIntrinsicIsVarArg(IsVarArg, TableRef),do { if (!(!VerifyIntrinsicIsVarArg(IsVarArg, TableRef))) { CheckFailed
("Callsite was not defined with variable arguments!", IF); return
; } } while (0)
3490 "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)
;
3491
3492 // All descriptors should be absorbed by now.
3493 Assert(TableRef.empty(), "Intrinsic has too few arguments!", IF)do { if (!(TableRef.empty())) { CheckFailed("Intrinsic has too few arguments!"
, IF); return; } } while (0)
;
3494
3495 // Now that we have the intrinsic ID and the actual argument types (and we
3496 // know they are legal for the intrinsic!) get the intrinsic name through the
3497 // usual means. This allows us to verify the mangling of argument types into
3498 // the name.
3499 const std::string ExpectedName = Intrinsic::getName(ID, ArgTys);
3500 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)
3501 "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)
3502 "Should be: " +do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! "
"Should be: " + ExpectedName, IF); return; } } while (0)
3503 ExpectedName,do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! "
"Should be: " + ExpectedName, IF); return; } } while (0)
3504 IF)do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! "
"Should be: " + ExpectedName, IF); return; } } while (0)
;
3505
3506 // If the intrinsic takes MDNode arguments, verify that they are either global
3507 // or are local to *this* function.
3508 for (Value *V : CS.args())
3509 if (auto *MD = dyn_cast<MetadataAsValue>(V))
3510 visitMetadataAsValue(*MD, CS.getCaller());
3511
3512 switch (ID) {
3513 default:
3514 break;
3515 case Intrinsic::ctlz: // llvm.ctlz
3516 case Intrinsic::cttz: // llvm.cttz
3517 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)
3518 "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)
3519 "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)
3520 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)
;
3521 break;
3522 case Intrinsic::dbg_declare: // llvm.dbg.declare
3523 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)
3524 "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)
;
3525 visitDbgIntrinsic("declare", cast<DbgDeclareInst>(*CS.getInstruction()));
3526 break;
3527 case Intrinsic::dbg_value: // llvm.dbg.value
3528 visitDbgIntrinsic("value", cast<DbgValueInst>(*CS.getInstruction()));
3529 break;
3530 case Intrinsic::memcpy:
3531 case Intrinsic::memmove:
3532 case Intrinsic::memset: {
3533 ConstantInt *AlignCI = dyn_cast<ConstantInt>(CS.getArgOperand(3));
3534 Assert(AlignCI,do { if (!(AlignCI)) { CheckFailed("alignment argument of memory intrinsics must be a constant int"
, CS); return; } } while (0)
3535 "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)
3536 CS)do { if (!(AlignCI)) { CheckFailed("alignment argument of memory intrinsics must be a constant int"
, CS); return; } } while (0)
;
3537 const APInt &AlignVal = AlignCI->getValue();
3538 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)
3539 "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)
;
3540 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)
3541 "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)
3542 CS)do { if (!(isa<ConstantInt>(CS.getArgOperand(4)))) { CheckFailed
("isvolatile argument of memory intrinsics must be a constant int"
, CS); return; } } while (0)
;
3543 break;
3544 }
3545 case Intrinsic::gcroot:
3546 case Intrinsic::gcwrite:
3547 case Intrinsic::gcread:
3548 if (ID == Intrinsic::gcroot) {
3549 AllocaInst *AI =
3550 dyn_cast<AllocaInst>(CS.getArgOperand(0)->stripPointerCasts());
3551 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)
;
3552 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)
3553 "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)
;
3554 if (!AI->getAllocatedType()->isPointerTy()) {
3555 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)
3556 "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)
3557 "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)
3558 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)
;
3559 }
3560 }
3561
3562 Assert(CS.getParent()->getParent()->hasGC(),do { if (!(CS.getParent()->getParent()->hasGC())) { CheckFailed
("Enclosing function does not use GC.", CS); return; } } while
(0)
3563 "Enclosing function does not use GC.", CS)do { if (!(CS.getParent()->getParent()->hasGC())) { CheckFailed
("Enclosing function does not use GC.", CS); return; } } while
(0)
;
3564 break;
3565 case Intrinsic::init_trampoline:
3566 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)
3567 "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)
3568 CS)do { if (!(isa<Function>(CS.getArgOperand(1)->stripPointerCasts
()))) { CheckFailed("llvm.init_trampoline parameter #2 must resolve to a function."
, CS); return; } } while (0)
;
3569 break;
3570 case Intrinsic::prefetch:
3571 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)
3572 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)
3573 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)
3574 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)
3575 "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)
;
3576 break;
3577 case Intrinsic::stackprotector:
3578 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)
3579 "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)
;
3580 break;
3581 case Intrinsic::lifetime_start:
3582 case Intrinsic::lifetime_end:
3583 case Intrinsic::invariant_start:
3584 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)
3585 "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)
3586 CS)do { if (!(isa<ConstantInt>(CS.getArgOperand(0)))) { CheckFailed
("size argument of memory use markers must be a constant integer"
, CS); return; } } while (0)
;
3587 break;
3588 case Intrinsic::invariant_end:
3589 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)
3590 "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)
;
3591 break;
3592
3593 case Intrinsic::localescape: {
3594 BasicBlock *BB = CS.getParent();
3595 Assert(BB == &BB->getParent()->front(),do { if (!(BB == &BB->getParent()->front())) { CheckFailed
("llvm.localescape used outside of entry block", CS); return;
} } while (0)
3596 "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)
;
3597 Assert(!SawFrameEscape,do { if (!(!SawFrameEscape)) { CheckFailed("multiple calls to llvm.localescape in one function"
, CS); return; } } while (0)
3598 "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)
;
3599 for (Value *Arg : CS.args()) {
3600 if (isa<ConstantPointerNull>(Arg))
3601 continue; // Null values are allowed as placeholders.
3602 auto *AI = dyn_cast<AllocaInst>(Arg->stripPointerCasts());
3603 Assert(AI && AI->isStaticAlloca(),do { if (!(AI && AI->isStaticAlloca())) { CheckFailed
("llvm.localescape only accepts static allocas", CS); return;
} } while (0)
3604 "llvm.localescape only accepts static allocas", CS)do { if (!(AI && AI->isStaticAlloca())) { CheckFailed
("llvm.localescape only accepts static allocas", CS); return;
} } while (0)
;
3605 }
3606 FrameEscapeInfo[BB->getParent()].first = CS.getNumArgOperands();
3607 SawFrameEscape = true;
3608 break;
3609 }
3610 case Intrinsic::localrecover: {
3611 Value *FnArg = CS.getArgOperand(0)->stripPointerCasts();
3612 Function *Fn = dyn_cast<Function>(FnArg);
3613 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)
3614 "llvm.localrecover first "do { if (!(Fn && !Fn->isDeclaration())) { CheckFailed
("llvm.localrecover first " "argument must be function defined in this module"
, CS); return; } } while (0)
3615 "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)
3616 CS)do { if (!(Fn && !Fn->isDeclaration())) { CheckFailed
("llvm.localrecover first " "argument must be function defined in this module"
, CS); return; } } while (0)
;
3617 auto *IdxArg = dyn_cast<ConstantInt>(CS.getArgOperand(2));
3618 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)
3619 CS)do { if (!(IdxArg)) { CheckFailed("idx argument of llvm.localrecover must be a constant int"
, CS); return; } } while (0)
;
3620 auto &Entry = FrameEscapeInfo[Fn];
3621 Entry.second = unsigned(
3622 std::max(uint64_t(Entry.second), IdxArg->getLimitedValue(~0U) + 1));
3623 break;
3624 }
3625
3626 case Intrinsic::experimental_gc_statepoint:
3627 Assert(!CS.isInlineAsm(),do { if (!(!CS.isInlineAsm())) { CheckFailed("gc.statepoint support for inline assembly unimplemented"
, CS); return; } } while (0)
3628 "gc.statepoint support for inline assembly unimplemented", CS)do { if (!(!CS.isInlineAsm())) { CheckFailed("gc.statepoint support for inline assembly unimplemented"
, CS); return; } } while (0)
;
3629 Assert(CS.getParent()->getParent()->hasGC(),do { if (!(CS.getParent()->getParent()->hasGC())) { CheckFailed
("Enclosing function does not use GC.", CS); return; } } while
(0)
3630 "Enclosing function does not use GC.", CS)do { if (!(CS.getParent()->getParent()->hasGC())) { CheckFailed
("Enclosing function does not use GC.", CS); return; } } while
(0)
;
3631
3632 VerifyStatepoint(CS);
3633 break;
3634 case Intrinsic::experimental_gc_result: {
3635 Assert(CS.getParent()->getParent()->hasGC(),do { if (!(CS.getParent()->getParent()->hasGC())) { CheckFailed
("Enclosing function does not use GC.", CS); return; } } while
(0)
3636 "Enclosing function does not use GC.", CS)do { if (!(CS.getParent()->getParent()->hasGC())) { CheckFailed
("Enclosing function does not use GC.", CS); return; } } while
(0)
;
3637 // Are we tied to a statepoint properly?
3638 CallSite StatepointCS(CS.getArgOperand(0));
3639 const Function *StatepointFn =
3640 StatepointCS.getInstruction() ? StatepointCS.getCalledFunction() : nullptr;
3641 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)
3642 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)
3643 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)
3644 "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)
3645 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)
;
3646
3647 // Assert that result type matches wrapped callee.
3648 const Value *Target = StatepointCS.getArgument(2);
3649 auto *PT = cast<PointerType>(Target->getType());
3650 auto *TargetFuncType = cast<FunctionType>(PT->getElementType());
3651 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)
3652 "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)
;
3653 break;
3654 }
3655 case Intrinsic::experimental_gc_relocate: {
3656 Assert(CS.getNumArgOperands() == 3, "wrong number of arguments", CS)do { if (!(CS.getNumArgOperands() == 3)) { CheckFailed("wrong number of arguments"
, CS); return; } } while (0)
;
3657
3658 Assert(isa<PointerType>(CS.getType()->getScalarType()),do { if (!(isa<PointerType>(CS.getType()->getScalarType
()))) { CheckFailed("gc.relocate must return a pointer or a vector of pointers"
, CS); return; } } while (0)
3659 "gc.relocate must return a pointer or a vector of pointers", CS)do { if (!(isa<PointerType>(CS.getType()->getScalarType
()))) { CheckFailed("gc.relocate must return a pointer or a vector of pointers"
, CS); return; } } while (0)
;
3660
3661 // Check that this relocate is correctly tied to the statepoint
3662
3663 // This is case for relocate on the unwinding path of an invoke statepoint
3664 if (LandingPadInst *LandingPad =
3665 dyn_cast<LandingPadInst>(CS.getArgOperand(0))) {
3666
3667 const BasicBlock *InvokeBB =
3668 LandingPad->getParent()->getUniquePredecessor();
3669
3670 // Landingpad relocates should have only one predecessor with invoke
3671 // statepoint terminator
3672 Assert(InvokeBB, "safepoints should have unique landingpads",do { if (!(InvokeBB)) { CheckFailed("safepoints should have unique landingpads"
, LandingPad->getParent()); return; } } while (0)
3673 LandingPad->getParent())do { if (!(InvokeBB)) { CheckFailed("safepoints should have unique landingpads"
, LandingPad->getParent()); return; } } while (0)
;
3674 Assert(InvokeBB->getTerminator(), "safepoint block should be well formed",do { if (!(InvokeBB->getTerminator())) { CheckFailed("safepoint block should be well formed"
, InvokeBB); return; } } while (0)
3675 InvokeBB)do { if (!(InvokeBB->getTerminator())) { CheckFailed("safepoint block should be well formed"
, InvokeBB); return; } } while (0)
;
3676 Assert(isStatepoint(InvokeBB->getTerminator()),do { if (!(isStatepoint(InvokeBB->getTerminator()))) { CheckFailed
("gc relocate should be linked to a statepoint", InvokeBB); return
; } } while (0)
3677 "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)
;
3678 }
3679 else {
3680 // In all other cases relocate should be tied to the statepoint directly.
3681 // This covers relocates on a normal return path of invoke statepoint and
3682 // relocates of a call statepoint
3683 auto Token = CS.getArgOperand(0);
3684 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)
3685 "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)
;
3686 }
3687
3688 // Verify rest of the relocate arguments
3689
3690 ImmutableCallSite StatepointCS(
3691 cast<GCRelocateInst>(*CS.getInstruction()).getStatepoint());
3692
3693 // Both the base and derived must be piped through the safepoint
3694 Value* Base = CS.getArgOperand(1);
3695 Assert(isa<ConstantInt>(Base),do { if (!(isa<ConstantInt>(Base))) { CheckFailed("gc.relocate operand #2 must be integer offset"
, CS); return; } } while (0)
3696 "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)
;
3697
3698 Value* Derived = CS.getArgOperand(2);
3699 Assert(isa<ConstantInt>(Derived),do { if (!(isa<ConstantInt>(Derived))) { CheckFailed("gc.relocate operand #3 must be integer offset"
, CS); return; } } while (0)
3700 "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)
;
3701
3702 const int BaseIndex = cast<ConstantInt>(Base)->getZExtValue();
3703 const int DerivedIndex = cast<ConstantInt>(Derived)->getZExtValue();
3704 // Check the bounds
3705 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)
3706 "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)
;
3707 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)
3708 "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)
;
3709
3710 // Check that BaseIndex and DerivedIndex fall within the 'gc parameters'
3711 // section of the statepoint's argument
3712 Assert(StatepointCS.arg_size() > 0,do { if (!(StatepointCS.arg_size() > 0)) { CheckFailed("gc.statepoint: insufficient arguments"
); return; } } while (0)
3713 "gc.statepoint: insufficient arguments")do { if (!(StatepointCS.arg_size() > 0)) { CheckFailed("gc.statepoint: insufficient arguments"
); return; } } while (0)
;
3714 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)
3715 "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)
;
3716 const unsigned NumCallArgs =
3717 cast<ConstantInt>(StatepointCS.getArgument(3))->getZExtValue();
3718 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)
3719 "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)
;
3720 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)
3721 "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)
3722 "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)
;
3723 const int NumTransitionArgs =
3724 cast<ConstantInt>(StatepointCS.getArgument(NumCallArgs + 5))
3725 ->getZExtValue();
3726 const int DeoptArgsStart = 4 + NumCallArgs + 1 + NumTransitionArgs + 1;
3727 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)
3728 "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)
3729 "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)
;
3730 const int NumDeoptArgs =
3731 cast<ConstantInt>(StatepointCS.getArgument(DeoptArgsStart))->getZExtValue();
3732 const int GCParamArgsStart = DeoptArgsStart + 1 + NumDeoptArgs;
3733 const int GCParamArgsEnd = StatepointCS.arg_size();
3734 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)
3735 "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)
3736 "'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)
3737 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)
;
3738 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)
3739 "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)
3740 "'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)
3741 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)
;
3742
3743 // Relocated value must be either a pointer type or vector-of-pointer type,
3744 // but gc_relocate does not need to return the same pointer type as the
3745 // relocated pointer. It can be casted to the correct type later if it's
3746 // desired. However, they must have the same address space and 'vectorness'
3747 GCRelocateInst &Relocate = cast<GCRelocateInst>(*CS.getInstruction());
3748 Assert(Relocate.getDerivedPtr()->getType()->getScalarType()->isPointerTy(),do { if (!(Relocate.getDerivedPtr()->getType()->getScalarType
()->isPointerTy())) { CheckFailed("gc.relocate: relocated value must be a gc pointer"
, CS); return; } } while (0)
3749 "gc.relocate: relocated value must be a gc pointer", CS)do { if (!(Relocate.getDerivedPtr()->getType()->getScalarType
()->isPointerTy())) { CheckFailed("gc.relocate: relocated value must be a gc pointer"
, CS); return; } } while (0)
;
3750
3751 auto ResultType = CS.getType();
3752 auto DerivedType = Relocate.getDerivedPtr()->getType();
3753 Assert(ResultType->isVectorTy() == DerivedType->isVectorTy(),do { if (!(ResultType->isVectorTy() == DerivedType->isVectorTy
())) { CheckFailed("gc.relocate: vector relocates to vector and pointer to pointer"
, CS); return; } } while (0)
3754 "gc.relocate: vector relocates to vector and pointer to pointer", CS)do { if (!(ResultType->isVectorTy() == DerivedType->isVectorTy
())) { CheckFailed("gc.relocate: vector relocates to vector and pointer to pointer"
, CS); return; } } while (0)
;
3755 Assert(ResultType->getPointerAddressSpace() ==do { if (!(ResultType->getPointerAddressSpace() == DerivedType
->getPointerAddressSpace())) { CheckFailed("gc.relocate: relocating a pointer shouldn't change its address space"
, CS); return; } } while (0)
3756 DerivedType->getPointerAddressSpace(),do { if (!(ResultType->getPointerAddressSpace() == DerivedType
->getPointerAddressSpace())) { CheckFailed("gc.relocate: relocating a pointer shouldn't change its address space"
, CS); return; } } while (0)
3757 "gc.relocate: relocating a pointer shouldn't change its address space", CS)do { if (!(ResultType->getPointerAddressSpace() == DerivedType
->getPointerAddressSpace())) { CheckFailed("gc.relocate: relocating a pointer shouldn't change its address space"
, CS); return; } } while (0)
;
3758 break;
3759 }
3760 case Intrinsic::eh_exceptioncode:
3761 case Intrinsic::eh_exceptionpointer: {
3762 Assert(isa<CatchPadInst>(CS.getArgOperand(0)),do { if (!(isa<CatchPadInst>(CS.getArgOperand(0)))) { CheckFailed
("eh.exceptionpointer argument must be a catchpad", CS); return
; } } while (0)
3763 "eh.exceptionpointer argument must be a catchpad", CS)do { if (!(isa<CatchPadInst>(CS.getArgOperand(0)))) { CheckFailed
("eh.exceptionpointer argument must be a catchpad", CS); return
; } } while (0)
;
3764 break;
3765 }
3766 };
3767}
3768
3769/// \brief Carefully grab the subprogram from a local scope.
3770///
3771/// This carefully grabs the subprogram from a local scope, avoiding the
3772/// built-in assertions that would typically fire.
3773static DISubprogram *getSubprogram(Metadata *LocalScope) {
3774 if (!LocalScope)
3775 return nullptr;
3776
3777 if (auto *SP = dyn_cast<DISubprogram>(LocalScope))
3778 return SP;
3779
3780 if (auto *LB = dyn_cast<DILexicalBlockBase>(LocalScope))
3781 return getSubprogram(LB->getRawScope());
3782
3783 // Just return null; broken scope chains are checked elsewhere.
3784 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~svn257205/lib/IR/Verifier.cpp"
, 3784, __PRETTY_FUNCTION__))
;
3785 return nullptr;
3786}
3787
3788template <class DbgIntrinsicTy>
3789void Verifier::visitDbgIntrinsic(StringRef Kind, DbgIntrinsicTy &DII) {
3790 auto *MD = cast<MetadataAsValue>(DII.getArgOperand(0))->getMetadata();
3791 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)
3792 (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)
3793 "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)
;
3794 Assert(isa<DILocalVariable>(DII.getRawVariable()),do { if (!(isa<DILocalVariable>(DII.getRawVariable())))
{ CheckFailed("invalid llvm.dbg." + Kind + " intrinsic variable"
, &DII, DII.getRawVariable()); return; } } while (0)
3795 "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)
3796 DII.getRawVariable())do { if (!(isa<DILocalVariable>(DII.getRawVariable())))
{ CheckFailed("invalid llvm.dbg." + Kind + " intrinsic variable"
, &DII, DII.getRawVariable()); return; } } while (0)
;
3797 Assert(isa<DIExpression>(DII.getRawExpression()),do { if (!(isa<DIExpression>(DII.getRawExpression()))) {
CheckFailed("invalid llvm.dbg." + Kind + " intrinsic expression"
, &DII, DII.getRawExpression()); return; } } while (0)
3798 "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)
3799 DII.getRawExpression())do { if (!(isa<DIExpression>(DII.getRawExpression()))) {
CheckFailed("invalid llvm.dbg." + Kind + " intrinsic expression"
, &DII, DII.getRawExpression()); return; } } while (0)
;
3800
3801 // Ignore broken !dbg attachments; they're checked elsewhere.
3802 if (MDNode *N = DII.getDebugLoc().getAsMDNode())
3803 if (!isa<DILocation>(N))
3804 return;
3805
3806 BasicBlock *BB = DII.getParent();
3807 Function *F = BB ? BB->getParent() : nullptr;
3808
3809 // The scopes for variables and !dbg attachments must agree.
3810 DILocalVariable *Var = DII.getVariable();
3811 DILocation *Loc = DII.getDebugLoc();
3812 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)
3813 &DII, BB, F)do { if (!(Loc)) { CheckFailed("llvm.dbg." + Kind + " intrinsic requires a !dbg attachment"
, &DII, BB, F); return; } } while (0)
;
3814
3815 DISubprogram *VarSP = getSubprogram(Var->getRawScope());
3816 DISubprogram *LocSP = getSubprogram(Loc->getRawScope());
3817 if (!VarSP || !LocSP)
3818 return; // Broken scope chains are checked elsewhere.
3819
3820 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)
3821 " 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)
3822 &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)
3823 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)
;
3824}
3825
3826template <class MapTy>
3827static uint64_t getVariableSize(const DILocalVariable &V, const MapTy &Map) {
3828 // Be careful of broken types (checked elsewhere).
3829 const Metadata *RawType = V.getRawType();
3830 while (RawType) {
3831 // Try to get the size directly.
3832 if (auto *T = dyn_cast<DIType>(RawType))
3833 if (uint64_t Size = T->getSizeInBits())
3834 return Size;
3835
3836 if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
3837 // Look at the base type.
3838 RawType = DT->getRawBaseType();
3839 continue;
3840 }
3841
3842 if (auto *S = dyn_cast<MDString>(RawType)) {
3843 // Don't error on missing types (checked elsewhere).
3844 RawType = Map.lookup(S);
3845 continue;
3846 }
3847
3848 // Missing type or size.
3849 break;
3850 }
3851
3852 // Fail gracefully.
3853 return 0;
3854}
3855
3856template <class MapTy>
3857void Verifier::verifyBitPieceExpression(const DbgInfoIntrinsic &I,
3858 const MapTy &TypeRefs) {
3859 DILocalVariable *V;
3860 DIExpression *E;
3861 if (auto *DVI = dyn_cast<DbgValueInst>(&I)) {
3862 V = dyn_cast_or_null<DILocalVariable>(DVI->getRawVariable());
3863 E = dyn_cast_or_null<DIExpression>(DVI->getRawExpression());
3864 } else {
3865 auto *DDI = cast<DbgDeclareInst>(&I);
3866 V = dyn_cast_or_null<DILocalVariable>(DDI->getRawVariable());
3867 E = dyn_cast_or_null<DIExpression>(DDI->getRawExpression());
3868 }
3869
3870 // We don't know whether this intrinsic verified correctly.
3871 if (!V || !E || !E->isValid())
3872 return;
3873
3874 // Nothing to do if this isn't a bit piece expression.
3875 if (!E->isBitPiece())
3876 return;
3877
3878 // The frontend helps out GDB by emitting the members of local anonymous
3879 // unions as artificial local variables with shared storage. When SROA splits
3880 // the storage for artificial local variables that are smaller than the entire
3881 // union, the overhang piece will be outside of the allotted space for the
3882 // variable and this check fails.
3883 // FIXME: Remove this check as soon as clang stops doing this; it hides bugs.
3884 if (V->isArtificial())
3885 return;
3886
3887 // If there's no size, the type is broken, but that should be checked
3888 // elsewhere.
3889 uint64_t VarSize = getVariableSize(*V, TypeRefs);
3890 if (!VarSize)
3891 return;
3892
3893 unsigned PieceSize = E->getBitPieceSize();
3894 unsigned PieceOffset = E->getBitPieceOffset();
3895 Assert(PieceSize + PieceOffset <= VarSize,do { if (!(PieceSize + PieceOffset <= VarSize)) { CheckFailed
("piece is larger than or outside of variable", &I, V, E)
; return; } } while (0)
3896 "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)
;
3897 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)
;
3898}
3899
3900void Verifier::visitUnresolvedTypeRef(const MDString *S, const MDNode *N) {
3901 // This is in its own function so we get an error for each bad type ref (not
3902 // just the first).
3903 Assert(false, "unresolved type ref", S, N)do { if (!(false)) { CheckFailed("unresolved type ref", S, N)
; return; } } while (0)
;
3904}
3905
3906void Verifier::verifyTypeRefs() {
3907 auto *CUs = M->getNamedMetadata("llvm.dbg.cu");
3908 if (!CUs)
3909 return;
3910
3911 // Visit all the compile units again to map the type references.
3912 SmallDenseMap<const MDString *, const DIType *, 32> TypeRefs;
3913 for (auto *CU : CUs->operands())
3914 if (auto Ts = cast<DICompileUnit>(CU)->getRetainedTypes())
3915 for (DIType *Op : Ts)
3916 if (auto *T = dyn_cast_or_null<DICompositeType>(Op))
3917 if (auto *S = T->getRawIdentifier()) {
3918 UnresolvedTypeRefs.erase(S);
3919 TypeRefs.insert(std::make_pair(S, T));
3920 }
3921
3922 // Verify debug info intrinsic bit piece expressions. This needs a second
3923 // pass through the intructions, since we haven't built TypeRefs yet when
3924 // verifying functions, and simply queuing the DbgInfoIntrinsics to evaluate
3925 // later/now would queue up some that could be later deleted.
3926 for (const Function &F : *M)
3927 for (const BasicBlock &BB : F)
3928 for (const Instruction &I : BB)
3929 if (auto *DII = dyn_cast<DbgInfoIntrinsic>(&I))
3930 verifyBitPieceExpression(*DII, TypeRefs);
3931
3932 // Return early if all typerefs were resolved.
3933 if (UnresolvedTypeRefs.empty())
3934 return;
3935
3936 // Sort the unresolved references by name so the output is deterministic.
3937 typedef std::pair<const MDString *, const MDNode *> TypeRef;
3938 SmallVector<TypeRef, 32> Unresolved(UnresolvedTypeRefs.begin(),
3939 UnresolvedTypeRefs.end());
3940 std::sort(Unresolved.begin(), Unresolved.end(),
3941 [](const TypeRef &LHS, const TypeRef &RHS) {
3942 return LHS.first->getString() < RHS.first->getString();
3943 });
3944
3945 // Visit the unresolved refs (printing out the errors).
3946 for (const TypeRef &TR : Unresolved)
3947 visitUnresolvedTypeRef(TR.first, TR.second);
3948}
3949
3950//===----------------------------------------------------------------------===//
3951// Implement the public interfaces to this file...
3952//===----------------------------------------------------------------------===//
3953
3954bool llvm::verifyFunction(const Function &f, raw_ostream *OS) {
3955 Function &F = const_cast<Function &>(f);
3956 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~svn257205/lib/IR/Verifier.cpp"
, 3956, __PRETTY_FUNCTION__))
;
3957
3958 raw_null_ostream NullStr;
3959 Verifier V(OS ? *OS : NullStr);
3960
3961 // Note that this function's return value is inverted from what you would
3962 // expect of a function called "verify".
3963 return !V.verify(F);
3964}
3965
3966bool llvm::verifyModule(const Module &M, raw_ostream *OS) {
3967 raw_null_ostream NullStr;
3968 Verifier V(OS ? *OS : NullStr);
3969
3970 bool Broken = false;
3971 for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)
3972 if (!I->isDeclaration() && !I->isMaterializable())
3973 Broken |= !V.verify(*I);
3974
3975 // Note that this function's return value is inverted from what you would
3976 // expect of a function called "verify".
3977 return !V.verify(M) || Broken;
3978}
3979
3980namespace {
3981struct VerifierLegacyPass : public FunctionPass {
3982 static char ID;
3983
3984 Verifier V;
3985 bool FatalErrors;
3986
3987 VerifierLegacyPass() : FunctionPass(ID), V(dbgs()), FatalErrors(true) {
3988 initializeVerifierLegacyPassPass(*PassRegistry::getPassRegistry());
3989 }
3990 explicit VerifierLegacyPass(bool FatalErrors)
3991 : FunctionPass(ID), V(dbgs()), FatalErrors(FatalErrors) {
3992 initializeVerifierLegacyPassPass(*PassRegistry::getPassRegistry());
3993 }
3994
3995 bool runOnFunction(Function &F) override {
3996 if (!V.verify(F) && FatalErrors)
3997 report_fatal_error("Broken function found, compilation aborted!");
3998
3999 return false;
4000 }
4001
4002 bool doFinalization(Module &M) override {
4003 if (!V.verify(M) && FatalErrors)
4004 report_fatal_error("Broken module found, compilation aborted!");
4005
4006 return false;
4007 }
4008
4009 void getAnalysisUsage(AnalysisUsage &AU) const override {
4010 AU.setPreservesAll();
4011 }
4012};
4013}
4014
4015char VerifierLegacyPass::ID = 0;
4016INITIALIZE_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(); } } ; }
4017
4018FunctionPass *llvm::createVerifierPass(bool FatalErrors) {
4019 return new VerifierLegacyPass(FatalErrors);
4020}
4021
4022PreservedAnalyses VerifierPass::run(Module &M) {
4023 if (verifyModule(M, &dbgs()) && FatalErrors)
4024 report_fatal_error("Broken module found, compilation aborted!");
4025
4026 return PreservedAnalyses::all();
4027}
4028
4029PreservedAnalyses VerifierPass::run(Function &F) {
4030 if (verifyFunction(F, &dbgs()) && FatalErrors)
4031 report_fatal_error("Broken function found, compilation aborted!");
4032
4033 return PreservedAnalyses::all();
4034}