re PR middle-end/27657 (bogus undefined reference error to static var with -g and -O)
authorRichard Guenther <rguenther@suse.de>
Tue, 30 Jan 2007 10:23:01 +0000 (10:23 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 30 Jan 2007 10:23:01 +0000 (10:23 +0000)
2007-01-30  Richard Guenther  <rguenther@suse.de>

PR middle-end/27657
* dwarf2out.c (reference_to_unused): Query varpool if the
variable was output.

* g++.dg/debug/pr27657.C: New testcase.

From-SVN: r121335

gcc/ChangeLog
gcc/dwarf2out.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/debug/pr27657.C [new file with mode: 0644]

index 3c9d149c0a3a010172ccd0fe27d2d3a1a98fd107..90c826f5a05aae5e131b8883654dcf2325fb92a1 100644 (file)
@@ -1,3 +1,9 @@
+2007-01-30  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/27657
+       * dwarf2out.c (reference_to_unused): Query varpool if the
+       variable was output.
+
 2007-01-30  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/30313
index 6cd34355394930527f01cd852335987d2760d6a3..2968d3b3547d1986fbf9fb3c26c632b42b985765 100644 (file)
@@ -10045,8 +10045,14 @@ reference_to_unused (tree * tp, int * walk_subtrees,
   if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
       && ! TREE_ASM_WRITTEN (*tp))
     return *tp;
-  else
-    return NULL_TREE;
+  else if (DECL_P (*tp) && TREE_CODE (*tp) != FUNCTION_DECL)
+    {
+      struct varpool_node *node = varpool_node (*tp);
+      if (!node->needed)
+       return *tp;
+    }
+
+  return NULL_TREE;
 }
 
 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
index a8ad0c5d622d9618844e904c73d06024c53724ad..be372cf48d8d003461d10bbef58fa4b69f4580d3 100644 (file)
@@ -1,3 +1,8 @@
+2007-01-30  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/27657
+       * g++.dg/debug/pr27657.C: New testcase.
+
 2007-01-30  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/30313
diff --git a/gcc/testsuite/g++.dg/debug/pr27657.C b/gcc/testsuite/g++.dg/debug/pr27657.C
new file mode 100644 (file)
index 0000000..8351625
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do link } */
+
+const char s[] = "";
+const char *const p = s;
+
+int main()
+{
+  return 0;
+}