Switch the code added in r173885 to use the new, shiny RTTI
authorChandler Carruth <chandlerc@gmail.com>
Thu, 31 Jan 2013 23:43:14 +0000 (23:43 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Thu, 31 Jan 2013 23:43:14 +0000 (23:43 +0000)
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
lib/Target/ARM/AsmParser/ARMAsmParser.cpp

index 577cdb09dbae36a8fe3e1df58784a56624148f5f..986dfb715ce58a77995510061486b8e566eb3b69 100644 (file)
@@ -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<MCELFStreamer &>(OutStreamer);
-    MES.getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
-  }
+  if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&OutStreamer))
+    MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
 }
 
 //===----------------------------------------------------------------------===//
index 77620e92189a4919091ec4c6f4822a43cf54e86f..106fd13c55f8073ab3e88c85cd5e9588e373588c 100644 (file)
@@ -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<MCELFStreamer &>(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<MCELFStreamer>(&Parser.getStreamer()))
+      MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
   }
 
   // Implementation of the MCTargetAsmParser interface: