This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR c++/21113


Hi,

This patch fixes c++/21113 which reports that the C++ frontend does not
forbid jumps into the scope of identifiers with variably-modified types.

The patch simply augments decl_jump_unsafe() to disallow jumping into
blocks that initialize variably-modified decls.

I bootstrapped and regtested this change on x86_64-unknown-linux-gnu.

2014-04-03  Patrick Palka  <patrick@parcs.ath.cx>

	PR c++/21113
	* decl.c (decl_jump_unsafe): Consider variably-modified decls.
---
 gcc/cp/decl.c                    |  5 ++---
 gcc/testsuite/g++.dg/ext/vla14.C | 23 +++++++++++++++++++++++
 2 files changed, 25 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/vla14.C

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 5bd33c5..6571af5 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -2785,9 +2785,8 @@ decl_jump_unsafe (tree decl)
       || type == error_mark_node)
     return 0;
 
-  type = strip_array_types (type);
-
-  if (DECL_NONTRIVIALLY_INITIALIZED_P (decl))
+  if (DECL_NONTRIVIALLY_INITIALIZED_P (decl)
+      || variably_modified_type_p (type, NULL_TREE))
     return 2;
 
   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
diff --git a/gcc/testsuite/g++.dg/ext/vla14.C b/gcc/testsuite/g++.dg/ext/vla14.C
new file mode 100644
index 0000000..278cb63
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/vla14.C
@@ -0,0 +1,23 @@
+// PR c++/21113
+// { dg-options "" }
+
+void
+f (int n)
+{
+  goto label; // { dg-error "from here" }
+  int a[n]; // { dg-error "crosses initialization" }
+label: // { dg-error "jump to label" }
+  ;
+}
+
+void
+g (int n)
+{
+  switch (1)
+  {
+  case 1:
+    int (*a)[n]; // { dg-error "crosses initialization" }
+  default: // { dg-error "jump to case label" }
+    ;
+  }
+}
-- 
1.9.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]