Skip to content

Commit fdf8e3e

Browse files
authored
[Modules][Diagnostic] Mention which AST file's options differ from the current TU options. (#101413)
Claiming a mismatch is always in a precompiled header is wrong and misleading as a mismatch can happen in any provided AST file. Emitting a path for a file with a problem allows to disambiguate between multiple input files. Use generic term "AST file" because we don't always know a kind of the provided file (for example, see `ASTReader::readASTFileControlBlock`). rdar://65005546
1 parent 2b1122e commit fdf8e3e

17 files changed

+176
-155
lines changed

clang/include/clang/Basic/DiagnosticSerializationKinds.td

+23-23
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ def note_pch_rebuild_required : Note<"please rebuild precompiled header '%0'">;
2929
def note_module_cache_path : Note<
3030
"after modifying system headers, please delete the module cache at '%0'">;
3131

32-
def err_pch_targetopt_mismatch : Error<
33-
"PCH file was compiled for the %0 '%1' but the current translation "
34-
"unit is being compiled for target '%2'">;
35-
def err_pch_targetopt_feature_mismatch : Error<
36-
"%select{AST file was|current translation unit is}0 compiled with the target "
37-
"feature '%1' but the %select{current translation unit is|AST file was}0 "
32+
def err_ast_file_targetopt_mismatch : Error<
33+
"AST file '%0' was compiled for the %1 '%2' but the current translation "
34+
"unit is being compiled for target '%3'">;
35+
def err_ast_file_targetopt_feature_mismatch : Error<
36+
"%select{AST file '%1' was|current translation unit is}0 compiled with the target "
37+
"feature '%2' but the %select{current translation unit is|AST file '%1' was}0 "
3838
"not">;
39-
def err_pch_langopt_mismatch : Error<"%0 was %select{disabled|enabled}1 in "
40-
"PCH file but is currently %select{disabled|enabled}2">;
41-
def err_pch_langopt_value_mismatch : Error<
42-
"%0 differs in PCH file vs. current file">;
43-
def err_pch_diagopt_mismatch : Error<"%0 is currently enabled, but was not in "
44-
"the PCH file">;
45-
def err_pch_modulecache_mismatch : Error<"PCH was compiled with module cache "
39+
def err_ast_file_langopt_mismatch : Error<"%0 was %select{disabled|enabled}1 in "
40+
"AST file '%3' but is currently %select{disabled|enabled}2">;
41+
def err_ast_file_langopt_value_mismatch : Error<
42+
"%0 differs in AST file '%1' vs. current file">;
43+
def err_ast_file_diagopt_mismatch : Error<"%0 is currently enabled, but was not in "
44+
"the AST file '%1'">;
45+
def err_ast_file_modulecache_mismatch : Error<"AST file '%2' was compiled with module cache "
4646
"path '%0', but the path is currently '%1'">;
4747
def warn_pch_vfsoverlay_mismatch : Warning<
4848
"PCH was compiled with different VFS overlay files than are currently in use">,
@@ -99,19 +99,19 @@ def err_module_different_modmap : Error<
9999
"module '%0' %select{uses|does not use}1 additional module map '%2'"
100100
"%select{| not}1 used when the module was built">;
101101

102-
def err_pch_macro_def_undef : Error<
103-
"macro '%0' was %select{defined|undef'd}1 in the precompiled header but "
102+
def err_ast_file_macro_def_undef : Error<
103+
"macro '%0' was %select{defined|undef'd}1 in the AST file '%2' but "
104104
"%select{undef'd|defined}1 on the command line">;
105-
def err_pch_macro_def_conflict : Error<
106-
"definition of macro '%0' differs between the precompiled header ('%1') "
105+
def err_ast_file_macro_def_conflict : Error<
106+
"definition of macro '%0' differs between the AST file '%3' ('%1') "
107107
"and the command line ('%2')">;
108-
def err_pch_undef : Error<
109-
"%select{command line contains|precompiled header was built with}0 "
110-
"'-undef' but %select{precompiled header was not built with it|"
108+
def err_ast_file_undef : Error<
109+
"%select{command line contains|AST file '%1' was built with}0 "
110+
"'-undef' but %select{AST file '%1' was not built with it|"
111111
"it is not present on the command line}0">;
112-
def err_pch_pp_detailed_record : Error<
113-
"%select{command line contains|precompiled header was built with}0 "
114-
"'-detailed-preprocessing-record' but %select{precompiled header was not "
112+
def err_ast_file_pp_detailed_record : Error<
113+
"%select{command line contains|AST file '%1' was built with}0 "
114+
"'-detailed-preprocessing-record' but %select{AST file '%1' was not "
115115
"built with it|it is not present on the command line}0">;
116116

117117
def err_module_odr_violation_missing_decl : Error<

clang/include/clang/Serialization/ASTReader.h

+23-11
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class ASTReaderListener {
130130
///
131131
/// \returns true to indicate the options are invalid or false otherwise.
132132
virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
133+
StringRef ModuleFilename,
133134
bool Complain,
134135
bool AllowCompatibleDifferences) {
135136
return false;
@@ -139,7 +140,7 @@ class ASTReaderListener {
139140
///
140141
/// \returns true to indicate the target options are invalid, or false
141142
/// otherwise.
142-
virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
143+
virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, StringRef ModuleFilename, bool Complain,
143144
bool AllowCompatibleDifferences) {
144145
return false;
145146
}
@@ -150,6 +151,7 @@ class ASTReaderListener {
150151
/// otherwise.
151152
virtual bool
152153
ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
154+
StringRef ModuleFilename,
153155
bool Complain) {
154156
return false;
155157
}
@@ -172,6 +174,7 @@ class ASTReaderListener {
172174
/// \returns true to indicate the header search options are invalid, or false
173175
/// otherwise.
174176
virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
177+
StringRef ModuleFilename,
175178
StringRef SpecificModuleCachePath,
176179
bool Complain) {
177180
return false;
@@ -200,6 +203,7 @@ class ASTReaderListener {
200203
/// \returns true to indicate the preprocessor options are invalid, or false
201204
/// otherwise.
202205
virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
206+
StringRef ModuleFilename,
203207
bool ReadMacros, bool Complain,
204208
std::string &SuggestedPredefines) {
205209
return false;
@@ -262,19 +266,22 @@ class ChainedASTReaderListener : public ASTReaderListener {
262266
bool ReadFullVersionInformation(StringRef FullVersion) override;
263267
void ReadModuleName(StringRef ModuleName) override;
264268
void ReadModuleMapFile(StringRef ModuleMapPath) override;
265-
bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
269+
bool ReadLanguageOptions(const LangOptions &LangOpts, StringRef ModuleFilename, bool Complain,
266270
bool AllowCompatibleDifferences) override;
267-
bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
271+
bool ReadTargetOptions(const TargetOptions &TargetOpts, StringRef ModuleFilename, bool Complain,
268272
bool AllowCompatibleDifferences) override;
269273
bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
274+
StringRef ModuleFilename,
270275
bool Complain) override;
271276
bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
272277
bool Complain) override;
273278

274279
bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
280+
StringRef ModuleFilename,
275281
StringRef SpecificModuleCachePath,
276282
bool Complain) override;
277283
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
284+
StringRef ModuleFilename,
278285
bool ReadMacros, bool Complain,
279286
std::string &SuggestedPredefines) override;
280287

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

302-
bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
309+
bool ReadLanguageOptions(const LangOptions &LangOpts, StringRef ModuleFilename, bool Complain,
303310
bool AllowCompatibleDifferences) override;
304-
bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
311+
bool ReadTargetOptions(const TargetOptions &TargetOpts, StringRef ModuleFilename, bool Complain,
305312
bool AllowCompatibleDifferences) override;
306313
bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
314+
StringRef ModuleFilename,
307315
bool Complain) override;
308316
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
317+
StringRef ModuleFilename,
309318
bool ReadMacros, bool Complain,
310319
std::string &SuggestedPredefines) override;
311320
bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
321+
StringRef ModuleFilename,
312322
StringRef SpecificModuleCachePath,
313323
bool Complain) override;
314324
void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
@@ -325,6 +335,7 @@ class SimpleASTReaderListener : public ASTReaderListener {
325335
SimpleASTReaderListener(Preprocessor &PP) : PP(PP) {}
326336

327337
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
338+
StringRef ModuleFilename,
328339
bool ReadMacros, bool Complain,
329340
std::string &SuggestedPredefines) override;
330341
};
@@ -1367,7 +1378,7 @@ class ASTReader
13671378
const ModuleFile *ImportedBy,
13681379
unsigned ClientLoadCapabilities);
13691380
static ASTReadResult ReadOptionsBlock(
1370-
llvm::BitstreamCursor &Stream, unsigned ClientLoadCapabilities,
1381+
llvm::BitstreamCursor &Stream, StringRef Filename, unsigned ClientLoadCapabilities,
13711382
bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener,
13721383
std::string &SuggestedPredefines);
13731384

@@ -1380,6 +1391,7 @@ class ASTReader
13801391

13811392
static ASTReadResult
13821393
readUnhashedControlBlockImpl(ModuleFile *F, llvm::StringRef StreamData,
1394+
StringRef Filename,
13831395
unsigned ClientLoadCapabilities,
13841396
bool AllowCompatibleConfigurationMismatch,
13851397
ASTReaderListener *Listener,
@@ -1396,21 +1408,21 @@ class ASTReader
13961408
unsigned ClientLoadCapabilities);
13971409
llvm::Error ReadSubmoduleBlock(ModuleFile &F,
13981410
unsigned ClientLoadCapabilities);
1399-
static bool ParseLanguageOptions(const RecordData &Record, bool Complain,
1411+
static bool ParseLanguageOptions(const RecordData &Record, StringRef ModuleFilename, bool Complain,
14001412
ASTReaderListener &Listener,
14011413
bool AllowCompatibleDifferences);
1402-
static bool ParseTargetOptions(const RecordData &Record, bool Complain,
1414+
static bool ParseTargetOptions(const RecordData &Record, StringRef ModuleFilename, bool Complain,
14031415
ASTReaderListener &Listener,
14041416
bool AllowCompatibleDifferences);
1405-
static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain,
1417+
static bool ParseDiagnosticOptions(const RecordData &Record, StringRef ModuleFilename, bool Complain,
14061418
ASTReaderListener &Listener);
14071419
static bool ParseFileSystemOptions(const RecordData &Record, bool Complain,
14081420
ASTReaderListener &Listener);
1409-
static bool ParseHeaderSearchOptions(const RecordData &Record, bool Complain,
1421+
static bool ParseHeaderSearchOptions(const RecordData &Record, StringRef ModuleFilename, bool Complain,
14101422
ASTReaderListener &Listener);
14111423
static bool ParseHeaderSearchPaths(const RecordData &Record, bool Complain,
14121424
ASTReaderListener &Listener);
1413-
static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain,
1425+
static bool ParsePreprocessorOptions(const RecordData &Record, StringRef ModuleFilename, bool Complain,
14141426
ASTReaderListener &Listener,
14151427
std::string &SuggestedPredefines);
14161428

clang/lib/Frontend/ASTUnit.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ class ASTInfoCollector : public ASTReaderListener {
536536
LangOpt(LangOpt), TargetOpts(TargetOpts), Target(Target),
537537
Counter(Counter) {}
538538

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

561561
bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
562+
StringRef ModuleFilename,
562563
StringRef SpecificModuleCachePath,
563564
bool Complain) override {
564565
// llvm::SaveAndRestore doesn't support bit field.
@@ -597,13 +598,14 @@ class ASTInfoCollector : public ASTReaderListener {
597598
}
598599

599600
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
601+
StringRef ModuleFilename,
600602
bool ReadMacros, bool Complain,
601603
std::string &SuggestedPredefines) override {
602604
this->PPOpts = PPOpts;
603605
return false;
604606
}
605607

606-
bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
608+
bool ReadTargetOptions(const TargetOptions &TargetOpts, StringRef ModuleFilename, bool Complain,
607609
bool AllowCompatibleDifferences) override {
608610
// If we've already initialized the target, don't do it again.
609611
if (Target)

clang/lib/Frontend/FrontendActions.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ namespace {
622622
Out.indent(2) << "Module map file: " << ModuleMapPath << "\n";
623623
}
624624

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

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

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

686686
bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
687+
StringRef ModuleFilename,
687688
StringRef SpecificModuleCachePath,
688689
bool Complain) override {
689690
Out.indent(2) << "Header search options:\n";
@@ -717,6 +718,7 @@ namespace {
717718
}
718719

719720
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
721+
StringRef ModuleFilename,
720722
bool ReadMacros, bool Complain,
721723
std::string &SuggestedPredefines) override {
722724
Out.indent(2) << "Preprocessor options:\n";

0 commit comments

Comments
 (0)