Skip to content

Commit ffc5b19

Browse files
authored
[Clang][TableGen] Use const pointers for various Init objects in Diagnostic Emitter (llvm#112318)
Use const pointers for various Init objects in Diagnostic Emitter. This is a part of effort to have better const correctness in TableGen backends: https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
1 parent 9b422d1 commit ffc5b19

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ getCategoryFromDiagGroup(const Record *Group,
8383
static std::string getDiagnosticCategory(const Record *R,
8484
DiagGroupParentMap &DiagGroupParents) {
8585
// If the diagnostic is in a group, and that group has a category, use it.
86-
if (DefInit *Group = dyn_cast<DefInit>(R->getValueInit("Group"))) {
86+
if (const auto *Group = dyn_cast<DefInit>(R->getValueInit("Group"))) {
8787
// Check the diagnostic's diag group for a category.
8888
std::string CatName = getCategoryFromDiagGroup(Group->getDef(),
8989
DiagGroupParents);
@@ -161,7 +161,7 @@ static void groupDiagnostics(ArrayRef<const Record *> Diags,
161161

162162
for (unsigned i = 0, e = Diags.size(); i != e; ++i) {
163163
const Record *R = Diags[i];
164-
DefInit *DI = dyn_cast<DefInit>(R->getValueInit("Group"));
164+
const auto *DI = dyn_cast<DefInit>(R->getValueInit("Group"));
165165
if (!DI)
166166
continue;
167167
assert(R->getValueAsDef("Class")->getName() != "CLASS_NOTE" &&
@@ -359,7 +359,7 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
359359
const Record *R = Diags[i];
360360
if (isExtension(R) && isOffByDefault(R)) {
361361
DiagsSet.insert(R);
362-
if (DefInit *Group = dyn_cast<DefInit>(R->getValueInit("Group"))) {
362+
if (const auto *Group = dyn_cast<DefInit>(R->getValueInit("Group"))) {
363363
const Record *GroupRec = Group->getDef();
364364
if (!isSubGroupOfGroup(GroupRec, "pedantic")) {
365365
markGroup(GroupRec);
@@ -378,13 +378,13 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
378378
// Check if the group is implicitly in -Wpedantic. If so,
379379
// the diagnostic should not be directly included in the -Wpedantic
380380
// diagnostic group.
381-
if (DefInit *Group = dyn_cast<DefInit>(R->getValueInit("Group")))
381+
if (const auto *Group = dyn_cast<DefInit>(R->getValueInit("Group")))
382382
if (groupInPedantic(Group->getDef()))
383383
continue;
384384

385385
// The diagnostic is not included in a group that is (transitively) in
386386
// -Wpedantic. Include it in -Wpedantic directly.
387-
if (RecordVec *V = DiagsInPedantic.dyn_cast<RecordVec*>())
387+
if (auto *V = DiagsInPedantic.dyn_cast<RecordVec *>())
388388
V->push_back(R);
389389
else {
390390
DiagsInPedantic.get<RecordSet*>()->insert(R);
@@ -413,7 +413,7 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
413413
if (Parents.size() > 0 && AllParentsInPedantic)
414414
continue;
415415

416-
if (RecordVec *V = GroupsInPedantic.dyn_cast<RecordVec*>())
416+
if (auto *V = GroupsInPedantic.dyn_cast<RecordVec *>())
417417
V->push_back(Group);
418418
else {
419419
GroupsInPedantic.get<RecordSet*>()->insert(Group);
@@ -1443,7 +1443,7 @@ void clang::EmitClangDiagsDefs(const RecordKeeper &Records, raw_ostream &OS,
14431443
// Check if this is an error that is accidentally in a warning
14441444
// group.
14451445
if (isError(R)) {
1446-
if (DefInit *Group = dyn_cast<DefInit>(R.getValueInit("Group"))) {
1446+
if (const auto *Group = dyn_cast<DefInit>(R.getValueInit("Group"))) {
14471447
const Record *GroupRec = Group->getDef();
14481448
const std::string &GroupName =
14491449
std::string(GroupRec->getValueAsString("GroupName"));
@@ -1478,7 +1478,7 @@ void clang::EmitClangDiagsDefs(const RecordKeeper &Records, raw_ostream &OS,
14781478

14791479
// Warning group associated with the diagnostic. This is stored as an index
14801480
// into the alphabetically sorted warning group table.
1481-
if (DefInit *DI = dyn_cast<DefInit>(R.getValueInit("Group"))) {
1481+
if (const auto *DI = dyn_cast<DefInit>(R.getValueInit("Group"))) {
14821482
std::map<std::string, GroupInfo>::iterator I = DiagsInGroup.find(
14831483
std::string(DI->getDef()->getValueAsString("GroupName")));
14841484
assert(I != DiagsInGroup.end());

0 commit comments

Comments
 (0)