Skip to content

Commit 7ec1efa

Browse files
Michael137Julian Nagele
authored andcommitted
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) {} ``` (cherry picked from commit 99c08ff) Conflicts: clang/lib/Parse/ParseDecl.cpp
1 parent 9068713 commit 7ec1efa

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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 10 additions & 10 deletions
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

Lines changed: 3 additions & 23 deletions
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.
@@ -1146,28 +1148,6 @@ class SelectorTable {
11461148
static std::string getPropertyNameFromSetterSelector(Selector Sel);
11471149
};
11481150

1149-
/// A simple pair of identifier info and location.
1150-
class IdentifierLoc {
1151-
SourceLocation Loc;
1152-
IdentifierInfo *II = nullptr;
1153-
1154-
public:
1155-
IdentifierLoc() = default;
1156-
IdentifierLoc(SourceLocation L, IdentifierInfo *Ident) : Loc(L), II(Ident) {}
1157-
1158-
void setLoc(SourceLocation L) { Loc = L; }
1159-
void setIdentifierInfo(IdentifierInfo *Ident) { II = Ident; }
1160-
SourceLocation getLoc() const { return Loc; }
1161-
IdentifierInfo *getIdentifierInfo() const { return II; }
1162-
1163-
bool operator==(const IdentifierLoc &X) const {
1164-
return Loc == X.Loc && II == X.II;
1165-
}
1166-
1167-
bool operator!=(const IdentifierLoc &X) const {
1168-
return Loc != X.Loc || II != X.II;
1169-
}
1170-
};
11711151
} // namespace clang
11721152

11731153
namespace llvm {

clang/include/clang/Lex/ModuleLoader.h

Lines changed: 1 addition & 2 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class Preprocessor {
331331
SourceLocation ModuleImportLoc;
332332

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

336336
llvm::DenseMap<FileID, SmallVector<const char *>> CheckPoints;
337337
unsigned CheckPointCounter = 0;
@@ -626,7 +626,7 @@ class Preprocessor {
626626

627627
/// The identifier and source location of the currently-active
628628
/// \#pragma clang arc_cf_code_audited begin.
629-
IdentifierLoc PragmaARCCFCodeAuditedInfo;
629+
std::pair<IdentifierInfo *, SourceLocation> PragmaARCCFCodeAuditedInfo;
630630

631631
/// The source location of the currently-active
632632
/// \#pragma clang assume_nonnull begin.
@@ -2013,15 +2013,16 @@ class Preprocessor {
20132013
/// arc_cf_code_audited begin.
20142014
///
20152015
/// Returns an invalid location if there is no such pragma active.
2016-
IdentifierLoc getPragmaARCCFCodeAuditedInfo() const {
2016+
std::pair<IdentifierInfo *, SourceLocation>
2017+
getPragmaARCCFCodeAuditedInfo() const {
20172018
return PragmaARCCFCodeAuditedInfo;
20182019
}
20192020

20202021
/// Set the location of the currently-active \#pragma clang
20212022
/// arc_cf_code_audited begin. An invalid location ends the pragma.
20222023
void setPragmaARCCFCodeAuditedInfo(IdentifierInfo *Ident,
20232024
SourceLocation Loc) {
2024-
PragmaARCCFCodeAuditedInfo = IdentifierLoc(Loc, Ident);
2025+
PragmaARCCFCodeAuditedInfo = {Ident, Loc};
20252026
}
20262027

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

clang/include/clang/Parse/LoopHint.h

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,8 +1729,8 @@ class Parser : public CodeCompletionHandler {
17291729
ObjCTypeParamList *parseObjCTypeParamList();
17301730
ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
17311731
ObjCTypeParamListScope &Scope, SourceLocation &lAngleLoc,
1732-
SmallVectorImpl<IdentifierLoc> &protocolIdents, SourceLocation &rAngleLoc,
1733-
bool mayBeProtocolList = true);
1732+
SmallVectorImpl<IdentifierLocPair> &protocolIdents,
1733+
SourceLocation &rAngleLoc, bool mayBeProtocolList = true);
17341734

17351735
void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
17361736
SourceLocation atLoc,
@@ -3886,7 +3886,8 @@ class Parser : public CodeCompletionHandler {
38863886
SourceLocation Loc,
38873887
llvm::SmallVectorImpl<Expr *> &IntExprs);
38883888
/// Parses the 'device-type-list', which is a list of identifiers.
3889-
bool ParseOpenACCDeviceTypeList(llvm::SmallVector<IdentifierLoc> &Archs);
3889+
bool ParseOpenACCDeviceTypeList(
3890+
llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>> &Archs);
38903891
/// Parses the 'async-argument', which is an integral value with two
38913892
/// 'special' values that are likely negative (but come from Macros).
38923893
OpenACCIntExprParseResult ParseOpenACCAsyncArgument(OpenACCDirectiveKind DK,
@@ -4018,8 +4019,10 @@ class Parser : public CodeCompletionHandler {
40184019
return false;
40194020
}
40204021

4021-
bool ParseModuleName(SourceLocation UseLoc,
4022-
SmallVectorImpl<IdentifierLoc> &Path, bool IsImport);
4022+
bool ParseModuleName(
4023+
SourceLocation UseLoc,
4024+
SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>> &Path,
4025+
bool IsImport);
40234026

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

clang/include/clang/Sema/ParsedAttr.h

Lines changed: 10 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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)