Skip to content

Commit efc82c4

Browse files
committed
[NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped enum (II)
Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D93765
1 parent abbef2f commit efc82c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+528
-573
lines changed

clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,7 @@ void ChangeNamespaceTool::run(
632632
return;
633633
// Ignore out-of-line static methods since they will be handled by nested
634634
// name specifiers.
635-
if (Func->getCanonicalDecl()->getStorageClass() ==
636-
StorageClass::SC_Static &&
635+
if (Func->getCanonicalDecl()->getStorageClass() == StorageClass::Static &&
637636
Func->isOutOfLine())
638637
return;
639638
const auto *Context = Result.Nodes.getNodeAs<Decl>("dc");

clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ FixItHint generateFixItHint(const FunctionDecl *Decl) {
5151
// A fixit can be generated for functions of static storage class but
5252
// otherwise the check cannot determine the appropriate function name prefix
5353
// to use.
54-
if (Decl->getStorageClass() != SC_Static)
54+
if (Decl->getStorageClass() != StorageClass::Static)
5555
return FixItHint();
5656

5757
StringRef Name = Decl->getName();
@@ -109,7 +109,7 @@ void FunctionNamingCheck::registerMatchers(MatchFinder *Finder) {
109109
void FunctionNamingCheck::check(const MatchFinder::MatchResult &Result) {
110110
const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>("function");
111111

112-
bool IsGlobal = MatchedDecl->getStorageClass() != SC_Static;
112+
bool IsGlobal = MatchedDecl->getStorageClass() != StorageClass::Static;
113113
diag(MatchedDecl->getLocation(),
114114
"%select{static function|function in global namespace}1 named %0 must "
115115
"%select{be in|have an appropriate prefix followed by}1 Pascal case as "

clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace {
2626
AST_MATCHER(VarDecl, isLocalVariable) { return Node.isLocalVarDecl(); }
2727

2828
FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
29-
if (IsConst && (Decl->getStorageClass() != SC_Static)) {
29+
if (IsConst && (Decl->getStorageClass() != StorageClass::Static)) {
3030
// No fix available if it is not a static constant, since it is difficult
3131
// to determine the proper fix in this case.
3232
return FixItHint();

clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,9 @@ void UseTrailingReturnTypeCheck::keepSpecifiers(
359359
// inline int.
360360
const auto *M = dyn_cast<CXXMethodDecl>(&F);
361361
if (!F.isConstexpr() && !F.isInlineSpecified() &&
362-
F.getStorageClass() != SC_Extern && F.getStorageClass() != SC_Static &&
363-
!Fr && !(M && M->isVirtualAsWritten()))
362+
F.getStorageClass() != StorageClass::Extern &&
363+
F.getStorageClass() != StorageClass::Static && !Fr &&
364+
!(M && M->isVirtualAsWritten()))
364365
return;
365366

366367
// Tokenize return type. If it contains macros which contain a mix of

clang/include/clang/AST/Decl.h

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
10571057
/// Returns true if a variable with function scope is a non-static local
10581058
/// variable.
10591059
bool hasLocalStorage() const {
1060-
if (getStorageClass() == SC_None) {
1060+
if (getStorageClass() == StorageClass::None) {
10611061
// OpenCL v1.2 s6.5.3: The __constant or constant address space name is
10621062
// used to describe variables allocated in global memory and which are
10631063
// accessed inside a kernel(s) as read-only variables. As such, variables
@@ -1069,29 +1069,40 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
10691069
}
10701070

10711071
// Global Named Register (GNU extension)
1072-
if (getStorageClass() == SC_Register && !isLocalVarDeclOrParm())
1072+
if (getStorageClass() == StorageClass::Register && !isLocalVarDeclOrParm())
10731073
return false;
10741074

10751075
// Return true for: Auto, Register.
10761076
// Return false for: Extern, Static, PrivateExtern, OpenCLWorkGroupLocal.
10771077

1078-
return getStorageClass() >= SC_Auto;
1078+
switch (getStorageClass()) {
1079+
case StorageClass::Auto:
1080+
case StorageClass::Register:
1081+
return true;
1082+
case StorageClass::Extern:
1083+
case StorageClass::None:
1084+
case StorageClass::PrivateExtern:
1085+
case StorageClass::Static:
1086+
return false;
1087+
}
1088+
llvm_unreachable("unknown storage class");
10791089
}
10801090

10811091
/// Returns true if a variable with function scope is a static local
10821092
/// variable.
10831093
bool isStaticLocal() const {
1084-
return (getStorageClass() == SC_Static ||
1094+
return (getStorageClass() == StorageClass::Static ||
10851095
// C++11 [dcl.stc]p4
1086-
(getStorageClass() == SC_None && getTSCSpec() == TSCS_thread_local))
1087-
&& !isFileVarDecl();
1096+
(getStorageClass() == StorageClass::None &&
1097+
getTSCSpec() == TSCS_thread_local)) &&
1098+
!isFileVarDecl();
10881099
}
10891100

10901101
/// Returns true if a variable has extern or __private_extern__
10911102
/// storage.
10921103
bool hasExternalStorage() const {
1093-
return getStorageClass() == SC_Extern ||
1094-
getStorageClass() == SC_PrivateExtern;
1104+
return getStorageClass() == StorageClass::Extern ||
1105+
getStorageClass() == StorageClass::PrivateExtern;
10951106
}
10961107

10971108
/// Returns true for all variables that do not have local storage.
@@ -1593,15 +1604,15 @@ class ImplicitParamDecl : public VarDecl {
15931604
IdentifierInfo *Id, QualType Type,
15941605
ImplicitParamKind ParamKind)
15951606
: VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type,
1596-
/*TInfo=*/nullptr, SC_None) {
1607+
/*TInfo=*/nullptr, StorageClass::None) {
15971608
NonParmVarDeclBits.ImplicitParamKind = ParamKind;
15981609
setImplicit();
15991610
}
16001611

16011612
ImplicitParamDecl(ASTContext &C, QualType Type, ImplicitParamKind ParamKind)
16021613
: VarDecl(ImplicitParam, C, /*DC=*/nullptr, SourceLocation(),
16031614
SourceLocation(), /*Id=*/nullptr, Type,
1604-
/*TInfo=*/nullptr, SC_None) {
1615+
/*TInfo=*/nullptr, StorageClass::None) {
16051616
NonParmVarDeclBits.ImplicitParamKind = ParamKind;
16061617
setImplicit();
16071618
}
@@ -2538,7 +2549,7 @@ class FunctionDecl : public DeclaratorDecl,
25382549

25392550
/// Sets the storage class as written in the source.
25402551
void setStorageClass(StorageClass SClass) {
2541-
FunctionDeclBits.SClass = SClass;
2552+
FunctionDeclBits.SClass = static_cast<uint64_t>(SClass);
25422553
}
25432554

25442555
/// Determine whether the "inline" keyword was specified for this
@@ -2565,7 +2576,7 @@ class FunctionDecl : public DeclaratorDecl,
25652576

25662577
bool doesDeclarationForceExternallyVisibleDefinition() const;
25672578

2568-
bool isStatic() const { return getStorageClass() == SC_Static; }
2579+
bool isStatic() const { return getStorageClass() == StorageClass::Static; }
25692580

25702581
/// Whether this function declaration represents an C++ overloaded
25712582
/// operator, e.g., "operator+".

clang/include/clang/AST/DeclCXX.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,7 @@ class CXXDeductionGuideDecl : public FunctionDecl {
18431843
const DeclarationNameInfo &NameInfo, QualType T,
18441844
TypeSourceInfo *TInfo, SourceLocation EndLocation)
18451845
: FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo,
1846-
SC_None, false, ConstexprSpecKind::Unspecified),
1846+
StorageClass::None, false, ConstexprSpecKind::Unspecified),
18471847
ExplicitSpec(ES) {
18481848
if (EndLocation.isValid())
18491849
setRangeEnd(EndLocation);
@@ -2657,8 +2657,8 @@ class CXXDestructorDecl : public CXXMethodDecl {
26572657
bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
26582658
Expr *TrailingRequiresClause = nullptr)
26592659
: CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo,
2660-
SC_None, isInline, ConstexprKind, SourceLocation(),
2661-
TrailingRequiresClause) {
2660+
StorageClass::None, isInline, ConstexprKind,
2661+
SourceLocation(), TrailingRequiresClause) {
26622662
setImplicit(isImplicitlyDeclared);
26632663
}
26642664

@@ -2713,7 +2713,7 @@ class CXXConversionDecl : public CXXMethodDecl {
27132713
ConstexprSpecKind ConstexprKind, SourceLocation EndLocation,
27142714
Expr *TrailingRequiresClause = nullptr)
27152715
: CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo,
2716-
SC_None, isInline, ConstexprKind, EndLocation,
2716+
StorageClass::None, isInline, ConstexprKind, EndLocation,
27172717
TrailingRequiresClause),
27182718
ExplicitSpec(ES) {}
27192719
void anchor() override;

clang/include/clang/AST/DeclOpenMP.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ class OMPCapturedExprDecl final : public VarDecl {
388388
QualType Type, TypeSourceInfo *TInfo,
389389
SourceLocation StartLoc)
390390
: VarDecl(OMPCapturedExpr, C, DC, StartLoc, StartLoc, Id, Type, TInfo,
391-
SC_None) {
391+
StorageClass::None) {
392392
setImplicit();
393393
}
394394

clang/include/clang/ASTMatchers/ASTMatchers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4723,7 +4723,7 @@ AST_POLYMORPHIC_MATCHER(isExternC, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
47234723
AST_POLYMORPHIC_MATCHER(isStaticStorageClass,
47244724
AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
47254725
VarDecl)) {
4726-
return Node.getStorageClass() == SC_Static;
4726+
return Node.getStorageClass() == StorageClass::Static;
47274727
}
47284728

47294729
/// Matches deleted function declarations.

clang/include/clang/Basic/Specifiers.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,21 +220,31 @@ namespace clang {
220220
};
221221

222222
/// Storage classes.
223-
enum StorageClass {
223+
enum class StorageClass {
224224
// These are legal on both functions and variables.
225-
SC_None,
226-
SC_Extern,
227-
SC_Static,
228-
SC_PrivateExtern,
225+
None,
226+
Extern,
227+
Static,
228+
PrivateExtern,
229229

230230
// These are only legal on variables.
231-
SC_Auto,
232-
SC_Register
231+
Auto,
232+
Register
233233
};
234234

235235
/// Checks whether the given storage class is legal for functions.
236236
inline bool isLegalForFunction(StorageClass SC) {
237-
return SC <= SC_PrivateExtern;
237+
switch (SC) {
238+
case StorageClass::None:
239+
case StorageClass::Extern:
240+
case StorageClass::Static:
241+
case StorageClass::PrivateExtern:
242+
return true;
243+
case StorageClass::Auto:
244+
case StorageClass::Register:
245+
return false;
246+
}
247+
llvm_unreachable("unknown storage class");
238248
}
239249

240250
/// Checks whether the given storage class is legal for variables.

clang/lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10681,7 +10681,7 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
1068110681
if (!VD->isFileVarDecl())
1068210682
return false;
1068310683
// Global named register variables (GNU extension) are never emitted.
10684-
if (VD->getStorageClass() == SC_Register)
10684+
if (VD->getStorageClass() == StorageClass::Register)
1068510685
return false;
1068610686
if (VD->getDescribedVarTemplate() ||
1068710687
isa<VarTemplatePartialSpecializationDecl>(VD))
@@ -11441,7 +11441,7 @@ bool ASTContext::mayExternalizeStaticVar(const Decl *D) const {
1144111441
(D->hasAttr<CUDAConstantAttr>() &&
1144211442
!D->getAttr<CUDAConstantAttr>()->isImplicit())) &&
1144311443
isa<VarDecl>(D) && cast<VarDecl>(D)->isFileVarDecl() &&
11444-
cast<VarDecl>(D)->getStorageClass() == SC_Static;
11444+
cast<VarDecl>(D)->getStorageClass() == StorageClass::Static;
1144511445
}
1144611446

1144711447
bool ASTContext::shouldExternalizeStaticVar(const Decl *D) const {

0 commit comments

Comments
 (0)