Bug Summary

File:lib/IR/Verifier.cpp
Warning:line 2327, column 7
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name Verifier.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-8/lib/clang/8.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/lib/IR -I /build/llvm-toolchain-snapshot-8~svn350071/lib/IR -I /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/include -I /build/llvm-toolchain-snapshot-8~svn350071/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/include/clang/8.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-8/lib/clang/8.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/lib/IR -fdebug-prefix-map=/build/llvm-toolchain-snapshot-8~svn350071=. -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -stack-protector 2 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-12-27-042839-1215-1 -x c++ /build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp -faddrsig
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/APFloat.h"
49#include "llvm/ADT/APInt.h"
50#include "llvm/ADT/ArrayRef.h"
51#include "llvm/ADT/DenseMap.h"
52#include "llvm/ADT/MapVector.h"
53#include "llvm/ADT/Optional.h"
54#include "llvm/ADT/STLExtras.h"
55#include "llvm/ADT/SmallPtrSet.h"
56#include "llvm/ADT/SmallSet.h"
57#include "llvm/ADT/SmallVector.h"
58#include "llvm/ADT/StringExtras.h"
59#include "llvm/ADT/StringMap.h"
60#include "llvm/ADT/StringRef.h"
61#include "llvm/ADT/Twine.h"
62#include "llvm/ADT/ilist.h"
63#include "llvm/BinaryFormat/Dwarf.h"
64#include "llvm/IR/Argument.h"
65#include "llvm/IR/Attributes.h"
66#include "llvm/IR/BasicBlock.h"
67#include "llvm/IR/CFG.h"
68#include "llvm/IR/CallSite.h"
69#include "llvm/IR/CallingConv.h"
70#include "llvm/IR/Comdat.h"
71#include "llvm/IR/Constant.h"
72#include "llvm/IR/ConstantRange.h"
73#include "llvm/IR/Constants.h"
74#include "llvm/IR/DataLayout.h"
75#include "llvm/IR/DebugInfo.h"
76#include "llvm/IR/DebugInfoMetadata.h"
77#include "llvm/IR/DebugLoc.h"
78#include "llvm/IR/DerivedTypes.h"
79#include "llvm/IR/Dominators.h"
80#include "llvm/IR/Function.h"
81#include "llvm/IR/GlobalAlias.h"
82#include "llvm/IR/GlobalValue.h"
83#include "llvm/IR/GlobalVariable.h"
84#include "llvm/IR/InlineAsm.h"
85#include "llvm/IR/InstVisitor.h"
86#include "llvm/IR/InstrTypes.h"
87#include "llvm/IR/Instruction.h"
88#include "llvm/IR/Instructions.h"
89#include "llvm/IR/IntrinsicInst.h"
90#include "llvm/IR/Intrinsics.h"
91#include "llvm/IR/LLVMContext.h"
92#include "llvm/IR/Metadata.h"
93#include "llvm/IR/Module.h"
94#include "llvm/IR/ModuleSlotTracker.h"
95#include "llvm/IR/PassManager.h"
96#include "llvm/IR/Statepoint.h"
97#include "llvm/IR/Type.h"
98#include "llvm/IR/Use.h"
99#include "llvm/IR/User.h"
100#include "llvm/IR/Value.h"
101#include "llvm/Pass.h"
102#include "llvm/Support/AtomicOrdering.h"
103#include "llvm/Support/Casting.h"
104#include "llvm/Support/CommandLine.h"
105#include "llvm/Support/Debug.h"
106#include "llvm/Support/ErrorHandling.h"
107#include "llvm/Support/MathExtras.h"
108#include "llvm/Support/raw_ostream.h"
109#include <algorithm>
110#include <cassert>
111#include <cstdint>
112#include <memory>
113#include <string>
114#include <utility>
115
116using namespace llvm;
117
118namespace llvm {
119
120struct VerifierSupport {
121 raw_ostream *OS;
122 const Module &M;
123 ModuleSlotTracker MST;
124 const DataLayout &DL;
125 LLVMContext &Context;
126
127 /// Track the brokenness of the module while recursively visiting.
128 bool Broken = false;
129 /// Broken debug info can be "recovered" from by stripping the debug info.
130 bool BrokenDebugInfo = false;
131 /// Whether to treat broken debug info as an error.
132 bool TreatBrokenDebugInfoAsError = true;
133
134 explicit VerifierSupport(raw_ostream *OS, const Module &M)
135 : OS(OS), M(M), MST(&M), DL(M.getDataLayout()), Context(M.getContext()) {}
136
137private:
138 void Write(const Module *M) {
139 *OS << "; ModuleID = '" << M->getModuleIdentifier() << "'\n";
140 }
141
142 void Write(const Value *V) {
143 if (!V)
144 return;
145 if (isa<Instruction>(V)) {
146 V->print(*OS, MST);
147 *OS << '\n';
148 } else {
149 V->printAsOperand(*OS, true, MST);
150 *OS << '\n';
151 }
152 }
153
154 void Write(ImmutableCallSite CS) {
155 Write(CS.getInstruction());
156 }
157
158 void Write(const Metadata *MD) {
159 if (!MD)
160 return;
161 MD->print(*OS, MST, &M);
162 *OS << '\n';
163 }
164
165 template <class T> void Write(const MDTupleTypedArrayWrapper<T> &MD) {
166 Write(MD.get());
167 }
168
169 void Write(const NamedMDNode *NMD) {
170 if (!NMD)
171 return;
172 NMD->print(*OS, MST);
173 *OS << '\n';
174 }
175
176 void Write(Type *T) {
177 if (!T)
178 return;
179 *OS << ' ' << *T;
180 }
181
182 void Write(const Comdat *C) {
183 if (!C)
184 return;
185 *OS << *C;
186 }
187
188 void Write(const APInt *AI) {
189 if (!AI)
190 return;
191 *OS << *AI << '\n';
192 }
193
194 void Write(const unsigned i) { *OS << i << '\n'; }
195
196 template <typename T> void Write(ArrayRef<T> Vs) {
197 for (const T &V : Vs)
198 Write(V);
199 }
200
201 template <typename T1, typename... Ts>
202 void WriteTs(const T1 &V1, const Ts &... Vs) {
203 Write(V1);
204 WriteTs(Vs...);
205 }
206
207 template <typename... Ts> void WriteTs() {}
208
209public:
210 /// A check failed, so printout out the condition and the message.
211 ///
212 /// This provides a nice place to put a breakpoint if you want to see why
213 /// something is not correct.
214 void CheckFailed(const Twine &Message) {
215 if (OS)
216 *OS << Message << '\n';
217 Broken = true;
218 }
219
220 /// A check failed (with values to print).
221 ///
222 /// This calls the Message-only version so that the above is easier to set a
223 /// breakpoint on.
224 template <typename T1, typename... Ts>
225 void CheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs) {
226 CheckFailed(Message);
227 if (OS)
228 WriteTs(V1, Vs...);
229 }
230
231 /// A debug info check failed.
232 void DebugInfoCheckFailed(const Twine &Message) {
233 if (OS)
234 *OS << Message << '\n';
235 Broken |= TreatBrokenDebugInfoAsError;
236 BrokenDebugInfo = true;
237 }
238
239 /// A debug info check failed (with values to print).
240 template <typename T1, typename... Ts>
241 void DebugInfoCheckFailed(const Twine &Message, const T1 &V1,
242 const Ts &... Vs) {
243 DebugInfoCheckFailed(Message);
244 if (OS)
245 WriteTs(V1, Vs...);
246 }
247};
248
249} // namespace llvm
250
251namespace {
252
253class Verifier : public InstVisitor<Verifier>, VerifierSupport {
254 friend class InstVisitor<Verifier>;
255
256 DominatorTree DT;
257
258 /// When verifying a basic block, keep track of all of the
259 /// instructions we have seen so far.
260 ///
261 /// This allows us to do efficient dominance checks for the case when an
262 /// instruction has an operand that is an instruction in the same block.
263 SmallPtrSet<Instruction *, 16> InstsInThisBlock;
264
265 /// Keep track of the metadata nodes that have been checked already.
266 SmallPtrSet<const Metadata *, 32> MDNodes;
267
268 /// Keep track which DISubprogram is attached to which function.
269 DenseMap<const DISubprogram *, const Function *> DISubprogramAttachments;
270
271 /// Track all DICompileUnits visited.
272 SmallPtrSet<const Metadata *, 2> CUVisited;
273
274 /// The result type for a landingpad.
275 Type *LandingPadResultTy;
276
277 /// Whether we've seen a call to @llvm.localescape in this function
278 /// already.
279 bool SawFrameEscape;
280
281 /// Whether the current function has a DISubprogram attached to it.
282 bool HasDebugInfo = false;
283
284 /// Whether source was present on the first DIFile encountered in each CU.
285 DenseMap<const DICompileUnit *, bool> HasSourceDebugInfo;
286
287 /// Stores the count of how many objects were passed to llvm.localescape for a
288 /// given function and the largest index passed to llvm.localrecover.
289 DenseMap<Function *, std::pair<unsigned, unsigned>> FrameEscapeInfo;
290
291 // Maps catchswitches and cleanuppads that unwind to siblings to the
292 // terminators that indicate the unwind, used to detect cycles therein.
293 MapVector<Instruction *, Instruction *> SiblingFuncletInfo;
294
295 /// Cache of constants visited in search of ConstantExprs.
296 SmallPtrSet<const Constant *, 32> ConstantExprVisited;
297
298 /// Cache of declarations of the llvm.experimental.deoptimize.<ty> intrinsic.
299 SmallVector<const Function *, 4> DeoptimizeDeclarations;
300
301 // Verify that this GlobalValue is only used in this module.
302 // This map is used to avoid visiting uses twice. We can arrive at a user
303 // twice, if they have multiple operands. In particular for very large
304 // constant expressions, we can arrive at a particular user many times.
305 SmallPtrSet<const Value *, 32> GlobalValueVisited;
306
307 // Keeps track of duplicate function argument debug info.
308 SmallVector<const DILocalVariable *, 16> DebugFnArgs;
309
310 TBAAVerifier TBAAVerifyHelper;
311
312 void checkAtomicMemAccessSize(Type *Ty, const Instruction *I);
313
314public:
315 explicit Verifier(raw_ostream *OS, bool ShouldTreatBrokenDebugInfoAsError,
316 const Module &M)
317 : VerifierSupport(OS, M), LandingPadResultTy(nullptr),
318 SawFrameEscape(false), TBAAVerifyHelper(this) {
319 TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError;
320 }
321
322 bool hasBrokenDebugInfo() const { return BrokenDebugInfo; }
323
324 bool verify(const Function &F) {
325 assert(F.getParent() == &M &&((F.getParent() == &M && "An instance of this class only works with a specific module!"
) ? static_cast<void> (0) : __assert_fail ("F.getParent() == &M && \"An instance of this class only works with a specific module!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp"
, 326, __PRETTY_FUNCTION__))
326 "An instance of this class only works with a specific module!")((F.getParent() == &M && "An instance of this class only works with a specific module!"
) ? static_cast<void> (0) : __assert_fail ("F.getParent() == &M && \"An instance of this class only works with a specific module!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp"
, 326, __PRETTY_FUNCTION__))
;
327
328 // First ensure the function is well-enough formed to compute dominance
329 // information, and directly compute a dominance tree. We don't rely on the
330 // pass manager to provide this as it isolates us from a potentially
331 // out-of-date dominator tree and makes it significantly more complex to run
332 // this code outside of a pass manager.
333 // FIXME: It's really gross that we have to cast away constness here.
334 if (!F.empty())
335 DT.recalculate(const_cast<Function &>(F));
336
337 for (const BasicBlock &BB : F) {
338 if (!BB.empty() && BB.back().isTerminator())
339 continue;
340
341 if (OS) {
342 *OS << "Basic Block in function '" << F.getName()
343 << "' does not have terminator!\n";
344 BB.printAsOperand(*OS, true, MST);
345 *OS << "\n";
346 }
347 return false;
348 }
349
350 Broken = false;
351 // FIXME: We strip const here because the inst visitor strips const.
352 visit(const_cast<Function &>(F));
353 verifySiblingFuncletUnwinds();
354 InstsInThisBlock.clear();
355 DebugFnArgs.clear();
356 LandingPadResultTy = nullptr;
357 SawFrameEscape = false;
358 SiblingFuncletInfo.clear();
359
360 return !Broken;
361 }
362
363 /// Verify the module that this instance of \c Verifier was initialized with.
364 bool verify() {
365 Broken = false;
366
367 // Collect all declarations of the llvm.experimental.deoptimize intrinsic.
368 for (const Function &F : M)
369 if (F.getIntrinsicID() == Intrinsic::experimental_deoptimize)
370 DeoptimizeDeclarations.push_back(&F);
371
372 // Now that we've visited every function, verify that we never asked to
373 // recover a frame index that wasn't escaped.
374 verifyFrameRecoverIndices();
375 for (const GlobalVariable &GV : M.globals())
376 visitGlobalVariable(GV);
377
378 for (const GlobalAlias &GA : M.aliases())
379 visitGlobalAlias(GA);
380
381 for (const NamedMDNode &NMD : M.named_metadata())
382 visitNamedMDNode(NMD);
383
384 for (const StringMapEntry<Comdat> &SMEC : M.getComdatSymbolTable())
385 visitComdat(SMEC.getValue());
386
387 visitModuleFlags(M);
388 visitModuleIdents(M);
389 visitModuleCommandLines(M);
390
391 verifyCompileUnits();
392
393 verifyDeoptimizeCallingConvs();
394 DISubprogramAttachments.clear();
395 return !Broken;
396 }
397
398private:
399 // Verification methods...
400 void visitGlobalValue(const GlobalValue &GV);
401 void visitGlobalVariable(const GlobalVariable &GV);
402 void visitGlobalAlias(const GlobalAlias &GA);
403 void visitAliaseeSubExpr(const GlobalAlias &A, const Constant &C);
404 void visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias *> &Visited,
405 const GlobalAlias &A, const Constant &C);
406 void visitNamedMDNode(const NamedMDNode &NMD);
407 void visitMDNode(const MDNode &MD);
408 void visitMetadataAsValue(const MetadataAsValue &MD, Function *F);
409 void visitValueAsMetadata(const ValueAsMetadata &MD, Function *F);
410 void visitComdat(const Comdat &C);
411 void visitModuleIdents(const Module &M);
412 void visitModuleCommandLines(const Module &M);
413 void visitModuleFlags(const Module &M);
414 void visitModuleFlag(const MDNode *Op,
415 DenseMap<const MDString *, const MDNode *> &SeenIDs,
416 SmallVectorImpl<const MDNode *> &Requirements);
417 void visitModuleFlagCGProfileEntry(const MDOperand &MDO);
418 void visitFunction(const Function &F);
419 void visitBasicBlock(BasicBlock &BB);
420 void visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty);
421 void visitDereferenceableMetadata(Instruction &I, MDNode *MD);
422
423 template <class Ty> bool isValidMetadataArray(const MDTuple &N);
424#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N);
425#include "llvm/IR/Metadata.def"
426 void visitDIScope(const DIScope &N);
427 void visitDIVariable(const DIVariable &N);
428 void visitDILexicalBlockBase(const DILexicalBlockBase &N);
429 void visitDITemplateParameter(const DITemplateParameter &N);
430
431 void visitTemplateParams(const MDNode &N, const Metadata &RawParams);
432
433 // InstVisitor overrides...
434 using InstVisitor<Verifier>::visit;
435 void visit(Instruction &I);
436
437 void visitTruncInst(TruncInst &I);
438 void visitZExtInst(ZExtInst &I);
439 void visitSExtInst(SExtInst &I);
440 void visitFPTruncInst(FPTruncInst &I);
441 void visitFPExtInst(FPExtInst &I);
442 void visitFPToUIInst(FPToUIInst &I);
443 void visitFPToSIInst(FPToSIInst &I);
444 void visitUIToFPInst(UIToFPInst &I);
445 void visitSIToFPInst(SIToFPInst &I);
446 void visitIntToPtrInst(IntToPtrInst &I);
447 void visitPtrToIntInst(PtrToIntInst &I);
448 void visitBitCastInst(BitCastInst &I);
449 void visitAddrSpaceCastInst(AddrSpaceCastInst &I);
450 void visitPHINode(PHINode &PN);
451 void visitUnaryOperator(UnaryOperator &U);
452 void visitBinaryOperator(BinaryOperator &B);
453 void visitICmpInst(ICmpInst &IC);
454 void visitFCmpInst(FCmpInst &FC);
455 void visitExtractElementInst(ExtractElementInst &EI);
456 void visitInsertElementInst(InsertElementInst &EI);
457 void visitShuffleVectorInst(ShuffleVectorInst &EI);
458 void visitVAArgInst(VAArgInst &VAA) { visitInstruction(VAA); }
459 void visitCallInst(CallInst &CI);
460 void visitInvokeInst(InvokeInst &II);
461 void visitGetElementPtrInst(GetElementPtrInst &GEP);
462 void visitLoadInst(LoadInst &LI);
463 void visitStoreInst(StoreInst &SI);
464 void verifyDominatesUse(Instruction &I, unsigned i);
465 void visitInstruction(Instruction &I);
466 void visitTerminator(Instruction &I);
467 void visitBranchInst(BranchInst &BI);
468 void visitReturnInst(ReturnInst &RI);
469 void visitSwitchInst(SwitchInst &SI);
470 void visitIndirectBrInst(IndirectBrInst &BI);
471 void visitSelectInst(SelectInst &SI);
472 void visitUserOp1(Instruction &I);
473 void visitUserOp2(Instruction &I) { visitUserOp1(I); }
474 void visitIntrinsicCallSite(Intrinsic::ID ID, CallSite CS);
475 void visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI);
476 void visitDbgIntrinsic(StringRef Kind, DbgVariableIntrinsic &DII);
477 void visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI);
478 void visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI);
479 void visitAtomicRMWInst(AtomicRMWInst &RMWI);
480 void visitFenceInst(FenceInst &FI);
481 void visitAllocaInst(AllocaInst &AI);
482 void visitExtractValueInst(ExtractValueInst &EVI);
483 void visitInsertValueInst(InsertValueInst &IVI);
484 void visitEHPadPredecessors(Instruction &I);
485 void visitLandingPadInst(LandingPadInst &LPI);
486 void visitResumeInst(ResumeInst &RI);
487 void visitCatchPadInst(CatchPadInst &CPI);
488 void visitCatchReturnInst(CatchReturnInst &CatchReturn);
489 void visitCleanupPadInst(CleanupPadInst &CPI);
490 void visitFuncletPadInst(FuncletPadInst &FPI);
491 void visitCatchSwitchInst(CatchSwitchInst &CatchSwitch);
492 void visitCleanupReturnInst(CleanupReturnInst &CRI);
493
494 void verifyCallSite(CallSite CS);
495 void verifySwiftErrorCallSite(CallSite CS, const Value *SwiftErrorVal);
496 void verifySwiftErrorValue(const Value *SwiftErrorVal);
497 void verifyMustTailCall(CallInst &CI);
498 bool performTypeCheck(Intrinsic::ID ID, Function *F, Type *Ty, int VT,
499 unsigned ArgNo, std::string &Suffix);
500 bool verifyAttributeCount(AttributeList Attrs, unsigned Params);
501 void verifyAttributeTypes(AttributeSet Attrs, bool IsFunction,
502 const Value *V);
503 void verifyParameterAttrs(AttributeSet Attrs, Type *Ty, const Value *V);
504 void verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
505 const Value *V);
506 void verifyFunctionMetadata(ArrayRef<std::pair<unsigned, MDNode *>> MDs);
507
508 void visitConstantExprsRecursively(const Constant *EntryC);
509 void visitConstantExpr(const ConstantExpr *CE);
510 void verifyStatepoint(ImmutableCallSite CS);
511 void verifyFrameRecoverIndices();
512 void verifySiblingFuncletUnwinds();
513
514 void verifyFragmentExpression(const DbgVariableIntrinsic &I);
515 template <typename ValueOrMetadata>
516 void verifyFragmentExpression(const DIVariable &V,
517 DIExpression::FragmentInfo Fragment,
518 ValueOrMetadata *Desc);
519 void verifyFnArgs(const DbgVariableIntrinsic &I);
520
521 /// Module-level debug info verification...
522 void verifyCompileUnits();
523
524 /// Module-level verification that all @llvm.experimental.deoptimize
525 /// declarations share the same calling convention.
526 void verifyDeoptimizeCallingConvs();
527
528 /// Verify all-or-nothing property of DIFile source attribute within a CU.
529 void verifySourceDebugInfo(const DICompileUnit &U, const DIFile &F);
530};
531
532} // end anonymous namespace
533
534/// We know that cond should be true, if not print an error message.
535#define Assert(C, ...)do { if (!(C)) { CheckFailed(...); return; } } while (false) \
536 do { if (!(C)) { CheckFailed(__VA_ARGS__); return; } } while (false)
537
538/// We know that a debug info condition should be true, if not print
539/// an error message.
540#define AssertDI(C, ...)do { if (!(C)) { DebugInfoCheckFailed(...); return; } } while
(false)
\
541 do { if (!(C)) { DebugInfoCheckFailed(__VA_ARGS__); return; } } while (false)
542
543void Verifier::visit(Instruction &I) {
544 for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i)
545 Assert(I.getOperand(i) != nullptr, "Operand is null", &I)do { if (!(I.getOperand(i) != nullptr)) { CheckFailed("Operand is null"
, &I); return; } } while (false)
;
546 InstVisitor<Verifier>::visit(I);
547}
548
549// Helper to recursively iterate over indirect users. By
550// returning false, the callback can ask to stop recursing
551// further.
552static void forEachUser(const Value *User,
553 SmallPtrSet<const Value *, 32> &Visited,
554 llvm::function_ref<bool(const Value *)> Callback) {
555 if (!Visited.insert(User).second)
556 return;
557 for (const Value *TheNextUser : User->materialized_users())
558 if (Callback(TheNextUser))
559 forEachUser(TheNextUser, Visited, Callback);
560}
561
562void Verifier::visitGlobalValue(const GlobalValue &GV) {
563 Assert(!GV.isDeclaration() || GV.hasValidDeclarationLinkage(),do { if (!(!GV.isDeclaration() || GV.hasValidDeclarationLinkage
())) { CheckFailed("Global is external, but doesn't have external or weak linkage!"
, &GV); return; } } while (false)
564 "Global is external, but doesn't have external or weak linkage!", &GV)do { if (!(!GV.isDeclaration() || GV.hasValidDeclarationLinkage
())) { CheckFailed("Global is external, but doesn't have external or weak linkage!"
, &GV); return; } } while (false)
;
565
566 Assert(GV.getAlignment() <= Value::MaximumAlignment,do { if (!(GV.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &GV
); return; } } while (false)
567 "huge alignment values are unsupported", &GV)do { if (!(GV.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &GV
); return; } } while (false)
;
568 Assert(!GV.hasAppendingLinkage() || isa<GlobalVariable>(GV),do { if (!(!GV.hasAppendingLinkage() || isa<GlobalVariable
>(GV))) { CheckFailed("Only global variables can have appending linkage!"
, &GV); return; } } while (false)
569 "Only global variables can have appending linkage!", &GV)do { if (!(!GV.hasAppendingLinkage() || isa<GlobalVariable
>(GV))) { CheckFailed("Only global variables can have appending linkage!"
, &GV); return; } } while (false)
;
570
571 if (GV.hasAppendingLinkage()) {
572 const GlobalVariable *GVar = dyn_cast<GlobalVariable>(&GV);
573 Assert(GVar && GVar->getValueType()->isArrayTy(),do { if (!(GVar && GVar->getValueType()->isArrayTy
())) { CheckFailed("Only global arrays can have appending linkage!"
, GVar); return; } } while (false)
574 "Only global arrays can have appending linkage!", GVar)do { if (!(GVar && GVar->getValueType()->isArrayTy
())) { CheckFailed("Only global arrays can have appending linkage!"
, GVar); return; } } while (false)
;
575 }
576
577 if (GV.isDeclarationForLinker())
578 Assert(!GV.hasComdat(), "Declaration may not be in a Comdat!", &GV)do { if (!(!GV.hasComdat())) { CheckFailed("Declaration may not be in a Comdat!"
, &GV); return; } } while (false)
;
579
580 if (GV.hasDLLImportStorageClass()) {
581 Assert(!GV.isDSOLocal(),do { if (!(!GV.isDSOLocal())) { CheckFailed("GlobalValue with DLLImport Storage is dso_local!"
, &GV); return; } } while (false)
582 "GlobalValue with DLLImport Storage is dso_local!", &GV)do { if (!(!GV.isDSOLocal())) { CheckFailed("GlobalValue with DLLImport Storage is dso_local!"
, &GV); return; } } while (false)
;
583
584 Assert((GV.isDeclaration() && GV.hasExternalLinkage()) ||do { if (!((GV.isDeclaration() && GV.hasExternalLinkage
()) || GV.hasAvailableExternallyLinkage())) { CheckFailed("Global is marked as dllimport, but not external"
, &GV); return; } } while (false)
585 GV.hasAvailableExternallyLinkage(),do { if (!((GV.isDeclaration() && GV.hasExternalLinkage
()) || GV.hasAvailableExternallyLinkage())) { CheckFailed("Global is marked as dllimport, but not external"
, &GV); return; } } while (false)
586 "Global is marked as dllimport, but not external", &GV)do { if (!((GV.isDeclaration() && GV.hasExternalLinkage
()) || GV.hasAvailableExternallyLinkage())) { CheckFailed("Global is marked as dllimport, but not external"
, &GV); return; } } while (false)
;
587 }
588
589 if (GV.hasLocalLinkage())
590 Assert(GV.isDSOLocal(),do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with private or internal linkage must be dso_local!"
, &GV); return; } } while (false)
591 "GlobalValue with private or internal linkage must be dso_local!",do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with private or internal linkage must be dso_local!"
, &GV); return; } } while (false)
592 &GV)do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with private or internal linkage must be dso_local!"
, &GV); return; } } while (false)
;
593
594 if (!GV.hasDefaultVisibility() && !GV.hasExternalWeakLinkage())
595 Assert(GV.isDSOLocal(),do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with non default visibility must be dso_local!"
, &GV); return; } } while (false)
596 "GlobalValue with non default visibility must be dso_local!", &GV)do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with non default visibility must be dso_local!"
, &GV); return; } } while (false)
;
597
598 forEachUser(&GV, GlobalValueVisited, [&](const Value *V) -> bool {
599 if (const Instruction *I = dyn_cast<Instruction>(V)) {
600 if (!I->getParent() || !I->getParent()->getParent())
601 CheckFailed("Global is referenced by parentless instruction!", &GV, &M,
602 I);
603 else if (I->getParent()->getParent()->getParent() != &M)
604 CheckFailed("Global is referenced in a different module!", &GV, &M, I,
605 I->getParent()->getParent(),
606 I->getParent()->getParent()->getParent());
607 return false;
608 } else if (const Function *F = dyn_cast<Function>(V)) {
609 if (F->getParent() != &M)
610 CheckFailed("Global is used by function in a different module", &GV, &M,
611 F, F->getParent());
612 return false;
613 }
614 return true;
615 });
616}
617
618void Verifier::visitGlobalVariable(const GlobalVariable &GV) {
619 if (GV.hasInitializer()) {
620 Assert(GV.getInitializer()->getType() == GV.getValueType(),do { if (!(GV.getInitializer()->getType() == GV.getValueType
())) { CheckFailed("Global variable initializer type does not match global "
"variable type!", &GV); return; } } while (false)
621 "Global variable initializer type does not match global "do { if (!(GV.getInitializer()->getType() == GV.getValueType
())) { CheckFailed("Global variable initializer type does not match global "
"variable type!", &GV); return; } } while (false)
622 "variable type!",do { if (!(GV.getInitializer()->getType() == GV.getValueType
())) { CheckFailed("Global variable initializer type does not match global "
"variable type!", &GV); return; } } while (false)
623 &GV)do { if (!(GV.getInitializer()->getType() == GV.getValueType
())) { CheckFailed("Global variable initializer type does not match global "
"variable type!", &GV); return; } } while (false)
;
624 // If the global has common linkage, it must have a zero initializer and
625 // cannot be constant.
626 if (GV.hasCommonLinkage()) {
627 Assert(GV.getInitializer()->isNullValue(),do { if (!(GV.getInitializer()->isNullValue())) { CheckFailed
("'common' global must have a zero initializer!", &GV); return
; } } while (false)
628 "'common' global must have a zero initializer!", &GV)do { if (!(GV.getInitializer()->isNullValue())) { CheckFailed
("'common' global must have a zero initializer!", &GV); return
; } } while (false)
;
629 Assert(!GV.isConstant(), "'common' global may not be marked constant!",do { if (!(!GV.isConstant())) { CheckFailed("'common' global may not be marked constant!"
, &GV); return; } } while (false)
630 &GV)do { if (!(!GV.isConstant())) { CheckFailed("'common' global may not be marked constant!"
, &GV); return; } } while (false)
;
631 Assert(!GV.hasComdat(), "'common' global may not be in a Comdat!", &GV)do { if (!(!GV.hasComdat())) { CheckFailed("'common' global may not be in a Comdat!"
, &GV); return; } } while (false)
;
632 }
633 }
634
635 if (GV.hasName() && (GV.getName() == "llvm.global_ctors" ||
636 GV.getName() == "llvm.global_dtors")) {
637 Assert(!GV.hasInitializer() || GV.hasAppendingLinkage(),do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage()))
{ CheckFailed("invalid linkage for intrinsic global variable"
, &GV); return; } } while (false)
638 "invalid linkage for intrinsic global variable", &GV)do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage()))
{ CheckFailed("invalid linkage for intrinsic global variable"
, &GV); return; } } while (false)
;
639 // Don't worry about emitting an error for it not being an array,
640 // visitGlobalValue will complain on appending non-array.
641 if (ArrayType *ATy = dyn_cast<ArrayType>(GV.getValueType())) {
642 StructType *STy = dyn_cast<StructType>(ATy->getElementType());
643 PointerType *FuncPtrTy =
644 FunctionType::get(Type::getVoidTy(Context), false)->
645 getPointerTo(DL.getProgramAddressSpace());
646 // FIXME: Reject the 2-field form in LLVM 4.0.
647 Assert(STy &&do { if (!(STy && (STy->getNumElements() == 2 || STy
->getNumElements() == 3) && STy->getTypeAtIndex
(0u)->isIntegerTy(32) && STy->getTypeAtIndex(1)
== FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable"
, &GV); return; } } while (false)
648 (STy->getNumElements() == 2 || STy->getNumElements() == 3) &&do { if (!(STy && (STy->getNumElements() == 2 || STy
->getNumElements() == 3) && STy->getTypeAtIndex
(0u)->isIntegerTy(32) && STy->getTypeAtIndex(1)
== FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable"
, &GV); return; } } while (false)
649 STy->getTypeAtIndex(0u)->isIntegerTy(32) &&do { if (!(STy && (STy->getNumElements() == 2 || STy
->getNumElements() == 3) && STy->getTypeAtIndex
(0u)->isIntegerTy(32) && STy->getTypeAtIndex(1)
== FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable"
, &GV); return; } } while (false)
650 STy->getTypeAtIndex(1) == FuncPtrTy,do { if (!(STy && (STy->getNumElements() == 2 || STy
->getNumElements() == 3) && STy->getTypeAtIndex
(0u)->isIntegerTy(32) && STy->getTypeAtIndex(1)
== FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable"
, &GV); return; } } while (false)
651 "wrong type for intrinsic global variable", &GV)do { if (!(STy && (STy->getNumElements() == 2 || STy
->getNumElements() == 3) && STy->getTypeAtIndex
(0u)->isIntegerTy(32) && STy->getTypeAtIndex(1)
== FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable"
, &GV); return; } } while (false)
;
652 if (STy->getNumElements() == 3) {
653 Type *ETy = STy->getTypeAtIndex(2);
654 Assert(ETy->isPointerTy() &&do { if (!(ETy->isPointerTy() && cast<PointerType
>(ETy)->getElementType()->isIntegerTy(8))) { CheckFailed
("wrong type for intrinsic global variable", &GV); return
; } } while (false)
655 cast<PointerType>(ETy)->getElementType()->isIntegerTy(8),do { if (!(ETy->isPointerTy() && cast<PointerType
>(ETy)->getElementType()->isIntegerTy(8))) { CheckFailed
("wrong type for intrinsic global variable", &GV); return
; } } while (false)
656 "wrong type for intrinsic global variable", &GV)do { if (!(ETy->isPointerTy() && cast<PointerType
>(ETy)->getElementType()->isIntegerTy(8))) { CheckFailed
("wrong type for intrinsic global variable", &GV); return
; } } while (false)
;
657 }
658 }
659 }
660
661 if (GV.hasName() && (GV.getName() == "llvm.used" ||
662 GV.getName() == "llvm.compiler.used")) {
663 Assert(!GV.hasInitializer() || GV.hasAppendingLinkage(),do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage()))
{ CheckFailed("invalid linkage for intrinsic global variable"
, &GV); return; } } while (false)
664 "invalid linkage for intrinsic global variable", &GV)do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage()))
{ CheckFailed("invalid linkage for intrinsic global variable"
, &GV); return; } } while (false)
;
665 Type *GVType = GV.getValueType();
666 if (ArrayType *ATy = dyn_cast<ArrayType>(GVType)) {
667 PointerType *PTy = dyn_cast<PointerType>(ATy->getElementType());
668 Assert(PTy, "wrong type for intrinsic global variable", &GV)do { if (!(PTy)) { CheckFailed("wrong type for intrinsic global variable"
, &GV); return; } } while (false)
;
669 if (GV.hasInitializer()) {
670 const Constant *Init = GV.getInitializer();
671 const ConstantArray *InitArray = dyn_cast<ConstantArray>(Init);
672 Assert(InitArray, "wrong initalizer for intrinsic global variable",do { if (!(InitArray)) { CheckFailed("wrong initalizer for intrinsic global variable"
, Init); return; } } while (false)
673 Init)do { if (!(InitArray)) { CheckFailed("wrong initalizer for intrinsic global variable"
, Init); return; } } while (false)
;
674 for (Value *Op : InitArray->operands()) {
675 Value *V = Op->stripPointerCastsNoFollowAliases();
676 Assert(isa<GlobalVariable>(V) || isa<Function>(V) ||do { if (!(isa<GlobalVariable>(V) || isa<Function>
(V) || isa<GlobalAlias>(V))) { CheckFailed("invalid llvm.used member"
, V); return; } } while (false)
677 isa<GlobalAlias>(V),do { if (!(isa<GlobalVariable>(V) || isa<Function>
(V) || isa<GlobalAlias>(V))) { CheckFailed("invalid llvm.used member"
, V); return; } } while (false)
678 "invalid llvm.used member", V)do { if (!(isa<GlobalVariable>(V) || isa<Function>
(V) || isa<GlobalAlias>(V))) { CheckFailed("invalid llvm.used member"
, V); return; } } while (false)
;
679 Assert(V->hasName(), "members of llvm.used must be named", V)do { if (!(V->hasName())) { CheckFailed("members of llvm.used must be named"
, V); return; } } while (false)
;
680 }
681 }
682 }
683 }
684
685 // Visit any debug info attachments.
686 SmallVector<MDNode *, 1> MDs;
687 GV.getMetadata(LLVMContext::MD_dbg, MDs);
688 for (auto *MD : MDs) {
689 if (auto *GVE = dyn_cast<DIGlobalVariableExpression>(MD))
690 visitDIGlobalVariableExpression(*GVE);
691 else
692 AssertDI(false, "!dbg attachment of global variable must be a "do { if (!(false)) { DebugInfoCheckFailed("!dbg attachment of global variable must be a "
"DIGlobalVariableExpression"); return; } } while (false)
693 "DIGlobalVariableExpression")do { if (!(false)) { DebugInfoCheckFailed("!dbg attachment of global variable must be a "
"DIGlobalVariableExpression"); return; } } while (false)
;
694 }
695
696 if (!GV.hasInitializer()) {
697 visitGlobalValue(GV);
698 return;
699 }
700
701 // Walk any aggregate initializers looking for bitcasts between address spaces
702 visitConstantExprsRecursively(GV.getInitializer());
703
704 visitGlobalValue(GV);
705}
706
707void Verifier::visitAliaseeSubExpr(const GlobalAlias &GA, const Constant &C) {
708 SmallPtrSet<const GlobalAlias*, 4> Visited;
709 Visited.insert(&GA);
710 visitAliaseeSubExpr(Visited, GA, C);
711}
712
713void Verifier::visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias*> &Visited,
714 const GlobalAlias &GA, const Constant &C) {
715 if (const auto *GV = dyn_cast<GlobalValue>(&C)) {
716 Assert(!GV->isDeclarationForLinker(), "Alias must point to a definition",do { if (!(!GV->isDeclarationForLinker())) { CheckFailed("Alias must point to a definition"
, &GA); return; } } while (false)
717 &GA)do { if (!(!GV->isDeclarationForLinker())) { CheckFailed("Alias must point to a definition"
, &GA); return; } } while (false)
;
718
719 if (const auto *GA2 = dyn_cast<GlobalAlias>(GV)) {
720 Assert(Visited.insert(GA2).second, "Aliases cannot form a cycle", &GA)do { if (!(Visited.insert(GA2).second)) { CheckFailed("Aliases cannot form a cycle"
, &GA); return; } } while (false)
;
721
722 Assert(!GA2->isInterposable(), "Alias cannot point to an interposable alias",do { if (!(!GA2->isInterposable())) { CheckFailed("Alias cannot point to an interposable alias"
, &GA); return; } } while (false)
723 &GA)do { if (!(!GA2->isInterposable())) { CheckFailed("Alias cannot point to an interposable alias"
, &GA); return; } } while (false)
;
724 } else {
725 // Only continue verifying subexpressions of GlobalAliases.
726 // Do not recurse into global initializers.
727 return;
728 }
729 }
730
731 if (const auto *CE = dyn_cast<ConstantExpr>(&C))
732 visitConstantExprsRecursively(CE);
733
734 for (const Use &U : C.operands()) {
735 Value *V = &*U;
736 if (const auto *GA2 = dyn_cast<GlobalAlias>(V))
737 visitAliaseeSubExpr(Visited, GA, *GA2->getAliasee());
738 else if (const auto *C2 = dyn_cast<Constant>(V))
739 visitAliaseeSubExpr(Visited, GA, *C2);
740 }
741}
742
743void Verifier::visitGlobalAlias(const GlobalAlias &GA) {
744 Assert(GlobalAlias::isValidLinkage(GA.getLinkage()),do { if (!(GlobalAlias::isValidLinkage(GA.getLinkage()))) { CheckFailed
("Alias should have private, internal, linkonce, weak, linkonce_odr, "
"weak_odr, or external linkage!", &GA); return; } } while
(false)
745 "Alias should have private, internal, linkonce, weak, linkonce_odr, "do { if (!(GlobalAlias::isValidLinkage(GA.getLinkage()))) { CheckFailed
("Alias should have private, internal, linkonce, weak, linkonce_odr, "
"weak_odr, or external linkage!", &GA); return; } } while
(false)
746 "weak_odr, or external linkage!",do { if (!(GlobalAlias::isValidLinkage(GA.getLinkage()))) { CheckFailed
("Alias should have private, internal, linkonce, weak, linkonce_odr, "
"weak_odr, or external linkage!", &GA); return; } } while
(false)
747 &GA)do { if (!(GlobalAlias::isValidLinkage(GA.getLinkage()))) { CheckFailed
("Alias should have private, internal, linkonce, weak, linkonce_odr, "
"weak_odr, or external linkage!", &GA); return; } } while
(false)
;
748 const Constant *Aliasee = GA.getAliasee();
749 Assert(Aliasee, "Aliasee cannot be NULL!", &GA)do { if (!(Aliasee)) { CheckFailed("Aliasee cannot be NULL!",
&GA); return; } } while (false)
;
750 Assert(GA.getType() == Aliasee->getType(),do { if (!(GA.getType() == Aliasee->getType())) { CheckFailed
("Alias and aliasee types should match!", &GA); return; }
} while (false)
751 "Alias and aliasee types should match!", &GA)do { if (!(GA.getType() == Aliasee->getType())) { CheckFailed
("Alias and aliasee types should match!", &GA); return; }
} while (false)
;
752
753 Assert(isa<GlobalValue>(Aliasee) || isa<ConstantExpr>(Aliasee),do { if (!(isa<GlobalValue>(Aliasee) || isa<ConstantExpr
>(Aliasee))) { CheckFailed("Aliasee should be either GlobalValue or ConstantExpr"
, &GA); return; } } while (false)
754 "Aliasee should be either GlobalValue or ConstantExpr", &GA)do { if (!(isa<GlobalValue>(Aliasee) || isa<ConstantExpr
>(Aliasee))) { CheckFailed("Aliasee should be either GlobalValue or ConstantExpr"
, &GA); return; } } while (false)
;
755
756 visitAliaseeSubExpr(GA, *Aliasee);
757
758 visitGlobalValue(GA);
759}
760
761void Verifier::visitNamedMDNode(const NamedMDNode &NMD) {
762 // There used to be various other llvm.dbg.* nodes, but we don't support
763 // upgrading them and we want to reserve the namespace for future uses.
764 if (NMD.getName().startswith("llvm.dbg."))
765 AssertDI(NMD.getName() == "llvm.dbg.cu",do { if (!(NMD.getName() == "llvm.dbg.cu")) { DebugInfoCheckFailed
("unrecognized named metadata node in the llvm.dbg namespace"
, &NMD); return; } } while (false)
766 "unrecognized named metadata node in the llvm.dbg namespace",do { if (!(NMD.getName() == "llvm.dbg.cu")) { DebugInfoCheckFailed
("unrecognized named metadata node in the llvm.dbg namespace"
, &NMD); return; } } while (false)
767 &NMD)do { if (!(NMD.getName() == "llvm.dbg.cu")) { DebugInfoCheckFailed
("unrecognized named metadata node in the llvm.dbg namespace"
, &NMD); return; } } while (false)
;
768 for (const MDNode *MD : NMD.operands()) {
769 if (NMD.getName() == "llvm.dbg.cu")
770 AssertDI(MD && isa<DICompileUnit>(MD), "invalid compile unit", &NMD, MD)do { if (!(MD && isa<DICompileUnit>(MD))) { DebugInfoCheckFailed
("invalid compile unit", &NMD, MD); return; } } while (false
)
;
771
772 if (!MD)
773 continue;
774
775 visitMDNode(*MD);
776 }
777}
778
779void Verifier::visitMDNode(const MDNode &MD) {
780 // Only visit each node once. Metadata can be mutually recursive, so this
781 // avoids infinite recursion here, as well as being an optimization.
782 if (!MDNodes.insert(&MD).second)
783 return;
784
785 switch (MD.getMetadataID()) {
786 default:
787 llvm_unreachable("Invalid MDNode subclass")::llvm::llvm_unreachable_internal("Invalid MDNode subclass", "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp"
, 787)
;
788 case Metadata::MDTupleKind:
789 break;
790#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
791 case Metadata::CLASS##Kind: \
792 visit##CLASS(cast<CLASS>(MD)); \
793 break;
794#include "llvm/IR/Metadata.def"
795 }
796
797 for (const Metadata *Op : MD.operands()) {
798 if (!Op)
799 continue;
800 Assert(!isa<LocalAsMetadata>(Op), "Invalid operand for global metadata!",do { if (!(!isa<LocalAsMetadata>(Op))) { CheckFailed("Invalid operand for global metadata!"
, &MD, Op); return; } } while (false)
801 &MD, Op)do { if (!(!isa<LocalAsMetadata>(Op))) { CheckFailed("Invalid operand for global metadata!"
, &MD, Op); return; } } while (false)
;
802 if (auto *N = dyn_cast<MDNode>(Op)) {
803 visitMDNode(*N);
804 continue;
805 }
806 if (auto *V = dyn_cast<ValueAsMetadata>(Op)) {
807 visitValueAsMetadata(*V, nullptr);
808 continue;
809 }
810 }
811
812 // Check these last, so we diagnose problems in operands first.
813 Assert(!MD.isTemporary(), "Expected no forward declarations!", &MD)do { if (!(!MD.isTemporary())) { CheckFailed("Expected no forward declarations!"
, &MD); return; } } while (false)
;
814 Assert(MD.isResolved(), "All nodes should be resolved!", &MD)do { if (!(MD.isResolved())) { CheckFailed("All nodes should be resolved!"
, &MD); return; } } while (false)
;
815}
816
817void Verifier::visitValueAsMetadata(const ValueAsMetadata &MD, Function *F) {
818 Assert(MD.getValue(), "Expected valid value", &MD)do { if (!(MD.getValue())) { CheckFailed("Expected valid value"
, &MD); return; } } while (false)
;
819 Assert(!MD.getValue()->getType()->isMetadataTy(),do { if (!(!MD.getValue()->getType()->isMetadataTy())) {
CheckFailed("Unexpected metadata round-trip through values",
&MD, MD.getValue()); return; } } while (false)
820 "Unexpected metadata round-trip through values", &MD, MD.getValue())do { if (!(!MD.getValue()->getType()->isMetadataTy())) {
CheckFailed("Unexpected metadata round-trip through values",
&MD, MD.getValue()); return; } } while (false)
;
821
822 auto *L = dyn_cast<LocalAsMetadata>(&MD);
823 if (!L)
824 return;
825
826 Assert(F, "function-local metadata used outside a function", L)do { if (!(F)) { CheckFailed("function-local metadata used outside a function"
, L); return; } } while (false)
;
827
828 // If this was an instruction, bb, or argument, verify that it is in the
829 // function that we expect.
830 Function *ActualF = nullptr;
831 if (Instruction *I = dyn_cast<Instruction>(L->getValue())) {
832 Assert(I->getParent(), "function-local metadata not in basic block", L, I)do { if (!(I->getParent())) { CheckFailed("function-local metadata not in basic block"
, L, I); return; } } while (false)
;
833 ActualF = I->getParent()->getParent();
834 } else if (BasicBlock *BB = dyn_cast<BasicBlock>(L->getValue()))
835 ActualF = BB->getParent();
836 else if (Argument *A = dyn_cast<Argument>(L->getValue()))
837 ActualF = A->getParent();
838 assert(ActualF && "Unimplemented function local metadata case!")((ActualF && "Unimplemented function local metadata case!"
) ? static_cast<void> (0) : __assert_fail ("ActualF && \"Unimplemented function local metadata case!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp"
, 838, __PRETTY_FUNCTION__))
;
839
840 Assert(ActualF == F, "function-local metadata used in wrong function", L)do { if (!(ActualF == F)) { CheckFailed("function-local metadata used in wrong function"
, L); return; } } while (false)
;
841}
842
843void Verifier::visitMetadataAsValue(const MetadataAsValue &MDV, Function *F) {
844 Metadata *MD = MDV.getMetadata();
845 if (auto *N = dyn_cast<MDNode>(MD)) {
846 visitMDNode(*N);
847 return;
848 }
849
850 // Only visit each node once. Metadata can be mutually recursive, so this
851 // avoids infinite recursion here, as well as being an optimization.
852 if (!MDNodes.insert(MD).second)
853 return;
854
855 if (auto *V = dyn_cast<ValueAsMetadata>(MD))
856 visitValueAsMetadata(*V, F);
857}
858
859static bool isType(const Metadata *MD) { return !MD || isa<DIType>(MD); }
860static bool isScope(const Metadata *MD) { return !MD || isa<DIScope>(MD); }
861static bool isDINode(const Metadata *MD) { return !MD || isa<DINode>(MD); }
862
863void Verifier::visitDILocation(const DILocation &N) {
864 AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { DebugInfoCheckFailed("location requires a valid scope"
, &N, N.getRawScope()); return; } } while (false)
865 "location requires a valid scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { DebugInfoCheckFailed("location requires a valid scope"
, &N, N.getRawScope()); return; } } while (false)
;
866 if (auto *IA = N.getRawInlinedAt())
867 AssertDI(isa<DILocation>(IA), "inlined-at should be a location", &N, IA)do { if (!(isa<DILocation>(IA))) { DebugInfoCheckFailed
("inlined-at should be a location", &N, IA); return; } } while
(false)
;
868 if (auto *SP = dyn_cast<DISubprogram>(N.getRawScope()))
869 AssertDI(SP->isDefinition(), "scope points into the type hierarchy", &N)do { if (!(SP->isDefinition())) { DebugInfoCheckFailed("scope points into the type hierarchy"
, &N); return; } } while (false)
;
870}
871
872void Verifier::visitGenericDINode(const GenericDINode &N) {
873 AssertDI(N.getTag(), "invalid tag", &N)do { if (!(N.getTag())) { DebugInfoCheckFailed("invalid tag",
&N); return; } } while (false)
;
874}
875
876void Verifier::visitDIScope(const DIScope &N) {
877 if (auto *F = N.getRawFile())
878 AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file"
, &N, F); return; } } while (false)
;
879}
880
881void Verifier::visitDISubrange(const DISubrange &N) {
882 AssertDI(N.getTag() == dwarf::DW_TAG_subrange_type, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_subrange_type)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
883 auto Count = N.getCount();
884 AssertDI(Count, "Count must either be a signed constant or a DIVariable",do { if (!(Count)) { DebugInfoCheckFailed("Count must either be a signed constant or a DIVariable"
, &N); return; } } while (false)
885 &N)do { if (!(Count)) { DebugInfoCheckFailed("Count must either be a signed constant or a DIVariable"
, &N); return; } } while (false)
;
886 AssertDI(!Count.is<ConstantInt*>() ||do { if (!(!Count.is<ConstantInt*>() || Count.get<ConstantInt
*>()->getSExtValue() >= -1)) { DebugInfoCheckFailed(
"invalid subrange count", &N); return; } } while (false)
887 Count.get<ConstantInt*>()->getSExtValue() >= -1,do { if (!(!Count.is<ConstantInt*>() || Count.get<ConstantInt
*>()->getSExtValue() >= -1)) { DebugInfoCheckFailed(
"invalid subrange count", &N); return; } } while (false)
888 "invalid subrange count", &N)do { if (!(!Count.is<ConstantInt*>() || Count.get<ConstantInt
*>()->getSExtValue() >= -1)) { DebugInfoCheckFailed(
"invalid subrange count", &N); return; } } while (false)
;
889}
890
891void Verifier::visitDIEnumerator(const DIEnumerator &N) {
892 AssertDI(N.getTag() == dwarf::DW_TAG_enumerator, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_enumerator)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
893}
894
895void Verifier::visitDIBasicType(const DIBasicType &N) {
896 AssertDI(N.getTag() == dwarf::DW_TAG_base_type ||do { if (!(N.getTag() == dwarf::DW_TAG_base_type || N.getTag(
) == dwarf::DW_TAG_unspecified_type)) { DebugInfoCheckFailed(
"invalid tag", &N); return; } } while (false)
897 N.getTag() == dwarf::DW_TAG_unspecified_type,do { if (!(N.getTag() == dwarf::DW_TAG_base_type || N.getTag(
) == dwarf::DW_TAG_unspecified_type)) { DebugInfoCheckFailed(
"invalid tag", &N); return; } } while (false)
898 "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_base_type || N.getTag(
) == dwarf::DW_TAG_unspecified_type)) { DebugInfoCheckFailed(
"invalid tag", &N); return; } } while (false)
;
899 AssertDI(!(N.isBigEndian() && N.isLittleEndian()) ,do { if (!(!(N.isBigEndian() && N.isLittleEndian())))
{ DebugInfoCheckFailed("has conflicting flags", &N); return
; } } while (false)
900 "has conflicting flags", &N)do { if (!(!(N.isBigEndian() && N.isLittleEndian())))
{ DebugInfoCheckFailed("has conflicting flags", &N); return
; } } while (false)
;
901}
902
903void Verifier::visitDIDerivedType(const DIDerivedType &N) {
904 // Common scope checks.
905 visitDIScope(N);
906
907 AssertDI(N.getTag() == dwarf::DW_TAG_typedef ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
908 N.getTag() == dwarf::DW_TAG_pointer_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
909 N.getTag() == dwarf::DW_TAG_ptr_to_member_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
910 N.getTag() == dwarf::DW_TAG_reference_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
911 N.getTag() == dwarf::DW_TAG_rvalue_reference_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
912 N.getTag() == dwarf::DW_TAG_const_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
913 N.getTag() == dwarf::DW_TAG_volatile_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
914 N.getTag() == dwarf::DW_TAG_restrict_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
915 N.getTag() == dwarf::DW_TAG_atomic_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
916 N.getTag() == dwarf::DW_TAG_member ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
917 N.getTag() == dwarf::DW_TAG_inheritance ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
918 N.getTag() == dwarf::DW_TAG_friend,do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
919 "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
;
920 if (N.getTag() == dwarf::DW_TAG_ptr_to_member_type) {
921 AssertDI(isType(N.getRawExtraData()), "invalid pointer to member type", &N,do { if (!(isType(N.getRawExtraData()))) { DebugInfoCheckFailed
("invalid pointer to member type", &N, N.getRawExtraData(
)); return; } } while (false)
922 N.getRawExtraData())do { if (!(isType(N.getRawExtraData()))) { DebugInfoCheckFailed
("invalid pointer to member type", &N, N.getRawExtraData(
)); return; } } while (false)
;
923 }
924
925 AssertDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope())do { if (!(isScope(N.getRawScope()))) { DebugInfoCheckFailed(
"invalid scope", &N, N.getRawScope()); return; } } while (
false)
;
926 AssertDI(isType(N.getRawBaseType()), "invalid base type", &N,do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed
("invalid base type", &N, N.getRawBaseType()); return; } }
while (false)
927 N.getRawBaseType())do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed
("invalid base type", &N, N.getRawBaseType()); return; } }
while (false)
;
928
929 if (N.getDWARFAddressSpace()) {
930 AssertDI(N.getTag() == dwarf::DW_TAG_pointer_type ||do { if (!(N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag
() == dwarf::DW_TAG_reference_type)) { DebugInfoCheckFailed("DWARF address space only applies to pointer or reference types"
, &N); return; } } while (false)
931 N.getTag() == dwarf::DW_TAG_reference_type,do { if (!(N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag
() == dwarf::DW_TAG_reference_type)) { DebugInfoCheckFailed("DWARF address space only applies to pointer or reference types"
, &N); return; } } while (false)
932 "DWARF address space only applies to pointer or reference types",do { if (!(N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag
() == dwarf::DW_TAG_reference_type)) { DebugInfoCheckFailed("DWARF address space only applies to pointer or reference types"
, &N); return; } } while (false)
933 &N)do { if (!(N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag
() == dwarf::DW_TAG_reference_type)) { DebugInfoCheckFailed("DWARF address space only applies to pointer or reference types"
, &N); return; } } while (false)
;
934 }
935}
936
937/// Detect mutually exclusive flags.
938static bool hasConflictingReferenceFlags(unsigned Flags) {
939 return ((Flags & DINode::FlagLValueReference) &&
940 (Flags & DINode::FlagRValueReference)) ||
941 ((Flags & DINode::FlagTypePassByValue) &&
942 (Flags & DINode::FlagTypePassByReference));
943}
944
945void Verifier::visitTemplateParams(const MDNode &N, const Metadata &RawParams) {
946 auto *Params = dyn_cast<MDTuple>(&RawParams);
947 AssertDI(Params, "invalid template params", &N, &RawParams)do { if (!(Params)) { DebugInfoCheckFailed("invalid template params"
, &N, &RawParams); return; } } while (false)
;
948 for (Metadata *Op : Params->operands()) {
949 AssertDI(Op && isa<DITemplateParameter>(Op), "invalid template parameter",do { if (!(Op && isa<DITemplateParameter>(Op)))
{ DebugInfoCheckFailed("invalid template parameter", &N,
Params, Op); return; } } while (false)
950 &N, Params, Op)do { if (!(Op && isa<DITemplateParameter>(Op)))
{ DebugInfoCheckFailed("invalid template parameter", &N,
Params, Op); return; } } while (false)
;
951 }
952}
953
954void Verifier::visitDICompositeType(const DICompositeType &N) {
955 // Common scope checks.
956 visitDIScope(N);
957
958 AssertDI(N.getTag() == dwarf::DW_TAG_array_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag
() == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type
|| N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag(
) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
959 N.getTag() == dwarf::DW_TAG_structure_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag
() == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type
|| N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag(
) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
960 N.getTag() == dwarf::DW_TAG_union_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag
() == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type
|| N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag(
) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
961 N.getTag() == dwarf::DW_TAG_enumeration_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag
() == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type
|| N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag(
) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
962 N.getTag() == dwarf::DW_TAG_class_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag
() == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type
|| N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag(
) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
963 N.getTag() == dwarf::DW_TAG_variant_part,do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag
() == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type
|| N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag(
) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
964 "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag
() == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type
|| N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag(
) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
;
965
966 AssertDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope())do { if (!(isScope(N.getRawScope()))) { DebugInfoCheckFailed(
"invalid scope", &N, N.getRawScope()); return; } } while (
false)
;
967 AssertDI(isType(N.getRawBaseType()), "invalid base type", &N,do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed
("invalid base type", &N, N.getRawBaseType()); return; } }
while (false)
968 N.getRawBaseType())do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed
("invalid base type", &N, N.getRawBaseType()); return; } }
while (false)
;
969
970 AssertDI(!N.getRawElements() || isa<MDTuple>(N.getRawElements()),do { if (!(!N.getRawElements() || isa<MDTuple>(N.getRawElements
()))) { DebugInfoCheckFailed("invalid composite elements", &
N, N.getRawElements()); return; } } while (false)
971 "invalid composite elements", &N, N.getRawElements())do { if (!(!N.getRawElements() || isa<MDTuple>(N.getRawElements
()))) { DebugInfoCheckFailed("invalid composite elements", &
N, N.getRawElements()); return; } } while (false)
;
972 AssertDI(isType(N.getRawVTableHolder()), "invalid vtable holder", &N,do { if (!(isType(N.getRawVTableHolder()))) { DebugInfoCheckFailed
("invalid vtable holder", &N, N.getRawVTableHolder()); return
; } } while (false)
973 N.getRawVTableHolder())do { if (!(isType(N.getRawVTableHolder()))) { DebugInfoCheckFailed
("invalid vtable holder", &N, N.getRawVTableHolder()); return
; } } while (false)
;
974 AssertDI(!hasConflictingReferenceFlags(N.getFlags()),do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed
("invalid reference flags", &N); return; } } while (false
)
975 "invalid reference flags", &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed
("invalid reference flags", &N); return; } } while (false
)
;
976
977 if (N.isVector()) {
978 const DINodeArray Elements = N.getElements();
979 AssertDI(Elements.size() == 1 &&do { if (!(Elements.size() == 1 && Elements[0]->getTag
() == dwarf::DW_TAG_subrange_type)) { DebugInfoCheckFailed("invalid vector, expected one element of type subrange"
, &N); return; } } while (false)
980 Elements[0]->getTag() == dwarf::DW_TAG_subrange_type,do { if (!(Elements.size() == 1 && Elements[0]->getTag
() == dwarf::DW_TAG_subrange_type)) { DebugInfoCheckFailed("invalid vector, expected one element of type subrange"
, &N); return; } } while (false)
981 "invalid vector, expected one element of type subrange", &N)do { if (!(Elements.size() == 1 && Elements[0]->getTag
() == dwarf::DW_TAG_subrange_type)) { DebugInfoCheckFailed("invalid vector, expected one element of type subrange"
, &N); return; } } while (false)
;
982 }
983
984 if (auto *Params = N.getRawTemplateParams())
985 visitTemplateParams(N, *Params);
986
987 if (N.getTag() == dwarf::DW_TAG_class_type ||
988 N.getTag() == dwarf::DW_TAG_union_type) {
989 AssertDI(N.getFile() && !N.getFile()->getFilename().empty(),do { if (!(N.getFile() && !N.getFile()->getFilename
().empty())) { DebugInfoCheckFailed("class/union requires a filename"
, &N, N.getFile()); return; } } while (false)
990 "class/union requires a filename", &N, N.getFile())do { if (!(N.getFile() && !N.getFile()->getFilename
().empty())) { DebugInfoCheckFailed("class/union requires a filename"
, &N, N.getFile()); return; } } while (false)
;
991 }
992
993 if (auto *D = N.getRawDiscriminator()) {
994 AssertDI(isa<DIDerivedType>(D) && N.getTag() == dwarf::DW_TAG_variant_part,do { if (!(isa<DIDerivedType>(D) && N.getTag() ==
dwarf::DW_TAG_variant_part)) { DebugInfoCheckFailed("discriminator can only appear on variant part"
); return; } } while (false)
995 "discriminator can only appear on variant part")do { if (!(isa<DIDerivedType>(D) && N.getTag() ==
dwarf::DW_TAG_variant_part)) { DebugInfoCheckFailed("discriminator can only appear on variant part"
); return; } } while (false)
;
996 }
997}
998
999void Verifier::visitDISubroutineType(const DISubroutineType &N) {
1000 AssertDI(N.getTag() == dwarf::DW_TAG_subroutine_type, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_subroutine_type)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1001 if (auto *Types = N.getRawTypeArray()) {
1002 AssertDI(isa<MDTuple>(Types), "invalid composite elements", &N, Types)do { if (!(isa<MDTuple>(Types))) { DebugInfoCheckFailed
("invalid composite elements", &N, Types); return; } } while
(false)
;
1003 for (Metadata *Ty : N.getTypeArray()->operands()) {
1004 AssertDI(isType(Ty), "invalid subroutine type ref", &N, Types, Ty)do { if (!(isType(Ty))) { DebugInfoCheckFailed("invalid subroutine type ref"
, &N, Types, Ty); return; } } while (false)
;
1005 }
1006 }
1007 AssertDI(!hasConflictingReferenceFlags(N.getFlags()),do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed
("invalid reference flags", &N); return; } } while (false
)
1008 "invalid reference flags", &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed
("invalid reference flags", &N); return; } } while (false
)
;
1009}
1010
1011void Verifier::visitDIFile(const DIFile &N) {
1012 AssertDI(N.getTag() == dwarf::DW_TAG_file_type, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_file_type)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1013 Optional<DIFile::ChecksumInfo<StringRef>> Checksum = N.getChecksum();
1014 if (Checksum) {
1015 AssertDI(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last,do { if (!(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last
)) { DebugInfoCheckFailed("invalid checksum kind", &N); return
; } } while (false)
1016 "invalid checksum kind", &N)do { if (!(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last
)) { DebugInfoCheckFailed("invalid checksum kind", &N); return
; } } while (false)
;
1017 size_t Size;
1018 switch (Checksum->Kind) {
1019 case DIFile::CSK_MD5:
1020 Size = 32;
1021 break;
1022 case DIFile::CSK_SHA1:
1023 Size = 40;
1024 break;
1025 }
1026 AssertDI(Checksum->Value.size() == Size, "invalid checksum length", &N)do { if (!(Checksum->Value.size() == Size)) { DebugInfoCheckFailed
("invalid checksum length", &N); return; } } while (false
)
;
1027 AssertDI(Checksum->Value.find_if_not(llvm::isHexDigit) == StringRef::npos,do { if (!(Checksum->Value.find_if_not(llvm::isHexDigit) ==
StringRef::npos)) { DebugInfoCheckFailed("invalid checksum",
&N); return; } } while (false)
1028 "invalid checksum", &N)do { if (!(Checksum->Value.find_if_not(llvm::isHexDigit) ==
StringRef::npos)) { DebugInfoCheckFailed("invalid checksum",
&N); return; } } while (false)
;
1029 }
1030}
1031
1032void Verifier::visitDICompileUnit(const DICompileUnit &N) {
1033 AssertDI(N.isDistinct(), "compile units must be distinct", &N)do { if (!(N.isDistinct())) { DebugInfoCheckFailed("compile units must be distinct"
, &N); return; } } while (false)
;
1034 AssertDI(N.getTag() == dwarf::DW_TAG_compile_unit, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_compile_unit)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1035
1036 // Don't bother verifying the compilation directory or producer string
1037 // as those could be empty.
1038 AssertDI(N.getRawFile() && isa<DIFile>(N.getRawFile()), "invalid file", &N,do { if (!(N.getRawFile() && isa<DIFile>(N.getRawFile
()))) { DebugInfoCheckFailed("invalid file", &N, N.getRawFile
()); return; } } while (false)
1039 N.getRawFile())do { if (!(N.getRawFile() && isa<DIFile>(N.getRawFile
()))) { DebugInfoCheckFailed("invalid file", &N, N.getRawFile
()); return; } } while (false)
;
1040 AssertDI(!N.getFile()->getFilename().empty(), "invalid filename", &N,do { if (!(!N.getFile()->getFilename().empty())) { DebugInfoCheckFailed
("invalid filename", &N, N.getFile()); return; } } while (
false)
1041 N.getFile())do { if (!(!N.getFile()->getFilename().empty())) { DebugInfoCheckFailed
("invalid filename", &N, N.getFile()); return; } } while (
false)
;
1042
1043 verifySourceDebugInfo(N, *N.getFile());
1044
1045 AssertDI((N.getEmissionKind() <= DICompileUnit::LastEmissionKind),do { if (!((N.getEmissionKind() <= DICompileUnit::LastEmissionKind
))) { DebugInfoCheckFailed("invalid emission kind", &N); return
; } } while (false)
1046 "invalid emission kind", &N)do { if (!((N.getEmissionKind() <= DICompileUnit::LastEmissionKind
))) { DebugInfoCheckFailed("invalid emission kind", &N); return
; } } while (false)
;
1047
1048 if (auto *Array = N.getRawEnumTypes()) {
1049 AssertDI(isa<MDTuple>(Array), "invalid enum list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed
("invalid enum list", &N, Array); return; } } while (false
)
;
1050 for (Metadata *Op : N.getEnumTypes()->operands()) {
1051 auto *Enum = dyn_cast_or_null<DICompositeType>(Op);
1052 AssertDI(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type,do { if (!(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type
)) { DebugInfoCheckFailed("invalid enum type", &N, N.getEnumTypes
(), Op); return; } } while (false)
1053 "invalid enum type", &N, N.getEnumTypes(), Op)do { if (!(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type
)) { DebugInfoCheckFailed("invalid enum type", &N, N.getEnumTypes
(), Op); return; } } while (false)
;
1054 }
1055 }
1056 if (auto *Array = N.getRawRetainedTypes()) {
1057 AssertDI(isa<MDTuple>(Array), "invalid retained type list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed
("invalid retained type list", &N, Array); return; } } while
(false)
;
1058 for (Metadata *Op : N.getRetainedTypes()->operands()) {
1059 AssertDI(Op && (isa<DIType>(Op) ||do { if (!(Op && (isa<DIType>(Op) || (isa<DISubprogram
>(Op) && !cast<DISubprogram>(Op)->isDefinition
())))) { DebugInfoCheckFailed("invalid retained type", &N
, Op); return; } } while (false)
1060 (isa<DISubprogram>(Op) &&do { if (!(Op && (isa<DIType>(Op) || (isa<DISubprogram
>(Op) && !cast<DISubprogram>(Op)->isDefinition
())))) { DebugInfoCheckFailed("invalid retained type", &N
, Op); return; } } while (false)
1061 !cast<DISubprogram>(Op)->isDefinition())),do { if (!(Op && (isa<DIType>(Op) || (isa<DISubprogram
>(Op) && !cast<DISubprogram>(Op)->isDefinition
())))) { DebugInfoCheckFailed("invalid retained type", &N
, Op); return; } } while (false)
1062 "invalid retained type", &N, Op)do { if (!(Op && (isa<DIType>(Op) || (isa<DISubprogram
>(Op) && !cast<DISubprogram>(Op)->isDefinition
())))) { DebugInfoCheckFailed("invalid retained type", &N
, Op); return; } } while (false)
;
1063 }
1064 }
1065 if (auto *Array = N.getRawGlobalVariables()) {
1066 AssertDI(isa<MDTuple>(Array), "invalid global variable list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed
("invalid global variable list", &N, Array); return; } } while
(false)
;
1067 for (Metadata *Op : N.getGlobalVariables()->operands()) {
1068 AssertDI(Op && (isa<DIGlobalVariableExpression>(Op)),do { if (!(Op && (isa<DIGlobalVariableExpression>
(Op)))) { DebugInfoCheckFailed("invalid global variable ref",
&N, Op); return; } } while (false)
1069 "invalid global variable ref", &N, Op)do { if (!(Op && (isa<DIGlobalVariableExpression>
(Op)))) { DebugInfoCheckFailed("invalid global variable ref",
&N, Op); return; } } while (false)
;
1070 }
1071 }
1072 if (auto *Array = N.getRawImportedEntities()) {
1073 AssertDI(isa<MDTuple>(Array), "invalid imported entity list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed
("invalid imported entity list", &N, Array); return; } } while
(false)
;
1074 for (Metadata *Op : N.getImportedEntities()->operands()) {
1075 AssertDI(Op && isa<DIImportedEntity>(Op), "invalid imported entity ref",do { if (!(Op && isa<DIImportedEntity>(Op))) { DebugInfoCheckFailed
("invalid imported entity ref", &N, Op); return; } } while
(false)
1076 &N, Op)do { if (!(Op && isa<DIImportedEntity>(Op))) { DebugInfoCheckFailed
("invalid imported entity ref", &N, Op); return; } } while
(false)
;
1077 }
1078 }
1079 if (auto *Array = N.getRawMacros()) {
1080 AssertDI(isa<MDTuple>(Array), "invalid macro list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed
("invalid macro list", &N, Array); return; } } while (false
)
;
1081 for (Metadata *Op : N.getMacros()->operands()) {
1082 AssertDI(Op && isa<DIMacroNode>(Op), "invalid macro ref", &N, Op)do { if (!(Op && isa<DIMacroNode>(Op))) { DebugInfoCheckFailed
("invalid macro ref", &N, Op); return; } } while (false)
;
1083 }
1084 }
1085 CUVisited.insert(&N);
1086}
1087
1088void Verifier::visitDISubprogram(const DISubprogram &N) {
1089 AssertDI(N.getTag() == dwarf::DW_TAG_subprogram, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_subprogram)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1090 AssertDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope())do { if (!(isScope(N.getRawScope()))) { DebugInfoCheckFailed(
"invalid scope", &N, N.getRawScope()); return; } } while (
false)
;
1091 if (auto *F = N.getRawFile())
1092 AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file"
, &N, F); return; } } while (false)
;
1093 else
1094 AssertDI(N.getLine() == 0, "line specified with no file", &N, N.getLine())do { if (!(N.getLine() == 0)) { DebugInfoCheckFailed("line specified with no file"
, &N, N.getLine()); return; } } while (false)
;
1095 if (auto *T = N.getRawType())
1096 AssertDI(isa<DISubroutineType>(T), "invalid subroutine type", &N, T)do { if (!(isa<DISubroutineType>(T))) { DebugInfoCheckFailed
("invalid subroutine type", &N, T); return; } } while (false
)
;
1097 AssertDI(isType(N.getRawContainingType()), "invalid containing type", &N,do { if (!(isType(N.getRawContainingType()))) { DebugInfoCheckFailed
("invalid containing type", &N, N.getRawContainingType())
; return; } } while (false)
1098 N.getRawContainingType())do { if (!(isType(N.getRawContainingType()))) { DebugInfoCheckFailed
("invalid containing type", &N, N.getRawContainingType())
; return; } } while (false)
;
1099 if (auto *Params = N.getRawTemplateParams())
1100 visitTemplateParams(N, *Params);
1101 if (auto *S = N.getRawDeclaration())
1102 AssertDI(isa<DISubprogram>(S) && !cast<DISubprogram>(S)->isDefinition(),do { if (!(isa<DISubprogram>(S) && !cast<DISubprogram
>(S)->isDefinition())) { DebugInfoCheckFailed("invalid subprogram declaration"
, &N, S); return; } } while (false)
1103 "invalid subprogram declaration", &N, S)do { if (!(isa<DISubprogram>(S) && !cast<DISubprogram
>(S)->isDefinition())) { DebugInfoCheckFailed("invalid subprogram declaration"
, &N, S); return; } } while (false)
;
1104 if (auto *RawNode = N.getRawRetainedNodes()) {
1105 auto *Node = dyn_cast<MDTuple>(RawNode);
1106 AssertDI(Node, "invalid retained nodes list", &N, RawNode)do { if (!(Node)) { DebugInfoCheckFailed("invalid retained nodes list"
, &N, RawNode); return; } } while (false)
;
1107 for (Metadata *Op : Node->operands()) {
1108 AssertDI(Op && (isa<DILocalVariable>(Op) || isa<DILabel>(Op)),do { if (!(Op && (isa<DILocalVariable>(Op) || isa
<DILabel>(Op)))) { DebugInfoCheckFailed("invalid retained nodes, expected DILocalVariable or DILabel"
, &N, Node, Op); return; } } while (false)
1109 "invalid retained nodes, expected DILocalVariable or DILabel",do { if (!(Op && (isa<DILocalVariable>(Op) || isa
<DILabel>(Op)))) { DebugInfoCheckFailed("invalid retained nodes, expected DILocalVariable or DILabel"
, &N, Node, Op); return; } } while (false)
1110 &N, Node, Op)do { if (!(Op && (isa<DILocalVariable>(Op) || isa
<DILabel>(Op)))) { DebugInfoCheckFailed("invalid retained nodes, expected DILocalVariable or DILabel"
, &N, Node, Op); return; } } while (false)
;
1111 }
1112 }
1113 AssertDI(!hasConflictingReferenceFlags(N.getFlags()),do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed
("invalid reference flags", &N); return; } } while (false
)
1114 "invalid reference flags", &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed
("invalid reference flags", &N); return; } } while (false
)
;
1115
1116 auto *Unit = N.getRawUnit();
1117 if (N.isDefinition()) {
1118 // Subprogram definitions (not part of the type hierarchy).
1119 AssertDI(N.isDistinct(), "subprogram definitions must be distinct", &N)do { if (!(N.isDistinct())) { DebugInfoCheckFailed("subprogram definitions must be distinct"
, &N); return; } } while (false)
;
1120 AssertDI(Unit, "subprogram definitions must have a compile unit", &N)do { if (!(Unit)) { DebugInfoCheckFailed("subprogram definitions must have a compile unit"
, &N); return; } } while (false)
;
1121 AssertDI(isa<DICompileUnit>(Unit), "invalid unit type", &N, Unit)do { if (!(isa<DICompileUnit>(Unit))) { DebugInfoCheckFailed
("invalid unit type", &N, Unit); return; } } while (false
)
;
1122 if (N.getFile())
1123 verifySourceDebugInfo(*N.getUnit(), *N.getFile());
1124 } else {
1125 // Subprogram declarations (part of the type hierarchy).
1126 AssertDI(!Unit, "subprogram declarations must not have a compile unit", &N)do { if (!(!Unit)) { DebugInfoCheckFailed("subprogram declarations must not have a compile unit"
, &N); return; } } while (false)
;
1127 }
1128
1129 if (auto *RawThrownTypes = N.getRawThrownTypes()) {
1130 auto *ThrownTypes = dyn_cast<MDTuple>(RawThrownTypes);
1131 AssertDI(ThrownTypes, "invalid thrown types list", &N, RawThrownTypes)do { if (!(ThrownTypes)) { DebugInfoCheckFailed("invalid thrown types list"
, &N, RawThrownTypes); return; } } while (false)
;
1132 for (Metadata *Op : ThrownTypes->operands())
1133 AssertDI(Op && isa<DIType>(Op), "invalid thrown type", &N, ThrownTypes,do { if (!(Op && isa<DIType>(Op))) { DebugInfoCheckFailed
("invalid thrown type", &N, ThrownTypes, Op); return; } }
while (false)
1134 Op)do { if (!(Op && isa<DIType>(Op))) { DebugInfoCheckFailed
("invalid thrown type", &N, ThrownTypes, Op); return; } }
while (false)
;
1135 }
1136
1137 if (N.areAllCallsDescribed())
1138 AssertDI(N.isDefinition(),do { if (!(N.isDefinition())) { DebugInfoCheckFailed("DIFlagAllCallsDescribed must be attached to a definition"
); return; } } while (false)
1139 "DIFlagAllCallsDescribed must be attached to a definition")do { if (!(N.isDefinition())) { DebugInfoCheckFailed("DIFlagAllCallsDescribed must be attached to a definition"
); return; } } while (false)
;
1140}
1141
1142void Verifier::visitDILexicalBlockBase(const DILexicalBlockBase &N) {
1143 AssertDI(N.getTag() == dwarf::DW_TAG_lexical_block, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_lexical_block)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1144 AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { DebugInfoCheckFailed("invalid local scope"
, &N, N.getRawScope()); return; } } while (false)
1145 "invalid local scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { DebugInfoCheckFailed("invalid local scope"
, &N, N.getRawScope()); return; } } while (false)
;
1146 if (auto *SP = dyn_cast<DISubprogram>(N.getRawScope()))
1147 AssertDI(SP->isDefinition(), "scope points into the type hierarchy", &N)do { if (!(SP->isDefinition())) { DebugInfoCheckFailed("scope points into the type hierarchy"
, &N); return; } } while (false)
;
1148}
1149
1150void Verifier::visitDILexicalBlock(const DILexicalBlock &N) {
1151 visitDILexicalBlockBase(N);
1152
1153 AssertDI(N.getLine() || !N.getColumn(),do { if (!(N.getLine() || !N.getColumn())) { DebugInfoCheckFailed
("cannot have column info without line info", &N); return
; } } while (false)
1154 "cannot have column info without line info", &N)do { if (!(N.getLine() || !N.getColumn())) { DebugInfoCheckFailed
("cannot have column info without line info", &N); return
; } } while (false)
;
1155}
1156
1157void Verifier::visitDILexicalBlockFile(const DILexicalBlockFile &N) {
1158 visitDILexicalBlockBase(N);
1159}
1160
1161void Verifier::visitDINamespace(const DINamespace &N) {
1162 AssertDI(N.getTag() == dwarf::DW_TAG_namespace, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_namespace)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1163 if (auto *S = N.getRawScope())
1164 AssertDI(isa<DIScope>(S), "invalid scope ref", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope ref"
, &N, S); return; } } while (false)
;
1165}
1166
1167void Verifier::visitDIMacro(const DIMacro &N) {
1168 AssertDI(N.getMacinfoType() == dwarf::DW_MACINFO_define ||do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_define || N
.getMacinfoType() == dwarf::DW_MACINFO_undef)) { DebugInfoCheckFailed
("invalid macinfo type", &N); return; } } while (false)
1169 N.getMacinfoType() == dwarf::DW_MACINFO_undef,do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_define || N
.getMacinfoType() == dwarf::DW_MACINFO_undef)) { DebugInfoCheckFailed
("invalid macinfo type", &N); return; } } while (false)
1170 "invalid macinfo type", &N)do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_define || N
.getMacinfoType() == dwarf::DW_MACINFO_undef)) { DebugInfoCheckFailed
("invalid macinfo type", &N); return; } } while (false)
;
1171 AssertDI(!N.getName().empty(), "anonymous macro", &N)do { if (!(!N.getName().empty())) { DebugInfoCheckFailed("anonymous macro"
, &N); return; } } while (false)
;
1172 if (!N.getValue().empty()) {
1173 assert(N.getValue().data()[0] != ' ' && "Macro value has a space prefix")((N.getValue().data()[0] != ' ' && "Macro value has a space prefix"
) ? static_cast<void> (0) : __assert_fail ("N.getValue().data()[0] != ' ' && \"Macro value has a space prefix\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp"
, 1173, __PRETTY_FUNCTION__))
;
1174 }
1175}
1176
1177void Verifier::visitDIMacroFile(const DIMacroFile &N) {
1178 AssertDI(N.getMacinfoType() == dwarf::DW_MACINFO_start_file,do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_start_file
)) { DebugInfoCheckFailed("invalid macinfo type", &N); return
; } } while (false)
1179 "invalid macinfo type", &N)do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_start_file
)) { DebugInfoCheckFailed("invalid macinfo type", &N); return
; } } while (false)
;
1180 if (auto *F = N.getRawFile())
1181 AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file"
, &N, F); return; } } while (false)
;
1182
1183 if (auto *Array = N.getRawElements()) {
1184 AssertDI(isa<MDTuple>(Array), "invalid macro list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed
("invalid macro list", &N, Array); return; } } while (false
)
;
1185 for (Metadata *Op : N.getElements()->operands()) {
1186 AssertDI(Op && isa<DIMacroNode>(Op), "invalid macro ref", &N, Op)do { if (!(Op && isa<DIMacroNode>(Op))) { DebugInfoCheckFailed
("invalid macro ref", &N, Op); return; } } while (false)
;
1187 }
1188 }
1189}
1190
1191void Verifier::visitDIModule(const DIModule &N) {
1192 AssertDI(N.getTag() == dwarf::DW_TAG_module, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_module)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1193 AssertDI(!N.getName().empty(), "anonymous module", &N)do { if (!(!N.getName().empty())) { DebugInfoCheckFailed("anonymous module"
, &N); return; } } while (false)
;
1194}
1195
1196void Verifier::visitDITemplateParameter(const DITemplateParameter &N) {
1197 AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType())do { if (!(isType(N.getRawType()))) { DebugInfoCheckFailed("invalid type ref"
, &N, N.getRawType()); return; } } while (false)
;
1198}
1199
1200void Verifier::visitDITemplateTypeParameter(const DITemplateTypeParameter &N) {
1201 visitDITemplateParameter(N);
1202
1203 AssertDI(N.getTag() == dwarf::DW_TAG_template_type_parameter, "invalid tag",do { if (!(N.getTag() == dwarf::DW_TAG_template_type_parameter
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
1204 &N)do { if (!(N.getTag() == dwarf::DW_TAG_template_type_parameter
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
;
1205}
1206
1207void Verifier::visitDITemplateValueParameter(
1208 const DITemplateValueParameter &N) {
1209 visitDITemplateParameter(N);
1210
1211 AssertDI(N.getTag() == dwarf::DW_TAG_template_value_parameter ||do { if (!(N.getTag() == dwarf::DW_TAG_template_value_parameter
|| N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||
N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
1212 N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||do { if (!(N.getTag() == dwarf::DW_TAG_template_value_parameter
|| N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||
N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
1213 N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack,do { if (!(N.getTag() == dwarf::DW_TAG_template_value_parameter
|| N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||
N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
1214 "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_template_value_parameter
|| N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||
N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1215}
1216
1217void Verifier::visitDIVariable(const DIVariable &N) {
1218 if (auto *S = N.getRawScope())
1219 AssertDI(isa<DIScope>(S), "invalid scope", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope"
, &N, S); return; } } while (false)
;
1220 if (auto *F = N.getRawFile())
1221 AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file"
, &N, F); return; } } while (false)
;
1222}
1223
1224void Verifier::visitDIGlobalVariable(const DIGlobalVariable &N) {
1225 // Checks common to all variables.
1226 visitDIVariable(N);
1227
1228 AssertDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_variable)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1229 AssertDI(!N.getName().empty(), "missing global variable name", &N)do { if (!(!N.getName().empty())) { DebugInfoCheckFailed("missing global variable name"
, &N); return; } } while (false)
;
1230 AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType())do { if (!(isType(N.getRawType()))) { DebugInfoCheckFailed("invalid type ref"
, &N, N.getRawType()); return; } } while (false)
;
1231 AssertDI(N.getType(), "missing global variable type", &N)do { if (!(N.getType())) { DebugInfoCheckFailed("missing global variable type"
, &N); return; } } while (false)
;
1232 if (auto *Member = N.getRawStaticDataMemberDeclaration()) {
1233 AssertDI(isa<DIDerivedType>(Member),do { if (!(isa<DIDerivedType>(Member))) { DebugInfoCheckFailed
("invalid static data member declaration", &N, Member); return
; } } while (false)
1234 "invalid static data member declaration", &N, Member)do { if (!(isa<DIDerivedType>(Member))) { DebugInfoCheckFailed
("invalid static data member declaration", &N, Member); return
; } } while (false)
;
1235 }
1236}
1237
1238void Verifier::visitDILocalVariable(const DILocalVariable &N) {
1239 // Checks common to all variables.
1240 visitDIVariable(N);
1241
1242 AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType())do { if (!(isType(N.getRawType()))) { DebugInfoCheckFailed("invalid type ref"
, &N, N.getRawType()); return; } } while (false)
;
1243 AssertDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_variable)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1244 AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { DebugInfoCheckFailed("local variable requires a valid scope"
, &N, N.getRawScope()); return; } } while (false)
1245 "local variable requires a valid scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { DebugInfoCheckFailed("local variable requires a valid scope"
, &N, N.getRawScope()); return; } } while (false)
;
1246}
1247
1248void Verifier::visitDILabel(const DILabel &N) {
1249 if (auto *S = N.getRawScope())
1250 AssertDI(isa<DIScope>(S), "invalid scope", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope"
, &N, S); return; } } while (false)
;
1251 if (auto *F = N.getRawFile())
1252 AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file"
, &N, F); return; } } while (false)
;
1253
1254 AssertDI(N.getTag() == dwarf::DW_TAG_label, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_label)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1255 AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { DebugInfoCheckFailed("label requires a valid scope"
, &N, N.getRawScope()); return; } } while (false)
1256 "label requires a valid scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { DebugInfoCheckFailed("label requires a valid scope"
, &N, N.getRawScope()); return; } } while (false)
;
1257}
1258
1259void Verifier::visitDIExpression(const DIExpression &N) {
1260 AssertDI(N.isValid(), "invalid expression", &N)do { if (!(N.isValid())) { DebugInfoCheckFailed("invalid expression"
, &N); return; } } while (false)
;
1261}
1262
1263void Verifier::visitDIGlobalVariableExpression(
1264 const DIGlobalVariableExpression &GVE) {
1265 AssertDI(GVE.getVariable(), "missing variable")do { if (!(GVE.getVariable())) { DebugInfoCheckFailed("missing variable"
); return; } } while (false)
;
1266 if (auto *Var = GVE.getVariable())
1267 visitDIGlobalVariable(*Var);
1268 if (auto *Expr = GVE.getExpression()) {
1269 visitDIExpression(*Expr);
1270 if (auto Fragment = Expr->getFragmentInfo())
1271 verifyFragmentExpression(*GVE.getVariable(), *Fragment, &GVE);
1272 }
1273}
1274
1275void Verifier::visitDIObjCProperty(const DIObjCProperty &N) {
1276 AssertDI(N.getTag() == dwarf::DW_TAG_APPLE_property, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_APPLE_property)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1277 if (auto *T = N.getRawType())
1278 AssertDI(isType(T), "invalid type ref", &N, T)do { if (!(isType(T))) { DebugInfoCheckFailed("invalid type ref"
, &N, T); return; } } while (false)
;
1279 if (auto *F = N.getRawFile())
1280 AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file"
, &N, F); return; } } while (false)
;
1281}
1282
1283void Verifier::visitDIImportedEntity(const DIImportedEntity &N) {
1284 AssertDI(N.getTag() == dwarf::DW_TAG_imported_module ||do { if (!(N.getTag() == dwarf::DW_TAG_imported_module || N.getTag
() == dwarf::DW_TAG_imported_declaration)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
1285 N.getTag() == dwarf::DW_TAG_imported_declaration,do { if (!(N.getTag() == dwarf::DW_TAG_imported_module || N.getTag
() == dwarf::DW_TAG_imported_declaration)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
1286 "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_imported_module || N.getTag
() == dwarf::DW_TAG_imported_declaration)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1287 if (auto *S = N.getRawScope())
1288 AssertDI(isa<DIScope>(S), "invalid scope for imported entity", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope for imported entity"
, &N, S); return; } } while (false)
;
1289 AssertDI(isDINode(N.getRawEntity()), "invalid imported entity", &N,do { if (!(isDINode(N.getRawEntity()))) { DebugInfoCheckFailed
("invalid imported entity", &N, N.getRawEntity()); return
; } } while (false)
1290 N.getRawEntity())do { if (!(isDINode(N.getRawEntity()))) { DebugInfoCheckFailed
("invalid imported entity", &N, N.getRawEntity()); return
; } } while (false)
;
1291}
1292
1293void Verifier::visitComdat(const Comdat &C) {
1294 // The Module is invalid if the GlobalValue has private linkage. Entities
1295 // with private linkage don't have entries in the symbol table.
1296 if (const GlobalValue *GV = M.getNamedValue(C.getName()))
1297 Assert(!GV->hasPrivateLinkage(), "comdat global value has private linkage",do { if (!(!GV->hasPrivateLinkage())) { CheckFailed("comdat global value has private linkage"
, GV); return; } } while (false)
1298 GV)do { if (!(!GV->hasPrivateLinkage())) { CheckFailed("comdat global value has private linkage"
, GV); return; } } while (false)
;
1299}
1300
1301void Verifier::visitModuleIdents(const Module &M) {
1302 const NamedMDNode *Idents = M.getNamedMetadata("llvm.ident");
1303 if (!Idents)
1304 return;
1305
1306 // llvm.ident takes a list of metadata entry. Each entry has only one string.
1307 // Scan each llvm.ident entry and make sure that this requirement is met.
1308 for (const MDNode *N : Idents->operands()) {
1309 Assert(N->getNumOperands() == 1,do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.ident metadata"
, N); return; } } while (false)
1310 "incorrect number of operands in llvm.ident metadata", N)do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.ident metadata"
, N); return; } } while (false)
;
1311 Assert(dyn_cast_or_null<MDString>(N->getOperand(0)),do { if (!(dyn_cast_or_null<MDString>(N->getOperand(
0)))) { CheckFailed(("invalid value for llvm.ident metadata entry operand"
"(the operand should be a string)"), N->getOperand(0)); return
; } } while (false)
1312 ("invalid value for llvm.ident metadata entry operand"do { if (!(dyn_cast_or_null<MDString>(N->getOperand(
0)))) { CheckFailed(("invalid value for llvm.ident metadata entry operand"
"(the operand should be a string)"), N->getOperand(0)); return
; } } while (false)
1313 "(the operand should be a string)"),do { if (!(dyn_cast_or_null<MDString>(N->getOperand(
0)))) { CheckFailed(("invalid value for llvm.ident metadata entry operand"
"(the operand should be a string)"), N->getOperand(0)); return
; } } while (false)
1314 N->getOperand(0))do { if (!(dyn_cast_or_null<MDString>(N->getOperand(
0)))) { CheckFailed(("invalid value for llvm.ident metadata entry operand"
"(the operand should be a string)"), N->getOperand(0)); return
; } } while (false)
;
1315 }
1316}
1317
1318void Verifier::visitModuleCommandLines(const Module &M) {
1319 const NamedMDNode *CommandLines = M.getNamedMetadata("llvm.commandline");
1320 if (!CommandLines)
1321 return;
1322
1323 // llvm.commandline takes a list of metadata entry. Each entry has only one
1324 // string. Scan each llvm.commandline entry and make sure that this
1325 // requirement is met.
1326 for (const MDNode *N : CommandLines->operands()) {
1327 Assert(N->getNumOperands() == 1,do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.commandline metadata"
, N); return; } } while (false)
1328 "incorrect number of operands in llvm.commandline metadata", N)do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.commandline metadata"
, N); return; } } while (false)
;
1329 Assert(dyn_cast_or_null<MDString>(N->getOperand(0)),do { if (!(dyn_cast_or_null<MDString>(N->getOperand(
0)))) { CheckFailed(("invalid value for llvm.commandline metadata entry operand"
"(the operand should be a string)"), N->getOperand(0)); return
; } } while (false)
1330 ("invalid value for llvm.commandline metadata entry operand"do { if (!(dyn_cast_or_null<MDString>(N->getOperand(
0)))) { CheckFailed(("invalid value for llvm.commandline metadata entry operand"
"(the operand should be a string)"), N->getOperand(0)); return
; } } while (false)
1331 "(the operand should be a string)"),do { if (!(dyn_cast_or_null<MDString>(N->getOperand(
0)))) { CheckFailed(("invalid value for llvm.commandline metadata entry operand"
"(the operand should be a string)"), N->getOperand(0)); return
; } } while (false)
1332 N->getOperand(0))do { if (!(dyn_cast_or_null<MDString>(N->getOperand(
0)))) { CheckFailed(("invalid value for llvm.commandline metadata entry operand"
"(the operand should be a string)"), N->getOperand(0)); return
; } } while (false)
;
1333 }
1334}
1335
1336void Verifier::visitModuleFlags(const Module &M) {
1337 const NamedMDNode *Flags = M.getModuleFlagsMetadata();
1338 if (!Flags) return;
1339
1340 // Scan each flag, and track the flags and requirements.
1341 DenseMap<const MDString*, const MDNode*> SeenIDs;
1342 SmallVector<const MDNode*, 16> Requirements;
1343 for (const MDNode *MDN : Flags->operands())
1344 visitModuleFlag(MDN, SeenIDs, Requirements);
1345
1346 // Validate that the requirements in the module are valid.
1347 for (const MDNode *Requirement : Requirements) {
1348 const MDString *Flag = cast<MDString>(Requirement->getOperand(0));
1349 const Metadata *ReqValue = Requirement->getOperand(1);
1350
1351 const MDNode *Op = SeenIDs.lookup(Flag);
1352 if (!Op) {
1353 CheckFailed("invalid requirement on flag, flag is not present in module",
1354 Flag);
1355 continue;
1356 }
1357
1358 if (Op->getOperand(2) != ReqValue) {
1359 CheckFailed(("invalid requirement on flag, "
1360 "flag does not have the required value"),
1361 Flag);
1362 continue;
1363 }
1364 }
1365}
1366
1367void
1368Verifier::visitModuleFlag(const MDNode *Op,
1369 DenseMap<const MDString *, const MDNode *> &SeenIDs,
1370 SmallVectorImpl<const MDNode *> &Requirements) {
1371 // Each module flag should have three arguments, the merge behavior (a
1372 // constant int), the flag ID (an MDString), and the value.
1373 Assert(Op->getNumOperands() == 3,do { if (!(Op->getNumOperands() == 3)) { CheckFailed("incorrect number of operands in module flag"
, Op); return; } } while (false)
1374 "incorrect number of operands in module flag", Op)do { if (!(Op->getNumOperands() == 3)) { CheckFailed("incorrect number of operands in module flag"
, Op); return; } } while (false)
;
1375 Module::ModFlagBehavior MFB;
1376 if (!Module::isValidModFlagBehavior(Op->getOperand(0), MFB)) {
1377 Assert(do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op
->getOperand(0)))) { CheckFailed("invalid behavior operand in module flag (expected constant integer)"
, Op->getOperand(0)); return; } } while (false)
1378 mdconst::dyn_extract_or_null<ConstantInt>(Op->getOperand(0)),do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op
->getOperand(0)))) { CheckFailed("invalid behavior operand in module flag (expected constant integer)"
, Op->getOperand(0)); return; } } while (false)
1379 "invalid behavior operand in module flag (expected constant integer)",do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op
->getOperand(0)))) { CheckFailed("invalid behavior operand in module flag (expected constant integer)"
, Op->getOperand(0)); return; } } while (false)
1380 Op->getOperand(0))do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op
->getOperand(0)))) { CheckFailed("invalid behavior operand in module flag (expected constant integer)"
, Op->getOperand(0)); return; } } while (false)
;
1381 Assert(false,do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)"
, Op->getOperand(0)); return; } } while (false)
1382 "invalid behavior operand in module flag (unexpected constant)",do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)"
, Op->getOperand(0)); return; } } while (false)
1383 Op->getOperand(0))do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)"
, Op->getOperand(0)); return; } } while (false)
;
1384 }
1385 MDString *ID = dyn_cast_or_null<MDString>(Op->getOperand(1));
1386 Assert(ID, "invalid ID operand in module flag (expected metadata string)",do { if (!(ID)) { CheckFailed("invalid ID operand in module flag (expected metadata string)"
, Op->getOperand(1)); return; } } while (false)
1387 Op->getOperand(1))do { if (!(ID)) { CheckFailed("invalid ID operand in module flag (expected metadata string)"
, Op->getOperand(1)); return; } } while (false)
;
1388
1389 // Sanity check the values for behaviors with additional requirements.
1390 switch (MFB) {
1391 case Module::Error:
1392 case Module::Warning:
1393 case Module::Override:
1394 // These behavior types accept any value.
1395 break;
1396
1397 case Module::Max: {
1398 Assert(mdconst::dyn_extract_or_null<ConstantInt>(Op->getOperand(2)),do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op
->getOperand(2)))) { CheckFailed("invalid value for 'max' module flag (expected constant integer)"
, Op->getOperand(2)); return; } } while (false)
1399 "invalid value for 'max' module flag (expected constant integer)",do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op
->getOperand(2)))) { CheckFailed("invalid value for 'max' module flag (expected constant integer)"
, Op->getOperand(2)); return; } } while (false)
1400 Op->getOperand(2))do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op
->getOperand(2)))) { CheckFailed("invalid value for 'max' module flag (expected constant integer)"
, Op->getOperand(2)); return; } } while (false)
;
1401 break;
1402 }
1403
1404 case Module::Require: {
1405 // The value should itself be an MDNode with two operands, a flag ID (an
1406 // MDString), and a value.
1407 MDNode *Value = dyn_cast<MDNode>(Op->getOperand(2));
1408 Assert(Value && Value->getNumOperands() == 2,do { if (!(Value && Value->getNumOperands() == 2))
{ CheckFailed("invalid value for 'require' module flag (expected metadata pair)"
, Op->getOperand(2)); return; } } while (false)
1409 "invalid value for 'require' module flag (expected metadata pair)",do { if (!(Value && Value->getNumOperands() == 2))
{ CheckFailed("invalid value for 'require' module flag (expected metadata pair)"
, Op->getOperand(2)); return; } } while (false)
1410 Op->getOperand(2))do { if (!(Value && Value->getNumOperands() == 2))
{ CheckFailed("invalid value for 'require' module flag (expected metadata pair)"
, Op->getOperand(2)); return; } } while (false)
;
1411 Assert(isa<MDString>(Value->getOperand(0)),do { if (!(isa<MDString>(Value->getOperand(0)))) { CheckFailed
(("invalid value for 'require' module flag " "(first value operand should be a string)"
), Value->getOperand(0)); return; } } while (false)
1412 ("invalid value for 'require' module flag "do { if (!(isa<MDString>(Value->getOperand(0)))) { CheckFailed
(("invalid value for 'require' module flag " "(first value operand should be a string)"
), Value->getOperand(0)); return; } } while (false)
1413 "(first value operand should be a string)"),do { if (!(isa<MDString>(Value->getOperand(0)))) { CheckFailed
(("invalid value for 'require' module flag " "(first value operand should be a string)"
), Value->getOperand(0)); return; } } while (false)
1414 Value->getOperand(0))do { if (!(isa<MDString>(Value->getOperand(0)))) { CheckFailed
(("invalid value for 'require' module flag " "(first value operand should be a string)"
), Value->getOperand(0)); return; } } while (false)
;
1415
1416 // Append it to the list of requirements, to check once all module flags are
1417 // scanned.
1418 Requirements.push_back(Value);
1419 break;
1420 }
1421
1422 case Module::Append:
1423 case Module::AppendUnique: {
1424 // These behavior types require the operand be an MDNode.
1425 Assert(isa<MDNode>(Op->getOperand(2)),do { if (!(isa<MDNode>(Op->getOperand(2)))) { CheckFailed
("invalid value for 'append'-type module flag " "(expected a metadata node)"
, Op->getOperand(2)); return; } } while (false)
1426 "invalid value for 'append'-type module flag "do { if (!(isa<MDNode>(Op->getOperand(2)))) { CheckFailed
("invalid value for 'append'-type module flag " "(expected a metadata node)"
, Op->getOperand(2)); return; } } while (false)
1427 "(expected a metadata node)",do { if (!(isa<MDNode>(Op->getOperand(2)))) { CheckFailed
("invalid value for 'append'-type module flag " "(expected a metadata node)"
, Op->getOperand(2)); return; } } while (false)
1428 Op->getOperand(2))do { if (!(isa<MDNode>(Op->getOperand(2)))) { CheckFailed
("invalid value for 'append'-type module flag " "(expected a metadata node)"
, Op->getOperand(2)); return; } } while (false)
;
1429 break;
1430 }
1431 }
1432
1433 // Unless this is a "requires" flag, check the ID is unique.
1434 if (MFB != Module::Require) {
1435 bool Inserted = SeenIDs.insert(std::make_pair(ID, Op)).second;
1436 Assert(Inserted,do { if (!(Inserted)) { CheckFailed("module flag identifiers must be unique (or of 'require' type)"
, ID); return; } } while (false)
1437 "module flag identifiers must be unique (or of 'require' type)", ID)do { if (!(Inserted)) { CheckFailed("module flag identifiers must be unique (or of 'require' type)"
, ID); return; } } while (false)
;
1438 }
1439
1440 if (ID->getString() == "wchar_size") {
1441 ConstantInt *Value
1442 = mdconst::dyn_extract_or_null<ConstantInt>(Op->getOperand(2));
1443 Assert(Value, "wchar_size metadata requires constant integer argument")do { if (!(Value)) { CheckFailed("wchar_size metadata requires constant integer argument"
); return; } } while (false)
;
1444 }
1445
1446 if (ID->getString() == "Linker Options") {
1447 // If the llvm.linker.options named metadata exists, we assume that the
1448 // bitcode reader has upgraded the module flag. Otherwise the flag might
1449 // have been created by a client directly.
1450 Assert(M.getNamedMetadata("llvm.linker.options"),do { if (!(M.getNamedMetadata("llvm.linker.options"))) { CheckFailed
("'Linker Options' named metadata no longer supported"); return
; } } while (false)
1451 "'Linker Options' named metadata no longer supported")do { if (!(M.getNamedMetadata("llvm.linker.options"))) { CheckFailed
("'Linker Options' named metadata no longer supported"); return
; } } while (false)
;
1452 }
1453
1454 if (ID->getString() == "CG Profile") {
1455 for (const MDOperand &MDO : cast<MDNode>(Op->getOperand(2))->operands())
1456 visitModuleFlagCGProfileEntry(MDO);
1457 }
1458}
1459
1460void Verifier::visitModuleFlagCGProfileEntry(const MDOperand &MDO) {
1461 auto CheckFunction = [&](const MDOperand &FuncMDO) {
1462 if (!FuncMDO)
1463 return;
1464 auto F = dyn_cast<ValueAsMetadata>(FuncMDO);
1465 Assert(F && isa<Function>(F->getValue()), "expected a Function or null",do { if (!(F && isa<Function>(F->getValue())
)) { CheckFailed("expected a Function or null", FuncMDO); return
; } } while (false)
1466 FuncMDO)do { if (!(F && isa<Function>(F->getValue())
)) { CheckFailed("expected a Function or null", FuncMDO); return
; } } while (false)
;
1467 };
1468 auto Node = dyn_cast_or_null<MDNode>(MDO);
1469 Assert(Node && Node->getNumOperands() == 3, "expected a MDNode triple", MDO)do { if (!(Node && Node->getNumOperands() == 3)) {
CheckFailed("expected a MDNode triple", MDO); return; } } while
(false)
;
1470 CheckFunction(Node->getOperand(0));
1471 CheckFunction(Node->getOperand(1));
1472 auto Count = dyn_cast_or_null<ConstantAsMetadata>(Node->getOperand(2));
1473 Assert(Count && Count->getType()->isIntegerTy(),do { if (!(Count && Count->getType()->isIntegerTy
())) { CheckFailed("expected an integer constant", Node->getOperand
(2)); return; } } while (false)
1474 "expected an integer constant", Node->getOperand(2))do { if (!(Count && Count->getType()->isIntegerTy
())) { CheckFailed("expected an integer constant", Node->getOperand
(2)); return; } } while (false)
;
1475}
1476
1477/// Return true if this attribute kind only applies to functions.
1478static bool isFuncOnlyAttr(Attribute::AttrKind Kind) {
1479 switch (Kind) {
1480 case Attribute::NoReturn:
1481 case Attribute::NoCfCheck:
1482 case Attribute::NoUnwind:
1483 case Attribute::NoInline:
1484 case Attribute::AlwaysInline:
1485 case Attribute::OptimizeForSize:
1486 case Attribute::StackProtect:
1487 case Attribute::StackProtectReq:
1488 case Attribute::StackProtectStrong:
1489 case Attribute::SafeStack:
1490 case Attribute::ShadowCallStack:
1491 case Attribute::NoRedZone:
1492 case Attribute::NoImplicitFloat:
1493 case Attribute::Naked:
1494 case Attribute::InlineHint:
1495 case Attribute::StackAlignment:
1496 case Attribute::UWTable:
1497 case Attribute::NonLazyBind:
1498 case Attribute::ReturnsTwice:
1499 case Attribute::SanitizeAddress:
1500 case Attribute::SanitizeHWAddress:
1501 case Attribute::SanitizeThread:
1502 case Attribute::SanitizeMemory:
1503 case Attribute::MinSize:
1504 case Attribute::NoDuplicate:
1505 case Attribute::Builtin:
1506 case Attribute::NoBuiltin:
1507 case Attribute::Cold:
1508 case Attribute::OptForFuzzing:
1509 case Attribute::OptimizeNone:
1510 case Attribute::JumpTable:
1511 case Attribute::Convergent:
1512 case Attribute::ArgMemOnly:
1513 case Attribute::NoRecurse:
1514 case Attribute::InaccessibleMemOnly:
1515 case Attribute::InaccessibleMemOrArgMemOnly:
1516 case Attribute::AllocSize:
1517 case Attribute::SpeculativeLoadHardening:
1518 case Attribute::Speculatable:
1519 case Attribute::StrictFP:
1520 return true;
1521 default:
1522 break;
1523 }
1524 return false;
1525}
1526
1527/// Return true if this is a function attribute that can also appear on
1528/// arguments.
1529static bool isFuncOrArgAttr(Attribute::AttrKind Kind) {
1530 return Kind == Attribute::ReadOnly || Kind == Attribute::WriteOnly ||
1531 Kind == Attribute::ReadNone;
1532}
1533
1534void Verifier::verifyAttributeTypes(AttributeSet Attrs, bool IsFunction,
1535 const Value *V) {
1536 for (Attribute A : Attrs) {
1537 if (A.isStringAttribute())
1538 continue;
1539
1540 if (isFuncOnlyAttr(A.getKindAsEnum())) {
1541 if (!IsFunction) {
1542 CheckFailed("Attribute '" + A.getAsString() +
1543 "' only applies to functions!",
1544 V);
1545 return;
1546 }
1547 } else if (IsFunction && !isFuncOrArgAttr(A.getKindAsEnum())) {
1548 CheckFailed("Attribute '" + A.getAsString() +
1549 "' does not apply to functions!",
1550 V);
1551 return;
1552 }
1553 }
1554}
1555
1556// VerifyParameterAttrs - Check the given attributes for an argument or return
1557// value of the specified type. The value V is printed in error messages.
1558void Verifier::verifyParameterAttrs(AttributeSet Attrs, Type *Ty,
1559 const Value *V) {
1560 if (!Attrs.hasAttributes())
1561 return;
1562
1563 verifyAttributeTypes(Attrs, /*IsFunction=*/false, V);
1564
1565 // Check for mutually incompatible attributes. Only inreg is compatible with
1566 // sret.
1567 unsigned AttrCount = 0;
1568 AttrCount += Attrs.hasAttribute(Attribute::ByVal);
1569 AttrCount += Attrs.hasAttribute(Attribute::InAlloca);
1570 AttrCount += Attrs.hasAttribute(Attribute::StructRet) ||
1571 Attrs.hasAttribute(Attribute::InReg);
1572 AttrCount += Attrs.hasAttribute(Attribute::Nest);
1573 Assert(AttrCount <= 1, "Attributes 'byval', 'inalloca', 'inreg', 'nest', "do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'inreg', 'nest', "
"and 'sret' are incompatible!", V); return; } } while (false
)
1574 "and 'sret' are incompatible!",do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'inreg', 'nest', "
"and 'sret' are incompatible!", V); return; } } while (false
)
1575 V)do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'inreg', 'nest', "
"and 'sret' are incompatible!", V); return; } } while (false
)
;
1576
1577 Assert(!(Attrs.hasAttribute(Attribute::InAlloca) &&do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) &&
Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes "
"'inalloca and readonly' are incompatible!", V); return; } }
while (false)
1578 Attrs.hasAttribute(Attribute::ReadOnly)),do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) &&
Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes "
"'inalloca and readonly' are incompatible!", V); return; } }
while (false)
1579 "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) &&
Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes "
"'inalloca and readonly' are incompatible!", V); return; } }
while (false)
1580 "'inalloca and readonly' are incompatible!",do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) &&
Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes "
"'inalloca and readonly' are incompatible!", V); return; } }
while (false)
1581 V)do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) &&
Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes "
"'inalloca and readonly' are incompatible!", V); return; } }
while (false)
;
1582
1583 Assert(!(Attrs.hasAttribute(Attribute::StructRet) &&do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) &&
Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes "
"'sret and returned' are incompatible!", V); return; } } while
(false)
1584 Attrs.hasAttribute(Attribute::Returned)),do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) &&
Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes "
"'sret and returned' are incompatible!", V); return; } } while
(false)
1585 "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) &&
Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes "
"'sret and returned' are incompatible!", V); return; } } while
(false)
1586 "'sret and returned' are incompatible!",do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) &&
Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes "
"'sret and returned' are incompatible!", V); return; } } while
(false)
1587 V)do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) &&
Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes "
"'sret and returned' are incompatible!", V); return; } } while
(false)
;
1588
1589 Assert(!(Attrs.hasAttribute(Attribute::ZExt) &&do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs
.hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes "
"'zeroext and signext' are incompatible!", V); return; } } while
(false)
1590 Attrs.hasAttribute(Attribute::SExt)),do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs
.hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes "
"'zeroext and signext' are incompatible!", V); return; } } while
(false)
1591 "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs
.hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes "
"'zeroext and signext' are incompatible!", V); return; } } while
(false)
1592 "'zeroext and signext' are incompatible!",do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs
.hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes "
"'zeroext and signext' are incompatible!", V); return; } } while
(false)
1593 V)do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs
.hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes "
"'zeroext and signext' are incompatible!", V); return; } } while
(false)
;
1594
1595 Assert(!(Attrs.hasAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) &&
Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes "
"'readnone and readonly' are incompatible!", V); return; } }
while (false)
1596 Attrs.hasAttribute(Attribute::ReadOnly)),do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) &&
Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes "
"'readnone and readonly' are incompatible!", V); return; } }
while (false)
1597 "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) &&
Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes "
"'readnone and readonly' are incompatible!", V); return; } }
while (false)
1598 "'readnone and readonly' are incompatible!",do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) &&
Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes "
"'readnone and readonly' are incompatible!", V); return; } }
while (false)
1599 V)do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) &&
Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes "
"'readnone and readonly' are incompatible!", V); return; } }
while (false)
;
1600
1601 Assert(!(Attrs.hasAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) &&
Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes "
"'readnone and writeonly' are incompatible!", V); return; } }
while (false)
1602 Attrs.hasAttribute(Attribute::WriteOnly)),do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) &&
Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes "
"'readnone and writeonly' are incompatible!", V); return; } }
while (false)
1603 "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) &&
Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes "
"'readnone and writeonly' are incompatible!", V); return; } }
while (false)
1604 "'readnone and writeonly' are incompatible!",do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) &&
Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes "
"'readnone and writeonly' are incompatible!", V); return; } }
while (false)
1605 V)do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) &&
Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes "
"'readnone and writeonly' are incompatible!", V); return; } }
while (false)
;
1606
1607 Assert(!(Attrs.hasAttribute(Attribute::ReadOnly) &&do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) &&
Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes "
"'readonly and writeonly' are incompatible!", V); return; } }
while (false)
1608 Attrs.hasAttribute(Attribute::WriteOnly)),do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) &&
Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes "
"'readonly and writeonly' are incompatible!", V); return; } }
while (false)
1609 "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) &&
Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes "
"'readonly and writeonly' are incompatible!", V); return; } }
while (false)
1610 "'readonly and writeonly' are incompatible!",do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) &&
Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes "
"'readonly and writeonly' are incompatible!", V); return; } }
while (false)
1611 V)do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) &&
Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes "
"'readonly and writeonly' are incompatible!", V); return; } }
while (false)
;
1612
1613 Assert(!(Attrs.hasAttribute(Attribute::NoInline) &&do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) &&
Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed
("Attributes " "'noinline and alwaysinline' are incompatible!"
, V); return; } } while (false)
1614 Attrs.hasAttribute(Attribute::AlwaysInline)),do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) &&
Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed
("Attributes " "'noinline and alwaysinline' are incompatible!"
, V); return; } } while (false)
1615 "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) &&
Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed
("Attributes " "'noinline and alwaysinline' are incompatible!"
, V); return; } } while (false)
1616 "'noinline and alwaysinline' are incompatible!",do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) &&
Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed
("Attributes " "'noinline and alwaysinline' are incompatible!"
, V); return; } } while (false)
1617 V)do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) &&
Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed
("Attributes " "'noinline and alwaysinline' are incompatible!"
, V); return; } } while (false)
;
1618
1619 AttrBuilder IncompatibleAttrs = AttributeFuncs::typeIncompatible(Ty);
1620 Assert(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs),do { if (!(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs))) {
CheckFailed("Wrong types for attribute: " + AttributeSet::get
(Context, IncompatibleAttrs).getAsString(), V); return; } } while
(false)
1621 "Wrong types for attribute: " +do { if (!(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs))) {
CheckFailed("Wrong types for attribute: " + AttributeSet::get
(Context, IncompatibleAttrs).getAsString(), V); return; } } while
(false)
1622 AttributeSet::get(Context, IncompatibleAttrs).getAsString(),do { if (!(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs))) {
CheckFailed("Wrong types for attribute: " + AttributeSet::get
(Context, IncompatibleAttrs).getAsString(), V); return; } } while
(false)
1623 V)do { if (!(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs))) {
CheckFailed("Wrong types for attribute: " + AttributeSet::get
(Context, IncompatibleAttrs).getAsString(), V); return; } } while
(false)
;
1624
1625 if (PointerType *PTy = dyn_cast<PointerType>(Ty)) {
1626 SmallPtrSet<Type*, 4> Visited;
1627 if (!PTy->getElementType()->isSized(&Visited)) {
1628 Assert(!Attrs.hasAttribute(Attribute::ByVal) &&do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && !
Attrs.hasAttribute(Attribute::InAlloca))) { CheckFailed("Attributes 'byval' and 'inalloca' do not support unsized types!"
, V); return; } } while (false)
1629 !Attrs.hasAttribute(Attribute::InAlloca),do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && !
Attrs.hasAttribute(Attribute::InAlloca))) { CheckFailed("Attributes 'byval' and 'inalloca' do not support unsized types!"
, V); return; } } while (false)
1630 "Attributes 'byval' and 'inalloca' do not support unsized types!",do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && !
Attrs.hasAttribute(Attribute::InAlloca))) { CheckFailed("Attributes 'byval' and 'inalloca' do not support unsized types!"
, V); return; } } while (false)
1631 V)do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && !
Attrs.hasAttribute(Attribute::InAlloca))) { CheckFailed("Attributes 'byval' and 'inalloca' do not support unsized types!"
, V); return; } } while (false)
;
1632 }
1633 if (!isa<PointerType>(PTy->getElementType()))
1634 Assert(!Attrs.hasAttribute(Attribute::SwiftError),do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed
("Attribute 'swifterror' only applies to parameters " "with pointer to pointer type!"
, V); return; } } while (false)
1635 "Attribute 'swifterror' only applies to parameters "do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed
("Attribute 'swifterror' only applies to parameters " "with pointer to pointer type!"
, V); return; } } while (false)
1636 "with pointer to pointer type!",do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed
("Attribute 'swifterror' only applies to parameters " "with pointer to pointer type!"
, V); return; } } while (false)
1637 V)do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed
("Attribute 'swifterror' only applies to parameters " "with pointer to pointer type!"
, V); return; } } while (false)
;
1638 } else {
1639 Assert(!Attrs.hasAttribute(Attribute::ByVal),do { if (!(!Attrs.hasAttribute(Attribute::ByVal))) { CheckFailed
("Attribute 'byval' only applies to parameters with pointer type!"
, V); return; } } while (false)
1640 "Attribute 'byval' only applies to parameters with pointer type!",do { if (!(!Attrs.hasAttribute(Attribute::ByVal))) { CheckFailed
("Attribute 'byval' only applies to parameters with pointer type!"
, V); return; } } while (false)
1641 V)do { if (!(!Attrs.hasAttribute(Attribute::ByVal))) { CheckFailed
("Attribute 'byval' only applies to parameters with pointer type!"
, V); return; } } while (false)
;
1642 Assert(!Attrs.hasAttribute(Attribute::SwiftError),do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed
("Attribute 'swifterror' only applies to parameters " "with pointer type!"
, V); return; } } while (false)
1643 "Attribute 'swifterror' only applies to parameters "do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed
("Attribute 'swifterror' only applies to parameters " "with pointer type!"
, V); return; } } while (false)
1644 "with pointer type!",do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed
("Attribute 'swifterror' only applies to parameters " "with pointer type!"
, V); return; } } while (false)
1645 V)do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed
("Attribute 'swifterror' only applies to parameters " "with pointer type!"
, V); return; } } while (false)
;
1646 }
1647}
1648
1649// Check parameter attributes against a function type.
1650// The value V is printed in error messages.
1651void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
1652 const Value *V) {
1653 if (Attrs.isEmpty())
1654 return;
1655
1656 bool SawNest = false;
1657 bool SawReturned = false;
1658 bool SawSRet = false;
1659 bool SawSwiftSelf = false;
1660 bool SawSwiftError = false;
1661
1662 // Verify return value attributes.
1663 AttributeSet RetAttrs = Attrs.getRetAttributes();
1664 Assert((!RetAttrs.hasAttribute(Attribute::ByVal) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) &&
!RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs
.hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute
(Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute
::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca
) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) &&
!RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed
("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', "
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1665 !RetAttrs.hasAttribute(Attribute::Nest) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) &&
!RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs
.hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute
(Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute
::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca
) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) &&
!RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed
("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', "
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1666 !RetAttrs.hasAttribute(Attribute::StructRet) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) &&
!RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs
.hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute
(Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute
::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca
) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) &&
!RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed
("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', "
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1667 !RetAttrs.hasAttribute(Attribute::NoCapture) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) &&
!RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs
.hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute
(Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute
::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca
) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) &&
!RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed
("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', "
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1668 !RetAttrs.hasAttribute(Attribute::Returned) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) &&
!RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs
.hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute
(Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute
::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca
) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) &&
!RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed
("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', "
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1669 !RetAttrs.hasAttribute(Attribute::InAlloca) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) &&
!RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs
.hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute
(Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute
::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca
) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) &&
!RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed
("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', "
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1670 !RetAttrs.hasAttribute(Attribute::SwiftSelf) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) &&
!RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs
.hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute
(Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute
::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca
) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) &&
!RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed
("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', "
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1671 !RetAttrs.hasAttribute(Attribute::SwiftError)),do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) &&
!RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs
.hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute
(Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute
::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca
) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) &&
!RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed
("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', "
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1672 "Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', "do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) &&
!RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs
.hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute
(Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute
::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca
) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) &&
!RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed
("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', "
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1673 "'returned', 'swiftself', and 'swifterror' do not apply to return "do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) &&
!RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs
.hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute
(Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute
::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca
) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) &&
!RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed
("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', "
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1674 "values!",do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) &&
!RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs
.hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute
(Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute
::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca
) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) &&
!RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed
("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', "
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1675 V)do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) &&
!RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs
.hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute
(Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute
::Returned) && !RetAttrs.hasAttribute(Attribute::InAlloca
) && !RetAttrs.hasAttribute(Attribute::SwiftSelf) &&
!RetAttrs.hasAttribute(Attribute::SwiftError)))) { CheckFailed
("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', "
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
;
1676 Assert((!RetAttrs.hasAttribute(Attribute::ReadOnly) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) &&
!RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs
.hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '"
+ RetAttrs.getAsString() + "' does not apply to function returns"
, V); return; } } while (false)
1677 !RetAttrs.hasAttribute(Attribute::WriteOnly) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) &&
!RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs
.hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '"
+ RetAttrs.getAsString() + "' does not apply to function returns"
, V); return; } } while (false)
1678 !RetAttrs.hasAttribute(Attribute::ReadNone)),do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) &&
!RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs
.hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '"
+ RetAttrs.getAsString() + "' does not apply to function returns"
, V); return; } } while (false)
1679 "Attribute '" + RetAttrs.getAsString() +do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) &&
!RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs
.hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '"
+ RetAttrs.getAsString() + "' does not apply to function returns"
, V); return; } } while (false)
1680 "' does not apply to function returns",do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) &&
!RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs
.hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '"
+ RetAttrs.getAsString() + "' does not apply to function returns"
, V); return; } } while (false)
1681 V)do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) &&
!RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs
.hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '"
+ RetAttrs.getAsString() + "' does not apply to function returns"
, V); return; } } while (false)
;
1682 verifyParameterAttrs(RetAttrs, FT->getReturnType(), V);
1683
1684 // Verify parameter attributes.
1685 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
1686 Type *Ty = FT->getParamType(i);
1687 AttributeSet ArgAttrs = Attrs.getParamAttributes(i);
1688
1689 verifyParameterAttrs(ArgAttrs, Ty, V);
1690
1691 if (ArgAttrs.hasAttribute(Attribute::Nest)) {
1692 Assert(!SawNest, "More than one parameter has attribute nest!", V)do { if (!(!SawNest)) { CheckFailed("More than one parameter has attribute nest!"
, V); return; } } while (false)
;
1693 SawNest = true;
1694 }
1695
1696 if (ArgAttrs.hasAttribute(Attribute::Returned)) {
1697 Assert(!SawReturned, "More than one parameter has attribute returned!",do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!"
, V); return; } } while (false)
1698 V)do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!"
, V); return; } } while (false)
;
1699 Assert(Ty->canLosslesslyBitCastTo(FT->getReturnType()),do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType
()))) { CheckFailed("Incompatible argument and return types for 'returned' attribute"
, V); return; } } while (false)
1700 "Incompatible argument and return types for 'returned' attribute",do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType
()))) { CheckFailed("Incompatible argument and return types for 'returned' attribute"
, V); return; } } while (false)
1701 V)do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType
()))) { CheckFailed("Incompatible argument and return types for 'returned' attribute"
, V); return; } } while (false)
;
1702 SawReturned = true;
1703 }
1704
1705 if (ArgAttrs.hasAttribute(Attribute::StructRet)) {
1706 Assert(!SawSRet, "Cannot have multiple 'sret' parameters!", V)do { if (!(!SawSRet)) { CheckFailed("Cannot have multiple 'sret' parameters!"
, V); return; } } while (false)
;
1707 Assert(i == 0 || i == 1,do { if (!(i == 0 || i == 1)) { CheckFailed("Attribute 'sret' is not on first or second parameter!"
, V); return; } } while (false)
1708 "Attribute 'sret' is not on first or second parameter!", V)do { if (!(i == 0 || i == 1)) { CheckFailed("Attribute 'sret' is not on first or second parameter!"
, V); return; } } while (false)
;
1709 SawSRet = true;
1710 }
1711
1712 if (ArgAttrs.hasAttribute(Attribute::SwiftSelf)) {
1713 Assert(!SawSwiftSelf, "Cannot have multiple 'swiftself' parameters!", V)do { if (!(!SawSwiftSelf)) { CheckFailed("Cannot have multiple 'swiftself' parameters!"
, V); return; } } while (false)
;
1714 SawSwiftSelf = true;
1715 }
1716
1717 if (ArgAttrs.hasAttribute(Attribute::SwiftError)) {
1718 Assert(!SawSwiftError, "Cannot have multiple 'swifterror' parameters!",do { if (!(!SawSwiftError)) { CheckFailed("Cannot have multiple 'swifterror' parameters!"
, V); return; } } while (false)
1719 V)do { if (!(!SawSwiftError)) { CheckFailed("Cannot have multiple 'swifterror' parameters!"
, V); return; } } while (false)
;
1720 SawSwiftError = true;
1721 }
1722
1723 if (ArgAttrs.hasAttribute(Attribute::InAlloca)) {
1724 Assert(i == FT->getNumParams() - 1,do { if (!(i == FT->getNumParams() - 1)) { CheckFailed("inalloca isn't on the last parameter!"
, V); return; } } while (false)
1725 "inalloca isn't on the last parameter!", V)do { if (!(i == FT->getNumParams() - 1)) { CheckFailed("inalloca isn't on the last parameter!"
, V); return; } } while (false)
;
1726 }
1727 }
1728
1729 if (!Attrs.hasAttributes(AttributeList::FunctionIndex))
1730 return;
1731
1732 verifyAttributeTypes(Attrs.getFnAttributes(), /*IsFunction=*/true, V);
1733
1734 Assert(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&
Attrs.hasFnAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes 'readnone and readonly' are incompatible!"
, V); return; } } while (false)
1735 Attrs.hasFnAttribute(Attribute::ReadOnly)),do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&
Attrs.hasFnAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes 'readnone and readonly' are incompatible!"
, V); return; } } while (false)
1736 "Attributes 'readnone and readonly' are incompatible!", V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&
Attrs.hasFnAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes 'readnone and readonly' are incompatible!"
, V); return; } } while (false)
;
1737
1738 Assert(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&
Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed(
"Attributes 'readnone and writeonly' are incompatible!", V); return
; } } while (false)
1739 Attrs.hasFnAttribute(Attribute::WriteOnly)),do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&
Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed(
"Attributes 'readnone and writeonly' are incompatible!", V); return
; } } while (false)
1740 "Attributes 'readnone and writeonly' are incompatible!", V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&
Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed(
"Attributes 'readnone and writeonly' are incompatible!", V); return
; } } while (false)
;
1741
1742 Assert(!(Attrs.hasFnAttribute(Attribute::ReadOnly) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadOnly) &&
Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed(
"Attributes 'readonly and writeonly' are incompatible!", V); return
; } } while (false)
1743 Attrs.hasFnAttribute(Attribute::WriteOnly)),do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadOnly) &&
Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed(
"Attributes 'readonly and writeonly' are incompatible!", V); return
; } } while (false)
1744 "Attributes 'readonly and writeonly' are incompatible!", V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadOnly) &&
Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed(
"Attributes 'readonly and writeonly' are incompatible!", V); return
; } } while (false)
;
1745
1746 Assert(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&
Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly)
))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are "
"incompatible!", V); return; } } while (false)
1747 Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly)),do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&
Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly)
))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are "
"incompatible!", V); return; } } while (false)
1748 "Attributes 'readnone and inaccessiblemem_or_argmemonly' are "do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&
Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly)
))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are "
"incompatible!", V); return; } } while (false)
1749 "incompatible!",do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&
Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly)
))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are "
"incompatible!", V); return; } } while (false)
1750 V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&
Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly)
))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are "
"incompatible!", V); return; } } while (false)
;
1751
1752 Assert(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&
Attrs.hasFnAttribute(Attribute::InaccessibleMemOnly)))) { CheckFailed
("Attributes 'readnone and inaccessiblememonly' are incompatible!"
, V); return; } } while (false)
1753 Attrs.hasFnAttribute(Attribute::InaccessibleMemOnly)),do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&
Attrs.hasFnAttribute(Attribute::InaccessibleMemOnly)))) { CheckFailed
("Attributes 'readnone and inaccessiblememonly' are incompatible!"
, V); return; } } while (false)
1754 "Attributes 'readnone and inaccessiblememonly' are incompatible!", V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&
Attrs.hasFnAttribute(Attribute::InaccessibleMemOnly)))) { CheckFailed
("Attributes 'readnone and inaccessiblememonly' are incompatible!"
, V); return; } } while (false)
;
1755
1756 Assert(!(Attrs.hasFnAttribute(Attribute::NoInline) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::NoInline) &&
Attrs.hasFnAttribute(Attribute::AlwaysInline)))) { CheckFailed
("Attributes 'noinline and alwaysinline' are incompatible!", V
); return; } } while (false)
1757 Attrs.hasFnAttribute(Attribute::AlwaysInline)),do { if (!(!(Attrs.hasFnAttribute(Attribute::NoInline) &&
Attrs.hasFnAttribute(Attribute::AlwaysInline)))) { CheckFailed
("Attributes 'noinline and alwaysinline' are incompatible!", V
); return; } } while (false)
1758 "Attributes 'noinline and alwaysinline' are incompatible!", V)do { if (!(!(Attrs.hasFnAttribute(Attribute::NoInline) &&
Attrs.hasFnAttribute(Attribute::AlwaysInline)))) { CheckFailed
("Attributes 'noinline and alwaysinline' are incompatible!", V
); return; } } while (false)
;
1759
1760 if (Attrs.hasFnAttribute(Attribute::OptimizeNone)) {
1761 Assert(Attrs.hasFnAttribute(Attribute::NoInline),do { if (!(Attrs.hasFnAttribute(Attribute::NoInline))) { CheckFailed
("Attribute 'optnone' requires 'noinline'!", V); return; } } while
(false)
1762 "Attribute 'optnone' requires 'noinline'!", V)do { if (!(Attrs.hasFnAttribute(Attribute::NoInline))) { CheckFailed
("Attribute 'optnone' requires 'noinline'!", V); return; } } while
(false)
;
1763
1764 Assert(!Attrs.hasFnAttribute(Attribute::OptimizeForSize),do { if (!(!Attrs.hasFnAttribute(Attribute::OptimizeForSize))
) { CheckFailed("Attributes 'optsize and optnone' are incompatible!"
, V); return; } } while (false)
1765 "Attributes 'optsize and optnone' are incompatible!", V)do { if (!(!Attrs.hasFnAttribute(Attribute::OptimizeForSize))
) { CheckFailed("Attributes 'optsize and optnone' are incompatible!"
, V); return; } } while (false)
;
1766
1767 Assert(!Attrs.hasFnAttribute(Attribute::MinSize),do { if (!(!Attrs.hasFnAttribute(Attribute::MinSize))) { CheckFailed
("Attributes 'minsize and optnone' are incompatible!", V); return
; } } while (false)
1768 "Attributes 'minsize and optnone' are incompatible!", V)do { if (!(!Attrs.hasFnAttribute(Attribute::MinSize))) { CheckFailed
("Attributes 'minsize and optnone' are incompatible!", V); return
; } } while (false)
;
1769 }
1770
1771 if (Attrs.hasFnAttribute(Attribute::JumpTable)) {
1772 const GlobalValue *GV = cast<GlobalValue>(V);
1773 Assert(GV->hasGlobalUnnamedAddr(),do { if (!(GV->hasGlobalUnnamedAddr())) { CheckFailed("Attribute 'jumptable' requires 'unnamed_addr'"
, V); return; } } while (false)
1774 "Attribute 'jumptable' requires 'unnamed_addr'", V)do { if (!(GV->hasGlobalUnnamedAddr())) { CheckFailed("Attribute 'jumptable' requires 'unnamed_addr'"
, V); return; } } while (false)
;
1775 }
1776
1777 if (Attrs.hasFnAttribute(Attribute::AllocSize)) {
1778 std::pair<unsigned, Optional<unsigned>> Args =
1779 Attrs.getAllocSizeArgs(AttributeList::FunctionIndex);
1780
1781 auto CheckParam = [&](StringRef Name, unsigned ParamNo) {
1782 if (ParamNo >= FT->getNumParams()) {
1783 CheckFailed("'allocsize' " + Name + " argument is out of bounds", V);
1784 return false;
1785 }
1786
1787 if (!FT->getParamType(ParamNo)->isIntegerTy()) {
1788 CheckFailed("'allocsize' " + Name +
1789 " argument must refer to an integer parameter",
1790 V);
1791 return false;
1792 }
1793
1794 return true;
1795 };
1796
1797 if (!CheckParam("element size", Args.first))
1798 return;
1799
1800 if (Args.second && !CheckParam("number of elements", *Args.second))
1801 return;
1802 }
1803}
1804
1805void Verifier::verifyFunctionMetadata(
1806 ArrayRef<std::pair<unsigned, MDNode *>> MDs) {
1807 for (const auto &Pair : MDs) {
1808 if (Pair.first == LLVMContext::MD_prof) {
1809 MDNode *MD = Pair.second;
1810 Assert(MD->getNumOperands() >= 2,do { if (!(MD->getNumOperands() >= 2)) { CheckFailed("!prof annotations should have no less than 2 operands"
, MD); return; } } while (false)
1811 "!prof annotations should have no less than 2 operands", MD)do { if (!(MD->getNumOperands() >= 2)) { CheckFailed("!prof annotations should have no less than 2 operands"
, MD); return; } } while (false)
;
1812
1813 // Check first operand.
1814 Assert(MD->getOperand(0) != nullptr, "first operand should not be null",do { if (!(MD->getOperand(0) != nullptr)) { CheckFailed("first operand should not be null"
, MD); return; } } while (false)
1815 MD)do { if (!(MD->getOperand(0) != nullptr)) { CheckFailed("first operand should not be null"
, MD); return; } } while (false)
;
1816 Assert(isa<MDString>(MD->getOperand(0)),do { if (!(isa<MDString>(MD->getOperand(0)))) { CheckFailed
("expected string with name of the !prof annotation", MD); return
; } } while (false)
1817 "expected string with name of the !prof annotation", MD)do { if (!(isa<MDString>(MD->getOperand(0)))) { CheckFailed
("expected string with name of the !prof annotation", MD); return
; } } while (false)
;
1818 MDString *MDS = cast<MDString>(MD->getOperand(0));
1819 StringRef ProfName = MDS->getString();
1820 Assert(ProfName.equals("function_entry_count") ||do { if (!(ProfName.equals("function_entry_count") || ProfName
.equals("synthetic_function_entry_count"))) { CheckFailed("first operand should be 'function_entry_count'"
" or 'synthetic_function_entry_count'", MD); return; } } while
(false)
1821 ProfName.equals("synthetic_function_entry_count"),do { if (!(ProfName.equals("function_entry_count") || ProfName
.equals("synthetic_function_entry_count"))) { CheckFailed("first operand should be 'function_entry_count'"
" or 'synthetic_function_entry_count'", MD); return; } } while
(false)
1822 "first operand should be 'function_entry_count'"do { if (!(ProfName.equals("function_entry_count") || ProfName
.equals("synthetic_function_entry_count"))) { CheckFailed("first operand should be 'function_entry_count'"
" or 'synthetic_function_entry_count'", MD); return; } } while
(false)
1823 " or 'synthetic_function_entry_count'",do { if (!(ProfName.equals("function_entry_count") || ProfName
.equals("synthetic_function_entry_count"))) { CheckFailed("first operand should be 'function_entry_count'"
" or 'synthetic_function_entry_count'", MD); return; } } while
(false)
1824 MD)do { if (!(ProfName.equals("function_entry_count") || ProfName
.equals("synthetic_function_entry_count"))) { CheckFailed("first operand should be 'function_entry_count'"
" or 'synthetic_function_entry_count'", MD); return; } } while
(false)
;
1825
1826 // Check second operand.
1827 Assert(MD->getOperand(1) != nullptr, "second operand should not be null",do { if (!(MD->getOperand(1) != nullptr)) { CheckFailed("second operand should not be null"
, MD); return; } } while (false)
1828 MD)do { if (!(MD->getOperand(1) != nullptr)) { CheckFailed("second operand should not be null"
, MD); return; } } while (false)
;
1829 Assert(isa<ConstantAsMetadata>(MD->getOperand(1)),do { if (!(isa<ConstantAsMetadata>(MD->getOperand(1)
))) { CheckFailed("expected integer argument to function_entry_count"
, MD); return; } } while (false)
1830 "expected integer argument to function_entry_count", MD)do { if (!(isa<ConstantAsMetadata>(MD->getOperand(1)
))) { CheckFailed("expected integer argument to function_entry_count"
, MD); return; } } while (false)
;
1831 }
1832 }
1833}
1834
1835void Verifier::visitConstantExprsRecursively(const Constant *EntryC) {
1836 if (!ConstantExprVisited.insert(EntryC).second)
1837 return;
1838
1839 SmallVector<const Constant *, 16> Stack;
1840 Stack.push_back(EntryC);
1841
1842 while (!Stack.empty()) {
1843 const Constant *C = Stack.pop_back_val();
1844
1845 // Check this constant expression.
1846 if (const auto *CE = dyn_cast<ConstantExpr>(C))
1847 visitConstantExpr(CE);
1848
1849 if (const auto *GV = dyn_cast<GlobalValue>(C)) {
1850 // Global Values get visited separately, but we do need to make sure
1851 // that the global value is in the correct module
1852 Assert(GV->getParent() == &M, "Referencing global in another module!",do { if (!(GV->getParent() == &M)) { CheckFailed("Referencing global in another module!"
, EntryC, &M, GV, GV->getParent()); return; } } while (
false)
1853 EntryC, &M, GV, GV->getParent())do { if (!(GV->getParent() == &M)) { CheckFailed("Referencing global in another module!"
, EntryC, &M, GV, GV->getParent()); return; } } while (
false)
;
1854 continue;
1855 }
1856
1857 // Visit all sub-expressions.
1858 for (const Use &U : C->operands()) {
1859 const auto *OpC = dyn_cast<Constant>(U);
1860 if (!OpC)
1861 continue;
1862 if (!ConstantExprVisited.insert(OpC).second)
1863 continue;
1864 Stack.push_back(OpC);
1865 }
1866 }
1867}
1868
1869void Verifier::visitConstantExpr(const ConstantExpr *CE) {
1870 if (CE->getOpcode() == Instruction::BitCast)
1871 Assert(CastInst::castIsValid(Instruction::BitCast, CE->getOperand(0),do { if (!(CastInst::castIsValid(Instruction::BitCast, CE->
getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast"
, CE); return; } } while (false)
1872 CE->getType()),do { if (!(CastInst::castIsValid(Instruction::BitCast, CE->
getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast"
, CE); return; } } while (false)
1873 "Invalid bitcast", CE)do { if (!(CastInst::castIsValid(Instruction::BitCast, CE->
getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast"
, CE); return; } } while (false)
;
1874
1875 if (CE->getOpcode() == Instruction::IntToPtr ||
1876 CE->getOpcode() == Instruction::PtrToInt) {
1877 auto *PtrTy = CE->getOpcode() == Instruction::IntToPtr
1878 ? CE->getType()
1879 : CE->getOperand(0)->getType();
1880 StringRef Msg = CE->getOpcode() == Instruction::IntToPtr
1881 ? "inttoptr not supported for non-integral pointers"
1882 : "ptrtoint not supported for non-integral pointers";
1883 Assert(do { if (!(!DL.isNonIntegralPointerType(cast<PointerType>
(PtrTy->getScalarType())))) { CheckFailed(Msg); return; } }
while (false)
1884 !DL.isNonIntegralPointerType(cast<PointerType>(PtrTy->getScalarType())),do { if (!(!DL.isNonIntegralPointerType(cast<PointerType>
(PtrTy->getScalarType())))) { CheckFailed(Msg); return; } }
while (false)
1885 Msg)do { if (!(!DL.isNonIntegralPointerType(cast<PointerType>
(PtrTy->getScalarType())))) { CheckFailed(Msg); return; } }
while (false)
;
1886 }
1887}
1888
1889bool Verifier::verifyAttributeCount(AttributeList Attrs, unsigned Params) {
1890 // There shouldn't be more attribute sets than there are parameters plus the
1891 // function and return value.
1892 return Attrs.getNumAttrSets() <= Params + 2;
1893}
1894
1895/// Verify that statepoint intrinsic is well formed.
1896void Verifier::verifyStatepoint(ImmutableCallSite CS) {
1897 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"
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp"
, 1899, __PRETTY_FUNCTION__))
1898 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"
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp"
, 1899, __PRETTY_FUNCTION__))
1899 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"
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp"
, 1899, __PRETTY_FUNCTION__))
;
1900
1901 const Instruction &CI = *CS.getInstruction();
1902
1903 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 (false)
1904 !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 (false)
1905 "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 (false)
1906 "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 (false)
1907 &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 (false)
;
1908
1909 const Value *IDV = CS.getArgument(0);
1910 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 (false)
1911 &CI)do { if (!(isa<ConstantInt>(IDV))) { CheckFailed("gc.statepoint ID must be a constant integer"
, &CI); return; } } while (false)
;
1912
1913 const Value *NumPatchBytesV = CS.getArgument(1);
1914 Assert(isa<ConstantInt>(NumPatchBytesV),do { if (!(isa<ConstantInt>(NumPatchBytesV))) { CheckFailed
("gc.statepoint number of patchable bytes must be a constant integer"
, &CI); return; } } while (false)
1915 "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 (false)
1916 &CI)do { if (!(isa<ConstantInt>(NumPatchBytesV))) { CheckFailed
("gc.statepoint number of patchable bytes must be a constant integer"
, &CI); return; } } while (false)
;
1917 const int64_t NumPatchBytes =
1918 cast<ConstantInt>(NumPatchBytesV)->getSExtValue();
1919 assert(isInt<32>(NumPatchBytes) && "NumPatchBytesV is an i32!")((isInt<32>(NumPatchBytes) && "NumPatchBytesV is an i32!"
) ? static_cast<void> (0) : __assert_fail ("isInt<32>(NumPatchBytes) && \"NumPatchBytesV is an i32!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp"
, 1919, __PRETTY_FUNCTION__))
;
1920 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 (false)
1921 "positive",do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be "
"positive", &CI); return; } } while (false)
1922 &CI)do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be "
"positive", &CI); return; } } while (false)
;
1923
1924 const Value *Target = CS.getArgument(2);
1925 auto *PT = dyn_cast<PointerType>(Target->getType());
1926 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 (false)
1927 "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 (false)
;
1928 FunctionType *TargetFuncType = cast<FunctionType>(PT->getElementType());
1929
1930 const Value *NumCallArgsV = CS.getArgument(3);
1931 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 (false)
1932 "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 (false)
1933 "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 (false)
1934 &CI)do { if (!(isa<ConstantInt>(NumCallArgsV))) { CheckFailed
("gc.statepoint number of arguments to underlying call " "must be constant integer"
, &CI); return; } } while (false)
;
1935 const int NumCallArgs = cast<ConstantInt>(NumCallArgsV)->getZExtValue();
1936 Assert(NumCallArgs >= 0,do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call "
"must be positive", &CI); return; } } while (false)
1937 "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 (false)
1938 "must be positive",do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call "
"must be positive", &CI); return; } } while (false)
1939 &CI)do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call "
"must be positive", &CI); return; } } while (false)
;
1940 const int NumParams = (int)TargetFuncType->getNumParams();
1941 if (TargetFuncType->isVarArg()) {
1942 Assert(NumCallArgs >= NumParams,do { if (!(NumCallArgs >= NumParams)) { CheckFailed("gc.statepoint mismatch in number of vararg call args"
, &CI); return; } } while (false)
1943 "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 (false)
;
1944
1945 // TODO: Remove this limitation
1946 Assert(TargetFuncType->getReturnType()->isVoidTy(),do { if (!(TargetFuncType->getReturnType()->isVoidTy())
) { CheckFailed("gc.statepoint doesn't support wrapping non-void "
"vararg functions yet", &CI); return; } } while (false)
1947 "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 (false)
1948 "vararg functions yet",do { if (!(TargetFuncType->getReturnType()->isVoidTy())
) { CheckFailed("gc.statepoint doesn't support wrapping non-void "
"vararg functions yet", &CI); return; } } while (false)
1949 &CI)do { if (!(TargetFuncType->getReturnType()->isVoidTy())
) { CheckFailed("gc.statepoint doesn't support wrapping non-void "
"vararg functions yet", &CI); return; } } while (false)
;
1950 } else
1951 Assert(NumCallArgs == NumParams,do { if (!(NumCallArgs == NumParams)) { CheckFailed("gc.statepoint mismatch in number of call args"
, &CI); return; } } while (false)
1952 "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 (false)
;
1953
1954 const Value *FlagsV = CS.getArgument(4);
1955 Assert(isa<ConstantInt>(FlagsV),do { if (!(isa<ConstantInt>(FlagsV))) { CheckFailed("gc.statepoint flags must be constant integer"
, &CI); return; } } while (false)
1956 "gc.statepoint flags must be constant integer", &CI)do { if (!(isa<ConstantInt>(FlagsV))) { CheckFailed("gc.statepoint flags must be constant integer"
, &CI); return; } } while (false)
;
1957 const uint64_t Flags = cast<ConstantInt>(FlagsV)->getZExtValue();
1958 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 (false)
1959 "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 (false)
;
1960
1961 // Verify that the types of the call parameter arguments match
1962 // the type of the wrapped callee.
1963 AttributeList Attrs = CS.getAttributes();
1964 for (int i = 0; i < NumParams; i++) {
1965 Type *ParamType = TargetFuncType->getParamType(i);
1966 Type *ArgType = CS.getArgument(5 + i)->getType();
1967 Assert(ArgType == ParamType,do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped "
"function type", &CI); return; } } while (false)
1968 "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 (false)
1969 "function type",do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped "
"function type", &CI); return; } } while (false)
1970 &CI)do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped "
"function type", &CI); return; } } while (false)
;
1971
1972 if (TargetFuncType->isVarArg()) {
1973 AttributeSet ArgAttrs = Attrs.getParamAttributes(5 + i);
1974 Assert(!ArgAttrs.hasAttribute(Attribute::StructRet),do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed
("Attribute 'sret' cannot be used for vararg call arguments!"
, &CI); return; } } while (false)
1975 "Attribute 'sret' cannot be used for vararg call arguments!", &CI)do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed
("Attribute 'sret' cannot be used for vararg call arguments!"
, &CI); return; } } while (false)
;
1976 }
1977 }
1978
1979 const int EndCallArgsInx = 4 + NumCallArgs;
1980
1981 const Value *NumTransitionArgsV = CS.getArgument(EndCallArgsInx+1);
1982 Assert(isa<ConstantInt>(NumTransitionArgsV),do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed
("gc.statepoint number of transition arguments " "must be constant integer"
, &CI); return; } } while (false)
1983 "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 (false)
1984 "must be constant integer",do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed
("gc.statepoint number of transition arguments " "must be constant integer"
, &CI); return; } } while (false)
1985 &CI)do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed
("gc.statepoint number of transition arguments " "must be constant integer"
, &CI); return; } } while (false)
;
1986 const int NumTransitionArgs =
1987 cast<ConstantInt>(NumTransitionArgsV)->getZExtValue();
1988 Assert(NumTransitionArgs >= 0,do { if (!(NumTransitionArgs >= 0)) { CheckFailed("gc.statepoint number of transition arguments must be positive"
, &CI); return; } } while (false)
1989 "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 (false)
;
1990 const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs;
1991
1992 const Value *NumDeoptArgsV = CS.getArgument(EndTransitionArgsInx+1);
1993 Assert(isa<ConstantInt>(NumDeoptArgsV),do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed
("gc.statepoint number of deoptimization arguments " "must be constant integer"
, &CI); return; } } while (false)
1994 "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 (false)
1995 "must be constant integer",do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed
("gc.statepoint number of deoptimization arguments " "must be constant integer"
, &CI); return; } } while (false)
1996 &CI)do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed
("gc.statepoint number of deoptimization arguments " "must be constant integer"
, &CI); return; } } while (false)
;
1997 const int NumDeoptArgs = cast<ConstantInt>(NumDeoptArgsV)->getZExtValue();
1998 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 (false)
1999 "must be positive",do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments "
"must be positive", &CI); return; } } while (false)
2000 &CI)do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments "
"must be positive", &CI); return; } } while (false)
;
2001
2002 const int ExpectedNumArgs =
2003 7 + NumCallArgs + NumTransitionArgs + NumDeoptArgs;
2004 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 (false)
2005 "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 (false)
;
2006
2007 // Check that the only uses of this gc.statepoint are gc.result or
2008 // gc.relocate calls which are tied to this statepoint and thus part
2009 // of the same statepoint sequence
2010 for (const User *U : CI.users()) {
2011 const CallInst *Call = dyn_cast<const CallInst>(U);
2012 Assert(Call, "illegal use of statepoint token", &CI, U)do { if (!(Call)) { CheckFailed("illegal use of statepoint token"
, &CI, U); return; } } while (false)
;
2013 if (!Call) continue;
2014 Assert(isa<GCRelocateInst>(Call) || isa<GCResultInst>(Call),do { if (!(isa<GCRelocateInst>(Call) || isa<GCResultInst
>(Call))) { CheckFailed("gc.result or gc.relocate are the only value uses "
"of a gc.statepoint", &CI, U); return; } } while (false)
2015 "gc.result or gc.relocate are the only value uses "do { if (!(isa<GCRelocateInst>(Call) || isa<GCResultInst
>(Call))) { CheckFailed("gc.result or gc.relocate are the only value uses "
"of a gc.statepoint", &CI, U); return; } } while (false)
2016 "of a gc.statepoint",do { if (!(isa<GCRelocateInst>(Call) || isa<GCResultInst
>(Call))) { CheckFailed("gc.result or gc.relocate are the only value uses "
"of a gc.statepoint", &CI, U); return; } } while (false)
2017 &CI, U)do { if (!(isa<GCRelocateInst>(Call) || isa<GCResultInst
>(Call))) { CheckFailed("gc.result or gc.relocate are the only value uses "
"of a gc.statepoint", &CI, U); return; } } while (false)
;
2018 if (isa<GCResultInst>(Call)) {
2019 Assert(Call->getArgOperand(0) == &CI,do { if (!(Call->getArgOperand(0) == &CI)) { CheckFailed
("gc.result connected to wrong gc.statepoint", &CI, Call)
; return; } } while (false)
2020 "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 (false)
;
2021 } else if (isa<GCRelocateInst>(Call)) {
2022 Assert(Call->getArgOperand(0) == &CI,do { if (!(Call->getArgOperand(0) == &CI)) { CheckFailed
("gc.relocate connected to wrong gc.statepoint", &CI, Call
); return; } } while (false)
2023 "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 (false)
;
2024 }
2025 }
2026
2027 // Note: It is legal for a single derived pointer to be listed multiple
2028 // times. It's non-optimal, but it is legal. It can also happen after
2029 // insertion if we strip a bitcast away.
2030 // Note: It is really tempting to check that each base is relocated and
2031 // that a derived pointer is never reused as a base pointer. This turns
2032 // out to be problematic since optimizations run after safepoint insertion
2033 // can recognize equality properties that the insertion logic doesn't know
2034 // about. See example statepoint.ll in the verifier subdirectory
2035}
2036
2037void Verifier::verifyFrameRecoverIndices() {
2038 for (auto &Counts : FrameEscapeInfo) {
2039 Function *F = Counts.first;
2040 unsigned EscapedObjectCount = Counts.second.first;
2041 unsigned MaxRecoveredIndex = Counts.second.second;
2042 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 (false)
2043 "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 (false)
2044 "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 (false)
2045 "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 (false)
2046 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 (false)
;
2047 }
2048}
2049
2050static Instruction *getSuccPad(Instruction *Terminator) {
2051 BasicBlock *UnwindDest;
2052 if (auto *II = dyn_cast<InvokeInst>(Terminator))
2053 UnwindDest = II->getUnwindDest();
2054 else if (auto *CSI = dyn_cast<CatchSwitchInst>(Terminator))
2055 UnwindDest = CSI->getUnwindDest();
2056 else
2057 UnwindDest = cast<CleanupReturnInst>(Terminator)->getUnwindDest();
2058 return UnwindDest->getFirstNonPHI();
2059}
2060
2061void Verifier::verifySiblingFuncletUnwinds() {
2062 SmallPtrSet<Instruction *, 8> Visited;
2063 SmallPtrSet<Instruction *, 8> Active;
2064 for (const auto &Pair : SiblingFuncletInfo) {
2065 Instruction *PredPad = Pair.first;
2066 if (Visited.count(PredPad))
2067 continue;
2068 Active.insert(PredPad);
2069 Instruction *Terminator = Pair.second;
2070 do {
2071 Instruction *SuccPad = getSuccPad(Terminator);
2072 if (Active.count(SuccPad)) {
2073 // Found a cycle; report error
2074 Instruction *CyclePad = SuccPad;
2075 SmallVector<Instruction *, 8> CycleNodes;
2076 do {
2077 CycleNodes.push_back(CyclePad);
2078 Instruction *CycleTerminator = SiblingFuncletInfo[CyclePad];
2079 if (CycleTerminator != CyclePad)
2080 CycleNodes.push_back(CycleTerminator);
2081 CyclePad = getSuccPad(CycleTerminator);
2082 } while (CyclePad != SuccPad);
2083 Assert(false, "EH pads can't handle each other's exceptions",do { if (!(false)) { CheckFailed("EH pads can't handle each other's exceptions"
, ArrayRef<Instruction *>(CycleNodes)); return; } } while
(false)
2084 ArrayRef<Instruction *>(CycleNodes))do { if (!(false)) { CheckFailed("EH pads can't handle each other's exceptions"
, ArrayRef<Instruction *>(CycleNodes)); return; } } while
(false)
;
2085 }
2086 // Don't re-walk a node we've already checked
2087 if (!Visited.insert(SuccPad).second)
2088 break;
2089 // Walk to this successor if it has a map entry.
2090 PredPad = SuccPad;
2091 auto TermI = SiblingFuncletInfo.find(PredPad);
2092 if (TermI == SiblingFuncletInfo.end())
2093 break;
2094 Terminator = TermI->second;
2095 Active.insert(PredPad);
2096 } while (true);
2097 // Each node only has one successor, so we've walked all the active
2098 // nodes' successors.
2099 Active.clear();
2100 }
2101}
2102
2103// visitFunction - Verify that a function is ok.
2104//
2105void Verifier::visitFunction(const Function &F) {
2106 visitGlobalValue(F);
2107
2108 // Check function arguments.
2109 FunctionType *FT = F.getFunctionType();
2110 unsigned NumArgs = F.arg_size();
2111
2112 Assert(&Context == &F.getContext(),do { if (!(&Context == &F.getContext())) { CheckFailed
("Function context does not match Module context!", &F); return
; } } while (false)
1
Assuming the condition is true
2
Taking false branch
3
Loop condition is false. Exiting loop
2113 "Function context does not match Module context!", &F)do { if (!(&Context == &F.getContext())) { CheckFailed
("Function context does not match Module context!", &F); return
; } } while (false)
;
2114
2115 Assert(!F.hasCommonLinkage(), "Functions may not have common linkage", &F)do { if (!(!F.hasCommonLinkage())) { CheckFailed("Functions may not have common linkage"
, &F); return; } } while (false)
;
4
Taking false branch
5
Loop condition is false. Exiting loop
2116 Assert(FT->getNumParams() == NumArgs,do { if (!(FT->getNumParams() == NumArgs)) { CheckFailed("# formal arguments must match # of arguments for function type!"
, &F, FT); return; } } while (false)
6
Assuming the condition is true
7
Taking false branch
8
Loop condition is false. Exiting loop
2117 "# formal arguments must match # of arguments for function type!", &F,do { if (!(FT->getNumParams() == NumArgs)) { CheckFailed("# formal arguments must match # of arguments for function type!"
, &F, FT); return; } } while (false)
2118 FT)do { if (!(FT->getNumParams() == NumArgs)) { CheckFailed("# formal arguments must match # of arguments for function type!"
, &F, FT); return; } } while (false)
;
2119 Assert(F.getReturnType()->isFirstClassType() ||do { if (!(F.getReturnType()->isFirstClassType() || F.getReturnType
()->isVoidTy() || F.getReturnType()->isStructTy())) { CheckFailed
("Functions cannot return aggregate values!", &F); return
; } } while (false)
9
Taking false branch
10
Loop condition is false. Exiting loop
2120 F.getReturnType()->isVoidTy() || F.getReturnType()->isStructTy(),do { if (!(F.getReturnType()->isFirstClassType() || F.getReturnType
()->isVoidTy() || F.getReturnType()->isStructTy())) { CheckFailed
("Functions cannot return aggregate values!", &F); return
; } } while (false)
2121 "Functions cannot return aggregate values!", &F)do { if (!(F.getReturnType()->isFirstClassType() || F.getReturnType
()->isVoidTy() || F.getReturnType()->isStructTy())) { CheckFailed
("Functions cannot return aggregate values!", &F); return
; } } while (false)
;
2122
2123 Assert(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy(),do { if (!(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy
())) { CheckFailed("Invalid struct return type!", &F); return
; } } while (false)
11
Assuming the condition is false
12
Taking false branch
13
Loop condition is false. Exiting loop
2124 "Invalid struct return type!", &F)do { if (!(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy
())) { CheckFailed("Invalid struct return type!", &F); return
; } } while (false)
;
2125
2126 AttributeList Attrs = F.getAttributes();
2127
2128 Assert(verifyAttributeCount(Attrs, FT->getNumParams()),do { if (!(verifyAttributeCount(Attrs, FT->getNumParams())
)) { CheckFailed("Attribute after last parameter!", &F); return
; } } while (false)
14
Taking false branch
15
Loop condition is false. Exiting loop
2129 "Attribute after last parameter!", &F)do { if (!(verifyAttributeCount(Attrs, FT->getNumParams())
)) { CheckFailed("Attribute after last parameter!", &F); return
; } } while (false)
;
2130
2131 // Check function attributes.
2132 verifyFunctionAttrs(FT, Attrs, &F);
2133
2134 // On function declarations/definitions, we do not support the builtin
2135 // attribute. We do not check this in VerifyFunctionAttrs since that is
2136 // checking for Attributes that can/can not ever be on functions.
2137 Assert(!Attrs.hasFnAttribute(Attribute::Builtin),do { if (!(!Attrs.hasFnAttribute(Attribute::Builtin))) { CheckFailed
("Attribute 'builtin' can only be applied to a callsite.", &
F); return; } } while (false)
16
Assuming the condition is true
17
Taking false branch
18
Loop condition is false. Exiting loop
2138 "Attribute 'builtin' can only be applied to a callsite.", &F)do { if (!(!Attrs.hasFnAttribute(Attribute::Builtin))) { CheckFailed
("Attribute 'builtin' can only be applied to a callsite.", &
F); return; } } while (false)
;
2139
2140 // Check that this function meets the restrictions on this calling convention.
2141 // Sometimes varargs is used for perfectly forwarding thunks, so some of these
2142 // restrictions can be lifted.
2143 switch (F.getCallingConv()) {
19
Control jumps to the 'default' case at line 2144
2144 default:
2145 case CallingConv::C:
2146 break;
20
Execution continues on line 2171
2147 case CallingConv::AMDGPU_KERNEL:
2148 case CallingConv::SPIR_KERNEL:
2149 Assert(F.getReturnType()->isVoidTy(),do { if (!(F.getReturnType()->isVoidTy())) { CheckFailed("Calling convention requires void return type"
, &F); return; } } while (false)
2150 "Calling convention requires void return type", &F)do { if (!(F.getReturnType()->isVoidTy())) { CheckFailed("Calling convention requires void return type"
, &F); return; } } while (false)
;
2151 LLVM_FALLTHROUGH[[clang::fallthrough]];
2152 case CallingConv::AMDGPU_VS:
2153 case CallingConv::AMDGPU_HS:
2154 case CallingConv::AMDGPU_GS:
2155 case CallingConv::AMDGPU_PS:
2156 case CallingConv::AMDGPU_CS:
2157 Assert(!F.hasStructRetAttr(),do { if (!(!F.hasStructRetAttr())) { CheckFailed("Calling convention does not allow sret"
, &F); return; } } while (false)
2158 "Calling convention does not allow sret", &F)do { if (!(!F.hasStructRetAttr())) { CheckFailed("Calling convention does not allow sret"
, &F); return; } } while (false)
;
2159 LLVM_FALLTHROUGH[[clang::fallthrough]];
2160 case CallingConv::Fast:
2161 case CallingConv::Cold:
2162 case CallingConv::Intel_OCL_BI:
2163 case CallingConv::PTX_Kernel:
2164 case CallingConv::PTX_Device:
2165 Assert(!F.isVarArg(), "Calling convention does not support varargs or "do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or "
"perfect forwarding!", &F); return; } } while (false)
2166 "perfect forwarding!",do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or "
"perfect forwarding!", &F); return; } } while (false)
2167 &F)do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or "
"perfect forwarding!", &F); return; } } while (false)
;
2168 break;
2169 }
2170
2171 bool isLLVMdotName = F.getName().size() >= 5 &&
21
Assuming the condition is false
2172 F.getName().substr(0, 5) == "llvm.";
2173
2174 // Check that the argument values match the function type for this function...
2175 unsigned i = 0;
2176 for (const Argument &Arg : F.args()) {
22
Assuming '__begin1' is equal to '__end1'
2177 Assert(Arg.getType() == FT->getParamType(i),do { if (!(Arg.getType() == FT->getParamType(i))) { CheckFailed
("Argument value does not match function argument type!", &
Arg, FT->getParamType(i)); return; } } while (false)
2178 "Argument value does not match function argument type!", &Arg,do { if (!(Arg.getType() == FT->getParamType(i))) { CheckFailed
("Argument value does not match function argument type!", &
Arg, FT->getParamType(i)); return; } } while (false)
2179 FT->getParamType(i))do { if (!(Arg.getType() == FT->getParamType(i))) { CheckFailed
("Argument value does not match function argument type!", &
Arg, FT->getParamType(i)); return; } } while (false)
;
2180 Assert(Arg.getType()->isFirstClassType(),do { if (!(Arg.getType()->isFirstClassType())) { CheckFailed
("Function arguments must have first-class types!", &Arg)
; return; } } while (false)
2181 "Function arguments must have first-class types!", &Arg)do { if (!(Arg.getType()->isFirstClassType())) { CheckFailed
("Function arguments must have first-class types!", &Arg)
; return; } } while (false)
;
2182 if (!isLLVMdotName) {
2183 Assert(!Arg.getType()->isMetadataTy(),do { if (!(!Arg.getType()->isMetadataTy())) { CheckFailed(
"Function takes metadata but isn't an intrinsic", &Arg, &
F); return; } } while (false)
2184 "Function takes metadata but isn't an intrinsic", &Arg, &F)do { if (!(!Arg.getType()->isMetadataTy())) { CheckFailed(
"Function takes metadata but isn't an intrinsic", &Arg, &
F); return; } } while (false)
;
2185 Assert(!Arg.getType()->isTokenTy(),do { if (!(!Arg.getType()->isTokenTy())) { CheckFailed("Function takes token but isn't an intrinsic"
, &Arg, &F); return; } } while (false)
2186 "Function takes token but isn't an intrinsic", &Arg, &F)do { if (!(!Arg.getType()->isTokenTy())) { CheckFailed("Function takes token but isn't an intrinsic"
, &Arg, &F); return; } } while (false)
;
2187 }
2188
2189 // Check that swifterror argument is only used by loads and stores.
2190 if (Attrs.hasParamAttribute(i, Attribute::SwiftError)) {
2191 verifySwiftErrorValue(&Arg);
2192 }
2193 ++i;
2194 }
2195
2196 if (!isLLVMdotName)
23
Taking true branch
2197 Assert(!F.getReturnType()->isTokenTy(),do { if (!(!F.getReturnType()->isTokenTy())) { CheckFailed
("Functions returns a token but isn't an intrinsic", &F);
return; } } while (false)
24
Taking false branch
25
Loop condition is false. Exiting loop
2198 "Functions returns a token but isn't an intrinsic", &F)do { if (!(!F.getReturnType()->isTokenTy())) { CheckFailed
("Functions returns a token but isn't an intrinsic", &F);
return; } } while (false)
;
2199
2200 // Get the function metadata attachments.
2201 SmallVector<std::pair<unsigned, MDNode *>, 4> MDs;
2202 F.getAllMetadata(MDs);
2203 assert(F.hasMetadata() != MDs.empty() && "Bit out-of-sync")((F.hasMetadata() != MDs.empty() && "Bit out-of-sync"
) ? static_cast<void> (0) : __assert_fail ("F.hasMetadata() != MDs.empty() && \"Bit out-of-sync\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp"
, 2203, __PRETTY_FUNCTION__))
;
26
Assuming the condition is true
27
'?' condition is true
2204 verifyFunctionMetadata(MDs);
2205
2206 // Check validity of the personality function
2207 if (F.hasPersonalityFn()) {
28
Assuming the condition is false
29
Taking false branch
2208 auto *Per = dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts());
2209 if (Per)
2210 Assert(Per->getParent() == F.getParent(),do { if (!(Per->getParent() == F.getParent())) { CheckFailed
("Referencing personality function in another module!", &
F, F.getParent(), Per, Per->getParent()); return; } } while
(false)
2211 "Referencing personality function in another module!",do { if (!(Per->getParent() == F.getParent())) { CheckFailed
("Referencing personality function in another module!", &
F, F.getParent(), Per, Per->getParent()); return; } } while
(false)
2212 &F, F.getParent(), Per, Per->getParent())do { if (!(Per->getParent() == F.getParent())) { CheckFailed
("Referencing personality function in another module!", &
F, F.getParent(), Per, Per->getParent()); return; } } while
(false)
;
2213 }
2214
2215 if (F.isMaterializable()) {
30
Assuming the condition is false
31
Taking false branch
2216 // Function has a body somewhere we can't see.
2217 Assert(MDs.empty(), "unmaterialized function cannot have metadata", &F,do { if (!(MDs.empty())) { CheckFailed("unmaterialized function cannot have metadata"
, &F, MDs.empty() ? nullptr : MDs.front().second); return
; } } while (false)
2218 MDs.empty() ? nullptr : MDs.front().second)do { if (!(MDs.empty())) { CheckFailed("unmaterialized function cannot have metadata"
, &F, MDs.empty() ? nullptr : MDs.front().second); return
; } } while (false)
;
2219 } else if (F.isDeclaration()) {
32
Assuming the condition is false
33
Taking false branch
2220 for (const auto &I : MDs) {
2221 AssertDI(I.first != LLVMContext::MD_dbg,do { if (!(I.first != LLVMContext::MD_dbg)) { DebugInfoCheckFailed
("function declaration may not have a !dbg attachment", &
F); return; } } while (false)
2222 "function declaration may not have a !dbg attachment", &F)do { if (!(I.first != LLVMContext::MD_dbg)) { DebugInfoCheckFailed
("function declaration may not have a !dbg attachment", &
F); return; } } while (false)
;
2223 Assert(I.first != LLVMContext::MD_prof,do { if (!(I.first != LLVMContext::MD_prof)) { CheckFailed("function declaration may not have a !prof attachment"
, &F); return; } } while (false)
2224 "function declaration may not have a !prof attachment", &F)do { if (!(I.first != LLVMContext::MD_prof)) { CheckFailed("function declaration may not have a !prof attachment"
, &F); return; } } while (false)
;
2225
2226 // Verify the metadata itself.
2227 visitMDNode(*I.second);
2228 }
2229 Assert(!F.hasPersonalityFn(),do { if (!(!F.hasPersonalityFn())) { CheckFailed("Function declaration shouldn't have a personality routine"
, &F); return; } } while (false)
2230 "Function declaration shouldn't have a personality routine", &F)do { if (!(!F.hasPersonalityFn())) { CheckFailed("Function declaration shouldn't have a personality routine"
, &F); return; } } while (false)
;
2231 } else {
2232 // Verify that this function (which has a body) is not named "llvm.*". It
2233 // is not legal to define intrinsics.
2234 Assert(!isLLVMdotName, "llvm intrinsics cannot be defined!", &F)do { if (!(!isLLVMdotName)) { CheckFailed("llvm intrinsics cannot be defined!"
, &F); return; } } while (false)
;
34
Taking false branch
35
Loop condition is false. Exiting loop
2235
2236 // Check the entry node
2237 const BasicBlock *Entry = &F.getEntryBlock();
2238 Assert(pred_empty(Entry),do { if (!(pred_empty(Entry))) { CheckFailed("Entry block to function must not have predecessors!"
, Entry); return; } } while (false)
36
Assuming the condition is false
37
Taking false branch
38
Loop condition is false. Exiting loop
2239 "Entry block to function must not have predecessors!", Entry)do { if (!(pred_empty(Entry))) { CheckFailed("Entry block to function must not have predecessors!"
, Entry); return; } } while (false)
;
2240
2241 // The address of the entry block cannot be taken, unless it is dead.
2242 if (Entry->hasAddressTaken()) {
39
Assuming the condition is false
40
Taking false branch
2243 Assert(!BlockAddress::lookup(Entry)->isConstantUsed(),do { if (!(!BlockAddress::lookup(Entry)->isConstantUsed())
) { CheckFailed("blockaddress may not be used with the entry block!"
, Entry); return; } } while (false)
2244 "blockaddress may not be used with the entry block!", Entry)do { if (!(!BlockAddress::lookup(Entry)->isConstantUsed())
) { CheckFailed("blockaddress may not be used with the entry block!"
, Entry); return; } } while (false)
;
2245 }
2246
2247 unsigned NumDebugAttachments = 0, NumProfAttachments = 0;
2248 // Visit metadata attachments.
2249 for (const auto &I : MDs) {
41
Assuming '__begin3' is equal to '__end3'
2250 // Verify that the attachment is legal.
2251 switch (I.first) {
2252 default:
2253 break;
2254 case LLVMContext::MD_dbg: {
2255 ++NumDebugAttachments;
2256 AssertDI(NumDebugAttachments == 1,do { if (!(NumDebugAttachments == 1)) { DebugInfoCheckFailed(
"function must have a single !dbg attachment", &F, I.second
); return; } } while (false)
2257 "function must have a single !dbg attachment", &F, I.second)do { if (!(NumDebugAttachments == 1)) { DebugInfoCheckFailed(
"function must have a single !dbg attachment", &F, I.second
); return; } } while (false)
;
2258 AssertDI(isa<DISubprogram>(I.second),do { if (!(isa<DISubprogram>(I.second))) { DebugInfoCheckFailed
("function !dbg attachment must be a subprogram", &F, I.second
); return; } } while (false)
2259 "function !dbg attachment must be a subprogram", &F, I.second)do { if (!(isa<DISubprogram>(I.second))) { DebugInfoCheckFailed
("function !dbg attachment must be a subprogram", &F, I.second
); return; } } while (false)
;
2260 auto *SP = cast<DISubprogram>(I.second);
2261 const Function *&AttachedTo = DISubprogramAttachments[SP];
2262 AssertDI(!AttachedTo || AttachedTo == &F,do { if (!(!AttachedTo || AttachedTo == &F)) { DebugInfoCheckFailed
("DISubprogram attached to more than one function", SP, &
F); return; } } while (false)
2263 "DISubprogram attached to more than one function", SP, &F)do { if (!(!AttachedTo || AttachedTo == &F)) { DebugInfoCheckFailed
("DISubprogram attached to more than one function", SP, &
F); return; } } while (false)
;
2264 AttachedTo = &F;
2265 break;
2266 }
2267 case LLVMContext::MD_prof:
2268 ++NumProfAttachments;
2269 Assert(NumProfAttachments == 1,do { if (!(NumProfAttachments == 1)) { CheckFailed("function must have a single !prof attachment"
, &F, I.second); return; } } while (false)
2270 "function must have a single !prof attachment", &F, I.second)do { if (!(NumProfAttachments == 1)) { CheckFailed("function must have a single !prof attachment"
, &F, I.second); return; } } while (false)
;
2271 break;
2272 }
2273
2274 // Verify the metadata itself.
2275 visitMDNode(*I.second);
2276 }
2277 }
2278
2279 // If this function is actually an intrinsic, verify that it is only used in
2280 // direct call/invokes, never having its "address taken".
2281 // Only do this if the module is materialized, otherwise we don't have all the
2282 // uses.
2283 if (F.getIntrinsicID() && F.getParent()->isMaterialized()) {
42
Assuming the condition is false
2284 const User *U;
2285 if (F.hasAddressTaken(&U))
2286 Assert(false, "Invalid user of intrinsic instruction!", U)do { if (!(false)) { CheckFailed("Invalid user of intrinsic instruction!"
, U); return; } } while (false)
;
2287 }
2288
2289 auto *N = F.getSubprogram();
2290 HasDebugInfo = (N != nullptr);
43
Assuming the condition is true
2291 if (!HasDebugInfo)
44
Taking false branch
2292 return;
2293
2294 // Check that all !dbg attachments lead to back to N (or, at least, another
2295 // subprogram that describes the same function).
2296 //
2297 // FIXME: Check this incrementally while visiting !dbg attachments.
2298 // FIXME: Only check when N is the canonical subprogram for F.
2299 SmallPtrSet<const MDNode *, 32> Seen;
2300 for (auto &BB : F)
2301 for (auto &I : BB) {
2302 // Be careful about using DILocation here since we might be dealing with
2303 // broken code (this is the Verifier after all).
2304 DILocation *DL =
2305 dyn_cast_or_null<DILocation>(I.getDebugLoc().getAsMDNode());
2306 if (!DL)
45
Assuming 'DL' is non-null
46
Taking false branch
2307 continue;
2308 if (!Seen.insert(DL).second)
47
Assuming the condition is false
48
Taking false branch
2309 continue;
2310
2311 Metadata *Parent = DL->getRawScope();
2312 AssertDI(Parent && isa<DILocalScope>(Parent),do { if (!(Parent && isa<DILocalScope>(Parent))
) { DebugInfoCheckFailed("DILocation's scope must be a DILocalScope"
, N, &F, &I, DL, Parent); return; } } while (false)
49
Assuming 'Parent' is non-null
50
Taking false branch
51
Loop condition is false. Exiting loop
2313 "DILocation's scope must be a DILocalScope", N, &F, &I, DL,do { if (!(Parent && isa<DILocalScope>(Parent))
) { DebugInfoCheckFailed("DILocation's scope must be a DILocalScope"
, N, &F, &I, DL, Parent); return; } } while (false)
2314 Parent)do { if (!(Parent && isa<DILocalScope>(Parent))
) { DebugInfoCheckFailed("DILocation's scope must be a DILocalScope"
, N, &F, &I, DL, Parent); return; } } while (false)
;
2315 DILocalScope *Scope = DL->getInlinedAtScope();
2316 if (Scope && !Seen.insert(Scope).second)
52
Assuming the condition is false
53
Taking false branch
2317 continue;
2318
2319 DISubprogram *SP = Scope ? Scope->getSubprogram() : nullptr;
54
'?' condition is true
55
'SP' initialized here
2320
2321 // Scope and SP could be the same MDNode and we don't want to skip
2322 // validation in that case
2323 if (SP && ((Scope != SP) && !Seen.insert(SP).second))
56
Assuming 'SP' is null
57
Taking false branch
2324 continue;
2325
2326 // FIXME: Once N is canonical, check "SP == &N".
2327 AssertDI(SP->describes(&F),do { if (!(SP->describes(&F))) { DebugInfoCheckFailed(
"!dbg attachment points at wrong subprogram for function", N,
&F, &I, DL, Scope, SP); return; } } while (false)
58
Called C++ object pointer is null
2328 "!dbg attachment points at wrong subprogram for function", N, &F,do { if (!(SP->describes(&F))) { DebugInfoCheckFailed(
"!dbg attachment points at wrong subprogram for function", N,
&F, &I, DL, Scope, SP); return; } } while (false)
2329 &I, DL, Scope, SP)do { if (!(SP->describes(&F))) { DebugInfoCheckFailed(
"!dbg attachment points at wrong subprogram for function", N,
&F, &I, DL, Scope, SP); return; } } while (false)
;
2330 }
2331}
2332
2333// verifyBasicBlock - Verify that a basic block is well formed...
2334//
2335void Verifier::visitBasicBlock(BasicBlock &BB) {
2336 InstsInThisBlock.clear();
2337
2338 // Ensure that basic blocks have terminators!
2339 Assert(BB.getTerminator(), "Basic Block does not have terminator!", &BB)do { if (!(BB.getTerminator())) { CheckFailed("Basic Block does not have terminator!"
, &BB); return; } } while (false)
;
2340
2341 // Check constraints that this basic block imposes on all of the PHI nodes in
2342 // it.
2343 if (isa<PHINode>(BB.front())) {
2344 SmallVector<BasicBlock*, 8> Preds(pred_begin(&BB), pred_end(&BB));
2345 SmallVector<std::pair<BasicBlock*, Value*>, 8> Values;
2346 llvm::sort(Preds);
2347 for (const PHINode &PN : BB.phis()) {
2348 // Ensure that PHI nodes have at least one entry!
2349 Assert(PN.getNumIncomingValues() != 0,do { if (!(PN.getNumIncomingValues() != 0)) { CheckFailed("PHI nodes must have at least one entry. If the block is dead, "
"the PHI should be removed!", &PN); return; } } while (false
)
2350 "PHI nodes must have at least one entry. If the block is dead, "do { if (!(PN.getNumIncomingValues() != 0)) { CheckFailed("PHI nodes must have at least one entry. If the block is dead, "
"the PHI should be removed!", &PN); return; } } while (false
)
2351 "the PHI should be removed!",do { if (!(PN.getNumIncomingValues() != 0)) { CheckFailed("PHI nodes must have at least one entry. If the block is dead, "
"the PHI should be removed!", &PN); return; } } while (false
)
2352 &PN)do { if (!(PN.getNumIncomingValues() != 0)) { CheckFailed("PHI nodes must have at least one entry. If the block is dead, "
"the PHI should be removed!", &PN); return; } } while (false
)
;
2353 Assert(PN.getNumIncomingValues() == Preds.size(),do { if (!(PN.getNumIncomingValues() == Preds.size())) { CheckFailed
("PHINode should have one entry for each predecessor of its "
"parent basic block!", &PN); return; } } while (false)
2354 "PHINode should have one entry for each predecessor of its "do { if (!(PN.getNumIncomingValues() == Preds.size())) { CheckFailed
("PHINode should have one entry for each predecessor of its "
"parent basic block!", &PN); return; } } while (false)
2355 "parent basic block!",do { if (!(PN.getNumIncomingValues() == Preds.size())) { CheckFailed
("PHINode should have one entry for each predecessor of its "
"parent basic block!", &PN); return; } } while (false)
2356 &PN)do { if (!(PN.getNumIncomingValues() == Preds.size())) { CheckFailed
("PHINode should have one entry for each predecessor of its "
"parent basic block!", &PN); return; } } while (false)
;
2357
2358 // Get and sort all incoming values in the PHI node...
2359 Values.clear();
2360 Values.reserve(PN.getNumIncomingValues());
2361 for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
2362 Values.push_back(
2363 std::make_pair(PN.getIncomingBlock(i), PN.getIncomingValue(i)));
2364 llvm::sort(Values);
2365
2366 for (unsigned i = 0, e = Values.size(); i != e; ++i) {
2367 // Check to make sure that if there is more than one entry for a
2368 // particular basic block in this PHI node, that the incoming values are
2369 // all identical.
2370 //
2371 Assert(i == 0 || Values[i].first != Values[i - 1].first ||do { if (!(i == 0 || Values[i].first != Values[i - 1].first ||
Values[i].second == Values[i - 1].second)) { CheckFailed("PHI node has multiple entries for the same basic block with "
"different incoming values!", &PN, Values[i].first, Values
[i].second, Values[i - 1].second); return; } } while (false)
2372 Values[i].second == Values[i - 1].second,do { if (!(i == 0 || Values[i].first != Values[i - 1].first ||
Values[i].second == Values[i - 1].second)) { CheckFailed("PHI node has multiple entries for the same basic block with "
"different incoming values!", &PN, Values[i].first, Values
[i].second, Values[i - 1].second); return; } } while (false)
2373 "PHI node has multiple entries for the same basic block with "do { if (!(i == 0 || Values[i].first != Values[i - 1].first ||
Values[i].second == Values[i - 1].second)) { CheckFailed("PHI node has multiple entries for the same basic block with "
"different incoming values!", &PN, Values[i].first, Values
[i].second, Values[i - 1].second); return; } } while (false)
2374 "different incoming values!",do { if (!(i == 0 || Values[i].first != Values[i - 1].first ||
Values[i].second == Values[i - 1].second)) { CheckFailed("PHI node has multiple entries for the same basic block with "
"different incoming values!", &PN, Values[i].first, Values
[i].second, Values[i - 1].second); return; } } while (false)
2375 &PN, Values[i].first, Values[i].second, Values[i - 1].second)do { if (!(i == 0 || Values[i].first != Values[i - 1].first ||
Values[i].second == Values[i - 1].second)) { CheckFailed("PHI node has multiple entries for the same basic block with "
"different incoming values!", &PN, Values[i].first, Values
[i].second, Values[i - 1].second); return; } } while (false)
;
2376
2377 // Check to make sure that the predecessors and PHI node entries are
2378 // matched up.
2379 Assert(Values[i].first == Preds[i],do { if (!(Values[i].first == Preds[i])) { CheckFailed("PHI node entries do not match predecessors!"
, &PN, Values[i].first, Preds[i]); return; } } while (false
)
2380 "PHI node entries do not match predecessors!", &PN,do { if (!(Values[i].first == Preds[i])) { CheckFailed("PHI node entries do not match predecessors!"
, &PN, Values[i].first, Preds[i]); return; } } while (false
)
2381 Values[i].first, Preds[i])do { if (!(Values[i].first == Preds[i])) { CheckFailed("PHI node entries do not match predecessors!"
, &PN, Values[i].first, Preds[i]); return; } } while (false
)
;
2382 }
2383 }
2384 }
2385
2386 // Check that all instructions have their parent pointers set up correctly.
2387 for (auto &I : BB)
2388 {
2389 Assert(I.getParent() == &BB, "Instruction has bogus parent pointer!")do { if (!(I.getParent() == &BB)) { CheckFailed("Instruction has bogus parent pointer!"
); return; } } while (false)
;
2390 }
2391}
2392
2393void Verifier::visitTerminator(Instruction &I) {
2394 // Ensure that terminators only exist at the end of the basic block.
2395 Assert(&I == I.getParent()->getTerminator(),do { if (!(&I == I.getParent()->getTerminator())) { CheckFailed
("Terminator found in the middle of a basic block!", I.getParent
()); return; } } while (false)
2396 "Terminator found in the middle of a basic block!", I.getParent())do { if (!(&I == I.getParent()->getTerminator())) { CheckFailed
("Terminator found in the middle of a basic block!", I.getParent
()); return; } } while (false)
;
2397 visitInstruction(I);
2398}
2399
2400void Verifier::visitBranchInst(BranchInst &BI) {
2401 if (BI.isConditional()) {
2402 Assert(BI.getCondition()->getType()->isIntegerTy(1),do { if (!(BI.getCondition()->getType()->isIntegerTy(1)
)) { CheckFailed("Branch condition is not 'i1' type!", &BI
, BI.getCondition()); return; } } while (false)
2403 "Branch condition is not 'i1' type!", &BI, BI.getCondition())do { if (!(BI.getCondition()->getType()->isIntegerTy(1)
)) { CheckFailed("Branch condition is not 'i1' type!", &BI
, BI.getCondition()); return; } } while (false)
;
2404 }
2405 visitTerminator(BI);
2406}
2407
2408void Verifier::visitReturnInst(ReturnInst &RI) {
2409 Function *F = RI.getParent()->getParent();
2410 unsigned N = RI.getNumOperands();
2411 if (F->getReturnType()->isVoidTy())
2412 Assert(N == 0,do { if (!(N == 0)) { CheckFailed("Found return instr that returns non-void in Function of void "
"return type!", &RI, F->getReturnType()); return; } }
while (false)
2413 "Found return instr that returns non-void in Function of void "do { if (!(N == 0)) { CheckFailed("Found return instr that returns non-void in Function of void "
"return type!", &RI, F->getReturnType()); return; } }
while (false)
2414 "return type!",do { if (!(N == 0)) { CheckFailed("Found return instr that returns non-void in Function of void "
"return type!", &RI, F->getReturnType()); return; } }
while (false)
2415 &RI, F->getReturnType())do { if (!(N == 0)) { CheckFailed("Found return instr that returns non-void in Function of void "
"return type!", &RI, F->getReturnType()); return; } }
while (false)
;
2416 else
2417 Assert(N == 1 && F->getReturnType() == RI.getOperand(0)->getType(),do { if (!(N == 1 && F->getReturnType() == RI.getOperand
(0)->getType())) { CheckFailed("Function return type does not match operand "
"type of return inst!", &RI, F->getReturnType()); return
; } } while (false)
2418 "Function return type does not match operand "do { if (!(N == 1 && F->getReturnType() == RI.getOperand
(0)->getType())) { CheckFailed("Function return type does not match operand "
"type of return inst!", &RI, F->getReturnType()); return
; } } while (false)
2419 "type of return inst!",do { if (!(N == 1 && F->getReturnType() == RI.getOperand
(0)->getType())) { CheckFailed("Function return type does not match operand "
"type of return inst!", &RI, F->getReturnType()); return
; } } while (false)
2420 &RI, F->getReturnType())do { if (!(N == 1 && F->getReturnType() == RI.getOperand
(0)->getType())) { CheckFailed("Function return type does not match operand "
"type of return inst!", &RI, F->getReturnType()); return
; } } while (false)
;
2421
2422 // Check to make sure that the return value has necessary properties for
2423 // terminators...
2424 visitTerminator(RI);
2425}
2426
2427void Verifier::visitSwitchInst(SwitchInst &SI) {
2428 // Check to make sure that all of the constants in the switch instruction
2429 // have the same type as the switched-on value.
2430 Type *SwitchTy = SI.getCondition()->getType();
2431 SmallPtrSet<ConstantInt*, 32> Constants;
2432 for (auto &Case : SI.cases()) {
2433 Assert(Case.getCaseValue()->getType() == SwitchTy,do { if (!(Case.getCaseValue()->getType() == SwitchTy)) { CheckFailed
("Switch constants must all be same type as switch value!", &
SI); return; } } while (false)
2434 "Switch constants must all be same type as switch value!", &SI)do { if (!(Case.getCaseValue()->getType() == SwitchTy)) { CheckFailed
("Switch constants must all be same type as switch value!", &
SI); return; } } while (false)
;
2435 Assert(Constants.insert(Case.getCaseValue()).second,do { if (!(Constants.insert(Case.getCaseValue()).second)) { CheckFailed
("Duplicate integer as switch case", &SI, Case.getCaseValue
()); return; } } while (false)
2436 "Duplicate integer as switch case", &SI, Case.getCaseValue())do { if (!(Constants.insert(Case.getCaseValue()).second)) { CheckFailed
("Duplicate integer as switch case", &SI, Case.getCaseValue
()); return; } } while (false)
;
2437 }
2438
2439 visitTerminator(SI);
2440}
2441
2442void Verifier::visitIndirectBrInst(IndirectBrInst &BI) {
2443 Assert(BI.getAddress()->getType()->isPointerTy(),do { if (!(BI.getAddress()->getType()->isPointerTy())) {
CheckFailed("Indirectbr operand must have pointer type!", &
BI); return; } } while (false)
2444 "Indirectbr operand must have pointer type!", &BI)do { if (!(BI.getAddress()->getType()->isPointerTy())) {
CheckFailed("Indirectbr operand must have pointer type!", &
BI); return; } } while (false)
;
2445 for (unsigned i = 0, e = BI.getNumDestinations(); i != e; ++i)
2446 Assert(BI.getDestination(i)->getType()->isLabelTy(),do { if (!(BI.getDestination(i)->getType()->isLabelTy()
)) { CheckFailed("Indirectbr destinations must all have pointer type!"
, &BI); return; } } while (false)
2447 "Indirectbr destinations must all have pointer type!", &BI)do { if (!(BI.getDestination(i)->getType()->isLabelTy()
)) { CheckFailed("Indirectbr destinations must all have pointer type!"
, &BI); return; } } while (false)
;
2448
2449 visitTerminator(BI);
2450}
2451
2452void Verifier::visitSelectInst(SelectInst &SI) {
2453 Assert(!SelectInst::areInvalidOperands(SI.getOperand(0), SI.getOperand(1),do { if (!(!SelectInst::areInvalidOperands(SI.getOperand(0), SI
.getOperand(1), SI.getOperand(2)))) { CheckFailed("Invalid operands for select instruction!"
, &SI); return; } } while (false)
2454 SI.getOperand(2)),do { if (!(!SelectInst::areInvalidOperands(SI.getOperand(0), SI
.getOperand(1), SI.getOperand(2)))) { CheckFailed("Invalid operands for select instruction!"
, &SI); return; } } while (false)
2455 "Invalid operands for select instruction!", &SI)do { if (!(!SelectInst::areInvalidOperands(SI.getOperand(0), SI
.getOperand(1), SI.getOperand(2)))) { CheckFailed("Invalid operands for select instruction!"
, &SI); return; } } while (false)
;
2456
2457 Assert(SI.getTrueValue()->getType() == SI.getType(),do { if (!(SI.getTrueValue()->getType() == SI.getType())) {
CheckFailed("Select values must have same type as select instruction!"
, &SI); return; } } while (false)
2458 "Select values must have same type as select instruction!", &SI)do { if (!(SI.getTrueValue()->getType() == SI.getType())) {
CheckFailed("Select values must have same type as select instruction!"
, &SI); return; } } while (false)
;
2459 visitInstruction(SI);
2460}
2461
2462/// visitUserOp1 - User defined operators shouldn't live beyond the lifetime of
2463/// a pass, if any exist, it's an error.
2464///
2465void Verifier::visitUserOp1(Instruction &I) {
2466 Assert(false, "User-defined operators should not live outside of a pass!", &I)do { if (!(false)) { CheckFailed("User-defined operators should not live outside of a pass!"
, &I); return; } } while (false)
;
2467}
2468
2469void Verifier::visitTruncInst(TruncInst &I) {
2470 // Get the source and destination types
2471 Type *SrcTy = I.getOperand(0)->getType();
2472 Type *DestTy = I.getType();
2473
2474 // Get the size of the types in bits, we'll need this later
2475 unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
2476 unsigned DestBitSize = DestTy->getScalarSizeInBits();
2477
2478 Assert(SrcTy->isIntOrIntVectorTy(), "Trunc only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("Trunc only operates on integer"
, &I); return; } } while (false)
;
2479 Assert(DestTy->isIntOrIntVectorTy(), "Trunc only produces integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("Trunc only produces integer"
, &I); return; } } while (false)
;
2480 Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(),do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("trunc source and destination must both be a vector or neither"
, &I); return; } } while (false)
2481 "trunc source and destination must both be a vector or neither", &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("trunc source and destination must both be a vector or neither"
, &I); return; } } while (false)
;
2482 Assert(SrcBitSize > DestBitSize, "DestTy too big for Trunc", &I)do { if (!(SrcBitSize > DestBitSize)) { CheckFailed("DestTy too big for Trunc"
, &I); return; } } while (false)
;
2483
2484 visitInstruction(I);
2485}
2486
2487void Verifier::visitZExtInst(ZExtInst &I) {
2488 // Get the source and destination types
2489 Type *SrcTy = I.getOperand(0)->getType();
2490 Type *DestTy = I.getType();
2491
2492 // Get the size of the types in bits, we'll need this later
2493 Assert(SrcTy->isIntOrIntVectorTy(), "ZExt only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("ZExt only operates on integer"
, &I); return; } } while (false)
;
2494 Assert(DestTy->isIntOrIntVectorTy(), "ZExt only produces an integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("ZExt only produces an integer"
, &I); return; } } while (false)
;
2495 Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(),do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("zext source and destination must both be a vector or neither"
, &I); return; } } while (false)
2496 "zext source and destination must both be a vector or neither", &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("zext source and destination must both be a vector or neither"
, &I); return; } } while (false)
;
2497 unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
2498 unsigned DestBitSize = DestTy->getScalarSizeInBits();
2499
2500 Assert(SrcBitSize < DestBitSize, "Type too small for ZExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("Type too small for ZExt"
, &I); return; } } while (false)
;
2501
2502 visitInstruction(I);
2503}
2504
2505void Verifier::visitSExtInst(SExtInst &I) {
2506 // Get the source and destination types
2507 Type *SrcTy = I.getOperand(0)->getType();
2508 Type *DestTy = I.getType();
2509
2510 // Get the size of the types in bits, we'll need this later
2511 unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
2512 unsigned DestBitSize = DestTy->getScalarSizeInBits();
2513
2514 Assert(SrcTy->isIntOrIntVectorTy(), "SExt only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("SExt only operates on integer"
, &I); return; } } while (false)
;
2515 Assert(DestTy->isIntOrIntVectorTy(), "SExt only produces an integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("SExt only produces an integer"
, &I); return; } } while (false)
;
2516 Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(),do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("sext source and destination must both be a vector or neither"
, &I); return; } } while (false)
2517 "sext source and destination must both be a vector or neither", &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("sext source and destination must both be a vector or neither"
, &I); return; } } while (false)
;
2518 Assert(SrcBitSize < DestBitSize, "Type too small for SExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("Type too small for SExt"
, &I); return; } } while (false)
;
2519
2520 visitInstruction(I);
2521}
2522
2523void Verifier::visitFPTruncInst(FPTruncInst &I) {
2524 // Get the source and destination types
2525 Type *SrcTy = I.getOperand(0)->getType();
2526 Type *DestTy = I.getType();
2527 // Get the size of the types in bits, we'll need this later
2528 unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
2529 unsigned DestBitSize = DestTy->getScalarSizeInBits();
2530
2531 Assert(SrcTy->isFPOrFPVectorTy(), "FPTrunc only operates on FP", &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPTrunc only operates on FP"
, &I); return; } } while (false)
;
2532 Assert(DestTy->isFPOrFPVectorTy(), "FPTrunc only produces an FP", &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("FPTrunc only produces an FP"
, &I); return; } } while (false)
;
2533 Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(),do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("fptrunc source and destination must both be a vector or neither"
, &I); return; } } while (false)
2534 "fptrunc source and destination must both be a vector or neither", &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("fptrunc source and destination must both be a vector or neither"
, &I); return; } } while (false)
;
2535 Assert(SrcBitSize > DestBitSize, "DestTy too big for FPTrunc", &I)do { if (!(SrcBitSize > DestBitSize)) { CheckFailed("DestTy too big for FPTrunc"
, &I); return; } } while (false)
;
2536
2537 visitInstruction(I);
2538}
2539
2540void Verifier::visitFPExtInst(FPExtInst &I) {
2541 // Get the source and destination types
2542 Type *SrcTy = I.getOperand(0)->getType();
2543 Type *DestTy = I.getType();
2544
2545 // Get the size of the types in bits, we'll need this later
2546 unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
2547 unsigned DestBitSize = DestTy->getScalarSizeInBits();
2548
2549 Assert(SrcTy->isFPOrFPVectorTy(), "FPExt only operates on FP", &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPExt only operates on FP"
, &I); return; } } while (false)
;
2550 Assert(DestTy->isFPOrFPVectorTy(), "FPExt only produces an FP", &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("FPExt only produces an FP"
, &I); return; } } while (false)
;
2551 Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(),do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("fpext source and destination must both be a vector or neither"
, &I); return; } } while (false)
2552 "fpext source and destination must both be a vector or neither", &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("fpext source and destination must both be a vector or neither"
, &I); return; } } while (false)
;
2553 Assert(SrcBitSize < DestBitSize, "DestTy too small for FPExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("DestTy too small for FPExt"
, &I); return; } } while (false)
;
2554
2555 visitInstruction(I);
2556}
2557
2558void Verifier::visitUIToFPInst(UIToFPInst &I) {
2559 // Get the source and destination types
2560 Type *SrcTy = I.getOperand(0)->getType();
2561 Type *DestTy = I.getType();
2562
2563 bool SrcVec = SrcTy->isVectorTy();
2564 bool DstVec = DestTy->isVectorTy();
2565
2566 Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("UIToFP source and dest must both be vector or scalar"
, &I); return; } } while (false)
2567 "UIToFP source and dest must both be vector or scalar", &I)do { if (!(SrcVec == DstVec)) { CheckFailed("UIToFP source and dest must both be vector or scalar"
, &I); return; } } while (false)
;
2568 Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("UIToFP source must be integer or integer vector"
, &I); return; } } while (false)
2569 "UIToFP source must be integer or integer vector", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("UIToFP source must be integer or integer vector"
, &I); return; } } while (false)
;
2570 Assert(DestTy->isFPOrFPVectorTy(), "UIToFP result must be FP or FP vector",do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("UIToFP result must be FP or FP vector"
, &I); return; } } while (false)
2571 &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("UIToFP result must be FP or FP vector"
, &I); return; } } while (false)
;
2572
2573 if (SrcVec && DstVec)
2574 Assert(cast<VectorType>(SrcTy)->getNumElements() ==do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("UIToFP source and dest vector length mismatch", &I); return
; } } while (false)
2575 cast<VectorType>(DestTy)->getNumElements(),do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("UIToFP source and dest vector length mismatch", &I); return
; } } while (false)
2576 "UIToFP source and dest vector length mismatch", &I)do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("UIToFP source and dest vector length mismatch", &I); return
; } } while (false)
;
2577
2578 visitInstruction(I);
2579}
2580
2581void Verifier::visitSIToFPInst(SIToFPInst &I) {
2582 // Get the source and destination types
2583 Type *SrcTy = I.getOperand(0)->getType();
2584 Type *DestTy = I.getType();
2585
2586 bool SrcVec = SrcTy->isVectorTy();
2587 bool DstVec = DestTy->isVectorTy();
2588
2589 Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("SIToFP source and dest must both be vector or scalar"
, &I); return; } } while (false)
2590 "SIToFP source and dest must both be vector or scalar", &I)do { if (!(SrcVec == DstVec)) { CheckFailed("SIToFP source and dest must both be vector or scalar"
, &I); return; } } while (false)
;
2591 Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("SIToFP source must be integer or integer vector"
, &I); return; } } while (false)
2592 "SIToFP source must be integer or integer vector", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("SIToFP source must be integer or integer vector"
, &I); return; } } while (false)
;
2593 Assert(DestTy->isFPOrFPVectorTy(), "SIToFP result must be FP or FP vector",do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("SIToFP result must be FP or FP vector"
, &I); return; } } while (false)
2594 &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("SIToFP result must be FP or FP vector"
, &I); return; } } while (false)
;
2595
2596 if (SrcVec && DstVec)
2597 Assert(cast<VectorType>(SrcTy)->getNumElements() ==do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("SIToFP source and dest vector length mismatch", &I); return
; } } while (false)
2598 cast<VectorType>(DestTy)->getNumElements(),do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("SIToFP source and dest vector length mismatch", &I); return
; } } while (false)
2599 "SIToFP source and dest vector length mismatch", &I)do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("SIToFP source and dest vector length mismatch", &I); return
; } } while (false)
;
2600
2601 visitInstruction(I);
2602}
2603
2604void Verifier::visitFPToUIInst(FPToUIInst &I) {
2605 // Get the source and destination types
2606 Type *SrcTy = I.getOperand(0)->getType();
2607 Type *DestTy = I.getType();
2608
2609 bool SrcVec = SrcTy->isVectorTy();
2610 bool DstVec = DestTy->isVectorTy();
2611
2612 Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("FPToUI source and dest must both be vector or scalar"
, &I); return; } } while (false)
2613 "FPToUI source and dest must both be vector or scalar", &I)do { if (!(SrcVec == DstVec)) { CheckFailed("FPToUI source and dest must both be vector or scalar"
, &I); return; } } while (false)
;
2614 Assert(SrcTy->isFPOrFPVectorTy(), "FPToUI source must be FP or FP vector",do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToUI source must be FP or FP vector"
, &I); return; } } while (false)
2615 &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToUI source must be FP or FP vector"
, &I); return; } } while (false)
;
2616 Assert(DestTy->isIntOrIntVectorTy(),do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToUI result must be integer or integer vector"
, &I); return; } } while (false)
2617 "FPToUI result must be integer or integer vector", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToUI result must be integer or integer vector"
, &I); return; } } while (false)
;
2618
2619 if (SrcVec && DstVec)
2620 Assert(cast<VectorType>(SrcTy)->getNumElements() ==do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("FPToUI source and dest vector length mismatch", &I); return
; } } while (false)
2621 cast<VectorType>(DestTy)->getNumElements(),do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("FPToUI source and dest vector length mismatch", &I); return
; } } while (false)
2622 "FPToUI source and dest vector length mismatch", &I)do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("FPToUI source and dest vector length mismatch", &I); return
; } } while (false)
;
2623
2624 visitInstruction(I);
2625}
2626
2627void Verifier::visitFPToSIInst(FPToSIInst &I) {
2628 // Get the source and destination types
2629 Type *SrcTy = I.getOperand(0)->getType();
2630 Type *DestTy = I.getType();
2631
2632 bool SrcVec = SrcTy->isVectorTy();
2633 bool DstVec = DestTy->isVectorTy();
2634
2635 Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("FPToSI source and dest must both be vector or scalar"
, &I); return; } } while (false)
2636 "FPToSI source and dest must both be vector or scalar", &I)do { if (!(SrcVec == DstVec)) { CheckFailed("FPToSI source and dest must both be vector or scalar"
, &I); return; } } while (false)
;
2637 Assert(SrcTy->isFPOrFPVectorTy(), "FPToSI source must be FP or FP vector",do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToSI source must be FP or FP vector"
, &I); return; } } while (false)
2638 &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToSI source must be FP or FP vector"
, &I); return; } } while (false)
;
2639 Assert(DestTy->isIntOrIntVectorTy(),do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToSI result must be integer or integer vector"
, &I); return; } } while (false)
2640 "FPToSI result must be integer or integer vector", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToSI result must be integer or integer vector"
, &I); return; } } while (false)
;
2641
2642 if (SrcVec && DstVec)
2643 Assert(cast<VectorType>(SrcTy)->getNumElements() ==do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("FPToSI source and dest vector length mismatch", &I); return
; } } while (false)
2644 cast<VectorType>(DestTy)->getNumElements(),do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("FPToSI source and dest vector length mismatch", &I); return
; } } while (false)
2645 "FPToSI source and dest vector length mismatch", &I)do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("FPToSI source and dest vector length mismatch", &I); return
; } } while (false)
;
2646
2647 visitInstruction(I);
2648}
2649
2650void Verifier::visitPtrToIntInst(PtrToIntInst &I) {
2651 // Get the source and destination types
2652 Type *SrcTy = I.getOperand(0)->getType();
2653 Type *DestTy = I.getType();
2654
2655 Assert(SrcTy->isPtrOrPtrVectorTy(), "PtrToInt source must be pointer", &I)do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("PtrToInt source must be pointer"
, &I); return; } } while (false)
;
2656
2657 if (auto *PTy = dyn_cast<PointerType>(SrcTy->getScalarType()))
2658 Assert(!DL.isNonIntegralPointerType(PTy),do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed(
"ptrtoint not supported for non-integral pointers"); return; }
} while (false)
2659 "ptrtoint not supported for non-integral pointers")do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed(
"ptrtoint not supported for non-integral pointers"); return; }
} while (false)
;
2660
2661 Assert(DestTy->isIntOrIntVectorTy(), "PtrToInt result must be integral", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("PtrToInt result must be integral"
, &I); return; } } while (false)
;
2662 Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(), "PtrToInt type mismatch",do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("PtrToInt type mismatch", &I); return; } }
while (false)
2663 &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("PtrToInt type mismatch", &I); return; } }
while (false)
;
2664
2665 if (SrcTy->isVectorTy()) {
2666 VectorType *VSrc = dyn_cast<VectorType>(SrcTy);
2667 VectorType *VDest = dyn_cast<VectorType>(DestTy);
2668 Assert(VSrc->getNumElements() == VDest->getNumElements(),do { if (!(VSrc->getNumElements() == VDest->getNumElements
())) { CheckFailed("PtrToInt Vector width mismatch", &I);
return; } } while (false)
2669 "PtrToInt Vector width mismatch", &I)do { if (!(VSrc->getNumElements() == VDest->getNumElements
())) { CheckFailed("PtrToInt Vector width mismatch", &I);
return; } } while (false)
;
2670 }
2671
2672 visitInstruction(I);
2673}
2674
2675void Verifier::visitIntToPtrInst(IntToPtrInst &I) {
2676 // Get the source and destination types
2677 Type *SrcTy = I.getOperand(0)->getType();
2678 Type *DestTy = I.getType();
2679
2680 Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("IntToPtr source must be an integral"
, &I); return; } } while (false)
2681 "IntToPtr source must be an integral", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("IntToPtr source must be an integral"
, &I); return; } } while (false)
;
2682 Assert(DestTy->isPtrOrPtrVectorTy(), "IntToPtr result must be a pointer", &I)do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("IntToPtr result must be a pointer"
, &I); return; } } while (false)
;
2683
2684 if (auto *PTy = dyn_cast<PointerType>(DestTy->getScalarType()))
2685 Assert(!DL.isNonIntegralPointerType(PTy),do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed(
"inttoptr not supported for non-integral pointers"); return; }
} while (false)
2686 "inttoptr not supported for non-integral pointers")do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed(
"inttoptr not supported for non-integral pointers"); return; }
} while (false)
;
2687
2688 Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(), "IntToPtr type mismatch",do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("IntToPtr type mismatch", &I); return; } }
while (false)
2689 &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("IntToPtr type mismatch", &I); return; } }
while (false)
;
2690 if (SrcTy->isVectorTy()) {
2691 VectorType *VSrc = dyn_cast<VectorType>(SrcTy);
2692 VectorType *VDest = dyn_cast<VectorType>(DestTy);
2693 Assert(VSrc->getNumElements() == VDest->getNumElements(),do { if (!(VSrc->getNumElements() == VDest->getNumElements
())) { CheckFailed("IntToPtr Vector width mismatch", &I);
return; } } while (false)
2694 "IntToPtr Vector width mismatch", &I)do { if (!(VSrc->getNumElements() == VDest->getNumElements
())) { CheckFailed("IntToPtr Vector width mismatch", &I);
return; } } while (false)
;
2695 }
2696 visitInstruction(I);
2697}
2698
2699void Verifier::visitBitCastInst(BitCastInst &I) {
2700 Assert(do { if (!(CastInst::castIsValid(Instruction::BitCast, I.getOperand
(0), I.getType()))) { CheckFailed("Invalid bitcast", &I);
return; } } while (false)
2701 CastInst::castIsValid(Instruction::BitCast, I.getOperand(0), I.getType()),do { if (!(CastInst::castIsValid(Instruction::BitCast, I.getOperand
(0), I.getType()))) { CheckFailed("Invalid bitcast", &I);
return; } } while (false)
2702 "Invalid bitcast", &I)do { if (!(CastInst::castIsValid(Instruction::BitCast, I.getOperand
(0), I.getType()))) { CheckFailed("Invalid bitcast", &I);
return; } } while (false)
;
2703 visitInstruction(I);
2704}
2705
2706void Verifier::visitAddrSpaceCastInst(AddrSpaceCastInst &I) {
2707 Type *SrcTy = I.getOperand(0)->getType();
2708 Type *DestTy = I.getType();
2709
2710 Assert(SrcTy->isPtrOrPtrVectorTy(), "AddrSpaceCast source must be a pointer",do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast source must be a pointer"
, &I); return; } } while (false)
2711 &I)do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast source must be a pointer"
, &I); return; } } while (false)
;
2712 Assert(DestTy->isPtrOrPtrVectorTy(), "AddrSpaceCast result must be a pointer",do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast result must be a pointer"
, &I); return; } } while (false)
2713 &I)do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast result must be a pointer"
, &I); return; } } while (false)
;
2714 Assert(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace(),do { if (!(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace
())) { CheckFailed("AddrSpaceCast must be between different address spaces"
, &I); return; } } while (false)
2715 "AddrSpaceCast must be between different address spaces", &I)do { if (!(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace
())) { CheckFailed("AddrSpaceCast must be between different address spaces"
, &I); return; } } while (false)
;
2716 if (SrcTy->isVectorTy())
2717 Assert(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements(),do { if (!(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements
())) { CheckFailed("AddrSpaceCast vector pointer number of elements mismatch"
, &I); return; } } while (false)
2718 "AddrSpaceCast vector pointer number of elements mismatch", &I)do { if (!(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements
())) { CheckFailed("AddrSpaceCast vector pointer number of elements mismatch"
, &I); return; } } while (false)
;
2719 visitInstruction(I);
2720}
2721
2722/// visitPHINode - Ensure that a PHI node is well formed.
2723///
2724void Verifier::visitPHINode(PHINode &PN) {
2725 // Ensure that the PHI nodes are all grouped together at the top of the block.
2726 // This can be tested by checking whether the instruction before this is
2727 // either nonexistent (because this is begin()) or is a PHI node. If not,
2728 // then there is some other instruction before a PHI.
2729 Assert(&PN == &PN.getParent()->front() ||do { if (!(&PN == &PN.getParent()->front() || isa<
PHINode>(--BasicBlock::iterator(&PN)))) { CheckFailed(
"PHI nodes not grouped at top of basic block!", &PN, PN.getParent
()); return; } } while (false)
2730 isa<PHINode>(--BasicBlock::iterator(&PN)),do { if (!(&PN == &PN.getParent()->front() || isa<
PHINode>(--BasicBlock::iterator(&PN)))) { CheckFailed(
"PHI nodes not grouped at top of basic block!", &PN, PN.getParent
()); return; } } while (false)
2731 "PHI nodes not grouped at top of basic block!", &PN, PN.getParent())do { if (!(&PN == &PN.getParent()->front() || isa<
PHINode>(--BasicBlock::iterator(&PN)))) { CheckFailed(
"PHI nodes not grouped at top of basic block!", &PN, PN.getParent
()); return; } } while (false)
;
2732
2733 // Check that a PHI doesn't yield a Token.
2734 Assert(!PN.getType()->isTokenTy(), "PHI nodes cannot have token type!")do { if (!(!PN.getType()->isTokenTy())) { CheckFailed("PHI nodes cannot have token type!"
); return; } } while (false)
;
2735
2736 // Check that all of the values of the PHI node have the same type as the
2737 // result, and that the incoming blocks are really basic blocks.
2738 for (Value *IncValue : PN.incoming_values()) {
2739 Assert(PN.getType() == IncValue->getType(),do { if (!(PN.getType() == IncValue->getType())) { CheckFailed
("PHI node operands are not the same type as the result!", &
PN); return; } } while (false)
2740 "PHI node operands are not the same type as the result!", &PN)do { if (!(PN.getType() == IncValue->getType())) { CheckFailed
("PHI node operands are not the same type as the result!", &
PN); return; } } while (false)
;
2741 }
2742
2743 // All other PHI node constraints are checked in the visitBasicBlock method.
2744
2745 visitInstruction(PN);
2746}
2747
2748void Verifier::verifyCallSite(CallSite CS) {
2749 Instruction *I = CS.getInstruction();
2750
2751 Assert(CS.getCalledValue()->getType()->isPointerTy(),do { if (!(CS.getCalledValue()->getType()->isPointerTy(
))) { CheckFailed("Called function must be a pointer!", I); return
; } } while (false)
2752 "Called function must be a pointer!", I)do { if (!(CS.getCalledValue()->getType()->isPointerTy(
))) { CheckFailed("Called function must be a pointer!", I); return
; } } while (false)
;
2753 PointerType *FPTy = cast<PointerType>(CS.getCalledValue()->getType());
2754
2755 Assert(FPTy->getElementType()->isFunctionTy(),do { if (!(FPTy->getElementType()->isFunctionTy())) { CheckFailed
("Called function is not pointer to function type!", I); return
; } } while (false)
2756 "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 (false)
;
2757
2758 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 (false)
2759 "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 (false)
;
2760
2761 FunctionType *FTy = CS.getFunctionType();
2762
2763 // Verify that the correct number of arguments are being passed
2764 if (FTy->isVarArg())
2765 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 (false)
2766 "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 (false)
;
2767 else
2768 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 (false)
2769 "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 (false)
;
2770
2771 // Verify that all arguments to the call match the function type.
2772 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
2773 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 (false)
2774 "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 (false)
2775 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 (false)
;
2776
2777 AttributeList Attrs = CS.getAttributes();
2778
2779 Assert(verifyAttributeCount(Attrs, CS.arg_size()),do { if (!(verifyAttributeCount(Attrs, CS.arg_size()))) { CheckFailed
("Attribute after last parameter!", I); return; } } while (false
)
2780 "Attribute after last parameter!", I)do { if (!(verifyAttributeCount(Attrs, CS.arg_size()))) { CheckFailed
("Attribute after last parameter!", I); return; } } while (false
)
;
2781
2782 if (Attrs.hasAttribute(AttributeList::FunctionIndex, Attribute::Speculatable)) {
2783 // Don't allow speculatable on call sites, unless the underlying function
2784 // declaration is also speculatable.
2785 Function *Callee
2786 = dyn_cast<Function>(CS.getCalledValue()->stripPointerCasts());
2787 Assert(Callee && Callee->isSpeculatable(),do { if (!(Callee && Callee->isSpeculatable())) { CheckFailed
("speculatable attribute may not apply to call sites", I); return
; } } while (false)
2788 "speculatable attribute may not apply to call sites", I)do { if (!(Callee && Callee->isSpeculatable())) { CheckFailed
("speculatable attribute may not apply to call sites", I); return
; } } while (false)
;
2789 }
2790
2791 // Verify call attributes.
2792 verifyFunctionAttrs(FTy, Attrs, I);
2793
2794 // Conservatively check the inalloca argument.
2795 // We have a bug if we can find that there is an underlying alloca without
2796 // inalloca.
2797 if (CS.hasInAllocaArgument()) {
2798 Value *InAllocaArg = CS.getArgument(FTy->getNumParams() - 1);
2799 if (auto AI = dyn_cast<AllocaInst>(InAllocaArg->stripInBoundsOffsets()))
2800 Assert(AI->isUsedWithInAlloca(),do { if (!(AI->isUsedWithInAlloca())) { CheckFailed("inalloca argument for call has mismatched alloca"
, AI, I); return; } } while (false)
2801 "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 (false)
;
2802 }
2803
2804 // For each argument of the callsite, if it has the swifterror argument,
2805 // make sure the underlying alloca/parameter it comes from has a swifterror as
2806 // well.
2807 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
2808 if (CS.paramHasAttr(i, Attribute::SwiftError)) {
2809 Value *SwiftErrorArg = CS.getArgument(i);
2810 if (auto AI = dyn_cast<AllocaInst>(SwiftErrorArg->stripInBoundsOffsets())) {
2811 Assert(AI->isSwiftError(),do { if (!(AI->isSwiftError())) { CheckFailed("swifterror argument for call has mismatched alloca"
, AI, I); return; } } while (false)
2812 "swifterror argument for call has mismatched alloca", AI, I)do { if (!(AI->isSwiftError())) { CheckFailed("swifterror argument for call has mismatched alloca"
, AI, I); return; } } while (false)
;
2813 continue;
2814 }
2815 auto ArgI = dyn_cast<Argument>(SwiftErrorArg);
2816 Assert(ArgI, "swifterror argument should come from an alloca or parameter", SwiftErrorArg, I)do { if (!(ArgI)) { CheckFailed("swifterror argument should come from an alloca or parameter"
, SwiftErrorArg, I); return; } } while (false)
;
2817 Assert(ArgI->hasSwiftErrorAttr(),do { if (!(ArgI->hasSwiftErrorAttr())) { CheckFailed("swifterror argument for call has mismatched parameter"
, ArgI, I); return; } } while (false)
2818 "swifterror argument for call has mismatched parameter", ArgI, I)do { if (!(ArgI->hasSwiftErrorAttr())) { CheckFailed("swifterror argument for call has mismatched parameter"
, ArgI, I); return; } } while (false)
;
2819 }
2820
2821 if (FTy->isVarArg()) {
2822 // FIXME? is 'nest' even legal here?
2823 bool SawNest = false;
2824 bool SawReturned = false;
2825
2826 for (unsigned Idx = 0; Idx < FTy->getNumParams(); ++Idx) {
2827 if (Attrs.hasParamAttribute(Idx, Attribute::Nest))
2828 SawNest = true;
2829 if (Attrs.hasParamAttribute(Idx, Attribute::Returned))
2830 SawReturned = true;
2831 }
2832
2833 // Check attributes on the varargs part.
2834 for (unsigned Idx = FTy->getNumParams(); Idx < CS.arg_size(); ++Idx) {
2835 Type *Ty = CS.getArgument(Idx)->getType();
2836 AttributeSet ArgAttrs = Attrs.getParamAttributes(Idx);
2837 verifyParameterAttrs(ArgAttrs, Ty, I);
2838
2839 if (ArgAttrs.hasAttribute(Attribute::Nest)) {
2840 Assert(!SawNest, "More than one parameter has attribute nest!", I)do { if (!(!SawNest)) { CheckFailed("More than one parameter has attribute nest!"
, I); return; } } while (false)
;
2841 SawNest = true;
2842 }
2843
2844 if (ArgAttrs.hasAttribute(Attribute::Returned)) {
2845 Assert(!SawReturned, "More than one parameter has attribute returned!",do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!"
, I); return; } } while (false)
2846 I)do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!"
, I); return; } } while (false)
;
2847 Assert(Ty->canLosslesslyBitCastTo(FTy->getReturnType()),do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType
()))) { CheckFailed("Incompatible argument and return types for 'returned' "
"attribute", I); return; } } while (false)
2848 "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 (false)
2849 "attribute",do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType
()))) { CheckFailed("Incompatible argument and return types for 'returned' "
"attribute", I); return; } } while (false)
2850 I)do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType
()))) { CheckFailed("Incompatible argument and return types for 'returned' "
"attribute", I); return; } } while (false)
;
2851 SawReturned = true;
2852 }
2853
2854 // Statepoint intrinsic is vararg but the wrapped function may be not.
2855 // Allow sret here and check the wrapped function in verifyStatepoint.
2856 if (CS.getCalledFunction() == nullptr ||
2857 CS.getCalledFunction()->getIntrinsicID() !=
2858 Intrinsic::experimental_gc_statepoint)
2859 Assert(!ArgAttrs.hasAttribute(Attribute::StructRet),do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed
("Attribute 'sret' cannot be used for vararg call arguments!"
, I); return; } } while (false)
2860 "Attribute 'sret' cannot be used for vararg call arguments!", I)do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed
("Attribute 'sret' cannot be used for vararg call arguments!"
, I); return; } } while (false)
;
2861
2862 if (ArgAttrs.hasAttribute(Attribute::InAlloca))
2863 Assert(Idx == CS.arg_size() - 1, "inalloca isn't on the last argument!",do { if (!(Idx == CS.arg_size() - 1)) { CheckFailed("inalloca isn't on the last argument!"
, I); return; } } while (false)
2864 I)do { if (!(Idx == CS.arg_size() - 1)) { CheckFailed("inalloca isn't on the last argument!"
, I); return; } } while (false)
;
2865 }
2866 }
2867
2868 // Verify that there's no metadata unless it's a direct call to an intrinsic.
2869 if (CS.getCalledFunction() == nullptr ||
2870 !CS.getCalledFunction()->getName().startswith("llvm.")) {
2871 for (Type *ParamTy : FTy->params()) {
2872 Assert(!ParamTy->isMetadataTy(),do { if (!(!ParamTy->isMetadataTy())) { CheckFailed("Function has metadata parameter but isn't an intrinsic"
, I); return; } } while (false)
2873 "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 (false)
;
2874 Assert(!ParamTy->isTokenTy(),do { if (!(!ParamTy->isTokenTy())) { CheckFailed("Function has token parameter but isn't an intrinsic"
, I); return; } } while (false)
2875 "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 (false)
;
2876 }
2877 }
2878
2879 // Verify that indirect calls don't return tokens.
2880 if (CS.getCalledFunction() == nullptr)
2881 Assert(!FTy->getReturnType()->isTokenTy(),do { if (!(!FTy->getReturnType()->isTokenTy())) { CheckFailed
("Return type cannot be token for indirect call!"); return; }
} while (false)
2882 "Return type cannot be token for indirect call!")do { if (!(!FTy->getReturnType()->isTokenTy())) { CheckFailed
("Return type cannot be token for indirect call!"); return; }
} while (false)
;
2883
2884 if (Function *F = CS.getCalledFunction())
2885 if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID())
2886 visitIntrinsicCallSite(ID, CS);
2887
2888 // Verify that a callsite has at most one "deopt", at most one "funclet" and
2889 // at most one "gc-transition" operand bundle.
2890 bool FoundDeoptBundle = false, FoundFuncletBundle = false,
2891 FoundGCTransitionBundle = false;
2892 for (unsigned i = 0, e = CS.getNumOperandBundles(); i < e; ++i) {
2893 OperandBundleUse BU = CS.getOperandBundleAt(i);
2894 uint32_t Tag = BU.getTagID();
2895 if (Tag == LLVMContext::OB_deopt) {
2896 Assert(!FoundDeoptBundle, "Multiple deopt operand bundles", I)do { if (!(!FoundDeoptBundle)) { CheckFailed("Multiple deopt operand bundles"
, I); return; } } while (false)
;
2897 FoundDeoptBundle = true;
2898 } else if (Tag == LLVMContext::OB_gc_transition) {
2899 Assert(!FoundGCTransitionBundle, "Multiple gc-transition operand bundles",do { if (!(!FoundGCTransitionBundle)) { CheckFailed("Multiple gc-transition operand bundles"
, I); return; } } while (false)
2900 I)do { if (!(!FoundGCTransitionBundle)) { CheckFailed("Multiple gc-transition operand bundles"
, I); return; } } while (false)
;
2901 FoundGCTransitionBundle = true;
2902 } else if (Tag == LLVMContext::OB_funclet) {
2903 Assert(!FoundFuncletBundle, "Multiple funclet operand bundles", I)do { if (!(!FoundFuncletBundle)) { CheckFailed("Multiple funclet operand bundles"
, I); return; } } while (false)
;
2904 FoundFuncletBundle = true;
2905 Assert(BU.Inputs.size() == 1,do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one funclet bundle operand"
, I); return; } } while (false)
2906 "Expected exactly one funclet bundle operand", I)do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one funclet bundle operand"
, I); return; } } while (false)
;
2907 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 (false)
2908 "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 (false)
2909 I)do { if (!(isa<FuncletPadInst>(BU.Inputs.front()))) { CheckFailed
("Funclet bundle operands should correspond to a FuncletPadInst"
, I); return; } } while (false)
;
2910 }
2911 }
2912
2913 // Verify that each inlinable callsite of a debug-info-bearing function in a
2914 // debug-info-bearing function has a debug location attached to it. Failure to
2915 // do so causes assertion failures when the inliner sets up inline scope info.
2916 if (I->getFunction()->getSubprogram() && CS.getCalledFunction() &&
2917 CS.getCalledFunction()->getSubprogram())
2918 AssertDI(I->getDebugLoc(), "inlinable function call in a function with "do { if (!(I->getDebugLoc())) { DebugInfoCheckFailed("inlinable function call in a function with "
"debug info must have a !dbg location", I); return; } } while
(false)
2919 "debug info must have a !dbg location",do { if (!(I->getDebugLoc())) { DebugInfoCheckFailed("inlinable function call in a function with "
"debug info must have a !dbg location", I); return; } } while
(false)
2920 I)do { if (!(I->getDebugLoc())) { DebugInfoCheckFailed("inlinable function call in a function with "
"debug info must have a !dbg location", I); return; } } while
(false)
;
2921
2922 visitInstruction(*I);
2923}
2924
2925/// Two types are "congruent" if they are identical, or if they are both pointer
2926/// types with different pointee types and the same address space.
2927static bool isTypeCongruent(Type *L, Type *R) {
2928 if (L == R)
2929 return true;
2930 PointerType *PL = dyn_cast<PointerType>(L);
2931 PointerType *PR = dyn_cast<PointerType>(R);
2932 if (!PL || !PR)
2933 return false;
2934 return PL->getAddressSpace() == PR->getAddressSpace();
2935}
2936
2937static AttrBuilder getParameterABIAttributes(int I, AttributeList Attrs) {
2938 static const Attribute::AttrKind ABIAttrs[] = {
2939 Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca,
2940 Attribute::InReg, Attribute::Returned, Attribute::SwiftSelf,
2941 Attribute::SwiftError};
2942 AttrBuilder Copy;
2943 for (auto AK : ABIAttrs) {
2944 if (Attrs.hasParamAttribute(I, AK))
2945 Copy.addAttribute(AK);
2946 }
2947 if (Attrs.hasParamAttribute(I, Attribute::Alignment))
2948 Copy.addAlignmentAttr(Attrs.getParamAlignment(I));
2949 return Copy;
2950}
2951
2952void Verifier::verifyMustTailCall(CallInst &CI) {
2953 Assert(!CI.isInlineAsm(), "cannot use musttail call with inline asm", &CI)do { if (!(!CI.isInlineAsm())) { CheckFailed("cannot use musttail call with inline asm"
, &CI); return; } } while (false)
;
2954
2955 // - The caller and callee prototypes must match. Pointer types of
2956 // parameters or return types may differ in pointee type, but not
2957 // address space.
2958 Function *F = CI.getParent()->getParent();
2959 FunctionType *CallerTy = F->getFunctionType();
2960 FunctionType *CalleeTy = CI.getFunctionType();
2961 if (!CI.getCalledFunction() || !CI.getCalledFunction()->isIntrinsic()) {
2962 Assert(CallerTy->getNumParams() == CalleeTy->getNumParams(),do { if (!(CallerTy->getNumParams() == CalleeTy->getNumParams
())) { CheckFailed("cannot guarantee tail call due to mismatched parameter counts"
, &CI); return; } } while (false)
2963 "cannot guarantee tail call due to mismatched parameter counts",do { if (!(CallerTy->getNumParams() == CalleeTy->getNumParams
())) { CheckFailed("cannot guarantee tail call due to mismatched parameter counts"
, &CI); return; } } while (false)
2964 &CI)do { if (!(CallerTy->getNumParams() == CalleeTy->getNumParams
())) { CheckFailed("cannot guarantee tail call due to mismatched parameter counts"
, &CI); return; } } while (false)
;
2965 for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) {
2966 Assert(do { if (!(isTypeCongruent(CallerTy->getParamType(I), CalleeTy
->getParamType(I)))) { CheckFailed("cannot guarantee tail call due to mismatched parameter types"
, &CI); return; } } while (false)
2967 isTypeCongruent(CallerTy->getParamType(I), CalleeTy->getParamType(I)),do { if (!(isTypeCongruent(CallerTy->getParamType(I), CalleeTy
->getParamType(I)))) { CheckFailed("cannot guarantee tail call due to mismatched parameter types"
, &CI); return; } } while (false)
2968 "cannot guarantee tail call due to mismatched parameter types", &CI)do { if (!(isTypeCongruent(CallerTy->getParamType(I), CalleeTy
->getParamType(I)))) { CheckFailed("cannot guarantee tail call due to mismatched parameter types"
, &CI); return; } } while (false)
;
2969 }
2970 }
2971 Assert(CallerTy->isVarArg() == CalleeTy->isVarArg(),do { if (!(CallerTy->isVarArg() == CalleeTy->isVarArg()
)) { CheckFailed("cannot guarantee tail call due to mismatched varargs"
, &CI); return; } } while (false)
2972 "cannot guarantee tail call due to mismatched varargs", &CI)do { if (!(CallerTy->isVarArg() == CalleeTy->isVarArg()
)) { CheckFailed("cannot guarantee tail call due to mismatched varargs"
, &CI); return; } } while (false)
;
2973 Assert(isTypeCongruent(CallerTy->getReturnType(), CalleeTy->getReturnType()),do { if (!(isTypeCongruent(CallerTy->getReturnType(), CalleeTy
->getReturnType()))) { CheckFailed("cannot guarantee tail call due to mismatched return types"
, &CI); return; } } while (false)
2974 "cannot guarantee tail call due to mismatched return types", &CI)do { if (!(isTypeCongruent(CallerTy->getReturnType(), CalleeTy
->getReturnType()))) { CheckFailed("cannot guarantee tail call due to mismatched return types"
, &CI); return; } } while (false)
;
2975
2976 // - The calling conventions of the caller and callee must match.
2977 Assert(F->getCallingConv() == CI.getCallingConv(),do { if (!(F->getCallingConv() == CI.getCallingConv())) { CheckFailed
("cannot guarantee tail call due to mismatched calling conv",
&CI); return; } } while (false)
2978 "cannot guarantee tail call due to mismatched calling conv", &CI)do { if (!(F->getCallingConv() == CI.getCallingConv())) { CheckFailed
("cannot guarantee tail call due to mismatched calling conv",
&CI); return; } } while (false)
;
2979
2980 // - All ABI-impacting function attributes, such as sret, byval, inreg,
2981 // returned, and inalloca, must match.
2982 AttributeList CallerAttrs = F->getAttributes();
2983 AttributeList CalleeAttrs = CI.getAttributes();
2984 for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) {
2985 AttrBuilder CallerABIAttrs = getParameterABIAttributes(I, CallerAttrs);
2986 AttrBuilder CalleeABIAttrs = getParameterABIAttributes(I, CalleeAttrs);
2987 Assert(CallerABIAttrs == CalleeABIAttrs,do { if (!(CallerABIAttrs == CalleeABIAttrs)) { CheckFailed("cannot guarantee tail call due to mismatched ABI impacting "
"function attributes", &CI, CI.getOperand(I)); return; }
} while (false)
2988 "cannot guarantee tail call due to mismatched ABI impacting "do { if (!(CallerABIAttrs == CalleeABIAttrs)) { CheckFailed("cannot guarantee tail call due to mismatched ABI impacting "
"function attributes", &CI, CI.getOperand(I)); return; }
} while (false)
2989 "function attributes",do { if (!(CallerABIAttrs == CalleeABIAttrs)) { CheckFailed("cannot guarantee tail call due to mismatched ABI impacting "
"function attributes", &CI, CI.getOperand(I)); return; }
} while (false)
2990 &CI, CI.getOperand(I))do { if (!(CallerABIAttrs == CalleeABIAttrs)) { CheckFailed("cannot guarantee tail call due to mismatched ABI impacting "
"function attributes", &CI, CI.getOperand(I)); return; }
} while (false)
;
2991 }
2992
2993 // - The call must immediately precede a :ref:`ret <i_ret>` instruction,
2994 // or a pointer bitcast followed by a ret instruction.
2995 // - The ret instruction must return the (possibly bitcasted) value
2996 // produced by the call or void.
2997 Value *RetVal = &CI;
2998 Instruction *Next = CI.getNextNode();
2999
3000 // Handle the optional bitcast.
3001 if (BitCastInst *BI = dyn_cast_or_null<BitCastInst>(Next)) {
3002 Assert(BI->getOperand(0) == RetVal,do { if (!(BI->getOperand(0) == RetVal)) { CheckFailed("bitcast following musttail call must use the call"
, BI); return; } } while (false)
3003 "bitcast following musttail call must use the call", BI)do { if (!(BI->getOperand(0) == RetVal)) { CheckFailed("bitcast following musttail call must use the call"
, BI); return; } } while (false)
;
3004 RetVal = BI;
3005 Next = BI->getNextNode();
3006 }
3007
3008 // Check the return.
3009 ReturnInst *Ret = dyn_cast_or_null<ReturnInst>(Next);
3010 Assert(Ret, "musttail call must precede a ret with an optional bitcast",do { if (!(Ret)) { CheckFailed("musttail call must precede a ret with an optional bitcast"
, &CI); return; } } while (false)
3011 &CI)do { if (!(Ret)) { CheckFailed("musttail call must precede a ret with an optional bitcast"
, &CI); return; } } while (false)
;
3012 Assert(!Ret->getReturnValue() || Ret->getReturnValue() == RetVal,do { if (!(!Ret->getReturnValue() || Ret->getReturnValue
() == RetVal)) { CheckFailed("musttail call result must be returned"
, Ret); return; } } while (false)
3013 "musttail call result must be returned", Ret)do { if (!(!Ret->getReturnValue() || Ret->getReturnValue
() == RetVal)) { CheckFailed("musttail call result must be returned"
, Ret); return; } } while (false)
;
3014}
3015
3016void Verifier::visitCallInst(CallInst &CI) {
3017 verifyCallSite(&CI);
3018
3019 if (CI.isMustTailCall())
3020 verifyMustTailCall(CI);
3021}
3022
3023void Verifier::visitInvokeInst(InvokeInst &II) {
3024 verifyCallSite(&II);
3025
3026 // Verify that the first non-PHI instruction of the unwind destination is an
3027 // exception handling instruction.
3028 Assert(do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!"
, &II); return; } } while (false)
3029 II.getUnwindDest()->isEHPad(),do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!"
, &II); return; } } while (false)
3030 "The unwind destination does not have an exception handling instruction!",do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!"
, &II); return; } } while (false)
3031 &II)do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!"
, &II); return; } } while (false)
;
3032
3033 visitTerminator(II);
3034}
3035
3036/// visitUnaryOperator - Check the argument to the unary operator.
3037///
3038void Verifier::visitUnaryOperator(UnaryOperator &U) {
3039 Assert(U.getType() == U.getOperand(0)->getType(),do { if (!(U.getType() == U.getOperand(0)->getType())) { CheckFailed
("Unary operators must have same type for" "operands and result!"
, &U); return; } } while (false)
3040 "Unary operators must have same type for"do { if (!(U.getType() == U.getOperand(0)->getType())) { CheckFailed
("Unary operators must have same type for" "operands and result!"
, &U); return; } } while (false)
3041 "operands and result!",do { if (!(U.getType() == U.getOperand(0)->getType())) { CheckFailed
("Unary operators must have same type for" "operands and result!"
, &U); return; } } while (false)
3042 &U)do { if (!(U.getType() == U.getOperand(0)->getType())) { CheckFailed
("Unary operators must have same type for" "operands and result!"
, &U); return; } } while (false)
;
3043
3044 switch (U.getOpcode()) {
3045 // Check that floating-point arithmetic operators are only used with
3046 // floating-point operands.
3047 case Instruction::FNeg:
3048 Assert(U.getType()->isFPOrFPVectorTy(),do { if (!(U.getType()->isFPOrFPVectorTy())) { CheckFailed
("FNeg operator only works with float types!", &U); return
; } } while (false)
3049 "FNeg operator only works with float types!", &U)do { if (!(U.getType()->isFPOrFPVectorTy())) { CheckFailed
("FNeg operator only works with float types!", &U); return
; } } while (false)
;
3050 break;
3051 default:
3052 llvm_unreachable("Unknown UnaryOperator opcode!")::llvm::llvm_unreachable_internal("Unknown UnaryOperator opcode!"
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp"
, 3052)
;
3053 }
3054
3055 visitInstruction(U);
3056}
3057
3058/// visitBinaryOperator - Check that both arguments to the binary operator are
3059/// of the same type!
3060///
3061void Verifier::visitBinaryOperator(BinaryOperator &B) {
3062 Assert(B.getOperand(0)->getType() == B.getOperand(1)->getType(),do { if (!(B.getOperand(0)->getType() == B.getOperand(1)->
getType())) { CheckFailed("Both operands to a binary operator are not of the same type!"
, &B); return; } } while (false)
3063 "Both operands to a binary operator are not of the same type!", &B)do { if (!(B.getOperand(0)->getType() == B.getOperand(1)->
getType())) { CheckFailed("Both operands to a binary operator are not of the same type!"
, &B); return; } } while (false)
;
3064
3065 switch (B.getOpcode()) {
3066 // Check that integer arithmetic operators are only used with
3067 // integral operands.
3068 case Instruction::Add:
3069 case Instruction::Sub:
3070 case Instruction::Mul:
3071 case Instruction::SDiv:
3072 case Instruction::UDiv:
3073 case Instruction::SRem:
3074 case Instruction::URem:
3075 Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed
("Integer arithmetic operators only work with integral types!"
, &B); return; } } while (false)
3076 "Integer arithmetic operators only work with integral types!", &B)do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed
("Integer arithmetic operators only work with integral types!"
, &B); return; } } while (false)
;
3077 Assert(B.getType() == B.getOperand(0)->getType(),do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed
("Integer arithmetic operators must have same type " "for operands and result!"
, &B); return; } } while (false)
3078 "Integer arithmetic operators must have same type "do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed
("Integer arithmetic operators must have same type " "for operands and result!"
, &B); return; } } while (false)
3079 "for operands and result!",do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed
("Integer arithmetic operators must have same type " "for operands and result!"
, &B); return; } } while (false)
3080 &B)do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed
("Integer arithmetic operators must have same type " "for operands and result!"
, &B); return; } } while (false)
;
3081 break;
3082 // Check that floating-point arithmetic operators are only used with
3083 // floating-point operands.
3084 case Instruction::FAdd:
3085 case Instruction::FSub:
3086 case Instruction::FMul:
3087 case Instruction::FDiv:
3088 case Instruction::FRem:
3089 Assert(B.getType()->isFPOrFPVectorTy(),do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed
("Floating-point arithmetic operators only work with " "floating-point types!"
, &B); return; } } while (false)
3090 "Floating-point arithmetic operators only work with "do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed
("Floating-point arithmetic operators only work with " "floating-point types!"
, &B); return; } } while (false)
3091 "floating-point types!",do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed
("Floating-point arithmetic operators only work with " "floating-point types!"
, &B); return; } } while (false)
3092 &B)do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed
("Floating-point arithmetic operators only work with " "floating-point types!"
, &B); return; } } while (false)
;
3093 Assert(B.getType() == B.getOperand(0)->getType(),do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed
("Floating-point arithmetic operators must have same type " "for operands and result!"
, &B); return; } } while (false)
3094 "Floating-point arithmetic operators must have same type "do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed
("Floating-point arithmetic operators must have same type " "for operands and result!"
, &B); return; } } while (false)
3095 "for operands and result!",do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed
("Floating-point arithmetic operators must have same type " "for operands and result!"
, &B); return; } } while (false)
3096 &B)do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed
("Floating-point arithmetic operators must have same type " "for operands and result!"
, &B); return; } } while (false)
;
3097 break;
3098 // Check that logical operators are only used with integral operands.
3099 case Instruction::And:
3100 case Instruction::Or:
3101 case Instruction::Xor:
3102 Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed
("Logical operators only work with integral types!", &B);
return; } } while (false)
3103 "Logical operators only work with integral types!", &B)do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed
("Logical operators only work with integral types!", &B);
return; } } while (false)
;
3104 Assert(B.getType() == B.getOperand(0)->getType(),do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed
("Logical operators must have same type for operands and result!"
, &B); return; } } while (false)
3105 "Logical operators must have same type for operands and result!",do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed
("Logical operators must have same type for operands and result!"
, &B); return; } } while (false)
3106 &B)do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed
("Logical operators must have same type for operands and result!"
, &B); return; } } while (false)
;
3107 break;
3108 case Instruction::Shl:
3109 case Instruction::LShr:
3110 case Instruction::AShr:
3111 Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed
("Shifts only work with integral types!", &B); return; } }
while (false)
3112 "Shifts only work with integral types!", &B)do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed
("Shifts only work with integral types!", &B); return; } }
while (false)
;
3113 Assert(B.getType() == B.getOperand(0)->getType(),do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed
("Shift return type must be same as operands!", &B); return
; } } while (false)
3114 "Shift return type must be same as operands!", &B)do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed
("Shift return type must be same as operands!", &B); return
; } } while (false)
;
3115 break;
3116 default:
3117 llvm_unreachable("Unknown BinaryOperator opcode!")::llvm::llvm_unreachable_internal("Unknown BinaryOperator opcode!"
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp"
, 3117)
;
3118 }
3119
3120 visitInstruction(B);
3121}
3122
3123void Verifier::visitICmpInst(ICmpInst &IC) {
3124 // Check that the operands are the same type
3125 Type *Op0Ty = IC.getOperand(0)->getType();
3126 Type *Op1Ty = IC.getOperand(1)->getType();
3127 Assert(Op0Ty == Op1Ty,do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to ICmp instruction are not of the same type!"
, &IC); return; } } while (false)
3128 "Both operands to ICmp instruction are not of the same type!", &IC)do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to ICmp instruction are not of the same type!"
, &IC); return; } } while (false)
;
3129 // Check that the operands are the right type
3130 Assert(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy(),do { if (!(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy
())) { CheckFailed("Invalid operand types for ICmp instruction"
, &IC); return; } } while (false)
3131 "Invalid operand types for ICmp instruction", &IC)do { if (!(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy
())) { CheckFailed("Invalid operand types for ICmp instruction"
, &IC); return; } } while (false)
;
3132 // Check that the predicate is valid.
3133 Assert(IC.isIntPredicate(),do { if (!(IC.isIntPredicate())) { CheckFailed("Invalid predicate in ICmp instruction!"
, &IC); return; } } while (false)
3134 "Invalid predicate in ICmp instruction!", &IC)do { if (!(IC.isIntPredicate())) { CheckFailed("Invalid predicate in ICmp instruction!"
, &IC); return; } } while (false)
;
3135
3136 visitInstruction(IC);
3137}
3138
3139void Verifier::visitFCmpInst(FCmpInst &FC) {
3140 // Check that the operands are the same type
3141 Type *Op0Ty = FC.getOperand(0)->getType();
3142 Type *Op1Ty = FC.getOperand(1)->getType();
3143 Assert(Op0Ty == Op1Ty,do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to FCmp instruction are not of the same type!"
, &FC); return; } } while (false)
3144 "Both operands to FCmp instruction are not of the same type!", &FC)do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to FCmp instruction are not of the same type!"
, &FC); return; } } while (false)
;
3145 // Check that the operands are the right type
3146 Assert(Op0Ty->isFPOrFPVectorTy(),do { if (!(Op0Ty->isFPOrFPVectorTy())) { CheckFailed("Invalid operand types for FCmp instruction"
, &FC); return; } } while (false)
3147 "Invalid operand types for FCmp instruction", &FC)do { if (!(Op0Ty->isFPOrFPVectorTy())) { CheckFailed("Invalid operand types for FCmp instruction"
, &FC); return; } } while (false)
;
3148 // Check that the predicate is valid.
3149 Assert(FC.isFPPredicate(),do { if (!(FC.isFPPredicate())) { CheckFailed("Invalid predicate in FCmp instruction!"
, &FC); return; } } while (false)
3150 "Invalid predicate in FCmp instruction!", &FC)do { if (!(FC.isFPPredicate())) { CheckFailed("Invalid predicate in FCmp instruction!"
, &FC); return; } } while (false)
;
3151
3152 visitInstruction(FC);
3153}
3154
3155void Verifier::visitExtractElementInst(ExtractElementInst &EI) {
3156 Assert(do { if (!(ExtractElementInst::isValidOperands(EI.getOperand(
0), EI.getOperand(1)))) { CheckFailed("Invalid extractelement operands!"
, &EI); return; } } while (false)
3157 ExtractElementInst::isValidOperands(EI.getOperand(0), EI.getOperand(1)),do { if (!(ExtractElementInst::isValidOperands(EI.getOperand(
0), EI.getOperand(1)))) { CheckFailed("Invalid extractelement operands!"
, &EI); return; } } while (false)
3158 "Invalid extractelement operands!", &EI)do { if (!(ExtractElementInst::isValidOperands(EI.getOperand(
0), EI.getOperand(1)))) { CheckFailed("Invalid extractelement operands!"
, &EI); return; } } while (false)
;
3159 visitInstruction(EI);
3160}
3161
3162void Verifier::visitInsertElementInst(InsertElementInst &IE) {
3163 Assert(InsertElementInst::isValidOperands(IE.getOperand(0), IE.getOperand(1),do { if (!(InsertElementInst::isValidOperands(IE.getOperand(0
), IE.getOperand(1), IE.getOperand(2)))) { CheckFailed("Invalid insertelement operands!"
, &IE); return; } } while (false)
3164 IE.getOperand(2)),do { if (!(InsertElementInst::isValidOperands(IE.getOperand(0
), IE.getOperand(1), IE.getOperand(2)))) { CheckFailed("Invalid insertelement operands!"
, &IE); return; } } while (false)
3165 "Invalid insertelement operands!", &IE)do { if (!(InsertElementInst::isValidOperands(IE.getOperand(0
), IE.getOperand(1), IE.getOperand(2)))) { CheckFailed("Invalid insertelement operands!"
, &IE); return; } } while (false)
;
3166 visitInstruction(IE);
3167}
3168
3169void Verifier::visitShuffleVectorInst(ShuffleVectorInst &SV) {
3170 Assert(ShuffleVectorInst::isValidOperands(SV.getOperand(0), SV.getOperand(1),do { if (!(ShuffleVectorInst::isValidOperands(SV.getOperand(0
), SV.getOperand(1), SV.getOperand(2)))) { CheckFailed("Invalid shufflevector operands!"
, &SV); return; } } while (false)
3171 SV.getOperand(2)),do { if (!(ShuffleVectorInst::isValidOperands(SV.getOperand(0
), SV.getOperand(1), SV.getOperand(2)))) { CheckFailed("Invalid shufflevector operands!"
, &SV); return; } } while (false)
3172 "Invalid shufflevector operands!", &SV)do { if (!(ShuffleVectorInst::isValidOperands(SV.getOperand(0
), SV.getOperand(1), SV.getOperand(2)))) { CheckFailed("Invalid shufflevector operands!"
, &SV); return; } } while (false)
;
3173 visitInstruction(SV);
3174}
3175
3176void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
3177 Type *TargetTy = GEP.getPointerOperandType()->getScalarType();
3178
3179 Assert(isa<PointerType>(TargetTy),do { if (!(isa<PointerType>(TargetTy))) { CheckFailed("GEP base pointer is not a vector or a vector of pointers"
, &GEP); return; } } while (false)
3180 "GEP base pointer is not a vector or a vector of pointers", &GEP)do { if (!(isa<PointerType>(TargetTy))) { CheckFailed("GEP base pointer is not a vector or a vector of pointers"
, &GEP); return; } } while (false)
;
3181 Assert(GEP.getSourceElementType()->isSized(), "GEP into unsized type!", &GEP)do { if (!(GEP.getSourceElementType()->isSized())) { CheckFailed
("GEP into unsized type!", &GEP); return; } } while (false
)
;
3182
3183 SmallVector<Value*, 16> Idxs(GEP.idx_begin(), GEP.idx_end());
3184 Assert(all_of(do { if (!(all_of( Idxs, [](Value* V) { return V->getType(
)->isIntOrIntVectorTy(); }))) { CheckFailed("GEP indexes must be integers"
, &GEP); return; } } while (false)
3185 Idxs, [](Value* V) { return V->getType()->isIntOrIntVectorTy(); }),do { if (!(all_of( Idxs, [](Value* V) { return V->getType(
)->isIntOrIntVectorTy(); }))) { CheckFailed("GEP indexes must be integers"
, &GEP); return; } } while (false)
3186 "GEP indexes must be integers", &GEP)do { if (!(all_of( Idxs, [](Value* V) { return V->getType(
)->isIntOrIntVectorTy(); }))) { CheckFailed("GEP indexes must be integers"
, &GEP); return; } } while (false)
;
3187 Type *ElTy =
3188 GetElementPtrInst::getIndexedType(GEP.getSourceElementType(), Idxs);
3189 Assert(ElTy, "Invalid indices for GEP pointer type!", &GEP)do { if (!(ElTy)) { CheckFailed("Invalid indices for GEP pointer type!"
, &GEP); return; } } while (false)
;
3190
3191 Assert(GEP.getType()->isPtrOrPtrVectorTy() &&do { if (!(GEP.getType()->isPtrOrPtrVectorTy() && GEP
.getResultElementType() == ElTy)) { CheckFailed("GEP is not of right type for indices!"
, &GEP, ElTy); return; } } while (false)
3192 GEP.getResultElementType() == ElTy,do { if (!(GEP.getType()->isPtrOrPtrVectorTy() && GEP
.getResultElementType() == ElTy)) { CheckFailed("GEP is not of right type for indices!"
, &GEP, ElTy); return; } } while (false)
3193 "GEP is not of right type for indices!", &GEP, ElTy)do { if (!(GEP.getType()->isPtrOrPtrVectorTy() && GEP
.getResultElementType() == ElTy)) { CheckFailed("GEP is not of right type for indices!"
, &GEP, ElTy); return; } } while (false)
;
3194
3195 if (GEP.getType()->isVectorTy()) {
3196 // Additional checks for vector GEPs.
3197 unsigned GEPWidth = GEP.getType()->getVectorNumElements();
3198 if (GEP.getPointerOperandType()->isVectorTy())
3199 Assert(GEPWidth == GEP.getPointerOperandType()->getVectorNumElements(),do { if (!(GEPWidth == GEP.getPointerOperandType()->getVectorNumElements
())) { CheckFailed("Vector GEP result width doesn't match operand's"
, &GEP); return; } } while (false)
3200 "Vector GEP result width doesn't match operand's", &GEP)do { if (!(GEPWidth == GEP.getPointerOperandType()->getVectorNumElements
())) { CheckFailed("Vector GEP result width doesn't match operand's"
, &GEP); return; } } while (false)
;
3201 for (Value *Idx : Idxs) {
3202 Type *IndexTy = Idx->getType();
3203 if (IndexTy->isVectorTy()) {
3204 unsigned IndexWidth = IndexTy->getVectorNumElements();
3205 Assert(IndexWidth == GEPWidth, "Invalid GEP index vector width", &GEP)do { if (!(IndexWidth == GEPWidth)) { CheckFailed("Invalid GEP index vector width"
, &GEP); return; } } while (false)
;
3206 }
3207 Assert(IndexTy->isIntOrIntVectorTy(),do { if (!(IndexTy->isIntOrIntVectorTy())) { CheckFailed("All GEP indices should be of integer type"
); return; } } while (false)
3208 "All GEP indices should be of integer type")do { if (!(IndexTy->isIntOrIntVectorTy())) { CheckFailed("All GEP indices should be of integer type"
); return; } } while (false)
;
3209 }
3210 }
3211
3212 if (auto *PTy = dyn_cast<PointerType>(GEP.getType())) {
3213 Assert(GEP.getAddressSpace() == PTy->getAddressSpace(),do { if (!(GEP.getAddressSpace() == PTy->getAddressSpace()
)) { CheckFailed("GEP address space doesn't match type", &
GEP); return; } } while (false)
3214 "GEP address space doesn't match type", &GEP)do { if (!(GEP.getAddressSpace() == PTy->getAddressSpace()
)) { CheckFailed("GEP address space doesn't match type", &
GEP); return; } } while (false)
;
3215 }
3216
3217 visitInstruction(GEP);
3218}
3219
3220static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {
3221 return A.getUpper() == B.getLower() || A.getLower() == B.getUpper();
3222}
3223
3224void Verifier::visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty) {
3225 assert(Range && Range == I.getMetadata(LLVMContext::MD_range) &&((Range && Range == I.getMetadata(LLVMContext::MD_range
) && "precondition violation") ? static_cast<void>
(0) : __assert_fail ("Range && Range == I.getMetadata(LLVMContext::MD_range) && \"precondition violation\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp"
, 3226, __PRETTY_FUNCTION__))
3226 "precondition violation")((Range && Range == I.getMetadata(LLVMContext::MD_range
) && "precondition violation") ? static_cast<void>
(0) : __assert_fail ("Range && Range == I.getMetadata(LLVMContext::MD_range) && \"precondition violation\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp"
, 3226, __PRETTY_FUNCTION__))
;
3227
3228 unsigned NumOperands = Range->getNumOperands();
3229 Assert(NumOperands % 2 == 0, "Unfinished range!", Range)do { if (!(NumOperands % 2 == 0)) { CheckFailed("Unfinished range!"
, Range); return; } } while (false)
;
3230 unsigned NumRanges = NumOperands / 2;
3231 Assert(NumRanges >= 1, "It should have at least one range!", Range)do { if (!(NumRanges >= 1)) { CheckFailed("It should have at least one range!"
, Range); return; } } while (false)
;
3232
3233 ConstantRange LastRange(1); // Dummy initial value
3234 for (unsigned i = 0; i < NumRanges; ++i) {
3235 ConstantInt *Low =
3236 mdconst::dyn_extract<ConstantInt>(Range->getOperand(2 * i));
3237 Assert(Low, "The lower limit must be an integer!", Low)do { if (!(Low)) { CheckFailed("The lower limit must be an integer!"
, Low); return; } } while (false)
;
3238 ConstantInt *High =
3239 mdconst::dyn_extract<ConstantInt>(Range->getOperand(2 * i + 1));
3240 Assert(High, "The upper limit must be an integer!", High)do { if (!(High)) { CheckFailed("The upper limit must be an integer!"
, High); return; } } while (false)
;
3241 Assert(High->getType() == Low->getType() && High->getType() == Ty,do { if (!(High->getType() == Low->getType() &&
High->getType() == Ty)) { CheckFailed("Range types must match instruction type!"
, &I); return; } } while (false)
3242 "Range types must match instruction type!", &I)do { if (!(High->getType() == Low->getType() &&
High->getType() == Ty)) { CheckFailed("Range types must match instruction type!"
, &I); return; } } while (false)
;
3243
3244 APInt HighV = High->getValue();
3245 APInt LowV = Low->getValue();
3246 ConstantRange CurRange(LowV, HighV);
3247 Assert(!CurRange.isEmptySet() && !CurRange.isFullSet(),do { if (!(!CurRange.isEmptySet() && !CurRange.isFullSet
())) { CheckFailed("Range must not be empty!", Range); return
; } } while (false)
3248 "Range must not be empty!", Range)do { if (!(!CurRange.isEmptySet() && !CurRange.isFullSet
())) { CheckFailed("Range must not be empty!", Range); return
; } } while (false)
;
3249 if (i != 0) {
3250 Assert(CurRange.intersectWith(LastRange).isEmptySet(),do { if (!(CurRange.intersectWith(LastRange).isEmptySet())) {
CheckFailed("Intervals are overlapping", Range); return; } }
while (false)
3251 "Intervals are overlapping", Range)do { if (!(CurRange.intersectWith(LastRange).isEmptySet())) {
CheckFailed("Intervals are overlapping", Range); return; } }
while (false)
;
3252 Assert(LowV.sgt(LastRange.getLower()), "Intervals are not in order",do { if (!(LowV.sgt(LastRange.getLower()))) { CheckFailed("Intervals are not in order"
, Range); return; } } while (false)
3253 Range)do { if (!(LowV.sgt(LastRange.getLower()))) { CheckFailed("Intervals are not in order"
, Range); return; } } while (false)
;
3254 Assert(!isContiguous(CurRange, LastRange), "Intervals are contiguous",do { if (!(!isContiguous(CurRange, LastRange))) { CheckFailed
("Intervals are contiguous", Range); return; } } while (false
)
3255 Range)do { if (!(!isContiguous(CurRange, LastRange))) { CheckFailed
("Intervals are contiguous", Range); return; } } while (false
)
;
3256 }
3257 LastRange = ConstantRange(LowV, HighV);
3258 }
3259 if (NumRanges > 2) {
3260 APInt FirstLow =
3261 mdconst::dyn_extract<ConstantInt>(Range->getOperand(0))->getValue();
3262 APInt FirstHigh =
3263 mdconst::dyn_extract<ConstantInt>(Range->getOperand(1))->getValue();
3264 ConstantRange FirstRange(FirstLow, FirstHigh);
3265 Assert(FirstRange.intersectWith(LastRange).isEmptySet(),do { if (!(FirstRange.intersectWith(LastRange).isEmptySet()))
{ CheckFailed("Intervals are overlapping", Range); return; }
} while (false)
3266 "Intervals are overlapping", Range)do { if (!(FirstRange.intersectWith(LastRange).isEmptySet()))
{ CheckFailed("Intervals are overlapping", Range); return; }
} while (false)
;
3267 Assert(!isContiguous(FirstRange, LastRange), "Intervals are contiguous",do { if (!(!isContiguous(FirstRange, LastRange))) { CheckFailed
("Intervals are contiguous", Range); return; } } while (false
)
3268 Range)do { if (!(!isContiguous(FirstRange, LastRange))) { CheckFailed
("Intervals are contiguous", Range); return; } } while (false
)
;
3269 }
3270}
3271
3272void Verifier::checkAtomicMemAccessSize(Type *Ty, const Instruction *I) {
3273 unsigned Size = DL.getTypeSizeInBits(Ty);
3274 Assert(Size >= 8, "atomic memory access' size must be byte-sized", Ty, I)do { if (!(Size >= 8)) { CheckFailed("atomic memory access' size must be byte-sized"
, Ty, I); return; } } while (false)
;
3275 Assert(!(Size & (Size - 1)),do { if (!(!(Size & (Size - 1)))) { CheckFailed("atomic memory access' operand must have a power-of-two size"
, Ty, I); return; } } while (false)
3276 "atomic memory access' operand must have a power-of-two size", Ty, I)do { if (!(!(Size & (Size - 1)))) { CheckFailed("atomic memory access' operand must have a power-of-two size"
, Ty, I); return; } } while (false)
;
3277}
3278
3279void Verifier::visitLoadInst(LoadInst &LI) {
3280 PointerType *PTy = dyn_cast<PointerType>(LI.getOperand(0)->getType());
3281 Assert(PTy, "Load operand must be a pointer.", &LI)do { if (!(PTy)) { CheckFailed("Load operand must be a pointer."
, &LI); return; } } while (false)
;
3282 Type *ElTy = LI.getType();
3283 Assert(LI.getAlignment() <= Value::MaximumAlignment,do { if (!(LI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &LI
); return; } } while (false)
3284 "huge alignment values are unsupported", &LI)do { if (!(LI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &LI
); return; } } while (false)
;
3285 Assert(ElTy->isSized(), "loading unsized types is not allowed", &LI)do { if (!(ElTy->isSized())) { CheckFailed("loading unsized types is not allowed"
, &LI); return; } } while (false)
;
3286 if (LI.isAtomic()) {
3287 Assert(LI.getOrdering() != AtomicOrdering::Release &&do { if (!(LI.getOrdering() != AtomicOrdering::Release &&
LI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed
("Load cannot have Release ordering", &LI); return; } } while
(false)
3288 LI.getOrdering() != AtomicOrdering::AcquireRelease,do { if (!(LI.getOrdering() != AtomicOrdering::Release &&
LI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed
("Load cannot have Release ordering", &LI); return; } } while
(false)
3289 "Load cannot have Release ordering", &LI)do { if (!(LI.getOrdering() != AtomicOrdering::Release &&
LI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed
("Load cannot have Release ordering", &LI); return; } } while
(false)
;
3290 Assert(LI.getAlignment() != 0,do { if (!(LI.getAlignment() != 0)) { CheckFailed("Atomic load must specify explicit alignment"
, &LI); return; } } while (false)
3291 "Atomic load must specify explicit alignment", &LI)do { if (!(LI.getAlignment() != 0)) { CheckFailed("Atomic load must specify explicit alignment"
, &LI); return; } } while (false)
;
3292 Assert(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy(),do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy
())) { CheckFailed("atomic load operand must have integer, pointer, or floating point "
"type!", ElTy, &LI); return; } } while (false)
3293 "atomic load operand must have integer, pointer, or floating point "do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy
())) { CheckFailed("atomic load operand must have integer, pointer, or floating point "
"type!", ElTy, &LI); return; } } while (false)
3294 "type!",do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy
())) { CheckFailed("atomic load operand must have integer, pointer, or floating point "
"type!", ElTy, &LI); return; } } while (false)
3295 ElTy, &LI)do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy
())) { CheckFailed("atomic load operand must have integer, pointer, or floating point "
"type!", ElTy, &LI); return; } } while (false)
;
3296 checkAtomicMemAccessSize(ElTy, &LI);
3297 } else {
3298 Assert(LI.getSyncScopeID() == SyncScope::System,do { if (!(LI.getSyncScopeID() == SyncScope::System)) { CheckFailed
("Non-atomic load cannot have SynchronizationScope specified"
, &LI); return; } } while (false)
3299 "Non-atomic load cannot have SynchronizationScope specified", &LI)do { if (!(LI.getSyncScopeID() == SyncScope::System)) { CheckFailed
("Non-atomic load cannot have SynchronizationScope specified"
, &LI); return; } } while (false)
;
3300 }
3301
3302 visitInstruction(LI);
3303}
3304
3305void Verifier::visitStoreInst(StoreInst &SI) {
3306 PointerType *PTy = dyn_cast<PointerType>(SI.getOperand(1)->getType());
3307 Assert(PTy, "Store operand must be a pointer.", &SI)do { if (!(PTy)) { CheckFailed("Store operand must be a pointer."
, &SI); return; } } while (false)
;
3308 Type *ElTy = PTy->getElementType();
3309 Assert(ElTy == SI.getOperand(0)->getType(),do { if (!(ElTy == SI.getOperand(0)->getType())) { CheckFailed
("Stored value type does not match pointer operand type!", &
SI, ElTy); return; } } while (false)
3310 "Stored value type does not match pointer operand type!", &SI, ElTy)do { if (!(ElTy == SI.getOperand(0)->getType())) { CheckFailed
("Stored value type does not match pointer operand type!", &
SI, ElTy); return; } } while (false)
;
3311 Assert(SI.getAlignment() <= Value::MaximumAlignment,do { if (!(SI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &SI
); return; } } while (false)
3312 "huge alignment values are unsupported", &SI)do { if (!(SI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &SI
); return; } } while (false)
;
3313 Assert(ElTy->isSized(), "storing unsized types is not allowed", &SI)do { if (!(ElTy->isSized())) { CheckFailed("storing unsized types is not allowed"
, &SI); return; } } while (false)
;
3314 if (SI.isAtomic()) {
3315 Assert(SI.getOrdering() != AtomicOrdering::Acquire &&do { if (!(SI.getOrdering() != AtomicOrdering::Acquire &&
SI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed
("Store cannot have Acquire ordering", &SI); return; } } while
(false)
3316 SI.getOrdering() != AtomicOrdering::AcquireRelease,do { if (!(SI.getOrdering() != AtomicOrdering::Acquire &&
SI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed
("Store cannot have Acquire ordering", &SI); return; } } while
(false)
3317 "Store cannot have Acquire ordering", &SI)do { if (!(SI.getOrdering() != AtomicOrdering::Acquire &&
SI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed
("Store cannot have Acquire ordering", &SI); return; } } while
(false)
;
3318 Assert(SI.getAlignment() != 0,do { if (!(SI.getAlignment() != 0)) { CheckFailed("Atomic store must specify explicit alignment"
, &SI); return; } } while (false)
3319 "Atomic store must specify explicit alignment", &SI)do { if (!(SI.getAlignment() != 0)) { CheckFailed("Atomic store must specify explicit alignment"
, &SI); return; } } while (false)
;
3320 Assert(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy(),do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy
())) { CheckFailed("atomic store operand must have integer, pointer, or floating point "
"type!", ElTy, &SI); return; } } while (false)
3321 "atomic store operand must have integer, pointer, or floating point "do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy
())) { CheckFailed("atomic store operand must have integer, pointer, or floating point "
"type!", ElTy, &SI); return; } } while (false)
3322 "type!",do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy
())) { CheckFailed("atomic store operand must have integer, pointer, or floating point "
"type!", ElTy, &SI); return; } } while (false)
3323 ElTy, &SI)do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy
())) { CheckFailed("atomic store operand must have integer, pointer, or floating point "
"type!", ElTy, &SI); return; } } while (false)
;
3324 checkAtomicMemAccessSize(ElTy, &SI);
3325 } else {
3326 Assert(SI.getSyncScopeID() == SyncScope::System,do { if (!(SI.getSyncScopeID() == SyncScope::System)) { CheckFailed
("Non-atomic store cannot have SynchronizationScope specified"
, &SI); return; } } while (false)
3327 "Non-atomic store cannot have SynchronizationScope specified", &SI)do { if (!(SI.getSyncScopeID() == SyncScope::System)) { CheckFailed
("Non-atomic store cannot have SynchronizationScope specified"
, &SI); return; } } while (false)
;
3328 }
3329 visitInstruction(SI);
3330}
3331
3332/// Check that SwiftErrorVal is used as a swifterror argument in CS.
3333void Verifier::verifySwiftErrorCallSite(CallSite CS,
3334 const Value *SwiftErrorVal) {
3335 unsigned Idx = 0;
3336 for (CallSite::arg_iterator I = CS.arg_begin(), E = CS.arg_end();
3337 I != E; ++I, ++Idx) {
3338 if (*I == SwiftErrorVal) {
3339 Assert(CS.paramHasAttr(Idx, Attribute::SwiftError),do { if (!(CS.paramHasAttr(Idx, Attribute::SwiftError))) { CheckFailed
("swifterror value when used in a callsite should be marked "
"with swifterror attribute", SwiftErrorVal, CS); return; } }
while (false)
3340 "swifterror value when used in a callsite should be marked "do { if (!(CS.paramHasAttr(Idx, Attribute::SwiftError))) { CheckFailed
("swifterror value when used in a callsite should be marked "
"with swifterror attribute", SwiftErrorVal, CS); return; } }
while (false)
3341 "with swifterror attribute",do { if (!(CS.paramHasAttr(Idx, Attribute::SwiftError))) { CheckFailed
("swifterror value when used in a callsite should be marked "
"with swifterror attribute", SwiftErrorVal, CS); return; } }
while (false)
3342 SwiftErrorVal, CS)do { if (!(CS.paramHasAttr(Idx, Attribute::SwiftError))) { CheckFailed
("swifterror value when used in a callsite should be marked "
"with swifterror attribute", SwiftErrorVal, CS); return; } }
while (false)
;
3343 }
3344 }
3345}
3346
3347void Verifier::verifySwiftErrorValue(const Value *SwiftErrorVal) {
3348 // Check that swifterror value is only used by loads, stores, or as
3349 // a swifterror argument.
3350 for (const User *U : SwiftErrorVal->users()) {
3351 Assert(isa<LoadInst>(U) || isa<StoreInst>(U) || isa<CallInst>(U) ||do { if (!(isa<LoadInst>(U) || isa<StoreInst>(U) ||
isa<CallInst>(U) || isa<InvokeInst>(U))) { CheckFailed
("swifterror value can only be loaded and stored from, or " "as a swifterror argument!"
, SwiftErrorVal, U); return; } } while (false)
3352 isa<InvokeInst>(U),do { if (!(isa<LoadInst>(U) || isa<StoreInst>(U) ||
isa<CallInst>(U) || isa<InvokeInst>(U))) { CheckFailed
("swifterror value can only be loaded and stored from, or " "as a swifterror argument!"
, SwiftErrorVal, U); return; } } while (false)
3353 "swifterror value can only be loaded and stored from, or "do { if (!(isa<LoadInst>(U) || isa<StoreInst>(U) ||
isa<CallInst>(U) || isa<InvokeInst>(U))) { CheckFailed
("swifterror value can only be loaded and stored from, or " "as a swifterror argument!"
, SwiftErrorVal, U); return; } } while (false)
3354 "as a swifterror argument!",do { if (!(isa<LoadInst>(U) || isa<StoreInst>(U) ||
isa<CallInst>(U) || isa<InvokeInst>(U))) { CheckFailed
("swifterror value can only be loaded and stored from, or " "as a swifterror argument!"
, SwiftErrorVal, U); return; } } while (false)
3355 SwiftErrorVal, U)do { if (!(isa<LoadInst>(U) || isa<StoreInst>(U) ||
isa<CallInst>(U) || isa<InvokeInst>(U))) { CheckFailed
("swifterror value can only be loaded and stored from, or " "as a swifterror argument!"
, SwiftErrorVal, U); return; } } while (false)
;
3356 // If it is used by a store, check it is the second operand.
3357 if (auto StoreI = dyn_cast<StoreInst>(U))
3358 Assert(StoreI->getOperand(1) == SwiftErrorVal,do { if (!(StoreI->getOperand(1) == SwiftErrorVal)) { CheckFailed
("swifterror value should be the second operand when used " "by stores"
, SwiftErrorVal, U); return; } } while (false)
3359 "swifterror value should be the second operand when used "do { if (!(StoreI->getOperand(1) == SwiftErrorVal)) { CheckFailed
("swifterror value should be the second operand when used " "by stores"
, SwiftErrorVal, U); return; } } while (false)
3360 "by stores", SwiftErrorVal, U)do { if (!(StoreI->getOperand(1) == SwiftErrorVal)) { CheckFailed
("swifterror value should be the second operand when used " "by stores"
, SwiftErrorVal, U); return; } } while (false)
;
3361 if (auto CallI = dyn_cast<CallInst>(U))
3362 verifySwiftErrorCallSite(const_cast<CallInst*>(CallI), SwiftErrorVal);
3363 if (auto II = dyn_cast<InvokeInst>(U))
3364 verifySwiftErrorCallSite(const_cast<InvokeInst*>(II), SwiftErrorVal);
3365 }
3366}
3367
3368void Verifier::visitAllocaInst(AllocaInst &AI) {
3369 SmallPtrSet<Type*, 4> Visited;
3370 PointerType *PTy = AI.getType();
3371 // TODO: Relax this restriction?
3372 Assert(PTy->getAddressSpace() == DL.getAllocaAddrSpace(),do { if (!(PTy->getAddressSpace() == DL.getAllocaAddrSpace
())) { CheckFailed("Allocation instruction pointer not in the stack address space!"
, &AI); return; } } while (false)
3373 "Allocation instruction pointer not in the stack address space!",do { if (!(PTy->getAddressSpace() == DL.getAllocaAddrSpace
())) { CheckFailed("Allocation instruction pointer not in the stack address space!"
, &AI); return; } } while (false)
3374 &AI)do { if (!(PTy->getAddressSpace() == DL.getAllocaAddrSpace
())) { CheckFailed("Allocation instruction pointer not in the stack address space!"
, &AI); return; } } while (false)
;
3375 Assert(AI.getAllocatedType()->isSized(&Visited),do { if (!(AI.getAllocatedType()->isSized(&Visited))) {
CheckFailed("Cannot allocate unsized type", &AI); return
; } } while (false)
3376 "Cannot allocate unsized type", &AI)do { if (!(AI.getAllocatedType()->isSized(&Visited))) {
CheckFailed("Cannot allocate unsized type", &AI); return
; } } while (false)
;
3377 Assert(AI.getArraySize()->getType()->isIntegerTy(),do { if (!(AI.getArraySize()->getType()->isIntegerTy())
) { CheckFailed("Alloca array size must have integer type", &
AI); return; } } while (false)
3378 "Alloca array size must have integer type", &AI)do { if (!(AI.getArraySize()->getType()->isIntegerTy())
) { CheckFailed("Alloca array size must have integer type", &
AI); return; } } while (false)
;
3379 Assert(AI.getAlignment() <= Value::MaximumAlignment,do { if (!(AI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &AI
); return; } } while (false)
3380 "huge alignment values are unsupported", &AI)do { if (!(AI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &AI
); return; } } while (false)
;
3381
3382 if (AI.isSwiftError()) {
3383 verifySwiftErrorValue(&AI);
3384 }
3385
3386 visitInstruction(AI);
3387}
3388
3389void Verifier::visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI) {
3390
3391 // FIXME: more conditions???
3392 Assert(CXI.getSuccessOrdering() != AtomicOrdering::NotAtomic,do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::NotAtomic
)) { CheckFailed("cmpxchg instructions must be atomic.", &
CXI); return; } } while (false)
3393 "cmpxchg instructions must be atomic.", &CXI)do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::NotAtomic
)) { CheckFailed("cmpxchg instructions must be atomic.", &
CXI); return; } } while (false)
;
3394 Assert(CXI.getFailureOrdering() != AtomicOrdering::NotAtomic,do { if (!(CXI.getFailureOrdering() != AtomicOrdering::NotAtomic
)) { CheckFailed("cmpxchg instructions must be atomic.", &
CXI); return; } } while (false)
3395 "cmpxchg instructions must be atomic.", &CXI)do { if (!(CXI.getFailureOrdering() != AtomicOrdering::NotAtomic
)) { CheckFailed("cmpxchg instructions must be atomic.", &
CXI); return; } } while (false)
;
3396 Assert(CXI.getSuccessOrdering() != AtomicOrdering::Unordered,do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::Unordered
)) { CheckFailed("cmpxchg instructions cannot be unordered.",
&CXI); return; } } while (false)
3397 "cmpxchg instructions cannot be unordered.", &CXI)do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::Unordered
)) { CheckFailed("cmpxchg instructions cannot be unordered.",
&CXI); return; } } while (false)
;
3398 Assert(CXI.getFailureOrdering() != AtomicOrdering::Unordered,do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Unordered
)) { CheckFailed("cmpxchg instructions cannot be unordered.",
&CXI); return; } } while (false)
3399 "cmpxchg instructions cannot be unordered.", &CXI)do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Unordered
)) { CheckFailed("cmpxchg instructions cannot be unordered.",
&CXI); return; } } while (false)
;
3400 Assert(!isStrongerThan(CXI.getFailureOrdering(), CXI.getSuccessOrdering()),do { if (!(!isStrongerThan(CXI.getFailureOrdering(), CXI.getSuccessOrdering
()))) { CheckFailed("cmpxchg instructions failure argument shall be no stronger than the "
"success argument", &CXI); return; } } while (false)
3401 "cmpxchg instructions failure argument shall be no stronger than the "do { if (!(!isStrongerThan(CXI.getFailureOrdering(), CXI.getSuccessOrdering
()))) { CheckFailed("cmpxchg instructions failure argument shall be no stronger than the "
"success argument", &CXI); return; } } while (false)
3402 "success argument",do { if (!(!isStrongerThan(CXI.getFailureOrdering(), CXI.getSuccessOrdering
()))) { CheckFailed("cmpxchg instructions failure argument shall be no stronger than the "
"success argument", &CXI); return; } } while (false)
3403 &CXI)do { if (!(!isStrongerThan(CXI.getFailureOrdering(), CXI.getSuccessOrdering
()))) { CheckFailed("cmpxchg instructions failure argument shall be no stronger than the "
"success argument", &CXI); return; } } while (false)
;
3404 Assert(CXI.getFailureOrdering() != AtomicOrdering::Release &&do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Release
&& CXI.getFailureOrdering() != AtomicOrdering::AcquireRelease
)) { CheckFailed("cmpxchg failure ordering cannot include release semantics"
, &CXI); return; } } while (false)
3405 CXI.getFailureOrdering() != AtomicOrdering::AcquireRelease,do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Release
&& CXI.getFailureOrdering() != AtomicOrdering::AcquireRelease
)) { CheckFailed("cmpxchg failure ordering cannot include release semantics"
, &CXI); return; } } while (false)
3406 "cmpxchg failure ordering cannot include release semantics", &CXI)do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Release
&& CXI.getFailureOrdering() != AtomicOrdering::AcquireRelease
)) { CheckFailed("cmpxchg failure ordering cannot include release semantics"
, &CXI); return; } } while (false)
;
3407
3408 PointerType *PTy = dyn_cast<PointerType>(CXI.getOperand(0)->getType());
3409 Assert(PTy, "First cmpxchg operand must be a pointer.", &CXI)do { if (!(PTy)) { CheckFailed("First cmpxchg operand must be a pointer."
, &CXI); return; } } while (false)
;
3410 Type *ElTy = PTy->getElementType();
3411 Assert(ElTy->isIntOrPtrTy(),do { if (!(ElTy->isIntOrPtrTy())) { CheckFailed("cmpxchg operand must have integer or pointer type"
, ElTy, &CXI); return; } } while (false)
3412 "cmpxchg operand must have integer or pointer type", ElTy, &CXI)do { if (!(ElTy->isIntOrPtrTy())) { CheckFailed("cmpxchg operand must have integer or pointer type"
, ElTy, &CXI); return; } } while (false)
;
3413 checkAtomicMemAccessSize(ElTy, &CXI);
3414 Assert(ElTy == CXI.getOperand(1)->getType(),do { if (!(ElTy == CXI.getOperand(1)->getType())) { CheckFailed
("Expected value type does not match pointer operand type!", &
CXI, ElTy); return; } } while (false)
3415 "Expected value type does not match pointer operand type!", &CXI,do { if (!(ElTy == CXI.getOperand(1)->getType())) { CheckFailed
("Expected value type does not match pointer operand type!", &
CXI, ElTy); return; } } while (false)
3416 ElTy)do { if (!(ElTy == CXI.getOperand(1)->getType())) { CheckFailed
("Expected value type does not match pointer operand type!", &
CXI, ElTy); return; } } while (false)
;
3417 Assert(ElTy == CXI.getOperand(2)->getType(),do { if (!(ElTy == CXI.getOperand(2)->getType())) { CheckFailed
("Stored value type does not match pointer operand type!", &
CXI, ElTy); return; } } while (false)
3418 "Stored value type does not match pointer operand type!", &CXI, ElTy)do { if (!(ElTy == CXI.getOperand(2)->getType())) { CheckFailed
("Stored value type does not match pointer operand type!", &
CXI, ElTy); return; } } while (false)
;
3419 visitInstruction(CXI);
3420}
3421
3422void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) {
3423 Assert(RMWI.getOrdering() != AtomicOrdering::NotAtomic,do { if (!(RMWI.getOrdering() != AtomicOrdering::NotAtomic)) {
CheckFailed("atomicrmw instructions must be atomic.", &RMWI
); return; } } while (false)
3424 "atomicrmw instructions must be atomic.", &RMWI)do { if (!(RMWI.getOrdering() != AtomicOrdering::NotAtomic)) {
CheckFailed("atomicrmw instructions must be atomic.", &RMWI
); return; } } while (false)
;
3425 Assert(RMWI.getOrdering() != AtomicOrdering::Unordered,do { if (!(RMWI.getOrdering() != AtomicOrdering::Unordered)) {
CheckFailed("atomicrmw instructions cannot be unordered.", &
RMWI); return; } } while (false)
3426 "atomicrmw instructions cannot be unordered.", &RMWI)do { if (!(RMWI.getOrdering() != AtomicOrdering::Unordered)) {
CheckFailed("atomicrmw instructions cannot be unordered.", &
RMWI); return; } } while (false)
;
3427 auto Op = RMWI.getOperation();
3428 PointerType *PTy = dyn_cast<PointerType>(RMWI.getOperand(0)->getType());
3429 Assert(PTy, "First atomicrmw operand must be a pointer.", &RMWI)do { if (!(PTy)) { CheckFailed("First atomicrmw operand must be a pointer."
, &RMWI); return; } } while (false)
;
3430 Type *ElTy = PTy->getElementType();
3431 Assert(ElTy->isIntegerTy(), "atomicrmw " +do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw "
+ AtomicRMWInst::getOperationName(Op) + " operand must have integer type!"
, &RMWI, ElTy); return; } } while (false)
3432 AtomicRMWInst::getOperationName(Op) +do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw "
+ AtomicRMWInst::getOperationName(Op) + " operand must have integer type!"
, &RMWI, ElTy); return; } } while (false)
3433 " operand must have integer type!",do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw "
+ AtomicRMWInst::getOperationName(Op) + " operand must have integer type!"
, &RMWI, ElTy); return; } } while (false)
3434 &RMWI, ElTy)do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw "
+ AtomicRMWInst::getOperationName(Op) + " operand must have integer type!"
, &RMWI, ElTy); return; } } while (false)
;
3435 checkAtomicMemAccessSize(ElTy, &RMWI);
3436 Assert(ElTy == RMWI.getOperand(1)->getType(),do { if (!(ElTy == RMWI.getOperand(1)->getType())) { CheckFailed
("Argument value type does not match pointer operand type!", &
RMWI, ElTy); return; } } while (false)
3437 "Argument value type does not match pointer operand type!", &RMWI,do { if (!(ElTy == RMWI.getOperand(1)->getType())) { CheckFailed
("Argument value type does not match pointer operand type!", &
RMWI, ElTy); return; } } while (false)
3438 ElTy)do { if (!(ElTy == RMWI.getOperand(1)->getType())) { CheckFailed
("Argument value type does not match pointer operand type!", &
RMWI, ElTy); return; } } while (false)
;
3439 Assert(AtomicRMWInst::FIRST_BINOP <= Op && Op <= AtomicRMWInst::LAST_BINOP,do { if (!(AtomicRMWInst::FIRST_BINOP <= Op && Op <=
AtomicRMWInst::LAST_BINOP)) { CheckFailed("Invalid binary operation!"
, &RMWI); return; } } while (false)
3440 "Invalid binary operation!", &RMWI)do { if (!(AtomicRMWInst::FIRST_BINOP <= Op && Op <=
AtomicRMWInst::LAST_BINOP)) { CheckFailed("Invalid binary operation!"
, &RMWI); return; } } while (false)
;
3441 visitInstruction(RMWI);
3442}
3443
3444void Verifier::visitFenceInst(FenceInst &FI) {
3445 const AtomicOrdering Ordering = FI.getOrdering();
3446 Assert(Ordering == AtomicOrdering::Acquire ||do { if (!(Ordering == AtomicOrdering::Acquire || Ordering ==
AtomicOrdering::Release || Ordering == AtomicOrdering::AcquireRelease
|| Ordering == AtomicOrdering::SequentiallyConsistent)) { CheckFailed
("fence instructions may only have acquire, release, acq_rel, or "
"seq_cst ordering.", &FI); return; } } while (false)
3447 Ordering == AtomicOrdering::Release ||do { if (!(Ordering == AtomicOrdering::Acquire || Ordering ==
AtomicOrdering::Release || Ordering == AtomicOrdering::AcquireRelease
|| Ordering == AtomicOrdering::SequentiallyConsistent)) { CheckFailed
("fence instructions may only have acquire, release, acq_rel, or "
"seq_cst ordering.", &FI); return; } } while (false)
3448 Ordering == AtomicOrdering::AcquireRelease ||do { if (!(Ordering == AtomicOrdering::Acquire || Ordering ==
AtomicOrdering::Release || Ordering == AtomicOrdering::AcquireRelease
|| Ordering == AtomicOrdering::SequentiallyConsistent)) { CheckFailed
("fence instructions may only have acquire, release, acq_rel, or "
"seq_cst ordering.", &FI); return; } } while (false)
3449 Ordering == AtomicOrdering::SequentiallyConsistent,do { if (!(Ordering == AtomicOrdering::Acquire || Ordering ==
AtomicOrdering::Release || Ordering == AtomicOrdering::AcquireRelease
|| Ordering == AtomicOrdering::SequentiallyConsistent)) { CheckFailed
("fence instructions may only have acquire, release, acq_rel, or "
"seq_cst ordering.", &FI); return; } } while (false)
3450 "fence instructions may only have acquire, release, acq_rel, or "do { if (!(Ordering == AtomicOrdering::Acquire || Ordering ==
AtomicOrdering::Release || Ordering == AtomicOrdering::AcquireRelease
|| Ordering == AtomicOrdering::SequentiallyConsistent)) { CheckFailed
("fence instructions may only have acquire, release, acq_rel, or "
"seq_cst ordering.", &FI); return; } } while (false)
3451 "seq_cst ordering.",do { if (!(Ordering == AtomicOrdering::Acquire || Ordering ==
AtomicOrdering::Release || Ordering == AtomicOrdering::AcquireRelease
|| Ordering == AtomicOrdering::SequentiallyConsistent)) { CheckFailed
("fence instructions may only have acquire, release, acq_rel, or "
"seq_cst ordering.", &FI); return; } } while (false)
3452 &FI)do { if (!(Ordering == AtomicOrdering::Acquire || Ordering ==
AtomicOrdering::Release || Ordering == AtomicOrdering::AcquireRelease
|| Ordering == AtomicOrdering::SequentiallyConsistent)) { CheckFailed
("fence instructions may only have acquire, release, acq_rel, or "
"seq_cst ordering.", &FI); return; } } while (false)
;
3453 visitInstruction(FI);
3454}
3455
3456void Verifier::visitExtractValueInst(ExtractValueInst &EVI) {
3457 Assert(ExtractValueInst::getIndexedType(EVI.getAggregateOperand()->getType(),do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand
()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed
("Invalid ExtractValueInst operands!", &EVI); return; } }
while (false)
3458 EVI.getIndices()) == EVI.getType(),do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand
()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed
("Invalid ExtractValueInst operands!", &EVI); return; } }
while (false)
3459 "Invalid ExtractValueInst operands!", &EVI)do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand
()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed
("Invalid ExtractValueInst operands!", &EVI); return; } }
while (false)
;
3460
3461 visitInstruction(EVI);
3462}
3463
3464void Verifier::visitInsertValueInst(InsertValueInst &IVI) {
3465 Assert(ExtractValueInst::getIndexedType(IVI.getAggregateOperand()->getType(),do { if (!(ExtractValueInst::getIndexedType(IVI.getAggregateOperand
()->getType(), IVI.getIndices()) == IVI.getOperand(1)->
getType())) { CheckFailed("Invalid InsertValueInst operands!"
, &IVI); return; } } while (false)
3466 IVI.getIndices()) ==do { if (!(ExtractValueInst::getIndexedType(IVI.getAggregateOperand
()->getType(), IVI.getIndices()) == IVI.getOperand(1)->
getType())) { CheckFailed("Invalid InsertValueInst operands!"
, &IVI); return; } } while (false)
3467 IVI.getOperand(1)->getType(),do { if (!(ExtractValueInst::getIndexedType(IVI.getAggregateOperand
()->getType(), IVI.getIndices()) == IVI.getOperand(1)->
getType())) { CheckFailed("Invalid InsertValueInst operands!"
, &IVI); return; } } while (false)
3468 "Invalid InsertValueInst operands!", &IVI)do { if (!(ExtractValueInst::getIndexedType(IVI.getAggregateOperand
()->getType(), IVI.getIndices()) == IVI.getOperand(1)->
getType())) { CheckFailed("Invalid InsertValueInst operands!"
, &IVI); return; } } while (false)
;
3469
3470 visitInstruction(IVI);
3471}
3472
3473static Value *getParentPad(Value *EHPad) {
3474 if (auto *FPI = dyn_cast<FuncletPadInst>(EHPad))
3475 return FPI->getParentPad();
3476
3477 return cast<CatchSwitchInst>(EHPad)->getParentPad();
3478}
3479
3480void Verifier::visitEHPadPredecessors(Instruction &I) {
3481 assert(I.isEHPad())((I.isEHPad()) ? static_cast<void> (0) : __assert_fail (
"I.isEHPad()", "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp"
, 3481, __PRETTY_FUNCTION__))
;
3482
3483 BasicBlock *BB = I.getParent();
3484 Function *F = BB->getParent();
3485
3486 Assert(BB != &F->getEntryBlock(), "EH pad cannot be in entry block.", &I)do { if (!(BB != &F->getEntryBlock())) { CheckFailed("EH pad cannot be in entry block."
, &I); return; } } while (false)
;
3487
3488 if (auto *LPI = dyn_cast<LandingPadInst>(&I)) {
3489 // The landingpad instruction defines its parent as a landing pad block. The
3490 // landing pad block may be branched to only by the unwind edge of an
3491 // invoke.
3492 for (BasicBlock *PredBB : predecessors(BB)) {
3493 const auto *II = dyn_cast<InvokeInst>(PredBB->getTerminator());
3494 Assert(II && II->getUnwindDest() == BB && II->getNormalDest() != BB,do { if (!(II && II->getUnwindDest() == BB &&
II->getNormalDest() != BB)) { CheckFailed("Block containing LandingPadInst must be jumped to "
"only by the unwind edge of an invoke.", LPI); return; } } while
(false)
3495 "Block containing LandingPadInst must be jumped to "do { if (!(II && II->getUnwindDest() == BB &&
II->getNormalDest() != BB)) { CheckFailed("Block containing LandingPadInst must be jumped to "
"only by the unwind edge of an invoke.", LPI); return; } } while
(false)
3496 "only by the unwind edge of an invoke.",do { if (!(II && II->getUnwindDest() == BB &&
II->getNormalDest() != BB)) { CheckFailed("Block containing LandingPadInst must be jumped to "
"only by the unwind edge of an invoke.", LPI); return; } } while
(false)
3497 LPI)do { if (!(II && II->getUnwindDest() == BB &&
II->getNormalDest() != BB)) { CheckFailed("Block containing LandingPadInst must be jumped to "
"only by the unwind edge of an invoke.", LPI); return; } } while
(false)
;
3498 }
3499 return;
3500 }
3501 if (auto *CPI = dyn_cast<CatchPadInst>(&I)) {
3502 if (!pred_empty(BB))
3503 Assert(BB->getUniquePredecessor() == CPI->getCatchSwitch()->getParent(),do { if (!(BB->getUniquePredecessor() == CPI->getCatchSwitch
()->getParent())) { CheckFailed("Block containg CatchPadInst must be jumped to "
"only by its catchswitch.", CPI); return; } } while (false)
3504 "Block containg CatchPadInst must be jumped to "do { if (!(BB->getUniquePredecessor() == CPI->getCatchSwitch
()->getParent())) { CheckFailed("Block containg CatchPadInst must be jumped to "
"only by its catchswitch.", CPI); return; } } while (false)
3505 "only by its catchswitch.",do { if (!(BB->getUniquePredecessor() == CPI->getCatchSwitch
()->getParent())) { CheckFailed("Block containg CatchPadInst must be jumped to "
"only by its catchswitch.", CPI); return; } } while (false)
3506 CPI)do { if (!(BB->getUniquePredecessor() == CPI->getCatchSwitch
()->getParent())) { CheckFailed("Block containg CatchPadInst must be jumped to "
"only by its catchswitch.", CPI); return; } } while (false)
;
3507 Assert(BB != CPI->getCatchSwitch()->getUnwindDest(),do { if (!(BB != CPI->getCatchSwitch()->getUnwindDest()
)) { CheckFailed("Catchswitch cannot unwind to one of its catchpads"
, CPI->getCatchSwitch(), CPI); return; } } while (false)
3508 "Catchswitch cannot unwind to one of its catchpads",do { if (!(BB != CPI->getCatchSwitch()->getUnwindDest()
)) { CheckFailed("Catchswitch cannot unwind to one of its catchpads"
, CPI->getCatchSwitch(), CPI); return; } } while (false)
3509 CPI->getCatchSwitch(), CPI)do { if (!(BB != CPI->getCatchSwitch()->getUnwindDest()
)) { CheckFailed("Catchswitch cannot unwind to one of its catchpads"
, CPI->getCatchSwitch(), CPI); return; } } while (false)
;
3510 return;
3511 }
3512
3513 // Verify that each pred has a legal terminator with a legal to/from EH
3514 // pad relationship.
3515 Instruction *ToPad = &I;
3516 Value *ToPadParent = getParentPad(ToPad);
3517 for (BasicBlock *PredBB : predecessors(BB)) {
3518 Instruction *TI = PredBB->getTerminator();
3519 Value *FromPad;
3520 if (auto *II = dyn_cast<InvokeInst>(TI)) {
3521 Assert(II->getUnwindDest() == BB && II->getNormalDest() != BB,do { if (!(II->getUnwindDest() == BB && II->getNormalDest
() != BB)) { CheckFailed("EH pad must be jumped to via an unwind edge"
, ToPad, II); return; } } while (false)
3522 "EH pad must be jumped to via an unwind edge", ToPad, II)do { if (!(II->getUnwindDest() == BB && II->getNormalDest
() != BB)) { CheckFailed("EH pad must be jumped to via an unwind edge"
, ToPad, II); return; } } while (false)
;
3523 if (auto Bundle = II->getOperandBundle(LLVMContext::OB_funclet))
3524 FromPad = Bundle->Inputs[0];
3525 else
3526 FromPad = ConstantTokenNone::get(II->getContext());
3527 } else if (auto *CRI = dyn_cast<CleanupReturnInst>(TI)) {
3528 FromPad = CRI->getOperand(0);
3529 Assert(FromPad != ToPadParent, "A cleanupret must exit its cleanup", CRI)do { if (!(FromPad != ToPadParent)) { CheckFailed("A cleanupret must exit its cleanup"
, CRI); return; } } while (false)
;
3530 } else if (auto *CSI = dyn_cast<CatchSwitchInst>(TI)) {
3531 FromPad = CSI;
3532 } else {
3533 Assert(false, "EH pad must be jumped to via an unwind edge", ToPad, TI)do { if (!(false)) { CheckFailed("EH pad must be jumped to via an unwind edge"
, ToPad, TI); return; } } while (false)
;
3534 }
3535
3536 // The edge may exit from zero or more nested pads.
3537 SmallSet<Value *, 8> Seen;
3538 for (;; FromPad = getParentPad(FromPad)) {
3539 Assert(FromPad != ToPad,do { if (!(FromPad != ToPad)) { CheckFailed("EH pad cannot handle exceptions raised within it"
, FromPad, TI); return; } } while (false)
3540 "EH pad cannot handle exceptions raised within it", FromPad, TI)do { if (!(FromPad != ToPad)) { CheckFailed("EH pad cannot handle exceptions raised within it"
, FromPad, TI); return; } } while (false)
;
3541 if (FromPad == ToPadParent) {
3542 // This is a legal unwind edge.
3543 break;
3544 }
3545 Assert(!isa<ConstantTokenNone>(FromPad),do { if (!(!isa<ConstantTokenNone>(FromPad))) { CheckFailed
("A single unwind edge may only enter one EH pad", TI); return
; } } while (false)
3546 "A single unwind edge may only enter one EH pad", TI)do { if (!(!isa<ConstantTokenNone>(FromPad))) { CheckFailed
("A single unwind edge may only enter one EH pad", TI); return
; } } while (false)
;
3547 Assert(Seen.insert(FromPad).second,do { if (!(Seen.insert(FromPad).second)) { CheckFailed("EH pad jumps through a cycle of pads"
, FromPad); return; } } while (false)
3548 "EH pad jumps through a cycle of pads", FromPad)do { if (!(Seen.insert(FromPad).second)) { CheckFailed("EH pad jumps through a cycle of pads"
, FromPad); return; } } while (false)
;
3549 }
3550 }
3551}
3552
3553void Verifier::visitLandingPadInst(LandingPadInst &LPI) {
3554 // The landingpad instruction is ill-formed if it doesn't have any clauses and
3555 // isn't a cleanup.
3556 Assert(LPI.getNumClauses() > 0 || LPI.isCleanup(),do { if (!(LPI.getNumClauses() > 0 || LPI.isCleanup())) { CheckFailed
("LandingPadInst needs at least one clause or to be a cleanup."
, &LPI); return; } } while (false)
3557 "LandingPadInst needs at least one clause or to be a cleanup.", &LPI)do { if (!(LPI.getNumClauses() > 0 || LPI.isCleanup())) { CheckFailed
("LandingPadInst needs at least one clause or to be a cleanup."
, &LPI); return; } } while (false)
;
3558
3559 visitEHPadPredecessors(LPI);
3560
3561 if (!LandingPadResultTy)
3562 LandingPadResultTy = LPI.getType();
3563 else
3564 Assert(LandingPadResultTy == LPI.getType(),do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed
("The landingpad instruction should have a consistent result type "
"inside a function.", &LPI); return; } } while (false)
3565 "The landingpad instruction should have a consistent result type "do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed
("The landingpad instruction should have a consistent result type "
"inside a function.", &LPI); return; } } while (false)
3566 "inside a function.",do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed
("The landingpad instruction should have a consistent result type "
"inside a function.", &LPI); return; } } while (false)
3567 &LPI)do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed
("The landingpad instruction should have a consistent result type "
"inside a function.", &LPI); return; } } while (false)
;
3568
3569 Function *F = LPI.getParent()->getParent();
3570 Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("LandingPadInst needs to be in a function with a personality."
, &LPI); return; } } while (false)
3571 "LandingPadInst needs to be in a function with a personality.", &LPI)do { if (!(F->hasPersonalityFn())) { CheckFailed("LandingPadInst needs to be in a function with a personality."
, &LPI); return; } } while (false)
;
3572
3573 // The landingpad instruction must be the first non-PHI instruction in the
3574 // block.
3575 Assert(LPI.getParent()->getLandingPadInst() == &LPI,do { if (!(LPI.getParent()->getLandingPadInst() == &LPI
)) { CheckFailed("LandingPadInst not the first non-PHI instruction in the block."
, &LPI); return; } } while (false)
3576 "LandingPadInst not the first non-PHI instruction in the block.",do { if (!(LPI.getParent()->getLandingPadInst() == &LPI
)) { CheckFailed("LandingPadInst not the first non-PHI instruction in the block."
, &LPI); return; } } while (false)
3577 &LPI)do { if (!(LPI.getParent()->getLandingPadInst() == &LPI
)) { CheckFailed("LandingPadInst not the first non-PHI instruction in the block."
, &LPI); return; } } while (false)
;
3578
3579 for (unsigned i = 0, e = LPI.getNumClauses(); i < e; ++i) {
3580 Constant *Clause = LPI.getClause(i);
3581 if (LPI.isCatch(i)) {
3582 Assert(isa<PointerType>(Clause->getType()),do { if (!(isa<PointerType>(Clause->getType()))) { CheckFailed
("Catch operand does not have pointer type!", &LPI); return
; } } while (false)
3583 "Catch operand does not have pointer type!", &LPI)do { if (!(isa<PointerType>(Clause->getType()))) { CheckFailed
("Catch operand does not have pointer type!", &LPI); return
; } } while (false)
;
3584 } else {
3585 Assert(LPI.isFilter(i), "Clause is neither catch nor filter!", &LPI)do { if (!(LPI.isFilter(i))) { CheckFailed("Clause is neither catch nor filter!"
, &LPI); return; } } while (false)
;
3586 Assert(isa<ConstantArray>(Clause) || isa<ConstantAggregateZero>(Clause),do { if (!(isa<ConstantArray>(Clause) || isa<ConstantAggregateZero
>(Clause))) { CheckFailed("Filter operand is not an array of constants!"
, &LPI); return; } } while (false)
3587 "Filter operand is not an array of constants!", &LPI)do { if (!(isa<ConstantArray>(Clause) || isa<ConstantAggregateZero
>(Clause))) { CheckFailed("Filter operand is not an array of constants!"
, &LPI); return; } } while (false)
;
3588 }
3589 }
3590
3591 visitInstruction(LPI);
3592}
3593
3594void Verifier::visitResumeInst(ResumeInst &RI) {
3595 Assert(RI.getFunction()->hasPersonalityFn(),do { if (!(RI.getFunction()->hasPersonalityFn())) { CheckFailed
("ResumeInst needs to be in a function with a personality.", &
RI); return; } } while (false)
3596 "ResumeInst needs to be in a function with a personality.", &RI)do { if (!(RI.getFunction()->hasPersonalityFn())) { CheckFailed
("ResumeInst needs to be in a function with a personality.", &
RI); return; } } while (false)
;
3597
3598 if (!LandingPadResultTy)
3599 LandingPadResultTy = RI.getValue()->getType();
3600 else
3601 Assert(LandingPadResultTy == RI.getValue()->getType(),do { if (!(LandingPadResultTy == RI.getValue()->getType())
) { CheckFailed("The resume instruction should have a consistent result type "
"inside a function.", &RI); return; } } while (false)
3602 "The resume instruction should have a consistent result type "do { if (!(LandingPadResultTy == RI.getValue()->getType())
) { CheckFailed("The resume instruction should have a consistent result type "
"inside a function.", &RI); return; } } while (false)
3603 "inside a function.",do { if (!(LandingPadResultTy == RI.getValue()->getType())
) { CheckFailed("The resume instruction should have a consistent result type "
"inside a function.", &RI); return; } } while (false)
3604 &RI)do { if (!(LandingPadResultTy == RI.getValue()->getType())
) { CheckFailed("The resume instruction should have a consistent result type "
"inside a function.", &RI); return; } } while (false)
;
3605
3606 visitTerminator(RI);
3607}
3608
3609void Verifier::visitCatchPadInst(CatchPadInst &CPI) {
3610 BasicBlock *BB = CPI.getParent();
3611
3612 Function *F = BB->getParent();
3613 Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchPadInst needs to be in a function with a personality."
, &CPI); return; } } while (false)
3614 "CatchPadInst needs to be in a function with a personality.", &CPI)do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchPadInst needs to be in a function with a personality."
, &CPI); return; } } while (false)
;
3615
3616 Assert(isa<CatchSwitchInst>(CPI.getParentPad()),do { if (!(isa<CatchSwitchInst>(CPI.getParentPad()))) {
CheckFailed("CatchPadInst needs to be directly nested in a CatchSwitchInst."
, CPI.getParentPad()); return; } } while (false)
3617 "CatchPadInst needs to be directly nested in a CatchSwitchInst.",do { if (!(isa<CatchSwitchInst>(CPI.getParentPad()))) {
CheckFailed("CatchPadInst needs to be directly nested in a CatchSwitchInst."
, CPI.getParentPad()); return; } } while (false)
3618 CPI.getParentPad())do { if (!(isa<CatchSwitchInst>(CPI.getParentPad()))) {
CheckFailed("CatchPadInst needs to be directly nested in a CatchSwitchInst."
, CPI.getParentPad()); return; } } while (false)
;
3619
3620 // The catchpad instruction must be the first non-PHI instruction in the
3621 // block.
3622 Assert(BB->getFirstNonPHI() == &CPI,do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed
("CatchPadInst not the first non-PHI instruction in the block."
, &CPI); return; } } while (false)
3623 "CatchPadInst not the first non-PHI instruction in the block.", &CPI)do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed
("CatchPadInst not the first non-PHI instruction in the block."
, &CPI); return; } } while (false)
;
3624
3625 visitEHPadPredecessors(CPI);
3626 visitFuncletPadInst(CPI);
3627}
3628
3629void Verifier::visitCatchReturnInst(CatchReturnInst &CatchReturn) {
3630 Assert(isa<CatchPadInst>(CatchReturn.getOperand(0)),do { if (!(isa<CatchPadInst>(CatchReturn.getOperand(0))
)) { CheckFailed("CatchReturnInst needs to be provided a CatchPad"
, &CatchReturn, CatchReturn.getOperand(0)); return; } } while
(false)
3631 "CatchReturnInst needs to be provided a CatchPad", &CatchReturn,do { if (!(isa<CatchPadInst>(CatchReturn.getOperand(0))
)) { CheckFailed("CatchReturnInst needs to be provided a CatchPad"
, &CatchReturn, CatchReturn.getOperand(0)); return; } } while
(false)
3632 CatchReturn.getOperand(0))do { if (!(isa<CatchPadInst>(CatchReturn.getOperand(0))
)) { CheckFailed("CatchReturnInst needs to be provided a CatchPad"
, &CatchReturn, CatchReturn.getOperand(0)); return; } } while
(false)
;
3633
3634 visitTerminator(CatchReturn);
3635}
3636
3637void Verifier::visitCleanupPadInst(CleanupPadInst &CPI) {
3638 BasicBlock *BB = CPI.getParent();
3639
3640 Function *F = BB->getParent();
3641 Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CleanupPadInst needs to be in a function with a personality."
, &CPI); return; } } while (false)
3642 "CleanupPadInst needs to be in a function with a personality.", &CPI)do { if (!(F->hasPersonalityFn())) { CheckFailed("CleanupPadInst needs to be in a function with a personality."
, &CPI); return; } } while (false)
;
3643
3644 // The cleanuppad instruction must be the first non-PHI instruction in the
3645 // block.
3646 Assert(BB->getFirstNonPHI() == &CPI,do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed
("CleanupPadInst not the first non-PHI instruction in the block."
, &CPI); return; } } while (false)
3647 "CleanupPadInst not the first non-PHI instruction in the block.",do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed
("CleanupPadInst not the first non-PHI instruction in the block."
, &CPI); return; } } while (false)
3648 &CPI)do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed
("CleanupPadInst not the first non-PHI instruction in the block."
, &CPI); return; } } while (false)
;
3649
3650 auto *ParentPad = CPI.getParentPad();
3651 Assert(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),do { if (!(isa<ConstantTokenNone>(ParentPad) || isa<
FuncletPadInst>(ParentPad))) { CheckFailed("CleanupPadInst has an invalid parent."
, &CPI); return; } } while (false)
3652 "CleanupPadInst has an invalid parent.", &CPI)do { if (!(isa<ConstantTokenNone>(ParentPad) || isa<
FuncletPadInst>(ParentPad))) { CheckFailed("CleanupPadInst has an invalid parent."
, &CPI); return; } } while (false)
;
3653
3654 visitEHPadPredecessors(CPI);
3655 visitFuncletPadInst(CPI);
3656}
3657
3658void Verifier::visitFuncletPadInst(FuncletPadInst &FPI) {
3659 User *FirstUser = nullptr;
3660 Value *FirstUnwindPad = nullptr;
3661 SmallVector<FuncletPadInst *, 8> Worklist({&FPI});
3662 SmallSet<FuncletPadInst *, 8> Seen;
3663
3664 while (!Worklist.empty()) {
3665 FuncletPadInst *CurrentPad = Worklist.pop_back_val();
3666 Assert(Seen.insert(CurrentPad).second,do { if (!(Seen.insert(CurrentPad).second)) { CheckFailed("FuncletPadInst must not be nested within itself"
, CurrentPad); return; } } while (false)
3667 "FuncletPadInst must not be nested within itself", CurrentPad)do { if (!(Seen.insert(CurrentPad).second)) { CheckFailed("FuncletPadInst must not be nested within itself"
, CurrentPad); return; } } while (false)
;
3668 Value *UnresolvedAncestorPad = nullptr;
3669 for (User *U : CurrentPad->users()) {
3670 BasicBlock *UnwindDest;
3671 if (auto *CRI = dyn_cast<CleanupReturnInst>(U)) {
3672 UnwindDest = CRI->getUnwindDest();
3673 } else if (auto *CSI = dyn_cast<CatchSwitchInst>(U)) {
3674 // We allow catchswitch unwind to caller to nest
3675 // within an outer pad that unwinds somewhere else,
3676 // because catchswitch doesn't have a nounwind variant.
3677 // See e.g. SimplifyCFGOpt::SimplifyUnreachable.
3678 if (CSI->unwindsToCaller())
3679 continue;
3680 UnwindDest = CSI->getUnwindDest();
3681 } else if (auto *II = dyn_cast<InvokeInst>(U)) {
3682 UnwindDest = II->getUnwindDest();
3683 } else if (isa<CallInst>(U)) {
3684 // Calls which don't unwind may be found inside funclet
3685 // pads that unwind somewhere else. We don't *require*
3686 // such calls to be annotated nounwind.
3687 continue;
3688 } else if (auto *CPI = dyn_cast<CleanupPadInst>(U)) {
3689 // The unwind dest for a cleanup can only be found by
3690 // recursive search. Add it to the worklist, and we'll
3691 // search for its first use that determines where it unwinds.
3692 Worklist.push_back(CPI);
3693 continue;
3694 } else {
3695 Assert(isa<CatchReturnInst>(U), "Bogus funclet pad use", U)do { if (!(isa<CatchReturnInst>(U))) { CheckFailed("Bogus funclet pad use"
, U); return; } } while (false)
;
3696 continue;
3697 }
3698
3699 Value *UnwindPad;
3700 bool ExitsFPI;
3701 if (UnwindDest) {
3702 UnwindPad = UnwindDest->getFirstNonPHI();
3703 if (!cast<Instruction>(UnwindPad)->isEHPad())
3704 continue;
3705 Value *UnwindParent = getParentPad(UnwindPad);
3706 // Ignore unwind edges that don't exit CurrentPad.
3707 if (UnwindParent == CurrentPad)
3708 continue;
3709 // Determine whether the original funclet pad is exited,
3710 // and if we are scanning nested pads determine how many
3711 // of them are exited so we can stop searching their
3712 // children.
3713 Value *ExitedPad = CurrentPad;
3714 ExitsFPI = false;
3715 do {
3716 if (ExitedPad == &FPI) {
3717 ExitsFPI = true;
3718 // Now we can resolve any ancestors of CurrentPad up to
3719 // FPI, but not including FPI since we need to make sure
3720 // to check all direct users of FPI for consistency.
3721 UnresolvedAncestorPad = &FPI;
3722 break;
3723 }
3724 Value *ExitedParent = getParentPad(ExitedPad);
3725 if (ExitedParent == UnwindParent) {
3726 // ExitedPad is the ancestor-most pad which this unwind
3727 // edge exits, so we can resolve up to it, meaning that
3728 // ExitedParent is the first ancestor still unresolved.
3729 UnresolvedAncestorPad = ExitedParent;
3730 break;
3731 }
3732 ExitedPad = ExitedParent;
3733 } while (!isa<ConstantTokenNone>(ExitedPad));
3734 } else {
3735 // Unwinding to caller exits all pads.
3736 UnwindPad = ConstantTokenNone::get(FPI.getContext());
3737 ExitsFPI = true;
3738 UnresolvedAncestorPad = &FPI;
3739 }
3740
3741 if (ExitsFPI) {
3742 // This unwind edge exits FPI. Make sure it agrees with other
3743 // such edges.
3744 if (FirstUser) {
3745 Assert(UnwindPad == FirstUnwindPad, "Unwind edges out of a funclet "do { if (!(UnwindPad == FirstUnwindPad)) { CheckFailed("Unwind edges out of a funclet "
"pad must have the same unwind " "dest", &FPI, U, FirstUser
); return; } } while (false)
3746 "pad must have the same unwind "do { if (!(UnwindPad == FirstUnwindPad)) { CheckFailed("Unwind edges out of a funclet "
"pad must have the same unwind " "dest", &FPI, U, FirstUser
); return; } } while (false)
3747 "dest",do { if (!(UnwindPad == FirstUnwindPad)) { CheckFailed("Unwind edges out of a funclet "
"pad must have the same unwind " "dest", &FPI, U, FirstUser
); return; } } while (false)
3748 &FPI, U, FirstUser)do { if (!(UnwindPad == FirstUnwindPad)) { CheckFailed("Unwind edges out of a funclet "
"pad must have the same unwind " "dest", &FPI, U, FirstUser
); return; } } while (false)
;
3749 } else {
3750 FirstUser = U;
3751 FirstUnwindPad = UnwindPad;
3752 // Record cleanup sibling unwinds for verifySiblingFuncletUnwinds
3753 if (isa<CleanupPadInst>(&FPI) && !isa<ConstantTokenNone>(UnwindPad) &&
3754 getParentPad(UnwindPad) == getParentPad(&FPI))
3755 SiblingFuncletInfo[&FPI] = cast<Instruction>(U);
3756 }
3757 }
3758 // Make sure we visit all uses of FPI, but for nested pads stop as
3759 // soon as we know where they unwind to.
3760 if (CurrentPad != &FPI)
3761 break;
3762 }
3763 if (UnresolvedAncestorPad) {
3764 if (CurrentPad == UnresolvedAncestorPad) {
3765 // When CurrentPad is FPI itself, we don't mark it as resolved even if
3766 // we've found an unwind edge that exits it, because we need to verify
3767 // all direct uses of FPI.
3768 assert(CurrentPad == &FPI)((CurrentPad == &FPI) ? static_cast<void> (0) : __assert_fail
("CurrentPad == &FPI", "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/Verifier.cpp"
, 3768, __PRETTY_FUNCTION__))
;
3769 continue;
3770 }
3771 // Pop off the worklist any nested pads that we've found an unwind
3772 // destination for. The pads on the worklist are the uncles,
3773 // great-uncles, etc. of CurrentPad. We've found an unwind destination
3774 // for all ancestors of CurrentPad up to but not including
3775 // UnresolvedAncestorPad.
3776 Value *ResolvedPad = CurrentPad;
3777 while (!Worklist.empty()) {
3778 Value *UnclePad = Worklist.back();
3779 Value *AncestorPad = getParentPad(UnclePad);
3780 // Walk ResolvedPad up the ancestor list until we either find the
3781 // uncle's parent or the last resolved ancestor.
3782 while (ResolvedPad != AncestorPad) {
3783 Value *ResolvedParent = getParentPad(ResolvedPad);
3784 if (ResolvedParent == UnresolvedAncestorPad) {
3785 break;
3786 }
3787 ResolvedPad = ResolvedParent;
3788 }
3789 // If the resolved ancestor search didn't find the uncle's parent,
3790 // then the uncle is not yet resolved.
3791 if (ResolvedPad != AncestorPad)
3792 break;
3793 // This uncle is resolved, so pop it from the worklist.
3794 Worklist.pop_back();
3795 }
3796 }
3797 }
3798
3799 if (FirstUnwindPad) {
3800 if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(FPI.getParentPad())) {
3801 BasicBlock *SwitchUnwindDest = CatchSwitch->getUnwindDest();
3802 Value *SwitchUnwindPad;
3803 if (SwitchUnwindDest)
3804 SwitchUnwindPad = SwitchUnwindDest->getFirstNonPHI();
3805 else
3806 SwitchUnwindPad = ConstantTokenNone::get(FPI.getContext());
3807 Assert(SwitchUnwindPad == FirstUnwindPad,do { if (!(SwitchUnwindPad == FirstUnwindPad)) { CheckFailed(
"Unwind edges out of a catch must have the same unwind dest as "
"the parent catchswitch", &FPI, FirstUser, CatchSwitch);
return; } } while (false)
3808 "Unwind edges out of a catch must have the same unwind dest as "do { if (!(SwitchUnwindPad == FirstUnwindPad)) { CheckFailed(
"Unwind edges out of a catch must have the same unwind dest as "
"the parent catchswitch", &FPI, FirstUser, CatchSwitch);
return; } } while (false)
3809 "the parent catchswitch",do { if (!(SwitchUnwindPad == FirstUnwindPad)) { CheckFailed(
"Unwind edges out of a catch must have the same unwind dest as "
"the parent catchswitch", &FPI, FirstUser, CatchSwitch);
return; } } while (false)
3810 &FPI, FirstUser, CatchSwitch)do { if (!(SwitchUnwindPad == FirstUnwindPad)) { CheckFailed(
"Unwind edges out of a catch must have the same unwind dest as "
"the parent catchswitch", &FPI, FirstUser, CatchSwitch);
return; } } while (false)
;
3811 }
3812 }
3813
3814 visitInstruction(FPI);
3815}
3816
3817void Verifier::visitCatchSwitchInst(CatchSwitchInst &CatchSwitch) {
3818 BasicBlock *BB = CatchSwitch.getParent();
3819
3820 Function *F = BB->getParent();
3821 Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchSwitchInst needs to be in a function with a personality."
, &CatchSwitch); return; } } while (false)
3822 "CatchSwitchInst needs to be in a function with a personality.",do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchSwitchInst needs to be in a function with a personality."
, &CatchSwitch); return; } } while (false)
3823 &CatchSwitch)do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchSwitchInst needs to be in a function with a personality."
, &CatchSwitch); return; } } while (false)
;
3824
3825 // The catchswitch instruction must be the first non-PHI instruction in the
3826 // block.
3827 Assert(BB->getFirstNonPHI() == &CatchSwitch,do { if (!(BB->getFirstNonPHI() == &CatchSwitch)) { CheckFailed
("CatchSwitchInst not the first non-PHI instruction in the block."
, &CatchSwitch); return; } } while (false)
3828 "CatchSwitchInst not the first non-PHI instruction in the block.",do { if (!(BB->getFirstNonPHI() == &CatchSwitch)) { CheckFailed
("CatchSwitchInst not the first non-PHI instruction in the block."
, &CatchSwitch); return; } } while (false)
3829 &CatchSwitch)do { if (!(BB->getFirstNonPHI() == &CatchSwitch)) { CheckFailed
("CatchSwitchInst not the first non-PHI instruction in the block."
, &CatchSwitch); return; } } while (false)
;
3830
3831 auto *ParentPad = CatchSwitch.getParentPad();
3832 Assert(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),do { if (!(isa<ConstantTokenNone>(ParentPad) || isa<
FuncletPadInst>(ParentPad))) { CheckFailed("CatchSwitchInst has an invalid parent."
, ParentPad); return; } } while (false)
3833 "CatchSwitchInst has an invalid parent.", ParentPad)do { if (!(isa<ConstantTokenNone>(ParentPad) || isa<
FuncletPadInst>(ParentPad))) { CheckFailed("CatchSwitchInst has an invalid parent."
, ParentPad); return; } } while (false)
;
3834
3835 if (BasicBlock *UnwindDest = CatchSwitch.getUnwindDest()) {
3836 Instruction *I = UnwindDest->getFirstNonPHI();
3837 Assert(I->isEHPad() && !isa<LandingPadInst>(I),do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CatchSwitchInst must unwind to an EH block which is not a "
"landingpad.", &CatchSwitch); return; } } while (false)
3838 "CatchSwitchInst must unwind to an EH block which is not a "do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CatchSwitchInst must unwind to an EH block which is not a "
"landingpad.", &CatchSwitch); return; } } while (false)
3839 "landingpad.",do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CatchSwitchInst must unwind to an EH block which is not a "
"landingpad.", &CatchSwitch); return; } } while (false)
3840 &CatchSwitch)do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CatchSwitchInst must unwind to an EH block which is not a "
"landingpad.", &CatchSwitch); return; } } while (false)
;
3841
3842 // Record catchswitch sibling unwinds for verifySiblingFuncletUnwinds
3843 if (getParentPad(I) == ParentPad)
3844 SiblingFuncletInfo[&CatchSwitch] = &CatchSwitch;
3845 }
3846
3847 Assert(CatchSwitch.getNumHandlers() != 0,do { if (!(CatchSwitch.getNumHandlers() != 0)) { CheckFailed(
"CatchSwitchInst cannot have empty handler list", &CatchSwitch
); return; } } while (false)
3848 "CatchSwitchInst cannot have empty handler list", &CatchSwitch)do { if (!(CatchSwitch.getNumHandlers() != 0)) { CheckFailed(
"CatchSwitchInst cannot have empty handler list", &CatchSwitch
); return; } } while (false)
;
3849
3850 for (BasicBlock *Handler : CatchSwitch.handlers()) {
3851 Assert(isa<CatchPadInst>(Handler->getFirstNonPHI()),do { if (!(isa<CatchPadInst>(Handler->getFirstNonPHI
()))) { CheckFailed("CatchSwitchInst handlers must be catchpads"
, &CatchSwitch, Handler); return; } } while (false)
3852 "CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler)do { if (!(isa<CatchPadInst>(Handler->getFirstNonPHI
()))) { CheckFailed("CatchSwitchInst handlers must be catchpads"
, &CatchSwitch, Handler); return; } } while (false)
;
3853 }
3854
3855 visitEHPadPredecessors(CatchSwitch);
3856 visitTerminator(CatchSwitch);
3857}
3858
3859void Verifier::visitCleanupReturnInst(CleanupReturnInst &CRI) {
3860 Assert(isa<CleanupPadInst>(CRI.getOperand(0)),do { if (!(isa<CleanupPadInst>(CRI.getOperand(0)))) { CheckFailed
("CleanupReturnInst needs to be provided a CleanupPad", &
CRI, CRI.getOperand(0)); return; } } while (false)
3861 "CleanupReturnInst needs to be provided a CleanupPad", &CRI,do { if (!(isa<CleanupPadInst>(CRI.getOperand(0)))) { CheckFailed
("CleanupReturnInst needs to be provided a CleanupPad", &
CRI, CRI.getOperand(0)); return; } } while (false)
3862 CRI.getOperand(0))do { if (!(isa<CleanupPadInst>(CRI.getOperand(0)))) { CheckFailed
("CleanupReturnInst needs to be provided a CleanupPad", &
CRI, CRI.getOperand(0)); return; } } while (false)
;
3863
3864 if (BasicBlock *UnwindDest = CRI.getUnwindDest()) {
3865 Instruction *I = UnwindDest->getFirstNonPHI();
3866 Assert(I->isEHPad() && !isa<LandingPadInst>(I),do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CleanupReturnInst must unwind to an EH block which is not a "
"landingpad.", &CRI); return; } } while (false)
3867 "CleanupReturnInst must unwind to an EH block which is not a "do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CleanupReturnInst must unwind to an EH block which is not a "
"landingpad.", &CRI); return; } } while (false)
3868 "landingpad.",do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CleanupReturnInst must unwind to an EH block which is not a "
"landingpad.", &CRI); return; } } while (false)
3869 &CRI)do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CleanupReturnInst must unwind to an EH block which is not a "
"landingpad.", &CRI); return; } } while (false)
;
3870 }
3871
3872 visitTerminator(CRI);
3873}
3874
3875void Verifier::verifyDominatesUse(Instruction &I, unsigned i) {
3876 Instruction *Op = cast<Instruction>(I.getOperand(i));
3877 // If the we have an invalid invoke, don't try to compute the dominance.
3878 // We already reject it in the invoke specific checks and the dominance
3879 // computation doesn't handle multiple edges.
3880 if (InvokeInst *II = dyn_cast<InvokeInst>(Op)) {
3881 if (II->getNormalDest() == II->getUnwindDest())
3882 return;
3883 }
3884
3885 // Quick check whether the def has already been encountered in the same block.
3886 // PHI nodes are not checked to prevent accepting preceeding PHIs, because PHI
3887 // uses are defined to happen on the incoming edge, not at the instruction.
3888 //
3889 // FIXME: If this operand is a MetadataAsValue (wrapping a LocalAsMetadata)
3890 // wrapping an SSA value, assert that we've already encountered it. See
3891 // related FIXME in Mapper::mapLocalAsMetadata in ValueMapper.cpp.
3892 if (!isa<PHINode>(I) && InstsInThisBlock.count(Op))
3893 return;
3894
3895 const Use &U = I.getOperandUse(i);
3896 Assert(DT.dominates(Op, U),do { if (!(DT.dominates(Op, U))) { CheckFailed("Instruction does not dominate all uses!"
, Op, &I); return; } } while (false)
3897 "Instruction does not dominate all uses!", Op, &I)do { if (!(DT.dominates(Op, U))) { CheckFailed("Instruction does not dominate all uses!"
, Op, &I); return; } } while (false)
;
3898}
3899
3900void Verifier::visitDereferenceableMetadata(Instruction& I, MDNode* MD) {
3901 Assert(I.getType()->isPointerTy(), "dereferenceable, dereferenceable_or_null "do { if (!(I.getType()->isPointerTy())) { CheckFailed("dereferenceable, dereferenceable_or_null "
"apply only to pointer types", &I); return; } } while (false
)
3902 "apply only to pointer types", &I)do { if (!(I.getType()->isPointerTy())) { CheckFailed("dereferenceable, dereferenceable_or_null "
"apply only to pointer types", &I); return; } } while (false
)
;
3903 Assert(isa<LoadInst>(I),do { if (!(isa<LoadInst>(I))) { CheckFailed("dereferenceable, dereferenceable_or_null apply only to load"
" instructions, use attributes for calls or invokes", &I
); return; } } while (false)
3904 "dereferenceable, dereferenceable_or_null apply only to load"do { if (!(isa<LoadInst>(I))) { CheckFailed("dereferenceable, dereferenceable_or_null apply only to load"
" instructions, use attributes for calls or invokes", &I
); return; } } while (false)
3905 " instructions, use attributes for calls or invokes", &I)do { if (!(isa<LoadInst>(I))) { CheckFailed("dereferenceable, dereferenceable_or_null apply only to load"
" instructions, use attributes for calls or invokes", &I
); return; } } while (false)
;
3906 Assert(MD->getNumOperands() == 1, "dereferenceable, dereferenceable_or_null "do { if (!(MD->getNumOperands() == 1)) { CheckFailed("dereferenceable, dereferenceable_or_null "
"take one operand!", &I); return; } } while (false)
3907 "take one operand!", &I)do { if (!(MD->getNumOperands() == 1)) { CheckFailed("dereferenceable, dereferenceable_or_null "
"take one operand!", &I); return; } } while (false)
;
3908 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(MD->getOperand(0));
3909 Assert(CI && CI->getType()->isIntegerTy(64), "dereferenceable, "do { if (!(CI && CI->getType()->isIntegerTy(64)
)) { CheckFailed("dereferenceable, " "dereferenceable_or_null metadata value must be an i64!"
, &I); return; } } while (false)
3910 "dereferenceable_or_null metadata value must be an i64!", &I)do { if (!(CI && CI->getType()->isIntegerTy(64)
)) { CheckFailed("dereferenceable, " "dereferenceable_or_null metadata value must be an i64!"
, &I); return; } } while (false)
;
3911}
3912
3913/// verifyInstruction - Verify that an instruction is well formed.
3914///
3915void Verifier::visitInstruction(Instruction &I) {
3916 BasicBlock *BB = I.getParent();
3917 Assert(BB, "Instruction not embedded in basic block!", &I)do { if (!(BB)) { CheckFailed("Instruction not embedded in basic block!"
, &I); return; } } while (false)
;
3918
3919 if (!isa<PHINode>(I)) { // Check that non-phi nodes are not self referential
3920 for (User *U : I.users()) {
3921 Assert(U != (User *)&I || !DT.isReachableFromEntry(BB),do { if (!(U != (User *)&I || !DT.isReachableFromEntry(BB
))) { CheckFailed("Only PHI nodes may reference their own value!"
, &I); return; } } while (false)
3922 "Only PHI nodes may reference their own value!", &I)do { if (!(U != (User *)&I || !DT.isReachableFromEntry(BB
))) { CheckFailed("Only PHI nodes may reference their own value!"
, &I); return; } } while (false)
;
3923 }
3924 }
3925
3926 // Check that void typed values don't have names
3927 Assert(!I.getType()->isVoidTy() || !I.hasName(),do { if (!(!I.getType()->isVoidTy() || !I.hasName())) { CheckFailed
("Instruction has a name, but provides a void value!", &I
); return; } } while (false)
3928 "Instruction has a name, but provides a void value!", &I)do { if (!(!I.getType()->isVoidTy() || !I.hasName())) { CheckFailed
("Instruction has a name, but provides a void value!", &I
); return; } } while (false)
;
3929
3930 // Check that the return value of the instruction is either void or a legal
3931 // value type.
3932 Assert(I.getType()->isVoidTy() || I.getType()->isFirstClassType(),do { if (!(I.getType()->isVoidTy() || I.getType()->isFirstClassType
())) { CheckFailed("Instruction returns a non-scalar type!", &
I); return; } } while (false)
3933 "Instruction returns a non-scalar type!", &I)do { if (!(I.getType()->isVoidTy() || I.getType()->isFirstClassType
())) { CheckFailed("Instruction returns a non-scalar type!", &
I); return; } } while (false)
;
3934
3935 // Check that the instruction doesn't produce metadata. Calls are already
3936 // checked against the callee type.
3937 Assert(!I.getType()->isMetadataTy() || isa<CallInst>(I) || isa<InvokeInst>(I),do { if (!(!I.getType()->isMetadataTy() || isa<CallInst
>(I) || isa<InvokeInst>(I))) { CheckFailed("Invalid use of metadata!"
, &I); return; } } while (false)
3938 "Invalid use of metadata!", &I)do { if (!(!I.getType()->isMetadataTy() || isa<CallInst
>(I) || isa<InvokeInst>(I))) { CheckFailed("Invalid use of metadata!"
, &I); return; } } while (false)
;
3939
3940 // Check that all uses of the instruction, if they are instructions
3941 // themselves, actually have parent basic blocks. If the use is not an
3942 // instruction, it is an error!
3943 for (Use &U : I.uses()) {
3944 if (Instruction *Used = dyn_cast<Instruction>(U.getUser()))
3945 Assert(Used->getParent() != nullptr,do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing"
" instruction not embedded in a basic block!", &I, Used)
; return; } } while (false)
3946 "Instruction referencing"do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing"
" instruction not embedded in a basic block!", &I, Used)
; return; } } while (false)
3947 " instruction not embedded in a basic block!",do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing"
" instruction not embedded in a basic block!", &I, Used)
; return; } } while (false)
3948 &I, Used)do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing"
" instruction not embedded in a basic block!", &I, Used)
; return; } } while (false)
;
3949 else {
3950 CheckFailed("Use of instruction is not an instruction!", U);
3951 return;
3952 }
3953 }
3954
3955 // Get a pointer to the call base of the instruction if it is some form of
3956 // call.
3957 const CallBase *CBI = dyn_cast<CallBase>(&I);
3958
3959 for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) {
3960 Assert(I.getOperand(i) != nullptr, "Instruction has null operand!", &I)do { if (!(I.getOperand(i) != nullptr)) { CheckFailed("Instruction has null operand!"
, &I); return; } } while (false)
;
3961
3962 // Check to make sure that only first-class-values are operands to
3963 // instructions.
3964 if (!I.getOperand(i)->getType()->isFirstClassType()) {
3965 Assert(false, "Instruction operands must be first-class values!", &I)do { if (!(false)) { CheckFailed("Instruction operands must be first-class values!"
, &I); return; } } while (false)
;
3966 }
3967
3968 if (Function *F = dyn_cast<Function>(I.getOperand(i))) {
3969 // Check to make sure that the "address of" an intrinsic function is never
3970 // taken.
3971 Assert(!F->isIntrinsic() ||do { if (!(!F->isIntrinsic() || (CBI && &CBI->
getCalledOperandUse() == &I.getOperandUse(i)))) { CheckFailed
("Cannot take the address of an intrinsic!", &I); return;
} } while (false)
3972 (CBI && &CBI->getCalledOperandUse() == &I.getOperandUse(i)),do { if (!(!F->isIntrinsic() || (CBI && &CBI->
getCalledOperandUse() == &I.getOperandUse(i)))) { CheckFailed
("Cannot take the address of an intrinsic!", &I); return;
} } while (false)
3973 "Cannot take the address of an intrinsic!", &I)do { if (!(!F->isIntrinsic() || (CBI && &CBI->
getCalledOperandUse() == &I.getOperandUse(i)))) { CheckFailed
("Cannot take the address of an intrinsic!", &I); return;
} } while (false)
;
3974 Assert(do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
3975 !F->isIntrinsic() || isa<CallInst>(I) ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
3976 F->getIntrinsicID() == Intrinsic::donothing ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
3977 F->getIntrinsicID() == Intrinsic::coro_resume ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
3978 F->getIntrinsicID() == Intrinsic::coro_destroy ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
3979 F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
3980 F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
3981 F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint,do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
3982 "Cannot invoke an intrinsic other than donothing, patchpoint, "do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
3983 "statepoint, coro_resume or coro_destroy",do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
3984 &I)do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
;
3985 Assert(F->getParent() == &M, "Referencing function in another module!",do { if (!(F->getParent() == &M)) { CheckFailed("Referencing function in another module!"
, &I, &M, F, F->getParent()); return; } } while (false
)
3986 &I, &M, F, F->getParent())do { if (!(F->getParent() == &M)) { CheckFailed("Referencing function in another module!"
, &I, &M, F, F->getParent()); return; } } while (false
)
;
3987 } else if (BasicBlock *OpBB = dyn_cast<BasicBlock>(I.getOperand(i))) {
3988 Assert(OpBB->getParent() == BB->getParent(),do { if (!(OpBB->getParent() == BB->getParent())) { CheckFailed
("Referring to a basic block in another function!", &I); return
; } } while (false)
3989 "Referring to a basic block in another function!", &I)do { if (!(OpBB->getParent() == BB->getParent())) { CheckFailed
("Referring to a basic block in another function!", &I); return
; } } while (false)
;
3990 } else if (Argument *OpArg = dyn_cast<Argument>(I.getOperand(i))) {
3991 Assert(OpArg->getParent() == BB->getParent(),do { if (!(OpArg->getParent() == BB->getParent())) { CheckFailed
("Referring to an argument in another function!", &I); return
; } } while (false)
3992 "Referring to an argument in another function!", &I)do { if (!(OpArg->getParent() == BB->getParent())) { CheckFailed
("Referring to an argument in another function!", &I); return
; } } while (false)
;
3993 } else if (GlobalValue *GV = dyn_cast<GlobalValue>(I.getOperand(i))) {
3994 Assert(GV->getParent() == &M, "Referencing global in another module!", &I,do { if (!(GV->getParent() == &M)) { CheckFailed("Referencing global in another module!"
, &I, &M, GV, GV->getParent()); return; } } while (
false)
3995 &M, GV, GV->getParent())do { if (!(GV->getParent() == &M)) { CheckFailed("Referencing global in another module!"
, &I, &M, GV, GV->getParent()); return; } } while (
false)
;
3996 } else if (isa<Instruction>(I.getOperand(i))) {
3997 verifyDominatesUse(I, i);
3998 } else if (isa<InlineAsm>(I.getOperand(i))) {
3999 Assert(CBI && &CBI->getCalledOperandUse() == &I.getOperandUse(i),do { if (!(CBI && &CBI->getCalledOperandUse() ==
&I.getOperandUse(i))) { CheckFailed("Cannot take the address of an inline asm!"
, &I); return; } } while (false)
4000 "Cannot take the address of an inline asm!", &I)do { if (!(CBI && &CBI->getCalledOperandUse() ==
&I.getOperandUse(i))) { CheckFailed("Cannot take the address of an inline asm!"
, &I); return; } } while (false)
;
4001 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(I.getOperand(i))) {
4002 if (CE->getType()->isPtrOrPtrVectorTy() ||
4003 !DL.getNonIntegralAddressSpaces().empty()) {
4004 // If we have a ConstantExpr pointer, we need to see if it came from an
4005 // illegal bitcast. If the datalayout string specifies non-integral
4006 // address spaces then we also need to check for illegal ptrtoint and
4007 // inttoptr expressions.
4008 visitConstantExprsRecursively(CE);
4009 }
4010 }
4011 }
4012
4013 if (MDNode *MD = I.getMetadata(LLVMContext::MD_fpmath)) {
4014 Assert(I.getType()->isFPOrFPVectorTy(),do { if (!(I.getType()->isFPOrFPVectorTy())) { CheckFailed
("fpmath requires a floating point result!", &I); return;
} } while (false)
4015 "fpmath requires a floating point result!", &I)do { if (!(I.getType()->isFPOrFPVectorTy())) { CheckFailed
("fpmath requires a floating point result!", &I); return;
} } while (false)
;
4016 Assert(MD->getNumOperands() == 1, "fpmath takes one operand!", &I)do { if (!(MD->getNumOperands() == 1)) { CheckFailed("fpmath takes one operand!"
, &I); return; } } while (false)
;
4017 if (ConstantFP *CFP0 =
4018 mdconst::dyn_extract_or_null<ConstantFP>(MD->getOperand(0))) {
4019 const APFloat &Accuracy = CFP0->getValueAPF();
4020 Assert(&Accuracy.getSemantics() == &APFloat::IEEEsingle(),do { if (!(&Accuracy.getSemantics() == &APFloat::IEEEsingle
())) { CheckFailed("fpmath accuracy must have float type", &
I); return; } } while (false)
4021 "fpmath accuracy must have float type", &I)do { if (!(&Accuracy.getSemantics() == &APFloat::IEEEsingle
())) { CheckFailed("fpmath accuracy must have float type", &
I); return; } } while (false)
;
4022 Assert(Accuracy.isFiniteNonZero() && !Accuracy.isNegative(),do { if (!(Accuracy.isFiniteNonZero() && !Accuracy.isNegative
())) { CheckFailed("fpmath accuracy not a positive number!", &
I); return; } } while (false)
4023 "fpmath accuracy not a positive number!", &I)do { if (!(Accuracy.isFiniteNonZero() && !Accuracy.isNegative
())) { CheckFailed("fpmath accuracy not a positive number!", &
I); return; } } while (false)
;
4024 } else {
4025 Assert(false, "invalid fpmath accuracy!", &I)do { if (!(false)) { CheckFailed("invalid fpmath accuracy!", &
I); return; } } while (false)
;
4026 }
4027 }
4028
4029 if (MDNode *Range = I.getMetadata(LLVMContext::MD_range)) {
4030 Assert(isa<LoadInst>(I) || isa<CallInst>(I) || isa<InvokeInst>(I),do { if (!(isa<LoadInst>(I) || isa<CallInst>(I) ||
isa<InvokeInst>(I))) { CheckFailed("Ranges are only for loads, calls and invokes!"
, &I); return; } } while (false)
4031 "Ranges are only for loads, calls and invokes!", &I)do { if (!(isa<LoadInst>(I) || isa<CallInst>(I) ||
isa<InvokeInst>(I))) { CheckFailed("Ranges are only for loads, calls and invokes!"
, &I); return; } } while (false)
;
4032 visitRangeMetadata(I, Range, I.getType());
4033 }
4034
4035 if (I.getMetadata(LLVMContext::MD_nonnull)) {
4036 Assert(I.getType()->isPointerTy(), "nonnull applies only to pointer types",do { if (!(I.getType()->isPointerTy())) { CheckFailed("nonnull applies only to pointer types"
, &I); return; } } while (false)
4037 &I)do { if (!(I.getType()->isPointerTy())) { CheckFailed("nonnull applies only to pointer types"
, &I); return; } } while (false)
;
4038 Assert(isa<LoadInst>(I),do { if (!(isa<LoadInst>(I))) { CheckFailed("nonnull applies only to load instructions, use attributes"
" for calls or invokes", &I); return; } } while (false)
4039 "nonnull applies only to load instructions, use attributes"do { if (!(isa<LoadInst>(I))) { CheckFailed("nonnull applies only to load instructions, use attributes"
" for calls or invokes", &I); return; } } while (false)
4040 " for calls or invokes",do { if (!(isa<LoadInst>(I))) { CheckFailed("nonnull applies only to load instructions, use attributes"
" for calls or invokes", &I); return; } } while (false)
4041 &I)do { if (!(isa<LoadInst>(I))) { CheckFailed("nonnull applies only to load instructions, use attributes"
" for calls or invokes", &I); return; } } while (false)
;
4042 }
4043
4044 if (MDNode *MD = I.getMetadata(LLVMContext::MD_dereferenceable))
4045 visitDereferenceableMetadata(I, MD);
4046
4047 if (MDNode *MD = I.getMetadata(LLVMContext::MD_dereferenceable_or_null))
4048 visitDereferenceableMetadata(I, MD);
4049
4050 if (MDNode *TBAA = I.getMetadata(LLVMContext::MD_tbaa))
4051 TBAAVerifyHelper.visitTBAAMetadata(I, TBAA);
4052
4053 if (MDNode *AlignMD = I.getMetadata(LLVMContext::MD_align)) {
4054 Assert(I.getType()->isPointerTy(), "align applies only to pointer types",do { if (!(I.getType()->isPointerTy())) { CheckFailed("align applies only to pointer types"
, &I); return; } } while (false)
4055 &I)do { if (!(I.getType()->isPointerTy())) { CheckFailed("align applies only to pointer types"
, &I); return; } } while (false)
;
4056 Assert(isa<LoadInst>(I), "align applies only to load instructions, "do { if (!(isa<LoadInst>(I))) { CheckFailed("align applies only to load instructions, "
"use attributes for calls or invokes", &I); return; } } while
(false)
4057 "use attributes for calls or invokes", &I)do { if (!(isa<LoadInst>(I))) { CheckFailed("align applies only to load instructions, "
"use attributes for calls or invokes", &I); return; } } while
(false)
;
4058 Assert(AlignMD->getNumOperands() == 1, "align takes one operand!", &I)do { if (!(AlignMD->getNumOperands() == 1)) { CheckFailed(
"align takes one operand!", &I); return; } } while (false
)
;
4059 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(AlignMD->getOperand(0));
4060 Assert(CI && CI->getType()->isIntegerTy(64),do { if (!(CI && CI->getType()->isIntegerTy(64)
)) { CheckFailed("align metadata value must be an i64!", &
I); return; } } while (false)
4061 "align metadata value must be an i64!", &I)do { if (!(CI && CI->getType()->isIntegerTy(64)
)) { CheckFailed("align metadata value must be an i64!", &
I); return; } } while (false)
;
4062 uint64_t Align = CI->getZExtValue();
4063 Assert(isPowerOf2_64(Align),do { if (!(isPowerOf2_64(Align))) { CheckFailed("align metadata value must be a power of 2!"
, &I); return; } } while (false)
4064 "align metadata value must be a power of 2!", &I)do { if (!(isPowerOf2_64(Align))) { CheckFailed("align metadata value must be a power of 2!"
, &I); return; } } while (false)
;
4065 Assert(Align <= Value::MaximumAlignment,do { if (!(Align <= Value::MaximumAlignment)) { CheckFailed
("alignment is larger that implementation defined limit", &
I); return; } } while (false)
4066 "alignment is larger that implementation defined limit", &I)do { if (!(Align <= Value::MaximumAlignment)) { CheckFailed
("alignment is larger that implementation defined limit", &
I); return; } } while (false)
;
4067 }
4068
4069 if (MDNode *N = I.getDebugLoc().getAsMDNode()) {
4070 AssertDI(isa<DILocation>(N), "invalid !dbg metadata attachment", &I, N)do { if (!(isa<DILocation>(N))) { DebugInfoCheckFailed(
"invalid !dbg metadata attachment", &I, N); return; } } while
(false)
;
4071 visitMDNode(*N);
4072 }
4073
4074 if (auto *DII = dyn_cast<DbgVariableIntrinsic>(&I))
4075 verifyFragmentExpression(*DII);
4076
4077 InstsInThisBlock.insert(&I);
4078}
4079
4080/// Allow intrinsics to be verified in different ways.
4081void Verifier::visitIntrinsicCallSite(Intrinsic::ID ID, CallSite CS) {
4082 Function *IF = CS.getCalledFunction();
4083 Assert(IF->isDeclaration(), "Intrinsic functions should never be defined!",do { if (!(IF->isDeclaration())) { CheckFailed("Intrinsic functions should never be defined!"
, IF); return; } } while (false)
4084 IF)do { if (!(IF->isDeclaration())) { CheckFailed("Intrinsic functions should never be defined!"
, IF); return; } } while (false)
;
4085
4086 // Verify that the intrinsic prototype lines up with what the .td files
4087 // describe.
4088 FunctionType *IFTy = IF->getFunctionType();
4089 bool IsVarArg = IFTy->isVarArg();
4090
4091 SmallVector<Intrinsic::IITDescriptor, 8> Table;
4092 getIntrinsicInfoTableEntries(ID, Table);
4093 ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
4094
4095 SmallVector<Type *, 4> ArgTys;
4096 Assert(!Intrinsic::matchIntrinsicType(IFTy->getReturnType(),do { if (!(!Intrinsic::matchIntrinsicType(IFTy->getReturnType
(), TableRef, ArgTys))) { CheckFailed("Intrinsic has incorrect return type!"
, IF); return; } } while (false)
4097 TableRef, ArgTys),do { if (!(!Intrinsic::matchIntrinsicType(IFTy->getReturnType
(), TableRef, ArgTys))) { CheckFailed("Intrinsic has incorrect return type!"
, IF); return; } } while (false)
4098 "Intrinsic has incorrect return type!", IF)do { if (!(!Intrinsic::matchIntrinsicType(IFTy->getReturnType
(), TableRef, ArgTys))) { CheckFailed("Intrinsic has incorrect return type!"
, IF); return; } } while (false)
;
4099 for (unsigned i = 0, e = IFTy->getNumParams(); i != e; ++i)
4100 Assert(!Intrinsic::matchIntrinsicType(IFTy->getParamType(i),do { if (!(!Intrinsic::matchIntrinsicType(IFTy->getParamType
(i), TableRef, ArgTys))) { CheckFailed("Intrinsic has incorrect argument type!"
, IF); return; } } while (false)
4101 TableRef, ArgTys),do { if (!(!Intrinsic::matchIntrinsicType(IFTy->getParamType
(i), TableRef, ArgTys))) { CheckFailed("Intrinsic has incorrect argument type!"
, IF); return; } } while (false)
4102 "Intrinsic has incorrect argument type!", IF)do { if (!(!Intrinsic::matchIntrinsicType(IFTy->getParamType
(i), TableRef, ArgTys))) { CheckFailed("Intrinsic has incorrect argument type!"
, IF); return; } } while (false)
;
4103
4104 // Verify if the intrinsic call matches the vararg property.
4105 if (IsVarArg)
4106 Assert(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef),do { if (!(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef
))) { CheckFailed("Intrinsic was not defined with variable arguments!"
, IF); return; } } while (false)
4107 "Intrinsic was not defined with variable arguments!", IF)do { if (!(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef
))) { CheckFailed("Intrinsic was not defined with variable arguments!"
, IF); return; } } while (false)
;
4108 else
4109 Assert(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef),do { if (!(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef
))) { CheckFailed("Callsite was not defined with variable arguments!"
, IF); return; } } while (false)
4110 "Callsite was not defined with variable arguments!", IF)do { if (!(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef
))) { CheckFailed("Callsite was not defined with variable arguments!"
, IF); return; } } while (false)
;
4111
4112 // All descriptors should be absorbed by now.
4113 Assert(TableRef.empty(), "Intrinsic has too few arguments!", IF)do { if (!(TableRef.empty())) { CheckFailed("Intrinsic has too few arguments!"
, IF); return; } } while (false)
;
4114
4115 // Now that we have the intrinsic ID and the actual argument types (and we
4116 // know they are legal for the intrinsic!) get the intrinsic name through the
4117 // usual means. This allows us to verify the mangling of argument types into
4118 // the name.
4119 const std::string ExpectedName = Intrinsic::getName(ID, ArgTys);
4120 Assert(ExpectedName == IF->getName(),do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! "
"Should be: " + ExpectedName, IF); return; } } while (false)
4121 "Intrinsic name not mangled correctly for type arguments! "do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! "
"Should be: " + ExpectedName, IF); return; } } while (false)
4122 "Should be: " +do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! "
"Should be: " + ExpectedName, IF); return; } } while (false)
4123 ExpectedName,do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! "
"Should be: " + ExpectedName, IF); return; } } while (false)
4124 IF)do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! "
"Should be: " + ExpectedName, IF); return; } } while (false)
;
4125
4126 // If the intrinsic takes MDNode arguments, verify that they are either global
4127 // or are local to *this* function.
4128 for (Value *V : CS.args())
4129 if (auto *MD = dyn_cast<MetadataAsValue>(V))
4130 visitMetadataAsValue(*MD, CS.getCaller());
4131
4132 switch (ID) {
4133 default:
4134 break;
4135 case Intrinsic::coro_id: {
4136 auto *InfoArg = CS.getArgOperand(3)->stripPointerCasts();
4137 if (isa<ConstantPointerNull>(InfoArg))
4138 break;
4139 auto *GV = dyn_cast<GlobalVariable>(InfoArg);
4140 Assert(GV && GV->isConstant() && GV->hasDefinitiveInitializer(),do { if (!(GV && GV->isConstant() && GV->
hasDefinitiveInitializer())) { CheckFailed("info argument of llvm.coro.begin must refer to an initialized "
"constant"); return; } } while (false)
4141 "info argument of llvm.coro.begin must refer to an initialized "do { if (!(GV && GV->isConstant() && GV->
hasDefinitiveInitializer())) { CheckFailed("info argument of llvm.coro.begin must refer to an initialized "
"constant"); return; } } while (false)
4142 "constant")do { if (!(GV && GV->isConstant() && GV->
hasDefinitiveInitializer())) { CheckFailed("info argument of llvm.coro.begin must refer to an initialized "
"constant"); return; } } while (false)
;
4143 Constant *Init = GV->getInitializer();
4144 Assert(isa<ConstantStruct>(Init) || isa<ConstantArray>(Init),do { if (!(isa<ConstantStruct>(Init) || isa<ConstantArray
>(Init))) { CheckFailed("info argument of llvm.coro.begin must refer to either a struct or "
"an array"); return; } } while (false)
4145 "info argument of llvm.coro.begin must refer to either a struct or "do { if (!(isa<ConstantStruct>(Init) || isa<ConstantArray
>(Init))) { CheckFailed("info argument of llvm.coro.begin must refer to either a struct or "
"an array"); return; } } while (false)
4146 "an array")do { if (!(isa<ConstantStruct>(Init) || isa<ConstantArray
>(Init))) { CheckFailed("info argument of llvm.coro.begin must refer to either a struct or "
"an array"); return; } } while (false)
;
4147 break;
4148 }
4149 case Intrinsic::ctlz: // llvm.ctlz
4150 case Intrinsic::cttz: // llvm.cttz
4151 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 (false)
4152 "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 (false)
4153 "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 (false)
4154 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 (false)
;
4155 break;
4156 case Intrinsic::experimental_constrained_fadd:
4157 case Intrinsic::experimental_constrained_fsub:
4158 case Intrinsic::experimental_constrained_fmul:
4159 case Intrinsic::experimental_constrained_fdiv:
4160 case Intrinsic::experimental_constrained_frem:
4161 case Intrinsic::experimental_constrained_fma:
4162 case Intrinsic::experimental_constrained_sqrt:
4163 case Intrinsic::experimental_constrained_pow:
4164 case Intrinsic::experimental_constrained_powi:
4165 case Intrinsic::experimental_constrained_sin:
4166 case Intrinsic::experimental_constrained_cos:
4167 case Intrinsic::experimental_constrained_exp:
4168 case Intrinsic::experimental_constrained_exp2:
4169 case Intrinsic::experimental_constrained_log:
4170 case Intrinsic::experimental_constrained_log10:
4171 case Intrinsic::experimental_constrained_log2:
4172 case Intrinsic::experimental_constrained_rint:
4173 case Intrinsic::experimental_constrained_nearbyint:
4174 case Intrinsic::experimental_constrained_maxnum:
4175 case Intrinsic::experimental_constrained_minnum:
4176 case Intrinsic::experimental_constrained_ceil:
4177 case Intrinsic::experimental_constrained_floor:
4178 case Intrinsic::experimental_constrained_round:
4179 case Intrinsic::experimental_constrained_trunc:
4180 visitConstrainedFPIntrinsic(
4181 cast<ConstrainedFPIntrinsic>(*CS.getInstruction()));
4182 break;
4183 case Intrinsic::dbg_declare: // llvm.dbg.declare
4184 Assert(isa<MetadataAsValue>(CS.getArgOperand(0)),do { if (!(isa<MetadataAsValue>(CS.getArgOperand(0)))) {
CheckFailed("invalid llvm.dbg.declare intrinsic call 1", CS)
; return; } } while (false)
4185 "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 (false)
;
4186 visitDbgIntrinsic("declare", cast<DbgVariableIntrinsic>(*CS.getInstruction()));
4187 break;
4188 case Intrinsic::dbg_addr: // llvm.dbg.addr
4189 visitDbgIntrinsic("addr", cast<DbgVariableIntrinsic>(*CS.getInstruction()));
4190 break;
4191 case Intrinsic::dbg_value: // llvm.dbg.value
4192 visitDbgIntrinsic("value", cast<DbgVariableIntrinsic>(*CS.getInstruction()));
4193 break;
4194 case Intrinsic::dbg_label: // llvm.dbg.label
4195 visitDbgLabelIntrinsic("label", cast<DbgLabelInst>(*CS.getInstruction()));
4196 break;
4197 case Intrinsic::memcpy:
4198 case Intrinsic::memmove:
4199 case Intrinsic::memset: {