[clang] [clang-repl] Fix destructor for interpreter for the cuda negation case (PR #138091)
Anutosh Bhat via cfe-commits
cfe-commits at lists.llvm.org
Thu May 1 00:09:23 PDT 2025
https://github.com/anutosh491 updated https://github.com/llvm/llvm-project/pull/138091
>From 8783ea05d2d7f4504978427764da7e78c088aa39 Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Thu, 1 May 2025 12:16:06 +0530
Subject: [PATCH 1/2] Fix destructor for interpreter for the cuda negation case
---
clang/include/clang/Interpreter/Interpreter.h | 3 +++
clang/lib/Interpreter/DeviceOffload.cpp | 7 +++----
clang/lib/Interpreter/DeviceOffload.h | 3 +--
clang/lib/Interpreter/Interpreter.cpp | 8 +++++++-
4 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h
index 56213f88b9e30..f8663e3193a18 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -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,
diff --git a/clang/lib/Interpreter/DeviceOffload.cpp b/clang/lib/Interpreter/DeviceOffload.cpp
index 7d0125403ea52..8ab6a61993972 100644
--- a/clang/lib/Interpreter/DeviceOffload.cpp
+++ b/clang/lib/Interpreter/DeviceOffload.cpp
@@ -25,13 +25,13 @@
namespace clang {
IncrementalCUDADeviceParser::IncrementalCUDADeviceParser(
- std::unique_ptr<CompilerInstance> DeviceInstance,
+ 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 +41,6 @@ IncrementalCUDADeviceParser::IncrementalCUDADeviceParser(
llvm::inconvertibleErrorCode()));
return;
}
- DeviceCI = std::move(DeviceInstance);
}
llvm::Expected<llvm::StringRef> IncrementalCUDADeviceParser::GeneratePTX() {
diff --git a/clang/lib/Interpreter/DeviceOffload.h b/clang/lib/Interpreter/DeviceOffload.h
index 43645033c4840..c1cb4cd23a4b5 100644
--- a/clang/lib/Interpreter/DeviceOffload.h
+++ b/clang/lib/Interpreter/DeviceOffload.h
@@ -28,7 +28,7 @@ class IncrementalCUDADeviceParser : public IncrementalParser {
public:
IncrementalCUDADeviceParser(
- std::unique_ptr<CompilerInstance> DeviceInstance,
+ CompilerInstance &DeviceInstance,
CompilerInstance &HostInstance,
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS,
llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs);
@@ -42,7 +42,6 @@ class IncrementalCUDADeviceParser : public IncrementalParser {
~IncrementalCUDADeviceParser();
protected:
- std::unique_ptr<CompilerInstance> DeviceCI;
int SMVersion;
llvm::SmallString<1024> PTXCode;
llvm::SmallVector<char, 1024> FatbinContent;
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 80487eb4ef74a..4ca12f6858c9d 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -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,10 @@ 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);
>From 5df3bc6d7c28c728d14b3d484441b00e5074544e Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Thu, 1 May 2025 12:39:08 +0530
Subject: [PATCH 2/2] formatting
---
clang/lib/Interpreter/DeviceOffload.cpp | 3 +--
clang/lib/Interpreter/DeviceOffload.h | 3 +--
clang/lib/Interpreter/Interpreter.cpp | 3 ++-
3 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/clang/lib/Interpreter/DeviceOffload.cpp b/clang/lib/Interpreter/DeviceOffload.cpp
index 8ab6a61993972..05625ddedb72f 100644
--- a/clang/lib/Interpreter/DeviceOffload.cpp
+++ b/clang/lib/Interpreter/DeviceOffload.cpp
@@ -25,8 +25,7 @@
namespace clang {
IncrementalCUDADeviceParser::IncrementalCUDADeviceParser(
- 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),
diff --git a/clang/lib/Interpreter/DeviceOffload.h b/clang/lib/Interpreter/DeviceOffload.h
index c1cb4cd23a4b5..0b903e31c6799 100644
--- a/clang/lib/Interpreter/DeviceOffload.h
+++ b/clang/lib/Interpreter/DeviceOffload.h
@@ -28,8 +28,7 @@ class IncrementalCUDADeviceParser : public IncrementalParser {
public:
IncrementalCUDADeviceParser(
- CompilerInstance &DeviceInstance,
- CompilerInstance &HostInstance,
+ CompilerInstance &DeviceInstance, CompilerInstance &HostInstance,
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS,
llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs);
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 4ca12f6858c9d..c04b2099a4b9a 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -508,7 +508,8 @@ Interpreter::createWithCUDA(std::unique_ptr<CompilerInstance> CI,
Interp->DeviceCI = std::move(DCI);
auto DeviceParser = std::make_unique<IncrementalCUDADeviceParser>(
- *Interp->DeviceCI, *Interp->getCompilerInstance(), IMVFS, Err, Interp->PTUs);
+ *Interp->DeviceCI, *Interp->getCompilerInstance(), IMVFS, Err,
+ Interp->PTUs);
if (Err)
return std::move(Err);
More information about the cfe-commits
mailing list