Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions clang/lib/Interpreter/IncrementalAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ std::unique_ptr<llvm::Module> IncrementalAction::GenModule() {
return nullptr;
}

void IncrementalAction::discardCurrentCodeGenModule() {
if (CodeGenerator *CG = getCodeGen()) {
if (auto *CurM = CG->GetModule()) {
llvm::LLVMContext &Ctx = CurM->getContext();
std::string Name = CurM->getName().str();
std::unique_ptr<llvm::Module> Dead(CG->ReleaseModule());
CG->StartModule(Name, Ctx);
}
Copy link
Member Author

@anutosh491 anutosh491 Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used the variable name Dead for now ! Can you use Discarded or something along those lines I think

}
}

CodeGenerator *IncrementalAction::getCodeGen() const {
FrontendAction *WrappedAct = getWrapped();
if (!WrappedAct || !WrappedAct->hasIRSupport())
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Interpreter/IncrementalAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class IncrementalAction : public WrapperFrontendAction {

/// Generate an LLVM module for the most recent parsed input.
std::unique_ptr<llvm::Module> GenModule();

void discardCurrentCodeGenModule();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can add a comment explaining the purpose behind the function (just like we do for above functions) if needed !

};

class InProcessPrintingASTConsumer final : public MultiplexConsumer {
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Interpreter/IncrementalParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ IncrementalParser::ParseOrWrapTopLevelDecl() {

DiagnosticsEngine &Diags = S.getDiagnostics();
if (Diags.hasErrorOccurred()) {
Act->discardCurrentCodeGenModule();
CleanUpPTU(C.getTranslationUnitDecl());

Diags.Reset(/*soft=*/true);
Expand Down