Bug Summary

File:build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/llvm/lib/IR/Verifier.cpp
Warning:line 2747, column 5
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Verifier.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm -resource-dir /usr/lib/llvm-16/lib/clang/16.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I lib/IR -I /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/llvm/lib/IR -I include -I /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/llvm/include -D _FORTIFY_SOURCE=2 -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-16/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm=build-llvm -fmacro-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/= -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm=build-llvm -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/= -O3 -Wno-unused-command-line-argument -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -Wno-misleading-indentation -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm -fdebug-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm=build-llvm -fdebug-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/= -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-09-04-125545-48738-1 -x c++ /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/llvm/lib/IR/Verifier.cpp

/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/llvm/lib/IR/Verifier.cpp

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