From 3bb12d3005ffdf5b2b34d4a84008e50ef4577e46 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Sat, 29 Oct 2022 12:55:57 -0700 Subject: [PATCH] XCore: Register null MCTargetStreamer Fixes null dereference when printing globals --- llvm/lib/Target/XCore/MCTargetDesc/XCoreMCTargetDesc.cpp | 7 +++++++ llvm/lib/Target/XCore/XCoreTargetStreamer.h | 8 ++++---- llvm/test/CodeGen/XCore/globals.ll | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Target/XCore/MCTargetDesc/XCoreMCTargetDesc.cpp b/llvm/lib/Target/XCore/MCTargetDesc/XCoreMCTargetDesc.cpp index a782ff4..bc69e18 100644 --- a/llvm/lib/Target/XCore/MCTargetDesc/XCoreMCTargetDesc.cpp +++ b/llvm/lib/Target/XCore/MCTargetDesc/XCoreMCTargetDesc.cpp @@ -122,6 +122,10 @@ static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S, return new XCoreTargetAsmStreamer(S, OS); } +static MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) { + return new XCoreTargetStreamer(S); +} + // Force static initialization. extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeXCoreTargetMC() { // Register the MC asm info. @@ -145,4 +149,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeXCoreTargetMC() { TargetRegistry::RegisterAsmTargetStreamer(getTheXCoreTarget(), createTargetAsmStreamer); + + TargetRegistry::RegisterNullTargetStreamer(getTheXCoreTarget(), + createNullTargetStreamer); } diff --git a/llvm/lib/Target/XCore/XCoreTargetStreamer.h b/llvm/lib/Target/XCore/XCoreTargetStreamer.h index 3543fc5..373f0d7 100644 --- a/llvm/lib/Target/XCore/XCoreTargetStreamer.h +++ b/llvm/lib/Target/XCore/XCoreTargetStreamer.h @@ -16,10 +16,10 @@ class XCoreTargetStreamer : public MCTargetStreamer { public: XCoreTargetStreamer(MCStreamer &S); ~XCoreTargetStreamer() override; - virtual void emitCCTopData(StringRef Name) = 0; - virtual void emitCCTopFunction(StringRef Name) = 0; - virtual void emitCCBottomData(StringRef Name) = 0; - virtual void emitCCBottomFunction(StringRef Name) = 0; + virtual void emitCCTopData(StringRef Name){}; + virtual void emitCCTopFunction(StringRef Name){}; + virtual void emitCCBottomData(StringRef Name){}; + virtual void emitCCBottomFunction(StringRef Name){}; }; } diff --git a/llvm/test/CodeGen/XCore/globals.ll b/llvm/test/CodeGen/XCore/globals.ll index c7eba78..5d626f9 100644 --- a/llvm/test/CodeGen/XCore/globals.ll +++ b/llvm/test/CodeGen/XCore/globals.ll @@ -1,4 +1,5 @@ ; RUN: llc < %s -march=xcore -mcpu=xs1b-generic | FileCheck %s +; RUN: llc -march=xcore -mcpu=xs1b-generic -filetype=null %s define i32 *@addr_G1() { entry: -- 2.7.4