mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-01 15:40:55 +03:00
Fix compilation with LLVM 14 (#3822)
This commit is contained in:
parent
613ed42dca
commit
1568d0cdca
13 changed files with 135 additions and 33 deletions
|
@ -152,28 +152,50 @@ void emitLLVMUsedArray(IRState &irs) {
|
|||
llvmUsed->setSection("llvm.metadata");
|
||||
}
|
||||
|
||||
bool inlineAsmDiagnostic(IRState* irs,const llvm::SMDiagnostic &d, unsigned locCookie)
|
||||
{
|
||||
if (!locCookie) {
|
||||
d.print(nullptr, llvm::errs());
|
||||
return true;
|
||||
}
|
||||
|
||||
// replace the `<inline asm>` dummy filename by the LOC of the actual D
|
||||
// expression/statement (`myfile.d(123)`)
|
||||
const Loc &loc = irs->getInlineAsmSrcLoc(locCookie);
|
||||
const char *filename = loc.toChars(/*showColumns*/ false);
|
||||
|
||||
// keep on using llvm::SMDiagnostic::print() for nice, colorful output
|
||||
llvm::SMDiagnostic d2(*d.getSourceMgr(), d.getLoc(), filename, d.getLineNo(),
|
||||
d.getColumnNo(), d.getKind(), d.getMessage(),
|
||||
d.getLineContents(), d.getRanges(), d.getFixIts());
|
||||
d2.print(nullptr, llvm::errs());
|
||||
return true;
|
||||
}
|
||||
|
||||
#if LDC_LLVM_VER < 1300
|
||||
void inlineAsmDiagnosticHandler(const llvm::SMDiagnostic &d, void *context,
|
||||
unsigned locCookie) {
|
||||
if (d.getKind() == llvm::SourceMgr::DK_Error)
|
||||
++global.errors;
|
||||
|
||||
if (!locCookie) {
|
||||
d.print(nullptr, llvm::errs());
|
||||
return;
|
||||
}
|
||||
|
||||
// replace the `<inline asm>` dummy filename by the LOC of the actual D
|
||||
// expression/statement (`myfile.d(123)`)
|
||||
const Loc &loc =
|
||||
static_cast<IRState *>(context)->getInlineAsmSrcLoc(locCookie);
|
||||
const char *filename = loc.toChars(/*showColumns*/ false);
|
||||
|
||||
// keep on using llvm::SMDiagnostic::print() for nice, colorful output
|
||||
llvm::SMDiagnostic d2(*d.getSourceMgr(), d.getLoc(), filename, d.getLineNo(),
|
||||
d.getColumnNo(), d.getKind(), d.getMessage(),
|
||||
d.getLineContents(), d.getRanges(), d.getFixIts());
|
||||
d2.print(nullptr, llvm::errs());
|
||||
inlineAsmDiagnostic(static_cast<IRState *>(context), d, locCookie);
|
||||
}
|
||||
#else
|
||||
struct InlineAsmDiagnosticHandler : public llvm::DiagnosticHandler {
|
||||
IRState *irs;
|
||||
InlineAsmDiagnosticHandler(IRState *irs) : irs(irs) {}
|
||||
|
||||
// return false to defer to LLVMContext::diagnose()
|
||||
bool handleDiagnostics(const llvm::DiagnosticInfo &DI) override {
|
||||
if (DI.getKind() != llvm::DK_SrcMgr)
|
||||
return false;
|
||||
|
||||
const auto &DISM = llvm::cast<llvm::DiagnosticInfoSrcMgr>(DI);
|
||||
if (DISM.getKind() == llvm::SourceMgr::DK_Error)
|
||||
++global.errors;
|
||||
return inlineAsmDiagnostic(irs, DISM.getSMDiag(), DISM.getLocCookie());
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
|
@ -265,7 +287,12 @@ void CodeGenerator::writeAndFreeLLModule(const char *filename) {
|
|||
llvm::Metadata *IdentNode[] = {llvm::MDString::get(ir_->context(), Version)};
|
||||
IdentMetadata->addOperand(llvm::MDNode::get(ir_->context(), IdentNode));
|
||||
|
||||
#if LDC_LLVM_VER < 1300
|
||||
context_.setInlineAsmDiagnosticHandler(inlineAsmDiagnosticHandler, ir_);
|
||||
#else
|
||||
context_.setDiagnosticHandler(
|
||||
std::make_unique<InlineAsmDiagnosticHandler>(ir_));
|
||||
#endif
|
||||
|
||||
std::unique_ptr<llvm::ToolOutputFile> diagnosticsOutputFile =
|
||||
createAndSetDiagnosticsOutputFile(*ir_, context_, filename);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue