aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPatrick Palka <patrick@parcs.ath.cx>2014-04-05 02:36:00 +0700
committerJason Merrill <jason@gcc.gnu.org>2014-04-04 15:36:00 -0400
commit0450fc0b5172c89c5f4699918b8c9fab0cc4b8ce (patch)
treef7b75c382b59179eb5fe4c75f7d7165e04fa37ad /gcc
parent822cc906fd9341dd64f808f4553aaa07c8de8c6a (diff)
downloadgcc-0450fc0b5172c89c5f4699918b8c9fab0cc4b8ce.zip
gcc-0450fc0b5172c89c5f4699918b8c9fab0cc4b8ce.tar.gz
gcc-0450fc0b5172c89c5f4699918b8c9fab0cc4b8ce.tar.bz2
re PR c++/44613 (Declaring an array with non-constant length inside a switch corrupts stack pointer.)
PR c++/44613 * semantics.c (add_stmt): Set STATEMENT_LIST_HAS_LABEL. * decl.c (cp_finish_decl): Create a new BIND_EXPR before instantiating a variable-sized type. From-SVN: r209125
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/decl.c19
-rw-r--r--gcc/cp/semantics.c3
-rw-r--r--gcc/testsuite/g++.dg/ext/vla15.C20
4 files changed, 46 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 615db3f..b3b9ccb 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,10 @@
2014-04-04 Patrick Palka <patrick@parcs.ath.cx>
+ PR c++/44613
+ * semantics.c (add_stmt): Set STATEMENT_LIST_HAS_LABEL.
+ * decl.c (cp_finish_decl): Create a new BIND_EXPR before
+ instantiating a variable-sized type.
+
PR c++/21113
* decl.c (decl_jump_unsafe): Consider variably-modified decls.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 0d8ebcb..d70a865 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6440,7 +6440,24 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
after the call to check_initializer so that the DECL_EXPR for a
reference temp is added before the DECL_EXPR for the reference itself. */
if (DECL_FUNCTION_SCOPE_P (decl))
- add_decl_expr (decl);
+ {
+ /* If we're building a variable sized type, and we might be
+ reachable other than via the top of the current binding
+ level, then create a new BIND_EXPR so that we deallocate
+ the object at the right time. */
+ if (VAR_P (decl)
+ && DECL_SIZE (decl)
+ && !TREE_CONSTANT (DECL_SIZE (decl))
+ && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
+ {
+ tree bind;
+ bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
+ TREE_SIDE_EFFECTS (bind) = 1;
+ add_stmt (bind);
+ BIND_EXPR_BODY (bind) = push_stmt_list ();
+ }
+ add_decl_expr (decl);
+ }
/* Let the middle end know about variables and functions -- but not
static data members in uninstantiated class templates. */
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 07d1057..9269541 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -386,6 +386,9 @@ add_stmt (tree t)
STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
}
+ if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
+ STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
+
/* Add T to the statement-tree. Non-side-effect statements need to be
recorded during statement expressions. */
gcc_checking_assert (!stmt_list_stack->is_empty ());
diff --git a/gcc/testsuite/g++.dg/ext/vla15.C b/gcc/testsuite/g++.dg/ext/vla15.C
new file mode 100644
index 0000000..feeb49f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/vla15.C
@@ -0,0 +1,20 @@
+// PR c++/44613
+// { dg-do run }
+// { dg-options "" }
+
+void *volatile p;
+
+int
+main (void)
+{
+ int n = 0;
+ lab:;
+ int x[n % 1000 + 1];
+ x[0] = 1;
+ x[n % 1000] = 2;
+ p = x;
+ n++;
+ if (n < 1000000)
+ goto lab;
+ return 0;
+}