[PATCH] D146393: [Clang] Support free positioning of labels inside compound statements in C

Evgeny Shulgin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 19 14:07:20 PDT 2023


Izaron created this revision.
Izaron added reviewers: aaron.ballman, cor3ntin.
Herald added a project: All.
Izaron requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Implements part of paper P2324R2
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2508.pdf
Fixes https://github.com/llvm/llvm-project/issues/61507


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146393

Files:
  clang/lib/Parse/ParseStmt.cpp
  clang/test/OpenMP/allocate_messages.cpp
  clang/test/OpenMP/threadprivate_messages.cpp
  clang/test/Parser/c2x-label.c


Index: clang/test/Parser/c2x-label.c
===================================================================
--- clang/test/Parser/c2x-label.c
+++ clang/test/Parser/c2x-label.c
@@ -2,10 +2,11 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c2x -Wpre-c2x-compat -verify=c2x %s
 
 void test_label_in_func() {
-    int x;
 label1:
+    int x;
+label2:
     x = 1;
-label2: label3: label4:
+label3: label4: label5:
 } // c17-warning {{label at end of compound statement is a C2x extension}} \
      c2x-warning {{label at end of compound statement is incompatible with C standards before C2x}}
 
Index: clang/test/OpenMP/threadprivate_messages.cpp
===================================================================
--- clang/test/OpenMP/threadprivate_messages.cpp
+++ clang/test/OpenMP/threadprivate_messages.cpp
@@ -138,7 +138,7 @@
   }
 #pragma omp threadprivate(d3)
 label:
-#pragma omp threadprivate(d4) // expected-error {{'#pragma omp threadprivate' cannot be an immediate substatement}}
+#pragma omp threadprivate(d4)
 
 #pragma omp threadprivate(a) // expected-error {{'#pragma omp threadprivate' must appear in the scope of the 'a' variable declaration}}
   return (y);
Index: clang/test/OpenMP/allocate_messages.cpp
===================================================================
--- clang/test/OpenMP/allocate_messages.cpp
+++ clang/test/OpenMP/allocate_messages.cpp
@@ -141,7 +141,7 @@
   }
 #pragma omp allocate(d3)
 label:
-#pragma omp allocate(d4) // expected-error {{'#pragma omp allocate' cannot be an immediate substatement}}
+#pragma omp allocate(d4)
 
 #pragma omp allocate(a) // expected-error {{'#pragma omp allocate' must appear in the scope of the 'a' variable declaration}}
   return (y);
Index: clang/lib/Parse/ParseStmt.cpp
===================================================================
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -692,10 +692,6 @@
   assert(Tok.is(tok::identifier) && Tok.getIdentifierInfo() &&
          "Not an identifier!");
 
-  // The substatement is always a 'statement', not a 'declaration', but is
-  // otherwise in the same context as the labeled-statement.
-  StmtCtx &= ~ParsedStmtContext::AllowDeclarationsInC;
-
   Token IdentTok = Tok;  // Save the whole token.
   ConsumeToken();  // eat the identifier.
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146393.506424.patch
Type: text/x-patch
Size: 2290 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230319/9e1b61a2/attachment.bin>


More information about the cfe-commits mailing list