Skip to content

Commit aba1800

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

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

clang/include/clang/Interpreter/Interpreter.h

+3
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

+3-5
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@
2525
namespace clang {
2626

2727
IncrementalCUDADeviceParser::IncrementalCUDADeviceParser(
28-
std::unique_ptr<CompilerInstance> DeviceInstance,
29-
CompilerInstance &HostInstance,
28+
CompilerInstance &DeviceInstance, CompilerInstance &HostInstance,
3029
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS,
3130
llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs)
32-
: IncrementalParser(*DeviceInstance, Err), PTUs(PTUs), VFS(FS),
31+
: IncrementalParser(DeviceInstance, Err), PTUs(PTUs), VFS(FS),
3332
CodeGenOpts(HostInstance.getCodeGenOpts()),
34-
TargetOpts(DeviceInstance->getTargetOpts()) {
33+
TargetOpts(DeviceInstance.getTargetOpts()) {
3534
if (Err)
3635
return;
3736
StringRef Arch = TargetOpts.CPU;
@@ -41,7 +40,6 @@ IncrementalCUDADeviceParser::IncrementalCUDADeviceParser(
4140
llvm::inconvertibleErrorCode()));
4241
return;
4342
}
44-
DeviceCI = std::move(DeviceInstance);
4543
}
4644

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

clang/lib/Interpreter/DeviceOffload.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ class IncrementalCUDADeviceParser : public IncrementalParser {
2828

2929
public:
3030
IncrementalCUDADeviceParser(
31-
std::unique_ptr<CompilerInstance> DeviceInstance,
32-
CompilerInstance &HostInstance,
31+
CompilerInstance &DeviceInstance, CompilerInstance &HostInstance,
3332
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS,
3433
llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs);
3534

@@ -42,7 +41,6 @@ class IncrementalCUDADeviceParser : public IncrementalParser {
4241
~IncrementalCUDADeviceParser();
4342

4443
protected:
45-
std::unique_ptr<CompilerInstance> DeviceCI;
4644
int SMVersion;
4745
llvm::SmallString<1024> PTXCode;
4846
llvm::SmallVector<char, 1024> FatbinContent;

clang/lib/Interpreter/Interpreter.cpp

+8-1
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,11 @@ 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,
512+
Interp->PTUs);
506513

507514
if (Err)
508515
return std::move(Err);

0 commit comments

Comments
 (0)