Skip to content

Commit 2692eb0

Browse files
committed
Move vtordisp mode from Attr class to LangOptions.h, NFC
This removes one of the two uses of Attr.h in DeclCXX.h, reducing the need to include Attr.h as widely. LangOptions is already very popular.
1 parent b6ae524 commit 2692eb0

File tree

11 files changed

+25
-23
lines changed

11 files changed

+25
-23
lines changed

clang/include/clang/AST/DeclCXX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,7 @@ class CXXRecordDecl : public RecordDecl {
17551755

17561756
/// Controls when vtordisps will be emitted if this record is used as a
17571757
/// virtual base.
1758-
MSVtorDispAttr::Mode getMSVtorDispMode() const;
1758+
MSVtorDispMode getMSVtorDispMode() const;
17591759

17601760
/// Determine whether this lambda expression was known to be dependent
17611761
/// at the time it was created, even if its context does not appear to be

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3021,13 +3021,7 @@ def MSVtorDisp : InheritableAttr {
30213021
let SemaHandler = 0;
30223022

30233023
let AdditionalMembers = [{
3024-
enum Mode {
3025-
Never,
3026-
ForVBaseOverride,
3027-
ForVFTable
3028-
};
3029-
3030-
Mode getVtorDispMode() const { return Mode(vdm); }
3024+
MSVtorDispMode getVtorDispMode() const { return MSVtorDispMode(vdm); }
30313025
}];
30323026
let Documentation = [Undocumented];
30333027
}

clang/include/clang/Basic/LangOptions.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ BENIGN_LANGOPT(BracketDepth, 32, 256,
304304
BENIGN_LANGOPT(NumLargeByValueCopy, 32, 0,
305305
"if non-zero, warn about parameter or return Warn if parameter/return value is larger in bytes than this setting. 0 is no check.")
306306
VALUE_LANGOPT(MSCompatibilityVersion, 32, 0, "Microsoft Visual C/C++ Version")
307-
VALUE_LANGOPT(VtorDispMode, 2, 1, "How many vtordisps to insert")
307+
ENUM_LANGOPT(VtorDispMode, MSVtorDispMode, 2, MSVtorDispMode::ForVBaseOverride,
308+
"How many vtordisps to insert")
308309

309310
LANGOPT(ApplePragmaPack, 1, 0, "Apple gcc-compatible #pragma pack handling")
310311

clang/include/clang/Basic/LangOptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class LangOptionsBase {
4444
#include "clang/Basic/LangOptions.def"
4545
};
4646

47+
/// In the Microsoft ABI, this controls the placement of virtual displacement
48+
/// members used to implement virtual inheritance.
49+
enum class MSVtorDispMode { Never, ForVBaseOverride, ForVFTable };
50+
4751
/// Keeps track of the various options that can be
4852
/// enabled, which controls the dialect of C or C++ that is accepted.
4953
class LangOptions : public LangOptionsBase {
@@ -91,6 +95,8 @@ class LangOptions : public LangOptionsBase {
9195
PPTMK_FullGeneralityVirtualInheritance
9296
};
9397

98+
using MSVtorDispMode = clang::MSVtorDispMode;
99+
94100
enum DefaultCallingConvention {
95101
DCC_None,
96102
DCC_CDecl,

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ class Sema final {
518518
/// structors
519519
/// 2: Always insert vtordisps to support RTTI on partially constructed
520520
/// objects
521-
PragmaStack<MSVtorDispAttr::Mode> VtorDispStack;
521+
PragmaStack<MSVtorDispMode> VtorDispStack;
522522
// #pragma pack.
523523
// Sentinel to represent when the stack is set to mac68k alignment.
524524
static const unsigned kMac68kAlignmentSentinel = ~0U;
@@ -8960,7 +8960,7 @@ class Sema final {
89608960
/// Called on well formed \#pragma vtordisp().
89618961
void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action,
89628962
SourceLocation PragmaLoc,
8963-
MSVtorDispAttr::Mode Value);
8963+
MSVtorDispMode Value);
89648964

89658965
enum PragmaSectionKind {
89668966
PSK_DataSeg,

clang/lib/AST/MicrosoftCXXABI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ CXXRecordDecl::getMSInheritanceModel() const {
171171
return IA->getSemanticSpelling();
172172
}
173173

174-
MSVtorDispAttr::Mode CXXRecordDecl::getMSVtorDispMode() const {
174+
MSVtorDispMode CXXRecordDecl::getMSVtorDispMode() const {
175175
if (MSVtorDispAttr *VDA = getAttr<MSVtorDispAttr>())
176176
return VDA->getVtorDispMode();
177-
return MSVtorDispAttr::Mode(getASTContext().getLangOpts().VtorDispMode);
177+
return getASTContext().getLangOpts().getVtorDispMode();
178178
}
179179

180180
// Returns the number of pointer and integer slots used to represent a member

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,7 +2956,7 @@ void MicrosoftRecordLayoutBuilder::computeVtorDispSet(
29562956
const CXXRecordDecl *RD) const {
29572957
// /vd2 or #pragma vtordisp(2): Always use vtordisps for virtual bases with
29582958
// vftables.
2959-
if (RD->getMSVtorDispMode() == MSVtorDispAttr::ForVFTable) {
2959+
if (RD->getMSVtorDispMode() == MSVtorDispMode::ForVFTable) {
29602960
for (const CXXBaseSpecifier &Base : RD->vbases()) {
29612961
const CXXRecordDecl *BaseDecl = Base.getType()->getAsCXXRecordDecl();
29622962
const ASTRecordLayout &Layout = Context.getASTRecordLayout(BaseDecl);
@@ -2979,12 +2979,12 @@ void MicrosoftRecordLayoutBuilder::computeVtorDispSet(
29792979
// * A user declared constructor or destructor aren't declared.
29802980
// * #pragma vtordisp(0) or the /vd0 flag are in use.
29812981
if ((!RD->hasUserDeclaredConstructor() && !RD->hasUserDeclaredDestructor()) ||
2982-
RD->getMSVtorDispMode() == MSVtorDispAttr::Never)
2982+
RD->getMSVtorDispMode() == MSVtorDispMode::Never)
29832983
return;
29842984
// /vd1 or #pragma vtordisp(1): Try to guess based on whether we think it's
29852985
// possible for a partially constructed object with virtual base overrides to
29862986
// escape a non-trivial constructor.
2987-
assert(RD->getMSVtorDispMode() == MSVtorDispAttr::ForVBaseOverride);
2987+
assert(RD->getMSVtorDispMode() == MSVtorDispMode::ForVBaseOverride);
29882988
// Compute a set of base classes which define methods we override. A virtual
29892989
// base in this set will require a vtordisp. A virtual base that transitively
29902990
// contains one of these bases as a non-virtual base will also require a

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2716,7 +2716,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
27162716
OPT_fno_dollars_in_identifiers,
27172717
Opts.DollarIdents);
27182718
Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings);
2719-
Opts.VtorDispMode = getLastArgIntValue(Args, OPT_vtordisp_mode_EQ, 1, Diags);
2719+
Opts.setVtorDispMode(
2720+
MSVtorDispMode(getLastArgIntValue(Args, OPT_vtordisp_mode_EQ, 1, Diags)));
27202721
Opts.Borland = Args.hasArg(OPT_fborland_extensions);
27212722
Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings);
27222723
Opts.ConstStrings = Args.hasFlag(OPT_fconst_strings, OPT_fno_const_strings,

clang/lib/Parse/ParsePragma.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ void Parser::HandlePragmaMSVtorDisp() {
734734
uintptr_t Value = reinterpret_cast<uintptr_t>(Tok.getAnnotationValue());
735735
Sema::PragmaMsStackAction Action =
736736
static_cast<Sema::PragmaMsStackAction>((Value >> 16) & 0xFFFF);
737-
MSVtorDispAttr::Mode Mode = MSVtorDispAttr::Mode(Value & 0xFFFF);
737+
MSVtorDispMode Mode = MSVtorDispMode(Value & 0xFFFF);
738738
SourceLocation PragmaLoc = ConsumeAnnotationToken();
739739
Actions.ActOnPragmaMSVtorDisp(Action, PragmaLoc, Mode);
740740
}

clang/lib/Sema/Sema.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
137137
OriginalLexicalContext(nullptr), MSStructPragmaOn(false),
138138
MSPointerToMemberRepresentationMethod(
139139
LangOpts.getMSPointerToMemberRepresentationMethod()),
140-
VtorDispStack(MSVtorDispAttr::Mode(LangOpts.VtorDispMode)), PackStack(0),
140+
VtorDispStack(LangOpts.getVtorDispMode()), PackStack(0),
141141
DataSegStack(nullptr), BSSSegStack(nullptr), ConstSegStack(nullptr),
142142
CodeSegStack(nullptr), CurInitSeg(nullptr), VisContext(nullptr),
143143
PragmaAttributeCurrentTargetDecl(nullptr),

clang/lib/Sema/SemaAttr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ void Sema::AddMsStructLayoutForRecord(RecordDecl *RD) {
8080
// FIXME: We should merge AddAlignmentAttributesForRecord with
8181
// AddMsStructLayoutForRecord into AddPragmaAttributesForRecord, which takes
8282
// all active pragmas and applies them as attributes to class definitions.
83-
if (VtorDispStack.CurrentValue != getLangOpts().VtorDispMode)
84-
RD->addAttr(
85-
MSVtorDispAttr::CreateImplicit(Context, VtorDispStack.CurrentValue));
83+
if (VtorDispStack.CurrentValue != getLangOpts().getVtorDispMode())
84+
RD->addAttr(MSVtorDispAttr::CreateImplicit(
85+
Context, unsigned(VtorDispStack.CurrentValue)));
8686
}
8787

8888
template <typename Attribute>
@@ -416,7 +416,7 @@ void Sema::ActOnPragmaMSPointersToMembers(
416416

417417
void Sema::ActOnPragmaMSVtorDisp(PragmaMsStackAction Action,
418418
SourceLocation PragmaLoc,
419-
MSVtorDispAttr::Mode Mode) {
419+
MSVtorDispMode Mode) {
420420
if (Action & PSK_Pop && VtorDispStack.Stack.empty())
421421
Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "vtordisp"
422422
<< "stack empty";

0 commit comments

Comments
 (0)