[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-13 Thread Rahul Joshi via cfe-commits

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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-13 Thread Rahul Joshi via cfe-commits


@@ -1419,16 +1412,14 @@ void clang::EmitClangDiagsDefs(const RecordKeeper 
&Records, raw_ostream &OS,
   InferPedantic inferPedantic(DGParentMap, Diags, DiagGroups, DiagsInGroup);
   inferPedantic.compute(&DiagsInPedantic, (RecordVec*)nullptr);
 
-  for (unsigned i = 0, e = Diags.size(); i != e; ++i) {
-const Record &R = *Diags[i];
-
+  for (const Record *RP : Diags) {
+const Record &R = *RP;

jurahul wrote:

I can clean this up in this PR. I was looking into whether LLVM has any 
iterator adapters for this earlier and could not find one. But looking again, 
it seems `make_pointee_range` does what we want, so let me try it

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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-13 Thread Rahul Joshi via cfe-commits


@@ -1419,16 +1412,14 @@ void clang::EmitClangDiagsDefs(const RecordKeeper 
&Records, raw_ostream &OS,
   InferPedantic inferPedantic(DGParentMap, Diags, DiagGroups, DiagsInGroup);
   inferPedantic.compute(&DiagsInPedantic, (RecordVec*)nullptr);
 
-  for (unsigned i = 0, e = Diags.size(); i != e; ++i) {
-const Record &R = *Diags[i];
-
+  for (const Record *RP : Diags) {
+const Record &R = *RP;

jurahul wrote:

Done. 

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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-13 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul updated 
https://github.com/llvm/llvm-project/pull/115959

>From d63b8a017e73586cc8c4c9d5afe4b0d59f81ea17 Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Tue, 12 Nov 2024 15:38:02 -0800
Subject: [PATCH] [NFC][Clang] Use StringRef instead of string in
 ClangDiagnosticEmitter

Use StringRef instead of std::string in ClangDiagnosticEmitter.
---
 .../TableGen/ClangDiagnosticsEmitter.cpp  | 87 ---
 1 file changed, 35 insertions(+), 52 deletions(-)

diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp 
b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index 662c99fd47de3a..98b25ecac50647 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -55,11 +55,11 @@ class DiagGroupParentMap {
 };
 } // end anonymous namespace.
 
-static std::string
+static StringRef
 getCategoryFromDiagGroup(const Record *Group,
  DiagGroupParentMap &DiagGroupParents) {
   // If the DiagGroup has a category, return it.
-  std::string CatName = std::string(Group->getValueAsString("CategoryName"));
+  StringRef CatName = Group->getValueAsString("CategoryName");
   if (!CatName.empty()) return CatName;
 
   // The diag group may the subgroup of one or more other diagnostic groups,
@@ -73,25 +73,26 @@ getCategoryFromDiagGroup(const Record *Group,
 
 /// getDiagnosticCategory - Return the category that the specified diagnostic
 /// lives in.
-static std::string getDiagnosticCategory(const Record *R,
- DiagGroupParentMap &DiagGroupParents) 
{
+static StringRef getDiagnosticCategory(const Record *R,
+   DiagGroupParentMap &DiagGroupParents) {
   // If the diagnostic is in a group, and that group has a category, use it.
   if (const auto *Group = dyn_cast(R->getValueInit("Group"))) {
 // Check the diagnostic's diag group for a category.
-std::string CatName = getCategoryFromDiagGroup(Group->getDef(),
-   DiagGroupParents);
+StringRef CatName =
+getCategoryFromDiagGroup(Group->getDef(), DiagGroupParents);
 if (!CatName.empty()) return CatName;
   }
 
   // If the diagnostic itself has a category, get it.
-  return std::string(R->getValueAsString("CategoryName"));
+  return R->getValueAsString("CategoryName");
 }
 
 namespace {
   class DiagCategoryIDMap {
 const RecordKeeper &Records;
 StringMap CategoryIDs;
-std::vector CategoryStrings;
+std::vector CategoryStrings;
+
   public:
 DiagCategoryIDMap(const RecordKeeper &records) : Records(records) {
   DiagGroupParentMap ParentInfo(Records);
@@ -102,7 +103,7 @@ namespace {
 
   for (const Record *Diag :
Records.getAllDerivedDefinitions("Diagnostic")) {
-std::string Category = getDiagnosticCategory(Diag, ParentInfo);
+StringRef Category = getDiagnosticCategory(Diag, ParentInfo);
 if (Category.empty()) continue;  // Skip diags with no category.
 
 unsigned &ID = CategoryIDs[Category];
@@ -117,7 +118,7 @@ namespace {
   return CategoryIDs[CategoryString];
 }
 
-typedef std::vector::const_iterator const_iterator;
+typedef std::vector::const_iterator const_iterator;
 const_iterator begin() const { return CategoryStrings.begin(); }
 const_iterator end() const { return CategoryStrings.end(); }
   };
@@ -125,7 +126,7 @@ namespace {
   struct GroupInfo {
 StringRef GroupName;
 std::vector DiagsInGroup;
-std::vector SubGroups;
+std::vector SubGroups;
 unsigned IDNo = 0;
 
 SmallVector Defs;
@@ -145,7 +146,7 @@ static bool diagGroupBeforeByName(const Record *LHS, const 
Record *RHS) {
  RHS->getValueAsString("GroupName");
 }
 
-using DiagsInGroupTy = std::map>;
+using DiagsInGroupTy = std::map;
 
 /// Invert the 1-[0/1] mapping of diags to group into a one to many
 /// mapping of groups to diags in the group.
@@ -158,21 +159,19 @@ static void groupDiagnostics(ArrayRef 
Diags,
   continue;
 assert(R->getValueAsDef("Class")->getName() != "CLASS_NOTE" &&
"Note can't be in a DiagGroup");
-std::string GroupName =
-std::string(DI->getDef()->getValueAsString("GroupName"));
+StringRef GroupName = DI->getDef()->getValueAsString("GroupName");
 DiagsInGroup[GroupName].DiagsInGroup.push_back(R);
   }
 
   // Add all DiagGroup's to the DiagsInGroup list to make sure we pick up empty
   // groups (these are warnings that GCC supports that clang never produces).
   for (const Record *Group : DiagGroups) {
-GroupInfo &GI =
-DiagsInGroup[std::string(Group->getValueAsString("GroupName"))];
+GroupInfo &GI = DiagsInGroup[Group->getValueAsString("GroupName")];
 GI.GroupName = Group->getName();
 GI.Defs.push_back(Group);
 
 for (const Record *SubGroup : Group->getValueAsListOfDefs("SubGroups"))
-  GI.SubGroups.push_back(SubGroup->getValueAsSt

[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-13 Thread Kazu Hirata via cfe-commits


@@ -1419,16 +1412,14 @@ void clang::EmitClangDiagsDefs(const RecordKeeper 
&Records, raw_ostream &OS,
   InferPedantic inferPedantic(DGParentMap, Diags, DiagGroups, DiagsInGroup);
   inferPedantic.compute(&DiagsInPedantic, (RecordVec*)nullptr);
 
-  for (unsigned i = 0, e = Diags.size(); i != e; ++i) {
-const Record &R = *Diags[i];
-
+  for (const Record *RP : Diags) {
+const Record &R = *RP;

kazutakahirata wrote:

It's not ideal to have both `RP` and `R`.  You might want to clean this up in a 
follow-up patch or something.  Not a blocker for this patch.


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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-13 Thread Kazu Hirata via cfe-commits

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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-13 Thread Kazu Hirata via cfe-commits

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

LGTM.  Thanks!

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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-13 Thread Erich Keane via cfe-commits

erichkeane wrote:

FWIW, LGTM, I'm Ok with it as-is, but let @kazutakahirata do the approval when 
he's happy.

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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-13 Thread Kazu Hirata via cfe-commits


@@ -117,15 +118,15 @@ namespace {
   return CategoryIDs[CategoryString];
 }
 
-typedef std::vector::const_iterator const_iterator;
+typedef std::vector::const_iterator const_iterator;
 const_iterator begin() const { return CategoryStrings.begin(); }
 const_iterator end() const { return CategoryStrings.end(); }
   };
 
   struct GroupInfo {
 StringRef GroupName;
 std::vector DiagsInGroup;
-std::vector SubGroups;
+std::vector SubGroups;

kazutakahirata wrote:

Thanks for the pointer and explanation!

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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-13 Thread Kazu Hirata via cfe-commits


@@ -158,21 +159,19 @@ static void groupDiagnostics(ArrayRef 
Diags,
   continue;
 assert(R->getValueAsDef("Class")->getName() != "CLASS_NOTE" &&
"Note can't be in a DiagGroup");
-std::string GroupName =
-std::string(DI->getDef()->getValueAsString("GroupName"));
+StringRef GroupName = DI->getDef()->getValueAsString("GroupName");
 DiagsInGroup[GroupName].DiagsInGroup.push_back(R);
   }
 
   // Add all DiagGroup's to the DiagsInGroup list to make sure we pick up empty
   // groups (these are warnings that GCC supports that clang never produces).
   for (const Record *Group : DiagGroups) {
-GroupInfo &GI =
-DiagsInGroup[std::string(Group->getValueAsString("GroupName"))];
+GroupInfo &GI = DiagsInGroup[Group->getValueAsString("GroupName")];
 GI.GroupName = Group->getName();
 GI.Defs.push_back(Group);
 
 for (const Record *SubGroup : Group->getValueAsListOfDefs("SubGroups"))
-  GI.SubGroups.push_back(SubGroup->getValueAsString("GroupName").str());
+  GI.SubGroups.push_back(SubGroup->getValueAsString("GroupName"));

kazutakahirata wrote:

Thanks for the pointer and explanation!

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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-13 Thread Rahul Joshi via cfe-commits


@@ -145,7 +146,7 @@ static bool diagGroupBeforeByName(const Record *LHS, const 
Record *RHS) {
  RHS->getValueAsString("GroupName");
 }
 
-using DiagsInGroupTy = std::map>;
+using DiagsInGroupTy = std::map>;

jurahul wrote:

Done.

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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-13 Thread Rahul Joshi via cfe-commits


@@ -117,15 +118,15 @@ namespace {
   return CategoryIDs[CategoryString];
 }
 
-typedef std::vector::const_iterator const_iterator;
+typedef std::vector::const_iterator const_iterator;
 const_iterator begin() const { return CategoryStrings.begin(); }
 const_iterator end() const { return CategoryStrings.end(); }
   };
 
   struct GroupInfo {
 StringRef GroupName;
 std::vector DiagsInGroup;
-std::vector SubGroups;
+std::vector SubGroups;

jurahul wrote:

See reply below.

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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-13 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul updated 
https://github.com/llvm/llvm-project/pull/115959

>From aa016d306c717ddffc0a7227678d8928be9583b4 Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Tue, 12 Nov 2024 15:38:02 -0800
Subject: [PATCH] [NFC][Clang] Use StringRef instead of string in
 ClangDiagnosticEmitter

Use StringRef instead of std::string in ClangDiagnosticEmitter.
---
 .../TableGen/ClangDiagnosticsEmitter.cpp  | 88 ---
 1 file changed, 36 insertions(+), 52 deletions(-)

diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp 
b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index 662c99fd47de3a..465ebc44ba5203 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -55,11 +55,11 @@ class DiagGroupParentMap {
 };
 } // end anonymous namespace.
 
-static std::string
+static StringRef
 getCategoryFromDiagGroup(const Record *Group,
  DiagGroupParentMap &DiagGroupParents) {
   // If the DiagGroup has a category, return it.
-  std::string CatName = std::string(Group->getValueAsString("CategoryName"));
+  StringRef CatName = Group->getValueAsString("CategoryName");
   if (!CatName.empty()) return CatName;
 
   // The diag group may the subgroup of one or more other diagnostic groups,
@@ -73,25 +73,26 @@ getCategoryFromDiagGroup(const Record *Group,
 
 /// getDiagnosticCategory - Return the category that the specified diagnostic
 /// lives in.
-static std::string getDiagnosticCategory(const Record *R,
- DiagGroupParentMap &DiagGroupParents) 
{
+static StringRef getDiagnosticCategory(const Record *R,
+   DiagGroupParentMap &DiagGroupParents) {
   // If the diagnostic is in a group, and that group has a category, use it.
   if (const auto *Group = dyn_cast(R->getValueInit("Group"))) {
 // Check the diagnostic's diag group for a category.
-std::string CatName = getCategoryFromDiagGroup(Group->getDef(),
-   DiagGroupParents);
+StringRef CatName =
+getCategoryFromDiagGroup(Group->getDef(), DiagGroupParents);
 if (!CatName.empty()) return CatName;
   }
 
   // If the diagnostic itself has a category, get it.
-  return std::string(R->getValueAsString("CategoryName"));
+  return R->getValueAsString("CategoryName");
 }
 
 namespace {
   class DiagCategoryIDMap {
 const RecordKeeper &Records;
 StringMap CategoryIDs;
-std::vector CategoryStrings;
+std::vector CategoryStrings;
+
   public:
 DiagCategoryIDMap(const RecordKeeper &records) : Records(records) {
   DiagGroupParentMap ParentInfo(Records);
@@ -102,7 +103,7 @@ namespace {
 
   for (const Record *Diag :
Records.getAllDerivedDefinitions("Diagnostic")) {
-std::string Category = getDiagnosticCategory(Diag, ParentInfo);
+StringRef Category = getDiagnosticCategory(Diag, ParentInfo);
 if (Category.empty()) continue;  // Skip diags with no category.
 
 unsigned &ID = CategoryIDs[Category];
@@ -117,7 +118,7 @@ namespace {
   return CategoryIDs[CategoryString];
 }
 
-typedef std::vector::const_iterator const_iterator;
+typedef std::vector::const_iterator const_iterator;
 const_iterator begin() const { return CategoryStrings.begin(); }
 const_iterator end() const { return CategoryStrings.end(); }
   };
@@ -125,7 +126,7 @@ namespace {
   struct GroupInfo {
 StringRef GroupName;
 std::vector DiagsInGroup;
-std::vector SubGroups;
+std::vector SubGroups;
 unsigned IDNo = 0;
 
 SmallVector Defs;
@@ -145,7 +146,7 @@ static bool diagGroupBeforeByName(const Record *LHS, const 
Record *RHS) {
  RHS->getValueAsString("GroupName");
 }
 
-using DiagsInGroupTy = std::map>;
+using DiagsInGroupTy = std::map;
 
 /// Invert the 1-[0/1] mapping of diags to group into a one to many
 /// mapping of groups to diags in the group.
@@ -158,21 +159,19 @@ static void groupDiagnostics(ArrayRef 
Diags,
   continue;
 assert(R->getValueAsDef("Class")->getName() != "CLASS_NOTE" &&
"Note can't be in a DiagGroup");
-std::string GroupName =
-std::string(DI->getDef()->getValueAsString("GroupName"));
+StringRef GroupName = DI->getDef()->getValueAsString("GroupName");
 DiagsInGroup[GroupName].DiagsInGroup.push_back(R);
   }
 
   // Add all DiagGroup's to the DiagsInGroup list to make sure we pick up empty
   // groups (these are warnings that GCC supports that clang never produces).
   for (const Record *Group : DiagGroups) {
-GroupInfo &GI =
-DiagsInGroup[std::string(Group->getValueAsString("GroupName"))];
+GroupInfo &GI = DiagsInGroup[Group->getValueAsString("GroupName")];
 GI.GroupName = Group->getName();
 GI.Defs.push_back(Group);
 
 for (const Record *SubGroup : Group->getValueAsListOfDefs("SubGroups"))
-  GI.SubGroups.push_back(SubGroup->getValueAsSt

[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-13 Thread Rahul Joshi via cfe-commits


@@ -145,7 +146,7 @@ static bool diagGroupBeforeByName(const Record *LHS, const 
Record *RHS) {
  RHS->getValueAsString("GroupName");
 }
 
-using DiagsInGroupTy = std::map>;
+using DiagsInGroupTy = std::map>;

jurahul wrote:

Will do, I see that you added this just yesterday.

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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-13 Thread Rahul Joshi via cfe-commits


@@ -158,21 +159,19 @@ static void groupDiagnostics(ArrayRef 
Diags,
   continue;
 assert(R->getValueAsDef("Class")->getName() != "CLASS_NOTE" &&
"Note can't be in a DiagGroup");
-std::string GroupName =
-std::string(DI->getDef()->getValueAsString("GroupName"));
+StringRef GroupName = DI->getDef()->getValueAsString("GroupName");
 DiagsInGroup[GroupName].DiagsInGroup.push_back(R);
   }
 
   // Add all DiagGroup's to the DiagsInGroup list to make sure we pick up empty
   // groups (these are warnings that GCC supports that clang never produces).
   for (const Record *Group : DiagGroups) {
-GroupInfo &GI =
-DiagsInGroup[std::string(Group->getValueAsString("GroupName"))];
+GroupInfo &GI = DiagsInGroup[Group->getValueAsString("GroupName")];
 GI.GroupName = Group->getName();
 GI.Defs.push_back(Group);
 
 for (const Record *SubGroup : Group->getValueAsListOfDefs("SubGroups"))
-  GI.SubGroups.push_back(SubGroup->getValueAsString("GroupName").str());
+  GI.SubGroups.push_back(SubGroup->getValueAsString("GroupName"));

jurahul wrote:

Here's where the strings in the SubGroups vector originate from. As with most 
of my such changes, the strings are ultimately a part of the TableGen Records, 
which are ultimately backed by RecordKeeperImpl::StringInitStringPool. So the 
assumption is that the `RecordKeeper` (which is TableGen's IR) outlives the 
emitter backend invocation, which is true.

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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-12 Thread Kazu Hirata via cfe-commits


@@ -145,7 +146,7 @@ static bool diagGroupBeforeByName(const Record *LHS, const 
Record *RHS) {
  RHS->getValueAsString("GroupName");
 }
 
-using DiagsInGroupTy = std::map>;
+using DiagsInGroupTy = std::map>;

kazutakahirata wrote:

If you are putting `StringRef`, I'd drop `std::less<>`.  We don't need to 
support heterogenous lookups if the key is of `StringRef`.

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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-12 Thread Kazu Hirata via cfe-commits


@@ -117,15 +118,15 @@ namespace {
   return CategoryIDs[CategoryString];
 }
 
-typedef std::vector::const_iterator const_iterator;
+typedef std::vector::const_iterator const_iterator;
 const_iterator begin() const { return CategoryStrings.begin(); }
 const_iterator end() const { return CategoryStrings.end(); }
   };
 
   struct GroupInfo {
 StringRef GroupName;
 std::vector DiagsInGroup;
-std::vector SubGroups;
+std::vector SubGroups;

kazutakahirata wrote:

With another patch of yours, `StringRef` tends to be printed out right away, so 
I'm not worried about life time issues.  Where are the original strings stored?

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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rahul Joshi (jurahul)


Changes

Use StringRef instead of std::string in ClangDiagnosticEmitter.

---
Full diff: https://github.com/llvm/llvm-project/pull/115959.diff


1 Files Affected:

- (modified) clang/utils/TableGen/ClangDiagnosticsEmitter.cpp (+36-52) 


``diff
diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp 
b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index b7fd59090cd995..982809169e6bfd 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -55,11 +55,11 @@ class DiagGroupParentMap {
 };
 } // end anonymous namespace.
 
-static std::string
+static StringRef
 getCategoryFromDiagGroup(const Record *Group,
  DiagGroupParentMap &DiagGroupParents) {
   // If the DiagGroup has a category, return it.
-  std::string CatName = std::string(Group->getValueAsString("CategoryName"));
+  StringRef CatName = Group->getValueAsString("CategoryName");
   if (!CatName.empty()) return CatName;
 
   // The diag group may the subgroup of one or more other diagnostic groups,
@@ -73,25 +73,26 @@ getCategoryFromDiagGroup(const Record *Group,
 
 /// getDiagnosticCategory - Return the category that the specified diagnostic
 /// lives in.
-static std::string getDiagnosticCategory(const Record *R,
- DiagGroupParentMap &DiagGroupParents) 
{
+static StringRef getDiagnosticCategory(const Record *R,
+   DiagGroupParentMap &DiagGroupParents) {
   // If the diagnostic is in a group, and that group has a category, use it.
   if (const auto *Group = dyn_cast(R->getValueInit("Group"))) {
 // Check the diagnostic's diag group for a category.
-std::string CatName = getCategoryFromDiagGroup(Group->getDef(),
-   DiagGroupParents);
+StringRef CatName =
+getCategoryFromDiagGroup(Group->getDef(), DiagGroupParents);
 if (!CatName.empty()) return CatName;
   }
 
   // If the diagnostic itself has a category, get it.
-  return std::string(R->getValueAsString("CategoryName"));
+  return R->getValueAsString("CategoryName");
 }
 
 namespace {
   class DiagCategoryIDMap {
 const RecordKeeper &Records;
 StringMap CategoryIDs;
-std::vector CategoryStrings;
+std::vector CategoryStrings;
+
   public:
 DiagCategoryIDMap(const RecordKeeper &records) : Records(records) {
   DiagGroupParentMap ParentInfo(Records);
@@ -102,7 +103,7 @@ namespace {
 
   for (const Record *Diag :
Records.getAllDerivedDefinitions("Diagnostic")) {
-std::string Category = getDiagnosticCategory(Diag, ParentInfo);
+StringRef Category = getDiagnosticCategory(Diag, ParentInfo);
 if (Category.empty()) continue;  // Skip diags with no category.
 
 unsigned &ID = CategoryIDs[Category];
@@ -117,7 +118,7 @@ namespace {
   return CategoryIDs[CategoryString];
 }
 
-typedef std::vector::const_iterator const_iterator;
+typedef std::vector::const_iterator const_iterator;
 const_iterator begin() const { return CategoryStrings.begin(); }
 const_iterator end() const { return CategoryStrings.end(); }
   };
@@ -125,7 +126,7 @@ namespace {
   struct GroupInfo {
 StringRef GroupName;
 std::vector DiagsInGroup;
-std::vector SubGroups;
+std::vector SubGroups;
 unsigned IDNo = 0;
 
 SmallVector Defs;
@@ -145,7 +146,7 @@ static bool diagGroupBeforeByName(const Record *LHS, const 
Record *RHS) {
  RHS->getValueAsString("GroupName");
 }
 
-using DiagsInGroupTy = std::map>;
+using DiagsInGroupTy = std::map>;
 
 /// Invert the 1-[0/1] mapping of diags to group into a one to many
 /// mapping of groups to diags in the group.
@@ -158,21 +159,19 @@ static void groupDiagnostics(ArrayRef 
Diags,
   continue;
 assert(R->getValueAsDef("Class")->getName() != "CLASS_NOTE" &&
"Note can't be in a DiagGroup");
-std::string GroupName =
-std::string(DI->getDef()->getValueAsString("GroupName"));
+StringRef GroupName = DI->getDef()->getValueAsString("GroupName");
 DiagsInGroup[GroupName].DiagsInGroup.push_back(R);
   }
 
   // Add all DiagGroup's to the DiagsInGroup list to make sure we pick up empty
   // groups (these are warnings that GCC supports that clang never produces).
   for (const Record *Group : DiagGroups) {
-GroupInfo &GI =
-DiagsInGroup[std::string(Group->getValueAsString("GroupName"))];
+GroupInfo &GI = DiagsInGroup[Group->getValueAsString("GroupName")];
 GI.GroupName = Group->getName();
 GI.Defs.push_back(Group);
 
 for (const Record *SubGroup : Group->getValueAsListOfDefs("SubGroups"))
-  GI.SubGroups.push_back(SubGroup->getValueAsString("GroupName").str());
+  GI.SubGroups.push_back(SubGroup->getValueAsString("GroupName"));
   }
 
   // Assign unique ID numbers to the groups.
@@ -281,8 +28

[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-12 Thread Rahul Joshi via cfe-commits

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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-12 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul updated 
https://github.com/llvm/llvm-project/pull/115959

>From 5ba5485bbc8895743130f58779cf5c78eb0941aa Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Tue, 12 Nov 2024 15:38:02 -0800
Subject: [PATCH] [NFC][Clang] Use StringRef instead of string in
 ClangDiagnosticEmitter

Use StringRef instead of std::string in ClangDiagnosticEmitter.
---
 .../TableGen/ClangDiagnosticsEmitter.cpp  | 88 ---
 1 file changed, 36 insertions(+), 52 deletions(-)

diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp 
b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index b7fd59090cd995..982809169e6bfd 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -55,11 +55,11 @@ class DiagGroupParentMap {
 };
 } // end anonymous namespace.
 
-static std::string
+static StringRef
 getCategoryFromDiagGroup(const Record *Group,
  DiagGroupParentMap &DiagGroupParents) {
   // If the DiagGroup has a category, return it.
-  std::string CatName = std::string(Group->getValueAsString("CategoryName"));
+  StringRef CatName = Group->getValueAsString("CategoryName");
   if (!CatName.empty()) return CatName;
 
   // The diag group may the subgroup of one or more other diagnostic groups,
@@ -73,25 +73,26 @@ getCategoryFromDiagGroup(const Record *Group,
 
 /// getDiagnosticCategory - Return the category that the specified diagnostic
 /// lives in.
-static std::string getDiagnosticCategory(const Record *R,
- DiagGroupParentMap &DiagGroupParents) 
{
+static StringRef getDiagnosticCategory(const Record *R,
+   DiagGroupParentMap &DiagGroupParents) {
   // If the diagnostic is in a group, and that group has a category, use it.
   if (const auto *Group = dyn_cast(R->getValueInit("Group"))) {
 // Check the diagnostic's diag group for a category.
-std::string CatName = getCategoryFromDiagGroup(Group->getDef(),
-   DiagGroupParents);
+StringRef CatName =
+getCategoryFromDiagGroup(Group->getDef(), DiagGroupParents);
 if (!CatName.empty()) return CatName;
   }
 
   // If the diagnostic itself has a category, get it.
-  return std::string(R->getValueAsString("CategoryName"));
+  return R->getValueAsString("CategoryName");
 }
 
 namespace {
   class DiagCategoryIDMap {
 const RecordKeeper &Records;
 StringMap CategoryIDs;
-std::vector CategoryStrings;
+std::vector CategoryStrings;
+
   public:
 DiagCategoryIDMap(const RecordKeeper &records) : Records(records) {
   DiagGroupParentMap ParentInfo(Records);
@@ -102,7 +103,7 @@ namespace {
 
   for (const Record *Diag :
Records.getAllDerivedDefinitions("Diagnostic")) {
-std::string Category = getDiagnosticCategory(Diag, ParentInfo);
+StringRef Category = getDiagnosticCategory(Diag, ParentInfo);
 if (Category.empty()) continue;  // Skip diags with no category.
 
 unsigned &ID = CategoryIDs[Category];
@@ -117,7 +118,7 @@ namespace {
   return CategoryIDs[CategoryString];
 }
 
-typedef std::vector::const_iterator const_iterator;
+typedef std::vector::const_iterator const_iterator;
 const_iterator begin() const { return CategoryStrings.begin(); }
 const_iterator end() const { return CategoryStrings.end(); }
   };
@@ -125,7 +126,7 @@ namespace {
   struct GroupInfo {
 StringRef GroupName;
 std::vector DiagsInGroup;
-std::vector SubGroups;
+std::vector SubGroups;
 unsigned IDNo = 0;
 
 SmallVector Defs;
@@ -145,7 +146,7 @@ static bool diagGroupBeforeByName(const Record *LHS, const 
Record *RHS) {
  RHS->getValueAsString("GroupName");
 }
 
-using DiagsInGroupTy = std::map>;
+using DiagsInGroupTy = std::map>;
 
 /// Invert the 1-[0/1] mapping of diags to group into a one to many
 /// mapping of groups to diags in the group.
@@ -158,21 +159,19 @@ static void groupDiagnostics(ArrayRef 
Diags,
   continue;
 assert(R->getValueAsDef("Class")->getName() != "CLASS_NOTE" &&
"Note can't be in a DiagGroup");
-std::string GroupName =
-std::string(DI->getDef()->getValueAsString("GroupName"));
+StringRef GroupName = DI->getDef()->getValueAsString("GroupName");
 DiagsInGroup[GroupName].DiagsInGroup.push_back(R);
   }
 
   // Add all DiagGroup's to the DiagsInGroup list to make sure we pick up empty
   // groups (these are warnings that GCC supports that clang never produces).
   for (const Record *Group : DiagGroups) {
-GroupInfo &GI =
-DiagsInGroup[std::string(Group->getValueAsString("GroupName"))];
+GroupInfo &GI = DiagsInGroup[Group->getValueAsString("GroupName")];
 GI.GroupName = Group->getName();
 GI.Defs.push_back(Group);
 
 for (const Record *SubGroup : Group->getValueAsListOfDefs("SubGroups"))
-  GI.SubGroups.push_back(SubGroup->getValueAsS

[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-12 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 7b5e285d16090c2ddf4ee539c410d24bde52cbea 
cdcd09ec7c11a21da0804a6e886aff6410c42daf --extensions cpp -- 
clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp 
b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index 20b30261b7..9aab37514d 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -92,6 +92,7 @@ namespace {
 const RecordKeeper &Records;
 StringMap CategoryIDs;
 std::vector CategoryStrings;
+
   public:
 DiagCategoryIDMap(const RecordKeeper &records) : Records(records) {
   DiagGroupParentMap ParentInfo(Records);

``




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


[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-12 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul updated 
https://github.com/llvm/llvm-project/pull/115959

>From 04b7434139ffdb412797e9d4fe7d31ecbdbe7748 Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Tue, 12 Nov 2024 15:38:02 -0800
Subject: [PATCH] [NFC][Clang] Use StringRef instead of string in
 ClangDiagnosticEmitter

Use StringRef instead of std::string in ClangDiagnosticEmitter.
---
 .../TableGen/ClangDiagnosticsEmitter.cpp  | 79 ---
 1 file changed, 32 insertions(+), 47 deletions(-)

diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp 
b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index b7fd59090cd995..9aab37514d12b1 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -55,11 +55,11 @@ class DiagGroupParentMap {
 };
 } // end anonymous namespace.
 
-static std::string
+static StringRef
 getCategoryFromDiagGroup(const Record *Group,
  DiagGroupParentMap &DiagGroupParents) {
   // If the DiagGroup has a category, return it.
-  std::string CatName = std::string(Group->getValueAsString("CategoryName"));
+  StringRef CatName = Group->getValueAsString("CategoryName");
   if (!CatName.empty()) return CatName;
 
   // The diag group may the subgroup of one or more other diagnostic groups,
@@ -73,25 +73,26 @@ getCategoryFromDiagGroup(const Record *Group,
 
 /// getDiagnosticCategory - Return the category that the specified diagnostic
 /// lives in.
-static std::string getDiagnosticCategory(const Record *R,
- DiagGroupParentMap &DiagGroupParents) 
{
+static StringRef getDiagnosticCategory(const Record *R,
+   DiagGroupParentMap &DiagGroupParents) {
   // If the diagnostic is in a group, and that group has a category, use it.
   if (const auto *Group = dyn_cast(R->getValueInit("Group"))) {
 // Check the diagnostic's diag group for a category.
-std::string CatName = getCategoryFromDiagGroup(Group->getDef(),
-   DiagGroupParents);
+StringRef CatName =
+getCategoryFromDiagGroup(Group->getDef(), DiagGroupParents);
 if (!CatName.empty()) return CatName;
   }
 
   // If the diagnostic itself has a category, get it.
-  return std::string(R->getValueAsString("CategoryName"));
+  return R->getValueAsString("CategoryName");
 }
 
 namespace {
   class DiagCategoryIDMap {
 const RecordKeeper &Records;
 StringMap CategoryIDs;
-std::vector CategoryStrings;
+std::vector CategoryStrings;
+
   public:
 DiagCategoryIDMap(const RecordKeeper &records) : Records(records) {
   DiagGroupParentMap ParentInfo(Records);
@@ -102,7 +103,7 @@ namespace {
 
   for (const Record *Diag :
Records.getAllDerivedDefinitions("Diagnostic")) {
-std::string Category = getDiagnosticCategory(Diag, ParentInfo);
+StringRef Category = getDiagnosticCategory(Diag, ParentInfo);
 if (Category.empty()) continue;  // Skip diags with no category.
 
 unsigned &ID = CategoryIDs[Category];
@@ -117,7 +118,7 @@ namespace {
   return CategoryIDs[CategoryString];
 }
 
-typedef std::vector::const_iterator const_iterator;
+typedef std::vector::const_iterator const_iterator;
 const_iterator begin() const { return CategoryStrings.begin(); }
 const_iterator end() const { return CategoryStrings.end(); }
   };
@@ -125,7 +126,7 @@ namespace {
   struct GroupInfo {
 StringRef GroupName;
 std::vector DiagsInGroup;
-std::vector SubGroups;
+std::vector SubGroups;
 unsigned IDNo = 0;
 
 SmallVector Defs;
@@ -145,7 +146,7 @@ static bool diagGroupBeforeByName(const Record *LHS, const 
Record *RHS) {
  RHS->getValueAsString("GroupName");
 }
 
-using DiagsInGroupTy = std::map>;
+using DiagsInGroupTy = std::map>;
 
 /// Invert the 1-[0/1] mapping of diags to group into a one to many
 /// mapping of groups to diags in the group.
@@ -158,16 +159,14 @@ static void groupDiagnostics(ArrayRef 
Diags,
   continue;
 assert(R->getValueAsDef("Class")->getName() != "CLASS_NOTE" &&
"Note can't be in a DiagGroup");
-std::string GroupName =
-std::string(DI->getDef()->getValueAsString("GroupName"));
+StringRef GroupName = DI->getDef()->getValueAsString("GroupName");
 DiagsInGroup[GroupName].DiagsInGroup.push_back(R);
   }
 
   // Add all DiagGroup's to the DiagsInGroup list to make sure we pick up empty
   // groups (these are warnings that GCC supports that clang never produces).
   for (const Record *Group : DiagGroups) {
-GroupInfo &GI =
-DiagsInGroup[std::string(Group->getValueAsString("GroupName"))];
+GroupInfo &GI = DiagsInGroup[Group->getValueAsString("GroupName")];
 GI.GroupName = Group->getName();
 GI.Defs.push_back(Group);
 
@@ -281,8 +280,7 @@ class InferPedantic {
 } // end anonymous namespace
 
 bool InferPedantic::isSubGroupOfGroup(const Record *G

[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-12 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul updated 
https://github.com/llvm/llvm-project/pull/115959

>From cdcd09ec7c11a21da0804a6e886aff6410c42daf Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Tue, 12 Nov 2024 15:38:02 -0800
Subject: [PATCH] [NFC][Clang] Use StringRef instead of string in
 ClangDiagnosticEmitter

Use StringRef instead of std::string in ClangDiagnosticEmitter.
---
 .../TableGen/ClangDiagnosticsEmitter.cpp  | 78 ---
 1 file changed, 31 insertions(+), 47 deletions(-)

diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp 
b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index b7fd59090cd995..20b30261b7925f 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -55,11 +55,11 @@ class DiagGroupParentMap {
 };
 } // end anonymous namespace.
 
-static std::string
+static StringRef
 getCategoryFromDiagGroup(const Record *Group,
  DiagGroupParentMap &DiagGroupParents) {
   // If the DiagGroup has a category, return it.
-  std::string CatName = std::string(Group->getValueAsString("CategoryName"));
+  StringRef CatName = Group->getValueAsString("CategoryName");
   if (!CatName.empty()) return CatName;
 
   // The diag group may the subgroup of one or more other diagnostic groups,
@@ -73,25 +73,25 @@ getCategoryFromDiagGroup(const Record *Group,
 
 /// getDiagnosticCategory - Return the category that the specified diagnostic
 /// lives in.
-static std::string getDiagnosticCategory(const Record *R,
- DiagGroupParentMap &DiagGroupParents) 
{
+static StringRef getDiagnosticCategory(const Record *R,
+   DiagGroupParentMap &DiagGroupParents) {
   // If the diagnostic is in a group, and that group has a category, use it.
   if (const auto *Group = dyn_cast(R->getValueInit("Group"))) {
 // Check the diagnostic's diag group for a category.
-std::string CatName = getCategoryFromDiagGroup(Group->getDef(),
-   DiagGroupParents);
+StringRef CatName =
+getCategoryFromDiagGroup(Group->getDef(), DiagGroupParents);
 if (!CatName.empty()) return CatName;
   }
 
   // If the diagnostic itself has a category, get it.
-  return std::string(R->getValueAsString("CategoryName"));
+  return R->getValueAsString("CategoryName");
 }
 
 namespace {
   class DiagCategoryIDMap {
 const RecordKeeper &Records;
 StringMap CategoryIDs;
-std::vector CategoryStrings;
+std::vector CategoryStrings;
   public:
 DiagCategoryIDMap(const RecordKeeper &records) : Records(records) {
   DiagGroupParentMap ParentInfo(Records);
@@ -102,7 +102,7 @@ namespace {
 
   for (const Record *Diag :
Records.getAllDerivedDefinitions("Diagnostic")) {
-std::string Category = getDiagnosticCategory(Diag, ParentInfo);
+StringRef Category = getDiagnosticCategory(Diag, ParentInfo);
 if (Category.empty()) continue;  // Skip diags with no category.
 
 unsigned &ID = CategoryIDs[Category];
@@ -117,7 +117,7 @@ namespace {
   return CategoryIDs[CategoryString];
 }
 
-typedef std::vector::const_iterator const_iterator;
+typedef std::vector::const_iterator const_iterator;
 const_iterator begin() const { return CategoryStrings.begin(); }
 const_iterator end() const { return CategoryStrings.end(); }
   };
@@ -125,7 +125,7 @@ namespace {
   struct GroupInfo {
 StringRef GroupName;
 std::vector DiagsInGroup;
-std::vector SubGroups;
+std::vector SubGroups;
 unsigned IDNo = 0;
 
 SmallVector Defs;
@@ -145,7 +145,7 @@ static bool diagGroupBeforeByName(const Record *LHS, const 
Record *RHS) {
  RHS->getValueAsString("GroupName");
 }
 
-using DiagsInGroupTy = std::map>;
+using DiagsInGroupTy = std::map>;
 
 /// Invert the 1-[0/1] mapping of diags to group into a one to many
 /// mapping of groups to diags in the group.
@@ -158,16 +158,14 @@ static void groupDiagnostics(ArrayRef 
Diags,
   continue;
 assert(R->getValueAsDef("Class")->getName() != "CLASS_NOTE" &&
"Note can't be in a DiagGroup");
-std::string GroupName =
-std::string(DI->getDef()->getValueAsString("GroupName"));
+StringRef GroupName = DI->getDef()->getValueAsString("GroupName");
 DiagsInGroup[GroupName].DiagsInGroup.push_back(R);
   }
 
   // Add all DiagGroup's to the DiagsInGroup list to make sure we pick up empty
   // groups (these are warnings that GCC supports that clang never produces).
   for (const Record *Group : DiagGroups) {
-GroupInfo &GI =
-DiagsInGroup[std::string(Group->getValueAsString("GroupName"))];
+GroupInfo &GI = DiagsInGroup[Group->getValueAsString("GroupName")];
 GI.GroupName = Group->getName();
 GI.Defs.push_back(Group);
 
@@ -281,8 +279,7 @@ class InferPedantic {
 } // end anonymous namespace
 
 bool InferPedantic::isSubGroupOfGroup(const Record *Gro

[clang] [NFC][Clang] Use StringRef instead of string in ClangDiagnosticEmitter (PR #115959)

2024-11-12 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul created 
https://github.com/llvm/llvm-project/pull/115959

Use StringRef instead of std::string in ClangDiagnosticEmitter.

>From 5f67dd57f3e6333da438dc07a2efdfcb0c1874b1 Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Tue, 12 Nov 2024 15:38:02 -0800
Subject: [PATCH] [NFC][Clang] Use StringRef instead of string in
 ClangDiagnosticEmitter

Use StringRef instead of std::string in ClangDiagnosticEmitter.
---
 .../TableGen/ClangDiagnosticsEmitter.cpp  | 79 ---
 1 file changed, 32 insertions(+), 47 deletions(-)

diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp 
b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index b7fd59090cd995..9aab37514d12b1 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -55,11 +55,11 @@ class DiagGroupParentMap {
 };
 } // end anonymous namespace.
 
-static std::string
+static StringRef
 getCategoryFromDiagGroup(const Record *Group,
  DiagGroupParentMap &DiagGroupParents) {
   // If the DiagGroup has a category, return it.
-  std::string CatName = std::string(Group->getValueAsString("CategoryName"));
+  StringRef CatName = Group->getValueAsString("CategoryName");
   if (!CatName.empty()) return CatName;
 
   // The diag group may the subgroup of one or more other diagnostic groups,
@@ -73,25 +73,26 @@ getCategoryFromDiagGroup(const Record *Group,
 
 /// getDiagnosticCategory - Return the category that the specified diagnostic
 /// lives in.
-static std::string getDiagnosticCategory(const Record *R,
- DiagGroupParentMap &DiagGroupParents) 
{
+static StringRef getDiagnosticCategory(const Record *R,
+   DiagGroupParentMap &DiagGroupParents) {
   // If the diagnostic is in a group, and that group has a category, use it.
   if (const auto *Group = dyn_cast(R->getValueInit("Group"))) {
 // Check the diagnostic's diag group for a category.
-std::string CatName = getCategoryFromDiagGroup(Group->getDef(),
-   DiagGroupParents);
+StringRef CatName =
+getCategoryFromDiagGroup(Group->getDef(), DiagGroupParents);
 if (!CatName.empty()) return CatName;
   }
 
   // If the diagnostic itself has a category, get it.
-  return std::string(R->getValueAsString("CategoryName"));
+  return R->getValueAsString("CategoryName");
 }
 
 namespace {
   class DiagCategoryIDMap {
 const RecordKeeper &Records;
 StringMap CategoryIDs;
-std::vector CategoryStrings;
+std::vector CategoryStrings;
+
   public:
 DiagCategoryIDMap(const RecordKeeper &records) : Records(records) {
   DiagGroupParentMap ParentInfo(Records);
@@ -102,7 +103,7 @@ namespace {
 
   for (const Record *Diag :
Records.getAllDerivedDefinitions("Diagnostic")) {
-std::string Category = getDiagnosticCategory(Diag, ParentInfo);
+StringRef Category = getDiagnosticCategory(Diag, ParentInfo);
 if (Category.empty()) continue;  // Skip diags with no category.
 
 unsigned &ID = CategoryIDs[Category];
@@ -117,7 +118,7 @@ namespace {
   return CategoryIDs[CategoryString];
 }
 
-typedef std::vector::const_iterator const_iterator;
+typedef std::vector::const_iterator const_iterator;
 const_iterator begin() const { return CategoryStrings.begin(); }
 const_iterator end() const { return CategoryStrings.end(); }
   };
@@ -125,7 +126,7 @@ namespace {
   struct GroupInfo {
 StringRef GroupName;
 std::vector DiagsInGroup;
-std::vector SubGroups;
+std::vector SubGroups;
 unsigned IDNo = 0;
 
 SmallVector Defs;
@@ -145,7 +146,7 @@ static bool diagGroupBeforeByName(const Record *LHS, const 
Record *RHS) {
  RHS->getValueAsString("GroupName");
 }
 
-using DiagsInGroupTy = std::map>;
+using DiagsInGroupTy = std::map>;
 
 /// Invert the 1-[0/1] mapping of diags to group into a one to many
 /// mapping of groups to diags in the group.
@@ -158,16 +159,14 @@ static void groupDiagnostics(ArrayRef 
Diags,
   continue;
 assert(R->getValueAsDef("Class")->getName() != "CLASS_NOTE" &&
"Note can't be in a DiagGroup");
-std::string GroupName =
-std::string(DI->getDef()->getValueAsString("GroupName"));
+StringRef GroupName = DI->getDef()->getValueAsString("GroupName");
 DiagsInGroup[GroupName].DiagsInGroup.push_back(R);
   }
 
   // Add all DiagGroup's to the DiagsInGroup list to make sure we pick up empty
   // groups (these are warnings that GCC supports that clang never produces).
   for (const Record *Group : DiagGroups) {
-GroupInfo &GI =
-DiagsInGroup[std::string(Group->getValueAsString("GroupName"))];
+GroupInfo &GI = DiagsInGroup[Group->getValueAsString("GroupName")];
 GI.GroupName = Group->getName();
 GI.Defs.push_back(Group);
 
@@ -281,8 +280,7 @@ class InferPedantic {
 } // end anonymous n