From 27aacedf7d975243170206efb948a20d6fd4a2c1 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Thu, 31 Jan 2013 23:43:14 +0000 Subject: [PATCH] Switch the code added in r173885 to use the new, shiny RTTI infrastructure on MCStreamer to test for whether there is an MCELFStreamer object available. This is just a cleanup on the AsmPrinter side of things, moving ad-hoc tests of random APIs to a direct type query. But the AsmParser completely broken. There were no tests, it just blindly cast its streamer to an MCELFStreamer and started manipulating it. I don't have a test case -- this actually failed on LLVM's own regression test suite. Unfortunately the failure only appears when the stars, compilers, and runtime align to misbehave when we read a pointer to a formatted_raw_ostream as-if it were an MCAssembler. =/ UBSan would catch this immediately. Many thanks to Matt for doing about 80% of the debugging work here in GDB, Jim for helping to explain how exactly to fix this, and others for putting up with the hair pulling that ensued during debugging it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174118 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/ARMAsmPrinter.cpp | 8 ++------ lib/Target/ARM/AsmParser/ARMAsmParser.cpp | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/Target/ARM/ARMAsmPrinter.cpp b/lib/Target/ARM/ARMAsmPrinter.cpp index 577cdb09dba..986dfb715ce 100644 --- a/lib/Target/ARM/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/ARMAsmPrinter.cpp @@ -704,12 +704,8 @@ void ARMAsmPrinter::EmitEndOfAsmFile(Module &M) { // FIXME: This should eventually end up somewhere else where more // intelligent flag decisions can be made. For now we are just maintaining // the status quo for ARM and setting EF_ARM_EABI_VER5 as the default. - if (Subtarget->isTargetELF()) { - if (OutStreamer.hasRawTextSupport()) return; - - MCELFStreamer &MES = static_cast(OutStreamer); - MES.getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5); - } + if (MCELFStreamer *MES = dyn_cast(&OutStreamer)) + MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5); } //===----------------------------------------------------------------------===// diff --git a/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/lib/Target/ARM/AsmParser/ARMAsmParser.cpp index 77620e92189..106fd13c55f 100644 --- a/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ b/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -257,9 +257,9 @@ public: // Set ELF header flags. // FIXME: This should eventually end up somewhere else where more // intelligent flag decisions can be made. For now we are just maintaining - // the status quo for ARM and setting EF_ARM_EABI_VER5 as the default. - MCELFStreamer &MES = static_cast(Parser.getStreamer()); - MES.getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5); + // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default. + if (MCELFStreamer *MES = dyn_cast(&Parser.getStreamer())) + MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5); } // Implementation of the MCTargetAsmParser interface: -- 2.34.1