[clang] [llvm] [clang][OpenMP] Shorten directive classification in ParseOpenMP (PR #94691)

Mike Rice via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 24 15:40:56 PDT 2024


================
@@ -2374,86 +2374,209 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
   case OMPD_unknown:
     Diag(Tok, diag::err_omp_unknown_directive);
     break;
-  case OMPD_parallel:
-  case OMPD_simd:
-  case OMPD_tile:
-  case OMPD_unroll:
-  case OMPD_task:
-  case OMPD_taskyield:
+  default:
+    switch (getDirectiveCategory(DKind)) {
+    case Category::Executable:
+    case Category::Meta:
+    case Category::Subsidiary:
+    case Category::Utility:
+      Diag(Tok, diag::err_omp_unexpected_directive)
+          << 1 << getOpenMPDirectiveName(DKind);
+      break;
+    default:
+      break;
----------------
mikerice1969 wrote:

Can this be a fully covered switch instead?
For 'Declarative' I suspect there should be a case to handle it, if not it can assert here so we know we need to add code there.
And do whatever is needed for 'Informational' directives arriving here.
The idea is when someone adds a new directive it doesn't just fall through silently but alerts us to the missing code.

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


More information about the cfe-commits mailing list