Skip to content

[clang][Modules] checkModuleIsAvailable should use a const & parameter instead of pointer #67902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
2 changes: 1 addition & 1 deletion clang/include/clang/Lex/Preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2697,7 +2697,7 @@ class Preprocessor {
/// \c false if the module appears to be usable.
static bool checkModuleIsAvailable(const LangOptions &LangOpts,
const TargetInfo &TargetInfo,
DiagnosticsEngine &Diags, Module *M);
const Module &M, DiagnosticsEngine &Diags);

// Module inclusion testing.
/// Find the module that owns the source or header file that
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,

// Check whether this module is available.
if (Preprocessor::checkModuleIsAvailable(getLangOpts(), getTarget(),
getDiagnostics(), Module)) {
*Module, getDiagnostics())) {
getDiagnostics().Report(ImportLoc, diag::note_module_import_here)
<< SourceRange(Path.front().second, Path.back().second);
LastModuleImportLoc = ImportLoc;
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Frontend/FrontendAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@ static Module *prepareToBuildModule(CompilerInstance &CI,
}

// Check whether we can build this module at all.
if (Preprocessor::checkModuleIsAvailable(CI.getLangOpts(), CI.getTarget(),
CI.getDiagnostics(), M))
if (Preprocessor::checkModuleIsAvailable(CI.getLangOpts(), CI.getTarget(), *M,
CI.getDiagnostics()))
return nullptr;

// Inform the preprocessor that includes from within the input buffer should
Expand Down
18 changes: 10 additions & 8 deletions clang/lib/Lex/PPDirectives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1896,26 +1896,27 @@ static bool trySimplifyPath(SmallVectorImpl<StringRef> &Components,

bool Preprocessor::checkModuleIsAvailable(const LangOptions &LangOpts,
const TargetInfo &TargetInfo,
DiagnosticsEngine &Diags, Module *M) {
const Module &M,
DiagnosticsEngine &Diags) {
Module::Requirement Requirement;
Module::UnresolvedHeaderDirective MissingHeader;
Module *ShadowingModule = nullptr;
if (M->isAvailable(LangOpts, TargetInfo, Requirement, MissingHeader,
ShadowingModule))
if (M.isAvailable(LangOpts, TargetInfo, Requirement, MissingHeader,
ShadowingModule))
return false;

if (MissingHeader.FileNameLoc.isValid()) {
Diags.Report(MissingHeader.FileNameLoc, diag::err_module_header_missing)
<< MissingHeader.IsUmbrella << MissingHeader.FileName;
} else if (ShadowingModule) {
Diags.Report(M->DefinitionLoc, diag::err_module_shadowed) << M->Name;
Diags.Report(M.DefinitionLoc, diag::err_module_shadowed) << M.Name;
Diags.Report(ShadowingModule->DefinitionLoc,
diag::note_previous_definition);
} else {
// FIXME: Track the location at which the requirement was specified, and
// use it here.
Diags.Report(M->DefinitionLoc, diag::err_module_unavailable)
<< M->getFullModuleName() << Requirement.second << Requirement.first;
Diags.Report(M.DefinitionLoc, diag::err_module_unavailable)
<< M.getFullModuleName() << Requirement.second << Requirement.first;
}
return true;
}
Expand Down Expand Up @@ -2260,8 +2261,9 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
// unavailable, diagnose the situation and bail out.
// FIXME: Remove this; loadModule does the same check (but produces
// slightly worse diagnostics).
if (checkModuleIsAvailable(getLangOpts(), getTargetInfo(), getDiagnostics(),
SuggestedModule.getModule())) {
if (checkModuleIsAvailable(getLangOpts(), getTargetInfo(),
*SuggestedModule.getModule(),
getDiagnostics())) {
Diag(FilenameTok.getLocation(),
diag::note_implicit_top_level_module_import_here)
<< SuggestedModule.getModule()->getTopLevelModuleName();
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Lex/Pragma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1769,7 +1769,7 @@ struct PragmaModuleBeginHandler : public PragmaHandler {

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