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.
 


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.
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to