Bug Summary

File:llvm/lib/IR/Verifier.cpp
Warning:line 2595, 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 -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 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/build-llvm/lib/IR -resource-dir /usr/lib/llvm-13/lib/clang/13.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/build-llvm/lib/IR -I /build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/llvm/lib/IR -I /build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/build-llvm/include -I /build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/llvm/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/lib/llvm-13/lib/clang/13.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/build-llvm/lib/IR -fdebug-prefix-map=/build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f=. -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -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-2021-04-14-063029-18377-1 -x c++ /build/llvm-toolchain-snapshot-13~++20210413100635+64c24f493e5f/llvm/lib/IR/Verifier.cpp

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