Skip to content

Commit ab680c5

Browse files
committed
Revert "[clang][NFC] Convert Sema::PragmaMsStackAction to scoped enum"
This reverts commit bd2a3f8d90368288a73dd2ef1926f714acd9eff3.
1 parent 21444e3 commit ab680c5

File tree

4 files changed

+91
-101
lines changed

4 files changed

+91
-101
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -475,16 +475,6 @@ enum class PragmaClangSectionKind {
475475

476476
enum class PragmaClangSectionAction { Set = 0, Clear = 1 };
477477

478-
enum PragmaMsStackAction {
479-
Reset = 0x0, // #pragma ()
480-
Set = 0x1, // #pragma (value)
481-
Push = 0x2, // #pragma (push[, id])
482-
Pop = 0x4, // #pragma (pop[, id])
483-
Show = 0x8, // #pragma (show) -- only for "pack"!
484-
PushSet = Push | Set, // #pragma (push[, id], value)
485-
PopSet = Pop | Set, // #pragma (pop[, id], value)
486-
};
487-
488478
/// Sema - This implements semantic analysis and AST building for C.
489479
/// \nosubgrouping
490480
class Sema final : public SemaBase {
@@ -1446,6 +1436,16 @@ class Sema final : public SemaBase {
14461436
PragmaClangSection PragmaClangRelroSection;
14471437
PragmaClangSection PragmaClangTextSection;
14481438

1439+
enum PragmaMsStackAction {
1440+
PSK_Reset = 0x0, // #pragma ()
1441+
PSK_Set = 0x1, // #pragma (value)
1442+
PSK_Push = 0x2, // #pragma (push[, id])
1443+
PSK_Pop = 0x4, // #pragma (pop[, id])
1444+
PSK_Show = 0x8, // #pragma (show) -- only for "pack"!
1445+
PSK_Push_Set = PSK_Push | PSK_Set, // #pragma (push[, id], value)
1446+
PSK_Pop_Set = PSK_Pop | PSK_Set, // #pragma (pop[, id], value)
1447+
};
1448+
14491449
struct PragmaPackInfo {
14501450
PragmaMsStackAction Action;
14511451
StringRef SlotLabel;
@@ -1569,15 +1569,15 @@ class Sema final : public SemaBase {
15691569

15701570
void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action,
15711571
llvm::StringRef StackSlotLabel, ValueType Value) {
1572-
if (Action == PragmaMsStackAction::Reset) {
1572+
if (Action == PSK_Reset) {
15731573
CurrentValue = DefaultValue;
15741574
CurrentPragmaLocation = PragmaLocation;
15751575
return;
15761576
}
1577-
if (Action & PragmaMsStackAction::Push)
1577+
if (Action & PSK_Push)
15781578
Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation,
15791579
PragmaLocation);
1580-
else if (Action & PragmaMsStackAction::Pop) {
1580+
else if (Action & PSK_Pop) {
15811581
if (!StackSlotLabel.empty()) {
15821582
// If we've got a label, try to find it and jump there.
15831583
auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
@@ -1596,7 +1596,7 @@ class Sema final : public SemaBase {
15961596
Stack.pop_back();
15971597
}
15981598
}
1599-
if (Action & PragmaMsStackAction::Set) {
1599+
if (Action & PSK_Set) {
16001600
CurrentValue = Value;
16011601
CurrentPragmaLocation = PragmaLocation;
16021602
}
@@ -1617,8 +1617,7 @@ class Sema final : public SemaBase {
16171617
//
16181618
// Push / pop a named sentinel slot.
16191619
void SentinelAction(PragmaMsStackAction Action, StringRef Label) {
1620-
assert((Action == PragmaMsStackAction::Push ||
1621-
Action == PragmaMsStackAction::Pop) &&
1620+
assert((Action == PSK_Push || Action == PSK_Pop) &&
16221621
"Can only push / pop #pragma stack sentinels!");
16231622
Act(CurrentPragmaLocation, Action, Label, CurrentValue);
16241623
}
@@ -1630,7 +1629,7 @@ class Sema final : public SemaBase {
16301629
bool hasValue() const { return CurrentValue != DefaultValue; }
16311630

16321631
SmallVector<Slot, 2> Stack;
1633-
ValueType DefaultValue; // Value used for PragmaMsStackAction::Reset action.
1632+
ValueType DefaultValue; // Value used for PSK_Reset action.
16341633
ValueType CurrentValue;
16351634
SourceLocation CurrentPragmaLocation;
16361635
};

clang/lib/Parse/ParsePragma.cpp

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,8 @@ void Parser::HandlePragmaFloatControl() {
869869
// and the FloatControl is the lower 16 bits. Use shift and bit-and
870870
// to decode the parts.
871871
uintptr_t Value = reinterpret_cast<uintptr_t>(Tok.getAnnotationValue());
872-
PragmaMsStackAction Action =
873-
static_cast<PragmaMsStackAction>((Value >> 16) & 0xFFFF);
872+
Sema::PragmaMsStackAction Action =
873+
static_cast<Sema::PragmaMsStackAction>((Value >> 16) & 0xFFFF);
874874
PragmaFloatControlKind Kind = PragmaFloatControlKind(Value & 0xFFFF);
875875
SourceLocation PragmaLoc = ConsumeAnnotationToken();
876876
Actions.ActOnPragmaFloatControl(PragmaLoc, Action, Kind);
@@ -1019,8 +1019,8 @@ void Parser::HandlePragmaMSPointersToMembers() {
10191019
void Parser::HandlePragmaMSVtorDisp() {
10201020
assert(Tok.is(tok::annot_pragma_ms_vtordisp));
10211021
uintptr_t Value = reinterpret_cast<uintptr_t>(Tok.getAnnotationValue());
1022-
PragmaMsStackAction Action =
1023-
static_cast<PragmaMsStackAction>((Value >> 16) & 0xFFFF);
1022+
Sema::PragmaMsStackAction Action =
1023+
static_cast<Sema::PragmaMsStackAction>((Value >> 16) & 0xFFFF);
10241024
MSVtorDispMode Mode = MSVtorDispMode(Value & 0xFFFF);
10251025
SourceLocation PragmaLoc = ConsumeAnnotationToken();
10261026
Actions.ActOnPragmaMSVtorDisp(Action, PragmaLoc, Mode);
@@ -1151,21 +1151,21 @@ bool Parser::HandlePragmaMSSegment(StringRef PragmaName,
11511151
return false;
11521152
}
11531153
PP.Lex(Tok); // (
1154-
PragmaMsStackAction Action = PragmaMsStackAction::Reset;
1154+
Sema::PragmaMsStackAction Action = Sema::PSK_Reset;
11551155
StringRef SlotLabel;
11561156
if (Tok.isAnyIdentifier()) {
11571157
StringRef PushPop = Tok.getIdentifierInfo()->getName();
11581158
if (PushPop == "push")
1159-
Action = PragmaMsStackAction::Push;
1159+
Action = Sema::PSK_Push;
11601160
else if (PushPop == "pop")
1161-
Action = PragmaMsStackAction::Pop;
1161+
Action = Sema::PSK_Pop;
11621162
else {
11631163
PP.Diag(PragmaLocation,
11641164
diag::warn_pragma_expected_section_push_pop_or_name)
11651165
<< PragmaName;
11661166
return false;
11671167
}
1168-
if (Action != PragmaMsStackAction::Reset) {
1168+
if (Action != Sema::PSK_Reset) {
11691169
PP.Lex(Tok); // push | pop
11701170
if (Tok.is(tok::comma)) {
11711171
PP.Lex(Tok); // ,
@@ -1191,12 +1191,10 @@ bool Parser::HandlePragmaMSSegment(StringRef PragmaName,
11911191
StringLiteral *SegmentName = nullptr;
11921192
if (Tok.isNot(tok::r_paren)) {
11931193
if (Tok.isNot(tok::string_literal)) {
1194-
unsigned DiagID =
1195-
Action != PragmaMsStackAction::Reset
1196-
? !SlotLabel.empty()
1197-
? diag::warn_pragma_expected_section_name
1198-
: diag::warn_pragma_expected_section_label_or_name
1199-
: diag::warn_pragma_expected_section_push_pop_or_name;
1194+
unsigned DiagID = Action != Sema::PSK_Reset ? !SlotLabel.empty() ?
1195+
diag::warn_pragma_expected_section_name :
1196+
diag::warn_pragma_expected_section_label_or_name :
1197+
diag::warn_pragma_expected_section_push_pop_or_name;
12001198
PP.Diag(PragmaLocation, DiagID) << PragmaName;
12011199
return false;
12021200
}
@@ -1211,7 +1209,7 @@ bool Parser::HandlePragmaMSSegment(StringRef PragmaName,
12111209
}
12121210
// Setting section "" has no effect
12131211
if (SegmentName->getLength())
1214-
Action = (PragmaMsStackAction)(Action | PragmaMsStackAction::Set);
1212+
Action = (Sema::PragmaMsStackAction)(Action | Sema::PSK_Set);
12151213
}
12161214
if (Tok.isNot(tok::r_paren)) {
12171215
PP.Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
@@ -1300,23 +1298,23 @@ bool Parser::HandlePragmaMSStrictGuardStackCheck(
13001298
PragmaName))
13011299
return false;
13021300

1303-
PragmaMsStackAction Action = PragmaMsStackAction::Set;
1301+
Sema::PragmaMsStackAction Action = Sema::PSK_Set;
13041302
if (Tok.is(tok::identifier)) {
13051303
StringRef PushPop = Tok.getIdentifierInfo()->getName();
13061304
if (PushPop == "push") {
13071305
PP.Lex(Tok);
1308-
Action = PragmaMsStackAction::Push;
1306+
Action = Sema::PSK_Push;
13091307
if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_punc,
13101308
PragmaName))
13111309
return false;
13121310
} else if (PushPop == "pop") {
13131311
PP.Lex(Tok);
1314-
Action = PragmaMsStackAction::Pop;
1312+
Action = Sema::PSK_Pop;
13151313
}
13161314
}
13171315

13181316
bool Value = false;
1319-
if (Action & PragmaMsStackAction::Push || Action & PragmaMsStackAction::Set) {
1317+
if (Action & Sema::PSK_Push || Action & Sema::PSK_Set) {
13201318
const IdentifierInfo *II = Tok.getIdentifierInfo();
13211319
if (II && II->isStr("off")) {
13221320
PP.Lex(Tok);
@@ -2140,7 +2138,7 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
21402138
return;
21412139
}
21422140

2143-
PragmaMsStackAction Action = PragmaMsStackAction::Reset;
2141+
Sema::PragmaMsStackAction Action = Sema::PSK_Reset;
21442142
StringRef SlotLabel;
21452143
Token Alignment;
21462144
Alignment.startToken();
@@ -2154,12 +2152,12 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
21542152
// the push/pop stack.
21552153
// In Apple gcc/XL, #pragma pack(4) is equivalent to #pragma pack(push, 4)
21562154
Action = (PP.getLangOpts().ApplePragmaPack || PP.getLangOpts().XLPragmaPack)
2157-
? PragmaMsStackAction::PushSet
2158-
: PragmaMsStackAction::Set;
2155+
? Sema::PSK_Push_Set
2156+
: Sema::PSK_Set;
21592157
} else if (Tok.is(tok::identifier)) {
21602158
// Map pragma pack options to pack (integer).
21612159
auto MapPack = [&](const char *Literal) {
2162-
Action = PragmaMsStackAction::PushSet;
2160+
Action = Sema::PSK_Push_Set;
21632161
Alignment = Tok;
21642162
Alignment.setKind(tok::numeric_constant);
21652163
Alignment.setLiteralData(Literal);
@@ -2168,7 +2166,7 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
21682166

21692167
const IdentifierInfo *II = Tok.getIdentifierInfo();
21702168
if (II->isStr("show")) {
2171-
Action = PragmaMsStackAction::Show;
2169+
Action = Sema::PSK_Show;
21722170
PP.Lex(Tok);
21732171
} else if (II->isStr("packed") && PP.getLangOpts().ZOSExt) {
21742172
// #pragma pack(packed) is the same as #pragma pack(1)
@@ -2184,13 +2182,13 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
21842182
PP.Lex(Tok);
21852183
} else if (II->isStr("reset") && PP.getLangOpts().ZOSExt) {
21862184
// #pragma pack(reset) is the same as #pragma pack(pop) on XL
2187-
Action = PragmaMsStackAction::Pop;
2185+
Action = Sema::PSK_Pop;
21882186
PP.Lex(Tok);
21892187
} else {
21902188
if (II->isStr("push")) {
2191-
Action = PragmaMsStackAction::Push;
2189+
Action = Sema::PSK_Push;
21922190
} else if (II->isStr("pop")) {
2193-
Action = PragmaMsStackAction::Pop;
2191+
Action = Sema::PSK_Pop;
21942192
} else {
21952193
PP.Diag(Tok.getLocation(), diag::warn_pragma_invalid_action) << "pack";
21962194
return;
@@ -2201,7 +2199,7 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
22012199
PP.Lex(Tok);
22022200

22032201
if (Tok.is(tok::numeric_constant)) {
2204-
Action = (PragmaMsStackAction)(Action | PragmaMsStackAction::Set);
2202+
Action = (Sema::PragmaMsStackAction)(Action | Sema::PSK_Set);
22052203
Alignment = Tok;
22062204

22072205
PP.Lex(Tok);
@@ -2217,7 +2215,7 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
22172215
return;
22182216
}
22192217

2220-
Action = (PragmaMsStackAction)(Action | PragmaMsStackAction::Set);
2218+
Action = (Sema::PragmaMsStackAction)(Action | Sema::PSK_Set);
22212219
Alignment = Tok;
22222220

22232221
PP.Lex(Tok);
@@ -2234,7 +2232,7 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
22342232
// the push/pop stack.
22352233
// In Apple gcc and IBM XL, #pragma pack() is equivalent to #pragma
22362234
// pack(pop).
2237-
Action = PragmaMsStackAction::Pop;
2235+
Action = Sema::PSK_Pop;
22382236
}
22392237

22402238
if (Tok.isNot(tok::r_paren)) {
@@ -2897,7 +2895,7 @@ void PragmaMSVtorDisp::HandlePragma(Preprocessor &PP,
28972895
}
28982896
PP.Lex(Tok);
28992897

2900-
PragmaMsStackAction Action = PragmaMsStackAction::Set;
2898+
Sema::PragmaMsStackAction Action = Sema::PSK_Set;
29012899
const IdentifierInfo *II = Tok.getIdentifierInfo();
29022900
if (II) {
29032901
if (II->isStr("push")) {
@@ -2908,24 +2906,24 @@ void PragmaMSVtorDisp::HandlePragma(Preprocessor &PP,
29082906
return;
29092907
}
29102908
PP.Lex(Tok);
2911-
Action = PragmaMsStackAction::PushSet;
2909+
Action = Sema::PSK_Push_Set;
29122910
// not push, could be on/off
29132911
} else if (II->isStr("pop")) {
29142912
// #pragma vtordisp(pop)
29152913
PP.Lex(Tok);
2916-
Action = PragmaMsStackAction::Pop;
2914+
Action = Sema::PSK_Pop;
29172915
}
29182916
// not push or pop, could be on/off
29192917
} else {
29202918
if (Tok.is(tok::r_paren)) {
29212919
// #pragma vtordisp()
2922-
Action = PragmaMsStackAction::Reset;
2920+
Action = Sema::PSK_Reset;
29232921
}
29242922
}
29252923

29262924

29272925
uint64_t Value = 0;
2928-
if (Action & PragmaMsStackAction::Push || Action & PragmaMsStackAction::Set) {
2926+
if (Action & Sema::PSK_Push || Action & Sema::PSK_Set) {
29292927
const IdentifierInfo *II = Tok.getIdentifierInfo();
29302928
if (II && II->isStr("off")) {
29312929
PP.Lex(Tok);
@@ -3016,7 +3014,7 @@ void PragmaMSPragma::HandlePragma(Preprocessor &PP,
30163014
void PragmaFloatControlHandler::HandlePragma(Preprocessor &PP,
30173015
PragmaIntroducer Introducer,
30183016
Token &Tok) {
3019-
PragmaMsStackAction Action = PragmaMsStackAction::Set;
3017+
Sema::PragmaMsStackAction Action = Sema::PSK_Set;
30203018
SourceLocation FloatControlLoc = Tok.getLocation();
30213019
Token PragmaName = Tok;
30223020
if (!PP.getTargetInfo().hasStrictFP() && !PP.getLangOpts().ExpStrictFP) {
@@ -3056,8 +3054,7 @@ void PragmaFloatControlHandler::HandlePragma(Preprocessor &PP,
30563054
return;
30573055
}
30583056
PP.Lex(Tok); // Eat the r_paren
3059-
Action = (Kind == PFC_Pop) ? PragmaMsStackAction::Pop
3060-
: PragmaMsStackAction::Push;
3057+
Action = (Kind == PFC_Pop) ? Sema::PSK_Pop : Sema::PSK_Push;
30613058
} else {
30623059
if (Tok.is(tok::r_paren))
30633060
// Selecting Precise or Except
@@ -3081,7 +3078,7 @@ void PragmaFloatControlHandler::HandlePragma(Preprocessor &PP,
30813078
if (Kind == PFC_Except)
30823079
Kind = PFC_NoExcept;
30833080
} else if (PushOnOff == "push") {
3084-
Action = PragmaMsStackAction::PushSet;
3081+
Action = Sema::PSK_Push_Set;
30853082
} else {
30863083
PP.Diag(Tok.getLocation(), diag::err_pragma_float_control_malformed);
30873084
return;
@@ -3095,7 +3092,7 @@ void PragmaFloatControlHandler::HandlePragma(Preprocessor &PP,
30953092
}
30963093
StringRef ExpectedPush = Tok.getIdentifierInfo()->getName();
30973094
if (ExpectedPush == "push") {
3098-
Action = PragmaMsStackAction::PushSet;
3095+
Action = Sema::PSK_Push_Set;
30993096
} else {
31003097
PP.Diag(Tok.getLocation(), diag::err_pragma_float_control_malformed);
31013098
return;

0 commit comments

Comments
 (0)