Bug Summary

File:llvm/lib/IR/Verifier.cpp
Warning:line 2658, column 5
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -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 -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-14~++20220116100644+5f782d25a742/build-llvm -resource-dir /usr/lib/llvm-14/lib/clang/14.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I lib/IR -I /build/llvm-toolchain-snapshot-14~++20220116100644+5f782d25a742/llvm/lib/IR -I include -I /build/llvm-toolchain-snapshot-14~++20220116100644+5f782d25a742/llvm/include -D _FORTIFY_SOURCE=2 -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/build/llvm-toolchain-snapshot-14~++20220116100644+5f782d25a742/build-llvm=build-llvm -fmacro-prefix-map=/build/llvm-toolchain-snapshot-14~++20220116100644+5f782d25a742/= -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-14~++20220116100644+5f782d25a742/build-llvm=build-llvm -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-14~++20220116100644+5f782d25a742/= -O3 -Wno-unused-command-line-argument -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-14~++20220116100644+5f782d25a742/build-llvm -fdebug-prefix-map=/build/llvm-toolchain-snapshot-14~++20220116100644+5f782d25a742/build-llvm=build-llvm -fdebug-prefix-map=/build/llvm-toolchain-snapshot-14~++20220116100644+5f782d25a742/= -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-01-16-232930-107970-1 -x c++ /build/llvm-toolchain-snapshot-14~++20220116100644+5f782d25a742/llvm/lib/IR/Verifier.cpp

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