Skip to content

[clang-repl] Fix destructor for interpreter for the cuda negation case #138091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/include/clang/Interpreter/Interpreter.h
Original file line number Diff line number Diff line change
@@ -116,6 +116,9 @@ class Interpreter {
/// Compiler instance performing the incremental compilation.
std::unique_ptr<CompilerInstance> CI;

/// An optional compiler instance for CUDA offloading
std::unique_ptr<CompilerInstance> DeviceCI;

protected:
// Derived classes can use an extended interface of the Interpreter.
Interpreter(std::unique_ptr<CompilerInstance> Instance, llvm::Error &Err,
8 changes: 3 additions & 5 deletions clang/lib/Interpreter/DeviceOffload.cpp
Original file line number Diff line number Diff line change
@@ -25,13 +25,12 @@
namespace clang {

IncrementalCUDADeviceParser::IncrementalCUDADeviceParser(
std::unique_ptr<CompilerInstance> DeviceInstance,
CompilerInstance &HostInstance,
CompilerInstance &DeviceInstance, CompilerInstance &HostInstance,
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS,
llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs)
: IncrementalParser(*DeviceInstance, Err), PTUs(PTUs), VFS(FS),
: IncrementalParser(DeviceInstance, Err), PTUs(PTUs), VFS(FS),
CodeGenOpts(HostInstance.getCodeGenOpts()),
TargetOpts(DeviceInstance->getTargetOpts()) {
TargetOpts(DeviceInstance.getTargetOpts()) {
if (Err)
return;
StringRef Arch = TargetOpts.CPU;
@@ -41,7 +40,6 @@ IncrementalCUDADeviceParser::IncrementalCUDADeviceParser(
llvm::inconvertibleErrorCode()));
return;
}
DeviceCI = std::move(DeviceInstance);
}

llvm::Expected<llvm::StringRef> IncrementalCUDADeviceParser::GeneratePTX() {
4 changes: 1 addition & 3 deletions clang/lib/Interpreter/DeviceOffload.h
Original file line number Diff line number Diff line change
@@ -28,8 +28,7 @@ class IncrementalCUDADeviceParser : public IncrementalParser {

public:
IncrementalCUDADeviceParser(
std::unique_ptr<CompilerInstance> DeviceInstance,
CompilerInstance &HostInstance,
CompilerInstance &DeviceInstance, CompilerInstance &HostInstance,
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS,
llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs);

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

protected:
std::unique_ptr<CompilerInstance> DeviceCI;
int SMVersion;
llvm::SmallString<1024> PTXCode;
llvm::SmallVector<char, 1024> FatbinContent;
9 changes: 8 additions & 1 deletion clang/lib/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
@@ -416,6 +416,10 @@ Interpreter::Interpreter(std::unique_ptr<CompilerInstance> Instance,
Interpreter::~Interpreter() {
IncrParser.reset();
Act->FinalizeAction();
if (DeviceParser)
DeviceParser.reset();
if (DeviceAct)
DeviceAct->FinalizeAction();
if (IncrExecutor) {
if (llvm::Error Err = IncrExecutor->cleanUp())
llvm::report_fatal_error(
@@ -501,8 +505,11 @@ Interpreter::createWithCUDA(std::unique_ptr<CompilerInstance> CI,

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

Interp->DeviceCI = std::move(DCI);

auto DeviceParser = std::make_unique<IncrementalCUDADeviceParser>(
std::move(DCI), *Interp->getCompilerInstance(), IMVFS, Err, Interp->PTUs);
*Interp->DeviceCI, *Interp->getCompilerInstance(), IMVFS, Err,
Interp->PTUs);

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