Bug Summary

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