mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[PowerPC] Fix downcast from nullptr for target streamer
getTargetStreamer() might return null (e.g. when running inlined-strings.ll test), downcasting to a reference will be wrong. This is detectable with -fsanitize=null. Reviewed By: steven.zhang Differential Revision: https://reviews.llvm.org/D78686
This commit is contained in:
parent
cc12df82ea
commit
347f41d492
@ -1731,10 +1731,10 @@ bool PPCAsmParser::ParseDirectiveMachine(SMLoc L) {
|
|||||||
if (parseToken(AsmToken::EndOfStatement))
|
if (parseToken(AsmToken::EndOfStatement))
|
||||||
return addErrorSuffix(" in '.machine' directive");
|
return addErrorSuffix(" in '.machine' directive");
|
||||||
|
|
||||||
PPCTargetStreamer &TStreamer =
|
PPCTargetStreamer *TStreamer = static_cast<PPCTargetStreamer *>(
|
||||||
*static_cast<PPCTargetStreamer *>(
|
getParser().getStreamer().getTargetStreamer());
|
||||||
getParser().getStreamer().getTargetStreamer());
|
if (TStreamer != nullptr)
|
||||||
TStreamer.emitMachine(CPU);
|
TStreamer->emitMachine(CPU);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1773,10 +1773,10 @@ bool PPCAsmParser::ParseDirectiveAbiVersion(SMLoc L) {
|
|||||||
parseToken(AsmToken::EndOfStatement))
|
parseToken(AsmToken::EndOfStatement))
|
||||||
return addErrorSuffix(" in '.abiversion' directive");
|
return addErrorSuffix(" in '.abiversion' directive");
|
||||||
|
|
||||||
PPCTargetStreamer &TStreamer =
|
PPCTargetStreamer *TStreamer = static_cast<PPCTargetStreamer *>(
|
||||||
*static_cast<PPCTargetStreamer *>(
|
getParser().getStreamer().getTargetStreamer());
|
||||||
getParser().getStreamer().getTargetStreamer());
|
if (TStreamer != nullptr)
|
||||||
TStreamer.emitAbiVersion(AbiVersion);
|
TStreamer->emitAbiVersion(AbiVersion);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1796,10 +1796,10 @@ bool PPCAsmParser::ParseDirectiveLocalEntry(SMLoc L) {
|
|||||||
parseToken(AsmToken::EndOfStatement))
|
parseToken(AsmToken::EndOfStatement))
|
||||||
return addErrorSuffix(" in '.localentry' directive");
|
return addErrorSuffix(" in '.localentry' directive");
|
||||||
|
|
||||||
PPCTargetStreamer &TStreamer =
|
PPCTargetStreamer *TStreamer = static_cast<PPCTargetStreamer *>(
|
||||||
*static_cast<PPCTargetStreamer *>(
|
getParser().getStreamer().getTargetStreamer());
|
||||||
getParser().getStreamer().getTargetStreamer());
|
if (TStreamer != nullptr)
|
||||||
TStreamer.emitLocalEntry(Sym, Expr);
|
TStreamer->emitLocalEntry(Sym, Expr);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1396,8 +1396,8 @@ void PPCLinuxAsmPrinter::emitEndOfAsmFile(Module &M) {
|
|||||||
|
|
||||||
bool isPPC64 = DL.getPointerSizeInBits() == 64;
|
bool isPPC64 = DL.getPointerSizeInBits() == 64;
|
||||||
|
|
||||||
PPCTargetStreamer &TS =
|
PPCTargetStreamer *TS =
|
||||||
static_cast<PPCTargetStreamer &>(*OutStreamer->getTargetStreamer());
|
static_cast<PPCTargetStreamer *>(OutStreamer->getTargetStreamer());
|
||||||
|
|
||||||
if (!TOC.empty()) {
|
if (!TOC.empty()) {
|
||||||
const char *Name = isPPC64 ? ".toc" : ".got2";
|
const char *Name = isPPC64 ? ".toc" : ".got2";
|
||||||
@ -1412,8 +1412,8 @@ void PPCLinuxAsmPrinter::emitEndOfAsmFile(Module &M) {
|
|||||||
MCSymbol *const TOCEntryLabel = TOCMapPair.second;
|
MCSymbol *const TOCEntryLabel = TOCMapPair.second;
|
||||||
|
|
||||||
OutStreamer->emitLabel(TOCEntryLabel);
|
OutStreamer->emitLabel(TOCEntryLabel);
|
||||||
if (isPPC64)
|
if (isPPC64 && TS != nullptr)
|
||||||
TS.emitTCEntry(*TOCEntryTarget);
|
TS->emitTCEntry(*TOCEntryTarget);
|
||||||
else
|
else
|
||||||
OutStreamer->emitSymbolValue(TOCEntryTarget, 4);
|
OutStreamer->emitSymbolValue(TOCEntryTarget, 4);
|
||||||
}
|
}
|
||||||
@ -1687,8 +1687,8 @@ void PPCAIXAsmPrinter::emitEndOfAsmFile(Module &M) {
|
|||||||
// Switch to section to emit TOC base.
|
// Switch to section to emit TOC base.
|
||||||
OutStreamer->SwitchSection(getObjFileLowering().getTOCBaseSection());
|
OutStreamer->SwitchSection(getObjFileLowering().getTOCBaseSection());
|
||||||
|
|
||||||
PPCTargetStreamer &TS =
|
PPCTargetStreamer *TS =
|
||||||
static_cast<PPCTargetStreamer &>(*OutStreamer->getTargetStreamer());
|
static_cast<PPCTargetStreamer *>(OutStreamer->getTargetStreamer());
|
||||||
|
|
||||||
const unsigned EntryByteSize = Subtarget->isPPC64() ? 8 : 4;
|
const unsigned EntryByteSize = Subtarget->isPPC64() ? 8 : 4;
|
||||||
const unsigned TOCEntriesByteSize = TOC.size() * EntryByteSize;
|
const unsigned TOCEntriesByteSize = TOC.size() * EntryByteSize;
|
||||||
@ -1707,7 +1707,8 @@ void PPCAIXAsmPrinter::emitEndOfAsmFile(Module &M) {
|
|||||||
OutStreamer->SwitchSection(TCEntry);
|
OutStreamer->SwitchSection(TCEntry);
|
||||||
|
|
||||||
OutStreamer->emitLabel(I.second);
|
OutStreamer->emitLabel(I.second);
|
||||||
TS.emitTCEntry(*I.first);
|
if (TS != nullptr)
|
||||||
|
TS->emitTCEntry(*I.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
; RUN: llc -verify-machineinstrs -code-model=small < %s | FileCheck %s
|
; 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 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"
|
target triple = "powerpc64-unknown-linux-gnu"
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# RUN: llvm-mc -triple powerpc-unknown-unknown %s
|
# RUN: llvm-mc -triple powerpc-unknown-unknown %s
|
||||||
# RUN: llvm-mc -triple powerpc64-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 %s
|
||||||
|
# RUN: llvm-mc -triple powerpc64le-unknown-unknown -filetype=null %s
|
||||||
|
|
||||||
# For now, the only thing we check is that the .machine directive
|
# For now, the only thing we check is that the .machine directive
|
||||||
# is accepted without syntax error.
|
# is accepted without syntax error.
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
# RUN: llvm-readobj -h | FileCheck %s
|
# RUN: llvm-readobj -h | FileCheck %s
|
||||||
# RUN: llvm-mc -triple powerpc64le-unknown-unknown -filetype=obj %s | \
|
# RUN: llvm-mc -triple powerpc64le-unknown-unknown -filetype=obj %s | \
|
||||||
# RUN: llvm-readobj -h | FileCheck %s
|
# RUN: llvm-readobj -h | FileCheck %s
|
||||||
|
# RUN: llvm-mc -triple powerpc64le-unknown-unknown -filetype=null %s
|
||||||
|
|
||||||
.abiversion 2
|
.abiversion 2
|
||||||
# CHECK: Flags [ (0x2)
|
# CHECK: Flags [ (0x2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user