Skip to content

Commit 99c08ff

Browse files
authored
Revert "[clang] Unify SourceLocation and IdentifierInfo* pair-like data structures to IdentifierLoc" (llvm#135974)
Reverts llvm#135808 Example from the LLDB macOS CI: https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/24084/execution/node/54/log/?consoleFull ``` /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp:360:49: error: no viable conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'clang::ModuleIdPath' (aka 'ArrayRef<IdentifierLoc>') clang::Module *top_level_module = DoGetModule(clang_path.front(), false); ^~~~~~~~~~~~~~~~~~ /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:41:40: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'const llvm::ArrayRef<clang::IdentifierLoc> &' for 1st argument class LLVM_GSL_POINTER [[nodiscard]] ArrayRef { ^ /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:41:40: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'llvm::ArrayRef<clang::IdentifierLoc> &&' for 1st argument /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:70:18: note: candidate constructor not viable: no known conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'std::nullopt_t' for 1st argument /*implicit*/ ArrayRef(std::nullopt_t) {} ```
1 parent ef1abbe commit 99c08ff

Some content is hidden

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

45 files changed

+384
-399
lines changed

clang-tools-extra/pp-trace/PPCallbacksTracker.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,8 @@ void PPCallbacksTracker::appendArgument(const char *Name, ModuleIdPath Value) {
547547
if (I)
548548
SS << ", ";
549549
SS << "{"
550-
<< "Name: " << Value[I].getIdentifierInfo()->getName() << ", "
551-
<< "Loc: " << getSourceLocationString(PP, Value[I].getLoc()) << "}";
550+
<< "Name: " << Value[I].first->getName() << ", "
551+
<< "Loc: " << getSourceLocationString(PP, Value[I].second) << "}";
552552
}
553553
SS << "]";
554554
appendArgument(Name, SS.str());

clang/include/clang/AST/OpenACCClause.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ inline bool operator!=(const OpenACCBindClause &LHS,
258258
return !(LHS == RHS);
259259
}
260260

261-
using DeviceTypeArgument = IdentifierLoc;
261+
using DeviceTypeArgument = std::pair<IdentifierInfo *, SourceLocation>;
262262
/// A 'device_type' or 'dtype' clause, takes a list of either an 'asterisk' or
263263
/// an identifier. The 'asterisk' means 'the rest'.
264264
class OpenACCDeviceTypeClause final
@@ -280,16 +280,16 @@ class OpenACCDeviceTypeClause final
280280
"Invalid clause kind for device-type");
281281

282282
assert(!llvm::any_of(Archs, [](const DeviceTypeArgument &Arg) {
283-
return Arg.getLoc().isInvalid();
283+
return Arg.second.isInvalid();
284284
}) && "Invalid SourceLocation for an argument");
285285

286-
assert((Archs.size() == 1 ||
287-
!llvm::any_of(Archs,
288-
[](const DeviceTypeArgument &Arg) {
289-
return Arg.getIdentifierInfo() == nullptr;
290-
})) &&
291-
"Only a single asterisk version is permitted, and must be the "
292-
"only one");
286+
assert(
287+
(Archs.size() == 1 || !llvm::any_of(Archs,
288+
[](const DeviceTypeArgument &Arg) {
289+
return Arg.first == nullptr;
290+
})) &&
291+
"Only a single asterisk version is permitted, and must be the "
292+
"only one");
293293

294294
std::uninitialized_copy(Archs.begin(), Archs.end(),
295295
getTrailingObjects<DeviceTypeArgument>());
@@ -302,7 +302,7 @@ class OpenACCDeviceTypeClause final
302302
}
303303
bool hasAsterisk() const {
304304
return getArchitectures().size() > 0 &&
305-
getArchitectures()[0].getIdentifierInfo() == nullptr;
305+
getArchitectures()[0].first == nullptr;
306306
}
307307

308308
ArrayRef<DeviceTypeArgument> getArchitectures() const {

clang/include/clang/Basic/IdentifierTable.h

+3-23
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "clang/Basic/Builtins.h"
1919
#include "clang/Basic/DiagnosticIDs.h"
2020
#include "clang/Basic/LLVM.h"
21-
#include "clang/Basic/SourceLocation.h"
2221
#include "clang/Basic/TokenKinds.h"
2322
#include "llvm/ADT/DenseMapInfo.h"
2423
#include "llvm/ADT/FoldingSet.h"
@@ -77,6 +76,9 @@ inline bool isReservedInAllContexts(ReservedIdentifierStatus Status) {
7776
Status != ReservedIdentifierStatus::StartsWithUnderscoreAndIsExternC;
7877
}
7978

79+
/// A simple pair of identifier info and location.
80+
using IdentifierLocPair = std::pair<IdentifierInfo *, SourceLocation>;
81+
8082
/// IdentifierInfo and other related classes are aligned to
8183
/// 8 bytes so that DeclarationName can use the lower 3 bits
8284
/// of a pointer to one of these classes.
@@ -1163,28 +1165,6 @@ class SelectorTable {
11631165
static std::string getPropertyNameFromSetterSelector(Selector Sel);
11641166
};
11651167

1166-
/// A simple pair of identifier info and location.
1167-
class IdentifierLoc {
1168-
SourceLocation Loc;
1169-
IdentifierInfo *II = nullptr;
1170-
1171-
public:
1172-
IdentifierLoc() = default;
1173-
IdentifierLoc(SourceLocation L, IdentifierInfo *Ident) : Loc(L), II(Ident) {}
1174-
1175-
void setLoc(SourceLocation L) { Loc = L; }
1176-
void setIdentifierInfo(IdentifierInfo *Ident) { II = Ident; }
1177-
SourceLocation getLoc() const { return Loc; }
1178-
IdentifierInfo *getIdentifierInfo() const { return II; }
1179-
1180-
bool operator==(const IdentifierLoc &X) const {
1181-
return Loc == X.Loc && II == X.II;
1182-
}
1183-
1184-
bool operator!=(const IdentifierLoc &X) const {
1185-
return Loc != X.Loc || II != X.II;
1186-
}
1187-
};
11881168
} // namespace clang
11891169

11901170
namespace llvm {

clang/include/clang/Lex/ModuleLoader.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef LLVM_CLANG_LEX_MODULELOADER_H
1515
#define LLVM_CLANG_LEX_MODULELOADER_H
1616

17-
#include "clang/Basic/IdentifierTable.h"
1817
#include "clang/Basic/LLVM.h"
1918
#include "clang/Basic/Module.h"
2019
#include "clang/Basic/SourceLocation.h"
@@ -30,7 +29,7 @@ class IdentifierInfo;
3029

3130
/// A sequence of identifier/location pairs used to describe a particular
3231
/// module or submodule, e.g., std.vector.
33-
using ModuleIdPath = ArrayRef<IdentifierLoc>;
32+
using ModuleIdPath = ArrayRef<std::pair<IdentifierInfo *, SourceLocation>>;
3433

3534
/// Describes the result of attempting to load a module.
3635
class ModuleLoadResult {

clang/include/clang/Lex/PPCallbacks.h

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#define LLVM_CLANG_LEX_PPCALLBACKS_H
1616

1717
#include "clang/Basic/DiagnosticIDs.h"
18-
#include "clang/Basic/IdentifierTable.h"
1918
#include "clang/Basic/SourceLocation.h"
2019
#include "clang/Basic/SourceManager.h"
2120
#include "clang/Lex/ModuleLoader.h"

clang/include/clang/Lex/Preprocessor.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ class Preprocessor {
327327
SourceLocation ModuleImportLoc;
328328

329329
/// The import path for named module that we're currently processing.
330-
SmallVector<IdentifierLoc, 2> NamedModuleImportPath;
330+
SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> NamedModuleImportPath;
331331

332332
llvm::DenseMap<FileID, SmallVector<const char *>> CheckPoints;
333333
unsigned CheckPointCounter = 0;
@@ -622,7 +622,7 @@ class Preprocessor {
622622

623623
/// The identifier and source location of the currently-active
624624
/// \#pragma clang arc_cf_code_audited begin.
625-
IdentifierLoc PragmaARCCFCodeAuditedInfo;
625+
std::pair<IdentifierInfo *, SourceLocation> PragmaARCCFCodeAuditedInfo;
626626

627627
/// The source location of the currently-active
628628
/// \#pragma clang assume_nonnull begin.
@@ -1998,15 +1998,16 @@ class Preprocessor {
19981998
/// arc_cf_code_audited begin.
19991999
///
20002000
/// Returns an invalid location if there is no such pragma active.
2001-
IdentifierLoc getPragmaARCCFCodeAuditedInfo() const {
2001+
std::pair<IdentifierInfo *, SourceLocation>
2002+
getPragmaARCCFCodeAuditedInfo() const {
20022003
return PragmaARCCFCodeAuditedInfo;
20032004
}
20042005

20052006
/// Set the location of the currently-active \#pragma clang
20062007
/// arc_cf_code_audited begin. An invalid location ends the pragma.
20072008
void setPragmaARCCFCodeAuditedInfo(IdentifierInfo *Ident,
20082009
SourceLocation Loc) {
2009-
PragmaARCCFCodeAuditedInfo = IdentifierLoc(Loc, Ident);
2010+
PragmaARCCFCodeAuditedInfo = {Ident, Loc};
20102011
}
20112012

20122013
/// The location of the currently-active \#pragma clang

clang/include/clang/Parse/LoopHint.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
#ifndef LLVM_CLANG_PARSE_LOOPHINT_H
1010
#define LLVM_CLANG_PARSE_LOOPHINT_H
1111

12-
#include "clang/Basic/IdentifierTable.h"
1312
#include "clang/Basic/SourceLocation.h"
1413

1514
namespace clang {
1615

1716
class Expr;
17+
struct IdentifierLoc;
1818

1919
/// Loop optimization hint for loop and unroll pragmas.
2020
struct LoopHint {

clang/include/clang/Parse/Parser.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -1725,8 +1725,8 @@ class Parser : public CodeCompletionHandler {
17251725
ObjCTypeParamList *parseObjCTypeParamList();
17261726
ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
17271727
ObjCTypeParamListScope &Scope, SourceLocation &lAngleLoc,
1728-
SmallVectorImpl<IdentifierLoc> &protocolIdents, SourceLocation &rAngleLoc,
1729-
bool mayBeProtocolList = true);
1728+
SmallVectorImpl<IdentifierLocPair> &protocolIdents,
1729+
SourceLocation &rAngleLoc, bool mayBeProtocolList = true);
17301730

17311731
void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
17321732
SourceLocation atLoc,
@@ -3818,7 +3818,8 @@ class Parser : public CodeCompletionHandler {
38183818
SourceLocation Loc,
38193819
llvm::SmallVectorImpl<Expr *> &IntExprs);
38203820
/// Parses the 'device-type-list', which is a list of identifiers.
3821-
bool ParseOpenACCDeviceTypeList(llvm::SmallVector<IdentifierLoc> &Archs);
3821+
bool ParseOpenACCDeviceTypeList(
3822+
llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>> &Archs);
38223823
/// Parses the 'async-argument', which is an integral value with two
38233824
/// 'special' values that are likely negative (but come from Macros).
38243825
OpenACCIntExprParseResult ParseOpenACCAsyncArgument(OpenACCDirectiveKind DK,
@@ -3950,8 +3951,10 @@ class Parser : public CodeCompletionHandler {
39503951
return false;
39513952
}
39523953

3953-
bool ParseModuleName(SourceLocation UseLoc,
3954-
SmallVectorImpl<IdentifierLoc> &Path, bool IsImport);
3954+
bool ParseModuleName(
3955+
SourceLocation UseLoc,
3956+
SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>> &Path,
3957+
bool IsImport);
39553958

39563959
//===--------------------------------------------------------------------===//
39573960
// C++11/G++: Type Traits [Type-Traits.html in the GCC manual]

clang/include/clang/Sema/ParsedAttr.h

+10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class LangOptions;
4040
class Sema;
4141
class Stmt;
4242
class TargetInfo;
43+
struct IdentifierLoc;
4344

4445
/// Represents information about a change in availability for
4546
/// an entity, which is part of the encoding of the 'availability'
@@ -98,6 +99,15 @@ struct PropertyData {
9899

99100
} // namespace detail
100101

102+
/// Wraps an identifier and optional source location for the identifier.
103+
struct IdentifierLoc {
104+
SourceLocation Loc;
105+
IdentifierInfo *Ident;
106+
107+
static IdentifierLoc *create(ASTContext &Ctx, SourceLocation Loc,
108+
IdentifierInfo *Ident);
109+
};
110+
101111
/// A union of the various pointer types that can be passed to an
102112
/// ParsedAttr as an argument.
103113
using ArgsUnion = llvm::PointerUnion<Expr *, IdentifierLoc *>;

clang/include/clang/Sema/Sema.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ enum class LangAS : unsigned int;
143143
class LocalInstantiationScope;
144144
class LookupResult;
145145
class MangleNumberingContext;
146-
typedef ArrayRef<IdentifierLoc> ModuleIdPath;
146+
typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> ModuleIdPath;
147147
class ModuleLoader;
148148
class MultiLevelTemplateArgumentList;
149149
struct NormalizedConstraint;

clang/include/clang/Sema/SemaCodeCompletion.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ class SemaCodeCompletion : public SemaBase {
193193
void CodeCompleteObjCForCollection(Scope *S, DeclGroupPtrTy IterationVar);
194194
void CodeCompleteObjCSelector(Scope *S,
195195
ArrayRef<const IdentifierInfo *> SelIdents);
196-
void CodeCompleteObjCProtocolReferences(ArrayRef<IdentifierLoc> Protocols);
196+
void
197+
CodeCompleteObjCProtocolReferences(ArrayRef<IdentifierLocPair> Protocols);
197198
void CodeCompleteObjCProtocolDecl(Scope *S);
198199
void CodeCompleteObjCInterfaceDecl(Scope *S);
199200
void CodeCompleteObjCClassForwardDecl(Scope *S);

clang/include/clang/Sema/SemaObjC.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,11 @@ class SemaObjC : public SemaBase {
307307

308308
DeclGroupPtrTy
309309
ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc,
310-
ArrayRef<IdentifierLoc> IdentList,
310+
ArrayRef<IdentifierLocPair> IdentList,
311311
const ParsedAttributesView &attrList);
312312

313313
void FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer,
314-
ArrayRef<IdentifierLoc> ProtocolId,
314+
ArrayRef<IdentifierLocPair> ProtocolId,
315315
SmallVectorImpl<Decl *> &Protocols);
316316

317317
void DiagnoseTypeArgsAndProtocols(IdentifierInfo *ProtocolId,

clang/include/clang/Sema/SemaOpenACC.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class SemaOpenACC : public SemaBase {
212212
} LoopWithoutSeqInfo;
213213

214214
// Redeclaration of the version in OpenACCClause.h.
215-
using DeviceTypeArgument = IdentifierLoc;
215+
using DeviceTypeArgument = std::pair<IdentifierInfo *, SourceLocation>;
216216

217217
/// A type to represent all the data for an OpenACC Clause that has been
218218
/// parsed, but not yet created/semantically analyzed. This is effectively a

clang/lib/AST/OpenACCClause.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -891,10 +891,10 @@ void OpenACCClausePrinter::VisitDeviceTypeClause(
891891
OS << "(";
892892
llvm::interleaveComma(C.getArchitectures(), OS,
893893
[&](const DeviceTypeArgument &Arch) {
894-
if (Arch.getIdentifierInfo() == nullptr)
894+
if (Arch.first == nullptr)
895895
OS << "*";
896896
else
897-
OS << Arch.getIdentifierInfo()->getName();
897+
OS << Arch.first->getName();
898898
});
899899
OS << ")";
900900
}

clang/lib/AST/TextNodeDumper.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,10 @@ void TextNodeDumper::Visit(const OpenACCClause *C) {
500500
llvm::interleaveComma(
501501
cast<OpenACCDeviceTypeClause>(C)->getArchitectures(), OS,
502502
[&](const DeviceTypeArgument &Arch) {
503-
if (Arch.getIdentifierInfo() == nullptr)
503+
if (Arch.first == nullptr)
504504
OS << "*";
505505
else
506-
OS << Arch.getIdentifierInfo()->getName();
506+
OS << Arch.first->getName();
507507
});
508508
OS << ")";
509509
break;

0 commit comments

Comments
 (0)