blob: b74e113230bd5cef0bdd06cd3755ced8147d242f [file] [log] [blame]
Chris Lattner21e67f62018-07-06 10:46:19 -07001//===- Verifier.cpp - MLIR Verifier Implementation ------------------------===//
2//
3// Copyright 2019 The MLIR Authors.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16// =============================================================================
17//
18// This file implements the verify() methods on the various IR types, performing
19// (potentially expensive) checks on the holistic structure of the code. This
20// can be used for detecting bugs in compiler transformations and hand written
21// .mlir files.
22//
23// The checks in this file are only for things that can occur as part of IR
24// transformations: e.g. violation of dominance information, malformed operation
25// attributes, etc. MLIR supports transformations moving IR through locally
26// invalid states (e.g. unlinking an instruction from an instruction before
27// re-inserting it in a new place), but each transformation must complete with
28// the IR in a valid form.
29//
30// This should not check for things that are always wrong by construction (e.g.
31// affine maps or other immutable structures that are incorrect), because those
32// are not mutable and can be checked at time of construction.
33//
34//===----------------------------------------------------------------------===//
35
Chris Lattnerea5c3dc2018-08-21 08:42:19 -070036#include "mlir/IR/Attributes.h"
Chris Lattner21e67f62018-07-06 10:46:19 -070037#include "mlir/IR/CFGFunction.h"
38#include "mlir/IR/MLFunction.h"
39#include "mlir/IR/Module.h"
40#include "mlir/IR/OperationSet.h"
Chris Lattnerf7bdf952018-08-05 21:12:29 -070041#include "mlir/IR/Statements.h"
Chris Lattnerea5c3dc2018-08-21 08:42:19 -070042#include "mlir/IR/StmtVisitor.h"
Chris Lattnerf7bdf952018-08-05 21:12:29 -070043#include "llvm/ADT/ScopedHashTable.h"
Chris Lattner21e67f62018-07-06 10:46:19 -070044#include "llvm/ADT/Twine.h"
Chris Lattnerf7bdf952018-08-05 21:12:29 -070045#include "llvm/Support/PrettyStackTrace.h"
Chris Lattner21e67f62018-07-06 10:46:19 -070046#include "llvm/Support/raw_ostream.h"
47using namespace mlir;
48
Chris Lattner40746442018-07-21 14:32:09 -070049namespace {
50/// Base class for the verifiers in this file. It is a pervasive truth that
51/// this file treats "true" as an error that needs to be recovered from, and
52/// "false" as success.
53///
54class Verifier {
55public:
56 template <typename T>
57 static void failure(const Twine &message, const T &value, raw_ostream &os) {
58 // Print the error message and flush the stream in case printing the value
59 // causes a crash.
60 os << "MLIR verification failure: " + message + "\n";
61 os.flush();
62 value.print(os);
63 }
64
65 template <typename T>
66 bool failure(const Twine &message, const T &value) {
67 // If the caller isn't trying to collect failure information, just print
68 // the result and abort.
69 if (!errorResult) {
70 failure(message, value, llvm::errs());
71 abort();
72 }
73
74 // Otherwise, emit the error into the string and return true.
75 llvm::raw_string_ostream os(*errorResult);
76 failure(message, value, os);
77 os.flush();
78 return true;
79 }
80
Chris Lattner95865062018-08-01 10:18:59 -070081 bool opFailure(const Twine &message, const Operation &value) {
82 value.emitError(message);
83 return true;
84 }
85
Chris Lattnerea5c3dc2018-08-21 08:42:19 -070086 bool verifyOperation(const Operation &op);
87 bool verifyAttribute(Attribute *attr, const Operation &op);
88
Chris Lattner40746442018-07-21 14:32:09 -070089protected:
Chris Lattnerea5c3dc2018-08-21 08:42:19 -070090 explicit Verifier(std::string *errorResult, const Function &fn)
91 : errorResult(errorResult), fn(fn),
92 operationSet(OperationSet::get(fn.getContext())) {}
Chris Lattner40746442018-07-21 14:32:09 -070093
94private:
Chris Lattnerea5c3dc2018-08-21 08:42:19 -070095 /// If the verifier is returning errors back to a client, this is the error to
96 /// fill in.
Chris Lattner40746442018-07-21 14:32:09 -070097 std::string *errorResult;
Chris Lattnerea5c3dc2018-08-21 08:42:19 -070098
99 /// The function being checked.
100 const Function &fn;
101
102 /// The operation set installed in the current MLIR context.
103 OperationSet &operationSet;
Chris Lattner40746442018-07-21 14:32:09 -0700104};
105} // end anonymous namespace
Chris Lattner21e67f62018-07-06 10:46:19 -0700106
Chris Lattnerea5c3dc2018-08-21 08:42:19 -0700107// Check that function attributes are all well formed.
108bool Verifier::verifyAttribute(Attribute *attr, const Operation &op) {
109 if (!attr->isOrContainsFunction())
110 return false;
111
112 // If we have a function attribute, check that it is non-null and in the
113 // same module as the operation that refers to it.
114 if (auto *fnAttr = dyn_cast<FunctionAttr>(attr)) {
115 if (!fnAttr->getValue())
116 return opFailure("attribute refers to deallocated function!", op);
117
118 if (fnAttr->getValue()->getModule() != fn.getModule())
119 return opFailure("attribute refers to function '" +
120 Twine(fnAttr->getValue()->getName()) +
121 "' defined in another module!",
122 op);
123 return false;
124 }
125
126 // Otherwise, we must have an array attribute, remap the elements.
127 for (auto *elt : cast<ArrayAttr>(attr)->getValue()) {
128 if (verifyAttribute(elt, op))
129 return true;
130 }
131
132 return false;
133}
134
135/// Check the invariants of the specified operation instruction or statement.
136bool Verifier::verifyOperation(const Operation &op) {
137 if (op.getOperationFunction() != &fn)
138 return opFailure("operation in the wrong function", op);
139
140 // TODO: Check that operands are non-nil and structurally ok.
141
142 // Verify all attributes are ok. We need to check Function attributes, since
143 // they are actually mutable (the function they refer to can be deleted), and
144 // we have to check array attributes that can refer to them.
145 for (auto attr : op.getAttrs()) {
146 if (verifyAttribute(attr.second, op))
147 return true;
148 }
149
150 // If we can get operation info for this, check the custom hook.
151 if (auto *opInfo = op.getAbstractOperation()) {
152 if (auto *errorMessage = opInfo->verifyInvariants(&op))
153 return opFailure(Twine("'") + op.getName().str() + "' op " + errorMessage,
154 op);
155 }
156
157 return false;
158}
159
Chris Lattner21e67f62018-07-06 10:46:19 -0700160//===----------------------------------------------------------------------===//
161// CFG Functions
162//===----------------------------------------------------------------------===//
163
164namespace {
Chris Lattnerea5c3dc2018-08-21 08:42:19 -0700165struct CFGFuncVerifier : public Verifier {
Chris Lattner21e67f62018-07-06 10:46:19 -0700166 const CFGFunction &fn;
Chris Lattner21e67f62018-07-06 10:46:19 -0700167
Chris Lattner40746442018-07-21 14:32:09 -0700168 CFGFuncVerifier(const CFGFunction &fn, std::string *errorResult)
Chris Lattnerea5c3dc2018-08-21 08:42:19 -0700169 : Verifier(errorResult, fn), fn(fn) {}
Chris Lattner21e67f62018-07-06 10:46:19 -0700170
Chris Lattner40746442018-07-21 14:32:09 -0700171 bool verify();
172 bool verifyBlock(const BasicBlock &block);
Chris Lattner40746442018-07-21 14:32:09 -0700173 bool verifyTerminator(const TerminatorInst &term);
174 bool verifyReturn(const ReturnInst &inst);
Chris Lattner1604e472018-07-23 08:42:19 -0700175 bool verifyBranch(const BranchInst &inst);
James Molloy4f788372018-07-24 15:01:27 -0700176 bool verifyCondBranch(const CondBranchInst &inst);
177
178 // Given a list of "operands" and "arguments" that are the same length, verify
179 // that the types of operands pointwise match argument types. The iterator
180 // types must expose the "getType()" function when dereferenced twice; that
181 // is, the iterator's value_type must be equivalent to SSAValue*.
182 template <typename OperandIteratorTy, typename ArgumentIteratorTy>
183 bool verifyOperandsMatchArguments(OperandIteratorTy opBegin,
184 OperandIteratorTy opEnd,
185 ArgumentIteratorTy argBegin,
186 const Instruction &instContext);
Chris Lattner21e67f62018-07-06 10:46:19 -0700187};
188} // end anonymous namespace
189
Chris Lattner40746442018-07-21 14:32:09 -0700190bool CFGFuncVerifier::verify() {
Chris Lattnerf7bdf952018-08-05 21:12:29 -0700191 llvm::PrettyStackTraceFormat fmt("MLIR Verifier: cfgfunc @%s",
192 fn.getName().c_str());
193
Chris Lattner21e67f62018-07-06 10:46:19 -0700194 // TODO: Lots to be done here, including verifying dominance information when
195 // we have uses and defs.
James Molloy61a656c2018-07-22 15:45:24 -0700196 // TODO: Verify the first block has no predecessors.
197
198 if (fn.empty())
199 return failure("cfgfunc must have at least one basic block", fn);
200
201 // Verify that the argument list of the function and the arg list of the first
202 // block line up.
203 auto *firstBB = &fn.front();
204 auto fnInputTypes = fn.getType()->getInputs();
205 if (fnInputTypes.size() != firstBB->getNumArguments())
206 return failure("first block of cfgfunc must have " +
207 Twine(fnInputTypes.size()) +
208 " arguments to match function signature",
209 fn);
210 for (unsigned i = 0, e = firstBB->getNumArguments(); i != e; ++i)
211 if (fnInputTypes[i] != firstBB->getArgument(i)->getType())
212 return failure(
213 "type of argument #" + Twine(i) +
214 " must match corresponding argument in function signature",
215 fn);
Chris Lattner21e67f62018-07-06 10:46:19 -0700216
217 for (auto &block : fn) {
Chris Lattner40746442018-07-21 14:32:09 -0700218 if (verifyBlock(block))
219 return true;
Chris Lattner21e67f62018-07-06 10:46:19 -0700220 }
Chris Lattner40746442018-07-21 14:32:09 -0700221 return false;
Chris Lattner21e67f62018-07-06 10:46:19 -0700222}
223
Chris Lattner40746442018-07-21 14:32:09 -0700224bool CFGFuncVerifier::verifyBlock(const BasicBlock &block) {
Chris Lattner21e67f62018-07-06 10:46:19 -0700225 if (!block.getTerminator())
Chris Lattner40746442018-07-21 14:32:09 -0700226 return failure("basic block with no terminator", block);
227
228 if (verifyTerminator(*block.getTerminator()))
229 return true;
Chris Lattner21e67f62018-07-06 10:46:19 -0700230
James Molloy61a656c2018-07-22 15:45:24 -0700231 for (auto *arg : block.getArguments()) {
232 if (arg->getOwner() != &block)
233 return failure("basic block argument not owned by block", block);
234 }
235
Chris Lattner21e67f62018-07-06 10:46:19 -0700236 for (auto &inst : block) {
Chris Lattner40746442018-07-21 14:32:09 -0700237 if (verifyOperation(inst))
238 return true;
Chris Lattner21e67f62018-07-06 10:46:19 -0700239 }
Chris Lattner40746442018-07-21 14:32:09 -0700240 return false;
Chris Lattner21e67f62018-07-06 10:46:19 -0700241}
242
Chris Lattner40746442018-07-21 14:32:09 -0700243bool CFGFuncVerifier::verifyTerminator(const TerminatorInst &term) {
Chris Lattner21e67f62018-07-06 10:46:19 -0700244 if (term.getFunction() != &fn)
Chris Lattner40746442018-07-21 14:32:09 -0700245 return failure("terminator in the wrong function", term);
Chris Lattner21e67f62018-07-06 10:46:19 -0700246
247 // TODO: Check that operands are structurally ok.
248 // TODO: Check that successors are in the right function.
Chris Lattner40746442018-07-21 14:32:09 -0700249
250 if (auto *ret = dyn_cast<ReturnInst>(&term))
251 return verifyReturn(*ret);
252
Chris Lattner1604e472018-07-23 08:42:19 -0700253 if (auto *br = dyn_cast<BranchInst>(&term))
254 return verifyBranch(*br);
255
James Molloy4f788372018-07-24 15:01:27 -0700256 if (auto *br = dyn_cast<CondBranchInst>(&term))
257 return verifyCondBranch(*br);
258
Chris Lattner40746442018-07-21 14:32:09 -0700259 return false;
Chris Lattner21e67f62018-07-06 10:46:19 -0700260}
261
Chris Lattner40746442018-07-21 14:32:09 -0700262bool CFGFuncVerifier::verifyReturn(const ReturnInst &inst) {
263 // Verify that the return operands match the results of the function.
264 auto results = fn.getType()->getResults();
265 if (inst.getNumOperands() != results.size())
266 return failure("return has " + Twine(inst.getNumOperands()) +
267 " operands, but enclosing function returns " +
268 Twine(results.size()),
269 inst);
270
Chris Lattner1604e472018-07-23 08:42:19 -0700271 for (unsigned i = 0, e = results.size(); i != e; ++i)
272 if (inst.getOperand(i)->getType() != results[i])
273 return failure("type of return operand " + Twine(i) +
Tatiana Shpeismand9b1d862018-08-09 12:28:58 -0700274 " doesn't match function result type",
Chris Lattner1604e472018-07-23 08:42:19 -0700275 inst);
276
277 return false;
278}
279
280bool CFGFuncVerifier::verifyBranch(const BranchInst &inst) {
281 // Verify that the number of operands lines up with the number of BB arguments
282 // in the successor.
283 auto dest = inst.getDest();
284 if (inst.getNumOperands() != dest->getNumArguments())
285 return failure("branch has " + Twine(inst.getNumOperands()) +
286 " operands, but target block has " +
287 Twine(dest->getNumArguments()),
288 inst);
289
290 for (unsigned i = 0, e = inst.getNumOperands(); i != e; ++i)
291 if (inst.getOperand(i)->getType() != dest->getArgument(i)->getType())
292 return failure("type of branch operand " + Twine(i) +
293 " doesn't match target bb argument type",
294 inst);
295
Chris Lattner40746442018-07-21 14:32:09 -0700296 return false;
297}
298
James Molloy4f788372018-07-24 15:01:27 -0700299template <typename OperandIteratorTy, typename ArgumentIteratorTy>
300bool CFGFuncVerifier::verifyOperandsMatchArguments(
301 OperandIteratorTy opBegin, OperandIteratorTy opEnd,
302 ArgumentIteratorTy argBegin, const Instruction &instContext) {
303 OperandIteratorTy opIt = opBegin;
304 ArgumentIteratorTy argIt = argBegin;
305 for (; opIt != opEnd; ++opIt, ++argIt) {
306 if ((*opIt)->getType() != (*argIt)->getType())
307 return failure("type of operand " + Twine(std::distance(opBegin, opIt)) +
308 " doesn't match argument type",
309 instContext);
310 }
311 return false;
312}
313
314bool CFGFuncVerifier::verifyCondBranch(const CondBranchInst &inst) {
315 // Verify that the number of operands lines up with the number of BB arguments
316 // in the true successor.
317 auto trueDest = inst.getTrueDest();
318 if (inst.getNumTrueOperands() != trueDest->getNumArguments())
319 return failure("branch has " + Twine(inst.getNumTrueOperands()) +
320 " true operands, but true target block has " +
321 Twine(trueDest->getNumArguments()),
322 inst);
323
324 if (verifyOperandsMatchArguments(inst.true_operand_begin(),
325 inst.true_operand_end(),
326 trueDest->args_begin(), inst))
327 return true;
328
329 // And the false successor.
330 auto falseDest = inst.getFalseDest();
331 if (inst.getNumFalseOperands() != falseDest->getNumArguments())
332 return failure("branch has " + Twine(inst.getNumFalseOperands()) +
333 " false operands, but false target block has " +
334 Twine(falseDest->getNumArguments()),
335 inst);
336
337 if (verifyOperandsMatchArguments(inst.false_operand_begin(),
338 inst.false_operand_end(),
339 falseDest->args_begin(), inst))
340 return true;
341
342 if (inst.getCondition()->getType() != Type::getInteger(1, fn.getContext()))
343 return failure("type of condition is not boolean (i1)", inst);
344
345 return false;
346}
347
Chris Lattner21e67f62018-07-06 10:46:19 -0700348//===----------------------------------------------------------------------===//
349// ML Functions
350//===----------------------------------------------------------------------===//
351
352namespace {
Chris Lattnerea5c3dc2018-08-21 08:42:19 -0700353struct MLFuncVerifier : public Verifier, public StmtWalker<MLFuncVerifier> {
Chris Lattner21e67f62018-07-06 10:46:19 -0700354 const MLFunction &fn;
Chris Lattnerea5c3dc2018-08-21 08:42:19 -0700355 bool hadError = false;
Chris Lattner21e67f62018-07-06 10:46:19 -0700356
Chris Lattner40746442018-07-21 14:32:09 -0700357 MLFuncVerifier(const MLFunction &fn, std::string *errorResult)
Chris Lattnerea5c3dc2018-08-21 08:42:19 -0700358 : Verifier(errorResult, fn), fn(fn) {}
359
360 void visitOperationStmt(OperationStmt *opStmt) {
361 hadError |= verifyOperation(*opStmt);
362 }
Chris Lattner21e67f62018-07-06 10:46:19 -0700363
Chris Lattner40746442018-07-21 14:32:09 -0700364 bool verify() {
Chris Lattnerf7bdf952018-08-05 21:12:29 -0700365 llvm::PrettyStackTraceFormat fmt("MLIR Verifier: mlfunc @%s",
366 fn.getName().c_str());
367
Chris Lattnerea5c3dc2018-08-21 08:42:19 -0700368 // Check basic structural properties.
369 walk(const_cast<MLFunction *>(&fn));
370 if (hadError)
371 return true;
372
Tatiana Shpeismand9b1d862018-08-09 12:28:58 -0700373 // TODO: check that operation is not a return statement unless it's
374 // the last one in the function.
375 if (verifyReturn())
376 return true;
Chris Lattnerf7bdf952018-08-05 21:12:29 -0700377
378 return verifyDominance();
Chris Lattner21e67f62018-07-06 10:46:19 -0700379 }
Chris Lattnerf7bdf952018-08-05 21:12:29 -0700380
381 /// Walk all of the code in this MLFunc and verify that the operands of any
382 /// operations are properly dominated by their definitions.
383 bool verifyDominance();
Tatiana Shpeismand9b1d862018-08-09 12:28:58 -0700384
385 /// Verify that function has a return statement that matches its signature.
386 bool verifyReturn();
Chris Lattner21e67f62018-07-06 10:46:19 -0700387};
388} // end anonymous namespace
389
Chris Lattnerf7bdf952018-08-05 21:12:29 -0700390/// Walk all of the code in this MLFunc and verify that the operands of any
391/// operations are properly dominated by their definitions.
392bool MLFuncVerifier::verifyDominance() {
393 using HashTable = llvm::ScopedHashTable<const SSAValue *, bool>;
394 HashTable liveValues;
395 HashTable::ScopeTy topScope(liveValues);
396
397 // All of the arguments to the function are live for the whole function.
Tatiana Shpeismanbc3c7492018-08-06 11:54:39 -0700398 for (auto *arg : fn.getArguments())
399 liveValues.insert(arg, true);
Chris Lattnerf7bdf952018-08-05 21:12:29 -0700400
401 // This recursive function walks the statement list pushing scopes onto the
402 // stack as it goes, and popping them to remove them from the table.
403 std::function<bool(const StmtBlock &block)> walkBlock;
404 walkBlock = [&](const StmtBlock &block) -> bool {
405 HashTable::ScopeTy blockScope(liveValues);
406
407 // The induction variable of a for statement is live within its body.
408 if (auto *forStmt = dyn_cast<ForStmt>(&block))
409 liveValues.insert(forStmt, true);
410
411 for (auto &stmt : block) {
412 // TODO: For and If will eventually have operands, we need to check them.
413 // When this happens, Statement should have a general getOperands() method
414 // we can use here first.
415 if (auto *opStmt = dyn_cast<OperationStmt>(&stmt)) {
416 // Verify that each of the operands are live.
417 unsigned operandNo = 0;
418 for (auto *opValue : opStmt->getOperands()) {
419 if (!liveValues.count(opValue)) {
420 opStmt->emitError("operand #" + Twine(operandNo) +
421 " does not dominate this use");
422 if (auto *useStmt = opValue->getDefiningStmt())
423 useStmt->emitNote("operand defined here");
424 return true;
425 }
426 ++operandNo;
427 }
428
429 // Operations define values, add them to the hash table.
430 for (auto *result : opStmt->getResults())
431 liveValues.insert(result, true);
432 continue;
433 }
434
435 // If this is an if or for, recursively walk the block they contain.
436 if (auto *ifStmt = dyn_cast<IfStmt>(&stmt)) {
Chris Lattnere787b322018-08-08 11:14:57 -0700437 if (walkBlock(*ifStmt->getThen()))
Chris Lattnerf7bdf952018-08-05 21:12:29 -0700438 return true;
439
Chris Lattnere787b322018-08-08 11:14:57 -0700440 if (auto *elseClause = ifStmt->getElse())
Chris Lattnerf7bdf952018-08-05 21:12:29 -0700441 if (walkBlock(*elseClause))
442 return true;
443 }
444 if (auto *forStmt = dyn_cast<ForStmt>(&stmt))
445 if (walkBlock(*forStmt))
446 return true;
447 }
448
449 return false;
450 };
451
452 // Check the whole function out.
453 return walkBlock(fn);
454}
455
Tatiana Shpeismand9b1d862018-08-09 12:28:58 -0700456bool MLFuncVerifier::verifyReturn() {
457 // TODO: fold return verification in the pass that verifies all statements.
458 const char missingReturnMsg[] = "ML function must end with return statement";
459 if (fn.getStatements().empty())
460 return failure(missingReturnMsg, fn);
461
462 const auto &stmt = fn.getStatements().back();
463 if (const auto *op = dyn_cast<OperationStmt>(&stmt)) {
464 if (!op->isReturn())
465 return failure(missingReturnMsg, fn);
466
467 // The operand number and types must match the function signature.
468 // TODO: move this verification in ReturnOp::verify() if printing
469 // of the error messages below can be made to work there.
470 const auto &results = fn.getType()->getResults();
471 if (op->getNumOperands() != results.size())
472 return failure("return has " + Twine(op->getNumOperands()) +
473 " operands, but enclosing function returns " +
474 Twine(results.size()),
475 *op);
476
477 for (unsigned i = 0, e = results.size(); i != e; ++i)
478 if (op->getOperand(i)->getType() != results[i])
479 return failure("type of return operand " + Twine(i) +
480 " doesn't match function result type",
481 *op);
482 return false;
483 }
484 return failure(missingReturnMsg, fn);
485}
486
Chris Lattner21e67f62018-07-06 10:46:19 -0700487//===----------------------------------------------------------------------===//
488// Entrypoints
489//===----------------------------------------------------------------------===//
490
491/// Perform (potentially expensive) checks of invariants, used to detect
Chris Lattner40746442018-07-21 14:32:09 -0700492/// compiler bugs. On error, this fills in the string and return true,
493/// or aborts if the string was not provided.
494bool Function::verify(std::string *errorResult) const {
Chris Lattner21e67f62018-07-06 10:46:19 -0700495 switch (getKind()) {
496 case Kind::ExtFunc:
497 // No body, nothing can be wrong here.
Chris Lattner40746442018-07-21 14:32:09 -0700498 return false;
Chris Lattner21e67f62018-07-06 10:46:19 -0700499 case Kind::CFGFunc:
Chris Lattner40746442018-07-21 14:32:09 -0700500 return CFGFuncVerifier(*cast<CFGFunction>(this), errorResult).verify();
Chris Lattner21e67f62018-07-06 10:46:19 -0700501 case Kind::MLFunc:
Chris Lattner40746442018-07-21 14:32:09 -0700502 return MLFuncVerifier(*cast<MLFunction>(this), errorResult).verify();
Chris Lattner21e67f62018-07-06 10:46:19 -0700503 }
504}
505
506/// Perform (potentially expensive) checks of invariants, used to detect
Chris Lattner40746442018-07-21 14:32:09 -0700507/// compiler bugs. On error, this fills in the string and return true,
508/// or aborts if the string was not provided.
509bool Module::verify(std::string *errorResult) const {
510
Chris Lattner21e67f62018-07-06 10:46:19 -0700511 /// Check that each function is correct.
Chris Lattnera8e47672018-07-25 14:08:16 -0700512 for (auto &fn : *this) {
513 if (fn.verify(errorResult))
Chris Lattner40746442018-07-21 14:32:09 -0700514 return true;
Chris Lattner21e67f62018-07-06 10:46:19 -0700515 }
Chris Lattner40746442018-07-21 14:32:09 -0700516
517 // Make sure the error string is empty on success.
518 if (errorResult)
519 errorResult->clear();
520 return false;
Chris Lattner21e67f62018-07-06 10:46:19 -0700521}