Index: lib/LTO/LTO.cpp =================================================================== --- lib/LTO/LTO.cpp +++ lib/LTO/LTO.cpp @@ -320,8 +320,12 @@ if (Conf.ResolutionFile) writeToResolutionFile(*Conf.ResolutionFile, Input.get(), Res); - // FIXME: move to backend Module &M = Input->Obj->getModule(); + if (M.getDataLayoutStr().empty()) + return make_error("input module has no datalayout", + inconvertibleErrorCode()); + + // FIXME: move to backend if (!Conf.OverrideTriple.empty()) M.setTargetTriple(Conf.OverrideTriple); else if (M.getTargetTriple().empty()) Index: lib/LTO/LTOBackend.cpp =================================================================== --- lib/LTO/LTOBackend.cpp +++ lib/LTO/LTOBackend.cpp @@ -191,7 +191,6 @@ bool opt(Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod, bool IsThinLTO) { - Mod.setDataLayout(TM->createDataLayout()); if (Conf.OptPipeline.empty()) runOldPMPasses(Conf, Mod, TM, IsThinLTO); else Index: lib/LTO/LTOModule.cpp =================================================================== --- lib/LTO/LTOModule.cpp +++ lib/LTO/LTOModule.cpp @@ -231,7 +231,6 @@ TargetMachine *target = march->createTargetMachine(TripleStr, CPU, FeatureStr, options, None); - M->setDataLayout(target->createDataLayout()); std::unique_ptr IRObj( new object::IRObjectFile(Buffer, std::move(M))); Index: test/tools/llvm-lto2/X86/nodatalayout.ll =================================================================== --- /dev/null +++ test/tools/llvm-lto2/X86/nodatalayout.ll @@ -0,0 +1,13 @@ +; RUN: llvm-as < %s > %t1.bc + +; Reject input modules without a datalayout. +; RUN: not llvm-lto2 %t1.bc -o %t.o \ +; RUN: -r %t1.bc,patatino,px 2>&1 | FileCheck %s + +; CHECK: input module has no datalayout + +target triple = "x86_64-unknown-linux-gnu" + +define void @patatino() { + ret void +}