diff --git a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp --- a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp +++ b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp @@ -1731,10 +1731,10 @@ if (parseToken(AsmToken::EndOfStatement)) return addErrorSuffix(" in '.machine' directive"); - PPCTargetStreamer &TStreamer = - *static_cast( - getParser().getStreamer().getTargetStreamer()); - TStreamer.emitMachine(CPU); + PPCTargetStreamer *TStreamer = static_cast( + getParser().getStreamer().getTargetStreamer()); + if (TStreamer != nullptr) + TStreamer->emitMachine(CPU); return false; } @@ -1773,10 +1773,10 @@ parseToken(AsmToken::EndOfStatement)) return addErrorSuffix(" in '.abiversion' directive"); - PPCTargetStreamer &TStreamer = - *static_cast( - getParser().getStreamer().getTargetStreamer()); - TStreamer.emitAbiVersion(AbiVersion); + PPCTargetStreamer *TStreamer = static_cast( + getParser().getStreamer().getTargetStreamer()); + if (TStreamer != nullptr) + TStreamer->emitAbiVersion(AbiVersion); return false; } @@ -1796,10 +1796,10 @@ parseToken(AsmToken::EndOfStatement)) return addErrorSuffix(" in '.localentry' directive"); - PPCTargetStreamer &TStreamer = - *static_cast( - getParser().getStreamer().getTargetStreamer()); - TStreamer.emitLocalEntry(Sym, Expr); + PPCTargetStreamer *TStreamer = static_cast( + getParser().getStreamer().getTargetStreamer()); + if (TStreamer != nullptr) + TStreamer->emitLocalEntry(Sym, Expr); return false; } diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp --- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -1396,8 +1396,8 @@ bool isPPC64 = DL.getPointerSizeInBits() == 64; - PPCTargetStreamer &TS = - static_cast(*OutStreamer->getTargetStreamer()); + PPCTargetStreamer *TS = + static_cast(OutStreamer->getTargetStreamer()); if (!TOC.empty()) { const char *Name = isPPC64 ? ".toc" : ".got2"; @@ -1412,8 +1412,8 @@ MCSymbol *const TOCEntryLabel = TOCMapPair.second; OutStreamer->emitLabel(TOCEntryLabel); - if (isPPC64) - TS.emitTCEntry(*TOCEntryTarget); + if (isPPC64 && TS != nullptr) + TS->emitTCEntry(*TOCEntryTarget); else OutStreamer->emitSymbolValue(TOCEntryTarget, 4); } @@ -1687,8 +1687,8 @@ // Switch to section to emit TOC base. OutStreamer->SwitchSection(getObjFileLowering().getTOCBaseSection()); - PPCTargetStreamer &TS = - static_cast(*OutStreamer->getTargetStreamer()); + PPCTargetStreamer *TS = + static_cast(OutStreamer->getTargetStreamer()); const unsigned EntryByteSize = Subtarget->isPPC64() ? 8 : 4; const unsigned TOCEntriesByteSize = TOC.size() * EntryByteSize; @@ -1707,7 +1707,8 @@ OutStreamer->SwitchSection(TCEntry); OutStreamer->emitLabel(I.second); - TS.emitTCEntry(*I.first); + if (TS != nullptr) + TS->emitTCEntry(*I.first); } } diff --git a/llvm/test/CodeGen/PowerPC/ppc64-toc.ll b/llvm/test/CodeGen/PowerPC/ppc64-toc.ll --- a/llvm/test/CodeGen/PowerPC/ppc64-toc.ll +++ b/llvm/test/CodeGen/PowerPC/ppc64-toc.ll @@ -1,4 +1,6 @@ ; RUN: llc -verify-machineinstrs -code-model=small < %s | FileCheck %s +; Test with null streamer. +; RUN: llc -O0 -filetype=null < %s target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32:64" target triple = "powerpc64-unknown-linux-gnu" diff --git a/llvm/test/MC/PowerPC/ppc-machine.s b/llvm/test/MC/PowerPC/ppc-machine.s --- a/llvm/test/MC/PowerPC/ppc-machine.s +++ b/llvm/test/MC/PowerPC/ppc-machine.s @@ -1,6 +1,7 @@ # RUN: llvm-mc -triple powerpc-unknown-unknown %s # RUN: llvm-mc -triple powerpc64-unknown-unknown %s # RUN: llvm-mc -triple powerpc64le-unknown-unknown %s +# RUN: llvm-mc -triple powerpc64le-unknown-unknown -filetype=null %s # For now, the only thing we check is that the .machine directive # is accepted without syntax error. diff --git a/llvm/test/MC/PowerPC/ppc64-abiversion.s b/llvm/test/MC/PowerPC/ppc64-abiversion.s --- a/llvm/test/MC/PowerPC/ppc64-abiversion.s +++ b/llvm/test/MC/PowerPC/ppc64-abiversion.s @@ -3,6 +3,7 @@ # RUN: llvm-readobj -h | FileCheck %s # RUN: llvm-mc -triple powerpc64le-unknown-unknown -filetype=obj %s | \ # RUN: llvm-readobj -h | FileCheck %s +# RUN: llvm-mc -triple powerpc64le-unknown-unknown -filetype=null %s .abiversion 2 # CHECK: Flags [ (0x2)