[patch] Fix PR c++/27820
Lee Millward
lee.millward@gmail.com
Fri Jun 30 18:49:00 GMT 2006
Hi,
The C++ front-end currently ICE's on the following invalid code snippet:
void foo()
{
L: L: ;
}
In the bugzilla PR Andrew Pinski suggested the first portion of the
patch to define_label return error_mark_node when an invalid label is
detected. Unfortunately this simply swaps the ICE listed in the PR for
an ICE in the gimplifier. This is because finish_label_stmt doesn't
check to make sure that the label being returned to it from
define_label is valid or not before calling add_stmt.
The proposed patch below incorporates Andrew Pinski's initial
suggestion with a further ammendment to finish_label_stmt to check for
invalid labels before calling add_stmt.
Bootstrapped and regression tested successfully on i686-pc-linux-gnu,
ok for mainline and for 4.1/4.0 assuming bootstrap/reg test succeeds
there?
Cheers,
Lee.
cp/
2006-06-30 Lee Millward <lee.millward@gmail.com>
Andrew Pinski <pinskia@gmail.com>
PR c++/27820
* decl.c (define_label): Return error_mark_node on error.
* semantics.c (finish_label_stmt): Don't call add_stmt
for invalid labels.
testsuite/
2006-06-30 Lee Millward <lee.millward@gmail.com>
PR c++/27820
* g++.dg/other/label1.C: New test.
-------------- next part --------------
Index: gcc/testsuite/g++.dg/other/label1.C
===================================================================
--- gcc/testsuite/g++.dg/other/label1.C (revision 0)
+++ gcc/testsuite/g++.dg/other/label1.C (revision 0)
@@ -0,0 +1,7 @@
+//PR c++/27820
+
+void foo()
+{
+ L: L: ; // { dg-error "duplicate label" }
+}
+
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c (revision 115074)
+++ gcc/cp/decl.c (working copy)
@@ -2538,7 +2538,10 @@ define_label (location_t location, tree
pedwarn ("label named wchar_t");
if (DECL_INITIAL (decl) != NULL_TREE)
- error ("duplicate label %qD", decl);
+ {
+ error ("duplicate label %qD", decl);
+ POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
+ }
else
{
struct named_label_use_entry *use;
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c (revision 115074)
+++ gcc/cp/semantics.c (working copy)
@@ -1293,6 +1293,10 @@ tree
finish_label_stmt (tree name)
{
tree decl = define_label (input_location, name);
+
+ if (decl == error_mark_node)
+ return error_mark_node;
+
return add_stmt (build_stmt (LABEL_EXPR, decl));
}
More information about the Gcc-patches
mailing list