From: "Uecker, Martin" <Martin.Uecker@med.uni-goettingen.de>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Cc: "joseph@codesourcery.com" <joseph@codesourcery.com>
Subject: [PATCH] mixing of labels and code in C2X
Date: Sun, 13 Sep 2020 11:20:46 +0000 [thread overview]
Message-ID: <1599996046.28509.3.camel@med.uni-goettingen.de> (raw)
Hi Joseph,
here is the (unfinished) patch to support
mixing of labels in C2X.
I preserved existing tests by adding
"-std=c17 -pedantic-error"
So far, I haven't figured out how
to fix the OpenMP related warning
in 'gcc.dg/gomp/barrier-2.c'.
Best,
Martin
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index a8bc301ffad..dc7b2e6b555 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -5836,7 +5836,7 @@ c_parser_compound_statement_nostart (c_parser *parser)
parser->error = false;
}
if (last_label)
- error_at (label_loc, "label at end of compound statement");
+ pedwarn_c11 (label_loc, OPT_Wpedantic, "label at end of compound statement");
location_t endloc = c_parser_peek_token (parser)->location;
c_parser_consume_token (parser);
/* Restore the value we started with. */
@@ -5984,7 +5984,7 @@ c_parser_label (c_parser *parser)
|| (have_std_attrs
&& c_parser_next_token_is (parser, CPP_SEMICOLON)))
{
- error_at (c_parser_peek_token (parser)->location,
+ pedwarn_c11 (c_parser_peek_token (parser)->location, OPT_Wpedantic,
"a label can only be part of a statement and "
"a declaration is not a statement");
c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 3b37aba5795..b0c54b6042d 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -55,7 +55,7 @@ extensions, accepted by GCC in C90 mode and in C++.
* Designated Inits:: Labeling elements of initializers.
* Case Ranges:: `case 1 ... 9' and such.
* Cast to Union:: Casting to union type from any member of the union.
-* Mixed Declarations:: Mixing declarations and code.
+* Mixed Labels and Declarations:: Mixing declarations, labels and code.
* Function Attributes:: Declaring that functions have no side effects,
or that they can never return.
* Variable Attributes:: Specifying attributes of variables.
@@ -2353,15 +2353,17 @@ void hack (union foo);
hack ((union foo) x);
@end smallexample
-@node Mixed Declarations
-@section Mixed Declarations and Code
+@node Mixed Labels and Declarations
+@section Mixed Declarations, Labels and Code
@cindex mixed declarations and code
@cindex declarations, mixed with code
@cindex code, mixed with declarations
ISO C99 and ISO C++ allow declarations and code to be freely mixed
-within compound statements. As an extension, GNU C also allows this in
-C90 mode. For example, you could do:
+within compound statements. ISO C2X allows labels to be
+placed before declarations and at the end of a compound statement.
+As an extension, GNU C also allows all this in C90 mode. For example,
+you could do:
@smallexample
int i;
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 5d29a7fa23c..97c594eacce 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -7442,7 +7442,7 @@ except when the same as the default promotion.
@opindex Wno-declaration-after-statement
Warn when a declaration is found after a statement in a block. This
construct, known from C++, was introduced with ISO C99 and is by default
-allowed in GCC@. It is not supported by ISO C90. @xref{Mixed Declarations}.
+allowed in GCC@. It is not supported by ISO C90. @xref{Mixed Labels and Declarations}.
@item -Wshadow
@opindex Wshadow
diff --git a/gcc/testsuite/gcc.dg/20031223-1.c b/gcc/testsuite/gcc.dg/20031223-1.c
index 68aa74ffe50..2744dc69454 100644
--- a/gcc/testsuite/gcc.dg/20031223-1.c
+++ b/gcc/testsuite/gcc.dg/20031223-1.c
@@ -3,11 +3,11 @@
because GCC was trying to expand the trees to rtl. */
/* { dg-do compile } */
-/* { dg-options "" } */
+/* { dg-options "-std=c17 -pedantic-errors" } */
void f ()
{
l: int; /* { dg-error "a label can only be part of a statement and a declaration is not a
statement" "not stmt" } */
- /* { dg-warning "useless type name in empty declaration" "type name" { target *-*-* } .-1 } */
+ /* { dg-error "useless type name in empty declaration" "type name" { target *-*-* } .-1 } */
/* { dg-error "label at end of compound statement" "label" { target *-*-* } .-2 } */
}
diff --git a/gcc/testsuite/gcc.dg/c2x-attr-syntax-3.c b/gcc/testsuite/gcc.dg/c2x-attr-syntax-3.c
index 1f883d825e0..8ae33d9d01a 100644
--- a/gcc/testsuite/gcc.dg/c2x-attr-syntax-3.c
+++ b/gcc/testsuite/gcc.dg/c2x-attr-syntax-3.c
@@ -30,8 +30,9 @@ f2 (void)
void
f3 (void)
{
- x: [[]];; /* { dg-error "can only be part of a statement" } */
-}
+ if (1)
+ x: [[]];
+} /* { dg-error "expected" } */
/* Prefix attributes cannot appear on type names. */
diff --git a/gcc/testsuite/gcc.dg/c2x-labels-1.c b/gcc/testsuite/gcc.dg/c2x-labels-1.c
new file mode 100644
index 00000000000..5a7b7b97a01
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-labels-1.c
@@ -0,0 +1,22 @@
+/* Tests for labels before declarations and at ends of compound statements. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x" } */
+
+int f(int x)
+{
+ goto b;
+ a: int i = 2 * x;
+ goto c;
+ b: goto a;
+ { i *= 3; c: }
+ return i;
+ d:
+}
+
+int main(void)
+{
+ if (2 != f(1))
+ __builtin_abort();
+
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/decl-9.c b/gcc/testsuite/gcc.dg/decl-9.c
index eeca8e05e14..9bb15609d83 100644
--- a/gcc/testsuite/gcc.dg/decl-9.c
+++ b/gcc/testsuite/gcc.dg/decl-9.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-std=gnu89" } */
+/* { dg-options "-std=gnu89 -pedantic-errors" } */
w *x; /* { dg-error "unknown type name 'w'" } */
@@ -12,6 +12,7 @@ int f1()
int d, e;
d * e; /* { dg-bogus "unknown type name 'd'" } */
g * h; /* { dg-error "unknown type name 'g'" } */
+ /* { dg-error "mixed declarations" "" { target *-*-* } .-1 } */
g i; /* { dg-error "unknown type name 'g'" } */
}
diff --git a/gcc/testsuite/gcc.dg/gomp/barrier-2.c b/gcc/testsuite/gcc.dg/gomp/barrier-2.c
index 5a7091946c4..98e16b2e051 100644
--- a/gcc/testsuite/gcc.dg/gomp/barrier-2.c
+++ b/gcc/testsuite/gcc.dg/gomp/barrier-2.c
@@ -1,4 +1,5 @@
/* { dg-do compile } */
+/* { dg-options "-Wall -std=c17 -fopenmp -pedantic-errors" } */
void f1(void)
{
@@ -16,6 +17,7 @@ void f1(void)
void f2(void)
{
label: /* { dg-error "label at end of compound statement" } */
+ /* { dg-error "defined but not used" "" { target *-*-* } .-1 } */
#pragma omp barrier /* { dg-error "may only be used in compound statements" } */
}
diff --git a/gcc/testsuite/gcc.dg/gomp/declare-simd-5.c b/gcc/testsuite/gcc.dg/gomp/declare-simd-5.c
index fe236525d62..51bd5f25bb0 100644
--- a/gcc/testsuite/gcc.dg/gomp/declare-simd-5.c
+++ b/gcc/testsuite/gcc.dg/gomp/declare-simd-5.c
@@ -1,5 +1,6 @@
/* Test parsing of #pragma omp declare simd */
/* { dg-do compile } */
+/* { dg-options "-std=c17 -fopenmp -pedantic-errors" } */
int
f1 (int x)
diff --git a/gcc/testsuite/gcc.dg/label-compound-stmt-1.c b/gcc/testsuite/gcc.dg/label-compound-
stmt-1.c
index 2f8fa4e65c2..2ae2b82ef1c 100644
--- a/gcc/testsuite/gcc.dg/label-compound-stmt-1.c
+++ b/gcc/testsuite/gcc.dg/label-compound-stmt-1.c
@@ -1,7 +1,7 @@
/* Test that labels at ends of compound statements are hard errors. */
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
/* { dg-do compile } */
-/* { dg-options "" } */
+/* { dg-options "-std=c17 -pedantic-errors" } */
void f(void) { g: } /* { dg-bogus "warning" "warning in place of error" } */
/* { dg-error "label|parse|syntax" "label at end of compound statement" { target *-*-* } .-1 } */
diff --git a/gcc/testsuite/gcc.dg/parse-decl-after-label.c b/gcc/testsuite/gcc.dg/parse-decl-after-
label.c
index 9c9886a108f..6e2a047eb2e 100644
--- a/gcc/testsuite/gcc.dg/parse-decl-after-label.c
+++ b/gcc/testsuite/gcc.dg/parse-decl-after-label.c
@@ -1,6 +1,6 @@
/* PR 29062
{ dg-do compile }
-{ dg-options "-fsyntax-only" }
+{ dg-options "-std=c17 -pedantic-errors -fsyntax-only" }
*/
int f(int x)
next reply other threads:[~2020-09-13 11:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-13 11:20 Uecker, Martin [this message]
2020-09-14 20:30 ` Joseph Myers
2020-11-01 22:34 ` Uecker, Martin
2020-11-02 21:16 ` Joseph Myers
2020-11-06 6:56 ` Uecker, Martin
2020-11-06 22:07 ` Joseph Myers
2020-11-06 22:25 ` Uecker, Martin
2020-11-06 22:44 ` Joseph Myers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1599996046.28509.3.camel@med.uni-goettingen.de \
--to=martin.uecker@med.uni-goettingen.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=joseph@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).