Skip to content

Commit 8783ea0

Browse files
committed
Fix destructor for interpreter for the cuda negation case
1 parent c51be1b commit 8783ea0

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

clang/include/clang/Interpreter/Interpreter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ class Interpreter {
116116
/// Compiler instance performing the incremental compilation.
117117
std::unique_ptr<CompilerInstance> CI;
118118

119+
/// An optional compiler instance for CUDA offloading
120+
std::unique_ptr<CompilerInstance> DeviceCI;
121+
119122
protected:
120123
// Derived classes can use an extended interface of the Interpreter.
121124
Interpreter(std::unique_ptr<CompilerInstance> Instance, llvm::Error &Err,

clang/lib/Interpreter/DeviceOffload.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
namespace clang {
2626

2727
IncrementalCUDADeviceParser::IncrementalCUDADeviceParser(
28-
std::unique_ptr<CompilerInstance> DeviceInstance,
28+
CompilerInstance &DeviceInstance,
2929
CompilerInstance &HostInstance,
3030
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS,
3131
llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs)
32-
: IncrementalParser(*DeviceInstance, Err), PTUs(PTUs), VFS(FS),
32+
: IncrementalParser(DeviceInstance, Err), PTUs(PTUs), VFS(FS),
3333
CodeGenOpts(HostInstance.getCodeGenOpts()),
34-
TargetOpts(DeviceInstance->getTargetOpts()) {
34+
TargetOpts(DeviceInstance.getTargetOpts()) {
3535
if (Err)
3636
return;
3737
StringRef Arch = TargetOpts.CPU;
@@ -41,7 +41,6 @@ IncrementalCUDADeviceParser::IncrementalCUDADeviceParser(
4141
llvm::inconvertibleErrorCode()));
4242
return;
4343
}
44-
DeviceCI = std::move(DeviceInstance);
4544
}
4645

4746
llvm::Expected<llvm::StringRef> IncrementalCUDADeviceParser::GeneratePTX() {

clang/lib/Interpreter/DeviceOffload.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class IncrementalCUDADeviceParser : public IncrementalParser {
2828

2929
public:
3030
IncrementalCUDADeviceParser(
31-
std::unique_ptr<CompilerInstance> DeviceInstance,
31+
CompilerInstance &DeviceInstance,
3232
CompilerInstance &HostInstance,
3333
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS,
3434
llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs);
@@ -42,7 +42,6 @@ class IncrementalCUDADeviceParser : public IncrementalParser {
4242
~IncrementalCUDADeviceParser();
4343

4444
protected:
45-
std::unique_ptr<CompilerInstance> DeviceCI;
4645
int SMVersion;
4746
llvm::SmallString<1024> PTXCode;
4847
llvm::SmallVector<char, 1024> FatbinContent;

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ Interpreter::Interpreter(std::unique_ptr<CompilerInstance> Instance,
416416
Interpreter::~Interpreter() {
417417
IncrParser.reset();
418418
Act->FinalizeAction();
419+
if (DeviceParser)
420+
DeviceParser.reset();
421+
if (DeviceAct)
422+
DeviceAct->FinalizeAction();
419423
if (IncrExecutor) {
420424
if (llvm::Error Err = IncrExecutor->cleanUp())
421425
llvm::report_fatal_error(
@@ -501,8 +505,10 @@ Interpreter::createWithCUDA(std::unique_ptr<CompilerInstance> CI,
501505

502506
DCI->ExecuteAction(*Interp->DeviceAct);
503507

508+
Interp->DeviceCI = std::move(DCI);
509+
504510
auto DeviceParser = std::make_unique<IncrementalCUDADeviceParser>(
505-
std::move(DCI), *Interp->getCompilerInstance(), IMVFS, Err, Interp->PTUs);
511+
*Interp->DeviceCI, *Interp->getCompilerInstance(), IMVFS, Err, Interp->PTUs);
506512

507513
if (Err)
508514
return std::move(Err);

0 commit comments

Comments
 (0)