[clang] 634eb7e - [NFC] Constify IdentifierInfo (#173266)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 23 09:26:30 PST 2025
Author: Akira Hatanaka
Date: 2025-12-23T09:26:26-08:00
New Revision: 634eb7ee40f77af280beb41220d25c9674cc8e6a
URL: https://github.com/llvm/llvm-project/commit/634eb7ee40f77af280beb41220d25c9674cc8e6a
DIFF: https://github.com/llvm/llvm-project/commit/634eb7ee40f77af280beb41220d25c9674cc8e6a.diff
LOG: [NFC] Constify IdentifierInfo (#173266)
This change updates several APIs and local uses to take pointers to
const IdentifierInfo where mutation is not required.
Added:
Modified:
clang/include/clang/Basic/Attr.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/DeclBase.cpp
clang/lib/Index/CommentToXML.cpp
clang/lib/Sema/SemaAvailability.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaExprObjC.cpp
clang/lib/Sema/SemaHLSL.cpp
clang/lib/Sema/SemaObjC.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index f85d2da21eab9..b017906a8d690 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1486,7 +1486,7 @@ def CPUSpecific : InheritableAttr {
let Subjects = SubjectList<[Function]>;
let Documentation = [CPUSpecificCPUDispatchDocs];
let AdditionalMembers = [{
- IdentifierInfo *getCPUName(unsigned Index) const {
+ const IdentifierInfo *getCPUName(unsigned Index) const {
return *(cpus_begin() + Index);
}
}];
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b5d9f4cf9fa8b..c9ad6860dc625 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4913,12 +4913,14 @@ class Sema final : public SemaBase {
bool CheckAttrTarget(const ParsedAttr &CurrAttr);
bool CheckAttrNoArgs(const ParsedAttr &CurrAttr);
- AvailabilityAttr *mergeAvailabilityAttr(
- NamedDecl *D, const AttributeCommonInfo &CI, IdentifierInfo *Platform,
- bool Implicit, VersionTuple Introduced, VersionTuple Deprecated,
- VersionTuple Obsoleted, bool IsUnavailable, StringRef Message,
- bool IsStrict, StringRef Replacement, AvailabilityMergeKind AMK,
- int Priority, IdentifierInfo *IIEnvironment);
+ AvailabilityAttr *
+ mergeAvailabilityAttr(NamedDecl *D, const AttributeCommonInfo &CI,
+ const IdentifierInfo *Platform, bool Implicit,
+ VersionTuple Introduced, VersionTuple Deprecated,
+ VersionTuple Obsoleted, bool IsUnavailable,
+ StringRef Message, bool IsStrict, StringRef Replacement,
+ AvailabilityMergeKind AMK, int Priority,
+ const IdentifierInfo *IIEnvironment);
TypeVisibilityAttr *
mergeTypeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI,
@@ -4949,16 +4951,16 @@ class Sema final : public SemaBase {
ErrorAttr *mergeErrorAttr(Decl *D, const AttributeCommonInfo &CI,
StringRef NewUserDiagnostic);
FormatAttr *mergeFormatAttr(Decl *D, const AttributeCommonInfo &CI,
- IdentifierInfo *Format, int FormatIdx,
+ const IdentifierInfo *Format, int FormatIdx,
int FirstArg);
FormatMatchesAttr *mergeFormatMatchesAttr(Decl *D,
const AttributeCommonInfo &CI,
- IdentifierInfo *Format,
+ const IdentifierInfo *Format,
int FormatIdx,
StringLiteral *FormatStr);
ModularFormatAttr *mergeModularFormatAttr(Decl *D,
const AttributeCommonInfo &CI,
- IdentifierInfo *ModularImplFn,
+ const IdentifierInfo *ModularImplFn,
StringRef ImplName,
MutableArrayRef<StringRef> Aspects);
@@ -4984,8 +4986,8 @@ class Sema final : public SemaBase {
void CheckAlignasUnderalignment(Decl *D);
/// AddModeAttr - Adds a mode attribute to a particular declaration.
- void AddModeAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo *Name,
- bool InInstantiation = false);
+ void AddModeAttr(Decl *D, const AttributeCommonInfo &CI,
+ const IdentifierInfo *Name, bool InInstantiation = false);
AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D,
const AttributeCommonInfo &CI,
const IdentifierInfo *Ident);
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 30c6d3ed91f1e..0a1e442656c35 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -711,7 +711,7 @@ static AvailabilityResult CheckAvailability(ASTContext &Context,
// Make sure that this declaration has already been introduced.
if (!A->getIntroduced().empty() &&
EnclosingVersion < A->getIntroduced()) {
- IdentifierInfo *IIEnv = A->getEnvironment();
+ const IdentifierInfo *IIEnv = A->getEnvironment();
auto &Triple = Context.getTargetInfo().getTriple();
StringRef TargetEnv = Triple.getEnvironmentName();
StringRef EnvName =
diff --git a/clang/lib/Index/CommentToXML.cpp b/clang/lib/Index/CommentToXML.cpp
index f54d8be790217..f396760126fcc 100644
--- a/clang/lib/Index/CommentToXML.cpp
+++ b/clang/lib/Index/CommentToXML.cpp
@@ -1065,7 +1065,7 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) {
if (AA->getUnavailable())
Result << "<Unavailable/>";
- IdentifierInfo *Environment = AA->getEnvironment();
+ const IdentifierInfo *Environment = AA->getEnvironment();
if (Environment) {
Result << "<Environment>" << Environment->getName() << "</Environment>";
}
diff --git a/clang/lib/Sema/SemaAvailability.cpp b/clang/lib/Sema/SemaAvailability.cpp
index b09e1684e4e64..3624e487a7572 100644
--- a/clang/lib/Sema/SemaAvailability.cpp
+++ b/clang/lib/Sema/SemaAvailability.cpp
@@ -33,7 +33,7 @@ using namespace sema;
static bool hasMatchingEnvironmentOrNone(const ASTContext &Context,
const AvailabilityAttr *AA) {
- IdentifierInfo *IIEnvironment = AA->getEnvironment();
+ const IdentifierInfo *IIEnvironment = AA->getEnvironment();
auto Environment = Context.getTargetInfo().getTriple().getEnvironment();
if (!IIEnvironment || Environment == llvm::Triple::UnknownEnvironment)
return true;
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 1679573d34d1f..263ce2118ba86 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1938,7 +1938,7 @@ static void handleCPUSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
if (!AL.checkAtLeastNumArgs(S, 1))
return;
- SmallVector<IdentifierInfo *, 8> CPUs;
+ SmallVector<const IdentifierInfo *, 8> CPUs;
for (unsigned ArgNo = 0; ArgNo < getNumAttributeArgs(AL); ++ArgNo) {
if (!AL.isArgIdent(ArgNo)) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
@@ -2291,7 +2291,7 @@ static void handleAttrWithMessage(Sema &S, Decl *D, const ParsedAttr &AL) {
}
static bool checkAvailabilityAttr(Sema &S, SourceRange Range,
- IdentifierInfo *Platform,
+ const IdentifierInfo *Platform,
VersionTuple Introduced,
VersionTuple Deprecated,
VersionTuple Obsoleted) {
@@ -2348,11 +2348,11 @@ static bool versionsMatch(const VersionTuple &X, const VersionTuple &Y,
}
AvailabilityAttr *Sema::mergeAvailabilityAttr(
- NamedDecl *D, const AttributeCommonInfo &CI, IdentifierInfo *Platform,
+ NamedDecl *D, const AttributeCommonInfo &CI, const IdentifierInfo *Platform,
bool Implicit, VersionTuple Introduced, VersionTuple Deprecated,
VersionTuple Obsoleted, bool IsUnavailable, StringRef Message,
bool IsStrict, StringRef Replacement, AvailabilityMergeKind AMK,
- int Priority, IdentifierInfo *Environment) {
+ int Priority, const IdentifierInfo *Environment) {
VersionTuple MergedIntroduced = Introduced;
VersionTuple MergedDeprecated = Deprecated;
VersionTuple MergedObsoleted = Obsoleted;
@@ -2380,13 +2380,13 @@ AvailabilityAttr *Sema::mergeAvailabilityAttr(
continue;
}
- IdentifierInfo *OldPlatform = OldAA->getPlatform();
+ const IdentifierInfo *OldPlatform = OldAA->getPlatform();
if (OldPlatform != Platform) {
++i;
continue;
}
- IdentifierInfo *OldEnvironment = OldAA->getEnvironment();
+ const IdentifierInfo *OldEnvironment = OldAA->getEnvironment();
if (OldEnvironment != Environment) {
++i;
continue;
@@ -3783,7 +3783,7 @@ ErrorAttr *Sema::mergeErrorAttr(Decl *D, const AttributeCommonInfo &CI,
}
FormatAttr *Sema::mergeFormatAttr(Decl *D, const AttributeCommonInfo &CI,
- IdentifierInfo *Format, int FormatIdx,
+ const IdentifierInfo *Format, int FormatIdx,
int FirstArg) {
// Check whether we already have an equivalent format attribute.
for (auto *F : D->specific_attrs<FormatAttr>()) {
@@ -3803,7 +3803,7 @@ FormatAttr *Sema::mergeFormatAttr(Decl *D, const AttributeCommonInfo &CI,
FormatMatchesAttr *Sema::mergeFormatMatchesAttr(Decl *D,
const AttributeCommonInfo &CI,
- IdentifierInfo *Format,
+ const IdentifierInfo *Format,
int FormatIdx,
StringLiteral *FormatStr) {
// Check whether we already have an equivalent FormatMatches attribute.
@@ -4757,7 +4757,7 @@ static void handleModeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
}
void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo &CI,
- IdentifierInfo *Name, bool InInstantiation) {
+ const IdentifierInfo *Name, bool InInstantiation) {
StringRef Str = Name->getName();
normalizeName(Str);
SourceLocation AttrLoc = CI.getLoc();
@@ -7004,7 +7004,7 @@ static void handleVTablePointerAuthentication(Sema &S, Decl *D,
}
static bool modularFormatAttrsEquiv(const ModularFormatAttr *Existing,
- IdentifierInfo *ModularImplFn,
+ const IdentifierInfo *ModularImplFn,
StringRef ImplName,
ArrayRef<StringRef> Aspects) {
return Existing->getModularImplFn() == ModularImplFn &&
@@ -7013,10 +7013,9 @@ static bool modularFormatAttrsEquiv(const ModularFormatAttr *Existing,
llvm::equal(Existing->aspects(), Aspects);
}
-ModularFormatAttr *
-Sema::mergeModularFormatAttr(Decl *D, const AttributeCommonInfo &CI,
- IdentifierInfo *ModularImplFn, StringRef ImplName,
- MutableArrayRef<StringRef> Aspects) {
+ModularFormatAttr *Sema::mergeModularFormatAttr(
+ Decl *D, const AttributeCommonInfo &CI, const IdentifierInfo *ModularImplFn,
+ StringRef ImplName, MutableArrayRef<StringRef> Aspects) {
if (const auto *Existing = D->getAttr<ModularFormatAttr>()) {
if (!modularFormatAttrsEquiv(Existing, ModularImplFn, ImplName, Aspects)) {
Diag(Existing->getLocation(), diag::err_duplicate_attribute) << *Existing;
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 4daf01703d7dd..5dbd64b65c015 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -4007,7 +4007,7 @@ static bool CheckObjCBridgeNSCast(Sema &S, QualType castType, Expr *castExpr,
while (const auto *TD = T->getAs<TypedefType>()) {
TypedefNameDecl *TDNDecl = TD->getDecl();
if (TB *ObjCBAttr = getObjCBridgeAttr<TB>(TD)) {
- if (IdentifierInfo *Parm = ObjCBAttr->getBridgedType()) {
+ if (const IdentifierInfo *Parm = ObjCBAttr->getBridgedType()) {
HadTheAttribute = true;
if (Parm->isStr("id"))
return true;
@@ -4070,7 +4070,7 @@ static bool CheckObjCBridgeCFCast(Sema &S, QualType castType, Expr *castExpr,
while (const auto *TD = T->getAs<TypedefType>()) {
TypedefNameDecl *TDNDecl = TD->getDecl();
if (TB *ObjCBAttr = getObjCBridgeAttr<TB>(TD)) {
- if (IdentifierInfo *Parm = ObjCBAttr->getBridgedType()) {
+ if (const IdentifierInfo *Parm = ObjCBAttr->getBridgedType()) {
HadTheAttribute = true;
if (Parm->isStr("id"))
return true;
@@ -4228,9 +4228,9 @@ bool SemaObjC::checkObjCBridgeRelatedComponents(
if (!ObjCBAttr)
return false;
- IdentifierInfo *RCId = ObjCBAttr->getRelatedClass();
- IdentifierInfo *CMId = ObjCBAttr->getClassMethod();
- IdentifierInfo *IMId = ObjCBAttr->getInstanceMethod();
+ const IdentifierInfo *RCId = ObjCBAttr->getRelatedClass();
+ const IdentifierInfo *CMId = ObjCBAttr->getClassMethod();
+ const IdentifierInfo *IMId = ObjCBAttr->getInstanceMethod();
if (!RCId)
return false;
NamedDecl *Target = nullptr;
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 06130c985876f..0c79f954d5a8d 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2693,7 +2693,7 @@ void DiagnoseHLSLAvailability::RunOnFunction(const FunctionDecl *FD) {
bool DiagnoseHLSLAvailability::HasMatchingEnvironmentOrNone(
const AvailabilityAttr *AA) {
- IdentifierInfo *IIEnvironment = AA->getEnvironment();
+ const IdentifierInfo *IIEnvironment = AA->getEnvironment();
if (!IIEnvironment)
return true;
@@ -2737,7 +2737,7 @@ void DiagnoseHLSLAvailability::CheckDeclAvailability(NamedDecl *D,
const AvailabilityAttr *AA,
SourceRange Range) {
- IdentifierInfo *IIEnv = AA->getEnvironment();
+ const IdentifierInfo *IIEnv = AA->getEnvironment();
if (!IIEnv) {
// The availability attribute does not have environment -> it depends only
diff --git a/clang/lib/Sema/SemaObjC.cpp b/clang/lib/Sema/SemaObjC.cpp
index 7aaa56e37b3be..dae30b7e941d1 100644
--- a/clang/lib/Sema/SemaObjC.cpp
+++ b/clang/lib/Sema/SemaObjC.cpp
@@ -1468,7 +1468,7 @@ bool SemaObjC::isCFError(RecordDecl *RD) {
// declared with "objc_bridge_mutable", so look for either one of the two
// attributes.
if (RD->getTagKind() == TagTypeKind::Struct) {
- IdentifierInfo *bridgedType = nullptr;
+ const IdentifierInfo *bridgedType = nullptr;
if (auto bridgeAttr = RD->getAttr<ObjCBridgeAttr>())
bridgedType = bridgeAttr->getBridgedType();
else if (auto bridgeAttr = RD->getAttr<ObjCBridgeMutableAttr>())
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
index bee9a01a3b01a..77f0cae29f043 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -130,7 +130,7 @@ static std::string ReadPCHRecord(StringRef type) {
.EndsWith("Decl *", "Record.readDeclAs<" + type.drop_back().str() + ">()")
.Case("TypeSourceInfo *", "Record.readTypeSourceInfo()")
.Case("Expr *", "Record.readExpr()")
- .Case("IdentifierInfo *", "Record.readIdentifier()")
+ .Case("const IdentifierInfo *", "Record.readIdentifier()")
.Case("StringRef", "Record.readString()")
.Case("ParamIdx", "ParamIdx::deserialize(Record.readInt())")
.Case("OMPTraitInfo *", "Record.readOMPTraitInfo()")
@@ -152,7 +152,7 @@ static std::string WritePCHRecord(StringRef type, StringRef name) {
.Case("TypeSourceInfo *",
"AddTypeSourceInfo(" + name.str() + ");\n")
.Case("Expr *", "AddStmt(" + name.str() + ");\n")
- .Case("IdentifierInfo *",
+ .Case("const IdentifierInfo *",
"AddIdentifierRef(" + name.str() + ");\n")
.Case("StringRef", "AddString(" + name.str() + ");\n")
.Case("ParamIdx", "push_back(" + name.str() + ".serialize());\n")
@@ -340,7 +340,7 @@ namespace {
return ((subject == list) || ...);
};
- if (IsOneOf(type, "IdentifierInfo *", "Expr *"))
+ if (IsOneOf(type, "const IdentifierInfo *", "Expr *"))
return "!get" + getUpperName().str() + "()";
if (IsOneOf(type, "TypeSourceInfo *"))
return "!get" + getUpperName().str() + "Loc()";
@@ -356,7 +356,7 @@ namespace {
if (type == "FunctionDecl *")
OS << "\" << get" << getUpperName()
<< "()->getNameInfo().getAsString() << \"";
- else if (type == "IdentifierInfo *")
+ else if (type == "const IdentifierInfo *")
// Some non-optional (comma required) identifier arguments can be the
// empty string but are then recorded as a nullptr.
OS << "\" << (get" << getUpperName() << "() ? get" << getUpperName()
@@ -375,7 +375,7 @@ namespace {
if (StringRef(type).ends_with("Decl *")) {
OS << " OS << \" \";\n";
OS << " dumpBareDeclRef(SA->get" << getUpperName() << "());\n";
- } else if (type == "IdentifierInfo *") {
+ } else if (type == "const IdentifierInfo *") {
// Some non-optional (comma required) identifier arguments can be the
// empty string but are then recorded as a nullptr.
OS << " if (SA->get" << getUpperName() << "())\n"
@@ -1371,8 +1371,7 @@ namespace {
class VariadicIdentifierArgument : public VariadicArgument {
public:
VariadicIdentifierArgument(const Record &Arg, StringRef Attr)
- : VariadicArgument(Arg, Attr, "IdentifierInfo *")
- {}
+ : VariadicArgument(Arg, Attr, "const IdentifierInfo *") {}
};
class VariadicStringArgument : public VariadicArgument {
@@ -1481,7 +1480,7 @@ createArgument(const Record &Arg, StringRef Attr,
Ptr = std::make_unique<SimpleArgument>(
Arg, Attr, (Arg.getValueAsDef("Kind")->getName() + "Decl *").str());
else if (ArgName == "IdentifierArgument")
- Ptr = std::make_unique<SimpleArgument>(Arg, Attr, "IdentifierInfo *");
+ Ptr = std::make_unique<SimpleArgument>(Arg, Attr, "const IdentifierInfo *");
else if (ArgName == "DefaultBoolArgument")
Ptr = std::make_unique<DefaultSimpleArgument>(
Arg, Attr, "bool", Arg.getValueAsBit("Default"));
More information about the cfe-commits
mailing list