File: | llvm/lib/IR/Verifier.cpp |
Warning: | line 2558, column 5 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===-- Verifier.cpp - Implement the Module Verifier -----------------------==// | ||||
2 | // | ||||
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
4 | // See https://llvm.org/LICENSE.txt for license information. | ||||
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
6 | // | ||||
7 | //===----------------------------------------------------------------------===// | ||||
8 | // | ||||
9 | // This file defines the function verifier interface, that can be used for some | ||||
10 | // sanity checking of input to the system. | ||||
11 | // | ||||
12 | // Note that this does not provide full `Java style' security and verifications, | ||||
13 | // instead it just tries to ensure that code is well-formed. | ||||
14 | // | ||||
15 | // * Both of a binary operator's parameters are of the same type | ||||
16 | // * Verify that the indices of mem access instructions match other operands | ||||
17 | // * Verify that arithmetic and other things are only performed on first-class | ||||
18 | // types. Verify that shifts & logicals only happen on integrals f.e. | ||||
19 | // * All of the constants in a switch statement are of the correct type | ||||
20 | // * The code is in valid SSA form | ||||
21 | // * It should be illegal to put a label into any other type (like a structure) | ||||
22 | // or to return one. [except constant arrays!] | ||||
23 | // * Only phi nodes can be self referential: 'add i32 %0, %0 ; <int>:0' is bad | ||||
24 | // * PHI nodes must have an entry for each predecessor, with no extras. | ||||
25 | // * PHI nodes must be the first thing in a basic block, all grouped together | ||||
26 | // * PHI nodes must have at least one entry | ||||
27 | // * All basic blocks should only end with terminator insts, not contain them | ||||
28 | // * The entry node to a function must not have predecessors | ||||
29 | // * All Instructions must be embedded into a basic block | ||||
30 | // * Functions cannot take a void-typed parameter | ||||
31 | // * Verify that a function's argument list agrees with it's declared type. | ||||
32 | // * It is illegal to specify a name for a void value. | ||||
33 | // * It is illegal to have a internal global value with no initializer | ||||
34 | // * It is illegal to have a ret instruction that returns a value that does not | ||||
35 | // agree with the function return value type. | ||||
36 | // * Function call argument types match the function prototype | ||||
37 | // * A landing pad is defined by a landingpad instruction, and can be jumped to | ||||
38 | // only by the unwind edge of an invoke instruction. | ||||
39 | // * A landingpad instruction must be the first non-PHI instruction in the | ||||
40 | // block. | ||||
41 | // * Landingpad instructions must be in a function with a personality function. | ||||
42 | // * All other things that are tested by asserts spread about the code... | ||||
43 | // | ||||
44 | //===----------------------------------------------------------------------===// | ||||
45 | |||||
46 | #include "llvm/IR/Verifier.h" | ||||
47 | #include "llvm/ADT/APFloat.h" | ||||
48 | #include "llvm/ADT/APInt.h" | ||||
49 | #include "llvm/ADT/ArrayRef.h" | ||||
50 | #include "llvm/ADT/DenseMap.h" | ||||
51 | #include "llvm/ADT/MapVector.h" | ||||
52 | #include "llvm/ADT/Optional.h" | ||||
53 | #include "llvm/ADT/STLExtras.h" | ||||
54 | #include "llvm/ADT/SmallPtrSet.h" | ||||
55 | #include "llvm/ADT/SmallSet.h" | ||||
56 | #include "llvm/ADT/SmallVector.h" | ||||
57 | #include "llvm/ADT/StringExtras.h" | ||||
58 | #include "llvm/ADT/StringMap.h" | ||||
59 | #include "llvm/ADT/StringRef.h" | ||||
60 | #include "llvm/ADT/Twine.h" | ||||
61 | #include "llvm/ADT/ilist.h" | ||||
62 | #include "llvm/BinaryFormat/Dwarf.h" | ||||
63 | #include "llvm/IR/Argument.h" | ||||
64 | #include "llvm/IR/Attributes.h" | ||||
65 | #include "llvm/IR/BasicBlock.h" | ||||
66 | #include "llvm/IR/CFG.h" | ||||
67 | #include "llvm/IR/CallingConv.h" | ||||
68 | #include "llvm/IR/Comdat.h" | ||||
69 | #include "llvm/IR/Constant.h" | ||||
70 | #include "llvm/IR/ConstantRange.h" | ||||
71 | #include "llvm/IR/Constants.h" | ||||
72 | #include "llvm/IR/DataLayout.h" | ||||
73 | #include "llvm/IR/DebugInfo.h" | ||||
74 | #include "llvm/IR/DebugInfoMetadata.h" | ||||
75 | #include "llvm/IR/DebugLoc.h" | ||||
76 | #include "llvm/IR/DerivedTypes.h" | ||||
77 | #include "llvm/IR/Dominators.h" | ||||
78 | #include "llvm/IR/Function.h" | ||||
79 | #include "llvm/IR/GlobalAlias.h" | ||||
80 | #include "llvm/IR/GlobalValue.h" | ||||
81 | #include "llvm/IR/GlobalVariable.h" | ||||
82 | #include "llvm/IR/InlineAsm.h" | ||||
83 | #include "llvm/IR/InstVisitor.h" | ||||
84 | #include "llvm/IR/InstrTypes.h" | ||||
85 | #include "llvm/IR/Instruction.h" | ||||
86 | #include "llvm/IR/Instructions.h" | ||||
87 | #include "llvm/IR/IntrinsicInst.h" | ||||
88 | #include "llvm/IR/Intrinsics.h" | ||||
89 | #include "llvm/IR/IntrinsicsWebAssembly.h" | ||||
90 | #include "llvm/IR/LLVMContext.h" | ||||
91 | #include "llvm/IR/Metadata.h" | ||||
92 | #include "llvm/IR/Module.h" | ||||
93 | #include "llvm/IR/ModuleSlotTracker.h" | ||||
94 | #include "llvm/IR/PassManager.h" | ||||
95 | #include "llvm/IR/Statepoint.h" | ||||
96 | #include "llvm/IR/Type.h" | ||||
97 | #include "llvm/IR/Use.h" | ||||
98 | #include "llvm/IR/User.h" | ||||
99 | #include "llvm/IR/Value.h" | ||||
100 | #include "llvm/InitializePasses.h" | ||||
101 | #include "llvm/Pass.h" | ||||
102 | #include "llvm/Support/AtomicOrdering.h" | ||||
103 | #include "llvm/Support/Casting.h" | ||||
104 | #include "llvm/Support/CommandLine.h" | ||||
105 | #include "llvm/Support/Debug.h" | ||||
106 | #include "llvm/Support/ErrorHandling.h" | ||||
107 | #include "llvm/Support/MathExtras.h" | ||||
108 | #include "llvm/Support/raw_ostream.h" | ||||
109 | #include <algorithm> | ||||
110 | #include <cassert> | ||||
111 | #include <cstdint> | ||||
112 | #include <memory> | ||||
113 | #include <string> | ||||
114 | #include <utility> | ||||
115 | |||||
116 | using namespace llvm; | ||||
117 | |||||
118 | static cl::opt<bool> VerifyNoAliasScopeDomination( | ||||
119 | "verify-noalias-scope-decl-dom", cl::Hidden, cl::init(false), | ||||
120 | cl::desc("Ensure that llvm.experimental.noalias.scope.decl for identical " | ||||
121 | "scopes are not dominating")); | ||||
122 | |||||
123 | namespace llvm { | ||||
124 | |||||
125 | struct VerifierSupport { | ||||
126 | raw_ostream *OS; | ||||
127 | const Module &M; | ||||
128 | ModuleSlotTracker MST; | ||||
129 | Triple TT; | ||||
130 | const DataLayout &DL; | ||||
131 | LLVMContext &Context; | ||||
132 | |||||
133 | /// Track the brokenness of the module while recursively visiting. | ||||
134 | bool Broken = false; | ||||
135 | /// Broken debug info can be "recovered" from by stripping the debug info. | ||||
136 | bool BrokenDebugInfo = false; | ||||
137 | /// Whether to treat broken debug info as an error. | ||||
138 | bool TreatBrokenDebugInfoAsError = true; | ||||
139 | |||||
140 | explicit VerifierSupport(raw_ostream *OS, const Module &M) | ||||
141 | : OS(OS), M(M), MST(&M), TT(M.getTargetTriple()), DL(M.getDataLayout()), | ||||
142 | Context(M.getContext()) {} | ||||
143 | |||||
144 | private: | ||||
145 | void Write(const Module *M) { | ||||
146 | *OS << "; ModuleID = '" << M->getModuleIdentifier() << "'\n"; | ||||
147 | } | ||||
148 | |||||
149 | void Write(const Value *V) { | ||||
150 | if (V) | ||||
151 | Write(*V); | ||||
152 | } | ||||
153 | |||||
154 | void Write(const Value &V) { | ||||
155 | if (isa<Instruction>(V)) { | ||||
156 | V.print(*OS, MST); | ||||
157 | *OS << '\n'; | ||||
158 | } else { | ||||
159 | V.printAsOperand(*OS, true, MST); | ||||
160 | *OS << '\n'; | ||||
161 | } | ||||
162 | } | ||||
163 | |||||
164 | void Write(const Metadata *MD) { | ||||
165 | if (!MD) | ||||
166 | return; | ||||
167 | MD->print(*OS, MST, &M); | ||||
168 | *OS << '\n'; | ||||
169 | } | ||||
170 | |||||
171 | template <class T> void Write(const MDTupleTypedArrayWrapper<T> &MD) { | ||||
172 | Write(MD.get()); | ||||
173 | } | ||||
174 | |||||
175 | void Write(const NamedMDNode *NMD) { | ||||
176 | if (!NMD) | ||||
177 | return; | ||||
178 | NMD->print(*OS, MST); | ||||
179 | *OS << '\n'; | ||||
180 | } | ||||
181 | |||||
182 | void Write(Type *T) { | ||||
183 | if (!T) | ||||
184 | return; | ||||
185 | *OS << ' ' << *T; | ||||
186 | } | ||||
187 | |||||
188 | void Write(const Comdat *C) { | ||||
189 | if (!C) | ||||
190 | return; | ||||
191 | *OS << *C; | ||||
192 | } | ||||
193 | |||||
194 | void Write(const APInt *AI) { | ||||
195 | if (!AI) | ||||
196 | return; | ||||
197 | *OS << *AI << '\n'; | ||||
198 | } | ||||
199 | |||||
200 | void Write(const unsigned i) { *OS << i << '\n'; } | ||||
201 | |||||
202 | template <typename T> void Write(ArrayRef<T> Vs) { | ||||
203 | for (const T &V : Vs) | ||||
204 | Write(V); | ||||
205 | } | ||||
206 | |||||
207 | template <typename T1, typename... Ts> | ||||
208 | void WriteTs(const T1 &V1, const Ts &... Vs) { | ||||
209 | Write(V1); | ||||
210 | WriteTs(Vs...); | ||||
211 | } | ||||
212 | |||||
213 | template <typename... Ts> void WriteTs() {} | ||||
214 | |||||
215 | public: | ||||
216 | /// A check failed, so printout out the condition and the message. | ||||
217 | /// | ||||
218 | /// This provides a nice place to put a breakpoint if you want to see why | ||||
219 | /// something is not correct. | ||||
220 | void CheckFailed(const Twine &Message) { | ||||
221 | if (OS) | ||||
222 | *OS << Message << '\n'; | ||||
223 | Broken = true; | ||||
224 | } | ||||
225 | |||||
226 | /// A check failed (with values to print). | ||||
227 | /// | ||||
228 | /// This calls the Message-only version so that the above is easier to set a | ||||
229 | /// breakpoint on. | ||||
230 | template <typename T1, typename... Ts> | ||||
231 | void CheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs) { | ||||
232 | CheckFailed(Message); | ||||
233 | if (OS) | ||||
234 | WriteTs(V1, Vs...); | ||||
235 | } | ||||
236 | |||||
237 | /// A debug info check failed. | ||||
238 | void DebugInfoCheckFailed(const Twine &Message) { | ||||
239 | if (OS) | ||||
240 | *OS << Message << '\n'; | ||||
241 | Broken |= TreatBrokenDebugInfoAsError; | ||||
242 | BrokenDebugInfo = true; | ||||
243 | } | ||||
244 | |||||
245 | /// A debug info check failed (with values to print). | ||||
246 | template <typename T1, typename... Ts> | ||||
247 | void DebugInfoCheckFailed(const Twine &Message, const T1 &V1, | ||||
248 | const Ts &... Vs) { | ||||
249 | DebugInfoCheckFailed(Message); | ||||
250 | if (OS) | ||||
251 | WriteTs(V1, Vs...); | ||||
252 | } | ||||
253 | }; | ||||
254 | |||||
255 | } // namespace llvm | ||||
256 | |||||
257 | namespace { | ||||
258 | |||||
259 | class Verifier : public InstVisitor<Verifier>, VerifierSupport { | ||||
260 | friend class InstVisitor<Verifier>; | ||||
261 | |||||
262 | DominatorTree DT; | ||||
263 | |||||
264 | /// When verifying a basic block, keep track of all of the | ||||
265 | /// instructions we have seen so far. | ||||
266 | /// | ||||
267 | /// This allows us to do efficient dominance checks for the case when an | ||||
268 | /// instruction has an operand that is an instruction in the same block. | ||||
269 | SmallPtrSet<Instruction *, 16> InstsInThisBlock; | ||||
270 | |||||
271 | /// Keep track of the metadata nodes that have been checked already. | ||||
272 | SmallPtrSet<const Metadata *, 32> MDNodes; | ||||
273 | |||||
274 | /// Keep track which DISubprogram is attached to which function. | ||||
275 | DenseMap<const DISubprogram *, const Function *> DISubprogramAttachments; | ||||
276 | |||||
277 | /// Track all DICompileUnits visited. | ||||
278 | SmallPtrSet<const Metadata *, 2> CUVisited; | ||||
279 | |||||
280 | /// The result type for a landingpad. | ||||
281 | Type *LandingPadResultTy; | ||||
282 | |||||
283 | /// Whether we've seen a call to @llvm.localescape in this function | ||||
284 | /// already. | ||||
285 | bool SawFrameEscape; | ||||
286 | |||||
287 | /// Whether the current function has a DISubprogram attached to it. | ||||
288 | bool HasDebugInfo = false; | ||||
289 | |||||
290 | /// The current source language. | ||||
291 | dwarf::SourceLanguage CurrentSourceLang = dwarf::DW_LANG_lo_user; | ||||
292 | |||||
293 | /// Whether source was present on the first DIFile encountered in each CU. | ||||
294 | DenseMap<const DICompileUnit *, bool> HasSourceDebugInfo; | ||||
295 | |||||
296 | /// Stores the count of how many objects were passed to llvm.localescape for a | ||||
297 | /// given function and the largest index passed to llvm.localrecover. | ||||
298 | DenseMap<Function *, std::pair<unsigned, unsigned>> FrameEscapeInfo; | ||||
299 | |||||
300 | // Maps catchswitches and cleanuppads that unwind to siblings to the | ||||
301 | // terminators that indicate the unwind, used to detect cycles therein. | ||||
302 | MapVector<Instruction *, Instruction *> SiblingFuncletInfo; | ||||
303 | |||||
304 | /// Cache of constants visited in search of ConstantExprs. | ||||
305 | SmallPtrSet<const Constant *, 32> ConstantExprVisited; | ||||
306 | |||||
307 | /// Cache of declarations of the llvm.experimental.deoptimize.<ty> intrinsic. | ||||
308 | SmallVector<const Function *, 4> DeoptimizeDeclarations; | ||||
309 | |||||
310 | // Verify that this GlobalValue is only used in this module. | ||||
311 | // This map is used to avoid visiting uses twice. We can arrive at a user | ||||
312 | // twice, if they have multiple operands. In particular for very large | ||||
313 | // constant expressions, we can arrive at a particular user many times. | ||||
314 | SmallPtrSet<const Value *, 32> GlobalValueVisited; | ||||
315 | |||||
316 | // Keeps track of duplicate function argument debug info. | ||||
317 | SmallVector<const DILocalVariable *, 16> DebugFnArgs; | ||||
318 | |||||
319 | TBAAVerifier TBAAVerifyHelper; | ||||
320 | |||||
321 | SmallVector<IntrinsicInst *, 4> NoAliasScopeDecls; | ||||
322 | |||||
323 | void checkAtomicMemAccessSize(Type *Ty, const Instruction *I); | ||||
324 | |||||
325 | public: | ||||
326 | explicit Verifier(raw_ostream *OS, bool ShouldTreatBrokenDebugInfoAsError, | ||||
327 | const Module &M) | ||||
328 | : VerifierSupport(OS, M), LandingPadResultTy(nullptr), | ||||
329 | SawFrameEscape(false), TBAAVerifyHelper(this) { | ||||
330 | TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError; | ||||
331 | } | ||||
332 | |||||
333 | bool hasBrokenDebugInfo() const { return BrokenDebugInfo; } | ||||
334 | |||||
335 | bool verify(const Function &F) { | ||||
336 | assert(F.getParent() == &M &&((F.getParent() == &M && "An instance of this class only works with a specific module!" ) ? static_cast<void> (0) : __assert_fail ("F.getParent() == &M && \"An instance of this class only works with a specific module!\"" , "/build/llvm-toolchain-snapshot-12~++20210124100612+2afaf072f5c1/llvm/lib/IR/Verifier.cpp" , 337, __PRETTY_FUNCTION__)) | ||||
337 | "An instance of this class only works with a specific module!")((F.getParent() == &M && "An instance of this class only works with a specific module!" ) ? static_cast<void> (0) : __assert_fail ("F.getParent() == &M && \"An instance of this class only works with a specific module!\"" , "/build/llvm-toolchain-snapshot-12~++20210124100612+2afaf072f5c1/llvm/lib/IR/Verifier.cpp" , 337, __PRETTY_FUNCTION__)); | ||||
338 | |||||
339 | // First ensure the function is well-enough formed to compute dominance | ||||
340 | // information, and directly compute a dominance tree. We don't rely on the | ||||
341 | // pass manager to provide this as it isolates us from a potentially | ||||
342 | // out-of-date dominator tree and makes it significantly more complex to run | ||||
343 | // this code outside of a pass manager. | ||||
344 | // FIXME: It's really gross that we have to cast away constness here. | ||||
345 | if (!F.empty()) | ||||
346 | DT.recalculate(const_cast<Function &>(F)); | ||||
347 | |||||
348 | for (const BasicBlock &BB : F) { | ||||
349 | if (!BB.empty() && BB.back().isTerminator()) | ||||
350 | continue; | ||||
351 | |||||
352 | if (OS) { | ||||
353 | *OS << "Basic Block in function '" << F.getName() | ||||
354 | << "' does not have terminator!\n"; | ||||
355 | BB.printAsOperand(*OS, true, MST); | ||||
356 | *OS << "\n"; | ||||
357 | } | ||||
358 | return false; | ||||
359 | } | ||||
360 | |||||
361 | Broken = false; | ||||
362 | // FIXME: We strip const here because the inst visitor strips const. | ||||
363 | visit(const_cast<Function &>(F)); | ||||
364 | verifySiblingFuncletUnwinds(); | ||||
365 | InstsInThisBlock.clear(); | ||||
366 | DebugFnArgs.clear(); | ||||
367 | LandingPadResultTy = nullptr; | ||||
368 | SawFrameEscape = false; | ||||
369 | SiblingFuncletInfo.clear(); | ||||
370 | verifyNoAliasScopeDecl(); | ||||
371 | NoAliasScopeDecls.clear(); | ||||
372 | |||||
373 | return !Broken; | ||||
374 | } | ||||
375 | |||||
376 | /// Verify the module that this instance of \c Verifier was initialized with. | ||||
377 | bool verify() { | ||||
378 | Broken = false; | ||||
379 | |||||
380 | // Collect all declarations of the llvm.experimental.deoptimize intrinsic. | ||||
381 | for (const Function &F : M) | ||||
382 | if (F.getIntrinsicID() == Intrinsic::experimental_deoptimize) | ||||
383 | DeoptimizeDeclarations.push_back(&F); | ||||
384 | |||||
385 | // Now that we've visited every function, verify that we never asked to | ||||
386 | // recover a frame index that wasn't escaped. | ||||
387 | verifyFrameRecoverIndices(); | ||||
388 | for (const GlobalVariable &GV : M.globals()) | ||||
389 | visitGlobalVariable(GV); | ||||
390 | |||||
391 | for (const GlobalAlias &GA : M.aliases()) | ||||
392 | visitGlobalAlias(GA); | ||||
393 | |||||
394 | for (const NamedMDNode &NMD : M.named_metadata()) | ||||
395 | visitNamedMDNode(NMD); | ||||
396 | |||||
397 | for (const StringMapEntry<Comdat> &SMEC : M.getComdatSymbolTable()) | ||||
398 | visitComdat(SMEC.getValue()); | ||||
399 | |||||
400 | visitModuleFlags(M); | ||||
401 | visitModuleIdents(M); | ||||
402 | visitModuleCommandLines(M); | ||||
403 | |||||
404 | verifyCompileUnits(); | ||||
405 | |||||
406 | verifyDeoptimizeCallingConvs(); | ||||
407 | DISubprogramAttachments.clear(); | ||||
408 | return !Broken; | ||||
409 | } | ||||
410 | |||||
411 | private: | ||||
412 | /// Whether a metadata node is allowed to be, or contain, a DILocation. | ||||
413 | enum class AreDebugLocsAllowed { No, Yes }; | ||||
414 | |||||
415 | // Verification methods... | ||||
416 | void visitGlobalValue(const GlobalValue &GV); | ||||
417 | void visitGlobalVariable(const GlobalVariable &GV); | ||||
418 | void visitGlobalAlias(const GlobalAlias &GA); | ||||
419 | void visitAliaseeSubExpr(const GlobalAlias &A, const Constant &C); | ||||
420 | void visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias *> &Visited, | ||||
421 | const GlobalAlias &A, const Constant &C); | ||||
422 | void visitNamedMDNode(const NamedMDNode &NMD); | ||||
423 | void visitMDNode(const MDNode &MD, AreDebugLocsAllowed AllowLocs); | ||||
424 | void visitMetadataAsValue(const MetadataAsValue &MD, Function *F); | ||||
425 | void visitValueAsMetadata(const ValueAsMetadata &MD, Function *F); | ||||
426 | void visitComdat(const Comdat &C); | ||||
427 | void visitModuleIdents(const Module &M); | ||||
428 | void visitModuleCommandLines(const Module &M); | ||||
429 | void visitModuleFlags(const Module &M); | ||||
430 | void visitModuleFlag(const MDNode *Op, | ||||
431 | DenseMap<const MDString *, const MDNode *> &SeenIDs, | ||||
432 | SmallVectorImpl<const MDNode *> &Requirements); | ||||
433 | void visitModuleFlagCGProfileEntry(const MDOperand &MDO); | ||||
434 | void visitFunction(const Function &F); | ||||
435 | void visitBasicBlock(BasicBlock &BB); | ||||
436 | void visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty); | ||||
437 | void visitDereferenceableMetadata(Instruction &I, MDNode *MD); | ||||
438 | void visitProfMetadata(Instruction &I, MDNode *MD); | ||||
439 | void visitAnnotationMetadata(MDNode *Annotation); | ||||
440 | |||||
441 | template <class Ty> bool isValidMetadataArray(const MDTuple &N); | ||||
442 | #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N); | ||||
443 | #include "llvm/IR/Metadata.def" | ||||
444 | void visitDIScope(const DIScope &N); | ||||
445 | void visitDIVariable(const DIVariable &N); | ||||
446 | void visitDILexicalBlockBase(const DILexicalBlockBase &N); | ||||
447 | void visitDITemplateParameter(const DITemplateParameter &N); | ||||
448 | |||||
449 | void visitTemplateParams(const MDNode &N, const Metadata &RawParams); | ||||
450 | |||||
451 | // InstVisitor overrides... | ||||
452 | using InstVisitor<Verifier>::visit; | ||||
453 | void visit(Instruction &I); | ||||
454 | |||||
455 | void visitTruncInst(TruncInst &I); | ||||
456 | void visitZExtInst(ZExtInst &I); | ||||
457 | void visitSExtInst(SExtInst &I); | ||||
458 | void visitFPTruncInst(FPTruncInst &I); | ||||
459 | void visitFPExtInst(FPExtInst &I); | ||||
460 | void visitFPToUIInst(FPToUIInst &I); | ||||
461 | void visitFPToSIInst(FPToSIInst &I); | ||||
462 | void visitUIToFPInst(UIToFPInst &I); | ||||
463 | void visitSIToFPInst(SIToFPInst &I); | ||||
464 | void visitIntToPtrInst(IntToPtrInst &I); | ||||
465 | void visitPtrToIntInst(PtrToIntInst &I); | ||||
466 | void visitBitCastInst(BitCastInst &I); | ||||
467 | void visitAddrSpaceCastInst(AddrSpaceCastInst &I); | ||||
468 | void visitPHINode(PHINode &PN); | ||||
469 | void visitCallBase(CallBase &Call); | ||||
470 | void visitUnaryOperator(UnaryOperator &U); | ||||
471 | void visitBinaryOperator(BinaryOperator &B); | ||||
472 | void visitICmpInst(ICmpInst &IC); | ||||
473 | void visitFCmpInst(FCmpInst &FC); | ||||
474 | void visitExtractElementInst(ExtractElementInst &EI); | ||||
475 | void visitInsertElementInst(InsertElementInst &EI); | ||||
476 | void visitShuffleVectorInst(ShuffleVectorInst &EI); | ||||
477 | void visitVAArgInst(VAArgInst &VAA) { visitInstruction(VAA); } | ||||
478 | void visitCallInst(CallInst &CI); | ||||
479 | void visitInvokeInst(InvokeInst &II); | ||||
480 | void visitGetElementPtrInst(GetElementPtrInst &GEP); | ||||
481 | void visitLoadInst(LoadInst &LI); | ||||
482 | void visitStoreInst(StoreInst &SI); | ||||
483 | void verifyDominatesUse(Instruction &I, unsigned i); | ||||
484 | void visitInstruction(Instruction &I); | ||||
485 | void visitTerminator(Instruction &I); | ||||
486 | void visitBranchInst(BranchInst &BI); | ||||
487 | void visitReturnInst(ReturnInst &RI); | ||||
488 | void visitSwitchInst(SwitchInst &SI); | ||||
489 | void visitIndirectBrInst(IndirectBrInst &BI); | ||||
490 | void visitCallBrInst(CallBrInst &CBI); | ||||
491 | void visitSelectInst(SelectInst &SI); | ||||
492 | void visitUserOp1(Instruction &I); | ||||
493 | void visitUserOp2(Instruction &I) { visitUserOp1(I); } | ||||
494 | void visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call); | ||||
495 | void visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI); | ||||
496 | void visitDbgIntrinsic(StringRef Kind, DbgVariableIntrinsic &DII); | ||||
497 | void visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI); | ||||
498 | void visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI); | ||||
499 | void visitAtomicRMWInst(AtomicRMWInst &RMWI); | ||||
500 | void visitFenceInst(FenceInst &FI); | ||||
501 | void visitAllocaInst(AllocaInst &AI); | ||||
502 | void visitExtractValueInst(ExtractValueInst &EVI); | ||||
503 | void visitInsertValueInst(InsertValueInst &IVI); | ||||
504 | void visitEHPadPredecessors(Instruction &I); | ||||
505 | void visitLandingPadInst(LandingPadInst &LPI); | ||||
506 | void visitResumeInst(ResumeInst &RI); | ||||
507 | void visitCatchPadInst(CatchPadInst &CPI); | ||||
508 | void visitCatchReturnInst(CatchReturnInst &CatchReturn); | ||||
509 | void visitCleanupPadInst(CleanupPadInst &CPI); | ||||
510 | void visitFuncletPadInst(FuncletPadInst &FPI); | ||||
511 | void visitCatchSwitchInst(CatchSwitchInst &CatchSwitch); | ||||
512 | void visitCleanupReturnInst(CleanupReturnInst &CRI); | ||||
513 | |||||
514 | void verifySwiftErrorCall(CallBase &Call, const Value *SwiftErrorVal); | ||||
515 | void verifySwiftErrorValue(const Value *SwiftErrorVal); | ||||
516 | void verifyMustTailCall(CallInst &CI); | ||||
517 | bool verifyAttributeCount(AttributeList Attrs, unsigned Params); | ||||
518 | void verifyAttributeTypes(AttributeSet Attrs, bool IsFunction, | ||||
519 | const Value *V); | ||||
520 | void verifyParameterAttrs(AttributeSet Attrs, Type *Ty, const Value *V); | ||||
521 | void verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs, | ||||
522 | const Value *V, bool IsIntrinsic); | ||||
523 | void verifyFunctionMetadata(ArrayRef<std::pair<unsigned, MDNode *>> MDs); | ||||
524 | |||||
525 | void visitConstantExprsRecursively(const Constant *EntryC); | ||||
526 | void visitConstantExpr(const ConstantExpr *CE); | ||||
527 | void verifyStatepoint(const CallBase &Call); | ||||
528 | void verifyFrameRecoverIndices(); | ||||
529 | void verifySiblingFuncletUnwinds(); | ||||
530 | |||||
531 | void verifyFragmentExpression(const DbgVariableIntrinsic &I); | ||||
532 | template <typename ValueOrMetadata> | ||||
533 | void verifyFragmentExpression(const DIVariable &V, | ||||
534 | DIExpression::FragmentInfo Fragment, | ||||
535 | ValueOrMetadata *Desc); | ||||
536 | void verifyFnArgs(const DbgVariableIntrinsic &I); | ||||
537 | void verifyNotEntryValue(const DbgVariableIntrinsic &I); | ||||
538 | |||||
539 | /// Module-level debug info verification... | ||||
540 | void verifyCompileUnits(); | ||||
541 | |||||
542 | /// Module-level verification that all @llvm.experimental.deoptimize | ||||
543 | /// declarations share the same calling convention. | ||||
544 | void verifyDeoptimizeCallingConvs(); | ||||
545 | |||||
546 | /// Verify all-or-nothing property of DIFile source attribute within a CU. | ||||
547 | void verifySourceDebugInfo(const DICompileUnit &U, const DIFile &F); | ||||
548 | |||||
549 | /// Verify the llvm.experimental.noalias.scope.decl declarations | ||||
550 | void verifyNoAliasScopeDecl(); | ||||
551 | }; | ||||
552 | |||||
553 | } // end anonymous namespace | ||||
554 | |||||
555 | /// We know that cond should be true, if not print an error message. | ||||
556 | #define Assert(C, ...)do { if (!(C)) { CheckFailed(...); return; } } while (false) \ | ||||
557 | do { if (!(C)) { CheckFailed(__VA_ARGS__); return; } } while (false) | ||||
558 | |||||
559 | /// We know that a debug info condition should be true, if not print | ||||
560 | /// an error message. | ||||
561 | #define AssertDI(C, ...)do { if (!(C)) { DebugInfoCheckFailed(...); return; } } while (false) \ | ||||
562 | do { if (!(C)) { DebugInfoCheckFailed(__VA_ARGS__); return; } } while (false) | ||||
563 | |||||
564 | void Verifier::visit(Instruction &I) { | ||||
565 | for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) | ||||
566 | Assert(I.getOperand(i) != nullptr, "Operand is null", &I)do { if (!(I.getOperand(i) != nullptr)) { CheckFailed("Operand is null" , &I); return; } } while (false); | ||||
567 | InstVisitor<Verifier>::visit(I); | ||||
568 | } | ||||
569 | |||||
570 | // Helper to recursively iterate over indirect users. By | ||||
571 | // returning false, the callback can ask to stop recursing | ||||
572 | // further. | ||||
573 | static void forEachUser(const Value *User, | ||||
574 | SmallPtrSet<const Value *, 32> &Visited, | ||||
575 | llvm::function_ref<bool(const Value *)> Callback) { | ||||
576 | if (!Visited.insert(User).second) | ||||
577 | return; | ||||
578 | for (const Value *TheNextUser : User->materialized_users()) | ||||
579 | if (Callback(TheNextUser)) | ||||
580 | forEachUser(TheNextUser, Visited, Callback); | ||||
581 | } | ||||
582 | |||||
583 | void Verifier::visitGlobalValue(const GlobalValue &GV) { | ||||
584 | Assert(!GV.isDeclaration() || GV.hasValidDeclarationLinkage(),do { if (!(!GV.isDeclaration() || GV.hasValidDeclarationLinkage ())) { CheckFailed("Global is external, but doesn't have external or weak linkage!" , &GV); return; } } while (false) | ||||
585 | "Global is external, but doesn't have external or weak linkage!", &GV)do { if (!(!GV.isDeclaration() || GV.hasValidDeclarationLinkage ())) { CheckFailed("Global is external, but doesn't have external or weak linkage!" , &GV); return; } } while (false); | ||||
586 | |||||
587 | if (const GlobalObject *GO = dyn_cast<GlobalObject>(&GV)) | ||||
588 | Assert(GO->getAlignment() <= Value::MaximumAlignment,do { if (!(GO->getAlignment() <= Value::MaximumAlignment )) { CheckFailed("huge alignment values are unsupported", GO) ; return; } } while (false) | ||||
589 | "huge alignment values are unsupported", GO)do { if (!(GO->getAlignment() <= Value::MaximumAlignment )) { CheckFailed("huge alignment values are unsupported", GO) ; return; } } while (false); | ||||
590 | Assert(!GV.hasAppendingLinkage() || isa<GlobalVariable>(GV),do { if (!(!GV.hasAppendingLinkage() || isa<GlobalVariable >(GV))) { CheckFailed("Only global variables can have appending linkage!" , &GV); return; } } while (false) | ||||
591 | "Only global variables can have appending linkage!", &GV)do { if (!(!GV.hasAppendingLinkage() || isa<GlobalVariable >(GV))) { CheckFailed("Only global variables can have appending linkage!" , &GV); return; } } while (false); | ||||
592 | |||||
593 | if (GV.hasAppendingLinkage()) { | ||||
594 | const GlobalVariable *GVar = dyn_cast<GlobalVariable>(&GV); | ||||
595 | Assert(GVar && GVar->getValueType()->isArrayTy(),do { if (!(GVar && GVar->getValueType()->isArrayTy ())) { CheckFailed("Only global arrays can have appending linkage!" , GVar); return; } } while (false) | ||||
596 | "Only global arrays can have appending linkage!", GVar)do { if (!(GVar && GVar->getValueType()->isArrayTy ())) { CheckFailed("Only global arrays can have appending linkage!" , GVar); return; } } while (false); | ||||
597 | } | ||||
598 | |||||
599 | if (GV.isDeclarationForLinker()) | ||||
600 | Assert(!GV.hasComdat(), "Declaration may not be in a Comdat!", &GV)do { if (!(!GV.hasComdat())) { CheckFailed("Declaration may not be in a Comdat!" , &GV); return; } } while (false); | ||||
601 | |||||
602 | if (GV.hasDLLImportStorageClass()) { | ||||
603 | Assert(!GV.isDSOLocal(),do { if (!(!GV.isDSOLocal())) { CheckFailed("GlobalValue with DLLImport Storage is dso_local!" , &GV); return; } } while (false) | ||||
604 | "GlobalValue with DLLImport Storage is dso_local!", &GV)do { if (!(!GV.isDSOLocal())) { CheckFailed("GlobalValue with DLLImport Storage is dso_local!" , &GV); return; } } while (false); | ||||
605 | |||||
606 | Assert((GV.isDeclaration() &&do { if (!((GV.isDeclaration() && (GV.hasExternalLinkage () || GV.hasExternalWeakLinkage())) || GV.hasAvailableExternallyLinkage ())) { CheckFailed("Global is marked as dllimport, but not external" , &GV); return; } } while (false) | ||||
607 | (GV.hasExternalLinkage() || GV.hasExternalWeakLinkage())) ||do { if (!((GV.isDeclaration() && (GV.hasExternalLinkage () || GV.hasExternalWeakLinkage())) || GV.hasAvailableExternallyLinkage ())) { CheckFailed("Global is marked as dllimport, but not external" , &GV); return; } } while (false) | ||||
608 | GV.hasAvailableExternallyLinkage(),do { if (!((GV.isDeclaration() && (GV.hasExternalLinkage () || GV.hasExternalWeakLinkage())) || GV.hasAvailableExternallyLinkage ())) { CheckFailed("Global is marked as dllimport, but not external" , &GV); return; } } while (false) | ||||
609 | "Global is marked as dllimport, but not external", &GV)do { if (!((GV.isDeclaration() && (GV.hasExternalLinkage () || GV.hasExternalWeakLinkage())) || GV.hasAvailableExternallyLinkage ())) { CheckFailed("Global is marked as dllimport, but not external" , &GV); return; } } while (false); | ||||
610 | } | ||||
611 | |||||
612 | if (GV.isImplicitDSOLocal()) | ||||
613 | Assert(GV.isDSOLocal(),do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with local linkage or non-default " "visibility must be dso_local!", &GV); return; } } while (false) | ||||
614 | "GlobalValue with local linkage or non-default "do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with local linkage or non-default " "visibility must be dso_local!", &GV); return; } } while (false) | ||||
615 | "visibility must be dso_local!",do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with local linkage or non-default " "visibility must be dso_local!", &GV); return; } } while (false) | ||||
616 | &GV)do { if (!(GV.isDSOLocal())) { CheckFailed("GlobalValue with local linkage or non-default " "visibility must be dso_local!", &GV); return; } } while (false); | ||||
617 | |||||
618 | forEachUser(&GV, GlobalValueVisited, [&](const Value *V) -> bool { | ||||
619 | if (const Instruction *I = dyn_cast<Instruction>(V)) { | ||||
620 | if (!I->getParent() || !I->getParent()->getParent()) | ||||
621 | CheckFailed("Global is referenced by parentless instruction!", &GV, &M, | ||||
622 | I); | ||||
623 | else if (I->getParent()->getParent()->getParent() != &M) | ||||
624 | CheckFailed("Global is referenced in a different module!", &GV, &M, I, | ||||
625 | I->getParent()->getParent(), | ||||
626 | I->getParent()->getParent()->getParent()); | ||||
627 | return false; | ||||
628 | } else if (const Function *F = dyn_cast<Function>(V)) { | ||||
629 | if (F->getParent() != &M) | ||||
630 | CheckFailed("Global is used by function in a different module", &GV, &M, | ||||
631 | F, F->getParent()); | ||||
632 | return false; | ||||
633 | } | ||||
634 | return true; | ||||
635 | }); | ||||
636 | } | ||||
637 | |||||
638 | void Verifier::visitGlobalVariable(const GlobalVariable &GV) { | ||||
639 | if (GV.hasInitializer()) { | ||||
640 | Assert(GV.getInitializer()->getType() == GV.getValueType(),do { if (!(GV.getInitializer()->getType() == GV.getValueType ())) { CheckFailed("Global variable initializer type does not match global " "variable type!", &GV); return; } } while (false) | ||||
641 | "Global variable initializer type does not match global "do { if (!(GV.getInitializer()->getType() == GV.getValueType ())) { CheckFailed("Global variable initializer type does not match global " "variable type!", &GV); return; } } while (false) | ||||
642 | "variable type!",do { if (!(GV.getInitializer()->getType() == GV.getValueType ())) { CheckFailed("Global variable initializer type does not match global " "variable type!", &GV); return; } } while (false) | ||||
643 | &GV)do { if (!(GV.getInitializer()->getType() == GV.getValueType ())) { CheckFailed("Global variable initializer type does not match global " "variable type!", &GV); return; } } while (false); | ||||
644 | // If the global has common linkage, it must have a zero initializer and | ||||
645 | // cannot be constant. | ||||
646 | if (GV.hasCommonLinkage()) { | ||||
647 | Assert(GV.getInitializer()->isNullValue(),do { if (!(GV.getInitializer()->isNullValue())) { CheckFailed ("'common' global must have a zero initializer!", &GV); return ; } } while (false) | ||||
648 | "'common' global must have a zero initializer!", &GV)do { if (!(GV.getInitializer()->isNullValue())) { CheckFailed ("'common' global must have a zero initializer!", &GV); return ; } } while (false); | ||||
649 | Assert(!GV.isConstant(), "'common' global may not be marked constant!",do { if (!(!GV.isConstant())) { CheckFailed("'common' global may not be marked constant!" , &GV); return; } } while (false) | ||||
650 | &GV)do { if (!(!GV.isConstant())) { CheckFailed("'common' global may not be marked constant!" , &GV); return; } } while (false); | ||||
651 | Assert(!GV.hasComdat(), "'common' global may not be in a Comdat!", &GV)do { if (!(!GV.hasComdat())) { CheckFailed("'common' global may not be in a Comdat!" , &GV); return; } } while (false); | ||||
652 | } | ||||
653 | } | ||||
654 | |||||
655 | if (GV.hasName() && (GV.getName() == "llvm.global_ctors" || | ||||
656 | GV.getName() == "llvm.global_dtors")) { | ||||
657 | Assert(!GV.hasInitializer() || GV.hasAppendingLinkage(),do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage())) { CheckFailed("invalid linkage for intrinsic global variable" , &GV); return; } } while (false) | ||||
658 | "invalid linkage for intrinsic global variable", &GV)do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage())) { CheckFailed("invalid linkage for intrinsic global variable" , &GV); return; } } while (false); | ||||
659 | // Don't worry about emitting an error for it not being an array, | ||||
660 | // visitGlobalValue will complain on appending non-array. | ||||
661 | if (ArrayType *ATy = dyn_cast<ArrayType>(GV.getValueType())) { | ||||
662 | StructType *STy = dyn_cast<StructType>(ATy->getElementType()); | ||||
663 | PointerType *FuncPtrTy = | ||||
664 | FunctionType::get(Type::getVoidTy(Context), false)-> | ||||
665 | getPointerTo(DL.getProgramAddressSpace()); | ||||
666 | Assert(STy &&do { if (!(STy && (STy->getNumElements() == 2 || STy ->getNumElements() == 3) && STy->getTypeAtIndex (0u)->isIntegerTy(32) && STy->getTypeAtIndex(1) == FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable" , &GV); return; } } while (false) | ||||
667 | (STy->getNumElements() == 2 || STy->getNumElements() == 3) &&do { if (!(STy && (STy->getNumElements() == 2 || STy ->getNumElements() == 3) && STy->getTypeAtIndex (0u)->isIntegerTy(32) && STy->getTypeAtIndex(1) == FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable" , &GV); return; } } while (false) | ||||
668 | STy->getTypeAtIndex(0u)->isIntegerTy(32) &&do { if (!(STy && (STy->getNumElements() == 2 || STy ->getNumElements() == 3) && STy->getTypeAtIndex (0u)->isIntegerTy(32) && STy->getTypeAtIndex(1) == FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable" , &GV); return; } } while (false) | ||||
669 | STy->getTypeAtIndex(1) == FuncPtrTy,do { if (!(STy && (STy->getNumElements() == 2 || STy ->getNumElements() == 3) && STy->getTypeAtIndex (0u)->isIntegerTy(32) && STy->getTypeAtIndex(1) == FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable" , &GV); return; } } while (false) | ||||
670 | "wrong type for intrinsic global variable", &GV)do { if (!(STy && (STy->getNumElements() == 2 || STy ->getNumElements() == 3) && STy->getTypeAtIndex (0u)->isIntegerTy(32) && STy->getTypeAtIndex(1) == FuncPtrTy)) { CheckFailed("wrong type for intrinsic global variable" , &GV); return; } } while (false); | ||||
671 | Assert(STy->getNumElements() == 3,do { if (!(STy->getNumElements() == 3)) { CheckFailed("the third field of the element type is mandatory, " "specify i8* null to migrate from the obsoleted 2-field form" ); return; } } while (false) | ||||
672 | "the third field of the element type is mandatory, "do { if (!(STy->getNumElements() == 3)) { CheckFailed("the third field of the element type is mandatory, " "specify i8* null to migrate from the obsoleted 2-field form" ); return; } } while (false) | ||||
673 | "specify i8* null to migrate from the obsoleted 2-field form")do { if (!(STy->getNumElements() == 3)) { CheckFailed("the third field of the element type is mandatory, " "specify i8* null to migrate from the obsoleted 2-field form" ); return; } } while (false); | ||||
674 | Type *ETy = STy->getTypeAtIndex(2); | ||||
675 | Assert(ETy->isPointerTy() &&do { if (!(ETy->isPointerTy() && cast<PointerType >(ETy)->getElementType()->isIntegerTy(8))) { CheckFailed ("wrong type for intrinsic global variable", &GV); return ; } } while (false) | ||||
676 | cast<PointerType>(ETy)->getElementType()->isIntegerTy(8),do { if (!(ETy->isPointerTy() && cast<PointerType >(ETy)->getElementType()->isIntegerTy(8))) { CheckFailed ("wrong type for intrinsic global variable", &GV); return ; } } while (false) | ||||
677 | "wrong type for intrinsic global variable", &GV)do { if (!(ETy->isPointerTy() && cast<PointerType >(ETy)->getElementType()->isIntegerTy(8))) { CheckFailed ("wrong type for intrinsic global variable", &GV); return ; } } while (false); | ||||
678 | } | ||||
679 | } | ||||
680 | |||||
681 | if (GV.hasName() && (GV.getName() == "llvm.used" || | ||||
682 | GV.getName() == "llvm.compiler.used")) { | ||||
683 | Assert(!GV.hasInitializer() || GV.hasAppendingLinkage(),do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage())) { CheckFailed("invalid linkage for intrinsic global variable" , &GV); return; } } while (false) | ||||
684 | "invalid linkage for intrinsic global variable", &GV)do { if (!(!GV.hasInitializer() || GV.hasAppendingLinkage())) { CheckFailed("invalid linkage for intrinsic global variable" , &GV); return; } } while (false); | ||||
685 | Type *GVType = GV.getValueType(); | ||||
686 | if (ArrayType *ATy = dyn_cast<ArrayType>(GVType)) { | ||||
687 | PointerType *PTy = dyn_cast<PointerType>(ATy->getElementType()); | ||||
688 | Assert(PTy, "wrong type for intrinsic global variable", &GV)do { if (!(PTy)) { CheckFailed("wrong type for intrinsic global variable" , &GV); return; } } while (false); | ||||
689 | if (GV.hasInitializer()) { | ||||
690 | const Constant *Init = GV.getInitializer(); | ||||
691 | const ConstantArray *InitArray = dyn_cast<ConstantArray>(Init); | ||||
692 | Assert(InitArray, "wrong initalizer for intrinsic global variable",do { if (!(InitArray)) { CheckFailed("wrong initalizer for intrinsic global variable" , Init); return; } } while (false) | ||||
693 | Init)do { if (!(InitArray)) { CheckFailed("wrong initalizer for intrinsic global variable" , Init); return; } } while (false); | ||||
694 | for (Value *Op : InitArray->operands()) { | ||||
695 | Value *V = Op->stripPointerCasts(); | ||||
696 | Assert(isa<GlobalVariable>(V) || isa<Function>(V) ||do { if (!(isa<GlobalVariable>(V) || isa<Function> (V) || isa<GlobalAlias>(V))) { CheckFailed("invalid llvm.used member" , V); return; } } while (false) | ||||
697 | isa<GlobalAlias>(V),do { if (!(isa<GlobalVariable>(V) || isa<Function> (V) || isa<GlobalAlias>(V))) { CheckFailed("invalid llvm.used member" , V); return; } } while (false) | ||||
698 | "invalid llvm.used member", V)do { if (!(isa<GlobalVariable>(V) || isa<Function> (V) || isa<GlobalAlias>(V))) { CheckFailed("invalid llvm.used member" , V); return; } } while (false); | ||||
699 | Assert(V->hasName(), "members of llvm.used must be named", V)do { if (!(V->hasName())) { CheckFailed("members of llvm.used must be named" , V); return; } } while (false); | ||||
700 | } | ||||
701 | } | ||||
702 | } | ||||
703 | } | ||||
704 | |||||
705 | // Visit any debug info attachments. | ||||
706 | SmallVector<MDNode *, 1> MDs; | ||||
707 | GV.getMetadata(LLVMContext::MD_dbg, MDs); | ||||
708 | for (auto *MD : MDs) { | ||||
709 | if (auto *GVE = dyn_cast<DIGlobalVariableExpression>(MD)) | ||||
710 | visitDIGlobalVariableExpression(*GVE); | ||||
711 | else | ||||
712 | AssertDI(false, "!dbg attachment of global variable must be a "do { if (!(false)) { DebugInfoCheckFailed("!dbg attachment of global variable must be a " "DIGlobalVariableExpression"); return; } } while (false) | ||||
713 | "DIGlobalVariableExpression")do { if (!(false)) { DebugInfoCheckFailed("!dbg attachment of global variable must be a " "DIGlobalVariableExpression"); return; } } while (false); | ||||
714 | } | ||||
715 | |||||
716 | // Scalable vectors cannot be global variables, since we don't know | ||||
717 | // the runtime size. If the global is an array containing scalable vectors, | ||||
718 | // that will be caught by the isValidElementType methods in StructType or | ||||
719 | // ArrayType instead. | ||||
720 | Assert(!isa<ScalableVectorType>(GV.getValueType()),do { if (!(!isa<ScalableVectorType>(GV.getValueType())) ) { CheckFailed("Globals cannot contain scalable vectors", & GV); return; } } while (false) | ||||
721 | "Globals cannot contain scalable vectors", &GV)do { if (!(!isa<ScalableVectorType>(GV.getValueType())) ) { CheckFailed("Globals cannot contain scalable vectors", & GV); return; } } while (false); | ||||
722 | |||||
723 | if (auto *STy = dyn_cast<StructType>(GV.getValueType())) | ||||
724 | Assert(!STy->containsScalableVectorType(),do { if (!(!STy->containsScalableVectorType())) { CheckFailed ("Globals cannot contain scalable vectors", &GV); return; } } while (false) | ||||
725 | "Globals cannot contain scalable vectors", &GV)do { if (!(!STy->containsScalableVectorType())) { CheckFailed ("Globals cannot contain scalable vectors", &GV); return; } } while (false); | ||||
726 | |||||
727 | if (!GV.hasInitializer()) { | ||||
728 | visitGlobalValue(GV); | ||||
729 | return; | ||||
730 | } | ||||
731 | |||||
732 | // Walk any aggregate initializers looking for bitcasts between address spaces | ||||
733 | visitConstantExprsRecursively(GV.getInitializer()); | ||||
734 | |||||
735 | visitGlobalValue(GV); | ||||
736 | } | ||||
737 | |||||
738 | void Verifier::visitAliaseeSubExpr(const GlobalAlias &GA, const Constant &C) { | ||||
739 | SmallPtrSet<const GlobalAlias*, 4> Visited; | ||||
740 | Visited.insert(&GA); | ||||
741 | visitAliaseeSubExpr(Visited, GA, C); | ||||
742 | } | ||||
743 | |||||
744 | void Verifier::visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias*> &Visited, | ||||
745 | const GlobalAlias &GA, const Constant &C) { | ||||
746 | if (const auto *GV = dyn_cast<GlobalValue>(&C)) { | ||||
747 | Assert(!GV->isDeclarationForLinker(), "Alias must point to a definition",do { if (!(!GV->isDeclarationForLinker())) { CheckFailed("Alias must point to a definition" , &GA); return; } } while (false) | ||||
748 | &GA)do { if (!(!GV->isDeclarationForLinker())) { CheckFailed("Alias must point to a definition" , &GA); return; } } while (false); | ||||
749 | |||||
750 | if (const auto *GA2 = dyn_cast<GlobalAlias>(GV)) { | ||||
751 | Assert(Visited.insert(GA2).second, "Aliases cannot form a cycle", &GA)do { if (!(Visited.insert(GA2).second)) { CheckFailed("Aliases cannot form a cycle" , &GA); return; } } while (false); | ||||
752 | |||||
753 | Assert(!GA2->isInterposable(), "Alias cannot point to an interposable alias",do { if (!(!GA2->isInterposable())) { CheckFailed("Alias cannot point to an interposable alias" , &GA); return; } } while (false) | ||||
754 | &GA)do { if (!(!GA2->isInterposable())) { CheckFailed("Alias cannot point to an interposable alias" , &GA); return; } } while (false); | ||||
755 | } else { | ||||
756 | // Only continue verifying subexpressions of GlobalAliases. | ||||
757 | // Do not recurse into global initializers. | ||||
758 | return; | ||||
759 | } | ||||
760 | } | ||||
761 | |||||
762 | if (const auto *CE = dyn_cast<ConstantExpr>(&C)) | ||||
763 | visitConstantExprsRecursively(CE); | ||||
764 | |||||
765 | for (const Use &U : C.operands()) { | ||||
766 | Value *V = &*U; | ||||
767 | if (const auto *GA2 = dyn_cast<GlobalAlias>(V)) | ||||
768 | visitAliaseeSubExpr(Visited, GA, *GA2->getAliasee()); | ||||
769 | else if (const auto *C2 = dyn_cast<Constant>(V)) | ||||
770 | visitAliaseeSubExpr(Visited, GA, *C2); | ||||
771 | } | ||||
772 | } | ||||
773 | |||||
774 | void Verifier::visitGlobalAlias(const GlobalAlias &GA) { | ||||
775 | Assert(GlobalAlias::isValidLinkage(GA.getLinkage()),do { if (!(GlobalAlias::isValidLinkage(GA.getLinkage()))) { CheckFailed ("Alias should have private, internal, linkonce, weak, linkonce_odr, " "weak_odr, or external linkage!", &GA); return; } } while (false) | ||||
776 | "Alias should have private, internal, linkonce, weak, linkonce_odr, "do { if (!(GlobalAlias::isValidLinkage(GA.getLinkage()))) { CheckFailed ("Alias should have private, internal, linkonce, weak, linkonce_odr, " "weak_odr, or external linkage!", &GA); return; } } while (false) | ||||
777 | "weak_odr, or external linkage!",do { if (!(GlobalAlias::isValidLinkage(GA.getLinkage()))) { CheckFailed ("Alias should have private, internal, linkonce, weak, linkonce_odr, " "weak_odr, or external linkage!", &GA); return; } } while (false) | ||||
778 | &GA)do { if (!(GlobalAlias::isValidLinkage(GA.getLinkage()))) { CheckFailed ("Alias should have private, internal, linkonce, weak, linkonce_odr, " "weak_odr, or external linkage!", &GA); return; } } while (false); | ||||
779 | const Constant *Aliasee = GA.getAliasee(); | ||||
780 | Assert(Aliasee, "Aliasee cannot be NULL!", &GA)do { if (!(Aliasee)) { CheckFailed("Aliasee cannot be NULL!", &GA); return; } } while (false); | ||||
781 | Assert(GA.getType() == Aliasee->getType(),do { if (!(GA.getType() == Aliasee->getType())) { CheckFailed ("Alias and aliasee types should match!", &GA); return; } } while (false) | ||||
782 | "Alias and aliasee types should match!", &GA)do { if (!(GA.getType() == Aliasee->getType())) { CheckFailed ("Alias and aliasee types should match!", &GA); return; } } while (false); | ||||
783 | |||||
784 | Assert(isa<GlobalValue>(Aliasee) || isa<ConstantExpr>(Aliasee),do { if (!(isa<GlobalValue>(Aliasee) || isa<ConstantExpr >(Aliasee))) { CheckFailed("Aliasee should be either GlobalValue or ConstantExpr" , &GA); return; } } while (false) | ||||
785 | "Aliasee should be either GlobalValue or ConstantExpr", &GA)do { if (!(isa<GlobalValue>(Aliasee) || isa<ConstantExpr >(Aliasee))) { CheckFailed("Aliasee should be either GlobalValue or ConstantExpr" , &GA); return; } } while (false); | ||||
786 | |||||
787 | visitAliaseeSubExpr(GA, *Aliasee); | ||||
788 | |||||
789 | visitGlobalValue(GA); | ||||
790 | } | ||||
791 | |||||
792 | void Verifier::visitNamedMDNode(const NamedMDNode &NMD) { | ||||
793 | // There used to be various other llvm.dbg.* nodes, but we don't support | ||||
794 | // upgrading them and we want to reserve the namespace for future uses. | ||||
795 | if (NMD.getName().startswith("llvm.dbg.")) | ||||
796 | AssertDI(NMD.getName() == "llvm.dbg.cu",do { if (!(NMD.getName() == "llvm.dbg.cu")) { DebugInfoCheckFailed ("unrecognized named metadata node in the llvm.dbg namespace" , &NMD); return; } } while (false) | ||||
797 | "unrecognized named metadata node in the llvm.dbg namespace",do { if (!(NMD.getName() == "llvm.dbg.cu")) { DebugInfoCheckFailed ("unrecognized named metadata node in the llvm.dbg namespace" , &NMD); return; } } while (false) | ||||
798 | &NMD)do { if (!(NMD.getName() == "llvm.dbg.cu")) { DebugInfoCheckFailed ("unrecognized named metadata node in the llvm.dbg namespace" , &NMD); return; } } while (false); | ||||
799 | for (const MDNode *MD : NMD.operands()) { | ||||
800 | if (NMD.getName() == "llvm.dbg.cu") | ||||
801 | AssertDI(MD && isa<DICompileUnit>(MD), "invalid compile unit", &NMD, MD)do { if (!(MD && isa<DICompileUnit>(MD))) { DebugInfoCheckFailed ("invalid compile unit", &NMD, MD); return; } } while (false ); | ||||
802 | |||||
803 | if (!MD) | ||||
804 | continue; | ||||
805 | |||||
806 | visitMDNode(*MD, AreDebugLocsAllowed::Yes); | ||||
807 | } | ||||
808 | } | ||||
809 | |||||
810 | void Verifier::visitMDNode(const MDNode &MD, AreDebugLocsAllowed AllowLocs) { | ||||
811 | // Only visit each node once. Metadata can be mutually recursive, so this | ||||
812 | // avoids infinite recursion here, as well as being an optimization. | ||||
813 | if (!MDNodes.insert(&MD).second) | ||||
814 | return; | ||||
815 | |||||
816 | switch (MD.getMetadataID()) { | ||||
817 | default: | ||||
818 | llvm_unreachable("Invalid MDNode subclass")::llvm::llvm_unreachable_internal("Invalid MDNode subclass", "/build/llvm-toolchain-snapshot-12~++20210124100612+2afaf072f5c1/llvm/lib/IR/Verifier.cpp" , 818); | ||||
819 | case Metadata::MDTupleKind: | ||||
820 | break; | ||||
821 | #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \ | ||||
822 | case Metadata::CLASS##Kind: \ | ||||
823 | visit##CLASS(cast<CLASS>(MD)); \ | ||||
824 | break; | ||||
825 | #include "llvm/IR/Metadata.def" | ||||
826 | } | ||||
827 | |||||
828 | for (const Metadata *Op : MD.operands()) { | ||||
829 | if (!Op) | ||||
830 | continue; | ||||
831 | Assert(!isa<LocalAsMetadata>(Op), "Invalid operand for global metadata!",do { if (!(!isa<LocalAsMetadata>(Op))) { CheckFailed("Invalid operand for global metadata!" , &MD, Op); return; } } while (false) | ||||
832 | &MD, Op)do { if (!(!isa<LocalAsMetadata>(Op))) { CheckFailed("Invalid operand for global metadata!" , &MD, Op); return; } } while (false); | ||||
833 | AssertDI(!isa<DILocation>(Op) || AllowLocs == AreDebugLocsAllowed::Yes,do { if (!(!isa<DILocation>(Op) || AllowLocs == AreDebugLocsAllowed ::Yes)) { DebugInfoCheckFailed("DILocation not allowed within this metadata node" , &MD, Op); return; } } while (false) | ||||
834 | "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); | ||||
835 | if (auto *N = dyn_cast<MDNode>(Op)) { | ||||
836 | visitMDNode(*N, AllowLocs); | ||||
837 | continue; | ||||
838 | } | ||||
839 | if (auto *V = dyn_cast<ValueAsMetadata>(Op)) { | ||||
840 | visitValueAsMetadata(*V, nullptr); | ||||
841 | continue; | ||||
842 | } | ||||
843 | } | ||||
844 | |||||
845 | // Check these last, so we diagnose problems in operands first. | ||||
846 | Assert(!MD.isTemporary(), "Expected no forward declarations!", &MD)do { if (!(!MD.isTemporary())) { CheckFailed("Expected no forward declarations!" , &MD); return; } } while (false); | ||||
847 | Assert(MD.isResolved(), "All nodes should be resolved!", &MD)do { if (!(MD.isResolved())) { CheckFailed("All nodes should be resolved!" , &MD); return; } } while (false); | ||||
848 | } | ||||
849 | |||||
850 | void Verifier::visitValueAsMetadata(const ValueAsMetadata &MD, Function *F) { | ||||
851 | Assert(MD.getValue(), "Expected valid value", &MD)do { if (!(MD.getValue())) { CheckFailed("Expected valid value" , &MD); return; } } while (false); | ||||
852 | Assert(!MD.getValue()->getType()->isMetadataTy(),do { if (!(!MD.getValue()->getType()->isMetadataTy())) { CheckFailed("Unexpected metadata round-trip through values", &MD, MD.getValue()); return; } } while (false) | ||||
853 | "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); | ||||
854 | |||||
855 | auto *L = dyn_cast<LocalAsMetadata>(&MD); | ||||
856 | if (!L) | ||||
857 | return; | ||||
858 | |||||
859 | Assert(F, "function-local metadata used outside a function", L)do { if (!(F)) { CheckFailed("function-local metadata used outside a function" , L); return; } } while (false); | ||||
860 | |||||
861 | // If this was an instruction, bb, or argument, verify that it is in the | ||||
862 | // function that we expect. | ||||
863 | Function *ActualF = nullptr; | ||||
864 | if (Instruction *I = dyn_cast<Instruction>(L->getValue())) { | ||||
865 | Assert(I->getParent(), "function-local metadata not in basic block", L, I)do { if (!(I->getParent())) { CheckFailed("function-local metadata not in basic block" , L, I); return; } } while (false); | ||||
866 | ActualF = I->getParent()->getParent(); | ||||
867 | } else if (BasicBlock *BB = dyn_cast<BasicBlock>(L->getValue())) | ||||
868 | ActualF = BB->getParent(); | ||||
869 | else if (Argument *A = dyn_cast<Argument>(L->getValue())) | ||||
870 | ActualF = A->getParent(); | ||||
871 | assert(ActualF && "Unimplemented function local metadata case!")((ActualF && "Unimplemented function local metadata case!" ) ? static_cast<void> (0) : __assert_fail ("ActualF && \"Unimplemented function local metadata case!\"" , "/build/llvm-toolchain-snapshot-12~++20210124100612+2afaf072f5c1/llvm/lib/IR/Verifier.cpp" , 871, __PRETTY_FUNCTION__)); | ||||
872 | |||||
873 | Assert(ActualF == F, "function-local metadata used in wrong function", L)do { if (!(ActualF == F)) { CheckFailed("function-local metadata used in wrong function" , L); return; } } while (false); | ||||
874 | } | ||||
875 | |||||
876 | void Verifier::visitMetadataAsValue(const MetadataAsValue &MDV, Function *F) { | ||||
877 | Metadata *MD = MDV.getMetadata(); | ||||
878 | if (auto *N = dyn_cast<MDNode>(MD)) { | ||||
879 | visitMDNode(*N, AreDebugLocsAllowed::No); | ||||
880 | return; | ||||
881 | } | ||||
882 | |||||
883 | // Only visit each node once. Metadata can be mutually recursive, so this | ||||
884 | // avoids infinite recursion here, as well as being an optimization. | ||||
885 | if (!MDNodes.insert(MD).second) | ||||
886 | return; | ||||
887 | |||||
888 | if (auto *V = dyn_cast<ValueAsMetadata>(MD)) | ||||
889 | visitValueAsMetadata(*V, F); | ||||
890 | } | ||||
891 | |||||
892 | static bool isType(const Metadata *MD) { return !MD || isa<DIType>(MD); } | ||||
893 | static bool isScope(const Metadata *MD) { return !MD || isa<DIScope>(MD); } | ||||
894 | static bool isDINode(const Metadata *MD) { return !MD || isa<DINode>(MD); } | ||||
895 | |||||
896 | void Verifier::visitDILocation(const DILocation &N) { | ||||
897 | AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { DebugInfoCheckFailed("location requires a valid scope" , &N, N.getRawScope()); return; } } while (false) | ||||
898 | "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); | ||||
899 | if (auto *IA = N.getRawInlinedAt()) | ||||
900 | AssertDI(isa<DILocation>(IA), "inlined-at should be a location", &N, IA)do { if (!(isa<DILocation>(IA))) { DebugInfoCheckFailed ("inlined-at should be a location", &N, IA); return; } } while (false); | ||||
901 | if (auto *SP = dyn_cast<DISubprogram>(N.getRawScope())) | ||||
902 | AssertDI(SP->isDefinition(), "scope points into the type hierarchy", &N)do { if (!(SP->isDefinition())) { DebugInfoCheckFailed("scope points into the type hierarchy" , &N); return; } } while (false); | ||||
903 | } | ||||
904 | |||||
905 | void Verifier::visitGenericDINode(const GenericDINode &N) { | ||||
906 | AssertDI(N.getTag(), "invalid tag", &N)do { if (!(N.getTag())) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false); | ||||
907 | } | ||||
908 | |||||
909 | void Verifier::visitDIScope(const DIScope &N) { | ||||
910 | if (auto *F = N.getRawFile()) | ||||
911 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | ||||
912 | } | ||||
913 | |||||
914 | void Verifier::visitDISubrange(const DISubrange &N) { | ||||
915 | AssertDI(N.getTag() == dwarf::DW_TAG_subrange_type, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_subrange_type)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | ||||
916 | bool HasAssumedSizedArraySupport = dwarf::isFortran(CurrentSourceLang); | ||||
917 | AssertDI(HasAssumedSizedArraySupport || N.getRawCountNode() ||do { if (!(HasAssumedSizedArraySupport || N.getRawCountNode() || N.getRawUpperBound())) { DebugInfoCheckFailed("Subrange must contain count or upperBound" , &N); return; } } while (false) | ||||
918 | N.getRawUpperBound(),do { if (!(HasAssumedSizedArraySupport || N.getRawCountNode() || N.getRawUpperBound())) { DebugInfoCheckFailed("Subrange must contain count or upperBound" , &N); return; } } while (false) | ||||
919 | "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); | ||||
920 | AssertDI(!N.getRawCountNode() || !N.getRawUpperBound(),do { if (!(!N.getRawCountNode() || !N.getRawUpperBound())) { DebugInfoCheckFailed ("Subrange can have any one of count or upperBound", &N); return; } } while (false) | ||||
921 | "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); | ||||
922 | AssertDI(!N.getRawCountNode() || N.getCount(),do { if (!(!N.getRawCountNode() || N.getCount())) { DebugInfoCheckFailed ("Count must either be a signed constant or a DIVariable", & N); return; } } while (false) | ||||
923 | "Count must either be a signed constant or a DIVariable", &N)do { if (!(!N.getRawCountNode() || N.getCount())) { DebugInfoCheckFailed ("Count must either be a signed constant or a DIVariable", & N); return; } } while (false); | ||||
924 | auto Count = N.getCount(); | ||||
925 | AssertDI(!Count || !Count.is<ConstantInt *>() ||do { if (!(!Count || !Count.is<ConstantInt *>() || Count .get<ConstantInt *>()->getSExtValue() >= -1)) { DebugInfoCheckFailed ("invalid subrange count", &N); return; } } while (false) | ||||
926 | Count.get<ConstantInt *>()->getSExtValue() >= -1,do { if (!(!Count || !Count.is<ConstantInt *>() || Count .get<ConstantInt *>()->getSExtValue() >= -1)) { DebugInfoCheckFailed ("invalid subrange count", &N); return; } } while (false) | ||||
927 | "invalid subrange count", &N)do { if (!(!Count || !Count.is<ConstantInt *>() || Count .get<ConstantInt *>()->getSExtValue() >= -1)) { DebugInfoCheckFailed ("invalid subrange count", &N); return; } } while (false); | ||||
928 | auto *LBound = N.getRawLowerBound(); | ||||
929 | AssertDI(!LBound || isa<ConstantAsMetadata>(LBound) ||do { if (!(!LBound || isa<ConstantAsMetadata>(LBound) || isa<DIVariable>(LBound) || isa<DIExpression>(LBound ))) { DebugInfoCheckFailed("LowerBound must be signed constant or DIVariable or DIExpression" , &N); return; } } while (false) | ||||
930 | 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) | ||||
931 | "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) | ||||
932 | &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); | ||||
933 | auto *UBound = N.getRawUpperBound(); | ||||
934 | AssertDI(!UBound || isa<ConstantAsMetadata>(UBound) ||do { if (!(!UBound || isa<ConstantAsMetadata>(UBound) || isa<DIVariable>(UBound) || isa<DIExpression>(UBound ))) { DebugInfoCheckFailed("UpperBound must be signed constant or DIVariable or DIExpression" , &N); return; } } while (false) | ||||
935 | 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) | ||||
936 | "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) | ||||
937 | &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); | ||||
938 | auto *Stride = N.getRawStride(); | ||||
939 | AssertDI(!Stride || isa<ConstantAsMetadata>(Stride) ||do { if (!(!Stride || isa<ConstantAsMetadata>(Stride) || isa<DIVariable>(Stride) || isa<DIExpression>(Stride ))) { DebugInfoCheckFailed("Stride must be signed constant or DIVariable or DIExpression" , &N); return; } } while (false) | ||||
940 | 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) | ||||
941 | "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); | ||||
942 | } | ||||
943 | |||||
944 | void Verifier::visitDIGenericSubrange(const DIGenericSubrange &N) { | ||||
945 | AssertDI(N.getTag() == dwarf::DW_TAG_generic_subrange, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_generic_subrange)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | ||||
946 | AssertDI(N.getRawCountNode() || N.getRawUpperBound(),do { if (!(N.getRawCountNode() || N.getRawUpperBound())) { DebugInfoCheckFailed ("GenericSubrange must contain count or upperBound", &N); return; } } while (false) | ||||
947 | "GenericSubrange must contain count or upperBound", &N)do { if (!(N.getRawCountNode() || N.getRawUpperBound())) { DebugInfoCheckFailed ("GenericSubrange must contain count or upperBound", &N); return; } } while (false); | ||||
948 | AssertDI(!N.getRawCountNode() || !N.getRawUpperBound(),do { if (!(!N.getRawCountNode() || !N.getRawUpperBound())) { DebugInfoCheckFailed ("GenericSubrange can have any one of count or upperBound", & N); return; } } while (false) | ||||
949 | "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); | ||||
950 | auto *CBound = N.getRawCountNode(); | ||||
951 | AssertDI(!CBound || isa<DIVariable>(CBound) || isa<DIExpression>(CBound),do { if (!(!CBound || isa<DIVariable>(CBound) || isa< DIExpression>(CBound))) { DebugInfoCheckFailed("Count must be signed constant or DIVariable or DIExpression" , &N); return; } } while (false) | ||||
952 | "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); | ||||
953 | auto *LBound = N.getRawLowerBound(); | ||||
954 | AssertDI(LBound, "GenericSubrange must contain lowerBound", &N)do { if (!(LBound)) { DebugInfoCheckFailed("GenericSubrange must contain lowerBound" , &N); return; } } while (false); | ||||
955 | AssertDI(isa<DIVariable>(LBound) || isa<DIExpression>(LBound),do { if (!(isa<DIVariable>(LBound) || isa<DIExpression >(LBound))) { DebugInfoCheckFailed("LowerBound must be signed constant or DIVariable or DIExpression" , &N); return; } } while (false) | ||||
956 | "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) | ||||
957 | &N)do { if (!(isa<DIVariable>(LBound) || isa<DIExpression >(LBound))) { DebugInfoCheckFailed("LowerBound must be signed constant or DIVariable or DIExpression" , &N); return; } } while (false); | ||||
958 | auto *UBound = N.getRawUpperBound(); | ||||
959 | AssertDI(!UBound || isa<DIVariable>(UBound) || isa<DIExpression>(UBound),do { if (!(!UBound || isa<DIVariable>(UBound) || isa< DIExpression>(UBound))) { DebugInfoCheckFailed("UpperBound must be signed constant or DIVariable or DIExpression" , &N); return; } } while (false) | ||||
960 | "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) | ||||
961 | &N)do { if (!(!UBound || isa<DIVariable>(UBound) || isa< DIExpression>(UBound))) { DebugInfoCheckFailed("UpperBound must be signed constant or DIVariable or DIExpression" , &N); return; } } while (false); | ||||
962 | auto *Stride = N.getRawStride(); | ||||
963 | AssertDI(Stride, "GenericSubrange must contain stride", &N)do { if (!(Stride)) { DebugInfoCheckFailed("GenericSubrange must contain stride" , &N); return; } } while (false); | ||||
964 | AssertDI(isa<DIVariable>(Stride) || isa<DIExpression>(Stride),do { if (!(isa<DIVariable>(Stride) || isa<DIExpression >(Stride))) { DebugInfoCheckFailed("Stride must be signed constant or DIVariable or DIExpression" , &N); return; } } while (false) | ||||
965 | "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); | ||||
966 | } | ||||
967 | |||||
968 | void Verifier::visitDIEnumerator(const DIEnumerator &N) { | ||||
969 | AssertDI(N.getTag() == dwarf::DW_TAG_enumerator, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_enumerator)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | ||||
970 | } | ||||
971 | |||||
972 | void Verifier::visitDIBasicType(const DIBasicType &N) { | ||||
973 | AssertDI(N.getTag() == dwarf::DW_TAG_base_type ||do { if (!(N.getTag() == dwarf::DW_TAG_base_type || N.getTag( ) == dwarf::DW_TAG_unspecified_type || N.getTag() == dwarf::DW_TAG_string_type )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false) | ||||
974 | 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) | ||||
975 | 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) | ||||
976 | "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); | ||||
977 | } | ||||
978 | |||||
979 | void Verifier::visitDIStringType(const DIStringType &N) { | ||||
980 | AssertDI(N.getTag() == dwarf::DW_TAG_string_type, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_string_type)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | ||||
981 | AssertDI(!(N.isBigEndian() && N.isLittleEndian()) ,do { if (!(!(N.isBigEndian() && N.isLittleEndian()))) { DebugInfoCheckFailed("has conflicting flags", &N); return ; } } while (false) | ||||
982 | "has conflicting flags", &N)do { if (!(!(N.isBigEndian() && N.isLittleEndian()))) { DebugInfoCheckFailed("has conflicting flags", &N); return ; } } while (false); | ||||
983 | } | ||||
984 | |||||
985 | void Verifier::visitDIDerivedType(const DIDerivedType &N) { | ||||
986 | // Common scope checks. | ||||
987 | visitDIScope(N); | ||||
988 | |||||
989 | AssertDI(N.getTag() == dwarf::DW_TAG_typedef ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | ||||
990 | N.getTag() == dwarf::DW_TAG_pointer_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | ||||
991 | N.getTag() == dwarf::DW_TAG_ptr_to_member_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | ||||
992 | N.getTag() == dwarf::DW_TAG_reference_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | ||||
993 | N.getTag() == dwarf::DW_TAG_rvalue_reference_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | ||||
994 | N.getTag() == dwarf::DW_TAG_const_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | ||||
995 | N.getTag() == dwarf::DW_TAG_volatile_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | ||||
996 | N.getTag() == dwarf::DW_TAG_restrict_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | ||||
997 | N.getTag() == dwarf::DW_TAG_atomic_type ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | ||||
998 | N.getTag() == dwarf::DW_TAG_member ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | ||||
999 | N.getTag() == dwarf::DW_TAG_inheritance ||do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | ||||
1000 | N.getTag() == dwarf::DW_TAG_friend,do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false) | ||||
1001 | "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_typedef || N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag() == dwarf::DW_TAG_ptr_to_member_type || N.getTag() == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type || N.getTag() == dwarf:: DW_TAG_const_type || N.getTag() == dwarf::DW_TAG_volatile_type || N.getTag() == dwarf::DW_TAG_restrict_type || N.getTag() == dwarf::DW_TAG_atomic_type || N.getTag() == dwarf::DW_TAG_member || N.getTag() == dwarf::DW_TAG_inheritance || N.getTag() == dwarf ::DW_TAG_friend)) { DebugInfoCheckFailed("invalid tag", & N); return; } } while (false); | ||||
1002 | if (N.getTag() == dwarf::DW_TAG_ptr_to_member_type) { | ||||
1003 | AssertDI(isType(N.getRawExtraData()), "invalid pointer to member type", &N,do { if (!(isType(N.getRawExtraData()))) { DebugInfoCheckFailed ("invalid pointer to member type", &N, N.getRawExtraData( )); return; } } while (false) | ||||
1004 | N.getRawExtraData())do { if (!(isType(N.getRawExtraData()))) { DebugInfoCheckFailed ("invalid pointer to member type", &N, N.getRawExtraData( )); return; } } while (false); | ||||
1005 | } | ||||
1006 | |||||
1007 | AssertDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope())do { if (!(isScope(N.getRawScope()))) { DebugInfoCheckFailed( "invalid scope", &N, N.getRawScope()); return; } } while ( false); | ||||
1008 | AssertDI(isType(N.getRawBaseType()), "invalid base type", &N,do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed ("invalid base type", &N, N.getRawBaseType()); return; } } while (false) | ||||
1009 | N.getRawBaseType())do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed ("invalid base type", &N, N.getRawBaseType()); return; } } while (false); | ||||
1010 | |||||
1011 | if (N.getDWARFAddressSpace()) { | ||||
1012 | AssertDI(N.getTag() == dwarf::DW_TAG_pointer_type ||do { if (!(N.getTag() == dwarf::DW_TAG_pointer_type || N.getTag () == dwarf::DW_TAG_reference_type || N.getTag() == dwarf::DW_TAG_rvalue_reference_type )) { DebugInfoCheckFailed("DWARF address space only applies to pointer or reference types" , &N); return; } } while (false) | ||||
1013 | 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) | ||||
1014 | 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) | ||||
1015 | "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) | ||||
1016 | &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); | ||||
1017 | } | ||||
1018 | } | ||||
1019 | |||||
1020 | /// Detect mutually exclusive flags. | ||||
1021 | static bool hasConflictingReferenceFlags(unsigned Flags) { | ||||
1022 | return ((Flags & DINode::FlagLValueReference) && | ||||
1023 | (Flags & DINode::FlagRValueReference)) || | ||||
1024 | ((Flags & DINode::FlagTypePassByValue) && | ||||
1025 | (Flags & DINode::FlagTypePassByReference)); | ||||
1026 | } | ||||
1027 | |||||
1028 | void Verifier::visitTemplateParams(const MDNode &N, const Metadata &RawParams) { | ||||
1029 | auto *Params = dyn_cast<MDTuple>(&RawParams); | ||||
1030 | AssertDI(Params, "invalid template params", &N, &RawParams)do { if (!(Params)) { DebugInfoCheckFailed("invalid template params" , &N, &RawParams); return; } } while (false); | ||||
1031 | for (Metadata *Op : Params->operands()) { | ||||
1032 | AssertDI(Op && isa<DITemplateParameter>(Op), "invalid template parameter",do { if (!(Op && isa<DITemplateParameter>(Op))) { DebugInfoCheckFailed("invalid template parameter", &N, Params, Op); return; } } while (false) | ||||
1033 | &N, Params, Op)do { if (!(Op && isa<DITemplateParameter>(Op))) { DebugInfoCheckFailed("invalid template parameter", &N, Params, Op); return; } } while (false); | ||||
1034 | } | ||||
1035 | } | ||||
1036 | |||||
1037 | void Verifier::visitDICompositeType(const DICompositeType &N) { | ||||
1038 | // Common scope checks. | ||||
1039 | visitDIScope(N); | ||||
1040 | |||||
1041 | AssertDI(N.getTag() == dwarf::DW_TAG_array_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag () == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type || N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag( ) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false) | ||||
1042 | N.getTag() == dwarf::DW_TAG_structure_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag () == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type || N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag( ) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false) | ||||
1043 | N.getTag() == dwarf::DW_TAG_union_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag () == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type || N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag( ) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false) | ||||
1044 | N.getTag() == dwarf::DW_TAG_enumeration_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag () == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type || N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag( ) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false) | ||||
1045 | N.getTag() == dwarf::DW_TAG_class_type ||do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag () == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type || N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag( ) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false) | ||||
1046 | N.getTag() == dwarf::DW_TAG_variant_part,do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag () == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type || N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag( ) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false) | ||||
1047 | "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_array_type || N.getTag () == dwarf::DW_TAG_structure_type || N.getTag() == dwarf::DW_TAG_union_type || N.getTag() == dwarf::DW_TAG_enumeration_type || N.getTag( ) == dwarf::DW_TAG_class_type || N.getTag() == dwarf::DW_TAG_variant_part )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false); | ||||
1048 | |||||
1049 | AssertDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope())do { if (!(isScope(N.getRawScope()))) { DebugInfoCheckFailed( "invalid scope", &N, N.getRawScope()); return; } } while ( false); | ||||
1050 | AssertDI(isType(N.getRawBaseType()), "invalid base type", &N,do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed ("invalid base type", &N, N.getRawBaseType()); return; } } while (false) | ||||
1051 | N.getRawBaseType())do { if (!(isType(N.getRawBaseType()))) { DebugInfoCheckFailed ("invalid base type", &N, N.getRawBaseType()); return; } } while (false); | ||||
1052 | |||||
1053 | AssertDI(!N.getRawElements() || isa<MDTuple>(N.getRawElements()),do { if (!(!N.getRawElements() || isa<MDTuple>(N.getRawElements ()))) { DebugInfoCheckFailed("invalid composite elements", & N, N.getRawElements()); return; } } while (false) | ||||
1054 | "invalid composite elements", &N, N.getRawElements())do { if (!(!N.getRawElements() || isa<MDTuple>(N.getRawElements ()))) { DebugInfoCheckFailed("invalid composite elements", & N, N.getRawElements()); return; } } while (false); | ||||
1055 | AssertDI(isType(N.getRawVTableHolder()), "invalid vtable holder", &N,do { if (!(isType(N.getRawVTableHolder()))) { DebugInfoCheckFailed ("invalid vtable holder", &N, N.getRawVTableHolder()); return ; } } while (false) | ||||
1056 | N.getRawVTableHolder())do { if (!(isType(N.getRawVTableHolder()))) { DebugInfoCheckFailed ("invalid vtable holder", &N, N.getRawVTableHolder()); return ; } } while (false); | ||||
1057 | AssertDI(!hasConflictingReferenceFlags(N.getFlags()),do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ) | ||||
1058 | "invalid reference flags", &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ); | ||||
1059 | unsigned DIBlockByRefStruct = 1 << 4; | ||||
1060 | AssertDI((N.getFlags() & DIBlockByRefStruct) == 0,do { if (!((N.getFlags() & DIBlockByRefStruct) == 0)) { DebugInfoCheckFailed ("DIBlockByRefStruct on DICompositeType is no longer supported" , &N); return; } } while (false) | ||||
1061 | "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); | ||||
1062 | |||||
1063 | if (N.isVector()) { | ||||
1064 | const DINodeArray Elements = N.getElements(); | ||||
1065 | AssertDI(Elements.size() == 1 &&do { if (!(Elements.size() == 1 && Elements[0]->getTag () == dwarf::DW_TAG_subrange_type)) { DebugInfoCheckFailed("invalid vector, expected one element of type subrange" , &N); return; } } while (false) | ||||
1066 | 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) | ||||
1067 | "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); | ||||
1068 | } | ||||
1069 | |||||
1070 | if (auto *Params = N.getRawTemplateParams()) | ||||
1071 | visitTemplateParams(N, *Params); | ||||
1072 | |||||
1073 | if (N.getTag() == dwarf::DW_TAG_class_type || | ||||
1074 | N.getTag() == dwarf::DW_TAG_union_type) { | ||||
1075 | AssertDI(N.getFile() && !N.getFile()->getFilename().empty(),do { if (!(N.getFile() && !N.getFile()->getFilename ().empty())) { DebugInfoCheckFailed("class/union requires a filename" , &N, N.getFile()); return; } } while (false) | ||||
1076 | "class/union requires a filename", &N, N.getFile())do { if (!(N.getFile() && !N.getFile()->getFilename ().empty())) { DebugInfoCheckFailed("class/union requires a filename" , &N, N.getFile()); return; } } while (false); | ||||
1077 | } | ||||
1078 | |||||
1079 | if (auto *D = N.getRawDiscriminator()) { | ||||
1080 | AssertDI(isa<DIDerivedType>(D) && N.getTag() == dwarf::DW_TAG_variant_part,do { if (!(isa<DIDerivedType>(D) && N.getTag() == dwarf::DW_TAG_variant_part)) { DebugInfoCheckFailed("discriminator can only appear on variant part" ); return; } } while (false) | ||||
1081 | "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); | ||||
1082 | } | ||||
1083 | |||||
1084 | if (N.getRawDataLocation()) { | ||||
1085 | AssertDI(N.getTag() == dwarf::DW_TAG_array_type,do { if (!(N.getTag() == dwarf::DW_TAG_array_type)) { DebugInfoCheckFailed ("dataLocation can only appear in array type"); return; } } while (false) | ||||
1086 | "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); | ||||
1087 | } | ||||
1088 | |||||
1089 | if (N.getRawAssociated()) { | ||||
1090 | AssertDI(N.getTag() == dwarf::DW_TAG_array_type,do { if (!(N.getTag() == dwarf::DW_TAG_array_type)) { DebugInfoCheckFailed ("associated can only appear in array type"); return; } } while (false) | ||||
1091 | "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); | ||||
1092 | } | ||||
1093 | |||||
1094 | if (N.getRawAllocated()) { | ||||
1095 | AssertDI(N.getTag() == dwarf::DW_TAG_array_type,do { if (!(N.getTag() == dwarf::DW_TAG_array_type)) { DebugInfoCheckFailed ("allocated can only appear in array type"); return; } } while (false) | ||||
1096 | "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); | ||||
1097 | } | ||||
1098 | |||||
1099 | if (N.getRawRank()) { | ||||
1100 | AssertDI(N.getTag() == dwarf::DW_TAG_array_type,do { if (!(N.getTag() == dwarf::DW_TAG_array_type)) { DebugInfoCheckFailed ("rank can only appear in array type"); return; } } while (false ) | ||||
1101 | "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 ); | ||||
1102 | } | ||||
1103 | } | ||||
1104 | |||||
1105 | void Verifier::visitDISubroutineType(const DISubroutineType &N) { | ||||
1106 | AssertDI(N.getTag() == dwarf::DW_TAG_subroutine_type, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_subroutine_type)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | ||||
1107 | if (auto *Types = N.getRawTypeArray()) { | ||||
1108 | AssertDI(isa<MDTuple>(Types), "invalid composite elements", &N, Types)do { if (!(isa<MDTuple>(Types))) { DebugInfoCheckFailed ("invalid composite elements", &N, Types); return; } } while (false); | ||||
1109 | for (Metadata *Ty : N.getTypeArray()->operands()) { | ||||
1110 | AssertDI(isType(Ty), "invalid subroutine type ref", &N, Types, Ty)do { if (!(isType(Ty))) { DebugInfoCheckFailed("invalid subroutine type ref" , &N, Types, Ty); return; } } while (false); | ||||
1111 | } | ||||
1112 | } | ||||
1113 | AssertDI(!hasConflictingReferenceFlags(N.getFlags()),do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ) | ||||
1114 | "invalid reference flags", &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ); | ||||
1115 | } | ||||
1116 | |||||
1117 | void Verifier::visitDIFile(const DIFile &N) { | ||||
1118 | AssertDI(N.getTag() == dwarf::DW_TAG_file_type, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_file_type)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | ||||
1119 | Optional<DIFile::ChecksumInfo<StringRef>> Checksum = N.getChecksum(); | ||||
1120 | if (Checksum) { | ||||
1121 | AssertDI(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last,do { if (!(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last )) { DebugInfoCheckFailed("invalid checksum kind", &N); return ; } } while (false) | ||||
1122 | "invalid checksum kind", &N)do { if (!(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last )) { DebugInfoCheckFailed("invalid checksum kind", &N); return ; } } while (false); | ||||
1123 | size_t Size; | ||||
1124 | switch (Checksum->Kind) { | ||||
1125 | case DIFile::CSK_MD5: | ||||
1126 | Size = 32; | ||||
1127 | break; | ||||
1128 | case DIFile::CSK_SHA1: | ||||
1129 | Size = 40; | ||||
1130 | break; | ||||
1131 | case DIFile::CSK_SHA256: | ||||
1132 | Size = 64; | ||||
1133 | break; | ||||
1134 | } | ||||
1135 | AssertDI(Checksum->Value.size() == Size, "invalid checksum length", &N)do { if (!(Checksum->Value.size() == Size)) { DebugInfoCheckFailed ("invalid checksum length", &N); return; } } while (false ); | ||||
1136 | AssertDI(Checksum->Value.find_if_not(llvm::isHexDigit) == StringRef::npos,do { if (!(Checksum->Value.find_if_not(llvm::isHexDigit) == StringRef::npos)) { DebugInfoCheckFailed("invalid checksum", &N); return; } } while (false) | ||||
1137 | "invalid checksum", &N)do { if (!(Checksum->Value.find_if_not(llvm::isHexDigit) == StringRef::npos)) { DebugInfoCheckFailed("invalid checksum", &N); return; } } while (false); | ||||
1138 | } | ||||
1139 | } | ||||
1140 | |||||
1141 | void Verifier::visitDICompileUnit(const DICompileUnit &N) { | ||||
1142 | AssertDI(N.isDistinct(), "compile units must be distinct", &N)do { if (!(N.isDistinct())) { DebugInfoCheckFailed("compile units must be distinct" , &N); return; } } while (false); | ||||
1143 | AssertDI(N.getTag() == dwarf::DW_TAG_compile_unit, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_compile_unit)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | ||||
1144 | |||||
1145 | // Don't bother verifying the compilation directory or producer string | ||||
1146 | // as those could be empty. | ||||
1147 | AssertDI(N.getRawFile() && isa<DIFile>(N.getRawFile()), "invalid file", &N,do { if (!(N.getRawFile() && isa<DIFile>(N.getRawFile ()))) { DebugInfoCheckFailed("invalid file", &N, N.getRawFile ()); return; } } while (false) | ||||
1148 | N.getRawFile())do { if (!(N.getRawFile() && isa<DIFile>(N.getRawFile ()))) { DebugInfoCheckFailed("invalid file", &N, N.getRawFile ()); return; } } while (false); | ||||
1149 | AssertDI(!N.getFile()->getFilename().empty(), "invalid filename", &N,do { if (!(!N.getFile()->getFilename().empty())) { DebugInfoCheckFailed ("invalid filename", &N, N.getFile()); return; } } while ( false) | ||||
1150 | N.getFile())do { if (!(!N.getFile()->getFilename().empty())) { DebugInfoCheckFailed ("invalid filename", &N, N.getFile()); return; } } while ( false); | ||||
1151 | |||||
1152 | CurrentSourceLang = (dwarf::SourceLanguage)N.getSourceLanguage(); | ||||
1153 | |||||
1154 | verifySourceDebugInfo(N, *N.getFile()); | ||||
1155 | |||||
1156 | AssertDI((N.getEmissionKind() <= DICompileUnit::LastEmissionKind),do { if (!((N.getEmissionKind() <= DICompileUnit::LastEmissionKind ))) { DebugInfoCheckFailed("invalid emission kind", &N); return ; } } while (false) | ||||
1157 | "invalid emission kind", &N)do { if (!((N.getEmissionKind() <= DICompileUnit::LastEmissionKind ))) { DebugInfoCheckFailed("invalid emission kind", &N); return ; } } while (false); | ||||
1158 | |||||
1159 | if (auto *Array = N.getRawEnumTypes()) { | ||||
1160 | AssertDI(isa<MDTuple>(Array), "invalid enum list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed ("invalid enum list", &N, Array); return; } } while (false ); | ||||
1161 | for (Metadata *Op : N.getEnumTypes()->operands()) { | ||||
1162 | auto *Enum = dyn_cast_or_null<DICompositeType>(Op); | ||||
1163 | AssertDI(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type,do { if (!(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type )) { DebugInfoCheckFailed("invalid enum type", &N, N.getEnumTypes (), Op); return; } } while (false) | ||||
1164 | "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); | ||||
1165 | } | ||||
1166 | } | ||||
1167 | if (auto *Array = N.getRawRetainedTypes()) { | ||||
1168 | AssertDI(isa<MDTuple>(Array), "invalid retained type list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed ("invalid retained type list", &N, Array); return; } } while (false); | ||||
1169 | for (Metadata *Op : N.getRetainedTypes()->operands()) { | ||||
1170 | AssertDI(Op && (isa<DIType>(Op) ||do { if (!(Op && (isa<DIType>(Op) || (isa<DISubprogram >(Op) && !cast<DISubprogram>(Op)->isDefinition ())))) { DebugInfoCheckFailed("invalid retained type", &N , Op); return; } } while (false) | ||||
1171 | (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) | ||||
1172 | !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) | ||||
1173 | "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); | ||||
1174 | } | ||||
1175 | } | ||||
1176 | if (auto *Array = N.getRawGlobalVariables()) { | ||||
1177 | AssertDI(isa<MDTuple>(Array), "invalid global variable list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed ("invalid global variable list", &N, Array); return; } } while (false); | ||||
1178 | for (Metadata *Op : N.getGlobalVariables()->operands()) { | ||||
1179 | AssertDI(Op && (isa<DIGlobalVariableExpression>(Op)),do { if (!(Op && (isa<DIGlobalVariableExpression> (Op)))) { DebugInfoCheckFailed("invalid global variable ref", &N, Op); return; } } while (false) | ||||
1180 | "invalid global variable ref", &N, Op)do { if (!(Op && (isa<DIGlobalVariableExpression> (Op)))) { DebugInfoCheckFailed("invalid global variable ref", &N, Op); return; } } while (false); | ||||
1181 | } | ||||
1182 | } | ||||
1183 | if (auto *Array = N.getRawImportedEntities()) { | ||||
1184 | AssertDI(isa<MDTuple>(Array), "invalid imported entity list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed ("invalid imported entity list", &N, Array); return; } } while (false); | ||||
1185 | for (Metadata *Op : N.getImportedEntities()->operands()) { | ||||
1186 | AssertDI(Op && isa<DIImportedEntity>(Op), "invalid imported entity ref",do { if (!(Op && isa<DIImportedEntity>(Op))) { DebugInfoCheckFailed ("invalid imported entity ref", &N, Op); return; } } while (false) | ||||
1187 | &N, Op)do { if (!(Op && isa<DIImportedEntity>(Op))) { DebugInfoCheckFailed ("invalid imported entity ref", &N, Op); return; } } while (false); | ||||
1188 | } | ||||
1189 | } | ||||
1190 | if (auto *Array = N.getRawMacros()) { | ||||
1191 | AssertDI(isa<MDTuple>(Array), "invalid macro list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed ("invalid macro list", &N, Array); return; } } while (false ); | ||||
1192 | for (Metadata *Op : N.getMacros()->operands()) { | ||||
1193 | AssertDI(Op && isa<DIMacroNode>(Op), "invalid macro ref", &N, Op)do { if (!(Op && isa<DIMacroNode>(Op))) { DebugInfoCheckFailed ("invalid macro ref", &N, Op); return; } } while (false); | ||||
1194 | } | ||||
1195 | } | ||||
1196 | CUVisited.insert(&N); | ||||
1197 | } | ||||
1198 | |||||
1199 | void Verifier::visitDISubprogram(const DISubprogram &N) { | ||||
1200 | AssertDI(N.getTag() == dwarf::DW_TAG_subprogram, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_subprogram)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | ||||
1201 | AssertDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope())do { if (!(isScope(N.getRawScope()))) { DebugInfoCheckFailed( "invalid scope", &N, N.getRawScope()); return; } } while ( false); | ||||
1202 | if (auto *F = N.getRawFile()) | ||||
1203 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | ||||
1204 | else | ||||
1205 | AssertDI(N.getLine() == 0, "line specified with no file", &N, N.getLine())do { if (!(N.getLine() == 0)) { DebugInfoCheckFailed("line specified with no file" , &N, N.getLine()); return; } } while (false); | ||||
1206 | if (auto *T = N.getRawType()) | ||||
1207 | AssertDI(isa<DISubroutineType>(T), "invalid subroutine type", &N, T)do { if (!(isa<DISubroutineType>(T))) { DebugInfoCheckFailed ("invalid subroutine type", &N, T); return; } } while (false ); | ||||
1208 | AssertDI(isType(N.getRawContainingType()), "invalid containing type", &N,do { if (!(isType(N.getRawContainingType()))) { DebugInfoCheckFailed ("invalid containing type", &N, N.getRawContainingType()) ; return; } } while (false) | ||||
1209 | N.getRawContainingType())do { if (!(isType(N.getRawContainingType()))) { DebugInfoCheckFailed ("invalid containing type", &N, N.getRawContainingType()) ; return; } } while (false); | ||||
1210 | if (auto *Params = N.getRawTemplateParams()) | ||||
1211 | visitTemplateParams(N, *Params); | ||||
1212 | if (auto *S = N.getRawDeclaration()) | ||||
1213 | AssertDI(isa<DISubprogram>(S) && !cast<DISubprogram>(S)->isDefinition(),do { if (!(isa<DISubprogram>(S) && !cast<DISubprogram >(S)->isDefinition())) { DebugInfoCheckFailed("invalid subprogram declaration" , &N, S); return; } } while (false) | ||||
1214 | "invalid subprogram declaration", &N, S)do { if (!(isa<DISubprogram>(S) && !cast<DISubprogram >(S)->isDefinition())) { DebugInfoCheckFailed("invalid subprogram declaration" , &N, S); return; } } while (false); | ||||
1215 | if (auto *RawNode = N.getRawRetainedNodes()) { | ||||
1216 | auto *Node = dyn_cast<MDTuple>(RawNode); | ||||
1217 | AssertDI(Node, "invalid retained nodes list", &N, RawNode)do { if (!(Node)) { DebugInfoCheckFailed("invalid retained nodes list" , &N, RawNode); return; } } while (false); | ||||
1218 | for (Metadata *Op : Node->operands()) { | ||||
1219 | AssertDI(Op && (isa<DILocalVariable>(Op) || isa<DILabel>(Op)),do { if (!(Op && (isa<DILocalVariable>(Op) || isa <DILabel>(Op)))) { DebugInfoCheckFailed("invalid retained nodes, expected DILocalVariable or DILabel" , &N, Node, Op); return; } } while (false) | ||||
1220 | "invalid retained nodes, expected DILocalVariable or DILabel",do { if (!(Op && (isa<DILocalVariable>(Op) || isa <DILabel>(Op)))) { DebugInfoCheckFailed("invalid retained nodes, expected DILocalVariable or DILabel" , &N, Node, Op); return; } } while (false) | ||||
1221 | &N, Node, Op)do { if (!(Op && (isa<DILocalVariable>(Op) || isa <DILabel>(Op)))) { DebugInfoCheckFailed("invalid retained nodes, expected DILocalVariable or DILabel" , &N, Node, Op); return; } } while (false); | ||||
1222 | } | ||||
1223 | } | ||||
1224 | AssertDI(!hasConflictingReferenceFlags(N.getFlags()),do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ) | ||||
1225 | "invalid reference flags", &N)do { if (!(!hasConflictingReferenceFlags(N.getFlags()))) { DebugInfoCheckFailed ("invalid reference flags", &N); return; } } while (false ); | ||||
1226 | |||||
1227 | auto *Unit = N.getRawUnit(); | ||||
1228 | if (N.isDefinition()) { | ||||
1229 | // Subprogram definitions (not part of the type hierarchy). | ||||
1230 | AssertDI(N.isDistinct(), "subprogram definitions must be distinct", &N)do { if (!(N.isDistinct())) { DebugInfoCheckFailed("subprogram definitions must be distinct" , &N); return; } } while (false); | ||||
1231 | AssertDI(Unit, "subprogram definitions must have a compile unit", &N)do { if (!(Unit)) { DebugInfoCheckFailed("subprogram definitions must have a compile unit" , &N); return; } } while (false); | ||||
1232 | AssertDI(isa<DICompileUnit>(Unit), "invalid unit type", &N, Unit)do { if (!(isa<DICompileUnit>(Unit))) { DebugInfoCheckFailed ("invalid unit type", &N, Unit); return; } } while (false ); | ||||
1233 | if (N.getFile()) | ||||
1234 | verifySourceDebugInfo(*N.getUnit(), *N.getFile()); | ||||
1235 | } else { | ||||
1236 | // Subprogram declarations (part of the type hierarchy). | ||||
1237 | AssertDI(!Unit, "subprogram declarations must not have a compile unit", &N)do { if (!(!Unit)) { DebugInfoCheckFailed("subprogram declarations must not have a compile unit" , &N); return; } } while (false); | ||||
1238 | } | ||||
1239 | |||||
1240 | if (auto *RawThrownTypes = N.getRawThrownTypes()) { | ||||
1241 | auto *ThrownTypes = dyn_cast<MDTuple>(RawThrownTypes); | ||||
1242 | AssertDI(ThrownTypes, "invalid thrown types list", &N, RawThrownTypes)do { if (!(ThrownTypes)) { DebugInfoCheckFailed("invalid thrown types list" , &N, RawThrownTypes); return; } } while (false); | ||||
1243 | for (Metadata *Op : ThrownTypes->operands()) | ||||
1244 | AssertDI(Op && isa<DIType>(Op), "invalid thrown type", &N, ThrownTypes,do { if (!(Op && isa<DIType>(Op))) { DebugInfoCheckFailed ("invalid thrown type", &N, ThrownTypes, Op); return; } } while (false) | ||||
1245 | Op)do { if (!(Op && isa<DIType>(Op))) { DebugInfoCheckFailed ("invalid thrown type", &N, ThrownTypes, Op); return; } } while (false); | ||||
1246 | } | ||||
1247 | |||||
1248 | if (N.areAllCallsDescribed()) | ||||
1249 | AssertDI(N.isDefinition(),do { if (!(N.isDefinition())) { DebugInfoCheckFailed("DIFlagAllCallsDescribed must be attached to a definition" ); return; } } while (false) | ||||
1250 | "DIFlagAllCallsDescribed must be attached to a definition")do { if (!(N.isDefinition())) { DebugInfoCheckFailed("DIFlagAllCallsDescribed must be attached to a definition" ); return; } } while (false); | ||||
1251 | } | ||||
1252 | |||||
1253 | void Verifier::visitDILexicalBlockBase(const DILexicalBlockBase &N) { | ||||
1254 | AssertDI(N.getTag() == dwarf::DW_TAG_lexical_block, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_lexical_block)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | ||||
1255 | AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { DebugInfoCheckFailed("invalid local scope" , &N, N.getRawScope()); return; } } while (false) | ||||
1256 | "invalid local scope", &N, N.getRawScope())do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { DebugInfoCheckFailed("invalid local scope" , &N, N.getRawScope()); return; } } while (false); | ||||
1257 | if (auto *SP = dyn_cast<DISubprogram>(N.getRawScope())) | ||||
1258 | AssertDI(SP->isDefinition(), "scope points into the type hierarchy", &N)do { if (!(SP->isDefinition())) { DebugInfoCheckFailed("scope points into the type hierarchy" , &N); return; } } while (false); | ||||
1259 | } | ||||
1260 | |||||
1261 | void Verifier::visitDILexicalBlock(const DILexicalBlock &N) { | ||||
1262 | visitDILexicalBlockBase(N); | ||||
1263 | |||||
1264 | AssertDI(N.getLine() || !N.getColumn(),do { if (!(N.getLine() || !N.getColumn())) { DebugInfoCheckFailed ("cannot have column info without line info", &N); return ; } } while (false) | ||||
1265 | "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); | ||||
1266 | } | ||||
1267 | |||||
1268 | void Verifier::visitDILexicalBlockFile(const DILexicalBlockFile &N) { | ||||
1269 | visitDILexicalBlockBase(N); | ||||
1270 | } | ||||
1271 | |||||
1272 | void Verifier::visitDICommonBlock(const DICommonBlock &N) { | ||||
1273 | AssertDI(N.getTag() == dwarf::DW_TAG_common_block, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_common_block)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | ||||
1274 | if (auto *S = N.getRawScope()) | ||||
1275 | AssertDI(isa<DIScope>(S), "invalid scope ref", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope ref" , &N, S); return; } } while (false); | ||||
1276 | if (auto *S = N.getRawDecl()) | ||||
1277 | AssertDI(isa<DIGlobalVariable>(S), "invalid declaration", &N, S)do { if (!(isa<DIGlobalVariable>(S))) { DebugInfoCheckFailed ("invalid declaration", &N, S); return; } } while (false); | ||||
1278 | } | ||||
1279 | |||||
1280 | void Verifier::visitDINamespace(const DINamespace &N) { | ||||
1281 | AssertDI(N.getTag() == dwarf::DW_TAG_namespace, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_namespace)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | ||||
1282 | if (auto *S = N.getRawScope()) | ||||
1283 | AssertDI(isa<DIScope>(S), "invalid scope ref", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope ref" , &N, S); return; } } while (false); | ||||
1284 | } | ||||
1285 | |||||
1286 | void Verifier::visitDIMacro(const DIMacro &N) { | ||||
1287 | AssertDI(N.getMacinfoType() == dwarf::DW_MACINFO_define ||do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_define || N .getMacinfoType() == dwarf::DW_MACINFO_undef)) { DebugInfoCheckFailed ("invalid macinfo type", &N); return; } } while (false) | ||||
1288 | 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) | ||||
1289 | "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); | ||||
1290 | AssertDI(!N.getName().empty(), "anonymous macro", &N)do { if (!(!N.getName().empty())) { DebugInfoCheckFailed("anonymous macro" , &N); return; } } while (false); | ||||
1291 | if (!N.getValue().empty()) { | ||||
1292 | assert(N.getValue().data()[0] != ' ' && "Macro value has a space prefix")((N.getValue().data()[0] != ' ' && "Macro value has a space prefix" ) ? static_cast<void> (0) : __assert_fail ("N.getValue().data()[0] != ' ' && \"Macro value has a space prefix\"" , "/build/llvm-toolchain-snapshot-12~++20210124100612+2afaf072f5c1/llvm/lib/IR/Verifier.cpp" , 1292, __PRETTY_FUNCTION__)); | ||||
1293 | } | ||||
1294 | } | ||||
1295 | |||||
1296 | void Verifier::visitDIMacroFile(const DIMacroFile &N) { | ||||
1297 | AssertDI(N.getMacinfoType() == dwarf::DW_MACINFO_start_file,do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_start_file )) { DebugInfoCheckFailed("invalid macinfo type", &N); return ; } } while (false) | ||||
1298 | "invalid macinfo type", &N)do { if (!(N.getMacinfoType() == dwarf::DW_MACINFO_start_file )) { DebugInfoCheckFailed("invalid macinfo type", &N); return ; } } while (false); | ||||
1299 | if (auto *F = N.getRawFile()) | ||||
1300 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | ||||
1301 | |||||
1302 | if (auto *Array = N.getRawElements()) { | ||||
1303 | AssertDI(isa<MDTuple>(Array), "invalid macro list", &N, Array)do { if (!(isa<MDTuple>(Array))) { DebugInfoCheckFailed ("invalid macro list", &N, Array); return; } } while (false ); | ||||
1304 | for (Metadata *Op : N.getElements()->operands()) { | ||||
1305 | AssertDI(Op && isa<DIMacroNode>(Op), "invalid macro ref", &N, Op)do { if (!(Op && isa<DIMacroNode>(Op))) { DebugInfoCheckFailed ("invalid macro ref", &N, Op); return; } } while (false); | ||||
1306 | } | ||||
1307 | } | ||||
1308 | } | ||||
1309 | |||||
1310 | void Verifier::visitDIModule(const DIModule &N) { | ||||
1311 | AssertDI(N.getTag() == dwarf::DW_TAG_module, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_module)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | ||||
1312 | AssertDI(!N.getName().empty(), "anonymous module", &N)do { if (!(!N.getName().empty())) { DebugInfoCheckFailed("anonymous module" , &N); return; } } while (false); | ||||
1313 | } | ||||
1314 | |||||
1315 | void Verifier::visitDITemplateParameter(const DITemplateParameter &N) { | ||||
1316 | AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType())do { if (!(isType(N.getRawType()))) { DebugInfoCheckFailed("invalid type ref" , &N, N.getRawType()); return; } } while (false); | ||||
1317 | } | ||||
1318 | |||||
1319 | void Verifier::visitDITemplateTypeParameter(const DITemplateTypeParameter &N) { | ||||
1320 | visitDITemplateParameter(N); | ||||
1321 | |||||
1322 | AssertDI(N.getTag() == dwarf::DW_TAG_template_type_parameter, "invalid tag",do { if (!(N.getTag() == dwarf::DW_TAG_template_type_parameter )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false) | ||||
1323 | &N)do { if (!(N.getTag() == dwarf::DW_TAG_template_type_parameter )) { DebugInfoCheckFailed("invalid tag", &N); return; } } while (false); | ||||
1324 | } | ||||
1325 | |||||
1326 | void Verifier::visitDITemplateValueParameter( | ||||
1327 | const DITemplateValueParameter &N) { | ||||
1328 | visitDITemplateParameter(N); | ||||
1329 | |||||
1330 | AssertDI(N.getTag() == dwarf::DW_TAG_template_value_parameter ||do { if (!(N.getTag() == dwarf::DW_TAG_template_value_parameter || N.getTag() == dwarf::DW_TAG_GNU_template_template_param || N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false) | ||||
1331 | 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) | ||||
1332 | 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) | ||||
1333 | "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); | ||||
1334 | } | ||||
1335 | |||||
1336 | void Verifier::visitDIVariable(const DIVariable &N) { | ||||
1337 | if (auto *S = N.getRawScope()) | ||||
1338 | AssertDI(isa<DIScope>(S), "invalid scope", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope" , &N, S); return; } } while (false); | ||||
1339 | if (auto *F = N.getRawFile()) | ||||
1340 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | ||||
1341 | } | ||||
1342 | |||||
1343 | void Verifier::visitDIGlobalVariable(const DIGlobalVariable &N) { | ||||
1344 | // Checks common to all variables. | ||||
1345 | visitDIVariable(N); | ||||
1346 | |||||
1347 | AssertDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_variable)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | ||||
1348 | AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType())do { if (!(isType(N.getRawType()))) { DebugInfoCheckFailed("invalid type ref" , &N, N.getRawType()); return; } } while (false); | ||||
1349 | // Assert only if the global variable is not an extern | ||||
1350 | if (N.isDefinition()) | ||||
1351 | AssertDI(N.getType(), "missing global variable type", &N)do { if (!(N.getType())) { DebugInfoCheckFailed("missing global variable type" , &N); return; } } while (false); | ||||
1352 | if (auto *Member = N.getRawStaticDataMemberDeclaration()) { | ||||
1353 | AssertDI(isa<DIDerivedType>(Member),do { if (!(isa<DIDerivedType>(Member))) { DebugInfoCheckFailed ("invalid static data member declaration", &N, Member); return ; } } while (false) | ||||
1354 | "invalid static data member declaration", &N, Member)do { if (!(isa<DIDerivedType>(Member))) { DebugInfoCheckFailed ("invalid static data member declaration", &N, Member); return ; } } while (false); | ||||
1355 | } | ||||
1356 | } | ||||
1357 | |||||
1358 | void Verifier::visitDILocalVariable(const DILocalVariable &N) { | ||||
1359 | // Checks common to all variables. | ||||
1360 | visitDIVariable(N); | ||||
1361 | |||||
1362 | AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType())do { if (!(isType(N.getRawType()))) { DebugInfoCheckFailed("invalid type ref" , &N, N.getRawType()); return; } } while (false); | ||||
1363 | AssertDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_variable)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | ||||
1364 | AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { DebugInfoCheckFailed("local variable requires a valid scope" , &N, N.getRawScope()); return; } } while (false) | ||||
1365 | "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); | ||||
1366 | if (auto Ty = N.getType()) | ||||
1367 | AssertDI(!isa<DISubroutineType>(Ty), "invalid type", &N, N.getType())do { if (!(!isa<DISubroutineType>(Ty))) { DebugInfoCheckFailed ("invalid type", &N, N.getType()); return; } } while (false ); | ||||
1368 | } | ||||
1369 | |||||
1370 | void Verifier::visitDILabel(const DILabel &N) { | ||||
1371 | if (auto *S = N.getRawScope()) | ||||
1372 | AssertDI(isa<DIScope>(S), "invalid scope", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope" , &N, S); return; } } while (false); | ||||
1373 | if (auto *F = N.getRawFile()) | ||||
1374 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | ||||
1375 | |||||
1376 | AssertDI(N.getTag() == dwarf::DW_TAG_label, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_label)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | ||||
1377 | AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),do { if (!(N.getRawScope() && isa<DILocalScope> (N.getRawScope()))) { DebugInfoCheckFailed("label requires a valid scope" , &N, N.getRawScope()); return; } } while (false) | ||||
1378 | "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); | ||||
1379 | } | ||||
1380 | |||||
1381 | void Verifier::visitDIExpression(const DIExpression &N) { | ||||
1382 | AssertDI(N.isValid(), "invalid expression", &N)do { if (!(N.isValid())) { DebugInfoCheckFailed("invalid expression" , &N); return; } } while (false); | ||||
1383 | } | ||||
1384 | |||||
1385 | void Verifier::visitDIGlobalVariableExpression( | ||||
1386 | const DIGlobalVariableExpression &GVE) { | ||||
1387 | AssertDI(GVE.getVariable(), "missing variable")do { if (!(GVE.getVariable())) { DebugInfoCheckFailed("missing variable" ); return; } } while (false); | ||||
1388 | if (auto *Var = GVE.getVariable()) | ||||
1389 | visitDIGlobalVariable(*Var); | ||||
1390 | if (auto *Expr = GVE.getExpression()) { | ||||
1391 | visitDIExpression(*Expr); | ||||
1392 | if (auto Fragment = Expr->getFragmentInfo()) | ||||
1393 | verifyFragmentExpression(*GVE.getVariable(), *Fragment, &GVE); | ||||
1394 | } | ||||
1395 | } | ||||
1396 | |||||
1397 | void Verifier::visitDIObjCProperty(const DIObjCProperty &N) { | ||||
1398 | AssertDI(N.getTag() == dwarf::DW_TAG_APPLE_property, "invalid tag", &N)do { if (!(N.getTag() == dwarf::DW_TAG_APPLE_property)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false); | ||||
1399 | if (auto *T = N.getRawType()) | ||||
1400 | AssertDI(isType(T), "invalid type ref", &N, T)do { if (!(isType(T))) { DebugInfoCheckFailed("invalid type ref" , &N, T); return; } } while (false); | ||||
1401 | if (auto *F = N.getRawFile()) | ||||
1402 | AssertDI(isa<DIFile>(F), "invalid file", &N, F)do { if (!(isa<DIFile>(F))) { DebugInfoCheckFailed("invalid file" , &N, F); return; } } while (false); | ||||
1403 | } | ||||
1404 | |||||
1405 | void Verifier::visitDIImportedEntity(const DIImportedEntity &N) { | ||||
1406 | AssertDI(N.getTag() == dwarf::DW_TAG_imported_module ||do { if (!(N.getTag() == dwarf::DW_TAG_imported_module || N.getTag () == dwarf::DW_TAG_imported_declaration)) { DebugInfoCheckFailed ("invalid tag", &N); return; } } while (false) | ||||
1407 | 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) | ||||
1408 | "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); | ||||
1409 | if (auto *S = N.getRawScope()) | ||||
1410 | AssertDI(isa<DIScope>(S), "invalid scope for imported entity", &N, S)do { if (!(isa<DIScope>(S))) { DebugInfoCheckFailed("invalid scope for imported entity" , &N, S); return; } } while (false); | ||||
1411 | AssertDI(isDINode(N.getRawEntity()), "invalid imported entity", &N,do { if (!(isDINode(N.getRawEntity()))) { DebugInfoCheckFailed ("invalid imported entity", &N, N.getRawEntity()); return ; } } while (false) | ||||
1412 | N.getRawEntity())do { if (!(isDINode(N.getRawEntity()))) { DebugInfoCheckFailed ("invalid imported entity", &N, N.getRawEntity()); return ; } } while (false); | ||||
1413 | } | ||||
1414 | |||||
1415 | void Verifier::visitComdat(const Comdat &C) { | ||||
1416 | // In COFF the Module is invalid if the GlobalValue has private linkage. | ||||
1417 | // Entities with private linkage don't have entries in the symbol table. | ||||
1418 | if (TT.isOSBinFormatCOFF()) | ||||
1419 | if (const GlobalValue *GV = M.getNamedValue(C.getName())) | ||||
1420 | Assert(!GV->hasPrivateLinkage(),do { if (!(!GV->hasPrivateLinkage())) { CheckFailed("comdat global value has private linkage" , GV); return; } } while (false) | ||||
1421 | "comdat global value has private linkage", GV)do { if (!(!GV->hasPrivateLinkage())) { CheckFailed("comdat global value has private linkage" , GV); return; } } while (false); | ||||
1422 | } | ||||
1423 | |||||
1424 | void Verifier::visitModuleIdents(const Module &M) { | ||||
1425 | const NamedMDNode *Idents = M.getNamedMetadata("llvm.ident"); | ||||
1426 | if (!Idents) | ||||
1427 | return; | ||||
1428 | |||||
1429 | // llvm.ident takes a list of metadata entry. Each entry has only one string. | ||||
1430 | // Scan each llvm.ident entry and make sure that this requirement is met. | ||||
1431 | for (const MDNode *N : Idents->operands()) { | ||||
1432 | Assert(N->getNumOperands() == 1,do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.ident metadata" , N); return; } } while (false) | ||||
1433 | "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); | ||||
1434 | Assert(dyn_cast_or_null<MDString>(N->getOperand(0)),do { if (!(dyn_cast_or_null<MDString>(N->getOperand( 0)))) { CheckFailed(("invalid value for llvm.ident metadata entry operand" "(the operand should be a string)"), N->getOperand(0)); return ; } } while (false) | ||||
1435 | ("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) | ||||
1436 | "(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) | ||||
1437 | 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); | ||||
1438 | } | ||||
1439 | } | ||||
1440 | |||||
1441 | void Verifier::visitModuleCommandLines(const Module &M) { | ||||
1442 | const NamedMDNode *CommandLines = M.getNamedMetadata("llvm.commandline"); | ||||
1443 | if (!CommandLines) | ||||
1444 | return; | ||||
1445 | |||||
1446 | // llvm.commandline takes a list of metadata entry. Each entry has only one | ||||
1447 | // string. Scan each llvm.commandline entry and make sure that this | ||||
1448 | // requirement is met. | ||||
1449 | for (const MDNode *N : CommandLines->operands()) { | ||||
1450 | Assert(N->getNumOperands() == 1,do { if (!(N->getNumOperands() == 1)) { CheckFailed("incorrect number of operands in llvm.commandline metadata" , N); return; } } while (false) | ||||
1451 | "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); | ||||
1452 | Assert(dyn_cast_or_null<MDString>(N->getOperand(0)),do { if (!(dyn_cast_or_null<MDString>(N->getOperand( 0)))) { CheckFailed(("invalid value for llvm.commandline metadata entry operand" "(the operand should be a string)"), N->getOperand(0)); return ; } } while (false) | ||||
1453 | ("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) | ||||
1454 | "(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) | ||||
1455 | 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); | ||||
1456 | } | ||||
1457 | } | ||||
1458 | |||||
1459 | void Verifier::visitModuleFlags(const Module &M) { | ||||
1460 | const NamedMDNode *Flags = M.getModuleFlagsMetadata(); | ||||
1461 | if (!Flags) return; | ||||
1462 | |||||
1463 | // Scan each flag, and track the flags and requirements. | ||||
1464 | DenseMap<const MDString*, const MDNode*> SeenIDs; | ||||
1465 | SmallVector<const MDNode*, 16> Requirements; | ||||
1466 | for (const MDNode *MDN : Flags->operands()) | ||||
1467 | visitModuleFlag(MDN, SeenIDs, Requirements); | ||||
1468 | |||||
1469 | // Validate that the requirements in the module are valid. | ||||
1470 | for (const MDNode *Requirement : Requirements) { | ||||
1471 | const MDString *Flag = cast<MDString>(Requirement->getOperand(0)); | ||||
1472 | const Metadata *ReqValue = Requirement->getOperand(1); | ||||
1473 | |||||
1474 | const MDNode *Op = SeenIDs.lookup(Flag); | ||||
1475 | if (!Op) { | ||||
1476 | CheckFailed("invalid requirement on flag, flag is not present in module", | ||||
1477 | Flag); | ||||
1478 | continue; | ||||
1479 | } | ||||
1480 | |||||
1481 | if (Op->getOperand(2) != ReqValue) { | ||||
1482 | CheckFailed(("invalid requirement on flag, " | ||||
1483 | "flag does not have the required value"), | ||||
1484 | Flag); | ||||
1485 | continue; | ||||
1486 | } | ||||
1487 | } | ||||
1488 | } | ||||
1489 | |||||
1490 | void | ||||
1491 | Verifier::visitModuleFlag(const MDNode *Op, | ||||
1492 | DenseMap<const MDString *, const MDNode *> &SeenIDs, | ||||
1493 | SmallVectorImpl<const MDNode *> &Requirements) { | ||||
1494 | // Each module flag should have three arguments, the merge behavior (a | ||||
1495 | // constant int), the flag ID (an MDString), and the value. | ||||
1496 | Assert(Op->getNumOperands() == 3,do { if (!(Op->getNumOperands() == 3)) { CheckFailed("incorrect number of operands in module flag" , Op); return; } } while (false) | ||||
1497 | "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); | ||||
1498 | Module::ModFlagBehavior MFB; | ||||
1499 | if (!Module::isValidModFlagBehavior(Op->getOperand(0), MFB)) { | ||||
1500 | Assert(do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op ->getOperand(0)))) { CheckFailed("invalid behavior operand in module flag (expected constant integer)" , Op->getOperand(0)); return; } } while (false) | ||||
1501 | 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) | ||||
1502 | "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) | ||||
1503 | 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); | ||||
1504 | Assert(false,do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)" , Op->getOperand(0)); return; } } while (false) | ||||
1505 | "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) | ||||
1506 | Op->getOperand(0))do { if (!(false)) { CheckFailed("invalid behavior operand in module flag (unexpected constant)" , Op->getOperand(0)); return; } } while (false); | ||||
1507 | } | ||||
1508 | MDString *ID = dyn_cast_or_null<MDString>(Op->getOperand(1)); | ||||
1509 | Assert(ID, "invalid ID operand in module flag (expected metadata string)",do { if (!(ID)) { CheckFailed("invalid ID operand in module flag (expected metadata string)" , Op->getOperand(1)); return; } } while (false) | ||||
1510 | Op->getOperand(1))do { if (!(ID)) { CheckFailed("invalid ID operand in module flag (expected metadata string)" , Op->getOperand(1)); return; } } while (false); | ||||
1511 | |||||
1512 | // Sanity check the values for behaviors with additional requirements. | ||||
1513 | switch (MFB) { | ||||
1514 | case Module::Error: | ||||
1515 | case Module::Warning: | ||||
1516 | case Module::Override: | ||||
1517 | // These behavior types accept any value. | ||||
1518 | break; | ||||
1519 | |||||
1520 | case Module::Max: { | ||||
1521 | Assert(mdconst::dyn_extract_or_null<ConstantInt>(Op->getOperand(2)),do { if (!(mdconst::dyn_extract_or_null<ConstantInt>(Op ->getOperand(2)))) { CheckFailed("invalid value for 'max' module flag (expected constant integer)" , Op->getOperand(2)); return; } } while (false) | ||||
1522 | "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) | ||||
1523 | 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); | ||||
1524 | break; | ||||
1525 | } | ||||
1526 | |||||
1527 | case Module::Require: { | ||||
1528 | // The value should itself be an MDNode with two operands, a flag ID (an | ||||
1529 | // MDString), and a value. | ||||
1530 | MDNode *Value = dyn_cast<MDNode>(Op->getOperand(2)); | ||||
1531 | Assert(Value && Value->getNumOperands() == 2,do { if (!(Value && Value->getNumOperands() == 2)) { CheckFailed("invalid value for 'require' module flag (expected metadata pair)" , Op->getOperand(2)); return; } } while (false) | ||||
1532 | "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) | ||||
1533 | 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); | ||||
1534 | Assert(isa<MDString>(Value->getOperand(0)),do { if (!(isa<MDString>(Value->getOperand(0)))) { CheckFailed (("invalid value for 'require' module flag " "(first value operand should be a string)" ), Value->getOperand(0)); return; } } while (false) | ||||
1535 | ("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) | ||||
1536 | "(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) | ||||
1537 | 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); | ||||
1538 | |||||
1539 | // Append it to the list of requirements, to check once all module flags are | ||||
1540 | // scanned. | ||||
1541 | Requirements.push_back(Value); | ||||
1542 | break; | ||||
1543 | } | ||||
1544 | |||||
1545 | case Module::Append: | ||||
1546 | case Module::AppendUnique: { | ||||
1547 | // These behavior types require the operand be an MDNode. | ||||
1548 | Assert(isa<MDNode>(Op->getOperand(2)),do { if (!(isa<MDNode>(Op->getOperand(2)))) { CheckFailed ("invalid value for 'append'-type module flag " "(expected a metadata node)" , Op->getOperand(2)); return; } } while (false) | ||||
1549 | "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) | ||||
1550 | "(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) | ||||
1551 | 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); | ||||
1552 | break; | ||||
1553 | } | ||||
1554 | } | ||||
1555 | |||||
1556 | // Unless this is a "requires" flag, check the ID is unique. | ||||
1557 | if (MFB != Module::Require) { | ||||
1558 | bool Inserted = SeenIDs.insert(std::make_pair(ID, Op)).second; | ||||
1559 | Assert(Inserted,do { if (!(Inserted)) { CheckFailed("module flag identifiers must be unique (or of 'require' type)" , ID); return; } } while (false) | ||||
1560 | "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); | ||||
1561 | } | ||||
1562 | |||||
1563 | if (ID->getString() == "wchar_size") { | ||||
1564 | ConstantInt *Value | ||||
1565 | = mdconst::dyn_extract_or_null<ConstantInt>(Op->getOperand(2)); | ||||
1566 | Assert(Value, "wchar_size metadata requires constant integer argument")do { if (!(Value)) { CheckFailed("wchar_size metadata requires constant integer argument" ); return; } } while (false); | ||||
1567 | } | ||||
1568 | |||||
1569 | if (ID->getString() == "Linker Options") { | ||||
1570 | // If the llvm.linker.options named metadata exists, we assume that the | ||||
1571 | // bitcode reader has upgraded the module flag. Otherwise the flag might | ||||
1572 | // have been created by a client directly. | ||||
1573 | Assert(M.getNamedMetadata("llvm.linker.options"),do { if (!(M.getNamedMetadata("llvm.linker.options"))) { CheckFailed ("'Linker Options' named metadata no longer supported"); return ; } } while (false) | ||||
1574 | "'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); | ||||
1575 | } | ||||
1576 | |||||
1577 | if (ID->getString() == "SemanticInterposition") { | ||||
1578 | ConstantInt *Value = | ||||
1579 | mdconst::dyn_extract_or_null<ConstantInt>(Op->getOperand(2)); | ||||
1580 | Assert(Value,do { if (!(Value)) { CheckFailed("SemanticInterposition metadata requires constant integer argument" ); return; } } while (false) | ||||
1581 | "SemanticInterposition metadata requires constant integer argument")do { if (!(Value)) { CheckFailed("SemanticInterposition metadata requires constant integer argument" ); return; } } while (false); | ||||
1582 | } | ||||
1583 | |||||
1584 | if (ID->getString() == "CG Profile") { | ||||
1585 | for (const MDOperand &MDO : cast<MDNode>(Op->getOperand(2))->operands()) | ||||
1586 | visitModuleFlagCGProfileEntry(MDO); | ||||
1587 | } | ||||
1588 | } | ||||
1589 | |||||
1590 | void Verifier::visitModuleFlagCGProfileEntry(const MDOperand &MDO) { | ||||
1591 | auto CheckFunction = [&](const MDOperand &FuncMDO) { | ||||
1592 | if (!FuncMDO) | ||||
1593 | return; | ||||
1594 | auto F = dyn_cast<ValueAsMetadata>(FuncMDO); | ||||
1595 | Assert(F && isa<Function>(F->getValue()->stripPointerCasts()),do { if (!(F && isa<Function>(F->getValue()-> stripPointerCasts()))) { CheckFailed("expected a Function or null" , FuncMDO); return; } } while (false) | ||||
1596 | "expected a Function or null", FuncMDO)do { if (!(F && isa<Function>(F->getValue()-> stripPointerCasts()))) { CheckFailed("expected a Function or null" , FuncMDO); return; } } while (false); | ||||
1597 | }; | ||||
1598 | auto Node = dyn_cast_or_null<MDNode>(MDO); | ||||
1599 | Assert(Node && Node->getNumOperands() == 3, "expected a MDNode triple", MDO)do { if (!(Node && Node->getNumOperands() == 3)) { CheckFailed("expected a MDNode triple", MDO); return; } } while (false); | ||||
1600 | CheckFunction(Node->getOperand(0)); | ||||
1601 | CheckFunction(Node->getOperand(1)); | ||||
1602 | auto Count = dyn_cast_or_null<ConstantAsMetadata>(Node->getOperand(2)); | ||||
1603 | Assert(Count && Count->getType()->isIntegerTy(),do { if (!(Count && Count->getType()->isIntegerTy ())) { CheckFailed("expected an integer constant", Node->getOperand (2)); return; } } while (false) | ||||
1604 | "expected an integer constant", Node->getOperand(2))do { if (!(Count && Count->getType()->isIntegerTy ())) { CheckFailed("expected an integer constant", Node->getOperand (2)); return; } } while (false); | ||||
1605 | } | ||||
1606 | |||||
1607 | /// Return true if this attribute kind only applies to functions. | ||||
1608 | static bool isFuncOnlyAttr(Attribute::AttrKind Kind) { | ||||
1609 | switch (Kind) { | ||||
1610 | case Attribute::NoMerge: | ||||
1611 | case Attribute::NoReturn: | ||||
1612 | case Attribute::NoSync: | ||||
1613 | case Attribute::WillReturn: | ||||
1614 | case Attribute::NoCallback: | ||||
1615 | case Attribute::NoCfCheck: | ||||
1616 | case Attribute::NoUnwind: | ||||
1617 | case Attribute::NoInline: | ||||
1618 | case Attribute::AlwaysInline: | ||||
1619 | case Attribute::OptimizeForSize: | ||||
1620 | case Attribute::StackProtect: | ||||
1621 | case Attribute::StackProtectReq: | ||||
1622 | case Attribute::StackProtectStrong: | ||||
1623 | case Attribute::SafeStack: | ||||
1624 | case Attribute::ShadowCallStack: | ||||
1625 | case Attribute::NoRedZone: | ||||
1626 | case Attribute::NoImplicitFloat: | ||||
1627 | case Attribute::Naked: | ||||
1628 | case Attribute::InlineHint: | ||||
1629 | case Attribute::StackAlignment: | ||||
1630 | case Attribute::UWTable: | ||||
1631 | case Attribute::NonLazyBind: | ||||
1632 | case Attribute::ReturnsTwice: | ||||
1633 | case Attribute::SanitizeAddress: | ||||
1634 | case Attribute::SanitizeHWAddress: | ||||
1635 | case Attribute::SanitizeMemTag: | ||||
1636 | case Attribute::SanitizeThread: | ||||
1637 | case Attribute::SanitizeMemory: | ||||
1638 | case Attribute::MinSize: | ||||
1639 | case Attribute::NoDuplicate: | ||||
1640 | case Attribute::Builtin: | ||||
1641 | case Attribute::NoBuiltin: | ||||
1642 | case Attribute::Cold: | ||||
1643 | case Attribute::Hot: | ||||
1644 | case Attribute::OptForFuzzing: | ||||
1645 | case Attribute::OptimizeNone: | ||||
1646 | case Attribute::JumpTable: | ||||
1647 | case Attribute::Convergent: | ||||
1648 | case Attribute::ArgMemOnly: | ||||
1649 | case Attribute::NoRecurse: | ||||
1650 | case Attribute::InaccessibleMemOnly: | ||||
1651 | case Attribute::InaccessibleMemOrArgMemOnly: | ||||
1652 | case Attribute::AllocSize: | ||||
1653 | case Attribute::SpeculativeLoadHardening: | ||||
1654 | case Attribute::Speculatable: | ||||
1655 | case Attribute::StrictFP: | ||||
1656 | case Attribute::NullPointerIsValid: | ||||
1657 | case Attribute::MustProgress: | ||||
1658 | return true; | ||||
1659 | default: | ||||
1660 | break; | ||||
1661 | } | ||||
1662 | return false; | ||||
1663 | } | ||||
1664 | |||||
1665 | /// Return true if this is a function attribute that can also appear on | ||||
1666 | /// arguments. | ||||
1667 | static bool isFuncOrArgAttr(Attribute::AttrKind Kind) { | ||||
1668 | return Kind == Attribute::ReadOnly || Kind == Attribute::WriteOnly || | ||||
1669 | Kind == Attribute::ReadNone || Kind == Attribute::NoFree || | ||||
1670 | Kind == Attribute::Preallocated; | ||||
1671 | } | ||||
1672 | |||||
1673 | void Verifier::verifyAttributeTypes(AttributeSet Attrs, bool IsFunction, | ||||
1674 | const Value *V) { | ||||
1675 | for (Attribute A : Attrs) { | ||||
1676 | if (A.isStringAttribute()) | ||||
1677 | continue; | ||||
1678 | |||||
1679 | if (A.isIntAttribute() != | ||||
1680 | Attribute::doesAttrKindHaveArgument(A.getKindAsEnum())) { | ||||
1681 | CheckFailed("Attribute '" + A.getAsString() + "' should have an Argument", | ||||
1682 | V); | ||||
1683 | return; | ||||
1684 | } | ||||
1685 | |||||
1686 | if (isFuncOnlyAttr(A.getKindAsEnum())) { | ||||
1687 | if (!IsFunction) { | ||||
1688 | CheckFailed("Attribute '" + A.getAsString() + | ||||
1689 | "' only applies to functions!", | ||||
1690 | V); | ||||
1691 | return; | ||||
1692 | } | ||||
1693 | } else if (IsFunction && !isFuncOrArgAttr(A.getKindAsEnum())) { | ||||
1694 | CheckFailed("Attribute '" + A.getAsString() + | ||||
1695 | "' does not apply to functions!", | ||||
1696 | V); | ||||
1697 | return; | ||||
1698 | } | ||||
1699 | } | ||||
1700 | } | ||||
1701 | |||||
1702 | // VerifyParameterAttrs - Check the given attributes for an argument or return | ||||
1703 | // value of the specified type. The value V is printed in error messages. | ||||
1704 | void Verifier::verifyParameterAttrs(AttributeSet Attrs, Type *Ty, | ||||
1705 | const Value *V) { | ||||
1706 | if (!Attrs.hasAttributes()) | ||||
1707 | return; | ||||
1708 | |||||
1709 | verifyAttributeTypes(Attrs, /*IsFunction=*/false, V); | ||||
1710 | |||||
1711 | if (Attrs.hasAttribute(Attribute::ImmArg)) { | ||||
1712 | Assert(Attrs.getNumAttributes() == 1,do { if (!(Attrs.getNumAttributes() == 1)) { CheckFailed("Attribute 'immarg' is incompatible with other attributes" , V); return; } } while (false) | ||||
1713 | "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); | ||||
1714 | } | ||||
1715 | |||||
1716 | // Check for mutually incompatible attributes. Only inreg is compatible with | ||||
1717 | // sret. | ||||
1718 | unsigned AttrCount = 0; | ||||
1719 | AttrCount += Attrs.hasAttribute(Attribute::ByVal); | ||||
1720 | AttrCount += Attrs.hasAttribute(Attribute::InAlloca); | ||||
1721 | AttrCount += Attrs.hasAttribute(Attribute::Preallocated); | ||||
1722 | AttrCount += Attrs.hasAttribute(Attribute::StructRet) || | ||||
1723 | Attrs.hasAttribute(Attribute::InReg); | ||||
1724 | AttrCount += Attrs.hasAttribute(Attribute::Nest); | ||||
1725 | AttrCount += Attrs.hasAttribute(Attribute::ByRef); | ||||
1726 | Assert(AttrCount <= 1,do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'inreg', 'nest', " "'byref', and 'sret' are incompatible!", V); return; } } while (false) | ||||
1727 | "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) | ||||
1728 | "'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) | ||||
1729 | V)do { if (!(AttrCount <= 1)) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'inreg', 'nest', " "'byref', and 'sret' are incompatible!", V); return; } } while (false); | ||||
1730 | |||||
1731 | Assert(!(Attrs.hasAttribute(Attribute::InAlloca) &&do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'inalloca and readonly' are incompatible!", V); return; } } while (false) | ||||
1732 | 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) | ||||
1733 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'inalloca and readonly' are incompatible!", V); return; } } while (false) | ||||
1734 | "'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) | ||||
1735 | V)do { if (!(!(Attrs.hasAttribute(Attribute::InAlloca) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'inalloca and readonly' are incompatible!", V); return; } } while (false); | ||||
1736 | |||||
1737 | Assert(!(Attrs.hasAttribute(Attribute::StructRet) &&do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) && Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes " "'sret and returned' are incompatible!", V); return; } } while (false) | ||||
1738 | 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) | ||||
1739 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) && Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes " "'sret and returned' are incompatible!", V); return; } } while (false) | ||||
1740 | "'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) | ||||
1741 | V)do { if (!(!(Attrs.hasAttribute(Attribute::StructRet) && Attrs.hasAttribute(Attribute::Returned)))) { CheckFailed("Attributes " "'sret and returned' are incompatible!", V); return; } } while (false); | ||||
1742 | |||||
1743 | Assert(!(Attrs.hasAttribute(Attribute::ZExt) &&do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs .hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes " "'zeroext and signext' are incompatible!", V); return; } } while (false) | ||||
1744 | 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) | ||||
1745 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs .hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes " "'zeroext and signext' are incompatible!", V); return; } } while (false) | ||||
1746 | "'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) | ||||
1747 | V)do { if (!(!(Attrs.hasAttribute(Attribute::ZExt) && Attrs .hasAttribute(Attribute::SExt)))) { CheckFailed("Attributes " "'zeroext and signext' are incompatible!", V); return; } } while (false); | ||||
1748 | |||||
1749 | Assert(!(Attrs.hasAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'readnone and readonly' are incompatible!", V); return; } } while (false) | ||||
1750 | 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) | ||||
1751 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'readnone and readonly' are incompatible!", V); return; } } while (false) | ||||
1752 | "'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) | ||||
1753 | V)do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes " "'readnone and readonly' are incompatible!", V); return; } } while (false); | ||||
1754 | |||||
1755 | Assert(!(Attrs.hasAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readnone and writeonly' are incompatible!", V); return; } } while (false) | ||||
1756 | 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) | ||||
1757 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readnone and writeonly' are incompatible!", V); return; } } while (false) | ||||
1758 | "'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) | ||||
1759 | V)do { if (!(!(Attrs.hasAttribute(Attribute::ReadNone) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readnone and writeonly' are incompatible!", V); return; } } while (false); | ||||
1760 | |||||
1761 | Assert(!(Attrs.hasAttribute(Attribute::ReadOnly) &&do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readonly and writeonly' are incompatible!", V); return; } } while (false) | ||||
1762 | 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) | ||||
1763 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readonly and writeonly' are incompatible!", V); return; } } while (false) | ||||
1764 | "'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) | ||||
1765 | V)do { if (!(!(Attrs.hasAttribute(Attribute::ReadOnly) && Attrs.hasAttribute(Attribute::WriteOnly)))) { CheckFailed("Attributes " "'readonly and writeonly' are incompatible!", V); return; } } while (false); | ||||
1766 | |||||
1767 | Assert(!(Attrs.hasAttribute(Attribute::NoInline) &&do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) && Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed ("Attributes " "'noinline and alwaysinline' are incompatible!" , V); return; } } while (false) | ||||
1768 | 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) | ||||
1769 | "Attributes "do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) && Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed ("Attributes " "'noinline and alwaysinline' are incompatible!" , V); return; } } while (false) | ||||
1770 | "'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) | ||||
1771 | V)do { if (!(!(Attrs.hasAttribute(Attribute::NoInline) && Attrs.hasAttribute(Attribute::AlwaysInline)))) { CheckFailed ("Attributes " "'noinline and alwaysinline' are incompatible!" , V); return; } } while (false); | ||||
1772 | |||||
1773 | AttrBuilder IncompatibleAttrs = AttributeFuncs::typeIncompatible(Ty); | ||||
1774 | Assert(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs),do { if (!(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs))) { CheckFailed("Wrong types for attribute: " + AttributeSet::get (Context, IncompatibleAttrs).getAsString(), V); return; } } while (false) | ||||
1775 | "Wrong types for attribute: " +do { if (!(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs))) { CheckFailed("Wrong types for attribute: " + AttributeSet::get (Context, IncompatibleAttrs).getAsString(), V); return; } } while (false) | ||||
1776 | AttributeSet::get(Context, IncompatibleAttrs).getAsString(),do { if (!(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs))) { CheckFailed("Wrong types for attribute: " + AttributeSet::get (Context, IncompatibleAttrs).getAsString(), V); return; } } while (false) | ||||
1777 | V)do { if (!(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs))) { CheckFailed("Wrong types for attribute: " + AttributeSet::get (Context, IncompatibleAttrs).getAsString(), V); return; } } while (false); | ||||
1778 | |||||
1779 | if (PointerType *PTy = dyn_cast<PointerType>(Ty)) { | ||||
1780 | SmallPtrSet<Type*, 4> Visited; | ||||
1781 | if (!PTy->getElementType()->isSized(&Visited)) { | ||||
1782 | Assert(!Attrs.hasAttribute(Attribute::ByVal) &&do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && ! Attrs.hasAttribute(Attribute::ByRef) && !Attrs.hasAttribute (Attribute::InAlloca) && !Attrs.hasAttribute(Attribute ::Preallocated))) { CheckFailed("Attributes 'byval', 'byref', 'inalloca', and 'preallocated' do not " "support unsized types!", V); return; } } while (false) | ||||
1783 | !Attrs.hasAttribute(Attribute::ByRef) &&do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && ! Attrs.hasAttribute(Attribute::ByRef) && !Attrs.hasAttribute (Attribute::InAlloca) && !Attrs.hasAttribute(Attribute ::Preallocated))) { CheckFailed("Attributes 'byval', 'byref', 'inalloca', and 'preallocated' do not " "support unsized types!", V); return; } } while (false) | ||||
1784 | !Attrs.hasAttribute(Attribute::InAlloca) &&do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && ! Attrs.hasAttribute(Attribute::ByRef) && !Attrs.hasAttribute (Attribute::InAlloca) && !Attrs.hasAttribute(Attribute ::Preallocated))) { CheckFailed("Attributes 'byval', 'byref', 'inalloca', and 'preallocated' do not " "support unsized types!", V); return; } } while (false) | ||||
1785 | !Attrs.hasAttribute(Attribute::Preallocated),do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && ! Attrs.hasAttribute(Attribute::ByRef) && !Attrs.hasAttribute (Attribute::InAlloca) && !Attrs.hasAttribute(Attribute ::Preallocated))) { CheckFailed("Attributes 'byval', 'byref', 'inalloca', and 'preallocated' do not " "support unsized types!", V); return; } } while (false) | ||||
1786 | "Attributes 'byval', 'byref', 'inalloca', and 'preallocated' do not "do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && ! Attrs.hasAttribute(Attribute::ByRef) && !Attrs.hasAttribute (Attribute::InAlloca) && !Attrs.hasAttribute(Attribute ::Preallocated))) { CheckFailed("Attributes 'byval', 'byref', 'inalloca', and 'preallocated' do not " "support unsized types!", V); return; } } while (false) | ||||
1787 | "support unsized types!",do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && ! Attrs.hasAttribute(Attribute::ByRef) && !Attrs.hasAttribute (Attribute::InAlloca) && !Attrs.hasAttribute(Attribute ::Preallocated))) { CheckFailed("Attributes 'byval', 'byref', 'inalloca', and 'preallocated' do not " "support unsized types!", V); return; } } while (false) | ||||
1788 | V)do { if (!(!Attrs.hasAttribute(Attribute::ByVal) && ! Attrs.hasAttribute(Attribute::ByRef) && !Attrs.hasAttribute (Attribute::InAlloca) && !Attrs.hasAttribute(Attribute ::Preallocated))) { CheckFailed("Attributes 'byval', 'byref', 'inalloca', and 'preallocated' do not " "support unsized types!", V); return; } } while (false); | ||||
1789 | } | ||||
1790 | if (!isa<PointerType>(PTy->getElementType())) | ||||
1791 | Assert(!Attrs.hasAttribute(Attribute::SwiftError),do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer to pointer type!" , V); return; } } while (false) | ||||
1792 | "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) | ||||
1793 | "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) | ||||
1794 | V)do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer to pointer type!" , V); return; } } while (false); | ||||
1795 | |||||
1796 | if (Attrs.hasAttribute(Attribute::ByRef)) { | ||||
1797 | Assert(Attrs.getByRefType() == PTy->getElementType(),do { if (!(Attrs.getByRefType() == PTy->getElementType())) { CheckFailed("Attribute 'byref' type does not match parameter!" , V); return; } } while (false) | ||||
1798 | "Attribute 'byref' type does not match parameter!", V)do { if (!(Attrs.getByRefType() == PTy->getElementType())) { CheckFailed("Attribute 'byref' type does not match parameter!" , V); return; } } while (false); | ||||
1799 | } | ||||
1800 | |||||
1801 | if (Attrs.hasAttribute(Attribute::ByVal) && Attrs.getByValType()) { | ||||
1802 | Assert(Attrs.getByValType() == PTy->getElementType(),do { if (!(Attrs.getByValType() == PTy->getElementType())) { CheckFailed("Attribute 'byval' type does not match parameter!" , V); return; } } while (false) | ||||
1803 | "Attribute 'byval' type does not match parameter!", V)do { if (!(Attrs.getByValType() == PTy->getElementType())) { CheckFailed("Attribute 'byval' type does not match parameter!" , V); return; } } while (false); | ||||
1804 | } | ||||
1805 | |||||
1806 | if (Attrs.hasAttribute(Attribute::Preallocated)) { | ||||
1807 | Assert(Attrs.getPreallocatedType() == PTy->getElementType(),do { if (!(Attrs.getPreallocatedType() == PTy->getElementType ())) { CheckFailed("Attribute 'preallocated' type does not match parameter!" , V); return; } } while (false) | ||||
1808 | "Attribute 'preallocated' type does not match parameter!", V)do { if (!(Attrs.getPreallocatedType() == PTy->getElementType ())) { CheckFailed("Attribute 'preallocated' type does not match parameter!" , V); return; } } while (false); | ||||
1809 | } | ||||
1810 | } else { | ||||
1811 | Assert(!Attrs.hasAttribute(Attribute::ByVal),do { if (!(!Attrs.hasAttribute(Attribute::ByVal))) { CheckFailed ("Attribute 'byval' only applies to parameters with pointer type!" , V); return; } } while (false) | ||||
1812 | "Attribute 'byval' only applies to parameters with pointer type!",do { if (!(!Attrs.hasAttribute(Attribute::ByVal))) { CheckFailed ("Attribute 'byval' only applies to parameters with pointer type!" , V); return; } } while (false) | ||||
1813 | V)do { if (!(!Attrs.hasAttribute(Attribute::ByVal))) { CheckFailed ("Attribute 'byval' only applies to parameters with pointer type!" , V); return; } } while (false); | ||||
1814 | Assert(!Attrs.hasAttribute(Attribute::ByRef),do { if (!(!Attrs.hasAttribute(Attribute::ByRef))) { CheckFailed ("Attribute 'byref' only applies to parameters with pointer type!" , V); return; } } while (false) | ||||
1815 | "Attribute 'byref' only applies to parameters with pointer type!",do { if (!(!Attrs.hasAttribute(Attribute::ByRef))) { CheckFailed ("Attribute 'byref' only applies to parameters with pointer type!" , V); return; } } while (false) | ||||
1816 | V)do { if (!(!Attrs.hasAttribute(Attribute::ByRef))) { CheckFailed ("Attribute 'byref' only applies to parameters with pointer type!" , V); return; } } while (false); | ||||
1817 | Assert(!Attrs.hasAttribute(Attribute::SwiftError),do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer type!" , V); return; } } while (false) | ||||
1818 | "Attribute 'swifterror' only applies to parameters "do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer type!" , V); return; } } while (false) | ||||
1819 | "with pointer type!",do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer type!" , V); return; } } while (false) | ||||
1820 | V)do { if (!(!Attrs.hasAttribute(Attribute::SwiftError))) { CheckFailed ("Attribute 'swifterror' only applies to parameters " "with pointer type!" , V); return; } } while (false); | ||||
1821 | } | ||||
1822 | } | ||||
1823 | |||||
1824 | // Check parameter attributes against a function type. | ||||
1825 | // The value V is printed in error messages. | ||||
1826 | void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs, | ||||
1827 | const Value *V, bool IsIntrinsic) { | ||||
1828 | if (Attrs.isEmpty()) | ||||
1829 | return; | ||||
1830 | |||||
1831 | bool SawNest = false; | ||||
1832 | bool SawReturned = false; | ||||
1833 | bool SawSRet = false; | ||||
1834 | bool SawSwiftSelf = false; | ||||
1835 | bool SawSwiftError = false; | ||||
1836 | |||||
1837 | // Verify return value attributes. | ||||
1838 | AttributeSet RetAttrs = Attrs.getRetAttributes(); | ||||
1839 | Assert((!RetAttrs.hasAttribute(Attribute::ByVal) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::Preallocated) && ! RetAttrs.hasAttribute(Attribute::ByRef) && !RetAttrs. hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute (Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'byref', " "'nest', 'sret', 'nocapture', 'nofree', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | ||||
1840 | !RetAttrs.hasAttribute(Attribute::Nest) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::Preallocated) && ! RetAttrs.hasAttribute(Attribute::ByRef) && !RetAttrs. hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute (Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'byref', " "'nest', 'sret', 'nocapture', 'nofree', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | ||||
1841 | !RetAttrs.hasAttribute(Attribute::StructRet) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::Preallocated) && ! RetAttrs.hasAttribute(Attribute::ByRef) && !RetAttrs. hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute (Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'byref', " "'nest', 'sret', 'nocapture', 'nofree', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | ||||
1842 | !RetAttrs.hasAttribute(Attribute::NoCapture) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::Preallocated) && ! RetAttrs.hasAttribute(Attribute::ByRef) && !RetAttrs. hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute (Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'byref', " "'nest', 'sret', 'nocapture', 'nofree', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | ||||
1843 | !RetAttrs.hasAttribute(Attribute::NoFree) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::Preallocated) && ! RetAttrs.hasAttribute(Attribute::ByRef) && !RetAttrs. hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute (Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'byref', " "'nest', 'sret', 'nocapture', 'nofree', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | ||||
1844 | !RetAttrs.hasAttribute(Attribute::Returned) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::Preallocated) && ! RetAttrs.hasAttribute(Attribute::ByRef) && !RetAttrs. hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute (Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'byref', " "'nest', 'sret', 'nocapture', 'nofree', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | ||||
1845 | !RetAttrs.hasAttribute(Attribute::InAlloca) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::Preallocated) && ! RetAttrs.hasAttribute(Attribute::ByRef) && !RetAttrs. hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute (Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'byref', " "'nest', 'sret', 'nocapture', 'nofree', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | ||||
1846 | !RetAttrs.hasAttribute(Attribute::Preallocated) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::Preallocated) && ! RetAttrs.hasAttribute(Attribute::ByRef) && !RetAttrs. hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute (Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'byref', " "'nest', 'sret', 'nocapture', 'nofree', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | ||||
1847 | !RetAttrs.hasAttribute(Attribute::ByRef) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::Preallocated) && ! RetAttrs.hasAttribute(Attribute::ByRef) && !RetAttrs. hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute (Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'byref', " "'nest', 'sret', 'nocapture', 'nofree', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | ||||
1848 | !RetAttrs.hasAttribute(Attribute::SwiftSelf) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::Preallocated) && ! RetAttrs.hasAttribute(Attribute::ByRef) && !RetAttrs. hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute (Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'byref', " "'nest', 'sret', 'nocapture', 'nofree', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | ||||
1849 | !RetAttrs.hasAttribute(Attribute::SwiftError)),do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::Preallocated) && ! RetAttrs.hasAttribute(Attribute::ByRef) && !RetAttrs. hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute (Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'byref', " "'nest', 'sret', 'nocapture', 'nofree', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | ||||
1850 | "Attributes 'byval', 'inalloca', 'preallocated', 'byref', "do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::Preallocated) && ! RetAttrs.hasAttribute(Attribute::ByRef) && !RetAttrs. hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute (Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'byref', " "'nest', 'sret', 'nocapture', 'nofree', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | ||||
1851 | "'nest', 'sret', 'nocapture', 'nofree', "do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::Preallocated) && ! RetAttrs.hasAttribute(Attribute::ByRef) && !RetAttrs. hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute (Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'byref', " "'nest', 'sret', 'nocapture', 'nofree', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | ||||
1852 | "'returned', 'swiftself', and 'swifterror' do not apply to return "do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::Preallocated) && ! RetAttrs.hasAttribute(Attribute::ByRef) && !RetAttrs. hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute (Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'byref', " "'nest', 'sret', 'nocapture', 'nofree', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | ||||
1853 | "values!",do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::Preallocated) && ! RetAttrs.hasAttribute(Attribute::ByRef) && !RetAttrs. hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute (Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'byref', " "'nest', 'sret', 'nocapture', 'nofree', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false) | ||||
1854 | V)do { if (!((!RetAttrs.hasAttribute(Attribute::ByVal) && !RetAttrs.hasAttribute(Attribute::Nest) && !RetAttrs .hasAttribute(Attribute::StructRet) && !RetAttrs.hasAttribute (Attribute::NoCapture) && !RetAttrs.hasAttribute(Attribute ::NoFree) && !RetAttrs.hasAttribute(Attribute::Returned ) && !RetAttrs.hasAttribute(Attribute::InAlloca) && !RetAttrs.hasAttribute(Attribute::Preallocated) && ! RetAttrs.hasAttribute(Attribute::ByRef) && !RetAttrs. hasAttribute(Attribute::SwiftSelf) && !RetAttrs.hasAttribute (Attribute::SwiftError)))) { CheckFailed("Attributes 'byval', 'inalloca', 'preallocated', 'byref', " "'nest', 'sret', 'nocapture', 'nofree', " "'returned', 'swiftself', and 'swifterror' do not apply to return " "values!", V); return; } } while (false); | ||||
1855 | Assert((!RetAttrs.hasAttribute(Attribute::ReadOnly) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) && !RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs .hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '" + RetAttrs.getAsString() + "' does not apply to function returns" , V); return; } } while (false) | ||||
1856 | !RetAttrs.hasAttribute(Attribute::WriteOnly) &&do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) && !RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs .hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '" + RetAttrs.getAsString() + "' does not apply to function returns" , V); return; } } while (false) | ||||
1857 | !RetAttrs.hasAttribute(Attribute::ReadNone)),do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) && !RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs .hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '" + RetAttrs.getAsString() + "' does not apply to function returns" , V); return; } } while (false) | ||||
1858 | "Attribute '" + RetAttrs.getAsString() +do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) && !RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs .hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '" + RetAttrs.getAsString() + "' does not apply to function returns" , V); return; } } while (false) | ||||
1859 | "' does not apply to function returns",do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) && !RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs .hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '" + RetAttrs.getAsString() + "' does not apply to function returns" , V); return; } } while (false) | ||||
1860 | V)do { if (!((!RetAttrs.hasAttribute(Attribute::ReadOnly) && !RetAttrs.hasAttribute(Attribute::WriteOnly) && !RetAttrs .hasAttribute(Attribute::ReadNone)))) { CheckFailed("Attribute '" + RetAttrs.getAsString() + "' does not apply to function returns" , V); return; } } while (false); | ||||
1861 | verifyParameterAttrs(RetAttrs, FT->getReturnType(), V); | ||||
1862 | |||||
1863 | // Verify parameter attributes. | ||||
1864 | for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) { | ||||
1865 | Type *Ty = FT->getParamType(i); | ||||
1866 | AttributeSet ArgAttrs = Attrs.getParamAttributes(i); | ||||
1867 | |||||
1868 | if (!IsIntrinsic) { | ||||
1869 | Assert(!ArgAttrs.hasAttribute(Attribute::ImmArg),do { if (!(!ArgAttrs.hasAttribute(Attribute::ImmArg))) { CheckFailed ("immarg attribute only applies to intrinsics",V); return; } } while (false) | ||||
1870 | "immarg attribute only applies to intrinsics",V)do { if (!(!ArgAttrs.hasAttribute(Attribute::ImmArg))) { CheckFailed ("immarg attribute only applies to intrinsics",V); return; } } while (false); | ||||
1871 | } | ||||
1872 | |||||
1873 | verifyParameterAttrs(ArgAttrs, Ty, V); | ||||
1874 | |||||
1875 | if (ArgAttrs.hasAttribute(Attribute::Nest)) { | ||||
1876 | Assert(!SawNest, "More than one parameter has attribute nest!", V)do { if (!(!SawNest)) { CheckFailed("More than one parameter has attribute nest!" , V); return; } } while (false); | ||||
1877 | SawNest = true; | ||||
1878 | } | ||||
1879 | |||||
1880 | if (ArgAttrs.hasAttribute(Attribute::Returned)) { | ||||
1881 | Assert(!SawReturned, "More than one parameter has attribute returned!",do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!" , V); return; } } while (false) | ||||
1882 | V)do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!" , V); return; } } while (false); | ||||
1883 | Assert(Ty->canLosslesslyBitCastTo(FT->getReturnType()),do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' attribute" , V); return; } } while (false) | ||||
1884 | "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) | ||||
1885 | V)do { if (!(Ty->canLosslesslyBitCastTo(FT->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' attribute" , V); return; } } while (false); | ||||
1886 | SawReturned = true; | ||||
1887 | } | ||||
1888 | |||||
1889 | if (ArgAttrs.hasAttribute(Attribute::StructRet)) { | ||||
1890 | Assert(!SawSRet, "Cannot have multiple 'sret' parameters!", V)do { if (!(!SawSRet)) { CheckFailed("Cannot have multiple 'sret' parameters!" , V); return; } } while (false); | ||||
1891 | Assert(i == 0 || i == 1,do { if (!(i == 0 || i == 1)) { CheckFailed("Attribute 'sret' is not on first or second parameter!" , V); return; } } while (false) | ||||
1892 | "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); | ||||
1893 | SawSRet = true; | ||||
1894 | } | ||||
1895 | |||||
1896 | if (ArgAttrs.hasAttribute(Attribute::SwiftSelf)) { | ||||
1897 | Assert(!SawSwiftSelf, "Cannot have multiple 'swiftself' parameters!", V)do { if (!(!SawSwiftSelf)) { CheckFailed("Cannot have multiple 'swiftself' parameters!" , V); return; } } while (false); | ||||
1898 | SawSwiftSelf = true; | ||||
1899 | } | ||||
1900 | |||||
1901 | if (ArgAttrs.hasAttribute(Attribute::SwiftError)) { | ||||
1902 | Assert(!SawSwiftError, "Cannot have multiple 'swifterror' parameters!",do { if (!(!SawSwiftError)) { CheckFailed("Cannot have multiple 'swifterror' parameters!" , V); return; } } while (false) | ||||
1903 | V)do { if (!(!SawSwiftError)) { CheckFailed("Cannot have multiple 'swifterror' parameters!" , V); return; } } while (false); | ||||
1904 | SawSwiftError = true; | ||||
1905 | } | ||||
1906 | |||||
1907 | if (ArgAttrs.hasAttribute(Attribute::InAlloca)) { | ||||
1908 | Assert(i == FT->getNumParams() - 1,do { if (!(i == FT->getNumParams() - 1)) { CheckFailed("inalloca isn't on the last parameter!" , V); return; } } while (false) | ||||
1909 | "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); | ||||
1910 | } | ||||
1911 | } | ||||
1912 | |||||
1913 | if (!Attrs.hasAttributes(AttributeList::FunctionIndex)) | ||||
1914 | return; | ||||
1915 | |||||
1916 | verifyAttributeTypes(Attrs.getFnAttributes(), /*IsFunction=*/true, V); | ||||
1917 | |||||
1918 | Assert(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes 'readnone and readonly' are incompatible!" , V); return; } } while (false) | ||||
1919 | Attrs.hasFnAttribute(Attribute::ReadOnly)),do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes 'readnone and readonly' are incompatible!" , V); return; } } while (false) | ||||
1920 | "Attributes 'readnone and readonly' are incompatible!", V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::ReadOnly)))) { CheckFailed("Attributes 'readnone and readonly' are incompatible!" , V); return; } } while (false); | ||||
1921 | |||||
1922 | Assert(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed( "Attributes 'readnone and writeonly' are incompatible!", V); return ; } } while (false) | ||||
1923 | Attrs.hasFnAttribute(Attribute::WriteOnly)),do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed( "Attributes 'readnone and writeonly' are incompatible!", V); return ; } } while (false) | ||||
1924 | "Attributes 'readnone and writeonly' are incompatible!", V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed( "Attributes 'readnone and writeonly' are incompatible!", V); return ; } } while (false); | ||||
1925 | |||||
1926 | Assert(!(Attrs.hasFnAttribute(Attribute::ReadOnly) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadOnly) && Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed( "Attributes 'readonly and writeonly' are incompatible!", V); return ; } } while (false) | ||||
1927 | Attrs.hasFnAttribute(Attribute::WriteOnly)),do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadOnly) && Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed( "Attributes 'readonly and writeonly' are incompatible!", V); return ; } } while (false) | ||||
1928 | "Attributes 'readonly and writeonly' are incompatible!", V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadOnly) && Attrs.hasFnAttribute(Attribute::WriteOnly)))) { CheckFailed( "Attributes 'readonly and writeonly' are incompatible!", V); return ; } } while (false); | ||||
1929 | |||||
1930 | Assert(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly) ))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are " "incompatible!", V); return; } } while (false) | ||||
1931 | Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly)),do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly) ))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are " "incompatible!", V); return; } } while (false) | ||||
1932 | "Attributes 'readnone and inaccessiblemem_or_argmemonly' are "do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly) ))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are " "incompatible!", V); return; } } while (false) | ||||
1933 | "incompatible!",do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly) ))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are " "incompatible!", V); return; } } while (false) | ||||
1934 | V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly) ))) { CheckFailed("Attributes 'readnone and inaccessiblemem_or_argmemonly' are " "incompatible!", V); return; } } while (false); | ||||
1935 | |||||
1936 | Assert(!(Attrs.hasFnAttribute(Attribute::ReadNone) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOnly)))) { CheckFailed ("Attributes 'readnone and inaccessiblememonly' are incompatible!" , V); return; } } while (false) | ||||
1937 | Attrs.hasFnAttribute(Attribute::InaccessibleMemOnly)),do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOnly)))) { CheckFailed ("Attributes 'readnone and inaccessiblememonly' are incompatible!" , V); return; } } while (false) | ||||
1938 | "Attributes 'readnone and inaccessiblememonly' are incompatible!", V)do { if (!(!(Attrs.hasFnAttribute(Attribute::ReadNone) && Attrs.hasFnAttribute(Attribute::InaccessibleMemOnly)))) { CheckFailed ("Attributes 'readnone and inaccessiblememonly' are incompatible!" , V); return; } } while (false); | ||||
1939 | |||||
1940 | Assert(!(Attrs.hasFnAttribute(Attribute::NoInline) &&do { if (!(!(Attrs.hasFnAttribute(Attribute::NoInline) && Attrs.hasFnAttribute(Attribute::AlwaysInline)))) { CheckFailed ("Attributes 'noinline and alwaysinline' are incompatible!", V ); return; } } while (false) | ||||
1941 | Attrs.hasFnAttribute(Attribute::AlwaysInline)),do { if (!(!(Attrs.hasFnAttribute(Attribute::NoInline) && Attrs.hasFnAttribute(Attribute::AlwaysInline)))) { CheckFailed ("Attributes 'noinline and alwaysinline' are incompatible!", V ); return; } } while (false) | ||||
1942 | "Attributes 'noinline and alwaysinline' are incompatible!", V)do { if (!(!(Attrs.hasFnAttribute(Attribute::NoInline) && Attrs.hasFnAttribute(Attribute::AlwaysInline)))) { CheckFailed ("Attributes 'noinline and alwaysinline' are incompatible!", V ); return; } } while (false); | ||||
1943 | |||||
1944 | if (Attrs.hasFnAttribute(Attribute::OptimizeNone)) { | ||||
1945 | Assert(Attrs.hasFnAttribute(Attribute::NoInline),do { if (!(Attrs.hasFnAttribute(Attribute::NoInline))) { CheckFailed ("Attribute 'optnone' requires 'noinline'!", V); return; } } while (false) | ||||
1946 | "Attribute 'optnone' requires 'noinline'!", V)do { if (!(Attrs.hasFnAttribute(Attribute::NoInline))) { CheckFailed ("Attribute 'optnone' requires 'noinline'!", V); return; } } while (false); | ||||
1947 | |||||
1948 | Assert(!Attrs.hasFnAttribute(Attribute::OptimizeForSize),do { if (!(!Attrs.hasFnAttribute(Attribute::OptimizeForSize)) ) { CheckFailed("Attributes 'optsize and optnone' are incompatible!" , V); return; } } while (false) | ||||
1949 | "Attributes 'optsize and optnone' are incompatible!", V)do { if (!(!Attrs.hasFnAttribute(Attribute::OptimizeForSize)) ) { CheckFailed("Attributes 'optsize and optnone' are incompatible!" , V); return; } } while (false); | ||||
1950 | |||||
1951 | Assert(!Attrs.hasFnAttribute(Attribute::MinSize),do { if (!(!Attrs.hasFnAttribute(Attribute::MinSize))) { CheckFailed ("Attributes 'minsize and optnone' are incompatible!", V); return ; } } while (false) | ||||
1952 | "Attributes 'minsize and optnone' are incompatible!", V)do { if (!(!Attrs.hasFnAttribute(Attribute::MinSize))) { CheckFailed ("Attributes 'minsize and optnone' are incompatible!", V); return ; } } while (false); | ||||
1953 | } | ||||
1954 | |||||
1955 | if (Attrs.hasFnAttribute(Attribute::JumpTable)) { | ||||
1956 | const GlobalValue *GV = cast<GlobalValue>(V); | ||||
1957 | Assert(GV->hasGlobalUnnamedAddr(),do { if (!(GV->hasGlobalUnnamedAddr())) { CheckFailed("Attribute 'jumptable' requires 'unnamed_addr'" , V); return; } } while (false) | ||||
1958 | "Attribute 'jumptable' requires 'unnamed_addr'", V)do { if (!(GV->hasGlobalUnnamedAddr())) { CheckFailed("Attribute 'jumptable' requires 'unnamed_addr'" , V); return; } } while (false); | ||||
1959 | } | ||||
1960 | |||||
1961 | if (Attrs.hasFnAttribute(Attribute::AllocSize)) { | ||||
1962 | std::pair<unsigned, Optional<unsigned>> Args = | ||||
1963 | Attrs.getAllocSizeArgs(AttributeList::FunctionIndex); | ||||
1964 | |||||
1965 | auto CheckParam = [&](StringRef Name, unsigned ParamNo) { | ||||
1966 | if (ParamNo >= FT->getNumParams()) { | ||||
1967 | CheckFailed("'allocsize' " + Name + " argument is out of bounds", V); | ||||
1968 | return false; | ||||
1969 | } | ||||
1970 | |||||
1971 | if (!FT->getParamType(ParamNo)->isIntegerTy()) { | ||||
1972 | CheckFailed("'allocsize' " + Name + | ||||
1973 | " argument must refer to an integer parameter", | ||||
1974 | V); | ||||
1975 | return false; | ||||
1976 | } | ||||
1977 | |||||
1978 | return true; | ||||
1979 | }; | ||||
1980 | |||||
1981 | if (!CheckParam("element size", Args.first)) | ||||
1982 | return; | ||||
1983 | |||||
1984 | if (Args.second && !CheckParam("number of elements", *Args.second)) | ||||
1985 | return; | ||||
1986 | } | ||||
1987 | |||||
1988 | if (Attrs.hasFnAttribute("frame-pointer")) { | ||||
1989 | StringRef FP = Attrs.getAttribute(AttributeList::FunctionIndex, | ||||
1990 | "frame-pointer").getValueAsString(); | ||||
1991 | if (FP != "all" && FP != "non-leaf" && FP != "none") | ||||
1992 | CheckFailed("invalid value for 'frame-pointer' attribute: " + FP, V); | ||||
1993 | } | ||||
1994 | |||||
1995 | if (Attrs.hasFnAttribute("patchable-function-prefix")) { | ||||
1996 | StringRef S = Attrs | ||||
1997 | .getAttribute(AttributeList::FunctionIndex, | ||||
1998 | "patchable-function-prefix") | ||||
1999 | .getValueAsString(); | ||||
2000 | unsigned N; | ||||
2001 | if (S.getAsInteger(10, N)) | ||||
2002 | CheckFailed( | ||||
2003 | "\"patchable-function-prefix\" takes an unsigned integer: " + S, V); | ||||
2004 | } | ||||
2005 | if (Attrs.hasFnAttribute("patchable-function-entry")) { | ||||
2006 | StringRef S = Attrs | ||||
2007 | .getAttribute(AttributeList::FunctionIndex, | ||||
2008 | "patchable-function-entry") | ||||
2009 | .getValueAsString(); | ||||
2010 | unsigned N; | ||||
2011 | if (S.getAsInteger(10, N)) | ||||
2012 | CheckFailed( | ||||
2013 | "\"patchable-function-entry\" takes an unsigned integer: " + S, V); | ||||
2014 | } | ||||
2015 | } | ||||
2016 | |||||
2017 | void Verifier::verifyFunctionMetadata( | ||||
2018 | ArrayRef<std::pair<unsigned, MDNode *>> MDs) { | ||||
2019 | for (const auto &Pair : MDs) { | ||||
2020 | if (Pair.first == LLVMContext::MD_prof) { | ||||
2021 | MDNode *MD = Pair.second; | ||||
2022 | Assert(MD->getNumOperands() >= 2,do { if (!(MD->getNumOperands() >= 2)) { CheckFailed("!prof annotations should have no less than 2 operands" , MD); return; } } while (false) | ||||
2023 | "!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); | ||||
2024 | |||||
2025 | // Check first operand. | ||||
2026 | Assert(MD->getOperand(0) != nullptr, "first operand should not be null",do { if (!(MD->getOperand(0) != nullptr)) { CheckFailed("first operand should not be null" , MD); return; } } while (false) | ||||
2027 | MD)do { if (!(MD->getOperand(0) != nullptr)) { CheckFailed("first operand should not be null" , MD); return; } } while (false); | ||||
2028 | Assert(isa<MDString>(MD->getOperand(0)),do { if (!(isa<MDString>(MD->getOperand(0)))) { CheckFailed ("expected string with name of the !prof annotation", MD); return ; } } while (false) | ||||
2029 | "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); | ||||
2030 | MDString *MDS = cast<MDString>(MD->getOperand(0)); | ||||
2031 | StringRef ProfName = MDS->getString(); | ||||
2032 | Assert(ProfName.equals("function_entry_count") ||do { if (!(ProfName.equals("function_entry_count") || ProfName .equals("synthetic_function_entry_count"))) { CheckFailed("first operand should be 'function_entry_count'" " or 'synthetic_function_entry_count'", MD); return; } } while (false) | ||||
2033 | 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) | ||||
2034 | "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) | ||||
2035 | " 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) | ||||
2036 | 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); | ||||
2037 | |||||
2038 | // Check second operand. | ||||
2039 | Assert(MD->getOperand(1) != nullptr, "second operand should not be null",do { if (!(MD->getOperand(1) != nullptr)) { CheckFailed("second operand should not be null" , MD); return; } } while (false) | ||||
2040 | MD)do { if (!(MD->getOperand(1) != nullptr)) { CheckFailed("second operand should not be null" , MD); return; } } while (false); | ||||
2041 | Assert(isa<ConstantAsMetadata>(MD->getOperand(1)),do { if (!(isa<ConstantAsMetadata>(MD->getOperand(1) ))) { CheckFailed("expected integer argument to function_entry_count" , MD); return; } } while (false) | ||||
2042 | "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); | ||||
2043 | } | ||||
2044 | } | ||||
2045 | } | ||||
2046 | |||||
2047 | void Verifier::visitConstantExprsRecursively(const Constant *EntryC) { | ||||
2048 | if (!ConstantExprVisited.insert(EntryC).second) | ||||
2049 | return; | ||||
2050 | |||||
2051 | SmallVector<const Constant *, 16> Stack; | ||||
2052 | Stack.push_back(EntryC); | ||||
2053 | |||||
2054 | while (!Stack.empty()) { | ||||
2055 | const Constant *C = Stack.pop_back_val(); | ||||
2056 | |||||
2057 | // Check this constant expression. | ||||
2058 | if (const auto *CE = dyn_cast<ConstantExpr>(C)) | ||||
2059 | visitConstantExpr(CE); | ||||
2060 | |||||
2061 | if (const auto *GV = dyn_cast<GlobalValue>(C)) { | ||||
2062 | // Global Values get visited separately, but we do need to make sure | ||||
2063 | // that the global value is in the correct module | ||||
2064 | Assert(GV->getParent() == &M, "Referencing global in another module!",do { if (!(GV->getParent() == &M)) { CheckFailed("Referencing global in another module!" , EntryC, &M, GV, GV->getParent()); return; } } while ( false) | ||||
2065 | EntryC, &M, GV, GV->getParent())do { if (!(GV->getParent() == &M)) { CheckFailed("Referencing global in another module!" , EntryC, &M, GV, GV->getParent()); return; } } while ( false); | ||||
2066 | continue; | ||||
2067 | } | ||||
2068 | |||||
2069 | // Visit all sub-expressions. | ||||
2070 | for (const Use &U : C->operands()) { | ||||
2071 | const auto *OpC = dyn_cast<Constant>(U); | ||||
2072 | if (!OpC) | ||||
2073 | continue; | ||||
2074 | if (!ConstantExprVisited.insert(OpC).second) | ||||
2075 | continue; | ||||
2076 | Stack.push_back(OpC); | ||||
2077 | } | ||||
2078 | } | ||||
2079 | } | ||||
2080 | |||||
2081 | void Verifier::visitConstantExpr(const ConstantExpr *CE) { | ||||
2082 | if (CE->getOpcode() == Instruction::BitCast) | ||||
2083 | Assert(CastInst::castIsValid(Instruction::BitCast, CE->getOperand(0),do { if (!(CastInst::castIsValid(Instruction::BitCast, CE-> getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast" , CE); return; } } while (false) | ||||
2084 | CE->getType()),do { if (!(CastInst::castIsValid(Instruction::BitCast, CE-> getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast" , CE); return; } } while (false) | ||||
2085 | "Invalid bitcast", CE)do { if (!(CastInst::castIsValid(Instruction::BitCast, CE-> getOperand(0), CE->getType()))) { CheckFailed("Invalid bitcast" , CE); return; } } while (false); | ||||
2086 | |||||
2087 | if (CE->getOpcode() == Instruction::IntToPtr || | ||||
2088 | CE->getOpcode() == Instruction::PtrToInt) { | ||||
2089 | auto *PtrTy = CE->getOpcode() == Instruction::IntToPtr | ||||
2090 | ? CE->getType() | ||||
2091 | : CE->getOperand(0)->getType(); | ||||
2092 | StringRef Msg = CE->getOpcode() == Instruction::IntToPtr | ||||
2093 | ? "inttoptr not supported for non-integral pointers" | ||||
2094 | : "ptrtoint not supported for non-integral pointers"; | ||||
2095 | Assert(do { if (!(!DL.isNonIntegralPointerType(cast<PointerType> (PtrTy->getScalarType())))) { CheckFailed(Msg); return; } } while (false) | ||||
2096 | !DL.isNonIntegralPointerType(cast<PointerType>(PtrTy->getScalarType())),do { if (!(!DL.isNonIntegralPointerType(cast<PointerType> (PtrTy->getScalarType())))) { CheckFailed(Msg); return; } } while (false) | ||||
2097 | Msg)do { if (!(!DL.isNonIntegralPointerType(cast<PointerType> (PtrTy->getScalarType())))) { CheckFailed(Msg); return; } } while (false); | ||||
2098 | } | ||||
2099 | } | ||||
2100 | |||||
2101 | bool Verifier::verifyAttributeCount(AttributeList Attrs, unsigned Params) { | ||||
2102 | // There shouldn't be more attribute sets than there are parameters plus the | ||||
2103 | // function and return value. | ||||
2104 | return Attrs.getNumAttrSets() <= Params + 2; | ||||
2105 | } | ||||
2106 | |||||
2107 | /// Verify that statepoint intrinsic is well formed. | ||||
2108 | void Verifier::verifyStatepoint(const CallBase &Call) { | ||||
2109 | assert(Call.getCalledFunction() &&((Call.getCalledFunction() && Call.getCalledFunction( )->getIntrinsicID() == Intrinsic::experimental_gc_statepoint ) ? static_cast<void> (0) : __assert_fail ("Call.getCalledFunction() && Call.getCalledFunction()->getIntrinsicID() == Intrinsic::experimental_gc_statepoint" , "/build/llvm-toolchain-snapshot-12~++20210124100612+2afaf072f5c1/llvm/lib/IR/Verifier.cpp" , 2111, __PRETTY_FUNCTION__)) | ||||
2110 | Call.getCalledFunction()->getIntrinsicID() ==((Call.getCalledFunction() && Call.getCalledFunction( )->getIntrinsicID() == Intrinsic::experimental_gc_statepoint ) ? static_cast<void> (0) : __assert_fail ("Call.getCalledFunction() && Call.getCalledFunction()->getIntrinsicID() == Intrinsic::experimental_gc_statepoint" , "/build/llvm-toolchain-snapshot-12~++20210124100612+2afaf072f5c1/llvm/lib/IR/Verifier.cpp" , 2111, __PRETTY_FUNCTION__)) | ||||
2111 | Intrinsic::experimental_gc_statepoint)((Call.getCalledFunction() && Call.getCalledFunction( )->getIntrinsicID() == Intrinsic::experimental_gc_statepoint ) ? static_cast<void> (0) : __assert_fail ("Call.getCalledFunction() && Call.getCalledFunction()->getIntrinsicID() == Intrinsic::experimental_gc_statepoint" , "/build/llvm-toolchain-snapshot-12~++20210124100612+2afaf072f5c1/llvm/lib/IR/Verifier.cpp" , 2111, __PRETTY_FUNCTION__)); | ||||
2112 | |||||
2113 | Assert(!Call.doesNotAccessMemory() && !Call.onlyReadsMemory() &&do { if (!(!Call.doesNotAccessMemory() && !Call.onlyReadsMemory () && !Call.onlyAccessesArgMemory())) { CheckFailed("gc.statepoint must read and write all memory to preserve " "reordering restrictions required by safepoint semantics", Call ); return; } } while (false) | ||||
2114 | !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) | ||||
2115 | "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) | ||||
2116 | "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) | ||||
2117 | 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); | ||||
2118 | |||||
2119 | const int64_t NumPatchBytes = | ||||
2120 | cast<ConstantInt>(Call.getArgOperand(1))->getSExtValue(); | ||||
2121 | assert(isInt<32>(NumPatchBytes) && "NumPatchBytesV is an i32!")((isInt<32>(NumPatchBytes) && "NumPatchBytesV is an i32!" ) ? static_cast<void> (0) : __assert_fail ("isInt<32>(NumPatchBytes) && \"NumPatchBytesV is an i32!\"" , "/build/llvm-toolchain-snapshot-12~++20210124100612+2afaf072f5c1/llvm/lib/IR/Verifier.cpp" , 2121, __PRETTY_FUNCTION__)); | ||||
2122 | Assert(NumPatchBytes >= 0,do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be " "positive", Call); return; } } while (false) | ||||
2123 | "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) | ||||
2124 | "positive",do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be " "positive", Call); return; } } while (false) | ||||
2125 | Call)do { if (!(NumPatchBytes >= 0)) { CheckFailed("gc.statepoint number of patchable bytes must be " "positive", Call); return; } } while (false); | ||||
2126 | |||||
2127 | const Value *Target = Call.getArgOperand(2); | ||||
2128 | auto *PT = dyn_cast<PointerType>(Target->getType()); | ||||
2129 | Assert(PT && PT->getElementType()->isFunctionTy(),do { if (!(PT && PT->getElementType()->isFunctionTy ())) { CheckFailed("gc.statepoint callee must be of function pointer type" , Call, Target); return; } } while (false) | ||||
2130 | "gc.statepoint callee must be of function pointer type", Call, Target)do { if (!(PT && PT->getElementType()->isFunctionTy ())) { CheckFailed("gc.statepoint callee must be of function pointer type" , Call, Target); return; } } while (false); | ||||
2131 | FunctionType *TargetFuncType = cast<FunctionType>(PT->getElementType()); | ||||
2132 | |||||
2133 | const int NumCallArgs = cast<ConstantInt>(Call.getArgOperand(3))->getZExtValue(); | ||||
2134 | Assert(NumCallArgs >= 0,do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call " "must be positive", Call); return; } } while (false) | ||||
2135 | "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) | ||||
2136 | "must be positive",do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call " "must be positive", Call); return; } } while (false) | ||||
2137 | Call)do { if (!(NumCallArgs >= 0)) { CheckFailed("gc.statepoint number of arguments to underlying call " "must be positive", Call); return; } } while (false); | ||||
2138 | const int NumParams = (int)TargetFuncType->getNumParams(); | ||||
2139 | if (TargetFuncType->isVarArg()) { | ||||
2140 | Assert(NumCallArgs >= NumParams,do { if (!(NumCallArgs >= NumParams)) { CheckFailed("gc.statepoint mismatch in number of vararg call args" , Call); return; } } while (false) | ||||
2141 | "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); | ||||
2142 | |||||
2143 | // TODO: Remove this limitation | ||||
2144 | Assert(TargetFuncType->getReturnType()->isVoidTy(),do { if (!(TargetFuncType->getReturnType()->isVoidTy()) ) { CheckFailed("gc.statepoint doesn't support wrapping non-void " "vararg functions yet", Call); return; } } while (false) | ||||
2145 | "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) | ||||
2146 | "vararg functions yet",do { if (!(TargetFuncType->getReturnType()->isVoidTy()) ) { CheckFailed("gc.statepoint doesn't support wrapping non-void " "vararg functions yet", Call); return; } } while (false) | ||||
2147 | Call)do { if (!(TargetFuncType->getReturnType()->isVoidTy()) ) { CheckFailed("gc.statepoint doesn't support wrapping non-void " "vararg functions yet", Call); return; } } while (false); | ||||
2148 | } else | ||||
2149 | Assert(NumCallArgs == NumParams,do { if (!(NumCallArgs == NumParams)) { CheckFailed("gc.statepoint mismatch in number of call args" , Call); return; } } while (false) | ||||
2150 | "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); | ||||
2151 | |||||
2152 | const uint64_t Flags | ||||
2153 | = cast<ConstantInt>(Call.getArgOperand(4))->getZExtValue(); | ||||
2154 | Assert((Flags & ~(uint64_t)StatepointFlags::MaskAll) == 0,do { if (!((Flags & ~(uint64_t)StatepointFlags::MaskAll) == 0)) { CheckFailed("unknown flag used in gc.statepoint flags argument" , Call); return; } } while (false) | ||||
2155 | "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); | ||||
2156 | |||||
2157 | // Verify that the types of the call parameter arguments match | ||||
2158 | // the type of the wrapped callee. | ||||
2159 | AttributeList Attrs = Call.getAttributes(); | ||||
2160 | for (int i = 0; i < NumParams; i++) { | ||||
2161 | Type *ParamType = TargetFuncType->getParamType(i); | ||||
2162 | Type *ArgType = Call.getArgOperand(5 + i)->getType(); | ||||
2163 | Assert(ArgType == ParamType,do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped " "function type", Call); return; } } while (false) | ||||
2164 | "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) | ||||
2165 | "function type",do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped " "function type", Call); return; } } while (false) | ||||
2166 | Call)do { if (!(ArgType == ParamType)) { CheckFailed("gc.statepoint call argument does not match wrapped " "function type", Call); return; } } while (false); | ||||
2167 | |||||
2168 | if (TargetFuncType->isVarArg()) { | ||||
2169 | AttributeSet ArgAttrs = Attrs.getParamAttributes(5 + i); | ||||
2170 | Assert(!ArgAttrs.hasAttribute(Attribute::StructRet),do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed ("Attribute 'sret' cannot be used for vararg call arguments!" , Call); return; } } while (false) | ||||
2171 | "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) | ||||
2172 | Call)do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed ("Attribute 'sret' cannot be used for vararg call arguments!" , Call); return; } } while (false); | ||||
2173 | } | ||||
2174 | } | ||||
2175 | |||||
2176 | const int EndCallArgsInx = 4 + NumCallArgs; | ||||
2177 | |||||
2178 | const Value *NumTransitionArgsV = Call.getArgOperand(EndCallArgsInx + 1); | ||||
2179 | Assert(isa<ConstantInt>(NumTransitionArgsV),do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed ("gc.statepoint number of transition arguments " "must be constant integer" , Call); return; } } while (false) | ||||
2180 | "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) | ||||
2181 | "must be constant integer",do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed ("gc.statepoint number of transition arguments " "must be constant integer" , Call); return; } } while (false) | ||||
2182 | Call)do { if (!(isa<ConstantInt>(NumTransitionArgsV))) { CheckFailed ("gc.statepoint number of transition arguments " "must be constant integer" , Call); return; } } while (false); | ||||
2183 | const int NumTransitionArgs = | ||||
2184 | cast<ConstantInt>(NumTransitionArgsV)->getZExtValue(); | ||||
2185 | Assert(NumTransitionArgs == 0,do { if (!(NumTransitionArgs == 0)) { CheckFailed("gc.statepoint w/inline transition bundle is deprecated" , Call); return; } } while (false) | ||||
2186 | "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); | ||||
2187 | const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs; | ||||
2188 | |||||
2189 | const Value *NumDeoptArgsV = Call.getArgOperand(EndTransitionArgsInx + 1); | ||||
2190 | Assert(isa<ConstantInt>(NumDeoptArgsV),do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed ("gc.statepoint number of deoptimization arguments " "must be constant integer" , Call); return; } } while (false) | ||||
2191 | "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) | ||||
2192 | "must be constant integer",do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed ("gc.statepoint number of deoptimization arguments " "must be constant integer" , Call); return; } } while (false) | ||||
2193 | Call)do { if (!(isa<ConstantInt>(NumDeoptArgsV))) { CheckFailed ("gc.statepoint number of deoptimization arguments " "must be constant integer" , Call); return; } } while (false); | ||||
2194 | const int NumDeoptArgs = cast<ConstantInt>(NumDeoptArgsV)->getZExtValue(); | ||||
2195 | Assert(NumDeoptArgs == 0,do { if (!(NumDeoptArgs == 0)) { CheckFailed("gc.statepoint w/inline deopt operands is deprecated" , Call); return; } } while (false) | ||||
2196 | "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); | ||||
2197 | |||||
2198 | const int ExpectedNumArgs = 7 + NumCallArgs; | ||||
2199 | Assert(ExpectedNumArgs == (int)Call.arg_size(),do { if (!(ExpectedNumArgs == (int)Call.arg_size())) { CheckFailed ("gc.statepoint too many arguments", Call); return; } } while (false) | ||||
2200 | "gc.statepoint too many arguments", Call)do { if (!(ExpectedNumArgs == (int)Call.arg_size())) { CheckFailed ("gc.statepoint too many arguments", Call); return; } } while (false); | ||||
2201 | |||||
2202 | // Check that the only uses of this gc.statepoint are gc.result or | ||||
2203 | // gc.relocate calls which are tied to this statepoint and thus part | ||||
2204 | // of the same statepoint sequence | ||||
2205 | for (const User *U : Call.users()) { | ||||
2206 | const CallInst *UserCall = dyn_cast<const CallInst>(U); | ||||
2207 | Assert(UserCall, "illegal use of statepoint token", Call, U)do { if (!(UserCall)) { CheckFailed("illegal use of statepoint token" , Call, U); return; } } while (false); | ||||
2208 | if (!UserCall) | ||||
2209 | continue; | ||||
2210 | Assert(isa<GCRelocateInst>(UserCall) || isa<GCResultInst>(UserCall),do { if (!(isa<GCRelocateInst>(UserCall) || isa<GCResultInst >(UserCall))) { CheckFailed("gc.result or gc.relocate are the only value uses " "of a gc.statepoint", Call, U); return; } } while (false) | ||||
2211 | "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) | ||||
2212 | "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) | ||||
2213 | 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); | ||||
2214 | if (isa<GCResultInst>(UserCall)) { | ||||
2215 | Assert(UserCall->getArgOperand(0) == &Call,do { if (!(UserCall->getArgOperand(0) == &Call)) { CheckFailed ("gc.result connected to wrong gc.statepoint", Call, UserCall ); return; } } while (false) | ||||
2216 | "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); | ||||
2217 | } else if (isa<GCRelocateInst>(Call)) { | ||||
2218 | Assert(UserCall->getArgOperand(0) == &Call,do { if (!(UserCall->getArgOperand(0) == &Call)) { CheckFailed ("gc.relocate connected to wrong gc.statepoint", Call, UserCall ); return; } } while (false) | ||||
2219 | "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); | ||||
2220 | } | ||||
2221 | } | ||||
2222 | |||||
2223 | // Note: It is legal for a single derived pointer to be listed multiple | ||||
2224 | // times. It's non-optimal, but it is legal. It can also happen after | ||||
2225 | // insertion if we strip a bitcast away. | ||||
2226 | // Note: It is really tempting to check that each base is relocated and | ||||
2227 | // that a derived pointer is never reused as a base pointer. This turns | ||||
2228 | // out to be problematic since optimizations run after safepoint insertion | ||||
2229 | // can recognize equality properties that the insertion logic doesn't know | ||||
2230 | // about. See example statepoint.ll in the verifier subdirectory | ||||
2231 | } | ||||
2232 | |||||
2233 | void Verifier::verifyFrameRecoverIndices() { | ||||
2234 | for (auto &Counts : FrameEscapeInfo) { | ||||
2235 | Function *F = Counts.first; | ||||
2236 | unsigned EscapedObjectCount = Counts.second.first; | ||||
2237 | unsigned MaxRecoveredIndex = Counts.second.second; | ||||
2238 | Assert(MaxRecoveredIndex <= EscapedObjectCount,do { if (!(MaxRecoveredIndex <= EscapedObjectCount)) { CheckFailed ("all indices passed to llvm.localrecover must be less than the " "number of arguments passed to llvm.localescape in the parent " "function", F); return; } } while (false) | ||||
2239 | "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) | ||||
2240 | "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) | ||||
2241 | "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) | ||||
2242 | 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); | ||||
2243 | } | ||||
2244 | } | ||||
2245 | |||||
2246 | static Instruction *getSuccPad(Instruction *Terminator) { | ||||
2247 | BasicBlock *UnwindDest; | ||||
2248 | if (auto *II = dyn_cast<InvokeInst>(Terminator)) | ||||
2249 | UnwindDest = II->getUnwindDest(); | ||||
2250 | else if (auto *CSI = dyn_cast<CatchSwitchInst>(Terminator)) | ||||
2251 | UnwindDest = CSI->getUnwindDest(); | ||||
2252 | else | ||||
2253 | UnwindDest = cast<CleanupReturnInst>(Terminator)->getUnwindDest(); | ||||
2254 | return UnwindDest->getFirstNonPHI(); | ||||
2255 | } | ||||
2256 | |||||
2257 | void Verifier::verifySiblingFuncletUnwinds() { | ||||
2258 | SmallPtrSet<Instruction *, 8> Visited; | ||||
2259 | SmallPtrSet<Instruction *, 8> Active; | ||||
2260 | for (const auto &Pair : SiblingFuncletInfo) { | ||||
2261 | Instruction *PredPad = Pair.first; | ||||
2262 | if (Visited.count(PredPad)) | ||||
2263 | continue; | ||||
2264 | Active.insert(PredPad); | ||||
2265 | Instruction *Terminator = Pair.second; | ||||
2266 | do { | ||||
2267 | Instruction *SuccPad = getSuccPad(Terminator); | ||||
2268 | if (Active.count(SuccPad)) { | ||||
2269 | // Found a cycle; report error | ||||
2270 | Instruction *CyclePad = SuccPad; | ||||
2271 | SmallVector<Instruction *, 8> CycleNodes; | ||||
2272 | do { | ||||
2273 | CycleNodes.push_back(CyclePad); | ||||
2274 | Instruction *CycleTerminator = SiblingFuncletInfo[CyclePad]; | ||||
2275 | if (CycleTerminator != CyclePad) | ||||
2276 | CycleNodes.push_back(CycleTerminator); | ||||
2277 | CyclePad = getSuccPad(CycleTerminator); | ||||
2278 | } while (CyclePad != SuccPad); | ||||
2279 | Assert(false, "EH pads can't handle each other's exceptions",do { if (!(false)) { CheckFailed("EH pads can't handle each other's exceptions" , ArrayRef<Instruction *>(CycleNodes)); return; } } while (false) | ||||
2280 | ArrayRef<Instruction *>(CycleNodes))do { if (!(false)) { CheckFailed("EH pads can't handle each other's exceptions" , ArrayRef<Instruction *>(CycleNodes)); return; } } while (false); | ||||
2281 | } | ||||
2282 | // Don't re-walk a node we've already checked | ||||
2283 | if (!Visited.insert(SuccPad).second) | ||||
2284 | break; | ||||
2285 | // Walk to this successor if it has a map entry. | ||||
2286 | PredPad = SuccPad; | ||||
2287 | auto TermI = SiblingFuncletInfo.find(PredPad); | ||||
2288 | if (TermI == SiblingFuncletInfo.end()) | ||||
2289 | break; | ||||
2290 | Terminator = TermI->second; | ||||
2291 | Active.insert(PredPad); | ||||
2292 | } while (true); | ||||
2293 | // Each node only has one successor, so we've walked all the active | ||||
2294 | // nodes' successors. | ||||
2295 | Active.clear(); | ||||
2296 | } | ||||
2297 | } | ||||
2298 | |||||
2299 | // visitFunction - Verify that a function is ok. | ||||
2300 | // | ||||
2301 | void Verifier::visitFunction(const Function &F) { | ||||
2302 | visitGlobalValue(F); | ||||
2303 | |||||
2304 | // Check function arguments. | ||||
2305 | FunctionType *FT = F.getFunctionType(); | ||||
2306 | unsigned NumArgs = F.arg_size(); | ||||
2307 | |||||
2308 | Assert(&Context == &F.getContext(),do { if (!(&Context == &F.getContext())) { CheckFailed ("Function context does not match Module context!", &F); return ; } } while (false) | ||||
| |||||
2309 | "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); | ||||
2310 | |||||
2311 | Assert(!F.hasCommonLinkage(), "Functions may not have common linkage", &F)do { if (!(!F.hasCommonLinkage())) { CheckFailed("Functions may not have common linkage" , &F); return; } } while (false); | ||||
2312 | Assert(FT->getNumParams() == NumArgs,do { if (!(FT->getNumParams() == NumArgs)) { CheckFailed("# formal arguments must match # of arguments for function type!" , &F, FT); return; } } while (false) | ||||
2313 | "# 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) | ||||
2314 | FT)do { if (!(FT->getNumParams() == NumArgs)) { CheckFailed("# formal arguments must match # of arguments for function type!" , &F, FT); return; } } while (false); | ||||
2315 | Assert(F.getReturnType()->isFirstClassType() ||do { if (!(F.getReturnType()->isFirstClassType() || F.getReturnType ()->isVoidTy() || F.getReturnType()->isStructTy())) { CheckFailed ("Functions cannot return aggregate values!", &F); return ; } } while (false) | ||||
2316 | 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) | ||||
2317 | "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); | ||||
2318 | |||||
2319 | Assert(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy(),do { if (!(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy ())) { CheckFailed("Invalid struct return type!", &F); return ; } } while (false) | ||||
2320 | "Invalid struct return type!", &F)do { if (!(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy ())) { CheckFailed("Invalid struct return type!", &F); return ; } } while (false); | ||||
2321 | |||||
2322 | AttributeList Attrs = F.getAttributes(); | ||||
2323 | |||||
2324 | Assert(verifyAttributeCount(Attrs, FT->getNumParams()),do { if (!(verifyAttributeCount(Attrs, FT->getNumParams()) )) { CheckFailed("Attribute after last parameter!", &F); return ; } } while (false) | ||||
2325 | "Attribute after last parameter!", &F)do { if (!(verifyAttributeCount(Attrs, FT->getNumParams()) )) { CheckFailed("Attribute after last parameter!", &F); return ; } } while (false); | ||||
2326 | |||||
2327 | bool isLLVMdotName = F.getName().size() >= 5 && | ||||
2328 | F.getName().substr(0, 5) == "llvm."; | ||||
2329 | |||||
2330 | // Check function attributes. | ||||
2331 | verifyFunctionAttrs(FT, Attrs, &F, isLLVMdotName); | ||||
2332 | |||||
2333 | // On function declarations/definitions, we do not support the builtin | ||||
2334 | // attribute. We do not check this in VerifyFunctionAttrs since that is | ||||
2335 | // checking for Attributes that can/can not ever be on functions. | ||||
2336 | Assert(!Attrs.hasFnAttribute(Attribute::Builtin),do { if (!(!Attrs.hasFnAttribute(Attribute::Builtin))) { CheckFailed ("Attribute 'builtin' can only be applied to a callsite.", & F); return; } } while (false) | ||||
2337 | "Attribute 'builtin' can only be applied to a callsite.", &F)do { if (!(!Attrs.hasFnAttribute(Attribute::Builtin))) { CheckFailed ("Attribute 'builtin' can only be applied to a callsite.", & F); return; } } while (false); | ||||
2338 | |||||
2339 | // Check that this function meets the restrictions on this calling convention. | ||||
2340 | // Sometimes varargs is used for perfectly forwarding thunks, so some of these | ||||
2341 | // restrictions can be lifted. | ||||
2342 | switch (F.getCallingConv()) { | ||||
2343 | default: | ||||
2344 | case CallingConv::C: | ||||
2345 | break; | ||||
2346 | case CallingConv::X86_INTR: { | ||||
2347 | Assert(F.arg_empty() || Attrs.hasParamAttribute(0, Attribute::ByVal),do { if (!(F.arg_empty() || Attrs.hasParamAttribute(0, Attribute ::ByVal))) { CheckFailed("Calling convention parameter requires byval" , &F); return; } } while (false) | ||||
2348 | "Calling convention parameter requires byval", &F)do { if (!(F.arg_empty() || Attrs.hasParamAttribute(0, Attribute ::ByVal))) { CheckFailed("Calling convention parameter requires byval" , &F); return; } } while (false); | ||||
2349 | break; | ||||
2350 | } | ||||
2351 | case CallingConv::AMDGPU_KERNEL: | ||||
2352 | case CallingConv::SPIR_KERNEL: | ||||
2353 | Assert(F.getReturnType()->isVoidTy(),do { if (!(F.getReturnType()->isVoidTy())) { CheckFailed("Calling convention requires void return type" , &F); return; } } while (false) | ||||
2354 | "Calling convention requires void return type", &F)do { if (!(F.getReturnType()->isVoidTy())) { CheckFailed("Calling convention requires void return type" , &F); return; } } while (false); | ||||
2355 | LLVM_FALLTHROUGH[[gnu::fallthrough]]; | ||||
2356 | case CallingConv::AMDGPU_VS: | ||||
2357 | case CallingConv::AMDGPU_HS: | ||||
2358 | case CallingConv::AMDGPU_GS: | ||||
2359 | case CallingConv::AMDGPU_PS: | ||||
2360 | case CallingConv::AMDGPU_CS: | ||||
2361 | Assert(!F.hasStructRetAttr(),do { if (!(!F.hasStructRetAttr())) { CheckFailed("Calling convention does not allow sret" , &F); return; } } while (false) | ||||
2362 | "Calling convention does not allow sret", &F)do { if (!(!F.hasStructRetAttr())) { CheckFailed("Calling convention does not allow sret" , &F); return; } } while (false); | ||||
2363 | if (F.getCallingConv() != CallingConv::SPIR_KERNEL) { | ||||
2364 | const unsigned StackAS = DL.getAllocaAddrSpace(); | ||||
2365 | unsigned i = 0; | ||||
2366 | for (const Argument &Arg : F.args()) { | ||||
2367 | Assert(!Attrs.hasParamAttribute(i, Attribute::ByVal),do { if (!(!Attrs.hasParamAttribute(i, Attribute::ByVal))) { CheckFailed ("Calling convention disallows byval", &F); return; } } while (false) | ||||
2368 | "Calling convention disallows byval", &F)do { if (!(!Attrs.hasParamAttribute(i, Attribute::ByVal))) { CheckFailed ("Calling convention disallows byval", &F); return; } } while (false); | ||||
2369 | Assert(!Attrs.hasParamAttribute(i, Attribute::Preallocated),do { if (!(!Attrs.hasParamAttribute(i, Attribute::Preallocated ))) { CheckFailed("Calling convention disallows preallocated" , &F); return; } } while (false) | ||||
2370 | "Calling convention disallows preallocated", &F)do { if (!(!Attrs.hasParamAttribute(i, Attribute::Preallocated ))) { CheckFailed("Calling convention disallows preallocated" , &F); return; } } while (false); | ||||
2371 | Assert(!Attrs.hasParamAttribute(i, Attribute::InAlloca),do { if (!(!Attrs.hasParamAttribute(i, Attribute::InAlloca))) { CheckFailed("Calling convention disallows inalloca", & F); return; } } while (false) | ||||
2372 | "Calling convention disallows inalloca", &F)do { if (!(!Attrs.hasParamAttribute(i, Attribute::InAlloca))) { CheckFailed("Calling convention disallows inalloca", & F); return; } } while (false); | ||||
2373 | |||||
2374 | if (Attrs.hasParamAttribute(i, Attribute::ByRef)) { | ||||
2375 | // FIXME: Should also disallow LDS and GDS, but we don't have the enum | ||||
2376 | // value here. | ||||
2377 | Assert(Arg.getType()->getPointerAddressSpace() != StackAS,do { if (!(Arg.getType()->getPointerAddressSpace() != StackAS )) { CheckFailed("Calling convention disallows stack byref", & F); return; } } while (false) | ||||
2378 | "Calling convention disallows stack byref", &F)do { if (!(Arg.getType()->getPointerAddressSpace() != StackAS )) { CheckFailed("Calling convention disallows stack byref", & F); return; } } while (false); | ||||
2379 | } | ||||
2380 | |||||
2381 | ++i; | ||||
2382 | } | ||||
2383 | } | ||||
2384 | |||||
2385 | LLVM_FALLTHROUGH[[gnu::fallthrough]]; | ||||
2386 | case CallingConv::Fast: | ||||
2387 | case CallingConv::Cold: | ||||
2388 | case CallingConv::Intel_OCL_BI: | ||||
2389 | case CallingConv::PTX_Kernel: | ||||
2390 | case CallingConv::PTX_Device: | ||||
2391 | Assert(!F.isVarArg(), "Calling convention does not support varargs or "do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or " "perfect forwarding!", &F); return; } } while (false) | ||||
2392 | "perfect forwarding!",do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or " "perfect forwarding!", &F); return; } } while (false) | ||||
2393 | &F)do { if (!(!F.isVarArg())) { CheckFailed("Calling convention does not support varargs or " "perfect forwarding!", &F); return; } } while (false); | ||||
2394 | break; | ||||
2395 | } | ||||
2396 | |||||
2397 | // Check that the argument values match the function type for this function... | ||||
2398 | unsigned i = 0; | ||||
2399 | for (const Argument &Arg : F.args()) { | ||||
2400 | Assert(Arg.getType() == FT->getParamType(i),do { if (!(Arg.getType() == FT->getParamType(i))) { CheckFailed ("Argument value does not match function argument type!", & Arg, FT->getParamType(i)); return; } } while (false) | ||||
2401 | "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) | ||||
2402 | 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); | ||||
2403 | Assert(Arg.getType()->isFirstClassType(),do { if (!(Arg.getType()->isFirstClassType())) { CheckFailed ("Function arguments must have first-class types!", &Arg) ; return; } } while (false) | ||||
2404 | "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); | ||||
2405 | if (!isLLVMdotName) { | ||||
2406 | Assert(!Arg.getType()->isMetadataTy(),do { if (!(!Arg.getType()->isMetadataTy())) { CheckFailed( "Function takes metadata but isn't an intrinsic", &Arg, & F); return; } } while (false) | ||||
2407 | "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); | ||||
2408 | Assert(!Arg.getType()->isTokenTy(),do { if (!(!Arg.getType()->isTokenTy())) { CheckFailed("Function takes token but isn't an intrinsic" , &Arg, &F); return; } } while (false) | ||||
2409 | "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); | ||||
2410 | } | ||||
2411 | |||||
2412 | // Check that swifterror argument is only used by loads and stores. | ||||
2413 | if (Attrs.hasParamAttribute(i, Attribute::SwiftError)) { | ||||
2414 | verifySwiftErrorValue(&Arg); | ||||
2415 | } | ||||
2416 | ++i; | ||||
2417 | } | ||||
2418 | |||||
2419 | if (!isLLVMdotName
| ||||
2420 | Assert(!F.getReturnType()->isTokenTy(),do { if (!(!F.getReturnType()->isTokenTy())) { CheckFailed ("Functions returns a token but isn't an intrinsic", &F); return; } } while (false) | ||||
2421 | "Functions returns a token but isn't an intrinsic", &F)do { if (!(!F.getReturnType()->isTokenTy())) { CheckFailed ("Functions returns a token but isn't an intrinsic", &F); return; } } while (false); | ||||
2422 | |||||
2423 | // Get the function metadata attachments. | ||||
2424 | SmallVector<std::pair<unsigned, MDNode *>, 4> MDs; | ||||
2425 | F.getAllMetadata(MDs); | ||||
2426 | assert(F.hasMetadata() != MDs.empty() && "Bit out-of-sync")((F.hasMetadata() != MDs.empty() && "Bit out-of-sync" ) ? static_cast<void> (0) : __assert_fail ("F.hasMetadata() != MDs.empty() && \"Bit out-of-sync\"" , "/build/llvm-toolchain-snapshot-12~++20210124100612+2afaf072f5c1/llvm/lib/IR/Verifier.cpp" , 2426, __PRETTY_FUNCTION__)); | ||||
2427 | verifyFunctionMetadata(MDs); | ||||
2428 | |||||
2429 | // Check validity of the personality function | ||||
2430 | if (F.hasPersonalityFn()) { | ||||
2431 | auto *Per = dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts()); | ||||
2432 | if (Per) | ||||
2433 | Assert(Per->getParent() == F.getParent(),do { if (!(Per->getParent() == F.getParent())) { CheckFailed ("Referencing personality function in another module!", & F, F.getParent(), Per, Per->getParent()); return; } } while (false) | ||||
2434 | "Referencing personality function in another module!",do { if (!(Per->getParent() == F.getParent())) { CheckFailed ("Referencing personality function in another module!", & F, F.getParent(), Per, Per->getParent()); return; } } while (false) | ||||
2435 | &F, F.getParent(), Per, Per->getParent())do { if (!(Per->getParent() == F.getParent())) { CheckFailed ("Referencing personality function in another module!", & F, F.getParent(), Per, Per->getParent()); return; } } while (false); | ||||
2436 | } | ||||
2437 | |||||
2438 | if (F.isMaterializable()) { | ||||
2439 | // Function has a body somewhere we can't see. | ||||
2440 | Assert(MDs.empty(), "unmaterialized function cannot have metadata", &F,do { if (!(MDs.empty())) { CheckFailed("unmaterialized function cannot have metadata" , &F, MDs.empty() ? nullptr : MDs.front().second); return ; } } while (false) | ||||
2441 | 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); | ||||
2442 | } else if (F.isDeclaration()) { | ||||
2443 | for (const auto &I : MDs) { | ||||
2444 | // This is used for call site debug information. | ||||
2445 | AssertDI(I.first != LLVMContext::MD_dbg ||do { if (!(I.first != LLVMContext::MD_dbg || !cast<DISubprogram >(I.second)->isDistinct())) { DebugInfoCheckFailed("function declaration may only have a unique !dbg attachment" , &F); return; } } while (false) | ||||
2446 | !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) | ||||
2447 | "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) | ||||
2448 | &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); | ||||
2449 | Assert(I.first != LLVMContext::MD_prof,do { if (!(I.first != LLVMContext::MD_prof)) { CheckFailed("function declaration may not have a !prof attachment" , &F); return; } } while (false) | ||||
2450 | "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); | ||||
2451 | |||||
2452 | // Verify the metadata itself. | ||||
2453 | visitMDNode(*I.second, AreDebugLocsAllowed::Yes); | ||||
2454 | } | ||||
2455 | Assert(!F.hasPersonalityFn(),do { if (!(!F.hasPersonalityFn())) { CheckFailed("Function declaration shouldn't have a personality routine" , &F); return; } } while (false) | ||||
2456 | "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); | ||||
2457 | } else { | ||||
2458 | // Verify that this function (which has a body) is not named "llvm.*". It | ||||
2459 | // is not legal to define intrinsics. | ||||
2460 | Assert(!isLLVMdotName, "llvm intrinsics cannot be defined!", &F)do { if (!(!isLLVMdotName)) { CheckFailed("llvm intrinsics cannot be defined!" , &F); return; } } while (false); | ||||
2461 | |||||
2462 | // Check the entry node | ||||
2463 | const BasicBlock *Entry = &F.getEntryBlock(); | ||||
2464 | Assert(pred_empty(Entry),do { if (!(pred_empty(Entry))) { CheckFailed("Entry block to function must not have predecessors!" , Entry); return; } } while (false) | ||||
2465 | "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); | ||||
2466 | |||||
2467 | // The address of the entry block cannot be taken, unless it is dead. | ||||
2468 | if (Entry->hasAddressTaken()) { | ||||
2469 | Assert(!BlockAddress::lookup(Entry)->isConstantUsed(),do { if (!(!BlockAddress::lookup(Entry)->isConstantUsed()) ) { CheckFailed("blockaddress may not be used with the entry block!" , Entry); return; } } while (false) | ||||
2470 | "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); | ||||
2471 | } | ||||
2472 | |||||
2473 | unsigned NumDebugAttachments = 0, NumProfAttachments = 0; | ||||
2474 | // Visit metadata attachments. | ||||
2475 | for (const auto &I : MDs) { | ||||
2476 | // Verify that the attachment is legal. | ||||
2477 | auto AllowLocs = AreDebugLocsAllowed::No; | ||||
2478 | switch (I.first) { | ||||
2479 | default: | ||||
2480 | break; | ||||
2481 | case LLVMContext::MD_dbg: { | ||||
2482 | ++NumDebugAttachments; | ||||
2483 | AssertDI(NumDebugAttachments == 1,do { if (!(NumDebugAttachments == 1)) { DebugInfoCheckFailed( "function must have a single !dbg attachment", &F, I.second ); return; } } while (false) | ||||
2484 | "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); | ||||
2485 | AssertDI(isa<DISubprogram>(I.second),do { if (!(isa<DISubprogram>(I.second))) { DebugInfoCheckFailed ("function !dbg attachment must be a subprogram", &F, I.second ); return; } } while (false) | ||||
2486 | "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); | ||||
2487 | AssertDI(cast<DISubprogram>(I.second)->isDistinct(),do { if (!(cast<DISubprogram>(I.second)->isDistinct( ))) { DebugInfoCheckFailed("function definition may only have a distinct !dbg attachment" , &F); return; } } while (false) | ||||
2488 | "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) | ||||
2489 | &F)do { if (!(cast<DISubprogram>(I.second)->isDistinct( ))) { DebugInfoCheckFailed("function definition may only have a distinct !dbg attachment" , &F); return; } } while (false); | ||||
2490 | |||||
2491 | auto *SP = cast<DISubprogram>(I.second); | ||||
2492 | const Function *&AttachedTo = DISubprogramAttachments[SP]; | ||||
2493 | AssertDI(!AttachedTo || AttachedTo == &F,do { if (!(!AttachedTo || AttachedTo == &F)) { DebugInfoCheckFailed ("DISubprogram attached to more than one function", SP, & F); return; } } while (false) | ||||
2494 | "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); | ||||
2495 | AttachedTo = &F; | ||||
2496 | AllowLocs = AreDebugLocsAllowed::Yes; | ||||
2497 | break; | ||||
2498 | } | ||||
2499 | case LLVMContext::MD_prof: | ||||
2500 | ++NumProfAttachments; | ||||
2501 | Assert(NumProfAttachments == 1,do { if (!(NumProfAttachments == 1)) { CheckFailed("function must have a single !prof attachment" , &F, I.second); return; } } while (false) | ||||
2502 | "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); | ||||
2503 | break; | ||||
2504 | } | ||||
2505 | |||||
2506 | // Verify the metadata itself. | ||||
2507 | visitMDNode(*I.second, AllowLocs); | ||||
2508 | } | ||||
2509 | } | ||||
2510 | |||||
2511 | // If this function is actually an intrinsic, verify that it is only used in | ||||
2512 | // direct call/invokes, never having its "address taken". | ||||
2513 | // Only do this if the module is materialized, otherwise we don't have all the | ||||
2514 | // uses. | ||||
2515 | if (F.getIntrinsicID() && F.getParent()->isMaterialized()) { | ||||
2516 | const User *U; | ||||
2517 | if (F.hasAddressTaken(&U)) | ||||
2518 | Assert(false, "Invalid user of intrinsic instruction!", U)do { if (!(false)) { CheckFailed("Invalid user of intrinsic instruction!" , U); return; } } while (false); | ||||
2519 | } | ||||
2520 | |||||
2521 | auto *N = F.getSubprogram(); | ||||
2522 | HasDebugInfo = (N != nullptr); | ||||
2523 | if (!HasDebugInfo
| ||||
2524 | return; | ||||
2525 | |||||
2526 | // Check that all !dbg attachments lead to back to N. | ||||
2527 | // | ||||
2528 | // FIXME: Check this incrementally while visiting !dbg attachments. | ||||
2529 | // FIXME: Only check when N is the canonical subprogram for F. | ||||
2530 | SmallPtrSet<const MDNode *, 32> Seen; | ||||
2531 | auto VisitDebugLoc = [&](const Instruction &I, const MDNode *Node) { | ||||
2532 | // Be careful about using DILocation here since we might be dealing with | ||||
2533 | // broken code (this is the Verifier after all). | ||||
2534 | const DILocation *DL = dyn_cast_or_null<DILocation>(Node); | ||||
2535 | if (!DL
| ||||
2536 | return; | ||||
2537 | if (!Seen.insert(DL).second) | ||||
2538 | return; | ||||
2539 | |||||
2540 | Metadata *Parent = DL->getRawScope(); | ||||
2541 | AssertDI(Parent && isa<DILocalScope>(Parent),do { if (!(Parent && isa<DILocalScope>(Parent)) ) { DebugInfoCheckFailed("DILocation's scope must be a DILocalScope" , N, &F, &I, DL, Parent); return; } } while (false) | ||||
2542 | "DILocation's scope must be a DILocalScope", N, &F, &I, DL,do { if (!(Parent && isa<DILocalScope>(Parent)) ) { DebugInfoCheckFailed("DILocation's scope must be a DILocalScope" , N, &F, &I, DL, Parent); return; } } while (false) | ||||
2543 | Parent)do { if (!(Parent && isa<DILocalScope>(Parent)) ) { DebugInfoCheckFailed("DILocation's scope must be a DILocalScope" , N, &F, &I, DL, Parent); return; } } while (false); | ||||
2544 | |||||
2545 | DILocalScope *Scope = DL->getInlinedAtScope(); | ||||
2546 | Assert(Scope, "Failed to find DILocalScope", DL)do { if (!(Scope)) { CheckFailed("Failed to find DILocalScope" , DL); return; } } while (false); | ||||
2547 | |||||
2548 | if (!Seen.insert(Scope).second) | ||||
2549 | return; | ||||
2550 | |||||
2551 | DISubprogram *SP = Scope->getSubprogram(); | ||||
2552 | |||||
2553 | // Scope and SP could be the same MDNode and we don't want to skip | ||||
2554 | // validation in that case | ||||
2555 | if (SP && ((Scope != SP) && !Seen.insert(SP).second)) | ||||
2556 | return; | ||||
2557 | |||||
2558 | AssertDI(SP->describes(&F),do { if (!(SP->describes(&F))) { DebugInfoCheckFailed( "!dbg attachment points at wrong subprogram for function", N, &F, &I, DL, Scope, SP); return; } } while (false) | ||||
| |||||
2559 | "!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) | ||||
2560 | &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); | ||||
2561 | }; | ||||
2562 | for (auto &BB : F) | ||||
2563 | for (auto &I : BB) { | ||||
2564 | VisitDebugLoc(I, I.getDebugLoc().getAsMDNode()); | ||||
2565 | // The llvm.loop annotations also contain two DILocations. | ||||
2566 | if (auto MD = I.getMetadata(LLVMContext::MD_loop)) | ||||
2567 | for (unsigned i = 1; i < MD->getNumOperands(); ++i) | ||||
2568 | VisitDebugLoc(I, dyn_cast_or_null<MDNode>(MD->getOperand(i))); | ||||
2569 | if (BrokenDebugInfo) | ||||
2570 | return; | ||||
2571 | } | ||||
2572 | } | ||||
2573 | |||||
2574 | // verifyBasicBlock - Verify that a basic block is well formed... | ||||
2575 | // | ||||
2576 | void Verifier::visitBasicBlock(BasicBlock &BB) { | ||||
2577 | InstsInThisBlock.clear(); | ||||
2578 | |||||
2579 | // Ensure that basic blocks have terminators! | ||||
2580 | Assert(BB.getTerminator(), "Basic Block does not have terminator!", &BB)do { if (!(BB.getTerminator())) { CheckFailed("Basic Block does not have terminator!" , &BB); return; } } while (false); | ||||
2581 | |||||
2582 | // Check constraints that this basic block imposes on all of the PHI nodes in | ||||
2583 | // it. | ||||
2584 | if (isa<PHINode>(BB.front())) { | ||||
2585 | SmallVector<BasicBlock *, 8> Preds(predecessors(&BB)); | ||||
2586 | SmallVector<std::pair<BasicBlock*, Value*>, 8> Values; | ||||
2587 | llvm::sort(Preds); | ||||
2588 | for (const PHINode &PN : BB.phis()) { | ||||
2589 | Assert(PN.getNumIncomingValues() == Preds.size(),do { if (!(PN.getNumIncomingValues() == Preds.size())) { CheckFailed ("PHINode should have one entry for each predecessor of its " "parent basic block!", &PN); return; } } while (false) | ||||
2590 | "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) | ||||
2591 | "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) | ||||
2592 | &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); | ||||
2593 | |||||
2594 | // Get and sort all incoming values in the PHI node... | ||||
2595 | Values.clear(); | ||||
2596 | Values.reserve(PN.getNumIncomingValues()); | ||||
2597 | for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) | ||||
2598 | Values.push_back( | ||||
2599 | std::make_pair(PN.getIncomingBlock(i), PN.getIncomingValue(i))); | ||||
2600 | llvm::sort(Values); | ||||
2601 | |||||
2602 | for (unsigned i = 0, e = Values.size(); i != e; ++i) { | ||||
2603 | // Check to make sure that if there is more than one entry for a | ||||
2604 | // particular basic block in this PHI node, that the incoming values are | ||||
2605 | // all identical. | ||||
2606 | // | ||||
2607 | Assert(i == 0 || Values[i].first != Values[i - 1].first ||do { if (!(i == 0 || Values[i].first != Values[i - 1].first || Values[i].second == Values[i - 1].second)) { CheckFailed("PHI node has multiple entries for the same basic block with " "different incoming values!", &PN, Values[i].first, Values [i].second, Values[i - 1].second); return; } } while (false) | ||||
2608 | 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) | ||||
2609 | "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) | ||||
2610 | "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) | ||||
2611 | &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); | ||||
2612 | |||||
2613 | // Check to make sure that the predecessors and PHI node entries are | ||||
2614 | // matched up. | ||||
2615 | Assert(Values[i].first == Preds[i],do { if (!(Values[i].first == Preds[i])) { CheckFailed("PHI node entries do not match predecessors!" , &PN, Values[i].first, Preds[i]); return; } } while (false ) | ||||
2616 | "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 ) | ||||
2617 | 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 ); | ||||
2618 | } | ||||
2619 | } | ||||
2620 | } | ||||
2621 | |||||
2622 | // Check that all instructions have their parent pointers set up correctly. | ||||
2623 | for (auto &I : BB) | ||||
2624 | { | ||||
2625 | Assert(I.getParent() == &BB, "Instruction has bogus parent pointer!")do { if (!(I.getParent() == &BB)) { CheckFailed("Instruction has bogus parent pointer!" ); return; } } while (false); | ||||
2626 | } | ||||
2627 | } | ||||
2628 | |||||
2629 | void Verifier::visitTerminator(Instruction &I) { | ||||
2630 | // Ensure that terminators only exist at the end of the basic block. | ||||
2631 | Assert(&I == I.getParent()->getTerminator(),do { if (!(&I == I.getParent()->getTerminator())) { CheckFailed ("Terminator found in the middle of a basic block!", I.getParent ()); return; } } while (false) | ||||
2632 | "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); | ||||
2633 | visitInstruction(I); | ||||
2634 | } | ||||
2635 | |||||
2636 | void Verifier::visitBranchInst(BranchInst &BI) { | ||||
2637 | if (BI.isConditional()) { | ||||
2638 | Assert(BI.getCondition()->getType()->isIntegerTy(1),do { if (!(BI.getCondition()->getType()->isIntegerTy(1) )) { CheckFailed("Branch condition is not 'i1' type!", &BI , BI.getCondition()); return; } } while (false) | ||||
2639 | "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); | ||||
2640 | } | ||||
2641 | visitTerminator(BI); | ||||
2642 | } | ||||
2643 | |||||
2644 | void Verifier::visitReturnInst(ReturnInst &RI) { | ||||
2645 | Function *F = RI.getParent()->getParent(); | ||||
2646 | unsigned N = RI.getNumOperands(); | ||||
2647 | if (F->getReturnType()->isVoidTy()) | ||||
2648 | Assert(N == 0,do { if (!(N == 0)) { CheckFailed("Found return instr that returns non-void in Function of void " "return type!", &RI, F->getReturnType()); return; } } while (false) | ||||
2649 | "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) | ||||
2650 | "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) | ||||
2651 | &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); | ||||
2652 | else | ||||
2653 | Assert(N == 1 && F->getReturnType() == RI.getOperand(0)->getType(),do { if (!(N == 1 && F->getReturnType() == RI.getOperand (0)->getType())) { CheckFailed("Function return type does not match operand " "type of return inst!", &RI, F->getReturnType()); return ; } } while (false) | ||||
2654 | "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) | ||||
2655 | "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) | ||||
2656 | &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); | ||||
2657 | |||||
2658 | // Check to make sure that the return value has necessary properties for | ||||
2659 | // terminators... | ||||
2660 | visitTerminator(RI); | ||||
2661 | } | ||||
2662 | |||||
2663 | void Verifier::visitSwitchInst(SwitchInst &SI) { | ||||
2664 | // Check to make sure that all of the constants in the switch instruction | ||||
2665 | // have the same type as the switched-on value. | ||||
2666 | Type *SwitchTy = SI.getCondition()->getType(); | ||||
2667 | SmallPtrSet<ConstantInt*, 32> Constants; | ||||
2668 | for (auto &Case : SI.cases()) { | ||||
2669 | Assert(Case.getCaseValue()->getType() == SwitchTy,do { if (!(Case.getCaseValue()->getType() == SwitchTy)) { CheckFailed ("Switch constants must all be same type as switch value!", & SI); return; } } while (false) | ||||
2670 | "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); | ||||
2671 | Assert(Constants.insert(Case.getCaseValue()).second,do { if (!(Constants.insert(Case.getCaseValue()).second)) { CheckFailed ("Duplicate integer as switch case", &SI, Case.getCaseValue ()); return; } } while (false) | ||||
2672 | "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); | ||||
2673 | } | ||||
2674 | |||||
2675 | visitTerminator(SI); | ||||
2676 | } | ||||
2677 | |||||
2678 | void Verifier::visitIndirectBrInst(IndirectBrInst &BI) { | ||||
2679 | Assert(BI.getAddress()->getType()->isPointerTy(),do { if (!(BI.getAddress()->getType()->isPointerTy())) { CheckFailed("Indirectbr operand must have pointer type!", & BI); return; } } while (false) | ||||
2680 | "Indirectbr operand must have pointer type!", &BI)do { if (!(BI.getAddress()->getType()->isPointerTy())) { CheckFailed("Indirectbr operand must have pointer type!", & BI); return; } } while (false); | ||||
2681 | for (unsigned i = 0, e = BI.getNumDestinations(); i != e; ++i) | ||||
2682 | Assert(BI.getDestination(i)->getType()->isLabelTy(),do { if (!(BI.getDestination(i)->getType()->isLabelTy() )) { CheckFailed("Indirectbr destinations must all have pointer type!" , &BI); return; } } while (false) | ||||
2683 | "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); | ||||
2684 | |||||
2685 | visitTerminator(BI); | ||||
2686 | } | ||||
2687 | |||||
2688 | void Verifier::visitCallBrInst(CallBrInst &CBI) { | ||||
2689 | Assert(CBI.isInlineAsm(), "Callbr is currently only used for asm-goto!",do { if (!(CBI.isInlineAsm())) { CheckFailed("Callbr is currently only used for asm-goto!" , &CBI); return; } } while (false) | ||||
2690 | &CBI)do { if (!(CBI.isInlineAsm())) { CheckFailed("Callbr is currently only used for asm-goto!" , &CBI); return; } } while (false); | ||||
2691 | for (unsigned i = 0, e = CBI.getNumSuccessors(); i != e; ++i) | ||||
2692 | Assert(CBI.getSuccessor(i)->getType()->isLabelTy(),do { if (!(CBI.getSuccessor(i)->getType()->isLabelTy()) ) { CheckFailed("Callbr successors must all have pointer type!" , &CBI); return; } } while (false) | ||||
2693 | "Callbr successors must all have pointer type!", &CBI)do { if (!(CBI.getSuccessor(i)->getType()->isLabelTy()) ) { CheckFailed("Callbr successors must all have pointer type!" , &CBI); return; } } while (false); | ||||
2694 | for (unsigned i = 0, e = CBI.getNumOperands(); i != e; ++i) { | ||||
2695 | Assert(i >= CBI.getNumArgOperands() || !isa<BasicBlock>(CBI.getOperand(i)),do { if (!(i >= CBI.getNumArgOperands() || !isa<BasicBlock >(CBI.getOperand(i)))) { CheckFailed("Using an unescaped label as a callbr argument!" , &CBI); return; } } while (false) | ||||
2696 | "Using an unescaped label as a callbr argument!", &CBI)do { if (!(i >= CBI.getNumArgOperands() || !isa<BasicBlock >(CBI.getOperand(i)))) { CheckFailed("Using an unescaped label as a callbr argument!" , &CBI); return; } } while (false); | ||||
2697 | if (isa<BasicBlock>(CBI.getOperand(i))) | ||||
2698 | for (unsigned j = i + 1; j != e; ++j) | ||||
2699 | Assert(CBI.getOperand(i) != CBI.getOperand(j),do { if (!(CBI.getOperand(i) != CBI.getOperand(j))) { CheckFailed ("Duplicate callbr destination!", &CBI); return; } } while (false) | ||||
2700 | "Duplicate callbr destination!", &CBI)do { if (!(CBI.getOperand(i) != CBI.getOperand(j))) { CheckFailed ("Duplicate callbr destination!", &CBI); return; } } while (false); | ||||
2701 | } | ||||
2702 | { | ||||
2703 | SmallPtrSet<BasicBlock *, 4> ArgBBs; | ||||
2704 | for (Value *V : CBI.args()) | ||||
2705 | if (auto *BA = dyn_cast<BlockAddress>(V)) | ||||
2706 | ArgBBs.insert(BA->getBasicBlock()); | ||||
2707 | for (BasicBlock *BB : CBI.getIndirectDests()) | ||||
2708 | Assert(ArgBBs.count(BB), "Indirect label missing from arglist.", &CBI)do { if (!(ArgBBs.count(BB))) { CheckFailed("Indirect label missing from arglist." , &CBI); return; } } while (false); | ||||
2709 | } | ||||
2710 | |||||
2711 | visitTerminator(CBI); | ||||
2712 | } | ||||
2713 | |||||
2714 | void Verifier::visitSelectInst(SelectInst &SI) { | ||||
2715 | Assert(!SelectInst::areInvalidOperands(SI.getOperand(0), SI.getOperand(1),do { if (!(!SelectInst::areInvalidOperands(SI.getOperand(0), SI .getOperand(1), SI.getOperand(2)))) { CheckFailed("Invalid operands for select instruction!" , &SI); return; } } while (false) | ||||
2716 | 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) | ||||
2717 | "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); | ||||
2718 | |||||
2719 | Assert(SI.getTrueValue()->getType() == SI.getType(),do { if (!(SI.getTrueValue()->getType() == SI.getType())) { CheckFailed("Select values must have same type as select instruction!" , &SI); return; } } while (false) | ||||
2720 | "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); | ||||
2721 | visitInstruction(SI); | ||||
2722 | } | ||||
2723 | |||||
2724 | /// visitUserOp1 - User defined operators shouldn't live beyond the lifetime of | ||||
2725 | /// a pass, if any exist, it's an error. | ||||
2726 | /// | ||||
2727 | void Verifier::visitUserOp1(Instruction &I) { | ||||
2728 | Assert(false, "User-defined operators should not live outside of a pass!", &I)do { if (!(false)) { CheckFailed("User-defined operators should not live outside of a pass!" , &I); return; } } while (false); | ||||
2729 | } | ||||
2730 | |||||
2731 | void Verifier::visitTruncInst(TruncInst &I) { | ||||
2732 | // Get the source and destination types | ||||
2733 | Type *SrcTy = I.getOperand(0)->getType(); | ||||
2734 | Type *DestTy = I.getType(); | ||||
2735 | |||||
2736 | // Get the size of the types in bits, we'll need this later | ||||
2737 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | ||||
2738 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | ||||
2739 | |||||
2740 | Assert(SrcTy->isIntOrIntVectorTy(), "Trunc only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("Trunc only operates on integer" , &I); return; } } while (false); | ||||
2741 | Assert(DestTy->isIntOrIntVectorTy(), "Trunc only produces integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("Trunc only produces integer" , &I); return; } } while (false); | ||||
2742 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(),do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("trunc source and destination must both be a vector or neither" , &I); return; } } while (false) | ||||
2743 | "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); | ||||
2744 | Assert(SrcBitSize > DestBitSize, "DestTy too big for Trunc", &I)do { if (!(SrcBitSize > DestBitSize)) { CheckFailed("DestTy too big for Trunc" , &I); return; } } while (false); | ||||
2745 | |||||
2746 | visitInstruction(I); | ||||
2747 | } | ||||
2748 | |||||
2749 | void Verifier::visitZExtInst(ZExtInst &I) { | ||||
2750 | // Get the source and destination types | ||||
2751 | Type *SrcTy = I.getOperand(0)->getType(); | ||||
2752 | Type *DestTy = I.getType(); | ||||
2753 | |||||
2754 | // Get the size of the types in bits, we'll need this later | ||||
2755 | Assert(SrcTy->isIntOrIntVectorTy(), "ZExt only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("ZExt only operates on integer" , &I); return; } } while (false); | ||||
2756 | Assert(DestTy->isIntOrIntVectorTy(), "ZExt only produces an integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("ZExt only produces an integer" , &I); return; } } while (false); | ||||
2757 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(),do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("zext source and destination must both be a vector or neither" , &I); return; } } while (false) | ||||
2758 | "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); | ||||
2759 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | ||||
2760 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | ||||
2761 | |||||
2762 | Assert(SrcBitSize < DestBitSize, "Type too small for ZExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("Type too small for ZExt" , &I); return; } } while (false); | ||||
2763 | |||||
2764 | visitInstruction(I); | ||||
2765 | } | ||||
2766 | |||||
2767 | void Verifier::visitSExtInst(SExtInst &I) { | ||||
2768 | // Get the source and destination types | ||||
2769 | Type *SrcTy = I.getOperand(0)->getType(); | ||||
2770 | Type *DestTy = I.getType(); | ||||
2771 | |||||
2772 | // Get the size of the types in bits, we'll need this later | ||||
2773 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | ||||
2774 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | ||||
2775 | |||||
2776 | Assert(SrcTy->isIntOrIntVectorTy(), "SExt only operates on integer", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("SExt only operates on integer" , &I); return; } } while (false); | ||||
2777 | Assert(DestTy->isIntOrIntVectorTy(), "SExt only produces an integer", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("SExt only produces an integer" , &I); return; } } while (false); | ||||
2778 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(),do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("sext source and destination must both be a vector or neither" , &I); return; } } while (false) | ||||
2779 | "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); | ||||
2780 | Assert(SrcBitSize < DestBitSize, "Type too small for SExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("Type too small for SExt" , &I); return; } } while (false); | ||||
2781 | |||||
2782 | visitInstruction(I); | ||||
2783 | } | ||||
2784 | |||||
2785 | void Verifier::visitFPTruncInst(FPTruncInst &I) { | ||||
2786 | // Get the source and destination types | ||||
2787 | Type *SrcTy = I.getOperand(0)->getType(); | ||||
2788 | Type *DestTy = I.getType(); | ||||
2789 | // Get the size of the types in bits, we'll need this later | ||||
2790 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | ||||
2791 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | ||||
2792 | |||||
2793 | Assert(SrcTy->isFPOrFPVectorTy(), "FPTrunc only operates on FP", &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPTrunc only operates on FP" , &I); return; } } while (false); | ||||
2794 | Assert(DestTy->isFPOrFPVectorTy(), "FPTrunc only produces an FP", &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("FPTrunc only produces an FP" , &I); return; } } while (false); | ||||
2795 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(),do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("fptrunc source and destination must both be a vector or neither" , &I); return; } } while (false) | ||||
2796 | "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); | ||||
2797 | Assert(SrcBitSize > DestBitSize, "DestTy too big for FPTrunc", &I)do { if (!(SrcBitSize > DestBitSize)) { CheckFailed("DestTy too big for FPTrunc" , &I); return; } } while (false); | ||||
2798 | |||||
2799 | visitInstruction(I); | ||||
2800 | } | ||||
2801 | |||||
2802 | void Verifier::visitFPExtInst(FPExtInst &I) { | ||||
2803 | // Get the source and destination types | ||||
2804 | Type *SrcTy = I.getOperand(0)->getType(); | ||||
2805 | Type *DestTy = I.getType(); | ||||
2806 | |||||
2807 | // Get the size of the types in bits, we'll need this later | ||||
2808 | unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); | ||||
2809 | unsigned DestBitSize = DestTy->getScalarSizeInBits(); | ||||
2810 | |||||
2811 | Assert(SrcTy->isFPOrFPVectorTy(), "FPExt only operates on FP", &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPExt only operates on FP" , &I); return; } } while (false); | ||||
2812 | Assert(DestTy->isFPOrFPVectorTy(), "FPExt only produces an FP", &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("FPExt only produces an FP" , &I); return; } } while (false); | ||||
2813 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(),do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("fpext source and destination must both be a vector or neither" , &I); return; } } while (false) | ||||
2814 | "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); | ||||
2815 | Assert(SrcBitSize < DestBitSize, "DestTy too small for FPExt", &I)do { if (!(SrcBitSize < DestBitSize)) { CheckFailed("DestTy too small for FPExt" , &I); return; } } while (false); | ||||
2816 | |||||
2817 | visitInstruction(I); | ||||
2818 | } | ||||
2819 | |||||
2820 | void Verifier::visitUIToFPInst(UIToFPInst &I) { | ||||
2821 | // Get the source and destination types | ||||
2822 | Type *SrcTy = I.getOperand(0)->getType(); | ||||
2823 | Type *DestTy = I.getType(); | ||||
2824 | |||||
2825 | bool SrcVec = SrcTy->isVectorTy(); | ||||
2826 | bool DstVec = DestTy->isVectorTy(); | ||||
2827 | |||||
2828 | Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("UIToFP source and dest must both be vector or scalar" , &I); return; } } while (false) | ||||
2829 | "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); | ||||
2830 | Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("UIToFP source must be integer or integer vector" , &I); return; } } while (false) | ||||
2831 | "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); | ||||
2832 | Assert(DestTy->isFPOrFPVectorTy(), "UIToFP result must be FP or FP vector",do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("UIToFP result must be FP or FP vector" , &I); return; } } while (false) | ||||
2833 | &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("UIToFP result must be FP or FP vector" , &I); return; } } while (false); | ||||
2834 | |||||
2835 | if (SrcVec && DstVec) | ||||
2836 | Assert(cast<VectorType>(SrcTy)->getElementCount() ==do { if (!(cast<VectorType>(SrcTy)->getElementCount( ) == cast<VectorType>(DestTy)->getElementCount())) { CheckFailed("UIToFP source and dest vector length mismatch", &I); return; } } while (false) | ||||
2837 | 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) | ||||
2838 | "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); | ||||
2839 | |||||
2840 | visitInstruction(I); | ||||
2841 | } | ||||
2842 | |||||
2843 | void Verifier::visitSIToFPInst(SIToFPInst &I) { | ||||
2844 | // Get the source and destination types | ||||
2845 | Type *SrcTy = I.getOperand(0)->getType(); | ||||
2846 | Type *DestTy = I.getType(); | ||||
2847 | |||||
2848 | bool SrcVec = SrcTy->isVectorTy(); | ||||
2849 | bool DstVec = DestTy->isVectorTy(); | ||||
2850 | |||||
2851 | Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("SIToFP source and dest must both be vector or scalar" , &I); return; } } while (false) | ||||
2852 | "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); | ||||
2853 | Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("SIToFP source must be integer or integer vector" , &I); return; } } while (false) | ||||
2854 | "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); | ||||
2855 | Assert(DestTy->isFPOrFPVectorTy(), "SIToFP result must be FP or FP vector",do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("SIToFP result must be FP or FP vector" , &I); return; } } while (false) | ||||
2856 | &I)do { if (!(DestTy->isFPOrFPVectorTy())) { CheckFailed("SIToFP result must be FP or FP vector" , &I); return; } } while (false); | ||||
2857 | |||||
2858 | if (SrcVec && DstVec) | ||||
2859 | Assert(cast<VectorType>(SrcTy)->getElementCount() ==do { if (!(cast<VectorType>(SrcTy)->getElementCount( ) == cast<VectorType>(DestTy)->getElementCount())) { CheckFailed("SIToFP source and dest vector length mismatch", &I); return; } } while (false) | ||||
2860 | 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) | ||||
2861 | "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); | ||||
2862 | |||||
2863 | visitInstruction(I); | ||||
2864 | } | ||||
2865 | |||||
2866 | void Verifier::visitFPToUIInst(FPToUIInst &I) { | ||||
2867 | // Get the source and destination types | ||||
2868 | Type *SrcTy = I.getOperand(0)->getType(); | ||||
2869 | Type *DestTy = I.getType(); | ||||
2870 | |||||
2871 | bool SrcVec = SrcTy->isVectorTy(); | ||||
2872 | bool DstVec = DestTy->isVectorTy(); | ||||
2873 | |||||
2874 | Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("FPToUI source and dest must both be vector or scalar" , &I); return; } } while (false) | ||||
2875 | "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); | ||||
2876 | Assert(SrcTy->isFPOrFPVectorTy(), "FPToUI source must be FP or FP vector",do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToUI source must be FP or FP vector" , &I); return; } } while (false) | ||||
2877 | &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToUI source must be FP or FP vector" , &I); return; } } while (false); | ||||
2878 | Assert(DestTy->isIntOrIntVectorTy(),do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToUI result must be integer or integer vector" , &I); return; } } while (false) | ||||
2879 | "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); | ||||
2880 | |||||
2881 | if (SrcVec && DstVec) | ||||
2882 | Assert(cast<VectorType>(SrcTy)->getElementCount() ==do { if (!(cast<VectorType>(SrcTy)->getElementCount( ) == cast<VectorType>(DestTy)->getElementCount())) { CheckFailed("FPToUI source and dest vector length mismatch", &I); return; } } while (false) | ||||
2883 | 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) | ||||
2884 | "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); | ||||
2885 | |||||
2886 | visitInstruction(I); | ||||
2887 | } | ||||
2888 | |||||
2889 | void Verifier::visitFPToSIInst(FPToSIInst &I) { | ||||
2890 | // Get the source and destination types | ||||
2891 | Type *SrcTy = I.getOperand(0)->getType(); | ||||
2892 | Type *DestTy = I.getType(); | ||||
2893 | |||||
2894 | bool SrcVec = SrcTy->isVectorTy(); | ||||
2895 | bool DstVec = DestTy->isVectorTy(); | ||||
2896 | |||||
2897 | Assert(SrcVec == DstVec,do { if (!(SrcVec == DstVec)) { CheckFailed("FPToSI source and dest must both be vector or scalar" , &I); return; } } while (false) | ||||
2898 | "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); | ||||
2899 | Assert(SrcTy->isFPOrFPVectorTy(), "FPToSI source must be FP or FP vector",do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToSI source must be FP or FP vector" , &I); return; } } while (false) | ||||
2900 | &I)do { if (!(SrcTy->isFPOrFPVectorTy())) { CheckFailed("FPToSI source must be FP or FP vector" , &I); return; } } while (false); | ||||
2901 | Assert(DestTy->isIntOrIntVectorTy(),do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("FPToSI result must be integer or integer vector" , &I); return; } } while (false) | ||||
2902 | "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); | ||||
2903 | |||||
2904 | if (SrcVec && DstVec) | ||||
2905 | Assert(cast<VectorType>(SrcTy)->getElementCount() ==do { if (!(cast<VectorType>(SrcTy)->getElementCount( ) == cast<VectorType>(DestTy)->getElementCount())) { CheckFailed("FPToSI source and dest vector length mismatch", &I); return; } } while (false) | ||||
2906 | 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) | ||||
2907 | "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); | ||||
2908 | |||||
2909 | visitInstruction(I); | ||||
2910 | } | ||||
2911 | |||||
2912 | void Verifier::visitPtrToIntInst(PtrToIntInst &I) { | ||||
2913 | // Get the source and destination types | ||||
2914 | Type *SrcTy = I.getOperand(0)->getType(); | ||||
2915 | Type *DestTy = I.getType(); | ||||
2916 | |||||
2917 | Assert(SrcTy->isPtrOrPtrVectorTy(), "PtrToInt source must be pointer", &I)do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("PtrToInt source must be pointer" , &I); return; } } while (false); | ||||
2918 | |||||
2919 | if (auto *PTy = dyn_cast<PointerType>(SrcTy->getScalarType())) | ||||
2920 | Assert(!DL.isNonIntegralPointerType(PTy),do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed( "ptrtoint not supported for non-integral pointers"); return; } } while (false) | ||||
2921 | "ptrtoint not supported for non-integral pointers")do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed( "ptrtoint not supported for non-integral pointers"); return; } } while (false); | ||||
2922 | |||||
2923 | Assert(DestTy->isIntOrIntVectorTy(), "PtrToInt result must be integral", &I)do { if (!(DestTy->isIntOrIntVectorTy())) { CheckFailed("PtrToInt result must be integral" , &I); return; } } while (false); | ||||
2924 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(), "PtrToInt type mismatch",do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("PtrToInt type mismatch", &I); return; } } while (false) | ||||
2925 | &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("PtrToInt type mismatch", &I); return; } } while (false); | ||||
2926 | |||||
2927 | if (SrcTy->isVectorTy()) { | ||||
2928 | auto *VSrc = cast<VectorType>(SrcTy); | ||||
2929 | auto *VDest = cast<VectorType>(DestTy); | ||||
2930 | Assert(VSrc->getElementCount() == VDest->getElementCount(),do { if (!(VSrc->getElementCount() == VDest->getElementCount ())) { CheckFailed("PtrToInt Vector width mismatch", &I); return; } } while (false) | ||||
2931 | "PtrToInt Vector width mismatch", &I)do { if (!(VSrc->getElementCount() == VDest->getElementCount ())) { CheckFailed("PtrToInt Vector width mismatch", &I); return; } } while (false); | ||||
2932 | } | ||||
2933 | |||||
2934 | visitInstruction(I); | ||||
2935 | } | ||||
2936 | |||||
2937 | void Verifier::visitIntToPtrInst(IntToPtrInst &I) { | ||||
2938 | // Get the source and destination types | ||||
2939 | Type *SrcTy = I.getOperand(0)->getType(); | ||||
2940 | Type *DestTy = I.getType(); | ||||
2941 | |||||
2942 | Assert(SrcTy->isIntOrIntVectorTy(),do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("IntToPtr source must be an integral" , &I); return; } } while (false) | ||||
2943 | "IntToPtr source must be an integral", &I)do { if (!(SrcTy->isIntOrIntVectorTy())) { CheckFailed("IntToPtr source must be an integral" , &I); return; } } while (false); | ||||
2944 | Assert(DestTy->isPtrOrPtrVectorTy(), "IntToPtr result must be a pointer", &I)do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("IntToPtr result must be a pointer" , &I); return; } } while (false); | ||||
2945 | |||||
2946 | if (auto *PTy = dyn_cast<PointerType>(DestTy->getScalarType())) | ||||
2947 | Assert(!DL.isNonIntegralPointerType(PTy),do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed( "inttoptr not supported for non-integral pointers"); return; } } while (false) | ||||
2948 | "inttoptr not supported for non-integral pointers")do { if (!(!DL.isNonIntegralPointerType(PTy))) { CheckFailed( "inttoptr not supported for non-integral pointers"); return; } } while (false); | ||||
2949 | |||||
2950 | Assert(SrcTy->isVectorTy() == DestTy->isVectorTy(), "IntToPtr type mismatch",do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("IntToPtr type mismatch", &I); return; } } while (false) | ||||
2951 | &I)do { if (!(SrcTy->isVectorTy() == DestTy->isVectorTy()) ) { CheckFailed("IntToPtr type mismatch", &I); return; } } while (false); | ||||
2952 | if (SrcTy->isVectorTy()) { | ||||
2953 | auto *VSrc = cast<VectorType>(SrcTy); | ||||
2954 | auto *VDest = cast<VectorType>(DestTy); | ||||
2955 | Assert(VSrc->getElementCount() == VDest->getElementCount(),do { if (!(VSrc->getElementCount() == VDest->getElementCount ())) { CheckFailed("IntToPtr Vector width mismatch", &I); return; } } while (false) | ||||
2956 | "IntToPtr Vector width mismatch", &I)do { if (!(VSrc->getElementCount() == VDest->getElementCount ())) { CheckFailed("IntToPtr Vector width mismatch", &I); return; } } while (false); | ||||
2957 | } | ||||
2958 | visitInstruction(I); | ||||
2959 | } | ||||
2960 | |||||
2961 | void Verifier::visitBitCastInst(BitCastInst &I) { | ||||
2962 | Assert(do { if (!(CastInst::castIsValid(Instruction::BitCast, I.getOperand (0), I.getType()))) { CheckFailed("Invalid bitcast", &I); return; } } while (false) | ||||
2963 | 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) | ||||
2964 | "Invalid bitcast", &I)do { if (!(CastInst::castIsValid(Instruction::BitCast, I.getOperand (0), I.getType()))) { CheckFailed("Invalid bitcast", &I); return; } } while (false); | ||||
2965 | visitInstruction(I); | ||||
2966 | } | ||||
2967 | |||||
2968 | void Verifier::visitAddrSpaceCastInst(AddrSpaceCastInst &I) { | ||||
2969 | Type *SrcTy = I.getOperand(0)->getType(); | ||||
2970 | Type *DestTy = I.getType(); | ||||
2971 | |||||
2972 | Assert(SrcTy->isPtrOrPtrVectorTy(), "AddrSpaceCast source must be a pointer",do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast source must be a pointer" , &I); return; } } while (false) | ||||
2973 | &I)do { if (!(SrcTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast source must be a pointer" , &I); return; } } while (false); | ||||
2974 | Assert(DestTy->isPtrOrPtrVectorTy(), "AddrSpaceCast result must be a pointer",do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast result must be a pointer" , &I); return; } } while (false) | ||||
2975 | &I)do { if (!(DestTy->isPtrOrPtrVectorTy())) { CheckFailed("AddrSpaceCast result must be a pointer" , &I); return; } } while (false); | ||||
2976 | Assert(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace(),do { if (!(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace ())) { CheckFailed("AddrSpaceCast must be between different address spaces" , &I); return; } } while (false) | ||||
2977 | "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); | ||||
2978 | if (auto *SrcVTy = dyn_cast<VectorType>(SrcTy)) | ||||
2979 | Assert(SrcVTy->getElementCount() ==do { if (!(SrcVTy->getElementCount() == cast<VectorType >(DestTy)->getElementCount())) { CheckFailed("AddrSpaceCast vector pointer number of elements mismatch" , &I); return; } } while (false) | ||||
2980 | cast<VectorType>(DestTy)->getElementCount(),do { if (!(SrcVTy->getElementCount() == cast<VectorType >(DestTy)->getElementCount())) { CheckFailed("AddrSpaceCast vector pointer number of elements mismatch" , &I); return; } } while (false) | ||||
2981 | "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); | ||||
2982 | visitInstruction(I); | ||||
2983 | } | ||||
2984 | |||||
2985 | /// visitPHINode - Ensure that a PHI node is well formed. | ||||
2986 | /// | ||||
2987 | void Verifier::visitPHINode(PHINode &PN) { | ||||
2988 | // Ensure that the PHI nodes are all grouped together at the top of the block. | ||||
2989 | // This can be tested by checking whether the instruction before this is | ||||
2990 | // either nonexistent (because this is begin()) or is a PHI node. If not, | ||||
2991 | // then there is some other instruction before a PHI. | ||||
2992 | Assert(&PN == &PN.getParent()->front() ||do { if (!(&PN == &PN.getParent()->front() || isa< PHINode>(--BasicBlock::iterator(&PN)))) { CheckFailed( "PHI nodes not grouped at top of basic block!", &PN, PN.getParent ()); return; } } while (false) | ||||
2993 | 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) | ||||
2994 | "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); | ||||
2995 | |||||
2996 | // Check that a PHI doesn't yield a Token. | ||||
2997 | Assert(!PN.getType()->isTokenTy(), "PHI nodes cannot have token type!")do { if (!(!PN.getType()->isTokenTy())) { CheckFailed("PHI nodes cannot have token type!" ); return; } } while (false); | ||||
2998 | |||||
2999 | // Check that all of the values of the PHI node have the same type as the | ||||
3000 | // result, and that the incoming blocks are really basic blocks. | ||||
3001 | for (Value *IncValue : PN.incoming_values()) { | ||||
3002 | Assert(PN.getType() == IncValue->getType(),do { if (!(PN.getType() == IncValue->getType())) { CheckFailed ("PHI node operands are not the same type as the result!", & PN); return; } } while (false) | ||||
3003 | "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); | ||||
3004 | } | ||||
3005 | |||||
3006 | // All other PHI node constraints are checked in the visitBasicBlock method. | ||||
3007 | |||||
3008 | visitInstruction(PN); | ||||
3009 | } | ||||
3010 | |||||
3011 | void Verifier::visitCallBase(CallBase &Call) { | ||||
3012 | Assert(Call.getCalledOperand()->getType()->isPointerTy(),do { if (!(Call.getCalledOperand()->getType()->isPointerTy ())) { CheckFailed("Called function must be a pointer!", Call ); return; } } while (false) | ||||
3013 | "Called function must be a pointer!", Call)do { if (!(Call.getCalledOperand()->getType()->isPointerTy ())) { CheckFailed("Called function must be a pointer!", Call ); return; } } while (false); | ||||
3014 | PointerType *FPTy = cast<PointerType>(Call.getCalledOperand()->getType()); | ||||
3015 | |||||
3016 | Assert(FPTy->getElementType()->isFunctionTy(),do { if (!(FPTy->getElementType()->isFunctionTy())) { CheckFailed ("Called function is not pointer to function type!", Call); return ; } } while (false) | ||||
3017 | "Called function is not pointer to function type!", Call)do { if (!(FPTy->getElementType()->isFunctionTy())) { CheckFailed ("Called function is not pointer to function type!", Call); return ; } } while (false); | ||||
3018 | |||||
3019 | Assert(FPTy->getElementType() == Call.getFunctionType(),do { if (!(FPTy->getElementType() == Call.getFunctionType( ))) { CheckFailed("Called function is not the same type as the call!" , Call); return; } } while (false) | ||||
3020 | "Called function is not the same type as the call!", Call)do { if (!(FPTy->getElementType() == Call.getFunctionType( ))) { CheckFailed("Called function is not the same type as the call!" , Call); return; } } while (false); | ||||
3021 | |||||
3022 | FunctionType *FTy = Call.getFunctionType(); | ||||
3023 | |||||
3024 | // Verify that the correct number of arguments are being passed | ||||
3025 | if (FTy->isVarArg()) | ||||
3026 | Assert(Call.arg_size() >= FTy->getNumParams(),do { if (!(Call.arg_size() >= FTy->getNumParams())) { CheckFailed ("Called function requires more parameters than were provided!" , Call); return; } } while (false) | ||||
3027 | "Called function requires more parameters than were provided!",do { if (!(Call.arg_size() >= FTy->getNumParams())) { CheckFailed ("Called function requires more parameters than were provided!" , Call); return; } } while (false) | ||||
3028 | Call)do { if (!(Call.arg_size() >= FTy->getNumParams())) { CheckFailed ("Called function requires more parameters than were provided!" , Call); return; } } while (false); | ||||
3029 | else | ||||
3030 | Assert(Call.arg_size() == FTy->getNumParams(),do { if (!(Call.arg_size() == FTy->getNumParams())) { CheckFailed ("Incorrect number of arguments passed to called function!", Call ); return; } } while (false) | ||||
3031 | "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); | ||||
3032 | |||||
3033 | // Verify that all arguments to the call match the function type. | ||||
3034 | for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) | ||||
3035 | Assert(Call.getArgOperand(i)->getType() == FTy->getParamType(i),do { if (!(Call.getArgOperand(i)->getType() == FTy->getParamType (i))) { CheckFailed("Call parameter type does not match function signature!" , Call.getArgOperand(i), FTy->getParamType(i), Call); return ; } } while (false) | ||||
3036 | "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) | ||||
3037 | 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); | ||||
3038 | |||||
3039 | AttributeList Attrs = Call.getAttributes(); | ||||
3040 | |||||
3041 | Assert(verifyAttributeCount(Attrs, Call.arg_size()),do { if (!(verifyAttributeCount(Attrs, Call.arg_size()))) { CheckFailed ("Attribute after last parameter!", Call); return; } } while ( false) | ||||
3042 | "Attribute after last parameter!", Call)do { if (!(verifyAttributeCount(Attrs, Call.arg_size()))) { CheckFailed ("Attribute after last parameter!", Call); return; } } while ( false); | ||||
3043 | |||||
3044 | bool IsIntrinsic = Call.getCalledFunction() && | ||||
3045 | Call.getCalledFunction()->getName().startswith("llvm."); | ||||
3046 | |||||
3047 | Function *Callee = | ||||
3048 | dyn_cast<Function>(Call.getCalledOperand()->stripPointerCasts()); | ||||
3049 | |||||
3050 | if (Attrs.hasFnAttribute(Attribute::Speculatable)) { | ||||
3051 | // Don't allow speculatable on call sites, unless the underlying function | ||||
3052 | // declaration is also speculatable. | ||||
3053 | Assert(Callee && Callee->isSpeculatable(),do { if (!(Callee && Callee->isSpeculatable())) { CheckFailed ("speculatable attribute may not apply to call sites", Call); return; } } while (false) | ||||
3054 | "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); | ||||
3055 | } | ||||
3056 | |||||
3057 | if (Attrs.hasFnAttribute(Attribute::Preallocated)) { | ||||
3058 | Assert(Call.getCalledFunction()->getIntrinsicID() ==do { if (!(Call.getCalledFunction()->getIntrinsicID() == Intrinsic ::call_preallocated_arg)) { CheckFailed("preallocated as a call site attribute can only be on " "llvm.call.preallocated.arg"); return; } } while (false) | ||||
3059 | 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) | ||||
3060 | "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) | ||||
3061 | "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); | ||||
3062 | } | ||||
3063 | |||||
3064 | // Verify call attributes. | ||||
3065 | verifyFunctionAttrs(FTy, Attrs, &Call, IsIntrinsic); | ||||
3066 | |||||
3067 | // Conservatively check the inalloca argument. | ||||
3068 | // We have a bug if we can find that there is an underlying alloca without | ||||
3069 | // inalloca. | ||||
3070 | if (Call.hasInAllocaArgument()) { | ||||
3071 | Value *InAllocaArg = Call.getArgOperand(FTy->getNumParams() - 1); | ||||
3072 | if (auto AI = dyn_cast<AllocaInst>(InAllocaArg->stripInBoundsOffsets())) | ||||
3073 | Assert(AI->isUsedWithInAlloca(),do { if (!(AI->isUsedWithInAlloca())) { CheckFailed("inalloca argument for call has mismatched alloca" , AI, Call); return; } } while (false) | ||||
3074 | "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); | ||||
3075 | } | ||||
3076 | |||||
3077 | // For each argument of the callsite, if it has the swifterror argument, | ||||
3078 | // make sure the underlying alloca/parameter it comes from has a swifterror as | ||||
3079 | // well. | ||||
3080 | for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) { | ||||
3081 | if (Call.paramHasAttr(i, Attribute::SwiftError)) { | ||||
3082 | Value *SwiftErrorArg = Call.getArgOperand(i); | ||||
3083 | if (auto AI = dyn_cast<AllocaInst>(SwiftErrorArg->stripInBoundsOffsets())) { | ||||
3084 | Assert(AI->isSwiftError(),do { if (!(AI->isSwiftError())) { CheckFailed("swifterror argument for call has mismatched alloca" , AI, Call); return; } } while (false) | ||||
3085 | "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); | ||||
3086 | continue; | ||||
3087 | } | ||||
3088 | auto ArgI = dyn_cast<Argument>(SwiftErrorArg); | ||||
3089 | Assert(ArgI,do { if (!(ArgI)) { CheckFailed("swifterror argument should come from an alloca or parameter" , SwiftErrorArg, Call); return; } } while (false) | ||||
3090 | "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) | ||||
3091 | SwiftErrorArg, Call)do { if (!(ArgI)) { CheckFailed("swifterror argument should come from an alloca or parameter" , SwiftErrorArg, Call); return; } } while (false); | ||||
3092 | Assert(ArgI->hasSwiftErrorAttr(),do { if (!(ArgI->hasSwiftErrorAttr())) { CheckFailed("swifterror argument for call has mismatched parameter" , ArgI, Call); return; } } while (false) | ||||
3093 | "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) | ||||
3094 | Call)do { if (!(ArgI->hasSwiftErrorAttr())) { CheckFailed("swifterror argument for call has mismatched parameter" , ArgI, Call); return; } } while (false); | ||||
3095 | } | ||||
3096 | |||||
3097 | if (Attrs.hasParamAttribute(i, Attribute::ImmArg)) { | ||||
3098 | // Don't allow immarg on call sites, unless the underlying declaration | ||||
3099 | // also has the matching immarg. | ||||
3100 | Assert(Callee && Callee->hasParamAttribute(i, Attribute::ImmArg),do { if (!(Callee && Callee->hasParamAttribute(i, Attribute ::ImmArg))) { CheckFailed("immarg may not apply only to call sites" , Call.getArgOperand(i), Call); return; } } while (false) | ||||
3101 | "immarg may not apply only to call sites",do { if (!(Callee && Callee->hasParamAttribute(i, Attribute ::ImmArg))) { CheckFailed("immarg may not apply only to call sites" , Call.getArgOperand(i), Call); return; } } while (false) | ||||
3102 | Call.getArgOperand(i), Call)do { if (!(Callee && Callee->hasParamAttribute(i, Attribute ::ImmArg))) { CheckFailed("immarg may not apply only to call sites" , Call.getArgOperand(i), Call); return; } } while (false); | ||||
3103 | } | ||||
3104 | |||||
3105 | if (Call.paramHasAttr(i, Attribute::ImmArg)) { | ||||
3106 | Value *ArgVal = Call.getArgOperand(i); | ||||
3107 | Assert(isa<ConstantInt>(ArgVal) || isa<ConstantFP>(ArgVal),do { if (!(isa<ConstantInt>(ArgVal) || isa<ConstantFP >(ArgVal))) { CheckFailed("immarg operand has non-immediate parameter" , ArgVal, Call); return; } } while (false) | ||||
3108 | "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); | ||||
3109 | } | ||||
3110 | |||||
3111 | if (Call.paramHasAttr(i, Attribute::Preallocated)) { | ||||
3112 | Value *ArgVal = Call.getArgOperand(i); | ||||
3113 | bool hasOB = | ||||
3114 | Call.countOperandBundlesOfType(LLVMContext::OB_preallocated) != 0; | ||||
3115 | bool isMustTail = Call.isMustTailCall(); | ||||
3116 | Assert(hasOB != isMustTail,do { if (!(hasOB != isMustTail)) { CheckFailed("preallocated operand either requires a preallocated bundle or " "the call to be musttail (but not both)", ArgVal, Call); return ; } } while (false) | ||||
3117 | "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) | ||||
3118 | "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) | ||||
3119 | 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); | ||||
3120 | } | ||||
3121 | } | ||||
3122 | |||||
3123 | if (FTy->isVarArg()) { | ||||
3124 | // FIXME? is 'nest' even legal here? | ||||
3125 | bool SawNest = false; | ||||
3126 | bool SawReturned = false; | ||||
3127 | |||||
3128 | for (unsigned Idx = 0; Idx < FTy->getNumParams(); ++Idx) { | ||||
3129 | if (Attrs.hasParamAttribute(Idx, Attribute::Nest)) | ||||
3130 | SawNest = true; | ||||
3131 | if (Attrs.hasParamAttribute(Idx, Attribute::Returned)) | ||||
3132 | SawReturned = true; | ||||
3133 | } | ||||
3134 | |||||
3135 | // Check attributes on the varargs part. | ||||
3136 | for (unsigned Idx = FTy->getNumParams(); Idx < Call.arg_size(); ++Idx) { | ||||
3137 | Type *Ty = Call.getArgOperand(Idx)->getType(); | ||||
3138 | AttributeSet ArgAttrs = Attrs.getParamAttributes(Idx); | ||||
3139 | verifyParameterAttrs(ArgAttrs, Ty, &Call); | ||||
3140 | |||||
3141 | if (ArgAttrs.hasAttribute(Attribute::Nest)) { | ||||
3142 | Assert(!SawNest, "More than one parameter has attribute nest!", Call)do { if (!(!SawNest)) { CheckFailed("More than one parameter has attribute nest!" , Call); return; } } while (false); | ||||
3143 | SawNest = true; | ||||
3144 | } | ||||
3145 | |||||
3146 | if (ArgAttrs.hasAttribute(Attribute::Returned)) { | ||||
3147 | Assert(!SawReturned, "More than one parameter has attribute returned!",do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!" , Call); return; } } while (false) | ||||
3148 | Call)do { if (!(!SawReturned)) { CheckFailed("More than one parameter has attribute returned!" , Call); return; } } while (false); | ||||
3149 | Assert(Ty->canLosslesslyBitCastTo(FTy->getReturnType()),do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' " "attribute", Call); return; } } while (false) | ||||
3150 | "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) | ||||
3151 | "attribute",do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' " "attribute", Call); return; } } while (false) | ||||
3152 | Call)do { if (!(Ty->canLosslesslyBitCastTo(FTy->getReturnType ()))) { CheckFailed("Incompatible argument and return types for 'returned' " "attribute", Call); return; } } while (false); | ||||
3153 | SawReturned = true; | ||||
3154 | } | ||||
3155 | |||||
3156 | // Statepoint intrinsic is vararg but the wrapped function may be not. | ||||
3157 | // Allow sret here and check the wrapped function in verifyStatepoint. | ||||
3158 | if (!Call.getCalledFunction() || | ||||
3159 | Call.getCalledFunction()->getIntrinsicID() != | ||||
3160 | Intrinsic::experimental_gc_statepoint) | ||||
3161 | Assert(!ArgAttrs.hasAttribute(Attribute::StructRet),do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed ("Attribute 'sret' cannot be used for vararg call arguments!" , Call); return; } } while (false) | ||||
3162 | "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) | ||||
3163 | Call)do { if (!(!ArgAttrs.hasAttribute(Attribute::StructRet))) { CheckFailed ("Attribute 'sret' cannot be used for vararg call arguments!" , Call); return; } } while (false); | ||||
3164 | |||||
3165 | if (ArgAttrs.hasAttribute(Attribute::InAlloca)) | ||||
3166 | Assert(Idx == Call.arg_size() - 1,do { if (!(Idx == Call.arg_size() - 1)) { CheckFailed("inalloca isn't on the last argument!" , Call); return; } } while (false) | ||||
3167 | "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); | ||||
3168 | } | ||||
3169 | } | ||||
3170 | |||||
3171 | // Verify that there's no metadata unless it's a direct call to an intrinsic. | ||||
3172 | if (!IsIntrinsic) { | ||||
3173 | for (Type *ParamTy : FTy->params()) { | ||||
3174 | Assert(!ParamTy->isMetadataTy(),do { if (!(!ParamTy->isMetadataTy())) { CheckFailed("Function has metadata parameter but isn't an intrinsic" , Call); return; } } while (false) | ||||
3175 | "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); | ||||
3176 | Assert(!ParamTy->isTokenTy(),do { if (!(!ParamTy->isTokenTy())) { CheckFailed("Function has token parameter but isn't an intrinsic" , Call); return; } } while (false) | ||||
3177 | "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); | ||||
3178 | } | ||||
3179 | } | ||||
3180 | |||||
3181 | // Verify that indirect calls don't return tokens. | ||||
3182 | if (!Call.getCalledFunction()) | ||||
3183 | Assert(!FTy->getReturnType()->isTokenTy(),do { if (!(!FTy->getReturnType()->isTokenTy())) { CheckFailed ("Return type cannot be token for indirect call!"); return; } } while (false) | ||||
3184 | "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); | ||||
3185 | |||||
3186 | if (Function *F = Call.getCalledFunction()) | ||||
3187 | if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) | ||||
3188 | visitIntrinsicCall(ID, Call); | ||||
3189 | |||||
3190 | // Verify that a callsite has at most one "deopt", at most one "funclet", at | ||||
3191 | // most one "gc-transition", at most one "cfguardtarget", | ||||
3192 | // and at most one "preallocated" operand bundle. | ||||
3193 | bool FoundDeoptBundle = false, FoundFuncletBundle = false, | ||||
3194 | FoundGCTransitionBundle = false, FoundCFGuardTargetBundle = false, | ||||
3195 | FoundPreallocatedBundle = false, FoundGCLiveBundle = false;; | ||||
3196 | for (unsigned i = 0, e = Call.getNumOperandBundles(); i < e; ++i) { | ||||
3197 | OperandBundleUse BU = Call.getOperandBundleAt(i); | ||||
3198 | uint32_t Tag = BU.getTagID(); | ||||
3199 | if (Tag == LLVMContext::OB_deopt) { | ||||
3200 | Assert(!FoundDeoptBundle, "Multiple deopt operand bundles", Call)do { if (!(!FoundDeoptBundle)) { CheckFailed("Multiple deopt operand bundles" , Call); return; } } while (false); | ||||
3201 | FoundDeoptBundle = true; | ||||
3202 | } else if (Tag == LLVMContext::OB_gc_transition) { | ||||
3203 | Assert(!FoundGCTransitionBundle, "Multiple gc-transition operand bundles",do { if (!(!FoundGCTransitionBundle)) { CheckFailed("Multiple gc-transition operand bundles" , Call); return; } } while (false) | ||||
3204 | Call)do { if (!(!FoundGCTransitionBundle)) { CheckFailed("Multiple gc-transition operand bundles" , Call); return; } } while (false); | ||||
3205 | FoundGCTransitionBundle = true; | ||||
3206 | } else if (Tag == LLVMContext::OB_funclet) { | ||||
3207 | Assert(!FoundFuncletBundle, "Multiple funclet operand bundles", Call)do { if (!(!FoundFuncletBundle)) { CheckFailed("Multiple funclet operand bundles" , Call); return; } } while (false); | ||||
3208 | FoundFuncletBundle = true; | ||||
3209 | Assert(BU.Inputs.size() == 1,do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one funclet bundle operand" , Call); return; } } while (false) | ||||
3210 | "Expected exactly one funclet bundle operand", Call)do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one funclet bundle operand" , Call); return; } } while (false); | ||||
3211 | Assert(isa<FuncletPadInst>(BU.Inputs.front()),do { if (!(isa<FuncletPadInst>(BU.Inputs.front()))) { CheckFailed ("Funclet bundle operands should correspond to a FuncletPadInst" , Call); return; } } while (false) | ||||
3212 | "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) | ||||
3213 | Call)do { if (!(isa<FuncletPadInst>(BU.Inputs.front()))) { CheckFailed ("Funclet bundle operands should correspond to a FuncletPadInst" , Call); return; } } while (false); | ||||
3214 | } else if (Tag == LLVMContext::OB_cfguardtarget) { | ||||
3215 | Assert(!FoundCFGuardTargetBundle,do { if (!(!FoundCFGuardTargetBundle)) { CheckFailed("Multiple CFGuardTarget operand bundles" , Call); return; } } while (false) | ||||
3216 | "Multiple CFGuardTarget operand bundles", Call)do { if (!(!FoundCFGuardTargetBundle)) { CheckFailed("Multiple CFGuardTarget operand bundles" , Call); return; } } while (false); | ||||
3217 | FoundCFGuardTargetBundle = true; | ||||
3218 | Assert(BU.Inputs.size() == 1,do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one cfguardtarget bundle operand" , Call); return; } } while (false) | ||||
3219 | "Expected exactly one cfguardtarget bundle operand", Call)do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one cfguardtarget bundle operand" , Call); return; } } while (false); | ||||
3220 | } else if (Tag == LLVMContext::OB_preallocated) { | ||||
3221 | Assert(!FoundPreallocatedBundle, "Multiple preallocated operand bundles",do { if (!(!FoundPreallocatedBundle)) { CheckFailed("Multiple preallocated operand bundles" , Call); return; } } while (false) | ||||
3222 | Call)do { if (!(!FoundPreallocatedBundle)) { CheckFailed("Multiple preallocated operand bundles" , Call); return; } } while (false); | ||||
3223 | FoundPreallocatedBundle = true; | ||||
3224 | Assert(BU.Inputs.size() == 1,do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one preallocated bundle operand" , Call); return; } } while (false) | ||||
3225 | "Expected exactly one preallocated bundle operand", Call)do { if (!(BU.Inputs.size() == 1)) { CheckFailed("Expected exactly one preallocated bundle operand" , Call); return; } } while (false); | ||||
3226 | auto Input = dyn_cast<IntrinsicInst>(BU.Inputs.front()); | ||||
3227 | Assert(Input &&do { if (!(Input && Input->getIntrinsicID() == Intrinsic ::call_preallocated_setup)) { CheckFailed("\"preallocated\" argument must be a token from " "llvm.call.preallocated.setup", Call); return; } } while (false ) | ||||
3228 | 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 ) | ||||
3229 | "\"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 ) | ||||
3230 | "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 ) | ||||
3231 | 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 ); | ||||
3232 | } else if (Tag == LLVMContext::OB_gc_live) { | ||||
3233 | Assert(!FoundGCLiveBundle, "Multiple gc-live operand bundles",do { if (!(!FoundGCLiveBundle)) { CheckFailed("Multiple gc-live operand bundles" , Call); return; } } while (false) | ||||
3234 | Call)do { if (!(!FoundGCLiveBundle)) { CheckFailed("Multiple gc-live operand bundles" , Call); return; } } while (false); | ||||
3235 | FoundGCLiveBundle = true; | ||||
3236 | } | ||||
3237 | } | ||||
3238 | |||||
3239 | // Verify that each inlinable callsite of a debug-info-bearing function in a | ||||
3240 | // debug-info-bearing function has a debug location attached to it. Failure to | ||||
3241 | // do so causes assertion failures when the inliner sets up inline scope info. | ||||
3242 | if (Call.getFunction()->getSubprogram() && Call.getCalledFunction() && | ||||
3243 | Call.getCalledFunction()->getSubprogram()) | ||||
3244 | AssertDI(Call.getDebugLoc(),do { if (!(Call.getDebugLoc())) { DebugInfoCheckFailed("inlinable function call in a function with " "debug info must have a !dbg location", Call); return; } } while (false) | ||||
3245 | "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) | ||||
3246 | "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) | ||||
3247 | Call)do { if (!(Call.getDebugLoc())) { DebugInfoCheckFailed("inlinable function call in a function with " "debug info must have a !dbg location", Call); return; } } while (false); | ||||
3248 | |||||
3249 | visitInstruction(Call); | ||||
3250 | } | ||||
3251 | |||||
3252 | /// Two types are "congruent" if they are identical, or if they are both pointer | ||||
3253 | /// types with different pointee types and the same address space. | ||||
3254 | static bool isTypeCongruent(Type *L, Type *R) { | ||||
3255 | if (L == R) | ||||
3256 | return true; | ||||
3257 | PointerType *PL = dyn_cast<PointerType>(L); | ||||
3258 | PointerType *PR = dyn_cast<PointerType>(R); | ||||
3259 | if (!PL || !PR) | ||||
3260 | return false; | ||||
3261 | return PL->getAddressSpace() == PR->getAddressSpace(); | ||||
3262 | } | ||||
3263 | |||||
3264 | static AttrBuilder getParameterABIAttributes(int I, AttributeList Attrs) { | ||||
3265 | static const Attribute::AttrKind ABIAttrs[] = { | ||||
3266 | Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca, | ||||
3267 | Attribute::InReg, Attribute::SwiftSelf, Attribute::SwiftError, | ||||
3268 | Attribute::Preallocated, Attribute::ByRef}; | ||||
3269 | AttrBuilder Copy; | ||||
3270 | for (auto AK : ABIAttrs) { | ||||
3271 | if (Attrs.hasParamAttribute(I, AK)) | ||||
3272 | Copy.addAttribute(AK); | ||||
3273 | } | ||||
3274 | |||||
3275 | // `align` is ABI-affecting only in combination with `byval` or `byref`. | ||||
3276 | if (Attrs.hasParamAttribute(I, Attribute::Alignment) && | ||||
3277 | (Attrs.hasParamAttribute(I, Attribute::ByVal) || | ||||
3278 | Attrs.hasParamAttribute(I, Attribute::ByRef))) | ||||
3279 | Copy.addAlignmentAttr(Attrs.getParamAlignment(I)); | ||||
3280 | return Copy; | ||||
3281 | } | ||||
3282 | |||||
3283 | void Verifier::verifyMustTailCall(CallInst &CI) { | ||||
3284 | Assert(!CI.isInlineAsm(), "cannot use musttail call with inline asm", &CI)do { if (!(!CI.isInlineAsm())) { CheckFailed("cannot use musttail call with inline asm" , &CI); return; } } while (false); | ||||
3285 | |||||
3286 | // - The caller and callee prototypes must match. Pointer types of | ||||
3287 | // parameters or return types may differ in pointee type, but not | ||||
3288 | // address space. | ||||
3289 | Function *F = CI.getParent()->getParent(); | ||||
3290 | FunctionType *CallerTy = F->getFunctionType(); | ||||
3291 | FunctionType *CalleeTy = CI.getFunctionType(); | ||||
3292 | if (!CI.getCalledFunction() || !CI.getCalledFunction()->isIntrinsic()) { | ||||
3293 | Assert(CallerTy->getNumParams() == CalleeTy->getNumParams(),do { if (!(CallerTy->getNumParams() == CalleeTy->getNumParams ())) { CheckFailed("cannot guarantee tail call due to mismatched parameter counts" , &CI); return; } } while (false) | ||||
3294 | "cannot guarantee tail call due to mismatched parameter counts",do { if (!(CallerTy->getNumParams() == CalleeTy->getNumParams ())) { CheckFailed("cannot guarantee tail call due to mismatched parameter counts" , &CI); return; } } while (false) | ||||
3295 | &CI)do { if (!(CallerTy->getNumParams() == CalleeTy->getNumParams ())) { CheckFailed("cannot guarantee tail call due to mismatched parameter counts" , &CI); return; } } while (false); | ||||
3296 | for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) { | ||||
3297 | Assert(do { if (!(isTypeCongruent(CallerTy->getParamType(I), CalleeTy ->getParamType(I)))) { CheckFailed("cannot guarantee tail call due to mismatched parameter types" , &CI); return; } } while (false) | ||||
3298 | 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) | ||||
3299 | "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); | ||||
3300 | } | ||||
3301 | } | ||||
3302 | Assert(CallerTy->isVarArg() == CalleeTy->isVarArg(),do { if (!(CallerTy->isVarArg() == CalleeTy->isVarArg() )) { CheckFailed("cannot guarantee tail call due to mismatched varargs" , &CI); return; } } while (false) | ||||
3303 | "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); | ||||
3304 | Assert(isTypeCongruent(CallerTy->getReturnType(), CalleeTy->getReturnType()),do { if (!(isTypeCongruent(CallerTy->getReturnType(), CalleeTy ->getReturnType()))) { CheckFailed("cannot guarantee tail call due to mismatched return types" , &CI); return; } } while (false) | ||||
3305 | "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); | ||||
3306 | |||||
3307 | // - The calling conventions of the caller and callee must match. | ||||
3308 | Assert(F->getCallingConv() == CI.getCallingConv(),do { if (!(F->getCallingConv() == CI.getCallingConv())) { CheckFailed ("cannot guarantee tail call due to mismatched calling conv", &CI); return; } } while (false) | ||||
3309 | "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); | ||||
3310 | |||||
3311 | // - All ABI-impacting function attributes, such as sret, byval, inreg, | ||||
3312 | // returned, preallocated, and inalloca, must match. | ||||
3313 | AttributeList CallerAttrs = F->getAttributes(); | ||||
3314 | AttributeList CalleeAttrs = CI.getAttributes(); | ||||
3315 | for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) { | ||||
3316 | AttrBuilder CallerABIAttrs = getParameterABIAttributes(I, CallerAttrs); | ||||
3317 | AttrBuilder CalleeABIAttrs = getParameterABIAttributes(I, CalleeAttrs); | ||||
3318 | Assert(CallerABIAttrs == CalleeABIAttrs,do { if (!(CallerABIAttrs == CalleeABIAttrs)) { CheckFailed("cannot guarantee tail call due to mismatched ABI impacting " "function attributes", &CI, CI.getOperand(I)); return; } } while (false) | ||||
3319 | "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) | ||||
3320 | "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) | ||||
3321 | &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); | ||||
3322 | } | ||||
3323 | |||||
3324 | // - The call must immediately precede a :ref:`ret <i_ret>` instruction, | ||||
3325 | // or a pointer bitcast followed by a ret instruction. | ||||
3326 | // - The ret instruction must return the (possibly bitcasted) value | ||||
3327 | // produced by the call or void. | ||||
3328 | Value *RetVal = &CI; | ||||
3329 | Instruction *Next = CI.getNextNode(); | ||||
3330 | |||||
3331 | // Handle the optional bitcast. | ||||
3332 | if (BitCastInst *BI = dyn_cast_or_null<BitCastInst>(Next)) { | ||||
3333 | Assert(BI->getOperand(0) == RetVal,do { if (!(BI->getOperand(0) == RetVal)) { CheckFailed("bitcast following musttail call must use the call" , BI); return; } } while (false) | ||||
3334 | "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); | ||||
3335 | RetVal = BI; | ||||
3336 | Next = BI->getNextNode(); | ||||
3337 | } | ||||
3338 | |||||
3339 | // Check the return. | ||||
3340 | ReturnInst *Ret = dyn_cast_or_null<ReturnInst>(Next); | ||||
3341 | Assert(Ret, "musttail call must precede a ret with an optional bitcast",do { if (!(Ret)) { CheckFailed("musttail call must precede a ret with an optional bitcast" , &CI); return; } } while (false) | ||||
3342 | &CI)do { if (!(Ret)) { CheckFailed("musttail call must precede a ret with an optional bitcast" , &CI); return; } } while (false); | ||||
3343 | Assert(!Ret->getReturnValue() || Ret->getReturnValue() == RetVal,do { if (!(!Ret->getReturnValue() || Ret->getReturnValue () == RetVal)) { CheckFailed("musttail call result must be returned" , Ret); return; } } while (false) | ||||
3344 | "musttail call result must be returned", Ret)do { if (!(!Ret->getReturnValue() || Ret->getReturnValue () == RetVal)) { CheckFailed("musttail call result must be returned" , Ret); return; } } while (false); | ||||
3345 | } | ||||
3346 | |||||
3347 | void Verifier::visitCallInst(CallInst &CI) { | ||||
3348 | visitCallBase(CI); | ||||
3349 | |||||
3350 | if (CI.isMustTailCall()) | ||||
3351 | verifyMustTailCall(CI); | ||||
3352 | } | ||||
3353 | |||||
3354 | void Verifier::visitInvokeInst(InvokeInst &II) { | ||||
3355 | visitCallBase(II); | ||||
3356 | |||||
3357 | // Verify that the first non-PHI instruction of the unwind destination is an | ||||
3358 | // exception handling instruction. | ||||
3359 | Assert(do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!" , &II); return; } } while (false) | ||||
3360 | II.getUnwindDest()->isEHPad(),do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!" , &II); return; } } while (false) | ||||
3361 | "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) | ||||
3362 | &II)do { if (!(II.getUnwindDest()->isEHPad())) { CheckFailed("The unwind destination does not have an exception handling instruction!" , &II); return; } } while (false); | ||||
3363 | |||||
3364 | visitTerminator(II); | ||||
3365 | } | ||||
3366 | |||||
3367 | /// visitUnaryOperator - Check the argument to the unary operator. | ||||
3368 | /// | ||||
3369 | void Verifier::visitUnaryOperator(UnaryOperator &U) { | ||||
3370 | Assert(U.getType() == U.getOperand(0)->getType(),do { if (!(U.getType() == U.getOperand(0)->getType())) { CheckFailed ("Unary operators must have same type for" "operands and result!" , &U); return; } } while (false) | ||||
3371 | "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) | ||||
3372 | "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) | ||||
3373 | &U)do { if (!(U.getType() == U.getOperand(0)->getType())) { CheckFailed ("Unary operators must have same type for" "operands and result!" , &U); return; } } while (false); | ||||
3374 | |||||
3375 | switch (U.getOpcode()) { | ||||
3376 | // Check that floating-point arithmetic operators are only used with | ||||
3377 | // floating-point operands. | ||||
3378 | case Instruction::FNeg: | ||||
3379 | Assert(U.getType()->isFPOrFPVectorTy(),do { if (!(U.getType()->isFPOrFPVectorTy())) { CheckFailed ("FNeg operator only works with float types!", &U); return ; } } while (false) | ||||
3380 | "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); | ||||
3381 | break; | ||||
3382 | default: | ||||
3383 | llvm_unreachable("Unknown UnaryOperator opcode!")::llvm::llvm_unreachable_internal("Unknown UnaryOperator opcode!" , "/build/llvm-toolchain-snapshot-12~++20210124100612+2afaf072f5c1/llvm/lib/IR/Verifier.cpp" , 3383); | ||||
3384 | } | ||||
3385 | |||||
3386 | visitInstruction(U); | ||||
3387 | } | ||||
3388 | |||||
3389 | /// visitBinaryOperator - Check that both arguments to the binary operator are | ||||
3390 | /// of the same type! | ||||
3391 | /// | ||||
3392 | void Verifier::visitBinaryOperator(BinaryOperator &B) { | ||||
3393 | Assert(B.getOperand(0)->getType() == B.getOperand(1)->getType(),do { if (!(B.getOperand(0)->getType() == B.getOperand(1)-> getType())) { CheckFailed("Both operands to a binary operator are not of the same type!" , &B); return; } } while (false) | ||||
3394 | "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); | ||||
3395 | |||||
3396 | switch (B.getOpcode()) { | ||||
3397 | // Check that integer arithmetic operators are only used with | ||||
3398 | // integral operands. | ||||
3399 | case Instruction::Add: | ||||
3400 | case Instruction::Sub: | ||||
3401 | case Instruction::Mul: | ||||
3402 | case Instruction::SDiv: | ||||
3403 | case Instruction::UDiv: | ||||
3404 | case Instruction::SRem: | ||||
3405 | case Instruction::URem: | ||||
3406 | Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Integer arithmetic operators only work with integral types!" , &B); return; } } while (false) | ||||
3407 | "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); | ||||
3408 | Assert(B.getType() == B.getOperand(0)->getType(),do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Integer arithmetic operators must have same type " "for operands and result!" , &B); return; } } while (false) | ||||
3409 | "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) | ||||
3410 | "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) | ||||
3411 | &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); | ||||
3412 | break; | ||||
3413 | // Check that floating-point arithmetic operators are only used with | ||||
3414 | // floating-point operands. | ||||
3415 | case Instruction::FAdd: | ||||
3416 | case Instruction::FSub: | ||||
3417 | case Instruction::FMul: | ||||
3418 | case Instruction::FDiv: | ||||
3419 | case Instruction::FRem: | ||||
3420 | Assert(B.getType()->isFPOrFPVectorTy(),do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed ("Floating-point arithmetic operators only work with " "floating-point types!" , &B); return; } } while (false) | ||||
3421 | "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) | ||||
3422 | "floating-point types!",do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed ("Floating-point arithmetic operators only work with " "floating-point types!" , &B); return; } } while (false) | ||||
3423 | &B)do { if (!(B.getType()->isFPOrFPVectorTy())) { CheckFailed ("Floating-point arithmetic operators only work with " "floating-point types!" , &B); return; } } while (false); | ||||
3424 | Assert(B.getType() == B.getOperand(0)->getType(),do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Floating-point arithmetic operators must have same type " "for operands and result!" , &B); return; } } while (false) | ||||
3425 | "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) | ||||
3426 | "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) | ||||
3427 | &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); | ||||
3428 | break; | ||||
3429 | // Check that logical operators are only used with integral operands. | ||||
3430 | case Instruction::And: | ||||
3431 | case Instruction::Or: | ||||
3432 | case Instruction::Xor: | ||||
3433 | Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Logical operators only work with integral types!", &B); return; } } while (false) | ||||
3434 | "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); | ||||
3435 | Assert(B.getType() == B.getOperand(0)->getType(),do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Logical operators must have same type for operands and result!" , &B); return; } } while (false) | ||||
3436 | "Logical operators must have same type for operands and result!",do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Logical operators must have same type for operands and result!" , &B); return; } } while (false) | ||||
3437 | &B)do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Logical operators must have same type for operands and result!" , &B); return; } } while (false); | ||||
3438 | break; | ||||
3439 | case Instruction::Shl: | ||||
3440 | case Instruction::LShr: | ||||
3441 | case Instruction::AShr: | ||||
3442 | Assert(B.getType()->isIntOrIntVectorTy(),do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Shifts only work with integral types!", &B); return; } } while (false) | ||||
3443 | "Shifts only work with integral types!", &B)do { if (!(B.getType()->isIntOrIntVectorTy())) { CheckFailed ("Shifts only work with integral types!", &B); return; } } while (false); | ||||
3444 | Assert(B.getType() == B.getOperand(0)->getType(),do { if (!(B.getType() == B.getOperand(0)->getType())) { CheckFailed ("Shift return type must be same as operands!", &B); return ; } } while (false) | ||||
3445 | "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); | ||||
3446 | break; | ||||
3447 | default: | ||||
3448 | llvm_unreachable("Unknown BinaryOperator opcode!")::llvm::llvm_unreachable_internal("Unknown BinaryOperator opcode!" , "/build/llvm-toolchain-snapshot-12~++20210124100612+2afaf072f5c1/llvm/lib/IR/Verifier.cpp" , 3448); | ||||
3449 | } | ||||
3450 | |||||
3451 | visitInstruction(B); | ||||
3452 | } | ||||
3453 | |||||
3454 | void Verifier::visitICmpInst(ICmpInst &IC) { | ||||
3455 | // Check that the operands are the same type | ||||
3456 | Type *Op0Ty = IC.getOperand(0)->getType(); | ||||
3457 | Type *Op1Ty = IC.getOperand(1)->getType(); | ||||
3458 | Assert(Op0Ty == Op1Ty,do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to ICmp instruction are not of the same type!" , &IC); return; } } while (false) | ||||
3459 | "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); | ||||
3460 | // Check that the operands are the right type | ||||
3461 | Assert(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy(),do { if (!(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy ())) { CheckFailed("Invalid operand types for ICmp instruction" , &IC); return; } } while (false) | ||||
3462 | "Invalid operand types for ICmp instruction", &IC)do { if (!(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy ())) { CheckFailed("Invalid operand types for ICmp instruction" , &IC); return; } } while (false); | ||||
3463 | // Check that the predicate is valid. | ||||
3464 | Assert(IC.isIntPredicate(),do { if (!(IC.isIntPredicate())) { CheckFailed("Invalid predicate in ICmp instruction!" , &IC); return; } } while (false) | ||||
3465 | "Invalid predicate in ICmp instruction!", &IC)do { if (!(IC.isIntPredicate())) { CheckFailed("Invalid predicate in ICmp instruction!" , &IC); return; } } while (false); | ||||
3466 | |||||
3467 | visitInstruction(IC); | ||||
3468 | } | ||||
3469 | |||||
3470 | void Verifier::visitFCmpInst(FCmpInst &FC) { | ||||
3471 | // Check that the operands are the same type | ||||
3472 | Type *Op0Ty = FC.getOperand(0)->getType(); | ||||
3473 | Type *Op1Ty = FC.getOperand(1)->getType(); | ||||
3474 | Assert(Op0Ty == Op1Ty,do { if (!(Op0Ty == Op1Ty)) { CheckFailed("Both operands to FCmp instruction are not of the same type!" , &FC); return; } } while (false) | ||||
3475 | "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); | ||||
3476 | // Check that the operands are the right type | ||||
3477 | Assert(Op0Ty->isFPOrFPVectorTy(),do { if (!(Op0Ty->isFPOrFPVectorTy())) { CheckFailed("Invalid operand types for FCmp instruction" , &FC); return; } } while (false) | ||||
3478 | "Invalid operand types for FCmp instruction", &FC)do { if (!(Op0Ty->isFPOrFPVectorTy())) { CheckFailed("Invalid operand types for FCmp instruction" , &FC); return; } } while (false); | ||||
3479 | // Check that the predicate is valid. | ||||
3480 | Assert(FC.isFPPredicate(),do { if (!(FC.isFPPredicate())) { CheckFailed("Invalid predicate in FCmp instruction!" , &FC); return; } } while (false) | ||||
3481 | "Invalid predicate in FCmp instruction!", &FC)do { if (!(FC.isFPPredicate())) { CheckFailed("Invalid predicate in FCmp instruction!" , &FC); return; } } while (false); | ||||
3482 | |||||
3483 | visitInstruction(FC); | ||||
3484 | } | ||||
3485 | |||||
3486 | void Verifier::visitExtractElementInst(ExtractElementInst &EI) { | ||||
3487 | Assert(do { if (!(ExtractElementInst::isValidOperands(EI.getOperand( 0), EI.getOperand(1)))) { CheckFailed("Invalid extractelement operands!" , &EI); return; } } while (false) | ||||
3488 | 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) | ||||
3489 | "Invalid extractelement operands!", &EI)do { if (!(ExtractElementInst::isValidOperands(EI.getOperand( 0), EI.getOperand(1)))) { CheckFailed("Invalid extractelement operands!" , &EI); return; } } while (false); | ||||
3490 | visitInstruction(EI); | ||||
3491 | } | ||||
3492 | |||||
3493 | void Verifier::visitInsertElementInst(InsertElementInst &IE) { | ||||
3494 | Assert(InsertElementInst::isValidOperands(IE.getOperand(0), IE.getOperand(1),do { if (!(InsertElementInst::isValidOperands(IE.getOperand(0 ), IE.getOperand(1), IE.getOperand(2)))) { CheckFailed("Invalid insertelement operands!" , &IE); return; } } while (false) | ||||
3495 | IE.getOperand(2)),do { if (!(InsertElementInst::isValidOperands(IE.getOperand(0 ), IE.getOperand(1), IE.getOperand(2)))) { CheckFailed("Invalid insertelement operands!" , &IE); return; } } while (false) | ||||
3496 | "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); | ||||
3497 | visitInstruction(IE); | ||||
3498 | } | ||||
3499 | |||||
3500 | void Verifier::visitShuffleVectorInst(ShuffleVectorInst &SV) { | ||||
3501 | Assert(ShuffleVectorInst::isValidOperands(SV.getOperand(0), SV.getOperand(1),do { if (!(ShuffleVectorInst::isValidOperands(SV.getOperand(0 ), SV.getOperand(1), SV.getShuffleMask()))) { CheckFailed("Invalid shufflevector operands!" , &SV); return; } } while (false) | ||||
3502 | SV.getShuffleMask()),do { if (!(ShuffleVectorInst::isValidOperands(SV.getOperand(0 ), SV.getOperand(1), SV.getShuffleMask()))) { CheckFailed("Invalid shufflevector operands!" , &SV); return; } } while (false) | ||||
3503 | "Invalid shufflevector operands!", &SV)do { if (!(ShuffleVectorInst::isValidOperands(SV.getOperand(0 ), SV.getOperand(1), SV.getShuffleMask()))) { CheckFailed("Invalid shufflevector operands!" , &SV); return; } } while (false); | ||||
3504 | visitInstruction(SV); | ||||
3505 | } | ||||
3506 | |||||
3507 | void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) { | ||||
3508 | Type *TargetTy = GEP.getPointerOperandType()->getScalarType(); | ||||
3509 | |||||
3510 | Assert(isa<PointerType>(TargetTy),do { if (!(isa<PointerType>(TargetTy))) { CheckFailed("GEP base pointer is not a vector or a vector of pointers" , &GEP); return; } } while (false) | ||||
3511 | "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); | ||||
3512 | Assert(GEP.getSourceElementType()->isSized(), "GEP into unsized type!", &GEP)do { if (!(GEP.getSourceElementType()->isSized())) { CheckFailed ("GEP into unsized type!", &GEP); return; } } while (false ); | ||||
3513 | |||||
3514 | SmallVector<Value *, 16> Idxs(GEP.indices()); | ||||
3515 | Assert(all_of(do { if (!(all_of( Idxs, [](Value* V) { return V->getType( )->isIntOrIntVectorTy(); }))) { CheckFailed("GEP indexes must be integers" , &GEP); return; } } while (false) | ||||
3516 | 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) | ||||
3517 | "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); | ||||
3518 | Type *ElTy = | ||||
3519 | GetElementPtrInst::getIndexedType(GEP.getSourceElementType(), Idxs); | ||||
3520 | Assert(ElTy, "Invalid indices for GEP pointer type!", &GEP)do { if (!(ElTy)) { CheckFailed("Invalid indices for GEP pointer type!" , &GEP); return; } } while (false); | ||||
3521 | |||||
3522 | Assert(GEP.getType()->isPtrOrPtrVectorTy() &&do { if (!(GEP.getType()->isPtrOrPtrVectorTy() && GEP .getResultElementType() == ElTy)) { CheckFailed("GEP is not of right type for indices!" , &GEP, ElTy); return; } } while (false) | ||||
3523 | 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) | ||||
3524 | "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); | ||||
3525 | |||||
3526 | if (auto *GEPVTy = dyn_cast<VectorType>(GEP.getType())) { | ||||
3527 | // Additional checks for vector GEPs. | ||||
3528 | ElementCount GEPWidth = GEPVTy->getElementCount(); | ||||
3529 | if (GEP.getPointerOperandType()->isVectorTy()) | ||||
3530 | Assert(do { if (!(GEPWidth == cast<VectorType>(GEP.getPointerOperandType ())->getElementCount())) { CheckFailed("Vector GEP result width doesn't match operand's" , &GEP); return; } } while (false) | ||||
3531 | GEPWidth ==do { if (!(GEPWidth == cast<VectorType>(GEP.getPointerOperandType ())->getElementCount())) { CheckFailed("Vector GEP result width doesn't match operand's" , &GEP); return; } } while (false) | ||||
3532 | 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) | ||||
3533 | "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); | ||||
3534 | for (Value *Idx : Idxs) { | ||||
3535 | Type *IndexTy = Idx->getType(); | ||||
3536 | if (auto *IndexVTy = dyn_cast<VectorType>(IndexTy)) { | ||||
3537 | ElementCount IndexWidth = IndexVTy->getElementCount(); | ||||
3538 | Assert(IndexWidth == GEPWidth, "Invalid GEP index vector width", &GEP)do { if (!(IndexWidth == GEPWidth)) { CheckFailed("Invalid GEP index vector width" , &GEP); return; } } while (false); | ||||
3539 | } | ||||
3540 | Assert(IndexTy->isIntOrIntVectorTy(),do { if (!(IndexTy->isIntOrIntVectorTy())) { CheckFailed("All GEP indices should be of integer type" ); return; } } while (false) | ||||
3541 | "All GEP indices should be of integer type")do { if (!(IndexTy->isIntOrIntVectorTy())) { CheckFailed("All GEP indices should be of integer type" ); return; } } while (false); | ||||
3542 | } | ||||
3543 | } | ||||
3544 | |||||
3545 | if (auto *PTy = dyn_cast<PointerType>(GEP.getType())) { | ||||
3546 | Assert(GEP.getAddressSpace() == PTy->getAddressSpace(),do { if (!(GEP.getAddressSpace() == PTy->getAddressSpace() )) { CheckFailed("GEP address space doesn't match type", & GEP); return; } } while (false) | ||||
3547 | "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); | ||||
3548 | } | ||||
3549 | |||||
3550 | visitInstruction(GEP); | ||||
3551 | } | ||||
3552 | |||||
3553 | static bool isContiguous(const ConstantRange &A, const ConstantRange &B) { | ||||
3554 | return A.getUpper() == B.getLower() || A.getLower() == B.getUpper(); | ||||
3555 | } | ||||
3556 | |||||
3557 | void Verifier::visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty) { | ||||
3558 | assert(Range && Range == I.getMetadata(LLVMContext::MD_range) &&((Range && Range == I.getMetadata(LLVMContext::MD_range ) && "precondition violation") ? static_cast<void> (0) : __assert_fail ("Range && Range == I.getMetadata(LLVMContext::MD_range) && \"precondition violation\"" , "/build/llvm-toolchain-snapshot-12~++20210124100612+2afaf072f5c1/llvm/lib/IR/Verifier.cpp" , 3559, __PRETTY_FUNCTION__)) | ||||
3559 | "precondition violation")((Range && Range == I.getMetadata(LLVMContext::MD_range ) && "precondition violation") ? static_cast<void> (0) : __assert_fail ("Range && Range == I.getMetadata(LLVMContext::MD_range) && \"precondition violation\"" , "/build/llvm-toolchain-snapshot-12~++20210124100612+2afaf072f5c1/llvm/lib/IR/Verifier.cpp" , 3559, __PRETTY_FUNCTION__)); | ||||
3560 | |||||
3561 | unsigned NumOperands = Range->getNumOperands(); | ||||
3562 | Assert(NumOperands % 2 == 0, "Unfinished range!", Range)do { if (!(NumOperands % 2 == 0)) { CheckFailed("Unfinished range!" , Range); return; } } while (false); | ||||
3563 | unsigned NumRanges = NumOperands / 2; | ||||
3564 | Assert(NumRanges >= 1, "It should have at least one range!", Range)do { if (!(NumRanges >= 1)) { CheckFailed("It should have at least one range!" , Range); return; } } while (false); | ||||
3565 | |||||
3566 | ConstantRange LastRange(1, true); // Dummy initial value | ||||
3567 | for (unsigned i = 0; i < NumRanges; ++i) { | ||||
3568 | ConstantInt *Low = | ||||
3569 | mdconst::dyn_extract<ConstantInt>(Range->getOperand(2 * i)); | ||||
3570 | Assert(Low, "The lower limit must be an integer!", Low)do { if (!(Low)) { CheckFailed("The lower limit must be an integer!" , Low); return; } } while (false); | ||||
3571 | ConstantInt *High = | ||||
3572 | mdconst::dyn_extract<ConstantInt>(Range->getOperand(2 * i + 1)); | ||||
3573 | Assert(High, "The upper limit must be an integer!", High)do { if (!(High)) { CheckFailed("The upper limit must be an integer!" , High); return; } } while (false); | ||||
3574 | Assert(High->getType() == Low->getType() && High->getType() == Ty,do { if (!(High->getType() == Low->getType() && High->getType() == Ty)) { CheckFailed("Range types must match instruction type!" , &I); return; } } while (false) | ||||
3575 | "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); | ||||
3576 | |||||
3577 | APInt HighV = High->getValue(); | ||||
3578 | APInt LowV = Low->getValue(); | ||||
3579 | ConstantRange CurRange(LowV, HighV); | ||||
3580 | Assert(!CurRange.isEmptySet() && !CurRange.isFullSet(),do { if (!(!CurRange.isEmptySet() && !CurRange.isFullSet ())) { CheckFailed("Range must not be empty!", Range); return ; } } while (false) | ||||
3581 | "Range must not be empty!", Range)do { if (!(!CurRange.isEmptySet() && !CurRange.isFullSet ())) { CheckFailed("Range must not be empty!", Range); return ; } } while (false); | ||||
3582 | if (i != 0) { | ||||
3583 | Assert(CurRange.intersectWith(LastRange).isEmptySet(),do { if (!(CurRange.intersectWith(LastRange).isEmptySet())) { CheckFailed("Intervals are overlapping", Range); return; } } while (false) | ||||
3584 | "Intervals are overlapping", Range)do { if (!(CurRange.intersectWith(LastRange).isEmptySet())) { CheckFailed("Intervals are overlapping", Range); return; } } while (false); | ||||
3585 | Assert(LowV.sgt(LastRange.getLower()), "Intervals are not in order",do { if (!(LowV.sgt(LastRange.getLower()))) { CheckFailed("Intervals are not in order" , Range); return; } } while (false) | ||||
3586 | Range)do { if (!(LowV.sgt(LastRange.getLower()))) { CheckFailed("Intervals are not in order" , Range); return; } } while (false); | ||||
3587 | Assert(!isContiguous(CurRange, LastRange), "Intervals are contiguous",do { if (!(!isContiguous(CurRange, LastRange))) { CheckFailed ("Intervals are contiguous", Range); return; } } while (false ) | ||||
3588 | Range)do { if (!(!isContiguous(CurRange, LastRange))) { CheckFailed ("Intervals are contiguous", Range); return; } } while (false ); | ||||
3589 | } | ||||
3590 | LastRange = ConstantRange(LowV, HighV); | ||||
3591 | } | ||||
3592 | if (NumRanges > 2) { | ||||
3593 | APInt FirstLow = | ||||
3594 | mdconst::dyn_extract<ConstantInt>(Range->getOperand(0))->getValue(); | ||||
3595 | APInt FirstHigh = | ||||
3596 | mdconst::dyn_extract<ConstantInt>(Range->getOperand(1))->getValue(); | ||||
3597 | ConstantRange FirstRange(FirstLow, FirstHigh); | ||||
3598 | Assert(FirstRange.intersectWith(LastRange).isEmptySet(),do { if (!(FirstRange.intersectWith(LastRange).isEmptySet())) { CheckFailed("Intervals are overlapping", Range); return; } } while (false) | ||||
3599 | "Intervals are overlapping", Range)do { if (!(FirstRange.intersectWith(LastRange).isEmptySet())) { CheckFailed("Intervals are overlapping", Range); return; } } while (false); | ||||
3600 | Assert(!isContiguous(FirstRange, LastRange), "Intervals are contiguous",do { if (!(!isContiguous(FirstRange, LastRange))) { CheckFailed ("Intervals are contiguous", Range); return; } } while (false ) | ||||
3601 | Range)do { if (!(!isContiguous(FirstRange, LastRange))) { CheckFailed ("Intervals are contiguous", Range); return; } } while (false ); | ||||
3602 | } | ||||
3603 | } | ||||
3604 | |||||
3605 | void Verifier::checkAtomicMemAccessSize(Type *Ty, const Instruction *I) { | ||||
3606 | unsigned Size = DL.getTypeSizeInBits(Ty); | ||||
3607 | Assert(Size >= 8, "atomic memory access' size must be byte-sized", Ty, I)do { if (!(Size >= 8)) { CheckFailed("atomic memory access' size must be byte-sized" , Ty, I); return; } } while (false); | ||||
3608 | Assert(!(Size & (Size - 1)),do { if (!(!(Size & (Size - 1)))) { CheckFailed("atomic memory access' operand must have a power-of-two size" , Ty, I); return; } } while (false) | ||||
3609 | "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); | ||||
3610 | } | ||||
3611 | |||||
3612 | void Verifier::visitLoadInst(LoadInst &LI) { | ||||
3613 | PointerType *PTy = dyn_cast<PointerType>(LI.getOperand(0)->getType()); | ||||
3614 | Assert(PTy, "Load operand must be a pointer.", &LI)do { if (!(PTy)) { CheckFailed("Load operand must be a pointer." , &LI); return; } } while (false); | ||||
3615 | Type *ElTy = LI.getType(); | ||||
3616 | Assert(LI.getAlignment() <= Value::MaximumAlignment,do { if (!(LI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &LI ); return; } } while (false) | ||||
3617 | "huge alignment values are unsupported", &LI)do { if (!(LI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &LI ); return; } } while (false); | ||||
3618 | Assert(ElTy->isSized(), "loading unsized types is not allowed", &LI)do { if (!(ElTy->isSized())) { CheckFailed("loading unsized types is not allowed" , &LI); return; } } while (false); | ||||
3619 | if (LI.isAtomic()) { | ||||
3620 | Assert(LI.getOrdering() != AtomicOrdering::Release &&do { if (!(LI.getOrdering() != AtomicOrdering::Release && LI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed ("Load cannot have Release ordering", &LI); return; } } while (false) | ||||
3621 | LI.getOrdering() != AtomicOrdering::AcquireRelease,do { if (!(LI.getOrdering() != AtomicOrdering::Release && LI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed ("Load cannot have Release ordering", &LI); return; } } while (false) | ||||
3622 | "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); | ||||
3623 | Assert(LI.getAlignment() != 0,do { if (!(LI.getAlignment() != 0)) { CheckFailed("Atomic load must specify explicit alignment" , &LI); return; } } while (false) | ||||
3624 | "Atomic load must specify explicit alignment", &LI)do { if (!(LI.getAlignment() != 0)) { CheckFailed("Atomic load must specify explicit alignment" , &LI); return; } } while (false); | ||||
3625 | Assert(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy(),do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomic load operand must have integer, pointer, or floating point " "type!", ElTy, &LI); return; } } while (false) | ||||
3626 | "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) | ||||
3627 | "type!",do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomic load operand must have integer, pointer, or floating point " "type!", ElTy, &LI); return; } } while (false) | ||||
3628 | 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); | ||||
3629 | checkAtomicMemAccessSize(ElTy, &LI); | ||||
3630 | } else { | ||||
3631 | Assert(LI.getSyncScopeID() == SyncScope::System,do { if (!(LI.getSyncScopeID() == SyncScope::System)) { CheckFailed ("Non-atomic load cannot have SynchronizationScope specified" , &LI); return; } } while (false) | ||||
3632 | "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); | ||||
3633 | } | ||||
3634 | |||||
3635 | visitInstruction(LI); | ||||
3636 | } | ||||
3637 | |||||
3638 | void Verifier::visitStoreInst(StoreInst &SI) { | ||||
3639 | PointerType *PTy = dyn_cast<PointerType>(SI.getOperand(1)->getType()); | ||||
3640 | Assert(PTy, "Store operand must be a pointer.", &SI)do { if (!(PTy)) { CheckFailed("Store operand must be a pointer." , &SI); return; } } while (false); | ||||
3641 | Type *ElTy = PTy->getElementType(); | ||||
3642 | Assert(ElTy == SI.getOperand(0)->getType(),do { if (!(ElTy == SI.getOperand(0)->getType())) { CheckFailed ("Stored value type does not match pointer operand type!", & SI, ElTy); return; } } while (false) | ||||
3643 | "Stored value type does not match pointer operand type!", &SI, ElTy)do { if (!(ElTy == SI.getOperand(0)->getType())) { CheckFailed ("Stored value type does not match pointer operand type!", & SI, ElTy); return; } } while (false); | ||||
3644 | Assert(SI.getAlignment() <= Value::MaximumAlignment,do { if (!(SI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &SI ); return; } } while (false) | ||||
3645 | "huge alignment values are unsupported", &SI)do { if (!(SI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &SI ); return; } } while (false); | ||||
3646 | Assert(ElTy->isSized(), "storing unsized types is not allowed", &SI)do { if (!(ElTy->isSized())) { CheckFailed("storing unsized types is not allowed" , &SI); return; } } while (false); | ||||
3647 | if (SI.isAtomic()) { | ||||
3648 | Assert(SI.getOrdering() != AtomicOrdering::Acquire &&do { if (!(SI.getOrdering() != AtomicOrdering::Acquire && SI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed ("Store cannot have Acquire ordering", &SI); return; } } while (false) | ||||
3649 | SI.getOrdering() != AtomicOrdering::AcquireRelease,do { if (!(SI.getOrdering() != AtomicOrdering::Acquire && SI.getOrdering() != AtomicOrdering::AcquireRelease)) { CheckFailed ("Store cannot have Acquire ordering", &SI); return; } } while (false) | ||||
3650 | "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); | ||||
3651 | Assert(SI.getAlignment() != 0,do { if (!(SI.getAlignment() != 0)) { CheckFailed("Atomic store must specify explicit alignment" , &SI); return; } } while (false) | ||||
3652 | "Atomic store must specify explicit alignment", &SI)do { if (!(SI.getAlignment() != 0)) { CheckFailed("Atomic store must specify explicit alignment" , &SI); return; } } while (false); | ||||
3653 | Assert(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy(),do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomic store operand must have integer, pointer, or floating point " "type!", ElTy, &SI); return; } } while (false) | ||||
3654 | "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) | ||||
3655 | "type!",do { if (!(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomic store operand must have integer, pointer, or floating point " "type!", ElTy, &SI); return; } } while (false) | ||||
3656 | 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); | ||||
3657 | checkAtomicMemAccessSize(ElTy, &SI); | ||||
3658 | } else { | ||||
3659 | Assert(SI.getSyncScopeID() == SyncScope::System,do { if (!(SI.getSyncScopeID() == SyncScope::System)) { CheckFailed ("Non-atomic store cannot have SynchronizationScope specified" , &SI); return; } } while (false) | ||||
3660 | "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); | ||||
3661 | } | ||||
3662 | visitInstruction(SI); | ||||
3663 | } | ||||
3664 | |||||
3665 | /// Check that SwiftErrorVal is used as a swifterror argument in CS. | ||||
3666 | void Verifier::verifySwiftErrorCall(CallBase &Call, | ||||
3667 | const Value *SwiftErrorVal) { | ||||
3668 | unsigned Idx = 0; | ||||
3669 | for (auto I = Call.arg_begin(), E = Call.arg_end(); I != E; ++I, ++Idx) { | ||||
3670 | if (*I == SwiftErrorVal) { | ||||
3671 | Assert(Call.paramHasAttr(Idx, Attribute::SwiftError),do { if (!(Call.paramHasAttr(Idx, Attribute::SwiftError))) { CheckFailed ("swifterror value when used in a callsite should be marked " "with swifterror attribute", SwiftErrorVal, Call); return; } } while (false) | ||||
3672 | "swifterror value when used in a callsite should be marked "do { if (!(Call.paramHasAttr(Idx, Attribute::SwiftError))) { CheckFailed ("swifterror value when used in a callsite should be marked " "with swifterror attribute", SwiftErrorVal, Call); return; } } while (false) | ||||
3673 | "with swifterror attribute",do { if (!(Call.paramHasAttr(Idx, Attribute::SwiftError))) { CheckFailed ("swifterror value when used in a callsite should be marked " "with swifterror attribute", SwiftErrorVal, Call); return; } } while (false) | ||||
3674 | SwiftErrorVal, Call)do { if (!(Call.paramHasAttr(Idx, Attribute::SwiftError))) { CheckFailed ("swifterror value when used in a callsite should be marked " "with swifterror attribute", SwiftErrorVal, Call); return; } } while (false); | ||||
3675 | } | ||||
3676 | } | ||||
3677 | } | ||||
3678 | |||||
3679 | void Verifier::verifySwiftErrorValue(const Value *SwiftErrorVal) { | ||||
3680 | // Check that swifterror value is only used by loads, stores, or as | ||||
3681 | // a swifterror argument. | ||||
3682 | for (const User *U : SwiftErrorVal->users()) { | ||||
3683 | Assert(isa<LoadInst>(U) || isa<StoreInst>(U) || isa<CallInst>(U) ||do { if (!(isa<LoadInst>(U) || isa<StoreInst>(U) || isa<CallInst>(U) || isa<InvokeInst>(U))) { CheckFailed ("swifterror value can only be loaded and stored from, or " "as a swifterror argument!" , SwiftErrorVal, U); return; } } while (false) | ||||
3684 | 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) | ||||
3685 | "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) | ||||
3686 | "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) | ||||
3687 | 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); | ||||
3688 | // If it is used by a store, check it is the second operand. | ||||
3689 | if (auto StoreI = dyn_cast<StoreInst>(U)) | ||||
3690 | Assert(StoreI->getOperand(1) == SwiftErrorVal,do { if (!(StoreI->getOperand(1) == SwiftErrorVal)) { CheckFailed ("swifterror value should be the second operand when used " "by stores" , SwiftErrorVal, U); return; } } while (false) | ||||
3691 | "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) | ||||
3692 | "by stores", SwiftErrorVal, U)do { if (!(StoreI->getOperand(1) == SwiftErrorVal)) { CheckFailed ("swifterror value should be the second operand when used " "by stores" , SwiftErrorVal, U); return; } } while (false); | ||||
3693 | if (auto *Call = dyn_cast<CallBase>(U)) | ||||
3694 | verifySwiftErrorCall(*const_cast<CallBase *>(Call), SwiftErrorVal); | ||||
3695 | } | ||||
3696 | } | ||||
3697 | |||||
3698 | void Verifier::visitAllocaInst(AllocaInst &AI) { | ||||
3699 | SmallPtrSet<Type*, 4> Visited; | ||||
3700 | PointerType *PTy = AI.getType(); | ||||
3701 | // TODO: Relax this restriction? | ||||
3702 | Assert(PTy->getAddressSpace() == DL.getAllocaAddrSpace(),do { if (!(PTy->getAddressSpace() == DL.getAllocaAddrSpace ())) { CheckFailed("Allocation instruction pointer not in the stack address space!" , &AI); return; } } while (false) | ||||
3703 | "Allocation instruction pointer not in the stack address space!",do { if (!(PTy->getAddressSpace() == DL.getAllocaAddrSpace ())) { CheckFailed("Allocation instruction pointer not in the stack address space!" , &AI); return; } } while (false) | ||||
3704 | &AI)do { if (!(PTy->getAddressSpace() == DL.getAllocaAddrSpace ())) { CheckFailed("Allocation instruction pointer not in the stack address space!" , &AI); return; } } while (false); | ||||
3705 | Assert(AI.getAllocatedType()->isSized(&Visited),do { if (!(AI.getAllocatedType()->isSized(&Visited))) { CheckFailed("Cannot allocate unsized type", &AI); return ; } } while (false) | ||||
3706 | "Cannot allocate unsized type", &AI)do { if (!(AI.getAllocatedType()->isSized(&Visited))) { CheckFailed("Cannot allocate unsized type", &AI); return ; } } while (false); | ||||
3707 | Assert(AI.getArraySize()->getType()->isIntegerTy(),do { if (!(AI.getArraySize()->getType()->isIntegerTy()) ) { CheckFailed("Alloca array size must have integer type", & AI); return; } } while (false) | ||||
3708 | "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); | ||||
3709 | Assert(AI.getAlignment() <= Value::MaximumAlignment,do { if (!(AI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &AI ); return; } } while (false) | ||||
3710 | "huge alignment values are unsupported", &AI)do { if (!(AI.getAlignment() <= Value::MaximumAlignment)) { CheckFailed("huge alignment values are unsupported", &AI ); return; } } while (false); | ||||
3711 | |||||
3712 | if (AI.isSwiftError()) { | ||||
3713 | verifySwiftErrorValue(&AI); | ||||
3714 | } | ||||
3715 | |||||
3716 | visitInstruction(AI); | ||||
3717 | } | ||||
3718 | |||||
3719 | void Verifier::visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI) { | ||||
3720 | |||||
3721 | // FIXME: more conditions??? | ||||
3722 | Assert(CXI.getSuccessOrdering() != AtomicOrdering::NotAtomic,do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::NotAtomic )) { CheckFailed("cmpxchg instructions must be atomic.", & CXI); return; } } while (false) | ||||
3723 | "cmpxchg instructions must be atomic.", &CXI)do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::NotAtomic )) { CheckFailed("cmpxchg instructions must be atomic.", & CXI); return; } } while (false); | ||||
3724 | Assert(CXI.getFailureOrdering() != AtomicOrdering::NotAtomic,do { if (!(CXI.getFailureOrdering() != AtomicOrdering::NotAtomic )) { CheckFailed("cmpxchg instructions must be atomic.", & CXI); return; } } while (false) | ||||
3725 | "cmpxchg instructions must be atomic.", &CXI)do { if (!(CXI.getFailureOrdering() != AtomicOrdering::NotAtomic )) { CheckFailed("cmpxchg instructions must be atomic.", & CXI); return; } } while (false); | ||||
3726 | Assert(CXI.getSuccessOrdering() != AtomicOrdering::Unordered,do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::Unordered )) { CheckFailed("cmpxchg instructions cannot be unordered.", &CXI); return; } } while (false) | ||||
3727 | "cmpxchg instructions cannot be unordered.", &CXI)do { if (!(CXI.getSuccessOrdering() != AtomicOrdering::Unordered )) { CheckFailed("cmpxchg instructions cannot be unordered.", &CXI); return; } } while (false); | ||||
3728 | Assert(CXI.getFailureOrdering() != AtomicOrdering::Unordered,do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Unordered )) { CheckFailed("cmpxchg instructions cannot be unordered.", &CXI); return; } } while (false) | ||||
3729 | "cmpxchg instructions cannot be unordered.", &CXI)do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Unordered )) { CheckFailed("cmpxchg instructions cannot be unordered.", &CXI); return; } } while (false); | ||||
3730 | Assert(!isStrongerThan(CXI.getFailureOrdering(), CXI.getSuccessOrdering()),do { if (!(!isStrongerThan(CXI.getFailureOrdering(), CXI.getSuccessOrdering ()))) { CheckFailed("cmpxchg instructions failure argument shall be no stronger than the " "success argument", &CXI); return; } } while (false) | ||||
3731 | "cmpxchg instructions failure argument shall be no stronger than the "do { if (!(!isStrongerThan(CXI.getFailureOrdering(), CXI.getSuccessOrdering ()))) { CheckFailed("cmpxchg instructions failure argument shall be no stronger than the " "success argument", &CXI); return; } } while (false) | ||||
3732 | "success argument",do { if (!(!isStrongerThan(CXI.getFailureOrdering(), CXI.getSuccessOrdering ()))) { CheckFailed("cmpxchg instructions failure argument shall be no stronger than the " "success argument", &CXI); return; } } while (false) | ||||
3733 | &CXI)do { if (!(!isStrongerThan(CXI.getFailureOrdering(), CXI.getSuccessOrdering ()))) { CheckFailed("cmpxchg instructions failure argument shall be no stronger than the " "success argument", &CXI); return; } } while (false); | ||||
3734 | Assert(CXI.getFailureOrdering() != AtomicOrdering::Release &&do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Release && CXI.getFailureOrdering() != AtomicOrdering::AcquireRelease )) { CheckFailed("cmpxchg failure ordering cannot include release semantics" , &CXI); return; } } while (false) | ||||
3735 | CXI.getFailureOrdering() != AtomicOrdering::AcquireRelease,do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Release && CXI.getFailureOrdering() != AtomicOrdering::AcquireRelease )) { CheckFailed("cmpxchg failure ordering cannot include release semantics" , &CXI); return; } } while (false) | ||||
3736 | "cmpxchg failure ordering cannot include release semantics", &CXI)do { if (!(CXI.getFailureOrdering() != AtomicOrdering::Release && CXI.getFailureOrdering() != AtomicOrdering::AcquireRelease )) { CheckFailed("cmpxchg failure ordering cannot include release semantics" , &CXI); return; } } while (false); | ||||
3737 | |||||
3738 | PointerType *PTy = dyn_cast<PointerType>(CXI.getOperand(0)->getType()); | ||||
3739 | Assert(PTy, "First cmpxchg operand must be a pointer.", &CXI)do { if (!(PTy)) { CheckFailed("First cmpxchg operand must be a pointer." , &CXI); return; } } while (false); | ||||
3740 | Type *ElTy = PTy->getElementType(); | ||||
3741 | Assert(ElTy->isIntOrPtrTy(),do { if (!(ElTy->isIntOrPtrTy())) { CheckFailed("cmpxchg operand must have integer or pointer type" , ElTy, &CXI); return; } } while (false) | ||||
3742 | "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); | ||||
3743 | checkAtomicMemAccessSize(ElTy, &CXI); | ||||
3744 | Assert(ElTy == CXI.getOperand(1)->getType(),do { if (!(ElTy == CXI.getOperand(1)->getType())) { CheckFailed ("Expected value type does not match pointer operand type!", & CXI, ElTy); return; } } while (false) | ||||
3745 | "Expected value type does not match pointer operand type!", &CXI,do { if (!(ElTy == CXI.getOperand(1)->getType())) { CheckFailed ("Expected value type does not match pointer operand type!", & CXI, ElTy); return; } } while (false) | ||||
3746 | ElTy)do { if (!(ElTy == CXI.getOperand(1)->getType())) { CheckFailed ("Expected value type does not match pointer operand type!", & CXI, ElTy); return; } } while (false); | ||||
3747 | Assert(ElTy == CXI.getOperand(2)->getType(),do { if (!(ElTy == CXI.getOperand(2)->getType())) { CheckFailed ("Stored value type does not match pointer operand type!", & CXI, ElTy); return; } } while (false) | ||||
3748 | "Stored value type does not match pointer operand type!", &CXI, ElTy)do { if (!(ElTy == CXI.getOperand(2)->getType())) { CheckFailed ("Stored value type does not match pointer operand type!", & CXI, ElTy); return; } } while (false); | ||||
3749 | visitInstruction(CXI); | ||||
3750 | } | ||||
3751 | |||||
3752 | void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) { | ||||
3753 | Assert(RMWI.getOrdering() != AtomicOrdering::NotAtomic,do { if (!(RMWI.getOrdering() != AtomicOrdering::NotAtomic)) { CheckFailed("atomicrmw instructions must be atomic.", &RMWI ); return; } } while (false) | ||||
3754 | "atomicrmw instructions must be atomic.", &RMWI)do { if (!(RMWI.getOrdering() != AtomicOrdering::NotAtomic)) { CheckFailed("atomicrmw instructions must be atomic.", &RMWI ); return; } } while (false); | ||||
3755 | Assert(RMWI.getOrdering() != AtomicOrdering::Unordered,do { if (!(RMWI.getOrdering() != AtomicOrdering::Unordered)) { CheckFailed("atomicrmw instructions cannot be unordered.", & RMWI); return; } } while (false) | ||||
3756 | "atomicrmw instructions cannot be unordered.", &RMWI)do { if (!(RMWI.getOrdering() != AtomicOrdering::Unordered)) { CheckFailed("atomicrmw instructions cannot be unordered.", & RMWI); return; } } while (false); | ||||
3757 | auto Op = RMWI.getOperation(); | ||||
3758 | PointerType *PTy = dyn_cast<PointerType>(RMWI.getOperand(0)->getType()); | ||||
3759 | Assert(PTy, "First atomicrmw operand must be a pointer.", &RMWI)do { if (!(PTy)) { CheckFailed("First atomicrmw operand must be a pointer." , &RMWI); return; } } while (false); | ||||
3760 | Type *ElTy = PTy->getElementType(); | ||||
3761 | if (Op == AtomicRMWInst::Xchg) { | ||||
3762 | Assert(ElTy->isIntegerTy() || ElTy->isFloatingPointTy(), "atomicrmw " +do { if (!(ElTy->isIntegerTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName (Op) + " operand must have integer or floating point type!", & RMWI, ElTy); return; } } while (false) | ||||
3763 | AtomicRMWInst::getOperationName(Op) +do { if (!(ElTy->isIntegerTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName (Op) + " operand must have integer or floating point type!", & RMWI, ElTy); return; } } while (false) | ||||
3764 | " operand must have integer or floating point type!",do { if (!(ElTy->isIntegerTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName (Op) + " operand must have integer or floating point type!", & RMWI, ElTy); return; } } while (false) | ||||
3765 | &RMWI, ElTy)do { if (!(ElTy->isIntegerTy() || ElTy->isFloatingPointTy ())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName (Op) + " operand must have integer or floating point type!", & RMWI, ElTy); return; } } while (false); | ||||
3766 | } else if (AtomicRMWInst::isFPOperation(Op)) { | ||||
3767 | Assert(ElTy->isFloatingPointTy(), "atomicrmw " +do { if (!(ElTy->isFloatingPointTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have floating point type!" , &RMWI, ElTy); return; } } while (false) | ||||
3768 | AtomicRMWInst::getOperationName(Op) +do { if (!(ElTy->isFloatingPointTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have floating point type!" , &RMWI, ElTy); return; } } while (false) | ||||
3769 | " 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) | ||||
3770 | &RMWI, ElTy)do { if (!(ElTy->isFloatingPointTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have floating point type!" , &RMWI, ElTy); return; } } while (false); | ||||
3771 | } else { | ||||
3772 | Assert(ElTy->isIntegerTy(), "atomicrmw " +do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have integer type!" , &RMWI, ElTy); return; } } while (false) | ||||
3773 | AtomicRMWInst::getOperationName(Op) +do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have integer type!" , &RMWI, ElTy); return; } } while (false) | ||||
3774 | " operand must have integer type!",do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have integer type!" , &RMWI, ElTy); return; } } while (false) | ||||
3775 | &RMWI, ElTy)do { if (!(ElTy->isIntegerTy())) { CheckFailed("atomicrmw " + AtomicRMWInst::getOperationName(Op) + " operand must have integer type!" , &RMWI, ElTy); return; } } while (false); | ||||
3776 | } | ||||
3777 | checkAtomicMemAccessSize(ElTy, &RMWI); | ||||
3778 | Assert(ElTy == RMWI.getOperand(1)->getType(),do { if (!(ElTy == RMWI.getOperand(1)->getType())) { CheckFailed ("Argument value type does not match pointer operand type!", & RMWI, ElTy); return; } } while (false) | ||||
3779 | "Argument value type does not match pointer operand type!", &RMWI,do { if (!(ElTy == RMWI.getOperand(1)->getType())) { CheckFailed ("Argument value type does not match pointer operand type!", & RMWI, ElTy); return; } } while (false) | ||||
3780 | ElTy)do { if (!(ElTy == RMWI.getOperand(1)->getType())) { CheckFailed ("Argument value type does not match pointer operand type!", & RMWI, ElTy); return; } } while (false); | ||||
3781 | Assert(AtomicRMWInst::FIRST_BINOP <= Op && Op <= AtomicRMWInst::LAST_BINOP,do { if (!(AtomicRMWInst::FIRST_BINOP <= Op && Op <= AtomicRMWInst::LAST_BINOP)) { CheckFailed("Invalid binary operation!" , &RMWI); return; } } while (false) | ||||
3782 | "Invalid binary operation!", &RMWI)do { if (!(AtomicRMWInst::FIRST_BINOP <= Op && Op <= AtomicRMWInst::LAST_BINOP)) { CheckFailed("Invalid binary operation!" , &RMWI); return; } } while (false); | ||||
3783 | visitInstruction(RMWI); | ||||
3784 | } | ||||
3785 | |||||
3786 | void Verifier::visitFenceInst(FenceInst &FI) { | ||||
3787 | const AtomicOrdering Ordering = FI.getOrdering(); | ||||
3788 | Assert(Ordering == AtomicOrdering::Acquire ||do { if (!(Ordering == AtomicOrdering::Acquire || Ordering == AtomicOrdering::Release || Ordering == AtomicOrdering::AcquireRelease || Ordering == AtomicOrdering::SequentiallyConsistent)) { CheckFailed ("fence instructions may only have acquire, release, acq_rel, or " "seq_cst ordering.", &FI); return; } } while (false) | ||||
3789 | 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) | ||||
3790 | 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) | ||||
3791 | 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) | ||||
3792 | "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) | ||||
3793 | "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) | ||||
3794 | &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); | ||||
3795 | visitInstruction(FI); | ||||
3796 | } | ||||
3797 | |||||
3798 | void Verifier::visitExtractValueInst(ExtractValueInst &EVI) { | ||||
3799 | Assert(ExtractValueInst::getIndexedType(EVI.getAggregateOperand()->getType(),do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand ()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed ("Invalid ExtractValueInst operands!", &EVI); return; } } while (false) | ||||
3800 | EVI.getIndices()) == EVI.getType(),do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand ()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed ("Invalid ExtractValueInst operands!", &EVI); return; } } while (false) | ||||
3801 | "Invalid ExtractValueInst operands!", &EVI)do { if (!(ExtractValueInst::getIndexedType(EVI.getAggregateOperand ()->getType(), EVI.getIndices()) == EVI.getType())) { CheckFailed ("Invalid ExtractValueInst operands!", &EVI); return; } } while (false); | ||||
3802 | |||||
3803 | visitInstruction(EVI); | ||||
3804 | } | ||||
3805 | |||||
3806 | void Verifier::visitInsertValueInst(InsertValueInst &IVI) { | ||||
3807 | Assert(ExtractValueInst::getIndexedType(IVI.getAggregateOperand()->getType(),do { if (!(ExtractValueInst::getIndexedType(IVI.getAggregateOperand ()->getType(), IVI.getIndices()) == IVI.getOperand(1)-> getType())) { CheckFailed("Invalid InsertValueInst operands!" , &IVI); return; } } while (false) | ||||
3808 | IVI.getIndices()) ==do { if (!(ExtractValueInst::getIndexedType(IVI.getAggregateOperand ()->getType(), IVI.getIndices()) == IVI.getOperand(1)-> getType())) { CheckFailed("Invalid InsertValueInst operands!" , &IVI); return; } } while (false) | ||||
3809 | 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) | ||||
3810 | "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); | ||||
3811 | |||||
3812 | visitInstruction(IVI); | ||||
3813 | } | ||||
3814 | |||||
3815 | static Value *getParentPad(Value *EHPad) { | ||||
3816 | if (auto *FPI = dyn_cast<FuncletPadInst>(EHPad)) | ||||
3817 | return FPI->getParentPad(); | ||||
3818 | |||||
3819 | return cast<CatchSwitchInst>(EHPad)->getParentPad(); | ||||
3820 | } | ||||
3821 | |||||
3822 | void Verifier::visitEHPadPredecessors(Instruction &I) { | ||||
3823 | assert(I.isEHPad())((I.isEHPad()) ? static_cast<void> (0) : __assert_fail ( "I.isEHPad()", "/build/llvm-toolchain-snapshot-12~++20210124100612+2afaf072f5c1/llvm/lib/IR/Verifier.cpp" , 3823, __PRETTY_FUNCTION__)); | ||||
3824 | |||||
3825 | BasicBlock *BB = I.getParent(); | ||||
3826 | Function *F = BB->getParent(); | ||||
3827 | |||||
3828 | Assert(BB != &F->getEntryBlock(), "EH pad cannot be in entry block.", &I)do { if (!(BB != &F->getEntryBlock())) { CheckFailed("EH pad cannot be in entry block." , &I); return; } } while (false); | ||||
3829 | |||||
3830 | if (auto *LPI = dyn_cast<LandingPadInst>(&I)) { | ||||
3831 | // The landingpad instruction defines its parent as a landing pad block. The | ||||
3832 | // landing pad block may be branched to only by the unwind edge of an | ||||
3833 | // invoke. | ||||
3834 | for (BasicBlock *PredBB : predecessors(BB)) { | ||||
3835 | const auto *II = dyn_cast<InvokeInst>(PredBB->getTerminator()); | ||||
3836 | Assert(II && II->getUnwindDest() == BB && II->getNormalDest() != BB,do { if (!(II && II->getUnwindDest() == BB && II->getNormalDest() != BB)) { CheckFailed("Block containing LandingPadInst must be jumped to " "only by the unwind edge of an invoke.", LPI); return; } } while (false) | ||||
3837 | "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) | ||||
3838 | "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) | ||||
3839 | 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); | ||||
3840 | } | ||||
3841 | return; | ||||
3842 | } | ||||
3843 | if (auto *CPI = dyn_cast<CatchPadInst>(&I)) { | ||||
3844 | if (!pred_empty(BB)) | ||||
3845 | Assert(BB->getUniquePredecessor() == CPI->getCatchSwitch()->getParent(),do { if (!(BB->getUniquePredecessor() == CPI->getCatchSwitch ()->getParent())) { CheckFailed("Block containg CatchPadInst must be jumped to " "only by its catchswitch.", CPI); return; } } while (false) | ||||
3846 | "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) | ||||
3847 | "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) | ||||
3848 | CPI)do { if (!(BB->getUniquePredecessor() == CPI->getCatchSwitch ()->getParent())) { CheckFailed("Block containg CatchPadInst must be jumped to " "only by its catchswitch.", CPI); return; } } while (false); | ||||
3849 | Assert(BB != CPI->getCatchSwitch()->getUnwindDest(),do { if (!(BB != CPI->getCatchSwitch()->getUnwindDest() )) { CheckFailed("Catchswitch cannot unwind to one of its catchpads" , CPI->getCatchSwitch(), CPI); return; } } while (false) | ||||
3850 | "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) | ||||
3851 | CPI->getCatchSwitch(), CPI)do { if (!(BB != CPI->getCatchSwitch()->getUnwindDest() )) { CheckFailed("Catchswitch cannot unwind to one of its catchpads" , CPI->getCatchSwitch(), CPI); return; } } while (false); | ||||
3852 | return; | ||||
3853 | } | ||||
3854 | |||||
3855 | // Verify that each pred has a legal terminator with a legal to/from EH | ||||
3856 | // pad relationship. | ||||
3857 | Instruction *ToPad = &I; | ||||
3858 | Value *ToPadParent = getParentPad(ToPad); | ||||
3859 | for (BasicBlock *PredBB : predecessors(BB)) { | ||||
3860 | Instruction *TI = PredBB->getTerminator(); | ||||
3861 | Value *FromPad; | ||||
3862 | if (auto *II = dyn_cast<InvokeInst>(TI)) { | ||||
3863 | Assert(II->getUnwindDest() == BB && II->getNormalDest() != BB,do { if (!(II->getUnwindDest() == BB && II->getNormalDest () != BB)) { CheckFailed("EH pad must be jumped to via an unwind edge" , ToPad, II); return; } } while (false) | ||||
3864 | "EH pad must be jumped to via an unwind edge", ToPad, II)do { if (!(II->getUnwindDest() == BB && II->getNormalDest () != BB)) { CheckFailed("EH pad must be jumped to via an unwind edge" , ToPad, II); return; } } while (false); | ||||
3865 | if (auto Bundle = II->getOperandBundle(LLVMContext::OB_funclet)) | ||||
3866 | FromPad = Bundle->Inputs[0]; | ||||
3867 | else | ||||
3868 | FromPad = ConstantTokenNone::get(II->getContext()); | ||||
3869 | } else if (auto *CRI = dyn_cast<CleanupReturnInst>(TI)) { | ||||
3870 | FromPad = CRI->getOperand(0); | ||||
3871 | Assert(FromPad != ToPadParent, "A cleanupret must exit its cleanup", CRI)do { if (!(FromPad != ToPadParent)) { CheckFailed("A cleanupret must exit its cleanup" , CRI); return; } } while (false); | ||||
3872 | } else if (auto *CSI = dyn_cast<CatchSwitchInst>(TI)) { | ||||
3873 | FromPad = CSI; | ||||
3874 | } else { | ||||
3875 | Assert(false, "EH pad must be jumped to via an unwind edge", ToPad, TI)do { if (!(false)) { CheckFailed("EH pad must be jumped to via an unwind edge" , ToPad, TI); return; } } while (false); | ||||
3876 | } | ||||
3877 | |||||
3878 | // The edge may exit from zero or more nested pads. | ||||
3879 | SmallSet<Value *, 8> Seen; | ||||
3880 | for (;; FromPad = getParentPad(FromPad)) { | ||||
3881 | Assert(FromPad != ToPad,do { if (!(FromPad != ToPad)) { CheckFailed("EH pad cannot handle exceptions raised within it" , FromPad, TI); return; } } while (false) | ||||
3882 | "EH pad cannot handle exceptions raised within it", FromPad, TI)do { if (!(FromPad != ToPad)) { CheckFailed("EH pad cannot handle exceptions raised within it" , FromPad, TI); return; } } while (false); | ||||
3883 | if (FromPad == ToPadParent) { | ||||
3884 | // This is a legal unwind edge. | ||||
3885 | break; | ||||
3886 | } | ||||
3887 | Assert(!isa<ConstantTokenNone>(FromPad),do { if (!(!isa<ConstantTokenNone>(FromPad))) { CheckFailed ("A single unwind edge may only enter one EH pad", TI); return ; } } while (false) | ||||
3888 | "A single unwind edge may only enter one EH pad", TI)do { if (!(!isa<ConstantTokenNone>(FromPad))) { CheckFailed ("A single unwind edge may only enter one EH pad", TI); return ; } } while (false); | ||||
3889 | Assert(Seen.insert(FromPad).second,do { if (!(Seen.insert(FromPad).second)) { CheckFailed("EH pad jumps through a cycle of pads" , FromPad); return; } } while (false) | ||||
3890 | "EH pad jumps through a cycle of pads", FromPad)do { if (!(Seen.insert(FromPad).second)) { CheckFailed("EH pad jumps through a cycle of pads" , FromPad); return; } } while (false); | ||||
3891 | } | ||||
3892 | } | ||||
3893 | } | ||||
3894 | |||||
3895 | void Verifier::visitLandingPadInst(LandingPadInst &LPI) { | ||||
3896 | // The landingpad instruction is ill-formed if it doesn't have any clauses and | ||||
3897 | // isn't a cleanup. | ||||
3898 | Assert(LPI.getNumClauses() > 0 || LPI.isCleanup(),do { if (!(LPI.getNumClauses() > 0 || LPI.isCleanup())) { CheckFailed ("LandingPadInst needs at least one clause or to be a cleanup." , &LPI); return; } } while (false) | ||||
3899 | "LandingPadInst needs at least one clause or to be a cleanup.", &LPI)do { if (!(LPI.getNumClauses() > 0 || LPI.isCleanup())) { CheckFailed ("LandingPadInst needs at least one clause or to be a cleanup." , &LPI); return; } } while (false); | ||||
3900 | |||||
3901 | visitEHPadPredecessors(LPI); | ||||
3902 | |||||
3903 | if (!LandingPadResultTy) | ||||
3904 | LandingPadResultTy = LPI.getType(); | ||||
3905 | else | ||||
3906 | Assert(LandingPadResultTy == LPI.getType(),do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed ("The landingpad instruction should have a consistent result type " "inside a function.", &LPI); return; } } while (false) | ||||
3907 | "The landingpad instruction should have a consistent result type "do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed ("The landingpad instruction should have a consistent result type " "inside a function.", &LPI); return; } } while (false) | ||||
3908 | "inside a function.",do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed ("The landingpad instruction should have a consistent result type " "inside a function.", &LPI); return; } } while (false) | ||||
3909 | &LPI)do { if (!(LandingPadResultTy == LPI.getType())) { CheckFailed ("The landingpad instruction should have a consistent result type " "inside a function.", &LPI); return; } } while (false); | ||||
3910 | |||||
3911 | Function *F = LPI.getParent()->getParent(); | ||||
3912 | Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("LandingPadInst needs to be in a function with a personality." , &LPI); return; } } while (false) | ||||
3913 | "LandingPadInst needs to be in a function with a personality.", &LPI)do { if (!(F->hasPersonalityFn())) { CheckFailed("LandingPadInst needs to be in a function with a personality." , &LPI); return; } } while (false); | ||||
3914 | |||||
3915 | // The landingpad instruction must be the first non-PHI instruction in the | ||||
3916 | // block. | ||||
3917 | Assert(LPI.getParent()->getLandingPadInst() == &LPI,do { if (!(LPI.getParent()->getLandingPadInst() == &LPI )) { CheckFailed("LandingPadInst not the first non-PHI instruction in the block." , &LPI); return; } } while (false) | ||||
3918 | "LandingPadInst not the first non-PHI instruction in the block.",do { if (!(LPI.getParent()->getLandingPadInst() == &LPI )) { CheckFailed("LandingPadInst not the first non-PHI instruction in the block." , &LPI); return; } } while (false) | ||||
3919 | &LPI)do { if (!(LPI.getParent()->getLandingPadInst() == &LPI )) { CheckFailed("LandingPadInst not the first non-PHI instruction in the block." , &LPI); return; } } while (false); | ||||
3920 | |||||
3921 | for (unsigned i = 0, e = LPI.getNumClauses(); i < e; ++i) { | ||||
3922 | Constant *Clause = LPI.getClause(i); | ||||
3923 | if (LPI.isCatch(i)) { | ||||
3924 | Assert(isa<PointerType>(Clause->getType()),do { if (!(isa<PointerType>(Clause->getType()))) { CheckFailed ("Catch operand does not have pointer type!", &LPI); return ; } } while (false) | ||||
3925 | "Catch operand does not have pointer type!", &LPI)do { if (!(isa<PointerType>(Clause->getType()))) { CheckFailed ("Catch operand does not have pointer type!", &LPI); return ; } } while (false); | ||||
3926 | } else { | ||||
3927 | Assert(LPI.isFilter(i), "Clause is neither catch nor filter!", &LPI)do { if (!(LPI.isFilter(i))) { CheckFailed("Clause is neither catch nor filter!" , &LPI); return; } } while (false); | ||||
3928 | Assert(isa<ConstantArray>(Clause) || isa<ConstantAggregateZero>(Clause),do { if (!(isa<ConstantArray>(Clause) || isa<ConstantAggregateZero >(Clause))) { CheckFailed("Filter operand is not an array of constants!" , &LPI); return; } } while (false) | ||||
3929 | "Filter operand is not an array of constants!", &LPI)do { if (!(isa<ConstantArray>(Clause) || isa<ConstantAggregateZero >(Clause))) { CheckFailed("Filter operand is not an array of constants!" , &LPI); return; } } while (false); | ||||
3930 | } | ||||
3931 | } | ||||
3932 | |||||
3933 | visitInstruction(LPI); | ||||
3934 | } | ||||
3935 | |||||
3936 | void Verifier::visitResumeInst(ResumeInst &RI) { | ||||
3937 | Assert(RI.getFunction()->hasPersonalityFn(),do { if (!(RI.getFunction()->hasPersonalityFn())) { CheckFailed ("ResumeInst needs to be in a function with a personality.", & RI); return; } } while (false) | ||||
3938 | "ResumeInst needs to be in a function with a personality.", &RI)do { if (!(RI.getFunction()->hasPersonalityFn())) { CheckFailed ("ResumeInst needs to be in a function with a personality.", & RI); return; } } while (false); | ||||
3939 | |||||
3940 | if (!LandingPadResultTy) | ||||
3941 | LandingPadResultTy = RI.getValue()->getType(); | ||||
3942 | else | ||||
3943 | Assert(LandingPadResultTy == RI.getValue()->getType(),do { if (!(LandingPadResultTy == RI.getValue()->getType()) ) { CheckFailed("The resume instruction should have a consistent result type " "inside a function.", &RI); return; } } while (false) | ||||
3944 | "The resume instruction should have a consistent result type "do { if (!(LandingPadResultTy == RI.getValue()->getType()) ) { CheckFailed("The resume instruction should have a consistent result type " "inside a function.", &RI); return; } } while (false) | ||||
3945 | "inside a function.",do { if (!(LandingPadResultTy == RI.getValue()->getType()) ) { CheckFailed("The resume instruction should have a consistent result type " "inside a function.", &RI); return; } } while (false) | ||||
3946 | &RI)do { if (!(LandingPadResultTy == RI.getValue()->getType()) ) { CheckFailed("The resume instruction should have a consistent result type " "inside a function.", &RI); return; } } while (false); | ||||
3947 | |||||
3948 | visitTerminator(RI); | ||||
3949 | } | ||||
3950 | |||||
3951 | void Verifier::visitCatchPadInst(CatchPadInst &CPI) { | ||||
3952 | BasicBlock *BB = CPI.getParent(); | ||||
3953 | |||||
3954 | Function *F = BB->getParent(); | ||||
3955 | Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchPadInst needs to be in a function with a personality." , &CPI); return; } } while (false) | ||||
3956 | "CatchPadInst needs to be in a function with a personality.", &CPI)do { if (!(F->hasPersonalityFn())) { CheckFailed("CatchPadInst needs to be in a function with a personality." , &CPI); return; } } while (false); | ||||
3957 | |||||
3958 | Assert(isa<CatchSwitchInst>(CPI.getParentPad()),do { if (!(isa<CatchSwitchInst>(CPI.getParentPad()))) { CheckFailed("CatchPadInst needs to be directly nested in a CatchSwitchInst." , CPI.getParentPad()); return; } } while (false) | ||||
3959 | "CatchPadInst needs to be directly nested in a CatchSwitchInst.",do { if (!(isa<CatchSwitchInst>(CPI.getParentPad()))) { CheckFailed("CatchPadInst needs to be directly nested in a CatchSwitchInst." , CPI.getParentPad()); return; } } while (false) | ||||
3960 | CPI.getParentPad())do { if (!(isa<CatchSwitchInst>(CPI.getParentPad()))) { CheckFailed("CatchPadInst needs to be directly nested in a CatchSwitchInst." , CPI.getParentPad()); return; } } while (false); | ||||
3961 | |||||
3962 | // The catchpad instruction must be the first non-PHI instruction in the | ||||
3963 | // block. | ||||
3964 | Assert(BB->getFirstNonPHI() == &CPI,do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CatchPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (false) | ||||
3965 | "CatchPadInst not the first non-PHI instruction in the block.", &CPI)do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CatchPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (false); | ||||
3966 | |||||
3967 | visitEHPadPredecessors(CPI); | ||||
3968 | visitFuncletPadInst(CPI); | ||||
3969 | } | ||||
3970 | |||||
3971 | void Verifier::visitCatchReturnInst(CatchReturnInst &CatchReturn) { | ||||
3972 | Assert(isa<CatchPadInst>(CatchReturn.getOperand(0)),do { if (!(isa<CatchPadInst>(CatchReturn.getOperand(0)) )) { CheckFailed("CatchReturnInst needs to be provided a CatchPad" , &CatchReturn, CatchReturn.getOperand(0)); return; } } while (false) | ||||
3973 | "CatchReturnInst needs to be provided a CatchPad", &CatchReturn,do { if (!(isa<CatchPadInst>(CatchReturn.getOperand(0)) )) { CheckFailed("CatchReturnInst needs to be provided a CatchPad" , &CatchReturn, CatchReturn.getOperand(0)); return; } } while (false) | ||||
3974 | CatchReturn.getOperand(0))do { if (!(isa<CatchPadInst>(CatchReturn.getOperand(0)) )) { CheckFailed("CatchReturnInst needs to be provided a CatchPad" , &CatchReturn, CatchReturn.getOperand(0)); return; } } while (false); | ||||
3975 | |||||
3976 | visitTerminator(CatchReturn); | ||||
3977 | } | ||||
3978 | |||||
3979 | void Verifier::visitCleanupPadInst(CleanupPadInst &CPI) { | ||||
3980 | BasicBlock *BB = CPI.getParent(); | ||||
3981 | |||||
3982 | Function *F = BB->getParent(); | ||||
3983 | Assert(F->hasPersonalityFn(),do { if (!(F->hasPersonalityFn())) { CheckFailed("CleanupPadInst needs to be in a function with a personality." , &CPI); return; } } while (false) | ||||
3984 | "CleanupPadInst needs to be in a function with a personality.", &CPI)do { if (!(F->hasPersonalityFn())) { CheckFailed("CleanupPadInst needs to be in a function with a personality." , &CPI); return; } } while (false); | ||||
3985 | |||||
3986 | // The cleanuppad instruction must be the first non-PHI instruction in the | ||||
3987 | // block. | ||||
3988 | Assert(BB->getFirstNonPHI() == &CPI,do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CleanupPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (false) | ||||
3989 | "CleanupPadInst not the first non-PHI instruction in the block.",do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CleanupPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (false) | ||||
3990 | &CPI)do { if (!(BB->getFirstNonPHI() == &CPI)) { CheckFailed ("CleanupPadInst not the first non-PHI instruction in the block." , &CPI); return; } } while (false); | ||||
3991 | |||||
3992 | auto *ParentPad = CPI.getParentPad(); | ||||
3993 | Assert(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),do { if (!(isa<ConstantTokenNone>(ParentPad) || isa< FuncletPadInst>(ParentPad))) { CheckFailed("CleanupPadInst has an invalid parent." , &CPI); return; } } while (false) | ||||
3994 | "CleanupPadInst has an invalid parent.", &CPI)do { if (!(isa<ConstantTokenNone>(ParentPad) || isa< FuncletPadInst>(ParentPad))) { CheckFailed("CleanupPadInst has an invalid parent." , &CPI); return; } } while (false); | ||||
3995 | |||||
3996 | visitEHPadPredecessors(CPI); | ||||
3997 | visitFuncletPadInst(CPI); | ||||
3998 | } | ||||
3999 | |||||
4000 | void Verifier::visitFuncletPadInst(FuncletPadInst &FPI) { | ||||
4001 | User *FirstUser = nullptr; | ||||
4002 | Value *FirstUnwindPad = nullptr; | ||||
4003 | SmallVector<FuncletPadInst *, 8> Worklist({&FPI}); | ||||
4004 | SmallSet<FuncletPadInst *, 8> Seen; | ||||
4005 | |||||
4006 | while (!Worklist.empty()) { | ||||
4007 | FuncletPadInst *CurrentPad = Worklist.pop_back_val(); | ||||
4008 | Assert(Seen.insert(CurrentPad).second,do { if (!(Seen.insert(CurrentPad).second)) { CheckFailed("FuncletPadInst must not be nested within itself" , CurrentPad); return; } } while (false) | ||||
4009 | "FuncletPadInst must not be nested within itself", CurrentPad)do { if (!(Seen.insert(CurrentPad).second)) { CheckFailed("FuncletPadInst must not be nested within itself" , CurrentPad); return; } } while (false); | ||||
4010 | Value *UnresolvedAncestorPad = nullptr; | ||||
4011 | for (User *U : CurrentPad->users()) { | ||||
4012 | BasicBlock *UnwindDest; | ||||
4013 | if (auto *CRI = dyn_cast<CleanupReturnInst>(U)) { | ||||
4014 | UnwindDest = CRI->getUnwindDest(); | ||||
4015 | } else if (auto *CSI = dyn_cast<CatchSwitchInst>(U)) { | ||||
4016 | // We allow catchswitch unwind to caller to nest | ||||
4017 | // within an outer pad that unwinds somewhere else, | ||||
4018 | // because catchswitch doesn't have a nounwind variant. | ||||
4019 | // See e.g. SimplifyCFGOpt::SimplifyUnreachable. | ||||
4020 | if (CSI->unwindsToCaller()) | ||||
4021 | continue; | ||||
4022 | UnwindDest = CSI->getUnwindDest(); | ||||
4023 | } else if (auto *II = dyn_cast<InvokeInst>(U)) { | ||||
4024 | UnwindDest = II->getUnwindDest(); | ||||
4025 | } else if (isa<CallInst>(U)) { | ||||
4026 | // Calls which don't unwind may be found inside funclet | ||||
4027 | // pads that unwind somewhere else. We don't *require* | ||||
4028 | // such calls to be annotated nounwind. | ||||
4029 | continue; | ||||
4030 | } else if (auto *CPI = dyn_cast<CleanupPadInst>(U)) { | ||||
4031 | // The unwind dest for a cleanup can only be found by | ||||
4032 | // recursive search. Add it to the worklist, and we'll | ||||
4033 | // search for its first use that determines where it unwinds. | ||||
4034 | Worklist.push_back(CPI); | ||||
4035 | continue; | ||||
4036 | } else { | ||||
4037 | Assert(isa<CatchReturnInst>(U), "Bogus funclet pad use", U)do { if (!(isa<CatchReturnInst>(U))) { CheckFailed("Bogus funclet pad use" , U); return; } } while (false); | ||||
4038 | continue; | ||||
4039 | } | ||||
4040 | |||||
4041 | Value *UnwindPad; | ||||
4042 | bool ExitsFPI; | ||||
4043 | if (UnwindDest) { | ||||
4044 | UnwindPad = UnwindDest->getFirstNonPHI(); | ||||
4045 | if (!cast<Instruction>(UnwindPad)->isEHPad()) | ||||
4046 | continue; | ||||
4047 | Value *UnwindParent = getParentPad(UnwindPad); | ||||
4048 | // Ignore unwind edges that don't exit CurrentPad. | ||||
4049 | if (UnwindParent == CurrentPad) | ||||
4050 | continue; | ||||
4051 | // Determine whether the original funclet pad is exited, | ||||
4052 | // and if we are scanning nested pads determine how many | ||||
4053 | // of them are exited so we can stop searching their | ||||
4054 | // children. | ||||
4055 | Value *ExitedPad = CurrentPad; | ||||
4056 | ExitsFPI = false; | ||||
4057 | do { | ||||
4058 | if (ExitedPad == &FPI) { | ||||
4059 | ExitsFPI = true; | ||||
4060 | // Now we can resolve any ancestors of CurrentPad up to | ||||
4061 | // FPI, but not including FPI since we need to make sure | ||||
4062 | // to check all direct users of FPI for consistency. | ||||
4063 | UnresolvedAncestorPad = &FPI; | ||||
4064 | break; | ||||
4065 | } | ||||
4066 | Value *ExitedParent = getParentPad(ExitedPad); | ||||
4067 | if (ExitedParent == UnwindParent) { | ||||
4068 | // ExitedPad is the ancestor-most pad which this unwind | ||||
4069 | // edge exits, so we can resolve up to it, meaning that | ||||
4070 | // ExitedParent is the first ancestor still unresolved. | ||||
4071 | UnresolvedAncestorPad = ExitedParent; | ||||
4072 | break; | ||||
4073 | } | ||||
4074 | ExitedPad = ExitedParent; | ||||
4075 | } while (!isa<ConstantTokenNone>(ExitedPad)); | ||||
4076 | } else { | ||||
4077 | // Unwinding to caller exits all pads. | ||||
4078 | UnwindPad = ConstantTokenNone::get(FPI.getContext()); | ||||
4079 | ExitsFPI = true; | ||||
4080 | UnresolvedAncestorPad = &FPI; | ||||
4081 | } | ||||
4082 | |||||
4083 | if (ExitsFPI) { | ||||
4084 | // This unwind edge exits FPI. Make sure it agrees with other | ||||
4085 | // such edges. | ||||
4086 | if (FirstUser) { | ||||
4087 | Assert(UnwindPad == FirstUnwindPad, "Unwind edges out of a funclet "do { if (!(UnwindPad == FirstUnwindPad)) { CheckFailed("Unwind edges out of a funclet " "pad must have the same unwind " "dest", &FPI, U, FirstUser ); return; } } while (false) | ||||
4088 | "pad must have the same unwind "do { if (!(UnwindPad == FirstUnwindPad)) { CheckFailed("Unwind edges out of a funclet " "pad must have the same unwind " "dest", &FPI, U, FirstUser ); return; } } while (false) | ||||
4089 | "dest",do { if (!(UnwindPad == FirstUnwindPad)) { CheckFailed("Unwind edges out of a funclet " "pad must have the same unwind " "dest", &FPI, U, FirstUser ); return; } } while (false) | ||||
4090 | &FPI, U, FirstUser)do { if (!(UnwindPad == FirstUnwindPad)) { CheckFailed("Unwind edges out of a funclet " "pad must have the same unwind " "dest", &FPI, U, FirstUser ); return; } } while (false); | ||||
4091 | } else { | ||||
4092 | FirstUser = U; | ||||
4093 | FirstUnwindPad = UnwindPad; | ||||
4094 | // Record cleanup sibling unwinds for verifySiblingFuncletUnwinds | ||||
4095 | if (isa<CleanupPadInst>(&FPI) && !isa<ConstantTokenNone>(UnwindPad) && | ||||
4096 | getParentPad(UnwindPad) == getParentPad(&FPI)) | ||||
4097 | SiblingFuncletInfo[&FPI] = cast<Instruction>(U); | ||||
4098 | } | ||||
4099 | } | ||||
4100 | // Make sure we visit all uses of FPI, but for nested pads stop as | ||||
4101 | // soon as we know where they unwind to. | ||||
4102 | if (CurrentPad != &FPI) | ||||
4103 | break; | ||||
4104 | } | ||||
4105 | if (UnresolvedAncestorPad) { | ||||
4106 | if (CurrentPad == UnresolvedAncestorPad) { | ||||
4107 | // When CurrentPad is FPI itself, we don't mark it as resolved even if | ||||
4108 | // we've found an unwind edge that exits it, because we need to verify | ||||
4109 | // all direct uses of FPI. | ||||
4110 | assert(CurrentPad == &FPI)((CurrentPad == &FPI) ? static_cast<void> (0) : __assert_fail ("CurrentPad == &FPI", "/build/llvm-toolchain-snapshot-12~++20210124100612+2afaf072f5c1/llvm/lib/IR/Verifier.cpp" , 4110, __PRETTY_FUNCTION__)); | ||||
4111 | continue; | ||||
4112 | } | ||||
4113 | // Pop off the worklist any nested pads that we've found an unwind | ||||
4114 | // destination for. The pads on the worklist are the uncles, | ||||
4115 | // great-uncles, etc. of CurrentPad. We've found an unwind destination | ||||
4116 | // for all ancestors of CurrentPad up to but not including | ||||
4117 | // UnresolvedAncestorPad. | ||||
4118 | Value *ResolvedPad = CurrentPad; | ||||
4119 | while (!Worklist.empty()) { | ||||
4120 | Value *UnclePad = Worklist.back(); | ||||
4121 | Value *AncestorPad = getParentPad(UnclePad); | ||||
4122 | // Walk ResolvedPad up the ancestor list until we either find the | ||||
4123 | // uncle's parent or the last resolved ancestor. | ||||
4124 | while (ResolvedPad != AncestorPad) { | ||||
4125 | Value *ResolvedParent = getParentPad(ResolvedPad); | ||||
4126 | if (ResolvedParent == UnresolvedAncestorPad) { | ||||
4127 | break; | ||||
4128 | } | ||||
4129 | ResolvedPad = ResolvedParent; | ||||
4130 | } | ||||
4131 | // If the resolved ancestor search didn't find the uncle's parent, | ||||
4132 | // then the uncle is not yet resolved. | ||||