Skip to content

Commit c04d9d5

Browse files
authored
MCAsmStreamer: Replace the MCInstPrinter * parameter with unique_ptr
... to clarify ownership, aligning with other parameters. Using `std::unique_ptr` encourages users to manage `createMCInstPrinter` with a unique_ptr instead of a raw pointer, reducing the risk of memory leaks. * llvm-mc: fix a leak and update llvm/test/tools/llvm-mc/disassembler-options.test * llvm#121078 copied the llvm-mc code to CodeGenTargetMachineImpl and made the same mistake. Fixed by 2b8cc65 Using unique_ptr requires #include MCInstPrinter.h in a few translation units. * Delete a createAsmStreamer overload I deprecated in 2024 * SystemZMCTargetDesc.cpp: rename to `createSystemZAsmStreamer` to fix an overload conflict. Pull Request: llvm#135128
1 parent ba93fe9 commit c04d9d5

File tree

15 files changed

+80
-71
lines changed

15 files changed

+80
-71
lines changed

bolt/lib/Passes/AsmDump.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,14 @@ void dumpFunction(const BinaryFunction &BF) {
134134
std::unique_ptr<MCAsmBackend> MAB(
135135
BC.TheTarget->createMCAsmBackend(*BC.STI, *BC.MRI, MCTargetOptions()));
136136
int AsmPrinterVariant = BC.AsmInfo->getAssemblerDialect();
137-
MCInstPrinter *InstructionPrinter(BC.TheTarget->createMCInstPrinter(
138-
*BC.TheTriple, AsmPrinterVariant, *BC.AsmInfo, *BC.MII, *BC.MRI));
137+
std::unique_ptr<MCInstPrinter> InstructionPrinter(
138+
BC.TheTarget->createMCInstPrinter(*BC.TheTriple, AsmPrinterVariant,
139+
*BC.AsmInfo, *BC.MII, *BC.MRI));
139140
auto FOut = std::make_unique<formatted_raw_ostream>(OS);
140141
FOut->SetUnbuffered();
141-
std::unique_ptr<MCStreamer> AsmStreamer(
142-
createAsmStreamer(*LocalCtx, std::move(FOut), InstructionPrinter,
143-
std::move(MCEInstance.MCE), std::move(MAB)));
142+
std::unique_ptr<MCStreamer> AsmStreamer(createAsmStreamer(
143+
*LocalCtx, std::move(FOut), std::move(InstructionPrinter),
144+
std::move(MCEInstance.MCE), std::move(MAB)));
144145
AsmStreamer->initSections(true, *BC.STI);
145146
std::unique_ptr<TargetMachine> TM(BC.TheTarget->createTargetMachine(
146147
*BC.TheTriple, "", "", TargetOptions(), std::nullopt));

clang/tools/driver/cc1as_main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm/MC/MCAsmInfo.h"
2727
#include "llvm/MC/MCCodeEmitter.h"
2828
#include "llvm/MC/MCContext.h"
29+
#include "llvm/MC/MCInstPrinter.h"
2930
#include "llvm/MC/MCInstrInfo.h"
3031
#include "llvm/MC/MCObjectFileInfo.h"
3132
#include "llvm/MC/MCObjectWriter.h"
@@ -541,8 +542,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
541542

542543
// FIXME: There is a bit of code duplication with addPassesToEmitFile.
543544
if (Opts.OutputType == AssemblerInvocation::FT_Asm) {
544-
MCInstPrinter *IP = TheTarget->createMCInstPrinter(
545-
llvm::Triple(Opts.Triple), Opts.OutputAsmVariant, *MAI, *MCII, *MRI);
545+
std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
546+
llvm::Triple(Opts.Triple), Opts.OutputAsmVariant, *MAI, *MCII, *MRI));
546547

547548
std::unique_ptr<MCCodeEmitter> CE;
548549
if (Opts.ShowEncoding)
@@ -551,7 +552,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
551552
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
552553

553554
auto FOut = std::make_unique<formatted_raw_ostream>(*Out);
554-
Str.reset(TheTarget->createAsmStreamer(Ctx, std::move(FOut), IP,
555+
Str.reset(TheTarget->createAsmStreamer(Ctx, std::move(FOut), std::move(IP),
555556
std::move(CE), std::move(MAB)));
556557
} else if (Opts.OutputType == AssemblerInvocation::FT_Null) {
557558
Str.reset(createNullStreamer(Ctx));

llvm/include/llvm/DWARFLinker/Classic/DWARFStreamer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ class DwarfStreamer : public DwarfEmitter {
286286
MCAsmBackend *MAB; // Owned by MCStreamer
287287
std::unique_ptr<MCInstrInfo> MII;
288288
std::unique_ptr<MCSubtargetInfo> MSTI;
289-
MCInstPrinter *MIP; // Owned by AsmPrinter
290289
MCCodeEmitter *MCE; // Owned by MCStreamer
291290
MCStreamer *MS; // Owned by AsmPrinter
292291
std::unique_ptr<TargetMachine> TM;

llvm/include/llvm/MC/TargetRegistry.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ MCStreamer *createNullStreamer(MCContext &Ctx);
8484
///
8585
/// \param ShowInst - Whether to show the MCInst representation inline with
8686
/// the assembly.
87-
MCStreamer *
88-
createAsmStreamer(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
89-
MCInstPrinter *InstPrint, std::unique_ptr<MCCodeEmitter> &&CE,
90-
std::unique_ptr<MCAsmBackend> &&TAB);
87+
MCStreamer *createAsmStreamer(MCContext &Ctx,
88+
std::unique_ptr<formatted_raw_ostream> OS,
89+
std::unique_ptr<MCInstPrinter> InstPrint,
90+
std::unique_ptr<MCCodeEmitter> CE,
91+
std::unique_ptr<MCAsmBackend> TAB);
9192

9293
MCStreamer *createELFStreamer(MCContext &Ctx,
9394
std::unique_ptr<MCAsmBackend> &&TAB,
@@ -208,10 +209,10 @@ class Target {
208209
using AsmTargetStreamerCtorTy =
209210
MCTargetStreamer *(*)(MCStreamer &S, formatted_raw_ostream &OS,
210211
MCInstPrinter *InstPrint);
211-
using AsmStreamerCtorTy =
212-
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
213-
MCInstPrinter *IP, std::unique_ptr<MCCodeEmitter> CE,
214-
std::unique_ptr<MCAsmBackend> TAB);
212+
using AsmStreamerCtorTy = MCStreamer
213+
*(*)(MCContext & Ctx, std::unique_ptr<formatted_raw_ostream> OS,
214+
std::unique_ptr<MCInstPrinter> IP, std::unique_ptr<MCCodeEmitter> CE,
215+
std::unique_ptr<MCAsmBackend> TAB);
215216
using ObjectTargetStreamerCtorTy =
216217
MCTargetStreamer *(*)(MCStreamer &S, const MCSubtargetInfo &STI);
217218
using MCRelocationInfoCtorTy = MCRelocationInfo *(*)(const Triple &TT,
@@ -552,7 +553,7 @@ class Target {
552553

553554
MCStreamer *createAsmStreamer(MCContext &Ctx,
554555
std::unique_ptr<formatted_raw_ostream> OS,
555-
MCInstPrinter *IP,
556+
std::unique_ptr<MCInstPrinter> IP,
556557
std::unique_ptr<MCCodeEmitter> CE,
557558
std::unique_ptr<MCAsmBackend> TAB) const;
558559

llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,13 @@ CodeGenTargetMachineImpl::createMCStreamer(raw_pwrite_stream &Out,
162162

163163
switch (FileType) {
164164
case CodeGenFileType::AssemblyFile: {
165-
MCInstPrinter *InstPrinter = getTarget().createMCInstPrinter(
165+
std::unique_ptr<MCInstPrinter> InstPrinter(getTarget().createMCInstPrinter(
166166
getTargetTriple(),
167167
Options.MCOptions.OutputAsmVariant.value_or(MAI.getAssemblerDialect()),
168-
MAI, MII, MRI);
169-
for (StringRef Opt : Options.MCOptions.InstPrinterOptions) {
170-
if (!InstPrinter->applyTargetSpecificCLOption(Opt)) {
171-
delete InstPrinter;
168+
MAI, MII, MRI));
169+
for (StringRef Opt : Options.MCOptions.InstPrinterOptions)
170+
if (!InstPrinter->applyTargetSpecificCLOption(Opt))
172171
return createStringError("invalid InstPrinter option '" + Opt + "'");
173-
}
174-
}
175172

176173
// Create a code emitter if asked to show the encoding.
177174
std::unique_ptr<MCCodeEmitter> MCE;
@@ -182,7 +179,8 @@ CodeGenTargetMachineImpl::createMCStreamer(raw_pwrite_stream &Out,
182179
getTarget().createMCAsmBackend(STI, MRI, Options.MCOptions));
183180
auto FOut = std::make_unique<formatted_raw_ostream>(Out);
184181
MCStreamer *S = getTarget().createAsmStreamer(
185-
Context, std::move(FOut), InstPrinter, std::move(MCE), std::move(MAB));
182+
Context, std::move(FOut), std::move(InstPrinter), std::move(MCE),
183+
std::move(MAB));
186184
AsmStreamer.reset(S);
187185
break;
188186
}

llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "llvm/MC/MCAsmBackend.h"
1515
#include "llvm/MC/MCCodeEmitter.h"
1616
#include "llvm/MC/MCDwarf.h"
17+
#include "llvm/MC/MCInstPrinter.h"
1718
#include "llvm/MC/MCObjectWriter.h"
1819
#include "llvm/MC/MCSection.h"
1920
#include "llvm/MC/MCStreamer.h"
@@ -100,10 +101,10 @@ Error DwarfStreamer::init(Triple TheTriple,
100101

101102
switch (OutFileType) {
102103
case DWARFLinker::OutputFileType::Assembly: {
103-
MIP = TheTarget->createMCInstPrinter(TheTriple, MAI->getAssemblerDialect(),
104-
*MAI, *MII, *MRI);
104+
std::unique_ptr<MCInstPrinter> MIP(TheTarget->createMCInstPrinter(
105+
TheTriple, MAI->getAssemblerDialect(), *MAI, *MII, *MRI));
105106
MS = TheTarget->createAsmStreamer(
106-
*MC, std::make_unique<formatted_raw_ostream>(OutFile), MIP,
107+
*MC, std::make_unique<formatted_raw_ostream>(OutFile), std::move(MIP),
107108
std::unique_ptr<MCCodeEmitter>(MCE),
108109
std::unique_ptr<MCAsmBackend>(MAB));
109110
break;

llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "DWARFLinkerCompileUnit.h"
1111
#include "llvm/MC/MCAsmBackend.h"
1212
#include "llvm/MC/MCCodeEmitter.h"
13+
#include "llvm/MC/MCInstPrinter.h"
1314
#include "llvm/MC/MCObjectWriter.h"
1415
#include "llvm/MC/MCSubtargetInfo.h"
1516
#include "llvm/MC/MCTargetOptions.h"
@@ -79,10 +80,10 @@ Error DwarfEmitterImpl::init(Triple TheTriple,
7980

8081
switch (OutFileType) {
8182
case DWARFLinker::OutputFileType::Assembly: {
82-
MIP = TheTarget->createMCInstPrinter(TheTriple, MAI->getAssemblerDialect(),
83-
*MAI, *MII, *MRI);
83+
std::unique_ptr<MCInstPrinter> MIP(TheTarget->createMCInstPrinter(
84+
TheTriple, MAI->getAssemblerDialect(), *MAI, *MII, *MRI));
8485
MS = TheTarget->createAsmStreamer(
85-
*MC, std::make_unique<formatted_raw_ostream>(OutFile), MIP,
86+
*MC, std::make_unique<formatted_raw_ostream>(OutFile), std::move(MIP),
8687
std::unique_ptr<MCCodeEmitter>(MCE),
8788
std::unique_ptr<MCAsmBackend>(MAB));
8889
break;

llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/DWARFLinker/Parallel/DWARFLinker.h"
1717
#include "llvm/MC/MCAsmInfo.h"
1818
#include "llvm/MC/MCContext.h"
19+
#include "llvm/MC/MCInstPrinter.h"
1920
#include "llvm/MC/MCInstrInfo.h"
2021
#include "llvm/MC/MCObjectFileInfo.h"
2122
#include "llvm/MC/MCRegisterInfo.h"
@@ -110,7 +111,7 @@ class DwarfEmitterImpl {
110111
MCAsmBackend *MAB; // Owned by MCStreamer
111112
std::unique_ptr<MCInstrInfo> MII;
112113
std::unique_ptr<MCSubtargetInfo> MSTI;
113-
MCInstPrinter *MIP; // Owned by AsmPrinter
114+
std::unique_ptr<MCInstPrinter> MIP; // Owned by AsmPrinter
114115
MCCodeEmitter *MCE; // Owned by MCStreamer
115116
MCStreamer *MS; // Owned by AsmPrinter
116117
std::unique_ptr<TargetMachine> TM;

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ class MCAsmStreamer final : public MCStreamer {
7474

7575
public:
7676
MCAsmStreamer(MCContext &Context, std::unique_ptr<formatted_raw_ostream> os,
77-
MCInstPrinter *printer, std::unique_ptr<MCCodeEmitter> emitter,
77+
std::unique_ptr<MCInstPrinter> printer,
78+
std::unique_ptr<MCCodeEmitter> emitter,
7879
std::unique_ptr<MCAsmBackend> asmbackend)
7980
: MCStreamer(Context), OSOwner(std::move(os)), OS(*OSOwner),
80-
MAI(Context.getAsmInfo()), InstPrinter(printer),
81+
MAI(Context.getAsmInfo()), InstPrinter(std::move(printer)),
8182
Assembler(std::make_unique<MCAssembler>(
8283
Context, std::move(asmbackend), std::move(emitter),
8384
(asmbackend) ? asmbackend->createObjectWriter(NullStream)
@@ -2649,9 +2650,9 @@ void MCAsmStreamer::emitDwarfAdvanceLineAddr(int64_t LineDelta,
26492650

26502651
MCStreamer *llvm::createAsmStreamer(MCContext &Context,
26512652
std::unique_ptr<formatted_raw_ostream> OS,
2652-
MCInstPrinter *IP,
2653-
std::unique_ptr<MCCodeEmitter> &&CE,
2654-
std::unique_ptr<MCAsmBackend> &&MAB) {
2655-
return new MCAsmStreamer(Context, std::move(OS), IP, std::move(CE),
2653+
std::unique_ptr<MCInstPrinter> IP,
2654+
std::unique_ptr<MCCodeEmitter> CE,
2655+
std::unique_ptr<MCAsmBackend> MAB) {
2656+
return new MCAsmStreamer(Context, std::move(OS), std::move(IP), std::move(CE),
26562657
std::move(MAB));
26572658
}

llvm/lib/MC/TargetRegistry.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "llvm/MC/MCAsmBackend.h"
1313
#include "llvm/MC/MCCodeEmitter.h"
1414
#include "llvm/MC/MCContext.h"
15+
#include "llvm/MC/MCInstPrinter.h"
1516
#include "llvm/MC/MCObjectStreamer.h"
1617
#include "llvm/MC/MCObjectWriter.h"
1718
#include "llvm/Support/raw_ostream.h"
@@ -79,19 +80,20 @@ MCStreamer *Target::createMCObjectStreamer(
7980

8081
MCStreamer *Target::createAsmStreamer(MCContext &Ctx,
8182
std::unique_ptr<formatted_raw_ostream> OS,
82-
MCInstPrinter *IP,
83+
std::unique_ptr<MCInstPrinter> IP,
8384
std::unique_ptr<MCCodeEmitter> CE,
8485
std::unique_ptr<MCAsmBackend> TAB) const {
86+
MCInstPrinter *Printer = IP.get();
8587
formatted_raw_ostream &OSRef = *OS;
8688
MCStreamer *S;
8789
if (AsmStreamerCtorFn)
88-
S = AsmStreamerCtorFn(Ctx, std::move(OS), IP, std::move(CE),
90+
S = AsmStreamerCtorFn(Ctx, std::move(OS), std::move(IP), std::move(CE),
8991
std::move(TAB));
9092
else
91-
S = llvm::createAsmStreamer(Ctx, std::move(OS), IP, std::move(CE),
92-
std::move(TAB));
93+
S = llvm::createAsmStreamer(Ctx, std::move(OS), std::move(IP),
94+
std::move(CE), std::move(TAB));
9395

94-
createAsmTargetStreamer(*S, OSRef, IP);
96+
createAsmTargetStreamer(*S, OSRef, Printer);
9597
return S;
9698
}
9799

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ class SystemZHLASMAsmStreamer final : public MCStreamer {
4646
public:
4747
SystemZHLASMAsmStreamer(MCContext &Context,
4848
std::unique_ptr<formatted_raw_ostream> os,
49-
MCInstPrinter *printer,
49+
std::unique_ptr<MCInstPrinter> printer,
5050
std::unique_ptr<MCCodeEmitter> emitter,
5151
std::unique_ptr<MCAsmBackend> asmbackend)
5252
: MCStreamer(Context), FOSOwner(std::move(os)), FOS(*FOSOwner), OS(Str),
53-
MAI(Context.getAsmInfo()), InstPrinter(printer),
53+
MAI(Context.getAsmInfo()), InstPrinter(std::move(printer)),
5454
Assembler(std::make_unique<MCAssembler>(
5555
Context, std::move(asmbackend), std::move(emitter),
5656
(asmbackend) ? asmbackend->createObjectWriter(NullStream)

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,18 @@ static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
192192
return new SystemZTargetGNUStreamer(S, OS);
193193
}
194194

195-
static MCStreamer *createAsmStreamer(MCContext &Ctx,
196-
std::unique_ptr<formatted_raw_ostream> OS,
197-
MCInstPrinter *IP,
198-
std::unique_ptr<MCCodeEmitter> CE,
199-
std::unique_ptr<MCAsmBackend> TAB) {
195+
static MCStreamer *createSystemZAsmStreamer(
196+
MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
197+
std::unique_ptr<MCInstPrinter> IP, std::unique_ptr<MCCodeEmitter> CE,
198+
std::unique_ptr<MCAsmBackend> TAB) {
200199

201200
auto TT = Ctx.getTargetTriple();
202201
if (TT.isOSzOS() && !GNUAsOnzOSCL)
203-
return new SystemZHLASMAsmStreamer(Ctx, std::move(OS), IP, std::move(CE),
204-
std::move(TAB));
202+
return new SystemZHLASMAsmStreamer(Ctx, std::move(OS), std::move(IP),
203+
std::move(CE), std::move(TAB));
205204

206-
return llvm::createAsmStreamer(Ctx, std::move(OS), IP, std::move(CE),
207-
std::move(TAB));
205+
return llvm::createAsmStreamer(Ctx, std::move(OS), std::move(IP),
206+
std::move(CE), std::move(TAB));
208207
}
209208

210209
static MCTargetStreamer *
@@ -254,7 +253,8 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSystemZTargetMC() {
254253
createSystemZMCInstPrinter);
255254

256255
// Register the asm streamer.
257-
TargetRegistry::RegisterAsmStreamer(getTheSystemZTarget(), createAsmStreamer);
256+
TargetRegistry::RegisterAsmStreamer(getTheSystemZTarget(),
257+
createSystemZAsmStreamer);
258258

259259
// Register the asm target streamer.
260260
TargetRegistry::RegisterAsmTargetStreamer(getTheSystemZTarget(),
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# RUN: export LSAN_OPTIONS=detect_leaks=0
21
# RUN: not llvm-mc -M invalid /dev/null 2>&1 | FileCheck %s
32

43
# CHECK: error: invalid InstPrinter option 'invalid'

llvm/tools/llvm-mc/llvm-mc.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,10 @@ int main(int argc, char **argv) {
519519
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
520520
assert(MCII && "Unable to create instruction info!");
521521

522-
MCInstPrinter *IP = nullptr;
522+
std::unique_ptr<MCInstPrinter> IP;
523523
if (FileType == OFT_AssemblyFile) {
524-
IP = TheTarget->createMCInstPrinter(Triple(TripleName), OutputAsmVariant,
525-
*MAI, *MCII, *MRI);
524+
IP.reset(TheTarget->createMCInstPrinter(
525+
Triple(TripleName), OutputAsmVariant, *MAI, *MCII, *MRI));
526526

527527
if (!IP) {
528528
WithColor::error()
@@ -541,6 +541,17 @@ int main(int argc, char **argv) {
541541
// Set the display preference for hex vs. decimal immediates.
542542
IP->setPrintImmHex(PrintImmHex);
543543

544+
switch (Action) {
545+
case AC_MDisassemble:
546+
IP->setUseMarkup(true);
547+
break;
548+
case AC_CDisassemble:
549+
IP->setUseColor(true);
550+
break;
551+
default:
552+
break;
553+
}
554+
544555
// Set up the AsmStreamer.
545556
std::unique_ptr<MCCodeEmitter> CE;
546557
if (ShowEncoding)
@@ -549,7 +560,7 @@ int main(int argc, char **argv) {
549560
std::unique_ptr<MCAsmBackend> MAB(
550561
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
551562
auto FOut = std::make_unique<formatted_raw_ostream>(*OS);
552-
Str.reset(TheTarget->createAsmStreamer(Ctx, std::move(FOut), IP,
563+
Str.reset(TheTarget->createAsmStreamer(Ctx, std::move(FOut), std::move(IP),
553564
std::move(CE), std::move(MAB)));
554565

555566
} else if (FileType == OFT_Null) {
@@ -586,13 +597,7 @@ int main(int argc, char **argv) {
586597
*MCII, MCOptions);
587598
break;
588599
case AC_MDisassemble:
589-
IP->setUseMarkup(true);
590-
disassemble = true;
591-
break;
592600
case AC_CDisassemble:
593-
IP->setUseColor(true);
594-
disassemble = true;
595-
break;
596601
case AC_Disassemble:
597602
disassemble = true;
598603
break;

llvm/tools/llvm-ml/llvm-ml.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,12 @@ int llvm_ml_main(int Argc, char **Argv, const llvm::ToolContext &) {
363363
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
364364
assert(MCII && "Unable to create instruction info!");
365365

366-
MCInstPrinter *IP = nullptr;
367366
if (FileType == "s") {
368367
const bool OutputATTAsm = InputArgs.hasArg(OPT_output_att_asm);
369368
const unsigned OutputAsmVariant = OutputATTAsm ? 0U // ATT dialect
370369
: 1U; // Intel dialect
371-
IP = TheTarget->createMCInstPrinter(TheTriple, OutputAsmVariant, *MAI,
372-
*MCII, *MRI);
370+
std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
371+
TheTriple, OutputAsmVariant, *MAI, *MCII, *MRI));
373372

374373
if (!IP) {
375374
WithColor::error()
@@ -390,7 +389,7 @@ int llvm_ml_main(int Argc, char **Argv, const llvm::ToolContext &) {
390389
std::unique_ptr<MCAsmBackend> MAB(
391390
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
392391
auto FOut = std::make_unique<formatted_raw_ostream>(*OS);
393-
Str.reset(TheTarget->createAsmStreamer(Ctx, std::move(FOut), IP,
392+
Str.reset(TheTarget->createAsmStreamer(Ctx, std::move(FOut), std::move(IP),
394393
std::move(CE), std::move(MAB)));
395394

396395
} else if (FileType == "null") {

0 commit comments

Comments
 (0)