This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C PATCH] Fix statement frontiers handling in the C FE (PR c/84721)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: "Joseph S. Myers" <joseph at codesourcery dot com>, Marek Polacek <polacek at redhat dot com>, Alexandre Oliva <aoliva at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 6 Mar 2018 21:51:57 +0100
- Subject: [C PATCH] Fix statement frontiers handling in the C FE (PR c/84721)
- Authentication-results: sourceware.org; auth=none
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
The C FE in multiple spots checks building_stmt_list_p () to decide if
we are inside of parsing of functions or outside of that.
Unfortunately, that breaks with add_debug_begin_stmt which pushes
DEBUG_BEGIN_STMTs regardless of the scope it appears in; e.g. on the
testcase below it pushes DEBUG_BEGIN_STMT already for the int a
declaration in column 1 on line 5, and so with -g building_stmt_list_p ()
is pretty much always true.
Fixed by only pushing DEBUG_BEGIN_STMTs when the building_stmt_list_p ()
predicate is true, they aren't really useful outside of functions anyway.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2018-03-06 Jakub Jelinek <jakub@redhat.com>
PR c/84721
* c-parser.c (add_debug_begin_stmt): Don't add DEBUG_BEGIN_STMT if
!building_stmt_list_p ().
* gcc.dg/pr84721.c: New test.
--- gcc/c/c-parser.c.jj 2018-02-06 13:12:49.320804579 +0100
+++ gcc/c/c-parser.c 2018-03-06 10:56:54.207194189 +0100
@@ -1654,7 +1654,8 @@ static void c_finish_oacc_routine (struc
static void
add_debug_begin_stmt (location_t loc)
{
- if (!MAY_HAVE_DEBUG_MARKER_STMTS)
+ /* Don't add DEBUG_BEGIN_STMTs outside of functions, see PR84721. */
+ if (!MAY_HAVE_DEBUG_MARKER_STMTS || !building_stmt_list_p ())
return;
tree stmt = build0 (DEBUG_BEGIN_STMT, void_type_node);
--- gcc/testsuite/gcc.dg/pr84721.c.jj 2018-03-06 11:03:23.798005268 +0100
+++ gcc/testsuite/gcc.dg/pr84721.c 2018-03-06 11:02:59.741016937 +0100
@@ -0,0 +1,6 @@
+/* PR c/84721 */
+/* { dg-do compile } */
+/* { dg-options "-g -O2" } */
+
+int a[({ int b })]; /* { dg-error "braced-group within expression allowed only inside a function" } */
+int c[({ int d () {}; })]; /* { dg-error "braced-group within expression allowed only inside a function" } */
Jakub