Normally, gimplification removes the DECL_INITIAL from local variables
so that they aren't visible by the time we get to debug output. But in
the case of a cloned constructor, the DECL_INITIAL in the abstract copy
is still set, so we try to add DW_AT_const_value in for a local variable
now that the front end is setting DECL_INITIAL for simple non-constant
initializers.
I noticed that the comment on tree_add_const_value_attribute_for_decl
talked about variables with static storage duration, but the function
doesn't actually test for that. Adding such a test fixes the ICE.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 8ae67357954e593b1ce19c2fc570ccee0259668e
Author: Jason Merrill <ja...@redhat.com>
Date: Sat May 21 22:15:06 2011 -0400
PR c++/49092
* dwarf2out.c (tree_add_const_value_attribute_for_decl): Check for
static storage duration.
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index b85a55e..55453a3 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -17719,7 +17719,9 @@ tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
if (!decl
|| (TREE_CODE (decl) != VAR_DECL
- && TREE_CODE (decl) != CONST_DECL))
+ && TREE_CODE (decl) != CONST_DECL)
+ || (TREE_CODE (decl) == VAR_DECL
+ && !TREE_STATIC (decl)))
return false;
if (TREE_READONLY (decl)
diff --git a/gcc/testsuite/g++.dg/debug/const5.C b/gcc/testsuite/g++.dg/debug/const5.C
new file mode 100644
index 0000000..e5387ea
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/const5.C
@@ -0,0 +1,13 @@
+// PR c++/49092
+
+struct A
+{
+ A();
+};
+
+int i;
+
+A::A()
+{
+ const int j = i;
+}