diff --git a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp --- a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp @@ -27,6 +27,7 @@ #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/IR/IRBuilder.h" +#include "llvm/IR/Verifier.h" #include "llvm/MC/SubtargetFeature.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Error.h" @@ -234,6 +235,9 @@ auto dataLayout = llvmModule->getDataLayout(); + if (verifyModule(*llvmModule)) + return make_string_error("LLVM IR fails to verify"); + // Callback to create the object layer with symbol resolution to current // process and dynamically linked libraries. auto objectLinkingLayerCreator = [&](ExecutionSession &session, diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp --- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp @@ -71,6 +71,18 @@ if (!compileUnit || !func.walk(interruptIfValidLocation).wasInterrupted()) return; + // If we are to create debug info for the function, we need to ensure that all + // inlinable calls in it are with debug info, otherwise the LLVM verifier will + // complain. For now, be more restricted and treat all calls as inlinable. + const bool hasCallWithoutDebugInfo = + func.walk([](LLVM::CallOp call) { + return call.getLoc().isa() ? WalkResult::interrupt() + : WalkResult::advance(); + }) + .wasInterrupted(); + if (hasCallWithoutDebugInfo) + return; + FileLineColLoc fileLoc = extractFileLoc(func.getLoc()); auto *file = translateFile(fileLoc ? fileLoc.getFilename() : ""); unsigned line = fileLoc ? fileLoc.getLine() : 0;