[mlir] run the verifier before translating a module

In translation from MLIR to another IR, run the MLIR verifier on the parsed
module to ensure only valid modules are given to the translation. Previously,
we would send any module that could be parsed to the translation, including
semantically invalid modules, leading to surprising errors or lack thereof down
the pipeline.

Depends On D106937

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D106938
This commit is contained in:
Alex Zinenko 2021-07-28 10:23:38 +02:00
parent c1f719d1a7
commit 49f745f59c

View file

@ -102,7 +102,7 @@ TranslateFromMLIRRegistration::TranslateFromMLIRRegistration(
dialectRegistration(registry);
context->appendDialectRegistry(registry);
auto module = OwningModuleRef(parseSourceFile(sourceMgr, context));
if (!module)
if (!module || failed(verify(*module)))
return failure();
return function(module.get(), output);
});