Skip to content

Commit

Permalink
fix an MCInstPrinter leak that jyasskin pointed out:
Browse files Browse the repository at this point in the history
createAsmStreamer now takes ownership of the instprinter.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98939 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
lattner committed Mar 19, 2010
1 parent 1e50631 commit 4c42a6d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion include/llvm/MC/MCStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ class TargetAsmBackend;
/// assembler.
///
/// \param InstPrint - If given, the instruction printer to use. If not given
/// the MCInst representation will be printed.
/// the MCInst representation will be printed. This method takes ownership of
/// InstPrint.
///
/// \param CE - If given, a code emitter to use to show the instruction
/// encoding inline with the assembly.
Expand Down
3 changes: 2 additions & 1 deletion lib/MC/MCAsmStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/ErrorHandling.h"
Expand All @@ -29,7 +30,7 @@ namespace {
class MCAsmStreamer : public MCStreamer {
formatted_raw_ostream &OS;
const MCAsmInfo &MAI;
MCInstPrinter *InstPrinter;
OwningPtr<MCInstPrinter> InstPrinter;
MCCodeEmitter *Emitter;

SmallString<128> CommentToEmit;
Expand Down
7 changes: 3 additions & 4 deletions tools/llvm-mc/llvm-mc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,17 @@ static int AssembleInput(const char *ProgName) {
return 1;
}

OwningPtr<MCInstPrinter> IP;
OwningPtr<MCCodeEmitter> CE;
OwningPtr<MCStreamer> Str;
OwningPtr<TargetAsmBackend> TAB;

if (FileType == OFT_AssemblyFile) {
IP.reset(TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI, *Out));
MCInstPrinter *IP =
TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI, *Out);
if (ShowEncoding)
CE.reset(TheTarget->createCodeEmitter(*TM, Ctx));
Str.reset(createAsmStreamer(Ctx, *Out,TM->getTargetData()->isLittleEndian(),
/*asmverbose*/true, IP.get(), CE.get(),
ShowInst));
/*asmverbose*/true, IP, CE.get(), ShowInst));
} else {
assert(FileType == OFT_ObjectFile && "Invalid file type!");
CE.reset(TheTarget->createCodeEmitter(*TM, Ctx));
Expand Down

0 comments on commit 4c42a6d

Please sign in to comment.