From f53de29862193b761f3ef8ec0627d1e70d2fe674 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 23 Feb 2023 21:45:14 -0800 Subject: [PATCH] [FunctionImport] Change IRMover report_fatal_error to a proper error Conflicting module flags leads to a proper error for regular LTO but a crash (report_fatal_error) for ThinLTO. Switch to createStringError to fix the crash and match regular LTO. --- llvm/lib/Transforms/IPO/FunctionImport.cpp | 5 ++-- .../test/Transforms/FunctionImport/module-flags.ll | 33 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 llvm/test/Transforms/FunctionImport/module-flags.ll diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index 7c99465..222b719 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -1373,8 +1373,9 @@ Expected FunctionImporter::importFunctions( if (Error Err = Mover.move(std::move(SrcModule), GlobalsToImport.getArrayRef(), nullptr, /*IsPerformingImport=*/true)) - report_fatal_error(Twine("Function Import: link error: ") + - toString(std::move(Err))); + return createStringError(errc::invalid_argument, + Twine("Function Import: link error: ") + + toString(std::move(Err))); ImportedCount += GlobalsToImport.size(); NumImportedModules++; diff --git a/llvm/test/Transforms/FunctionImport/module-flags.ll b/llvm/test/Transforms/FunctionImport/module-flags.ll new file mode 100644 index 0000000..662df30 --- /dev/null +++ b/llvm/test/Transforms/FunctionImport/module-flags.ll @@ -0,0 +1,33 @@ +; RUN: rm -rf %t && split-file %s %t && cd %t +; RUN: opt -module-summary 1.ll -o 1.bc +; RUN: opt -module-summary 2.ll -o 2.bc +; RUN: llvm-lto -thinlto -o 3 1.bc 2.bc +; RUN: opt -S -passes=function-import -summary-file 3.thinlto.bc 1.bc 2>&1 | FileCheck %s + +; CHECK: Function Import: link error: linking module flags 'Error': IDs have conflicting values in '2.bc' and '1.bc' + +;--- 1.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" + +define i32 @main() { +entry: + call void () @foo() + ret i32 0 +} + +declare void @foo() + +!llvm.module.flags = !{!0} +!0 = !{i32 1, !"Error", i32 0} + +;--- 2.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" + +define void @foo() { + ret void +} + +!llvm.module.flags = !{!0} +!0 = !{i32 1, !"Error", i32 1} -- 2.7.4