Skip to content

Commit 8a25331

Browse files
committed
Always pass DiagnosticOptions to ASTUnit with DiagnosticsEngine
1 parent 40446a8 commit 8a25331

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

clang/include/clang/Frontend/ASTUnit.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ class ASTUnit {
679679
/// Create a ASTUnit. Gets ownership of the passed CompilerInvocation.
680680
static std::unique_ptr<ASTUnit>
681681
create(std::shared_ptr<CompilerInvocation> CI,
682+
std::shared_ptr<DiagnosticOptions> DiagOpts,
682683
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
683684
CaptureDiagsKind CaptureDiagnostics, bool UserFilesAreVolatile);
684685

@@ -705,7 +706,8 @@ class ASTUnit {
705706
/// \returns - The initialized ASTUnit or null if the AST failed to load.
706707
static std::unique_ptr<ASTUnit> LoadFromASTFile(
707708
StringRef Filename, const PCHContainerReader &PCHContainerRdr,
708-
WhatToLoad ToLoad, IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
709+
WhatToLoad ToLoad, std::shared_ptr<DiagnosticOptions> DiagOpts,
710+
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
709711
const FileSystemOptions &FileSystemOpts,
710712
const HeaderSearchOptions &HSOpts, const LangOptions *LangOpts = nullptr,
711713
bool OnlyLocalDecls = false,
@@ -767,6 +769,7 @@ class ASTUnit {
767769
static ASTUnit *LoadFromCompilerInvocationAction(
768770
std::shared_ptr<CompilerInvocation> CI,
769771
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
772+
std::shared_ptr<DiagnosticOptions> DiagOpts,
770773
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
771774
FrontendAction *Action = nullptr, ASTUnit *Unit = nullptr,
772775
bool Persistent = true, StringRef ResourceFilesPath = StringRef(),
@@ -794,6 +797,7 @@ class ASTUnit {
794797
static std::unique_ptr<ASTUnit> LoadFromCompilerInvocation(
795798
std::shared_ptr<CompilerInvocation> CI,
796799
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
800+
std::shared_ptr<DiagnosticOptions> DiagOpts,
797801
IntrusiveRefCntPtr<DiagnosticsEngine> Diags, FileManager *FileMgr,
798802
bool OnlyLocalDecls = false,
799803
CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,

clang/lib/Frontend/ASTUnit.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,8 @@ void ASTUnit::ConfigureDiags(IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
803803

804804
std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
805805
StringRef Filename, const PCHContainerReader &PCHContainerRdr,
806-
WhatToLoad ToLoad, IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
806+
WhatToLoad ToLoad, std::shared_ptr<DiagnosticOptions> DiagOpts,
807+
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
807808
const FileSystemOptions &FileSystemOpts, const HeaderSearchOptions &HSOpts,
808809
const LangOptions *LangOpts, bool OnlyLocalDecls,
809810
CaptureDiagsKind CaptureDiagnostics, bool AllowASTWithCompilerErrors,
@@ -823,6 +824,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
823824
: std::make_unique<LangOptions>();
824825
AST->OnlyLocalDecls = OnlyLocalDecls;
825826
AST->CaptureDiagnostics = CaptureDiagnostics;
827+
AST->DiagOpts = DiagOpts;
826828
AST->Diagnostics = Diags;
827829
AST->FileMgr = new FileManager(FileSystemOpts, VFS);
828830
AST->UserFilesAreVolatile = UserFilesAreVolatile;
@@ -1534,13 +1536,15 @@ StringRef ASTUnit::getASTFileName() const {
15341536

15351537
std::unique_ptr<ASTUnit>
15361538
ASTUnit::create(std::shared_ptr<CompilerInvocation> CI,
1539+
std::shared_ptr<DiagnosticOptions> DiagOpts,
15371540
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
15381541
CaptureDiagsKind CaptureDiagnostics,
15391542
bool UserFilesAreVolatile) {
15401543
std::unique_ptr<ASTUnit> AST(new ASTUnit(false));
15411544
ConfigureDiags(Diags, *AST, CaptureDiagnostics);
15421545
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
15431546
createVFSFromCompilerInvocation(*CI, *Diags);
1547+
AST->DiagOpts = DiagOpts;
15441548
AST->Diagnostics = Diags;
15451549
AST->FileSystemOpts = CI->getFileSystemOpts();
15461550
AST->Invocation = std::move(CI);
@@ -1556,6 +1560,7 @@ ASTUnit::create(std::shared_ptr<CompilerInvocation> CI,
15561560
ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
15571561
std::shared_ptr<CompilerInvocation> CI,
15581562
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1563+
std::shared_ptr<DiagnosticOptions> DiagOpts,
15591564
IntrusiveRefCntPtr<DiagnosticsEngine> Diags, FrontendAction *Action,
15601565
ASTUnit *Unit, bool Persistent, StringRef ResourceFilesPath,
15611566
bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
@@ -1567,7 +1572,8 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
15671572
ASTUnit *AST = Unit;
15681573
if (!AST) {
15691574
// Create the AST unit.
1570-
OwnAST = create(CI, Diags, CaptureDiagnostics, UserFilesAreVolatile);
1575+
OwnAST =
1576+
create(CI, DiagOpts, Diags, CaptureDiagnostics, UserFilesAreVolatile);
15711577
AST = OwnAST.get();
15721578
if (!AST)
15731579
return nullptr;
@@ -1729,6 +1735,7 @@ bool ASTUnit::LoadFromCompilerInvocation(
17291735
std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation(
17301736
std::shared_ptr<CompilerInvocation> CI,
17311737
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1738+
std::shared_ptr<DiagnosticOptions> DiagOpts,
17321739
IntrusiveRefCntPtr<DiagnosticsEngine> Diags, FileManager *FileMgr,
17331740
bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
17341741
unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind,
@@ -1737,6 +1744,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation(
17371744
// Create the AST unit.
17381745
std::unique_ptr<ASTUnit> AST(new ASTUnit(false));
17391746
ConfigureDiags(Diags, *AST, CaptureDiagnostics);
1747+
AST->DiagOpts = DiagOpts;
17401748
AST->Diagnostics = Diags;
17411749
AST->OnlyLocalDecls = OnlyLocalDecls;
17421750
AST->CaptureDiagnostics = CaptureDiagnostics;

0 commit comments

Comments
 (0)