[llvm] [NFCI] Update the directive pure-emitter to skip the switch if empty (PR #220255)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 1 06:56:25 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tablegen
Author: Erich Keane (erichkeane)
<details>
<summary>Changes</summary>
Since #<!-- -->212676, there has been a warning thanks to 'pure since' not being on any of the OpenACC directives. This patch skips the switch and just does a return if there are no pure directives.
---
Full diff: https://github.com/llvm/llvm-project/pull/220255.diff
3 Files Affected:
- (modified) llvm/test/TableGen/directive1.td (+1-4)
- (modified) llvm/test/TableGen/directive2.td (+3)
- (modified) llvm/utils/TableGen/Basic/DirectiveEmitter.cpp (+23-13)
``````````diff
diff --git a/llvm/test/TableGen/directive1.td b/llvm/test/TableGen/directive1.td
index 2b3a3a14828e5..a3400c42e4aca 100644
--- a/llvm/test/TableGen/directive1.td
+++ b/llvm/test/TableGen/directive1.td
@@ -191,10 +191,7 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-NEXT: constexpr unsigned getDirectivePureSince(Directive Dir) {
-// CHECK-NEXT: switch (Dir) {
-// CHECK-NEXT: default:
-// CHECK-NEXT: return 0x7FFFFFFF;
-// CHECK-NEXT: } // switch (Dir)
+// CHECK-NEXT: return 0x7FFFFFFF;
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-NEXT: constexpr SourceLanguage getDirectiveLanguages(Directive D) {
diff --git a/llvm/test/TableGen/directive2.td b/llvm/test/TableGen/directive2.td
index 367756206c6ac..2c7a2ccbe245e 100644
--- a/llvm/test/TableGen/directive2.td
+++ b/llvm/test/TableGen/directive2.td
@@ -40,6 +40,7 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
let isDefault = 1;
let association = AS_Block;
let category = CA_Declarative;
+ let pureSince = 0x00DEEA;
}
// CHECK: #ifndef LLVM_Tdl_INC
@@ -157,6 +158,8 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// CHECK-EMPTY:
// CHECK-NEXT: constexpr unsigned getDirectivePureSince(Directive Dir) {
// CHECK-NEXT: switch (Dir) {
+// CHECK-NEXT: case TDLD_dira:
+// CHECK-NEXT: return 57066;
// CHECK-NEXT: default:
// CHECK-NEXT: return 0x7FFFFFFF;
// CHECK-NEXT: } // switch (Dir)
diff --git a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
index 7fe9406b27d64..c990d63e30274 100644
--- a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
@@ -905,21 +905,31 @@ static void generateGetDirectivePureSince(const DirectiveLanguage &DirLang,
// OmpStructureChecker::CheckDirectiveInPureProcedure.
constexpr int NeverPure = 0x7FFFFFFF;
OS << "constexpr unsigned getDirectivePureSince(Directive Dir) {\n";
- OS << " switch (Dir) {\n";
-
- StringRef Prefix = DirLang.getDirectivePrefix();
- for (const Record *R : DirLang.getDirectives()) {
- Directive D(R);
- int PureSince = D.getPureSince();
- if (PureSince == NeverPure)
- continue;
- OS << " case " << getIdentifierName(R, Prefix) << ":\n";
- OS << " return " << PureSince << ";\n";
+ // Only print the switch if we have any pure directives, as the switch with
+ // only a default is a warning on some compilers.
+ if (llvm::any_of(DirLang.getDirectives(), [](const Record *R) {
+ Directive D(R);
+ return D.getPureSince() != NeverPure;
+ })) {
+ OS << " switch (Dir) {\n";
+
+ StringRef Prefix = DirLang.getDirectivePrefix();
+
+ for (const Record *R : DirLang.getDirectives()) {
+ Directive D(R);
+ int PureSince = D.getPureSince();
+ if (PureSince == NeverPure)
+ continue;
+ OS << " case " << getIdentifierName(R, Prefix) << ":\n";
+ OS << " return " << PureSince << ";\n";
+ }
+ OS << " default:\n";
+ OS << " return 0x7FFFFFFF;\n";
+ OS << " } // switch (Dir)\n";
+ } else {
+ OS << " return 0x7FFFFFFF;\n";
}
- OS << " default:\n";
- OS << " return 0x7FFFFFFF;\n";
- OS << " } // switch (Dir)\n";
OS << "}\n";
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/220255
More information about the llvm-commits
mailing list