Skip to content

[Clang][TableGen] Use const pointers for various Init * pointers in SA checker emitter #112321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

jurahul
Copy link
Contributor

@jurahul jurahul commented Oct 15, 2024

Use const pointers for various Init objects in SA checker 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

@jurahul jurahul force-pushed the const_init_clang_sa_checker_emitter branch from 658aa6c to 4743134 Compare October 15, 2024 15:14
@jurahul jurahul changed the title [Clang][TableGen] Use const pointers for various Init * pointers [Clang][TableGen] Use const pointers for various Init * pointers in SA checker emitter Oct 15, 2024
@jurahul jurahul marked this pull request as ready for review October 15, 2024 19:41
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Oct 15, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 15, 2024

@llvm/pr-subscribers-clang

Author: Rahul Joshi (jurahul)

Changes

Use const pointers for various Init objects in SA checker 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


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

1 Files Affected:

  • (modified) clang/utils/TableGen/ClangSACheckersEmitter.cpp (+5-5)
diff --git a/clang/utils/TableGen/ClangSACheckersEmitter.cpp b/clang/utils/TableGen/ClangSACheckersEmitter.cpp
index bebdcac3212613..36012dbf70791b 100644
--- a/clang/utils/TableGen/ClangSACheckersEmitter.cpp
+++ b/clang/utils/TableGen/ClangSACheckersEmitter.cpp
@@ -29,7 +29,7 @@ static std::string getPackageFullName(const Record *R, StringRef Sep = ".");
 static std::string getParentPackageFullName(const Record *R,
                                             StringRef Sep = ".") {
   std::string name;
-  if (DefInit *DI = dyn_cast<DefInit>(R->getValueInit("ParentPackage")))
+  if (const DefInit *DI = dyn_cast<DefInit>(R->getValueInit("ParentPackage")))
     name = getPackageFullName(DI->getDef(), Sep);
   return name;
 }
@@ -53,7 +53,7 @@ static std::string getCheckerFullName(const Record *R, StringRef Sep = ".") {
 }
 
 static std::string getStringValue(const Record &R, StringRef field) {
-  if (StringInit *SI = dyn_cast<StringInit>(R.getValueInit(field)))
+  if (const StringInit *SI = dyn_cast<StringInit>(R.getValueInit(field)))
     return std::string(SI->getValue());
   return std::string();
 }
@@ -94,7 +94,7 @@ static std::string getCheckerDocs(const Record &R) {
 /// the class itself has to be modified for adding a new option type in
 /// CheckerBase.td.
 static std::string getCheckerOptionType(const Record &R) {
-  if (BitsInit *BI = R.getValueAsBitsInit("Type")) {
+  if (const BitsInit *BI = R.getValueAsBitsInit("Type")) {
     switch(getValueFromBitsInit(BI, R)) {
     case 0:
       return "int";
@@ -111,7 +111,7 @@ static std::string getCheckerOptionType(const Record &R) {
 }
 
 static std::string getDevelopmentStage(const Record &R) {
-  if (BitsInit *BI = R.getValueAsBitsInit("DevelopmentStage")) {
+  if (const BitsInit *BI = R.getValueAsBitsInit("DevelopmentStage")) {
     switch(getValueFromBitsInit(BI, R)) {
     case 0:
       return "alpha";
@@ -131,7 +131,7 @@ static bool isHidden(const Record *R) {
     return true;
 
   // Not declared as hidden, check the parent package if it is hidden.
-  if (DefInit *DI = dyn_cast<DefInit>(R->getValueInit("ParentPackage")))
+  if (const DefInit *DI = dyn_cast<DefInit>(R->getValueInit("ParentPackage")))
     return isHidden(DI->getDef());
 
   return false;

Copy link
Contributor

@kazutakahirata kazutakahirata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@jurahul jurahul merged commit d1a4791 into llvm:main Oct 15, 2024
11 checks passed
@jurahul jurahul deleted the const_init_clang_sa_checker_emitter branch October 15, 2024 19:50
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
… SA checker emitter (llvm#112321)

Use const pointers for various Init objects in SA checker 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants