Skip to content

Commit 85eafb4

Browse files
committed
Fix valgrind/windows
1 parent 31b0126 commit 85eafb4

File tree

6 files changed

+43
-36
lines changed

6 files changed

+43
-36
lines changed

clang/include/clang/Interpreter/Interpreter.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@ class Interpreter {
110110
/// and we must keep it alive.
111111
std::unique_ptr<llvm::Module> CachedInCodeGenModule;
112112

113+
/// Compiler instance performing the incremental compilation.
114+
std::unique_ptr<CompilerInstance> CI;
115+
113116
protected:
114117
// Derived classes can use an extended interface of the Interpreter.
115-
Interpreter(std::unique_ptr<CompilerInstance> CI, llvm::Error &Err,
118+
Interpreter(std::unique_ptr<CompilerInstance> Instance, llvm::Error &Err,
116119
std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder = nullptr,
117120
std::unique_ptr<clang::ASTConsumer> Consumer = nullptr);
118121

clang/lib/Interpreter/DeviceOffload.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@
2525
namespace clang {
2626

2727
IncrementalCUDADeviceParser::IncrementalCUDADeviceParser(
28-
std::unique_ptr<CompilerInstance> Instance, IncrementalParser &HostParser,
28+
std::unique_ptr<CompilerInstance> DeviceInstance,
29+
CompilerInstance &HostInstance,
2930
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS,
3031
llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs)
31-
: IncrementalParser(std::move(Instance), Err), PTUs(PTUs),
32-
HostParser(HostParser), VFS(FS) {
32+
: IncrementalParser(*DeviceInstance, Err), PTUs(PTUs), VFS(FS),
33+
CodeGenOpts(HostInstance.getCodeGenOpts()),
34+
TargetOpts(HostInstance.getTargetOpts()) {
3335
if (Err)
3436
return;
35-
StringRef Arch = CI->getTargetOpts().CPU;
37+
DeviceCI = std::move(DeviceInstance);
38+
StringRef Arch = TargetOpts.CPU;
3639
if (!Arch.starts_with("sm_") || Arch.substr(3).getAsInteger(10, SMVersion)) {
3740
Err = llvm::joinErrors(std::move(Err), llvm::make_error<llvm::StringError>(
3841
"Invalid CUDA architecture",
@@ -62,7 +65,7 @@ IncrementalCUDADeviceParser::Parse(llvm::StringRef Input) {
6265
llvm::StringRef(FatbinContent.data(), FatbinContent.size()),
6366
"", false));
6467

65-
HostParser.getCI()->getCodeGenOpts().CudaGpuBinaryFileName = FatbinFileName;
68+
CodeGenOpts.CudaGpuBinaryFileName = FatbinFileName;
6669

6770
FatbinContent.clear();
6871

@@ -80,7 +83,7 @@ llvm::Expected<llvm::StringRef> IncrementalCUDADeviceParser::GeneratePTX() {
8083
std::error_code());
8184
llvm::TargetOptions TO = llvm::TargetOptions();
8285
llvm::TargetMachine *TargetMachine = Target->createTargetMachine(
83-
PTU.TheModule->getTargetTriple(), getCI()->getTargetOpts().CPU, "", TO,
86+
PTU.TheModule->getTargetTriple(), TargetOpts.CPU, "", TO,
8487
llvm::Reloc::Model::PIC_);
8588
PTU.TheModule->setDataLayout(TargetMachine->createDataLayout());
8689

clang/lib/Interpreter/DeviceOffload.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@
1919

2020
namespace clang {
2121
struct PartialTranslationUnit;
22+
class CompilerInstance;
23+
class CodeGenOptions;
24+
class TargetOptions;
25+
2226
class IncrementalCUDADeviceParser : public IncrementalParser {
2327
const std::list<PartialTranslationUnit> &PTUs;
2428

2529
public:
2630
IncrementalCUDADeviceParser(
27-
std::unique_ptr<CompilerInstance> Instance, IncrementalParser &HostParser,
31+
std::unique_ptr<CompilerInstance> DeviceInstance,
32+
CompilerInstance &HostInstance,
2833
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS,
2934
llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs);
3035

@@ -39,11 +44,13 @@ class IncrementalCUDADeviceParser : public IncrementalParser {
3944
~IncrementalCUDADeviceParser();
4045

4146
protected:
42-
IncrementalParser &HostParser;
47+
std::unique_ptr<CompilerInstance> DeviceCI;
4348
int SMVersion;
4449
llvm::SmallString<1024> PTXCode;
4550
llvm::SmallVector<char, 1024> FatbinContent;
4651
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS;
52+
CodeGenOptions &CodeGenOpts; // intentionally a reference.
53+
const TargetOptions &TargetOpts;
4754
};
4855

4956
} // namespace clang

clang/lib/Interpreter/IncrementalParser.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@
2424

2525
namespace clang {
2626

27-
IncrementalParser::IncrementalParser() {}
27+
// IncrementalParser::IncrementalParser() {}
2828

29-
IncrementalParser::IncrementalParser(std::unique_ptr<CompilerInstance> Instance,
29+
IncrementalParser::IncrementalParser(CompilerInstance &Instance,
3030
llvm::Error &Err)
31-
: CI(std::move(Instance)) {
31+
: S(Instance.getSema()) {
3232
llvm::ErrorAsOutParameter EAO(&Err);
33-
34-
Consumer = &CI->getASTConsumer();
35-
P.reset(
36-
new Parser(CI->getPreprocessor(), CI->getSema(), /*SkipBodies=*/false));
33+
Consumer = &S.getASTConsumer();
34+
P.reset(new Parser(S.getPreprocessor(), S, /*SkipBodies=*/false));
3735
P->Initialize();
3836
}
3937

@@ -42,7 +40,6 @@ IncrementalParser::~IncrementalParser() { P.reset(); }
4240
llvm::Expected<TranslationUnitDecl *>
4341
IncrementalParser::ParseOrWrapTopLevelDecl() {
4442
// Recover resources if we crash before exiting this method.
45-
Sema &S = CI->getSema();
4643
llvm::CrashRecoveryContextCleanupRegistrar<Sema> CleanupSema(&S);
4744
Sema::GlobalEagerInstantiationScope GlobalInstantiations(S, /*Enabled=*/true);
4845
Sema::LocalEagerInstantiationScope LocalInstantiations(S);
@@ -73,7 +70,7 @@ IncrementalParser::ParseOrWrapTopLevelDecl() {
7370
std::error_code());
7471
}
7572

76-
DiagnosticsEngine &Diags = getCI()->getDiagnostics();
73+
DiagnosticsEngine &Diags = S.getDiagnostics();
7774
if (Diags.hasErrorOccurred()) {
7875
CleanUpPTU(C.getTranslationUnitDecl());
7976

@@ -99,7 +96,7 @@ IncrementalParser::ParseOrWrapTopLevelDecl() {
9996

10097
llvm::Expected<TranslationUnitDecl *>
10198
IncrementalParser::Parse(llvm::StringRef input) {
102-
Preprocessor &PP = CI->getPreprocessor();
99+
Preprocessor &PP = S.getPreprocessor();
103100
assert(PP.isIncrementalProcessingEnabled() && "Not in incremental mode!?");
104101

105102
std::ostringstream SourceName;
@@ -115,7 +112,7 @@ IncrementalParser::Parse(llvm::StringRef input) {
115112
memcpy(MBStart, input.data(), InputSize);
116113
MBStart[InputSize] = '\n';
117114

118-
SourceManager &SM = CI->getSourceManager();
115+
SourceManager &SM = S.getSourceManager();
119116

120117
// FIXME: Create SourceLocation, which will allow clang to order the overload
121118
// candidates for example
@@ -183,7 +180,7 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl *MostRecentTU) {
183180
// Check if we need to clean up the IdResolver chain.
184181
if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
185182
!D->getLangOpts().CPlusPlus)
186-
getCI()->getSema().IdResolver.RemoveDecl(ND);
183+
S.IdResolver.RemoveDecl(ND);
187184
}
188185
}
189186

clang/lib/Interpreter/IncrementalParser.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ class ASTConsumer;
2424
class CodeGenerator;
2525
class CompilerInstance;
2626
class Parser;
27+
class Sema;
2728
class TranslationUnitDecl;
2829

2930
/// Provides support for incremental compilation. Keeps track of the state
3031
/// changes between the subsequent incremental input.
3132
///
3233
class IncrementalParser {
3334
protected:
34-
/// Compiler instance performing the incremental compilation.
35-
std::unique_ptr<CompilerInstance> CI;
35+
/// The Sema performing the incremental compilation.
36+
Sema &S;
3637

3738
/// Parser.
3839
std::unique_ptr<Parser> P;
@@ -43,15 +44,12 @@ class IncrementalParser {
4344
/// Counts the number of direct user input lines that have been parsed.
4445
unsigned InputCount = 0;
4546

46-
IncrementalParser();
47+
// IncrementalParser();
4748

4849
public:
49-
IncrementalParser(std::unique_ptr<CompilerInstance> Instance,
50-
llvm::Error &Err);
50+
IncrementalParser(CompilerInstance &Instance, llvm::Error &Err);
5151
virtual ~IncrementalParser();
5252

53-
CompilerInstance *getCI() { return CI.get(); }
54-
5553
/// Parses incremental input by creating an in-memory file.
5654
///\returns a \c PartialTranslationUnit which holds information about the
5755
/// \c TranslationUnitDecl.

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,12 @@ class IncrementalAction : public WrapperFrontendAction {
378378
}
379379
};
380380

381-
Interpreter::Interpreter(std::unique_ptr<CompilerInstance> CI,
381+
Interpreter::Interpreter(std::unique_ptr<CompilerInstance> Instance,
382382
llvm::Error &ErrOut,
383383
std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder,
384384
std::unique_ptr<clang::ASTConsumer> Consumer)
385385
: JITBuilder(std::move(JITBuilder)) {
386+
CI = std::move(Instance);
386387
llvm::ErrorAsOutParameter EAO(&ErrOut);
387388
auto LLVMCtx = std::make_unique<llvm::LLVMContext>();
388389
TSCtx = std::make_unique<llvm::orc::ThreadSafeContext>(std::move(LLVMCtx));
@@ -395,7 +396,7 @@ Interpreter::Interpreter(std::unique_ptr<CompilerInstance> CI,
395396

396397
ASTContext &C = CI->getASTContext();
397398

398-
IncrParser = std::make_unique<IncrementalParser>(std::move(CI), ErrOut);
399+
IncrParser = std::make_unique<IncrementalParser>(*CI, ErrOut);
399400

400401
if (ErrOut)
401402
return;
@@ -427,8 +428,8 @@ Interpreter::Interpreter(std::unique_ptr<CompilerInstance> CI,
427428
}
428429

429430
Interpreter::~Interpreter() {
430-
Act->FinalizeAction();
431431
IncrParser.reset();
432+
Act->FinalizeAction();
432433
if (IncrExecutor) {
433434
if (llvm::Error Err = IncrExecutor->cleanUp())
434435
llvm::report_fatal_error(
@@ -500,7 +501,7 @@ Interpreter::createWithCUDA(std::unique_ptr<CompilerInstance> CI,
500501

501502
llvm::Error Err = llvm::Error::success();
502503
auto DeviceParser = std::make_unique<IncrementalCUDADeviceParser>(
503-
std::move(DCI), *(*Interp)->IncrParser.get(), IMVFS, Err,
504+
std::move(DCI), *(*Interp)->getCompilerInstance(), IMVFS, Err,
504505
(*Interp)->PTUs);
505506
if (Err)
506507
return std::move(Err);
@@ -511,12 +512,10 @@ Interpreter::createWithCUDA(std::unique_ptr<CompilerInstance> CI,
511512
}
512513

513514
const CompilerInstance *Interpreter::getCompilerInstance() const {
514-
return IncrParser->getCI();
515+
return CI.get();
515516
}
516517

517-
CompilerInstance *Interpreter::getCompilerInstance() {
518-
return IncrParser->getCI();
519-
}
518+
CompilerInstance *Interpreter::getCompilerInstance() { return CI.get(); }
520519

521520
llvm::Expected<llvm::orc::LLJIT &> Interpreter::getExecutionEngine() {
522521
if (!IncrExecutor) {

0 commit comments

Comments
 (0)