diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -519,6 +519,8 @@ return TOrErr.takeError(); std::unique_ptr TM = createTargetMachine(C, *TOrErr, *Mod); + if (TM) + Mod->setDataLayout(TM->createDataLayout()); if (!C.CodeGenOnly) { if (!opt(C, TM.get(), 0, *Mod, /*IsThinLTO=*/false, @@ -567,6 +569,8 @@ return TOrErr.takeError(); std::unique_ptr TM = createTargetMachine(Conf, *TOrErr, Mod); + if (TM) + Mod.setDataLayout(TM->createDataLayout()); // Setup optimization remarks. auto DiagFileOrErr = lto::setupLLVMOptimizationRemarks( diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -232,6 +232,8 @@ static void optimizeModule(Module &TheModule, TargetMachine &TM, unsigned OptLevel, bool Freestanding, ModuleSummaryIndex *Index) { + TheModule.setDataLayout(TM.createDataLayout()); + // Populate the PassManager PassManagerBuilder PMB; PMB.LibraryInfo = new TargetLibraryInfoImpl(TM.getTargetTriple());