Bug Summary

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

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name Verifier.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=none -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-11/lib/clang/11.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/lib/IR -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/include -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/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/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-11/lib/clang/11.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/lib/IR -fdebug-prefix-map=/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347=. -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -o /tmp/scan-build-2020-03-09-184146-41876-1 -x c++ /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/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
118namespace llvm {
119
120struct VerifierSupport {
121 raw_ostream *OS;
122 const Module &M;
123 ModuleSlotTracker MST;
124 Triple TT;
125 const DataLayout &DL;
126 LLVMContext &Context;
127
128 /// Track the brokenness of the module while recursively visiting.
129 bool Broken = false;
130 /// Broken debug info can be "recovered" from by stripping the debug info.
131 bool BrokenDebugInfo = false;
132 /// Whether to treat broken debug info as an error.
133 bool TreatBrokenDebugInfoAsError = true;
134
135 explicit VerifierSupport(raw_ostream *OS, const Module &M)
136 : OS(OS), M(M), MST(&M), TT(M.getTargetTriple()), DL(M.getDataLayout()),
137 Context(M.getContext()) {}
138
139private:
140 void Write(const Module *M) {
141 *OS << "; ModuleID = '" << M->getModuleIdentifier() << "'\n";
142 }
143
144 void Write(const Value *V) {
145 if (V)
146 Write(*V);
147 }
148
149 void Write(const Value &V) {
150 if (isa<Instruction>(V)) {
151 V.print(*OS, MST);
152 *OS << '\n';
153 } else {
154 V.printAsOperand(*OS, true, MST);
155 *OS << '\n';
156 }
157 }
158
159 void Write(const Metadata *MD) {
160 if (!MD)
161 return;
162 MD->print(*OS, MST, &M);
163 *OS << '\n';
164 }
165
166 template <class T> void Write(const MDTupleTypedArrayWrapper<T> &MD) {
167 Write(MD.get());
168 }
169
170 void Write(const NamedMDNode *NMD) {
171 if (!NMD)
172 return;
173 NMD->print(*OS, MST);
174 *OS << '\n';
175 }
176
177 void Write(Type *T) {
178 if (!T)
179 return;
180 *OS << ' ' << *T;
181 }
182
183 void Write(const Comdat *C) {
184 if (!C)
185 return;
186 *OS << *C;
187 }
188
189 void Write(const APInt *AI) {
190 if (!AI)
191 return;
192 *OS << *AI << '\n';
193 }
194
195 void Write(const unsigned i) { *OS << i << '\n'; }
196
197 template <typename T> void Write(ArrayRef<T> Vs) {
198 for (const T &V : Vs)
199 Write(V);
200 }
201
202 template <typename T1, typename... Ts>
203 void WriteTs(const T1 &V1, const Ts &... Vs) {
204 Write(V1);
205 WriteTs(Vs...);
206 }
207
208 template <typename... Ts> void WriteTs() {}
209
210public:
211 /// A check failed, so printout out the condition and the message.
212 ///
213 /// This provides a nice place to put a breakpoint if you want to see why
214 /// something is not correct.
215 void CheckFailed(const Twine &Message) {
216 if (OS)
217 *OS << Message << '\n';
218 Broken = true;
219 }
220
221 /// A check failed (with values to print).
222 ///
223 /// This calls the Message-only version so that the above is easier to set a
224 /// breakpoint on.
225 template <typename T1, typename... Ts>
226 void CheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs) {
227 CheckFailed(Message);
228 if (OS)
229 WriteTs(V1, Vs...);
230 }
231
232 /// A debug info check failed.
233 void DebugInfoCheckFailed(const Twine &Message) {
234 if (OS)
235 *OS << Message << '\n';
236 Broken |= TreatBrokenDebugInfoAsError;
237 BrokenDebugInfo = true;
238 }
239
240 /// A debug info check failed (with values to print).
241 template <typename T1, typename... Ts>
242 void DebugInfoCheckFailed(const Twine &Message, const T1 &V1,
243 const Ts &... Vs) {
244 DebugInfoCheckFailed(Message);
245 if (OS)
246 WriteTs(V1, Vs...);
247 }
248};
249
250} // namespace llvm
251
252namespace {
253
254class Verifier : public InstVisitor<Verifier>, VerifierSupport {
255 friend class InstVisitor<Verifier>;
256
257 DominatorTree DT;
258
259 /// When verifying a basic block, keep track of all of the
260 /// instructions we have seen so far.
261 ///
262 /// This allows us to do efficient dominance checks for the case when an
263 /// instruction has an operand that is an instruction in the same block.
264 SmallPtrSet<Instruction *, 16> InstsInThisBlock;
265
266 /// Keep track of the metadata nodes that have been checked already.
267 SmallPtrSet<const Metadata *, 32> MDNodes;
268
269 /// Keep track which DISubprogram is attached to which function.
270 DenseMap<const DISubprogram *, const Function *> DISubprogramAttachments;
271
272 /// Track all DICompileUnits visited.
273 SmallPtrSet<const Metadata *, 2> CUVisited;
274
275 /// The result type for a landingpad.
276 Type *LandingPadResultTy;
277
278 /// Whether we've seen a call to @llvm.localescape in this function
279 /// already.
280 bool SawFrameEscape;
281
282 /// Whether the current function has a DISubprogram attached to it.
283 bool HasDebugInfo = false;
284
285 /// Whether source was present on the first DIFile encountered in each CU.
286 DenseMap<const DICompileUnit *, bool> HasSourceDebugInfo;
287
288 /// Stores the count of how many objects were passed to llvm.localescape for a
289 /// given function and the largest index passed to llvm.localrecover.
290 DenseMap<Function *, std::pair<unsigned, unsigned>> FrameEscapeInfo;
291
292 // Maps catchswitches and cleanuppads that unwind to siblings to the
293 // terminators that indicate the unwind, used to detect cycles therein.
294 MapVector<Instruction *, Instruction *> SiblingFuncletInfo;
295
296 /// Cache of constants visited in search of ConstantExprs.
297 SmallPtrSet<const Constant *, 32> ConstantExprVisited;
298
299 /// Cache of declarations of the llvm.experimental.deoptimize.<ty> intrinsic.
300 SmallVector<const Function *, 4> DeoptimizeDeclarations;
301
302 // Verify that this GlobalValue is only used in this module.
303 // This map is used to avoid visiting uses twice. We can arrive at a user
304 // twice, if they have multiple operands. In particular for very large
305 // constant expressions, we can arrive at a particular user many times.
306 SmallPtrSet<const Value *, 32> GlobalValueVisited;
307
308 // Keeps track of duplicate function argument debug info.
309 SmallVector<const DILocalVariable *, 16> DebugFnArgs;
310
311 TBAAVerifier TBAAVerifyHelper;
312
313 void checkAtomicMemAccessSize(Type *Ty, const Instruction *I);
314
315public:
316 explicit Verifier(raw_ostream *OS, bool ShouldTreatBrokenDebugInfoAsError,
317 const Module &M)
318 : VerifierSupport(OS, M), LandingPadResultTy(nullptr),
319 SawFrameEscape(false), TBAAVerifyHelper(this) {
320 TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError;
321 }
322
323 bool hasBrokenDebugInfo() const { return BrokenDebugInfo; }
324
325 bool verify(const Function &F) {
326 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-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 327, __PRETTY_FUNCTION__))
327 "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-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 327, __PRETTY_FUNCTION__))
;
328
329 // First ensure the function is well-enough formed to compute dominance
330 // information, and directly compute a dominance tree. We don't rely on the
331 // pass manager to provide this as it isolates us from a potentially
332 // out-of-date dominator tree and makes it significantly more complex to run
333 // this code outside of a pass manager.
334 // FIXME: It's really gross that we have to cast away constness here.
335 if (!F.empty())
336 DT.recalculate(const_cast<Function &>(F));
337
338 for (const BasicBlock &BB : F) {
339 if (!BB.empty() && BB.back().isTerminator())
340 continue;
341
342 if (OS) {
343 *OS << "Basic Block in function '" << F.getName()
344 << "' does not have terminator!\n";
345 BB.printAsOperand(*OS, true, MST);
346 *OS << "\n";
347 }
348 return false;
349 }
350
351 Broken = false;
352 // FIXME: We strip const here because the inst visitor strips const.
353 visit(const_cast<Function &>(F));
354 verifySiblingFuncletUnwinds();
355 InstsInThisBlock.clear();
356 DebugFnArgs.clear();
357 LandingPadResultTy = nullptr;
358 SawFrameEscape = false;
359 SiblingFuncletInfo.clear();
360
361 return !Broken;
362 }
363
364 /// Verify the module that this instance of \c Verifier was initialized with.
365 bool verify() {
366 Broken = false;
367
368 // Collect all declarations of the llvm.experimental.deoptimize intrinsic.
369 for (const Function &F : M)
370 if (F.getIntrinsicID() == Intrinsic::experimental_deoptimize)
371 DeoptimizeDeclarations.push_back(&F);
372
373 // Now that we've visited every function, verify that we never asked to
374 // recover a frame index that wasn't escaped.
375 verifyFrameRecoverIndices();
376 for (const GlobalVariable &GV : M.globals())
377 visitGlobalVariable(GV);
378
379 for (const GlobalAlias &GA : M.aliases())
380 visitGlobalAlias(GA);
381
382 for (const NamedMDNode &NMD : M.named_metadata())
383 visitNamedMDNode(NMD);
384
385 for (const StringMapEntry<Comdat> &SMEC : M.getComdatSymbolTable())
386 visitComdat(SMEC.getValue());
387
388 visitModuleFlags(M);
389 visitModuleIdents(M);
390 visitModuleCommandLines(M);
391
392 verifyCompileUnits();
393
394 verifyDeoptimizeCallingConvs();
395 DISubprogramAttachments.clear();
396 return !Broken;
397 }
398
399private:
400 // Verification methods...
401 void visitGlobalValue(const GlobalValue &GV);
402 void visitGlobalVariable(const GlobalVariable &GV);
403 void visitGlobalAlias(const GlobalAlias &GA);
404 void visitAliaseeSubExpr(const GlobalAlias &A, const Constant &C);
405 void visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias *> &Visited,
406 const GlobalAlias &A, const Constant &C);
407 void visitNamedMDNode(const NamedMDNode &NMD);
408 void visitMDNode(const MDNode &MD);
409 void visitMetadataAsValue(const MetadataAsValue &MD, Function *F);
410 void visitValueAsMetadata(const ValueAsMetadata &MD, Function *F);
411 void visitComdat(const Comdat &C);
412 void visitModuleIdents(const Module &M);
413 void visitModuleCommandLines(const Module &M);
414 void visitModuleFlags(const Module &M);
415 void visitModuleFlag(const MDNode *Op,
416 DenseMap<const MDString *, const MDNode *> &SeenIDs,
417 SmallVectorImpl<const MDNode *> &Requirements);
418 void visitModuleFlagCGProfileEntry(const MDOperand &MDO);
419 void visitFunction(const Function &F);
420 void visitBasicBlock(BasicBlock &BB);
421 void visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty);
422 void visitDereferenceableMetadata(Instruction &I, MDNode *MD);
423 void visitProfMetadata(Instruction &I, MDNode *MD);
424
425 template <class Ty> bool isValidMetadataArray(const MDTuple &N);
426#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N);
427#include "llvm/IR/Metadata.def"
428 void visitDIScope(const DIScope &N);
429 void visitDIVariable(const DIVariable &N);
430 void visitDILexicalBlockBase(const DILexicalBlockBase &N);
431 void visitDITemplateParameter(const DITemplateParameter &N);
432
433 void visitTemplateParams(const MDNode &N, const Metadata &RawParams);
434
435 // InstVisitor overrides...
436 using InstVisitor<Verifier>::visit;
437 void visit(Instruction &I);
438
439 void visitTruncInst(TruncInst &I);
440 void visitZExtInst(ZExtInst &I);
441 void visitSExtInst(SExtInst &I);
442 void visitFPTruncInst(FPTruncInst &I);
443 void visitFPExtInst(FPExtInst &I);
444 void visitFPToUIInst(FPToUIInst &I);
445 void visitFPToSIInst(FPToSIInst &I);
446 void visitUIToFPInst(UIToFPInst &I);
447 void visitSIToFPInst(SIToFPInst &I);
448 void visitIntToPtrInst(IntToPtrInst &I);
449 void visitPtrToIntInst(PtrToIntInst &I);
450 void visitBitCastInst(BitCastInst &I);
451 void visitAddrSpaceCastInst(AddrSpaceCastInst &I);
452 void visitPHINode(PHINode &PN);
453 void visitCallBase(CallBase &Call);
454 void visitUnaryOperator(UnaryOperator &U);
455 void visitBinaryOperator(BinaryOperator &B);
456 void visitICmpInst(ICmpInst &IC);
457 void visitFCmpInst(FCmpInst &FC);
458 void visitExtractElementInst(ExtractElementInst &EI);
459 void visitInsertElementInst(InsertElementInst &EI);
460 void visitShuffleVectorInst(ShuffleVectorInst &EI);
461 void visitVAArgInst(VAArgInst &VAA) { visitInstruction(VAA); }
462 void visitCallInst(CallInst &CI);
463 void visitInvokeInst(InvokeInst &II);
464 void visitGetElementPtrInst(GetElementPtrInst &GEP);
465 void visitLoadInst(LoadInst &LI);
466 void visitStoreInst(StoreInst &SI);
467 void verifyDominatesUse(Instruction &I, unsigned i);
468 void visitInstruction(Instruction &I);
469 void visitTerminator(Instruction &I);
470 void visitBranchInst(BranchInst &BI);
471 void visitReturnInst(ReturnInst &RI);
472 void visitSwitchInst(SwitchInst &SI);
473 void visitIndirectBrInst(IndirectBrInst &BI);
474 void visitCallBrInst(CallBrInst &CBI);
475 void visitSelectInst(SelectInst &SI);
476 void visitUserOp1(Instruction &I);
477 void visitUserOp2(Instruction &I) { visitUserOp1(I); }
478 void visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call);
479 void visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI);
480 void visitDbgIntrinsic(StringRef Kind, DbgVariableIntrinsic &DII);
481 void visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI);
482 void visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI);
483 void visitAtomicRMWInst(AtomicRMWInst &RMWI);
484 void visitFenceInst(FenceInst &FI);
485 void visitAllocaInst(AllocaInst &AI);
486 void visitExtractValueInst(ExtractValueInst &EVI);
487 void visitInsertValueInst(InsertValueInst &IVI);
488 void visitEHPadPredecessors(Instruction &I);
489 void visitLandingPadInst(LandingPadInst &LPI);
490 void visitResumeInst(ResumeInst &RI);
491 void visitCatchPadInst(CatchPadInst &CPI);
492 void visitCatchReturnInst(CatchReturnInst &CatchReturn);
493 void visitCleanupPadInst(CleanupPadInst &CPI);
494 void visitFuncletPadInst(FuncletPadInst &FPI);
495 void visitCatchSwitchInst(CatchSwitchInst &CatchSwitch);
496 void visitCleanupReturnInst(CleanupReturnInst &CRI);
497
498 void verifySwiftErrorCall(CallBase &Call, const Value *SwiftErrorVal);
499 void verifySwiftErrorValue(const Value *SwiftErrorVal);
500 void verifyMustTailCall(CallInst &CI);
501 bool performTypeCheck(Intrinsic::ID ID, Function *F, Type *Ty, int VT,
502 unsigned ArgNo, std::string &Suffix);
503 bool verifyAttributeCount(AttributeList Attrs, unsigned Params);
504 void verifyAttributeTypes(AttributeSet Attrs, bool IsFunction,
505 const Value *V);
506 void verifyParameterAttrs(AttributeSet Attrs, Type *Ty, const Value *V);
507 void verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
508 const Value *V, bool IsIntrinsic);
509 void verifyFunctionMetadata(ArrayRef<std::pair<unsigned, MDNode *>> MDs);
510
511 void visitConstantExprsRecursively(const Constant *EntryC);
512 void visitConstantExpr(const ConstantExpr *CE);
513 void verifyStatepoint(const CallBase &Call);
514 void verifyFrameRecoverIndices();
515 void verifySiblingFuncletUnwinds();
516
517 void verifyFragmentExpression(const DbgVariableIntrinsic &I);
518 template <typename ValueOrMetadata>
519 void verifyFragmentExpression(const DIVariable &V,
520 DIExpression::FragmentInfo Fragment,
521 ValueOrMetadata *Desc);
522 void verifyFnArgs(const DbgVariableIntrinsic &I);
523 void verifyNotEntryValue(const DbgVariableIntrinsic &I);
524
525 /// Module-level debug info verification...
526 void verifyCompileUnits();
527
528 /// Module-level verification that all @llvm.experimental.deoptimize
529 /// declarations share the same calling convention.
530 void verifyDeoptimizeCallingConvs();
531
532 /// Verify all-or-nothing property of DIFile source attribute within a CU.
533 void verifySourceDebugInfo(const DICompileUnit &U, const DIFile &F);
534};
535
536} // end anonymous namespace
537
538/// We know that cond should be true, if not print an error message.
539#define Assert(C, ...)do { if (!(C)) { CheckFailed(...); return; } } while (false) \
540 do { if (!(C)) { CheckFailed(__VA_ARGS__); return; } } while (false)
541
542/// We know that a debug info condition should be true, if not print
543/// an error message.
544#define AssertDI(C, ...)do { if (!(C)) { DebugInfoCheckFailed(...); return; } } while
(false)
\
545 do { if (!(C)) { DebugInfoCheckFailed(__VA_ARGS__); return; } } while (false)
546
547void Verifier::visit(Instruction &I) {
548 for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i)
549 Assert(I.getOperand(i) != nullptr, "Operand is null", &I)do { if (!(I.getOperand(i) != nullptr)) { CheckFailed("Operand is null"
, &I); return; } } while (false)
;
550 InstVisitor<Verifier>::visit(I);
551}
552
553// Helper to recursively iterate over indirect users. By
554// returning false, the callback can ask to stop recursing
555// further.
556static void forEachUser(const Value *User,
557 SmallPtrSet<const Value *, 32> &Visited,
558 llvm::function_ref<bool(const Value *)> Callback) {
559 if (!Visited.insert(User).second)
560 return;
561 for (const Value *TheNextUser : User->materialized_users())
562 if (Callback(TheNextUser))
563 forEachUser(TheNextUser, Visited, Callback);
564}
565
566void Verifier::visitGlobalValue(const GlobalValue &GV) {
567 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)
568 "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)
;
569
570 Assert(GV.getAlignment() <= Value::MaximumAlignment,do { if (!(GV.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &GV
); return; } } while (false)
571 "huge alignment values are unsupported", &GV)do { if (!(GV.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &GV
); return; } } while (false)
;
572 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)
573 "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)
;
574
575 if (GV.hasAppendingLinkage()) {
576 const GlobalVariable *GVar = dyn_cast<GlobalVariable>(&GV);
577 Assert(GVar && GVar->getValueType()->isArrayTy(),do { if (!(GVar && GVar->getValueType()->isArrayTy
())) { CheckFailed("Only global arrays can have appending linkage!"
, GVar); return; } } while (false)
578 "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)
;
579 }
580
581 if (GV.isDeclarationForLinker())
582 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)
;
583
584 if (GV.hasDLLImportStorageClass()) {
585 Assert(!GV.isDSOLocal(),do { if (!(!GV.isDSOLocal())) { CheckFailed("GlobalValue with DLLImport Storage is dso_local!"
, &GV); return; } } while (false)
586 "GlobalValue with DLLImport Storage is dso_local!", &GV)do { if (!(!GV.isDSOLocal())) { CheckFailed("GlobalValue with DLLImport Storage is dso_local!"
, &GV); return; } } while (false)
;
587
588 Assert((GV.isDeclaration() && GV.hasExternalLinkage()) ||do { if (!((GV.isDeclaration() && GV.hasExternalLinkage
()) || GV.hasAvailableExternallyLinkage())) { CheckFailed("Global is marked as dllimport, but not external"
, &GV); return; } } while (false)
589 GV.hasAvailableExternallyLinkage(),do { if (!((GV.isDeclaration() && GV.hasExternalLinkage
()) || GV.hasAvailableExternallyLinkage())) { CheckFailed("Global is marked as dllimport, but not external"
, &GV); return; } } while (false)
590 "Global is marked as dllimport, but not external", &GV)do { if (!((GV.isDeclaration() && GV.hasExternalLinkage
()) || GV.hasAvailableExternallyLinkage())) { CheckFailed("Global is marked as dllimport, but not external"
, &GV); return; } } while (false)
;
591 }
592
593 if (GV.isImplicitDSOLocal())
594 Assert(GV.isDSOLocal(),do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with local linkage or non-default "
"visibility must be dso_local!", &GV); return; } } while
(false)
595 "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)
596 "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)
597 &GV)do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with local linkage or non-default "
"visibility must be dso_local!", &GV); return; } } while
(false)
;
598
599 forEachUser(&GV, GlobalValueVisited, [&](const Value *V) -> bool {
600 if (const Instruction *I = dyn_cast<Instruction>(V)) {
601 if (!I->getParent() || !I->getParent()->getParent())
602 CheckFailed("Global is referenced by parentless instruction!", &GV, &M,
603 I);
604 else if (I->getParent()->getParent()->getParent() != &M)
605 CheckFailed("Global is referenced in a different module!", &GV, &M, I,
606 I->getParent()->getParent(),
607 I->getParent()->getParent()->getParent());
608 return false;
609 } else if (const Function *F = dyn_cast<Function>(V)) {
610 if (F->getParent() != &M)
611 CheckFailed("Global is used by function in a different module", &GV, &M,
612 F, F->getParent());
613 return false;
614 }
615 return true;
616 });
617}
618
619void Verifier::visitGlobalVariable(const GlobalVariable &GV) {
620 if (GV.hasInitializer()) {
621 Assert(GV.getInitializer()->getType() == GV.getValueType(),do { if (!(GV.getInitializer()->getType() == GV.getValueType
())) { CheckFailed("Global variable initializer type does not match global "
"variable type!", &GV); return; } } while (false)
622 "Global variable initializer type does not match global "do { if (!(GV.getInitializer()->getType() == GV.getValueType
())) { CheckFailed("Global variable initializer type does not match global "
"variable type!", &GV); return; } } while (false)
623 "variable type!",do { if (!(GV.getInitializer()->getType() == GV.getValueType
())) { CheckFailed("Global variable initializer type does not match global "
"variable type!", &GV); return; } } while (false)
624 &GV)do { if (!(GV.getInitializer()->getType() == GV.getValueType
())) { CheckFailed("Global variable initializer type does not match global "
"variable type!", &GV); return; } } while (false)
;
625 // If the global has common linkage, it must have a zero initializer and
626 // cannot be constant.
627 if (GV.hasCommonLinkage()) {
628 Assert(GV.getInitializer()->isNullValue(),do { if (!(GV.getInitializer()->isNullValue())) { CheckFailed
("'common' global must have a zero initializer!", &GV); return
; } } while (false)
629 "'common' global must have a zero initializer!", &GV)do { if (!(GV.getInitializer()->isNullValue())) { CheckFailed
("'common' global must have a zero initializer!", &GV); return
; } } while (false)
;
630 Assert(!GV.isConstant(), "'common' global may not be marked constant!",do { if (!(!GV.isConstant())) { CheckFailed("'common' global may not be marked constant!"
, &GV); return; } } while (false)
631 &GV)do { if (!(!GV.isConstant())) { CheckFailed("'common' global may not be marked constant!"
, &GV); return; } } while (false)
;
632 Assert(!GV.hasComdat(), "'common' global may not be in a Comdat!", &GV)do { if (!(!GV.hasComdat())) { CheckFailed("'common' global may not be in a Comdat!"
, &GV); return; } } while (false)
;
633 }
634 }
635
636 if (GV.hasName() && (GV.getName() == "llvm.global_ctors" ||
637 GV.getName() == "llvm.global_dtors")) {
638 Assert(!GV.hasInitializer() || GV.hasAppendingLinkage(),do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage()))
{ CheckFailed("invalid linkage for intrinsic global variable"
, &GV); return; } } while (false)
639 "invalid linkage for intrinsic global variable", &GV)do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage()))
{ CheckFailed("invalid linkage for intrinsic global variable"
, &GV); return; } } while (false)
;
640 // Don't worry about emitting an error for it not being an array,
641 // visitGlobalValue will complain on appending non-array.
642 if (ArrayType *ATy = dyn_cast<ArrayType>(GV.getValueType())) {
643 StructType *STy = dyn_cast<StructType>(ATy->getElementType());
644 PointerType *FuncPtrTy =
645 FunctionType::get(Type::getVoidTy(Context), false)->
646 getPointerTo(DL.getProgramAddressSpace());
647 Assert(STy &&do { if (!(STy && (STy->getNumElements() == 2 || STy
->getNumElements() == 3) && STy->getTypeAtIndex
(0u)->isIntegerTy(32) && STy->getTypeAtIndex(1)
== FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable"
, &GV); return; } } while (false)
648 (STy->getNumElements() == 2 || STy->getNumElements() == 3) &&do { if (!(STy && (STy->getNumElements() == 2 || STy
->getNumElements() == 3) && STy->getTypeAtIndex
(0u)->isIntegerTy(32) && STy->getTypeAtIndex(1)
== FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable"
, &GV); return; } } while (false)
649 STy->getTypeAtIndex(0u)->isIntegerTy(32) &&do { if (!(STy && (STy->getNumElements() == 2 || STy
->getNumElements() == 3) && STy->getTypeAtIndex
(0u)->isIntegerTy(32) && STy->getTypeAtIndex(1)
== FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable"
, &GV); return; } } while (false)
650 STy->getTypeAtIndex(1) == FuncPtrTy,do { if (!(STy && (STy->getNumElements() == 2 || STy
->getNumElements() == 3) && STy->getTypeAtIndex
(0u)->isIntegerTy(32) && STy->getTypeAtIndex(1)
== FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable"
, &GV); return; } } while (false)
651 "wrong type for intrinsic global variable", &GV)do { if (!(STy && (STy->getNumElements() == 2 || STy
->getNumElements() == 3) && STy->getTypeAtIndex
(0u)->isIntegerTy(32) && STy->getTypeAtIndex(1)
== FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable"
, &GV); return; } } while (false)
;
652 Assert(STy->getNumElements() == 3,do { if (!(STy->getNumElements() == 3)) { CheckFailed("the third field of the element type is mandatory, "
"specify i8* null to migrate from the obsoleted 2-field form"
); return; } } while (false)
653 "the third field of the element type is mandatory, "do { if (!(STy->getNumElements() == 3)) { CheckFailed("the third field of the element type is mandatory, "
"specify i8* null to migrate from the obsoleted 2-field form"
); return; } } while (false)
654 "specify i8* null to migrate from the obsoleted 2-field form")do { if (!(STy->getNumElements() == 3)) { CheckFailed("the third field of the element type is mandatory, "
"specify i8* null to migrate from the obsoleted 2-field form"
); return; } } while (false)
;
655 Type *ETy = STy->getTypeAtIndex(2);
656 Assert(ETy->isPointerTy() &&do { if (!(ETy->isPointerTy() && cast<PointerType
>(ETy)->getElementType()->isIntegerTy(8))) { CheckFailed
("wrong type for intrinsic global variable", &GV); return
; } } while (false)
657 cast<PointerType>(ETy)->getElementType()->isIntegerTy(8),do { if (!(ETy->isPointerTy() && cast<PointerType
>(ETy)->getElementType()->isIntegerTy(8))) { CheckFailed
("wrong type for intrinsic global variable", &GV); return
; } } while (false)
658 "wrong type for intrinsic global variable", &GV)do { if (!(ETy->isPointerTy() && cast<PointerType
>(ETy)->getElementType()->isIntegerTy(8))) { CheckFailed
("wrong type for intrinsic global variable", &GV); return
; } } while (false)
;
659 }
660 }
661
662 if (GV.hasName() && (GV.getName() == "llvm.used" ||
663 GV.getName() == "llvm.compiler.used")) {
664 Assert(!GV.hasInitializer() || GV.hasAppendingLinkage(),do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage()))
{ CheckFailed("invalid linkage for intrinsic global variable"
, &GV); return; } } while (false)
665 "invalid linkage for intrinsic global variable", &GV)do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage()))
{ CheckFailed("invalid linkage for intrinsic global variable"
, &GV); return; } } while (false)
;
666 Type *GVType = GV.getValueType();
667 if (ArrayType *ATy = dyn_cast<ArrayType>(GVType)) {
668 PointerType *PTy = dyn_cast<PointerType>(ATy->getElementType());
669 Assert(PTy, "wrong type for intrinsic global variable", &GV)do { if (!(PTy)) { CheckFailed("wrong type for intrinsic global variable"
, &GV); return; } } while (false)
;
670 if (GV.hasInitializer()) {
671 const Constant *Init = GV.getInitializer();
672 const ConstantArray *InitArray = dyn_cast<ConstantArray>(Init);
673 Assert(InitArray, "wrong initalizer for intrinsic global variable",do { if (!(InitArray)) { CheckFailed("wrong initalizer for intrinsic global variable"
, Init); return; } } while (false)
674 Init)do { if (!(InitArray)) { CheckFailed("wrong initalizer for intrinsic global variable"
, Init); return; } } while (false)
;
675 for (Value *Op : InitArray->operands()) {
676 Value *V = Op->stripPointerCasts();
677 Assert(isa<GlobalVariable>(V) || isa<Function>(V) ||do { if (!(isa<GlobalVariable>(V) || isa<Function>
(V) || isa<GlobalAlias>(V))) { CheckFailed("invalid llvm.used member"
, V); return; } } while (false)
678 isa<GlobalAlias>(V),do { if (!(isa<GlobalVariable>(V) || isa<Function>
(V) || isa<GlobalAlias>(V))) { CheckFailed("invalid llvm.used member"
, V); return; } } while (false)
679 "invalid llvm.used member", V)do { if (!(isa<GlobalVariable>(V) || isa<Function>
(V) || isa<GlobalAlias>(V))) { CheckFailed("invalid llvm.used member"
, V); return; } } while (false)
;
680 Assert(V->hasName(), "members of llvm.used must be named", V)do { if (!(V->hasName())) { CheckFailed("members of llvm.used must be named"
, V); return; } } while (false)
;
681 }
682 }
683 }
684 }
685
686 // Visit any debug info attachments.
687 SmallVector<MDNode *, 1> MDs;
688 GV.getMetadata(LLVMContext::MD_dbg, MDs);
689 for (auto *MD : MDs) {
690 if (auto *GVE = dyn_cast<DIGlobalVariableExpression>(MD))
691 visitDIGlobalVariableExpression(*GVE);
692 else
693 AssertDI(false, "!dbg attachment of global variable must be a "do { if (!(false)) { DebugInfoCheckFailed("!dbg attachment of global variable must be a "
"DIGlobalVariableExpression"); return; } } while (false)
694 "DIGlobalVariableExpression")do { if (!(false)) { DebugInfoCheckFailed("!dbg attachment of global variable must be a "
"DIGlobalVariableExpression"); return; } } while (false)
;
695 }
696
697 // Scalable vectors cannot be global variables, since we don't know
698 // the runtime size. If the global is a struct or an array containing
699 // scalable vectors, that will be caught by the isValidElementType methods
700 // in StructType or ArrayType instead.
701 if (auto *VTy = dyn_cast<VectorType>(GV.getValueType()))
702 Assert(!VTy->isScalable(), "Globals cannot contain scalable vectors", &GV)do { if (!(!VTy->isScalable())) { CheckFailed("Globals cannot contain scalable vectors"
, &GV); return; } } while (false)
;
703
704 if (!GV.hasInitializer()) {
705 visitGlobalValue(GV);
706 return;
707 }
708
709 // Walk any aggregate initializers looking for bitcasts between address spaces
710 visitConstantExprsRecursively(GV.getInitializer());
711
712 visitGlobalValue(GV);
713}
714
715void Verifier::visitAliaseeSubExpr(const GlobalAlias &GA, const Constant &C) {
716 SmallPtrSet<const GlobalAlias*, 4> Visited;
717 Visited.insert(&GA);
718 visitAliaseeSubExpr(Visited, GA, C);
719}
720
721void Verifier::visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias*> &Visited,
722 const GlobalAlias &GA, const Constant &C) {
723 if (const auto *GV = dyn_cast<GlobalValue>(&C)) {
724 Assert(!GV->isDeclarationForLinker(), "Alias must point to a definition",do { if (!(!GV->isDeclarationForLinker())) { CheckFailed("Alias must point to a definition"
, &GA); return; } } while (false)
725 &GA)do { if (!(!GV->isDeclarationForLinker())) { CheckFailed("Alias must point to a definition"
, &GA); return; } } while (false)
;
726
727 if (const auto *GA2 = dyn_cast<GlobalAlias>(GV)) {
728 Assert(Visited.insert(GA2).second, "Aliases cannot form a cycle", &GA)do { if (!(Visited.insert(GA2).second)) { CheckFailed("Aliases cannot form a cycle"
, &GA); return; } } while (false)
;
729
730 Assert(!GA2->isInterposable(), "Alias cannot point to an interposable alias",do { if (!(!GA2->isInterposable())) { CheckFailed("Alias cannot point to an interposable alias"
, &GA); return; } } while (false)
731 &GA)do { if (!(!GA2->isInterposable())) { CheckFailed("Alias cannot point to an interposable alias"
, &GA); return; } } while (false)
;
732 } else {
733 // Only continue verifying subexpressions of GlobalAliases.
734 // Do not recurse into global initializers.
735 return;
736 }
737 }
738
739 if (const auto *CE = dyn_cast<ConstantExpr>(&C))
740 visitConstantExprsRecursively(CE);
741
742 for (const Use &U : C.operands()) {
743 Value *V = &*U;
744 if (const auto *GA2 = dyn_cast<GlobalAlias>(V))
745 visitAliaseeSubExpr(Visited, GA, *GA2->getAliasee());
746 else if (const auto *C2 = dyn_cast<Constant>(V))
747 visitAliaseeSubExpr(Visited, GA, *C2);
748 }
749}
750
751void Verifier::visitGlobalAlias(const GlobalAlias &GA) {
752 Assert(GlobalAlias::isValidLinkage(GA.getLinkage()),do { if (!(GlobalAlias::isValidLinkage(GA.getLinkage()))) { CheckFailed
("Alias should have private, internal, linkonce, weak, linkonce_odr, "
"weak_odr, or external linkage!", &GA); return; } } while
(false)
753 "Alias should have private, internal, linkonce, weak, linkonce_odr, "do { if (!(GlobalAlias::isValidLinkage(GA.getLinkage()))) { CheckFailed
("Alias should have private, internal, linkonce, weak, linkonce_odr, "
"weak_odr, or external linkage!", &GA); return; } } while
(false)
754 "weak_odr, or external linkage!",do { if (!(GlobalAlias::isValidLinkage(GA.getLinkage()))) { CheckFailed
("Alias should have private, internal, linkonce, weak, linkonce_odr, "
"weak_odr, or external linkage!", &GA); return; } } while
(false)
755 &GA)do { if (!(GlobalAlias::isValidLinkage(GA.getLinkage()))) { CheckFailed
("Alias should have private, internal, linkonce, weak, linkonce_odr, "
"weak_odr, or external linkage!", &GA); return; } } while
(false)
;
756 const Constant *Aliasee = GA.getAliasee();
757 Assert(Aliasee, "Aliasee cannot be NULL!", &GA)do { if (!(Aliasee)) { CheckFailed("Aliasee cannot be NULL!",
&GA); return; } } while (false)
;
758 Assert(GA.getType() == Aliasee->getType(),do { if (!(GA.getType() == Aliasee->getType())) { CheckFailed
("Alias and aliasee types should match!", &GA); return; }
} while (false)
759 "Alias and aliasee types should match!", &GA)do { if (!(GA.getType() == Aliasee->getType())) { CheckFailed
("Alias and aliasee types should match!", &GA); return; }
} while (false)
;
760
761 Assert(isa<GlobalValue>(Aliasee) || isa<ConstantExpr>(Aliasee),do { if (!(isa<GlobalValue>(Aliasee) || isa<ConstantExpr
>(Aliasee))) { CheckFailed("Aliasee should be either GlobalValue or ConstantExpr"
, &GA); return; } } while (false)
762 "Aliasee should be either GlobalValue or ConstantExpr", &GA)do { if (!(isa<GlobalValue>(Aliasee) || isa<ConstantExpr
>(Aliasee))) { CheckFailed("Aliasee should be either GlobalValue or ConstantExpr"
, &GA); return; } } while (false)
;
763
764 visitAliaseeSubExpr(GA, *Aliasee);
765
766 visitGlobalValue(GA);
767}
768
769void Verifier::visitNamedMDNode(const NamedMDNode &NMD) {
770 // There used to be various other llvm.dbg.* nodes, but we don't support
771 // upgrading them and we want to reserve the namespace for future uses.
772 if (NMD.getName().startswith("llvm.dbg."))
773 AssertDI(NMD.getName() == "llvm.dbg.cu",do { if (!(NMD.getName() == "llvm.dbg.cu")) { DebugInfoCheckFailed
("unrecognized named metadata node in the llvm.dbg namespace"
, &NMD); return; } } while (false)
774 "unrecognized named metadata node in the llvm.dbg namespace",do { if (!(NMD.getName() == "llvm.dbg.cu")) { DebugInfoCheckFailed
("unrecognized named metadata node in the llvm.dbg namespace"
, &NMD); return; } } while (false)
775 &NMD)do { if (!(NMD.getName() == "llvm.dbg.cu")) { DebugInfoCheckFailed
("unrecognized named metadata node in the llvm.dbg namespace"
, &NMD); return; } } while (false)
;
776 for (const MDNode *MD : NMD.operands()) {
777 if (NMD.getName() == "llvm.dbg.cu")
778 AssertDI(MD && isa<DICompileUnit>(MD), "invalid compile unit", &NMD, MD)do { if (!(MD && isa<DICompileUnit>(MD))) { DebugInfoCheckFailed
("invalid compile unit", &NMD, MD); return; } } while (false
)
;
779
780 if (!MD)
781 continue;
782
783 visitMDNode(*MD);
784 }
785}
786
787void Verifier::visitMDNode(const MDNode &MD) {
788 // Only visit each node once. Metadata can be mutually recursive, so this
789 // avoids infinite recursion here, as well as being an optimization.
790 if (!MDNodes.insert(&MD).second)
791 return;
792
793 switch (MD.getMetadataID()) {
794 default:
795 llvm_unreachable("Invalid MDNode subclass")::llvm::llvm_unreachable_internal("Invalid MDNode subclass", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 795)
;
796 case Metadata::MDTupleKind:
797 break;
798#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
799 case Metadata::CLASS##Kind: \
800 visit##CLASS(cast<CLASS>(MD)); \
801 break;
802#include "llvm/IR/Metadata.def"
803 }
804
805 for (const Metadata *Op : MD.operands()) {
806 if (!Op)
807 continue;
808 Assert(!isa<LocalAsMetadata>(Op), "Invalid operand for global metadata!",do { if (!(!isa<LocalAsMetadata>(Op))) { CheckFailed("Invalid operand for global metadata!"
, &MD, Op); return; } } while (false)
809 &MD, Op)do { if (!(!isa<LocalAsMetadata>(Op))) { CheckFailed("Invalid operand for global metadata!"
, &MD, Op); return; } } while (false)
;
810 if (auto *N = dyn_cast<MDNode>(Op)) {
811 visitMDNode(*N);
812 continue;
813 }
814 if (auto *V = dyn_cast<ValueAsMetadata>(Op)) {
815 visitValueAsMetadata(*V, nullptr);
816 continue;
817 }
818 }
819
820 // Check these last, so we diagnose problems in operands first.
821 Assert(!MD.isTemporary(), "Expected no forward declarations!", &MD)do { if (!(!MD.isTemporary())) { CheckFailed("Expected no forward declarations!"
, &MD); return; } } while (false)
;
822 Assert(MD.isResolved(), "All nodes should be resolved!", &MD)do { if (!(MD.isResolved())) { CheckFailed("All nodes should be resolved!"
, &MD); return; } } while (false)
;
823}
824
825void Verifier::visitValueAsMetadata(const ValueAsMetadata &MD, Function *F) {
826 Assert(MD.getValue(), "Expected valid value", &MD)do { if (!(MD.getValue())) { CheckFailed("Expected valid value"
, &MD); return; } } while (false)
;
827 Assert(!MD.getValue()->getType()->isMetadataTy(),do { if (!(!MD.getValue()->getType()->isMetadataTy())) {
CheckFailed("Unexpected metadata round-trip through values",
&MD, MD.getValue()); return; } } while (false)
828 "Unexpected metadata round-trip through values", &MD, MD.getValue())do { if (!(!MD.getValue()->getType()->isMetadataTy())) {
CheckFailed("Unexpected metadata round-trip through values",
&MD, MD.getValue()); return; } } while (false)
;
829
830 auto *L = dyn_cast<LocalAsMetadata>(&MD);
831 if (!L)
832 return;
833
834 Assert(F, "function-local metadata used outside a function", L)do { if (!(F)) { CheckFailed("function-local metadata used outside a function"
, L); return; } } while (false)
;
835
836 // If this was an instruction, bb, or argument, verify that it is in the
837 // function that we expect.
838 Function *ActualF = nullptr;
839 if (Instruction *I = dyn_cast<Instruction>(L->getValue())) {
840 Assert(I->getParent(), "function-local metadata not in basic block", L, I)do { if (!(I->getParent())) { CheckFailed("function-local metadata not in basic block"
, L, I); return; } } while (false)
;
841 ActualF = I->getParent()->getParent();
842 } else if (BasicBlock *BB = dyn_cast<BasicBlock>(L->getValue()))
843 ActualF = BB->getParent();
844 else if (Argument *A = dyn_cast<Argument>(L->getValue()))
845 ActualF = A->getParent();
846 assert(ActualF && "Unimplemented function local metadata case!")((ActualF && "Unimplemented function local metadata case!"
) ? static_cast<void> (0) : __assert_fail ("ActualF && \"Unimplemented function local metadata case!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 846, __PRETTY_FUNCTION__))
;
847
848 Assert(ActualF == F, "function-local metadata used in wrong function", L)do { if (!(ActualF == F)) { CheckFailed("function-local metadata used in wrong function"
, L); return; } } while (false)
;
849}
850
851void Verifier::visitMetadataAsValue(const MetadataAsValue &MDV, Function *F) {
852 Metadata *MD = MDV.getMetadata();
853 if (auto *N = dyn_cast<MDNode>(MD)) {
854 visitMDNode(*N);
855 return;
856 }
857
858 // Only visit each node once. Metadata can be mutually recursive, so this
859 // avoids infinite recursion here, as well as being an optimization.
860 if (!MDNodes.insert(MD).second)
861 return;
862
863 if (auto *V = dyn_cast<ValueAsMetadata>(MD))
864 visitValueAsMetadata(*V, F);
865}
866
867static bool isType(const Metadata *MD) { return !MD || isa<DIType>(MD); }
868static bool isScope(const Metadata *MD) { return !MD || isa<DIScope>(MD); }
869static bool isDINode(const Metadata *MD) { return !MD || isa<DINode>(MD); }
870
871void Verifier::visitDILocation(const DILocation &N) {
872 AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { DebugInfoCheckFailed("location requires a valid scope"
, &N, N.getRawScope()); return; } } while (false)
873 "location requires a valid scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { DebugInfoCheckFailed("location requires a valid scope"
, &N, N.getRawScope()); return; } } while (false)
;
874 if (auto *IA = N.getRawInlinedAt())
875 AssertDI(isa<DILocation>(IA), "inlined-at should be a location", &N, IA)do { if (!(isa<DILocation>(IA))) { DebugInfoCheckFailed
("inlined-at should be a location", &N, IA); return; } } while
(false)
;
876 if (auto *SP = dyn_cast<DISubprogram>(N.getRawScope()))
877 AssertDI(SP->isDefinition(), "scope points into the type hierarchy", &N)do { if (!(SP->isDefinition())) { DebugInfoCheckFailed("scope points into the type hierarchy"
, &N); return; } } while (false)
;
878}
879
880void Verifier::visitGenericDINode(const GenericDINode &N) {
881 AssertDI(N.getTag(), "invalid tag", &N)do { if (!(N.getTag())) { DebugInfoCheckFailed("invalid tag",
&N); return; } } while (false)
;
882}
883
884void Verifier::visitDIScope(const DIScope &N) {
885 if (auto *F = N.getRawFile())
886 AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file"
, &N, F); return; } } while (false)
;
887}
888
889void Verifier::visitDISubrange(const DISubrange &N) {
890 AssertDI(N.getTag() == dwarf::DW_TAG_subrange_type, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_subrange_type)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
891 auto Count = N.getCount();
892 AssertDI(Count, "Count must either be a signed constant or a DIVariable",do { if (!(Count)) { DebugInfoCheckFailed("Count must either be a signed constant or a DIVariable"
, &N); return; } } while (false)
893 &N)do { if (!(Count)) { DebugInfoCheckFailed("Count must either be a signed constant or a DIVariable"
, &N); return; } } while (false)
;
894 AssertDI(!Count.is<ConstantInt*>() ||do { if (!(!Count.is<ConstantInt*>() || Count.get<ConstantInt
*>()->getSExtValue() >= -1)) { DebugInfoCheckFailed(
"invalid subrange count", &N); return; } } while (false)
895 Count.get<ConstantInt*>()->getSExtValue() >= -1,do { if (!(!Count.is<ConstantInt*>() || Count.get<ConstantInt
*>()->getSExtValue() >= -1)) { DebugInfoCheckFailed(
"invalid subrange count", &N); return; } } while (false)
896 "invalid subrange count", &N)do { if (!(!Count.is<ConstantInt*>() || Count.get<ConstantInt
*>()->getSExtValue() >= -1)) { DebugInfoCheckFailed(
"invalid subrange count", &N); return; } } while (false)
;
897}
898
899void Verifier::visitDIEnumerator(const DIEnumerator &N) {
900 AssertDI(N.getTag() == dwarf::DW_TAG_enumerator, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_enumerator)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
901}
902
903void Verifier::visitDIBasicType(const DIBasicType &N) {
904 AssertDI(N.getTag() == dwarf::DW_TAG_base_type ||do { if (!(N.getTag() == dwarf::DW_TAG_base_type || N.getTag(
) == dwarf::DW_TAG_unspecified_type)) { DebugInfoCheckFailed(
"invalid tag", &N); return; } } while (false)
905 N.getTag() == dwarf::DW_TAG_unspecified_type,do { if (!(N.getTag() == dwarf::DW_TAG_base_type || N.getTag(
) == dwarf::DW_TAG_unspecified_type)) { DebugInfoCheckFailed(
"invalid tag", &N); return; } } while (false)
906 "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_base_type || N.getTag(
) == dwarf::DW_TAG_unspecified_type)) { DebugInfoCheckFailed(
"invalid tag", &N); return; } } while (false)
;
907 AssertDI(!(N.isBigEndian() && N.isLittleEndian()) ,do { if (!(!(N.isBigEndian() && N.isLittleEndian())))
{ DebugInfoCheckFailed("has conflicting flags", &N); return
; } } while (false)
908 "has conflicting flags", &N)do { if (!(!(N.isBigEndian() && N.isLittleEndian())))
{ DebugInfoCheckFailed("has conflicting flags", &N); return
; } } while (false)
;
909}
910
911void Verifier::visitDIDerivedType(const DIDerivedType &N) {
912 // Common scope checks.
913 visitDIScope(N);
914
915 AssertDI(N.getTag() == dwarf::DW_TAG_typedef ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
916 N.getTag() == dwarf::DW_TAG_pointer_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
917 N.getTag() == dwarf::DW_TAG_ptr_to_member_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
918 N.getTag() == dwarf::DW_TAG_reference_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
919 N.getTag() == dwarf::DW_TAG_rvalue_reference_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
920 N.getTag() == dwarf::DW_TAG_const_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
921 N.getTag() == dwarf::DW_TAG_volatile_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
922 N.getTag() == dwarf::DW_TAG_restrict_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
923 N.getTag() == dwarf::DW_TAG_atomic_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
924 N.getTag() == dwarf::DW_TAG_member ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
925 N.getTag() == dwarf::DW_TAG_inheritance ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
926 N.getTag() == dwarf::DW_TAG_friend,do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
927 "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() ==
dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type
|| N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() ==
dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf::
DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type
|| N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() ==
dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member
|| N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf
::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", &
N); return; } } while (false)
;
928 if (N.getTag() == dwarf::DW_TAG_ptr_to_member_type) {
929 AssertDI(isType(N.getRawExtraData()), "invalid pointer to member type", &N,do { if (!(isType(N.getRawExtraData()))) { DebugInfoCheckFailed
("invalid pointer to member type", &N, N.getRawExtraData(
)); return; } } while (false)
930 N.getRawExtraData())do { if (!(isType(N.getRawExtraData()))) { DebugInfoCheckFailed
("invalid pointer to member type", &N, N.getRawExtraData(
)); return; } } while (false)
;
931 }
932
933 AssertDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope())do { if (!(isScope(N.getRawScope()))) { DebugInfoCheckFailed(
"invalid scope", &N, N.getRawScope()); return; } } while (
false)
;
934 AssertDI(isType(N.getRawBaseType()), "invalid base type", &N,do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed
("invalid base type", &N, N.getRawBaseType()); return; } }
while (false)
935 N.getRawBaseType())do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed
("invalid base type", &N, N.getRawBaseType()); return; } }
while (false)
;
936
937 if (N.getDWARFAddressSpace()) {
938 AssertDI(N.getTag() == dwarf::DW_TAG_pointer_type ||do { if (!(N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag
() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type
)) { DebugInfoCheckFailed("DWARF address space only applies to pointer or reference types"
, &N); return; } } while (false)
939 N.getTag() == dwarf::DW_TAG_reference_type ||do { if (!(N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag
() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type
)) { DebugInfoCheckFailed("DWARF address space only applies to pointer or reference types"
, &N); return; } } while (false)
940 N.getTag() == dwarf::DW_TAG_rvalue_reference_type,do { if (!(N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag
() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type
)) { DebugInfoCheckFailed("DWARF address space only applies to pointer or reference types"
, &N); return; } } while (false)
941 "DWARF address space only applies to pointer or reference types",do { if (!(N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag
() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type
)) { DebugInfoCheckFailed("DWARF address space only applies to pointer or reference types"
, &N); return; } } while (false)
942 &N)do { if (!(N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag
() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type
)) { DebugInfoCheckFailed("DWARF address space only applies to pointer or reference types"
, &N); return; } } while (false)
;
943 }
944}
945
946/// Detect mutually exclusive flags.
947static bool hasConflictingReferenceFlags(unsigned Flags) {
948 return ((Flags & DINode::FlagLValueReference) &&
949 (Flags & DINode::FlagRValueReference)) ||
950 ((Flags & DINode::FlagTypePassByValue) &&
951 (Flags & DINode::FlagTypePassByReference));
952}
953
954void Verifier::visitTemplateParams(const MDNode &N, const Metadata &RawParams) {
955 auto *Params = dyn_cast<MDTuple>(&RawParams);
956 AssertDI(Params, "invalid template params", &N, &RawParams)do { if (!(Params)) { DebugInfoCheckFailed("invalid template params"
, &N, &RawParams); return; } } while (false)
;
957 for (Metadata *Op : Params->operands()) {
958 AssertDI(Op && isa<DITemplateParameter>(Op), "invalid template parameter",do { if (!(Op && isa<DITemplateParameter>(Op)))
{ DebugInfoCheckFailed("invalid template parameter", &N,
Params, Op); return; } } while (false)
959 &N, Params, Op)do { if (!(Op && isa<DITemplateParameter>(Op)))
{ DebugInfoCheckFailed("invalid template parameter", &N,
Params, Op); return; } } while (false)
;
960 }
961}
962
963void Verifier::visitDICompositeType(const DICompositeType &N) {
964 // Common scope checks.
965 visitDIScope(N);
966
967 AssertDI(N.getTag() == dwarf::DW_TAG_array_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag
() == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type
|| N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag(
) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
968 N.getTag() == dwarf::DW_TAG_structure_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag
() == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type
|| N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag(
) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
969 N.getTag() == dwarf::DW_TAG_union_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag
() == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type
|| N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag(
) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
970 N.getTag() == dwarf::DW_TAG_enumeration_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag
() == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type
|| N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag(
) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
971 N.getTag() == dwarf::DW_TAG_class_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag
() == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type
|| N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag(
) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
972 N.getTag() == dwarf::DW_TAG_variant_part,do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag
() == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type
|| N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag(
) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
973 "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag
() == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type
|| N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag(
) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
;
974
975 AssertDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope())do { if (!(isScope(N.getRawScope()))) { DebugInfoCheckFailed(
"invalid scope", &N, N.getRawScope()); return; } } while (
false)
;
976 AssertDI(isType(N.getRawBaseType()), "invalid base type", &N,do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed
("invalid base type", &N, N.getRawBaseType()); return; } }
while (false)
977 N.getRawBaseType())do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed
("invalid base type", &N, N.getRawBaseType()); return; } }
while (false)
;
978
979 AssertDI(!N.getRawElements() || isa<MDTuple>(N.getRawElements()),do { if (!(!N.getRawElements() || isa<MDTuple>(N.getRawElements
()))) { DebugInfoCheckFailed("invalid composite elements", &
N, N.getRawElements()); return; } } while (false)
980 "invalid composite elements", &N, N.getRawElements())do { if (!(!N.getRawElements() || isa<MDTuple>(N.getRawElements
()))) { DebugInfoCheckFailed("invalid composite elements", &
N, N.getRawElements()); return; } } while (false)
;
981 AssertDI(isType(N.getRawVTableHolder()), "invalid vtable holder", &N,do { if (!(isType(N.getRawVTableHolder()))) { DebugInfoCheckFailed
("invalid vtable holder", &N, N.getRawVTableHolder()); return
; } } while (false)
982 N.getRawVTableHolder())do { if (!(isType(N.getRawVTableHolder()))) { DebugInfoCheckFailed
("invalid vtable holder", &N, N.getRawVTableHolder()); return
; } } while (false)
;
983 AssertDI(!hasConflictingReferenceFlags(N.getFlags()),do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed
("invalid reference flags", &N); return; } } while (false
)
984 "invalid reference flags", &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed
("invalid reference flags", &N); return; } } while (false
)
;
985 unsigned DIBlockByRefStruct = 1 << 4;
986 AssertDI((N.getFlags() & DIBlockByRefStruct) == 0,do { if (!((N.getFlags() & DIBlockByRefStruct) == 0)) { DebugInfoCheckFailed
("DIBlockByRefStruct on DICompositeType is no longer supported"
, &N); return; } } while (false)
987 "DIBlockByRefStruct on DICompositeType is no longer supported", &N)do { if (!((N.getFlags() & DIBlockByRefStruct) == 0)) { DebugInfoCheckFailed
("DIBlockByRefStruct on DICompositeType is no longer supported"
, &N); return; } } while (false)
;
988
989 if (N.isVector()) {
990 const DINodeArray Elements = N.getElements();
991 AssertDI(Elements.size() == 1 &&do { if (!(Elements.size() == 1 && Elements[0]->getTag
() == dwarf::DW_TAG_subrange_type)) { DebugInfoCheckFailed("invalid vector, expected one element of type subrange"
, &N); return; } } while (false)
992 Elements[0]->getTag() == dwarf::DW_TAG_subrange_type,do { if (!(Elements.size() == 1 && Elements[0]->getTag
() == dwarf::DW_TAG_subrange_type)) { DebugInfoCheckFailed("invalid vector, expected one element of type subrange"
, &N); return; } } while (false)
993 "invalid vector, expected one element of type subrange", &N)do { if (!(Elements.size() == 1 && Elements[0]->getTag
() == dwarf::DW_TAG_subrange_type)) { DebugInfoCheckFailed("invalid vector, expected one element of type subrange"
, &N); return; } } while (false)
;
994 }
995
996 if (auto *Params = N.getRawTemplateParams())
997 visitTemplateParams(N, *Params);
998
999 if (N.getTag() == dwarf::DW_TAG_class_type ||
1000 N.getTag() == dwarf::DW_TAG_union_type) {
1001 AssertDI(N.getFile() && !N.getFile()->getFilename().empty(),do { if (!(N.getFile() && !N.getFile()->getFilename
().empty())) { DebugInfoCheckFailed("class/union requires a filename"
, &N, N.getFile()); return; } } while (false)
1002 "class/union requires a filename", &N, N.getFile())do { if (!(N.getFile() && !N.getFile()->getFilename
().empty())) { DebugInfoCheckFailed("class/union requires a filename"
, &N, N.getFile()); return; } } while (false)
;
1003 }
1004
1005 if (auto *D = N.getRawDiscriminator()) {
1006 AssertDI(isa<DIDerivedType>(D) && N.getTag() == dwarf::DW_TAG_variant_part,do { if (!(isa<DIDerivedType>(D) && N.getTag() ==
dwarf::DW_TAG_variant_part)) { DebugInfoCheckFailed("discriminator can only appear on variant part"
); return; } } while (false)
1007 "discriminator can only appear on variant part")do { if (!(isa<DIDerivedType>(D) && N.getTag() ==
dwarf::DW_TAG_variant_part)) { DebugInfoCheckFailed("discriminator can only appear on variant part"
); return; } } while (false)
;
1008 }
1009}
1010
1011void Verifier::visitDISubroutineType(const DISubroutineType &N) {
1012 AssertDI(N.getTag() == dwarf::DW_TAG_subroutine_type, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_subroutine_type)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1013 if (auto *Types = N.getRawTypeArray()) {
1014 AssertDI(isa<MDTuple>(Types), "invalid composite elements", &N, Types)do { if (!(isa<MDTuple>(Types))) { DebugInfoCheckFailed
("invalid composite elements", &N, Types); return; } } while
(false)
;
1015 for (Metadata *Ty : N.getTypeArray()->operands()) {
1016 AssertDI(isType(Ty), "invalid subroutine type ref", &N, Types, Ty)do { if (!(isType(Ty))) { DebugInfoCheckFailed("invalid subroutine type ref"
, &N, Types, Ty); return; } } while (false)
;
1017 }
1018 }
1019 AssertDI(!hasConflictingReferenceFlags(N.getFlags()),do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed
("invalid reference flags", &N); return; } } while (false
)
1020 "invalid reference flags", &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed
("invalid reference flags", &N); return; } } while (false
)
;
1021}
1022
1023void Verifier::visitDIFile(const DIFile &N) {
1024 AssertDI(N.getTag() == dwarf::DW_TAG_file_type, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_file_type)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1025 Optional<DIFile::ChecksumInfo<StringRef>> Checksum = N.getChecksum();
1026 if (Checksum) {
1027 AssertDI(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last,do { if (!(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last
)) { DebugInfoCheckFailed("invalid checksum kind", &N); return
; } } while (false)
1028 "invalid checksum kind", &N)do { if (!(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last
)) { DebugInfoCheckFailed("invalid checksum kind", &N); return
; } } while (false)
;
1029 size_t Size;
1030 switch (Checksum->Kind) {
1031 case DIFile::CSK_MD5:
1032 Size = 32;
1033 break;
1034 case DIFile::CSK_SHA1:
1035 Size = 40;
1036 break;
1037 }
1038 AssertDI(Checksum->Value.size() == Size, "invalid checksum length", &N)do { if (!(Checksum->Value.size() == Size)) { DebugInfoCheckFailed
("invalid checksum length", &N); return; } } while (false
)
;
1039 AssertDI(Checksum->Value.find_if_not(llvm::isHexDigit) == StringRef::npos,do { if (!(Checksum->Value.find_if_not(llvm::isHexDigit) ==
StringRef::npos)) { DebugInfoCheckFailed("invalid checksum",
&N); return; } } while (false)
1040 "invalid checksum", &N)do { if (!(Checksum->Value.find_if_not(llvm::isHexDigit) ==
StringRef::npos)) { DebugInfoCheckFailed("invalid checksum",
&N); return; } } while (false)
;
1041 }
1042}
1043
1044void Verifier::visitDICompileUnit(const DICompileUnit &N) {
1045 AssertDI(N.isDistinct(), "compile units must be distinct", &N)do { if (!(N.isDistinct())) { DebugInfoCheckFailed("compile units must be distinct"
, &N); return; } } while (false)
;
1046 AssertDI(N.getTag() == dwarf::DW_TAG_compile_unit, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_compile_unit)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1047
1048 // Don't bother verifying the compilation directory or producer string
1049 // as those could be empty.
1050 AssertDI(N.getRawFile() && isa<DIFile>(N.getRawFile()), "invalid file", &N,do { if (!(N.getRawFile() && isa<DIFile>(N.getRawFile
()))) { DebugInfoCheckFailed("invalid file", &N, N.getRawFile
()); return; } } while (false)
1051 N.getRawFile())do { if (!(N.getRawFile() && isa<DIFile>(N.getRawFile
()))) { DebugInfoCheckFailed("invalid file", &N, N.getRawFile
()); return; } } while (false)
;
1052 AssertDI(!N.getFile()->getFilename().empty(), "invalid filename", &N,do { if (!(!N.getFile()->getFilename().empty())) { DebugInfoCheckFailed
("invalid filename", &N, N.getFile()); return; } } while (
false)
1053 N.getFile())do { if (!(!N.getFile()->getFilename().empty())) { DebugInfoCheckFailed
("invalid filename", &N, N.getFile()); return; } } while (
false)
;
1054
1055 verifySourceDebugInfo(N, *N.getFile());
1056
1057 AssertDI((N.getEmissionKind() <= DICompileUnit::LastEmissionKind),do { if (!((N.getEmissionKind() <= DICompileUnit::LastEmissionKind
))) { DebugInfoCheckFailed("invalid emission kind", &N); return
; } } while (false)
1058 "invalid emission kind", &N)do { if (!((N.getEmissionKind() <= DICompileUnit::LastEmissionKind
))) { DebugInfoCheckFailed("invalid emission kind", &N); return
; } } while (false)
;
1059
1060 if (auto *Array = N.getRawEnumTypes()) {
1061 AssertDI(isa<MDTuple>(Array), "invalid enum list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed
("invalid enum list", &N, Array); return; } } while (false
)
;
1062 for (Metadata *Op : N.getEnumTypes()->operands()) {
1063 auto *Enum = dyn_cast_or_null<DICompositeType>(Op);
1064 AssertDI(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type,do { if (!(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type
)) { DebugInfoCheckFailed("invalid enum type", &N, N.getEnumTypes
(), Op); return; } } while (false)
1065 "invalid enum type", &N, N.getEnumTypes(), Op)do { if (!(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type
)) { DebugInfoCheckFailed("invalid enum type", &N, N.getEnumTypes
(), Op); return; } } while (false)
;
1066 }
1067 }
1068 if (auto *Array = N.getRawRetainedTypes()) {
1069 AssertDI(isa<MDTuple>(Array), "invalid retained type list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed
("invalid retained type list", &N, Array); return; } } while
(false)
;
1070 for (Metadata *Op : N.getRetainedTypes()->operands()) {
1071 AssertDI(Op && (isa<DIType>(Op) ||do { if (!(Op && (isa<DIType>(Op) || (isa<DISubprogram
>(Op) && !cast<DISubprogram>(Op)->isDefinition
())))) { DebugInfoCheckFailed("invalid retained type", &N
, Op); return; } } while (false)
1072 (isa<DISubprogram>(Op) &&do { if (!(Op && (isa<DIType>(Op) || (isa<DISubprogram
>(Op) && !cast<DISubprogram>(Op)->isDefinition
())))) { DebugInfoCheckFailed("invalid retained type", &N
, Op); return; } } while (false)
1073 !cast<DISubprogram>(Op)->isDefinition())),do { if (!(Op && (isa<DIType>(Op) || (isa<DISubprogram
>(Op) && !cast<DISubprogram>(Op)->isDefinition
())))) { DebugInfoCheckFailed("invalid retained type", &N
, Op); return; } } while (false)
1074 "invalid retained type", &N, Op)do { if (!(Op && (isa<DIType>(Op) || (isa<DISubprogram
>(Op) && !cast<DISubprogram>(Op)->isDefinition
())))) { DebugInfoCheckFailed("invalid retained type", &N
, Op); return; } } while (false)
;
1075 }
1076 }
1077 if (auto *Array = N.getRawGlobalVariables()) {
1078 AssertDI(isa<MDTuple>(Array), "invalid global variable list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed
("invalid global variable list", &N, Array); return; } } while
(false)
;
1079 for (Metadata *Op : N.getGlobalVariables()->operands()) {
1080 AssertDI(Op && (isa<DIGlobalVariableExpression>(Op)),do { if (!(Op && (isa<DIGlobalVariableExpression>
(Op)))) { DebugInfoCheckFailed("invalid global variable ref",
&N, Op); return; } } while (false)
1081 "invalid global variable ref", &N, Op)do { if (!(Op && (isa<DIGlobalVariableExpression>
(Op)))) { DebugInfoCheckFailed("invalid global variable ref",
&N, Op); return; } } while (false)
;
1082 }
1083 }
1084 if (auto *Array = N.getRawImportedEntities()) {
1085 AssertDI(isa<MDTuple>(Array), "invalid imported entity list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed
("invalid imported entity list", &N, Array); return; } } while
(false)
;
1086 for (Metadata *Op : N.getImportedEntities()->operands()) {
1087 AssertDI(Op && isa<DIImportedEntity>(Op), "invalid imported entity ref",do { if (!(Op && isa<DIImportedEntity>(Op))) { DebugInfoCheckFailed
("invalid imported entity ref", &N, Op); return; } } while
(false)
1088 &N, Op)do { if (!(Op && isa<DIImportedEntity>(Op))) { DebugInfoCheckFailed
("invalid imported entity ref", &N, Op); return; } } while
(false)
;
1089 }
1090 }
1091 if (auto *Array = N.getRawMacros()) {
1092 AssertDI(isa<MDTuple>(Array), "invalid macro list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed
("invalid macro list", &N, Array); return; } } while (false
)
;
1093 for (Metadata *Op : N.getMacros()->operands()) {
1094 AssertDI(Op && isa<DIMacroNode>(Op), "invalid macro ref", &N, Op)do { if (!(Op && isa<DIMacroNode>(Op))) { DebugInfoCheckFailed
("invalid macro ref", &N, Op); return; } } while (false)
;
1095 }
1096 }
1097 CUVisited.insert(&N);
1098}
1099
1100void Verifier::visitDISubprogram(const DISubprogram &N) {
1101 AssertDI(N.getTag() == dwarf::DW_TAG_subprogram, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_subprogram)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1102 AssertDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope())do { if (!(isScope(N.getRawScope()))) { DebugInfoCheckFailed(
"invalid scope", &N, N.getRawScope()); return; } } while (
false)
;
1103 if (auto *F = N.getRawFile())
1104 AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file"
, &N, F); return; } } while (false)
;
1105 else
1106 AssertDI(N.getLine() == 0, "line specified with no file", &N, N.getLine())do { if (!(N.getLine() == 0)) { DebugInfoCheckFailed("line specified with no file"
, &N, N.getLine()); return; } } while (false)
;
1107 if (auto *T = N.getRawType())
1108 AssertDI(isa<DISubroutineType>(T), "invalid subroutine type", &N, T)do { if (!(isa<DISubroutineType>(T))) { DebugInfoCheckFailed
("invalid subroutine type", &N, T); return; } } while (false
)
;
1109 AssertDI(isType(N.getRawContainingType()), "invalid containing type", &N,do { if (!(isType(N.getRawContainingType()))) { DebugInfoCheckFailed
("invalid containing type", &N, N.getRawContainingType())
; return; } } while (false)
1110 N.getRawContainingType())do { if (!(isType(N.getRawContainingType()))) { DebugInfoCheckFailed
("invalid containing type", &N, N.getRawContainingType())
; return; } } while (false)
;
1111 if (auto *Params = N.getRawTemplateParams())
1112 visitTemplateParams(N, *Params);
1113 if (auto *S = N.getRawDeclaration())
1114 AssertDI(isa<DISubprogram>(S) && !cast<DISubprogram>(S)->isDefinition(),do { if (!(isa<DISubprogram>(S) && !cast<DISubprogram
>(S)->isDefinition())) { DebugInfoCheckFailed("invalid subprogram declaration"
, &N, S); return; } } while (false)
1115 "invalid subprogram declaration", &N, S)do { if (!(isa<DISubprogram>(S) && !cast<DISubprogram
>(S)->isDefinition())) { DebugInfoCheckFailed("invalid subprogram declaration"
, &N, S); return; } } while (false)
;
1116 if (auto *RawNode = N.getRawRetainedNodes()) {
1117 auto *Node = dyn_cast<MDTuple>(RawNode);
1118 AssertDI(Node, "invalid retained nodes list", &N, RawNode)do { if (!(Node)) { DebugInfoCheckFailed("invalid retained nodes list"
, &N, RawNode); return; } } while (false)
;
1119 for (Metadata *Op : Node->operands()) {
1120 AssertDI(Op && (isa<DILocalVariable>(Op) || isa<DILabel>(Op)),do { if (!(Op && (isa<DILocalVariable>(Op) || isa
<DILabel>(Op)))) { DebugInfoCheckFailed("invalid retained nodes, expected DILocalVariable or DILabel"
, &N, Node, Op); return; } } while (false)
1121 "invalid retained nodes, expected DILocalVariable or DILabel",do { if (!(Op && (isa<DILocalVariable>(Op) || isa
<DILabel>(Op)))) { DebugInfoCheckFailed("invalid retained nodes, expected DILocalVariable or DILabel"
, &N, Node, Op); return; } } while (false)
1122 &N, Node, Op)do { if (!(Op && (isa<DILocalVariable>(Op) || isa
<DILabel>(Op)))) { DebugInfoCheckFailed("invalid retained nodes, expected DILocalVariable or DILabel"
, &N, Node, Op); return; } } while (false)
;
1123 }
1124 }
1125 AssertDI(!hasConflictingReferenceFlags(N.getFlags()),do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed
("invalid reference flags", &N); return; } } while (false
)
1126 "invalid reference flags", &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed
("invalid reference flags", &N); return; } } while (false
)
;
1127
1128 auto *Unit = N.getRawUnit();
1129 if (N.isDefinition()) {
1130 // Subprogram definitions (not part of the type hierarchy).
1131 AssertDI(N.isDistinct(), "subprogram definitions must be distinct", &N)do { if (!(N.isDistinct())) { DebugInfoCheckFailed("subprogram definitions must be distinct"
, &N); return; } } while (false)
;
1132 AssertDI(Unit, "subprogram definitions must have a compile unit", &N)do { if (!(Unit)) { DebugInfoCheckFailed("subprogram definitions must have a compile unit"
, &N); return; } } while (false)
;
1133 AssertDI(isa<DICompileUnit>(Unit), "invalid unit type", &N, Unit)do { if (!(isa<DICompileUnit>(Unit))) { DebugInfoCheckFailed
("invalid unit type", &N, Unit); return; } } while (false
)
;
1134 if (N.getFile())
1135 verifySourceDebugInfo(*N.getUnit(), *N.getFile());
1136 } else {
1137 // Subprogram declarations (part of the type hierarchy).
1138 AssertDI(!Unit, "subprogram declarations must not have a compile unit", &N)do { if (!(!Unit)) { DebugInfoCheckFailed("subprogram declarations must not have a compile unit"
, &N); return; } } while (false)
;
1139 }
1140
1141 if (auto *RawThrownTypes = N.getRawThrownTypes()) {
1142 auto *ThrownTypes = dyn_cast<MDTuple>(RawThrownTypes);
1143 AssertDI(ThrownTypes, "invalid thrown types list", &N, RawThrownTypes)do { if (!(ThrownTypes)) { DebugInfoCheckFailed("invalid thrown types list"
, &N, RawThrownTypes); return; } } while (false)
;
1144 for (Metadata *Op : ThrownTypes->operands())
1145 AssertDI(Op && isa<DIType>(Op), "invalid thrown type", &N, ThrownTypes,do { if (!(Op && isa<DIType>(Op))) { DebugInfoCheckFailed
("invalid thrown type", &N, ThrownTypes, Op); return; } }
while (false)
1146 Op)do { if (!(Op && isa<DIType>(Op))) { DebugInfoCheckFailed
("invalid thrown type", &N, ThrownTypes, Op); return; } }
while (false)
;
1147 }
1148
1149 if (N.areAllCallsDescribed())
1150 AssertDI(N.isDefinition(),do { if (!(N.isDefinition())) { DebugInfoCheckFailed("DIFlagAllCallsDescribed must be attached to a definition"
); return; } } while (false)
1151 "DIFlagAllCallsDescribed must be attached to a definition")do { if (!(N.isDefinition())) { DebugInfoCheckFailed("DIFlagAllCallsDescribed must be attached to a definition"
); return; } } while (false)
;
1152}
1153
1154void Verifier::visitDILexicalBlockBase(const DILexicalBlockBase &N) {
1155 AssertDI(N.getTag() == dwarf::DW_TAG_lexical_block, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_lexical_block)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1156 AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { DebugInfoCheckFailed("invalid local scope"
, &N, N.getRawScope()); return; } } while (false)
1157 "invalid local scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { DebugInfoCheckFailed("invalid local scope"
, &N, N.getRawScope()); return; } } while (false)
;
1158 if (auto *SP = dyn_cast<DISubprogram>(N.getRawScope()))
1159 AssertDI(SP->isDefinition(), "scope points into the type hierarchy", &N)do { if (!(SP->isDefinition())) { DebugInfoCheckFailed("scope points into the type hierarchy"
, &N); return; } } while (false)
;
1160}
1161
1162void Verifier::visitDILexicalBlock(const DILexicalBlock &N) {
1163 visitDILexicalBlockBase(N);
1164
1165 AssertDI(N.getLine() || !N.getColumn(),do { if (!(N.getLine() || !N.getColumn())) { DebugInfoCheckFailed
("cannot have column info without line info", &N); return
; } } while (false)
1166 "cannot have column info without line info", &N)do { if (!(N.getLine() || !N.getColumn())) { DebugInfoCheckFailed
("cannot have column info without line info", &N); return
; } } while (false)
;
1167}
1168
1169void Verifier::visitDILexicalBlockFile(const DILexicalBlockFile &N) {
1170 visitDILexicalBlockBase(N);
1171}
1172
1173void Verifier::visitDICommonBlock(const DICommonBlock &N) {
1174 AssertDI(N.getTag() == dwarf::DW_TAG_common_block, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_common_block)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1175 if (auto *S = N.getRawScope())
1176 AssertDI(isa<DIScope>(S), "invalid scope ref", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope ref"
, &N, S); return; } } while (false)
;
1177 if (auto *S = N.getRawDecl())
1178 AssertDI(isa<DIGlobalVariable>(S), "invalid declaration", &N, S)do { if (!(isa<DIGlobalVariable>(S))) { DebugInfoCheckFailed
("invalid declaration", &N, S); return; } } while (false)
;
1179}
1180
1181void Verifier::visitDINamespace(const DINamespace &N) {
1182 AssertDI(N.getTag() == dwarf::DW_TAG_namespace, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_namespace)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1183 if (auto *S = N.getRawScope())
1184 AssertDI(isa<DIScope>(S), "invalid scope ref", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope ref"
, &N, S); return; } } while (false)
;
1185}
1186
1187void Verifier::visitDIMacro(const DIMacro &N) {
1188 AssertDI(N.getMacinfoType() == dwarf::DW_MACINFO_define ||do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_define || N
.getMacinfoType() == dwarf::DW_MACINFO_undef)) { DebugInfoCheckFailed
("invalid macinfo type", &N); return; } } while (false)
1189 N.getMacinfoType() == dwarf::DW_MACINFO_undef,do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_define || N
.getMacinfoType() == dwarf::DW_MACINFO_undef)) { DebugInfoCheckFailed
("invalid macinfo type", &N); return; } } while (false)
1190 "invalid macinfo type", &N)do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_define || N
.getMacinfoType() == dwarf::DW_MACINFO_undef)) { DebugInfoCheckFailed
("invalid macinfo type", &N); return; } } while (false)
;
1191 AssertDI(!N.getName().empty(), "anonymous macro", &N)do { if (!(!N.getName().empty())) { DebugInfoCheckFailed("anonymous macro"
, &N); return; } } while (false)
;
1192 if (!N.getValue().empty()) {
1193 assert(N.getValue().data()[0] != ' ' && "Macro value has a space prefix")((N.getValue().data()[0] != ' ' && "Macro value has a space prefix"
) ? static_cast<void> (0) : __assert_fail ("N.getValue().data()[0] != ' ' && \"Macro value has a space prefix\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 1193, __PRETTY_FUNCTION__))
;
1194 }
1195}
1196
1197void Verifier::visitDIMacroFile(const DIMacroFile &N) {
1198 AssertDI(N.getMacinfoType() == dwarf::DW_MACINFO_start_file,do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_start_file
)) { DebugInfoCheckFailed("invalid macinfo type", &N); return
; } } while (false)
1199 "invalid macinfo type", &N)do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_start_file
)) { DebugInfoCheckFailed("invalid macinfo type", &N); return
; } } while (false)
;
1200 if (auto *F = N.getRawFile())
1201 AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file"
, &N, F); return; } } while (false)
;
1202
1203 if (auto *Array = N.getRawElements()) {
1204 AssertDI(isa<MDTuple>(Array), "invalid macro list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed
("invalid macro list", &N, Array); return; } } while (false
)
;
1205 for (Metadata *Op : N.getElements()->operands()) {
1206 AssertDI(Op && isa<DIMacroNode>(Op), "invalid macro ref", &N, Op)do { if (!(Op && isa<DIMacroNode>(Op))) { DebugInfoCheckFailed
("invalid macro ref", &N, Op); return; } } while (false)
;
1207 }
1208 }
1209}
1210
1211void Verifier::visitDIModule(const DIModule &N) {
1212 AssertDI(N.getTag() == dwarf::DW_TAG_module, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_module)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1213 AssertDI(!N.getName().empty(), "anonymous module", &N)do { if (!(!N.getName().empty())) { DebugInfoCheckFailed("anonymous module"
, &N); return; } } while (false)
;
1214}
1215
1216void Verifier::visitDITemplateParameter(const DITemplateParameter &N) {
1217 AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType())do { if (!(isType(N.getRawType()))) { DebugInfoCheckFailed("invalid type ref"
, &N, N.getRawType()); return; } } while (false)
;
1218}
1219
1220void Verifier::visitDITemplateTypeParameter(const DITemplateTypeParameter &N) {
1221 visitDITemplateParameter(N);
1222
1223 AssertDI(N.getTag() == dwarf::DW_TAG_template_type_parameter, "invalid tag",do { if (!(N.getTag() == dwarf::DW_TAG_template_type_parameter
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
1224 &N)do { if (!(N.getTag() == dwarf::DW_TAG_template_type_parameter
)) { DebugInfoCheckFailed("invalid tag", &N); return; } }
while (false)
;
1225}
1226
1227void Verifier::visitDITemplateValueParameter(
1228 const DITemplateValueParameter &N) {
1229 visitDITemplateParameter(N);
1230
1231 AssertDI(N.getTag() == dwarf::DW_TAG_template_value_parameter ||do { if (!(N.getTag() == dwarf::DW_TAG_template_value_parameter
|| N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||
N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
1232 N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||do { if (!(N.getTag() == dwarf::DW_TAG_template_value_parameter
|| N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||
N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
1233 N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack,do { if (!(N.getTag() == dwarf::DW_TAG_template_value_parameter
|| N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||
N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
1234 "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_template_value_parameter
|| N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||
N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1235}
1236
1237void Verifier::visitDIVariable(const DIVariable &N) {
1238 if (auto *S = N.getRawScope())
1239 AssertDI(isa<DIScope>(S), "invalid scope", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope"
, &N, S); return; } } while (false)
;
1240 if (auto *F = N.getRawFile())
1241 AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file"
, &N, F); return; } } while (false)
;
1242}
1243
1244void Verifier::visitDIGlobalVariable(const DIGlobalVariable &N) {
1245 // Checks common to all variables.
1246 visitDIVariable(N);
1247
1248 AssertDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_variable)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1249 AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType())do { if (!(isType(N.getRawType()))) { DebugInfoCheckFailed("invalid type ref"
, &N, N.getRawType()); return; } } while (false)
;
1250 AssertDI(N.getType(), "missing global variable type", &N)do { if (!(N.getType())) { DebugInfoCheckFailed("missing global variable type"
, &N); return; } } while (false)
;
1251 if (auto *Member = N.getRawStaticDataMemberDeclaration()) {
1252 AssertDI(isa<DIDerivedType>(Member),do { if (!(isa<DIDerivedType>(Member))) { DebugInfoCheckFailed
("invalid static data member declaration", &N, Member); return
; } } while (false)
1253 "invalid static data member declaration", &N, Member)do { if (!(isa<DIDerivedType>(Member))) { DebugInfoCheckFailed
("invalid static data member declaration", &N, Member); return
; } } while (false)
;
1254 }
1255}
1256
1257void Verifier::visitDILocalVariable(const DILocalVariable &N) {
1258 // Checks common to all variables.
1259 visitDIVariable(N);
1260
1261 AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType())do { if (!(isType(N.getRawType()))) { DebugInfoCheckFailed("invalid type ref"
, &N, N.getRawType()); return; } } while (false)
;
1262 AssertDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_variable)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1263 AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { DebugInfoCheckFailed("local variable requires a valid scope"
, &N, N.getRawScope()); return; } } while (false)
1264 "local variable requires a valid scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { DebugInfoCheckFailed("local variable requires a valid scope"
, &N, N.getRawScope()); return; } } while (false)
;
1265 if (auto Ty = N.getType())
1266 AssertDI(!isa<DISubroutineType>(Ty), "invalid type", &N, N.getType())do { if (!(!isa<DISubroutineType>(Ty))) { DebugInfoCheckFailed
("invalid type", &N, N.getType()); return; } } while (false
)
;
1267}
1268
1269void Verifier::visitDILabel(const DILabel &N) {
1270 if (auto *S = N.getRawScope())
1271 AssertDI(isa<DIScope>(S), "invalid scope", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope"
, &N, S); return; } } while (false)
;
1272 if (auto *F = N.getRawFile())
1273 AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file"
, &N, F); return; } } while (false)
;
1274
1275 AssertDI(N.getTag() == dwarf::DW_TAG_label, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_label)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1276 AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { DebugInfoCheckFailed("label requires a valid scope"
, &N, N.getRawScope()); return; } } while (false)
1277 "label requires a valid scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope>
(N.getRawScope()))) { DebugInfoCheckFailed("label requires a valid scope"
, &N, N.getRawScope()); return; } } while (false)
;
1278}
1279
1280void Verifier::visitDIExpression(const DIExpression &N) {
1281 AssertDI(N.isValid(), "invalid expression", &N)do { if (!(N.isValid())) { DebugInfoCheckFailed("invalid expression"
, &N); return; } } while (false)
;
1282}
1283
1284void Verifier::visitDIGlobalVariableExpression(
1285 const DIGlobalVariableExpression &GVE) {
1286 AssertDI(GVE.getVariable(), "missing variable")do { if (!(GVE.getVariable())) { DebugInfoCheckFailed("missing variable"
); return; } } while (false)
;
1287 if (auto *Var = GVE.getVariable())
1288 visitDIGlobalVariable(*Var);
1289 if (auto *Expr = GVE.getExpression()) {
1290 visitDIExpression(*Expr);
1291 if (auto Fragment = Expr->getFragmentInfo())
1292 verifyFragmentExpression(*GVE.getVariable(), *Fragment, &GVE);
1293 }
1294}
1295
1296void Verifier::visitDIObjCProperty(const DIObjCProperty &N) {
1297 AssertDI(N.getTag() == dwarf::DW_TAG_APPLE_property, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_APPLE_property)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1298 if (auto *T = N.getRawType())
1299 AssertDI(isType(T), "invalid type ref", &N, T)do { if (!(isType(T))) { DebugInfoCheckFailed("invalid type ref"
, &N, T); return; } } while (false)
;
1300 if (auto *F = N.getRawFile())
1301 AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file"
, &N, F); return; } } while (false)
;
1302}
1303
1304void Verifier::visitDIImportedEntity(const DIImportedEntity &N) {
1305 AssertDI(N.getTag() == dwarf::DW_TAG_imported_module ||do { if (!(N.getTag() == dwarf::DW_TAG_imported_module || N.getTag
() == dwarf::DW_TAG_imported_declaration)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
1306 N.getTag() == dwarf::DW_TAG_imported_declaration,do { if (!(N.getTag() == dwarf::DW_TAG_imported_module || N.getTag
() == dwarf::DW_TAG_imported_declaration)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
1307 "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_imported_module || N.getTag
() == dwarf::DW_TAG_imported_declaration)) { DebugInfoCheckFailed
("invalid tag", &N); return; } } while (false)
;
1308 if (auto *S = N.getRawScope())
1309 AssertDI(isa<DIScope>(S), "invalid scope for imported entity", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope for imported entity"
, &N, S); return; } } while (false)
;
1310 AssertDI(isDINode(N.getRawEntity()), "invalid imported entity", &N,do { if (!(isDINode(N.getRawEntity()))) { DebugInfoCheckFailed
("invalid imported entity", &N, N.getRawEntity()); return
; } } while (false)
1311 N.getRawEntity())do { if (!(isDINode(N.getRawEntity()))) { DebugInfoCheckFailed
("invalid imported entity", &N, N.getRawEntity()); return
; } } while (false)
;
1312}
1313
1314void Verifier::visitComdat(const Comdat &C) {
1315 // In COFF the Module is invalid if the GlobalValue has private linkage.
1316 // Entities with private linkage don't have entries in the symbol table.
1317 if (TT.isOSBinFormatCOFF())
1318 if (const GlobalValue *GV = M.getNamedValue(C.getName()))
1319 Assert(!GV->hasPrivateLinkage(),do { if (!(!GV->hasPrivateLinkage())) { CheckFailed("comdat global value has private linkage"
, GV); return; } } while (false)
1320 "comdat global value has private linkage", GV)do { if (!(!GV->hasPrivateLinkage())) { CheckFailed("comdat global value has private linkage"
, GV); return; } } while (false)
;
1321}
1322
1323void Verifier::visitModuleIdents(const Module &M) {
1324 const NamedMDNode *Idents = M.getNamedMetadata("llvm.ident");
1325 if (!Idents)
1326 return;
1327
1328 // llvm.ident takes a list of metadata entry. Each entry has only one string.
1329 // Scan each llvm.ident entry and make sure that this requirement is met.
1330 for (const MDNode *N : Idents->operands()) {
1331 Assert(N->getNumOperands() == 1,do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.ident metadata"
, N); return; } } while (false)
1332 "incorrect number of operands in llvm.ident metadata", N)do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.ident metadata"
, N); return; } } while (false)
;
1333 Assert(dyn_cast_or_null<MDString>(N->getOperand(0)),do { if (!(dyn_cast_or_null<MDString>(N->getOperand(
0)))) { CheckFailed(("invalid value for llvm.ident metadata entry operand"
"(the operand should be a string)"), N->getOperand(0)); return
; } } while (false)
1334 ("invalid value for llvm.ident metadata entry operand"do { if (!(dyn_cast_or_null<MDString>(N->getOperand(
0)))) { CheckFailed(("invalid value for llvm.ident metadata entry operand"
"(the operand should be a string)"), N->getOperand(0)); return
; } } while (false)
1335 "(the operand should be a string)"),do { if (!(dyn_cast_or_null<MDString>(N->getOperand(
0)))) { CheckFailed(("invalid value for llvm.ident metadata entry operand"
"(the operand should be a string)"), N->getOperand(0)); return
; } } while (false)
1336 N->getOperand(0))do { if (!(dyn_cast_or_null<MDString>(N->getOperand(
0)))) { CheckFailed(("invalid value for llvm.ident metadata entry operand"
"(the operand should be a string)"), N->getOperand(0)); return
; } } while (false)
;
1337 }
1338}
1339
1340void Verifier::visitModuleCommandLines(const Module &M) {
1341 const NamedMDNode *CommandLines = M.getNamedMetadata("llvm.commandline");
1342 if (!CommandLines)
1343 return;
1344
1345 // llvm.commandline takes a list of metadata entry. Each entry has only one
1346 // string. Scan each llvm.commandline entry and make sure that this
1347 // requirement is met.
1348 for (const MDNode *N : CommandLines->operands()) {
1349 Assert(N->getNumOperands() == 1,do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.commandline metadata"
, N); return; } } while (false)
1350 "incorrect number of operands in llvm.commandline metadata", N)do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.commandline metadata"
, N); return; } } while (false)
;
1351 Assert(dyn_cast_or_null<MDString>(N->getOperand(0)),do { if (!(dyn_cast_or_null<MDString>(N->getOperand(
0)))) { CheckFailed(("invalid value for llvm.commandline metadata entry operand"
"(the operand should be a string)"), N->getOperand(0)); return
; } } while (false)
1352 ("invalid value for llvm.commandline metadata entry operand"do { if (!(dyn_cast_or_null<MDString>(N->getOperand(
0)))) { CheckFailed(("invalid value for llvm.commandline metadata entry operand"
"(the operand should be a string)"), N->getOperand(0)); return
; } } while (false)
1353 "(the operand should be a string)"),do { if (!(dyn_cast_or_null<MDString>(N->getOperand(
0)))) { CheckFailed(("invalid value for llvm.commandline metadata entry operand"
"(the operand should be a string)"), N->getOperand(0)); return
; } } while (false)
1354 N->getOperand(0))do { if (!(dyn_cast_or_null<MDString>(N->getOperand(
0)))) { CheckFailed(("invalid value for llvm.commandline metadata entry operand"
"(the operand should be a string)"), N->getOperand(0)); return
; } } while (false)
;
1355 }
1356}
1357
1358void Verifier::visitModuleFlags(const Module &M) {
1359 const NamedMDNode *Flags = M.getModuleFlagsMetadata();
1360 if (!Flags) return;
1361
1362 // Scan each flag, and track the flags and requirements.
1363 DenseMap<const MDString*, const MDNode*> SeenIDs;
1364 SmallVector<const MDNode*, 16> Requirements;
1365 for (const MDNode *MDN : Flags->operands())
1366 visitModuleFlag(MDN, SeenIDs, Requirements);
1367
1368 // Validate that the requirements in the module are valid.
1369 for (const MDNode *Requirement : Requirements) {
1370 const MDString *Flag = cast<MDString>(Requirement->getOperand(0));
1371 const Metadata *ReqValue = Requirement->getOperand(1);
1372
1373 const MDNode *Op = SeenIDs.lookup(Flag);
1374 if (!Op) {
1375 CheckFailed("invalid requirement on flag, flag is not present in module",
1376 Flag);
1377 continue;
1378 }
1379
1380 if (Op->getOperand(2) != ReqValue) {
1381 CheckFailed(("invalid requirement on flag, "
1382 "flag does not have the required value"),
1383 Flag);
1384 continue;
1385 }
1386 }
1387}
1388
1389void
1390Verifier::visitModuleFlag(const MDNode *Op,
1391 DenseMap<const MDString *, const MDNode *> &SeenIDs,
1392 SmallVectorImpl<const MDNode *> &Requirements) {
1393 // Each module flag should have three arguments, the merge behavior (a
1394 // constant int), the flag ID (an MDString), and the value.
1395 Assert(Op->getNumOperands() == 3,do { if (!(Op->getNumOperands() == 3)) { CheckFailed("incorrect number of operands in module flag"
, Op); return; } } while (false)
1396 "incorrect number of operands in module flag", Op)do { if (!(Op->getNumOperands() == 3)) { CheckFailed("incorrect number of operands in module flag"
, Op); return; } } while (false)
;
1397 Module::ModFlagBehavior MFB;
1398 if (!Module::isValidModFlagBehavior(Op->getOperand(0), MFB)) {
1399 Assert(do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op
->getOperand(0)))) { CheckFailed("invalid behavior operand in module flag (expected constant integer)"
, Op->getOperand(0)); return; } } while (false)
1400 mdconst::dyn_extract_or_null<ConstantInt>(Op->getOperand(0)),do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op
->getOperand(0)))) { CheckFailed("invalid behavior operand in module flag (expected constant integer)"
, Op->getOperand(0)); return; } } while (false)
1401 "invalid behavior operand in module flag (expected constant integer)",do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op
->getOperand(0)))) { CheckFailed("invalid behavior operand in module flag (expected constant integer)"
, Op->getOperand(0)); return; } } while (false)
1402 Op->getOperand(0))do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op
->getOperand(0)))) { CheckFailed("invalid behavior operand in module flag (expected constant integer)"
, Op->getOperand(0)); return; } } while (false)
;
1403 Assert(false,do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)"
, Op->getOperand(0)); return; } } while (false)
1404 "invalid behavior operand in module flag (unexpected constant)",do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)"
, Op->getOperand(0)); return; } } while (false)
1405 Op->getOperand(0))do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)"
, Op->getOperand(0)); return; } } while (false)
;
1406 }
1407 MDString *ID = dyn_cast_or_null<MDString>(Op->getOperand(1));
1408 Assert(ID, "invalid ID operand in module flag (expected metadata string)",do { if (!(ID)) { CheckFailed("invalid ID operand in module flag (expected metadata string)"
, Op->getOperand(1)); return; } } while (false)
1409 Op->getOperand(1))do { if (!(ID)) { CheckFailed("invalid ID operand in module flag (expected metadata string)"
, Op->getOperand(1)); return; } } while (false)
;
1410
1411 // Sanity check the values for behaviors with additional requirements.
1412 switch (MFB) {
1413 case Module::Error:
1414 case Module::Warning:
1415 case Module::Override:
1416 // These behavior types accept any value.
1417 break;
1418
1419 case Module::Max: {
1420 Assert(mdconst::dyn_extract_or_null<ConstantInt>(Op->getOperand(2)),do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op
->getOperand(2)))) { CheckFailed("invalid value for 'max' module flag (expected constant integer)"
, Op->getOperand(2)); return; } } while (false)
1421 "invalid value for 'max' module flag (expected constant integer)",do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op
->getOperand(2)))) { CheckFailed("invalid value for 'max' module flag (expected constant integer)"
, Op->getOperand(2)); return; } } while (false)
1422 Op->getOperand(2))do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op
->getOperand(2)))) { CheckFailed("invalid value for 'max' module flag (expected constant integer)"
, Op->getOperand(2)); return; } } while (false)
;
1423 break;
1424 }
1425
1426 case Module::Require: {
1427 // The value should itself be an MDNode with two operands, a flag ID (an
1428 // MDString), and a value.
1429 MDNode *Value = dyn_cast<MDNode>(Op->getOperand(2));
1430 Assert(Value && Value->getNumOperands() == 2,do { if (!(Value && Value->getNumOperands() == 2))
{ CheckFailed("invalid value for 'require' module flag (expected metadata pair)"
, Op->getOperand(2)); return; } } while (false)
1431 "invalid value for 'require' module flag (expected metadata pair)",do { if (!(Value && Value->getNumOperands() == 2))
{ CheckFailed("invalid value for 'require' module flag (expected metadata pair)"
, Op->getOperand(2)); return; } } while (false)
1432 Op->getOperand(2))do { if (!(Value && Value->getNumOperands() == 2))
{ CheckFailed("invalid value for 'require' module flag (expected metadata pair)"
, Op->getOperand(2)); return; } } while (false)
;
1433 Assert(isa<MDString>(Value->getOperand(0)),do { if (!(isa<MDString>(Value->getOperand(0)))) { CheckFailed
(("invalid value for 'require' module flag " "(first value operand should be a string)"
), Value->getOperand(0)); return; } } while (false)
1434 ("invalid value for 'require' module flag "do { if (!(isa<MDString>(Value->getOperand(0)))) { CheckFailed
(("invalid value for 'require' module flag " "(first value operand should be a string)"
), Value->getOperand(0)); return; } } while (false)
1435 "(first value operand should be a string)"),do { if (!(isa<MDString>(Value->getOperand(0)))) { CheckFailed
(("invalid value for 'require' module flag " "(first value operand should be a string)"
), Value->getOperand(0)); return; } } while (false)
1436 Value->getOperand(0))do { if (!(isa<MDString>(Value->getOperand(0)))) { CheckFailed
(("invalid value for 'require' module flag " "(first value operand should be a string)"
), Value->getOperand(0)); return; } } while (false)
;
1437
1438 // Append it to the list of requirements, to check once all module flags are
1439 // scanned.
1440 Requirements.push_back(Value);
1441 break;
1442 }
1443
1444 case Module::Append:
1445 case Module::AppendUnique: {
1446 // These behavior types require the operand be an MDNode.
1447 Assert(isa<MDNode>(Op->getOperand(2)),do { if (!(isa<MDNode>(Op->getOperand(2)))) { CheckFailed
("invalid value for 'append'-type module flag " "(expected a metadata node)"
, Op->getOperand(2)); return; } } while (false)
1448 "invalid value for 'append'-type module flag "do { if (!(isa<MDNode>(Op->getOperand(2)))) { CheckFailed
("invalid value for 'append'-type module flag " "(expected a metadata node)"
, Op->getOperand(2)); return; } } while (false)
1449 "(expected a metadata node)",do { if (!(isa<MDNode>(Op->getOperand(2)))) { CheckFailed
("invalid value for 'append'-type module flag " "(expected a metadata node)"
, Op->getOperand(2)); return; } } while (false)
1450 Op->getOperand(2))do { if (!(isa<MDNode>(Op->getOperand(2)))) { CheckFailed
("invalid value for 'append'-type module flag " "(expected a metadata node)"
, Op->getOperand(2)); return; } } while (false)
;
1451 break;
1452 }
1453 }
1454
1455 // Unless this is a "requires" flag, check the ID is unique.
1456 if (MFB != Module::Require) {
1457 bool Inserted = SeenIDs.insert(std::make_pair(ID, Op)).second;
1458 Assert(Inserted,do { if (!(Inserted)) { CheckFailed("module flag identifiers must be unique (or of 'require' type)"
, ID); return; } } while (false)
1459 "module flag identifiers must be unique (or of 'require' type)", ID)do { if (!(Inserted)) { CheckFailed("module flag identifiers must be unique (or of 'require' type)"
, ID); return; } } while (false)
;
1460 }
1461
1462 if (ID->getString() == "wchar_size") {
1463 ConstantInt *Value
1464 = mdconst::dyn_extract_or_null<ConstantInt>(Op->getOperand(2));
1465 Assert(Value, "wchar_size metadata requires constant integer argument")do { if (!(Value)) { CheckFailed("wchar_size metadata requires constant integer argument"
); return; } } while (false)
;
1466 }
1467
1468 if (ID->getString() == "Linker Options") {
1469 // If the llvm.linker.options named metadata exists, we assume that the
1470 // bitcode reader has upgraded the module flag. Otherwise the flag might
1471 // have been created by a client directly.
1472 Assert(M.getNamedMetadata("llvm.linker.options"),do { if (!(M.getNamedMetadata("llvm.linker.options"))) { CheckFailed
("'Linker Options' named metadata no longer supported"); return
; } } while (false)
1473 "'Linker Options' named metadata no longer supported")do { if (!(M.getNamedMetadata("llvm.linker.options"))) { CheckFailed
("'Linker Options' named metadata no longer supported"); return
; } } while (false)
;
1474 }
1475
1476 if (ID->getString() == "SemanticInterposition") {
1477 ConstantInt *Value =
1478 mdconst::dyn_extract_or_null<ConstantInt>(Op->getOperand(2));
1479 Assert(Value,do { if (!(Value)) { CheckFailed("SemanticInterposition metadata requires constant integer argument"
); return; } } while (false)
1480 "SemanticInterposition metadata requires constant integer argument")do { if (!(Value)) { CheckFailed("SemanticInterposition metadata requires constant integer argument"
); return; } } while (false)
;
1481 }
1482
1483 if (ID->getString() == "CG Profile") {
1484 for (const MDOperand &MDO : cast<MDNode>(Op->getOperand(2))->operands())
1485 visitModuleFlagCGProfileEntry(MDO);
1486 }
1487}
1488
1489void Verifier::visitModuleFlagCGProfileEntry(const MDOperand &MDO) {
1490 auto CheckFunction = [&](const MDOperand &FuncMDO) {
1491 if (!FuncMDO)
1492 return;
1493 auto F = dyn_cast<ValueAsMetadata>(FuncMDO);
1494 Assert(F && isa<Function>(F->getValue()), "expected a Function or null",do { if (!(F && isa<Function>(F->getValue())
)) { CheckFailed("expected a Function or null", FuncMDO); return
; } } while (false)
1495 FuncMDO)do { if (!(F && isa<Function>(F->getValue())
)) { CheckFailed("expected a Function or null", FuncMDO); return
; } } while (false)
;
1496 };
1497 auto Node = dyn_cast_or_null<MDNode>(MDO);
1498 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)
;
1499 CheckFunction(Node->getOperand(0));
1500 CheckFunction(Node->getOperand(1));
1501 auto Count = dyn_cast_or_null<ConstantAsMetadata>(Node->getOperand(2));
1502 Assert(Count && Count->getType()->isIntegerTy(),do { if (!(Count && Count->getType()->isIntegerTy
())) { CheckFailed("expected an integer constant", Node->getOperand
(2)); return; } } while (false)
1503 "expected an integer constant", Node->getOperand(2))do { if (!(Count && Count->getType()->isIntegerTy
())) { CheckFailed("expected an integer constant", Node->getOperand
(2)); return; } } while (false)
;
1504}
1505
1506/// Return true if this attribute kind only applies to functions.
1507static bool isFuncOnlyAttr(Attribute::AttrKind Kind) {
1508 switch (Kind) {
1509 case Attribute::NoReturn:
1510 case Attribute::NoSync:
1511 case Attribute::WillReturn:
1512 case Attribute::NoCfCheck:
1513 case Attribute::NoUnwind:
1514 case Attribute::NoInline:
1515 case Attribute::AlwaysInline:
1516 case Attribute::OptimizeForSize:
1517 case Attribute::StackProtect:
1518 case Attribute::StackProtectReq:
1519 case Attribute::StackProtectStrong:
1520 case Attribute::SafeStack:
1521 case Attribute::ShadowCallStack:
1522 case Attribute::NoRedZone:
1523 case Attribute::NoImplicitFloat:
1524 case Attribute::Naked:
1525 case Attribute::InlineHint:
1526 case Attribute::StackAlignment:
1527 case Attribute::UWTable:
1528 case Attribute::NonLazyBind:
1529 case Attribute::ReturnsTwice:
1530 case Attribute::SanitizeAddress:
1531 case Attribute::SanitizeHWAddress:
1532 case Attribute::SanitizeMemTag:
1533 case Attribute::SanitizeThread:
1534 case Attribute::SanitizeMemory:
1535 case Attribute::MinSize:
1536 case Attribute::NoDuplicate:
1537 case Attribute::Builtin:
1538 case Attribute::NoBuiltin:
1539 case Attribute::Cold:
1540 case Attribute::OptForFuzzing:
1541 case Attribute::OptimizeNone:
1542 case Attribute::JumpTable:
1543 case Attribute::Convergent:
1544 case Attribute::ArgMemOnly:
1545 case Attribute::NoRecurse:
1546 case Attribute::InaccessibleMemOnly:
1547 case Attribute::InaccessibleMemOrArgMemOnly:
1548 case Attribute::AllocSize:
1549 case Attribute::SpeculativeLoadHardening:
1550 case Attribute::Speculatable:
1551 case Attribute::StrictFP:
1552 return true;
1553 default:
1554 break;
1555 }
1556 return false;
1557}
1558
1559/// Return true if this is a function attribute that can also appear on
1560/// arguments.
1561static bool isFuncOrArgAttr(Attribute::AttrKind Kind) {
1562 return Kind == Attribute::ReadOnly || Kind == Attribute::WriteOnly ||
1563 Kind == Attribute::ReadNone || Kind == Attribute::NoFree;
1564}
1565
1566void Verifier::verifyAttributeTypes(AttributeSet Attrs, bool IsFunction,
1567 const Value *V) {
1568 for (Attribute A : Attrs) {
1569 if (A.isStringAttribute())
1570 continue;
1571
1572 if (A.isIntAttribute() !=
1573 Attribute::doesAttrKindHaveArgument(A.getKindAsEnum())) {
1574 CheckFailed("Attribute '" + A.getAsString() + "' should have an Argument",
1575 V);
1576 return;
1577 }
1578
1579 if (isFuncOnlyAttr(A.getKindAsEnum())) {
1580 if (!IsFunction) {
1581 CheckFailed("Attribute '" + A.getAsString() +
1582 "' only applies to functions!",
1583 V);
1584 return;
1585 }
1586 } else if (IsFunction && !isFuncOrArgAttr(A.getKindAsEnum())) {
1587 CheckFailed("Attribute '" + A.getAsString() +
1588 "' does not apply to functions!",
1589 V);
1590 return;
1591 }
1592 }
1593}
1594
1595// VerifyParameterAttrs - Check the given attributes for an argument or return
1596// value of the specified type. The value V is printed in error messages.
1597void Verifier::verifyParameterAttrs(AttributeSet Attrs, Type *Ty,
1598 const Value *V) {
1599 if (!Attrs.hasAttributes())
1600 return;
1601
1602 verifyAttributeTypes(Attrs, /*IsFunction=*/false, V);
1603
1604 if (Attrs.hasAttribute(Attribute::ImmArg)) {
1605 Assert(Attrs.getNumAttributes() == 1,do { if (!(Attrs.getNumAttributes() == 1)) { CheckFailed("Attribute 'immarg' is incompatible with other attributes"
, V); return; } } while (false)
1606 "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)
;
1607 }
1608
1609 // Check for mutually incompatible attributes. Only inreg is compatible with
1610 // sret.
1611 unsigned AttrCount = 0;
1612 AttrCount += Attrs.hasAttribute(Attribute::ByVal);
1613 AttrCount += Attrs.hasAttribute(Attribute::InAlloca);
1614 AttrCount += Attrs.hasAttribute(Attribute::StructRet) ||
1615 Attrs.hasAttribute(Attribute::InReg);
1616 AttrCount += Attrs.hasAttribute(Attribute::Nest);
1617 Assert(AttrCount <= 1, "Attributes 'byval', 'inalloca', 'inreg', 'nest', "do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'inreg', 'nest', "
"and 'sret' are incompatible!", V); return; } } while (false
)
1618 "and 'sret' are incompatible!",do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'inreg', 'nest', "
"and 'sret' are incompatible!", V); return; } } while (false
)
1619 V)do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'inreg', 'nest', "
"and 'sret' are incompatible!", V); return; } } while (false
)
;
1620
1621 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)
1622 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)
1623 "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) &&
Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes "
"'inalloca and readonly' are incompatible!", V); return; } }
while (false)
1624 "'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)
1625 V)do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) &&
Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes "
"'inalloca and readonly' are incompatible!", V); return; } }
while (false)
;
1626
1627 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)
1628 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)
1629 "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) &&
Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes "
"'sret and returned' are incompatible!", V); return; } } while
(false)
1630 "'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)
1631 V)do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) &&
Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes "
"'sret and returned' are incompatible!", V); return; } } while
(false)
;
1632
1633 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)
1634 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)
1635 "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs
.hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes "
"'zeroext and signext' are incompatible!", V); return; } } while
(false)
1636 "'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)
1637 V)do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs
.hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes "
"'zeroext and signext' are incompatible!", V); return; } } while
(false)
;
1638
1639 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)
1640 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)
1641 "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) &&
Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes "
"'readnone and readonly' are incompatible!", V); return; } }
while (false)
1642 "'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)
1643 V)do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) &&
Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes "
"'readnone and readonly' are incompatible!", V); return; } }
while (false)
;
1644
1645 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)
1646 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)
1647 "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) &&
Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes "
"'readnone and writeonly' are incompatible!", V); return; } }
while (false)
1648 "'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)
1649 V)do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) &&
Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes "
"'readnone and writeonly' are incompatible!", V); return; } }
while (false)
;
1650
1651 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)
1652 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)
1653 "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) &&
Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes "
"'readonly and writeonly' are incompatible!", V); return; } }
while (false)
1654 "'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)
1655 V)do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) &&
Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes "
"'readonly and writeonly' are incompatible!", V); return; } }
while (false)
;
1656
1657 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)
1658 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)
1659 "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) &&
Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed
("Attributes " "'noinline and alwaysinline' are incompatible!"
, V); return; } } while (false)
1660 "'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)
1661 V)do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) &&
Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed
("Attributes " "'noinline and alwaysinline' are incompatible!"
, V); return; } } while (false)
;
1662
1663 if (Attrs.hasAttribute(Attribute::ByVal) && Attrs.getByValType()) {
1664 Assert(Attrs.getByValType() == cast<PointerType>(Ty)->getElementType(),do { if (!(Attrs.getByValType() == cast<PointerType>(Ty
)->getElementType())) { CheckFailed("Attribute 'byval' type does not match parameter!"
, V); return; } } while (false)
1665 "Attribute 'byval' type does not match parameter!", V)do { if (!(Attrs.getByValType() == cast<PointerType>(Ty
)->getElementType())) { CheckFailed("Attribute 'byval' type does not match parameter!"
, V); return; } } while (false)
;
1666 }
1667
1668 AttrBuilder IncompatibleAttrs = AttributeFuncs::typeIncompatible(Ty);
1669 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)
1670 "Wrong types for attribute: " +do { if (!(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs))) {
CheckFailed("Wrong types for attribute: " + AttributeSet::get
(Context, IncompatibleAttrs).getAsString(), V); return; } } while
(false)
1671 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)
1672 V)do { if (!(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs))) {
CheckFailed("Wrong types for attribute: " + AttributeSet::get
(Context, IncompatibleAttrs).getAsString(), V); return; } } while
(false)
;
1673
1674 if (PointerType *PTy = dyn_cast<PointerType>(Ty)) {
1675 SmallPtrSet<Type*, 4> Visited;
1676 if (!PTy->getElementType()->isSized(&Visited)) {
1677 Assert(!Attrs.hasAttribute(Attribute::ByVal) &&do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && !
Attrs.hasAttribute(Attribute::InAlloca))) { CheckFailed("Attributes 'byval' and 'inalloca' do not support unsized types!"
, V); return; } } while (false)
1678 !Attrs.hasAttribute(Attribute::InAlloca),do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && !
Attrs.hasAttribute(Attribute::InAlloca))) { CheckFailed("Attributes 'byval' and 'inalloca' do not support unsized types!"
, V); return; } } while (false)
1679 "Attributes 'byval' and 'inalloca' do not support unsized types!",do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && !
Attrs.hasAttribute(Attribute::InAlloca))) { CheckFailed("Attributes 'byval' and 'inalloca' do not support unsized types!"
, V); return; } } while (false)
1680 V)do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && !
Attrs.hasAttribute(Attribute::InAlloca))) { CheckFailed("Attributes 'byval' and 'inalloca' do not support unsized types!"
, V); return; } } while (false)
;
1681 }
1682 if (!isa<PointerType>(PTy->getElementType()))
1683 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)
1684 "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)
1685 "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)
1686 V)do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed
("Attribute 'swifterror' only applies to parameters " "with pointer to pointer type!"
, V); return; } } while (false)
;
1687 } else {
1688 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)
1689 "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)
1690 V)do { if (!(!Attrs.hasAttribute(Attribute::ByVal))) { CheckFailed
("Attribute 'byval' only applies to parameters with pointer type!"
, V); return; } } while (false)
;
1691 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)
1692 "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)
1693 "with pointer type!",do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed
("Attribute 'swifterror' only applies to parameters " "with pointer type!"
, V); return; } } while (false)
1694 V)do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed
("Attribute 'swifterror' only applies to parameters " "with pointer type!"
, V); return; } } while (false)
;
1695 }
1696}
1697
1698// Check parameter attributes against a function type.
1699// The value V is printed in error messages.
1700void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
1701 const Value *V, bool IsIntrinsic) {
1702 if (Attrs.isEmpty())
1703 return;
1704
1705 bool SawNest = false;
1706 bool SawReturned = false;
1707 bool SawSRet = false;
1708 bool SawSwiftSelf = false;
1709 bool SawSwiftError = false;
1710
1711 // Verify return value attributes.
1712 AttributeSet RetAttrs = Attrs.getRetAttributes();
1713 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::SwiftSelf) && !RetAttrs
.hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'"
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1714 !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::SwiftSelf) && !RetAttrs
.hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'"
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1715 !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::SwiftSelf) && !RetAttrs
.hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'"
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1716 !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::SwiftSelf) && !RetAttrs
.hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'"
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1717 !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::SwiftSelf) && !RetAttrs
.hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'"
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1718 !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::SwiftSelf) && !RetAttrs
.hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'"
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1719 !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::SwiftSelf) && !RetAttrs
.hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'"
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1720 !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::SwiftSelf) && !RetAttrs
.hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'"
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1721 !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::SwiftSelf) && !RetAttrs
.hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'"
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1722 "Attributes 'byval', 'inalloca', '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::SwiftSelf) && !RetAttrs
.hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'"
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1723 "'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::SwiftSelf) && !RetAttrs
.hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'"
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1724 "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::SwiftSelf) && !RetAttrs
.hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'"
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
1725 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::SwiftSelf) && !RetAttrs
.hasAttribute(Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', 'nofree'"
"'returned', 'swiftself', and 'swifterror' do not apply to return "
"values!", V); return; } } while (false)
;
1726 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)
1727 !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)
1728 !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)
1729 "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)
1730 "' 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)
1731 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)
;
1732 verifyParameterAttrs(RetAttrs, FT->getReturnType(), V);
1733
1734 // Verify parameter attributes.
1735 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
1736 Type *Ty = FT->getParamType(i);
1737 AttributeSet ArgAttrs = Attrs.getParamAttributes(i);
1738
1739 if (!IsIntrinsic) {
1740 Assert(!ArgAttrs.hasAttribute(Attribute::ImmArg),do { if (!(!ArgAttrs.hasAttribute(Attribute::ImmArg))) { CheckFailed
("immarg attribute only applies to intrinsics",V); return; } }
while (false)
1741 "immarg attribute only applies to intrinsics",V)do { if (!(!ArgAttrs.hasAttribute(Attribute::ImmArg))) { CheckFailed
("immarg attribute only applies to intrinsics",V); return; } }
while (false)
;
1742 }
1743
1744 verifyParameterAttrs(ArgAttrs, Ty, V);
1745
1746 if (ArgAttrs.hasAttribute(Attribute::Nest)) {
1747 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)
;
1748 SawNest = true;
1749 }
1750
1751 if (ArgAttrs.hasAttribute(Attribute::Returned)) {
1752 Assert(!SawReturned, "More than one parameter has attribute returned!",do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!"
, V); return; } } while (false)
1753 V)do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!"
, V); return; } } while (false)
;
1754 Assert(Ty->canLosslesslyBitCastTo(FT->getReturnType()),do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType
()))) { CheckFailed("Incompatible argument and return types for 'returned' attribute"
, V); return; } } while (false)
1755 "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)
1756 V)do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType
()))) { CheckFailed("Incompatible argument and return types for 'returned' attribute"
, V); return; } } while (false)
;
1757 SawReturned = true;
1758 }
1759
1760 if (ArgAttrs.hasAttribute(Attribute::StructRet)) {
1761 Assert(!SawSRet, "Cannot have multiple 'sret' parameters!", V)do { if (!(!SawSRet)) { CheckFailed("Cannot have multiple 'sret' parameters!"
, V); return; } } while (false)
;
1762 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)
1763 "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)
;
1764 SawSRet = true;
1765 }
1766
1767 if (ArgAttrs.hasAttribute(Attribute::SwiftSelf)) {
1768 Assert(!SawSwiftSelf, "Cannot have multiple 'swiftself' parameters!", V)do { if (!(!SawSwiftSelf)) { CheckFailed("Cannot have multiple 'swiftself' parameters!"
, V); return; } } while (false)
;
1769 SawSwiftSelf = true;
1770 }
1771
1772 if (ArgAttrs.hasAttribute(Attribute::SwiftError)) {
1773 Assert(!SawSwiftError, "Cannot have multiple 'swifterror' parameters!",do { if (!(!SawSwiftError)) { CheckFailed("Cannot have multiple 'swifterror' parameters!"
, V); return; } } while (false)
1774 V)do { if (!(!SawSwiftError)) { CheckFailed("Cannot have multiple 'swifterror' parameters!"
, V); return; } } while (false)
;
1775 SawSwiftError = true;
1776 }
1777
1778 if (ArgAttrs.hasAttribute(Attribute::InAlloca)) {
1779 Assert(i == FT->getNumParams() - 1,do { if (!(i == FT->getNumParams() - 1)) { CheckFailed("inalloca isn't on the last parameter!"
, V); return; } } while (false)
1780 "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)
;
1781 }
1782 }
1783
1784 if (!Attrs.hasAttributes(AttributeList::FunctionIndex))
1785 return;
1786
1787 verifyAttributeTypes(Attrs.getFnAttributes(), /*IsFunction=*/true, V);
1788
1789 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)
1790 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)
1791 "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)
;
1792
1793 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)
1794 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)
1795 "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)
;
1796
1797 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)
1798 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)
1799 "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)
;
1800
1801 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)
1802 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)
1803 "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)
1804 "incompatible!",do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&
Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly)
))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are "
"incompatible!", V); return; } } while (false)
1805 V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&
Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly)
))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are "
"incompatible!", V); return; } } while (false)
;
1806
1807 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)
1808 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)
1809 "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)
;
1810
1811 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)
1812 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)
1813 "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)
;
1814
1815 if (Attrs.hasFnAttribute(Attribute::OptimizeNone)) {
1816 Assert(Attrs.hasFnAttribute(Attribute::NoInline),do { if (!(Attrs.hasFnAttribute(Attribute::NoInline))) { CheckFailed
("Attribute 'optnone' requires 'noinline'!", V); return; } } while
(false)
1817 "Attribute 'optnone' requires 'noinline'!", V)do { if (!(Attrs.hasFnAttribute(Attribute::NoInline))) { CheckFailed
("Attribute 'optnone' requires 'noinline'!", V); return; } } while
(false)
;
1818
1819 Assert(!Attrs.hasFnAttribute(Attribute::OptimizeForSize),do { if (!(!Attrs.hasFnAttribute(Attribute::OptimizeForSize))
) { CheckFailed("Attributes 'optsize and optnone' are incompatible!"
, V); return; } } while (false)
1820 "Attributes 'optsize and optnone' are incompatible!", V)do { if (!(!Attrs.hasFnAttribute(Attribute::OptimizeForSize))
) { CheckFailed("Attributes 'optsize and optnone' are incompatible!"
, V); return; } } while (false)
;
1821
1822 Assert(!Attrs.hasFnAttribute(Attribute::MinSize),do { if (!(!Attrs.hasFnAttribute(Attribute::MinSize))) { CheckFailed
("Attributes 'minsize and optnone' are incompatible!", V); return
; } } while (false)
1823 "Attributes 'minsize and optnone' are incompatible!", V)do { if (!(!Attrs.hasFnAttribute(Attribute::MinSize))) { CheckFailed
("Attributes 'minsize and optnone' are incompatible!", V); return
; } } while (false)
;
1824 }
1825
1826 if (Attrs.hasFnAttribute(Attribute::JumpTable)) {
1827 const GlobalValue *GV = cast<GlobalValue>(V);
1828 Assert(GV->hasGlobalUnnamedAddr(),do { if (!(GV->hasGlobalUnnamedAddr())) { CheckFailed("Attribute 'jumptable' requires 'unnamed_addr'"
, V); return; } } while (false)
1829 "Attribute 'jumptable' requires 'unnamed_addr'", V)do { if (!(GV->hasGlobalUnnamedAddr())) { CheckFailed("Attribute 'jumptable' requires 'unnamed_addr'"
, V); return; } } while (false)
;
1830 }
1831
1832 if (Attrs.hasFnAttribute(Attribute::AllocSize)) {
1833 std::pair<unsigned, Optional<unsigned>> Args =
1834 Attrs.getAllocSizeArgs(AttributeList::FunctionIndex);
1835
1836 auto CheckParam = [&](StringRef Name, unsigned ParamNo) {
1837 if (ParamNo >= FT->getNumParams()) {
1838 CheckFailed("'allocsize' " + Name + " argument is out of bounds", V);
1839 return false;
1840 }
1841
1842 if (!FT->getParamType(ParamNo)->isIntegerTy()) {
1843 CheckFailed("'allocsize' " + Name +
1844 " argument must refer to an integer parameter",
1845 V);
1846 return false;
1847 }
1848
1849 return true;
1850 };
1851
1852 if (!CheckParam("element size", Args.first))
1853 return;
1854
1855 if (Args.second && !CheckParam("number of elements", *Args.second))
1856 return;
1857 }
1858
1859 if (Attrs.hasFnAttribute("frame-pointer")) {
1860 StringRef FP = Attrs.getAttribute(AttributeList::FunctionIndex,
1861 "frame-pointer").getValueAsString();
1862 if (FP != "all" && FP != "non-leaf" && FP != "none")
1863 CheckFailed("invalid value for 'frame-pointer' attribute: " + FP, V);
1864 }
1865
1866 if (Attrs.hasFnAttribute("patchable-function-prefix")) {
1867 StringRef S = Attrs
1868 .getAttribute(AttributeList::FunctionIndex,
1869 "patchable-function-prefix")
1870 .getValueAsString();
1871 unsigned N;
1872 if (S.getAsInteger(10, N))
1873 CheckFailed(
1874 "\"patchable-function-prefix\" takes an unsigned integer: " + S, V);
1875 }
1876 if (Attrs.hasFnAttribute("patchable-function-entry")) {
1877 StringRef S = Attrs
1878 .getAttribute(AttributeList::FunctionIndex,
1879 "patchable-function-entry")
1880 .getValueAsString();
1881 unsigned N;
1882 if (S.getAsInteger(10, N))
1883 CheckFailed(
1884 "\"patchable-function-entry\" takes an unsigned integer: " + S, V);
1885 }
1886}
1887
1888void Verifier::verifyFunctionMetadata(
1889 ArrayRef<std::pair<unsigned, MDNode *>> MDs) {
1890 for (const auto &Pair : MDs) {
1891 if (Pair.first == LLVMContext::MD_prof) {
1892 MDNode *MD = Pair.second;
1893 Assert(MD->getNumOperands() >= 2,do { if (!(MD->getNumOperands() >= 2)) { CheckFailed("!prof annotations should have no less than 2 operands"
, MD); return; } } while (false)
1894 "!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)
;
1895
1896 // Check first operand.
1897 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)
1898 MD)do { if (!(MD->getOperand(0) != nullptr)) { CheckFailed("first operand should not be null"
, MD); return; } } while (false)
;
1899 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)
1900 "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)
;
1901 MDString *MDS = cast<MDString>(MD->getOperand(0));
1902 StringRef ProfName = MDS->getString();
1903 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)
1904 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)
1905 "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)
1906 " 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)
1907 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)
;
1908
1909 // Check second operand.
1910 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)
1911 MD)do { if (!(MD->getOperand(1) != nullptr)) { CheckFailed("second operand should not be null"
, MD); return; } } while (false)
;
1912 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)
1913 "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)
;
1914 }
1915 }
1916}
1917
1918void Verifier::visitConstantExprsRecursively(const Constant *EntryC) {
1919 if (!ConstantExprVisited.insert(EntryC).second)
1920 return;
1921
1922 SmallVector<const Constant *, 16> Stack;
1923 Stack.push_back(EntryC);
1924
1925 while (!Stack.empty()) {
1926 const Constant *C = Stack.pop_back_val();
1927
1928 // Check this constant expression.
1929 if (const auto *CE = dyn_cast<ConstantExpr>(C))
1930 visitConstantExpr(CE);
1931
1932 if (const auto *GV = dyn_cast<GlobalValue>(C)) {
1933 // Global Values get visited separately, but we do need to make sure
1934 // that the global value is in the correct module
1935 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)
1936 EntryC, &M, GV, GV->getParent())do { if (!(GV->getParent() == &M)) { CheckFailed("Referencing global in another module!"
, EntryC, &M, GV, GV->getParent()); return; } } while (
false)
;
1937 continue;
1938 }
1939
1940 // Visit all sub-expressions.
1941 for (const Use &U : C->operands()) {
1942 const auto *OpC = dyn_cast<Constant>(U);
1943 if (!OpC)
1944 continue;
1945 if (!ConstantExprVisited.insert(OpC).second)
1946 continue;
1947 Stack.push_back(OpC);
1948 }
1949 }
1950}
1951
1952void Verifier::visitConstantExpr(const ConstantExpr *CE) {
1953 if (CE->getOpcode() == Instruction::BitCast)
1954 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)
1955 CE->getType()),do { if (!(CastInst::castIsValid(Instruction::BitCast, CE->
getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast"
, CE); return; } } while (false)
1956 "Invalid bitcast", CE)do { if (!(CastInst::castIsValid(Instruction::BitCast, CE->
getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast"
, CE); return; } } while (false)
;
1957
1958 if (CE->getOpcode() == Instruction::IntToPtr ||
1959 CE->getOpcode() == Instruction::PtrToInt) {
1960 auto *PtrTy = CE->getOpcode() == Instruction::IntToPtr
1961 ? CE->getType()
1962 : CE->getOperand(0)->getType();
1963 StringRef Msg = CE->getOpcode() == Instruction::IntToPtr
1964 ? "inttoptr not supported for non-integral pointers"
1965 : "ptrtoint not supported for non-integral pointers";
1966 Assert(do { if (!(!DL.isNonIntegralPointerType(cast<PointerType>
(PtrTy->getScalarType())))) { CheckFailed(Msg); return; } }
while (false)
1967 !DL.isNonIntegralPointerType(cast<PointerType>(PtrTy->getScalarType())),do { if (!(!DL.isNonIntegralPointerType(cast<PointerType>
(PtrTy->getScalarType())))) { CheckFailed(Msg); return; } }
while (false)
1968 Msg)do { if (!(!DL.isNonIntegralPointerType(cast<PointerType>
(PtrTy->getScalarType())))) { CheckFailed(Msg); return; } }
while (false)
;
1969 }
1970}
1971
1972bool Verifier::verifyAttributeCount(AttributeList Attrs, unsigned Params) {
1973 // There shouldn't be more attribute sets than there are parameters plus the
1974 // function and return value.
1975 return Attrs.getNumAttrSets() <= Params + 2;
1976}
1977
1978/// Verify that statepoint intrinsic is well formed.
1979void Verifier::verifyStatepoint(const CallBase &Call) {
1980 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-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 1982, __PRETTY_FUNCTION__))
1981 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-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 1982, __PRETTY_FUNCTION__))
1982 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-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 1982, __PRETTY_FUNCTION__))
;
1983
1984 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)
1985 !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)
1986 "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)
1987 "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)
1988 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)
;
1989
1990 const int64_t NumPatchBytes =
1991 cast<ConstantInt>(Call.getArgOperand(1))->getSExtValue();
1992 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-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 1992, __PRETTY_FUNCTION__))
;
1993 Assert(NumPatchBytes >= 0,do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be "
"positive", Call); return; } } while (false)
1994 "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)
1995 "positive",do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be "
"positive", Call); return; } } while (false)
1996 Call)do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be "
"positive", Call); return; } } while (false)
;
1997
1998 const Value *Target = Call.getArgOperand(2);
1999 auto *PT = dyn_cast<PointerType>(Target->getType());
2000 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)
2001 "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)
;
2002 FunctionType *TargetFuncType = cast<FunctionType>(PT->getElementType());
2003
2004 const int NumCallArgs = cast<ConstantInt>(Call.getArgOperand(3))->getZExtValue();
2005 Assert(NumCallArgs >= 0,do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call "
"must be positive", Call); return; } } while (false)
2006 "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)
2007 "must be positive",do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call "
"must be positive", Call); return; } } while (false)
2008 Call)do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call "
"must be positive", Call); return; } } while (false)
;
2009 const int NumParams = (int)TargetFuncType->getNumParams();
2010 if (TargetFuncType->isVarArg()) {
2011 Assert(NumCallArgs >= NumParams,do { if (!(NumCallArgs >= NumParams)) { CheckFailed("gc.statepoint mismatch in number of vararg call args"
, Call); return; } } while (false)
2012 "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)
;
2013
2014 // TODO: Remove this limitation
2015 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)
2016 "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)
2017 "vararg functions yet",do { if (!(TargetFuncType->getReturnType()->isVoidTy())
) { CheckFailed("gc.statepoint doesn't support wrapping non-void "
"vararg functions yet", Call); return; } } while (false)
2018 Call)do { if (!(TargetFuncType->getReturnType()->isVoidTy())
) { CheckFailed("gc.statepoint doesn't support wrapping non-void "
"vararg functions yet", Call); return; } } while (false)
;
2019 } else
2020 Assert(NumCallArgs == NumParams,do { if (!(NumCallArgs == NumParams)) { CheckFailed("gc.statepoint mismatch in number of call args"
, Call); return; } } while (false)
2021 "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)
;
2022
2023 const uint64_t Flags
2024 = cast<ConstantInt>(Call.getArgOperand(4))->getZExtValue();
2025 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)
2026 "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)
;
2027
2028 // Verify that the types of the call parameter arguments match
2029 // the type of the wrapped callee.
2030 AttributeList Attrs = Call.getAttributes();
2031 for (int i = 0; i < NumParams; i++) {
2032 Type *ParamType = TargetFuncType->getParamType(i);
2033 Type *ArgType = Call.getArgOperand(5 + i)->getType();
2034 Assert(ArgType == ParamType,do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped "
"function type", Call); return; } } while (false)
2035 "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)
2036 "function type",do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped "
"function type", Call); return; } } while (false)
2037 Call)do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped "
"function type", Call); return; } } while (false)
;
2038
2039 if (TargetFuncType->isVarArg()) {
2040 AttributeSet ArgAttrs = Attrs.getParamAttributes(5 + i);
2041 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)
2042 "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)
2043 Call)do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed
("Attribute 'sret' cannot be used for vararg call arguments!"
, Call); return; } } while (false)
;
2044 }
2045 }
2046
2047 const int EndCallArgsInx = 4 + NumCallArgs;
2048
2049 const Value *NumTransitionArgsV = Call.getArgOperand(EndCallArgsInx + 1);
2050 Assert(isa<ConstantInt>(NumTransitionArgsV),do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed
("gc.statepoint number of transition arguments " "must be constant integer"
, Call); return; } } while (false)
2051 "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)
2052 "must be constant integer",do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed
("gc.statepoint number of transition arguments " "must be constant integer"
, Call); return; } } while (false)
2053 Call)do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed
("gc.statepoint number of transition arguments " "must be constant integer"
, Call); return; } } while (false)
;
2054 const int NumTransitionArgs =
2055 cast<ConstantInt>(NumTransitionArgsV)->getZExtValue();
2056 Assert(NumTransitionArgs >= 0,do { if (!(NumTransitionArgs >= 0)) { CheckFailed("gc.statepoint number of transition arguments must be positive"
, Call); return; } } while (false)
2057 "gc.statepoint number of transition arguments must be positive", Call)do { if (!(NumTransitionArgs >= 0)) { CheckFailed("gc.statepoint number of transition arguments must be positive"
, Call); return; } } while (false)
;
2058 const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs;
2059
2060 const Value *NumDeoptArgsV = Call.getArgOperand(EndTransitionArgsInx + 1);
2061 Assert(isa<ConstantInt>(NumDeoptArgsV),do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed
("gc.statepoint number of deoptimization arguments " "must be constant integer"
, Call); return; } } while (false)
2062 "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)
2063 "must be constant integer",do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed
("gc.statepoint number of deoptimization arguments " "must be constant integer"
, Call); return; } } while (false)
2064 Call)do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed
("gc.statepoint number of deoptimization arguments " "must be constant integer"
, Call); return; } } while (false)
;
2065 const int NumDeoptArgs = cast<ConstantInt>(NumDeoptArgsV)->getZExtValue();
2066 Assert(NumDeoptArgs >= 0,do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments "
"must be positive", Call); return; } } while (false)
2067 "gc.statepoint number of deoptimization arguments "do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments "
"must be positive", Call); return; } } while (false)
2068 "must be positive",do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments "
"must be positive", Call); return; } } while (false)
2069 Call)do { if (!(NumDeoptArgs >= 0)) { CheckFailed("gc.statepoint number of deoptimization arguments "
"must be positive", Call); return; } } while (false)
;
2070
2071 const int ExpectedNumArgs =
2072 7 + NumCallArgs + NumTransitionArgs + NumDeoptArgs;
2073 Assert(ExpectedNumArgs <= (int)Call.arg_size(),do { if (!(ExpectedNumArgs <= (int)Call.arg_size())) { CheckFailed
("gc.statepoint too few arguments according to length fields"
, Call); return; } } while (false)
2074 "gc.statepoint too few arguments according to length fields", Call)do { if (!(ExpectedNumArgs <= (int)Call.arg_size())) { CheckFailed
("gc.statepoint too few arguments according to length fields"
, Call); return; } } while (false)
;
2075
2076 // Check that the only uses of this gc.statepoint are gc.result or
2077 // gc.relocate calls which are tied to this statepoint and thus part
2078 // of the same statepoint sequence
2079 for (const User *U : Call.users()) {
2080 const CallInst *UserCall = dyn_cast<const CallInst>(U);
2081 Assert(UserCall, "illegal use of statepoint token", Call, U)do { if (!(UserCall)) { CheckFailed("illegal use of statepoint token"
, Call, U); return; } } while (false)
;
2082 if (!UserCall)
2083 continue;
2084 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)
2085 "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)
2086 "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)
2087 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)
;
2088 if (isa<GCResultInst>(UserCall)) {
2089 Assert(UserCall->getArgOperand(0) == &Call,do { if (!(UserCall->getArgOperand(0) == &Call)) { CheckFailed
("gc.result connected to wrong gc.statepoint", Call, UserCall
); return; } } while (false)
2090 "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)
;
2091 } else if (isa<GCRelocateInst>(Call)) {
2092 Assert(UserCall->getArgOperand(0) == &Call,do { if (!(UserCall->getArgOperand(0) == &Call)) { CheckFailed
("gc.relocate connected to wrong gc.statepoint", Call, UserCall
); return; } } while (false)
2093 "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)
;
2094 }
2095 }
2096
2097 // Note: It is legal for a single derived pointer to be listed multiple
2098 // times. It's non-optimal, but it is legal. It can also happen after
2099 // insertion if we strip a bitcast away.
2100 // Note: It is really tempting to check that each base is relocated and
2101 // that a derived pointer is never reused as a base pointer. This turns
2102 // out to be problematic since optimizations run after safepoint insertion
2103 // can recognize equality properties that the insertion logic doesn't know
2104 // about. See example statepoint.ll in the verifier subdirectory
2105}
2106
2107void Verifier::verifyFrameRecoverIndices() {
2108 for (auto &Counts : FrameEscapeInfo) {
2109 Function *F = Counts.first;
2110 unsigned EscapedObjectCount = Counts.second.first;
2111 unsigned MaxRecoveredIndex = Counts.second.second;
2112 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)
2113 "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)
2114 "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)
2115 "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)
2116 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)
;
2117 }
2118}
2119
2120static Instruction *getSuccPad(Instruction *Terminator) {
2121 BasicBlock *UnwindDest;
2122 if (auto *II = dyn_cast<InvokeInst>(Terminator))
2123 UnwindDest = II->getUnwindDest();
2124 else if (auto *CSI = dyn_cast<CatchSwitchInst>(Terminator))
2125 UnwindDest = CSI->getUnwindDest();
2126 else
2127 UnwindDest = cast<CleanupReturnInst>(Terminator)->getUnwindDest();
2128 return UnwindDest->getFirstNonPHI();
2129}
2130
2131void Verifier::verifySiblingFuncletUnwinds() {
2132 SmallPtrSet<Instruction *, 8> Visited;
2133 SmallPtrSet<Instruction *, 8> Active;
2134 for (const auto &Pair : SiblingFuncletInfo) {
2135 Instruction *PredPad = Pair.first;
2136 if (Visited.count(PredPad))
2137 continue;
2138 Active.insert(PredPad);
2139 Instruction *Terminator = Pair.second;
2140 do {
2141 Instruction *SuccPad = getSuccPad(Terminator);
2142 if (Active.count(SuccPad)) {
2143 // Found a cycle; report error
2144 Instruction *CyclePad = SuccPad;
2145 SmallVector<Instruction *, 8> CycleNodes;
2146 do {
2147 CycleNodes.push_back(CyclePad);
2148 Instruction *CycleTerminator = SiblingFuncletInfo[CyclePad];
2149 if (CycleTerminator != CyclePad)
2150 CycleNodes.push_back(CycleTerminator);
2151 CyclePad = getSuccPad(CycleTerminator);
2152 } while (CyclePad != SuccPad);
2153 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)
2154 ArrayRef<Instruction *>(CycleNodes))do { if (!(false)) { CheckFailed("EH pads can't handle each other's exceptions"
, ArrayRef<Instruction *>(CycleNodes)); return; } } while
(false)
;
2155 }
2156 // Don't re-walk a node we've already checked
2157 if (!Visited.insert(SuccPad).second)
2158 break;
2159 // Walk to this successor if it has a map entry.
2160 PredPad = SuccPad;
2161 auto TermI = SiblingFuncletInfo.find(PredPad);
2162 if (TermI == SiblingFuncletInfo.end())
2163 break;
2164 Terminator = TermI->second;
2165 Active.insert(PredPad);
2166 } while (true);
2167 // Each node only has one successor, so we've walked all the active
2168 // nodes' successors.
2169 Active.clear();
2170 }
2171}
2172
2173// visitFunction - Verify that a function is ok.
2174//
2175void Verifier::visitFunction(const Function &F) {
2176 visitGlobalValue(F);
2177
2178 // Check function arguments.
2179 FunctionType *FT = F.getFunctionType();
2180 unsigned NumArgs = F.arg_size();
2181
2182 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
2183 "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)
;
2184
2185 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
2186 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
2187 "# 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)
2188 FT)do { if (!(FT->getNumParams() == NumArgs)) { CheckFailed("# formal arguments must match # of arguments for function type!"
, &F, FT); return; } } while (false)
;
2189 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
2190 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)
2191 "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)
;
2192
2193 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
2194 "Invalid struct return type!", &F)do { if (!(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy
())) { CheckFailed("Invalid struct return type!", &F); return
; } } while (false)
;
2195
2196 AttributeList Attrs = F.getAttributes();
2197
2198 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
2199 "Attribute after last parameter!", &F)do { if (!(verifyAttributeCount(Attrs, FT->getNumParams())
)) { CheckFailed("Attribute after last parameter!", &F); return
; } } while (false)
;
2200
2201 bool isLLVMdotName = F.getName().size() >= 5 &&
16
Assuming the condition is false
2202 F.getName().substr(0, 5) == "llvm.";
2203
2204 // Check function attributes.
2205 verifyFunctionAttrs(FT, Attrs, &F, isLLVMdotName);
2206
2207 // On function declarations/definitions, we do not support the builtin
2208 // attribute. We do not check this in VerifyFunctionAttrs since that is
2209 // checking for Attributes that can/can not ever be on functions.
2210 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
2211 "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)
;
2212
2213 // Check that this function meets the restrictions on this calling convention.
2214 // Sometimes varargs is used for perfectly forwarding thunks, so some of these
2215 // restrictions can be lifted.
2216 switch (F.getCallingConv()) {
20
Control jumps to 'case C:' at line 2218
2217 default:
2218 case CallingConv::C:
2219 break;
21
Execution continues on line 2245
2220 case CallingConv::AMDGPU_KERNEL:
2221 case CallingConv::SPIR_KERNEL:
2222 Assert(F.getReturnType()->isVoidTy(),do { if (!(F.getReturnType()->isVoidTy())) { CheckFailed("Calling convention requires void return type"
, &F); return; } } while (false)
2223 "Calling convention requires void return type", &F)do { if (!(F.getReturnType()->isVoidTy())) { CheckFailed("Calling convention requires void return type"
, &F); return; } } while (false)
;
2224 LLVM_FALLTHROUGH[[gnu::fallthrough]];
2225 case CallingConv::AMDGPU_VS:
2226 case CallingConv::AMDGPU_HS:
2227 case CallingConv::AMDGPU_GS:
2228 case CallingConv::AMDGPU_PS:
2229 case CallingConv::AMDGPU_CS:
2230 Assert(!F.hasStructRetAttr(),do { if (!(!F.hasStructRetAttr())) { CheckFailed("Calling convention does not allow sret"
, &F); return; } } while (false)
2231 "Calling convention does not allow sret", &F)do { if (!(!F.hasStructRetAttr())) { CheckFailed("Calling convention does not allow sret"
, &F); return; } } while (false)
;
2232 LLVM_FALLTHROUGH[[gnu::fallthrough]];
2233 case CallingConv::Fast:
2234 case CallingConv::Cold:
2235 case CallingConv::Intel_OCL_BI:
2236 case CallingConv::PTX_Kernel:
2237 case CallingConv::PTX_Device:
2238 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)
2239 "perfect forwarding!",do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or "
"perfect forwarding!", &F); return; } } while (false)
2240 &F)do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or "
"perfect forwarding!", &F); return; } } while (false)
;
2241 break;
2242 }
2243
2244 // Check that the argument values match the function type for this function...
2245 unsigned i = 0;
2246 for (const Argument &Arg : F.args()) {
22
Assuming '__begin1' is equal to '__end1'
2247 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)
2248 "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)
2249 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)
;
2250 Assert(Arg.getType()->isFirstClassType(),do { if (!(Arg.getType()->isFirstClassType())) { CheckFailed
("Function arguments must have first-class types!", &Arg)
; return; } } while (false)
2251 "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)
;
2252 if (!isLLVMdotName) {
2253 Assert(!Arg.getType()->isMetadataTy(),do { if (!(!Arg.getType()->isMetadataTy())) { CheckFailed(
"Function takes metadata but isn't an intrinsic", &Arg, &
F); return; } } while (false)
2254 "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)
;
2255 Assert(!Arg.getType()->isTokenTy(),do { if (!(!Arg.getType()->isTokenTy())) { CheckFailed("Function takes token but isn't an intrinsic"
, &Arg, &F); return; } } while (false)
2256 "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)
;
2257 }
2258
2259 // Check that swifterror argument is only used by loads and stores.
2260 if (Attrs.hasParamAttribute(i, Attribute::SwiftError)) {
2261 verifySwiftErrorValue(&Arg);
2262 }
2263 ++i;
2264 }
2265
2266 if (!isLLVMdotName
22.1
'isLLVMdotName' is false
)
23
Taking true branch
2267 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
2268 "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)
;
2269
2270 // Get the function metadata attachments.
2271 SmallVector<std::pair<unsigned, MDNode *>, 4> MDs;
2272 F.getAllMetadata(MDs);
2273 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-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 2273, __PRETTY_FUNCTION__))
;
26
Assuming the condition is true
27
'?' condition is true
2274 verifyFunctionMetadata(MDs);
2275
2276 // Check validity of the personality function
2277 if (F.hasPersonalityFn()) {
28
Assuming the condition is false
29
Taking false branch
2278 auto *Per = dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts());
2279 if (Per)
2280 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)
2281 "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)
2282 &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)
;
2283 }
2284
2285 if (F.isMaterializable()) {
30
Assuming the condition is false
31
Taking false branch
2286 // Function has a body somewhere we can't see.
2287 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)
2288 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)
;
2289 } else if (F.isDeclaration()) {
32
Assuming the condition is false
33
Taking false branch
2290 for (const auto &I : MDs) {
2291 // This is used for call site debug information.
2292 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)
2293 !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)
2294 "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)
2295 &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)
;
2296 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)
2297 "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)
;
2298
2299 // Verify the metadata itself.
2300 visitMDNode(*I.second);
2301 }
2302 Assert(!F.hasPersonalityFn(),do { if (!(!F.hasPersonalityFn())) { CheckFailed("Function declaration shouldn't have a personality routine"
, &F); return; } } while (false)
2303 "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)
;
2304 } else {
2305 // Verify that this function (which has a body) is not named "llvm.*". It
2306 // is not legal to define intrinsics.
2307 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
2308
2309 // Check the entry node
2310 const BasicBlock *Entry = &F.getEntryBlock();
2311 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
2312 "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)
;
2313
2314 // The address of the entry block cannot be taken, unless it is dead.
2315 if (Entry->hasAddressTaken()) {
39
Assuming the condition is false
40
Taking false branch
2316 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)
2317 "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)
;
2318 }
2319
2320 unsigned NumDebugAttachments = 0, NumProfAttachments = 0;
2321 // Visit metadata attachments.
2322 for (const auto &I : MDs) {
41
Assuming '__begin3' is equal to '__end3'
2323 // Verify that the attachment is legal.
2324 switch (I.first) {
2325 default:
2326 break;
2327 case LLVMContext::MD_dbg: {
2328 ++NumDebugAttachments;
2329 AssertDI(NumDebugAttachments == 1,do { if (!(NumDebugAttachments == 1)) { DebugInfoCheckFailed(
"function must have a single !dbg attachment", &F, I.second
); return; } } while (false)
2330 "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)
;
2331 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)
2332 "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)
;
2333 auto *SP = cast<DISubprogram>(I.second);
2334 const Function *&AttachedTo = DISubprogramAttachments[SP];
2335 AssertDI(!AttachedTo || AttachedTo == &F,do { if (!(!AttachedTo || AttachedTo == &F)) { DebugInfoCheckFailed
("DISubprogram attached to more than one function", SP, &
F); return; } } while (false)
2336 "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)
;
2337 AttachedTo = &F;
2338 break;
2339 }
2340 case LLVMContext::MD_prof:
2341 ++NumProfAttachments;
2342 Assert(NumProfAttachments == 1,do { if (!(NumProfAttachments == 1)) { CheckFailed("function must have a single !prof attachment"
, &F, I.second); return; } } while (false)
2343 "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)
;
2344 break;
2345 }
2346
2347 // Verify the metadata itself.
2348 visitMDNode(*I.second);
2349 }
2350 }
2351
2352 // If this function is actually an intrinsic, verify that it is only used in
2353 // direct call/invokes, never having its "address taken".
2354 // Only do this if the module is materialized, otherwise we don't have all the
2355 // uses.
2356 if (F.getIntrinsicID() && F.getParent()->isMaterialized()) {
42
Assuming the condition is false
2357 const User *U;
2358 if (F.hasAddressTaken(&U))
2359 Assert(false, "Invalid user of intrinsic instruction!", U)do { if (!(false)) { CheckFailed("Invalid user of intrinsic instruction!"
, U); return; } } while (false)
;
2360 }
2361
2362 auto *N = F.getSubprogram();
2363 HasDebugInfo = (N != nullptr);
43
Assuming the condition is true
2364 if (!HasDebugInfo
43.1
Field 'HasDebugInfo' is true
)
44
Taking false branch
2365 return;
2366
2367 // Check that all !dbg attachments lead to back to N.
2368 //
2369 // FIXME: Check this incrementally while visiting !dbg attachments.
2370 // FIXME: Only check when N is the canonical subprogram for F.
2371 SmallPtrSet<const MDNode *, 32> Seen;
2372 auto VisitDebugLoc = [&](const Instruction &I, const MDNode *Node) {
2373 // Be careful about using DILocation here since we might be dealing with
2374 // broken code (this is the Verifier after all).
2375 const DILocation *DL = dyn_cast_or_null<DILocation>(Node);
46
Assuming 'Node' is a 'DILocation'
2376 if (!DL
46.1
'DL' is non-null
)
47
Taking false branch
2377 return;
2378 if (!Seen.insert(DL).second)
48
Assuming field 'second' is true
49
Taking false branch
2379 return;
2380
2381 Metadata *Parent = DL->getRawScope();
2382 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
2383 "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)
2384 Parent)do { if (!(Parent && isa<DILocalScope>(Parent))
) { DebugInfoCheckFailed("DILocation's scope must be a DILocalScope"
, N, &F, &I, DL, Parent); return; } } while (false)
;
2385 DILocalScope *Scope = DL->getInlinedAtScope();
2386 if (Scope
53.1
'Scope' is non-null
&& !Seen.insert(Scope).second)
54
Assuming field 'second' is true
55
Taking false branch
2387 return;
2388
2389 DISubprogram *SP = Scope
55.1
'Scope' is non-null
? Scope->getSubprogram() : nullptr;
56
'?' condition is true
57
'SP' initialized here
2390
2391 // Scope and SP could be the same MDNode and we don't want to skip
2392 // validation in that case
2393 if (SP && ((Scope != SP) && !Seen.insert(SP).second))
58
Assuming 'SP' is null
59
Taking false branch
2394 return;
2395
2396 AssertDI(SP->describes(&F),do { if (!(SP->describes(&F))) { DebugInfoCheckFailed(
"!dbg attachment points at wrong subprogram for function", N,
&F, &I, DL, Scope, SP); return; } } while (false)
60
Called C++ object pointer is null
2397 "!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)
2398 &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)
;
2399 };
2400 for (auto &BB : F)
2401 for (auto &I : BB) {
2402 VisitDebugLoc(I, I.getDebugLoc().getAsMDNode());
45
Calling 'operator()'
2403 // The llvm.loop annotations also contain two DILocations.
2404 if (auto MD = I.getMetadata(LLVMContext::MD_loop))
2405 for (unsigned i = 1; i < MD->getNumOperands(); ++i)
2406 VisitDebugLoc(I, dyn_cast_or_null<MDNode>(MD->getOperand(i)));
2407 if (BrokenDebugInfo)
2408 return;
2409 }
2410}
2411
2412// verifyBasicBlock - Verify that a basic block is well formed...
2413//
2414void Verifier::visitBasicBlock(BasicBlock &BB) {
2415 InstsInThisBlock.clear();
2416
2417 // Ensure that basic blocks have terminators!
2418 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)
;
2419
2420 // Check constraints that this basic block imposes on all of the PHI nodes in
2421 // it.
2422 if (isa<PHINode>(BB.front())) {
2423 SmallVector<BasicBlock*, 8> Preds(pred_begin(&BB), pred_end(&BB));
2424 SmallVector<std::pair<BasicBlock*, Value*>, 8> Values;
2425 llvm::sort(Preds);
2426 for (const PHINode &PN : BB.phis()) {
2427 // Ensure that PHI nodes have at least one entry!
2428 Assert(PN.getNumIncomingValues() != 0,do { if (!(PN.getNumIncomingValues() != 0)) { CheckFailed("PHI nodes must have at least one entry. If the block is dead, "
"the PHI should be removed!", &PN); return; } } while (false
)
2429 "PHI nodes must have at least one entry. If the block is dead, "do { if (!(PN.getNumIncomingValues() != 0)) { CheckFailed("PHI nodes must have at least one entry. If the block is dead, "
"the PHI should be removed!", &PN); return; } } while (false
)
2430 "the PHI should be removed!",do { if (!(PN.getNumIncomingValues() != 0)) { CheckFailed("PHI nodes must have at least one entry. If the block is dead, "
"the PHI should be removed!", &PN); return; } } while (false
)
2431 &PN)do { if (!(PN.getNumIncomingValues() != 0)) { CheckFailed("PHI nodes must have at least one entry. If the block is dead, "
"the PHI should be removed!", &PN); return; } } while (false
)
;
2432 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)
2433 "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)
2434 "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)
2435 &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)
;
2436
2437 // Get and sort all incoming values in the PHI node...
2438 Values.clear();
2439 Values.reserve(PN.getNumIncomingValues());
2440 for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
2441 Values.push_back(
2442 std::make_pair(PN.getIncomingBlock(i), PN.getIncomingValue(i)));
2443 llvm::sort(Values);
2444
2445 for (unsigned i = 0, e = Values.size(); i != e; ++i) {
2446 // Check to make sure that if there is more than one entry for a
2447 // particular basic block in this PHI node, that the incoming values are
2448 // all identical.
2449 //
2450 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)
2451 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)
2452 "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)
2453 "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)
2454 &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)
;
2455
2456 // Check to make sure that the predecessors and PHI node entries are
2457 // matched up.
2458 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
)
2459 "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
)
2460 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
)
;
2461 }
2462 }
2463 }
2464
2465 // Check that all instructions have their parent pointers set up correctly.
2466 for (auto &I : BB)
2467 {
2468 Assert(I.getParent() == &BB, "Instruction has bogus parent pointer!")do { if (!(I.getParent() == &BB)) { CheckFailed("Instruction has bogus parent pointer!"
); return; } } while (false)
;
2469 }
2470}
2471
2472void Verifier::visitTerminator(Instruction &I) {
2473 // Ensure that terminators only exist at the end of the basic block.
2474 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)
2475 "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)
;
2476 visitInstruction(I);
2477}
2478
2479void Verifier::visitBranchInst(BranchInst &BI) {
2480 if (BI.isConditional()) {
2481 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)
2482 "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)
;
2483 }
2484 visitTerminator(BI);
2485}
2486
2487void Verifier::visitReturnInst(ReturnInst &RI) {
2488 Function *F = RI.getParent()->getParent();
2489 unsigned N = RI.getNumOperands();
2490 if (F->getReturnType()->isVoidTy())
2491 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)
2492 "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)
2493 "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)
2494 &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)
;
2495 else
2496 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)
2497 "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)
2498 "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)
2499 &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)
;
2500
2501 // Check to make sure that the return value has necessary properties for
2502 // terminators...
2503 visitTerminator(RI);
2504}
2505
2506void Verifier::visitSwitchInst(SwitchInst &SI) {
2507 // Check to make sure that all of the constants in the switch instruction
2508 // have the same type as the switched-on value.
2509 Type *SwitchTy = SI.getCondition()->getType();
2510 SmallPtrSet<ConstantInt*, 32> Constants;
2511 for (auto &Case : SI.cases()) {
2512 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)
2513 "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)
;
2514 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)
2515 "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)
;
2516 }
2517
2518 visitTerminator(SI);
2519}
2520
2521void Verifier::visitIndirectBrInst(IndirectBrInst &BI) {
2522 Assert(BI.getAddress()->getType()->isPointerTy(),do { if (!(BI.getAddress()->getType()->isPointerTy())) {
CheckFailed("Indirectbr operand must have pointer type!", &
BI); return; } } while (false)
2523 "Indirectbr operand must have pointer type!", &BI)do { if (!(BI.getAddress()->getType()->isPointerTy())) {
CheckFailed("Indirectbr operand must have pointer type!", &
BI); return; } } while (false)
;
2524 for (unsigned i = 0, e = BI.getNumDestinations(); i != e; ++i)
2525 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)
2526 "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)
;
2527
2528 visitTerminator(BI);
2529}
2530
2531void Verifier::visitCallBrInst(CallBrInst &CBI) {
2532 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)
2533 &CBI)do { if (!(CBI.isInlineAsm())) { CheckFailed("Callbr is currently only used for asm-goto!"
, &CBI); return; } } while (false)
;
2534 for (unsigned i = 0, e = CBI.getNumSuccessors(); i != e; ++i)
2535 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)
2536 "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)
;
2537 for (unsigned i = 0, e = CBI.getNumOperands(); i != e; ++i) {
2538 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)
2539 "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)
;
2540 if (isa<BasicBlock>(CBI.getOperand(i)))
2541 for (unsigned j = i + 1; j != e; ++j)
2542 Assert(CBI.getOperand(i) != CBI.getOperand(j),do { if (!(CBI.getOperand(i) != CBI.getOperand(j))) { CheckFailed
("Duplicate callbr destination!", &CBI); return; } } while
(false)
2543 "Duplicate callbr destination!", &CBI)do { if (!(CBI.getOperand(i) != CBI.getOperand(j))) { CheckFailed
("Duplicate callbr destination!", &CBI); return; } } while
(false)
;
2544 }
2545 {
2546 SmallPtrSet<BasicBlock *, 4> ArgBBs;
2547 for (Value *V : CBI.args())
2548 if (auto *BA = dyn_cast<BlockAddress>(V))
2549 ArgBBs.insert(BA->getBasicBlock());
2550 for (BasicBlock *BB : CBI.getIndirectDests())
2551 Assert(ArgBBs.find(BB) != ArgBBs.end(),do { if (!(ArgBBs.find(BB) != ArgBBs.end())) { CheckFailed("Indirect label missing from arglist."
, &CBI); return; } } while (false)
2552 "Indirect label missing from arglist.", &CBI)do { if (!(ArgBBs.find(BB) != ArgBBs.end())) { CheckFailed("Indirect label missing from arglist."
, &CBI); return; } } while (false)
;
2553 }
2554
2555 visitTerminator(CBI);
2556}
2557
2558void Verifier::visitSelectInst(SelectInst &SI) {
2559 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)
2560 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)
2561 "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)
;
2562
2563 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)
2564 "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)
;
2565 visitInstruction(SI);
2566}
2567
2568/// visitUserOp1 - User defined operators shouldn't live beyond the lifetime of
2569/// a pass, if any exist, it's an error.
2570///
2571void Verifier::visitUserOp1(Instruction &I) {
2572 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)
;
2573}
2574
2575void Verifier::visitTruncInst(TruncInst &I) {
2576 // Get the source and destination types
2577 Type *SrcTy = I.getOperand(0)->getType();
2578 Type *DestTy = I.getType();
2579
2580 // Get the size of the types in bits, we'll need this later
2581 unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
2582 unsigned DestBitSize = DestTy->getScalarSizeInBits();
2583
2584 Assert(SrcTy->isIntOrIntVectorTy(), "Trunc only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("Trunc only operates on integer"
, &I); return; } } while (false)
;
2585 Assert(DestTy->isIntOrIntVectorTy(), "Trunc only produces integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("Trunc only produces integer"
, &I); return; } } while (false)
;
2586 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)
2587 "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)
;
2588 Assert(SrcBitSize > DestBitSize, "DestTy too big for Trunc", &I)do { if (!(SrcBitSize > DestBitSize)) { CheckFailed("DestTy too big for Trunc"
, &I); return; } } while (false)
;
2589
2590 visitInstruction(I);
2591}
2592
2593void Verifier::visitZExtInst(ZExtInst &I) {
2594 // Get the source and destination types
2595 Type *SrcTy = I.getOperand(0)->getType();
2596 Type *DestTy = I.getType();
2597
2598 // Get the size of the types in bits, we'll need this later
2599 Assert(SrcTy->isIntOrIntVectorTy(), "ZExt only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("ZExt only operates on integer"
, &I); return; } } while (false)
;
2600 Assert(DestTy->isIntOrIntVectorTy(), "ZExt only produces an integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("ZExt only produces an integer"
, &I); return; } } while (false)
;
2601 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)
2602 "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)
;
2603 unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
2604 unsigned DestBitSize = DestTy->getScalarSizeInBits();
2605
2606 Assert(SrcBitSize < DestBitSize, "Type too small for ZExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("Type too small for ZExt"
, &I); return; } } while (false)
;
2607
2608 visitInstruction(I);
2609}
2610
2611void Verifier::visitSExtInst(SExtInst &I) {
2612 // Get the source and destination types
2613 Type *SrcTy = I.getOperand(0)->getType();
2614 Type *DestTy = I.getType();
2615
2616 // Get the size of the types in bits, we'll need this later
2617 unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
2618 unsigned DestBitSize = DestTy->getScalarSizeInBits();
2619
2620 Assert(SrcTy->isIntOrIntVectorTy(), "SExt only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("SExt only operates on integer"
, &I); return; } } while (false)
;
2621 Assert(DestTy->isIntOrIntVectorTy(), "SExt only produces an integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("SExt only produces an integer"
, &I); return; } } while (false)
;
2622 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)
2623 "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)
;
2624 Assert(SrcBitSize < DestBitSize, "Type too small for SExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("Type too small for SExt"
, &I); return; } } while (false)
;
2625
2626 visitInstruction(I);
2627}
2628
2629void Verifier::visitFPTruncInst(FPTruncInst &I) {
2630 // Get the source and destination types
2631 Type *SrcTy = I.getOperand(0)->getType();
2632 Type *DestTy = I.getType();
2633 // Get the size of the types in bits, we'll need this later
2634 unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
2635 unsigned DestBitSize = DestTy->getScalarSizeInBits();
2636
2637 Assert(SrcTy->isFPOrFPVectorTy(), "FPTrunc only operates on FP", &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPTrunc only operates on FP"
, &I); return; } } while (false)
;
2638 Assert(DestTy->isFPOrFPVectorTy(), "FPTrunc only produces an FP", &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("FPTrunc only produces an FP"
, &I); return; } } while (false)
;
2639 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)
2640 "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)
;
2641 Assert(SrcBitSize > DestBitSize, "DestTy too big for FPTrunc", &I)do { if (!(SrcBitSize > DestBitSize)) { CheckFailed("DestTy too big for FPTrunc"
, &I); return; } } while (false)
;
2642
2643 visitInstruction(I);
2644}
2645
2646void Verifier::visitFPExtInst(FPExtInst &I) {
2647 // Get the source and destination types
2648 Type *SrcTy = I.getOperand(0)->getType();
2649 Type *DestTy = I.getType();
2650
2651 // Get the size of the types in bits, we'll need this later
2652 unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
2653 unsigned DestBitSize = DestTy->getScalarSizeInBits();
2654
2655 Assert(SrcTy->isFPOrFPVectorTy(), "FPExt only operates on FP", &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPExt only operates on FP"
, &I); return; } } while (false)
;
2656 Assert(DestTy->isFPOrFPVectorTy(), "FPExt only produces an FP", &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("FPExt only produces an FP"
, &I); return; } } while (false)
;
2657 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)
2658 "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)
;
2659 Assert(SrcBitSize < DestBitSize, "DestTy too small for FPExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("DestTy too small for FPExt"
, &I); return; } } while (false)
;
2660
2661 visitInstruction(I);
2662}
2663
2664void Verifier::visitUIToFPInst(UIToFPInst &I) {
2665 // Get the source and destination types
2666 Type *SrcTy = I.getOperand(0)->getType();
2667 Type *DestTy = I.getType();
2668
2669 bool SrcVec = SrcTy->isVectorTy();
2670 bool DstVec = DestTy->isVectorTy();
2671
2672 Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("UIToFP source and dest must both be vector or scalar"
, &I); return; } } while (false)
2673 "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)
;
2674 Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("UIToFP source must be integer or integer vector"
, &I); return; } } while (false)
2675 "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)
;
2676 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)
2677 &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("UIToFP result must be FP or FP vector"
, &I); return; } } while (false)
;
2678
2679 if (SrcVec && DstVec)
2680 Assert(cast<VectorType>(SrcTy)->getNumElements() ==do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("UIToFP source and dest vector length mismatch", &I); return
; } } while (false)
2681 cast<VectorType>(DestTy)->getNumElements(),do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("UIToFP source and dest vector length mismatch", &I); return
; } } while (false)
2682 "UIToFP source and dest vector length mismatch", &I)do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("UIToFP source and dest vector length mismatch", &I); return
; } } while (false)
;
2683
2684 visitInstruction(I);
2685}
2686
2687void Verifier::visitSIToFPInst(SIToFPInst &I) {
2688 // Get the source and destination types
2689 Type *SrcTy = I.getOperand(0)->getType();
2690 Type *DestTy = I.getType();
2691
2692 bool SrcVec = SrcTy->isVectorTy();
2693 bool DstVec = DestTy->isVectorTy();
2694
2695 Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("SIToFP source and dest must both be vector or scalar"
, &I); return; } } while (false)
2696 "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)
;
2697 Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("SIToFP source must be integer or integer vector"
, &I); return; } } while (false)
2698 "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)
;
2699 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)
2700 &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("SIToFP result must be FP or FP vector"
, &I); return; } } while (false)
;
2701
2702 if (SrcVec && DstVec)
2703 Assert(cast<VectorType>(SrcTy)->getNumElements() ==do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("SIToFP source and dest vector length mismatch", &I); return
; } } while (false)
2704 cast<VectorType>(DestTy)->getNumElements(),do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("SIToFP source and dest vector length mismatch", &I); return
; } } while (false)
2705 "SIToFP source and dest vector length mismatch", &I)do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("SIToFP source and dest vector length mismatch", &I); return
; } } while (false)
;
2706
2707 visitInstruction(I);
2708}
2709
2710void Verifier::visitFPToUIInst(FPToUIInst &I) {
2711 // Get the source and destination types
2712 Type *SrcTy = I.getOperand(0)->getType();
2713 Type *DestTy = I.getType();
2714
2715 bool SrcVec = SrcTy->isVectorTy();
2716 bool DstVec = DestTy->isVectorTy();
2717
2718 Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("FPToUI source and dest must both be vector or scalar"
, &I); return; } } while (false)
2719 "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)
;
2720 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)
2721 &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToUI source must be FP or FP vector"
, &I); return; } } while (false)
;
2722 Assert(DestTy->isIntOrIntVectorTy(),do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToUI result must be integer or integer vector"
, &I); return; } } while (false)
2723 "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)
;
2724
2725 if (SrcVec && DstVec)
2726 Assert(cast<VectorType>(SrcTy)->getNumElements() ==do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("FPToUI source and dest vector length mismatch", &I); return
; } } while (false)
2727 cast<VectorType>(DestTy)->getNumElements(),do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("FPToUI source and dest vector length mismatch", &I); return
; } } while (false)
2728 "FPToUI source and dest vector length mismatch", &I)do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("FPToUI source and dest vector length mismatch", &I); return
; } } while (false)
;
2729
2730 visitInstruction(I);
2731}
2732
2733void Verifier::visitFPToSIInst(FPToSIInst &I) {
2734 // Get the source and destination types
2735 Type *SrcTy = I.getOperand(0)->getType();
2736 Type *DestTy = I.getType();
2737
2738 bool SrcVec = SrcTy->isVectorTy();
2739 bool DstVec = DestTy->isVectorTy();
2740
2741 Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("FPToSI source and dest must both be vector or scalar"
, &I); return; } } while (false)
2742 "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)
;
2743 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)
2744 &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToSI source must be FP or FP vector"
, &I); return; } } while (false)
;
2745 Assert(DestTy->isIntOrIntVectorTy(),do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToSI result must be integer or integer vector"
, &I); return; } } while (false)
2746 "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)
;
2747
2748 if (SrcVec && DstVec)
2749 Assert(cast<VectorType>(SrcTy)->getNumElements() ==do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("FPToSI source and dest vector length mismatch", &I); return
; } } while (false)
2750 cast<VectorType>(DestTy)->getNumElements(),do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("FPToSI source and dest vector length mismatch", &I); return
; } } while (false)
2751 "FPToSI source and dest vector length mismatch", &I)do { if (!(cast<VectorType>(SrcTy)->getNumElements()
== cast<VectorType>(DestTy)->getNumElements())) { CheckFailed
("FPToSI source and dest vector length mismatch", &I); return
; } } while (false)
;
2752
2753 visitInstruction(I);
2754}
2755
2756void Verifier::visitPtrToIntInst(PtrToIntInst &I) {
2757 // Get the source and destination types
2758 Type *SrcTy = I.getOperand(0)->getType();
2759 Type *DestTy = I.getType();
2760
2761 Assert(SrcTy->isPtrOrPtrVectorTy(), "PtrToInt source must be pointer", &I)do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("PtrToInt source must be pointer"
, &I); return; } } while (false)
;
2762
2763 if (auto *PTy = dyn_cast<PointerType>(SrcTy->getScalarType()))
2764 Assert(!DL.isNonIntegralPointerType(PTy),do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed(
"ptrtoint not supported for non-integral pointers"); return; }
} while (false)
2765 "ptrtoint not supported for non-integral pointers")do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed(
"ptrtoint not supported for non-integral pointers"); return; }
} while (false)
;
2766
2767 Assert(DestTy->isIntOrIntVectorTy(), "PtrToInt result must be integral", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("PtrToInt result must be integral"
, &I); return; } } while (false)
;
2768 Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(), "PtrToInt type mismatch",do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("PtrToInt type mismatch", &I); return; } }
while (false)
2769 &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("PtrToInt type mismatch", &I); return; } }
while (false)
;
2770
2771 if (SrcTy->isVectorTy()) {
2772 VectorType *VSrc = cast<VectorType>(SrcTy);
2773 VectorType *VDest = cast<VectorType>(DestTy);
2774 Assert(VSrc->getNumElements() == VDest->getNumElements(),do { if (!(VSrc->getNumElements() == VDest->getNumElements
())) { CheckFailed("PtrToInt Vector width mismatch", &I);
return; } } while (false)
2775 "PtrToInt Vector width mismatch", &I)do { if (!(VSrc->getNumElements() == VDest->getNumElements
())) { CheckFailed("PtrToInt Vector width mismatch", &I);
return; } } while (false)
;
2776 }
2777
2778 visitInstruction(I);
2779}
2780
2781void Verifier::visitIntToPtrInst(IntToPtrInst &I) {
2782 // Get the source and destination types
2783 Type *SrcTy = I.getOperand(0)->getType();
2784 Type *DestTy = I.getType();
2785
2786 Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("IntToPtr source must be an integral"
, &I); return; } } while (false)
2787 "IntToPtr source must be an integral", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("IntToPtr source must be an integral"
, &I); return; } } while (false)
;
2788 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)
;
2789
2790 if (auto *PTy = dyn_cast<PointerType>(DestTy->getScalarType()))
2791 Assert(!DL.isNonIntegralPointerType(PTy),do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed(
"inttoptr not supported for non-integral pointers"); return; }
} while (false)
2792 "inttoptr not supported for non-integral pointers")do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed(
"inttoptr not supported for non-integral pointers"); return; }
} while (false)
;
2793
2794 Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(), "IntToPtr type mismatch",do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("IntToPtr type mismatch", &I); return; } }
while (false)
2795 &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy())
) { CheckFailed("IntToPtr type mismatch", &I); return; } }
while (false)
;
2796 if (SrcTy->isVectorTy()) {
2797 VectorType *VSrc = cast<VectorType>(SrcTy);
2798 VectorType *VDest = cast<VectorType>(DestTy);
2799 Assert(VSrc->getNumElements() == VDest->getNumElements(),do { if (!(VSrc->getNumElements() == VDest->getNumElements
())) { CheckFailed("IntToPtr Vector width mismatch", &I);
return; } } while (false)
2800 "IntToPtr Vector width mismatch", &I)do { if (!(VSrc->getNumElements() == VDest->getNumElements
())) { CheckFailed("IntToPtr Vector width mismatch", &I);
return; } } while (false)
;
2801 }
2802 visitInstruction(I);
2803}
2804
2805void Verifier::visitBitCastInst(BitCastInst &I) {
2806 Assert(do { if (!(CastInst::castIsValid(Instruction::BitCast, I.getOperand
(0), I.getType()))) { CheckFailed("Invalid bitcast", &I);
return; } } while (false)
2807 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)
2808 "Invalid bitcast", &I)do { if (!(CastInst::castIsValid(Instruction::BitCast, I.getOperand
(0), I.getType()))) { CheckFailed("Invalid bitcast", &I);
return; } } while (false)
;
2809 visitInstruction(I);
2810}
2811
2812void Verifier::visitAddrSpaceCastInst(AddrSpaceCastInst &I) {
2813 Type *SrcTy = I.getOperand(0)->getType();
2814 Type *DestTy = I.getType();
2815
2816 Assert(SrcTy->isPtrOrPtrVectorTy(), "AddrSpaceCast source must be a pointer",do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast source must be a pointer"
, &I); return; } } while (false)
2817 &I)do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast source must be a pointer"
, &I); return; } } while (false)
;
2818 Assert(DestTy->isPtrOrPtrVectorTy(), "AddrSpaceCast result must be a pointer",do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast result must be a pointer"
, &I); return; } } while (false)
2819 &I)do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast result must be a pointer"
, &I); return; } } while (false)
;
2820 Assert(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace(),do { if (!(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace
())) { CheckFailed("AddrSpaceCast must be between different address spaces"
, &I); return; } } while (false)
2821 "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)
;
2822 if (SrcTy->isVectorTy())
2823 Assert(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements(),do { if (!(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements
())) { CheckFailed("AddrSpaceCast vector pointer number of elements mismatch"
, &I); return; } } while (false)
2824 "AddrSpaceCast vector pointer number of elements mismatch", &I)do { if (!(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements
())) { CheckFailed("AddrSpaceCast vector pointer number of elements mismatch"
, &I); return; } } while (false)
;
2825 visitInstruction(I);
2826}
2827
2828/// visitPHINode - Ensure that a PHI node is well formed.
2829///
2830void Verifier::visitPHINode(PHINode &PN) {
2831 // Ensure that the PHI nodes are all grouped together at the top of the block.
2832 // This can be tested by checking whether the instruction before this is
2833 // either nonexistent (because this is begin()) or is a PHI node. If not,
2834 // then there is some other instruction before a PHI.
2835 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)
2836 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)
2837 "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)
;
2838
2839 // Check that a PHI doesn't yield a Token.
2840 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)
;
2841
2842 // Check that all of the values of the PHI node have the same type as the
2843 // result, and that the incoming blocks are really basic blocks.
2844 for (Value *IncValue : PN.incoming_values()) {
2845 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)
2846 "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)
;
2847 }
2848
2849 // All other PHI node constraints are checked in the visitBasicBlock method.
2850
2851 visitInstruction(PN);
2852}
2853
2854void Verifier::visitCallBase(CallBase &Call) {
2855 Assert(Call.getCalledValue()->getType()->isPointerTy(),do { if (!(Call.getCalledValue()->getType()->isPointerTy
())) { CheckFailed("Called function must be a pointer!", Call
); return; } } while (false)
2856 "Called function must be a pointer!", Call)do { if (!(Call.getCalledValue()->getType()->isPointerTy
())) { CheckFailed("Called function must be a pointer!", Call
); return; } } while (false)
;
2857 PointerType *FPTy = cast<PointerType>(Call.getCalledValue()->getType());
2858
2859 Assert(FPTy->getElementType()->isFunctionTy(),do { if (!(FPTy->getElementType()->isFunctionTy())) { CheckFailed
("Called function is not pointer to function type!", Call); return
; } } while (false)
2860 "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)
;
2861
2862 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)
2863 "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)
;
2864
2865 FunctionType *FTy = Call.getFunctionType();
2866
2867 // Verify that the correct number of arguments are being passed
2868 if (FTy->isVarArg())
2869 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)
2870 "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)
2871 Call)do { if (!(Call.arg_size() >= FTy->getNumParams())) { CheckFailed
("Called function requires more parameters than were provided!"
, Call); return; } } while (false)
;
2872 else
2873 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)
2874 "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)
;
2875
2876 // Verify that all arguments to the call match the function type.
2877 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
2878 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)
2879 "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)
2880 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)
;
2881
2882 AttributeList Attrs = Call.getAttributes();
2883
2884 Assert(verifyAttributeCount(Attrs, Call.arg_size()),do { if (!(verifyAttributeCount(Attrs, Call.arg_size()))) { CheckFailed
("Attribute after last parameter!", Call); return; } } while (
false)
2885 "Attribute after last parameter!", Call)do { if (!(verifyAttributeCount(Attrs, Call.arg_size()))) { CheckFailed
("Attribute after last parameter!", Call); return; } } while (
false)
;
2886
2887 bool IsIntrinsic = Call.getCalledFunction() &&
2888 Call.getCalledFunction()->getName().startswith("llvm.");
2889
2890 Function *Callee
2891 = dyn_cast<Function>(Call.getCalledValue()->stripPointerCasts());
2892
2893 if (Attrs.hasAttribute(AttributeList::FunctionIndex, Attribute::Speculatable)) {
2894 // Don't allow speculatable on call sites, unless the underlying function
2895 // declaration is also speculatable.
2896 Assert(Callee && Callee->isSpeculatable(),do { if (!(Callee && Callee->isSpeculatable())) { CheckFailed
("speculatable attribute may not apply to call sites", Call);
return; } } while (false)
2897 "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)
;
2898 }
2899
2900 // Verify call attributes.
2901 verifyFunctionAttrs(FTy, Attrs, &Call, IsIntrinsic);
2902
2903 // Conservatively check the inalloca argument.
2904 // We have a bug if we can find that there is an underlying alloca without
2905 // inalloca.
2906 if (Call.hasInAllocaArgument()) {
2907 Value *InAllocaArg = Call.getArgOperand(FTy->getNumParams() - 1);
2908 if (auto AI = dyn_cast<AllocaInst>(InAllocaArg->stripInBoundsOffsets()))
2909 Assert(AI->isUsedWithInAlloca(),do { if (!(AI->isUsedWithInAlloca())) { CheckFailed("inalloca argument for call has mismatched alloca"
, AI, Call); return; } } while (false)
2910 "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)
;
2911 }
2912
2913 // For each argument of the callsite, if it has the swifterror argument,
2914 // make sure the underlying alloca/parameter it comes from has a swifterror as
2915 // well.
2916 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
2917 if (Call.paramHasAttr(i, Attribute::SwiftError)) {
2918 Value *SwiftErrorArg = Call.getArgOperand(i);
2919 if (auto AI = dyn_cast<AllocaInst>(SwiftErrorArg->stripInBoundsOffsets())) {
2920 Assert(AI->isSwiftError(),do { if (!(AI->isSwiftError())) { CheckFailed("swifterror argument for call has mismatched alloca"
, AI, Call); return; } } while (false)
2921 "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)
;
2922 continue;
2923 }
2924 auto ArgI = dyn_cast<Argument>(SwiftErrorArg);
2925 Assert(ArgI,do { if (!(ArgI)) { CheckFailed("swifterror argument should come from an alloca or parameter"
, SwiftErrorArg, Call); return; } } while (false)
2926 "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)
2927 SwiftErrorArg, Call)do { if (!(ArgI)) { CheckFailed("swifterror argument should come from an alloca or parameter"
, SwiftErrorArg, Call); return; } } while (false)
;
2928 Assert(ArgI->hasSwiftErrorAttr(),do { if (!(ArgI->hasSwiftErrorAttr())) { CheckFailed("swifterror argument for call has mismatched parameter"
, ArgI, Call); return; } } while (false)
2929 "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)
2930 Call)do { if (!(ArgI->hasSwiftErrorAttr())) { CheckFailed("swifterror argument for call has mismatched parameter"
, ArgI, Call); return; } } while (false)
;
2931 }
2932
2933 if (Attrs.hasParamAttribute(i, Attribute::ImmArg)) {
2934 // Don't allow immarg on call sites, unless the underlying declaration
2935 // also has the matching immarg.
2936 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)
2937 "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)
2938 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)
;
2939 }
2940
2941 if (Call.paramHasAttr(i, Attribute::ImmArg)) {
2942 Value *ArgVal = Call.getArgOperand(i);
2943 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)
2944 "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)
;
2945 }
2946 }
2947
2948 if (FTy->isVarArg()) {
2949 // FIXME? is 'nest' even legal here?
2950 bool SawNest = false;
2951 bool SawReturned = false;
2952
2953 for (unsigned Idx = 0; Idx < FTy->getNumParams(); ++Idx) {
2954 if (Attrs.hasParamAttribute(Idx, Attribute::Nest))
2955 SawNest = true;
2956 if (Attrs.hasParamAttribute(Idx, Attribute::Returned))
2957 SawReturned = true;
2958 }
2959
2960 // Check attributes on the varargs part.
2961 for (unsigned Idx = FTy->getNumParams(); Idx < Call.arg_size(); ++Idx) {
2962 Type *Ty = Call.getArgOperand(Idx)->getType();
2963 AttributeSet ArgAttrs = Attrs.getParamAttributes(Idx);
2964 verifyParameterAttrs(ArgAttrs, Ty, &Call);
2965
2966 if (ArgAttrs.hasAttribute(Attribute::Nest)) {
2967 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)
;
2968 SawNest = true;
2969 }
2970
2971 if (ArgAttrs.hasAttribute(Attribute::Returned)) {
2972 Assert(!SawReturned, "More than one parameter has attribute returned!",do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!"
, Call); return; } } while (false)
2973 Call)do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!"
, Call); return; } } while (false)
;
2974 Assert(Ty->canLosslesslyBitCastTo(FTy->getReturnType()),do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType
()))) { CheckFailed("Incompatible argument and return types for 'returned' "
"attribute", Call); return; } } while (false)
2975 "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)
2976 "attribute",do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType
()))) { CheckFailed("Incompatible argument and return types for 'returned' "
"attribute", Call); return; } } while (false)
2977 Call)do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType
()))) { CheckFailed("Incompatible argument and return types for 'returned' "
"attribute", Call); return; } } while (false)
;
2978 SawReturned = true;
2979 }
2980
2981 // Statepoint intrinsic is vararg but the wrapped function may be not.
2982 // Allow sret here and check the wrapped function in verifyStatepoint.
2983 if (!Call.getCalledFunction() ||
2984 Call.getCalledFunction()->getIntrinsicID() !=
2985 Intrinsic::experimental_gc_statepoint)
2986 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)
2987 "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)
2988 Call)do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed
("Attribute 'sret' cannot be used for vararg call arguments!"
, Call); return; } } while (false)
;
2989
2990 if (ArgAttrs.hasAttribute(Attribute::InAlloca))
2991 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)
2992 "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)
;
2993 }
2994 }
2995
2996 // Verify that there's no metadata unless it's a direct call to an intrinsic.
2997 if (!IsIntrinsic) {
2998 for (Type *ParamTy : FTy->params()) {
2999 Assert(!ParamTy->isMetadataTy(),do { if (!(!ParamTy->isMetadataTy())) { CheckFailed("Function has metadata parameter but isn't an intrinsic"
, Call); return; } } while (false)
3000 "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)
;
3001 Assert(!ParamTy->isTokenTy(),do { if (!(!ParamTy->isTokenTy())) { CheckFailed("Function has token parameter but isn't an intrinsic"
, Call); return; } } while (false)
3002 "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)
;
3003 }
3004 }
3005
3006 // Verify that indirect calls don't return tokens.
3007 if (!Call.getCalledFunction())
3008 Assert(!FTy->getReturnType()->isTokenTy(),do { if (!(!FTy->getReturnType()->isTokenTy())) { CheckFailed
("Return type cannot be token for indirect call!"); return; }
} while (false)
3009 "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)
;
3010
3011 if (Function *F = Call.getCalledFunction())
3012 if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID())
3013 visitIntrinsicCall(ID, Call);
3014
3015 // Verify that a callsite has at most one "deopt", at most one "funclet", at
3016 // most one "gc-transition", and at most one "cfguardtarget" operand bundle.
3017 bool FoundDeoptBundle = false, FoundFuncletBundle = false,
3018 FoundGCTransitionBundle = false, FoundCFGuardTargetBundle = false;
3019 for (unsigned i = 0, e = Call.getNumOperandBundles(); i < e; ++i) {
3020 OperandBundleUse BU = Call.getOperandBundleAt(i);
3021 uint32_t Tag = BU.getTagID();
3022 if (Tag == LLVMContext::OB_deopt) {
3023 Assert(!FoundDeoptBundle, "Multiple deopt operand bundles", Call)do { if (!(!FoundDeoptBundle)) { CheckFailed("Multiple deopt operand bundles"
, Call); return; } } while (false)
;
3024 FoundDeoptBundle = true;
3025 } else if (Tag == LLVMContext::OB_gc_transition) {
3026 Assert(!FoundGCTransitionBundle, "Multiple gc-transition operand bundles",do { if (!(!FoundGCTransitionBundle)) { CheckFailed("Multiple gc-transition operand bundles"
, Call); return; } } while (false)
3027 Call)do { if (!(!FoundGCTransitionBundle)) { CheckFailed("Multiple gc-transition operand bundles"
, Call); return; } } while (false)
;
3028 FoundGCTransitionBundle = true;
3029 } else if (Tag == LLVMContext::OB_funclet) {
3030 Assert(!FoundFuncletBundle, "Multiple funclet operand bundles", Call)do { if (!(!FoundFuncletBundle)) { CheckFailed("Multiple funclet operand bundles"
, Call); return; } } while (false)
;
3031 FoundFuncletBundle = true;
3032 Assert(BU.Inputs.size() == 1,do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one funclet bundle operand"
, Call); return; } } while (false)
3033 "Expected exactly one funclet bundle operand", Call)do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one funclet bundle operand"
, Call); return; } } while (false)
;
3034 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)
3035 "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)
3036 Call)do { if (!(isa<FuncletPadInst>(BU.Inputs.front()))) { CheckFailed
("Funclet bundle operands should correspond to a FuncletPadInst"
, Call); return; } } while (false)
;
3037 } else if (Tag == LLVMContext::OB_cfguardtarget) {
3038 Assert(!FoundCFGuardTargetBundle,do { if (!(!FoundCFGuardTargetBundle)) { CheckFailed("Multiple CFGuardTarget operand bundles"
, Call); return; } } while (false)
3039 "Multiple CFGuardTarget operand bundles", Call)do { if (!(!FoundCFGuardTargetBundle)) { CheckFailed("Multiple CFGuardTarget operand bundles"
, Call); return; } } while (false)
;
3040 FoundCFGuardTargetBundle = true;
3041 Assert(BU.Inputs.size() == 1,do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one cfguardtarget bundle operand"
, Call); return; } } while (false)
3042 "Expected exactly one cfguardtarget bundle operand", Call)do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one cfguardtarget bundle operand"
, Call); return; } } while (false)
;
3043 }
3044 }
3045
3046 // Verify that each inlinable callsite of a debug-info-bearing function in a
3047 // debug-info-bearing function has a debug location attached to it. Failure to
3048 // do so causes assertion failures when the inliner sets up inline scope info.
3049 if (Call.getFunction()->getSubprogram() && Call.getCalledFunction() &&
3050 Call.getCalledFunction()->getSubprogram())
3051 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)
3052 "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)
3053 "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)
3054 Call)do { if (!(Call.getDebugLoc())) { DebugInfoCheckFailed("inlinable function call in a function with "
"debug info must have a !dbg location", Call); return; } } while
(false)
;
3055
3056 visitInstruction(Call);
3057}
3058
3059/// Two types are "congruent" if they are identical, or if they are both pointer
3060/// types with different pointee types and the same address space.
3061static bool isTypeCongruent(Type *L, Type *R) {
3062 if (L == R)
3063 return true;
3064 PointerType *PL = dyn_cast<PointerType>(L);
3065 PointerType *PR = dyn_cast<PointerType>(R);
3066 if (!PL || !PR)
3067 return false;
3068 return PL->getAddressSpace() == PR->getAddressSpace();
3069}
3070
3071static AttrBuilder getParameterABIAttributes(int I, AttributeList Attrs) {
3072 static const Attribute::AttrKind ABIAttrs[] = {
3073 Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca,
3074 Attribute::InReg, Attribute::Returned, Attribute::SwiftSelf,
3075 Attribute::SwiftError};
3076 AttrBuilder Copy;
3077 for (auto AK : ABIAttrs) {
3078 if (Attrs.hasParamAttribute(I, AK))
3079 Copy.addAttribute(AK);
3080 }
3081 if (Attrs.hasParamAttribute(I, Attribute::Alignment))
3082 Copy.addAlignmentAttr(Attrs.getParamAlignment(I));
3083 return Copy;
3084}
3085
3086void Verifier::verifyMustTailCall(CallInst &CI) {
3087 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)
;
3088
3089 // - The caller and callee prototypes must match. Pointer types of
3090 // parameters or return types may differ in pointee type, but not
3091 // address space.
3092 Function *F = CI.getParent()->getParent();
3093 FunctionType *CallerTy = F->getFunctionType();
3094 FunctionType *CalleeTy = CI.getFunctionType();
3095 if (!CI.getCalledFunction() || !CI.getCalledFunction()->isIntrinsic()) {
3096 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)
3097 "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)
3098 &CI)do { if (!(CallerTy->getNumParams() == CalleeTy->getNumParams
())) { CheckFailed("cannot guarantee tail call due to mismatched parameter counts"
, &CI); return; } } while (false)
;
3099 for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) {
3100 Assert(do { if (!(isTypeCongruent(CallerTy->getParamType(I), CalleeTy
->getParamType(I)))) { CheckFailed("cannot guarantee tail call due to mismatched parameter types"
, &CI); return; } } while (false)
3101 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)
3102 "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)
;
3103 }
3104 }
3105 Assert(CallerTy->isVarArg() == CalleeTy->isVarArg(),do { if (!(CallerTy->isVarArg() == CalleeTy->isVarArg()
)) { CheckFailed("cannot guarantee tail call due to mismatched varargs"
, &CI); return; } } while (false)
3106 "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)
;
3107 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)
3108 "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)
;
3109
3110 // - The calling conventions of the caller and callee must match.
3111 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)
3112 "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)
;
3113
3114 // - All ABI-impacting function attributes, such as sret, byval, inreg,
3115 // returned, and inalloca, must match.
3116 AttributeList CallerAttrs = F->getAttributes();
3117 AttributeList CalleeAttrs = CI.getAttributes();
3118 for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) {
3119 AttrBuilder CallerABIAttrs = getParameterABIAttributes(I, CallerAttrs);
3120 AttrBuilder CalleeABIAttrs = getParameterABIAttributes(I, CalleeAttrs);
3121 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)
3122 "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)
3123 "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)
3124 &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)
;
3125 }
3126
3127 // - The call must immediately precede a :ref:`ret <i_ret>` instruction,
3128 // or a pointer bitcast followed by a ret instruction.
3129 // - The ret instruction must return the (possibly bitcasted) value
3130 // produced by the call or void.
3131 Value *RetVal = &CI;
3132 Instruction *Next = CI.getNextNode();
3133
3134 // Handle the optional bitcast.
3135 if (BitCastInst *BI = dyn_cast_or_null<BitCastInst>(Next)) {
3136 Assert(BI->getOperand(0) == RetVal,do { if (!(BI->getOperand(0) == RetVal)) { CheckFailed("bitcast following musttail call must use the call"
, BI); return; } } while (false)
3137 "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)
;
3138 RetVal = BI;
3139 Next = BI->getNextNode();
3140 }
3141
3142 // Check the return.
3143 ReturnInst *Ret = dyn_cast_or_null<ReturnInst>(Next);
3144 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)
3145 &CI)do { if (!(Ret)) { CheckFailed("musttail call must precede a ret with an optional bitcast"
, &CI); return; } } while (false)
;
3146 Assert(!Ret->getReturnValue() || Ret->getReturnValue() == RetVal,do { if (!(!Ret->getReturnValue() || Ret->getReturnValue
() == RetVal)) { CheckFailed("musttail call result must be returned"
, Ret); return; } } while (false)
3147 "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)
;
3148}
3149
3150void Verifier::visitCallInst(CallInst &CI) {
3151 visitCallBase(CI);
3152
3153 if (CI.isMustTailCall())
3154 verifyMustTailCall(CI);
3155}
3156
3157void Verifier::visitInvokeInst(InvokeInst &II) {
3158 visitCallBase(II);
3159
3160 // Verify that the first non-PHI instruction of the unwind destination is an
3161 // exception handling instruction.
3162 Assert(do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!"
, &II); return; } } while (false)
3163 II.getUnwindDest()->isEHPad(),do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!"
, &II); return; } } while (false)
3164 "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)
3165 &II)do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!"
, &II); return; } } while (false)
;
3166
3167 visitTerminator(II);
3168}
3169
3170/// visitUnaryOperator - Check the argument to the unary operator.
3171///
3172void Verifier::visitUnaryOperator(UnaryOperator &U) {
3173 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)
3174 "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)
3175 "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)
3176 &U)do { if (!(U.getType() == U.getOperand(0)->getType())) { CheckFailed
("Unary operators must have same type for" "operands and result!"
, &U); return; } } while (false)
;
3177
3178 switch (U.getOpcode()) {
3179 // Check that floating-point arithmetic operators are only used with
3180 // floating-point operands.
3181 case Instruction::FNeg:
3182 Assert(U.getType()->isFPOrFPVectorTy(),do { if (!(U.getType()->isFPOrFPVectorTy())) { CheckFailed
("FNeg operator only works with float types!", &U); return
; } } while (false)
3183 "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)
;
3184 break;
3185 default:
3186 llvm_unreachable("Unknown UnaryOperator opcode!")::llvm::llvm_unreachable_internal("Unknown UnaryOperator opcode!"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 3186)
;
3187 }
3188
3189 visitInstruction(U);
3190}
3191
3192/// visitBinaryOperator - Check that both arguments to the binary operator are
3193/// of the same type!
3194///
3195void Verifier::visitBinaryOperator(BinaryOperator &B) {
3196 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)
3197 "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)
;
3198
3199 switch (B.getOpcode()) {
3200 // Check that integer arithmetic operators are only used with
3201 // integral operands.
3202 case Instruction::Add:
3203 case Instruction::Sub:
3204 case Instruction::Mul:
3205 case Instruction::SDiv:
3206 case Instruction::UDiv:
3207 case Instruction::SRem:
3208 case Instruction::URem:
3209 Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed
("Integer arithmetic operators only work with integral types!"
, &B); return; } } while (false)
3210 "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)
;
3211 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)
3212 "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)
3213 "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)
3214 &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)
;
3215 break;
3216 // Check that floating-point arithmetic operators are only used with
3217 // floating-point operands.
3218 case Instruction::FAdd:
3219 case Instruction::FSub:
3220 case Instruction::FMul:
3221 case Instruction::FDiv:
3222 case Instruction::FRem:
3223 Assert(B.getType()->isFPOrFPVectorTy(),do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed
("Floating-point arithmetic operators only work with " "floating-point types!"
, &B); return; } } while (false)
3224 "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)
3225 "floating-point types!",do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed
("Floating-point arithmetic operators only work with " "floating-point types!"
, &B); return; } } while (false)
3226 &B)do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed
("Floating-point arithmetic operators only work with " "floating-point types!"
, &B); return; } } while (false)
;
3227 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)
3228 "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)
3229 "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)
3230 &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)
;
3231 break;
3232 // Check that logical operators are only used with integral operands.
3233 case Instruction::And:
3234 case Instruction::Or:
3235 case Instruction::Xor:
3236 Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed
("Logical operators only work with integral types!", &B);
return; } } while (false)
3237 "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)
;
3238 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)
3239 "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)
3240 &B)do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed
("Logical operators must have same type for operands and result!"
, &B); return; } } while (false)
;
3241 break;
3242 case Instruction::Shl:
3243 case Instruction::LShr:
3244 case Instruction::AShr:
3245 Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed
("Shifts only work with integral types!", &B); return; } }
while (false)
3246 "Shifts only work with integral types!", &B)do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed
("Shifts only work with integral types!", &B); return; } }
while (false)
;
3247 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)
3248 "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)
;
3249 break;
3250 default:
3251 llvm_unreachable("Unknown BinaryOperator opcode!")::llvm::llvm_unreachable_internal("Unknown BinaryOperator opcode!"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 3251)
;
3252 }
3253
3254 visitInstruction(B);
3255}
3256
3257void Verifier::visitICmpInst(ICmpInst &IC) {
3258 // Check that the operands are the same type
3259 Type *Op0Ty = IC.getOperand(0)->getType();
3260 Type *Op1Ty = IC.getOperand(1)->getType();
3261 Assert(Op0Ty == Op1Ty,do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to ICmp instruction are not of the same type!"
, &IC); return; } } while (false)
3262 "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)
;
3263 // Check that the operands are the right type
3264 Assert(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy(),do { if (!(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy
())) { CheckFailed("Invalid operand types for ICmp instruction"
, &IC); return; } } while (false)
3265 "Invalid operand types for ICmp instruction", &IC)do { if (!(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy
())) { CheckFailed("Invalid operand types for ICmp instruction"
, &IC); return; } } while (false)
;
3266 // Check that the predicate is valid.
3267 Assert(IC.isIntPredicate(),do { if (!(IC.isIntPredicate())) { CheckFailed("Invalid predicate in ICmp instruction!"
, &IC); return; } } while (false)
3268 "Invalid predicate in ICmp instruction!", &IC)do { if (!(IC.isIntPredicate())) { CheckFailed("Invalid predicate in ICmp instruction!"
, &IC); return; } } while (false)
;
3269
3270 visitInstruction(IC);
3271}
3272
3273void Verifier::visitFCmpInst(FCmpInst &FC) {
3274 // Check that the operands are the same type
3275 Type *Op0Ty = FC.getOperand(0)->getType();
3276 Type *Op1Ty = FC.getOperand(1)->getType();
3277 Assert(Op0Ty == Op1Ty,do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to FCmp instruction are not of the same type!"
, &FC); return; } } while (false)
3278 "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)
;
3279 // Check that the operands are the right type
3280 Assert(Op0Ty->isFPOrFPVectorTy(),do { if (!(Op0Ty->isFPOrFPVectorTy())) { CheckFailed("Invalid operand types for FCmp instruction"
, &FC); return; } } while (false)
3281 "Invalid operand types for FCmp instruction", &FC)do { if (!(Op0Ty->isFPOrFPVectorTy())) { CheckFailed("Invalid operand types for FCmp instruction"
, &FC); return; } } while (false)
;
3282 // Check that the predicate is valid.
3283 Assert(FC.isFPPredicate(),do { if (!(FC.isFPPredicate())) { CheckFailed("Invalid predicate in FCmp instruction!"
, &FC); return; } } while (false)
3284 "Invalid predicate in FCmp instruction!", &FC)do { if (!(FC.isFPPredicate())) { CheckFailed("Invalid predicate in FCmp instruction!"
, &FC); return; } } while (false)
;
3285
3286 visitInstruction(FC);
3287}
3288
3289void Verifier::visitExtractElementInst(ExtractElementInst &EI) {
3290 Assert(do { if (!(ExtractElementInst::isValidOperands(EI.getOperand(
0), EI.getOperand(1)))) { CheckFailed("Invalid extractelement operands!"
, &EI); return; } } while (false)
3291 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)
3292 "Invalid extractelement operands!", &EI)do { if (!(ExtractElementInst::isValidOperands(EI.getOperand(
0), EI.getOperand(1)))) { CheckFailed("Invalid extractelement operands!"
, &EI); return; } } while (false)
;
3293 visitInstruction(EI);
3294}
3295
3296void Verifier::visitInsertElementInst(InsertElementInst &IE) {
3297 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)
3298 IE.getOperand(2)),do { if (!(InsertElementInst::isValidOperands(IE.getOperand(0
), IE.getOperand(1), IE.getOperand(2)))) { CheckFailed("Invalid insertelement operands!"
, &IE); return; } } while (false)
3299 "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)
;
3300 visitInstruction(IE);
3301}
3302
3303void Verifier::visitShuffleVectorInst(ShuffleVectorInst &SV) {
3304 Assert(ShuffleVectorInst::isValidOperands(SV.getOperand(0), SV.getOperand(1),do { if (!(ShuffleVectorInst::isValidOperands(SV.getOperand(0
), SV.getOperand(1), SV.getOperand(2)))) { CheckFailed("Invalid shufflevector operands!"
, &SV); return; } } while (false)
3305 SV.getOperand(2)),do { if (!(ShuffleVectorInst::isValidOperands(SV.getOperand(0
), SV.getOperand(1), SV.getOperand(2)))) { CheckFailed("Invalid shufflevector operands!"
, &SV); return; } } while (false)
3306 "Invalid shufflevector operands!", &SV)do { if (!(ShuffleVectorInst::isValidOperands(SV.getOperand(0
), SV.getOperand(1), SV.getOperand(2)))) { CheckFailed("Invalid shufflevector operands!"
, &SV); return; } } while (false)
;
3307 visitInstruction(SV);
3308}
3309
3310void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
3311 Type *TargetTy = GEP.getPointerOperandType()->getScalarType();
3312
3313 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)
3314 "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)
;
3315 Assert(GEP.getSourceElementType()->isSized(), "GEP into unsized type!", &GEP)do { if (!(GEP.getSourceElementType()->isSized())) { CheckFailed
("GEP into unsized type!", &GEP); return; } } while (false
)
;
3316
3317 SmallVector<Value*, 16> Idxs(GEP.idx_begin(), GEP.idx_end());
3318 Assert(all_of(do { if (!(all_of( Idxs, [](Value* V) { return V->getType(
)->isIntOrIntVectorTy(); }))) { CheckFailed("GEP indexes must be integers"
, &GEP); return; } } while (false)
3319 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)
3320 "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)
;
3321 Type *ElTy =
3322 GetElementPtrInst::getIndexedType(GEP.getSourceElementType(), Idxs);
3323 Assert(ElTy, "Invalid indices for GEP pointer type!", &GEP)do { if (!(ElTy)) { CheckFailed("Invalid indices for GEP pointer type!"
, &GEP); return; } } while (false)
;
3324
3325 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)
3326 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)
3327 "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)
;
3328
3329 if (GEP.getType()->isVectorTy()) {
3330 // Additional checks for vector GEPs.
3331 unsigned GEPWidth = GEP.getType()->getVectorNumElements();
3332 if (GEP.getPointerOperandType()->isVectorTy())
3333 Assert(GEPWidth == GEP.getPointerOperandType()->getVectorNumElements(),do { if (!(GEPWidth == GEP.getPointerOperandType()->getVectorNumElements
())) { CheckFailed("Vector GEP result width doesn't match operand's"
, &GEP); return; } } while (false)
3334 "Vector GEP result width doesn't match operand's", &GEP)do { if (!(GEPWidth == GEP.getPointerOperandType()->getVectorNumElements
())) { CheckFailed("Vector GEP result width doesn't match operand's"
, &GEP); return; } } while (false)
;
3335 for (Value *Idx : Idxs) {
3336 Type *IndexTy = Idx->getType();
3337 if (IndexTy->isVectorTy()) {
3338 unsigned IndexWidth = IndexTy->getVectorNumElements();
3339 Assert(IndexWidth == GEPWidth, "Invalid GEP index vector width", &GEP)do { if (!(IndexWidth == GEPWidth)) { CheckFailed("Invalid GEP index vector width"
, &GEP); return; } } while (false)
;
3340 }
3341 Assert(IndexTy->isIntOrIntVectorTy(),do { if (!(IndexTy->isIntOrIntVectorTy())) { CheckFailed("All GEP indices should be of integer type"
); return; } } while (false)
3342 "All GEP indices should be of integer type")do { if (!(IndexTy->isIntOrIntVectorTy())) { CheckFailed("All GEP indices should be of integer type"
); return; } } while (false)
;
3343 }
3344 }
3345
3346 if (auto *PTy = dyn_cast<PointerType>(GEP.getType())) {
3347 Assert(GEP.getAddressSpace() == PTy->getAddressSpace(),do { if (!(GEP.getAddressSpace() == PTy->getAddressSpace()
)) { CheckFailed("GEP address space doesn't match type", &
GEP); return; } } while (false)
3348 "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)
;
3349 }
3350
3351 visitInstruction(GEP);
3352}
3353
3354static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {
3355 return A.getUpper() == B.getLower() || A.getLower() == B.getUpper();
3356}
3357
3358void Verifier::visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty) {
3359 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-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 3360, __PRETTY_FUNCTION__))
3360 "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-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 3360, __PRETTY_FUNCTION__))
;
3361
3362 unsigned NumOperands = Range->getNumOperands();
3363 Assert(NumOperands % 2 == 0, "Unfinished range!", Range)do { if (!(NumOperands % 2 == 0)) { CheckFailed("Unfinished range!"
, Range); return; } } while (false)
;
3364 unsigned NumRanges = NumOperands / 2;
3365 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)
;
3366
3367 ConstantRange LastRange(1, true); // Dummy initial value
3368 for (unsigned i = 0; i < NumRanges; ++i) {
3369 ConstantInt *Low =
3370 mdconst::dyn_extract<ConstantInt>(Range->getOperand(2 * i));
3371 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)
;
3372 ConstantInt *High =
3373 mdconst::dyn_extract<ConstantInt>(Range->getOperand(2 * i + 1));
3374 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)
;
3375 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)
3376 "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)
;
3377
3378 APInt HighV = High->getValue();
3379 APInt LowV = Low->getValue();
3380 ConstantRange CurRange(LowV, HighV);
3381 Assert(!CurRange.isEmptySet() && !CurRange.isFullSet(),do { if (!(!CurRange.isEmptySet() && !CurRange.isFullSet
())) { CheckFailed("Range must not be empty!", Range); return
; } } while (false)
3382 "Range must not be empty!", Range)do { if (!(!CurRange.isEmptySet() && !CurRange.isFullSet
())) { CheckFailed("Range must not be empty!", Range); return
; } } while (false)
;
3383 if (i != 0) {
3384 Assert(CurRange.intersectWith(LastRange).isEmptySet(),do { if (!(CurRange.intersectWith(LastRange).isEmptySet())) {
CheckFailed("Intervals are overlapping", Range); return; } }
while (false)
3385 "Intervals are overlapping", Range)do { if (!(CurRange.intersectWith(LastRange).isEmptySet())) {
CheckFailed("Intervals are overlapping", Range); return; } }
while (false)
;
3386 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)
3387 Range)do { if (!(LowV.sgt(LastRange.getLower()))) { CheckFailed("Intervals are not in order"
, Range); return; } } while (false)
;
3388 Assert(!isContiguous(CurRange, LastRange), "Intervals are contiguous",do { if (!(!isContiguous(CurRange, LastRange))) { CheckFailed
("Intervals are contiguous", Range); return; } } while (false
)
3389 Range)do { if (!(!isContiguous(CurRange, LastRange))) { CheckFailed
("Intervals are contiguous", Range); return; } } while (false
)
;
3390 }
3391 LastRange = ConstantRange(LowV, HighV);
3392 }
3393 if (NumRanges > 2) {
3394 APInt FirstLow =
3395 mdconst::dyn_extract<ConstantInt>(Range->getOperand(0))->getValue();
3396 APInt FirstHigh =
3397 mdconst::dyn_extract<ConstantInt>(Range->getOperand(1))->getValue();
3398 ConstantRange FirstRange(FirstLow, FirstHigh);
3399 Assert(FirstRange.intersectWith(LastRange).isEmptySet(),do { if (!(FirstRange.intersectWith(LastRange).isEmptySet()))
{ CheckFailed("Intervals are overlapping", Range); return; }
} while (false)
3400 "Intervals are overlapping", Range)do { if (!(FirstRange.intersectWith(LastRange).isEmptySet()))
{ CheckFailed("Intervals are overlapping", Range); return; }
} while (false)
;
3401 Assert(!isContiguous(FirstRange, LastRange), "Intervals are contiguous",do { if (!(!isContiguous(FirstRange, LastRange))) { CheckFailed
("Intervals are contiguous", Range); return; } } while (false
)
3402 Range)do { if (!(!isContiguous(FirstRange, LastRange))) { CheckFailed
("Intervals are contiguous", Range); return; } } while (false
)
;
3403 }
3404}
3405
3406void Verifier::checkAtomicMemAccessSize(Type *Ty, const Instruction *I) {
3407 unsigned Size = DL.getTypeSizeInBits(Ty);
3408 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)
;
3409 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)
3410 "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)
;
3411}
3412
3413void Verifier::visitLoadInst(LoadInst &LI) {
3414 PointerType *PTy = dyn_cast<PointerType>(LI.getOperand(0)->getType());
3415 Assert(PTy, "Load operand must be a pointer.", &LI)do { if (!(PTy)) { CheckFailed("Load operand must be a pointer."
, &LI); return; } } while (false)
;
3416 Type *ElTy = LI.getType();
3417 Assert(LI.getAlignment() <= Value::MaximumAlignment,do { if (!(LI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &LI
); return; } } while (false)
3418 "huge alignment values are unsupported", &LI)do { if (!(LI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &LI
); return; } } while (false)
;
3419 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)
;
3420 if (LI.isAtomic()) {
3421 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)
3422 LI.getOrdering() != AtomicOrdering::AcquireRelease,do { if (!(LI.getOrdering() != AtomicOrdering::Release &&
LI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed
("Load cannot have Release ordering", &LI); return; } } while
(false)
3423 "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)
;
3424 Assert(LI.getAlignment() != 0,do { if (!(LI.getAlignment() != 0)) { CheckFailed("Atomic load must specify explicit alignment"
, &LI); return; } } while (false)
3425 "Atomic load must specify explicit alignment", &LI)do { if (!(LI.getAlignment() != 0)) { CheckFailed("Atomic load must specify explicit alignment"
, &LI); return; } } while (false)
;
3426 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)
3427 "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)
3428 "type!",do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy
())) { CheckFailed("atomic load operand must have integer, pointer, or floating point "
"type!", ElTy, &LI); return; } } while (false)
3429 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)
;
3430 checkAtomicMemAccessSize(ElTy, &LI);
3431 } else {
3432 Assert(LI.getSyncScopeID() == SyncScope::System,do { if (!(LI.getSyncScopeID() == SyncScope::System)) { CheckFailed
("Non-atomic load cannot have SynchronizationScope specified"
, &LI); return; } } while (false)
3433 "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)
;
3434 }
3435
3436 visitInstruction(LI);
3437}
3438
3439void Verifier::visitStoreInst(StoreInst &SI) {
3440 PointerType *PTy = dyn_cast<PointerType>(SI.getOperand(1)->getType());
3441 Assert(PTy, "Store operand must be a pointer.", &SI)do { if (!(PTy)) { CheckFailed("Store operand must be a pointer."
, &SI); return; } } while (false)
;
3442 Type *ElTy = PTy->getElementType();
3443 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)
3444 "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)
;
3445 Assert(SI.getAlignment() <= Value::MaximumAlignment,do { if (!(SI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &SI
); return; } } while (false)
3446 "huge alignment values are unsupported", &SI)do { if (!(SI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &SI
); return; } } while (false)
;
3447 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)
;
3448 if (SI.isAtomic()) {
3449 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)
3450 SI.getOrdering() != AtomicOrdering::AcquireRelease,do { if (!(SI.getOrdering() != AtomicOrdering::Acquire &&
SI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed
("Store cannot have Acquire ordering", &SI); return; } } while
(false)
3451 "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)
;
3452 Assert(SI.getAlignment() != 0,do { if (!(SI.getAlignment() != 0)) { CheckFailed("Atomic store must specify explicit alignment"
, &SI); return; } } while (false)
3453 "Atomic store must specify explicit alignment", &SI)do { if (!(SI.getAlignment() != 0)) { CheckFailed("Atomic store must specify explicit alignment"
, &SI); return; } } while (false)
;
3454 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)
3455 "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)
3456 "type!",do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy
())) { CheckFailed("atomic store operand must have integer, pointer, or floating point "
"type!", ElTy, &SI); return; } } while (false)
3457 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)
;
3458 checkAtomicMemAccessSize(ElTy, &SI);
3459 } else {
3460 Assert(SI.getSyncScopeID() == SyncScope::System,do { if (!(SI.getSyncScopeID() == SyncScope::System)) { CheckFailed
("Non-atomic store cannot have SynchronizationScope specified"
, &SI); return; } } while (false)
3461 "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)
;
3462 }
3463 visitInstruction(SI);
3464}
3465
3466/// Check that SwiftErrorVal is used as a swifterror argument in CS.
3467void Verifier::verifySwiftErrorCall(CallBase &Call,
3468 const Value *SwiftErrorVal) {
3469 unsigned Idx = 0;
3470 for (auto I = Call.arg_begin(), E = Call.arg_end(); I != E; ++I, ++Idx) {
3471 if (*I == SwiftErrorVal) {
3472 Assert(Call.paramHasAttr(Idx, Attribute::SwiftError),do { if (!(Call.paramHasAttr(Idx, Attribute::SwiftError))) { CheckFailed
("swifterror value when used in a callsite should be marked "
"with swifterror attribute", SwiftErrorVal, Call); return; }
} while (false)
3473 "swifterror value when used in a callsite should be marked "do { if (!(Call.paramHasAttr(Idx, Attribute::SwiftError))) { CheckFailed
("swifterror value when used in a callsite should be marked "
"with swifterror attribute", SwiftErrorVal, Call); return; }
} while (false)
3474 "with swifterror attribute",do { if (!(Call.paramHasAttr(Idx, Attribute::SwiftError))) { CheckFailed
("swifterror value when used in a callsite should be marked "
"with swifterror attribute", SwiftErrorVal, Call); return; }
} while (false)
3475 SwiftErrorVal, Call)do { if (!(Call.paramHasAttr(Idx, Attribute::SwiftError))) { CheckFailed
("swifterror value when used in a callsite should be marked "
"with swifterror attribute", SwiftErrorVal, Call); return; }
} while (false)
;
3476 }
3477 }
3478}
3479
3480void Verifier::verifySwiftErrorValue(const Value *SwiftErrorVal) {
3481 // Check that swifterror value is only used by loads, stores, or as
3482 // a swifterror argument.
3483 for (const User *U : SwiftErrorVal->users()) {
3484 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)
3485 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)
3486 "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)
3487 "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)
3488 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)
;
3489 // If it is used by a store, check it is the second operand.
3490 if (auto StoreI = dyn_cast<StoreInst>(U))
3491 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)
3492 "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)
3493 "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)
;
3494 if (auto *Call = dyn_cast<CallBase>(U))
3495 verifySwiftErrorCall(*const_cast<CallBase *>(Call), SwiftErrorVal);
3496 }
3497}
3498
3499void Verifier::visitAllocaInst(AllocaInst &AI) {
3500 SmallPtrSet<Type*, 4> Visited;
3501 PointerType *PTy = AI.getType();
3502 // TODO: Relax this restriction?
3503 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)
3504 "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)
3505 &AI)do { if (!(PTy->getAddressSpace() == DL.getAllocaAddrSpace
())) { CheckFailed("Allocation instruction pointer not in the stack address space!"
, &AI); return; } } while (false)
;
3506 Assert(AI.getAllocatedType()->isSized(&Visited),do { if (!(AI.getAllocatedType()->isSized(&Visited))) {
CheckFailed("Cannot allocate unsized type", &AI); return
; } } while (false)
3507 "Cannot allocate unsized type", &AI)do { if (!(AI.getAllocatedType()->isSized(&Visited))) {
CheckFailed("Cannot allocate unsized type", &AI); return
; } } while (false)
;
3508 Assert(AI.getArraySize()->getType()->isIntegerTy(),do { if (!(AI.getArraySize()->getType()->isIntegerTy())
) { CheckFailed("Alloca array size must have integer type", &
AI); return; } } while (false)
3509 "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)
;
3510 Assert(AI.getAlignment() <= Value::MaximumAlignment,do { if (!(AI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &AI
); return; } } while (false)
3511 "huge alignment values are unsupported", &AI)do { if (!(AI.getAlignment() <= Value::MaximumAlignment)) {
CheckFailed("huge alignment values are unsupported", &AI
); return; } } while (false)
;
3512
3513 if (AI.isSwiftError()) {
3514 verifySwiftErrorValue(&AI);
3515 }
3516
3517 visitInstruction(AI);
3518}
3519
3520void Verifier::visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI) {
3521
3522 // FIXME: more conditions???
3523 Assert(CXI.getSuccessOrdering() != AtomicOrdering::NotAtomic,do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::NotAtomic
)) { CheckFailed("cmpxchg instructions must be atomic.", &
CXI); return; } } while (false)
3524 "cmpxchg instructions must be atomic.", &CXI)do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::NotAtomic
)) { CheckFailed("cmpxchg instructions must be atomic.", &
CXI); return; } } while (false)
;
3525 Assert(CXI.getFailureOrdering() != AtomicOrdering::NotAtomic,do { if (!(CXI.getFailureOrdering() != AtomicOrdering::NotAtomic
)) { CheckFailed("cmpxchg instructions must be atomic.", &
CXI); return; } } while (false)
3526 "cmpxchg instructions must be atomic.", &CXI)do { if (!(CXI.getFailureOrdering() != AtomicOrdering::NotAtomic
)) { CheckFailed("cmpxchg instructions must be atomic.", &
CXI); return; } } while (false)
;
3527 Assert(CXI.getSuccessOrdering() != AtomicOrdering::Unordered,do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::Unordered
)) { CheckFailed("cmpxchg instructions cannot be unordered.",
&CXI); return; } } while (false)
3528 "cmpxchg instructions cannot be unordered.", &CXI)do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::Unordered
)) { CheckFailed("cmpxchg instructions cannot be unordered.",
&CXI); return; } } while (false)
;
3529 Assert(CXI.getFailureOrdering() != AtomicOrdering::Unordered,do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Unordered
)) { CheckFailed("cmpxchg instructions cannot be unordered.",
&CXI); return; } } while (false)
3530 "cmpxchg instructions cannot be unordered.", &CXI)do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Unordered
)) { CheckFailed("cmpxchg instructions cannot be unordered.",
&CXI); return; } } while (false)
;
3531 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)
3532 "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)
3533 "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)
3534 &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)
;
3535 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)
3536 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)
3537 "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)
;
3538
3539 PointerType *PTy = dyn_cast<PointerType>(CXI.getOperand(0)->getType());
3540 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)
;
3541 Type *ElTy = PTy->getElementType();
3542 Assert(ElTy->isIntOrPtrTy(),do { if (!(ElTy->isIntOrPtrTy())) { CheckFailed("cmpxchg operand must have integer or pointer type"
, ElTy, &CXI); return; } } while (false)
3543 "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)
;
3544 checkAtomicMemAccessSize(ElTy, &CXI);
3545 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)
3546 "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)
3547 ElTy)do { if (!(ElTy == CXI.getOperand(1)->getType())) { CheckFailed
("Expected value type does not match pointer operand type!", &
CXI, ElTy); return; } } while (false)
;
3548 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)
3549 "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)
;
3550 visitInstruction(CXI);
3551}
3552
3553void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) {
3554 Assert(RMWI.getOrdering() != AtomicOrdering::NotAtomic,do { if (!(RMWI.getOrdering() != AtomicOrdering::NotAtomic)) {
CheckFailed("atomicrmw instructions must be atomic.", &RMWI
); return; } } while (false)
3555 "atomicrmw instructions must be atomic.", &RMWI)do { if (!(RMWI.getOrdering() != AtomicOrdering::NotAtomic)) {
CheckFailed("atomicrmw instructions must be atomic.", &RMWI
); return; } } while (false)
;
3556 Assert(RMWI.getOrdering() != AtomicOrdering::Unordered,do { if (!(RMWI.getOrdering() != AtomicOrdering::Unordered)) {
CheckFailed("atomicrmw instructions cannot be unordered.", &
RMWI); return; } } while (false)
3557 "atomicrmw instructions cannot be unordered.", &RMWI)do { if (!(RMWI.getOrdering() != AtomicOrdering::Unordered)) {
CheckFailed("atomicrmw instructions cannot be unordered.", &
RMWI); return; } } while (false)
;
3558 auto Op = RMWI.getOperation();
3559 PointerType *PTy = dyn_cast<PointerType>(RMWI.getOperand(0)->getType());
3560 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)
;
3561 Type *ElTy = PTy->getElementType();
3562 if (Op == AtomicRMWInst::Xchg) {
3563 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)
3564 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)
3565 " 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)
3566 &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)
;
3567 } else if (AtomicRMWInst::isFPOperation(Op)) {
3568 Assert(ElTy->isFloatingPointTy(), "atomicrmw " +do { if (!(ElTy->isFloatingPointTy())) { CheckFailed("atomicrmw "
+ AtomicRMWInst::getOperationName(Op) + " operand must have floating point type!"
, &RMWI, ElTy); return; } } while (false)
3569 AtomicRMWInst::getOperationName(Op) +do { if (!(ElTy->isFloatingPointTy())) { CheckFailed("atomicrmw "
+ AtomicRMWInst::getOperationName(Op) + " operand must have floating point type!"
, &RMWI, ElTy); return; } } while (false)
3570 " 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)
3571 &RMWI, ElTy)do { if (!(ElTy->isFloatingPointTy())) { CheckFailed("atomicrmw "
+ AtomicRMWInst::getOperationName(Op) + " operand must have floating point type!"
, &RMWI, ElTy); return; } } while (false)
;
3572 } else {
3573 Assert(ElTy->isIntegerTy(), "atomicrmw " +do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw "
+ AtomicRMWInst::getOperationName(Op) + " operand must have integer type!"
, &RMWI, ElTy); return; } } while (false)
3574 AtomicRMWInst::getOperationName(Op) +do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw "
+ AtomicRMWInst::getOperationName(Op) + " operand must have integer type!"
, &RMWI, ElTy); return; } } while (false)
3575 " operand must have integer type!",do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw "
+ AtomicRMWInst::getOperationName(Op) + " operand must have integer type!"
, &RMWI, ElTy); return; } } while (false)
3576 &RMWI, ElTy)do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw "
+ AtomicRMWInst::getOperationName(Op) + " operand must have integer type!"
, &RMWI, ElTy); return; } } while (false)
;
3577 }
3578 checkAtomicMemAccessSize(ElTy, &RMWI);
3579 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)
3580 "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)
3581 ElTy)do { if (!(ElTy == RMWI.getOperand(1)->getType())) { CheckFailed
("Argument value type does not match pointer operand type!", &
RMWI, ElTy); return; } } while (false)
;
3582 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)
3583 "Invalid binary operation!", &RMWI)do { if (!(AtomicRMWInst::FIRST_BINOP <= Op && Op <=
AtomicRMWInst::LAST_BINOP)) { CheckFailed("Invalid binary operation!"
, &RMWI); return; } } while (false)
;
3584 visitInstruction(RMWI);
3585}
3586
3587void Verifier::visitFenceInst(FenceInst &FI) {
3588 const AtomicOrdering Ordering = FI.getOrdering();
3589 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)
3590 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)
3591 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)
3592 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)
3593 "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)
3594 "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)
3595 &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)
;
3596 visitInstruction(FI);
3597}
3598
3599void Verifier::visitExtractValueInst(ExtractValueInst &EVI) {
3600 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)
3601 EVI.getIndices()) == EVI.getType(),do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand
()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed
("Invalid ExtractValueInst operands!", &EVI); return; } }
while (false)
3602 "Invalid ExtractValueInst operands!", &EVI)do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand
()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed
("Invalid ExtractValueInst operands!", &EVI); return; } }
while (false)
;
3603
3604 visitInstruction(EVI);
3605}
3606
3607void Verifier::visitInsertValueInst(InsertValueInst &IVI) {
3608 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)
3609 IVI.getIndices()) ==do { if (!(ExtractValueInst::getIndexedType(IVI.getAggregateOperand
()->getType(), IVI.getIndices()) == IVI.getOperand(1)->
getType())) { CheckFailed("Invalid InsertValueInst operands!"
, &IVI); return; } } while (false)
3610 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)
3611 "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)
;
3612
3613 visitInstruction(IVI);
3614}
3615
3616static Value *getParentPad(Value *EHPad) {
3617 if (auto *FPI = dyn_cast<FuncletPadInst>(EHPad))
3618 return FPI->getParentPad();
3619
3620 return cast<CatchSwitchInst>(EHPad)->getParentPad();
3621}
3622
3623void Verifier::visitEHPadPredecessors(Instruction &I) {
3624 assert(I.isEHPad())((I.isEHPad()) ? static_cast<void> (0) : __assert_fail (
"I.isEHPad()", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 3624, __PRETTY_FUNCTION__))
;
3625
3626 BasicBlock *BB = I.getParent();
3627 Function *F = BB->getParent();
3628
3629 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)
;
3630
3631 if (auto *LPI = dyn_cast<LandingPadInst>(&I)) {
3632 // The landingpad instruction defines its parent as a landing pad block. The
3633 // landing pad block may be branched to only by the unwind edge of an
3634 // invoke.
3635 for (BasicBlock *PredBB : predecessors(BB)) {
3636 const auto *II = dyn_cast<InvokeInst>(PredBB->getTerminator());
3637 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)
3638 "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)
3639 "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)
3640 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)
;
3641 }
3642 return;
3643 }
3644 if (auto *CPI = dyn_cast<CatchPadInst>(&I)) {
3645 if (!pred_empty(BB))
3646 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)
3647 "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)
3648 "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)
3649 CPI)do { if (!(BB->getUniquePredecessor() == CPI->getCatchSwitch
()->getParent())) { CheckFailed("Block containg CatchPadInst must be jumped to "
"only by its catchswitch.", CPI); return; } } while (false)
;
3650 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)
3651 "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)
3652 CPI->getCatchSwitch(), CPI)do { if (!(BB != CPI->getCatchSwitch()->getUnwindDest()
)) { CheckFailed("Catchswitch cannot unwind to one of its catchpads"
, CPI->getCatchSwitch(), CPI); return; } } while (false)
;
3653 return;
3654 }
3655
3656 // Verify that each pred has a legal terminator with a legal to/from EH
3657 // pad relationship.
3658 Instruction *ToPad = &I;
3659 Value *ToPadParent = getParentPad(ToPad);
3660 for (BasicBlock *PredBB : predecessors(BB)) {
3661 Instruction *TI = PredBB->getTerminator();
3662 Value *FromPad;
3663 if (auto *II = dyn_cast<InvokeInst>(TI)) {
3664 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)
3665 "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)
;
3666 if (auto Bundle = II->getOperandBundle(LLVMContext::OB_funclet))
3667 FromPad = Bundle->Inputs[0];
3668 else
3669 FromPad = ConstantTokenNone::get(II->getContext());
3670 } else if (auto *CRI = dyn_cast<CleanupReturnInst>(TI)) {
3671 FromPad = CRI->getOperand(0);
3672 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)
;
3673 } else if (auto *CSI = dyn_cast<CatchSwitchInst>(TI)) {
3674 FromPad = CSI;
3675 } else {
3676 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)
;
3677 }
3678
3679 // The edge may exit from zero or more nested pads.
3680 SmallSet<Value *, 8> Seen;
3681 for (;; FromPad = getParentPad(FromPad)) {
3682 Assert(FromPad != ToPad,do { if (!(FromPad != ToPad)) { CheckFailed("EH pad cannot handle exceptions raised within it"
, FromPad, TI); return; } } while (false)
3683 "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)
;
3684 if (FromPad == ToPadParent) {
3685 // This is a legal unwind edge.
3686 break;
3687 }
3688 Assert(!isa<ConstantTokenNone>(FromPad),do { if (!(!isa<ConstantTokenNone>(FromPad))) { CheckFailed
("A single unwind edge may only enter one EH pad", TI); return
; } } while (false)
3689 "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)
;
3690 Assert(Seen.insert(FromPad).second,do { if (!(Seen.insert(FromPad).second)) { CheckFailed("EH pad jumps through a cycle of pads"
, FromPad); return; } } while (false)
3691 "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)
;
3692 }
3693 }
3694}
3695
3696void Verifier::visitLandingPadInst(LandingPadInst &LPI) {
3697 // The landingpad instruction is ill-formed if it doesn't have any clauses and
3698 // isn't a cleanup.
3699 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)
3700 "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)
;
3701
3702 visitEHPadPredecessors(LPI);
3703
3704 if (!LandingPadResultTy)
3705 LandingPadResultTy = LPI.getType();
3706 else
3707 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)
3708 "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)
3709 "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)
3710 &LPI)do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed
("The landingpad instruction should have a consistent result type "
"inside a function.", &LPI); return; } } while (false)
;
3711
3712 Function *F = LPI.getParent()->getParent();
3713 Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("LandingPadInst needs to be in a function with a personality."
, &LPI); return; } } while (false)
3714 "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)
;
3715
3716 // The landingpad instruction must be the first non-PHI instruction in the
3717 // block.
3718 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)
3719 "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)
3720 &LPI)do { if (!(LPI.getParent()->getLandingPadInst() == &LPI
)) { CheckFailed("LandingPadInst not the first non-PHI instruction in the block."
, &LPI); return; } } while (false)
;
3721
3722 for (unsigned i = 0, e = LPI.getNumClauses(); i < e; ++i) {
3723 Constant *Clause = LPI.getClause(i);
3724 if (LPI.isCatch(i)) {
3725 Assert(isa<PointerType>(Clause->getType()),do { if (!(isa<PointerType>(Clause->getType()))) { CheckFailed
("Catch operand does not have pointer type!", &LPI); return
; } } while (false)
3726 "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)
;
3727 } else {
3728 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)
;
3729 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)
3730 "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)
;
3731 }
3732 }
3733
3734 visitInstruction(LPI);
3735}
3736
3737void Verifier::visitResumeInst(ResumeInst &RI) {
3738 Assert(RI.getFunction()->hasPersonalityFn(),do { if (!(RI.getFunction()->hasPersonalityFn())) { CheckFailed
("ResumeInst needs to be in a function with a personality.", &
RI); return; } } while (false)
3739 "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)
;
3740
3741 if (!LandingPadResultTy)
3742 LandingPadResultTy = RI.getValue()->getType();
3743 else
3744 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)
3745 "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)
3746 "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)
3747 &RI)do { if (!(LandingPadResultTy == RI.getValue()->getType())
) { CheckFailed("The resume instruction should have a consistent result type "
"inside a function.", &RI); return; } } while (false)
;
3748
3749 visitTerminator(RI);
3750}
3751
3752void Verifier::visitCatchPadInst(CatchPadInst &CPI) {
3753 BasicBlock *BB = CPI.getParent();
3754
3755 Function *F = BB->getParent();
3756 Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchPadInst needs to be in a function with a personality."
, &CPI); return; } } while (false)
3757 "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)
;
3758
3759 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)
3760 "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)
3761 CPI.getParentPad())do { if (!(isa<CatchSwitchInst>(CPI.getParentPad()))) {
CheckFailed("CatchPadInst needs to be directly nested in a CatchSwitchInst."
, CPI.getParentPad()); return; } } while (false)
;
3762
3763 // The catchpad instruction must be the first non-PHI instruction in the
3764 // block.
3765 Assert(BB->getFirstNonPHI() == &CPI,do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed
("CatchPadInst not the first non-PHI instruction in the block."
, &CPI); return; } } while (false)
3766 "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)
;
3767
3768 visitEHPadPredecessors(CPI);
3769 visitFuncletPadInst(CPI);
3770}
3771
3772void Verifier::visitCatchReturnInst(CatchReturnInst &CatchReturn) {
3773 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)
3774 "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)
3775 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)
;
3776
3777 visitTerminator(CatchReturn);
3778}
3779
3780void Verifier::visitCleanupPadInst(CleanupPadInst &CPI) {
3781 BasicBlock *BB = CPI.getParent();
3782
3783 Function *F = BB->getParent();
3784 Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CleanupPadInst needs to be in a function with a personality."
, &CPI); return; } } while (false)
3785 "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)
;
3786
3787 // The cleanuppad instruction must be the first non-PHI instruction in the
3788 // block.
3789 Assert(BB->getFirstNonPHI() == &CPI,do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed
("CleanupPadInst not the first non-PHI instruction in the block."
, &CPI); return; } } while (false)
3790 "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)
3791 &CPI)do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed
("CleanupPadInst not the first non-PHI instruction in the block."
, &CPI); return; } } while (false)
;
3792
3793 auto *ParentPad = CPI.getParentPad();
3794 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)
3795 "CleanupPadInst has an invalid parent.", &CPI)do { if (!(isa<ConstantTokenNone>(ParentPad) || isa<
FuncletPadInst>(ParentPad))) { CheckFailed("CleanupPadInst has an invalid parent."
, &CPI); return; } } while (false)
;
3796
3797 visitEHPadPredecessors(CPI);
3798 visitFuncletPadInst(CPI);
3799}
3800
3801void Verifier::visitFuncletPadInst(FuncletPadInst &FPI) {
3802 User *FirstUser = nullptr;
3803 Value *FirstUnwindPad = nullptr;
3804 SmallVector<FuncletPadInst *, 8> Worklist({&FPI});
3805 SmallSet<FuncletPadInst *, 8> Seen;
3806
3807 while (!Worklist.empty()) {
3808 FuncletPadInst *CurrentPad = Worklist.pop_back_val();
3809 Assert(Seen.insert(CurrentPad).second,do { if (!(Seen.insert(CurrentPad).second)) { CheckFailed("FuncletPadInst must not be nested within itself"
, CurrentPad); return; } } while (false)
3810 "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)
;
3811 Value *UnresolvedAncestorPad = nullptr;
3812 for (User *U : CurrentPad->users()) {
3813 BasicBlock *UnwindDest;
3814 if (auto *CRI = dyn_cast<CleanupReturnInst>(U)) {
3815 UnwindDest = CRI->getUnwindDest();
3816 } else if (auto *CSI = dyn_cast<CatchSwitchInst>(U)) {
3817 // We allow catchswitch unwind to caller to nest
3818 // within an outer pad that unwinds somewhere else,
3819 // because catchswitch doesn't have a nounwind variant.
3820 // See e.g. SimplifyCFGOpt::SimplifyUnreachable.
3821 if (CSI->unwindsToCaller())
3822 continue;
3823 UnwindDest = CSI->getUnwindDest();
3824 } else if (auto *II = dyn_cast<InvokeInst>(U)) {
3825 UnwindDest = II->getUnwindDest();
3826 } else if (isa<CallInst>(U)) {
3827 // Calls which don't unwind may be found inside funclet
3828 // pads that unwind somewhere else. We don't *require*
3829 // such calls to be annotated nounwind.
3830 continue;
3831 } else if (auto *CPI = dyn_cast<CleanupPadInst>(U)) {
3832 // The unwind dest for a cleanup can only be found by
3833 // recursive search. Add it to the worklist, and we'll
3834 // search for its first use that determines where it unwinds.
3835 Worklist.push_back(CPI);
3836 continue;
3837 } else {
3838 Assert(isa<CatchReturnInst>(U), "Bogus funclet pad use", U)do { if (!(isa<CatchReturnInst>(U))) { CheckFailed("Bogus funclet pad use"
, U); return; } } while (false)
;
3839 continue;
3840 }
3841
3842 Value *UnwindPad;
3843 bool ExitsFPI;
3844 if (UnwindDest) {
3845 UnwindPad = UnwindDest->getFirstNonPHI();
3846 if (!cast<Instruction>(UnwindPad)->isEHPad())
3847 continue;
3848 Value *UnwindParent = getParentPad(UnwindPad);
3849 // Ignore unwind edges that don't exit CurrentPad.
3850 if (UnwindParent == CurrentPad)
3851 continue;
3852 // Determine whether the original funclet pad is exited,
3853 // and if we are scanning nested pads determine how many
3854 // of them are exited so we can stop searching their
3855 // children.
3856 Value *ExitedPad = CurrentPad;
3857 ExitsFPI = false;
3858 do {
3859 if (ExitedPad == &FPI) {
3860 ExitsFPI = true;
3861 // Now we can resolve any ancestors of CurrentPad up to
3862 // FPI, but not including FPI since we need to make sure
3863 // to check all direct users of FPI for consistency.
3864 UnresolvedAncestorPad = &FPI;
3865 break;
3866 }
3867 Value *ExitedParent = getParentPad(ExitedPad);
3868 if (ExitedParent == UnwindParent) {
3869 // ExitedPad is the ancestor-most pad which this unwind
3870 // edge exits, so we can resolve up to it, meaning that
3871 // ExitedParent is the first ancestor still unresolved.
3872 UnresolvedAncestorPad = ExitedParent;
3873 break;
3874 }
3875 ExitedPad = ExitedParent;
3876 } while (!isa<ConstantTokenNone>(ExitedPad));
3877 } else {
3878 // Unwinding to caller exits all pads.
3879 UnwindPad = ConstantTokenNone::get(FPI.getContext());
3880 ExitsFPI = true;
3881 UnresolvedAncestorPad = &FPI;
3882 }
3883
3884 if (ExitsFPI) {
3885 // This unwind edge exits FPI. Make sure it agrees with other
3886 // such edges.
3887 if (FirstUser) {
3888 Assert(UnwindPad == FirstUnwindPad, "Unwind edges out of a funclet "do { if (!(UnwindPad == FirstUnwindPad)) { CheckFailed("Unwind edges out of a funclet "
"pad must have the same unwind " "dest", &FPI, U, FirstUser
); return; } } while (false)
3889 "pad must have the same unwind "do { if (!(UnwindPad == FirstUnwindPad)) { CheckFailed("Unwind edges out of a funclet "
"pad must have the same unwind " "dest", &FPI, U, FirstUser
); return; } } while (false)
3890 "dest",do { if (!(UnwindPad == FirstUnwindPad)) { CheckFailed("Unwind edges out of a funclet "
"pad must have the same unwind " "dest", &FPI, U, FirstUser
); return; } } while (false)
3891 &FPI, U, FirstUser)do { if (!(UnwindPad == FirstUnwindPad)) { CheckFailed("Unwind edges out of a funclet "
"pad must have the same unwind " "dest", &FPI, U, FirstUser
); return; } } while (false)
;
3892 } else {
3893 FirstUser = U;
3894 FirstUnwindPad = UnwindPad;
3895 // Record cleanup sibling unwinds for verifySiblingFuncletUnwinds
3896 if (isa<CleanupPadInst>(&FPI) && !isa<ConstantTokenNone>(UnwindPad) &&
3897 getParentPad(UnwindPad) == getParentPad(&FPI))
3898 SiblingFuncletInfo[&FPI] = cast<Instruction>(U);
3899 }
3900 }
3901 // Make sure we visit all uses of FPI, but for nested pads stop as
3902 // soon as we know where they unwind to.
3903 if (CurrentPad != &FPI)
3904 break;
3905 }
3906 if (UnresolvedAncestorPad) {
3907 if (CurrentPad == UnresolvedAncestorPad) {
3908 // When CurrentPad is FPI itself, we don't mark it as resolved even if
3909 // we've found an unwind edge that exits it, because we need to verify
3910 // all direct uses of FPI.
3911 assert(CurrentPad == &FPI)((CurrentPad == &FPI) ? static_cast<void> (0) : __assert_fail
("CurrentPad == &FPI", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 3911, __PRETTY_FUNCTION__))
;
3912 continue;
3913 }
3914 // Pop off the worklist any nested pads that we've found an unwind
3915 // destination for. The pads on the worklist are the uncles,
3916 // great-uncles, etc. of CurrentPad. We've found an unwind destination
3917 // for all ancestors of CurrentPad up to but not including
3918 // UnresolvedAncestorPad.
3919 Value *ResolvedPad = CurrentPad;
3920 while (!Worklist.empty()) {
3921 Value *UnclePad = Worklist.back();
3922 Value *AncestorPad = getParentPad(UnclePad);
3923 // Walk ResolvedPad up the ancestor list until we either find the
3924 // uncle's parent or the last resolved ancestor.
3925 while (ResolvedPad != AncestorPad) {
3926 Value *ResolvedParent = getParentPad(ResolvedPad);
3927 if (ResolvedParent == UnresolvedAncestorPad) {
3928 break;
3929 }
3930 ResolvedPad = ResolvedParent;
3931 }
3932 // If the resolved ancestor search didn't find the uncle's parent,
3933 // then the uncle is not yet resolved.
3934 if (ResolvedPad != AncestorPad)
3935 break;
3936 // This uncle is resolved, so pop it from the worklist.
3937 Worklist.pop_back();
3938 }
3939 }
3940 }
3941
3942 if (FirstUnwindPad) {
3943 if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(FPI.getParentPad())) {
3944 BasicBlock *SwitchUnwindDest = CatchSwitch->getUnwindDest();
3945 Value *SwitchUnwindPad;
3946 if (SwitchUnwindDest)
3947 SwitchUnwindPad = SwitchUnwindDest->getFirstNonPHI();
3948 else
3949 SwitchUnwindPad = ConstantTokenNone::get(FPI.getContext());
3950 Assert(SwitchUnwindPad == FirstUnwindPad,do { if (!(SwitchUnwindPad == FirstUnwindPad)) { CheckFailed(
"Unwind edges out of a catch must have the same unwind dest as "
"the parent catchswitch", &FPI, FirstUser, CatchSwitch);
return; } } while (false)
3951 "Unwind edges out of a catch must have the same unwind dest as "do { if (!(SwitchUnwindPad == FirstUnwindPad)) { CheckFailed(
"Unwind edges out of a catch must have the same unwind dest as "
"the parent catchswitch", &FPI, FirstUser, CatchSwitch);
return; } } while (false)
3952 "the parent catchswitch",do { if (!(SwitchUnwindPad == FirstUnwindPad)) { CheckFailed(
"Unwind edges out of a catch must have the same unwind dest as "
"the parent catchswitch", &FPI, FirstUser, CatchSwitch);
return; } } while (false)
3953 &FPI, FirstUser, CatchSwitch)do { if (!(SwitchUnwindPad == FirstUnwindPad)) { CheckFailed(
"Unwind edges out of a catch must have the same unwind dest as "
"the parent catchswitch", &FPI, FirstUser, CatchSwitch);
return; } } while (false)
;
3954 }
3955 }
3956
3957 visitInstruction(FPI);
3958}
3959
3960void Verifier::visitCatchSwitchInst(CatchSwitchInst &CatchSwitch) {
3961 BasicBlock *BB = CatchSwitch.getParent();
3962
3963 Function *F = BB->getParent();
3964 Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchSwitchInst needs to be in a function with a personality."
, &CatchSwitch); return; } } while (false)
3965 "CatchSwitchInst needs to be in a function with a personality.",do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchSwitchInst needs to be in a function with a personality."
, &CatchSwitch); return; } } while (false)
3966 &CatchSwitch)do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchSwitchInst needs to be in a function with a personality."
, &CatchSwitch); return; } } while (false)
;
3967
3968 // The catchswitch instruction must be the first non-PHI instruction in the
3969 // block.
3970 Assert(BB->getFirstNonPHI() == &CatchSwitch,do { if (!(BB->getFirstNonPHI() == &CatchSwitch)) { CheckFailed
("CatchSwitchInst not the first non-PHI instruction in the block."
, &CatchSwitch); return; } } while (false)
3971 "CatchSwitchInst not the first non-PHI instruction in the block.",do { if (!(BB->getFirstNonPHI() == &CatchSwitch)) { CheckFailed
("CatchSwitchInst not the first non-PHI instruction in the block."
, &CatchSwitch); return; } } while (false)
3972 &CatchSwitch)do { if (!(BB->getFirstNonPHI() == &CatchSwitch)) { CheckFailed
("CatchSwitchInst not the first non-PHI instruction in the block."
, &CatchSwitch); return; } } while (false)
;
3973
3974 auto *ParentPad = CatchSwitch.getParentPad();
3975 Assert(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),do { if (!(isa<ConstantTokenNone>(ParentPad) || isa<
FuncletPadInst>(ParentPad))) { CheckFailed("CatchSwitchInst has an invalid parent."
, ParentPad); return; } } while (false)
3976 "CatchSwitchInst has an invalid parent.", ParentPad)do { if (!(isa<ConstantTokenNone>(ParentPad) || isa<
FuncletPadInst>(ParentPad))) { CheckFailed("CatchSwitchInst has an invalid parent."
, ParentPad); return; } } while (false)
;
3977
3978 if (BasicBlock *UnwindDest = CatchSwitch.getUnwindDest()) {
3979 Instruction *I = UnwindDest->getFirstNonPHI();
3980 Assert(I->isEHPad() && !isa<LandingPadInst>(I),do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CatchSwitchInst must unwind to an EH block which is not a "
"landingpad.", &CatchSwitch); return; } } while (false)
3981 "CatchSwitchInst must unwind to an EH block which is not a "do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CatchSwitchInst must unwind to an EH block which is not a "
"landingpad.", &CatchSwitch); return; } } while (false)
3982 "landingpad.",do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CatchSwitchInst must unwind to an EH block which is not a "
"landingpad.", &CatchSwitch); return; } } while (false)
3983 &CatchSwitch)do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CatchSwitchInst must unwind to an EH block which is not a "
"landingpad.", &CatchSwitch); return; } } while (false)
;
3984
3985 // Record catchswitch sibling unwinds for verifySiblingFuncletUnwinds
3986 if (getParentPad(I) == ParentPad)
3987 SiblingFuncletInfo[&CatchSwitch] = &CatchSwitch;
3988 }
3989
3990 Assert(CatchSwitch.getNumHandlers() != 0,do { if (!(CatchSwitch.getNumHandlers() != 0)) { CheckFailed(
"CatchSwitchInst cannot have empty handler list", &CatchSwitch
); return; } } while (false)
3991 "CatchSwitchInst cannot have empty handler list", &CatchSwitch)do { if (!(CatchSwitch.getNumHandlers() != 0)) { CheckFailed(
"CatchSwitchInst cannot have empty handler list", &CatchSwitch
); return; } } while (false)
;
3992
3993 for (BasicBlock *Handler : CatchSwitch.handlers()) {
3994 Assert(isa<CatchPadInst>(Handler->getFirstNonPHI()),do { if (!(isa<CatchPadInst>(Handler->getFirstNonPHI
()))) { CheckFailed("CatchSwitchInst handlers must be catchpads"
, &CatchSwitch, Handler); return; } } while (false)
3995 "CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler)do { if (!(isa<CatchPadInst>(Handler->getFirstNonPHI
()))) { CheckFailed("CatchSwitchInst handlers must be catchpads"
, &CatchSwitch, Handler); return; } } while (false)
;
3996 }
3997
3998 visitEHPadPredecessors(CatchSwitch);
3999 visitTerminator(CatchSwitch);
4000}
4001
4002void Verifier::visitCleanupReturnInst(CleanupReturnInst &CRI) {
4003 Assert(isa<CleanupPadInst>(CRI.getOperand(0)),do { if (!(isa<CleanupPadInst>(CRI.getOperand(0)))) { CheckFailed
("CleanupReturnInst needs to be provided a CleanupPad", &
CRI, CRI.getOperand(0)); return; } } while (false)
4004 "CleanupReturnInst needs to be provided a CleanupPad", &CRI,do { if (!(isa<CleanupPadInst>(CRI.getOperand(0)))) { CheckFailed
("CleanupReturnInst needs to be provided a CleanupPad", &
CRI, CRI.getOperand(0)); return; } } while (false)
4005 CRI.getOperand(0))do { if (!(isa<CleanupPadInst>(CRI.getOperand(0)))) { CheckFailed
("CleanupReturnInst needs to be provided a CleanupPad", &
CRI, CRI.getOperand(0)); return; } } while (false)
;
4006
4007 if (BasicBlock *UnwindDest = CRI.getUnwindDest()) {
4008 Instruction *I = UnwindDest->getFirstNonPHI();
4009 Assert(I->isEHPad() && !isa<LandingPadInst>(I),do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CleanupReturnInst must unwind to an EH block which is not a "
"landingpad.", &CRI); return; } } while (false)
4010 "CleanupReturnInst must unwind to an EH block which is not a "do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CleanupReturnInst must unwind to an EH block which is not a "
"landingpad.", &CRI); return; } } while (false)
4011 "landingpad.",do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CleanupReturnInst must unwind to an EH block which is not a "
"landingpad.", &CRI); return; } } while (false)
4012 &CRI)do { if (!(I->isEHPad() && !isa<LandingPadInst>
(I))) { CheckFailed("CleanupReturnInst must unwind to an EH block which is not a "
"landingpad.", &CRI); return; } } while (false)
;
4013 }
4014
4015 visitTerminator(CRI);
4016}
4017
4018void Verifier::verifyDominatesUse(Instruction &I, unsigned i) {
4019 Instruction *Op = cast<Instruction>(I.getOperand(i));
4020 // If the we have an invalid invoke, don't try to compute the dominance.
4021 // We already reject it in the invoke specific checks and the dominance
4022 // computation doesn't handle multiple edges.
4023 if (InvokeInst *II = dyn_cast<InvokeInst>(Op)) {
4024 if (II->getNormalDest() == II->getUnwindDest())
4025 return;
4026 }
4027
4028 // Quick check whether the def has already been encountered in the same block.
4029 // PHI nodes are not checked to prevent accepting preceding PHIs, because PHI
4030 // uses are defined to happen on the incoming edge, not at the instruction.
4031 //
4032 // FIXME: If this operand is a MetadataAsValue (wrapping a LocalAsMetadata)
4033 // wrapping an SSA value, assert that we've already encountered it. See
4034 // related FIXME in Mapper::mapLocalAsMetadata in ValueMapper.cpp.
4035 if (!isa<PHINode>(I) && InstsInThisBlock.count(Op))
4036 return;
4037
4038 const Use &U = I.getOperandUse(i);
4039 Assert(DT.dominates(Op, U),do { if (!(DT.dominates(Op, U))) { CheckFailed("Instruction does not dominate all uses!"
, Op, &I); return; } } while (false)
4040 "Instruction does not dominate all uses!", Op, &I)do { if (!(DT.dominates(Op, U))) { CheckFailed("Instruction does not dominate all uses!"
, Op, &I); return; } } while (false)
;
4041}
4042
4043void Verifier::visitDereferenceableMetadata(Instruction& I, MDNode* MD) {
4044 Assert(I.getType()->isPointerTy(), "dereferenceable, dereferenceable_or_null "do { if (!(I.getType()->isPointerTy())) { CheckFailed("dereferenceable, dereferenceable_or_null "
"apply only to pointer types", &I); return; } } while (false
)
4045 "apply only to pointer types", &I)do { if (!(I.getType()->isPointerTy())) { CheckFailed("dereferenceable, dereferenceable_or_null "
"apply only to pointer types", &I); return; } } while (false
)
;
4046 Assert((isa<LoadInst>(I) || isa<IntToPtrInst>(I)),do { if (!((isa<LoadInst>(I) || isa<IntToPtrInst>
(I)))) { CheckFailed("dereferenceable, dereferenceable_or_null apply only to load"
" and inttoptr instructions, use attributes for calls or invokes"
, &I); return; } } while (false)
4047 "dereferenceable, dereferenceable_or_null apply only to load"do { if (!((isa<LoadInst>(I) || isa<IntToPtrInst>
(I)))) { CheckFailed("dereferenceable, dereferenceable_or_null apply only to load"
" and inttoptr instructions, use attributes for calls or invokes"
, &I); return; } } while (false)
4048 " and inttoptr instructions, use attributes for calls or invokes", &I)do { if (!((isa<LoadInst>(I) || isa<IntToPtrInst>
(I)))) { CheckFailed("dereferenceable, dereferenceable_or_null apply only to load"
" and inttoptr instructions, use attributes for calls or invokes"
, &I); return; } } while (false)
;
4049 Assert(MD->getNumOperands() == 1, "dereferenceable, dereferenceable_or_null "do { if (!(MD->getNumOperands() == 1)) { CheckFailed("dereferenceable, dereferenceable_or_null "
"take one operand!", &I); return; } } while (false)
4050 "take one operand!", &I)do { if (!(MD->getNumOperands() == 1)) { CheckFailed("dereferenceable, dereferenceable_or_null "
"take one operand!", &I); return; } } while (false)
;
4051 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(MD->getOperand(0));
4052 Assert(CI && CI->getType()->isIntegerTy(64), "dereferenceable, "do { if (!(CI && CI->getType()->isIntegerTy(64)
)) { CheckFailed("dereferenceable, " "dereferenceable_or_null metadata value must be an i64!"
, &I); return; } } while (false)
4053 "dereferenceable_or_null metadata value must be an i64!", &I)do { if (!(CI && CI->getType()->isIntegerTy(64)
)) { CheckFailed("dereferenceable, " "dereferenceable_or_null metadata value must be an i64!"
, &I); return; } } while (false)
;
4054}
4055
4056void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
4057 Assert(MD->getNumOperands() >= 2,do { if (!(MD->getNumOperands() >= 2)) { CheckFailed("!prof annotations should have no less than 2 operands"
, MD); return; } } while (false)
4058 "!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)
;
4059
4060 // Check first operand.
4061 Assert(MD->getOperand(0) != nullptr, "first operand should not be null", MD)do { if (!(MD->getOperand(0) != nullptr)) { CheckFailed("first operand should not be null"
, MD); return; } } while (false)
;
4062 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)
4063 "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)
;
4064 MDString *MDS = cast<MDString>(MD->getOperand(0));
4065 StringRef ProfName = MDS->getString();
4066
4067 // Check consistency of !prof branch_weights metadata.
4068 if (ProfName.equals("branch_weights")) {
4069 unsigned ExpectedNumOperands = 0;
4070 if (BranchInst *BI = dyn_cast<BranchInst>(&I))
4071 ExpectedNumOperands = BI->getNumSuccessors();
4072 else if (SwitchInst *SI = dyn_cast<SwitchInst>(&I))
4073 ExpectedNumOperands = SI->getNumSuccessors();
4074 else if (isa<CallInst>(&I) || isa<InvokeInst>(&I))
4075 ExpectedNumOperands = 1;
4076 else if (IndirectBrInst *IBI = dyn_cast<IndirectBrInst>(&I))
4077 ExpectedNumOperands = IBI->getNumDestinations();
4078 else if (isa<SelectInst>(&I))
4079 ExpectedNumOperands = 2;
4080 else
4081 CheckFailed("!prof branch_weights are not allowed for this instruction",
4082 MD);
4083
4084 Assert(MD->getNumOperands() == 1 + ExpectedNumOperands,do { if (!(MD->getNumOperands() == 1 + ExpectedNumOperands
)) { CheckFailed("Wrong number of operands", MD); return; } }
while (false)
4085 "Wrong number of operands", MD)do { if (!(MD->getNumOperands() == 1 + ExpectedNumOperands
)) { CheckFailed("Wrong number of operands", MD); return; } }
while (false)
;
4086 for (unsigned i = 1; i < MD->getNumOperands(); ++i) {
4087 auto &MDO = MD->getOperand(i);
4088 Assert(MDO, "second operand should not be null", MD)do { if (!(MDO)) { CheckFailed("second operand should not be null"
, MD); return; } } while (false)
;
4089 Assert(mdconst::dyn_extract<ConstantInt>(MDO),do { if (!(mdconst::dyn_extract<ConstantInt>(MDO))) { CheckFailed
("!prof brunch_weights operand is not a const int"); return; }
} while (false)
4090 "!prof brunch_weights operand is not a const int")do { if (!(mdconst::dyn_extract<ConstantInt>(MDO))) { CheckFailed
("!prof brunch_weights operand is not a const int"); return; }
} while (false)
;
4091 }
4092 }
4093}
4094
4095/// verifyInstruction - Verify that an instruction is well formed.
4096///
4097void Verifier::visitInstruction(Instruction &I) {
4098 BasicBlock *BB = I.getParent();
4099 Assert(BB, "Instruction not embedded in basic block!", &I)do { if (!(BB)) { CheckFailed("Instruction not embedded in basic block!"
, &I); return; } } while (false)
;
4100
4101 if (!isa<PHINode>(I)) { // Check that non-phi nodes are not self referential
4102 for (User *U : I.users()) {
4103 Assert(U != (User *)&I || !DT.isReachableFromEntry(BB),do { if (!(U != (User *)&I || !DT.isReachableFromEntry(BB
))) { CheckFailed("Only PHI nodes may reference their own value!"
, &I); return; } } while (false)
4104 "Only PHI nodes may reference their own value!", &I)do { if (!(U != (User *)&I || !DT.isReachableFromEntry(BB
))) { CheckFailed("Only PHI nodes may reference their own value!"
, &I); return; } } while (false)
;
4105 }
4106 }
4107
4108 // Check that void typed values don't have names
4109 Assert(!I.getType()->isVoidTy() || !I.hasName(),do { if (!(!I.getType()->isVoidTy() || !I.hasName())) { CheckFailed
("Instruction has a name, but provides a void value!", &I
); return; } } while (false)
4110 "Instruction has a name, but provides a void value!", &I)do { if (!(!I.getType()->isVoidTy() || !I.hasName())) { CheckFailed
("Instruction has a name, but provides a void value!", &I
); return; } } while (false)
;
4111
4112 // Check that the return value of the instruction is either void or a legal
4113 // value type.
4114 Assert(I.getType()->isVoidTy() || I.getType()->isFirstClassType(),do { if (!(I.getType()->isVoidTy() || I.getType()->isFirstClassType
())) { CheckFailed("Instruction returns a non-scalar type!", &
I); return; } } while (false)
4115 "Instruction returns a non-scalar type!", &I)do { if (!(I.getType()->isVoidTy() || I.getType()->isFirstClassType
())) { CheckFailed("Instruction returns a non-scalar type!", &
I); return; } } while (false)
;
4116
4117 // Check that the instruction doesn't produce metadata. Calls are already
4118 // checked against the callee type.
4119 Assert(!I.getType()->isMetadataTy() || isa<CallInst>(I) || isa<InvokeInst>(I),do { if (!(!I.getType()->isMetadataTy() || isa<CallInst
>(I) || isa<InvokeInst>(I))) { CheckFailed("Invalid use of metadata!"
, &I); return; } } while (false)
4120 "Invalid use of metadata!", &I)do { if (!(!I.getType()->isMetadataTy() || isa<CallInst
>(I) || isa<InvokeInst>(I))) { CheckFailed("Invalid use of metadata!"
, &I); return; } } while (false)
;
4121
4122 // Check that all uses of the instruction, if they are instructions
4123 // themselves, actually have parent basic blocks. If the use is not an
4124 // instruction, it is an error!
4125 for (Use &U : I.uses()) {
4126 if (Instruction *Used = dyn_cast<Instruction>(U.getUser()))
4127 Assert(Used->getParent() != nullptr,do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing"
" instruction not embedded in a basic block!", &I, Used)
; return; } } while (false)
4128 "Instruction referencing"do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing"
" instruction not embedded in a basic block!", &I, Used)
; return; } } while (false)
4129 " instruction not embedded in a basic block!",do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing"
" instruction not embedded in a basic block!", &I, Used)
; return; } } while (false)
4130 &I, Used)do { if (!(Used->getParent() != nullptr)) { CheckFailed("Instruction referencing"
" instruction not embedded in a basic block!", &I, Used)
; return; } } while (false)
;
4131 else {
4132 CheckFailed("Use of instruction is not an instruction!", U);
4133 return;
4134 }
4135 }
4136
4137 // Get a pointer to the call base of the instruction if it is some form of
4138 // call.
4139 const CallBase *CBI = dyn_cast<CallBase>(&I);
4140
4141 for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) {
4142 Assert(I.getOperand(i) != nullptr, "Instruction has null operand!", &I)do { if (!(I.getOperand(i) != nullptr)) { CheckFailed("Instruction has null operand!"
, &I); return; } } while (false)
;
4143
4144 // Check to make sure that only first-class-values are operands to
4145 // instructions.
4146 if (!I.getOperand(i)->getType()->isFirstClassType()) {
4147 Assert(false, "Instruction operands must be first-class values!", &I)do { if (!(false)) { CheckFailed("Instruction operands must be first-class values!"
, &I); return; } } while (false)
;
4148 }
4149
4150 if (Function *F = dyn_cast<Function>(I.getOperand(i))) {
4151 // Check to make sure that the "address of" an intrinsic function is never
4152 // taken.
4153 Assert(!F->isIntrinsic() ||do { if (!(!F->isIntrinsic() || (CBI && &CBI->
getCalledOperandUse() == &I.getOperandUse(i)))) { CheckFailed
("Cannot take the address of an intrinsic!", &I); return;
} } while (false)
4154 (CBI && &CBI->getCalledOperandUse() == &I.getOperandUse(i)),do { if (!(!F->isIntrinsic() || (CBI && &CBI->
getCalledOperandUse() == &I.getOperandUse(i)))) { CheckFailed
("Cannot take the address of an intrinsic!", &I); return;
} } while (false)
4155 "Cannot take the address of an intrinsic!", &I)do { if (!(!F->isIntrinsic() || (CBI && &CBI->
getCalledOperandUse() == &I.getOperandUse(i)))) { CheckFailed
("Cannot take the address of an intrinsic!", &I); return;
} } while (false)
;
4156 Assert(do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
|| F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
4157 !F->isIntrinsic() || isa<CallInst>(I) ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
|| F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
4158 F->getIntrinsicID() == Intrinsic::donothing ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
|| F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
4159 F->getIntrinsicID() == Intrinsic::coro_resume ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
|| F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
4160 F->getIntrinsicID() == Intrinsic::coro_destroy ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
|| F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
4161 F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
|| F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
4162 F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
|| F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
4163 F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint ||do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
|| F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
4164 F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch,do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
|| F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
4165 "Cannot invoke an intrinsic other than donothing, patchpoint, "do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
|| F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
4166 "statepoint, coro_resume or coro_destroy",do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
|| F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
4167 &I)do { if (!(!F->isIntrinsic() || isa<CallInst>(I) || F
->getIntrinsicID() == Intrinsic::donothing || F->getIntrinsicID
() == Intrinsic::coro_resume || F->getIntrinsicID() == Intrinsic
::coro_destroy || F->getIntrinsicID() == Intrinsic::experimental_patchpoint_void
|| F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64
|| F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint
|| F->getIntrinsicID() == Intrinsic::wasm_rethrow_in_catch
)) { CheckFailed("Cannot invoke an intrinsic other than donothing, patchpoint, "
"statepoint, coro_resume or coro_destroy", &I); return; }
} while (false)
;
4168 Assert(F->getParent() == &M, "Referencing function in another module!",do { if (!(F->getParent() == &M)) { CheckFailed("Referencing function in another module!"
, &I, &M, F, F->getParent()); return; } } while (false
)
4169 &I, &M, F, F->getParent())do { if (!(F->getParent() == &M)) { CheckFailed("Referencing function in another module!"
, &I, &M, F, F->getParent()); return; } } while (false
)
;
4170 } else if (BasicBlock *OpBB = dyn_cast<BasicBlock>(I.getOperand(i))) {
4171 Assert(OpBB->getParent() == BB->getParent(),do { if (!(OpBB->getParent() == BB->getParent())) { CheckFailed
("Referring to a basic block in another function!", &I); return
; } } while (false)
4172 "Referring to a basic block in another function!", &I)do { if (!(OpBB->getParent() == BB->getParent())) { CheckFailed
("Referring to a basic block in another function!", &I); return
; } } while (false)
;
4173 } else if (Argument *OpArg = dyn_cast<Argument>(I.getOperand(i))) {
4174 Assert(OpArg->getParent() == BB->getParent(),do { if (!(OpArg->getParent() == BB->getParent())) { CheckFailed
("Referring to an argument in another function!", &I); return
; } } while (false)
4175 "Referring to an argument in another function!", &I)do { if (!(OpArg->getParent() == BB->getParent())) { CheckFailed
("Referring to an argument in another function!", &I); return
; } } while (false)
;
4176 } else if (GlobalValue *GV = dyn_cast<GlobalValue>(I.getOperand(i))) {
4177 Assert(GV->getParent() == &M, "Referencing global in another module!", &I,do { if (!(GV->getParent() == &M)) { CheckFailed("Referencing global in another module!"
, &I, &M, GV, GV->getParent()); return; } } while (
false)
4178 &M, GV, GV->getParent())do { if (!(GV->getParent() == &M)) { CheckFailed("Referencing global in another module!"
, &I, &M, GV, GV->getParent()); return; } } while (
false)
;
4179 } else if (isa<Instruction>(I.getOperand(i))) {
4180 verifyDominatesUse(I, i);
4181 } else if (isa<InlineAsm>(I.getOperand(i))) {
4182 Assert(CBI && &CBI->getCalledOperandUse() == &I.getOperandUse(i),do { if (!(CBI && &CBI->getCalledOperandUse() ==
&I.getOperandUse(i))) { CheckFailed("Cannot take the address of an inline asm!"
, &I); return; } } while (false)
4183 "Cannot take the address of an inline asm!", &I)do { if (!(CBI && &CBI->getCalledOperandUse() ==
&I.getOperandUse(i))) { CheckFailed("Cannot take the address of an inline asm!"
, &I); return; } } while (false)
;
4184 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(I.getOperand(i))) {
4185 if (CE->getType()->isPtrOrPtrVectorTy() ||
4186 !DL.getNonIntegralAddressSpaces().empty()) {
4187 // If we have a ConstantExpr pointer, we need to see if it came from an
4188 // illegal bitcast. If the datalayout string specifies non-integral
4189 // address spaces then we also need to check for illegal ptrtoint and
4190 // inttoptr expressions.
4191 visitConstantExprsRecursively(CE);
4192 }
4193 }
4194 }
4195
4196 if (MDNode *MD = I.getMetadata(LLVMContext::MD_fpmath)) {
4197 Assert(I.getType()->isFPOrFPVectorTy(),do { if (!(I.getType()->isFPOrFPVectorTy())) { CheckFailed
("fpmath requires a floating point result!", &I); return;
} } while (false)
4198 "fpmath requires a floating point result!", &I)do { if (!(I.getType()->isFPOrFPVectorTy())) { CheckFailed
("fpmath requires a floating point result!", &I); return;
} } while (false)
;
4199 Assert(MD->getNumOperands() == 1, "fpmath takes one operand!", &I)do { if (!(MD->getNumOperands() == 1)) { CheckFailed("fpmath takes one operand!"
, &I); return; } } while (false)
;
4200 if (ConstantFP *CFP0 =
4201 mdconst::dyn_extract_or_null<ConstantFP>(MD->getOperand(0))) {
4202 const APFloat &Accuracy = CFP0->getValueAPF();
4203 Assert(&Accuracy.getSemantics() == &APFloat::IEEEsingle(),do { if (!(&Accuracy.getSemantics() == &APFloat::IEEEsingle
())) { CheckFailed("fpmath accuracy must have float type", &
I); return; } } while (false)
4204 "fpmath accuracy must have float type", &I)do { if (!(&Accuracy.getSemantics() == &APFloat::IEEEsingle
())) { CheckFailed("fpmath accuracy must have float type", &
I); return; } } while (false)
;
4205 Assert(Accuracy.isFiniteNonZero() && !Accuracy.isNegative(),do { if (!(Accuracy.isFiniteNonZero() && !Accuracy.isNegative
())) { CheckFailed("fpmath accuracy not a positive number!", &
I); return; } } while (false)
4206 "fpmath accuracy not a positive number!", &I)do { if (!(Accuracy.isFiniteNonZero() && !Accuracy.isNegative
())) { CheckFailed("fpmath accuracy not a positive number!", &
I); return; } } while (false)
;
4207 } else {
4208 Assert(false, "invalid fpmath accuracy!", &I)do { if (!(false)) { CheckFailed("invalid fpmath accuracy!", &
I); return; } } while (false)
;
4209 }
4210 }
4211
4212 if (MDNode *Range = I.getMetadata(LLVMContext::MD_range)) {
4213 Assert(isa<LoadInst>(I) || isa<CallInst>(I) || isa<InvokeInst>(I),do { if (!(isa<LoadInst>(I) || isa<CallInst>(I) ||
isa<InvokeInst>(I))) { CheckFailed("Ranges are only for loads, calls and invokes!"
, &I); return; } } while (false)
4214 "Ranges are only for loads, calls and invokes!", &I)do { if (!(isa<LoadInst>(I) || isa<CallInst>(I) ||
isa<InvokeInst>(I))) { CheckFailed("Ranges are only for loads, calls and invokes!"
, &I); return; } } while (false)
;
4215 visitRangeMetadata(I, Range, I.getType());
4216 }
4217
4218 if (I.getMetadata(LLVMContext::MD_nonnull)) {
4219 Assert(I.getType()->isPointerTy(), "nonnull applies only to pointer types",do { if (!(I.getType()->isPointerTy())) { CheckFailed("nonnull applies only to pointer types"
, &I); return; } } while (false)
4220 &I)do { if (!(I.getType()->isPointerTy())) { CheckFailed("nonnull applies only to pointer types"
, &I); return; } } while (false)
;
4221 Assert(isa<LoadInst>(I),do { if (!(isa<LoadInst>(I))) { CheckFailed("nonnull applies only to load instructions, use attributes"
" for calls or invokes", &I); return; } } while (false)
4222 "nonnull applies only to load instructions, use attributes"do { if (!(isa<LoadInst>(I))) { CheckFailed("nonnull applies only to load instructions, use attributes"
" for calls or invokes", &I); return; } } while (false)
4223 " for calls or invokes",do { if (!(isa<LoadInst>(I))) { CheckFailed("nonnull applies only to load instructions, use attributes"
" for calls or invokes", &I); return; } } while (false)
4224 &I)do { if (!(isa<LoadInst>(I))) { CheckFailed("nonnull applies only to load instructions, use attributes"
" for calls or invokes", &I); return; } } while (false)
;
4225 }
4226
4227 if (MDNode *MD = I.getMetadata(LLVMContext::MD_dereferenceable))
4228 visitDereferenceableMetadata(I, MD);
4229
4230 if (MDNode *MD = I.getMetadata(LLVMContext::MD_dereferenceable_or_null))
4231 visitDereferenceableMetadata(I, MD);
4232
4233 if (MDNode *TBAA = I.getMetadata(LLVMContext::MD_tbaa))
4234 TBAAVerifyHelper.visitTBAAMetadata(I, TBAA);
4235
4236 if (MDNode *AlignMD = I.getMetadata(LLVMContext::MD_align)) {
4237 Assert(I.getType()->isPointerTy(), "align applies only to pointer types",do { if (!(I.getType()->isPointerTy())) { CheckFailed("align applies only to pointer types"
, &I); return; } } while (false)
4238 &I)do { if (!(I.getType()->isPointerTy())) { CheckFailed("align applies only to pointer types"
, &I); return; } } while (false)
;
4239 Assert(isa<LoadInst>(I), "align applies only to load instructions, "do { if (!(isa<LoadInst>(I))) { CheckFailed("align applies only to load instructions, "
"use attributes for calls or invokes", &I); return; } } while
(false)
4240 "use attributes for calls or invokes", &I)do { if (!(isa<LoadInst>(I))) { CheckFailed("align applies only to load instructions, "
"use attributes for calls or invokes", &I); return; } } while
(false)
;
4241 Assert(AlignMD->getNumOperands() == 1, "align takes one operand!", &I)do { if (!(AlignMD->getNumOperands() == 1)) { CheckFailed(
"align takes one operand!", &I); return; } } while (false
)
;
4242 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(AlignMD->getOperand(0));
4243 Assert(CI && CI->getType()->isIntegerTy(64),do { if (!(CI && CI->getType()->isIntegerTy(64)
)) { CheckFailed("align metadata value must be an i64!", &
I); return; } } while (false)
4244 "align metadata value must be an i64!", &I)do { if (!(CI && CI->getType()->isIntegerTy(64)
)) { CheckFailed("align metadata value must be an i64!", &
I); return; } } while (false)
;
4245 uint64_t Align = CI->getZExtValue();
4246 Assert(isPowerOf2_64(Align),do { if (!(isPowerOf2_64(Align))) { CheckFailed("align metadata value must be a power of 2!"
, &I); return; } } while (false)
4247 "align metadata value must be a power of 2!", &I)do { if (!(isPowerOf2_64(Align))) { CheckFailed("align metadata value must be a power of 2!"
, &I); return; } } while (false)
;
4248 Assert(Align <= Value::MaximumAlignment,do { if (!(Align <= Value::MaximumAlignment)) { CheckFailed
("alignment is larger that implementation defined limit", &
I); return; } } while (false)
4249 "alignment is larger that implementation defined limit", &I)do { if (!(Align <= Value::MaximumAlignment)) { CheckFailed
("alignment is larger that implementation defined limit", &
I); return; } } while (false)
;
4250 }
4251
4252 if (MDNode *MD = I.getMetadata(LLVMContext::MD_prof))
4253 visitProfMetadata(I, MD);
4254
4255 if (MDNode *N = I.getDebugLoc().getAsMDNode()) {
4256 AssertDI(isa<DILocation>(N), "invalid !dbg metadata attachment", &I, N)do { if (!(isa<DILocation>(N))) { DebugInfoCheckFailed(
"invalid !dbg metadata attachment", &I, N); return; } } while
(false)
;
4257 visitMDNode(*N);
4258 }
4259
4260 if (auto *DII = dyn_cast<DbgVariableIntrinsic>(&I)) {
4261 verifyFragmentExpression(*DII);
4262 verifyNotEntryValue(*DII);
4263 }
4264
4265 InstsInThisBlock.insert(&I);
4266}
4267
4268/// Allow intrinsics to be verified in different ways.
4269void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
4270 Function *IF = Call.getCalledFunction();
4271 Assert(IF->isDeclaration(), "Intrinsic functions should never be defined!",do { if (!(IF->isDeclaration())) { CheckFailed("Intrinsic functions should never be defined!"
, IF); return; } } while (false)
4272 IF)do { if (!(IF->isDeclaration())) { CheckFailed("Intrinsic functions should never be defined!"
, IF); return; } } while (false)
;
4273
4274 // Verify that the intrinsic prototype lines up with what the .td files
4275 // describe.
4276 FunctionType *IFTy = IF->getFunctionType();
4277 bool IsVarArg = IFTy->isVarArg();
4278
4279 SmallVector<Intrinsic::IITDescriptor, 8> Table;
4280 getIntrinsicInfoTableEntries(ID, Table);
4281 ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
4282
4283 // Walk the descriptors to extract overloaded types.
4284 SmallVector<Type *, 4> ArgTys;
4285 Intrinsic::MatchIntrinsicTypesResult Res =
4286 Intrinsic::matchIntrinsicSignature(IFTy, TableRef, ArgTys);
4287 Assert(Res != Intrinsic::MatchIntrinsicTypes_NoMatchRet,do { if (!(Res != Intrinsic::MatchIntrinsicTypes_NoMatchRet))
{ CheckFailed("Intrinsic has incorrect return type!", IF); return
; } } while (false)
4288 "Intrinsic has incorrect return type!", IF)do { if (!(Res != Intrinsic::MatchIntrinsicTypes_NoMatchRet))
{ CheckFailed("Intrinsic has incorrect return type!", IF); return
; } } while (false)
;
4289 Assert(Res != Intrinsic::MatchIntrinsicTypes_NoMatchArg,do { if (!(Res != Intrinsic::MatchIntrinsicTypes_NoMatchArg))
{ CheckFailed("Intrinsic has incorrect argument type!", IF);
return; } } while (false)
4290 "Intrinsic has incorrect argument type!", IF)do { if (!(Res != Intrinsic::MatchIntrinsicTypes_NoMatchArg))
{ CheckFailed("Intrinsic has incorrect argument type!", IF);
return; } } while (false)
;
4291
4292 // Verify if the intrinsic call matches the vararg property.
4293 if (IsVarArg)
4294 Assert(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef),do { if (!(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef
))) { CheckFailed("Intrinsic was not defined with variable arguments!"
, IF); return; } } while (false)
4295 "Intrinsic was not defined with variable arguments!", IF)do { if (!(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef
))) { CheckFailed("Intrinsic was not defined with variable arguments!"
, IF); return; } } while (false)
;
4296 else
4297 Assert(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef),do { if (!(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef
))) { CheckFailed("Callsite was not defined with variable arguments!"
, IF); return; } } while (false)
4298 "Callsite was not defined with variable arguments!", IF)do { if (!(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef
))) { CheckFailed("Callsite was not defined with variable arguments!"
, IF); return; } } while (false)
;
4299
4300 // All descriptors should be absorbed by now.
4301 Assert(TableRef.empty(), "Intrinsic has too few arguments!", IF)do { if (!(TableRef.empty())) { CheckFailed("Intrinsic has too few arguments!"
, IF); return; } } while (false)
;
4302
4303 // Now that we have the intrinsic ID and the actual argument types (and we
4304 // know they are legal for the intrinsic!) get the intrinsic name through the
4305 // usual means. This allows us to verify the mangling of argument types into
4306 // the name.
4307 const std::string ExpectedName = Intrinsic::getName(ID, ArgTys);
4308 Assert(ExpectedName == IF->getName(),do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! "
"Should be: " + ExpectedName, IF); return; } } while (false)
4309 "Intrinsic name not mangled correctly for type arguments! "do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! "
"Should be: " + ExpectedName, IF); return; } } while (false)
4310 "Should be: " +do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! "
"Should be: " + ExpectedName, IF); return; } } while (false)
4311 ExpectedName,do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! "
"Should be: " + ExpectedName, IF); return; } } while (false)
4312 IF)do { if (!(ExpectedName == IF->getName())) { CheckFailed("Intrinsic name not mangled correctly for type arguments! "
"Should be: " + ExpectedName, IF); return; } } while (false)
;
4313
4314 // If the intrinsic takes MDNode arguments, verify that they are either global
4315 // or are local to *this* function.
4316 for (Value *V : Call.args())
4317 if (auto *MD = dyn_cast<MetadataAsValue>(V))
4318 visitMetadataAsValue(*MD, Call.getCaller());
4319
4320 switch (ID) {
4321 default:
4322 break;
4323 case Intrinsic::coro_id: {
4324 auto *InfoArg = Call.getArgOperand(3)->stripPointerCasts();
4325 if (isa<ConstantPointerNull>(InfoArg))
4326 break;
4327 auto *GV = dyn_cast<GlobalVariable>(InfoArg);
4328 Assert(GV && GV->isConstant() && GV->hasDefinitiveInitializer(),do { if (!(GV && GV->isConstant() && GV->
hasDefinitiveInitializer())) { CheckFailed("info argument of llvm.coro.begin must refer to an initialized "
"constant"); return; } } while (false)
4329 "info argument of llvm.coro.begin must refer to an initialized "do { if (!(GV && GV->isConstant() && GV->
hasDefinitiveInitializer())) { CheckFailed("info argument of llvm.coro.begin must refer to an initialized "
"constant"); return; } } while (false)
4330 "constant")do { if (!(GV && GV->isConstant() && GV->
hasDefinitiveInitializer())) { CheckFailed("info argument of llvm.coro.begin must refer to an initialized "
"constant"); return; } } while (false)
;
4331 Constant *Init = GV->getInitializer();
4332 Assert(isa<ConstantStruct>(Init) || isa<ConstantArray>(Init),do { if (!(isa<ConstantStruct>(Init) || isa<ConstantArray
>(Init))) { CheckFailed("info argument of llvm.coro.begin must refer to either a struct or "
"an array"); return; } } while (false)
4333 "info argument of llvm.coro.begin must refer to either a struct or "do { if (!(isa<ConstantStruct>(Init) || isa<ConstantArray
>(Init))) { CheckFailed("info argument of llvm.coro.begin must refer to either a struct or "
"an array"); return; } } while (false)
4334 "an array")do { if (!(isa<ConstantStruct>(Init) || isa<ConstantArray
>(Init))) { CheckFailed("info argument of llvm.coro.begin must refer to either a struct or "
"an array"); return; } } while (false)
;
4335 break;
4336 }
4337#define INSTRUCTION(NAME, NARGS, ROUND_MODE, INTRINSIC) \
4338 case Intrinsic::INTRINSIC:
4339#include "llvm/IR/ConstrainedOps.def"
4340 visitConstrainedFPIntrinsic(cast<ConstrainedFPIntrinsic>(Call));
4341 break;
4342 case Intrinsic::dbg_declare: // llvm.dbg.declare
4343 Assert(isa<MetadataAsValue>(Call.getArgOperand(0)),do { if (!(isa<MetadataAsValue>(Call.getArgOperand(0)))
) { CheckFailed("invalid llvm.dbg.declare intrinsic call 1", Call
); return; } } while (false)
4344 "invalid llvm.dbg.declare intrinsic call 1", Call)do { if (!(isa<MetadataAsValue>(Call.getArgOperand(0)))
) { CheckFailed("invalid llvm.dbg.declare intrinsic call 1", Call
); return; } } while (false)
;
4345 visitDbgIntrinsic("declare", cast<DbgVariableIntrinsic>(Call));
4346 break;
4347 case Intrinsic::dbg_addr: // llvm.dbg.addr
4348 visitDbgIntrinsic("addr", cast<DbgVariableIntrinsic>(Call));
4349 break;
4350 case Intrinsic::dbg_value: // llvm.dbg.value
4351 visitDbgIntrinsic("value", cast<DbgVariableIntrinsic>(Call));
4352 break;
4353 case Intrinsic::dbg_label: // llvm.dbg.label
4354 visitDbgLabelIntrinsic("label", cast<DbgLabelInst>(Call));
4355 break;
4356 case Intrinsic::memcpy:
4357 case Intrinsic::memcpy_inline:
4358 case Intrinsic::memmove:
4359 case Intrinsic::memset: {
4360 const auto *MI = cast<MemIntrinsic>(&Call);
4361 auto IsValidAlignment = [&](unsigned Alignment) -> bool {
4362 return Alignment == 0 || isPowerOf2_32(Alignment);
4363 };
4364 Assert(IsValidAlignment(MI->getDestAlignment()),do { if (!(IsValidAlignment(MI->getDestAlignment()))) { CheckFailed
("alignment of arg 0 of memory intrinsic must be 0 or a power of 2"
, Call); return; } } while (false)
4365 "alignment of arg 0 of memory intrinsic must be 0 or a power of 2",do { if (!(IsValidAlignment(MI->getDestAlignment()))) { CheckFailed
("alignment of arg 0 of memory intrinsic must be 0 or a power of 2"
, Call); return; } } while (false)
4366 Call)do { if (!(IsValidAlignment(MI->getDestAlignment()))) { CheckFailed
("alignment of arg 0 of memory intrinsic must be 0 or a power of 2"
, Call); return; } } while (false)
;
4367 if (const auto *MTI = dyn_cast<MemTransferInst>(MI)) {
4368 Assert(IsValidAlignment(MTI->getSourceAlignment()),do { if (!(IsValidAlignment(MTI->getSourceAlignment()))) {
CheckFailed("alignment of arg 1 of memory intrinsic must be 0 or a power of 2"
, Call); return; } } while (false)
4369 "alignment of arg 1 of memory intrinsic must be 0 or a power of 2",do { if (!(IsValidAlignment(MTI->getSourceAlignment()))) {
CheckFailed("alignment of arg 1 of memory intrinsic must be 0 or a power of 2"
, Call); return; } } while (false)
4370 Call)do { if (!(IsValidAlignment(MTI->getSourceAlignment()))) {
CheckFailed("alignment of arg 1 of memory intrinsic must be 0 or a power of 2"
, Call); return; } } while (false)
;
4371 }
4372
4373 break;
4374 }
4375 case Intrinsic::memcpy_element_unordered_atomic:
4376 case Intrinsic::memmove_element_unordered_atomic:
4377 case Intrinsic::memset_element_unordered_atomic: {
4378 const auto *AMI = cast<AtomicMemIntrinsic>(&Call);
4379
4380 ConstantInt *ElementSizeCI =
4381 cast<ConstantInt>(AMI->getRawElementSizeInBytes());
4382 const APInt &ElementSizeVal = ElementSizeCI->getValue();
4383 Assert(ElementSizeVal.isPowerOf2(),do { if (!(ElementSizeVal.isPowerOf2())) { CheckFailed("element size of the element-wise atomic memory intrinsic "
"must be a power of 2", Call); return; } } while (false)
4384 "element size of the element-wise atomic memory intrinsic "do { if (!(ElementSizeVal.isPowerOf2())) { CheckFailed("element size of the element-wise atomic memory intrinsic "
"must be a power of 2", Call); return; } } while (false)
4385 "must be a power of 2",do { if (!(ElementSizeVal.isPowerOf2())) { CheckFailed("element size of the element-wise atomic memory intrinsic "
"must be a power of 2", Call); return; } } while (false)
4386 Call)do { if (!(ElementSizeVal.isPowerOf2())) { CheckFailed("element size of the element-wise atomic memory intrinsic "
"must be a power of 2", Call); return; } } while (false)
;
4387
4388 if (auto *LengthCI = dyn_cast<ConstantInt>(AMI->getLength())) {
4389 uint64_t Length = LengthCI->getZExtValue();
4390 uint64_t ElementSize = AMI->getElementSizeInBytes();
4391 Assert((Length % ElementSize) == 0,do { if (!((Length % ElementSize) == 0)) { CheckFailed("constant length must be a multiple of the element size in the "
"element-wise atomic memory intrinsic", Call); return; } } while
(false)
4392 "constant length must be a multiple of the element size in the "do { if (!((Length % ElementSize) == 0)) { CheckFailed("constant length must be a multiple of the element size in the "
"element-wise atomic memory intrinsic", Call); return; } } while
(false)
4393 "element-wise atomic memory intrinsic",do { if (!((Length % ElementSize) == 0)) { CheckFailed("constant length must be a multiple of the element size in the "
"element-wise atomic memory intrinsic", Call); return; } } while
(false)
4394 Call)do { if (!((Length % ElementSize) == 0)) { CheckFailed("constant length must be a multiple of the element size in the "
"element-wise atomic memory intrinsic", Call); return; } } while
(false)
;
4395 }
4396
4397 auto IsValidAlignment = [&](uint64_t Alignment) {
4398 return isPowerOf2_64(Alignment) && ElementSizeVal.ule(Alignment);
4399 };
4400 uint64_t DstAlignment = AMI->getDestAlignment();
4401 Assert(IsValidAlignment(DstAlignment),do { if (!(IsValidAlignment(DstAlignment))) { CheckFailed("incorrect alignment of the destination argument"
, Call); return; } } while (false)
4402 "incorrect alignment of the destination argument", Call)do { if (!(IsValidAlignment(DstAlignment))) { CheckFailed("incorrect alignment of the destination argument"
, Call); return; } } while (false)
;
4403 if (const auto *AMT = dyn_cast<AtomicMemTransferInst>(AMI)) {
4404 uint64_t SrcAlignment = AMT->getSourceAlignment();
4405 Assert(IsValidAlignment(SrcAlignment),do { if (!(IsValidAlignment(SrcAlignment))) { CheckFailed("incorrect alignment of the source argument"
, Call); return; } } while (false)
4406 "incorrect alignment of the source argument", Call)do { if (!(IsValidAlignment(SrcAlignment))) { CheckFailed("incorrect alignment of the source argument"
, Call); return; } } while (false)
;
4407 }
4408 break;
4409 }
4410 case Intrinsic::gcroot:
4411 case Intrinsic::gcwrite:
4412 case Intrinsic::gcread:
4413 if (ID == Intrinsic::gcroot) {
4414 AllocaInst *AI =
4415 dyn_cast<AllocaInst>(Call.getArgOperand(0)->stripPointerCasts());
4416 Assert(AI, "llvm.gcroot parameter #1 must be an alloca.", Call)do { if (!(AI)) { CheckFailed("llvm.gcroot parameter #1 must be an alloca."
, Call); return; } } while (false)
;
4417 Assert(isa<Constant>(Call.getArgOperand(1)),do { if (!(isa<Constant>(Call.getArgOperand(1)))) { CheckFailed
("llvm.gcroot parameter #2 must be a constant.", Call); return
; } } while (false)
4418 "llvm.gcroot parameter #2 must be a constant.", Call)do { if (!(isa<Constant>(Call.getArgOperand(1)))) { CheckFailed
("llvm.gcroot parameter #2 must be a constant.", Call); return
; } } while (false)
;
4419 if (!AI->getAllocatedType()->isPointerTy()) {
4420 Assert(!isa<ConstantPointerNull>(Call.getArgOperand(1)),do { if (!(!isa<ConstantPointerNull>(Call.getArgOperand
(1)))) { CheckFailed("llvm.gcroot parameter #1 must either be a pointer alloca, "
"or argument #2 must be a non-null constant.", Call); return
; } } while (false)
4421 "llvm.gcroot parameter #1 must either be a pointer alloca, "do { if (!(!isa<ConstantPointerNull>(Call.getArgOperand
(1)))) { CheckFailed("llvm.gcroot parameter #1 must either be a pointer alloca, "
"or argument #2 must be a non-null constant.", Call); return
; } } while (false)
4422 "or argument #2 must be a non-null constant.",do { if (!(!isa<ConstantPointerNull>(Call.getArgOperand
(1)))) { CheckFailed("llvm.gcroot parameter #1 must either be a pointer alloca, "
"or argument #2 must be a non-null constant.", Call); return
; } } while (false)
4423 Call)do { if (!(!isa<ConstantPointerNull>(Call.getArgOperand
(1)))) { CheckFailed("llvm.gcroot parameter #1 must either be a pointer alloca, "
"or argument #2 must be a non-null constant.", Call); return
; } } while (false)
;
4424 }
4425 }
4426
4427 Assert(Call.getParent()->getParent()->hasGC(),do { if (!(Call.getParent()->getParent()->hasGC())) { CheckFailed
("Enclosing function does not use GC.", Call); return; } } while
(false)
4428 "Enclosing function does not use GC.", Call)do { if (!(Call.getParent()->getParent()->hasGC())) { CheckFailed
("Enclosing function does not use GC.", Call); return; } } while
(false)
;
4429 break;
4430 case Intrinsic::init_trampoline:
4431 Assert(isa<Function>(Call.getArgOperand(1)->stripPointerCasts()),do { if (!(isa<Function>(Call.getArgOperand(1)->stripPointerCasts
()))) { CheckFailed("llvm.init_trampoline parameter #2 must resolve to a function."
, Call); return; } } while (false)
4432 "llvm.init_trampoline parameter #2 must resolve to a function.",do { if (!(isa<Function>(Call.getArgOperand(1)->stripPointerCasts
()))) { CheckFailed("llvm.init_trampoline parameter #2 must resolve to a function."
, Call); return; } } while (false)
4433 Call)do { if (!(isa<Function>(Call.getArgOperand(1)->stripPointerCasts
()))) { CheckFailed("llvm.init_trampoline parameter #2 must resolve to a function."
, Call); return; } } while (false)
;
4434 break;
4435 case Intrinsic::prefetch:
4436 Assert(cast<ConstantInt>(Call.getArgOperand(1))->getZExtValue() < 2 &&do { if (!(cast<ConstantInt>(Call.getArgOperand(1))->
getZExtValue() < 2 && cast<ConstantInt>(Call
.getArgOperand(2))->getZExtValue() < 4)) { CheckFailed(
"invalid arguments to llvm.prefetch", Call); return; } } while
(false)
4437 cast<ConstantInt>(Call.getArgOperand(2))->getZExtValue() < 4,do { if (!(cast<ConstantInt>(Call.getArgOperand(1))->
getZExtValue() < 2 && cast<ConstantInt>(Call
.getArgOperand(2))->getZExtValue() < 4)) { CheckFailed(
"invalid arguments to llvm.prefetch", Call); return; } } while
(false)
4438 "invalid arguments to llvm.prefetch", Call)do { if (!(cast<ConstantInt>(Call.getArgOperand(1))->
getZExtValue() < 2 && cast<ConstantInt>(Call
.getArgOperand(2))->getZExtValue() < 4)) { CheckFailed(
"invalid arguments to llvm.prefetch", Call); return; } } while
(false)
;
4439 break;
4440 case Intrinsic::stackprotector:
4441 Assert(isa<AllocaInst>(Call.getArgOperand(1)->stripPointerCasts()),do { if (!(isa<AllocaInst>(Call.getArgOperand(1)->stripPointerCasts
()))) { CheckFailed("llvm.stackprotector parameter #2 must resolve to an alloca."
, Call); return; } } while (false)
4442 "llvm.stackprotector parameter #2 must resolve to an alloca.", Call)do { if (!(isa<AllocaInst>(Call.getArgOperand(1)->stripPointerCasts
()))) { CheckFailed("llvm.stackprotector parameter #2 must resolve to an alloca."
, Call); return; } } while (false)
;
4443 break;
4444 case Intrinsic::localescape: {
4445 BasicBlock *BB = Call.getParent();
4446 Assert(BB == &BB->getParent()->front(),do { if (!(BB == &BB->getParent()->front())) { CheckFailed
("llvm.localescape used outside of entry block", Call); return
; } } while (false)
4447 "llvm.localescape used outside of entry block", Call)do { if (!(BB == &BB->getParent()->front())) { CheckFailed
("llvm.localescape used outside of entry block", Call); return
; } } while (false)
;
4448 Assert(!SawFrameEscape,do { if (!(!SawFrameEscape)) { CheckFailed("multiple calls to llvm.localescape in one function"
, Call); return; } } while (false)
4449 "multiple calls to llvm.localescape in one function", Call)do { if (!(!SawFrameEscape)) { CheckFailed("multiple calls to llvm.localescape in one function"
, Call); return; } } while (false)
;
4450 for (Value *Arg : Call.args()) {
4451 if (isa<ConstantPointerNull>(Arg))
4452 continue; // Null values are allowed as placeholders.
4453 auto *AI = dyn_cast<AllocaInst>(Arg->stripPointerCasts());
4454 Assert(AI && AI->isStaticAlloca(),do { if (!(AI && AI->isStaticAlloca())) { CheckFailed
("llvm.localescape only accepts static allocas", Call); return
; } } while (false)
4455 "llvm.localescape only accepts static allocas", Call)do { if (!(AI && AI->isStaticAlloca())) { CheckFailed
("llvm.localescape only accepts static allocas", Call); return
; } } while (false)
;
4456 }
4457 FrameEscapeInfo[BB->getParent()].first = Call.getNumArgOperands();
4458 SawFrameEscape = true;
4459 break;
4460 }
4461 case Intrinsic::localrecover: {
4462 Value *FnArg = Call.getArgOperand(0)->stripPointerCasts();
4463 Function *Fn = dyn_cast<Function>(FnArg);
4464 Assert(Fn && !Fn->isDeclaration(),do { if (!(Fn && !Fn->isDeclaration())) { CheckFailed
("llvm.localrecover first " "argument must be function defined in this module"
, Call); return; } } while (false)
4465 "llvm.localrecover first "do { if (!(Fn && !Fn->isDeclaration())) { CheckFailed
("llvm.localrecover first " "argument must be function defined in this module"
, Call); return; } } while (false)
4466 "argument must be function defined in this module",do { if (!(Fn && !Fn->isDeclaration())) { CheckFailed
("llvm.localrecover first " "argument must be function defined in this module"
, Call); return; } } while (false)
4467 Call)do { if (!(Fn && !Fn->isDeclaration())) { CheckFailed
("llvm.localrecover first " "argument must be function defined in this module"
, Call); return; } } while (false)
;
4468 auto *IdxArg = cast<ConstantInt>(Call.getArgOperand(2));
4469 auto &Entry = FrameEscapeInfo[Fn];
4470 Entry.second = unsigned(
4471 std::max(uint64_t(Entry.second), IdxArg->getLimitedValue(~0U) + 1));
4472 break;
4473 }
4474
4475 case Intrinsic::experimental_gc_statepoint:
4476 if (auto *CI = dyn_cast<CallInst>(&Call))
4477 Assert(!CI->isInlineAsm(),do { if (!(!CI->isInlineAsm())) { CheckFailed("gc.statepoint support for inline assembly unimplemented"
, CI); return; } } while (false)
4478 "gc.statepoint support for inline assembly unimplemented", CI)do { if (!(!CI->isInlineAsm())) { CheckFailed("gc.statepoint support for inline assembly unimplemented"
, CI); return; } } while (false)
;
4479 Assert(Call.getParent()->getParent()->hasGC(),do { if (!(Call.getParent()->getParent()->hasGC())) { CheckFailed
("Enclosing function does not use GC.", Call); return; } } while
(false)
4480 "Enclosing function does not use GC.", Call)do { if (!(Call.getParent()->getParent()->hasGC())) { CheckFailed
("Enclosing function does not use GC.", Call); return; } } while
(false)
;
4481
4482 verifyStatepoint(Call);
4483 break;
4484 case Intrinsic::experimental_gc_result: {
4485 Assert(Call.getParent()->getParent()->hasGC(),do { if (!(Call.getParent()->getParent()->hasGC())) { CheckFailed
("Enclosing function does not use GC.", Call); return; } } while
(false)
4486 "Enclosing function does not use GC.", Call)do { if (!(Call.getParent()->getParent()->hasGC())) { CheckFailed
("Enclosing function does not use GC.", Call); return; } } while
(false)
;
4487 // Are we tied to a statepoint properly?
4488 const auto *StatepointCall = dyn_cast<CallBase>(Call.getArgOperand(0));
4489 const Function *StatepointFn =
4490 StatepointCall ? StatepointCall->getCalledFunction() : nullptr;
4491 Assert(StatepointFn && StatepointFn->isDeclaration() &&do { if (!(StatepointFn && StatepointFn->isDeclaration
() && StatepointFn->getIntrinsicID() == Intrinsic::
experimental_gc_statepoint)) { CheckFailed("gc.result operand #1 must be from a statepoint"
, Call, Call.getArgOperand(0)); return; } } while (false)
4492 StatepointFn->getIntrinsicID() ==do { if (!(StatepointFn && StatepointFn->isDeclaration
() && StatepointFn->getIntrinsicID() == Intrinsic::
experimental_gc_statepoint)) { CheckFailed("gc.result operand #1 must be from a statepoint"
, Call, Call.getArgOperand(0)); return; } } while (false)
4493 Intrinsic::experimental_gc_statepoint,do { if (!(StatepointFn && StatepointFn->isDeclaration
() && StatepointFn->getIntrinsicID() == Intrinsic::
experimental_gc_statepoint)) { CheckFailed("gc.result operand #1 must be from a statepoint"
, Call, Call.getArgOperand(0)); return; } } while (false)
4494 "gc.result operand #1 must be from a statepoint", Call,do { if (!(StatepointFn && StatepointFn->isDeclaration
() && StatepointFn->getIntrinsicID() == Intrinsic::
experimental_gc_statepoint)) { CheckFailed("gc.result operand #1 must be from a statepoint"
, Call, Call.getArgOperand(0)); return; } } while (false)
4495 Call.getArgOperand(0))do { if (!(StatepointFn && StatepointFn->isDeclaration
() && StatepointFn->getIntrinsicID() == Intrinsic::
experimental_gc_statepoint)) { CheckFailed("gc.result operand #1 must be from a statepoint"
, Call, Call.getArgOperand(0)); return; } } while (false)
;
4496
4497 // Assert that result type matches wrapped callee.
4498 const Value *Target = StatepointCall->getArgOperand(2);
4499 auto *PT = cast<PointerType>(Target->getType());
4500 auto *TargetFuncType = cast<FunctionType>(PT->getElementType());
4501 Assert(Call.getType() == TargetFuncType->getReturnType(),do { if (!(Call.getType() == TargetFuncType->getReturnType
())) { CheckFailed("gc.result result type does not match wrapped callee"
, Call); return; } } while (false)
4502 "gc.result result type does not match wrapped callee", Call)do { if (!(Call.getType() == TargetFuncType->getReturnType
())) { CheckFailed("gc.result result type does not match wrapped callee"
, Call); return; } } while (false)
;
4503 break;
4504 }
4505 case Intrinsic::experimental_gc_relocate: {
4506 Assert(Call.getNumArgOperands() == 3, "wrong number of arguments", Call)do { if (!(Call.getNumArgOperands() == 3)) { CheckFailed("wrong number of arguments"
, Call); return; } } while (false)
;
4507
4508 Assert(isa<PointerType>(Call.getType()->getScalarType()),do { if (!(isa<PointerType>(Call.getType()->getScalarType
()))) { CheckFailed("gc.relocate must return a pointer or a vector of pointers"
, Call); return; } } while (false)
4509 "gc.relocate must return a pointer or a vector of pointers", Call)do { if (!(isa<PointerType>(Call.getType()->getScalarType
()))) { CheckFailed("gc.relocate must return a pointer or a vector of pointers"
, Call); return; } } while (false)
;
4510
4511 // Check that this relocate is correctly tied to the statepoint
4512
4513 // This is case for relocate on the unwinding path of an invoke statepoint
4514 if (LandingPadInst *LandingPad =
4515 dyn_cast<LandingPadInst>(Call.getArgOperand(0))) {
4516
4517 const BasicBlock *InvokeBB =
4518 LandingPad->getParent()->getUniquePredecessor();
4519
4520 // Landingpad relocates should have only one predecessor with invoke
4521 // statepoint terminator
4522 Assert(InvokeBB, "safepoints should have unique landingpads",do { if (!(InvokeBB)) { CheckFailed("safepoints should have unique landingpads"
, LandingPad->getParent()); return; } } while (false)
4523 LandingPad->getParent())do { if (!(InvokeBB)) { CheckFailed("safepoints should have unique landingpads"
, LandingPad->getParent()); return; } } while (false)
;
4524 Assert(InvokeBB->getTerminator(), "safepoint block should be well formed",do { if (!(InvokeBB->getTerminator())) { CheckFailed("safepoint block should be well formed"
, InvokeBB); return; } } while (false)
4525 InvokeBB)do { if (!(InvokeBB->getTerminator())) { CheckFailed("safepoint block should be well formed"
, InvokeBB); return; } } while (false)
;
4526 Assert(isStatepoint(InvokeBB->getTerminator()),do { if (!(isStatepoint(InvokeBB->getTerminator()))) { CheckFailed
("gc relocate should be linked to a statepoint", InvokeBB); return
; } } while (false)
4527 "gc relocate should be linked to a statepoint", InvokeBB)do { if (!(isStatepoint(InvokeBB->getTerminator()))) { CheckFailed
("gc relocate should be linked to a statepoint", InvokeBB); return
; } } while (false)
;
4528 } else {
4529 // In all other cases relocate should be tied to the statepoint directly.
4530 // This covers relocates on a normal return path of invoke statepoint and
4531 // relocates of a call statepoint.
4532 auto Token = Call.getArgOperand(0);
4533 Assert(isa<Instruction>(Token) && isStatepoint(cast<Instruction>(Token)),do { if (!(isa<Instruction>(Token) && isStatepoint
(cast<Instruction>(Token)))) { CheckFailed("gc relocate is incorrectly tied to the statepoint"
, Call, Token); return; } } while (false)
4534 "gc relocate is incorrectly tied to the statepoint", Call, Token)do { if (!(isa<Instruction>(Token) && isStatepoint
(cast<Instruction>(Token)))) { CheckFailed("gc relocate is incorrectly tied to the statepoint"
, Call, Token); return; } } while (false)
;
4535 }
4536
4537 // Verify rest of the relocate arguments.
4538 const CallBase &StatepointCall =
4539 *cast<CallBase>(cast<GCRelocateInst>(Call).getStatepoint());
4540
4541 // Both the base and derived must be piped through the safepoint.
4542 Value *Base = Call.getArgOperand(1);
4543 Assert(isa<ConstantInt>(Base),do { if (!(isa<ConstantInt>(Base))) { CheckFailed("gc.relocate operand #2 must be integer offset"
, Call); return; } } while (false)
4544 "gc.relocate operand #2 must be integer offset", Call)do { if (!(isa<ConstantInt>(Base))) { CheckFailed("gc.relocate operand #2 must be integer offset"
, Call); return; } } while (false)
;
4545
4546 Value *Derived = Call.getArgOperand(2);
4547 Assert(isa<ConstantInt>(Derived),do { if (!(isa<ConstantInt>(Derived))) { CheckFailed("gc.relocate operand #3 must be integer offset"
, Call); return; } } while (false)
4548 "gc.relocate operand #3 must be integer offset", Call)do { if (!(isa<ConstantInt>(Derived))) { CheckFailed("gc.relocate operand #3 must be integer offset"
, Call); return; } } while (false)
;
4549
4550 const int BaseIndex = cast<ConstantInt>(Base)->getZExtValue();
4551 const int DerivedIndex = cast<ConstantInt>(Derived)->getZExtValue();
4552 // Check the bounds
4553 Assert(0 <= BaseIndex && BaseIndex < (int)StatepointCall.arg_size(),do { if (!(0 <= BaseIndex && BaseIndex < (int)StatepointCall
.arg_size())) { CheckFailed("gc.relocate: statepoint base index out of bounds"
, Call); return; } } while (false)
4554 "gc.relocate: statepoint base index out of bounds", Call)do { if (!(0 <= BaseIndex && BaseIndex < (int)StatepointCall
.arg_size())) { CheckFailed("gc.relocate: statepoint base index out of bounds"
, Call); return; } } while (false)
;
4555 Assert(0 <= DerivedIndex && DerivedIndex < (int)StatepointCall.arg_size(),do { if (!(0 <= DerivedIndex && DerivedIndex < (
int)StatepointCall.arg_size())) { CheckFailed("gc.relocate: statepoint derived index out of bounds"
, Call); return; } } while (false)
4556 "gc.relocate: statepoint derived index out of bounds", Call)do { if (!(0 <= DerivedIndex && DerivedIndex < (
int)StatepointCall.arg_size())) { CheckFailed("gc.relocate: statepoint derived index out of bounds"
, Call); return; } } while (false)
;
4557
4558 // Check that BaseIndex and DerivedIndex fall within the 'gc parameters'
4559 // section of the statepoint's argument.
4560 Assert(StatepointCall.arg_size() > 0,do { if (!(StatepointCall.arg_size() > 0)) { CheckFailed("gc.statepoint: insufficient arguments"
); return; } } while (false)
4561 "gc.statepoint: insufficient arguments")do { if (!(StatepointCall.arg_size() > 0)) { CheckFailed("gc.statepoint: insufficient arguments"
); return; } } while (false)
;
4562 Assert(isa<ConstantInt>(StatepointCall.getArgOperand(3)),do { if (!(isa<ConstantInt>(StatepointCall.getArgOperand
(3)))) { CheckFailed("gc.statement: number of call arguments must be constant integer"
); return; } } while (false)
4563 "gc.statement: number of call arguments must be constant integer")do { if (!(isa<ConstantInt>(StatepointCall.getArgOperand
(3)))) { CheckFailed("gc.statement: number of call arguments must be constant integer"
); return; } } while (false)
;
4564 const unsigned NumCallArgs =
4565 cast<ConstantInt>(StatepointCall.getArgOperand(3))->getZExtValue();
4566 Assert(StatepointCall.arg_size() > NumCallArgs + 5,do { if (!(StatepointCall.arg_size() > NumCallArgs + 5)) {
CheckFailed("gc.statepoint: mismatch in number of call arguments"
); return; } } while (false)
4567 "gc.statepoint: mismatch in number of call arguments")do { if (!(StatepointCall.arg_size() > NumCallArgs + 5)) {
CheckFailed("gc.statepoint: mismatch in number of call arguments"
); return; } } while (false)
;
4568 Assert(isa<ConstantInt>(StatepointCall.getArgOperand(NumCallArgs + 5)),do { if (!(isa<ConstantInt>(StatepointCall.getArgOperand
(NumCallArgs + 5)))) { CheckFailed("gc.statepoint: number of transition arguments must be "
"a constant integer"); return; } } while (false)
4569 "gc.statepoint: number of transition arguments must be "do { if (!(isa<ConstantInt>(StatepointCall.getArgOperand
(NumCallArgs + 5)))) { CheckFailed("gc.statepoint: number of transition arguments must be "
"a constant integer"); return; } } while (false)
4570 "a constant integer")do { if (!(isa<ConstantInt>(StatepointCall.getArgOperand
(NumCallArgs + 5)))) { CheckFailed("gc.statepoint: number of transition arguments must be "
"a constant integer"); return; } } while (false)
;
4571 const int NumTransitionArgs =
4572 cast<ConstantInt>(StatepointCall.getArgOperand(NumCallArgs + 5))
4573 ->getZExtValue();
4574 const int DeoptArgsStart = 4 + NumCallArgs + 1 + NumTransitionArgs + 1;
4575 Assert(isa<ConstantInt>(StatepointCall.getArgOperand(DeoptArgsStart)),do { if (!(isa<ConstantInt>(StatepointCall.getArgOperand
(DeoptArgsStart)))) { CheckFailed("gc.statepoint: number of deoptimization arguments must be "
"a constant integer"); return; } } while (false)
4576 "gc.statepoint: number of deoptimization arguments must be "do { if (!(isa<ConstantInt>(StatepointCall.getArgOperand
(DeoptArgsStart)))) { CheckFailed("gc.statepoint: number of deoptimization arguments must be "
"a constant integer"); return; } } while (false)
4577 "a constant integer")do { if (!(isa<ConstantInt>(StatepointCall.getArgOperand
(DeoptArgsStart)))) { CheckFailed("gc.statepoint: number of deoptimization arguments must be "
"a constant integer"); return; } } while (false)
;
4578 const int NumDeoptArgs =
4579 cast<ConstantInt>(StatepointCall.getArgOperand(DeoptArgsStart))
4580 ->getZExtValue();
4581 const int GCParamArgsStart = DeoptArgsStart + 1 + NumDeoptArgs;
4582 const int GCParamArgsEnd = StatepointCall.arg_size();
4583 Assert(GCParamArgsStart <= BaseIndex && BaseIndex < GCParamArgsEnd,do { if (!(GCParamArgsStart <= BaseIndex && BaseIndex
< GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint base index doesn't fall within the "
"'gc parameters' section of the statepoint call", Call); return
; } } while (false)
4584 "gc.relocate: statepoint base index doesn't fall within the "do { if (!(GCParamArgsStart <= BaseIndex && BaseIndex
< GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint base index doesn't fall within the "
"'gc parameters' section of the statepoint call", Call); return
; } } while (false)
4585 "'gc parameters' section of the statepoint call",do { if (!(GCParamArgsStart <= BaseIndex && BaseIndex
< GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint base index doesn't fall within the "
"'gc parameters' section of the statepoint call", Call); return
; } } while (false)
4586 Call)do { if (!(GCParamArgsStart <= BaseIndex && BaseIndex
< GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint base index doesn't fall within the "
"'gc parameters' section of the statepoint call", Call); return
; } } while (false)
;
4587 Assert(GCParamArgsStart <= DerivedIndex && DerivedIndex < GCParamArgsEnd,do { if (!(GCParamArgsStart <= DerivedIndex && DerivedIndex
< GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint derived index doesn't fall within the "
"'gc parameters' section of the statepoint call", Call); return
; } } while (false)
4588 "gc.relocate: statepoint derived index doesn't fall within the "do { if (!(GCParamArgsStart <= DerivedIndex && DerivedIndex
< GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint derived index doesn't fall within the "
"'gc parameters' section of the statepoint call", Call); return
; } } while (false)
4589 "'gc parameters' section of the statepoint call",do { if (!(GCParamArgsStart <= DerivedIndex && DerivedIndex
< GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint derived index doesn't fall within the "
"'gc parameters' section of the statepoint call", Call); return
; } } while (false)
4590 Call)do { if (!(GCParamArgsStart <= DerivedIndex && DerivedIndex
< GCParamArgsEnd)) { CheckFailed("gc.relocate: statepoint derived index doesn't fall within the "
"'gc parameters' section of the statepoint call", Call); return
; } } while (false)
;
4591
4592 // Relocated value must be either a pointer type or vector-of-pointer type,
4593 // but gc_relocate does not need to return the same pointer type as the
4594 // relocated pointer. It can be casted to the correct type later if it's
4595 // desired. However, they must have the same address space and 'vectorness'
4596 GCRelocateInst &Relocate = cast<GCRelocateInst>(Call);
4597 Assert(Relocate.getDerivedPtr()->getType()->isPtrOrPtrVectorTy(),do { if (!(Relocate.getDerivedPtr()->getType()->isPtrOrPtrVectorTy
())) { CheckFailed("gc.relocate: relocated value must be a gc pointer"
, Call); return; } } while (false)
4598 "gc.relocate: relocated value must be a gc pointer", Call)do { if (!(Relocate.getDerivedPtr()->getType()->isPtrOrPtrVectorTy
())) { CheckFailed("gc.relocate: relocated value must be a gc pointer"
, Call); return; } } while (false)
;
4599
4600 auto ResultType = Call.getType();
4601 auto DerivedType = Relocate.getDerivedPtr()->getType();
4602 Assert(ResultType->isVectorTy() == DerivedType->isVectorTy(),do { if (!(ResultType->isVectorTy() == DerivedType->isVectorTy
())) { CheckFailed("gc.relocate: vector relocates to vector and pointer to pointer"
, Call); return; } } while (false)
4603 "gc.relocate: vector relocates to vector and pointer to pointer",do { if (!(ResultType->isVectorTy() == DerivedType->isVectorTy
())) { CheckFailed("gc.relocate: vector relocates to vector and pointer to pointer"
, Call); return; } } while (false)
4604 Call)do { if (!(ResultType->isVectorTy() == DerivedType->isVectorTy
())) { CheckFailed("gc.relocate: vector relocates to vector and pointer to pointer"
, Call); return; } } while (false)
;
4605 Assert(do { if (!(ResultType->getPointerAddressSpace() == DerivedType
->getPointerAddressSpace())) { CheckFailed("gc.relocate: relocating a pointer shouldn't change its address space"
, Call); return; } } while (false)
4606 ResultType->getPointerAddressSpace() ==do { if (!(ResultType->getPointerAddressSpace() == DerivedType
->getPointerAddressSpace())) { CheckFailed("gc.relocate: relocating a pointer shouldn't change its address space"
, Call); return; } } while (false)
4607 DerivedType->getPointerAddressSpace(),do { if (!(ResultType->getPointerAddressSpace() == DerivedType
->getPointerAddressSpace())) { CheckFailed("gc.relocate: relocating a pointer shouldn't change its address space"
, Call); return; } } while (false)
4608 "gc.relocate: relocating a pointer shouldn't change its address space",do { if (!(ResultType->getPointerAddressSpace() == DerivedType
->getPointerAddressSpace())) { CheckFailed("gc.relocate: relocating a pointer shouldn't change its address space"
, Call); return; } } while (false)
4609 Call)do { if (!(ResultType->getPointerAddressSpace() == DerivedType
->getPointerAddressSpace())) { CheckFailed("gc.relocate: relocating a pointer shouldn't change its address space"
, Call); return; } } while (false)
;
4610 break;
4611 }
4612 case Intrinsic::eh_exceptioncode:
4613 case Intrinsic::eh_exceptionpointer: {
4614 Assert(isa<CatchPadInst>(Call.getArgOperand(0)),do { if (!(isa<CatchPadInst>(Call.getArgOperand(0)))) {
CheckFailed("eh.exceptionpointer argument must be a catchpad"
, Call); return; } } while (false)
4615 "eh.exceptionpointer argument must be a catchpad", Call)do { if (!(isa<CatchPadInst>(Call.getArgOperand(0)))) {
CheckFailed("eh.exceptionpointer argument must be a catchpad"
, Call); return; } } while (false)
;
4616 break;
4617 }
4618 case Intrinsic::masked_load: {
4619 Assert(Call.getType()->isVectorTy(), "masked_load: must return a vector",do { if (!(Call.getType()->isVectorTy())) { CheckFailed("masked_load: must return a vector"
, Call); return; } } while (false)
4620 Call)do { if (!(Call.getType()->isVectorTy())) { CheckFailed("masked_load: must return a vector"
, Call); return; } } while (false)
;
4621
4622 Value *Ptr = Call.getArgOperand(0);
4623 ConstantInt *Alignment = cast<ConstantInt>(Call.getArgOperand(1));
4624 Value *Mask = Call.getArgOperand(2);
4625 Value *PassThru = Call.getArgOperand(3);
4626 Assert(Mask->getType()->isVectorTy(), "masked_load: mask must be vector",do { if (!(Mask->getType()->isVectorTy())) { CheckFailed
("masked_load: mask must be vector", Call); return; } } while
(false)
4627 Call)do { if (!(Mask->getType()->isVectorTy())) { CheckFailed
("masked_load: mask must be vector", Call); return; } } while
(false)
;
4628 Assert(Alignment->getValue().isPowerOf2(),do { if (!(Alignment->getValue().isPowerOf2())) { CheckFailed
("masked_load: alignment must be a power of 2", Call); return
; } } while (false)
4629 "masked_load: alignment must be a power of 2", Call)do { if (!(Alignment->getValue().isPowerOf2())) { CheckFailed
("masked_load: alignment must be a power of 2", Call); return
; } } while (false)
;
4630
4631 // DataTy is the overloaded type
4632 Type *DataTy = cast<PointerType>(Ptr->getType())->getElementType();
4633 Assert(DataTy == Call.getType(),do { if (!(DataTy == Call.getType())) { CheckFailed("masked_load: return must match pointer type"
, Call); return; } } while (false)
4634 "masked_load: return must match pointer type", Call)do { if (!(DataTy == Call.getType())) { CheckFailed("masked_load: return must match pointer type"
, Call); return; } } while (false)
;
4635 Assert(PassThru->getType() == DataTy,do { if (!(PassThru->getType() == DataTy)) { CheckFailed("masked_load: pass through and data type must match"
, Call); return; } } while (false)
4636 "masked_load: pass through and data type must match", Call)do { if (!(PassThru->getType() == DataTy)) { CheckFailed("masked_load: pass through and data type must match"
, Call); return; } } while (false)
;
4637 Assert(Mask->getType()->getVectorNumElements() ==do { if (!(Mask->getType()->getVectorNumElements() == DataTy
->getVectorNumElements())) { CheckFailed("masked_load: vector mask must be same length as data"
, Call); return; } } while (false)
4638 DataTy->getVectorNumElements(),do { if (!(Mask->getType()->getVectorNumElements() == DataTy
->getVectorNumElements())) { CheckFailed("masked_load: vector mask must be same length as data"
, Call); return; } } while (false)
4639 "masked_load: vector mask must be same length as data", Call)do { if (!(Mask->getType()->getVectorNumElements() == DataTy
->getVectorNumElements())) { CheckFailed("masked_load: vector mask must be same length as data"
, Call); return; } } while (false)
;
4640 break;
4641 }
4642 case Intrinsic::masked_store: {
4643 Value *Val = Call.getArgOperand(0);
4644 Value *Ptr = Call.getArgOperand(1);
4645 ConstantInt *Alignment = cast<ConstantInt>(Call.getArgOperand(2));
4646 Value *Mask = Call.getArgOperand(3);
4647 Assert(Mask->getType()->isVectorTy(), "masked_store: mask must be vector",do { if (!(Mask->getType()->isVectorTy())) { CheckFailed
("masked_store: mask must be vector", Call); return; } } while
(false)
4648 Call)do { if (!(Mask->getType()->isVectorTy())) { CheckFailed
("masked_store: mask must be vector", Call); return; } } while
(false)
;
4649 Assert(Alignment->getValue().isPowerOf2(),do { if (!(Alignment->getValue().isPowerOf2())) { CheckFailed
("masked_store: alignment must be a power of 2", Call); return
; } } while (false)
4650 "masked_store: alignment must be a power of 2", Call)do { if (!(Alignment->getValue().isPowerOf2())) { CheckFailed
("masked_store: alignment must be a power of 2", Call); return
; } } while (false)
;
4651
4652 // DataTy is the overloaded type
4653 Type *DataTy = cast<PointerType>(Ptr->getType())->getElementType();
4654 Assert(DataTy == Val->getType(),do { if (!(DataTy == Val->getType())) { CheckFailed("masked_store: storee must match pointer type"
, Call); return; } } while (false)
4655 "masked_store: storee must match pointer type", Call)do { if (!(DataTy == Val->getType())) { CheckFailed("masked_store: storee must match pointer type"
, Call); return; } } while (false)
;
4656 Assert(Mask->getType()->getVectorNumElements() ==do { if (!(Mask->getType()->getVectorNumElements() == DataTy
->getVectorNumElements())) { CheckFailed("masked_store: vector mask must be same length as data"
, Call); return; } } while (false)
4657 DataTy->getVectorNumElements(),do { if (!(Mask->getType()->getVectorNumElements() == DataTy
->getVectorNumElements())) { CheckFailed("masked_store: vector mask must be same length as data"
, Call); return; } } while (false)
4658 "masked_store: vector mask must be same length as data", Call)do { if (!(Mask->getType()->getVectorNumElements() == DataTy
->getVectorNumElements())) { CheckFailed("masked_store: vector mask must be same length as data"
, Call); return; } } while (false)
;
4659 break;
4660 }
4661
4662 case Intrinsic::masked_gather: {
4663 const APInt &Alignment =
4664 cast<ConstantInt>(Call.getArgOperand(1))->getValue();
4665 Assert(Alignment.isNullValue() || Alignment.isPowerOf2(),do { if (!(Alignment.isNullValue() || Alignment.isPowerOf2())
) { CheckFailed("masked_gather: alignment must be 0 or a power of 2"
, Call); return; } } while (false)
4666 "masked_gather: alignment must be 0 or a power of 2", Call)do { if (!(Alignment.isNullValue() || Alignment.isPowerOf2())
) { CheckFailed("masked_gather: alignment must be 0 or a power of 2"
, Call); return; } } while (false)
;
4667 break;
4668 }
4669 case Intrinsic::masked_scatter: {
4670 const APInt &Alignment =
4671 cast<ConstantInt>(Call.getArgOperand(2))->getValue();
4672 Assert(Alignment.isNullValue() || Alignment.isPowerOf2(),do { if (!(Alignment.isNullValue() || Alignment.isPowerOf2())
) { CheckFailed("masked_scatter: alignment must be 0 or a power of 2"
, Call); return; } } while (false)
4673 "masked_scatter: alignment must be 0 or a power of 2", Call)do { if (!(Alignment.isNullValue() || Alignment.isPowerOf2())
) { CheckFailed("masked_scatter: alignment must be 0 or a power of 2"
, Call); return; } } while (false)
;
4674 break;
4675 }
4676
4677 case Intrinsic::experimental_guard: {
4678 Assert(isa<CallInst>(Call), "experimental_guard cannot be invoked", Call)do { if (!(isa<CallInst>(Call))) { CheckFailed("experimental_guard cannot be invoked"
, Call); return; } } while (false)
;
4679 Assert(Call.countOperandBundlesOfType(LLVMContext::OB_deopt) == 1,do { if (!(Call.countOperandBundlesOfType(LLVMContext::OB_deopt
) == 1)) { CheckFailed("experimental_guard must have exactly one "
"\"deopt\" operand bundle"); return; } } while (false)
4680 "experimental_guard must have exactly one "do { if (!(Call.countOperandBundlesOfType(LLVMContext::OB_deopt
) == 1)) { CheckFailed("experimental_guard must have exactly one "
"\"deopt\" operand bundle"); return; } } while (false)
4681 "\"deopt\" operand bundle")do { if (!(Call.countOperandBundlesOfType(LLVMContext::OB_deopt
) == 1)) { CheckFailed("experimental_guard must have exactly one "
"\"deopt\" operand bundle"); return; } } while (false)
;
4682 break;
4683 }
4684
4685 case Intrinsic::experimental_deoptimize: {
4686 Assert(isa<CallInst>(Call), "experimental_deoptimize cannot be invoked",do { if (!(isa<CallInst>(Call))) { CheckFailed("experimental_deoptimize cannot be invoked"
, Call); return; } } while (false)
4687 Call)do { if (!(isa<CallInst>(Call))) { CheckFailed("experimental_deoptimize cannot be invoked"
, Call); return; } } while (false)
;
4688 Assert(Call.countOperandBundlesOfType(LLVMContext::OB_deopt) == 1,do { if (!(Call.countOperandBundlesOfType(LLVMContext::OB_deopt
) == 1)) { CheckFailed("experimental_deoptimize must have exactly one "
"\"deopt\" operand bundle"); return; } } while (false)
4689 "experimental_deoptimize must have exactly one "do { if (!(Call.countOperandBundlesOfType(LLVMContext::OB_deopt
) == 1)) { CheckFailed("experimental_deoptimize must have exactly one "
"\"deopt\" operand bundle"); return; } } while (false)
4690 "\"deopt\" operand bundle")do { if (!(Call.countOperandBundlesOfType(LLVMContext::OB_deopt
) == 1)) { CheckFailed("experimental_deoptimize must have exactly one "
"\"deopt\" operand bundle"); return; } } while (false)
;
4691 Assert(Call.getType() == Call.getFunction()->getReturnType(),do { if (!(Call.getType() == Call.getFunction()->getReturnType
())) { CheckFailed("experimental_deoptimize return type must match caller return type"
); return; } } while (false)
4692 "experimental_deoptimize return type must match caller return type")do { if (!(Call.getType() == Call.getFunction()->getReturnType
())) { CheckFailed("experimental_deoptimize return type must match caller return type"
); return; } } while (false)
;
4693
4694 if (isa<CallInst>(Call)) {
4695 auto *RI = dyn_cast<ReturnInst>(Call.getNextNode());
4696 Assert(RI,do { if (!(RI)) { CheckFailed("calls to experimental_deoptimize must be followed by a return"
); return; } } while (false)
4697 "calls to experimental_deoptimize must be followed by a return")do { if (!(RI)) { CheckFailed("calls to experimental_deoptimize must be followed by a return"
); return; } } while (false)
;
4698
4699 if (!Call.getType()->isVoidTy() && RI)
4700 Assert(RI->getReturnValue() == &Call,do { if (!(RI->getReturnValue() == &Call)) { CheckFailed
("calls to experimental_deoptimize must be followed by a return "
"of the value computed by experimental_deoptimize"); return;
} } while (false)
4701 "calls to experimental_deoptimize must be followed by a return "do { if (!(RI->getReturnValue() == &Call)) { CheckFailed
("calls to experimental_deoptimize must be followed by a return "
"of the value computed by experimental_deoptimize"); return;
} } while (false)
4702 "of the value computed by experimental_deoptimize")do { if (!(RI->getReturnValue() == &Call)) { CheckFailed
("calls to experimental_deoptimize must be followed by a return "
"of the value computed by experimental_deoptimize"); return;
} } while (false)
;
4703 }
4704
4705 break;
4706 }
4707 case Intrinsic::sadd_sat:
4708 case Intrinsic::uadd_sat:
4709 case Intrinsic::ssub_sat:
4710 case Intrinsic::usub_sat: {
4711 Value *Op1 = Call.getArgOperand(0);
4712 Value *Op2 = Call.getArgOperand(1);
4713 Assert(Op1->getType()->isIntOrIntVectorTy(),do { if (!(Op1->getType()->isIntOrIntVectorTy())) { CheckFailed
("first operand of [us][add|sub]_sat must be an int type or vector "
"of ints"); return; } } while (false)
4714 "first operand of [us][add|sub]_sat must be an int type or vector "do { if (!(Op1->getType()->isIntOrIntVectorTy())) { CheckFailed
("first operand of [us][add|sub]_sat must be an int type or vector "
"of ints"); return; } } while (false)
4715 "of ints")do { if (!(Op1->getType()->isIntOrIntVectorTy())) { CheckFailed
("first operand of [us][add|sub]_sat must be an int type or vector "
"of ints"); return; } } while (false)
;
4716 Assert(Op2->getType()->isIntOrIntVectorTy(),do { if (!(Op2->getType()->isIntOrIntVectorTy())) { CheckFailed
("second operand of [us][add|sub]_sat must be an int type or vector "
"of ints"); return; } } while (false)
4717 "second operand of [us][add|sub]_sat must be an int type or vector "do { if (!(Op2->getType()->isIntOrIntVectorTy())) { CheckFailed
("second operand of [us][add|sub]_sat must be an int type or vector "
"of ints"); return; } } while (false)
4718 "of ints")do { if (!(Op2->getType()->isIntOrIntVectorTy())) { CheckFailed
("second operand of [us][add|sub]_sat must be an int type or vector "
"of ints"); return; } } while (false)
;
4719 break;
4720 }
4721 case Intrinsic::smul_fix:
4722 case Intrinsic::smul_fix_sat:
4723 case Intrinsic::umul_fix:
4724 case Intrinsic::umul_fix_sat:
4725 case Intrinsic::sdiv_fix:
4726 case Intrinsic::sdiv_fix_sat:
4727 case Intrinsic::udiv_fix:
4728 case Intrinsic::udiv_fix_sat: {
4729 Value *Op1 = Call.getArgOperand(0);
4730 Value *Op2 = Call.getArgOperand(1);
4731 Assert(Op1->getType()->isIntOrIntVectorTy(),do { if (!(Op1->getType()->isIntOrIntVectorTy())) { CheckFailed
("first operand of [us][mul|div]_fix[_sat] must be an int type or "
"vector of ints"); return; } } while (false)
4732 "first operand of [us][mul|div]_fix[_sat] must be an int type or "do { if (!(Op1->getType()->isIntOrIntVectorTy())) { CheckFailed
("first operand of [us][mul|div]_fix[_sat] must be an int type or "
"vector of ints"); return; } } while (false)
4733 "vector of ints")do { if (!(Op1->getType()->isIntOrIntVectorTy())) { CheckFailed
("first operand of [us][mul|div]_fix[_sat] must be an int type or "
"vector of ints"); return; } } while (false)
;
4734 Assert(Op2->getType()->isIntOrIntVectorTy(),do { if (!(Op2->getType()->isIntOrIntVectorTy())) { CheckFailed
("second operand of [us][mul|div]_fix[_sat] must be an int type or "
"vector of ints"); return; } } while (false)
4735 "second operand of [us][mul|div]_fix[_sat] must be an int type or "do { if (!(Op2->getType()->isIntOrIntVectorTy())) { CheckFailed
("second operand of [us][mul|div]_fix[_sat] must be an int type or "
"vector of ints"); return; } } while (false)
4736 "vector of ints")do { if (!(Op2->getType()->isIntOrIntVectorTy())) { CheckFailed
("second operand of [us][mul|div]_fix[_sat] must be an int type or "
"vector of ints"); return; } } while (false)
;
4737
4738 auto *Op3 = cast<ConstantInt>(Call.getArgOperand(2));
4739 Assert(Op3->getType()->getBitWidth() <= 32,do { if (!(Op3->getType()->getBitWidth() <= 32)) { CheckFailed
("third argument of [us][mul|div]_fix[_sat] must fit within 32 bits"
); return; } } while (false)
4740 "third argument of [us][mul|div]_fix[_sat] must fit within 32 bits")do { if (!(Op3->getType()->getBitWidth() <= 32)) { CheckFailed
("third argument of [us][mul|div]_fix[_sat] must fit within 32 bits"
); return; } } while (false)
;
4741
4742 if (ID == Intrinsic::smul_fix || ID == Intrinsic::smul_fix_sat ||
4743 ID == Intrinsic::sdiv_fix || ID == Intrinsic::sdiv_fix_sat) {
4744 Assert(do { if (!(Op3->getZExtValue() < Op1->getType()->
getScalarSizeInBits())) { CheckFailed("the scale of s[mul|div]_fix[_sat] must be less than the width of "
"the operands"); return; } } while (false)
4745 Op3->getZExtValue() < Op1->getType()->getScalarSizeInBits(),do { if (!(Op3->getZExtValue() < Op1->getType()->
getScalarSizeInBits())) { CheckFailed("the scale of s[mul|div]_fix[_sat] must be less than the width of "
"the operands"); return; } } while (false)
4746 "the scale of s[mul|div]_fix[_sat] must be less than the width of "do { if (!(Op3->getZExtValue() < Op1->getType()->
getScalarSizeInBits())) { CheckFailed("the scale of s[mul|div]_fix[_sat] must be less than the width of "
"the operands"); return; } } while (false)
4747 "the operands")do { if (!(Op3->getZExtValue() < Op1->getType()->
getScalarSizeInBits())) { CheckFailed("the scale of s[mul|div]_fix[_sat] must be less than the width of "
"the operands"); return; } } while (false)
;
4748 } else {
4749 Assert(Op3->getZExtValue() <= Op1->getType()->getScalarSizeInBits(),do { if (!(Op3->getZExtValue() <= Op1->getType()->
getScalarSizeInBits())) { CheckFailed("the scale of u[mul|div]_fix[_sat] must be less than or equal "
"to the width of the operands"); return; } } while (false)
4750 "the scale of u[mul|div]_fix[_sat] must be less than or equal "do { if (!(Op3->getZExtValue() <= Op1->getType()->
getScalarSizeInBits())) { CheckFailed("the scale of u[mul|div]_fix[_sat] must be less than or equal "
"to the width of the operands"); return; } } while (false)
4751 "to the width of the operands")do { if (!(Op3->getZExtValue() <= Op1->getType()->
getScalarSizeInBits())) { CheckFailed("the scale of u[mul|div]_fix[_sat] must be less than or equal "
"to the width of the operands"); return; } } while (false)
;
4752 }
4753 break;
4754 }
4755 case Intrinsic::lround:
4756 case Intrinsic::llround:
4757 case Intrinsic::lrint:
4758 case Intrinsic::llrint: {
4759 Type *ValTy = Call.getArgOperand(0)->getType();
4760 Type *ResultTy = Call.getType();
4761 Assert(!ValTy->isVectorTy() && !ResultTy->isVectorTy(),do { if (!(!ValTy->isVectorTy() && !ResultTy->isVectorTy
())) { CheckFailed("Intrinsic does not support vectors", &
Call); return; } } while (false)
4762 "Intrinsic does not support vectors", &Call)do { if (!(!ValTy->isVectorTy() && !ResultTy->isVectorTy
())) { CheckFailed("Intrinsic does not support vectors", &
Call); return; } } while (false)
;
4763 break;
4764 }
4765 };
4766}
4767
4768/// Carefully grab the subprogram from a local scope.
4769///
4770/// This carefully grabs the subprogram from a local scope, avoiding the
4771/// built-in assertions that would typically fire.
4772static DISubprogram *getSubprogram(Metadata *LocalScope) {
4773 if (!LocalScope)
4774 return nullptr;
4775
4776 if (auto *SP = dyn_cast<DISubprogram>(LocalScope))
4777 return SP;
4778
4779 if (auto *LB = dyn_cast<DILexicalBlockBase>(LocalScope))
4780 return getSubprogram(LB->getRawScope());
4781
4782 // Just return null; broken scope chains are checked elsewhere.
4783 assert(!isa<DILocalScope>(LocalScope) && "Unknown type of local scope")((!isa<DILocalScope>(LocalScope) && "Unknown type of local scope"
) ? static_cast<void> (0) : __assert_fail ("!isa<DILocalScope>(LocalScope) && \"Unknown type of local scope\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 4783, __PRETTY_FUNCTION__))
;
4784 return nullptr;
4785}
4786
4787void Verifier::visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI) {
4788 unsigned NumOperands;
4789 bool HasRoundingMD;
4790 switch (FPI.getIntrinsicID()) {
4791#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
4792 case Intrinsic::INTRINSIC: \
4793 NumOperands = NARG; \
4794 HasRoundingMD = ROUND_MODE; \
4795 break;
4796#include "llvm/IR/ConstrainedOps.def"
4797 default:
4798 llvm_unreachable("Invalid constrained FP intrinsic!")::llvm::llvm_unreachable_internal("Invalid constrained FP intrinsic!"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 4798)
;
4799 }
4800 NumOperands += (1 + HasRoundingMD);
4801 // Compare intrinsics carry an extra predicate metadata operand.
4802 if (isa<ConstrainedFPCmpIntrinsic>(FPI))
4803 NumOperands += 1;
4804 Assert((FPI.getNumArgOperands() == NumOperands),do { if (!((FPI.getNumArgOperands() == NumOperands))) { CheckFailed
("invalid arguments for constrained FP intrinsic", &FPI);
return; } } while (false)
4805 "invalid arguments for constrained FP intrinsic", &FPI)do { if (!((FPI.getNumArgOperands() == NumOperands))) { CheckFailed
("invalid arguments for constrained FP intrinsic", &FPI);
return; } } while (false)
;
4806
4807 switch (FPI.getIntrinsicID()) {
4808 case Intrinsic::experimental_constrained_lrint:
4809 case Intrinsic::experimental_constrained_llrint: {
4810 Type *ValTy = FPI.getArgOperand(0)->getType();
4811 Type *ResultTy = FPI.getType();
4812 Assert(!ValTy->isVectorTy() && !ResultTy->isVectorTy(),do { if (!(!ValTy->isVectorTy() && !ResultTy->isVectorTy
())) { CheckFailed("Intrinsic does not support vectors", &
FPI); return; } } while (false)
4813 "Intrinsic does not support vectors", &FPI)do { if (!(!ValTy->isVectorTy() && !ResultTy->isVectorTy
())) { CheckFailed("Intrinsic does not support vectors", &
FPI); return; } } while (false)
;
4814 }
4815 break;
4816
4817 case Intrinsic::experimental_constrained_lround:
4818 case Intrinsic::experimental_constrained_llround: {
4819 Type *ValTy = FPI.getArgOperand(0)->getType();
4820 Type *ResultTy = FPI.getType();
4821 Assert(!ValTy->isVectorTy() && !ResultTy->isVectorTy(),do { if (!(!ValTy->isVectorTy() && !ResultTy->isVectorTy
())) { CheckFailed("Intrinsic does not support vectors", &
FPI); return; } } while (false)
4822 "Intrinsic does not support vectors", &FPI)do { if (!(!ValTy->isVectorTy() && !ResultTy->isVectorTy
())) { CheckFailed("Intrinsic does not support vectors", &
FPI); return; } } while (false)
;
4823 break;
4824 }
4825
4826 case Intrinsic::experimental_constrained_fcmp:
4827 case Intrinsic::experimental_constrained_fcmps: {
4828 auto Pred = cast<ConstrainedFPCmpIntrinsic>(&FPI)->getPredicate();
4829 Assert(CmpInst::isFPPredicate(Pred),do { if (!(CmpInst::isFPPredicate(Pred))) { CheckFailed("invalid predicate for constrained FP comparison intrinsic"
, &FPI); return; } } while (false)
4830 "invalid predicate for constrained FP comparison intrinsic", &FPI)do { if (!(CmpInst::isFPPredicate(Pred))) { CheckFailed("invalid predicate for constrained FP comparison intrinsic"
, &FPI); return; } } while (false)
;
4831 break;
4832 }
4833
4834 case Intrinsic::experimental_constrained_fptosi:
4835 case Intrinsic::experimental_constrained_fptoui: {
4836 Value *Operand = FPI.getArgOperand(0);
4837 uint64_t NumSrcElem = 0;
4838 Assert(Operand->getType()->isFPOrFPVectorTy(),do { if (!(Operand->getType()->isFPOrFPVectorTy())) { CheckFailed
("Intrinsic first argument must be floating point", &FPI)
; return; } } while (false)
4839 "Intrinsic first argument must be floating point", &FPI)do { if (!(Operand->getType()->isFPOrFPVectorTy())) { CheckFailed
("Intrinsic first argument must be floating point", &FPI)
; return; } } while (false)
;
4840 if (auto *OperandT = dyn_cast<VectorType>(Operand->getType())) {
4841 NumSrcElem = OperandT->getNumElements();
4842 }
4843
4844 Operand = &FPI;
4845 Assert((NumSrcElem > 0) == Operand->getType()->isVectorTy(),do { if (!((NumSrcElem > 0) == Operand->getType()->isVectorTy
())) { CheckFailed("Intrinsic first argument and result disagree on vector use"
, &FPI); return; } } while (false)
4846 "Intrinsic first argument and result disagree on vector use", &FPI)do { if (!((NumSrcElem > 0) == Operand->getType()->isVectorTy
())) { CheckFailed("Intrinsic first argument and result disagree on vector use"
, &FPI); return; } } while (false)
;
4847 Assert(Operand->getType()->isIntOrIntVectorTy(),do { if (!(Operand->getType()->isIntOrIntVectorTy())) {
CheckFailed("Intrinsic result must be an integer", &FPI)
; return; } } while (false)
4848 "Intrinsic result must be an integer", &FPI)do { if (!(Operand->getType()->isIntOrIntVectorTy())) {
CheckFailed("Intrinsic result must be an integer", &FPI)
; return; } } while (false)
;
4849 if (auto *OperandT = dyn_cast<VectorType>(Operand->getType())) {
4850 Assert(NumSrcElem == OperandT->getNumElements(),do { if (!(NumSrcElem == OperandT->getNumElements())) { CheckFailed
("Intrinsic first argument and result vector lengths must be equal"
, &FPI); return; } } while (false)
4851 "Intrinsic first argument and result vector lengths must be equal",do { if (!(NumSrcElem == OperandT->getNumElements())) { CheckFailed
("Intrinsic first argument and result vector lengths must be equal"
, &FPI); return; } } while (false)
4852 &FPI)do { if (!(NumSrcElem == OperandT->getNumElements())) { CheckFailed
("Intrinsic first argument and result vector lengths must be equal"
, &FPI); return; } } while (false)
;
4853 }
4854 }
4855 break;
4856
4857 case Intrinsic::experimental_constrained_sitofp:
4858 case Intrinsic::experimental_constrained_uitofp: {
4859 Value *Operand = FPI.getArgOperand(0);
4860 uint64_t NumSrcElem = 0;
4861 Assert(Operand->getType()->isIntOrIntVectorTy(),do { if (!(Operand->getType()->isIntOrIntVectorTy())) {
CheckFailed("Intrinsic first argument must be integer", &
FPI); return; } } while (false)
4862 "Intrinsic first argument must be integer", &FPI)do { if (!(Operand->getType()->isIntOrIntVectorTy())) {
CheckFailed("Intrinsic first argument must be integer", &
FPI); return; } } while (false)
;
4863 if (auto *OperandT = dyn_cast<VectorType>(Operand->getType())) {
4864 NumSrcElem = OperandT->getNumElements();
4865 }
4866
4867 Operand = &FPI;
4868 Assert((NumSrcElem > 0) == Operand->getType()->isVectorTy(),do { if (!((NumSrcElem > 0) == Operand->getType()->isVectorTy
())) { CheckFailed("Intrinsic first argument and result disagree on vector use"
, &FPI); return; } } while (false)
4869 "Intrinsic first argument and result disagree on vector use", &FPI)do { if (!((NumSrcElem > 0) == Operand->getType()->isVectorTy
())) { CheckFailed("Intrinsic first argument and result disagree on vector use"
, &FPI); return; } } while (false)
;
4870 Assert(Operand->getType()->isFPOrFPVectorTy(),do { if (!(Operand->getType()->isFPOrFPVectorTy())) { CheckFailed
("Intrinsic result must be a floating point", &FPI); return
; } } while (false)
4871 "Intrinsic result must be a floating point", &FPI)do { if (!(Operand->getType()->isFPOrFPVectorTy())) { CheckFailed
("Intrinsic result must be a floating point", &FPI); return
; } } while (false)
;
4872 if (auto *OperandT = dyn_cast<VectorType>(Operand->getType())) {
4873 Assert(NumSrcElem == OperandT->getNumElements(),do { if (!(NumSrcElem == OperandT->getNumElements())) { CheckFailed
("Intrinsic first argument and result vector lengths must be equal"
, &FPI); return; } } while (false)
4874 "Intrinsic first argument and result vector lengths must be equal",do { if (!(NumSrcElem == OperandT->getNumElements())) { CheckFailed
("Intrinsic first argument and result vector lengths must be equal"
, &FPI); return; } } while (false)
4875 &FPI)do { if (!(NumSrcElem == OperandT->getNumElements())) { CheckFailed
("Intrinsic first argument and result vector lengths must be equal"
, &FPI); return; } } while (false)
;
4876 }
4877 } break;
4878
4879 case Intrinsic::experimental_constrained_fptrunc:
4880 case Intrinsic::experimental_constrained_fpext: {
4881 Value *Operand = FPI.getArgOperand(0);
4882 Type *OperandTy = Operand->getType();
4883 Value *Result = &FPI;
4884 Type *ResultTy = Result->getType();
4885 Assert(OperandTy->isFPOrFPVectorTy(),do { if (!(OperandTy->isFPOrFPVectorTy())) { CheckFailed("Intrinsic first argument must be FP or FP vector"
, &FPI); return; } } while (false)
4886 "Intrinsic first argument must be FP or FP vector", &FPI)do { if (!(OperandTy->isFPOrFPVectorTy())) { CheckFailed("Intrinsic first argument must be FP or FP vector"
, &FPI); return; } } while (false)
;
4887 Assert(ResultTy->isFPOrFPVectorTy(),do { if (!(ResultTy->isFPOrFPVectorTy())) { CheckFailed("Intrinsic result must be FP or FP vector"
, &FPI); return; } } while (false)
4888 "Intrinsic result must be FP or FP vector", &FPI)do { if (!(ResultTy->isFPOrFPVectorTy())) { CheckFailed("Intrinsic result must be FP or FP vector"
, &FPI); return; } } while (false)
;
4889 Assert(OperandTy->isVectorTy() == ResultTy->isVectorTy(),do { if (!(OperandTy->isVectorTy() == ResultTy->isVectorTy
())) { CheckFailed("Intrinsic first argument and result disagree on vector use"
, &FPI); return; } } while (false)
4890 "Intrinsic first argument and result disagree on vector use", &FPI)do { if (!(OperandTy->isVectorTy() == ResultTy->isVectorTy
())) { CheckFailed("Intrinsic first argument and result disagree on vector use"
, &FPI); return; } } while (false)
;
4891 if (OperandTy->isVectorTy()) {
4892 auto *OperandVecTy = cast<VectorType>(OperandTy);
4893 auto *ResultVecTy = cast<VectorType>(ResultTy);
4894 Assert(OperandVecTy->getNumElements() == ResultVecTy->getNumElements(),do { if (!(OperandVecTy->getNumElements() == ResultVecTy->
getNumElements())) { CheckFailed("Intrinsic first argument and result vector lengths must be equal"
, &FPI); return; } } while (false)
4895 "Intrinsic first argument and result vector lengths must be equal",do { if (!(OperandVecTy->getNumElements() == ResultVecTy->
getNumElements())) { CheckFailed("Intrinsic first argument and result vector lengths must be equal"
, &FPI); return; } } while (false)
4896 &FPI)do { if (!(OperandVecTy->getNumElements() == ResultVecTy->
getNumElements())) { CheckFailed("Intrinsic first argument and result vector lengths must be equal"
, &FPI); return; } } while (false)
;
4897 }
4898 if (FPI.getIntrinsicID() == Intrinsic::experimental_constrained_fptrunc) {
4899 Assert(OperandTy->getScalarSizeInBits() > ResultTy->getScalarSizeInBits(),do { if (!(OperandTy->getScalarSizeInBits() > ResultTy->
getScalarSizeInBits())) { CheckFailed("Intrinsic first argument's type must be larger than result type"
, &FPI); return; } } while (false)
4900 "Intrinsic first argument's type must be larger than result type",do { if (!(OperandTy->getScalarSizeInBits() > ResultTy->
getScalarSizeInBits())) { CheckFailed("Intrinsic first argument's type must be larger than result type"
, &FPI); return; } } while (false)
4901 &FPI)do { if (!(OperandTy->getScalarSizeInBits() > ResultTy->
getScalarSizeInBits())) { CheckFailed("Intrinsic first argument's type must be larger than result type"
, &FPI); return; } } while (false)
;
4902 } else {
4903 Assert(OperandTy->getScalarSizeInBits() < ResultTy->getScalarSizeInBits(),do { if (!(OperandTy->getScalarSizeInBits() < ResultTy->
getScalarSizeInBits())) { CheckFailed("Intrinsic first argument's type must be smaller than result type"
, &FPI); return; } } while (false)
4904 "Intrinsic first argument's type must be smaller than result type",do { if (!(OperandTy->getScalarSizeInBits() < ResultTy->
getScalarSizeInBits())) { CheckFailed("Intrinsic first argument's type must be smaller than result type"
, &FPI); return; } } while (false)
4905 &FPI)do { if (!(OperandTy->getScalarSizeInBits() < ResultTy->
getScalarSizeInBits())) { CheckFailed("Intrinsic first argument's type must be smaller than result type"
, &FPI); return; } } while (false)
;
4906 }
4907 }
4908 break;
4909
4910 default:
4911 break;
4912 }
4913
4914 // If a non-metadata argument is passed in a metadata slot then the
4915 // error will be caught earlier when the incorrect argument doesn't
4916 // match the specification in the intrinsic call table. Thus, no
4917 // argument type check is needed here.
4918
4919 Assert(FPI.getExceptionBehavior().hasValue(),do { if (!(FPI.getExceptionBehavior().hasValue())) { CheckFailed
("invalid exception behavior argument", &FPI); return; } }
while (false)
4920 "invalid exception behavior argument", &FPI)do { if (!(FPI.getExceptionBehavior().hasValue())) { CheckFailed
("invalid exception behavior argument", &FPI); return; } }
while (false)
;
4921 if (HasRoundingMD) {
4922 Assert(FPI.getRoundingMode().hasValue(),do { if (!(FPI.getRoundingMode().hasValue())) { CheckFailed("invalid rounding mode argument"
, &FPI); return; } } while (false)
4923 "invalid rounding mode argument", &FPI)do { if (!(FPI.getRoundingMode().hasValue())) { CheckFailed("invalid rounding mode argument"
, &FPI); return; } } while (false)
;
4924 }
4925}
4926
4927void Verifier::visitDbgIntrinsic(StringRef Kind, DbgVariableIntrinsic &DII) {
4928 auto *MD = cast<MetadataAsValue>(DII.getArgOperand(0))->getMetadata();
4929 AssertDI(isa<ValueAsMetadata>(MD) ||do { if (!(isa<ValueAsMetadata>(MD) || (isa<MDNode>
(MD) && !cast<MDNode>(MD)->getNumOperands())
)) { DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic address/value"
, &DII, MD); return; } } while (false)
4930 (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands()),do { if (!(isa<ValueAsMetadata>(MD) || (isa<MDNode>
(MD) && !cast<MDNode>(MD)->getNumOperands())
)) { DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic address/value"
, &DII, MD); return; } } while (false)
4931 "invalid llvm.dbg." + Kind + " intrinsic address/value", &DII, MD)do { if (!(isa<ValueAsMetadata>(MD) || (isa<MDNode>
(MD) && !cast<MDNode>(MD)->getNumOperands())
)) { DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic address/value"
, &DII, MD); return; } } while (false)
;
4932 AssertDI(isa<DILocalVariable>(DII.getRawVariable()),do { if (!(isa<DILocalVariable>(DII.getRawVariable())))
{ DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic variable"
, &DII, DII.getRawVariable()); return; } } while (false)
4933 "invalid llvm.dbg." + Kind + " intrinsic variable", &DII,do { if (!(isa<DILocalVariable>(DII.getRawVariable())))
{ DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic variable"
, &DII, DII.getRawVariable()); return; } } while (false)
4934 DII.getRawVariable())do { if (!(isa<DILocalVariable>(DII.getRawVariable())))
{ DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic variable"
, &DII, DII.getRawVariable()); return; } } while (false)
;
4935 AssertDI(isa<DIExpression>(DII.getRawExpression()),do { if (!(isa<DIExpression>(DII.getRawExpression()))) {
DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic expression"
, &DII, DII.getRawExpression()); return; } } while (false
)
4936 "invalid llvm.dbg." + Kind + " intrinsic expression", &DII,do { if (!(isa<DIExpression>(DII.getRawExpression()))) {
DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic expression"
, &DII, DII.getRawExpression()); return; } } while (false
)
4937 DII.getRawExpression())do { if (!(isa<DIExpression>(DII.getRawExpression()))) {
DebugInfoCheckFailed("invalid llvm.dbg." + Kind + " intrinsic expression"
, &DII, DII.getRawExpression()); return; } } while (false
)
;
4938
4939 // Ignore broken !dbg attachments; they're checked elsewhere.
4940 if (MDNode *N = DII.getDebugLoc().getAsMDNode())
4941 if (!isa<DILocation>(N))
4942 return;
4943
4944 BasicBlock *BB = DII.getParent();
4945 Function *F = BB ? BB->getParent() : nullptr;
4946
4947 // The scopes for variables and !dbg attachments must agree.
4948 DILocalVariable *Var = DII.getVariable();
4949 DILocation *Loc = DII.getDebugLoc();
4950 AssertDI(Loc, "llvm.dbg." + Kind + " intrinsic requires a !dbg attachment",do { if (!(Loc)) { DebugInfoCheckFailed("llvm.dbg." + Kind + " intrinsic requires a !dbg attachment"
, &DII, BB, F); return; } } while (false)
4951 &DII, BB, F)do { if (!(Loc)) { DebugInfoCheckFailed("llvm.dbg." + Kind + " intrinsic requires a !dbg attachment"
, &DII, BB, F); return; } } while (false)
;
4952
4953 DISubprogram *VarSP = getSubprogram(Var->getRawScope());
4954 DISubprogram *LocSP = getSubprogram(Loc->getRawScope());
4955 if (!VarSP || !LocSP)
4956 return; // Broken scope chains are checked elsewhere.
4957
4958 AssertDI(VarSP == LocSP, "mismatched subprogram between llvm.dbg." + Kind +do { if (!(VarSP == LocSP)) { DebugInfoCheckFailed("mismatched subprogram between llvm.dbg."
+ Kind + " variable and !dbg attachment", &DII, BB, F, Var
, Var->getScope()->getSubprogram(), Loc, Loc->getScope
()->getSubprogram()); return; } } while (false)
4959 " variable and !dbg attachment",do { if (!(VarSP == LocSP)) { DebugInfoCheckFailed("mismatched subprogram between llvm.dbg."
+ Kind + " variable and !dbg attachment", &DII, BB, F, Var
, Var->getScope()->getSubprogram(), Loc, Loc->getScope
()->getSubprogram()); return; } } while (false)
4960 &DII, BB, F, Var, Var->getScope()->getSubprogram(), Loc,do { if (!(VarSP == LocSP)) { DebugInfoCheckFailed("mismatched subprogram between llvm.dbg."
+ Kind + " variable and !dbg attachment", &DII, BB, F, Var
, Var->getScope()->getSubprogram(), Loc, Loc->getScope
()->getSubprogram()); return; } } while (false)
4961 Loc->getScope()->getSubprogram())do { if (!(VarSP == LocSP)) { DebugInfoCheckFailed("mismatched subprogram between llvm.dbg."
+ Kind + " variable and !dbg attachment", &DII, BB, F, Var
, Var->getScope()->getSubprogram(), Loc, Loc->getScope
()->getSubprogram()); return; } } while (false)
;
4962
4963 // This check is redundant with one in visitLocalVariable().
4964 AssertDI(isType(Var->getRawType()), "invalid type ref", Var,do { if (!(isType(Var->getRawType()))) { DebugInfoCheckFailed
("invalid type ref", Var, Var->getRawType()); return; } } while
(false)
4965 Var->getRawType())do { if (!(isType(Var->getRawType()))) { DebugInfoCheckFailed
("invalid type ref", Var, Var->getRawType()); return; } } while
(false)
;
4966 verifyFnArgs(DII);
4967}
4968
4969void Verifier::visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI) {
4970 AssertDI(isa<DILabel>(DLI.getRawLabel()),do { if (!(isa<DILabel>(DLI.getRawLabel()))) { DebugInfoCheckFailed
("invalid llvm.dbg." + Kind + " intrinsic variable", &DLI
, DLI.getRawLabel()); return; } } while (false)
4971 "invalid llvm.dbg." + Kind + " intrinsic variable", &DLI,do { if (!(isa<DILabel>(DLI.getRawLabel()))) { DebugInfoCheckFailed
("invalid llvm.dbg." + Kind + " intrinsic variable", &DLI
, DLI.getRawLabel()); return; } } while (false)
4972 DLI.getRawLabel())do { if (!(isa<DILabel>(DLI.getRawLabel()))) { DebugInfoCheckFailed
("invalid llvm.dbg." + Kind + " intrinsic variable", &DLI
, DLI.getRawLabel()); return; } } while (false)
;
4973
4974 // Ignore broken !dbg attachments; they're checked elsewhere.
4975 if (MDNode *N = DLI.getDebugLoc().getAsMDNode())
4976 if (!isa<DILocation>(N))
4977 return;
4978
4979 BasicBlock *BB = DLI.getParent();
4980 Function *F = BB ? BB->getParent() : nullptr;
4981
4982 // The scopes for variables and !dbg attachments must agree.
4983 DILabel *Label = DLI.getLabel();
4984 DILocation *Loc = DLI.getDebugLoc();
4985 Assert(Loc, "llvm.dbg." + Kind + " intrinsic requires a !dbg attachment",do { if (!(Loc)) { CheckFailed("llvm.dbg." + Kind + " intrinsic requires a !dbg attachment"
, &DLI, BB, F); return; } } while (false)
4986 &DLI, BB, F)do { if (!(Loc)) { CheckFailed("llvm.dbg." + Kind + " intrinsic requires a !dbg attachment"
, &DLI, BB, F); return; } } while (false)
;
4987
4988 DISubprogram *LabelSP = getSubprogram(Label->getRawScope());
4989 DISubprogram *LocSP = getSubprogram(Loc->getRawScope());
4990 if (!LabelSP || !LocSP)
4991 return;
4992
4993 AssertDI(LabelSP == LocSP, "mismatched subprogram between llvm.dbg." + Kind +do { if (!(LabelSP == LocSP)) { DebugInfoCheckFailed("mismatched subprogram between llvm.dbg."
+ Kind + " label and !dbg attachment", &DLI, BB, F, Label
, Label->getScope()->getSubprogram(), Loc, Loc->getScope
()->getSubprogram()); return; } } while (false)
4994 " label and !dbg attachment",do { if (!(LabelSP == LocSP)) { DebugInfoCheckFailed("mismatched subprogram between llvm.dbg."
+ Kind + " label and !dbg attachment", &DLI, BB, F, Label
, Label->getScope()->getSubprogram(), Loc, Loc->getScope
()->getSubprogram()); return; } } while (false)
4995 &DLI, BB, F, Label, Label->getScope()->getSubprogram(), Loc,do { if (!(LabelSP == LocSP)) { DebugInfoCheckFailed("mismatched subprogram between llvm.dbg."
+ Kind + " label and !dbg attachment", &DLI, BB, F, Label
, Label->getScope()->getSubprogram(), Loc, Loc->getScope
()->getSubprogram()); return; } } while (false)
4996 Loc->getScope()->getSubprogram())do { if (!(LabelSP == LocSP)) { DebugInfoCheckFailed("mismatched subprogram between llvm.dbg."
+ Kind + " label and !dbg attachment", &DLI, BB, F, Label
, Label->getScope()->getSubprogram(), Loc, Loc->getScope
()->getSubprogram()); return; } } while (false)
;
4997}
4998
4999void Verifier::verifyFragmentExpression(const DbgVariableIntrinsic &I) {
5000 DILocalVariable *V = dyn_cast_or_null<DILocalVariable>(I.getRawVariable());
5001 DIExpression *E = dyn_cast_or_null<DIExpression>(I.getRawExpression());
5002
5003 // We don't know whether this intrinsic verified correctly.
5004 if (!V || !E || !E->isValid())
5005 return;
5006
5007 // Nothing to do if this isn't a DW_OP_LLVM_fragment expression.
5008 auto Fragment = E->getFragmentInfo();
5009 if (!Fragment)
5010 return;
5011
5012 // The frontend helps out GDB by emitting the members of local anonymous
5013 // unions as artificial local variables with shared storage. When SROA splits
5014 // the storage for artificial local variables that are smaller than the entire
5015 // union, the overhang piece will be outside of the allotted space for the
5016 // variable and this check fails.
5017 // FIXME: Remove this check as soon as clang stops doing this; it hides bugs.
5018 if (V->isArtificial())
5019 return;
5020
5021 verifyFragmentExpression(*V, *Fragment, &I);
5022}
5023
5024template <typename ValueOrMetadata>
5025void Verifier::verifyFragmentExpression(const DIVariable &V,
5026 DIExpression::FragmentInfo Fragment,
5027 ValueOrMetadata *Desc) {
5028 // If there's no size, the type is broken, but that should be checked
5029 // elsewhere.
5030 auto VarSize = V.getSizeInBits();
5031 if (!VarSize)
5032 return;
5033
5034 unsigned FragSize = Fragment.SizeInBits;
5035 unsigned FragOffset = Fragment.OffsetInBits;
5036 AssertDI(FragSize + FragOffset <= *VarSize,do { if (!(FragSize + FragOffset <= *VarSize)) { DebugInfoCheckFailed
("fragment is larger than or outside of variable", Desc, &
V); return; } } while (false)
5037 "fragment is larger than or outside of variable", Desc, &V)do { if (!(FragSize + FragOffset <= *VarSize)) { DebugInfoCheckFailed
("fragment is larger than or outside of variable", Desc, &
V); return; } } while (false)
;
5038 AssertDI(FragSize != *VarSize, "fragment covers entire variable", Desc, &V)do { if (!(FragSize != *VarSize)) { DebugInfoCheckFailed("fragment covers entire variable"
, Desc, &V); return; } } while (false)
;
5039}
5040
5041void Verifier::verifyFnArgs(const DbgVariableIntrinsic &I) {
5042 // This function does not take the scope of noninlined function arguments into
5043 // account. Don't run it if current function is nodebug, because it may
5044 // contain inlined debug intrinsics.
5045 if (!HasDebugInfo)
5046 return;
5047
5048 // For performance reasons only check non-inlined ones.
5049 if (I.getDebugLoc()->getInlinedAt())
5050 return;
5051
5052 DILocalVariable *Var = I.getVariable();
5053 AssertDI(Var, "dbg intrinsic without variable")do { if (!(Var)) { DebugInfoCheckFailed("dbg intrinsic without variable"
); return; } } while (false)
;
5054
5055 unsigned ArgNo = Var->getArg();
5056 if (!ArgNo)
5057 return;
5058
5059 // Verify there are no duplicate function argument debug info entries.
5060 // These will cause hard-to-debug assertions in the DWARF backend.
5061 if (DebugFnArgs.size() < ArgNo)
5062 DebugFnArgs.resize(ArgNo, nullptr);
5063
5064 auto *Prev = DebugFnArgs[ArgNo - 1];
5065 DebugFnArgs[ArgNo - 1] = Var;
5066 AssertDI(!Prev || (Prev == Var), "conflicting debug info for argument", &I,do { if (!(!Prev || (Prev == Var))) { DebugInfoCheckFailed("conflicting debug info for argument"
, &I, Prev, Var); return; } } while (false)
5067 Prev, Var)do { if (!(!Prev || (Prev == Var))) { DebugInfoCheckFailed("conflicting debug info for argument"
, &I, Prev, Var); return; } } while (false)
;
5068}
5069
5070void Verifier::verifyNotEntryValue(const DbgVariableIntrinsic &I) {
5071 DIExpression *E = dyn_cast_or_null<DIExpression>(I.getRawExpression());
5072
5073 // We don't know whether this intrinsic verified correctly.
5074 if (!E || !E->isValid())
5075 return;
5076
5077 AssertDI(!E->isEntryValue(), "Entry values are only allowed in MIR", &I)do { if (!(!E->isEntryValue())) { DebugInfoCheckFailed("Entry values are only allowed in MIR"
, &I); return; } } while (false)
;
5078}
5079
5080void Verifier::verifyCompileUnits() {
5081 // When more than one Module is imported into the same context, such as during
5082 // an LTO build before linking the modules, ODR type uniquing may cause types
5083 // to point to a different CU. This check does not make sense in this case.
5084 if (M.getContext().isODRUniquingDebugTypes())
5085 return;
5086 auto *CUs = M.getNamedMetadata("llvm.dbg.cu");
5087 SmallPtrSet<const Metadata *, 2> Listed;
5088 if (CUs)
5089 Listed.insert(CUs->op_begin(), CUs->op_end());
5090 for (auto *CU : CUVisited)
5091 AssertDI(Listed.count(CU), "DICompileUnit not listed in llvm.dbg.cu", CU)do { if (!(Listed.count(CU))) { DebugInfoCheckFailed("DICompileUnit not listed in llvm.dbg.cu"
, CU); return; } } while (false)
;
5092 CUVisited.clear();
5093}
5094
5095void Verifier::verifyDeoptimizeCallingConvs() {
5096 if (DeoptimizeDeclarations.empty())
5097 return;
5098
5099 const Function *First = DeoptimizeDeclarations[0];
5100 for (auto *F : makeArrayRef(DeoptimizeDeclarations).slice(1)) {
5101 Assert(First->getCallingConv() == F->getCallingConv(),do { if (!(First->getCallingConv() == F->getCallingConv
())) { CheckFailed("All llvm.experimental.deoptimize declarations must have the same "
"calling convention", First, F); return; } } while (false)
5102 "All llvm.experimental.deoptimize declarations must have the same "do { if (!(First->getCallingConv() == F->getCallingConv
())) { CheckFailed("All llvm.experimental.deoptimize declarations must have the same "
"calling convention", First, F); return; } } while (false)
5103 "calling convention",do { if (!(First->getCallingConv() == F->getCallingConv
())) { CheckFailed("All llvm.experimental.deoptimize declarations must have the same "
"calling convention", First, F); return; } } while (false)
5104 First, F)do { if (!(First->getCallingConv() == F->getCallingConv
())) { CheckFailed("All llvm.experimental.deoptimize declarations must have the same "
"calling convention", First, F); return; } } while (false)
;
5105 }
5106}
5107
5108void Verifier::verifySourceDebugInfo(const DICompileUnit &U, const DIFile &F) {
5109 bool HasSource = F.getSource().hasValue();
5110 if (!HasSourceDebugInfo.count(&U))
5111 HasSourceDebugInfo[&U] = HasSource;
5112 AssertDI(HasSource == HasSourceDebugInfo[&U],do { if (!(HasSource == HasSourceDebugInfo[&U])) { DebugInfoCheckFailed
("inconsistent use of embedded source"); return; } } while (false
)
5113 "inconsistent use of embedded source")do { if (!(HasSource == HasSourceDebugInfo[&U])) { DebugInfoCheckFailed
("inconsistent use of embedded source"); return; } } while (false
)
;
5114}
5115
5116//===----------------------------------------------------------------------===//
5117// Implement the public interfaces to this file...
5118//===----------------------------------------------------------------------===//
5119
5120bool llvm::verifyFunction(const Function &f, raw_ostream *OS) {
5121 Function &F = const_cast<Function &>(f);
5122
5123 // Don't use a raw_null_ostream. Printing IR is expensive.
5124 Verifier V(OS, /*ShouldTreatBrokenDebugInfoAsError=*/true, *f.getParent());
5125
5126 // Note that this function's return value is inverted from what you would
5127 // expect of a function called "verify".
5128 return !V.verify(F);
5129}
5130
5131bool llvm::verifyModule(const Module &M, raw_ostream *OS,
5132 bool *BrokenDebugInfo) {
5133 // Don't use a raw_null_ostream. Printing IR is expensive.
5134 Verifier V(OS, /*ShouldTreatBrokenDebugInfoAsError=*/!BrokenDebugInfo, M);
5135
5136 bool Broken = false;
5137 for (const Function &F : M)
5138 Broken |= !V.verify(F);
5139
5140 Broken |= !V.verify();
5141 if (BrokenDebugInfo)
5142 *BrokenDebugInfo = V.hasBrokenDebugInfo();
5143 // Note that this function's return value is inverted from what you would
5144 // expect of a function called "verify".
5145 return Broken;
5146}
5147
5148namespace {
5149
5150struct VerifierLegacyPass : public FunctionPass {
5151 static char ID;
5152
5153 std::unique_ptr<Verifier> V;
5154 bool FatalErrors = true;
5155
5156 VerifierLegacyPass() : FunctionPass(ID) {
5157 initializeVerifierLegacyPassPass(*PassRegistry::getPassRegistry());
5158 }
5159 explicit VerifierLegacyPass(bool FatalErrors)
5160 : FunctionPass(ID),
5161 FatalErrors(FatalErrors) {
5162 initializeVerifierLegacyPassPass(*PassRegistry::getPassRegistry());
5163 }
5164
5165 bool doInitialization(Module &M) override {
5166 V = std::make_unique<Verifier>(
5167 &dbgs(), /*ShouldTreatBrokenDebugInfoAsError=*/false, M);
5168 return false;
5169 }
5170
5171 bool runOnFunction(Function &F) override {
5172 if (!V->verify(F) && FatalErrors) {
5173 errs() << "in function " << F.getName() << '\n';
5174 report_fatal_error("Broken function found, compilation aborted!");
5175 }
5176 return false;
5177 }
5178
5179 bool doFinalization(Module &M) override {
5180 bool HasErrors = false;
5181 for (Function &F : M)
5182 if (F.isDeclaration())
5183 HasErrors |= !V->verify(F);
5184
5185 HasErrors |= !V->verify();
5186 if (FatalErrors && (HasErrors || V->hasBrokenDebugInfo()))
5187 report_fatal_error("Broken module found, compilation aborted!");
5188 return false;
5189 }
5190
5191 void getAnalysisUsage(AnalysisUsage &AU) const override {
5192 AU.setPreservesAll();
5193 }
5194};
5195
5196} // end anonymous namespace
5197
5198/// Helper to issue failure from the TBAA verification
5199template <typename... Tys> void TBAAVerifier::CheckFailed(Tys &&... Args) {
5200 if (Diagnostic)
5201 return Diagnostic->CheckFailed(Args...);
5202}
5203
5204#define AssertTBAA(C, ...)do { if (!(C)) { CheckFailed(...); return false; } } while (false
)
\
5205 do { \
5206 if (!(C)) { \
5207 CheckFailed(__VA_ARGS__); \
5208 return false; \
5209 } \
5210 } while (false)
5211
5212/// Verify that \p BaseNode can be used as the "base type" in the struct-path
5213/// TBAA scheme. This means \p BaseNode is either a scalar node, or a
5214/// struct-type node describing an aggregate data structure (like a struct).
5215TBAAVerifier::TBAABaseNodeSummary
5216TBAAVerifier::verifyTBAABaseNode(Instruction &I, const MDNode *BaseNode,
5217 bool IsNewFormat) {
5218 if (BaseNode->getNumOperands() < 2) {
5219 CheckFailed("Base nodes must have at least two operands", &I, BaseNode);
5220 return {true, ~0u};
5221 }
5222
5223 auto Itr = TBAABaseNodes.find(BaseNode);
5224 if (Itr != TBAABaseNodes.end())
5225 return Itr->second;
5226
5227 auto Result = verifyTBAABaseNodeImpl(I, BaseNode, IsNewFormat);
5228 auto InsertResult = TBAABaseNodes.insert({BaseNode, Result});
5229 (void)InsertResult;
5230 assert(InsertResult.second && "We just checked!")((InsertResult.second && "We just checked!") ? static_cast
<void> (0) : __assert_fail ("InsertResult.second && \"We just checked!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 5230, __PRETTY_FUNCTION__))
;
5231 return Result;
5232}
5233
5234TBAAVerifier::TBAABaseNodeSummary
5235TBAAVerifier::verifyTBAABaseNodeImpl(Instruction &I, const MDNode *BaseNode,
5236 bool IsNewFormat) {
5237 const TBAAVerifier::TBAABaseNodeSummary InvalidNode = {true, ~0u};
5238
5239 if (BaseNode->getNumOperands() == 2) {
5240 // Scalar nodes can only be accessed at offset 0.
5241 return isValidScalarTBAANode(BaseNode)
5242 ? TBAAVerifier::TBAABaseNodeSummary({false, 0})
5243 : InvalidNode;
5244 }
5245
5246 if (IsNewFormat) {
5247 if (BaseNode->getNumOperands() % 3 != 0) {
5248 CheckFailed("Access tag nodes must have the number of operands that is a "
5249 "multiple of 3!", BaseNode);
5250 return InvalidNode;
5251 }
5252 } else {
5253 if (BaseNode->getNumOperands() % 2 != 1) {
5254 CheckFailed("Struct tag nodes must have an odd number of operands!",
5255 BaseNode);
5256 return InvalidNode;
5257 }
5258 }
5259
5260 // Check the type size field.
5261 if (IsNewFormat) {
5262 auto *TypeSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
5263 BaseNode->getOperand(1));
5264 if (!TypeSizeNode) {
5265 CheckFailed("Type size nodes must be constants!", &I, BaseNode);
5266 return InvalidNode;
5267 }
5268 }
5269
5270 // Check the type name field. In the new format it can be anything.
5271 if (!IsNewFormat && !isa<MDString>(BaseNode->getOperand(0))) {
5272 CheckFailed("Struct tag nodes have a string as their first operand",
5273 BaseNode);
5274 return InvalidNode;
5275 }
5276
5277 bool Failed = false;
5278
5279 Optional<APInt> PrevOffset;
5280 unsigned BitWidth = ~0u;
5281
5282 // We've already checked that BaseNode is not a degenerate root node with one
5283 // operand in \c verifyTBAABaseNode, so this loop should run at least once.
5284 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
5285 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
5286 for (unsigned Idx = FirstFieldOpNo; Idx < BaseNode->getNumOperands();
5287 Idx += NumOpsPerField) {
5288 const MDOperand &FieldTy = BaseNode->getOperand(Idx);
5289 const MDOperand &FieldOffset = BaseNode->getOperand(Idx + 1);
5290 if (!isa<MDNode>(FieldTy)) {
5291 CheckFailed("Incorrect field entry in struct type node!", &I, BaseNode);
5292 Failed = true;
5293 continue;
5294 }
5295
5296 auto *OffsetEntryCI =
5297 mdconst::dyn_extract_or_null<ConstantInt>(FieldOffset);
5298 if (!OffsetEntryCI) {
5299 CheckFailed("Offset entries must be constants!", &I, BaseNode);
5300 Failed = true;
5301 continue;
5302 }
5303
5304 if (BitWidth == ~0u)
5305 BitWidth = OffsetEntryCI->getBitWidth();
5306
5307 if (OffsetEntryCI->getBitWidth() != BitWidth) {
5308 CheckFailed(
5309 "Bitwidth between the offsets and struct type entries must match", &I,
5310 BaseNode);
5311 Failed = true;
5312 continue;
5313 }
5314
5315 // NB! As far as I can tell, we generate a non-strictly increasing offset
5316 // sequence only from structs that have zero size bit fields. When
5317 // recursing into a contained struct in \c getFieldNodeFromTBAABaseNode we
5318 // pick the field lexically the latest in struct type metadata node. This
5319 // mirrors the actual behavior of the alias analysis implementation.
5320 bool IsAscending =
5321 !PrevOffset || PrevOffset->ule(OffsetEntryCI->getValue());
5322
5323 if (!IsAscending) {
5324 CheckFailed("Offsets must be increasing!", &I, BaseNode);
5325 Failed = true;
5326 }
5327
5328 PrevOffset = OffsetEntryCI->getValue();
5329
5330 if (IsNewFormat) {
5331 auto *MemberSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
5332 BaseNode->getOperand(Idx + 2));
5333 if (!MemberSizeNode) {
5334 CheckFailed("Member size entries must be constants!", &I, BaseNode);
5335 Failed = true;
5336 continue;
5337 }
5338 }
5339 }
5340
5341 return Failed ? InvalidNode
5342 : TBAAVerifier::TBAABaseNodeSummary(false, BitWidth);
5343}
5344
5345static bool IsRootTBAANode(const MDNode *MD) {
5346 return MD->getNumOperands() < 2;
5347}
5348
5349static bool IsScalarTBAANodeImpl(const MDNode *MD,
5350 SmallPtrSetImpl<const MDNode *> &Visited) {
5351 if (MD->getNumOperands() != 2 && MD->getNumOperands() != 3)
5352 return false;
5353
5354 if (!isa<MDString>(MD->getOperand(0)))
5355 return false;
5356
5357 if (MD->getNumOperands() == 3) {
5358 auto *Offset = mdconst::dyn_extract<ConstantInt>(MD->getOperand(2));
5359 if (!(Offset && Offset->isZero() && isa<MDString>(MD->getOperand(0))))
5360 return false;
5361 }
5362
5363 auto *Parent = dyn_cast_or_null<MDNode>(MD->getOperand(1));
5364 return Parent && Visited.insert(Parent).second &&
5365 (IsRootTBAANode(Parent) || IsScalarTBAANodeImpl(Parent, Visited));
5366}
5367
5368bool TBAAVerifier::isValidScalarTBAANode(const MDNode *MD) {
5369 auto ResultIt = TBAAScalarNodes.find(MD);
5370 if (ResultIt != TBAAScalarNodes.end())
5371 return ResultIt->second;
5372
5373 SmallPtrSet<const MDNode *, 4> Visited;
5374 bool Result = IsScalarTBAANodeImpl(MD, Visited);
5375 auto InsertResult = TBAAScalarNodes.insert({MD, Result});
5376 (void)InsertResult;
5377 assert(InsertResult.second && "Just checked!")((InsertResult.second && "Just checked!") ? static_cast
<void> (0) : __assert_fail ("InsertResult.second && \"Just checked!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 5377, __PRETTY_FUNCTION__))
;
5378
5379 return Result;
5380}
5381
5382/// Returns the field node at the offset \p Offset in \p BaseNode. Update \p
5383/// Offset in place to be the offset within the field node returned.
5384///
5385/// We assume we've okayed \p BaseNode via \c verifyTBAABaseNode.
5386MDNode *TBAAVerifier::getFieldNodeFromTBAABaseNode(Instruction &I,
5387 const MDNode *BaseNode,
5388 APInt &Offset,
5389 bool IsNewFormat) {
5390 assert(BaseNode->getNumOperands() >= 2 && "Invalid base node!")((BaseNode->getNumOperands() >= 2 && "Invalid base node!"
) ? static_cast<void> (0) : __assert_fail ("BaseNode->getNumOperands() >= 2 && \"Invalid base node!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Verifier.cpp"
, 5390, __PRETTY_FUNCTION__))
;
5391
5392 // Scalar nodes have only one possible "field" -- their parent in the access
5393 // hierarchy. Offset must be zero at this point, but our caller is supposed
5394 // to Assert that.
5395 if (BaseNode->getNumOperands() == 2)
5396 return cast<MDNode>(BaseNode->getOperand(1));
5397
5398 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
5399 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
5400 for (unsigned Idx = FirstFieldOpNo; Idx < BaseNode->getNumOperands();
5401 Idx += NumOpsPerField) {
5402 auto *OffsetEntryCI =
5403 mdconst::extract<ConstantInt>(BaseNode->getOperand(Idx + 1));
5404 if (OffsetEntryCI->getValue().ugt(Offset)) {
5405 if (Idx == FirstFieldOpNo) {
5406 CheckFailed("Could not find TBAA parent in struct type node", &I,
5407 BaseNode, &Offset);
5408 return nullptr;
5409 }
5410
5411 unsigned PrevIdx = Idx - NumOpsPerField;
5412 auto *PrevOffsetEntryCI =
5413 mdconst::extract<ConstantInt>(BaseNode->getOperand(PrevIdx + 1));
5414 Offset -= PrevOffsetEntryCI->getValue();
5415 return cast<MDNode>(BaseNode->getOperand(PrevIdx));
5416 }
5417 }
5418
5419 unsigned LastIdx = BaseNode->getNumOperands() - NumOpsPerField;
5420 auto *LastOffsetEntryCI = mdconst::extract<ConstantInt>(
5421 BaseNode->getOperand(LastIdx + 1));
5422 Offset -= LastOffsetEntryCI->getValue();
5423 return cast<MDNode>(BaseNode->getOperand(LastIdx));
5424}
5425
5426static bool isNewFormatTBAATypeNode(llvm::MDNode *Type) {
5427 if (!Type || Type->getNumOperands() < 3)
5428 return false;
5429
5430 // In the new format type nodes shall have a reference to the parent type as
5431 // its first operand.
5432 MDNode *Parent = dyn_cast_or_null<MDNode>(Type->getOperand(0));
5433 if (!Parent)
5434 return false;
5435
5436 return true;
5437}
5438
5439bool TBAAVerifier::visitTBAAMetadata(Instruction &I, const MDNode *MD) {
5440 AssertTBAA(isa<LoadInst>(I) || isa<StoreInst>(I) || isa<CallInst>(I) ||do { if (!(isa<LoadInst>(I) || isa<StoreInst>(I) ||
isa<CallInst>(I) || isa<VAArgInst>(I) || isa<
AtomicRMWInst>(I) || isa<AtomicCmpXchgInst>(I))) { CheckFailed
("This instruction shall not have a TBAA access tag!", &I
); return false; } } while (false)
5441 isa<VAArgInst>(I) || isa<AtomicRMWInst>(I) ||do { if (!(isa<LoadInst>(I) || isa<StoreInst>(I) ||
isa<CallInst>(I) || isa<VAArgInst>(I) || isa<
AtomicRMWInst>(I) || isa<AtomicCmpXchgInst>(I))) { CheckFailed
("This instruction shall not have a TBAA access tag!", &I
); return false; } } while (false)
5442 isa<AtomicCmpXchgInst>(I),do { if (!(isa<LoadInst>(I) || isa<StoreInst>(I) ||
isa<CallInst>(I) || isa<VAArgInst>(I) || isa<
AtomicRMWInst>(I) || isa<AtomicCmpXchgInst>(I))) { CheckFailed
("This instruction shall not have a TBAA access tag!", &I
); return false; } } while (false)
5443 "This instruction shall not have a TBAA access tag!", &I)do { if (!(isa<LoadInst>(I) || isa<StoreInst>(I) ||
isa<CallInst>(I) || isa<VAArgInst>(I) || isa<
AtomicRMWInst>(I) || isa<AtomicCmpXchgInst>(I))) { CheckFailed
("This instruction shall not have a TBAA access tag!", &I
); return false; } } while (false)
;
5444
5445 bool IsStructPathTBAA =
5446 isa<MDNode>(MD->getOperand(0)) && MD->getNumOperands() >= 3;
5447
5448 AssertTBAA(do { if (!(IsStructPathTBAA)) { CheckFailed("Old-style TBAA is no longer allowed, use struct-path TBAA instead"
, &I); return false; } } while (false)
5449 IsStructPathTBAA,do { if (!(IsStructPathTBAA)) { CheckFailed("Old-style TBAA is no longer allowed, use struct-path TBAA instead"
, &I); return false; } } while (false)
5450 "Old-style TBAA is no longer allowed, use struct-path TBAA instead", &I)do { if (!(IsStructPathTBAA)) { CheckFailed("Old-style TBAA is no longer allowed, use struct-path TBAA instead"
, &I); return false; } } while (false)
;
5451
5452 MDNode *BaseNode = dyn_cast_or_null<MDNode>(MD->getOperand(0));
5453 MDNode *AccessType = dyn_cast_or_null<MDNode>(MD->getOperand(1));
5454
5455 bool IsNewFormat = isNewFormatTBAATypeNode(AccessType);
5456
5457 if (IsNewFormat) {
5458 AssertTBAA(MD->getNumOperands() == 4 || MD->getNumOperands() == 5,do { if (!(MD->getNumOperands() == 4 || MD->getNumOperands
() == 5)) { CheckFailed("Access tag metadata must have either 4 or 5 operands"
, &I, MD); return false; } } while (false)
5459 "Access tag metadata must have either 4 or 5 operands", &I, MD)do { if (!(MD->getNumOperands() == 4 || MD->getNumOperands
() == 5)) { CheckFailed("Access tag metadata must have either 4 or 5 operands"
, &I, MD); return false; } } while (false)
;
5460 } else {
5461 AssertTBAA(MD->getNumOperands() < 5,do { if (!(MD->getNumOperands() < 5)) { CheckFailed("Struct tag metadata must have either 3 or 4 operands"
, &I, MD); return false; } } while (false)
5462 "Struct tag metadata must have either 3 or 4 operands", &I, MD)do { if (!(MD->getNumOperands() < 5)) { CheckFailed("Struct tag metadata must have either 3 or 4 operands"
, &I, MD); return false; } } while (false)
;
5463 }
5464
5465 // Check the access size field.
5466 if (IsNewFormat) {
5467 auto *AccessSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
5468 MD->getOperand(3));
5469 AssertTBAA(AccessSizeNode, "Access size field must be a constant", &I, MD)do { if (!(AccessSizeNode)) { CheckFailed("Access size field must be a constant"
, &I, MD); return false; } } while (false)
;
5470 }
5471
5472 // Check the immutability flag.
5473 unsigned ImmutabilityFlagOpNo = IsNewFormat ? 4 : 3;
5474 if (MD->getNumOperands() == ImmutabilityFlagOpNo + 1) {
5475 auto *IsImmutableCI = mdconst::dyn_extract_or_null<ConstantInt>(
5476 MD->getOperand(ImmutabilityFlagOpNo));
5477 AssertTBAA(IsImmutableCI,do { if (!(IsImmutableCI)) { CheckFailed("Immutability tag on struct tag metadata must be a constant"
, &I, MD); return false; } } while (false)
5478 "Immutability tag on struct tag metadata must be a constant",do { if (!(IsImmutableCI)) { CheckFailed("Immutability tag on struct tag metadata must be a constant"
, &I, MD); return false; } } while (false)
5479 &I, MD)do { if (!(IsImmutableCI)) { CheckFailed("Immutability tag on struct tag metadata must be a constant"
, &I, MD); return false; } } while (false)
;
5480 AssertTBAA(do { if (!(IsImmutableCI->isZero() || IsImmutableCI->isOne
())) { CheckFailed("Immutability part of the struct tag metadata must be either 0 or 1"
, &I, MD); return false; } } while (false)
5481 IsImmutableCI->isZero() || IsImmutableCI->isOne(),do { if (!(IsImmutableCI->isZero() || IsImmutableCI->isOne
())) { CheckFailed("Immutability part of the struct tag metadata must be either 0 or 1"
, &I, MD); return false; } } while (false)
5482 "Immutability part of the struct tag metadata must be either 0 or 1",do { if (!(IsImmutableCI->isZero() || IsImmutableCI->isOne
())) { CheckFailed("Immutability part of the struct tag metadata must be either 0 or 1"
, &I, MD); return false; } } while (false)
5483 &I, MD)do { if (!(IsImmutableCI->isZero() || IsImmutableCI->isOne
())) { CheckFailed("Immutability part of the struct tag metadata must be either 0 or 1"
, &I, MD); return false; } } while (false)
;
5484 }
5485
5486 AssertTBAA(BaseNode && AccessType,do { if (!(BaseNode && AccessType)) { CheckFailed("Malformed struct tag metadata: base and access-type "
"should be non-null and point to Metadata nodes", &I, MD
, BaseNode, AccessType); return false; } } while (false)
5487 "Malformed struct tag metadata: base and access-type "do { if (!(BaseNode && AccessType)) { CheckFailed("Malformed struct tag metadata: base and access-type "
"should be non-null and point to Metadata nodes", &I, MD
, BaseNode, AccessType); return false; } } while (false)
5488 "should be non-null and point to Metadata nodes",do { if (!(BaseNode && AccessType)) { CheckFailed("Malformed struct tag metadata: base and access-type "
"should be non-null and point to Metadata nodes", &I, MD
, BaseNode, AccessType); return false; } } while (false)
5489 &I, MD, BaseNode, AccessType)do { if (!(BaseNode && AccessType)) { CheckFailed("Malformed struct tag metadata: base and access-type "
"should be non-null and point to Metadata nodes", &I, MD
, BaseNode, AccessType); return false; } } while (false)
;
5490
5491 if (!IsNewFormat) {
5492 AssertTBAA(isValidScalarTBAANode(AccessType),do { if (!(isValidScalarTBAANode(AccessType))) { CheckFailed(
"Access type node must be a valid scalar type", &I, MD, AccessType
); return false; } } while (false)
5493 "Access type node must be a valid scalar type", &I, MD,do { if (!(isValidScalarTBAANode(AccessType))) { CheckFailed(
"Access type node must be a valid scalar type", &I, MD, AccessType
); return false; } } while (false)
5494 AccessType)do { if (!(isValidScalarTBAANode(AccessType))) { CheckFailed(
"Access type node must be a valid scalar type", &I, MD, AccessType
); return false; } } while (false)
;
5495 }
5496
5497 auto *OffsetCI = mdconst::dyn_extract_or_null<ConstantInt>(MD->getOperand(2));
5498 AssertTBAA(OffsetCI, "Offset must be constant integer", &I, MD)do { if (!(OffsetCI)) { CheckFailed("Offset must be constant integer"
, &I, MD); return false; } } while (false)
;
5499
5500 APInt Offset = OffsetCI->getValue();
5501 bool SeenAccessTypeInPath = false;
5502
5503 SmallPtrSet<MDNode *, 4> StructPath;
5504
5505 for (/* empty */; BaseNode && !IsRootTBAANode(BaseNode);
5506 BaseNode = getFieldNodeFromTBAABaseNode(I, BaseNode, Offset,
5507 IsNewFormat)) {
5508 if (!StructPath.insert(BaseNode).second) {
5509 CheckFailed("Cycle detected in struct path", &I, MD);
5510 return false;
5511 }
5512
5513 bool Invalid;
5514 unsigned BaseNodeBitWidth;
5515 std::tie(Invalid, BaseNodeBitWidth) = verifyTBAABaseNode(I, BaseNode,
5516 IsNewFormat);
5517
5518 // If the base node is invalid in itself, then we've already printed all the
5519 // errors we wanted to print.
5520 if (Invalid)
5521 return false;
5522
5523 SeenAccessTypeInPath |= BaseNode == AccessType;
5524
5525 if (isValidScalarTBAANode(BaseNode) || BaseNode == AccessType)
5526 AssertTBAA(Offset == 0, "Offset not zero at the point of scalar access",do { if (!(Offset == 0)) { CheckFailed("Offset not zero at the point of scalar access"
, &I, MD, &Offset); return false; } } while (false)
5527 &I, MD, &Offset)do { if (!(Offset == 0)) { CheckFailed("Offset not zero at the point of scalar access"
, &I, MD, &Offset); return false; } } while (false)
;
5528
5529 AssertTBAA(BaseNodeBitWidth == Offset.getBitWidth() ||do { if (!(BaseNodeBitWidth == Offset.getBitWidth() || (BaseNodeBitWidth
== 0 && Offset == 0) || (IsNewFormat && BaseNodeBitWidth
== ~0u))) { CheckFailed("Access bit-width not the same as description bit-width"
, &I, MD, BaseNodeBitWidth, Offset.getBitWidth()); return
false; } } while (false)
5530 (BaseNodeBitWidth == 0 && Offset == 0) ||do { if (!(BaseNodeBitWidth == Offset.getBitWidth() || (BaseNodeBitWidth
== 0 && Offset == 0) || (IsNewFormat && BaseNodeBitWidth
== ~0u))) { CheckFailed("Access bit-width not the same as description bit-width"
, &I, MD, BaseNodeBitWidth, Offset.getBitWidth()); return
false; } } while (false)
5531 (IsNewFormat && BaseNodeBitWidth == ~0u),do { if (!(BaseNodeBitWidth == Offset.getBitWidth() || (BaseNodeBitWidth
== 0 && Offset == 0) || (IsNewFormat && BaseNodeBitWidth
== ~0u))) { CheckFailed("Access bit-width not the same as description bit-width"
, &I, MD, BaseNodeBitWidth, Offset.getBitWidth()); return
false; } } while (false)
5532 "Access bit-width not the same as description bit-width", &I, MD,do { if (!(BaseNodeBitWidth == Offset.getBitWidth() || (BaseNodeBitWidth
== 0 && Offset == 0) || (IsNewFormat && BaseNodeBitWidth
== ~0u))) { CheckFailed("Access bit-width not the same as description bit-width"
, &I, MD, BaseNodeBitWidth, Offset.getBitWidth()); return
false; } } while (false)
5533 BaseNodeBitWidth, Offset.getBitWidth())do { if (!(BaseNodeBitWidth == Offset.getBitWidth() || (BaseNodeBitWidth
== 0 && Offset == 0) || (IsNewFormat && BaseNodeBitWidth
== ~0u))) { CheckFailed("Access bit-width not the same as description bit-width"
, &I, MD, BaseNodeBitWidth, Offset.getBitWidth()); return
false; } } while (false)
;
5534
5535 if (IsNewFormat && SeenAccessTypeInPath)
5536 break;
5537 }
5538
5539 AssertTBAA(SeenAccessTypeInPath, "Did not see access type in access path!",do { if (!(SeenAccessTypeInPath)) { CheckFailed("Did not see access type in access path!"
, &I, MD); return false; } } while (false)
5540 &I, MD)do { if (!(SeenAccessTypeInPath)) { CheckFailed("Did not see access type in access path!"
, &I, MD); return false; } } while (false)
;
5541 return true;
5542}
5543
5544char VerifierLegacyPass::ID = 0;
5545INITIALIZE_PASS(VerifierLegacyPass, "verify", "Module Verifier", false, false)static void *initializeVerifierLegacyPassPassOnce(PassRegistry
&Registry) { PassInfo *PI = new PassInfo( "Module Verifier"
, "verify", &VerifierLegacyPass::ID, PassInfo::NormalCtor_t
(callDefaultCtor<VerifierLegacyPass>), false, false); Registry
.registerPass(*PI, true); return PI; } static llvm::once_flag
InitializeVerifierLegacyPassPassFlag; void llvm::initializeVerifierLegacyPassPass
(PassRegistry &Registry) { llvm::call_once(InitializeVerifierLegacyPassPassFlag
, initializeVerifierLegacyPassPassOnce, std::ref(Registry)); }
5546
5547FunctionPass *llvm::createVerifierPass(bool FatalErrors) {
5548 return new VerifierLegacyPass(FatalErrors);
5549}
5550
5551AnalysisKey VerifierAnalysis::Key;
5552VerifierAnalysis::Result VerifierAnalysis::run(Module &M,
5553 ModuleAnalysisManager &) {
5554 Result Res;
5555 Res.IRBroken = llvm::verifyModule(M, &dbgs(), &Res.DebugInfoBroken);
5556 return Res;
5557}
5558
5559VerifierAnalysis::Result VerifierAnalysis::run(Function &F,
5560 FunctionAnalysisManager &) {
5561 return { llvm::verifyFunction(F, &dbgs()), false };
5562}
5563
5564PreservedAnalyses VerifierPass::run(Module &M, ModuleAnalysisManager &AM) {
5565 auto Res = AM.getResult<VerifierAnalysis>(M);
5566 if (FatalErrors && (Res.IRBroken || Res.DebugInfoBroken))
5567 report_fatal_error("Broken module found, compilation aborted!");
5568
5569 return PreservedAnalyses::all();
5570}
5571
5572PreservedAnalyses VerifierPass::run(Function &F, FunctionAnalysisManager &AM) {
5573 auto res = AM.getResult<VerifierAnalysis>(F);
5574 if (res.IRBroken && FatalErrors)
5575 report_fatal_error("Broken function found, compilation aborted!");
5576
5577 return PreservedAnalyses::all();
5578}