[clang] [clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data structures to `IdentifierLoc` (PR #135808)

2025-04-15 Thread via cfe-commits


@@ -466,6 +467,29 @@ class FullSourceLoc : public SourceLocation {
   }
 };
 
+/// A simple pair of identifier info and location.
+class IdentifierLoc {
+  SourceLocation Loc;
+  IdentifierInfo *II = nullptr;
+
+public:
+  IdentifierLoc() = default;
+  IdentifierLoc(SourceLocation L, IdentifierInfo *Ident) : Loc(L), II(Ident) {}
+
+  void setLoc(SourceLocation L) { Loc = L; }
+  void setIdentifierInfo(IdentifierInfo *Ident) { II = Ident; }
+  SourceLocation getLoc() const { return Loc; }
+  IdentifierInfo *getIdentifierInfo() const { return II; }
+
+  bool operator==(const IdentifierLoc &X) const {
+return Loc == X.Loc && II == X.II;
+  }
+
+  bool operator!=(const IdentifierLoc &X) const {
+return Loc != X.Loc || II != X.II;
+  }
+};
+

yronglin wrote:

Agree, I have moved `IdentifierLoc` to`IdentifierLoc.h`.

https://github.com/llvm/llvm-project/pull/135808
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data structures to `IdentifierLoc` (PR #135808)

2025-04-15 Thread via cfe-commits

yronglin wrote:

@mizvekov @cor3ntin @erichkeane  Thanks for your review!

https://github.com/llvm/llvm-project/pull/135808
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data structures to `IdentifierLoc` (PR #135808)

2025-04-15 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

lgtm, but make sure to address Matheus's comments

https://github.com/llvm/llvm-project/pull/135808
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data structures to `IdentifierLoc` (PR #135808)

2025-04-15 Thread via cfe-commits

https://github.com/cor3ntin reopened 
https://github.com/llvm/llvm-project/pull/135808
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data structures to `IdentifierLoc` (PR #135808)

2025-04-15 Thread via cfe-commits

https://github.com/cor3ntin closed 
https://github.com/llvm/llvm-project/pull/135808
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data structures to `IdentifierLoc` (PR #135808)

2025-04-15 Thread Matheus Izvekov via cfe-commits


@@ -466,6 +467,29 @@ class FullSourceLoc : public SourceLocation {
   }
 };
 
+/// A simple pair of identifier info and location.
+class IdentifierLoc {
+  SourceLocation Loc;
+  IdentifierInfo *II = nullptr;
+
+public:
+  IdentifierLoc() = default;
+  IdentifierLoc(SourceLocation L, IdentifierInfo *Ident) : Loc(L), II(Ident) {}
+
+  void setLoc(SourceLocation L) { Loc = L; }
+  void setIdentifierInfo(IdentifierInfo *Ident) { II = Ident; }
+  SourceLocation getLoc() const { return Loc; }
+  IdentifierInfo *getIdentifierInfo() const { return II; }
+
+  bool operator==(const IdentifierLoc &X) const {
+return Loc == X.Loc && II == X.II;
+  }
+
+  bool operator!=(const IdentifierLoc &X) const {
+return Loc != X.Loc || II != X.II;
+  }
+};
+

mizvekov wrote:

I think this would be more appropriate to stay in `IdentifierTable.h`

Not only it already had IdentifierLocPair, but there is more precedent in that 
sort of direction.
Ie we have precedent to define the `Loc` versions of AST nodes in the same 
headers which define the basic AST node. See for example NestedNameSpecifierLoc.

On the other hand, this would be the first Loc-like entity which we are 
defining in the SourceLocation Header, which would be breaking a clear line we 
have in place today.

https://github.com/llvm/llvm-project/pull/135808
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data structures to `IdentifierLoc` (PR #135808)

2025-04-15 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/135808
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data structures to `IdentifierLoc` (PR #135808)

2025-04-15 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov commented:

Thanks, I like the idea!

https://github.com/llvm/llvm-project/pull/135808
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data structures to `IdentifierLoc` (PR #135808)

2025-04-15 Thread Erich Keane via cfe-commits

https://github.com/erichkeane approved this pull request.

I REALLY like this.  I THINK this ends up being pretty trivial implementation 
for most of the files, and did a quick overlook on it, but please let another 
person or two do the scroll through to mkae sure I didnt miss anything.

https://github.com/llvm/llvm-project/pull/135808
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data structures to `IdentifierLoc` (PR #135808)

2025-04-15 Thread via cfe-commits

https://github.com/yronglin edited 
https://github.com/llvm/llvm-project/pull/135808
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data structures to `IdentifierLoc` (PR #135808)

2025-04-15 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-clang

Author: None (yronglin)


Changes

Currently we have many similiar data structures like:
 - `std::pair`.
 - Element type of `ModuleIdPath`.
 - `IdentifierLocPair`.
 - `IdentifierLoc`.
 
This PR unify these data structures to `IdentifierLoc`. I found this issue when 
I working on https://github.com/llvm/llvm-project/pull/107168.

---

Patch is 105.19 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/135808.diff


44 Files Affected:

- (modified) clang/include/clang/AST/OpenACCClause.h (+2-2) 
- (modified) clang/include/clang/Basic/IdentifierTable.h (-3) 
- (modified) clang/include/clang/Basic/SourceLocation.h (+24) 
- (modified) clang/include/clang/Lex/ModuleLoader.h (+1-1) 
- (modified) clang/include/clang/Lex/Preprocessor.h (+4-5) 
- (modified) clang/include/clang/Parse/LoopHint.h (-1) 
- (modified) clang/include/clang/Parse/Parser.h (+5-8) 
- (modified) clang/include/clang/Sema/ParsedAttr.h (-10) 
- (modified) clang/include/clang/Sema/Sema.h (+1-1) 
- (modified) clang/include/clang/Sema/SemaCodeCompletion.h (+1-2) 
- (modified) clang/include/clang/Sema/SemaObjC.h (+2-2) 
- (modified) clang/include/clang/Sema/SemaOpenACC.h (+1-1) 
- (modified) clang/lib/AST/OpenACCClause.cpp (+2-2) 
- (modified) clang/lib/AST/TextNodeDumper.cpp (+2-2) 
- (modified) clang/lib/Frontend/CompilerInstance.cpp (+28-25) 
- (modified) clang/lib/Frontend/FrontendActions.cpp (+2-2) 
- (modified) clang/lib/Lex/PPDirectives.cpp (+11-11) 
- (modified) clang/lib/Lex/PPLexerChange.cpp (+3-3) 
- (modified) clang/lib/Lex/Pragma.cpp (+35-38) 
- (modified) clang/lib/Lex/Preprocessor.cpp (+8-8) 
- (modified) clang/lib/Parse/ParseDecl.cpp (+14-14) 
- (modified) clang/lib/Parse/ParseExpr.cpp (+4-3) 
- (modified) clang/lib/Parse/ParseHLSL.cpp (+1-1) 
- (modified) clang/lib/Parse/ParseObjc.cpp (+18-20) 
- (modified) clang/lib/Parse/ParseOpenACC.cpp (+7-5) 
- (modified) clang/lib/Parse/ParsePragma.cpp (+7-8) 
- (modified) clang/lib/Parse/ParseStmt.cpp (+3-3) 
- (modified) clang/lib/Parse/Parser.cpp (+9-10) 
- (modified) clang/lib/Sema/ParsedAttr.cpp (-8) 
- (modified) clang/lib/Sema/SemaARM.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+4-4) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+65-59) 
- (modified) clang/lib/Sema/SemaDeclObjC.cpp (+19-16) 
- (modified) clang/lib/Sema/SemaHLSL.cpp (+6-6) 
- (modified) clang/lib/Sema/SemaModule.cpp (+23-19) 
- (modified) clang/lib/Sema/SemaObjC.cpp (+23-22) 
- (modified) clang/lib/Sema/SemaOpenACCClause.cpp (+6-5) 
- (modified) clang/lib/Sema/SemaStmtAttr.cpp (+16-13) 
- (modified) clang/lib/Sema/SemaSwift.cpp (+12-12) 
- (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+5-5) 
- (modified) clang/lib/Sema/SemaType.cpp (+6-7) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+1-1) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+4-4) 
- (modified) clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/AST/OpenACCClause.h 
b/clang/include/clang/AST/OpenACCClause.h
index 3687af76a559f..0f09fa7d0a698 100644
--- a/clang/include/clang/AST/OpenACCClause.h
+++ b/clang/include/clang/AST/OpenACCClause.h
@@ -258,7 +258,7 @@ inline bool operator!=(const OpenACCBindClause &LHS,
   return !(LHS == RHS);
 }
 
-using DeviceTypeArgument = std::pair;
+using DeviceTypeArgument = IdentifierLoc;
 /// A 'device_type' or 'dtype' clause, takes a list of either an 'asterisk' or
 /// an identifier. The 'asterisk' means 'the rest'.
 class OpenACCDeviceTypeClause final
@@ -302,7 +302,7 @@ class OpenACCDeviceTypeClause final
   }
   bool hasAsterisk() const {
 return getArchitectures().size() > 0 &&
-   getArchitectures()[0].first == nullptr;
+   getArchitectures()[0].getIdentifierInfo() == nullptr;
   }
 
   ArrayRef getArchitectures() const {
diff --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index 0347880244a40..55ef6e571aff2 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -76,9 +76,6 @@ inline bool isReservedInAllContexts(ReservedIdentifierStatus 
Status) {
  Status != ReservedIdentifierStatus::StartsWithUnderscoreAndIsExternC;
 }
 
-/// A simple pair of identifier info and location.
-using IdentifierLocPair = std::pair;
-
 /// IdentifierInfo and other related classes are aligned to
 /// 8 bytes so that DeclarationName can use the lower 3 bits
 /// of a pointer to one of these classes.
diff --git a/clang/include/clang/Basic/SourceLocation.h 
b/clang/include/clang/Basic/SourceLocation.h
index 7a0f5ba8d1270..8039172188746 100644
--- a/clang/include/clang/Basic/SourceLocation.h
+++ b/clang/include/clang/Basic/SourceLocation.h
@@ -31,6 +31,7 @@ template  struct FoldingSetTrait;
 
 namespace clang {
 
+class IdentifierInfo;
 class SourceManager;
 
 /