Skip to content

Commit 43d6a4e

Browse files
committed
[clang][Modules] checkModuleIsAvailable should use a const & parameter instead of pointer
The `Module` parameter to `checkModuleIsAvailable` is currently passed by pointer to non-const. However, it requires only const access and it cannot be null. Change this to be a reference to const instead. This then makes it obvious that it is an input-only parameter, so move it to be before the in-out parameter for diagnostics.
1 parent 0b07b06 commit 43d6a4e

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

clang/include/clang/Lex/Preprocessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,7 @@ class Preprocessor {
26972697
/// \c false if the module appears to be usable.
26982698
static bool checkModuleIsAvailable(const LangOptions &LangOpts,
26992699
const TargetInfo &TargetInfo,
2700-
DiagnosticsEngine &Diags, Module *M);
2700+
const Module &M, DiagnosticsEngine &Diags);
27012701

27022702
// Module inclusion testing.
27032703
/// Find the module that owns the source or header file that

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
21162116

21172117
// Check whether this module is available.
21182118
if (Preprocessor::checkModuleIsAvailable(getLangOpts(), getTarget(),
2119-
getDiagnostics(), Module)) {
2119+
*Module, getDiagnostics())) {
21202120
getDiagnostics().Report(ImportLoc, diag::note_module_import_here)
21212121
<< SourceRange(Path.front().second, Path.back().second);
21222122
LastModuleImportLoc = ImportLoc;

clang/lib/Frontend/FrontendAction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,8 @@ static Module *prepareToBuildModule(CompilerInstance &CI,
510510
}
511511

512512
// Check whether we can build this module at all.
513-
if (Preprocessor::checkModuleIsAvailable(CI.getLangOpts(), CI.getTarget(),
514-
CI.getDiagnostics(), M))
513+
if (Preprocessor::checkModuleIsAvailable(CI.getLangOpts(), CI.getTarget(), *M,
514+
CI.getDiagnostics()))
515515
return nullptr;
516516

517517
// Inform the preprocessor that includes from within the input buffer should

clang/lib/Lex/PPDirectives.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,26 +1896,27 @@ static bool trySimplifyPath(SmallVectorImpl<StringRef> &Components,
18961896

18971897
bool Preprocessor::checkModuleIsAvailable(const LangOptions &LangOpts,
18981898
const TargetInfo &TargetInfo,
1899-
DiagnosticsEngine &Diags, Module *M) {
1899+
const Module &M,
1900+
DiagnosticsEngine &Diags) {
19001901
Module::Requirement Requirement;
19011902
Module::UnresolvedHeaderDirective MissingHeader;
19021903
Module *ShadowingModule = nullptr;
1903-
if (M->isAvailable(LangOpts, TargetInfo, Requirement, MissingHeader,
1904-
ShadowingModule))
1904+
if (M.isAvailable(LangOpts, TargetInfo, Requirement, MissingHeader,
1905+
ShadowingModule))
19051906
return false;
19061907

19071908
if (MissingHeader.FileNameLoc.isValid()) {
19081909
Diags.Report(MissingHeader.FileNameLoc, diag::err_module_header_missing)
19091910
<< MissingHeader.IsUmbrella << MissingHeader.FileName;
19101911
} else if (ShadowingModule) {
1911-
Diags.Report(M->DefinitionLoc, diag::err_module_shadowed) << M->Name;
1912+
Diags.Report(M.DefinitionLoc, diag::err_module_shadowed) << M.Name;
19121913
Diags.Report(ShadowingModule->DefinitionLoc,
19131914
diag::note_previous_definition);
19141915
} else {
19151916
// FIXME: Track the location at which the requirement was specified, and
19161917
// use it here.
1917-
Diags.Report(M->DefinitionLoc, diag::err_module_unavailable)
1918-
<< M->getFullModuleName() << Requirement.second << Requirement.first;
1918+
Diags.Report(M.DefinitionLoc, diag::err_module_unavailable)
1919+
<< M.getFullModuleName() << Requirement.second << Requirement.first;
19191920
}
19201921
return true;
19211922
}
@@ -2260,8 +2261,9 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
22602261
// unavailable, diagnose the situation and bail out.
22612262
// FIXME: Remove this; loadModule does the same check (but produces
22622263
// slightly worse diagnostics).
2263-
if (checkModuleIsAvailable(getLangOpts(), getTargetInfo(), getDiagnostics(),
2264-
SuggestedModule.getModule())) {
2264+
if (checkModuleIsAvailable(getLangOpts(), getTargetInfo(),
2265+
*SuggestedModule.getModule(),
2266+
getDiagnostics())) {
22652267
Diag(FilenameTok.getLocation(),
22662268
diag::note_implicit_top_level_module_import_here)
22672269
<< SuggestedModule.getModule()->getTopLevelModuleName();

clang/lib/Lex/Pragma.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,7 @@ struct PragmaModuleBeginHandler : public PragmaHandler {
17691769

17701770
// If the module isn't available, it doesn't make sense to enter it.
17711771
if (Preprocessor::checkModuleIsAvailable(
1772-
PP.getLangOpts(), PP.getTargetInfo(), PP.getDiagnostics(), M)) {
1772+
PP.getLangOpts(), PP.getTargetInfo(), *M, PP.getDiagnostics())) {
17731773
PP.Diag(BeginLoc, diag::note_pp_module_begin_here)
17741774
<< M->getTopLevelModuleName();
17751775
return;

0 commit comments

Comments
 (0)