From bd658f9fa5183ac996d3bd0f89eafbd4bc18bc42 Mon Sep 17 00:00:00 2001 From: evgeny Date: Wed, 26 Feb 2020 16:34:11 +0300 Subject: [PATCH] [Assembler] Allow assembling empty index with non-zero flags Differential revision: https://reviews.llvm.org/D74778 --- test/Assembler/summary-flags2.ll | 8 ++++++++ tools/llvm-as/llvm-as.cpp | 8 +++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 test/Assembler/summary-flags2.ll diff --git a/test/Assembler/summary-flags2.ll b/test/Assembler/summary-flags2.ll new file mode 100644 index 00000000000..8abca0ea9e5 --- /dev/null +++ b/test/Assembler/summary-flags2.ll @@ -0,0 +1,8 @@ +; Check that we can assemble/disassemble empty index with non-trivial flags +; RUN: llvm-as %s -o - | llvm-dis -o - | FileCheck %s + +; ModuleID = 'index.bc' +source_filename = "index.bc" + +^0 = flags: 2 +; CHECK: ^0 = flags: 2 diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp index c9f50e38fc6..0f6de69c10d 100644 --- a/tools/llvm-as/llvm-as.cpp +++ b/tools/llvm-as/llvm-as.cpp @@ -90,9 +90,11 @@ static void WriteOutputFile(const Module *M, const ModuleSummaryIndex *Index) { if (Force || !CheckBitcodeOutputToConsole(Out->os(), true)) { const ModuleSummaryIndex *IndexToWrite = nullptr; - // Don't attempt to write a summary index unless it contains any entries. - // Otherwise we get an empty summary section. - if (Index && Index->begin() != Index->end()) + // Don't attempt to write a summary index unless it contains any entries or + // has non-zero flags. The latter is used to assemble dummy index files for + // skipping modules by distributed ThinLTO backends. Otherwise we get an empty + // summary section. + if (Index && (Index->begin() != Index->end() || Index->getFlags())) IndexToWrite = Index; if (!IndexToWrite || (M && (!M->empty() || !M->global_empty()))) // If we have a non-empty Module, then we write the Module plus