[PATCH] D27082: [LTO] Reject modules without datalayout

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 23 16:17:28 PST 2016


davide created this revision.
davide added reviewers: mehdi_amini, pcc, rafael.
davide added a subscriber: llvm-commits.

As per our previous discussion, see https://llvm.org/bugs/show_bug.cgi?id=31123 for reference.
If you agree on the patch, I'll also update the gold/lld tests failing.


https://reviews.llvm.org/D27082

Files:
  lib/LTO/LTOBackend.cpp
  lib/LTO/LTOModule.cpp
  test/tools/llvm-lto2/X86/nodatalayout.ll


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
+}
Index: lib/LTO/LTOModule.cpp
===================================================================
--- lib/LTO/LTOModule.cpp
+++ lib/LTO/LTOModule.cpp
@@ -231,7 +231,8 @@
 
   TargetMachine *target =
       march->createTargetMachine(TripleStr, CPU, FeatureStr, options, None);
-  M->setDataLayout(target->createDataLayout());
+  if (M->getDataLayoutStr().empty())
+   report_fatal_error("input module has no datalayout");
 
   std::unique_ptr<object::IRObjectFile> IRObj(
       new object::IRObjectFile(Buffer, std::move(M)));
Index: lib/LTO/LTOBackend.cpp
===================================================================
--- lib/LTO/LTOBackend.cpp
+++ lib/LTO/LTOBackend.cpp
@@ -191,7 +191,8 @@
 
 bool opt(Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
          bool IsThinLto) {
-  Mod.setDataLayout(TM->createDataLayout());
+  if (Mod.getDataLayoutStr().empty())
+    report_fatal_error("input module has no datalayout");
   if (Conf.OptPipeline.empty())
     runOldPMPasses(Conf, Mod, TM, IsThinLto);
   else


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27082.79174.patch
Type: text/x-patch
Size: 1525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161124/03eaaf08/attachment.bin>


More information about the llvm-commits mailing list