[llvm] [TableGen] Avoid deprecated-enum-enum-conversion C++20 warnings; NFC (PR #218909)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 05:00:32 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-tablegen

Author: Sven van Haastregt (svenvh)

<details>
<summary>Changes</summary>

The bitwise OR of different enum types resulted in many C++20 deprecation warnings in the generated option tables:

     warning: bitwise operation between different enumeration types
     ‘llvm::opt::DriverVisibility’ and
     ‘clang::options::ClangVisibility’ is deprecated
     [-Wdeprecated-enum-enum-conversion]

Fix by emitting casts to `unsigned`, matching the types of the corresponding fields in `OptTable::Info`.

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


1 Files Affected:

- (modified) llvm/utils/TableGen/OptionParserEmitter.cpp (+8-7) 


``````````diff
diff --git a/llvm/utils/TableGen/OptionParserEmitter.cpp b/llvm/utils/TableGen/OptionParserEmitter.cpp
index 829c202b495e4..471119edccfd6 100644
--- a/llvm/utils/TableGen/OptionParserEmitter.cpp
+++ b/llvm/utils/TableGen/OptionParserEmitter.cpp
@@ -524,11 +524,12 @@ static void emitOptionParser(const RecordKeeper &Records, raw_ostream &OS) {
     int NumFlags = 0;
     const ListInit *LI = R.getValueAsListInit("Flags");
     for (const Init *I : *LI)
-      OS << (NumFlags++ ? " | " : "") << cast<DefInit>(I)->getDef()->getName();
+      OS << (NumFlags++ ? " | " : "") << "static_cast<unsigned>("
+         << cast<DefInit>(I)->getDef()->getName() << ")";
     if (GroupFlags) {
       for (const Init *I : *GroupFlags)
-        OS << (NumFlags++ ? " | " : "")
-           << cast<DefInit>(I)->getDef()->getName();
+        OS << (NumFlags++ ? " | " : "") << "static_cast<unsigned>("
+           << cast<DefInit>(I)->getDef()->getName() << ")";
     }
     if (NumFlags == 0)
       OS << '0';
@@ -538,12 +539,12 @@ static void emitOptionParser(const RecordKeeper &Records, raw_ostream &OS) {
     int NumVisFlags = 0;
     LI = R.getValueAsListInit("Visibility");
     for (const Init *I : *LI)
-      OS << (NumVisFlags++ ? " | " : "")
-         << cast<DefInit>(I)->getDef()->getName();
+      OS << (NumVisFlags++ ? " | " : "") << "static_cast<unsigned>("
+         << cast<DefInit>(I)->getDef()->getName() << ")";
     if (GroupVis) {
       for (const Init *I : *GroupVis)
-        OS << (NumVisFlags++ ? " | " : "")
-           << cast<DefInit>(I)->getDef()->getName();
+        OS << (NumVisFlags++ ? " | " : "") << "static_cast<unsigned>("
+           << cast<DefInit>(I)->getDef()->getName() << ")";
     }
     if (NumVisFlags == 0)
       OS << '0';

``````````

</details>


https://github.com/llvm/llvm-project/pull/218909


More information about the llvm-commits mailing list