Skip to content

Commit 3789122

Browse files
committed
[WIP] [clang] Refactor affecting LangOptions
1 parent 86077c4 commit 3789122

File tree

7 files changed

+453
-484
lines changed

7 files changed

+453
-484
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 368 additions & 419 deletions
Large diffs are not rendered by default.

clang/include/clang/Basic/LangOptions.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ enum class PointerAuthenticationMode : unsigned {
6666
SignAndAuth
6767
};
6868

69+
enum EffectKind {
70+
// Does affect the construction of the AST in a way that does prevent module
71+
// interoperability.
72+
Affecting,
73+
// Does affect the construction of the AST in a way that doesn't prevent
74+
// interoperability (that is, the value can be different between an explicit
75+
// module and the user of that module).
76+
Compatible,
77+
// Does not affect the construction of the AST in any way (that is, the
78+
// value can be different between an implicit module and the user of that
79+
// module).
80+
Benign,
81+
};
82+
6983
/// Bitfields of LangOptions, split out from LangOptions in order to ensure that
7084
/// this large collection of bitfields is a trivial class type.
7185
class LangOptionsBase {
@@ -486,16 +500,17 @@ class LangOptionsBase {
486500
};
487501

488502
// Define simple language options (with no accessors).
489-
#define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
490-
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
503+
#define LANGOPT(Name, Bits, Default, Compatibility, Description) \
504+
unsigned Name : Bits;
505+
#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description)
491506
#include "clang/Basic/LangOptions.def"
492507

493508
protected:
494509
// Define language options of enumeration type. These are private, and will
495510
// have accessors (below).
496-
#define LANGOPT(Name, Bits, Default, Description)
497-
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
498-
LLVM_PREFERRED_TYPE(Type) \
511+
#define LANGOPT(Name, Bits, Default, Compatibility, Description)
512+
#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \
513+
LLVM_PREFERRED_TYPE(Type) \
499514
unsigned Name : Bits;
500515
#include "clang/Basic/LangOptions.def"
501516
};
@@ -655,8 +670,8 @@ class LangOptions : public LangOptionsBase {
655670
LangStandard::Kind LangStd = LangStandard::lang_unspecified);
656671

657672
// Define accessors/mutators for language options of enumeration type.
658-
#define LANGOPT(Name, Bits, Default, Description)
659-
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
673+
#define LANGOPT(Name, Bits, Default, Compatibility, Description)
674+
#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \
660675
Type get##Name() const { return static_cast<Type>(Name); } \
661676
void set##Name(Type Value) { \
662677
assert(static_cast<unsigned>(Value) < (1u << Bits)); \

clang/lib/Basic/LangOptions.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@
1616
using namespace clang;
1717

1818
LangOptions::LangOptions() : LangStd(LangStandard::lang_unspecified) {
19-
#define LANGOPT(Name, Bits, Default, Description) Name = Default;
20-
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) set##Name(Default);
19+
#define LANGOPT(Name, Bits, Default, Compatibility, Description) Name = Default;
20+
#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \
21+
set##Name(Default);
2122
#include "clang/Basic/LangOptions.def"
2223
}
2324

2425
void LangOptions::resetNonModularOptions() {
25-
#define LANGOPT(Name, Bits, Default, Description)
26-
#define BENIGN_LANGOPT(Name, Bits, Default, Description) Name = Default;
27-
#define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
26+
#define LANGOPT(Name, Bits, Default, Compatibility, Description)
27+
#define BENIGN_LANGOPT(Name, Bits, Default, Compatibility, Description) \
28+
Name = Default;
29+
#define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, \
30+
Description) \
2831
Name = static_cast<unsigned>(Default);
2932
#include "clang/Basic/LangOptions.def"
3033

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5178,11 +5178,12 @@ std::string CompilerInvocation::getModuleHash() const {
51785178
HBuilder.add(serialization::VERSION_MAJOR, serialization::VERSION_MINOR);
51795179

51805180
// Extend the signature with the language options
5181-
#define LANGOPT(Name, Bits, Default, Description) HBuilder.add(LangOpts->Name);
5182-
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
5183-
HBuilder.add(static_cast<unsigned>(LangOpts->get##Name()));
5184-
#define BENIGN_LANGOPT(Name, Bits, Default, Description)
5185-
#define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
5181+
#define LANGOPT(Name, Bits, Default, Compatibility, Description) \
5182+
if constexpr (Compatibility != Benign) \
5183+
HBuilder.add(LangOpts->Name);
5184+
#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \
5185+
if constexpr (Compatibility != Benign) \
5186+
HBuilder.add(static_cast<unsigned>(LangOpts->get##Name()));
51865187
#include "clang/Basic/LangOptions.def"
51875188

51885189
HBuilder.addRange(getLangOpts().ModuleFeatures);

clang/lib/Frontend/FrontendActions.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -644,15 +644,16 @@ namespace {
644644
StringRef ModuleFilename, bool Complain,
645645
bool AllowCompatibleDifferences) override {
646646
Out.indent(2) << "Language options:\n";
647-
#define LANGOPT(Name, Bits, Default, Description) \
647+
#define LANGOPT(Name, Bits, Default, Compatibility, Description) \
648+
if constexpr (Compatibility != Benign) \
648649
DUMP_BOOLEAN(LangOpts.Name, Description);
649-
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
650-
Out.indent(4) << Description << ": " \
650+
#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \
651+
if constexpr (Compatibility != Benign) \
652+
Out.indent(4) << Description << ": " \
651653
<< static_cast<unsigned>(LangOpts.get##Name()) << "\n";
652-
#define VALUE_LANGOPT(Name, Bits, Default, Description) \
654+
#define VALUE_LANGOPT(Name, Bits, Default, Compatibility, Description) \
655+
if constexpr (Compatibility != Benign) \
653656
Out.indent(4) << Description << ": " << LangOpts.Name << "\n";
654-
#define BENIGN_LANGOPT(Name, Bits, Default, Description)
655-
#define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
656657
#include "clang/Basic/LangOptions.def"
657658

658659
if (!LangOpts.ModuleFeatures.empty()) {

clang/lib/Serialization/ASTReader.cpp

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -278,51 +278,51 @@ static bool checkLanguageOptions(const LangOptions &LangOpts,
278278
StringRef ModuleFilename,
279279
DiagnosticsEngine *Diags,
280280
bool AllowCompatibleDifferences = true) {
281-
#define LANGOPT(Name, Bits, Default, Description) \
282-
if (ExistingLangOpts.Name != LangOpts.Name) { \
283-
if (Diags) { \
284-
if (Bits == 1) \
285-
Diags->Report(diag::err_ast_file_langopt_mismatch) \
286-
<< Description << LangOpts.Name << ExistingLangOpts.Name \
287-
<< ModuleFilename; \
288-
else \
289-
Diags->Report(diag::err_ast_file_langopt_value_mismatch) \
290-
<< Description << ModuleFilename; \
281+
#define LANGOPT(Name, Bits, Default, Compatibility, Description) \
282+
if constexpr (Compatibility != Benign) { \
283+
if ((Compatibility == Affecting) || \
284+
(Compatibility == Compatible && !AllowCompatibleDifferences)) { \
285+
if (ExistingLangOpts.Name != LangOpts.Name) { \
286+
if (Diags) { \
287+
if (Bits == 1) \
288+
Diags->Report(diag::err_ast_file_langopt_mismatch) \
289+
<< Description << LangOpts.Name << ExistingLangOpts.Name \
290+
<< ModuleFilename; \
291+
else \
292+
Diags->Report(diag::err_ast_file_langopt_value_mismatch) \
293+
<< Description << ModuleFilename; \
294+
} \
295+
return true; \
296+
} \
291297
} \
292-
return true; \
293298
}
294299

295-
#define VALUE_LANGOPT(Name, Bits, Default, Description) \
296-
if (ExistingLangOpts.Name != LangOpts.Name) { \
297-
if (Diags) \
298-
Diags->Report(diag::err_ast_file_langopt_value_mismatch) \
299-
<< Description << ModuleFilename; \
300-
return true; \
300+
#define VALUE_LANGOPT(Name, Bits, Default, Compatibility, Description) \
301+
if constexpr (Compatibility != Benign) { \
302+
if ((Compatibility == Affecting) || \
303+
(Compatibility == Compatible && !AllowCompatibleDifferences)) { \
304+
if (ExistingLangOpts.Name != LangOpts.Name) { \
305+
if (Diags) \
306+
Diags->Report(diag::err_ast_file_langopt_value_mismatch) \
307+
<< Description << ModuleFilename; \
308+
return true; \
309+
} \
310+
} \
301311
}
302312

303-
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
304-
if (ExistingLangOpts.get##Name() != LangOpts.get##Name()) { \
305-
if (Diags) \
306-
Diags->Report(diag::err_ast_file_langopt_value_mismatch) \
307-
<< Description << ModuleFilename; \
308-
return true; \
313+
#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \
314+
if constexpr (Compatibility != Benign) { \
315+
if ((Compatibility == Affecting) || \
316+
(Compatibility == Compatible && !AllowCompatibleDifferences)) { \
317+
if (ExistingLangOpts.get##Name() != LangOpts.get##Name()) { \
318+
if (Diags) \
319+
Diags->Report(diag::err_ast_file_langopt_value_mismatch) \
320+
<< Description << ModuleFilename; \
321+
return true; \
322+
} \
323+
} \
309324
}
310325

311-
#define COMPATIBLE_LANGOPT(Name, Bits, Default, Description) \
312-
if (!AllowCompatibleDifferences) \
313-
LANGOPT(Name, Bits, Default, Description)
314-
315-
#define COMPATIBLE_ENUM_LANGOPT(Name, Bits, Default, Description) \
316-
if (!AllowCompatibleDifferences) \
317-
ENUM_LANGOPT(Name, Bits, Default, Description)
318-
319-
#define COMPATIBLE_VALUE_LANGOPT(Name, Bits, Default, Description) \
320-
if (!AllowCompatibleDifferences) \
321-
VALUE_LANGOPT(Name, Bits, Default, Description)
322-
323-
#define BENIGN_LANGOPT(Name, Bits, Default, Description)
324-
#define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
325-
#define BENIGN_VALUE_LANGOPT(Name, Bits, Default, Description)
326326
#include "clang/Basic/LangOptions.def"
327327

328328
if (ExistingLangOpts.ModuleFeatures != LangOpts.ModuleFeatures) {
@@ -6353,9 +6353,9 @@ bool ASTReader::ParseLanguageOptions(const RecordData &Record,
63536353
bool AllowCompatibleDifferences) {
63546354
LangOptions LangOpts;
63556355
unsigned Idx = 0;
6356-
#define LANGOPT(Name, Bits, Default, Description) \
6356+
#define LANGOPT(Name, Bits, Default, Compatibility, Description) \
63576357
LangOpts.Name = Record[Idx++];
6358-
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
6358+
#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \
63596359
LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++]));
63606360
#include "clang/Basic/LangOptions.def"
63616361
#define SANITIZER(NAME, ID) \

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,9 +1612,9 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, StringRef isysroot) {
16121612
// Language options.
16131613
Record.clear();
16141614
const LangOptions &LangOpts = PP.getLangOpts();
1615-
#define LANGOPT(Name, Bits, Default, Description) \
1615+
#define LANGOPT(Name, Bits, Default, Compatibility, Description) \
16161616
Record.push_back(LangOpts.Name);
1617-
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
1617+
#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \
16181618
Record.push_back(static_cast<unsigned>(LangOpts.get##Name()));
16191619
#include "clang/Basic/LangOptions.def"
16201620
#define SANITIZER(NAME, ID) \

0 commit comments

Comments
 (0)