From 99aabd70801bd4bc72c4942747f6d62c675112f5 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 25 Dec 2023 14:49:57 +0100 Subject: Vendor import of llvm-project main llvmorg-18-init-15692-g007ed0dccd6a. --- llvm/lib/Object/ModuleSymbolTable.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Object/ModuleSymbolTable.cpp') diff --git a/llvm/lib/Object/ModuleSymbolTable.cpp b/llvm/lib/Object/ModuleSymbolTable.cpp index ab073e18cb46..07f76688fa43 100644 --- a/llvm/lib/Object/ModuleSymbolTable.cpp +++ b/llvm/lib/Object/ModuleSymbolTable.cpp @@ -16,6 +16,7 @@ #include "RecordStreamer.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" +#include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalAlias.h" #include "llvm/IR/GlobalValue.h" @@ -68,6 +69,11 @@ void ModuleSymbolTable::addModule(Module *M) { static void initializeRecordStreamer(const Module &M, function_ref Init) { + // This function may be called twice, once for ModuleSummaryIndexAnalysis and + // the other when writing the IR symbol table. If parsing inline assembly has + // caused errors in the first run, suppress the second run. + if (M.getContext().getDiagHandlerPtr()->HasErrors) + return; StringRef InlineAsm = M.getModuleInlineAsm(); if (InlineAsm.empty()) return; @@ -95,7 +101,8 @@ initializeRecordStreamer(const Module &M, if (!MCII) return; - std::unique_ptr Buffer(MemoryBuffer::getMemBuffer(InlineAsm)); + std::unique_ptr Buffer( + MemoryBuffer::getMemBuffer(InlineAsm, "")); SourceMgr SrcMgr; SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc()); @@ -115,6 +122,13 @@ initializeRecordStreamer(const Module &M, if (!TAP) return; + MCCtx.setDiagnosticHandler([&](const SMDiagnostic &SMD, bool IsInlineAsm, + const SourceMgr &SrcMgr, + std::vector &LocInfos) { + M.getContext().diagnose( + DiagnosticInfoSrcMgr(SMD, M.getName(), IsInlineAsm, /*LocCookie=*/0)); + }); + // Module-level inline asm is assumed to use At&t syntax (see // AsmPrinter::doInitialization()). Parser->setAssemblerDialect(InlineAsm::AD_ATT); -- cgit v1.2.3