Skip to content

[Modules][Diagnostic] Mention which AST file's options differ from the current TU options. #101413

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 5 commits into from
Aug 8, 2024
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
46 changes: 23 additions & 23 deletions clang/include/clang/Basic/DiagnosticSerializationKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ def note_pch_rebuild_required : Note<"please rebuild precompiled header '%0'">;
def note_module_cache_path : Note<
"after modifying system headers, please delete the module cache at '%0'">;

def err_pch_targetopt_mismatch : Error<
"PCH file was compiled for the %0 '%1' but the current translation "
"unit is being compiled for target '%2'">;
def err_pch_targetopt_feature_mismatch : Error<
"%select{AST file was|current translation unit is}0 compiled with the target "
"feature '%1' but the %select{current translation unit is|AST file was}0 "
def err_ast_file_targetopt_mismatch : Error<
"AST file '%0' was compiled for the %1 '%2' but the current translation "
"unit is being compiled for target '%3'">;
def err_ast_file_targetopt_feature_mismatch : Error<
"%select{AST file '%1' was|current translation unit is}0 compiled with the target "
"feature '%2' but the %select{current translation unit is|AST file '%1' was}0 "
"not">;
def err_pch_langopt_mismatch : Error<"%0 was %select{disabled|enabled}1 in "
"PCH file but is currently %select{disabled|enabled}2">;
def err_pch_langopt_value_mismatch : Error<
"%0 differs in PCH file vs. current file">;
def err_pch_diagopt_mismatch : Error<"%0 is currently enabled, but was not in "
"the PCH file">;
def err_pch_modulecache_mismatch : Error<"PCH was compiled with module cache "
def err_ast_file_langopt_mismatch : Error<"%0 was %select{disabled|enabled}1 in "
"AST file '%3' but is currently %select{disabled|enabled}2">;
def err_ast_file_langopt_value_mismatch : Error<
"%0 differs in AST file '%1' vs. current file">;
def err_ast_file_diagopt_mismatch : Error<"%0 is currently enabled, but was not in "
"the AST file '%1'">;
def err_ast_file_modulecache_mismatch : Error<"AST file '%2' was compiled with module cache "
"path '%0', but the path is currently '%1'">;
def warn_pch_vfsoverlay_mismatch : Warning<
"PCH was compiled with different VFS overlay files than are currently in use">,
Expand Down Expand Up @@ -99,19 +99,19 @@ def err_module_different_modmap : Error<
"module '%0' %select{uses|does not use}1 additional module map '%2'"
"%select{| not}1 used when the module was built">;

def err_pch_macro_def_undef : Error<
"macro '%0' was %select{defined|undef'd}1 in the precompiled header but "
def err_ast_file_macro_def_undef : Error<
"macro '%0' was %select{defined|undef'd}1 in the AST file '%2' but "
"%select{undef'd|defined}1 on the command line">;
def err_pch_macro_def_conflict : Error<
"definition of macro '%0' differs between the precompiled header ('%1') "
def err_ast_file_macro_def_conflict : Error<
"definition of macro '%0' differs between the AST file '%3' ('%1') "
"and the command line ('%2')">;
def err_pch_undef : Error<
"%select{command line contains|precompiled header was built with}0 "
"'-undef' but %select{precompiled header was not built with it|"
def err_ast_file_undef : Error<
"%select{command line contains|AST file '%1' was built with}0 "
"'-undef' but %select{AST file '%1' was not built with it|"
"it is not present on the command line}0">;
def err_pch_pp_detailed_record : Error<
"%select{command line contains|precompiled header was built with}0 "
"'-detailed-preprocessing-record' but %select{precompiled header was not "
def err_ast_file_pp_detailed_record : Error<
"%select{command line contains|AST file '%1' was built with}0 "
"'-detailed-preprocessing-record' but %select{AST file '%1' was not "
"built with it|it is not present on the command line}0">;

def err_module_odr_violation_missing_decl : Error<
Expand Down
34 changes: 23 additions & 11 deletions clang/include/clang/Serialization/ASTReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class ASTReaderListener {
///
/// \returns true to indicate the options are invalid or false otherwise.
virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
StringRef ModuleFilename,
bool Complain,
bool AllowCompatibleDifferences) {
return false;
Expand All @@ -139,7 +140,7 @@ class ASTReaderListener {
///
/// \returns true to indicate the target options are invalid, or false
/// otherwise.
virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, StringRef ModuleFilename, bool Complain,
bool AllowCompatibleDifferences) {
return false;
}
Expand All @@ -150,6 +151,7 @@ class ASTReaderListener {
/// otherwise.
virtual bool
ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
StringRef ModuleFilename,
bool Complain) {
return false;
}
Expand All @@ -172,6 +174,7 @@ class ASTReaderListener {
/// \returns true to indicate the header search options are invalid, or false
/// otherwise.
virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
StringRef ModuleFilename,
StringRef SpecificModuleCachePath,
bool Complain) {
return false;
Expand Down Expand Up @@ -200,6 +203,7 @@ class ASTReaderListener {
/// \returns true to indicate the preprocessor options are invalid, or false
/// otherwise.
virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
StringRef ModuleFilename,
bool ReadMacros, bool Complain,
std::string &SuggestedPredefines) {
return false;
Expand Down Expand Up @@ -262,19 +266,22 @@ class ChainedASTReaderListener : public ASTReaderListener {
bool ReadFullVersionInformation(StringRef FullVersion) override;
void ReadModuleName(StringRef ModuleName) override;
void ReadModuleMapFile(StringRef ModuleMapPath) override;
bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
bool ReadLanguageOptions(const LangOptions &LangOpts, StringRef ModuleFilename, bool Complain,
bool AllowCompatibleDifferences) override;
bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
bool ReadTargetOptions(const TargetOptions &TargetOpts, StringRef ModuleFilename, bool Complain,
bool AllowCompatibleDifferences) override;
bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
StringRef ModuleFilename,
bool Complain) override;
bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
bool Complain) override;

bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
StringRef ModuleFilename,
StringRef SpecificModuleCachePath,
bool Complain) override;
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
StringRef ModuleFilename,
bool ReadMacros, bool Complain,
std::string &SuggestedPredefines) override;

Expand All @@ -299,16 +306,19 @@ class PCHValidator : public ASTReaderListener {
PCHValidator(Preprocessor &PP, ASTReader &Reader)
: PP(PP), Reader(Reader) {}

bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
bool ReadLanguageOptions(const LangOptions &LangOpts, StringRef ModuleFilename, bool Complain,
bool AllowCompatibleDifferences) override;
bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
bool ReadTargetOptions(const TargetOptions &TargetOpts, StringRef ModuleFilename, bool Complain,
bool AllowCompatibleDifferences) override;
bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
StringRef ModuleFilename,
bool Complain) override;
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
StringRef ModuleFilename,
bool ReadMacros, bool Complain,
std::string &SuggestedPredefines) override;
bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
StringRef ModuleFilename,
StringRef SpecificModuleCachePath,
bool Complain) override;
void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
Expand All @@ -325,6 +335,7 @@ class SimpleASTReaderListener : public ASTReaderListener {
SimpleASTReaderListener(Preprocessor &PP) : PP(PP) {}

bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
StringRef ModuleFilename,
bool ReadMacros, bool Complain,
std::string &SuggestedPredefines) override;
};
Expand Down Expand Up @@ -1362,7 +1373,7 @@ class ASTReader
const ModuleFile *ImportedBy,
unsigned ClientLoadCapabilities);
static ASTReadResult ReadOptionsBlock(
llvm::BitstreamCursor &Stream, unsigned ClientLoadCapabilities,
llvm::BitstreamCursor &Stream, StringRef Filename, unsigned ClientLoadCapabilities,
bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener,
std::string &SuggestedPredefines);

Expand All @@ -1375,6 +1386,7 @@ class ASTReader

static ASTReadResult
readUnhashedControlBlockImpl(ModuleFile *F, llvm::StringRef StreamData,
StringRef Filename,
unsigned ClientLoadCapabilities,
bool AllowCompatibleConfigurationMismatch,
ASTReaderListener *Listener,
Expand All @@ -1391,21 +1403,21 @@ class ASTReader
unsigned ClientLoadCapabilities);
llvm::Error ReadSubmoduleBlock(ModuleFile &F,
unsigned ClientLoadCapabilities);
static bool ParseLanguageOptions(const RecordData &Record, bool Complain,
static bool ParseLanguageOptions(const RecordData &Record, StringRef ModuleFilename, bool Complain,
ASTReaderListener &Listener,
bool AllowCompatibleDifferences);
static bool ParseTargetOptions(const RecordData &Record, bool Complain,
static bool ParseTargetOptions(const RecordData &Record, StringRef ModuleFilename, bool Complain,
ASTReaderListener &Listener,
bool AllowCompatibleDifferences);
static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain,
static bool ParseDiagnosticOptions(const RecordData &Record, StringRef ModuleFilename, bool Complain,
ASTReaderListener &Listener);
static bool ParseFileSystemOptions(const RecordData &Record, bool Complain,
ASTReaderListener &Listener);
static bool ParseHeaderSearchOptions(const RecordData &Record, bool Complain,
static bool ParseHeaderSearchOptions(const RecordData &Record, StringRef ModuleFilename, bool Complain,
ASTReaderListener &Listener);
static bool ParseHeaderSearchPaths(const RecordData &Record, bool Complain,
ASTReaderListener &Listener);
static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain,
static bool ParsePreprocessorOptions(const RecordData &Record, StringRef ModuleFilename, bool Complain,
ASTReaderListener &Listener,
std::string &SuggestedPredefines);

Expand Down
6 changes: 4 additions & 2 deletions clang/lib/Frontend/ASTUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ class ASTInfoCollector : public ASTReaderListener {
LangOpt(LangOpt), TargetOpts(TargetOpts), Target(Target),
Counter(Counter) {}

bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
bool ReadLanguageOptions(const LangOptions &LangOpts, StringRef ModuleFilename, bool Complain,
bool AllowCompatibleDifferences) override {
if (InitializedLanguage)
return false;
Expand All @@ -559,6 +559,7 @@ class ASTInfoCollector : public ASTReaderListener {
}

bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
StringRef ModuleFilename,
StringRef SpecificModuleCachePath,
bool Complain) override {
// llvm::SaveAndRestore doesn't support bit field.
Expand Down Expand Up @@ -597,13 +598,14 @@ class ASTInfoCollector : public ASTReaderListener {
}

bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
StringRef ModuleFilename,
bool ReadMacros, bool Complain,
std::string &SuggestedPredefines) override {
this->PPOpts = PPOpts;
return false;
}

bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
bool ReadTargetOptions(const TargetOptions &TargetOpts, StringRef ModuleFilename, bool Complain,
bool AllowCompatibleDifferences) override {
// If we've already initialized the target, don't do it again.
if (Target)
Expand Down
8 changes: 5 additions & 3 deletions clang/lib/Frontend/FrontendActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ namespace {
Out.indent(2) << "Module map file: " << ModuleMapPath << "\n";
}

bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
bool ReadLanguageOptions(const LangOptions &LangOpts, StringRef ModuleFilename, bool Complain,
bool AllowCompatibleDifferences) override {
Out.indent(2) << "Language options:\n";
#define LANGOPT(Name, Bits, Default, Description) \
Expand All @@ -645,7 +645,7 @@ namespace {
return false;
}

bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
bool ReadTargetOptions(const TargetOptions &TargetOpts, StringRef ModuleFilename, bool Complain,
bool AllowCompatibleDifferences) override {
Out.indent(2) << "Target options:\n";
Out.indent(4) << " Triple: " << TargetOpts.Triple << "\n";
Expand All @@ -665,7 +665,7 @@ namespace {
}

bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
bool Complain) override {
StringRef ModuleFilename, bool Complain) override {
Out.indent(2) << "Diagnostic options:\n";
#define DIAGOPT(Name, Bits, Default) DUMP_BOOLEAN(DiagOpts->Name, #Name);
#define ENUM_DIAGOPT(Name, Type, Bits, Default) \
Expand All @@ -684,6 +684,7 @@ namespace {
}

bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
StringRef ModuleFilename,
StringRef SpecificModuleCachePath,
bool Complain) override {
Out.indent(2) << "Header search options:\n";
Expand Down Expand Up @@ -717,6 +718,7 @@ namespace {
}

bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
StringRef ModuleFilename,
bool ReadMacros, bool Complain,
std::string &SuggestedPredefines) override {
Out.indent(2) << "Preprocessor options:\n";
Expand Down
Loading
Loading