[PATCH] D79140: [ThinLTO] return error instead of crashing on invalid input

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 8 21:11:47 PST 2023


Amir updated this revision to Diff 487276.
Amir added a comment.
Herald added a subscriber: emaste.
Herald added a project: All.

Add testcase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79140/new/

https://reviews.llvm.org/D79140

Files:
  lld/test/ELF/stale-profile-error.ll
  llvm/lib/Transforms/IPO/FunctionImport.cpp


Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===================================================================
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -39,6 +39,7 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -1247,8 +1248,9 @@
             std::move(SrcModule), GlobalsToImport.getArrayRef(),
             [](GlobalValue &, IRMover::ValueAdder) {},
             /*IsPerformingImport=*/true))
-      report_fatal_error("Function Import: link error: " +
-                         toString(std::move(Err)));
+      return createStringError(errc::invalid_argument,
+                               "Function Import: link error: %s",
+                               toString(std::move(Err)).c_str());
 
     ImportedCount += GlobalsToImport.size();
     NumImportedModules++;
Index: lld/test/ELF/stale-profile-error.ll
===================================================================
--- /dev/null
+++ lld/test/ELF/stale-profile-error.ll
@@ -0,0 +1,24 @@
+; RUN: split-file %s %t
+; RUN: llvm-as %t/size1.ll -o %t/size1.bc
+; RUN: llvm-as %t/size2.ll -o %t/size2.bc
+
+; RUN: not ld.lld %t/size1.bc %t/size2.bc -S -o - 2>&1 | FileCheck %s
+
+; Test module flags error messages.
+; CHECK: linking module flags 'foo': IDs have conflicting values in '{{.*}}size2.bc' and 'ld-temp.o'
+
+;--- size1.ll
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+!0 = !{ i32 1, !"foo", i32 37 }
+
+!llvm.module.flags = !{ !0 }
+
+;--- size2.ll
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+!0 = !{ i32 1, !"foo", i32 38 }
+
+!llvm.module.flags = !{ !0 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79140.487276.patch
Type: text/x-patch
Size: 1997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230109/e97a7bde/attachment.bin>


More information about the llvm-commits mailing list